action.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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($_['uid'])) throw new Exception('Scope non spécifié');
  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. if(empty($_['scope'])) throw new Exception('Scope non sépcifié');
  28. $filters = array('scope'=>$_['scope']);
  29. if(!empty($_['uid'])) $filters['uid'] = $_['uid'];
  30. $dashboard = Dashboard::load($filters);
  31. if(!$dashboard) throw new Exception("Dashboard introuvable");
  32. $widget = new DashboardWidget();
  33. $widget->dashboard = $dashboard->id;
  34. if(isset($_['row'])) $widget->row = $_['row'];
  35. if(isset($_['column'])) $widget->column = $_['column'];
  36. $widget->save();
  37. $row = $widget->toArray();
  38. $model = DashboardWidget::model($widget->model);
  39. $row = array_merge($model,$row);
  40. $response = $row;
  41. });
  42. Action::register('dashboard_widget_move',function(&$response){
  43. global $_;
  44. User::check_access('dashboard','edit');
  45. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  46. require_once(__DIR__.SLASH.'Dashboard.class.php');
  47. if(empty($_['widget']['id'])) throw new Exception('Id non spécifié');
  48. if(!isset($_['widget']['column'])) throw new Exception('Colonne non spécifié');
  49. if(!isset($_['widget']['row'])) throw new Exception('Ligne non spécifié');
  50. $widget = DashboardWidget::getById($_['widget']['id'],1);
  51. if(!$widget) throw new Exception('Widget introuvable');
  52. $widget->column = $_['widget']['column'];
  53. $widget->row = $_['widget']['row'];
  54. $widget->save();
  55. });
  56. Action::register('dashboard_widget_resize',function(&$response){
  57. global $_;
  58. User::check_access('dashboard','edit');
  59. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  60. require_once(__DIR__.SLASH.'Dashboard.class.php');
  61. if(empty($_['widget']['id'])) throw new Exception('Id non spécifié');
  62. if(!isset($_['widget']['width'])) throw new Exception('Largeur non spécifiée');
  63. if(!isset($_['widget']['height'])) throw new Exception('Hauteur non spécifiée');
  64. $widget = DashboardWidget::getById($_['widget']['id'],1);
  65. if(!$widget) throw new Exception('Widget introuvable');
  66. $widget->width = $_['widget']['width'];
  67. $widget->height = $_['widget']['height'];
  68. $widget->save();
  69. });
  70. Action::register('dashboard_widget_delete',function(&$response){
  71. global $_;
  72. User::check_access('dashboard','delete');
  73. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  74. require_once(__DIR__.SLASH.'Dashboard.class.php');
  75. if(empty($_['widget']['id'])) throw new Exception('Id non spécifié');
  76. $widget = DashboardWidget::getById($_['widget']['id'],1);
  77. if(!$widget) throw new Exception('Widget introuvable');
  78. DashboardWidget::deleteById($widget->id);
  79. });
  80. Action::register('dashboard_widget_configure',function(&$response){
  81. global $_;
  82. User::check_access('dashboard','edit');
  83. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  84. require_once(__DIR__.SLASH.'Dashboard.class.php');
  85. if(empty($_['id'])) throw new Exception('Id non spécifié');
  86. $widget = DashboardWidget::getById($_['id'],1);
  87. if(!$widget) throw new Exception('Widget introuvable');
  88. $response['widget'] = $widget->toArray();
  89. });
  90. ?>