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.

98 lines
2.8 KiB

  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file ContactManage.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief A little widget which manage the current contact
  9. *
  10. * @author Jaussoin Timothée <edhelas@gmail.com>
  11. *
  12. * @version 1.0
  13. * @date 24 March 2013
  14. *
  15. * Copyright (C)2013 MOVIM project
  16. *
  17. * See COPYING for licensing information.
  18. */
  19. class ContactManage extends WidgetCommon
  20. {
  21. function load() {
  22. $this->registerEvent('rosterupdateditem', 'onRoster');
  23. }
  24. public function onRoster($jid)
  25. {
  26. $html = $this->prepareContactManage($jid);
  27. Notification::appendNotification(t('Contact updated'));
  28. RPC::call('movim_fill', 'contactmanage', $html);
  29. }
  30. public function ajaxContactManage($form) {
  31. $rd = new \moxl\RosterUpdateItem();
  32. $rd->setTo(echapJid($form['jid']))
  33. ->setFrom($this->user->getLogin())
  34. ->setName(htmlspecialchars($form['alias']))
  35. ->setGroup(htmlspecialchars($form['group']))
  36. ->request();
  37. }
  38. private function prepareContactManage($jid) {
  39. $rd = new \modl\RosterLinkDAO();
  40. $groups = $rd->getGroups();
  41. $rl = $rd->get($jid);
  42. $html = '';
  43. if(isset($rl)) {
  44. $submit = $this->genCallAjax('ajaxContactManage', "movim_parse_form('manage')");
  45. $html .= '<h2>'.t('Manage').'</h2>';
  46. $html .= '
  47. <form name="manage">';
  48. $ghtml = '';
  49. foreach($groups as $g)
  50. $ghtml .= '<option value="'.$g.'"/>';
  51. $html .= '
  52. <input type="hidden" name="jid" value="'.$jid.'"/>
  53. <div class="element large mini">
  54. <input name="alias" id="alias" class="tiny" placeholder="'.t('Alias').'" value="'.$rl->rostername.'"/>
  55. </div>
  56. <div class="element large mini">
  57. <datalist id="group" style="display: none;">
  58. '.$ghtml.'
  59. </datalist>
  60. <input name="group" list="group" id="alias" class="tiny" placeholder="'.t('Group').'" value="'.$rl->groupname.'"/>
  61. </div>
  62. <a name="submit" class="button black icon yes" onclick="'.$submit.' this.style.display = \'none\';">'.t('Save').'</a>';
  63. $html .= '
  64. </form>';
  65. }
  66. return $html;
  67. }
  68. function build() {
  69. ?>
  70. <div class="clear"></div>
  71. <div id="contactmanage">
  72. <?php
  73. if($_GET['f'] != $this->user->getLogin())
  74. echo $this->prepareContactManage($_GET['f']);
  75. ?>
  76. </div>
  77. <?php
  78. }
  79. }