
<script type="text/javascript">
	$(document).ready(function(){
		
		$("#checkall").click(function(){
			if(this.checked){
				$(".check_class").attr("checked",true);					
			}else{
				$(".check_class").attr("checked",false);					
			}
		});
		
		//$.tablesorter.defaults.sortList = [[1,0]];
/*		$(".tablesorter").tablesorter({
			headers: {
				0: { sorter: false },
				1: { sorter: false },
				4: { sorter: false },
				5: { sorter: false }
			}
		});
*/		
		//$(".tablesorter").tablesorterPager({container: $("#pager")}); 
		
	});
	
function change_status(page_id,status){

	showLoader(1);

	$.ajax({
	  url: "pagelist.php",
	  data: 'act=change_status&page_id='+page_id+'&status='+status,
	  success: function(msg){
			showLoader(0);
		  	$(".info").html(msg);
		  	$("#status_msg").show();
		  	$("#status_msg").html(msg);
		  	
		  	if(status==0){
			  	$("#td_status_"+page_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+page_id+"','1')\" ><img src=\"images/publish.gif\" alt=\"Publish\" width=\"14\" height=\"15\" border=\"0\" /></a>");
		  	}else{
			  	$("#td_status_"+page_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+page_id+"','0')\" ><img src=\"images/unpublish.gif\" alt=\"Unpublish\" width=\"14\" height=\"15\" border=\"0\" /></a>");
		  	}
	  }
	});
}

function validate_all(){
	if($("#select_action").val()==''){
		$("#msg_select_action").html('Please Select action');
		$("#select_action").addClass('jquery_err');
		$("#select_action").focus();
		return false;
	}else{
		$("#msg_select_action").html('');
		$("#select_action").removeClass('jquery_err');
	}	

	if($(".check_class:checked").length == 0){
		$("#msg_select_action").html('Please Select atleast one checkbox');
		return false;
	}else{
		$("#msg_select_action").html('');
	}	
}

function changeOrder(page_id,page_order,position)
{
	location.href ="pagelist.php?act=order&page_id="+page_id+"&page_order="+page_order+"&position="+position;
}

</script>


<div id="content" class="box">

	<h1>Pages &raquo; Page List</h1>

	<?php if(isset($successMsg) && $successMsg!=''){ ?>
		<p class="msg done"><?php echo $successMsg; ?></p>
	<?php } ?>
	
	<?php if(isset($failedMsg) && $failedMsg!=''){ ?>
		<p class="msg error"><?php echo $failedMsg; ?></p>
	<?php } ?>

	<p id="status_msg" class="msg info" style="display:none">&nbsp;</p>
	
	<div class="loading_image" style="display:none"><img src="images/loading.gif" > </div>

    <form id="select_all_frm" name="select_all_frm" method="post" action="" onsubmit="return validate_all();">

		<table class="tablesorter" width="100%"> <!-- Sort this TABLE -->
			<thead>
				<tr>
					<th style="text-align:center"><input type="checkbox" id="checkall" name="checkall" > </th>
					<th>Order</th>
					<th>Name</th>
					<th>Slug</th>
					<th style="text-align:center">Status</th>
					<th style="text-align:center">Action</th>
				</tr>
			</thead>
			<tfoot>
				<tr class="bg">
				    <td colspan="8" class="arrow-01" style="border-right:0px none">
							<select name="action_val" id="action_val" class="input-text">
							    
								<?php if($DELETE_ACCESS && $EDIT_ACCESS){ ?>
								    <option value="">Select Action</option>
								    <option value="delete_all">Delete selected</option>
								    <option value="activate_all">Activate selected</option>
								    <option value="inactivate_all">Inactivate selected</option>
								    
								<?php }else if($DELETE_ACCESS){ ?>
								    <option value="">Select Action</option>
								    <option value="delete_all">Delete selected</option>
								    
								<?php } else if ($EDIT_ACCESS){ ?>
								    <option value="activate_all">Activate selected</option>
								    <option value="inactivate_all">Inactivate selected</option>
								
								<?php } ?>
								
							</select>&nbsp;
							<input type="submit" value="OK" id="submit" name="submit" />&nbsp;
							<span id="msg_select_action" class="message">&nbsp;</span>
					</td>
					
