Location: PHPKode > scripts > Linker IMG > linker-img/comment.php
<?php

//=====================================
// LINKER Category Engine
//=====================================
// Filename : comment.php
// Path  : Main directory
// last update : 2002/03/13
// Desc : Add User new comment
//=====================================

if (!$sid) errmsg($l_error_nolink);

//=====================================
// File include part
//=====================================

$time1 = microtime();
include ("./function/base_info.php");
include ("./function/main_func.php");
include ("./function/$Sdb_type.php");
include ("./function/template.php");

$lan_dir = $HTTP_COOKIE_VARS[cook_lan];
if ($lan_dir && file_exists("./$lan_dir/u_common.php")) 
include ("./$lan_dir/u_common.php"); 
else include ("./$Slang/u_common.php"); 

//=====================================
// DB_LAYER / TEMPLATE
//=====================================

$tpl = new Stemplate($Stemplate);
$tpl->define(	array(comment      => "comment.html"));

$tpl->assign(array(
TEMPLATE	=> $Stemplate,
DOMAIN			=> $Sdomain,
CHARSET		=> $Scharset,
BGCOLOR		=> $Sbgcolor,
MWIDTH			=> $Smain_width,
ALIGN			=> $Salign,
SID				=> $sid
));

//=====================================
// Input Form
//=====================================


if (!$switch) {

$tpl->assign(array(
L_COMMENT => $l_comment,
L_NAME		=> $l_name,
L_PASS		=> $l_pass,
L_VOTE		=> $l_vote,
L_CONTENT		=> $l_content,
L_CLOWIN			=> $l_clowin,
L_NONAME => $l_error_noname,
L_NOPASS => $l_error_nopass,
L_NODESC => $l_error_nodesc,

));
$tpl->parse(MAIN,"comment");
$tpl->simprint("MAIN");
exit;
}


//================================================
// Comment Add part (switch on)
//================================================

// error check
if (!$name) errmsg($l_error_noname);
if (!$content) errmsg($l_error_nodesc);
if (!$vote)	errmsg($l_error_novote);


//=====================================
// DB_LAYER / TEMPLATE
//=====================================


$tpl->define(	array(
comment_ok => "comment_ok.html",
comment_error => "comment_error.html" ));

$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);


// trim all data
while (list($key,$val) = each($HTTP_POST_VARS)) 
$$key = trim($val);



// Duplicate comment prevent
$cook_comment = unserialize(stripslashes($HTTP_COOKIE_VARS[cook_comment]));

if (is_array($cook_comment) && isset($cook_comment)) {
	while (list(,$val) = each($cook_comment)) 
	if ($val == $sid) {
	$tpl->assign(array( L_ALREADY_COM => $l_already_com ));
	$tpl->parse("MAIN","comment_error");
	$tpl->simprint("MAIN");
	exit;
	}
}
$cook_comment[] = $sid;
setcookie("cook_comment",serialize($cook_comment),time() + $Scooklimit,"/");


//=====================================
// DATA INPUT part
//=====================================

$maxnum = maxnum("LINKER_COM","sid");
$time = time();

$db->query("update LINKER_LINK set comment = comment +1 where sid='$sid'");
$db->query("insert into LINKER_COM set
sid  = '$maxnum',
parent = '$sid',
name = '$name',
home = '$home',
email = '$email',
ipaddr = '$REMOTE_ADDR',
uptime = '$time',
content = '$content',
vote = '$vote',
passwd='$passwd'
");

// Plus Link num
$score = "n".$vote;
$db->query("update LINKER_LINK SET $score = $score +1  where sid='$sid'");

$tpl->assign(array( L_COMMENT_OK => $l_comment_ok ));
$tpl->parse(MAIN,"comment_ok");
$tpl->simprint("MAIN");

?>
Return current item: Linker IMG