action.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /** DASHBOARDWIDGET / BLOC DE TABLEAU DE BORD **/
  3. Action::register('dashboard_widget_search',function(&$response){
  4. global $_;
  5. User::check_access('dashboard','read');
  6. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  7. require_once(__DIR__.SLASH.'Dashboard.class.php');
  8. $filters = array();
  9. if(empty($_['scope'])) throw new Exception('Portée non spécifiée');
  10. $filters['scope'] = $_['scope'];
  11. if(empty($_['uid'])) $filters['uid'] = $_['uid'];
  12. $dashboard = Dashboard::load($filters);
  13. $widgets = DashboardWidget::loadAll(array('dashboard'=>$dashboard->id));
  14. $response['widgets'] = array();
  15. foreach($widgets as $widget){
  16. $row = $widget->toArray();
  17. $model = DashboardWidget::model($widget->model);
  18. $row = array_merge($model,$row);
  19. $response['widgets'][] = $row ;
  20. }
  21. });
  22. Action::register('dashboard_widget_add',function(&$response){
  23. global $_,$myUser;
  24. User::check_access('dashboard','edit');
  25. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  26. require_once(__DIR__.SLASH.'Dashboard.class.php');
  27. $filters = array();
  28. if(empty($_['scope'])) throw new Exception('Portée non sépcifiée');
  29. $filters = array('scope'=>$_['scope']);
  30. if(!empty($_['uid'])) $filters['uid'] = $_['uid'];
  31. $dashboard = Dashboard::load($filters);
  32. if(!$dashboard) throw new Exception("Tableau de bord introuvable");
  33. $widget = new DashboardWidget();
  34. $widget->dashboard = $dashboard->id;
  35. if(isset($_['row'])) $widget->row = $_['row'];
  36. if(isset($_['column'])) $widget->column = $_['column'];
  37. $widget->save();
  38. $row = $widget->toArray();
  39. $model = DashboardWidget::model($widget->model);
  40. $row = array_merge($model,$row);
  41. $response = $row;
  42. });
  43. Action::register('dashboard_widget_move',function(&$response){
  44. global $_;
  45. User::check_access('dashboard','edit');
  46. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  47. require_once(__DIR__.SLASH.'Dashboard.class.php');
  48. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  49. if(!isset($_['widget']['column'])) throw new Exception('Colonne non spécifiée');
  50. if(!isset($_['widget']['row'])) throw new Exception('Ligne non spécifiée');
  51. $widget = DashboardWidget::getById($_['widget']['id'],1);
  52. if(!$widget) throw new Exception('Widget introuvable');
  53. $widget->column = $_['widget']['column'];
  54. $widget->row = $_['widget']['row'];
  55. $widget->save();
  56. });
  57. Action::register('dashboard_widget_resize',function(&$response){
  58. global $_;
  59. User::check_access('dashboard','edit');
  60. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  61. require_once(__DIR__.SLASH.'Dashboard.class.php');
  62. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  63. if(!isset($_['widget']['width'])) throw new Exception('Largeur non spécifiée');
  64. if(!isset($_['widget']['height'])) throw new Exception('Hauteur non spécifiée');
  65. $widget = DashboardWidget::getById($_['widget']['id'],1);
  66. if(!$widget) throw new Exception('Widget introuvable');
  67. $widget->width = $_['widget']['width'];
  68. $widget->height = $_['widget']['height'];
  69. $widget->save();
  70. });
  71. Action::register('dashboard_widget_delete',function(&$response){
  72. global $_;
  73. User::check_access('dashboard','delete');
  74. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  75. require_once(__DIR__.SLASH.'Dashboard.class.php');
  76. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  77. $widget = DashboardWidget::getById($_['widget']['id'],1);
  78. if(!$widget) throw new Exception('Widget introuvable');
  79. DashboardWidget::deleteById($widget->id);
  80. });
  81. Action::register('dashboard_widget_configure',function(&$response){
  82. global $_;
  83. User::check_access('dashboard','edit');
  84. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  85. require_once(__DIR__.SLASH.'Dashboard.class.php');
  86. if(empty($_['id'])) throw new Exception('Aucun identifiant renseigné');
  87. $widget = DashboardWidget::getById($_['id'],1);
  88. if(!$widget) throw new Exception('Widget introuvable');
  89. $response['widget'] = $widget->toArray();
  90. });
  91. ?>