ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
36 protected $rbacsystem;
37
38 protected $latitude;
39 protected $longitude;
40 protected $zoom;
41 protected $address;
42
49 public function __construct($a_title = "", $a_postvar = "")
50 {
51 global $DIC;
52
53 $this->lng = $DIC->language();
54 $this->rbacsystem = $DIC->rbac()->system();
55 parent::__construct($a_title, $a_postvar);
56 $this->setType("location");
57 }
58
64 public function setLatitude($a_latitude)
65 {
66 $this->latitude = $a_latitude;
67 }
68
74 public function getLatitude()
75 {
76 return $this->latitude;
77 }
78
79
80
86 public function setLongitude($a_longitude)
87 {
88 $this->longitude = $a_longitude;
89 }
90
96 public function getLongitude()
97 {
98 return $this->longitude;
99 }
100
106 public function setZoom($a_zoom)
107 {
108 $this->zoom = $a_zoom;
109 }
110
116 public function getZoom()
117 {
118 return $this->zoom;
119 }
120
126 public function setAddress($a_address)
127 {
128 $this->address = $a_address;
129 }
130
136 public function getAddress()
137 {
138 return $this->address;
139 }
140
146 public function setValueByArray($a_values)
147 {
148 $this->setLatitude($a_values[$this->getPostVar()]["latitude"]);
149 $this->setLongitude($a_values[$this->getPostVar()]["longitude"]);
150 $this->setZoom($a_values[$this->getPostVar()]["zoom"]);
151 }
152
158 public function checkInput()
159 {
161
162 $_POST[$this->getPostVar()]["latitude"] =
163 ilUtil::stripSlashes($_POST[$this->getPostVar()]["latitude"]);
164 $_POST[$this->getPostVar()]["longitude"] =
165 ilUtil::stripSlashes($_POST[$this->getPostVar()]["longitude"]);
166 if ($this->getRequired() &&
167 (trim($_POST[$this->getPostVar()]["latitude"]) == "" || trim($_POST[$this->getPostVar()]["longitude"]) == "")) {
168 $this->setAlert($lng->txt("msg_input_is_required"));
169
170 return false;
171 }
172 return true;
173 }
174
179 public function insert($a_tpl)
180 {
183
184 $lng->loadLanguageModule("maps");
185 $tpl = new ilTemplate("tpl.prop_location.html", true, true, "Services/Form");
186 $tpl->setVariable("POST_VAR", $this->getPostVar());
187 $tpl->setVariable("TXT_ZOOM", $lng->txt("maps_zoom_level"));
188 $tpl->setVariable("TXT_LATITUDE", $lng->txt("maps_latitude"));
189 $tpl->setVariable("TXT_LONGITUDE", $lng->txt("maps_longitude"));
190 $tpl->setVariable("LOC_DESCRIPTION", $lng->txt("maps_std_location_desc"));
191
192 $lat = is_numeric($this->getLatitude())
193 ? $this->getLatitude()
194 : 0;
195 $long = is_numeric($this->getLongitude())
196 ? $this->getLongitude()
197 : 0;
198 $tpl->setVariable("PROPERTY_VALUE_LAT", $lat);
199 $tpl->setVariable("PROPERTY_VALUE_LONG", $long);
200 for ($i = 0; $i <= 18; $i++) {
201 $levels[$i] = $i;
202 }
203
204 $map_id = "map_" . md5(uniqid());
205
206 $tpl->setVariable(
207 "ZOOM_SELECT",
209 $this->getZoom(),
210 $this->getPostVar() . "[zoom]",
211 $levels,
212 false,
213 true,
214 0,
215 "",
216 array("id" => $map_id . "_zoom",
217 "onchange" => "ilUpdateMap('" . $map_id . "');")
218 )
219 );
220 $tpl->setVariable("MAP_ID", $map_id);
221 $tpl->setVariable("ID", $this->getPostVar());
222
223 // only show address input if geolocation url available
224 // else, if admin: show warning.
225
226 if ($this->geolocationAvailiable()) {
227 $tpl->setVariable("TXT_ADDR", $lng->txt("address"));
228 $tpl->setVariable("TXT_LOOKUP", $lng->txt("maps_lookup_address"));
229 $tpl->setVariable("TXT_ADDRESS", $this->getAddress());
230 $tpl->setVariable("MAP_ID_ADDR", $map_id);
231 $tpl->setVariable("POST_VAR_ADDR", $this->getPostVar());
232 } else {
233 if ($rbacsystem->checkAccess("visible", SYSTEM_FOLDER_ID)) {
234 $tpl->setVariable("TEXT", $lng->txt("configure_geolocation"));
235 }
236 }
237
238 include_once("./Services/Maps/classes/class.ilMapUtil.php");
239 $map_gui = ilMapUtil::getMapGUI();
240 $map_gui->setMapId($map_id)
241 ->setLatitude($lat)
242 ->setLongitude($long)
243 ->setZoom($this->getZoom())
244 ->setEnableTypeControl(true)
245 ->setEnableLargeMapControl(true)
246 ->setEnableUpdateListener(true)
247 ->setEnableCentralMarker(true);
248
249 $tpl->setVariable("MAP", $map_gui->getHtml());
250
251 $a_tpl->setCurrentBlock("prop_generic");
252 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
253 $a_tpl->parseCurrentBlock();
254 }
255
260 protected function geolocationAvailiable()
261 {
262 include_once("./Services/Maps/classes/class.ilMapUtil.php");
263 switch (ilMapUtil::getType()) {
264 case 'openlayers':
265 return ilMapUtil::getStdGeolocationServer() ? true : false;
266 case 'googlemaps':
267 return true;
268 default:
269 return false;
270 }
271 }
272}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
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.
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46