<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');
?>
<script type="text/javascript">
function chk_valid_date() {
	if (document.bannerFrm.validFrom.value==0) {
		alert("Please select Validity Period");
		return false;
	}
	if (document.bannerFrm.validTo.value==0) {
		alert("Please select Validity Period");
		return false;
	}
}
</script>
<?php
################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)<0 or $start=="")?0:$start;
$pagesize = intval($pagesize)==0?$pagesize=20:$pagesize;

$heading="Manage Video Gallery";
$record_type="Video Gallery";
$script_name="manage_videogallery.php";
$table_name="videogallery_tbl";
####################################################
if($id=="add_record") {

if($_FILES[pimage][name]!=""){
			$file_extension=strtolower(getExtension($_FILES[pimage][name]));
			if($file_extension!="jpg" && $file_extension!="gif" && $file_extension!="jpeg" && $file_extension!="png"){
				$_SESSION[session_message]='Please upload image (.jpg,.gif,.png Format Only)';
			/*	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);*/
				
                
               $redirect_url = SITE_ADMIN_URL."/".$redirect_script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize;
        echo "<script>window.location.href='$redirect_url';</script>";
        exit;
                
			}
			if($_FILES[pimage][name]!=""){
				$img_name=$ptitle;
				$img=upload_file($img_name,"pimage","uploaded_files/pgal_images");	
				
				$width="250";
				$height="250";
				$source_folder=SITE_DIR_PATH."/uploaded_files/pgal_images/";
				$destination_folder=SITE_DIR_PATH."/uploaded_files/pgal_images/thumbs/";
				saveResizedImage($img, $width, $height, $source_folder, $destination_folder);			
			}
		}
	
		$sql=db_query("insert into $table_name set product_title='$ptitle', product_code='$pcode', product_image='$img', product_alt='$palt', product_desc='$cdesc', product_metatitle='$cmtitle', product_metadesc='$cmdesc', product_min_order='$pminorder', product_supply='$psupply', product_swearType='$pswearType',vurl='$vurl', product_supplyType='$psupplyType', product_Gender='$pgenser', product_ageGroup='$pagegroup', product_size='$psize', product_origin='$porigin', product_pterms='$pterms', product_price='$pprice', product_metakeyword='$cmkey', product_cat='$cat', prodcut_subcat='$subcat', product_subsubcat='$subsubcat', product_finalcat='$finalcat', prodcut_status='1', product_date=now() ");
		
		
		$_SESSION[session_message]='New '.$record_type.' has been added 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($id=="update_record") {


if($_FILES[pimage][name]!=""){
		$file_extension=strtolower(getExtension($_FILES[pimage][name]));
		if($file_extension!="jpg" && $file_extension!="gif" && $file_extension!="jpeg" && $file_extension!="png"){
			$_SESSION[session_message]='Please upload image (.jpg,.gif,.png Format Only)';
			/*header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
			exit;*/
            $redirect_url = SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize;
        echo "<script>window.location.href='$redirect_url';</script>";
            exit;
		}
		if($_FILES[pimage][name]!=""){
			$categoryRes=getResult($table_name," where product_id='$recordID'","product_image");
			$filename=$categoryRes['product_image'];
			if($filename!="") {
				$file=SITE_DIR_PATH."/uploaded_files/pgal_images/".$filename;
				if(file_exists($file)) {
					unlink($file);
				}
				
				$file_thumb=SITE_DIR_PATH."/uploaded_files/pgal_images/thumbs/".$filename;
				if(file_exists($file_thumb)) {
					unlink($file_thumb);
				}
			}
			
			$img_name=$ptitle;
			$img=upload_file($img_name,"pimage","uploaded_files/pgal_images");
			updateTable($table_name," product_image='$img' where product_id='$recordID'");
			
			$width="250";
			$height="250";
			$source_folder=SITE_DIR_PATH."/uploaded_files/pgal_images/";
			$destination_folder=SITE_DIR_PATH."/uploaded_files/pgal_images/thumbs/";
			saveResizedImage($img, $width, $height, $source_folder, $destination_folder);
		}
	}

		updateTable($table_name,"product_title='$ptitle', product_code='$pcode', product_alt='$palt', product_desc='$cdesc', product_metatitle='$cmtitle', product_metadesc='$cmdesc', product_metakeyword='$cmkey', product_cat='$cat', prodcut_subcat='$subcat',vurl='$vurl', product_subsubcat='$subsubcat', product_finalcat='$finalcat', product_min_order='$pminorder', product_supply='$psupply', product_swearType='$pswearType', product_supplyType='$psupplyType', product_Gender='$pgenser', product_ageGroup='$pagegroup', product_size='$psize', product_origin='$porigin', product_pterms='$pterms', product_price='$pprice' where product_id='$recordID'");
		
		$_SESSION[session_message]=$record_type.' has been updated successfully';
		/*header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;*/
    $redirect_url = SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize;
        echo "<script>window.location.href='$redirect_url';</script>";
            exit;
	}
	
	else {
		$msg=html_head();
		$msg.=$form_check_alert;
		$msg.=html_foot();
	}	
