Psyduck - 可達鴨 之 鴨力山大 v0.1

Current Path : home/irplbiz/www/lnselgallery/control/
Upload File :
Current File : /home/irplbiz/www/lnselgallery/control/second_category.php

<?php

session_start();

include('../inc/config.php');



	$SQL2 = "SELECT * FROM `categories` WHERE cat_id='".$_REQUEST['id']."' OR cat_id='".$_REQUEST['eid']."'";

	$RS2 = mysql_query($SQL2);

	$RES2 = mysql_fetch_array($RS2);



if($_SESSION['loggedin']=1)

 {



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="style.css" rel="stylesheet" type="text/css" />

<title>Welcome to Our  Website::Admin Panel</title>

</head>





<?php

$msg = "";



	if($_POST['Submit']=='Add')

	{



	set_time_limit(0);

	define ("MAX_SIZE","1000");

	define ("WIDTH","150"); 

	define ("HEIGHT","150"); 

	

	function make_thumb($img_name,$filename,$new_w,$new_h){

	$ext=getExtension($img_name);

	if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))

	$src_img=imagecreatefromjpeg($img_name);

	if(!strcmp("png",$ext))

	$src_img=imagecreatefrompng($img_name);

	if(!strcmp("gif",$ext))

	$src_img=imagecreatefromgif($img_name);

	$old_x=imageSX($src_img);

	$old_y=imageSY($src_img);

	$ratio1=$old_x/$new_w;

	$ratio2=$old_y/$new_h;

	if($ratio1>$ratio2) {

	$thumb_w=$new_w;

	$thumb_h=$old_y/$ratio1;

	}else{

	$thumb_h=$new_h;

	$thumb_w=$old_x/$ratio2;

	}

	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

	if(!strcmp("png",$ext))

	imagepng($dst_img,$filename);

	else

	imagejpeg($dst_img,$filename);

	if (!strcmp("gif",$ext))

	imagegif($dst_img,$filename);

	imagedestroy($dst_img);

	imagedestroy($src_img);

	}

	function getExtension($str) {

	$i = strrpos($str,".");

	if (!$i) { return ""; }

	$l = strlen($str) - $i;

	$ext = substr($str,$i+1,$l);

	return $ext;

	}

	$errors=0;

	

	$image=$_FILES['image']['name'];

	if ($image)

				{

				$filename = stripslashes($_FILES['image']['name']);

				$extension = getExtension($filename);

				$extension = strtolower($extension);

				if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {

				echo 'Unknown extension! Please use .gif, .jpg or .png files only.';

				$errors=1;

				}else{

				$size=getimagesize($_FILES['image']['tmp_name']);

				$sizekb=filesize($_FILES['image']['tmp_name']);

				if ($sizekb > MAX_SIZE*1024)

				{

				echo 'You have exceeded the 1MB size limit!';

				$errors=1;

				}

				$timestamp = time().rand(1,1000);

				

				$galleryImageBefore1 = $timestamp . "." . $extension ; 

				$galleryThumbBefore1 = $timestamp . "." . $extension ;

				$consname="product_image/big/" . $galleryImageBefore1 ; 

				$consname2="product_image/thumb/" . $galleryThumbBefore1 ;

				$copied = copy($_FILES['image']['tmp_name'], $consname);

				$copied = copy($_FILES['image']['tmp_name'], $consname2);

				if (!$copied) {

				$errors=1;

				}else{

				$thumb_name=$consname2 ;

				$thumb=make_thumb($consname,$thumb_name,WIDTH,HEIGHT);

				}

				}

				}	



		$sql="INSERT INTO `categories`(`cat_id`,`name`,`image`,`parent`)

		 values('','".$_POST['name']."','$galleryThumbBefore1','".$_REQUEST['id']."')";

	

		 $ins = mysql_query($sql);



		$msg = "Second Level Category Name Added Successfully";

	}

	

	if($_POST['Submit']=='Edit')

	{



	set_time_limit(0);

	define ("MAX_SIZE","1000");

	define ("WIDTH","150"); 

	define ("HEIGHT","150"); 

	

	function make_thumb($img_name,$filename,$new_w,$new_h){

	$ext=getExtension($img_name);

	if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))

	$src_img=imagecreatefromjpeg($img_name);

	if(!strcmp("png",$ext))

	$src_img=imagecreatefrompng($img_name);

	if(!strcmp("gif",$ext))

	$src_img=imagecreatefromgif($img_name);

	$old_x=imageSX($src_img);

	$old_y=imageSY($src_img);

	$ratio1=$old_x/$new_w;

	$ratio2=$old_y/$new_h;

	if($ratio1>$ratio2) {

	$thumb_w=$new_w;

	$thumb_h=$old_y/$ratio1;

	}else{

	$thumb_h=$new_h;

	$thumb_w=$old_x/$ratio2;

	}

	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

	if(!strcmp("png",$ext))

	imagepng($dst_img,$filename);

	else

	imagejpeg($dst_img,$filename);

	if (!strcmp("gif",$ext))

	imagegif($dst_img,$filename);

	imagedestroy($dst_img);

	imagedestroy($src_img);

	}

	function getExtension($str) {

	$i = strrpos($str,".");

	if (!$i) { return ""; }

	$l = strlen($str) - $i;

	$ext = substr($str,$i+1,$l);

	return $ext;

	}

	$errors=0;

		

	$image=$_FILES['image']['name'];



			if ($image)

			{

			$filename = stripslashes($_FILES['image']['name']);

			$extension = getExtension($filename);

			$extension = strtolower($extension);

			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {

			echo 'Unknown extension! Please use .gif, .jpg or .png files only.';

			$errors=1;

			}else{

			$size=getimagesize($_FILES['image']['tmp_name']);

			$sizekb=filesize($_FILES['image']['tmp_name']);

			if ($sizekb > MAX_SIZE*1024)

			{

			echo 'You have exceeded the 1MB size limit!';

			$errors=1;

			}

			$timestamp = time().rand(1,1000);

			

			$galleryImageBefore1 = $timestamp . "." . $extension ; 

			$galleryThumbBefore1 = $timestamp . "." . $extension ;

			$consname="product_image/big/" . $galleryImageBefore1 ; 

			$consname2="product_image/thumb/" . $galleryThumbBefore1 ;

			$copied = copy($_FILES['image']['tmp_name'], $consname);

			$copied = copy($_FILES['image']['tmp_name'], $consname2);

			

			if (!$copied) {

			echo 'Copy unsuccessfull!';

			$errors=1;

			}else{

			$thumb_name=$consname2 ;

			$thumb=make_thumb($consname,$thumb_name,WIDTH,HEIGHT);

			}

			}

			$image = $galleryThumbBefore1;

			}

			else

			{

			$image = $RES2['image'];

			}

			

			

		 $sql = "UPDATE `categories` SET 

		`name` 			= '".$_POST['name']."',

		`image` 			= '".$image."'

		WHERE `cat_id` = '".$_REQUEST['eid']."'";

		 $ins = mysql_query($sql);



		$msg = "Second Level Category Name Edited Successfully";

		echo "<script>window.location.href='second_category.php';</script>";

	}



}

