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

//=====================================
// LINKER Category Engine
//=====================================
// Filename : edit_link.php
// Path  : Manage directory
// last update : 2002/07/13
// Desc : Edit 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"); 

if (!$update) errmsg($l_error_nosid);
$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);

//=====================================
// View link edit form
//===================================== 

if (!$switch)  
{

$db->query("select * from LINKER_LINK where sid='$update'");
$row = $db->nrecord();

while(list($key , $val) = each ($row))
if ($key <> "upfile") $row[$key] =  htmlspecialchars(stripslashes(trim($val)));


$up_cat=view_category("sid",1,$row[parent]);

if ($row[c_pick]) 
$choice="<select name='c_pick'>
<option value='1' selected>$l_pick_yes</option>
<option value='0'>$l_pick_no</option>
</select>";

else $choice="<select name='c_pick'>
<option value='1'>$l_pick_yes</option>
<option  value='0' selected>$l_pick_no</option>
</select>";

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='edit_link.php' method='post' ENCTYPE="multipart/form-data">
<input type='hidden' name='switch' value='up'>
<input type='hidden' name='update' value='$update'>
<input type='hidden' name='old_pass' value='$row[passwd]'>
<input type='hidden' name='old_parent' value='$row[parent]'>
<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">$row[title] $l_link_info</font></b>
</td></tr></table>

</td>	</tr>

<tr><td colspan=2>&nbsp;</td>	</tr>

<tr>
<td bgcolor='#E0E0E0' colspan=2 height=24 align=center width=500>
<font size='2'>&nbsp; $l_link_head </font></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_sid</font></td>
<td bgcolor='#F6F6F6' height='24'>&nbsp;<font size=2>$row[sid]</font></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_title</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='text' size='20'  name='title' value='$row[title]' style="width:220px"></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_source</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='text' size='20'  name='url' value='$row[url]' style="width:220px"></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_cat</font></td>
<td bgcolor='#F6F6F6' height='24'><font size='2'><select name='parent'>$up_cat</select></font></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_scont</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='text' size='30'  name='scont' value='$row[scont]' style="width:300px"></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_name</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='text' size='20'  name='name' value='$row[name]' style="width:220px"></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_email</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='text' size='20'  name='email' value='$row[email]' style="width:220px"></td>
</tr>

EOF;

//=====================================
// for File upload
//===================================== 


$upfile = unserialize(stripslashes($row[upfile]));
$upfile[2] = size_cut($upfile[2]);
$upfile[5] = strtoupper($upfile[5]);


print <<<EOF

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_edit_file</font></td>
<td bgcolor='#F6F6F6' height='24'>

	<table width=100% border=0><tr>
	<td><ul>
	<li><a href="../download.php?sid=$row[sid]"><font size='2'>$upfile[0]</font></a></li>
	<li><font size='2'>$upfile[3] X $upfile[4]</font></li>
	<li><font size='2'>$upfile[5], $upfile[2]</font></li>
	<li><font size='2'>$l_down : $upfile[6]</font></li></ul>
	<input type='file' name="upfile" size='10'></td>
	<td align=right><a href='../imageview.php?uid=$upfile[1]&vtype=orgin' target='_blank'><font  size='2'><img src='../imageview.php?uid=$upfile[1]' border=0></font></td>
	</tr></table>
</td>
</tr>

EOF;


//=====================================
// For user field
//===================================== 

for ($k=1 ;$k<=5 ;$k++) {
$u_name = ${"u_user" . $k};
$u_fname = "user". $k;

if($u_name)
print <<<EOF
    <tr>
        <td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$u_name</font></td>
        <td bgcolor='#F6F6F6' height='24'><input type='text' size='20'  name='$u_fname' value='$row[$u_fname]' style="width:220px"></td>
    </tr>

EOF;
}

//-------------------------------

print <<<EOF

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_pick</font></td>
<td bgcolor='#F6F6F6' height='24'><font size=2>$choice</font></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_vote_score</font></td>
<td bgcolor='#F6F6F6' height='24'>
&nbsp;1 <input type='text' size='2'  name='n1' value='$row[n1]'>
&nbsp;2 <input type='text' size='2' name='n2' value='$row[n2]'>
&nbsp;3 <input type='text' size='2' name='n3' value='$row[n3]'>
&nbsp;4 <input type='text'  size='2' name='n4' value='$row[n4]'>
&nbsp;5 <input type='text'  size='2' name='n5' value='$row[n5]'>
</font></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_vote_score</font></td>
<td bgcolor='#F6F6F6' height='24'>
&nbsp;6 <input type='text'   size='2' name='n6' value='$row[n6]'>
&nbsp;7 <input type='text'   size='2' name='n7' value='$row[n7]'>
&nbsp;8 <input type='text'   size='2' name='n8' value='$row[n8]'>
&nbsp;9 <input type='text'   size='2' name='n9' value='$row[n9]'>
&nbsp;10 <input type='text'  size='2' name='n10' value='$row[n10]'>
</td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_count</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='text' size='10'  name='count' value='$row[count]'></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_pass</font></td>
<td bgcolor='#F6F6F6' height='24'><input type='password' name='passwd' value='$row[passwd]'></td>
</tr>

<tr>
<td width='100' bgcolor='#F6F6F6' height='24'><font  size='2'>&nbsp;$l_lcont</font></td>
<td bgcolor='#F6F6F6' height='24'><textarea name='lcont' rows=5 cols=30 style="width:350px">$row[lcont]</textarea></td>
</tr>

<tr><td colspan=2 align=center bgcolor='#E0E0E0'><font size=2>
<input type='submit' value=' $l_edit ' class=cinput><input type='reset' value=' $l_reset ' class=cinput></font>
</td></tr>
</table>

</div></form>

EOF;
exit;
 }

