<?php
/*
 * @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
 -------------------------------------------------------------------------
 Eventlog plugin for GLPI
 Copyright (C) 2003-2011 by the Eventlog Development Team.

 https://forge.indepnet.net/projects/eventlog
 -------------------------------------------------------------------------

 LICENSE
		
 This file is part of Eventlog.

 Eventlog is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Eventlog is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Eventlog. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 */

include_once (GLPI_ROOT . "/plugins/eventlog/inc/dbeventlog.class.php");

// Init the hooks of the plugins -Needed
function plugin_init_eventlog() {
	global $PLUGIN_HOOKS,$CFG_GLPI,$LANG;

	$PLUGIN_HOOKS['change_profile']['eventlog'] = array('PluginEventlogProfile','changeProfile');
   
   //Clean Plugin on Profile delete
   $PLUGIN_HOOKS['pre_item_purge']['eventlog'] = 
                              array('Profile'=>array('PluginEventlogProfile', 'purgeProfiles'));
   
	if (Session::getLoginUserID()) {
      
      Plugin::registerClass('PluginEventlogProfile',
                         array('addtabon' => 'Profile'));
                         
      if (plugin_eventlog_haveRight("eventlog","r")) {
         $PLUGIN_HOOKS['menu_entry']['eventlog'] = 'front/event.php';
         $PLUGIN_HOOKS['submenu_entry']['eventlog']['search'] = 'front/event.php';
         if (plugin_eventlog_haveRight("eventlog","w")) {
            $PLUGIN_HOOKS['submenu_entry']['eventlog']["<img  src='".$CFG_GLPI["root_doc"]."/pics/menu_addtemplate.png' title='".$LANG['plugin_eventlog']['config'][5]."' alt='".$LANG['plugin_eventlog']['config'][5]."'>"] = 'front/eventlogserver.form.php?new=1';
            $PLUGIN_HOOKS['submenu_entry']['eventlog']["<img  src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".$LANG['plugin_eventlog']['config'][0]."' alt='".$LANG['plugin_eventlog']['config'][0]."'>"] = 'front/eventlogserver.php';
            $PLUGIN_HOOKS['submenu_entry']['eventlog']['config'] = 'front/config.form.php';
         }
      }

      // Config page
      if (plugin_eventlog_haveRight("eventlog","w") || Session::haveRight("config","w")) {
         $PLUGIN_HOOKS['config_page']['eventlog'] = 'front/config.form.php';
		}

      // Add specific files to add to the header : javascript or css
      $PLUGIN_HOOKS['add_javascript']['eventlog']="eventlog.js";
      $PLUGIN_HOOKS['add_css']['eventlog']="eventlog.css";

	}
}

// Get the name and the version of the plugin - Needed
function plugin_version_eventlog() {
	global $LANG;

	return array (
		'name' => $LANG['plugin_eventlog']['title'][0],
		'version' => '1.5.0',
		'license' => 'GPLv2+',
		'author'=>'Xavier Caillaud',
		'homepage'=>'https://forge.indepnet.net/projects/show/eventlog',
		'minGlpiVersion' => '0.83',// For compatibility / no install in version < 0.83
	);

}

// Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_eventlog_check_prerequisites() {
	if (version_compare(GLPI_VERSION,'0.83','lt') || version_compare(GLPI_VERSION,'0.84','ge')) {
      echo "This plugin requires GLPI >= 0.83 and GLPI < 0.84";
      return false;
   }
   return true;
}

// Uninstall process for plugin : need to return true if succeeded : may display messages or add to message after redirect
function plugin_eventlog_check_config() {
	return true;
}

function plugin_eventlog_haveRight($module,$right) {
	$matches=array(
			""  => array("","r","w"), // ne doit pas arriver normalement
			"r" => array("r","w"),
			"w" => array("w"),
			"1" => array("1"),
			"0" => array("0","1"), // ne doit pas arriver non plus
		      );
	if (isset($_SESSION["glpi_plugin_eventlog_profile"][$module]) 
            && in_array($_SESSION["glpi_plugin_eventlog_profile"][$module],$matches[$right]))
		return true;
	else return false;
}

?>