<?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 Sub Domain";

$record_type="content";

$script_name="manage_scontent.php";

$table_name="subcontent_tbl";

####################################################

if($id=="add_record") {



	 $all_categories=implode("^",$locality);

	 	$all_cat=implode("^",$cat);

		$all_subcat=implode("^",$subcat);

		$all_finalcat=implode("^",$subsubcat);
    
    $all_finalcats=implode("^",$subsubsubcat);
    

	$sql=db_query("insert into $table_name set subcontent_cat='$all_cat', subcontent_subcat='$all_subcat', subcontent_desc='$cdesc', short_desc='$sdesc', subcontent_metatitle='$cmtitle', subcontent_mrtakey='$cmkey', subcontent_metadesc='$cmdesc', product_subsubcat='$all_finalcat', product_finalcat='$finalcat', location='$cat_location',product_subsubsubcat='$all_finalcats'");

	

	$_SESSION[session_message]='New '.$record_type.' has been added successfully';

	//header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);

	$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=="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);


			$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/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);

				}

			}

			

			$img_name=$ptitle.date("d_m_Y_H_i_s");

			$img=upload_file($img_name,"pimage","uploaded_files/product_images");

			updateTable($table_name," product_image='$img' where product_id='$recordID'");

			

			$width="100";

			$height="100";

			$source_folder=SITE_DIR_PATH."/uploaded_files/product_images/";

			$destination_folder=SITE_DIR_PATH."/uploaded_files/product_images/thumbs/";

			saveResizedImage($img, $width, $height, $source_folder, $destination_folder);

		}

	}



	 	$all_cat=implode("^",$cat);

		$all_subcat=implode("^",$subcat);

		$all_finalcat=implode("^",$subsubcat);
    
        $all_finalcats=implode("^",$subsubsubcat);




		updateTable($table_name,"subcontent_cat='$all_cat', subcontent_subcat='$all_subcat', subcontent_desc='$cdesc', short_desc='$sdesc', subcontent_metatitle='$cmtitle', subcontent_mrtakey='$cmkey', subcontent_metadesc='$cmdesc', product_subsubcat='$all_finalcat',product_subsubsubcat='$all_finalcats', product_finalcat='$finalcat', location='$cat_location' where subcontent_id='$recordID'");

		

		$_SESSION[session_message]=$record_type.' has been updated successfully';

		//header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);

		$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 subcontent_id='$recordID'");

	$_SESSION[session_message]=$record_type.' has been deleted successfully';

	//header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);

	$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 subcontent_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="6%" align="center"><strong>S.No.</strong></td>

	 <td width="10%" align="left"><strong>Category</strong></td>

	 <td width="20%" align="left"><strong>Sub Category</strong></td>

	 <td width="23%" align="center"><strong>Sub Sub Category</strong></td>

	 <td width="22%" align="left"><strong>Desc</strong></td>

	 <td width="12%" align="left"><strong>Location</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">

		  

		  <?

		 $cct=$arr['subcontent_cat'];

		 $sql_cat=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where catID='$cct'");

         $res_cat=mysqli_fetch_array($sql_cat);

		 echo $res_cat['catName'];

         ?>		  </td>

		  <td align="center">		

		   <?

		 $cct=$arr['subcontent_subcat'];

		 //echo "select * from category_tbl where parentID='$res_cat[cat]' and parentID!=''";

		 $sql_cat=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where catID='$cct'");

         $res_cat=mysqli_fetch_array($sql_cat);

		 echo $res_cat['catName'];

         ?>		 

		  

		  

		  </td>

		  <td align="center">	

		  <?

		 $cct=$arr['product_subsubcat'];

		 //echo "select * from category_tbl where parentID='$res_cat[cat]' and parentID!=''";

		 $sql_cat=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where catID='$cct'");

         $res_cat=mysqli_fetch_array($sql_cat);

		 echo $res_cat['catName'];

         ?>		 

		  </td>

		  

		  <td align="center">

		 <?

		  echo $arr['subcontent_desc'];

		  ?>

		  

		  <td align="center">

		  

		 <?php

		 $ccty=$arr['location'];

		 //echo "select * from location_tbl where locationID='$ccty";

		 $sql_caty=mysqli_query($GLOBALS['dbcon'],"select * from location_tbl where locationID='$ccty'");

         $res_caty=mysqli_fetch_array($sql_caty);

		 echo $res_caty['locationName'];

		  ?>

		  		</td>

				

						</td>

		<td align="center">&nbsp;<a href="<?=$script_name;?>?id=edit_record&start=<?=$start;?>&pagesize=<?=$pagesize?>&recordID=<?=$arr[subcontent_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[subcontent_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">

<tbody style="float:left; width:100%;">

 <?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" style="float:left; width:100%;" >

	  <td width="29%" height="20" align="left"><a name="bot"></a><b>Edit <?=$record_type;?></b></td>

	  <td width="71%" height="20" align="right"><a href="<?=$script_name;?>"><b>Add New <?=$record_type;?></b></a></td>

	 </tr>

	 <?php

 }

 $res=getResult($table_name," where subcontent_id='$_GET[recordID]'");

 ?>







<?php



$sql_cat=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where parentID='0'");

while ($res_cat=mysqli_fetch_array($sql_cat))

