ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLocationInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $latitude;
34  protected $longitude;
35  protected $zoom;
36  protected $address;
37 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  $this->setType("location");
48  }
49 
55  function setLatitude($a_latitude)
56  {
57  $this->latitude = $a_latitude;
58  }
59 
65  function getLatitude()
66  {
67  return $this->latitude;
68  }
69 
75  function setLongitude($a_longitude)
76  {
77  $this->longitude = $a_longitude;
78  }
79 
85  function getLongitude()
86  {
87  return $this->longitude;
88  }
89 
95  function setZoom($a_zoom)
96  {
97  $this->zoom = $a_zoom;
98  }
99 
105  function getZoom()
106  {
107  return $this->zoom;
108  }
109 
115  function setAddress($a_address)
116  {
117  $this->address = $a_address;
118  }
119 
125  function getAddress()
126  {
127  return $this->address;
128  }
129 
135  function setValueByArray($a_values)
136  {
137  $this->setLatitude($a_values[$this->getPostVar()]["latitude"]);
138  $this->setLongitude($a_values[$this->getPostVar()]["longitude"]);
139  $this->setZoom($a_values[$this->getPostVar()]["zoom"]);
140  }
141 
147  function checkInput()
148  {
149  global $lng;
150 
151  $_POST[$this->getPostVar()]["latitude"] =
152  ilUtil::stripSlashes($_POST[$this->getPostVar()]["latitude"]);
153  $_POST[$this->getPostVar()]["longitude"] =
154  ilUtil::stripSlashes($_POST[$this->getPostVar()]["longitude"]);
155  if ($this->getRequired() &&
156  (trim($_POST[$this->getPostVar()]["latitude"]) == "" || trim($_POST[$this->getPostVar()]["longitude"]) == ""))
157  {
158  $this->setAlert($lng->txt("msg_input_is_required"));
159 
160  return false;
161  }
162  return true;
163  }
164 
169  function insert(&$a_tpl)
170  {
171  global $lng;
172 
173  $lng->loadLanguageModule("gmaps");
174  $tpl = new ilTemplate("tpl.prop_location.html", true, true, "Services/Form");
175  $tpl->setVariable("POST_VAR", $this->getPostVar());
176  $tpl->setVariable("TXT_ZOOM", $lng->txt("gmaps_zoom_level"));
177  $tpl->setVariable("TXT_LATITUDE", $lng->txt("gmaps_latitude"));
178  $tpl->setVariable("TXT_LONGITUDE", $lng->txt("gmaps_longitude"));
179  $tpl->setVariable("TXT_ADDR", $lng->txt("address"));
180  $tpl->setVariable("LOC_DESCRIPTION", $lng->txt("gmaps_std_location_desc"));
181 
182  $lat = is_numeric($this->getLatitude())
183  ? $this->getLatitude()
184  : 0;
185  $long = is_numeric($this->getLongitude())
186  ? $this->getLongitude()
187  : 0;
188  $tpl->setVariable("PROPERTY_VALUE_LAT", $lat);
189  $tpl->setVariable("PROPERTY_VALUE_LONG", $long);
190  for($i = 0; $i <= 18; $i++)
191  {
192  $levels[$i] = $i;
193  }
194  $tpl->setVariable("ZOOM_SELECT",
195  ilUtil::formSelect($this->getZoom(), $this->getPostVar()."[zoom]",
196  $levels, false, true, 0, "", array("id" => "map_".$this->getPostVar()."_zoom",
197  "onchange" => "ilUpdateMap('"."map_".$this->getPostVar()."');")));
198  $tpl->setVariable("MAP_ID", "map_".$this->getPostVar());
199  $tpl->setVariable("ID", $this->getPostVar());
200  $tpl->setVariable("TXT_LOOKUP", $lng->txt("gmaps_lookup_address"));
201  $tpl->setVariable("TXT_ADDRESS", $this->getAddress());
202 
203  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
204  $map_gui = new ilGoogleMapGUI();
205  $map_gui->setMapId("map_".$this->getPostVar());
206  $map_gui->setLatitude($lat);
207  $map_gui->setLongitude($long);
208  $map_gui->setZoom($this->getZoom());
209  $map_gui->setEnableTypeControl(true);
210  $map_gui->setEnableLargeMapControl(true);
211  $map_gui->setEnableUpdateListener(true);
212  $map_gui->setEnableCentralMarker(true);
213 
214  $tpl->setVariable("MAP", $map_gui->getHtml());
215 
216  $a_tpl->setCurrentBlock("prop_generic");
217  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
218  $a_tpl->parseCurrentBlock();
219  }
220 
221 }