<?php
//=====================================
// LINKER Category Engine
//=====================================
// Filename : add_link.php
// Path : Manage directory
// last update : 2002/07/13
// Desc : Add link
//=====================================
//=====================================
// File include part
//=====================================
include ("./authen.php");
include ("../function/$Sdb_type.php");
include ("../function/main_func.php");
include ("../function/userfield_info.php");
include ("../$Slang/m_common.php");
$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);
//=====================================
// Print add form
//=====================================
if (!$switch) {
$view_cat = view_category("sid","1");
print <<<EOF
<html>
<head>
<LINK rel='stylesheet' type='text/css' href='./linker.css'>
<meta http-equiv='Content-Type' content='text/html; charset=$Scharset'>
</head>
<body bgcolor="#E9E9E9">
<form action='add_link.php' method='post' ENCTYPE='multipart/form-data'>
<input type='hidden' name='switch' value='add'>
<table border=0 cellpadding=0 cellspacing=1>
<tr>
<td colspan=2>
<table width="100%" border="1"><tr><td bgcolor="#000066" align="center">
<b><font color="white" size="2">$l_link $l_add</font></b>
</td></tr></table>
</td> </tr>
<tr><td colspan=2> </td> </tr>
<tr>
<td bgcolor='#E0E0E0' colspan=2 height=24 align=center width=500>
<font size='2'> $l_addcat_head </font></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6' width="100"><font size='2'> $l_title</font></td>
<td bgcolor='#F6F6F6'><input type='text' name='title' maxlength='40' size='25' style="width:300px"></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_source</font></td>
<td bgcolor='#F6F6F6'><input type='text' name='url' size='25' style="width:300px"></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_cat</font></td>
<td bgcolor='#F6F6F6'><font size=2><select name='parent'>$view_cat</select></font></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_scont</font></td>
<td bgcolor='#F6F6F6'><input type='text' name='scont' maxlength='200' size='25' style="width:300px"></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_name</font></td>
<td bgcolor='#F6F6F6'><input type='text' name='name' maxlength='40' size='25' style="width:300px"></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_email</font></td>
<td bgcolor='#F6F6F6'><input type='text' name='email' maxlength='40' size='25' style="width:300px"></td>
</tr>
EOF;
// Upload File part
if ($Sfupload) {
print <<<EOF
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_link</font></td>
<td bgcolor='#F6F6F6'><input type='file' name='upfile' size='15'></td>
</tr>
EOF;
}
// User filed
for ($i=1 ;$i<=5 ;$i++)
{
$u_name = ${"u_user" . $i};
$u_fname = "user". $i;
if($u_name)
print <<<EOF
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $u_name</font></td>
<td bgcolor='#F6F6F6'><input type='text' name='$u_fname' size='25' style="width:300px"></td>
</tr>
EOF;
}
print <<<EOF
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_pick</font></td>
<td bgcolor='#F6F6F6'><font size='2'><select name='c_pick'>
<option selected value='0'>$l_pick_no</option>
<option value='1'>$l_pick_yes</option></select></font></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_pass</font></td>
<td bgcolor='#F6F6F6'><input type='password' name='passwd' maxlength='10' size='10'></td>
</tr>
<tr>
<td height='24' bgcolor='#F6F6F6'><font size='2'> $l_lcont</font></td>
<td bgcolor='#F6F6F6'><textarea name='lcont' rows='5' cols='25' style="width:300px"></textarea></td>
</tr>
<tr>
<td colspan='2' bgcolor='#E0E0E0' align='center'>
<input type='submit' value=' $l_submit ' class=cinput><input type='reset' value=' $l_reset ' class=cinput>
</td>
</tr>
</table></form>
EOF;
exit;
}
//=====================================
// Insert part
//=====================================
if (!$title || !$parent) errmsg($l_error_cattitle);
$maxnum = maxnum("LINKER_LINK","sid");
$time = time();
$db->query("select path,pathtxt,parent from LINKER_CAT where sid='$parent'");
$row = $db->nrecord();
//---------------------------------
// fileupload part
//---------------------------------
// Check routine
if (!$upfile_name)
{
errmsg($l_error_nofile);
}
if (!$upfile_size)
{
errmsg($l_error_nosize);
}
$file_ext = strtolower(substr($upfile_name,-strlen(strrchr($upfile_name,"."))+1));
$md5 = md5 (uniqid (rand()));
// Make Thumb nail
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]) // width < height
{
$file_width = intval($Snail_height * ($imginfo[0] / $imginfo[1])) ;
$file_height = $Snail_height ;
}
else if ($imginfo[0] > $imginfo[1])
{
$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);
}
//---------------------------------
// 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'");
$add_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',
c_pick = '$c_pick',
c_new = 'Y',
user1 = '$user1',
user2 = '$user2',
user3 = '$user3',
user4 = '$user4',
user5 = '$user5'
";
$db->query($add_query);
//=====================================
// Print result
//=====================================
$row[pathtxt] = str_replace($Ssepchar, $Sarrow,stripslashes($row[pathtxt]));
$date = date("Y/m/d H:i:s",$time);
$title = htmlspecial($title);
$scont = htmlspecial($scont);
$lcont = htmlspecial($lcont);
print <<<EOF
<html>
<head>
<LINK rel='stylesheet' type='text/css' href='./linker.css'>
<meta http-equiv='Content-Type' content='text/html; charset=$Scharset'>
<meta http-equiv='refresh' content='2; url=add_link.php'>
</head>
<body bgcolor="#E9E9E9">
<div align='left'>
<table border=0 cellpadding=0 cellspacing=1>
<tr>
<td colspan=2>
<table width="100%" border="1"><tr><td bgcolor="#000066" align="center">
<b><font color="white" size="2">$l_submit_link</font></b>
</td></tr></table>
</td> </tr>
<tr><td colspan=2> </td> </tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_cat</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $row[pathtxt]</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_title</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $title</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_source</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $url</font></td>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_scont</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $scont</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_lcont</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $lcont</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_name</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $name</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_email</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $email</font></td>
</tr>
EOF;
//---------------------------------
// file upload and user filed
//---------------------------------
if ($Sfupload && $upfile_name) {
print <<<EOF
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_link</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $upfile_name</font></td>
</tr>
EOF;
}
for ($i=1 ;$i<=5 ;$i++) {
$u_num = ${"u_user" . $i};
$u_val = ${"user". $i};
if($u_num)
print <<<EOF
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $u_num</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $u_val</font></td>
</tr>
EOF;
}
$c_pick = ($c_pick) ? $l_pick_yes : $l_pick_no ;
print <<<EOF
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_pick</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $c_pick</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_uptime</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $date</font></td>
</tr>
<tr>
<td height='24' width='100' bgcolor='#F6F6F6'><font size='2'> $l_pass</font></td>
<td width='400' bgcolor='#F6F6F6' ><font size='2'> $passwd</font></td>
</tr>
</table></body></html>
EOF;
?>