<?php	
	$ctrl_name = BASE_URL."/downloads";
	$page_name = BASE_URL."/downloads/index";
	
?>
<script type="text/javascript" charset="utf-8">			
			$(document).ready(function() {
				$('#datagrid').dataTable( {
					"sDom": "<'row'<'span8'l><'span9'f>r>t<'row'<'span8'i><'pagingspan8'p>>",
					"sPaginationType": "bootstrap",
					"oLanguage": {
					  "sLengthMenu": 'Display <select>'+
						'<option value="1">1</option>'+
						'<option value="5">5</option>'+
						'<option value="10">10</option>'+
						'<option value="20">20</option>'+
						'<option value="30">30</option>'+
						'<option value="40">40</option>'+
						'<option value="50">50</option>'+
						'<option value="-1">All</option>'+
						'</select> records'
					},
					"aoColumns": [
						{ "sType": "numeric" },
						{ "sType": "string" },
						{ "sType": "string" },
						{ "sType": "alt-string" },
						{ "sType": "title-string" }
						
					]
				} );
			} );	
</script>
<h1 class="page-header">Download Categories</h1>          
<div class="bs-example table-responsive">
	<form name="section_form" id="section_form" action="<?php echo $page_name?>" method="post">
    <table class="" width="100%" border="0">	                
         	  <tr>
              	<td align="right">
                	<button value="AddRecord" type="button" name="AddButton" class="btn btn-primary" onclick="Add('section_form')">Add Download Category</button>
                </td>
              </tr>	 
              <tr>
              	<td align="right">&nbsp;
                	
                </td>
              </tr>					 
               <?php if(!empty($error_msg)) {?>     
                <tr>
                    <td align="center">  
                      <div class="col-lg-6 alert alert-danger" style="clear:right; float:none">
                        <?php echo $error_msg;?>
                     </div>             
                    </td>
                 </tr>   
             <?php } ?>  
			 <?php if($_SESSION["sess_error_msg"]!=''){
			 ?>
			 	<tr>
                    <td align="center">  
                      <div class="col-lg-6 alert alert-danger" style="clear:right; float:none">
                        <?php echo $_SESSION["sess_error_msg"];
								$_SESSION["sess_error_msg"]='';?>
                     </div>             
                    </td>
                 </tr>   
			 <?php
						}
						?>                                
                  <?php  if(count($Downloads) > 0) {?>                  
                  <tr>
                    <td align="center" valign="top">  
					<div class="container">                       
                        <table class="bordered-table zebra-striped dataTable" width="100%" id="datagrid">                        
                         <thead>
                          <tr>                            
                            <th class="header srnoTd">Sr.No.</th>
                            <th class="header">Download Category</th>
                            <th class="header">Count</th>
                            <th class="header statusTd">Status</th>
							<th class="header actoinTd">Action</th>
                           <!-- <th class="header actoinTd">Action</th>-->
                          </tr>
                        </thead>                     
                         <tbody>
						   <?php				  
                           $i=$start;	
                          foreach ($Downloads as $section) { 							  
                            $i++;	
							 if($section->status == 1){
								$active = "Active";
								$active = '<a href="javascript:;" title="'.$section->status.'" onclick="activeinactive('."'"."section_form"."'".','.$section->id.','.$section->status.');"><img src="'.BASE_URL.'/static/images/icon_approve.png" title="Make Inactive" alt="'.$section->status.'" border="0"></a>';
							}
                            else{ 
								$active = "Inactive"; 
								$active = '<a href="javascript:;" title="'.$section->status.'" onclick="activeinactive('."'"."section_form"."'".','.$section->id.','.$section->status.');"><img src="'.BASE_URL.'/static/images/icon_unapprove.png" title="Make Active" alt="'.$section->status.'" border="0"></a>';
							} 					  							              
                          ?>
						  
                          <tr>
                             <td ><?php echo $i?></td>
                             <td ><?php echo $section->catname?></td>
                             <td ><?php echo $section->down_count?></td>
                             <td ><?php echo $active?></td>
							<td align="left" valign="middle" class="<?php echo $class?>"><span title="<?php echo $section->id; ?>"><a href="javascript:;" onclick="View('section_form','<?php echo $section->id; ?>')"><img src="<?php echo BASE_URL?>/static/images/view.png" title="View Subsections" alt="View Subsections"></a>&nbsp;&nbsp;<a href="javascript:;" onclick="Edit('section_form','<?php echo $section->id; ?>')"><img src="<?php echo BASE_URL?>/static/images/icon_edit.png" title="Edit Record" alt="Edit Record"></a>&nbsp;&nbsp;<a href="javascript:;" onclick="DeleteRecord('section_form','<?php echo $section->id; ?>')" title="Delete Record" alt="Delete Record"><img src="<?php echo BASE_URL?>/static/images/delete.png" title="Delete Record" alt="Delete Record"></a></span></td>
                          </tr>
                          <?php
                           }
                          ?>
                      </tbody>
                    </table>
                   </div>
                    </td>
                </tr>
                  <?php  }else{ ?>
                  <tr >
                    <td align="center">
                         <div class="col-lg-6 alert alert-danger" style="clear:right; float:none">
                            No records found.
                         </div>   
                    </td>
                  </tr>
                 <?php } ?>                  
              </table>
        <input type="hidden" name="id" value="">
		<input type="hidden" name="download_id" value="">
        <input type="hidden" name="List" value="">
        <input type="hidden" name="recStatus" value="">
        <input type="hidden" name="start" value="<?php echo $start?>">       
        <input type="hidden" name="ctrl_name" value="<?php echo $ctrl_name?>"> 
		<input type="hidden" name="ctrl_sub_name" value="<?php echo $ctrl_sub_name?>"> 
