<? global $vis_language;  
 ?>

   <? $status=array($img => ' <i class="vh vh-module"></i>');
   $priority=array(1 => $vis_language['TXTLOW'],2 => $vis_language['TXTMEDIUM'],3 => $vis_language['TXTHIGH']); 
  
 ?>
    <section class="padder">
    <section class="m-t-sm tbledata" id="tbl_<? echo $pagetoken_data; ?>">   
		
		<div id="vh-drive">
			  <div id="drive-modal-view" class="drive-object grid-view">
		
      
                <div class="drive-head animated fadeInUp">
                        <div class="drive-items">
                                Item
                        </div>
                        <div class="drive-items">
                                Name
                        </div>
                        <div class="drive-items">
                                Owner
                        </div>
                        <div class="drive-items">
                                Size
                        </div>
                        <div class="drive-items">
                                Creation date
                        </div>
                </div>
            	<?if($file_list!=-1)
{  
	for($i=0; $i<$filecount; $i++){
if((!empty($file_list[$i]['mimeType']))&&$file_list[$i]['mimeType']!='Directory') 
{	$flag=0;
$creation_date=$file_list[$i]['createdDate'];
$date=date(VIS_DATE_FORMAT,strtotime($creation_date));
?>
        
			  
			<a href="#" class="list-drive-a">
                        <div class="drive-info">
						 <div class="drive-checkbox">
                                <input id="drive-item-<? echo  $file_list[$i]['alternateLink'];?>" name="drive-item[]" value="<a href=<? echo $file_list[$i]['alternateLink']?>><? echo $file_list[$i]['alternateLink']?></a> " type="checkbox" class="checkbox">
                                <i></i>
                            </div>
                                <div class="drive-item">
                                        <?  if($file_list[$i]['mimeType']=='text/plain') { ?>
      <i class="vh vh-file-text text-muted"></i>
      <?}
      else if($file_list[$i]['mimeType']=='image/jpeg') { ?>
        <img src="<?=$file_list[$i]['thumbnailLink'];?>" alt="techimage" />
      <?}
      else if($file_list[$i]['mimeType']=='application/vnd.ms-excel') { ?>
       <i class="vh vh-file-spreadsheet vh-file-spreadsheet-color"></i>
      <?}
      else if($file_list[$i]['mimeType']=='image/png') { ?>
        <img src="<?=$file_list[$i]['thumbnailLink'];?>" alt="techimage" />
       <?} 
       else if($file_list[$i]['mimeType']=='application/pdf') { ?>
      <i class="vh vh-file-pdf vh-file-pdf-color"></i>
       <?}
       else if($file_list[$i]['mimeType']=='application/vnd.openxmlformats-officedocument.wordprocessingml.document') { ?>
      <i class="vh vh-file-word vh-file-word-color"></i>
        <?}
        else if($file_list[$i]['mimeType']=='text/csv') { ?>
      <i class="vh vh-file-spreadsheet vh-file-spreadsheet-color"></i>
        <?} 
        else if($file_list[$i]['mimeType']=='message/rfc822') { ?>
      <i class="vh vh-file-text text-muted"></i>
        <?}
         else if(($file_list[$i]['mimeType']=='application/zip') || ($file_list[$i]['mimeType']=='application/octet-stream')) { ?>
      <i class="vh vh-file-zip vh-file-zip-color"></i>
        <?}
        else if($file_list[$i]['mimeType']=='application/vnd.openxmlformats-officedocument.presentationml.presentation') { ?>
      <i class="vh vh-file-presentation vh-file-presentation-color"></i>
        <?} else
        {?>
			<i class="vh vh-file vh-info"></i>
		<?}
        ?>
                                </div>
                                <div class="drive-item-name">
                                        <small>Name</small>
                                       <?= $file_list[$i]['title']?>
                                </div>
                                <div class="drive-item-owner">
                                        <small>Owner</small>
                                        <?=$file_list[$i]['ownername']?>
                                </div>
                                <div class="drive-item-size">
                                        <small>Size</small>
                                       <?= $file_list[$i]['fileSize']." Bytes";?> 
                                </div>
                                <div class="drive-item-date">
                                        <small>Creation date</small>
                                        <?= $date?>
                                </div>
                        </div>
                </a>
             
	<?   }
   }
 
		}else
				   {
					include(VIS_PATH_TEMPLATE.'no_record_yet.php');
				   }?>	
		</div>
