<?php




//Cette fonction va generer une page quand on clique sur dashboard dans menu
function dashboard_page(){
	global $_,$myUser,$conf;
	if(isset($_['module'])) return;
	$page = !isset($_['page']) ? 'home' : $_['page'];
	$file = __DIR__.SLASH.'page.'.$page.'.php';
	if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
	require_once($file);
}

//Fonction executée lors de l'activation du plugin
function dashboard_install($id){
	if($id != 'fr.idleman.dashboard') return;
	global $conf;
	Entity::install(__DIR__);
	$conf->put('dashboard_enable_sidebar',1);
}

//Fonction executée lors de la désactivation du plugin
function dashboard_uninstall($id){
	if($id != 'fr.idleman.dashboard') return;
	Entity::uninstall(__DIR__);
}

//Déclaration des sections de droits du plugin
function dashboard_section(&$sections){
	$sections['dashboard'] = "Gestion des droits sur le plugin dashboard";
}

//cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
function dashboard_action(){
	require_once(__DIR__.SLASH.'action.php');
}

//Déclaration du menu de réglages
function dashboard_menu_setting(&$settingMenu){
	global $_, $myUser;
	
	if(!$myUser->can('dashboard','configure')) return;
		
		$settingMenu[]= array(
			'sort' =>1,
			'url' => 'setting.php?section=dashboard',
			'icon' => 'fas fa-angle-right',
			'label' => 'Dashboard'
		);

	

	
}

//Déclaration des pages de réglages
function dashboard_content_setting(){
	global $_;
	if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
		require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
}


//Déclaration des settings de base
//Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
// Configuration::setting('dashboard',array(
//     "Général",
// ));

function dashboard_default_widget(&$widgets){
	global $myUser;
	require_once('DashboardWidget.class.php');
	$modelWidget = new DashboardWidget();
	$modelWidget->model = 'clock';
	$modelWidget->title = 'Horloge';
	$modelWidget->icon = 'far fa-clock';
	$modelWidget->background = '#212529';
	$modelWidget->load = 'action.php?action=dashboard_widget_clock_load';
	$modelWidget->js = [Plugin::url().'/js/progressbar.js',Plugin::url().'/js/widget.js?v=2'];
	$modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
	$modelWidget->description = "Affiche l'heure en temps réel";
	$widgets[] = $modelWidget;


	$modelWidget = new DashboardWidget();
	$modelWidget->model = 'profile';
	$modelWidget->title = 'Profile';
	$modelWidget->icon = 'far fa-user';
	$modelWidget->background = '#007bff';
	$modelWidget->load = 'action.php?action=dashboard_widget_profile_load';
	$modelWidget->js = [Plugin::url().'/js/widget.js'];
	$modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
	$modelWidget->description = "Affiche les informations de profil";
	$widgets[] = $modelWidget;


	$modelWidget = new DashboardWidget();
	$modelWidget->model = 'log';
	$modelWidget->title = 'Logs';
	$modelWidget->width = 8;
	$modelWidget->options[] = array('function'=>'window.location = \'setting.php?section=log\';','icon'=>'fa-eye','label'=>'Voir tous les logs');
	$modelWidget->icon = 'far fa-comment-dots';
	$modelWidget->background = '#28a745';
	$modelWidget->load = 'action.php?action=dashboard_widget_log_load';
	$modelWidget->js = [Plugin::url().'/js/widget.js'];
	$modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
	$modelWidget->description = "Affiche les informations des 30 derniers logs";
	if($myUser->can('log','read')) 
		$widgets[] = $modelWidget;
}


//Déclation des assets
Plugin::addCss("/css/main.css?v=1"); 
Plugin::addJs("/js/main.js?v=1"); 

//Mapping hook / fonctions
Plugin::addHook("install", "dashboard_install");
Plugin::addHook("uninstall", "dashboard_uninstall"); 
Plugin::addHook("section", "dashboard_section");
Plugin::addHook("page", "dashboard_page");  
Plugin::addHook("action", "dashboard_action");  
Plugin::addHook("menu_setting", "dashboard_menu_setting");    
Plugin::addHook("content_setting", "dashboard_content_setting");   
Plugin::addHook("widget", "dashboard_default_widget");

?>