<?php
/*======================================================================================
Module: Articles
======================================================================================*/

// Check authorisation
$errors = array();
if (!isset($gCms)) exit;
if ( !$this->CheckPermission('Articles: show orders') ) {
	$errors[] = $this->Lang('needpermission', array($this->Lang('vieworders')));
} else {

	// Get POST data
	$tabto = preg_replace('/[^0-9a-zA-Z_]/','',$params['tabto']);
	$order = (int)$params['order'];
	$all = isset($params['all']) ? true : false;

	// Delete the order
	if ($order) {
		// check order for existence
		$query = 'SELECT 0 FROM '.cms_db_prefix().'module_articles_orders WHERE entry_id=?';
		$result = $db->Execute($query, array($order));
		if(!$result->FetchRow()) $errors[] = $this->Lang('nosuchid', array($order));
		// delete order
		if (!$errors) {
			// delete from order table
			$sql = 'DELETE FROM '.cms_db_prefix().'module_articles_orders WHERE entry_id=?';
			$res = $db->Execute($sql,array($order));
			if(!$res) $errors[] = 'SQL ERROR: ' . $db->ErrorMsg() . '(with ' . $db->sql . ')';
		}
	}
	// Delete all orders
	if ($all) {
		// delete orders
		$sql = 'DELETE FROM '.cms_db_prefix().'module_articles_orders';
		$res = $db->Execute($sql,array());
		if(!$res) $errors[] = 'SQL ERROR: ' . $db->ErrorMsg() . '(with ' . $db->sql . ')';
	}

	// Redirect
	if (!$errors) $this->Redirect($id, 'defaultadmin', $returnid, array('tabto'=>$tabto, 'message' => $this->Lang('postdelete')));

}

// EOF