if($id=="delete_record") {
	db_query("delete from $table_name where product_id='$recordID'");
	$_SESSION[session_message]=$record_type.' has been deleted successfully';
	/*header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;*/
     $redirect_url = SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize;
        echo "<script>window.location.href='$redirect_url';</script>";
            exit;
}

if($id=="set_hot") {
	db_query("update $table_name set product_hot='1' where product_id='$recordID'");
	$_SESSION[session_message]=$record_type.' has been set hot successfully';
	/*header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;*/
     $redirect_url = SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize;
        echo "<script>window.location.href='$redirect_url';</script>";
            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="pgimg_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
$qry1= db_query("select * from $table_name");
$reccnt = NumRows($qry1);
$qry= db_query("select * from $table_name order by product_id desc limit $start, $pagesize");
echo pageNavigation($reccnt,$pagesize,$start);
print_message();
?>

<table width="99%" border="0" cellpadding="2" cellspacing="2" class="lightBorder">
 <?php
 if($reccnt>0) {
	 ?>
	 <tr height="25" bgcolor="#EAEAEA">
	 <td width="5%" align="center"><strong>S.No.</strong></td>
	 <td width="10%" align="left"><strong> Title</strong></td>
	
	 <td width="20%" align="center"><strong>Video URL</strong></td>
<!--	 <td width="10%" align="left"><strong>Category</strong></td>-->
	
	 <td width="10%" align="left"><strong>Options</strong></td>
	 </tr>
	 <?php
	 $sl=$start+1;
	 while($arr=mysqli_fetch_array($qry)) {
		 $arr=ms_htmlentities_decode($arr);
		 if($sl%2!=0) {
			 $color="#f9f9f9";
		 }
		 else{
			 $color="#f0f0f0";
		 }
		 ?>		 
		  <tr bgcolor="<?=$color;?>">
		  <td align="center"><?=$sl;?></td>
		  <td align="left">
		  <?
		  echo $arr['product_title'];
		  ?>
		  </td>
		 
		<td align="center">
			 <?
		  echo $arr['vurl'];
		  ?>
		</td>
<!--
		<td align="center">
		 <?
		 $cct=$arr[product_cat];
		 $sql_cat=mysqli_query($GLOBALS['dbcon'], "select * from gal_tbl where catID='$cct'");
         $res_cat=mysqli_fetch_array($sql_cat);
		 echo $res_cat['catName'];
         ?>
		</td>
-->
		
		<td align="center">&nbsp;<a href="<?=$script_name;?>?id=edit_record&start=<?=$start;?>&pagesize=<?=$pagesize?>&recordID=<?=$arr[product_id];?>#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_record&start=<?=$start;?>&pagesize=<?=$pagesize?>&recordID=<?=$arr[product_id];?>" onClick="return confirm('Are you sure to delete this record...');"><img src="<?=SITE_ADMIN_URL?>/images/cancel.gif" alt="Delete This <?=$record_type;?>" border="0">
		
	
		</td>
		</tr>
		<?php
		$sl++;
	 }
     }
 else{
	 ?>
	 <tr><td><b>No Record Found........</b></td></tr>
	 <?php
 }
 ?>
</table><br />

<form name="bannerFrm" method=post action="" enctype="multipart/form-data" onsubmit="return validate('bannerFrm') && chk_valid_date();">
<table width="99%"  border="1" cellpadding="2" cellspacing="2" class="lightBorder">
 <?php
 if($_GET[recordID]=="" || $id!="edit_record") {
	 ?>
	 <tr bgcolor="#EAEAEA"><td colspan="2" align="left" height="20"><b><a name="bot">Add New <?=$record_type;?></a></b></td></tr>
	 <?php
 }
 else {
	 ?>
	 <tr bgcolor="#EAEAEA">
	  <td align="left" height="20"><a name="bot"></a><b>Edit <?=$record_type;?></b></td>
	  <td align="right" height="20"><a href="<?=$script_name;?>"><b>Add New <?=$record_type;?></b></a></td>
	 </tr>
	 <?php
 }
 $res=getResult($table_name," where product_id='$_GET[recordID]'");
 ?>

<?php /*?><tr>
<td class="brdrbtm"><b>Select Category <font color="red">*</font></b></td>
<td class="brdrbtm"><select name="cat" id="quickCity">
<option>Select Category</option>
<?php
$sql_cat=mysql_query("select * from gal_tbl where parentID='0'");
while ($res_cat=mysql_fetch_array($sql_cat))
{
?>
<option value="<?php echo $res_cat['catID']; ?>" <? if ($res[product_cat]==$res_cat[catID]) { echo "selected"; }?>><?php echo $res_cat['catName']; ?></option>
<?php
}
?></select></td>
</tr><?php */?>
<?php /*?><tr>
<td class="brdrbtm"><b>Select Sub Category <font color="red">*</font></b></td>
<td class="brdrbtm"><select name="subcat" id="locatity">
  <?php
 $sql_tl=mysql_query("select * from category_tbl where parentID='$res[product_cat]' and parentID!=''");
 if(mysql_num_rows($sql_tl) > 0)
 {
 while($qq_res=mysql_fetch_array($sql_tl))
 {
?>
  <option value="<?php echo $qq_res['catID'];?>" <? if ($res[prodcut_subcat]==$qq_res[catID]) { echo "selected"; }?>><?php echo $qq_res['catName'];?></option>
  <?php
 }
 }
?>
</select></td>
</tr><?php */?>
<?php /*?><tr>
<td class="brdrbtm"><b>Select Sub Sub Category <font color="red">*</font></b></td>
<td class="brdrbtm"><select name="subsubcat" id="asd">
<?php
 $sql_tl=mysql_query("select * from category_tbl where parentID='$res[prodcut_subcat]' and parentID!=''");
 if(mysql_num_rows($sql_tl) > 0)
 {

 while($qq_res=mysql_fetch_array($sql_tl))
 {
 ?>
 <option value="<?php echo $qq_res['catID'];?>" <? if ($res[product_subsubcat]==$qq_res[catID]) { echo "selected"; }?>><?php echo $qq_res['catName'];?></option>
 <?php
 }
 }
 ?>
</select></td>
</tr><?php */?>
<?php /*?><tr>
<td class="brdrbtm"><b>Select Final Category <font color="red">*</font></b></td>
<td class="brdrbtm"><select name="finalcat" id="asd1">
<?php
 $sql_tl=mysql_query("select * from category_tbl where parentID='$res[product_subsubcat]' and parentID!=''");
 if(mysql_num_rows($sql_tl) > 0)
 {
 while($qq_res=mysql_fetch_array($sql_tl))
 {
 ?>
 <option value="<?php echo $qq_res['catID'];?>" <? if ($res[product_finalcat]==$qq_res[catID]) { echo "selected"; }?>><?php echo $qq_res['catName'];?></option>
 <?php
 }

 }
 ?>
</select></td>
</tr><?php */?>

<tr>
<td class="brdrbtm"><b>Title <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="ptitle" size="60" value="<?=$res[product_title];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
	
	<tr>
<td class="brdrbtm"><b>Youtube Video Link (only paste id of video URL) <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="vurl" size="60" value="<?=$res[vurl];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr>
<?php /*?><tr>
<td class="brdrbtm"><b>Product Code <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="pcode" size="60" value="<?=$res[product_code];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr><?php */?> 


<?php /*?><tr>
<td class="brdrbtm"><b>Min. Order Quantity <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="pminorder" size="60" value="<?=$res[product_min_order];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> <?php */?>
<?php /*?><td class="brdrbtm"><b>Supply Ability <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="psupply" size="60" value="<?=$res[product_supply];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
<tr>
<td class="brdrbtm"><b>Sportswear Type<font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="pswearType" size="60" value="<?=$res[product_swearType];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
<tr>
<td class="brdrbtm"><b>Supply Type <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="psupplyType" size="60" value="<?=$res[product_supplyType];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
<tr>
<td class="brdrbtm"><b>Gender <font color="red">*</font></b></td>
<td class="brdrbtm">

<select name="pgenser">
<option value="1" <?php if($res[product_Gender] =='1') { echo "Selected"; } ?>>Men</option>
<option value="2" <?php if($res[product_Gender] =='2') { echo "Selected"; } ?>>Women</option>
</select>

</td>
</tr><?php */?> 
<?php /*?><tr>
<td class="brdrbtm"><b>Age Group <font color="red">*</font></b></td>
<td class="brdrbtm">

<select name="pagegroup">
<option value="1" <?php if($res[product_ageGroup] =='1') { echo "Selected"; } ?>>Adult</option>
<option value="2" <?php if($res[product_ageGroup] =='2') { echo "Selected"; } ?>>Child</option>
</select>

</td>
</tr> 
<tr>
<td class="brdrbtm"><b>Size <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="psize" size="60" value="<?=$res[product_size];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
<tr>
<td class="brdrbtm"><b>Place of Origin <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="porigin" size="60" value="<?=$res[product_origin];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
<tr>
<td class="brdrbtm"><b>Payment Terms <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="pterms" size="60" value="<?=$res[product_pterms];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
<tr>
<td class="brdrbtm"><b>FOB Price (US$ )<font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="pprice" size="60" value="<?=$res[product_price];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr><?php */?>
<!--

<tr>
<td class="brdrbtm"><b> Image<font color="red">*</font></b></td>
<td class="brdrbtm"><input type="file" name="pimage" size="60" value="" id="NOBLANK~Please enter Person Name.~DM~" /></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="<?=$res[product_id];?>">
	   <input type="hidden" name="id" value="update_record">
	   <?php	   
   }
   else{
	   ?>
	   <input type="submit" name="submit" value="Add New <?=$record_type;?>" class="button">
	   <input type="hidden" name="id" value="add_record">
	   <?php
   }
   ?>
   <input type="hidden" name="start" value="<?=$start;?>">
   <input type="hidden" name="pagesize" value="<?=$pagesize;?>"></td>
