<? require_once("../includes/main.inc.php");
/**for activate delete and deactivate Current Updates**/
if(isset($_REQUEST['arr_page_ids'])){
	$arr_page_ids = $_REQUEST['arr_page_ids'];
	if(is_array($arr_page_ids)){
		$arr_page_ids = implode(',', $arr_page_ids);
		if(isset($_REQUEST['Delete'])){
			
			$qrr=mysql_query("select sv_image from  tbl_content where page_id='".$arr_page_ids."'");
			$rrs=mysql_fetch_array($qrr);
			unlink(UP_FILES_FS_PATH."/background_image/original/".$rrs['sv_image']);	
			unlink(UP_FILES_FS_PATH."/background_image/thumb/".$rrs['sv_image']);	

			$sql = "delete from tbl_content where page_id in ($arr_page_ids)";
			db_query($sql);
			set_session_msg("Selected Content have been deleted successfully");
		}
		else if(isset($_REQUEST['Activate']) || isset($_REQUEST['Activate_x'])){
			$sql = "update tbl_content  set page_status = 'Active' where page_id in ($arr_page_ids)";
			db_query($sql);			
			set_session_msg("Selected Content have been activated successfully");
		}
		else if(isset($_REQUEST['Deactivate']) || isset($_REQUEST['Deactivate_x'])){
			$sql = "update tbl_content  set page_status = 'Inactive' where page_id in ($arr_page_ids)";
			db_query($sql);			
			set_session_msg("Selected Content have been deactivated successfully");
		}
	}
	header("Location: ".$_SERVER['HTTP_REFERER']);
	exit;
}

/**End of checking***/
$start = intval($start);
$pagesize = intval($pagesize)==0?$pagesize=25:$pagesize;
$columns = "select * ";
$sql = " from tbl_content ";
$sql .= " where 1=1 ";
if($keyword!=""){
	switch($type){
		case 'page_title':
			$sql .=" And page_title like '%$keyword%' ";
			break;
		case 'page_url':
			$sql .=" And page_url like '%$keyword%' ";
			break;
		case 'parent':
			$sql .=" And parent =(select page_id from tbl_content where page_title='".$keyword."')";
			break;
	}
}
$order_by == '' ? $order_by = 'menu_position' : true;
$order_by2 == '' ? $order_by2 = 'asc' : true;
$sql_count = "select count(*) ".$sql; 
$sql .= "order by $order_by $order_by2 ";
$sql .= "limit $start, $pagesize ";
$sql = $columns.$sql;
$result = db_query($sql);
$reccnt = db_scalar($sql_count);
?>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">              
function checkall(objForm)
{
       //alert(objForm);
       var ele,len,i;
       ele= document.getElementsByTagName("input");
       len=ele.length;
       for(i=0;i<len;i++){
       if(ele[i].type=='checkbox')
       {
		   if(ele[i].name=="ch1" )
				   {continue;}
				   else
				   if(ele[i].name=="ch2" )
				   {continue;}
				   else                        
				   {ele[i].checked=objForm;}
		   }
       }
       
}                

