action.php 3.9 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($_['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. $response['widgets'][] = $widget->toData();
  17. }
  18. });
  19. Action::register('dashboard_widget_add',function(&$response){
  20. global $_,$myUser;
  21. User::check_access('dashboard','edit');
  22. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  23. require_once(__DIR__.SLASH.'Dashboard.class.php');
  24. $filters = array();
  25. if(empty($_['scope'])) throw new Exception('Portée non sépcifiée');
  26. $filters = array('scope'=>$_['scope']);
  27. if(!empty($_['uid'])) $filters['uid'] = $_['uid'];
  28. $dashboard = Dashboard::load($filters);
  29. if(!$dashboard) throw new Exception("Tableau de bord introuvable");
  30. $widget = new DashboardWidget();
  31. $widget->dashboard = $dashboard->id;
  32. if(isset($_['row'])) $widget->row = $_['row'];
  33. if(isset($_['column'])) $widget->column = $_['column'];
  34. $widget->save();
  35. $response = $widget->toData();
  36. });
  37. Action::register('dashboard_widget_move',function(&$response){
  38. global $_;
  39. User::check_access('dashboard','edit');
  40. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  41. require_once(__DIR__.SLASH.'Dashboard.class.php');
  42. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  43. if(!isset($_['widget']['column'])) throw new Exception('Colonne non spécifiée');
  44. if(!isset($_['widget']['row'])) throw new Exception('Ligne non spécifiée');
  45. $widget = DashboardWidget::getById($_['widget']['id'],1);
  46. if(!$widget) throw new Exception('Widget introuvable');
  47. $widget->column = $_['widget']['column'];
  48. $widget->row = $_['widget']['row'];
  49. $widget->save();
  50. });
  51. Action::register('dashboard_widget_resize',function(&$response){
  52. global $_;
  53. User::check_access('dashboard','edit');
  54. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  55. require_once(__DIR__.SLASH.'Dashboard.class.php');
  56. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  57. if(!isset($_['widget']['width'])) throw new Exception('Largeur non spécifiée');
  58. if(!isset($_['widget']['height'])) throw new Exception('Hauteur non spécifiée');
  59. $widget = DashboardWidget::getById($_['widget']['id'],1);
  60. if(!$widget) throw new Exception('Widget introuvable');
  61. $widget->width = $_['widget']['width'];
  62. $widget->height = $_['widget']['height'];
  63. $widget->save();
  64. });
  65. Action::register('dashboard_widget_delete',function(&$response){
  66. global $_;
  67. User::check_access('dashboard','delete');
  68. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  69. require_once(__DIR__.SLASH.'Dashboard.class.php');
  70. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  71. $widget = DashboardWidget::getById($_['widget']['id'],1);
  72. if(!$widget) throw new Exception('Widget introuvable');
  73. DashboardWidget::deleteById($widget->id);
  74. });
  75. Action::register('dashboard_widget_configure',function(&$response){
  76. global $_;
  77. User::check_access('dashboard','edit');
  78. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  79. require_once(__DIR__.SLASH.'Dashboard.class.php');
  80. if(empty($_['id'])) throw new Exception('Aucun identifiant renseigné');
  81. $widget = DashboardWidget::getById($_['id'],1);
  82. if(!$widget) throw new Exception('Widget introuvable');
  83. switch($_['menu']){
  84. case 'type':
  85. $response['rows'] = DashboardWidget::model();
  86. unset($response['rows'][DashboardWidget::MODEL_NEW]);
  87. break;
  88. case 'properties':
  89. //@TODO
  90. break;
  91. case 'style':
  92. //@TODO
  93. break;
  94. }
  95. });