ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
70
71
77 function setLongitude($a_longitude)
78 {
79 $this->longitude = $a_longitude;
80 }
81
87 function getLongitude()
88 {
89 return $this->longitude;
90 }
91
97 function setZoom($a_zoom)
98 {
99 $this->zoom = $a_zoom;
100 }
101
107 function getZoom()
108 {
109 return $this->zoom;
110 }
111
117 function setAddress($a_address)
118 {
119 $this->address = $a_address;
120 }
121
127 function getAddress()
128 {
129 return $this->address;
130 }
131
137 function setValueByArray($a_values)
138 {
139 $this->setLatitude($a_values[$this->getPostVar()]["latitude"]);
140 $this->setLongitude($a_values[$this->getPostVar()]["longitude"]);
141 $this->setZoom($a_values[$this->getPostVar()]["zoom"]);
142 }
143
149 function checkInput()
150 {
151 global $lng;
152
153 $_POST[$this->getPostVar()]["latitude"] =
154 ilUtil::stripSlashes($_POST[$this->getPostVar()]["latitude"]);
155 $_POST[$this->getPostVar()]["longitude"] =
156 ilUtil::stripSlashes($_POST[$this->getPostVar()]["longitude"]);
157 if ($this->getRequired() &&
158 (trim($_POST[$this->getPostVar()]["latitude"]) == "" || trim($_POST[$this->getPostVar()]["longitude"]) == ""))
159 {
160 $this->setAlert($lng->txt("msg_input_is_required"));
161
162 return false;
163 }
164 return true;
165 }
166
171 function insert(&$a_tpl)
172 {
173 global $lng, $rbacsystem;
174
175 $lng->loadLanguageModule("maps");
176 $tpl = new ilTemplate("tpl.prop_location.html", true, true, "Services/Form");
177 $tpl->setVariable("POST_VAR", $this->getPostVar());
178 $tpl->setVariable("TXT_ZOOM", $lng->txt("maps_zoom_level"));
179 $tpl->setVariable("TXT_LATITUDE", $lng->txt("maps_latitude"));
180 $tpl->setVariable("TXT_LONGITUDE", $lng->txt("maps_longitude"));
181 $tpl->setVariable("LOC_DESCRIPTION", $lng->txt("maps_std_location_desc"));
182
183 $lat = is_numeric($this->getLatitude())
184 ? $this->getLatitude()
185 : 0;
186 $long = is_numeric($this->getLongitude())
187 ? $this->getLongitude()
188 : 0;
189 $tpl->setVariable("PROPERTY_VALUE_LAT", $lat);
190 $tpl->setVariable("PROPERTY_VALUE_LONG", $long);
191 for($i = 0; $i <= 18; $i++)
192 {
193 $levels[$i] = $i;
194 }
195
196 $map_id = "map_".md5(uniqid());
197
198 $tpl->setVariable("ZOOM_SELECT",
199 ilUtil::formSelect($this->getZoom(), $this->getPostVar()."[zoom]",
200 $levels, false, true, 0, "", array("id" => $map_id."_zoom",
201 "onchange" => "ilUpdateMap('".$map_id."');")));
202 $tpl->setVariable("MAP_ID", $map_id);
203 $tpl->setVariable("ID", $this->getPostVar());
204
205 // only show address input if geolocation url available
206 // else, if admin: show warning.
207
208 if($this->geolocationAvailiable()) {
209 $tpl->setVariable("TXT_ADDR", $lng->txt("address"));
210 $tpl->setVariable("TXT_LOOKUP", $lng->txt("maps_lookup_address"));
211 $tpl->setVariable("TXT_ADDRESS", $this->getAddress());
212 $tpl->setVariable("MAP_ID_ADDR", $map_id);
213 $tpl->setVariable("POST_VAR_ADDR", $this->getPostVar());
214 } else {
215 if($rbacsystem->checkAccess("visible", SYSTEM_FOLDER_ID)) {
216 $tpl->setVariable("TEXT", $lng->txt("configure_geolocation"));
217 }
218 }
219
220 include_once("./Services/Maps/classes/class.ilMapUtil.php");
221 $map_gui = ilMapUtil::getMapGUI();
222 $map_gui->setMapId($map_id)
223 ->setLatitude($lat)
224 ->setLongitude($long)
225 ->setZoom($this->getZoom())
226 ->setEnableTypeControl(true)
227 ->setEnableLargeMapControl(true)
228 ->setEnableUpdateListener(true)
229 ->setEnableCentralMarker(true);
230
231 $tpl->setVariable("MAP", $map_gui->getHtml());
232
233 $a_tpl->setCurrentBlock("prop_generic");
234 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
235 $a_tpl->parseCurrentBlock();
236 }
237
242 protected function geolocationAvailiable() {
243 include_once("./Services/Maps/classes/class.ilMapUtil.php");
244 switch(ilMapUtil::getType()) {
245 case 'openlayers':
246 return ilMapUtil::getStdGeolocationServer() ? true : false;
247 case 'googlemaps':
248 return true;
249 default:
250 return false;
251 }
252 }
253}
global $tpl
Definition: ilias.php:8
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
This class represents a location property in a property form.
checkInput()
Check input, strip slashes etc.
setAddress($a_address)
Set Address.
setValueByArray($a_values)
Set value by array.
insert(&$a_tpl)
Insert property html.
__construct($a_title="", $a_postvar="")
Constructor.
geolocationAvailiable()
Is geolocation configured?
setLatitude($a_latitude)
Set Latitude.
setLongitude($a_longitude)
Set Longitude.
static getStdGeolocationServer()
Returns the reverse geolocation server to be used in the installation.
static getMapGUI()
Get an instance of the GUI class.
static getType()
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static formSelect($selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40