can('dashboard','read')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'Dashboard.class.php'); foreach(Dashboard::populate() as $dashboard){ $response['rows'][] = $dashboard; } }); break; //Ajout ou modification d'élément dashboard case 'dashboard_dashboard_save': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','edit')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'Dashboard.class.php'); $item = Dashboard::provide(); $item->user = $myUser->login; $item->label = $_['label']; $item->icon = $_['icon']; $item->default = $_['default']; $item->save(); }); break; //Récuperation ou edition d'élément dashboard case 'dashboard_dashboard_edit': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','edit')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'Dashboard.class.php'); $response = Dashboard::getById($_['id']); }); break; //Suppression d'élement dashboard case 'dashboard_dashboard_delete': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','delete')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'Dashboard.class.php'); Dashboard::deleteById($_['id']); }); break; //Sauvegarde des configurations de dashboard case 'dashboard_setting_save': Action::write(function(&$response){ global $myUser,$_,$conf; if(!$myUser->can('dashboard','configure')) throw new Exception("Permissions insuffisantes",403); foreach(Configuration::setting('dashboard') as $key=>$value){ if(!is_array($value)) continue; $allowed[] = $key; } foreach ($_['fields'] as $key => $value) { if(in_array($key, $allowed)) $conf->put($key,$value); } }); break; /** DASHBOARDWIDGET **/ //Récuperation d'une liste de dashboardwidget case 'dashboard_dashboardwidget_search': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','read')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'DashboardWidget.class.php'); $models = array(); Plugin::callHook('widget',array(&$models)); foreach($models as $model): $models[$model->model] = $model; endforeach; $widgets = DashboardWidget::loadAll(array('dashboard'=>$_['dashboard']),array('position')); foreach($widgets as $widget): if(!isset($models[$widget->model])) continue; $model = clone $models[$widget->model]; $model->id = $widget->id; $model->position = $widget->position; $model->minified = $widget->minified; $model->dashboard = $widget->dashboard; $response['rows'][] = $model; endforeach; }); break; //Ajout ou modification d'élément dashboardwidget case 'dashboard_dashboardwidget_save': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','edit')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'DashboardWidget.class.php'); $item = DashboardWidget::provide(); $item->model = $_['model']; $item->data = $_['data']; $item->position = $_['position']; $item->minified = $_['minified']; $item->dashboard = $_['dashboard']; $item->save(); }); break; //Récuperation ou edition d'élément dashboardwidget case 'dashboard_dashboardwidget_edit': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','edit')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'DashboardWidget.class.php'); $response = DashboardWidget::getById($_['id']); }); break; //Suppression d'élement dashboardwidget case 'dashboard_dashboardwidget_delete': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','delete')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'DashboardWidget.class.php'); require_once(__DIR__.SLASH.'Dashboard.class.php'); if(!$myUser->can('widget','delete')) throw new Exception("Permissions insuffisantes",403); $widget = DashboardWidget::getById($_['widget']); $dashboard = Dashboard::getById($_['dashboard']); if($widget->dashboard!=$dashboard->id || $dashboard->user!=$myUser->login) throw new Exception("Vous ne pouvez supprimer que vos propres widgets"); $widget->deleteById($widget->id); $response['message'] = 'Widget supprimé'; }); break; case 'dashboard_dashboardwidget_refresh': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','read')) throw new Exception("Permissions insuffisantes",403); $widgets = array(); Plugin::callHook('widget_refresh',array(&$widgets)); $response['rows'] = $widgets; }); break; //Sauvegarde des configurations de dashboard case 'dashboard_setting_save': Action::write(function(&$response){ global $myUser,$_,$conf; if(!$myUser->can('dashboard','configure')) throw new Exception("Permissions insuffisantes",403); foreach(Configuration::setting('dashboard') as $key=>$value){ if(!is_array($value)) continue; $allowed[] = $key; } foreach ($_['fields'] as $key => $value) { if(in_array($key, $allowed)) $conf->put($key,$value); } }); break; case 'dashboard_dashboardwidget_add': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','edit')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'DashboardWidget.class.php'); $widget = new DashboardWidget(); $widget->model = $_['widget']; $widget->position = 666; $widget->minified = false; $widget->dashboard = $_['dashboard']; $widget->save(); $response['message'] = 'Widget ajouté'; }); break; case 'dashboard_dashboardwidget_save_position': Action::write(function(&$response){ global $myUser,$_; if(!$myUser->can('dashboard','update')) throw new Exception("Permissions insuffisantes",403); require_once(__DIR__.SLASH.'Dashboard.class.php'); require_once(__DIR__.SLASH.'DashboardWidget.class.php'); $dashboard = Dashboard::getById($_['dashboard']); if( $dashboard->user!=$myUser->login) throw new Exception("Vous ne pouvez modifier que vos propres widgets"); $dashboard_widgets = DashboardWidget::loadAll( array('dashboard' => $dashboard->id ) ); foreach($_['positions'] as $move){ foreach($dashboard_widgets as $dashboard_widget){ if($dashboard_widget->id!=$move['id']) continue; $dashboard_widget->position = $move['position']; $dashboard_widget->save(); } } }); break; case 'dashboard_widget_clock_load': require_once('DashboardWidget.class.php'); $widget = DashboardWidget::current(); $widget->title = 'Horloge'; $widget->content = '
Date | Libellé | Utilisateur |
---|---|---|
'.date('d-m-y',$log->created).' '.date('H:i:s',$log->created).' | '.$log->label().' | '.$log->creator.' |