<? global $vis_language;  
 
?>
    <div id="drive_list" class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"><? echo $vis_language['TXTDRIVE']; ?></h4> </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12">
                        <section class=" ">
                            <? if(isset($operation['vis_tab'])) {?>
                                <input type="hidden" name="tab" id="tab" value="<?=$operation['vis_tab'];?>" />
                                <? }else { ?>
                                    <input type="hidden" name="tab" id="tab" value="1" />
                                    <? }?>
                                        <header>
                                           
                                            <div class="wrapper-sm">
                                                <div class="form-inline">
                                                    <div class="form-group">
                                                        <a class="rtpcls btn btn-sm btn-rounded btn-default <? if(isset($operation['vis_tab'])){if(isset($operation['vis_tab']) && $operation['vis_tab']==1){?>btn-primary<? }?> <? }else{?>btn-primary<? }?> " onclick="$('#vis_details_list').visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'view_drive', 'vis_action': 'insert_ticket','vis_tab':'1'});$('#insrtbtndiv').show();$('#tab').val(1);;set_tab(1);">
                                                            <?php echo $vis_language['TXTALLFILE']; ?>
                                                        </a>
                                                    </div>
                                                    
                                                    <div class="form-group">
                                                        <a class="rtpcls btn btn-sm btn-rounded btn-default <? if(isset($operation['vis_tab'])){if(isset($operation['vis_tab']) && $operation['vis_tab']==5){?>btn-primary<? }?> <? }else{?>btn-primary<? }?> " onclick="$('#vis_details_list').visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'view_drive', 'vis_action': 'insert_ticket','vis_tab':'5'});$('#insrtbtndiv').show();$('#tab').val(5);;set_tab(5);">
                                                            <?php echo $vis_language['TXTMYFILE'];?>
                                                        </a>
                                                    </div>
                                                    <div class="form-group">
                                                        <a class="rtpcls btn btn-sm btn-rounded btn-default <? if(isset($operation['vis_tab'])){if(isset($operation['vis_tab']) && $operation['vis_tab']==2){?>btn-primary<? }?> <? }else{?>btn-primary<? }?> " onclick="$('#vis_details_list').visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'view_ticket_attachments', 'vis_action': 'insert_ticket','vis_tab':'2'}); $('#insrtbtndiv').show();$('#tab').val(2);;set_tab(2);">
                                                            <?php echo $vis_language['TXTTICKETATTACHMENTS'];?>
                                                        </a>
                                                    </div>
													
													 							
													
                                                    <?php if($gcal_details!='' && $gcal_details['is_enabled']!=0 && ($gcal_details['admin_user']!='' && $gcal_details['admin_user']!=0))
			        { ?>
                                                        <div class="form-group">
                                                            <a class="rtpcls btn btn-sm btn-rounded btn-default <? if(isset($operation['vis_tab'])){if(isset($operation['vis_tab']) && $operation['vis_tab']==3){?>btn-primary<? }?> <? }else{?>btn-primary<? }?> " onclick="$('#vis_details_list').visExecution('load_operations', {'vis_module':'selfhelp', 'vis_operation':'get_file_list', 'vis_action': 'insert_ticket','vis_tab':'3' }); $('#insrtbtndiv').show();$('#tab').val(3);;set_tab(3);">
                                                                <? echo $vis_language['TXTGOOGLEDRIVE']; ?>
                                                            </a>
                                                        </div>
                                                        <? }?>
                                                            <?php if($dropbox_details!='' && $dropbox_details['is_enabled']!=0)
			        { ?>
                                                                <div class="form-group">
                                                                    <a class="rtpcls btn btn-sm btn-rounded btn-default <? if(isset($operation['vis_tab'])){if(isset($operation['vis_tab']) && $operation['vis_tab']==6){?>btn-primary<? }?> <? }else{?>btn-primary<? }?> " onclick="$('#vis_details_list').visExecution('load_operations', {'vis_module':'selfhelp', 'vis_operation':'dropbox_details', 'vis_action': 'insert_ticket','vis_tab':'6' }); $('#insrtbtndiv').show();$('#tab').val(6);;set_tab(6);">
                                                                        <? echo $vis_language['TXTDROPBOX']; ?>
                                                                    </a>
                                                                </div>
                                                                <?}?>
                                                                    <div class="form-group aside-lg pull-right">
                                                                            <div class="col-xs-9">
                                                                                <div class="input-group ">
                                                                                    <input class="form-control rounded input-sm" type="text" placeholder="<?php echo $vis_language['TXTSEARCHDRIVE'];?>" value="<?php echo (isset($operation['criteria']))?$operation['criteria']:'';?>" id="search_drive"> <span class="input-group-btn">
                                                             <button class="btn btn-sm btn-rounded btn-default btn-icon" type="button" onclick="drive_search1();">
                                                                 <i class="vh vh-search"></i>
                                                             </button>
                                                         </span> </div>
                                                                            </div>
                                                                            <div class="col-xs-3">
                                                                                <div class="input-group">
                                                                                    <? if(isset($operation['vis_tab'])) {?>
                                                                                        <input type="hidden" name="tab" id="tab" value="<?=$operation['vis_tab'];?>" />
                                                                                        <? }else { ?>
                                                                                            <input type="hidden" name="tab" id="tab" value="1" />
                                                                                            <? }
															if((isset($operation['vis_check_id'])&&$operation['vis_check_id']==2)&& (isset($operation['vis_tab'])&&$operation['vis_tab']==3)){?>
                                                                                                <script>
                                                                                                    $('#upload_btn').hide();
                                                                                                </script>
                                                                                                <? }elseif(isset($operation['criteria']) && (isset($operation['vis_tab'])&& $operation['vis_tab']==3))
													{  ?>
                                                                                                    <script>
                                                                                                        $('#upload_btn').hide();
                                                                                                    </script>
                                                                                                    <?} else {?>
                                                                                                        <script>
                                                                                                            $('#upload_btn').show();
                                                                                                        </script>
                                                                                                        <? } ?>
                                                                                                            <!--<a id="upload_btn" class="btn btn-sm btn-primary btn-rounded" href="javascript:void(0)"  data-toggle="ajaxModal" data-modal-arguments="vis_module=selfhelp&vis_operation=upload_file&cache=true"><i class="vh vh-plus"></i><? echo " Upload"; ?></a>-->
                                                                                                            <a id="upload_btn" class="btn btn-sm btn-primary btn-rounded  " onclick="$('#vis_details_list').visExecution('load_operations', {'vis_module':'selfhelp', 'vis_operation':'upload1_file', 'vis_action':'insert_ticket','vis_tab':'8'}); $('#insrtbtndiv').hide();">
                                                                                                                <? echo 'Upload'; ?>
                                                                                                            </a>
                                                                                </div>
                                                                            </div>
                                                                    </div>
                                                </div>
                                            </div>
                                            <div> </div>
                                        </header>
                                         <div class="panel-body scrollable" style="height:400px;">
                                        <div class="slim-scroll" data-height="auto" data-disable-fade-out="true" data-distance="0" data-size="10px" data-railOpacity="0.2">
                                            <div class="tab-content">
                                                <div class="tab-pane active" id="vis_details_list">
                                                    <script language="javascript">
                                                        $('#vis_details_list').visExecution('load_operations', {
                                                            'vis_module': 'selfhelp'
                                                            , 'vis_operation': 'view_drive'
                                                            , 'vis_action': 'insert_ticket'
                                                        });
                                                    </script>
                                                </div>
                                            </div>
                                            </div>
                                        </div>
                        </section>
                        <div class="modal-footer" id="insrtbtndiv">
                            <a class="btn btn-primary m-l" id="btn" href="javascript:void(0);" onclick="vis_quick_insert_drive_url(<? echo (isset($operation['vis_action']) && $operation['vis_action']!='')?$operation['vis_action']:0;?>);" data-dismiss="modal">
                                <? echo "Insert"; ?>
                            </a>
                            <!--<button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'selfhelp', 'vis_operation':'add_quick_url_drive', 'vis_form':'vis_drive_form','vis_drive_item':'vis_drive_item.val();'})"><? echo $vis_language['TXTADD']; ?></button>-->
                            <a class="btn btn-default" data-dismiss="modal">
                                <? echo $vis_language['TXTCANCEL']; ?>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $('.rtpcls').click(function () {
            $('.rtpcls').removeClass('btn-primary');
            $(this).addClass('btn-primary');
        });

        function vis_quick_insert_drive_url(loc) {
            var checkboxes = document.getElementsByName('drive-item[]');
            var vals = "";
			var driveid;
			var tokens;
			var token_idarr="{";
            for (var i = 0, n = checkboxes.length; i < n; i++) {
			
                if (checkboxes[i].checked) {
					
					var chkvalue=checkboxes[i].value;
					chkval=chkvalue.split('/');
					driveid=chkval[chkval.length - 1];
					tokens=chkval[chkval.length - 3];
					
					token_idarr+='"'+driveid+'":"'+tokens+'",';
                   var firststr = chkvalue.substring(0, chkvalue.lastIndexOf("/")); 
					vals += '<br><a href="'+firststr+'">'+firststr+'</a>';
                }
            }
			
			  token_idarr = token_idarr.substring(0, token_idarr.length - 1); 
			token_idarr+="}";
			
            if (vals) {
			$.ajax({
            			url: 'index.php?vis_tmpst=new Date().getTime()',
            			data: {'vis_module':'selfhelp', 'vis_operation':'add_token', 'vis_as_val':$("#tab").val() ,'vis_form':'vis_drive_form','vis_value':vals,'token_idarr':token_idarr},
            			type: "POST",
            			
            			success: function(data) {
							$('#vis_ticket_post_' + loc).redactor('code.set', vals + '<br/>' + $('#vis_ticket_post_' + loc).redactor('code.get'));
							
						}
            		});
            }
           
            $(".modal").modal("toggle");
            document.getElementById('drive_list').style.display = "none"; 
        }

        function drive_search1() {
            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 searchfiles(drive, tab);
                }
                else {
                    var drive = $('#search_drive').val();
                    if (drive.length < 4) $("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['TXTGOOGLEDRIVESEARCHERROR'];?>");
                    else searchfiles(drive, tab);
                }
            }
        }

        function searchfiles(drive, tab) {
            var actionlink = '';
            if (tab == 2) {
                actionlink = 'index.php?vis_module=selfhelp&vis_operation=view_ticket_attachments&vis_action=insert_ticket&vis_tmpst=';
            }
												else if (tab != 3) {
                actionlink = 'index.php?vis_module=selfhelp&vis_operation=view_drive&vis_action=insert_ticket&vis_tmpst=';
            }
            else if (tab != 6) {
                actionlink = 'index.php?vis_module=selfhelp&vis_operation=view_drive&vis_action=insert_ticket&vis_tmpst=';
            }
            else {
                actionlink = 'index.php?vis_module=selfhelp&vis_operation=get_file_list&vis_action=insert_ticket&vis_tmpst=';
            }
            $.post(actionlink + new Date().getTime(), {
                'criteria': drive
                , 'vis_tab': tab
            }, function (data) {
                $("#vis_details_list").html(data);
																$('.rtpcls').removeClass('btn-primary');
            });
        }

	function set_tab(id)
   {   if(id==3 || id==6 ||id==2)
	   {
		   $('#upload_btn').hide(); 
	   }
	   else
	   {
		   $('#upload_btn').show();
	   }
	   document.getElementById("tab").value=id;
   }
    </script>
