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.

99 lines
3.1 KiB

  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file NodeAffiliations.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief A widget for retrieving your group's members
  9. *
  10. * @author Ho Christine <nodpounod@gmail.com>
  11. *
  12. * @version 1.0
  13. * @date 17 April 2013
  14. *
  15. * Copyright (C)2010 MOVIM project
  16. *
  17. * See COPYING for licensing information.
  18. */
  19. use Moxl\Xec\Action\Pubsub\GetSubscriptions;
  20. use Moxl\Xec\Action\Pubsub\SetSubscriptions;
  21. class NodeSubscriptions extends WidgetBase
  22. {
  23. function load() {
  24. $this->registerEvent('pubsubsubscriptions', 'onSubscriptionsList');
  25. $this->registerEvent('pubsubsubscriptionsssubmited', 'onSubmit');
  26. }
  27. function display() {
  28. $this->view->assign('pepfilter', !filter_var($_GET['s'], FILTER_VALIDATE_EMAIL));
  29. $this->view->assign('getsubscriptions',
  30. $this->genCallAjax('ajaxGetSubscriptions',
  31. "'".$_GET['s']."'",
  32. "'".$_GET['n']."'"));
  33. }
  34. function prepareList($list) { //0:data 1:server 2:node
  35. $subscription = array("none", "pending", "unconfigured", "subscribed");
  36. $html = '<form id="subscriptionsManaging">';
  37. foreach($list['subscriptions'] as $item){ //0:jid 1:affiliation 2:subid
  38. $html .= '
  39. <div class="element">
  40. <label for="'.$item['jid'].'_'.$item['subid'].'">
  41. <a href="'.Route::urlize('friend', $item['jid']).'">'.$item['jid'].'</a>
  42. </label>
  43. <div class="select">
  44. <select name="'.$item['jid'].'_'.$item['subid'].'">';
  45. foreach($subscription as $status){
  46. $status == $item['subscription'] ? $selected = "selected" : $selected = "";
  47. $html .= '<option '.$selected.'>'.t($status).'</option>';
  48. }
  49. $html .= ' </select>
  50. </div>
  51. </div>';
  52. }
  53. $ok = $this->genCallAjax('ajaxChangeSubscriptions', "'".$list['to']."'", "'".$list['node']."'", "movim_parse_form('subscriptionsManaging')");
  54. $html .= '
  55. <hr />
  56. <br />
  57. <a
  58. class="button color green oppose"
  59. onclick="'.$ok.'">
  60. <i class="fa fa-check"></i> '.__('button.validate').'
  61. </a></form><div class="clear"></div>';
  62. return $html;
  63. }
  64. function onSubmit($stanza) {
  65. Notification::appendNotification($this->__('subscriptions.saved'), 'success');
  66. RPC::commit();
  67. }
  68. function onSubscriptionsList($list) {
  69. $html = $this->prepareList($list);
  70. RPC::call('movim_fill', 'subscriptionslist', $html);
  71. RPC::commit();
  72. }
  73. function ajaxChangeSubscriptions($server, $node, $data){
  74. $r = new SetSubscriptions;
  75. $r->setNode($node)
  76. ->setTo($server)
  77. ->setData($data)
  78. ->request();
  79. }
  80. function ajaxGetSubscriptions($server, $node){
  81. $r = new GetSubscriptions;
  82. $r->setTo($server)
  83. ->setNode($node)
  84. ->request();
  85. }
  86. }
  87. ?>