{

$cate=$res[subcontent_cat];

$l_cat_id=explode("^",$cate);

(in_array($res_cat[catID],$l_cat_id))?$bsel="checked":$bsel='';

static $i=0;

?>

<tr style="float:left; width:100%; padding:0 2px;">

<td style="float:left; width:99%; ">

<br>-

<input type="checkbox" name="cat[]" id="chek<?=$i?>" <?=$bsel?> value="<?php echo $res_cat['catID']; ?>"><?php echo $res_cat['catName']; ?><br>

<?php

//echo "select * from category_tbl where parentID='$res_cat[cat]' and parentID!=''";

$sql_tl=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where parentID='$res_cat[catID]' and parentID!=''");

if(mysqli_num_rows($sql_tl) > 0)

{

?>



<?php

while($qq_res=mysqli_fetch_array($sql_tl))

{

$subcate=$res[subcontent_subcat];

$l_subcat_id=explode("^",$subcate);

(in_array($qq_res[catID],$l_subcat_id))?$bsel="checked":$bsel='';

static $i=0;	

?>
<br>--
<input type="checkbox" name="subcat[]" id="chek<?=$i?>" <?=$bsel?> value="<?php echo $qq_res['catID']; ?>"><?php echo $qq_res['catName'];?>

<?php

$sql_tls=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where parentID='$qq_res[catID]' and parentID!=''");

if(mysqli_num_rows($sql_tls) > 0)

{

?>

<br>---

<?php

while($qq_ress=mysqli_fetch_array($sql_tls))

{

$subsubcate=$res[product_subsubcat];

$l_subsubcat_id=explode("^",$subsubcate);

(in_array($qq_ress[catID],$l_subsubcat_id))?$bsel="checked":$bsel='';

static $i=0;

?>

<input type="checkbox" name="subsubcat[]" id="chek<?=$i?>" <?=$bsel?> value="<?php echo $qq_ress['catID']; ?>"><?php echo $qq_ress['catName'];?>
    <?php

$sql_tlss=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where parentID='$qq_ress[catID]' and parentID!=''");

if(mysqli_num_rows($sql_tlss) > 0)

{

?>

<br>----
    <?php

while($qq_resss=mysqli_fetch_array($sql_tlss))

{

$subsubcates=$res[product_subsubsubcat];

$l_subsubcat_ids=explode("^",$subsubcates);

(in_array($qq_resss[catID],$l_subsubcat_ids))?$bsel="checked":$bsel='';

static $i=0;

?>
    <input type="checkbox" name="subsubsubcat[]" id="chek<?=$i?>" <?=$bsel?> value="<?php echo $qq_resss['catID']; ?>"><?php echo $qq_resss['catName'];?>


<?php
}
}
}

}

}

}

?>

<br>

<hr>

</td>

</tr>



<?php

}

?>





<tr>

<td class="brdrbtm"><b>Select Location <font color="red">*</font></b></td>

<td class="brdrbtm"><select name="cat_location" id="quickCity">

<option value="">Select Location</option>

<?php

$res=getResult($table_name," where subcontent_id='$_GET[recordID]'");

$sql_cat=mysqli_query($GLOBALS['dbcon'],"select * from location_tbl where parentID='0' order by locationName asc");

while ($res_cat=mysqli_fetch_array($sql_cat))

{

?>

<option value="<?php echo $res_cat['locationID']; ?>" <? if ($res[location]==$res_cat[locationID]) { echo "selected"; }?>><?php echo $res_cat['locationName']; ?></option>

<?php

}

?></select></td>

</tr>











<tr>

<td class="brdrbtm"><b>Description <br />[Product Name - catname]<br /> [Country Name - countryname ] <font color="red">*</font></b></td>

<td class="brdrbtm"><textarea rows="10" cols="50" name="cdesc" id="cdesc"><?=$res[subcontent_desc];?></textarea>



<script type="text/javascript">

	var oFCKeditor=new FCKeditor('cdesc');

	oFCKeditor.BasePath="fckeditor/";

	oFCKeditor.Width="600px";

	oFCKeditor.Height="400px";

	oFCKeditor.ReplaceTextarea();

	</script>



</td>

</tr>

<tr>

<td class="brdrbtm"><b>Short Desc <br />[Product Name - catname]<br /> [Country Name - countryname ] <font color="red">*</font></b></td>

<td class="brdrbtm"><textarea rows="10" cols="50" name="sdesc"><?=$res[short_desc];?></textarea></td>

</tr>

<tr>

<td class="brdrbtm"><b>Meta Title <br />[Product Name - catname]<br /> [Country Name - countryname ] <font color="red">*</font></b></td>

<td class="brdrbtm"><textarea rows="10" cols="50" name="cmtitle"><?=$res[subcontent_metatitle];?></textarea></td>

</tr>

<tr>

<td class="brdrbtm"><b>Meta Desc <br />[Product Name - catname]<br /> [Country Name - countryname ] <font color="red">*</font></b></td>

<td class="brdrbtm"><textarea rows="10" cols="50" name="cmdesc"><?=$res[subcontent_metadesc];?></textarea></td>

</tr>

<tr>

<td class="brdrbtm"><b>Meta Keyword <br />[Product Name - catname]<br /> [Country Name - countryname ] <font color="red">*</font></b></td>

<td class="brdrbtm"><textarea rows="10" cols="50" name="cmkey"><?=$res[subcontent_mrtakey];?></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="<?=$res[subcontent_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>

</tbody>

</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 parentID  =  $('#quickCity').val();



                           $.ajax({   



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



                                async: false,



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



                                data: "parentID="+parentID, //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">



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



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



                           $.ajax({   



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



                                async: false,



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



                                data: "cityyid="+cityyid, //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.



                                    $('#locatityy').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;

?>