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

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

 LICENSE
		
 This file is part of certificates.

 Certificates 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.

 Certificates 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 Certificates. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 */

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

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

$certif=new PluginCertificatesCertificate();
$certif_item=new PluginCertificatesCertificate_Item();

if (isset($_POST["add"])) {
	$certif->check(-1,'w',$_POST);
   $newID=$certif->add($_POST);
	Html::back();
	
} else if (isset($_POST["delete"])) {

	$certif->check($_POST['id'],'w');
   $certif->delete($_POST);
	$certif->redirectToList();
	
} else if (isset($_POST["restore"])) {

	$certif->check($_POST['id'],'w');
   $certif->restore($_POST);
	$certif->redirectToList();
	
} else if (isset($_POST["purge"])) {

	$certif->check($_POST['id'],'w');
   $certif->delete($_POST,1);
	$certif->redirectToList();
	
} else if (isset($_POST["update"])) {

	$certif->check($_POST['id'],'w');
   $certif->update($_POST);
	Html::back();
	
} else if (isset($_POST["additem"])) {

	if (!empty($_POST['itemtype'])&&$_POST['items_id']>0) {
		$certif_item->check(-1,'w',$_POST);
      $certif_item->addItem($_POST);
	}
	Html::back();
	
} else if (isset($_POST["deleteitem"])) {

	foreach ($_POST["item"] as $key => $val) {
      $input = array('id' => $key);
      if ($val==1) {
         $certif_item->check($key,'w');
         $certif_item->delete($input);
      }
   }
	Html::back();
	
} else if (isset($_GET["deletecertificates"])) {

	$input = array('id' => $_GET["id"]);
   $certif_item->check($_GET["id"],'w');
	$certif_item->delete($input);
	Html::back();
	
} else {

	$certif->checkGlobal("r");

	$plugin = new Plugin();
	if ($plugin->isActivated("environment"))
		Html::header($LANG['plugin_certificates']['title'][1],'',"plugins","environment","certificates");
	else
		Html::header($LANG['plugin_certificates']['title'][1],'',"plugins","certificates");

	$certif->showForm($_GET["id"]);

	Html::footer();
}

?>