//=====================================
// Edit part
//===================================== 

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


$db->query("select path,pathtxt from LINKER_CAT where sid = '$parent'");
$row2 = $db->nrecord();

//------------------------------
// Edit Link num
//------------------------------
if ($old_parent <> $parent) {

if (isset($old_parent)) $db->query("update LINKER_CAT set sub_link = sub_link-1 where sid='$old_parent'");
if (isset($parent)) $db->query("update LINKER_CAT set sub_link = sub_link+1 where sid='$parent'");

}



//=====================================
//  file upload
//=====================================

$db->query("select upfile from LINKER_LINK where sid='$update'");
$frow = $db->nrecord();
$old_upfile = unserialize(stripslashes($frow[upfile]));

if ($upfile_name && $upfile_size >0)	
{



	// delete old image file
	@unlink("./upfile/$old_upfile[1]");
	@unlink("./upfile/thumb_" . $old_upfile[1]);

	$file_ext = strtolower(substr($upfile_name,-strlen(strrchr($upfile_name,"."))+1));

/*
	if (!$file_ext) 
	{
		errmsg($l_error_noext);
	}
*/

	if ($Sfupext) 
	{
		$extar = @implode("|", explode(",",$Sfupext));
		if (!ereg($extar,$file_ext)) 
		{
			errmsg ($l_error_9);
		}
	}


	$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);
	}
} // end if

else 	
{ 
	$add_file = $frow[upfile];
}



//----------------------------------------------

$edit_sql="
update LINKER_LINK set 
title='$title',url='$url',parent='$parent', scont='$scont',
lcont = '$lcont', name='$name', email='$email',c_pick='$c_pick',
n1='$n1',n2='$n2',n3='$n3',n4='$n4',n5='$n5',
n6='$n6',n7='$n7',n8='$n8',n9='$n9',n10='$n10',
passwd='$passwd',count='$count',visit='$visit',path='$row2[path]',pathtxt='$row2[pathtxt]',upfile = '$add_file',
user1='$user1',user2='$user2',user3='$user3',user4='$user4',user5='$user5' where sid = '$update'
";

$db->query($edit_sql);


//=====================================
// Print Edit result
//===================================== 

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=./view_link.php?type=update'>
</head>

<body bgcolor="#E9E9E9">
<table width="500" border="1"><tr><td bgcolor="#000066" align="center">
<font color="white" size="2"><b>$update $l_link_result</b></font>
</td></tr></table>

</body></html>

EOF;

?>
Return current item: Linker IMG