You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.2 KiB

  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file Profile.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief The Profile widget
  9. *
  10. * @author Timothée Jaussoin <edhelas_at_gmail_dot_com>
  11. *
  12. * @version 1.0
  13. * @date 20 October 2010
  14. *
  15. * Copyright (C)2010 MOVIM project
  16. *
  17. * See COPYING for licensing information.
  18. */
  19. class ProfileData extends WidgetBase
  20. {
  21. function WidgetLoad()
  22. {
  23. $this->addjs('profiledata.js');
  24. $this->registerEvent('locationpublished', 'onLocationPublished');
  25. $this->registerEvent('locationpublisherror', 'onLocationPublishError');
  26. }
  27. function ajaxLocationPublish($pos)
  28. {
  29. $pos = json_decode($pos);
  30. if($pos->place_id) {
  31. $geo = array(
  32. 'latitude' => (string)$pos->lat,
  33. 'longitude' => (string)$pos->lon,
  34. 'altitude' => (string)$pos->alt,
  35. 'country' => (string)$pos->address->country,
  36. 'countrycode' => (string)$pos->address->country_code,
  37. 'region' => (string)$pos->address->county,
  38. 'postalcode' => (string)$pos->address->postcode,
  39. 'locality' => (string)$pos->address->city,
  40. 'street' => (string)$pos->address->path,
  41. 'building' => (string)$pos->address->building,
  42. 'text' => (string)$pos->display_name,
  43. 'uri' => ''//'http://www.openstreetmap.org/'.urlencode('?lat='.(string)$pos->lat.'&lon='.(string)$pos->lon.'&zoom=10')
  44. );
  45. $p = new moxl\LocationPublish();
  46. $p->setTo($this->user->getLogin())
  47. ->setGeo($geo)
  48. ->request();
  49. } else {
  50. $html = '
  51. <div class="message error">'.t('Wrong position').'</div>';
  52. RPC::call('movim_fill', 'maperror', RPC::cdata($html));
  53. RPC::commit();
  54. }
  55. }
  56. function onLocationPublished($me)
  57. {
  58. $html = $me->getPlace();
  59. RPC::call('movim_fill', 'mapdata', RPC::cdata($html));
  60. $html = '
  61. <div class="message success">'.t('Location updated').'</div><br />';
  62. RPC::call('movim_fill', 'maperror', RPC::cdata($html));
  63. RPC::call('movim_delete', 'mapdiv');
  64. RPC::commit();
  65. }
  66. function onLocationPublishError($error)
  67. {
  68. $html = '
  69. <div class="message error">'.$error.'</div>';
  70. RPC::call('movim_fill', 'maperror', RPC::cdata($html));
  71. RPC::call('movim_delete', 'mapdiv');
  72. RPC::call('movim_delete', 'mapdata');
  73. RPC::commit();
  74. }
  75. function prepareProfileData()
  76. {
  77. $submit = $this->genCallAjax('ajaxLocationPublish', "getMyPositionData()");
  78. $cd = new modl\ContactDAO();
  79. $c = $cd->get($this->user->getLogin());
  80. if($c->loctimestamp) {
  81. $data = prepareDate(strtotime($c->loctimestamp)).'<br /><br />';
  82. $data .= $c->getPlace();
  83. } else {
  84. $data = '';
  85. }
  86. $html = '';
  87. $html .= '
  88. <h2>'.t('Location').'</h2>
  89. <div id="location">
  90. <div id="maperror"></div>
  91. <div id="mapdata" style="margin-bottom: 10px;">'.$data.'</div>
  92. <div id="mapdiv" style="width: auto; height: 250px; display: none;"></div>
  93. <div class="clear"></div>
  94. <a
  95. class="button tiny icon add"
  96. onclick="getMyPosition(); this.style.display = \'none\';">'.
  97. t('Update my position').'
  98. </a>
  99. <a
  100. id="mypossubmit"
  101. style="display: none;"
  102. class="button tiny icon yes merged left"
  103. onclick="'.$submit.' hidePositionChoice();">'.t('Accept').'</a><a
  104. style="display: none; margin-top: 1em;"
  105. id="myposrefuse"
  106. onclick="hidePositionChoice();"
  107. class="button tiny icon no merged right">'.t('Cancel').'</a>
  108. </div>';
  109. return $html;
  110. }
  111. function build()
  112. {
  113. echo $this->prepareProfileData();
  114. }
  115. }