<?php	
	$ctrl_name = BASE_URL."/galleries";
	$page_name = BASE_URL."/galleries/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">Manage Photos &raquo; <?php echo $gallerycat?></h1>          
<div class="bs-example table-responsive">
    <table class="" width="100%" border="0">	                
         	  <tr>
              	<td align="right">
                	<button value="AddRecord" type="button" name="AddButton" class="btn btn-primary" onclick="location.href='<?php echo BASE_URL?>/galleries/gallerycat'">Back to Galleries</button><?php /*?> <button value="AddRecord" type="button" name="AddButton" class="btn btn-primary" onclick="Add('section_form')">Add Photos</button><?php */?>
                </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($Galleries) > 0) 
				  {?>                  
                  <tr>
                    <td align="center" valign="top">  
					<div class="container">                       
                        <form name="section_form" id="section_form" action="<?php echo $page_name?>" method="post"  enctype="multipart/form-data">
                  
							<input type="hidden" name="ImgId" value="">
							<input type="hidden" name="pid" value="<?php echo $_REQUEST['pid']?>">
							<input type="hidden" name="Imgname" value="">
							<input type="hidden" name="act" value="ADD">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" >
	 
	
			  <tr>
			    <td colspan="2" align="center" valign="top" class="message"><?php echo $msg?></td>
		        
			  </tr>
			 
              <tr>
                <td colspan="2" align="center" valign="top">
                
                        <table width="95%" border="0" align="center" cellpadding="2" cellspacing="0">
                        
								<?php
                                    $nume = $totalpages;
                                    $numrows = count($Galleries);
                                    $rows = ceil($numrows / 3);
                                    //echo $rows;
                                    $i =0;
                                    $j = 0;
                                    foreach($Galleries as $Gallery)
                                    {
                                      if($j % 5 == 0 && $j !=0)
                                      {
                                      $i=0;
                                      echo "</tr>";
                                      echo "<tr><td colspan='6'>&nbsp;</td></tr>";
                                      echo "<tr>";
                                      }
                                      if($j == 0)
                                      {
                                        echo "<tr>";
                                      }
                                      ?>
                                  
                                      <td width="20%" nowrap="nowrap"><img src="<?php echo "../". UPLOADDIR_GALLERY."/".$Gallery->filename?>" border="1" width="100" height="100"/>&nbsp;<a href="javascript:Delete_Img('<?php echo $Gallery->id?>','<?php echo $Gallery->filename?>')"><img src="<?php echo BASE_URL?>/static/images/delete.png" title="delete" border="0"></a><br>
                                      
                                      <input type="text" name="photoTitle[]" value="<?php echo $Gallery->title?>"><br>
                                      <textarea name="photoDesc[]"><?php echo $Gallery->description?></textarea>
                                      <input type="hidden" name="photoIds[]" value="<?php echo $Gallery->id?>">
                                      </td>
                                        <?php
                                  if($j == $numrows-1)  
                                  {
                                                 if($i==0)
                                                   {
                                                    echo "<td width='20%'>&nbsp;</td>";
                                                    echo "<td width='20%'>&nbsp;</td>";
                                                    echo "<td width='20%'>&nbsp;</td>"; 
                                                    echo "<td width='20%'>&nbsp;</td>";
                                                    echo "<td width='20%'>&nbsp;</td>";                                                   
                                                    //echo "<td width='14%'>&nbsp;</td>";
                                                   }
                                                   if($i==1)
                                                   {
                                                    echo "<td width='20%'>&nbsp;</td>";
                                                    echo "<td width='20%'>&nbsp;</td>";
                                                    echo "<td width='20%'>&nbsp;</td>";
                                                    echo "<td width='20%'>&nbsp;</td>";                                                  
                                                    //echo "<td width='14%'>&nbsp;</td>";
                                                   }
                                                   if($i==2)
                                                   {
                                                     echo "<td width='20%'>&nbsp;</td>";
                                                     echo "<td width='20%'>&nbsp;</td>";
                                                     echo "<td width='20%'>&nbsp;</td>";                                                   
                                                   }
                                                   if($i==3)
                                                   {
                                                    echo "<td width='20%'>&nbsp;</td>";
													echo "<td width='20%'>&nbsp;</td>";
                                                    //echo "<td width='14%'>&nbsp;</td>";
                                                   }					   
                                                   if($i==4)
                                                   {
                                                   echo "<td width='20%'>&nbsp;</td>";                                                   
                                                    //echo "<td width='14%'>&nbsp;</td>";
                                                   }	
                                                  if($i==5)
                                                   {
                                                
                                                   }	 
                                                
                                                   
                                  echo "</tr>";
                                 
                                  }
                                  $j++;
                                  $i++;
                                }
                                ?>
                        <tr>
                        	<td colspan="5" align="left">&nbsp;</td>
                        </tr>
                        <tr>
                        	<td colspan="5" align="center"><input type="button" name="EditTitle" value="Update Titles" onClick="UpdateTitles()" class="btn btn-primary"></td>
                        </tr>
                        </table>
                          
                </td>
			  </tr>
             <tr>
        <td colspan="2"  align="right" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="50%" align="left"><?php 
						if($back >=0) { 
										//echo "<a href='$page_name?start_client=$back&pid=$pid' style=text-decoration:none;><font >Previous</font></a>"; 
										?>
											<input type="button" value="Previous" class="btn btn-primary" onclick="previous('<?php echo $back;?>')" />
										<?php
										} 
						?>
                &nbsp; </td>
              <td width="50%" align="right"><?php
					  if($th < $nume) { 	
										//echo  "<a href='$page_name?start_client=$next&pid=$pid'  style=text-decoration:none;><font >Next</font></a>";
										?>
											<input type="button" value="Next" class="btn btn-primary" onclick="next('<?php echo $next;?>')"/>
										<?php
										}
					  ?>
					  <br /><br /><br />
                &nbsp;</td>
            </tr>
        </table></td>
      </tr>
            
	 <tr>
	 <td><strong style="font-size:16px; color:#F63">
	 (Only <?php echo VALID_EXT_GALLERY?>, image size 800px x 600px)</strong>
	   <table>
          <td width="25%" class="td"><b>Upload Image</b></td>
          <td><input type="file" name="fileUpload1">  &nbsp;&nbsp;&nbsp; Title&nbsp;&nbsp;<input type="text" name="title1"></td>    
          <td><textarea name="description1"></textarea></td> 
	  </table>
      </td>
      
	  </tr>
	  <tr >
	   <td>
	 <table>
      <td width="25%" class="td"><b>Upload Image</b></td>
      <td><input type="file" name="fileUpload2">  &nbsp;&nbsp;&nbsp; Title&nbsp;&nbsp;<input type="text" name="title2"></td>
      <td><textarea name="description2"></textarea></td> 
	  </table>
      </td>
	  </tr>
	  <tr >
	  <td>
	 <table>
      <td width="25%" class="td"><b>Upload Image</b></td>
      <td><input type="file" name="fileUpload3">  &nbsp;&nbsp;&nbsp; Title&nbsp;&nbsp;<input type="text" name="title3"></td>
      <td><textarea name="description3"></textarea></td> 
	  </table></td>
	  </tr>
	  <tr >
	  <td>
	 <table>
      <td width="25%" class="td"><b>Upload Image</b></td>
      <td><input type="file" name="fileUpload4">  &nbsp;&nbsp;&nbsp; Title&nbsp;&nbsp;<input type="text" name="title4"></td>
      <td><textarea name="description4"></textarea></td> 
	  </table></td>
	  </tr>
       <tr >
	  <td>
	 <table>
      <td width="25%" class="td"><b>Upload Image</b></td>
      <td><input type="file" name="fileUpload5">  &nbsp;&nbsp;&nbsp; Title&nbsp;&nbsp;<input type="text" name="title5"></td>
      <td><textarea name="description5"></textarea></td> 
	  </table></td>
	  </tr>
	 
	  
		
		<td><input name="hdnLine" type="hidden" value="5"></td>
		 <tr >
      <td colspan="2" ><input name="Submit" type="submit"  value="Upload" class="btn btn-primary"></td>
    </tr>
	  
            </table>
			<input type="hidden" name="start_client" value="<?php echo $start_client?>" />
			<input type="hidden" name="id" value="">
			<input type="hidden" name="gallery_id" value="<?php echo $gallerycat_id?>">
			<input type="hidden" name="gallerycat_id" value="<?php echo $gallerycat_id?>">
			<input type="hidden" name="List" value="">
			<input type="hidden" name="recStatus" value="">
			<input type="hidden" name="start" value="<?php echo $start?>">       
             </form>
                   </div>
                    </td>
                </tr>
                  <?php  }//else
				  { ?>
                  <?php /*?><tr >
                    <td align="center">
                         <div class="col-lg-6 alert alert-danger" style="clear:right; float:none">
                            No records found.
                         </div>   
                    </td>
                  </tr><?php */?>
                 <?php } ?>                  
              </table>
        

<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 next(v){
	document.section_form.start_client.value=v;
	document.section_form.submit();
}
function previous(v){
	document.section_form.start_client.value=v;
	document.section_form.submit();
}
	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+"/"+Frm.List.value;						
		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+"/"+Frm.List.value;							
			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_sub_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="Delete";				
				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";
		Frm.action=Frm.ctrl_name.value+"/"+Frm.List.value;		
		Frm.recStatus.value=Status;				
		Frm.submit();
  }	
function Delete_Img(Id,ImgName)
{
if(confirm("Are You Sure You Want to Delete Image ?"))
  {
	 document.section_form.ImgId.value = Id;
	 document.section_form.Imgname.value = ImgName;
	 document.section_form.act.value = "DELETE";
	 document.section_form.submit();
  }
}


function UpdateTitles(){
	document.section_form.act.value="EDIT";
	document.section_form.submit();
}
</script>