</tr>
</table>
</form>
<link rel='stylesheet' href='calendar.css' title='calendar'>
<script language="javascript" src="calendar.js"></script>
<script src="jquery.min.js"></script>
<script type="text/javascript">

                    $("#quickCity").change(function(){	

                            var cityid  =  $('#quickCity').val();

                           $.ajax({   

                                url: "ajax99.php", //The url where the server req would we made.

                                async: false,

                                type: "POST", //The type which you want to use: GET/POST

                                data: "cityid="+cityid, //The variables which are going.

                                dataType: "html", //Return data type (what we expect).

                                //This is the function which will be called if ajax call is successful.

                                success: function(data) {

                                    //data is the html of the page where the request is made.

                                    $('#locatity').html(data);

                                }

                            })

                });
				
				 

        </script>
		<script type="text/javascript">

		
		$("#locatity").change(function(){	

                            var locatityid  =  $('#locatity').val();

                           $.ajax({   

                                url: "ajax999.php", //The url where the server req would we made.

                                async: false,

                                type: "POST", //The type which you want to use: GET/POST

                                data: "locatityid="+locatityid, //The variables which are going.

                                dataType: "html", //Return data type (what we expect).

                                //This is the function which will be called if ajax call is successful.

                                success: function(data) {

                                    //data is the html of the page where the request is made.

                                    $('#asd').html(data);

                                }

                            })

                });

</script>
<script type="text/javascript">

		
		$("#asd").change(function(){	

                            var asdid  =  $('#asd').val();

                           $.ajax({   

                                url: "ajax9999.php", //The url where the server req would we made.

                                async: false,

                                type: "POST", //The type which you want to use: GET/POST

                                data: "asdid="+asdid, //The variables which are going.

                                dataType: "html", //Return data type (what we expect).

                                //This is the function which will be called if ajax call is successful.

                                success: function(data) {

                                    //data is the html of the page where the request is made.

                                    $('#asd1').html(data);

                                }

                            })

                });

</script>
<?php
admin_footer();
exit;
?>