<?php
/**************************************************************************************************
|
| iDocScript - Document Sharing Script
| http://www.idocscript.com
| webmaster@idocscript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.idocscript.com/eula.html and to be bound by it.
|
| Copyright (c) 2011 iDocScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

$DID = cleanit($_REQUEST['DID']);
STemplate::assign('DID',$DID);

if ($_SESSION['USERID'] != "" && $_SESSION['USERID'] >= 0 && is_numeric($_SESSION['USERID']))
{
	if ($DID != "" && $DID >= 0 && is_numeric($DID))
	{
		$DID = intval($DID);
		
		if($_REQUEST['editdoc']!="")
		{			
			$title = cleanit($_REQUEST['title']);
			$description = cleanit($_REQUEST['desc']);
			$tags = cleanit($_REQUEST['tags']);
			$category = intval(cleanit($_REQUEST['category']));
			$public = intval(cleanit($_REQUEST['public']));
			$allowcomments = intval(cleanit($_REQUEST['allowcomments']));
			$allowratings = intval(cleanit($_REQUEST['allowratings']));
			$allowembeds = intval(cleanit($_REQUEST['allowembeds']));
			
			$approve_docs = $config['approve_docs'];
			if($approve_docs == 1) 
			{
				$active = "active='0'";
			} 
			else 
			{
				$active = "active='1'";
			}
			
			if ($error == "")
			{
				
				$query="UPDATE docs SET title='".mysql_real_escape_string($title)."', description='".mysql_real_escape_string($description)."', tags='".mysql_real_escape_string($tags)."', categories='".mysql_real_escape_string($category)."', public='".mysql_real_escape_string($public)."', allowcomments='".mysql_real_escape_string($allowcomments)."', allowratings='".mysql_real_escape_string($allowratings)."', allowembeds='".mysql_real_escape_string($allowembeds)."',  $active WHERE DID='".mysql_real_escape_string($DID)."'";
				$conn->execute($query);
				$message = $lang['648'];

			}
		}
		$query = "SELECT * FROM docs WHERE DID='".mysql_real_escape_string($DID)."'";
    	$executequery = $conn->execute($query);
    	$docarray = $executequery->getarray();
		STemplate::assign('docarray',$docarray);
		$templateselect = "mydocsedit.tpl";
	}
}
else
{
	$redirect = base64_encode($thebaseurl."/mydocsedit.php?DID=".$DID);
	header("Location:$config[baseurl]/login.php?redirect=$redirect");exit;
}

STemplate::assign('pagetitle',$lang['318']);

//TEMPLATES BEGIN
STemplate::assign('error',$error);
STemplate::assign('message',$message);
STemplate::display('header.tpl');
STemplate::display($templateselect);
STemplate::display('footer.tpl');
//TEMPLATES END
?>