function validcheck1(){  return confirm("Are you sure want to activete?"); }
function validcheck2(){  return confirm("Are you sure want to deactivete?"); }
function validcheck3(){  return confirm("Are you sure want to delete?"); }
</script>
<? include("top.inc.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="pageHead"><div id="txtPageHead">
    Manage Page and Menu </div></td>
  </tr>
</table>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="content">
        <div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br />
        <form method="get" name="form2" id="form2" onSubmit="return confirm_submit(this)">
            <br />
            <table width="62%"  border="0" align="center" cellpadding="2" cellspacing="0" class="tableSearch">
            	<tr align="center">
            		<th colspan="1">Search Page</th>
            	</tr>
            	<tr>
            		<!--<td width="36%" class="tdLabel">Keyword: </td>-->
            		<td width="100%" align="center" height="40"><input name="keyword" type="text" value="<?=$keyword?>" placeholder="Keyword" />
            			<select name="type">
            				<option value="page_title" <? if($type=="page_title"){ echo "selected";}?>>Page Title</option>
                            <option value="page_url" <? if($type=="page_url"){ echo "selected";}?>>Page URL</option>
                            <option value="parent" <? if($type=="parent"){ echo "selected";}?>>Parent Menu</option>
            			</select>
                        <input type="button" name="imageField" id="imageField" value="Search" />
            		</td>
            		<!--<td><input type="image" name="imageField" src="images/buttons/search.gif" /></td>-->
            	</tr>
            	<tr>
            		<td colspan="2" align="center"><a href="<?=$_SERVER[PHP_SELF]?>">Show All</a></td>
            	</tr>
            	<tr>
            		<td>&nbsp;</td>
            		<td>
            		<input name="pagesize" type="hidden" id="pagesize" value="<?=$pagesize?>" /></td>
            	</tr>
            </table>
            </form>
			<div align="left">
				<a href="page_text.php">Add New Page </a>
			</div>
      <? if(mysql_num_rows($result)==0){?>
      <div class="msg">Sorry, no records found.</div>
      <? } else{ ?>
      <div align="right"> Showing Records: <?= $start+1?> to <?=($reccnt<$start+$pagesize)?($reccnt-$start):($start+$pagesize)?> of <?= $reccnt?></div>
      <form method="post" name="form1" id="form1" onSubmit="confirm_submit(this)">
        <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="tableList">
          <tr>
          <th  align="left" width="5%">SL</th>
          <th  align="center" width="5%"><input name="check_all" type="checkbox" id="check_all" value="1" onClick="checkall(this.form)" /></th>
          <th  align="left">Page Title/Menu</th>
          <th  align="left">Parent Mneu</th>
          <th  align="left">Page URL</th>
          <th  align="center" width="10%">Menu Position</th>
		  <th  align="left">Page Text</th>
          <th align="center" width="8%">Edit</th>
          <th  align="center" width="8%">Status</th>
          </tr>
<? 
if($start==0){ $cnt=0; }
else{ $cnt=$start; }
while ($line_raw = mysql_fetch_array($result)) {
	$cnt++;
$line = ms_display_value($line_raw);
@extract($line);
$css = ($css=='trOdd')?'trEven':'trOdd';
?>
<tr class="<?=$css?>">
<td  valign="top"><?=$cnt;?></td>
<td align="center"><?php if($page_url=='home'){echo "*"; }else{ ?><input name="arr_page_ids[]" type="checkbox" id="arr_page_ids[]" value="<?=$page_id;?>" /><?php } ?></td>
<td  valign="top"><?=stripslashes($page_title)?></td>
<td  valign="top"><?php $res=mysql_fetch_array(mysql_query("select page_title as pname from tbl_content where page_id='".$parent."'")); echo $res['pname']; ?></td>
<td align="left"><?=stripslashes($page_url);?></td>
<td align="center"><?=stripslashes($menu_position);?></td>
<td  valign="top"><a href='javascript:;' onClick="window.open('view_1.php?page_id=<?=$page_id?>','_blank','toolbar=no,menubar=no,scrollbars=yes,resizable=1,height=300,width=500');">View</a></td>
<td align="center" valign="top"><a href="page_text.php?page_id=<?=$page_id?>&start=<?=$start?>"><img src="images/icons/edit.png" alt="Edit" width="16" height="16" border="0" /></a></td>
<td align="center"><?php if($page_status=='Active'){ echo '<span style="color:green;">'; }else{ echo '<span style="color:red;">'; } echo $page_status; ?></span></td>
</tr>
<? }?>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="right" height="35"style="padding:2px">
            <input name="Activate" type="submit"  value="Activate" class="button" id="Activate" onClick="return validcheck1('arr_page_ids[]','Activate','Page');"/>
        	<input name="Deactivate" type="submit" class="button" value="Deactivate" id="Deactivate"  onClick="return validcheck2('arr_page_ids[]','Deactivate','Page');"/>
            <input name="Delete" type="submit" class="button" id="Delete" value="Delete"  onClick="return validcheck3('arr_page_ids[]','Delete','Page');"/>
        </td>
    </tr>
</table>
 </form>
<? }?>
 <? include("paging.inc.php");?>    </td>
  </tr>
</table>
<? include("bottom.inc.php");?>