<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');

if($_GET['id']=='show_sub_categories') {
	$catID=$_GET['q'];
	echo getListingSubCategoriesDropDown("industryType", $catID, $industryType, "428");
	exit;
}

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=10:$pagesize;

$heading="Manage Catalog Products";
$record_type="Catalog Product";
$script_name="admin_staff_manage_products.php";
$table_name="product_tbl";
################## Add Record #########################
if($action=="add_record") {
	
	$productCnt=getCount("product_tbl"," where memberID='$memberID'","productID");
	$memberRes=getResult("member_tbl"," where memberID='$memberID'","membershipType");
	if ($memberRes['membershipType'] == 4) {
		$max_limit=6;
	}
	else if ($memberRes['membershipType'] == 3) {
		$max_limit=20;
	}
	else if ($memberRes['membershipType'] == 2) {
		$max_limit=50;
	}	
	
	if ($membershipType != 1 && $productCnt >= $max_limit) {
		$_SESSION['session_message']="You can upload only ".$max_limit." products as a ".$membershipName.". Please contact admin for more details.";
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	
	$form_check_alert=dynamic_check_form_values(array("rp-11-Please enter product name" => "".$productName."", "rp-11-Please enter product keyword" => "".$keyword."", "rp-1-Please select your category" => "".$mainCategory."", "rp-3-Please select your sub category" => "".$industryType."", "rp-1-Please enter product price" => "".$productPrice."", "rp-1-Please enter product minimum order" => "".$minimumOrder."", "rp-11-Please enter your product payment terms" => "".$paymentTerms."", "rp-11-Please enter your product delivery time" => "".$deliveryTime."", "rp-11-Please enter your product description" => "".$completeDescription.""), $validation_ans_arr);
	
	if($_FILES[image1][name]!="") {
		$file_extension=strtolower(getExtension($_FILES[image1][name]));
		if($file_extension!="jpg" && $file_extension!="gif" && $file_extension!="jpeg" && $file_extension!="png") {
			$form_check_alert .="<li>Please upload full image(.jpg,.gif,.png Format Only)</li>";
		}
	}
	
	if(!strlen($form_check_alert)>0){
		
		$all_categories="";
		for ($i=0; $i<count($industryType); $i++) {
			$catids=getCategoryHierarchy($industryType[$i]);
			$all_categories.=$catids;			
		}
		$all_categories=substr($all_categories,0,-1);
		$tmp=explode("^",$all_categories);
		asort($tmp);
		$tmp=array_unique($tmp);
		$all_categories=implode("^",$tmp);
		$allCategories="^".$all_categories."^";		
		
		if (count($industryType) > 1) {
			$industryType1=implode("^",$industryType);
			$industryType2="^".$industryType1."^";
		}
		else {
			$industryType2="^".$industryType[0]."^";
		}
		$industryType=$industryType2;
		
		if($_FILES[image1][name]!="") {
			$img_name="product_".date("Y_m_d_H_i_s");
			$product_image=upload_file($img_name,"image1","uploaded_files/product_images");
			
			$width="110";
			$height="130";
			$source_folder=SITE_DIR_PATH."/uploaded_files/product_images/";
			$destination_folder=SITE_DIR_PATH."/uploaded_files/product_images/thumbs/";
			saveResizedImage($product_image, $width, $height, $source_folder, $destination_folder);
			
			$width1="300";
			$height1="350";
			$source_folder=SITE_DIR_PATH."/uploaded_files/product_images/";
			$destination_folder1=SITE_DIR_PATH."/uploaded_files/product_images/big/";
			saveResizedImage($product_image, $width1, $height1, $source_folder, $destination_folder1);
		}
		
		db_query("insert into product_tbl set productName='$productName', image1='$product_image', keyword='$keyword', mainCategory='$mainCategory', industryType='$industryType', allCategories='$allCategories', productPrice='$productPrice', discountedPrice='$discountedPrice', minimumOrder='$minimumOrder', paymentTerms='$paymentTerms', availability='$availability', brandName='$brandName', modelType='$modelType', deliveryTime='$deliveryTime', completeDescription='$completeDescription', catalogProduct='Y', status='Y', memberID='$memberID', membershipType='".$membershipType."', addedBy='".$_SESSION['MyAdminUserSLNO']."', recvDate=now()");
		$_SESSION['session_message']=$record_type." has been added sucessfully.";
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}	
	else{
		$msg=html_head();
		$msg.=$form_check_alert;
		$msg.=html_foot();
	}
}


################### Update Record ######################
if($action=="update_record") {
	
	$memberRes=getResult("member_tbl"," where memberID='$memberID'","membershipType");
	$form_check_alert=dynamic_check_form_values(array("rp-11-Please enter product name" => "".$productName."", "rp-11-Please enter product keyword" => "".$keyword."", "rp-1-Please select your category" => "".$mainCategory."", "rp-3-Please select your sub category" => "".$industryType."", "rp-1-Please enter product price" => "".$productPrice."", "rp-1-Please enter product minimum order" => "".$minimumOrder."", "rp-11-Please enter your product payment terms" => "".$paymentTerms."", "rp-11-Please enter your product delivery time" => "".$deliveryTime."", "rp-11-Please enter your product description" => "".$completeDescription.""), $validation_ans_arr);
	
	if($_FILES[image1][name]!="") {
		$file_extension=strtolower(getExtension($_FILES[image1][name]));
		if($file_extension!="jpg" && $file_extension!="gif" && $file_extension!="jpeg" && $file_extension!="png") {
			$form_check_alert .="<li>Please upload full image(.jpg,.gif,.png Format Only)</li>";
		}
	}
	
	if(!strlen($form_check_alert)>0){
		
		$all_categories="";
		for ($i=0; $i<count($industryType); $i++) {
			$catids=getCategoryHierarchy($industryType[$i]);
			$all_categories.=$catids;			
		}
		$all_categories=substr($all_categories,0,-1);
		$tmp=explode("^",$all_categories);
		asort($tmp);
		$tmp=array_unique($tmp);
		$all_categories=implode("^",$tmp);
		$allCategories="^".$all_categories."^";		
		
		if (count($industryType) > 1) {
			$industryType1=implode("^",$industryType);
			$industryType2="^".$industryType1."^";
		}
		else {
			$industryType2="^".$industryType[0]."^";
		}
		$industryType=$industryType2;
		
		if($_FILES[image1][name]!="") {
			
			$productRes=getResult("product_tbl"," where productID='$productID'","image1");
			
			if($image1!="") {
				$filenm1=SITE_DIR_PATH."/uploaded_files/product_images/".$productRes['image1'];
				if(file_exists($filenm1)) {
					unlink($filenm1);
				}
				
				$filenm_thumb=SITE_DIR_PATH."/uploaded_files/product_images/thumbs/".$productRes['image1'];
						
				if(file_exists($filenm_thumb)) {
					unlink($filenm_thumb);
				}
				
				$filenm_big=SITE_DIR_PATH."/uploaded_files/product_images/big/".$productRes['image1'];
						
				if(file_exists($filenm_big)) {
					unlink($filenm_big);
				}
			}	
			
			$img_name="product_".date("Y_m_d_H_i_s");
			$product_image=upload_file($img_name,"image1","uploaded_files/product_images");
			
			updateTable("product_tbl"," image1='$product_image' where productID='$productID'");
			
			$width="110";
			$height="130";
			$source_folder=SITE_DIR_PATH."/uploaded_files/product_images/";
			$destination_folder=SITE_DIR_PATH."/uploaded_files/product_images/thumbs/";
			saveResizedImage($product_image, $width, $height, $source_folder, $destination_folder);
			
			$width1="300";
			$height1="350";
			$source_folder=SITE_DIR_PATH."/uploaded_files/product_images/";
			$destination_folder1=SITE_DIR_PATH."/uploaded_files/product_images/big/";
			saveResizedImage($product_image, $width1, $height1, $source_folder, $destination_folder1);
		}
		
		updateTable("product_tbl"," productName='$productName', keyword='$keyword', mainCategory='$mainCategory', industryType='$industryType', allCategories='$allCategories', productPrice='$productPrice', discountedPrice='$discountedPrice', minimumOrder='$minimumOrder', paymentTerms='$paymentTerms', availability='$availability', brandName='$brandName', modelType='$modelType', deliveryTime='$deliveryTime', completeDescription='$completeDescription', catalogProduct='$catalogProduct', memberID='$memberID', membershipType='".$memberRes['membershipType']."', recvDate=now() where productID='$recordID'");
		$_SESSION['session_message']=$record_type.' has been updated successfully';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	else{
		$msg=html_head();
		$msg.=$form_check_alert;
		$msg.=html_foot();
	}
}

if($action=="Delete"){
	if(sizeof($_POST[cid])==0) {
		$_SESSION['session_message']='Please select a record first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	for ($x=0; $x < sizeof($_POST[cid]); $x++){
		$arr=$_POST[cid];
		
		$tsRes=getResult($table_name," where productID='$arr[$x]'","image");
		$filename=$tsRes['image'];
		if($filename!="") {
			$file=SITE_DIR_PATH."/uploaded_files/product_images/".$filename;
			if(file_exists($file)) {
				unlink($file);
			}
			
			$file_thumb=SITE_DIR_PATH."/uploaded_files/product_images/thumbs/".$filename;
			if(file_exists($file_thumb)) {
				unlink($file_thumb);
			}
			
			$file_big=SITE_DIR_PATH."/uploaded_files/product_images/big/".$filename;
			if(file_exists($file_big)) {
				unlink($file_big);
			}
		}
		
		db_query("delete from $table_name where productID='$arr[$x]'");
	}
	$_SESSION['session_message']='Record has been deleted from the admin panel.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($action=="Activate"){
	if(sizeof($_POST[cid])==0) {
		$_SESSION['session_message']='Please select a record first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=$start&pagesize=$pagesize");
		exit;
	}
	for ($x=0; $x < sizeof($_POST[cid]); $x++){
		$arr=$_POST[cid];
		updateTable($table_name," status='Y' where productID='$arr[$x]'");
	}
	$_SESSION['session_message']='Selected record(s) activated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($action=="Deactivate"){
	if(sizeof($_POST[cid])==0) {
		$_SESSION['session_message']='Please select a record first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=$start&pagesize=$pagesize");
		exit;
	}
	for ($x=0; $x < sizeof($_POST[cid]); $x++){
		$arr=$_POST[cid];
		updateTable($table_name," status='N' where productID='$arr[$x]'");
	}
	$_SESSION['session_message']='Selected record(s) deactivated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}


if($id=="deactivate") {
	updateTable($table_name," status='N' where productID='$recordID' and status='Y' ");	
	$_SESSION['session_message']=$record_type.' has been deactivated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($id=="activate") {
	updateTable($table_name," status='Y' where productID='$recordID' and status='N' ");
	$_SESSION['session_message']=$record_type.' has been activated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}


if($id=="delete_record") {
	$tsRes=getResult($table_name," where productID='$recordID'","image");
	$filename=$tsRes['image'];
	if($filename!="") {
		$file=SITE_DIR_PATH."/uploaded_files/product_images/".$filename;
		if(file_exists($file)) {
			unlink($file);
		}
		
		$file_thumb=SITE_DIR_PATH."/uploaded_files/product_images/thumbs/".$filename;
		if(file_exists($file_thumb)) {
			unlink($file_thumb);
		}
		
		$file_big=SITE_DIR_PATH."/uploaded_files/product_images/big/".$filename;
		if(file_exists($file_big)) {
			unlink($file_big);
		}
	}
				
	db_query("delete from $table_name where productID='$recordID'");
	$_SESSION['session_message']=$record_type.' is deleted successfully';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

admin_header("");
?>

<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr>
	<td align="left" width="50%" class="myTitle"><?=$heading;?></td>
	<td align="right">
	 <form name="pgcolor_form" action="" method="post" style="margin:0px;padding:0px;">
	 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="right">Records Per Page:
	    <select name="pagesize" onchange="this.form.submit();">
	     <option value="0">Select</option>
	     <?php
	     foreach($_GLOBALS[pgsize_arr] as $val) {
		     if(trim($pagesize)==trim($val)) {
			     echo '<option value="'.$val.'" selected>'.$val.'</option>';
		     }
		     else{
			     echo '<option value="'.$val.'">'.$val.'</option>';
		     }
	     }
	     ?>
	    </select>	    
		 </td>
		</tr>
	 </table>
	 </form>
	</td>
 </tr>
</table>
<hr size="2" width="99%" color="#DA251C">
 
<?
if ($featuredProduct!="") {
	if ($featuredProduct=="Y") {
		updateTable($table_name," status='Y', featuredProduct='$featuredProduct' where productID='$recordID'");
	}
	else {
		updateTable($table_name," featuredProduct='$featuredProduct' where productID='$recordID'");
	}
}


if ($expressProduct!="") {
	if ($expressProduct=="Y") {
		updateTable($table_name," status='Y', expressProduct='$expressProduct' where productID='$recordID'");
	}
	else {
		updateTable($table_name," expressProduct='$expressProduct' where productID='$recordID'");
	}
}


if ($status!="") {
	$cond="where status='$status'";
	$link="&status=$status";
}
else {
	$cond="where 1";
	$cond.=" and addedBy='".$_SESSION['MyAdminUserSLNO']."'";
}
$qry="select * from $table_name $cond";
$keyword=trim($keyword);
if($keyword!=""){
  $qry.=" and (productName LIKE '%$keyword%' or completeDescription LIKE '%$keyword%' )"; 
}

if($sortName!=''){
	$qry.= " order by $sortName $sortBy";
}
else {
	$qry.= " order by productID desc";
}

$qry1= db_query($qry);
$reccnt = NumRows($qry1);
$qry.= " limit $start, $pagesize";
$qry= db_query($qry);
echo pageNavigation($reccnt,$pagesize,$start,$link);
print_message();
?>

<table width="100%"  border="0" cellpadding="6" cellspacing="2" class="lightBorder">
 <tr>
  <td class="lightGrayBg" align="left"><strong>Search Products</strong> by name & description<br>
  <form name="search2" method="POST" action="">
   Keyword: <input name="keyword" type="text" class="input" size="25" value="<?=$keyword;?>">
   <input type="hidden"  class="button" name="id" value="Search2">
   <input type="submit"  class="button" name="search" value="Search">	
  </form>
  </td>
  <td class="lightGrayBg">
  <strong>Sort Products<strong><br>
  <form name="search3" method="POST" action="">
   <select name="sortName" size=1>
    <option value=''>--------Select---------</option>
    <option value='recvDate' <? if($sortName=="recvDate"){ echo "selected";}?>>Added On</option>
    <option value='productName' <? if($sortName=="productName"){ echo "selected";}?>>Product Name</option>    
   </select>
   <select name="sortBy">
    <option value=''>-----Sort By-----</option>
    <option value="asc" <? if($sortBy=="asc"){ echo "selected";}?>>Ascending</option>
    <option value="desc" <? if($sortBy=="desc"){ echo "selected";}?>>Descending</option>
   </select>
   <input type="hidden"  class="button" name="id" value="Search3">
   <input type="submit"  class="button" name="search" value="Sort">
  </form>
  </td>
  <td class="lightGrayBg">
   <strong>Select Status</strong><br/>
   <form name="sts_form" action="" method="post" style="margin:0px;padding:0px;">
	 <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="left">
	    <select name="status" onchange="this.form.submit();">
	     <option value="">All Products</option>
	     <option value="Y" <? if($status=="Y"){ echo "selected";}?>>Active</option>
	     <option value="N" <? if($status=="N"){ echo "selected";}?>>InActive</option>
	     <option value="D" <? if($status=="D"){ echo "selected";}?>>Deleted</option>
	    </select>
	    <input type="hidden" name="keyword" value="<?=$keyword;?>" />
	    <input type="hidden" name="pagesize" value="<?=$pagesize;?>" />
		 </td>
		</tr>
	 </table>
	 </form>
	</td> 
 </tr>
</table><br />

<?php
if($reccnt>0){
	?>
	<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
	<input type="hidden" name="recordID" value="" />
	<input type="hidden" name="featuredProduct" value="" />
	<input type="hidden" name="expressProduct" value="" />	
	<table width="99%" border="0" cellpadding="2" cellspacing="2" class="lightBorder">
	 <tr height="25" bgcolor="#EAEAEA">
	  <td width="4%"><input type="checkbox" name="chk" onclick="CheckAll()" class="NoStyle"></td>
	  <td width="25%"><strong>Member Details</strong></td>
	  <td width="30%"><strong>Product Details</strong></td>
	  <td width="7%" align="center"><strong>Image</strong></td>
	  <td width="11%"><strong>Added On</strong></td>
	  <td width="8%" align="center"><strong>Status</strong></td>
	  <td width="15%"><strong>Options</strong></td>
	 </tr>
	 <?php
	 $sl=$start+1;
	 while ($arr=mysql_fetch_array($qry)) {
		 $arr=ms_htmlentities_decode($arr);
		 $memberRes=getResult("member_tbl"," where memberID='$arr[memberID]'");
		 if($sl%2==0){
			 $color="f0f0f0";
		 }
		 else{
			 $color="f9f9f9";
		 }
		 ?>
		 <tr bgcolor="<?=$color;?>">
		  <td valign="top"><input type=checkbox name="cid[]" value="<?=$arr['productID']?>" class="NoStyle"></td>
		  <td valign="top">
		   Name: <strong><?=ucwords($memberRes['memberName']);?></strong>
		   <br/>Email: <strong><?=$memberRes['email'];?></strong>
		   <br/>Membership Type: <strong><?=getMembershipPlanName($memberRes['membershipType']);?></strong>
		  </td>
		  <td valign='top'>
		   <strong>Product Name</strong>: <?=$arr['productName'];?>
		   <br/><strong>Product Price</strong>: <?php echo $arr['productPrice'];
		   if ($arr['discountedPrice'] > 0) {
			   ?>
			   <br/><strong>Discounted Price</strong>: <?php echo $arr['discountedPrice'];
		   }
		   if ($arr['brandName'] != "") {
			   ?>
			   <br/><strong>Brand Name</strong>: <?php echo $arr['brandName'];
		   }
		   if ($arr['modelType'] != "") {
			   ?>
			   <br/><strong>Model Type</strong>: <?php echo $arr['modelType'];
		   }
		   if ($arr['availability'] == "Y") {
			   ?>
			   <br/><strong>Availability</strong>: Yes
			   <?php
		   }
		   else {
			   ?>
			   <br/><strong>Availability</strong>: No
			   <?php
		   }
		   ?>
		   <br/><strong>Main Category</strong>: <?=getCategoryName($arr['mainCategory']);?>
		   <br/><strong>Sub Categories</strong>: <?=getIndustryType($arr['industryType']);?>		   
		  </td>
		  <td valign="top" align="center">
		   <?php
		   if($arr['image1']!="") {
			   $file1=SITE_DIR_PATH."/uploaded_files/product_images/".$arr['image1'];
			   if(file_exists($file1)) {
				   $dimens=GetImageSize($file1);
				   if($dimens[0]>130) {
					   $dimens[0]=$dimens[0]+30;
					   $dimens[1]=$dimens[1]+80;
				   }
				   else{
					   $dimens[0]=200;
					   $dimens[1]=200;
				   }
				   ?>
				   <a href="javascript:void(0);" onClick="openwin('<?=SITE_ADMIN_URL;?>/popup.php?img=product_images/<?=$arr['image1'];?>', '<?=$dimens[0];?>', '<?=$dimens[1];?>')" class="linkgray fontbold"><strong>View</strong>
				   <?php
			   }
		   }
		   else {
			   ?>
			   <strong>No<br/>Image</strong>
			   <?php
		   }		   
		   ?>
		  </td>
		  <td valign='top'><?=show_date($arr['recvDate']);?></td>
		  <td valign='top' align="center">
		   <?php
		   if($arr['status']=='Y') {
			   ?>
			   <strong>Active</strong>
			   <?php
		   }
		   else if($arr['status']=='D') {
			   ?>
			   <strong>Deleted</strong>
			   <?php
		   }
		   else {
			   ?>
			   <strong>Inactive</strong>
			   <?php
		   }
		   ?>		   
		  </td>
		  <td valign='top'>
		   <?php		   
		   if($arr['status']=='Y') {
			   ?>
			   &nbsp;<a href="<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=deactivate&recordID=<?=$arr[productID];?>&start=<?=$start;?>&pagesize=<?=$pagesize?>"><img src="<?=SITE_ADMIN_URL?>/images/active.gif" alt="Deactivate This <?=$record_type;?>" title="Deactivate This <?=$record_type;?>" border="0"></a>
			   <?php
		   }
		   if($arr['status']=='N') {
			   ?>
			   &nbsp;<a href="<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=activate&recordID=<?=$arr[productID];?>&start=<?=$start;?>&pagesize=<?=$pagesize?>"><img src="<?=SITE_ADMIN_URL?>/images/deactive.gif" alt="Activate This <?=$record_type;?>" title="Activate This <?=$record_type;?>" border="0"></a>
			   <?php
		   }
		   if($arr['status'] != "D") {
			   ?>
			   &nbsp;<a href="javascript:void(0);" onclick="window.open('<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=View&recordID=<?=$arr[productID]?>&start=<?=$start?>&pagesize=<?=$pagesize?>','pop','height=550,width=550,scrollbars=yes,resizable=yes');"><img src="<?=SITE_ADMIN_URL?>/images/preview.gif" alt="View This <?=$record_type;?> Details" title="View This <?=$record_type;?> Details" border="0"></a>
			   <? if($arr['status']!='D') { ?>
			   &nbsp;<a href="<?=$script_name;?>?id=delete&recordID=<?=$arr[productID]?>&start=<?=$start?>&pagesize=<?=$pagesize?>" onClick="return confirm('Are you sure you want to delete this record')"><img src="<?=SITE_ADMIN_URL?>/images/cancel.gif" alt="Delete This <?=$record_type;?>" title="Delete This <?=$record_type;?>" border="0"></a>
			   <?php } ?>
			   
			   <br/><br/>
			   <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" valign="top">
			    <tr>
			     <td align="center">
			      <select name="featuredProduct<?=$arr[productID];?>" onchange="return submit_form2(this.value,'<?=$arr[productID];?>');">
			       <option value="">Set Product As</option>
			       <option value="Y" <? if($arr[featuredProduct]=="Y"){ echo "selected";}?>>Featured</option>
			       <option value="N">Unset Featured</option>
			      </select>			      			      
			     </td>
			    </tr>
			   </table>
			   
			   <br/><br/>
			   <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" valign="top">
			    <tr>
			     <td align="center">
			      <select name="expressProduct<?=$arr[productID];?>" onchange="return submit_form3(this.value,'<?=$arr[productID];?>');">
			       <option value="">Set Product As</option>
			       <option value="Y" <? if($arr[expressProduct]=="Y"){ echo "selected";}?>>Express</option>
			       <option value="N">Unset Express</option>
			      </select>			      			      
			     </td>
			    </tr>
			   </table>
			   <?php
		   }
		   ?>
		  </td>
		 </tr>
		 <?php
		 $sl++;
	 }
	 ?>
	 <tr>
	  <td colspan="5">
	   <input type="submit"  class="button" name="action" value="Delete"  onclick="return chkdelete();">
	   <input type="submit"  class="button" name="action" value="Activate"  onclick="return chkactivate();">
	   <input type="submit"  class="button" name="action" value="Deactivate"  onclick="return chkactivate();">
	   <input type="hidden" name="start" value="<?=$start;?>">
	   <input type="hidden" name="pagesize" value="<?=$pagesize;?>">
	  </td>
	 </tr>
	</table>
	</form><br>
	<?php
}
else {
	?>
	<table width="100%"  border="0" cellpadding="6" cellspacing="2" class="lightBorder">
	 <tr><td><strong>No Record Found.............</strong></td></tr>
	</table>
	<?php
}
?>
<table width="96%" align="center" cellpadding="0" cellspacing="0" border="0">
 <tr><td align="right"><input type="button" onclick="window.location.href='<?=SITE_ADMIN_URL;?>/<?=$script_name;?>?id=add_new#bot'" value="Add New <?=$record_type;?>" class="button"></td></tr>
</table>

<?php
/*
?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr>
	<td align="left" width="50%" class="myTitle"><?=$heading;?></td>
	<td align="right">
	 <form name="pgcolor_form" action="<?=$PHP_SELF?>" method="post" style="margin:0px;padding:0px;">
	 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="right">Records Per Page:
	    <select name="pagesize" onchange="this.form.submit();">
	     <option value="0">Select</option>
	     <?php
	     foreach($_GLOBALS[pgsize_arr] as $val) {
		     if(trim($pagesize)==trim($val)) {
			     echo '<option value="'.$val.'" selected>'.$val.'</option>';
		     }
		     else{
			     echo '<option value="'.$val.'">'.$val.'</option>';
		     }
	     }
	     ?>
	    </select>	    
		 </td>
		</tr>
	 </table>
	 </form>
	</td>
 </tr>
</table>
<hr size="2" width="99%" color="#DA251C">

 
<?php
$cond.=" and addedBy='".$_SESSION['MyAdminUserSLNO']."'";
$qry1= db_query("select * from $table_name where status!='D' $cond");
$reccnt = NumRows($qry1);
$qry= db_query("select * from $table_name where status!='D' $cond order by productID desc limit $start, $pagesize");
echo pageNavigation($reccnt,$pagesize,$start);
print_message();

if($reccnt>0){
	?>
	<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
	<table width="99%" border="0" cellpadding="2" cellspacing="2" class="lightBorder">
	 <tr height="25" bgcolor="#EAEAEA">
	  <td width="4%" align="left"><input type="checkbox" name="chk" onclick="CheckAll()" class="NoStyle"></td>
	  <td width="40%" align="left"><strong>Product Details</strong></td>
	  <td width="27%" align="left"><strong>Member Details</strong></td>
	  <td width="7%" align="center"><strong>Image</strong></td>
	  <td width="12%" align="left"><strong>Added On</strong></td>
	  <td width="10%" align="left"><strong>Options</strong></td>
	 </tr>
	 <?php
	 $sl=$start+1;
	 while ($arr=mysql_fetch_array($qry)) {
		 $arr=ms_htmlentities_decode($arr);
		 if($sl%2==0){
			 $color="f0f0f0";
		 }
		 else{
			 $color="f9f9f9";
		 }
		 ?>
		 <tr bgcolor="<?=$color;?>">
		  <td valign="top" align="left"><input type=checkbox name="cid[]" value="<?=$arr[productID]?>" class="NoStyle"></td>
		  <td valign="top" align="left">
		   Name: <span class="red"><?=ucwords($arr[productName]);?></span> <?=$status;?>
		   <br/>Product Price: <span class="red"><?=CURRENCY_SYMBOL;?><?=$arr[productPrice];?>.00</span>
		   <?php
		   if ($arr[discountedPrice] > 0) {
			   ?>
			   <br/>Discounted Price: <span class="red"><?=CURRENCY_SYMBOL;?><?=$arr[discountedPrice];?>.00</span>
			   <?php
		   }
		   if ($arr[brandName] != "") {
			   ?>
			   <br/>Brand Name: <span class="red"><?=$arr[brandName];?></span>
			   <?php
		   }
		   if ($arr[modelType] != "") {
			   ?>
			   <br/>Model Type: <span class="red"><?=$arr[modelType];?></span>
			   <?php
		   }
		   if ($arr[availability] == "Y") {
			   ?>
			   <br/>Availability: <span class="red">Yes</span>
			   <?php
		   }
		   else {
			   ?>
			   <br/>Availability: <span class="red">No</span>
			   <?php
		   }
		   ?>
		   <br/>Categories: <span class="red"><?=getCategoryName($arr['mainCategory']);?></span>
		   <br/>Sub Categories: <span class="red"><?=getIndustryType($arr['industryType']);?></span>
		  </td>
		  <td valign="top" align="left"></td>
		  <td valign="top" align="center">
		   <?php
		   if($arr['image1']!="") {
			   $file1=SITE_DIR_PATH."/uploaded_files/product_images/".$arr['image1'];
			   if(file_exists($file1)) {
				   $dimens=GetImageSize($file1);
				   if($dimens[0]>130) {
					   $dimens[0]=$dimens[0]+30;
					   $dimens[1]=$dimens[1]+80;
				   }
				   else{
					   $dimens[0]=200;
					   $dimens[1]=200;
				   }
				   ?>
				   <a href="javascript:void(0);" onClick="openwin('<?=SITE_ADMIN_URL;?>/popup.php?img=product_images/<?=$arr['image1'];?>', '<?=$dimens[0];?>', '<?=$dimens[1];?>')" class="linkgray fontbold"><strong>View</strong>
				   <?php
			   }
		   }
		   else {
			   ?>
			   <strong>No<br/>Image</strong>
			   <?php
		   }		   
		   ?>
		  </td>
		  <td valign="top" align="left"><?=show_date($arr['recvDate'])?></td>
		  <td valign="top" align="left">
		   <?php
		   if($arr['status']=='Y') {
			   ?>
			   &nbsp;<a href="<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=deactivate&recordID=<?=$arr[productID];?>&start=<?=$start;?>&pagesize=<?=$pagesize?>"><img src="<?=SITE_ADMIN_URL?>/images/active.gif" alt="Deactivate This <?=$record_type;?>" title="Deactivate This <?=$record_type;?>" border="0"></a>
			   <?php
		   }
		   if($arr['status']=='N') {
			   ?>
			   &nbsp;<a href="<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=activate&recordID=<?=$arr[productID];?>&start=<?=$start;?>&pagesize=<?=$pagesize?>"><img src="<?=SITE_ADMIN_URL?>/images/deactive.gif" alt="Activate This <?=$record_type;?>" title="Activate This <?=$record_type;?>" border="0"></a>
			   <?php
		   }
		   ?>
		   &nbsp;<a href="<?=$script_name;?>?id=edit_record&start=<?=$start;?>&recordID=<?=$arr[productID];?>#bot"><img src="<?=SITE_ADMIN_URL?>/images/edit.gif" alt="Edit This <?=$record_type;?>" title="Edit This <?=$record_type;?>" border="0"></a>
		   &nbsp;<a href="<?=$script_name;?>?id=delete&recordID=<?=$arr[productID]?>&start=<?=$start?>&pagesize=<?=$pagesize?>" onClick="return confirm('Are you sure you want to delete this record')"><img src="<?=SITE_ADMIN_URL?>/images/cancel.gif" alt="Delete This <?=$record_type;?>" title="Delete This <?=$record_type;?>" border="0"></a>
		  </td>
		 </tr>
		 <?php
		 $sl++;
	 }
	 ?>
	 <tr>
	  <td colspan="5">
	   <input type="submit"  class="button" name="action" value="Delete"  onclick="return chkdelete();">
	   <input type="submit"  class="button" name="action" value="Activate"  onclick="return chkactivate();">
	   <input type="submit"  class="button" name="action" value="Deactivate"  onclick="return chkactivate();">
	   <input type="hidden" name="start" value="<?=$start;?>">
	   <input type="hidden" name="pagesize" value="<?=$pagesize;?>">
	  </td>
	 </tr>
	</table><br>
	</form>
	<?php
}
else {
	?>
	<table width="100%"  border="0" cellpadding="6" cellspacing="2" class="lightBorder">
	 <tr><td><strong>No Record Found.............</strong></td></tr>
	</table>
	<?php
}
*/

echo $msg;

if ($id == "add_new" || $id == "edit_record") {
	?>
	<a name="bot"></a>
	<br/><br/>
	<form action="" name="add_new_product_form" method="post" enctype="multipart/form-data" onsubmit="return validate_add_new_product_form();">
	<table width="99%"  border="1" cellpadding="2" cellspacing="2" class="lightBorder">
	 <?php
	 if($recordID=="" || $id!="edit_record") {
		 ?>
		 <tr bgcolor="#EAEAEA"><td colspan="2" align="left" class="PadFive" height="20"><b><a name="bot">Add New <?=$record_type;?></a></b></td></tr>
		 <?php
	 }
	 else {
		 ?>
		 <tr bgcolor="#EAEAEA">
		  <td align="left" class="PadFive" height="20"><b>Edit <?=$record_type;?></b></td>
		  <td align="right" class="PadFive" height="20"><a href="<?=$script_name;?>"><b>Add New <?=$record_type;?></b></a></td>
		 </tr>
		 <?php
	 }
	 $productRes=getResult($table_name," where productID='$recordID'");
	 @extract($productRes);
	 $memberQry=db_query("select memberID, nameTitle, memberName, companyName, city, membershipType from member_tbl where status!='D' and addedBy='".$_SESSION['MyAdminUserSLNO']."'");
	 ?>
	 <tr><td colspan="2" align="right"><font color="red">*</font> fields are mandatory</td></tr>
	 <tr>
	  <td class="brdrbtm" valign="top"><b>Select Member</b></td>
	  <td class="brdrbtm" valign="top">
	   <select name="memberID" size="1" style="width:430px;">
	    <?php
	    while ($memberRes=mysql_fetch_array($memberQry)) {
			 $memberRes=ms_htmlentities_decode($memberRes);
			 if ($memberRes['membershipType'] == 4) {
				 $mem_type="FREE MEMBER";
			 }
			 if ($memberRes['membershipType'] == 3) {
				 $mem_type="SILVER MEMBER";
			 }
			 if ($memberRes['membershipType'] == 2) {
				 $mem_type="GOLD MEMBER";
			 }
			 if ($memberRes['membershipType'] == 1) {
				 $mem_type="PLATINUM MEMBER";
			 }
			 ?>
			 <option value="<?=$memberRes['memberID'];?>"><?=$memberRes['nameTitle'];?> <?=ucwords($memberRes['memberName']);?> (<?=$memberRes['companyName'];?>, <?=$memberRes['city'];?>) (<?=$mem_type;?>)</option>
			 <?php
		 }
		 ?>
	   </select>
	  </td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm" width="22%"><b>Product Name <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input type="text" name="productName" style="width:425px;" value="<?=$productName;?>" /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm" valign="top"><b>Product Photo</b></td>
	  <td class="brdrbtm" valign="top"><input name="image1" type="file" style="width:430px;" class="button" />
	   <?php
	   if($image!="") {
		   $file1=SITE_DIR_PATH."/uploaded_files/product_images/".$image;
		   if(file_exists($file1)) {
			   $dimens=GetImageSize($file1);
			   if($dimens[0]>130) {
				   $dimens[0]=$dimens[0]+50;
				   $dimens[1]=$dimens[1]+80;
			   }
			   else{
				   $dimens[0]=200;
				   $dimens[1]=200;
			   }
			   echo "&nbsp;<a href=\"javascript:void(0);\" onClick=\"openwin('".SITE_ADMIN_URL."/popup.php?img=product_images/".$image."', '$dimens[0]', '$dimens[1]')\" class=\"linkgray fontbold\"><b>View Image</b></a>"; 
		   }
	   }
	   ?>
	   <br/><strong>Image Size: Please upload square image for better view.</strong>
	  </td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"><b>Keyword <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input type="text" name="keyword" style="width:425px;" value="<?=$keyword;?>" /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Select Category <font color="red">*</font></b></td>
	  <td class="brdrbtm"><?=getListingCategoriesDropDownAjax("mainCategory",$mainCategory,"430");?></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"></td>
	  <td class="brdrbtm"><span id="showSubCategories"><?php if ($industryType) { echo getListingSubCategoriesDropDown("industryType", $mainCategory, $industryType, "430"); } ?></td>
	 </tr>
	 
	 <tr>
	  <td class="brdrbtm"><b>Price <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input type="text" name="productPrice" style="width:200px;" value="<?=$productPrice;?>" />&nbsp;<?=CURRENCY;?></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Discounted Price </b></td>
	  <td class="brdrbtm"><input type="text" name="discountedPrice" style="width:200px;" value="<?=$discountedPrice;?>" />&nbsp;<?=CURRENCY;?></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Minimum Order <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input type="text" name="minimumOrder" style="width:425px;" value="<?=$minimumOrder;?>" /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Payment Terms <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input type="text" name="paymentTerms" style="width:425px;" value="<?=$paymentTerms;?>" /></td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"><b>Availability <font color="red">*</font></b></td>
	  <td class="brdrbtm">
	   <select name="availability" size="1">
	    <option value="Y" <?php if ($availability == "Y") { echo 'selected="selected"'; } ?>>Yes</option>
	    <option value="N" <?php if ($availability == "N") { echo 'selected="selected"'; } ?>>No</option>
	   </select>
	  </td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"><b>Brand Name </b></td>
	  <td class="brdrbtm"><input type="text" name="brandName" style="width:425px;" value="<?=$brandName;?>" /></td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"><b>Model </b></td>
	  <td class="brdrbtm"><input type="text" name="modelType" style="width:425px;" value="<?=$modelType;?>" /></td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"><b>Delivery Time <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input type="text" name="deliveryTime" style="width:425px;" value="<?=$deliveryTime;?>" /></td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"><b>Description <font color="red">*</font></b></td>
	  <td class="brdrbtm"><textarea name="completeDescription" rows="7" style="width:427px;"><?=$completeDescription;?></textarea></td>
	 </tr> 
	 <tr>
	  <td class="brdrbtm"></td>
	  <td class="brdrbtm">
	   <?php
	   if($recordID!="") {
		   ?>
		   <input type="submit" name="submit" value="Update <?=$record_type;?>" class="button">
		   <input type="hidden" name="recordID" value="<?=$memberRes[productID];?>">
		   <input type="hidden" name="action" value="update_record">
		   <?php	   
	   }
	   else{
		   ?>
		   <input type="submit" name="submit" value="Add New <?=$record_type;?>" class="button">
		   <input type="hidden" name="action" value="add_record">
		   <?php
	   }
	   ?>   
	  </td>
	 </tr>
	</table>
	</form>
	<?php
}

admin_footer();
exit;
?>