<?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";
$record_type="Video";
$script_name="manage_categoryvideo.php";
$table_name="catvideo_tbl";
####################################################
if($id=="add_record") {
	$file_name_array = [];
	if(count($_FILES['image']) > 0){
		foreach($_FILES["image"]["tmp_name"] as $key=>$tmp_name) {
		    $file_name=$_FILES["image"]["name"][$key];
		    $file_tmp=$_FILES["image"]["tmp_name"][$key];
		    $ext=pathinfo($file_name,PATHINFO_EXTENSION);   
		    $filename=basename($file_name,$ext);
		    $newFileName=$filename.time().".".$ext;
		    move_uploaded_file($file_tmp=$_FILES["image"]["tmp_name"][$key],"../uploaded-files/product-images/".$newFileName);
		    array_push($file_name_array, $newFileName);
		}
		$file_name1 = implode(',', $file_name_array);
	}
	
		$sql=db_query("insert into $table_name set product_title='$ptitle', product_code='$pcode', product_image='$file_name1', product_alt='$palt', product_desc='$cdesc', product_metatitle='$cmtitle', product_metadesc='$cmdesc', 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', 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(isset($_REQUEST['id']) && $_REQUEST['id']=='delete'){

	$name = $_REQUEST['name'];
	$cat_id = $_REQUEST['cat_id'];
	$delete_sql = mysql_query("SELECT * FROM $table_name WHERE product_id='$cat_id'");
	$result = mysql_fetch_array($delete_sql);
	if(count($result) > 0){
		$image_array = explode(',',$result['product_image']);
		if(in_array($name, $image_array)){
			$new_array = array_diff($image_array, [$name]);
			$file_name = implode(',',$new_array);
			$table = mysql_query("UPDATE $table_name SET product_image='$file_name' WHERE product_id='$cat_id'");
		}	
	}
	
}
if($id=="update_record") {
		$prod_sql = mysql_query("SELECT * FROM $table_name where product_id='$recordID'");
		$prod_res = mysql_fetch_array($prod_sql);
		if(count($prod_res) > 0){
			$file_name_array = [];
if(count($_FILES['image']) > 0){
		foreach($_FILES["image"]["tmp_name"] as $key=>$tmp_name) {
		    $file_name=$_FILES["image"]["name"][$key];
		    $file_tmp=$_FILES["image"]["tmp_name"][$key];
		    $ext=pathinfo($file_name,PATHINFO_EXTENSION);   
		    $filename=basename($file_name,$ext);
		    $newFileName=$filename.date('s').".".$ext;
		    move_uploaded_file($file_tmp=$_FILES["image"]["tmp_name"][$key],"../uploaded-files/product-images/".$newFileName);
		    array_push($file_name_array, $newFileName);
		}

		$file_name1 = implode(',', $file_name_array);
		$file_array = explode(',',$prod_res['product_image']);
			$new_array = array_merge($file_array, $file_name_array);
			$file_name1 = implode(',', $new_array);	
			mysql_query("UPDATE $table_name SET product_image='$file_name1' WHERE product_id='$recordID'");
	}

		
			
		}

		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', 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;
	}
	
	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;
}
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 table table-bordered table-hover">
 <?php
 if($reccnt>0) {
	 ?>
	 <tr height="25" bgcolor="#EAEAEA">
	 <td width="5%" align="center"><strong style="
    color: #468cd2;">S.No.</strong></td>
	 <td width="10%" align="left"><strong style="
    color: #468cd2;">Video url</strong></td>
<!--
	 <td width="10%" align="left"><strong style="
    color: #468cd2;">Product Code</strong></td>
-->
<!--
	 <td width="20%" align="center"><strong style="
    color: #468cd2;">Product Image</strong></td>
-->
	 <td width="10%" align="left"><strong style="
    color: #468cd2;">Category</strong></td>
	 <td width="10%" align="left"><strong style="
    color: #468cd2;">Options</strong></td>
	 </tr>
	 <?php
	 $sl=$start+1;
	 while($arr=mysql_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['product_code'];
		  ?>
		</td>
-->
<!--
		<td align="center">
		<?php
	   if($arr['product_image']!="") {
		   $file1=SITE_DIR_PATH."/uploaded_files/product_images/".$arr['product_image'];
		   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['product_image'];?>', '<?=$dimens[0];?>', '<?=$dimens[1];?>')" class="linkgray fontbold"><strong>View Image</strong>
			   <?php
		   }
	   }

	   ?>	
		</td>
-->
		<td align="center">
		 <?
		 $cct=$arr[product_cat];
		 $sql_cat=mysql_query("select * from category_tbl where catID='$cct'");
         $res_cat=mysql_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"><i class="fa fa-edit"></i></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...');"><i class="fa fa-trash"></i></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]'");
 ?>

<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 category_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>
<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>
<!--<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 gal_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>-->
<!--
<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 gal_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>-->

<tr>
<td class="brdrbtm"><b>Embeded video URL <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~" required/></td>
</tr> 
<!--
<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> 
-->
<!--
<tr>
<td class="brdrbtm"><b>Product Alt <font color="red">*</font></b></td>
<td class="brdrbtm"><input type="text" name="palt" size="60" value="<?=$res[product_alt];?>" id="NOBLANK~Please enter Person Name.~DM~" /></td>
</tr> 
-->

<!--
<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> 
-->
<!--
<tr>
<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> 
-->
<!--
<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> 
-->
<!--
<tr>
<td class="brdrbtm"><b>Product Desc<font color="red">*</font></b></td>
<td class="brdrbtm"><textarea rows="10" cols="50" name="cdesc"><?=$res[product_desc];?></textarea></td>
</tr>
<tr>
-->
<!--
<td class="brdrbtm"><b>Meta Title<font color="red">*</font></b></td>
<td class="brdrbtm"><textarea rows="10" cols="50" name="cmtitle"><?=$res[product_metatitle];?></textarea></td>
</tr>
-->
<!--
<tr>
<td class="brdrbtm"><b>Meta Desc<font color="red">*</font></b></td>
<td class="brdrbtm"><textarea rows="10" cols="50" name="cmdesc"><?=$res[product_metadesc];?></textarea></td>
</tr>
-->
<!--
<tr>
<td class="brdrbtm"><b>Meta Keyword<font color="red">*</font></b></td>
<td class="brdrbtm"><textarea rows="10" cols="50" name="cmkey"><?=$res[product_metakeyword];?></textarea></td>
</tr>
-->

<!--
<tr>
<td class="brdrbtm"><b>Multiple Image<font color="red">*</font></b></td>
<td class="brdrbtm"><input type="file" name="image[]" multiple size="60" value="" id="NOBLANK~Please enter Person Name.~DM~" /><?php
if($res[product_image]!=""){
	$image_array = explode(',', $res['product_image']);?>
	
	<div class="display-img">
	<ul>
	<?php foreach($image_array as $image){?>
				<li>
					
						
							<img src="<?= SITE_URL_PATH ?>/uploaded-files/product-images/<?= $image ?>">
					
						<div class="card-footer">
							<a href="?id=delete&name=<?= $image ?>&cat_id=<?= $res[product_id] ?>" onclick="confirm('Do you want to delete the image?')">Delete</a>
						</div>
				
				</li>
			<?php } ?>
	</ul>
</div>
<?php } ?>

</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: "ajax9910.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>
<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="<?=SITE_URL_PATH;?>/js/calendar/themes/Normal/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>
<?php
admin_footer();
exit;
?>