?>

<body>

<div class="main">

<div class="inner-panel">

<table width="978" border="0" cellspacing="0" cellpadding="0" align="center" >

    <?php include('includes/header.php'); ?>



  <tr>

    <td width="200">&nbsp;</td>

    <td align="right" width="10">&nbsp;</td>

    <td align="right" width="768">&nbsp;</td>

  </tr>

  <tr>

    <td width="200" valign="top"><?php include('includes/sidebar.php'); ?></td>

    <td width="10" style="background-color:none;">&nbsp;</td>

    <td width="768" bgcolor="#FFFFFF" valign="top" align="right">

		<table width="97%" border="0" align="left" cellpadding="0" cellspacing="0"  bgcolor="#fff"  style="padding:0px; margin:2px 10px;">

    <tr>

	  	<td align="center" style="color: green; font-weight: bold;">

			<?php echo $msg; ?>		</td>

	  </tr>

      

    <?php if(isset($_REQUEST['id']) && $_REQUEST['id']!='')  { ?>

      

      <tr>

        <td colspan="4"  style="background:#0dbad9; font-size:18px; color:#FFFFFF;  padding:10px 0 10px 10px; margin-bottom:7px;"><span class="style3"><?php echo $RES2['name'];?> > Add Subcategory</span></td></tr>

      <tr><td><form action="" method="post" name="form"  enctype="multipart/form-data">

      

    <table width="100%">

      <tr>

        <td><table width="100%">

            <tr>

            <td style="border:1px dotted #ccc;">Second Level Category Name</td>

            <td style="border:1px dotted #ccc;"><input type="text" name="name" value=""/></td>

            </tr>

            <tr>

            <td style="border:1px dotted #ccc;">Image</td>

            <td style="border:1px dotted #ccc;"><input type="file" name="image" value=""/></td>

            </tr>

            <tr>

            <td style="border:1px dotted #ccc;">&nbsp;</td>

           

            <td style="border:1px dotted #ccc;"><input name="Submit" type="submit" class="submit1" value="Add" style="width:185px;"/></td>

            </tr>

            </table></td>

      </tr>

    </table>



 </form>



    <?php } elseif(isset($_REQUEST['eid']) && $_REQUEST['eid']!='')  { ?>

      

      <tr>

        <td colspan="4"  style="background:#0dbad9; font-size:18px; color:#FFFFFF;  padding:10px 0 10px 10px; margin-bottom:7px;"><span class="style3"><?php echo $RES2['name'];?> > Edit Subcategory</span></td></tr>

        

      <tr><td><form action="" method="post" name="form"  enctype="multipart/form-data">

      

    <table width="100%">

      <tr>

        <td><table width="100%">

            <tr>

            <td style="border:1px dotted #ccc;">Second Level Category Name</td>

            <td style="border:1px dotted #ccc;"><input type="text" name="name" value="<?php echo $RES2['name'];?>"/></td>

            </tr>

            <tr>

            <td style="border:1px dotted #ccc;">Image</td>

            <td style="border:1px dotted #ccc;"><input type="file" name="image" value="<?php echo $RES2['image'];?>"/><img src="product_image/thumb/<?php echo $RES2['image'];?>" style="width: 50px;" /></td>

            </tr>

            <tr>

            <td style="border:1px dotted #ccc;">&nbsp;</td>

           

            <td style="border:1px dotted #ccc;"><input name="Submit" type="submit" class="submit1" value="Edit" style="width:185px;"/></td>

            </tr>

            </table></td>

      </tr>

    </table>



 </form>

		

    <?php } else {} ?>

 

    <table width="100%">

      <tr>

        <td><table width="100%">

            <tr>

            <td colspan="3" style="background:#0dbad9; font-size:18px; color:#FFFFFF;  padding:5px 0 5px 10px; margin-bottom:7px;"><span class="style3">View Second Level Subcategory</span></td></tr>



            <td colspan="3">&nbsp;</td>

            </tr>

            <tr align="center">

            <td width="33%" style="border:1px dotted #ccc;"><b>Subcategory Name</b></td>

            <td width="23%" style="border:1px dotted #ccc;"><b>Image</b></td>

            <td width="44%" style="border:1px dotted #ccc;"><b>Action</b></td>



            </tr>

            