</div>	

  </section>
<input type="hidden" name="hidden_token" id="hidden_token"/>
<input type="hidden" name="hidden_token2" id="hidden_token2"/>
<? if($pageToken){?>
<div id="div_ld_more">
<button id="load_more" name="load_more" class="btn btn-sm btn-rounded btn-default btn-primary" onclick="paging_data(<?=$pagetoken_data;?>,'<?=$pageToken?>');">Load More</button>
</div>
<? } ?>
  </form>
</section>
<script>
  $('.list-drive-a').click(function() {
   //$('.rtpcls').removeClass('btn-primary');
//alert('hi');
			
var checkbox = $(this).find("input[type='checkbox']");
var parentdiv=$(this).find(".drive-info");

if((checkbox.is(":checked") && parentdiv.hasClass('active')) || (checkbox.is(":checked")==false && parentdiv.hasClass('active')))
			{
$(this).find(".drive-info").removeClass('active');
			checkbox.prop('checked', false);
			}else{
				checkbox.prop('checked', true);
$(this).find(".drive-info").addClass('active');
			}
  });

 
    $(document).ready(function () {
        if ($('#view').hasClass("btn btn-icon active") == true) {
            $('.drive-object').addClass('grid-view list-view');
        }
        else $('.drive-object').addClass('grid-view');
    });
    $('#search_drive').keyup(function (e) {
        if (e.keyCode == 13) {
            var search_string = $("#search_drive").val();
            if (search_string.length < 3) $("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['TXTGLOBALSEARCHERROR'];?>");
            else $.post("index.php?vis_module=selfhelp&vis_operation=view_drive&vis_tmpst=" + new Date().getTime(), {
                'vis_action': 'insert_ticket'
                , 'criteria': search_string
            }, function (data) {
                $("#search_drive").parent().addClass('open');
                $('#drive-modal-view').show().html(data);
            });
        }
    });
     

function paging_data(pagetoken_data,pagetoken){


	var data1 = {'vis_module':'selfhelp','vis_operation':'get_file_list','vis_pagetoken':pagetoken,'vis_load_more':pagetoken_data,'vis_pagetoken_data':pagetoken_data};

    var m = $("#hide_token").val();
    $.ajax({
    type: "POST",
    url: 'index.php',
	data: data1,
    dataType: "json",
    success: function(result){
		var pgtkn=document.getElementById('hidden_token').value;
	
	document.getElementById('hidden_token2').value=pgtkn;
	$('#hidden_token').attr('value',result.page_token);    
    check_token();
	
	
	$('#drive-view').append(result.list);
	
	if(result.file_count!=0 || result.file_count!="")
	{
	$('#div_ld_more').html('<button id="load_more" class="btn btn-sm btn-rounded btn-default btn-primary" name="load_more" onclick="paging_data(\'' + result.pagetoken_data + '\',\'' + result.page_token + '\')">Load More</button>');
	}
	else
	{
		$('#div_ld_more').hide();
		$('#div_ld_more').attr("display","none");
	}
	
  }
});




}
function check_token()
{
	var pgtkn_new=document.getElementById('hidden_token').value;
	var pgtkn=document.getElementById('hidden_token2').value;
	if(pgtkn_new==pgtkn)
	{
	$('#div_ld_more').hide();
    $('#div_ld_more').attr("display","none");	
	}
}
</script>
<script>
function display_drive()
    {
		if($('#search_drive').val())
		{ var tab=$('#tab').val();  
	     
	      if(tab!=3)
			{
				var drive = $('#search_drive').val();
				if(drive.length < 3)
					$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['TXTGLOBALSEARCHERROR'];?>");
				else
					$('#drive-view').visExecution('load_module',drive, {'vis_module':'selfhelp', 'vis_operation':'view_drive', 'vis_action':'no_load','criteria':drive});
			}
			else
			{
				
				var drive = $('#search_drive').val();
				if(drive.length < 4)
				$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['TXTGOOGLEDRIVESEARCHERROR'];?>");
				else
				$('#drive-view').visExecution('load_module',drive, {'vis_module':'selfhelp', 'vis_operation':'get_file_list','vis_action':'no_load','criteria':drive});	
			}
		}
	}
</script>


