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 24/** 25* This class represents a location property in a property form. 26* 27* @author Alex Killing <alex.killing@gmx.de> 28* @version $Id$ 29* @ingroup ServicesForm 30*/ 31class ilLocationInputGUI extends ilFormPropertyGUI 32{ 33 /** 34 * @var ilRbacSystem 35 */ 36 protected $rbacsystem; 37 38 protected $latitude; 39 protected $longitude; 40 protected $zoom; 41 protected $address; 42 43 /** 44 * Constructor 45 * 46 * @param string $a_title Title 47 * @param string $a_postvar Post Variable 48 */ 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 59 /** 60 * Set Latitude. 61 * 62 * @param real $a_latitude Latitude 63 */ 64 public function setLatitude($a_latitude) 65 { 66 $this->latitude = $a_latitude; 67 } 68 69 /** 70 * Get Latitude. 71 * 72 * @return real Latitude 73 */ 74 public function getLatitude() 75 { 76 return $this->latitude; 77 } 78 79 80 81 /** 82 * Set Longitude. 83 * 84 * @param real $a_longitude Longitude 85 */ 86 public function setLongitude($a_longitude) 87 { 88 $this->longitude = $a_longitude; 89 } 90 91 /** 92 * Get Longitude. 93 * 94 * @return real Longitude 95 */ 96 public function getLongitude() 97 { 98 return $this->longitude; 99 } 100 101 /** 102 * Set Zoom. 103 * 104 * @param int $a_zoom Zoom 105 */ 106 public function setZoom($a_zoom) 107 { 108 $this->zoom = $a_zoom; 109 } 110 111 /** 112 * Get Zoom. 113 * 114 * @return int Zoom 115 */ 116 public function getZoom() 117 { 118 return $this->zoom; 119 } 120 121 /** 122 * Set Address. 123 * 124 * @param string $a_Address Address 125 */ 126 public function setAddress($a_address) 127 { 128 $this->address = $a_address; 129 } 130 131 /** 132 * Get Address. 133 * 134 * @return string Address 135 */ 136 public function getAddress() 137 { 138 return $this->address; 139 } 140 141 /** 142 * Set value by array 143 * 144 * @param array $a_values value array 145 */ 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 153 /** 154 * Check input, strip slashes etc. set alert, if input is not ok. 155 * 156 * @return boolean Input ok, true/false 157 */ 158 public function checkInput() 159 { 160 $lng = $this->lng; 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 175 /** 176 * Insert property html 177 * 178 */ 179 public function insert($a_tpl) 180 { 181 $lng = $this->lng; 182 $rbacsystem = $this->rbacsystem; 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", 208 ilUtil::formSelect( 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 256 /** 257 * Is geolocation configured? 258 * @return bool 259 */ 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} 273