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

Current Path : home/irplbiz/public_html/universalleather/admin/
Upload File :
Current File : /home/irplbiz/public_html/universalleather/admin/add_category.php

<?php
session_start();
include('includes/config.php');
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="css/style.css" rel="stylesheet" type="text/css" />
<title>Welcome to Our  Website::Admin Panel</title>
</head>



<?php
	ob_start();
	session_start();
	/*if(!isset($_SESSION['username']))
	{
		header("location: index.php?login=expired");
	}*/
	
	//include("../includes/config.php");
	include("includes/config.php");

	set_time_limit(0);
	define ("MAX_SIZE","1000");
	define ("WIDTH","190"); 
	define ("HEIGHT","125"); 
	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;
	if(isset($_POST['Submit'])){
	$image=$_FILES['cons_image']['name'];
	if ($image)
	{
	$filename = stripslashes($_FILES['cons_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['cons_image']['tmp_name']);
	$sizekb=filesize($_FILES['cons_image']['tmp_name']);
	if ($sizekb > MAX_SIZE*1024)
	{
	echo 'You have exceeded the 1MB size limit!';
	$errors=1;
	}
	$timestamp = time();
	
	
	$galleryImageBefore = $timestamp . "." . $extension ; 
	$galleryThumbBefore = $timestamp . "." . $extension ;
	$consname="product_img/images/" . $galleryImageBefore ; 
	$consname2="product_img/thumbs/" . $galleryThumbBefore ;
	$copied = copy($_FILES['cons_image']['tmp_name'], $consname);
	$copied = copy($_FILES['cons_image']['tmp_name'], $consname2);
	if (!$copied) {
	echo 'Copy unsuccessfull!';
	$errors=1;
	}else{
	$thumb_name=$consname2 ;
	$thumb=make_thumb($consname,$thumb_name,WIDTH,HEIGHT);
	}
	}
	}
	}

	if(isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'add')
	{
		$sql = "INSERT INTO `ln_tbl_categories` SET 
		`cat_id` 	= '',
		`name` 		= '".$_REQUEST['name']."',
		`desc` 			= '".$_REQUEST['desc']."',
		`image` 		= '".$galleryThumbBefore."',
		`parent` 	= '".$_REQUEST['parent']."'";
		
		mysql_query($sql) or die("Cannot add Categories...".mysql_error());
		
		$err = "One New Category Successfully Added...";
	}
	
?>
<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>
    
        
      <tr>
      
      <td>
		

    
      <tr>
  <td colspan="4"  style="background:#0dbad9; font-size:18px; color:#FFFFFF;  padding:10px 0 10px 10px; margin-bottom:7px;"><span class="style3">Add Category</span></td></tr>
 
 
      <tr>
    <td height="100" align="left" valign="top">
		<table width="100%" cellpadding="0" cellspacing="3" border="0" align="center" style="border: dashed 1px #999999;" >
				
			<table width="100%">
            
            <?php
	if($err != '')
	{
	?>
		<font color="#009900"><?php echo $err;?></font><br />
		<br /><br />
	<?php	
	}
	?>
            
            <form action="add_category.php" method="post" name="frm" enctype="multipart/form-data" onSubmit="return validateRegistrationForm();">
	     <input type="hidden" name="mode" value="add" />
						<tr>		
							<td class="grey" for="signup" align="right" width="154">Category Name : *</td>
							<td>
								<input name="name" id="name" type="text" style="width:200px" />
							</td>
						</tr>
						<tr>		
							<td class="grey" for="signup" align="right" width="154">Description / Features : </td>
							<td>
							<?php $value = $row['desc']; ?>
							
							<?php
							include_once ('fckeditor/fckeditor.php');
							$oFCKeditor = new FCKeditor('desc') ;
							$oFCKeditor->BasePath = 'fckeditor/';
							$oFCKeditor->Value = $value;
							//$oFCKeditor->ToolbarSet = "Basic";
							$oFCKeditor->Width  = '100%' ;
							$oFCKeditor->Height = '250' ;
							$oFCKeditor->Create() ;
							?>
							</td>							
						</tr>
						<!--<tr>		
							<td class="grey" for="signup" align="right" width="200">Upload Category Image : *</td>
							<td>
								<input name="cons_image" type="file" style="width:200px" />
							</td>
						</tr>-->
						<!--<tr>		
							<td class="grey" for="signup" align="right" width="154" valign="top">Parent : * </td>
							<td>
								<select name="parent" >
									<option value="0">No Parent</option>
									<?php
										$sql2 = "SELECT * FROM `ln_tbl_categories` WHERE `parent` = 0";
										$rs2  = mysql_query($sql2);
										while($row2 = mysql_fetch_array($rs2)) {
									?>
									<option value="<?php echo $row2['cat_id']; ?>" <?php if($row2['cat_id'] == $row['parent']) { ?> selected="selected" <?php } ?> ><?php echo $row2['name']; ?></option>
									
									<?php
										$sql3 = "SELECT * FROM `ln_tbl_categories` WHERE `parent` = ".$row2['cat_id'];
										$rs3  = mysql_query($sql3);
										while($row3 = mysql_fetch_array($rs3)) {
									?>
									<option value="<?php echo $row3['cat_id']; ?>" <?php if($row3['cat_id'] == $row['parent']) { ?> selected="selected" <?php } ?> >------<?php echo $row3['name']; ?></option>
									
									<?php
										$sql4 = "SELECT * FROM `ln_tbl_categories` WHERE `parent` = ".$row3['cat_id'];
										$rs4  = mysql_query($sql4);
										while($row4 = mysql_fetch_array($rs4)) {
									?>
									<option value="<?php echo $row4['cat_id']; ?>" <?php if($row4['cat_id'] == $row['parent']) { ?> selected="selected" <?php } ?> >----------<?php echo $row4['name']; ?></option>
									
									<?php
									}
									?>
									<?php
									}
									?>
									<?php
									}
									?>	
								</select>
							</td>	
						</tr>-->
						<!--<tr>		
							<td class="grey" for="signup" align="right" width="200">Upload Category Image : * </td>
							<td>
								<input name="cons_image" type="file" style="width:200px" />
							</td>
						</tr>-->
						<tr>
							<td>&nbsp;</td>
							<td><input type="submit" name="Submit" value="Add Category" class="bt_register" /></td>
						</tr>
                        </form>
					</table>
            		
		</table>
							
	</td>
     </tr>
      
    </table>
      
	 </td>
      
      
      
      </tr>
      

	  
	
   </td>
  </tr>
</table>
</div> 
</div>

</body>

<?php
 }
else
{
header("location:index.php");
}
?>