<?php 
	
	// We check in which language we will work
	if (isset($_SESSION["DATAGLOBAL"][0]) && !empty($_SESSION["DATAGLOBAL"][0])) $C->LANGUAGE = $_SESSION["DATAGLOBAL"][0];

	$this->load_langfile('inside/admin.php');

	// We are here only if you're logged in
	if (!$this->user->is_logged || !$this->user->info->is_network_admin) {
		echo('0: '.$this->lang('admin_no_session'));
		die();
	}

	$errored = 0;
	$txterror = '';
	
	$action=0;
	
	if (isset($_POST["todo"]) && $_POST["todo"] != '') $action = $this->db1->e($_POST["todo"]);
	if (!is_numeric($action)) {
		$errored = 1;
		$txterror .= 'Error... ';
		echo('0: '.$txterror);
		die();
	}

	// edit page
	if ($action == 1)	{

		$title = $description= $cpage = '';
		$idcat = $idsubcat = $status = $vefified = 0;
		
		if (isset($_POST["tp"]) && !empty($_POST["tp"])) $title = $this->db1->e(htmlspecialchars($_POST["tp"]));
		if (isset($_POST["dp"]) && !empty($_POST["dp"])) $description = $this->db1->e(htmlspecialchars($_POST["dp"]));
		if (isset($_POST["idc"]) && !empty($_POST["idc"])) $idcat = $this->db1->e($_POST["idc"]);
		if (isset($_POST["idsc"]) && !empty($_POST["idsc"])) $idsubcat = $this->db1->e($_POST["idsc"]);
		if (isset($_POST["cp"]) && !empty($_POST["cp"])) $cpage = $this->db1->e($_POST["cp"]);
		if (isset($_POST["stat"])) $status = $this->db1->e($_POST["stat"]);
		if (isset($_POST["pverif"])) $vefified = $this->db1->e($_POST["pverif"]);
		
		if (empty($cpage)) { $errored = 1; $txterror .= 'Error... '; }
		if (empty($title)) { $errored = 1; $txterror .= 'Error... '; }
		if (!is_numeric($idcat) || $idcat == 0) { $errored = 1; $txterror .= 'Error... '; }
		if (!is_numeric($idsubcat) || $idsubcat == 0) { $errored = 1; $txterror .= 'Error... '; }
		if (!is_numeric($status)) { $errored = 1; $txterror .= 'Error... '; }
		if (!is_numeric($vefified)) { $errored = 1; $txterror .= 'Error... '; }
				
	}

	
	if ($errored == 1) {
		echo('0: '.$txterror);
	} else {

		if ($action == 1) {
			$this->db1->query("UPDATE pages SET idcategory=".$idcat.", idsubcategory=".$idsubcat.", verified=".$vefified.", status=".$status.", title='".$title."', description='".$description."'  WHERE code='".$cpage."' LIMIT 1");
			$txtreturn = $this->lang('admin_pages_update_txt_msgok');
			echo('1: '.$txtreturn);
			return;
		}
			
	}
?>