ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGoogleMapGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
33 {
34 
35  protected $enabletypecontrol = false;
36  protected $enableupdatelistener = false;
37  protected $enablenavigationcontrol = false;
38  protected $enablelargemapcontrol = false;
39  protected $width = "500px";
40  protected $height = "300px";
41  protected $user_marker = array();
42 
43  function ilGoogleMapGUI()
44  {
45  global $lng, $tpl;
46 
47  $gm_set = new ilSetting("google_maps");
48  $lng->loadLanguageModule("gmaps");
49 
50  if ($gm_set->get("api_key") != "")
51  {
52  $tpl->addJavaScript("http://maps.google.com/maps?file=api&amp;v=2&amp;key=".
53  $gm_set->get("api_key"), false);
54  $tpl->addJavaScript("Services/JavaScript/js/Basic.js");
55  $tpl->addJavaScript("Services/GoogleMaps/js/ServiceGoogleMaps.js");
56  }
57  }
58 
64  function setMapId($a_mapid)
65  {
66  $this->mapid = $a_mapid;
67  }
68 
74  function getMapId()
75  {
76  return $this->mapid;
77  }
78 
84  function setWidth($a_width)
85  {
86  $this->width = $a_width;
87  }
88 
94  function getWidth()
95  {
96  return $this->width;
97  }
98 
104  function setHeight($a_height)
105  {
106  $this->height = $a_height;
107  }
108 
114  function getHeight()
115  {
116  return $this->height;
117  }
118 
124  function setLatitude($a_latitude)
125  {
126  $this->latitude = $a_latitude;
127  }
128 
134  function getLatitude()
135  {
136  return $this->latitude;
137  }
138 
144  function setLongitude($a_longitude)
145  {
146  $this->longitude = $a_longitude;
147  }
148 
154  function getLongitude()
155  {
156  return $this->longitude;
157  }
158 
164  function setZoom($a_zoom)
165  {
166  $this->zoom = $a_zoom;
167  }
168 
174  function getZoom()
175  {
176  return $this->zoom;
177  }
178 
184  function setEnableTypeControl($a_enabletypecontrol)
185  {
186  $this->enabletypecontrol = $a_enabletypecontrol;
187  }
188 
195  {
197  }
198 
204  function setEnableNavigationControl($a_enablenavigationcontrol)
205  {
206  $this->enablenavigationcontrol = $a_enablenavigationcontrol;
207  }
208 
215  {
217  }
218 
224  function setEnableUpdateListener($a_enableupdatelistener)
225  {
226  $this->enableupdatelistener = $a_enableupdatelistener;
227  }
228 
235  {
237  }
238 
244  function setEnableLargeMapControl($a_largemapcontrol)
245  {
246  $this->largemapcontrol = $a_largemapcontrol;
247  }
248 
255  {
256  return $this->largemapcontrol;
257  }
258 
264  function setEnableCentralMarker($a_centralmarker)
265  {
266  $this->centralmarker = $a_centralmarker;
267  }
268 
275  {
276  return $this->centralmarker;
277  }
278 
284  function addUserMarker($a_user_id)
285  {
286  return $this->user_marker[] = $a_user_id;
287  }
288 
292  function getHtml()
293  {
294  global $tpl;
295 
296  $this->tpl = new ilTemplate("tpl.google_map.html",
297  true, true, "Services/GoogleMaps");
298 
299  $gm_set = new ilSetting("google_maps");
300  if ($gm_set->get("api_key") != "")
301  {
302  $tpl->addJavaScript("http://maps.google.com/maps?file=api&amp;v=2&amp;key=".
303  $gm_set->get("api_key"));
304  $tpl->addJavaScript("Services/JavaScript/js/Basic.js");
305  $tpl->addJavaScript("Services/GoogleMaps/js/ServiceGoogleMaps.js");
306 
307  // add user markers
308  $cnt = 0;
309  foreach($this->user_marker as $user_id)
310  {
311  if (ilObject::_exists($user_id))
312  {
313  $user = new ilObjUser($user_id);
314  if ($user->getLatitude() != 0 && $user->getLongitude() != 0 &&
315  $user->getPref("public_location") == "y")
316  {
317  $this->tpl->setCurrentBlock("user_marker");
318  $this->tpl->setVariable("UMAP_ID",
319  $this->getMapId());
320  $this->tpl->setVariable("CNT", $cnt);
321 
322  $this->tpl->setVariable("ULAT", htmlspecialchars($user->getLatitude()));
323  $this->tpl->setVariable("ULONG", htmlspecialchars($user->getLongitude()));
324  $info = htmlspecialchars($user->getFirstName()." ".$user->getLastName());
325  $delim = "<br \/>";
326  if ($user->getPref("public_institution") == "y")
327  {
328  $info.= $delim.htmlspecialchars($user->getInstitution());
329  $delim = ", ";
330  }
331  if ($user->getPref("public_department") == "y")
332  {
333  $info.= $delim.htmlspecialchars($user->getDepartment());
334  }
335  $delim = "<br \/>";
336  if ($user->getPref("public_street") == "y")
337  {
338  $info.= $delim.htmlspecialchars($user->getStreet());
339  }
340  if ($user->getPref("public_zip") == "y")
341  {
342  $info.= $delim.htmlspecialchars($user->getZipcode());
343  $delim = " ";
344  }
345  if ($user->getPref("public_city") == "y")
346  {
347  $info.= $delim.htmlspecialchars($user->getCity());
348  }
349  $delim = "<br \/>";
350  if ($user->getPref("public_country") == "y")
351  {
352  $info.= $delim.htmlspecialchars($user->getCountry());
353  }
354  $this->tpl->setVariable("USER_INFO",
355  $info);
356  $this->tpl->setVariable("IMG_USER",
357  $user->getPersonalPicturePath("xsmall"));
358  $this->tpl->parseCurrentBlock();
359  $cnt++;
360  }
361  }
362  }
363 
364  $this->tpl->setVariable("MAP_ID", $this->getMapId());
365  $lat = is_numeric($this->getLatitude())
366  ? $this->getLatitude()
367  : 0;
368  $long = is_numeric($this->getLongitude())
369  ? $this->getLongitude()
370  : 0;
371  $this->tpl->setVariable("WIDTH", $this->getWidth());
372  $this->tpl->setVariable("HEIGHT", $this->getHeight());
373  $this->tpl->setVariable("LAT", $this->getLatitude());
374  $this->tpl->setVariable("LONG", $this->getLongitude());
375  $this->tpl->setVariable("ZOOM", (int) $this->getZoom());
376  $type_control = $this->getEnableTypeControl()
377  ? "true"
378  : "false";
379  $this->tpl->setVariable("TYPE_CONTROL", $type_control);
380  $nav_control = $this->getEnableNavigationControl()
381  ? "true"
382  : "false";
383  $this->tpl->setVariable("NAV_CONTROL", $nav_control);
384  $update_listener = $this->getEnableUpdateListener()
385  ? "true"
386  : "false";
387  $this->tpl->setVariable("UPDATE_LISTENER", $update_listener);
388  $large_map_control = $this->getEnableLargeMapControl()
389  ? "true"
390  : "false";
391  $this->tpl->setVariable("LARGE_CONTROL", $large_map_control);
392  $central_marker = $this->getEnableCentralMarker()
393  ? "true"
394  : "false";
395  $this->tpl->setVariable("CENTRAL_MARKER", $central_marker);
396 
397  return $this->tpl->get();
398  }
399  else
400  {
401  return "";
402  }
403  }
404 
408  function getUserListHtml()
409  {
410  global $tpl;
411 
412  $list_tpl = new ilTemplate("tpl.google_map_user_list.html",
413  true, true, "Services/GoogleMaps");
414 
415  $cnt = 0;
416  foreach($this->user_marker as $user_id)
417  {
418  if (ilObject::_exists($user_id))
419  {
420  $user = new ilObjUser($user_id);
421  $this->css_row = ($this->css_row != "tblrow1_mo")
422  ? "tblrow1_mo"
423  : "tblrow2_mo";
424  if ($user->getLatitude() != 0 && $user->getLongitude() != 0
425  && $user->getPref("public_location") == "y")
426  {
427  $list_tpl->setCurrentBlock("item");
428  $list_tpl->setVariable("MARKER_CNT", $cnt);
429  $list_tpl->setVariable("MAP_ID", $this->getMapId());
430  $cnt++;
431  }
432  else
433  {
434  $list_tpl->setCurrentBlock("item_no_link");
435  }
436  $list_tpl->setVariable("CSS_ROW", $this->css_row);
437  $list_tpl->setVariable("TXT_USER", $user->getLogin());
438  $list_tpl->setVariable("IMG_USER",
439  $user->getPersonalPicturePath("xxsmall"));
440  $list_tpl->parseCurrentBlock();
441  $list_tpl->touchBlock("row");
442  }
443  }
444 
445  return $list_tpl->get();
446  }
447 
448 }
449 ?>