</form> 

<script type="text/javascript">
    $(document).on("click", ".open-ProjectDialog", function () {
        var myProjectId = $(this).data('id');
        $("#assign_designer_project_id").val(myProjectId);		
    });
	
	/*var $modal = $('#responsive');	
	$modal.on('click', '#UpdateBtn', function(){
		//alert($("#assign_desiger_project_id").attr('value'));
	});*/

 $(document).ready(function() {
    $('#assign_designer').bootstrapValidator({		
        message: 'This value is not valid',		
        fields: {
            assign_desiger_designer_id: {
                message: 'The Assign Designer is not valid',
                validators: {
                    notEmpty: {
                        message: 'The Assign Designer is required and can\'t be empty'
                    }
                }
            }
        }
    });		
});

</script>
<script language="javascript">
	function gotoPage(start_val,frm_name){
		var Frm = document.getElementById(frm_name);
		Frm.start.value=start_val;
		Frm.action=Frm.ctrl_name.value+"/index";						
		Frm.submit();
	}
	
	var selIndex =0;
    function GetSelInd(Ind,frm_name)
	 {
	  selIndex = Ind;
	  ChangeStatus(frm_name);
	 }
  	function CheckAction(frm_name)
	{	 
	 var Elem = document.getElementsByName("actionradio[]");
	 // alert(Elem.length);
	  for(i=0;i<Elem.length;i++)
	   {
	    if(Elem[i].checked)
		 {
		  selIndex = Elem[i].value;
		 }
	   }	 	   
	 }
		
	function Add(frm_name)
	{	
		var Frm = document.getElementById(frm_name);
		Frm.List.value="Add";						
		Frm.action=Frm.ctrl_name.value+"/AddCat";						
		Frm.submit();
	}
	
	function Edit(frm_name,id)
	{
			var Frm = document.getElementById(frm_name);
			Frm.List.value="Edit";
			Frm.download_id.value=id;		
			Frm.action=Frm.ctrl_name.value+"/EditCat";							
			Frm.submit();
	}
	function View(frm_name,id)
	{	
			var Frm = document.getElementById(frm_name);
			Frm.download_id.value=id;
			Frm.List.value="index";		
			Frm.action=Frm.ctrl_name.value+"/"+Frm.List.value;				
			Frm.submit();
		
	}
	function DeleteRecord(frm_name,id)
	{	
			agree=confirm("Are you sure want to Delete this record?");
			if (agree)
			{
				var Frm = document.getElementById(frm_name);
				Frm.download_id.value=id;				
				Frm.List.value="DeleteCat";				
				Frm.action=Frm.ctrl_name.value+"/"+Frm.List.value;							
				Frm.submit();
			}
	}
	
  
function activeinactive(Frm,id,Status)
  {
  	var Frm=document.getElementById(Frm);
		Frm.download_id.value=id;
		Frm.List.value = "ChangeStatus_cat";
		Frm.action=Frm.ctrl_name.value+"/"+Frm.List.value;		
		Frm.recStatus.value=Status;				
		Frm.submit();
  }	
</script>