<? 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']); 
  $imgext_arr=array('ai','bmp','eps','gif','jpg','jpeg','png','psd','tiff','tif','svg','svgz');
		 
  
  
 
?>
<section class="wrapper">
    <section class="row">
        <form class="form-horizontal" name="vis_drive_form" id="vis_drive_form" method="post" enctype="multipart/form-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"></div>
                        <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($share_link['links']!=-1)
                    { for($i=0; $i<count($share_link['links'][$i]); $i++){ $flag=0; //$creation_date=$drive_info[$i][ 'creation_date']+ VIS_TIMEZONE;
				$date=date(VIS_DATE_FORMAT,$creation_date);
				$ext = pathinfo($share_link['links'][$i]['name'], PATHINFO_EXTENSION);
                    ?>
                    <a href="#" class="list-drive-a">
                        <div class="drive-info">
                            <div class="drive-checkbox">
                                <input id="drive-item-<? echo $share_link['links'][$i]['url']?>" name="drive-item[]" value="<a href=<? echo $share_link['links'][$i]['url']?>><? echo $share_link['links'][$i]['url']?></a> " type="checkbox" class="checkbox">
                                <i></i>
                            </div>
                            <div class="drive-item">
                                <?if($ext=='zip' || $ext=='patch' || $ext=='php' || $ext=='json' || $ext=='css' || $ext=='sql' || $ext=='mkdn' || $ext=='cpp' || $ext=='as') { ?>
      <i class="vh vh-file-text text-muted"></i>
      <?						
						 }
      elseif(in_array($ext,$imgext_arr) ) { ?>
	   <img src="<?= str_replace('www.dropbox.com','dl.dropboxusercontent.com',$share_link['links'][$i]['url']);?>" alt="<? echo $share_link['links'][$i]['url'];?>" />
       <?}
      else if($ext=='xlsx' || $ext=='xlsm' || $ext=='xls') { ?>
       <i class="vh vh-file-spreadsheet vh-file-spreadsheet-color"></i>
       <?} 
       else if($ext=='pdf') { ?>
      <i class="vh vh-file-pdf vh-file-pdf-color"></i>
       <?}
       else if($ext=='doc' || $ext=='docx' || $ext=='docm' || $ext=='ods' || $ext=='odt') { ?>
      <i class="vh vh-file-word vh-file-word-color"></i>
        <?}
        else if($ext=='csv' || $ext=='xhtml' || $ext=='xml') { ?>
      <i class="vh vh-file-spreadsheet vh-file-spreadsheet-color"></i>
        <?} 
        else if($ext=='txt' ) { ?>
      <i class="vh vh-file-text text-muted"></i>
        <?}
		
         else if($ext=='zip' ) { ?>
      <i class="vh vh-file-zip vh-file-zip-color"></i>
         <?} 
        else if($ext=='odp' || $ext=='pps' || $ext=='ppsm'|| $ext=='ppsx' || $ext=='ppt' || $ext=='pptm' || $ext=='pptx') { ?>
      <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>
                                       <?= $share_link['links'][$i]['name'];?>
                                </div>
                                <div class="drive-item-owner">
                                        <small>Owner</small>
                                        <?=$client_info['display_name'];?>
                                </div>
                                <div class="drive-item-size">
                                        <small>Size</small>
                                       <?= $share_link['links'][$i]['size'];?>KiB
                                </div>
                                <div class="drive-item-date">
                                        <small>Creation date</small>
                                        <?= $share_link['links'][$i]['client_modified']?>
                                </div> 
                        </div>
                    </a>
                    <?}
                        if($drive_details[0]['count']>$view_info['page_count'])
                    {?>
                    <div id="load_more_activities" onclick="javascript:mydrive_list_load(<?= $page+1;?>);">
                        <div style="text-align: center;"> <span class="link vis-pointer"><?= $vis_language['TXTLOADMORE'];?></span> </div>
                    </div>
                    <? 
                                                                            } 
                    }else
				   {
					include(VIS_PATH_TEMPLATE.'no_record_yet.php');
				   }?>
                </div>
            </div>
        </form>
    </section>
</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 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-modal-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-modal-view').visExecution('load_module', drive, {
                    'vis_module': 'selfhelp'
                    , 'vis_operation': 'get_file_list'
                    , 'vis_action': 'no_load'
                    , 'criteria': drive
                });
            }
        }
    }

    function mydrive_list_load(page) { <?
        if(isset($operation['vis_tab']) && $operation['vis_tab'] == 5) { ?>
            var tab = 5; <?
                                                                        }
            else if (isset($operation['vis_tab']) && $operation['vis_tab'] == 4) { ?>
                var tab = 4; <?
                                                                                 }
                else { ?>
                    var tab = 1; <?
                     } ?>
                         var drive = $('#search_drive').val();
                      $.post("index.php?vis_module=selfhelp&vis_operation=view_drive&vis_action=load&vis_tmpst=" + new Date().getTime(), {
                          'vis_page': page
                          , 'criteria': drive
                          , 'vis_tab': tab
                      }, function (data) {
                          $("#load_more_activities").last().remove();
                          $("#drive-modal-view").last().append(data);
                          //$("#load_more_activities").before(data);
                      });
                     }
</script>