<?php if(isset($_REQUEST['id']) && $_REQUEST['id']!='') { 

			$add="WHERE parent ='".$_REQUEST['id']."' AND sub_parent=0";

	  } else {

			$add="WHERE parent !=0 AND sub_parent=0";

	  } 

	  

		$SQL11 = "SELECT * FROM `categories` ".$add;

		$RS11 = mysql_query($SQL11);

		while($RES11 = mysql_fetch_array($RS11)) {

			

	?>

    

    <tr align="center">

            <td style="border:1px dotted #ccc;"><?php echo $RES11['name'];?></td>

            <td style="border:1px dotted #ccc;"><img src="product_image/thumb/<?php echo $RES11['image'];?>" style="width: 60px;" /></td>

    <td style="border:1px dotted #ccc;"><div align="center"> &nbsp; <a href="delete_second_category.php?id=<?php echo $RES11["cat_id"];?>"><img src="images/del.png" onClick="return confirm('Do you want to delete this category?');" ></a>&nbsp;&nbsp;&nbsp;<a href="second_category.php?eid=<?php echo $RES11["cat_id"];?>"><img src="images/edit.png"></a></div></td>

		</tr>

       <?php } ?>       

            

            </table></td>

      </tr>

    </table>

      

	 </td>

      

      

      

      </tr>

      

	  </table>

	  

	

   </td>

  </tr>

</table>

</div>

</div>

</body>

</html>