HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/spire.komma-mediadesign.nl/wwwroot/kms/app/controllers/c_trashcan.php
<?php

/* 
	c_trashcan.php // Controller
	
	Guides user to the right page within the trashcan section
	
*/


/** 
*
* Check if the "sub" GET variable is set
*/
if(defined('URL_SUB')) $sub = URL_SUB;

/** 
*
* Gain acces to the global language variable
*/
global $template;
$lang = $template->lang;

/** 
*
* Include the Trashcan class
*/
$Trashcan = new Trashcan();


/***********************************************************************************/

/*
	 Check if any actions are needed
*/

/**
*
* When the user hits the button for permantly delete or the button to recover items, we catch the array of selected items.
* Check if this selected array has content, else the users hasn't selected an item, so display an error message.
* Get info from the items with the Trashcan::get method. Store these in a session and guide the user to the right page.
*/
if(isset($_POST['prepare_perm_delete']) || isset($_POST['prepare_recover']))
{	
	if(isset($_POST['selected']))
	{
		if($items = $Trashcan->get($_POST['selected']))
		{
			$_SESSION['trash_items'] = $items;
			if(isset($_POST['prepare_perm_delete'])) $this->redirect(LANG_ROOT.'prullenbak/definitief-verwijderen/');
			if(isset($_POST['prepare_recover'])) $this->redirect(LANG_ROOT.'prullenbak/herstellen/');
		}
	}
	else
	{
		$this->setAlert($lang['no_items_selected'],'error');
		$this->redirect(LANG_ROOT.'prullenbak/');
	}
}

/**
*
* When a user confirms that he wants to delete his selected items, grap the comma-separated-string from the hidden "ids" input field.
* Create an array by exploding the string. Delete the ids with the Trashcan::delete method.
* Redirect back to the trashcan.
*/
else if(isset($_POST['sbm_delete_items']))
{
	$ids = explode(',',$_POST['ids']);
	$Trashcan->delete($ids);
	$this->redirect(LANG_ROOT.'prullenbak/');
}

/**
*
* When a user confirms that he wants to recover his selected items, grap the comma-separated-string from the hidden "ids" input field.
* Create an array by exploding the string. Recover the ids with the Trashcan::recover method.
* Redirect back to the trashcan.
*/
else if(isset($_POST['sbm_recover_items']))
{
	$ids = explode(',',$_POST['ids']);
	$Trashcan->recover($ids);
	$this->redirect(LANG_ROOT.'prullenbak/');
}

/**
*	
*	Check if there are any actions needed when a subpage is found
*/
else if(isset($sub))
{
	switch($sub)
	{	
		case 'definitief-verwijderen':
		case 'herstellen':
			if(isset($_SESSION['trash_items'])) 
			{
				list($output, $ids) = $Trashcan->createList($_SESSION['trash_items'],FALSE);
				$this->setData('list_ids',$ids,TRUE);
				$this->setData('item_list',$output,TRUE);
				
				unset($_SESSION['trash_items']);
			}
		break;
		
	}
}

/**
*	
*	Code below is used for the dashboard of the trashcan page
*	A string of list items is created and stored in the Template::data property.
*/
else {
	$items = $Trashcan->get();
	list($output, $ids) = $Trashcan->createList($items);

	$this->setData('list_ids',$ids,TRUE);
	$this->setData('item_list',$output,TRUE);
}


/***********************************************************************************/

/*
	 Guide user to page
*/

/**
*	
*	If a subpage is found, switch this and guide the user to the right page
*	When no page found, header a 404-error and display a nice message to the user.
*/
if(isset($sub))
{
	switch($sub)
	{	
		case 'definitief-verwijderen':
			$this->load('app/views/trashcan/v_kms_trashcan_perm_delete.php', $this->lang['trashcan'].' - '.SITE_NAME);
		break;
		case 'herstellen':
			$this->load('app/views/trashcan/v_kms_trashcan_recover.php', $this->lang['trashcan'].' - '.SITE_NAME);
		break;
		default:
			// 404
			$this->notFound();
	}
}
else {
	$this->load('app/views/trashcan/v_kms_trashcan_dashb.php', $this->lang['trashcan'].' - '.SITE_NAME);
}