<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'smartyvariables.php');

// sidebar
$main_smarty = do_sidebar($main_smarty);

// pagename
define('pagename', 'edit_content'); 
$main_smarty->assign('pagename', pagename);

function str_startswith($source, $prefix)
{
   return strncmp($source, $prefix, strlen($prefix)) == 0;
}
if(str_startswith($_REQUEST['id'], "ttl")){
	$ttl = 1;
}
if(str_startswith($_REQUEST['id'], "cont")){
	$cont = 1;
}
if(str_startswith($_REQUEST['id'], "cat")){
	$cat = 1;
}
if(str_startswith($_REQUEST['id'], "tag")){
	$tag = 1;
}

if($_REQUEST['content']){
	$link_id = $_REQUEST['link_id'];
	$content = $_REQUEST['content'];

	if($cont==1){
		$sql_1 = (" UPDATE ".table_links." SET `link_modified` = NOW( ) ,`link_content` = '".$content."', `link_summary` = '".$content."' WHERE `link_id` ='".$link_id."' LIMIT 1 ");
		$result_1 = mysql_query($sql_1);
		if($result_1 == 1){
			echo htmlspecialchars($content);
			return true;
		}
		else 
			return false;
	}
	else if($ttl==1){
		$sql = (" UPDATE ".table_links." SET `link_modified` = NOW( ) , `link_title` = '".$content."' WHERE `link_id` ='".$link_id."' LIMIT 1 ");
		//echo $sql;
		$result = mysql_query($sql);
		if($result == 1){
			echo htmlspecialchars($content);
			return true;
		}
			else 
				return false;
	}
	
	else if($cat==1){
		global $db;
		$sql_2 = (" UPDATE ".table_links." SET `link_modified` = NOW( ) , `link_category` = '".$content."' WHERE `link_id` ='".$link_id."' LIMIT 1 ");
		//echo $sql;
		$result_2 = mysql_query($sql_2);
		if($result_2 == 1){
			$cats = $db->get_var(" Select category_name from " . table_categories . " where `category_id` = '".$content."' LIMIT 1 ");
			echo htmlspecialchars($cats);
			return true;
		}
			else 
				return false;
		}
	
	else if($tag==1){
		$sql_3 = (" UPDATE ".table_links." SET `link_modified` = NOW( ) , `link_tags` = '".$content."' WHERE `link_id` ='".$link_id."' LIMIT 1 ");
		//echo $sql;
		$result_3 = mysql_query($sql_3);
		if($result_3 == 1){
			echo htmlspecialchars($content);
			return true;
		}
			else 
				return false;
		}
	echo "No update done";
	return false;
}

// show the template
/*	$main_smarty->assign('tpl_center', $the_template . '/edit_content');
	$main_smarty->display($the_template . '/pligg.tpl');*/
?>