<? global $vis_language;?>
<div id="article_list">
<div  style="margin: 30px auto;width: 700px;">
    <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['TXTSELFHELPSEARCH']; ?></h4>
        </div>
        <div class="modal-body ">
            <div class="row">
                <div class="col-sm-12">
			 <header class="panel-heading text-right bg-light clearfix">
                <ul class="nav nav-tabs pull-left no-borders" id="tabs">
					 <li  id="ticket_details" class="active"><a href= "#article_list" data-toggle="tab" oncontextmenu="return false;" onclick="$('#article_list').visExecution('load_operations',{'vis_module':'ticket', 'vis_operation':'article_search', 'vis_action': '','vis_domain_id': '<? echo $operation['vis_domain_id']; ?>','vis_tab':'1','vis_forward':'<? echo $operation['vis_forward'];?>','vis_reply':'<? echo $operation['vis_reply'];?>','vis_ticket_id':'<? echo  $operation['vis_ticket_id'];?>'})"><?php echo $vis_language['TXTSPECIFIC']; ?></a></li>
					<li  id="ticket_details" ><a href="#all_selfhelp_articles" data-toggle="tab" oncontextmenu="return false;" onclick="$('#all_selfhelp_articles').visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'get_article_list', 'vis_action': '','vis_domain_id': '<? echo $operation['vis_domain_id']; ?>','vis_tab':'2','vis_forward':'<?echo $operation['vis_forward'];?>','vis_reply':'<?echo $operation['vis_reply'];?>','vis_ticket_id':'<? echo $operation['vis_ticket_id'];?>'})"><?php echo $vis_language['TXTALL'];  ?></a></li>
				</ul>
			</header>
             <form method="post" role="form" class="form-horizontal" name="vis_problem_form" id="vis_problem_form">
			 <div id="all_selfhelp_articles" class="scrollable m-t" style="max-height: 300px">
			  <div class="form-group">
                   <div class="col-sm-12 text-center">
                   <input type="text" id="search_language_variables" onkeyup="vis_apply_filter(this.value);" placeholder="<?= $vis_language['TXTSELFHELPSEARCH'];?>" class="form-control">
                   </div>
				   <div class="col-sm-3"></div>
                </div>
                <div class="form-group" id="vis_show_amt_balance">
                    <div class="col-sm-12">
                        <div id="selfhelp_articles" class="scrollable m-t" style="max-height: 300px"></div>                        
                    </div>
                </div>
				</div>
              </form>
              </div>
            </div>
        </div>
        <div class="modal-footer">
			<a class="btn btn-default" data-dismiss="modal"><? echo $vis_language['TXTCANCEL']; ?></a>        
        </div>
    </div>
</div>
</div>
<script type="text/javascript">
	$('.selectpicker').selectpicker();
	function vis_apply_filter(){
		var filter = $("#search_language_variables").val();
	    var data = {'vis_filter_enable':'1', 'vis_filter':''+filter+'', 'vis_section':'ticket', 'vis_domain_id':'<?= $operation['vis_domain_id'];?>','vis_forward':'<?= $operation['vis_forward'];?>','vis_reply':'<?= $operation['vis_reply'];?>','vis_ticket_id':'<?= $operation['vis_ticket_id'];?>','vis_tab':'1'};
		if(filter!=''){
		  var len = filter.length;
		  if(len>2){
			$.ajax({
				url: 'index.php?vis_module=selfhelp&vis_operation=get_article_list',
				data: data,
				type: "POST",
				dataType: "json",
				success: function(data){
					if(data.vis_msg!=undefined)
					{
						$("#vis_global_msg_div").visInterface("load_global_message", data.vis_msg);
					}
					$("#selfhelp_articles").html(data.list);
				},
				error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
			});
		  }else{
			  $("#selfhelp_articles").html('<div style="text-align:center;"><?= $vis_language['TXTGLOBALSEARCHERROR'];?></div>');
		  }
		}
	}	
	function show_link(i)
	{
        $(".article_links").css("display",'none');
		if(document.getElementById('show_link_'+i).style.display == "none")
			document.getElementById('show_link_'+i).style.display = "block";	
		else
			document.getElementById('show_link_'+i).style.display = "none";	
	}
	function add_quick_attachments(position, article_id, vis_ticketid){
		var vis_attachments	= 'vis_attachments';
		var vis_formname = '';
		if(position == 'vis_reply_attachments')
		{
			vis_formname = '#vis_ticket_post_form_'+vis_ticketid;
		}
		if(position == 'vis_forward_attachments')
		{
			vis_attachments	= 'vis_fattachments';
			vis_formname = '#vis_ticket_forward_form_'+vis_ticketid;
		}
		if(position == 'vis_new_ticket_attachments')
		{
			vis_formname = '#vis_new_ticket_form';
		}
		
		$.post( 'index.php?vis_tmpst=new Date().getTime()', { 'vis_module': 'selfhelp', 'vis_operation': 'add_quick_attachments', 'vis_article_id': article_id, 'vis_ticket_action': 1, 'vis_ticket_id': vis_ticketid, 'attachment_ids' : $(vis_formname+" "+"#"+vis_attachments).val() }, function( data ) {console.log(data);
				$(vis_formname+" "+"#vis_ticket_post_" + vis_ticketid).append("");
				$(vis_formname+" "+"#"+vis_attachments).val(data.vis_attachment_ids);
				$(vis_formname+" "+"#"+position).html(data.vis_attachment_html);
			}, "json");
	}
	function vis_quick_insert_selfhelp_search(article_id, location){		
		$.ajax({
			url: 'index.php?vis_tmpst=new Date().getTime()',
			data: { 'vis_module': "selfhelp", 'vis_operation': "add_quick_article", 'vis_as_val':1, 'vis_article_id':article_id },
			type: "POST",
			success: function(data) {
                <? if($operation['vis_signature']==1){ ?>
				    $('#vis_ticket_post_'+location).redactor('code.set', data+'<br/>'+$('#vis_ticket_post_'+location).redactor('code.get'));
                <? }else{ ?>
                    $('#vis_ticket_post_'+location).redactor('code.set', data+'<br/>'+$('#vis_ticket_post_'+location).redactor('code.get'));
                <? } ?>
			}
		});$(".modal").modal("toggle");
		document.getElementById('article_list').style.display = "none";	
	}
	function vis_quick_insert_article_url(article_id, location){		
		$.ajax({
			url: 'index.php?vis_tmpst=new Date().getTime()',
			data: { 'vis_module': "selfhelp", 'vis_operation': "add_quick_url", 'vis_as_val':1, 'vis_article_id':article_id },
			type: "POST",
			success: function(data) {
				 <? if($operation['vis_signature']==1){ ?>
				   $('#vis_ticket_post_'+location).redactor('code.set', data+'<br/>'+$('#vis_ticket_post_'+location).redactor('code.get'));
                <? }else{ ?>
                   $('#vis_ticket_post_'+location).redactor('code.set', data+'<br/>'+$('#vis_ticket_post_'+location).redactor('code.get'));
                <? } ?>
			}
		});$(".modal").modal("toggle");
		document.getElementById('article_list').style.display = "none";	
	}
</script>