<!--				    <td colspan="3" class="arrow-01" style="border-left:0px none" >
						<div id="pager" class="pager">
							<img src="images/first.png" class="first"/>
							<img src="images/prev.png" class="prev"/>
							<input type="text" disabled="disabled" class="pagedisplay"/>
							<img src="images/next.png" class="next"/>
							<img src="images/last.png" class="last"/>
							<select class="pagesize">
								<option selected="selected" value="20">20</option>
								<option value="50">50</option>
								<option  value="100">100</option>
								<option  value="150">150</option>
							</select>
						</div>
					</td>-->
				</tr>
	
			</tfoot>
			<tbody>
				
				<?php if($pagesDetails && count($pagesDetails) > 0 ){ $caOrder =1; 
						foreach ($pagesDetails as $pages){  ?>
						<tr>
							<td class="t-center ">
								<input type="checkbox" name="check[]" id="check[]" value="<?php echo $pages->page_id; ?>" class="check_class" />
							</td>
							<td><?php echo $caOrder; ?> 
								<?php if($EDIT_ACCESS){ ?>	
									<?php if($caOrder!=1){?><a href="javascript:changeOrder('<?php echo $pages->page_id ?>','<?php echo $pages->page_order ?>','Up');"><img src="images/uparrow.png" alt="Up" width="16" height="16" border="0" /></a><?php }?>
									<?php if($caOrder!=count($pagesDetails)){?><a href="javascript:changeOrder('<?php echo $pages->page_id ?>','<?php echo $pages->page_order ?>','Dn');"><img src="images/downarrow.png" alt="Down" width="16" height="16" border="0" /></a><?php }?>
								<?php } ?>	
							</td>
							<td>
								<?php if($EDIT_ACCESS){ ?>	
									<a href="addpage.php?act=edit&page_id=<?php echo $pages->page_id; ?>" class="edit"><?php echo $pages->page_title;  ?></a>
								<?php }else{ ?>	
									<?php echo $pages->page_title;  ?>
								<?php } ?>
							</td>
							<td><?php echo $pages->page_slug;  ?></td>
							
							<td style="text-align:center" id="td_status_<?php echo $pages->page_id ?>">
								<?php if($EDIT_ACCESS){ ?>	
									<?php if($pages->page_status=='1'){?><a href="javascript:void(0)" onclick="change_status('<?php echo $pages->page_id ?>','1')" ><img src="images/publish.gif" alt="Publish" width="14" height="15" border="0" /></a> <?php }else{?><a href="javascript:void(0)" onclick="change_status('<?php echo $pages->page_id ?>','0')" ><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /></a><?php }?>	
								<?php }else{ ?>
									<?php if($pages->page_status=='1'){?><img src="images/publish.gif" alt="Publish" width="14" height="15" border="0" /><?php }else{?><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /><?php }?>	
								<?php } ?>	
							</td>
							<td class="t-center">
									<?php if($EDIT_ACCESS){ ?>	
										<a href="addpage.php?act=edit&page_id=<?php echo $pages->page_id; ?>" class="edit"><img src="images/edit.png" alt="Edit" border="0" title="Edit Record" /></a> 
									<?php } ?>	
									<?php if(!in_array(trim($pages->page_slug),$noneEditPage) && $DELETE_ACCESS){ ?>
										<a onclick="javascript:if(confirm('Are you sure to delete ? ')){location.href='pagelist.php?act=delete&page_id=<?php echo $pages->page_id; ?>'}"><img src="images/delete.gif" alt="Delete"  border="0" title="Delete Record" /></a>
									<?php } ?>	
							</td>
						</tr>
						<?php if($pages->page_id!=0){ 
								$subpageDetails = $pagesObj->getAllRecords('*',' page_parent ='.$pages->page_id," ORDER BY page_order ");
								
								if($subpageDetails && count($subpageDetails) > 0){ $subcatOrder=1;
									foreach ($subpageDetails as $subpage){?>
                                    <tr>
							<td class="t-center ">
								<input type="checkbox" name="check[]" id="check[]" value="<?php echo $pages->page_id; ?>" class="check_class" />
							</td>
							
							
                            
                            
                            <td><?php echo $caOrder.'.'.$subcatOrder; ?> 
											<?php if($subcatOrder!=1){?><a href="javascript:changeOrder('<?php echo $subpage->page_id ?>','<?php echo $subpage->page_order ?>','Up');"><img src="images/uparrow.png" alt="Up" width="16" height="16" border="0" /></a><?php }?>
											<?php if($subcatOrder!=count($subpageDetails)){?><a href="javascript:changeOrder('<?php echo $subpage->page_id ?>','<?php echo $subpage->page_order ?>','Dn');"><img src="images/downarrow.png" alt="Down" width="16" height="16" border="0" /></a><?php }?>
										</td>
										<td>&nbsp;<img src="images/arrow-01.gif">&nbsp;<a href="addpage.php?act=edit&page_id=<?php echo $subpage->page_id; ?>" class="edit"><?php echo $subpage->page_title;  ?></a></td>
                                        
                                        
							<td><?php echo $subpage->page_slug;  ?></td>
							
							<td style="text-align:center" id="td_status_<?php echo $subpage->page_id ?>">
								<?php if($EDIT_ACCESS){ ?>	
									<?php if($subpage->page_status=='1'){?><a href="javascript:void(0)" onclick="change_status('<?php echo $subpage->page_id ?>','1')" ><img src="images/publish.gif" alt="Publish" width="14" height="15" border="0" /></a> <?php }else{?><a href="javascript:void(0)" onclick="change_status('<?php echo $subpage->page_id ?>','0')" ><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /></a><?php }?>	
								<?php }else{ ?>
									<?php if($subpage->page_status=='1'){?><img src="images/publish.gif" alt="Publish" width="14" height="15" border="0" /><?php }else{?><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /><?php }?>	
								<?php } ?>	
							</td>
							<td class="t-center">
									<?php if($EDIT_ACCESS){ ?>	
										<a href="addpage.php?act=edit&page_id=<?php echo $subpage->page_id; ?>" class="edit"><img src="images/edit.png" alt="Edit" border="0" title="Edit Record" /></a> 
									<?php } ?>	
									<?php if(!in_array(trim($subpage->page_slug),$noneEditPage) && $DELETE_ACCESS){ ?>
										<a onclick="javascript:if(confirm('Are you sure to delete ? ')){location.href='pagelist.php?act=delete&page_id=<?php echo $subpage->page_id; ?>'}"><img src="images/delete.gif" alt="Delete"  border="0" title="Delete Record" /></a>
									<?php } ?>	
							</td>
						</tr>
                                    <?php $subcatOrder++; } } } ?>
				<?php $caOrder++; } }else { ?>
						<tr>
							<td colspan="6" align="center">No Record Found</td>
						</tr>
				<?php } ?>

				
			</tbody>
			
		</table>
		
	</form>

</div> <!-- /content -->