<script src="<?php echo SITE_URL;?>js/jquery-1.7.2.min.js"></script>
<script src="<?php echo SITE_URL;?>js/lightbox.js"></script>
<link href="<?php echo SITE_URL;?>css/lightbox.css" rel="stylesheet" />
<script type="text/javascript">
	$(document).ready(function(){
		
		$("#checkall").click(function(){
			if(this.checked){
				$(".check_class").attr("checked",true);					
			}else{
				$(".check_class").attr("checked",false);					
			}
		});		
	});
	
function change_status(gallery_id,status){

	showLoader(1);

	$.ajax({
	  url: "gallerylist.php",
	  data: 'act=change_status&gallery_id='+gallery_id+'&status='+status,
	  success: function(msg){
			showLoader(0);
		  	$(".info").html(msg);
		  	$("#status_msg").show();
		  	$("#status_msg").html(msg);
		  	
		  	if(status==0){
			  	$("#td_status_"+gallery_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+gallery_id+"','1')\" ><img src=\"images/publish.gif\" alt=\"Publish\" width=\"14\" height=\"15\" border=\"0\" /></a>");
		  	}else{
			  	$("#td_status_"+gallery_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+gallery_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(gallery_id,gallery_order,position)
{
	location.href ="gallerylist.php?act=order&gallery_id="+gallery_id+"&gallery_order="+gallery_order+"&position="+position;
}

</script>

<div id="content" class="box">
  <h1>Image Gallery &raquo; Image Gallery 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 width="4%" style="text-align:center"><input type="checkbox" id="checkall" name="checkall" >
          </th>
          <th width="11%">Order</th>
          <th width="37%">Name</th>
          <th width="23%">Image</th>
          <th width="12%" style="text-align:center">Status</th>
          <th width="13%" 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>
         
        </tr>
      </tfoot>
      <tbody>
        <?php if($gallerysDetails && count($gallerysDetails) > 0 ){ $caOrder =1; 
						foreach ($gallerysDetails as $gallerys){  ?>
        <tr>
          <td class="t-center "><input type="checkbox" name="check[]" id="check[]" value="<?php echo $gallerys->gallery_id; ?>" class="check_class" />
          </td>
          <td><?php echo $caOrder; ?>
            <?php if($EDIT_ACCESS){ ?>
            <?php if($caOrder!=1){?>
            <a href="javascript:changeOrder('<?php echo $gallerys->gallery_id ?>','<?php echo $gallerys->gallery_order ?>','Up');"><img src="images/uparrow.png" alt="Up" width="16" height="16" border="0" /></a>
            <?php }?>
            <?php if($caOrder!=count($gallerysDetails)){?>
            <a href="javascript:changeOrder('<?php echo $gallerys->gallery_id ?>','<?php echo $gallerys->gallery_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="addgallery.php?act=edit&gallery_id=<?php echo $gallerys->gallery_id; ?>" class="edit"><?php echo $gallerys->gallery_title;  ?></a>
            <?php }else{ ?>
            <?php echo $gallerys->gallery_title;  ?>
            <?php } ?>
          </td>
          <td><?php if($gallerys->gallery_banner!='' && file_exists(DIR_UPLOAD_BANNER.$gallerys->gallery_banner)) {?>
    <a href="<?php echo DIR_UPLOAD_BANNER_SHOW.$gallerys->gallery_banner; ?>" rel="lightbox[plants]" title="<?php echo $gallerys->gallery_title ?>">  <img src="<?php echo DIR_UPLOAD_BANNER_SHOW.$gallerys->gallery_banner ?>" height="74" width="150" /></a>
      <?php } ?></td>
          <td style="text-align:center" id="td_status_<?php echo $gallerys->gallery_id ?>"><?php if($EDIT_ACCESS){ ?>
            <?php if($gallerys->gallery_status=='1'){?>
            <a href="javascript:void(0)" onclick="change_status('<?php echo $gallerys->gallery_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 $gallerys->gallery_id ?>','0')" ><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /></a>
            <?php }?>
            <?php }else{ ?>
            <?php if($gallerys->gallery_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="addgallery.php?act=edit&gallery_id=<?php echo $gallerys->gallery_id; ?>" class="edit"><img src="images/edit.png" alt="Edit" border="0" title="Edit Record" /></a>
            <?php } ?>
            <?php if(!in_array(trim($gallerys->gallery_slug),$noneEditPage) && $DELETE_ACCESS){ ?>
            <a onclick="javascript:if(confirm('Are you sure to delete ? ')){location.href='gallerylist.php?act=delete&gallery_id=<?php echo $gallerys->gallery_id; ?>'}"><img src="images/delete.gif" alt="Delete"  border="0" title="Delete Record" /></a>
            <?php } ?>
          </td>
        </tr>
        <?php $caOrder++; } }else { ?>
        <tr>
          <td colspan="6" align="center">No Record Found</td>
        </tr>
        <?php } ?>
      </tbody>
    </table>
  </form>
</div>
<!-- /content -->
