File: D:/HostingSpaces/SBogers64/klimroosbudel.nl/wwwroot/kms/app/controllers/c_trash.class.php
<?php
/**
* c_trash.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 3/19/13
*/
class Trash extends Controller
{
public function __construct()
{
parent::__construct();
}
/*
* Shows dashboard of the trashcan
*/
public function index()
{
// Get items from the database
$trashed = $this->Model->getItems(null, false);
$items = $this->Model->getItems(null);
foreach (array_keys($items) as $key) {
$items[$key]['trash_id'] = $trashed[$key]['id'];
}
$ItemList = new Item_List();
$ItemList->set('_editable', false);
$ItemList->set('_recover', true);
$ItemList->setItems($items);
$list = $ItemList->display();
// Set items list for the view
$this->View->setData('item_list', $list);
// Delete permanently
$content = ['type'=>'submit', 'name'=>'empty_trash', 'label'=>$this->View->lang['empty_trash']];
$BtnDelete = new Button($content);
$BtnDelete->addClasses(['blue']);
$btnDelete = $BtnDelete->display(false);
// Set buttons for the view
$this->View->setData('btn_delete', $btnDelete);
// Set Global parameters for the view
$this->View->setData('page_label', $this->View->lang['trash']);
$this->View->setData('page_name', $this->View->urls['trash']);
$this->View->setData('page_title', $this->View->lang['trash'].' | '.SITE_NAME);
// Render the view
$this->View->render('trash/v_dash');
}
/*
* Recovers an item from the trashcan
*/
public function recover()
{
// Set id back
if (defined('URL_SUB2')) {
// Recover item
$id = URL_SUB2;
$this->Model->recover($id);
// Show success message
$msg = 'Recover Success!';
$this->Alert->set($msg, 'success');
// Redirect to page of recovered item
// Get pageId
$result = $this->Model->getItems($id, false);
$result = $result[key($result)];
$pageId = $result['pageId'];
// Get pageName
$Dbh = new DatabaseHandler();
$Dbh->setTableName('kms_basic_pages');
$Dbh->addRule('id', $pageId);
$page = $Dbh->select();
$pageName = $page['name'];
// Get location en redirect
$location = LANG_ROOT.$this->View->urls[$pageName];
$this->Functions->redirect($location);
} else {
// Redirect to dashboard
$this->Functions->redirect(LANG_ROOT.$this->View->urls['trash']);
}
}
/*
* Ask if the user is sure he wants to empty the trashcan
*/
public function emptyTrash()
{
// Create buttons
$content = ['type'=>'link', 'href'=> LANG_ROOT.$this->View->urls['trash'].'/submitEmpty/', 'label'=>$this->View->lang['yes']];
$BtnYes = new Button($content);
$BtnYes->addClasses(['blue']);
$btnYes = $BtnYes->display(false);
$content = ['type'=>'link', 'href'=> LANG_ROOT.$this->View->urls['trash'].'/', 'label'=>$this->View->lang['no']];
$BtnNo = new Button($content);
$BtnNo->addClasses(['blue']);
$btnNo = $BtnNo->display(false);
// Set buttons for the view
$this->View->setData('btn_yes', $btnYes);
$this->View->setData('btn_no', $btnNo);
// Render
$this->View->render('trash/v_empty');
}
/*
* Empties the trashcan
*/
public function submitEmpty()
{
// Recover item
$this->Model->emptyTrash();
// Redirect to dashboard
$this->Functions->redirect(LANG_ROOT.$this->View->urls['trash']);
}
}