<?php
//=====================================
// LINKER Category Engine
//=====================================
// Filename : add.php
// Path : Main directory
// last update : 2002/07/13
// Desc : Add User new Image
//=====================================
//=====================================
// File include part
//=====================================
$time1 = microtime();
include ("./function/base_info.php");
include ("./function/main_func.php");
include ("./function/$Sdb_type.php");
include ("./function/template.php");
include ("./function/userfield_info.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
//=====================================
$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);
$tpl = new Stemplate($Stemplate);
$tpl->assign( array(
TEMPLATE => $Stemplate,
DOMAIN => $Sdomain,
CHARSET => $Scharset,
MWIDTH => $Smain_width,
BGCOLOR => $Sbgcolor,
ALIGN => $Salign,
PAGE_HEADER => implode("",file("$Stemplate/header.html")),
PAGE_FOOTER => implode("",file("$Stemplate/footer.html"))
));
show_menu();
show_here("","",$l_link_add);
show_search();
//=====================================
// Link data Input Form part
//=====================================
if (!$switch) {
//template define
$tpl->define( array(add => "add.html"));
$tpl->dyn_define ( "tdcol", "add" );
// Make category selectbox
$tpl->assign( array( VIEW_CAT => view_category("","",$sid,1) ));
// User Filed
for ($k=1 ;$k<=5 ;$k++) {
$u_name = ${"u_user" . $k};
$u_fname = "user". $k;
if($u_name) {
$tpl->assign( array( ADD_NAME => $u_name, ADD_RNAME => $u_fname ));
$tpl->parse("TDCOL", ".tdcol");
}
}
// Language
$tpl->assign( array(
L_LINK_ADD => $l_link_add,
L_ERROR_1 => $l_error_1,
L_ERROR_2 => $l_error_2,
L_ERROR_3 => $l_error_3,
L_ERROR_4 => $l_error_4,
L_ERROR_5 => $l_error_5,
L_ERROR_6 => $l_error_6,
L_ERROR_7 => $l_error_7,
L_ADD_PRE_TXT => $l_add_pre_txt,
L_TITLE => $l_title,
L_SOURCE => $l_source,
L_LINK => $l_link,
L_CAT => $l_cat,
L_SELECT_CAT => $l_select_cat,
L_SCONT => $l_scont,
L_LCONT => $l_lcont,
L_NAME => $l_name,
L_EMAIL => $l_email,
L_PASS => $l_pass,
L_ADD_SUBMIT => $l_add_submit,
L_ADD_HEAD => $l_add_head
));
$tpl->parse(MAIN,"add");
$tpl->simprint("MAIN");
}
//=====================================
// Insert Database
//=====================================
if ($switch=='add') {
$tpl->define( array( add_sub => "add_sub.html" ));
$tpl->dyn_define ( "tdcol", "add_sub" );
if (!$parent) errmsg($l_error_1);
if (!$title) errmsg($l_error_2);
if (!$scont) errmsg($l_error_4);
if (!$name) errmsg($l_error_5);
if (!$email) errmsg($l_error_6);
if (!$passwd) errmsg($l_error_7);
if (!check_email($email)) errmsg ($l_error_8);
$time = time();
//=====================================
// fileupload part
//=====================================
// Check routine
if (!$upfile_name)
{
errmsg($l_error_10);
}
if (!$upfile_size)
{
errmsg($l_error_11);
}
$file_ext = strtolower(substr($upfile_name,-strlen(strrchr($upfile_name,"."))+1));
if (!$file_ext)
{
errmsg($l_error_12);
}
if ($Sfupext)
{
$extar = @implode("|", explode(",",$Sfupext));
if (!ereg($extar,$file_ext))
{
errmsg ($l_error_9);
}
}
$md5 = md5 (uniqid (rand()));
// Make thumbnail
if (ereg("jpg|png|gif", $file_ext))
{
$imginfo = @getimagesize ($upfile);
switch ($imginfo[2])
{
case 1: $file_ext = "gif"; break;
case 2: $file_ext = "jpg"; break;
case 3: $file_ext = "png"; break;
}
if ($imginfo[0] < $imginfo[1]) // height > width
{
$file_width = intval($Snail_height * ($imginfo[0] / $imginfo[1])) ;
$file_height = $Snail_height ;
}
else if ($imginfo[0] > $imginfo[1]) // height < width
{
$file_height = intval($Snail_width * ($imginfo[1] / $imginfo[0]));
$file_width = $Snail_width;
}
else
{
if ($Snail_width < $Snail_height)
{
$file_height = intval($Snail_width * ($imginfo[1] / $imginfo[0]));
$file_width = $Snail_width;
}
else
{
$file_width = intval($Snail_height * ($imginfo[0] / $imginfo[1])) ;
$file_height = $Snail_height ;
}
}
$dst_img = ImageCreate($file_width, $file_height);
switch ($imginfo[2])
{
case 1: $src_img = ImageCreateFromgif($upfile); break;
case 2: $src_img = ImageCreateFromjpeg($upfile); break;
case 3: $src_img = ImageCreateFrompng($upfile); break;
}
ImageCopyResized($dst_img, $src_img,0,0,0,0, $file_width, $file_height, ImageSX($src_img), ImageSY($src_img));
switch ($imginfo[2])
{
case 1: Imagegif($dst_img, "./upfile/thumb_" . $md5 ,100); break;
case 2: Imagejpeg($dst_img, "./upfile/thumb_" . $md5 ,100); break;
case 3: Imagepng($dst_img, "./upfile/thumb_" . $md5 ,100); break;
}
@ImageDestroy($dst_img);
@ImageDestroy($src_img);
}
$check_upload = move_uploaded_file($upfile, "upfile/$md5");
if ($check_upload)
{
$add_filear[0]= $upfile_name;
$add_filear[1]= $md5;
$add_filear[2]= $upfile_size;
$add_filear[3]= $imginfo[0];
$add_filear[4]= $imginfo[1];
$add_filear[5]= $file_ext;
$add_filear[6]= 0;
$add_file = serialize($add_filear);
}
//---------------------------------
// Plus Link num and Selective query
//---------------------------------
$db->query("select path,pathtxt from LINKER_CAT where sid='$parent'");
$row = $db->nrecord();
if ($Saddtype) { // 1 -> wait 0 -> link
$maxnum = maxnum("LINKER_WAIT","sid");
$query = "insert into LINKER_WAIT SET
sid = '$maxnum',
parent = '$parent',
title = '$title',
scont = '$scont',
lcont = '$lcont',
url = '$url',
path = '$row[path]',
name = '$name',
email ='$email',
passwd = '$passwd',
upfile = '$add_file',
user1='$user1',
user2='$user2',
user3='$user3',
user4='$user4',
user5='$user5'
";
}
else {
$maxnum = maxnum("LINKER_LINK","sid");
$query = "insert into LINKER_LINK SET
sid = '$maxnum',
parent = '$parent',
title = '$title',
scont = '$scont',
lcont = '$lcont',
url = '$url',
uptime = '$time',
path = '$row[path]',
pathtxt = '$row[pathtxt]',
name = '$name',
email ='$email',
passwd = '$passwd',
upfile = '$add_file',
user1='$user1',
user2='$user2',
user3='$user3',
user4='$user4',
user5='$user5',
c_new = 'Y'
";
//---------------------------------
// parent last update time update
//---------------------------------
$parent_array = @explode("/", $row[path]);
for ($i=0; $i<count($parent_array) ;$i++)
{
$parent_last[] = "sid = $parent_array[$i]";
}
$parent_update = @implode(" or " , $parent_last);
$db->query("update LINKER_CAT set bingo1 = '$time' where $parent_update");
//---------------------------------
// plus sub_link num
//---------------------------------
if (isset($parent)) $db->query("update LINKER_CAT set sub_link = sub_link+1 where sid='$parent'");
}
$db->query($query);
//---------------------------------
// Add output Print
//---------------------------------
$category = str_replace($Ssepchar, $Sarrow ,stripslashes($row[pathtxt]));
$tpl->assign( array(
CATEGORY => htmlspecial($category),
TITLE => htmlspecial($title),
SCONT => htmlspecial($scont),
LCONT => nl2br(htmlspecial($lcont)),
NAME => htmlspecial($name),
EMAIL => htmlspecial($email),
SOURCE => htmlspecial($url),
PASSWD => htmlspecial($passwd),
UPFILE_NAME => $upfile_name
)
);
// User field
for ($k=1 ;$k<=5 ;$k++) {
$u_name = ${"u_user" . $k};
$u_fname = ${"user". $k};
if($u_name) {
$tpl->assign( array( ADD_NAME => $u_name, ADD_VALUE => htmlspecial($u_fname) ));
$tpl->parse("TDCOL", ".tdcol");
}
}
$tpl->assign( array(
L_ADDED_CONTENT => $l_added_content,
L_TITLE => $l_title,
L_SOURCE => $l_source,
L_CAT => $l_cat,
L_LINK => $l_link,
L_SCONT => $l_scont,
L_LCONT => $l_lcont,
L_NAME => $l_name,
L_EMAIL => $l_email,
L_PASS => $l_pass
));
$tpl->parse("MAIN","add_sub");
$tpl->simprint("MAIN");
}
//====================================
// Establish time
//====================================
if ($Stime == "Y") check_time($time1);
?>