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.

118 lines
3.2 KiB

  1. <?php
  2. use Moxl\Xec\Action\AdHoc\Get;
  3. use Moxl\Xec\Action\AdHoc\Command;
  4. use Moxl\Xec\Action\AdHoc\Submit;
  5. class AdHoc extends WidgetBase
  6. {
  7. function load()
  8. {
  9. $this->addjs('adhoc.js');
  10. $this->registerEvent('adhoc_get_handle', 'onList');
  11. $this->registerEvent('adhoc_command_handle', 'onCommand');
  12. $this->registerEvent('adhoc_submit_handle', 'onCommand');
  13. }
  14. function onList($package)
  15. {
  16. $list = $package->content;
  17. $html = $this->prepareList($list);
  18. RPC::call('movim_fill', 'adhoc_widget', $html);
  19. RPC::call('AdHoc.refresh');
  20. }
  21. function onCommand($package)
  22. {
  23. $command = $package->content;
  24. $view = $this->tpl();
  25. if(isset($command->note)) {
  26. $view->assign('note', $command->note);
  27. Dialog::fill($view->draw('_adhoc_note', true));
  28. }
  29. if(isset($command->x)) {
  30. $xml = new \XMPPtoForm();
  31. $form = $xml->getHTML($command->x->asXML());
  32. $view->assign('form', $form);
  33. $view->assign('attributes', $command->attributes());
  34. $view->assign('actions', null);
  35. if(isset($command->actions)) {
  36. $view->assign('actions', $command->actions);
  37. }
  38. Dialog::fill($view->draw('_adhoc_form', true), true);
  39. }
  40. RPC::call('AdHoc.initForm');
  41. }
  42. function prepareList($list)
  43. {
  44. $view = $this->tpl();
  45. $view->assign('list', $list);
  46. return $view->draw('_adhoc_list', true);
  47. }
  48. function ajaxGet()
  49. {
  50. $session = \Sessionx::start();
  51. $g = new Get;
  52. $g->setTo($session->host)
  53. ->request();
  54. }
  55. function ajaxCommand($jid, $node)
  56. {
  57. $c = new Command;
  58. $c->setTo($jid)
  59. ->setNode($node)
  60. ->request();
  61. }
  62. function ajaxSubmit($data, $node, $sessionid)
  63. {
  64. $session = \Sessionx::start();
  65. $s = new Submit;
  66. $s->setTo($session->host)
  67. ->setNode($node)
  68. ->setData($data)
  69. ->setSessionid($sessionid)
  70. ->request();
  71. }
  72. function getIcon($command)
  73. {
  74. $icons = array(
  75. 'http://jabber.org/protocol/admin#delete-user' => 'md-delete',
  76. 'http://jabber.org/protocol/admin#end-user-session' => 'md-stop',
  77. 'http://jabber.org/protocol/admin#change-user-password' => 'md-lock',
  78. 'ping' => 'md-swap-horiz',
  79. 'http://jabber.org/protocol/admin#shutdown' => 'md-settings-power',
  80. 'http://jabber.org/protocol/admin#add-user' => 'md-person-add',
  81. 'http://jabber.org/protocol/admin#user-stats' => 'md-people',
  82. 'uptime' => 'md-access-time',
  83. 'http://jabber.org/protocol/admin#server-buddy' => 'md-stop',
  84. 'http://jabber.org/protocol/admin#get-user-roster' => 'md-format-list-bulleted',
  85. 'http://jabber.org/protocol/admin#get-online-users' => 'md-trending-up',
  86. 'http://jabber.org/protocol/admin#announce' => 'md-notifications',
  87. );
  88. if(array_key_exists($command, $icons)) {
  89. return $icons[$command];
  90. } else {
  91. return 'md-chevron-right';
  92. }
  93. }
  94. function display()
  95. {
  96. }
  97. }