<?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/>.
 --------------------------------------------------------------------------
 */

define('GLPI_ROOT', '../../..');
include (GLPI_ROOT."/inc/includes.php");

if (!isset($_GET["id"])) $_GET["id"] = "";

Html::header($LANG['plugin_eventlog']['title'][0],'',"plugins","eventlog");

$server = new PluginEventlogEventlogServer();
$log = new PluginEventlogDefaultLog();
$type = new PluginEventlogDefaultType();

if (isset ($_POST["delete"])) {
	$server->delete($_POST);
	$server->redirectToList();;
}
//Update server
else if (isset ($_POST["update"])) {
	$server->update($_POST);
	Html::back();
}
//Add new server
else if (isset ($_POST["add"])) {
  $eventlogservers_id = $server->getEvenlogDBByEntity();
  
  if ($eventlogservers_id==-1) {
      $newid = $server->add($_POST);
   } else {
      Session::addMessageAfterRedirect($LANG['plugin_eventlog']['setup'][6],false,ERROR);
   }
	Html::back();

} else if (isset($_POST["add_type"])) {

	$type->addDefaultType($_POST['types_id']);
	Html::back();

} else if (isset($_POST["delete_type"])) {

	foreach ($_POST["item"] as $key => $val) {
		if ($val==1) {
			$type->delete(array('id'=>$key));
		}
	}

	Html::back();

} else if (isset($_POST["add_log"])) {

	$log->addDefaultLog($_POST['logs_name']);
	Html::back();

} else if (isset($_POST["delete_log"])) {

	foreach ($_POST["item"] as $key => $val) {
		if ($val==1) {
			$log->delete(array('id'=>$key));
		}
	}

	Html::back();

} else {
  
  $server->showForm($_GET["id"]);
  
}

Html::footer();

?>