<? global $vis_language; ?>
   <link rel="stylesheet" href="<?= VIS_PATH_SCRIPT; ?>tokenfield/bootstrap-tokenfield.min.css" type="text/css" />
   <link rel="stylesheet" href="<?= VIS_PATH_SCRIPT; ?>tokenfield/tokenfield-typeahead.min.css" type="text/css" />
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
   <div class="col-sm-6">
      <h3 class="m-b-xs text-black"><? echo $operation['view_title'];?></h3>
      <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
         <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
		<li><a class="link" href="#/selfhelp/view_selfhelp/<? echo $vis_language['TXTSELFHELP']; ?>"><? echo $vis_language['TXTSELFHELP']; ?></a></li>
         <li> <a href="#/selfhelp/view_articles/<? echo $vis_language['TXTARTICLES']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTARTICLES']; ?>',{'vis_module':'selfhelp','vis_operation':'view_articles'});" class="link"><? echo $operation['view_title']; ?></a></li>
         <li> <a href="#/selfhelp/view_article/<? echo addslashes(str_replace(array('"', "'", '/', '\\'), '',$article['article_url'])).'/'.$article['article_id'];  ?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo addslashes(str_replace(array('"', "'", '/', '\\'), '',$article['article_title'].'/'.$article['article_id'])); ?>',{'vis_module':'selfhelp','vis_operation':'view_article','vis_action':'<? echo $operation['vis_action']; ?>'});" class="link"><?  echo (strlen($article['article_title'])>15)?substr($article['article_title'],0,25).".....":$article['article_title']; ?></a></li>
         <li class="active"> <? echo $vis_language['TXTUPDATEARTICLE'];?></li>
      </ul>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><? echo $vis_language['TXTUPDATEARTICLE']; ?></header>
      <div class="panel-body">
         <form  class="form-horizontal" name="vis_selfhelp_article_form" id="vis_selfhelp_article_form" method="post" enctype="multipart/form-data">
		  <input type="hidden" id="vis_article_id" name="vis_article_id" value="<? echo $article['article_id']; ?>" />
	 	 <input type="hidden" name="vis_action" value="<? echo $operation['vis_action']; ?>" />
    
    
    
  
  <div class="form-group">
			<label class="col-sm-2 text-right"><?= $vis_language['TXTCATEGORY']; ?></label>
			<div class="col-sm-10">
				<span id="vis_parent_category" name="vis_parent_category" style="margin-top:20px;"><? echo $parent_category_details['selfhelp_title']; ?></span>
				<span class="vis_button label vh-success-bg m vis-pointer" data-toggle="ajaxModal" data-modal-arguments="vis_module=selfhelp&vis_operation=view_categories&vis_static_area=vis_client_merge_area&vis_set=1&vis_domain_id=<? echo $article['domain_id'];?>"><? echo $vis_language['TXTCHANGE']; ?></span>
			</div>
			</div>
   
   <div class="form-group">
			<label class="col-sm-2 control-label"><? echo $vis_language['TXTLANGUAGE']; ?></label>
			<div class="col-sm-10">
				<select class="form-control input-sm selectpicker" id="vis_art_language" name="vis_art_language" <? if(count($language_list)>10) echo 'data-live-search="true"';?> onchange="changetextbylang(this.value);"> <?
				for($i=0;$i<count($language_list);$i++) { ?>
					<option value="<? echo $language_list[$i]['language_id']; ?>"<? if($poral_setting['vis_manage_language']==$language_list[$i]['language_id']) echo ' selected="selected"'?>><? echo $language_list[$i]['language_name']; ?></option><?
				} ?> </select>
			</div>
		</div>
  
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTTITLE']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_article_title" id="vis_article_title"  value="<? //echo $article['article_title']; ?>" onblur="set_article_url()"/>
               </div>
            </div>
             <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTURL']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_article_url" id="vis_article_url" value="<? //echo $article['article_url']; ?>" onblur="reset_article_url()"/>
               </div>
            </div>
              
			<div class="form-group">
				<label class="col-sm-2 control-label"><? echo $vis_language['TXTKEYWORDS']; ?></label>
				<div class="col-sm-10"> <input type="hidden" name="vis_keyword" id="vis_keyword" value="" />
					<input type="text" class="form-control" id="tokenfield-typeahead" name="vis_article_keywords" value="<? echo $article['article_keywords']; ?>" placeholder="<?= $vis_language['TXTTYPEHEREART']; ?>"/>
				</div>
			</div>
		   <div class="form-group">
			  <label class="col-sm-2 control-label"><? echo $vis_language['TXTCONTENT']; ?></label>
			  <div class="col-sm-10">
				 <div id="vis_article_content">
					<textarea name="vis_article_content" id="vis_new_article_content" class="form-control"><? //echo $article['content']; ?></textarea>
				 </div>
			  </div>
		   </div>
			<div class="form-group">
					<div class="col-sm-12">
						<label class="col-sm-2 control-label"></label>
						<div class="col-sm-8 p-l-none">
						<div id="vis_selfhelp_attachments">
			   			<?php
                        $atts='';
                        if($attachments!=-1) {
                            for($i=0;$i<count($attachments);$i++) {
                                $atts.=$attachments[$i]['attachment_id'].','; ?>
                       <!-- <div class="btn-group wrapper-xxs"><label class="btn btn-xs alert-success"><?php echo $attachments[$i]['file_name']; ?></label><button class="btn btn-xs alert-success" type="button" data-dismiss="alert" onclick='$(this).parent().remove(); $(this).visExecution("load_operations", {"vis_module":"ticket", "vis_operation":"remove_attachment", "vis_attachment_id":<?php echo $attachments[$i]["attachment_id"] ?>}); vis_remove_attachment(<?php echo $attachments[$i]["attachment_id"] ?>, "vis_attachments");'>&times;</button></div>--><?
                            }
                            }
                            ?>
						</div>
						</div>
						<div class="col-sm-2 p-r-none text-right">
							<input type="file" name="files[]" multiple="multiple" class="filestyle" data-icon="false" data-classButton="btn btn-link link" data-buttonText="<? echo $vis_language['TXTATTACHFILE']; ?>" data-input="false" onchange="$(this).visExecution('upload_file', {'vis_static_area':'#vis_selfhelp_attachments', 'vis_form':'vis_selfhelp_article_form', 'vis_form_attachment_area':'#vis_attachments'});">
							<input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" />
						    <input type="hidden" name="vis_parent_type" value="1" />
							<input type="hidden" name="vis_attachments" id="vis_attachments" value="<?php echo $atts; ?>" />
						</div>
				    </div>
            </div>
			<div class="form-group">
               <label class="col-sm-2 control-label"></label>
               <div class="col-sm-5">
                  <label class="checkbox-inline i-checks m-r-lg">
                  <input value="1" name="vis_article_comment" id="vis_article_comment" type="checkbox" <? echo ($article['can_comment']==1)?' checked="checked"':''; ?> /><i></i>
                  <?  echo $vis_language['TXTALLOWCOMMENTS']; ?>
                  </label>
				</div>
				<div class="col-sm-5">
                  <label class="checkbox-inline i-checks m-r-lg">
                  <input value="1" name="vis_article_rating" id="vis_article_rating" type="checkbox" <? echo ($article['can_rate']==1)?' checked="checked"':''; ?>><i></i>
                  <?  echo $vis_language['TXTALLOWRATINGS']; ?>
                  </label>
               </div>
            </div>
			<div class="form-group">
               <label class="col-sm-2 control-label"></label>
				<div class="col-sm-5">
                  <label class="checkbox-inline i-checks m-r-lg">
                  <input value="1" name="vis_article_stick" id="vis_article_stick" type="checkbox" <? echo ($article['is_stick']==1)?' checked="checked"':''; ?> ><i></i>
                  <?  echo $vis_language['TXTSETASFEATUREDARTICLE']; ?>
                  </label>
               </div>
               <div class="col-sm-5">
                  <label class="checkbox-inline i-checks m-r-lg">
                  <input value="1" name="vis_article_login" id="vis_article_login" type="checkbox" <? echo ($article['need_login']==1)?' checked="checked"':''; ?>  ><i></i>
                  <?  echo $vis_language['TXTLOGINCOMPULSORYTOCLIENT']; ?>
                  </label>
				</div>
            </div>
			<div class="form-group">
			  <label class="col-sm-2 control-label" ><? echo $vis_language['TXTSTATUS']; ?></label>
			  <div class="col-sm-1">
				 <label class="switch  <? if($article['is_enabled']==0) echo 'radio-no-uncheck'; ?>  ">
				 <input type="checkbox"  name="vis_status"  id="vis_status" <? if($article['is_enabled']==1) echo ' checked="checked"'; ?>>
				 <span ></span>
				 </label>
			  </div>
 			</div>
            <div class="line b-b line-lg pull-in"></div>
            <br/>
            <div class="form-group">
               <div class="col-sm-4 col-sm-offset-2">
				    <input name="vis_parent" id="vis_parent" type="hidden"  value="<? echo $article['parent_id'];?>"/>
        <input name="vis_art_parent_id" id="vis_art_parent_id" type="hidden"  value="<? echo $article['art_parent_id'];?>"/>
                  <button type="button" class="btn btn-primary" onclick="reset_article_url();$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'selfhelp', 'vis_operation':'update_article', 'vis_form':'vis_selfhelp_article_form'})"><? echo $vis_language['TXTUPDATE']; ?></button>
               </div>
            </div>
      </form>
      </div>
   </section>
</section>
<script language="javascript">
   $(".selectpicker").selectpicker();
    <? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>
	$(function(){
		$('#vis_new_article_content').redactor({ 
			maxHeight: '180px',
            minHeight: 180,
			plugins: ['source'],
			deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet'],
			imageUpload: "index.php?vis_tmpst="+new Date().getTime()+"&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",         
			imageUploadParam: 'files',
			imageUploadErrorCallback: function(json)
			{
				 $("#vis_global_msg_div").show();
				 document.getElementById("vis_global_msg_div").innerHTML = json.message;
				 setTimeout( function(){ $("#vis_global_msg_div").hide().html(''); }, 10000);
			}
		});
	});
   <? } ?>
    function vis_remove_attachment(ticket_id, attach_location){
		var loc = '';
		loc = (attach_location != "" && typeof(attach_location) != "undefined") ? attach_location : "vis_attachments";
		$("#" + loc).val( $("#" + loc).val().replace(ticket_id + ',', '') );
	}
	function set_article_url(){
       var title = document.getElementById('vis_article_title').value;
	   title = title.replace(/_/, '-');
       title = title.replace(/[&\/\\#,+()$@^!`=;|~%.'":*?<>{}]/g, '');
	   title = title.replace(/_/g, '-');
       var url = title.trim().replace(/_+(?=)/g,"-");
       document.getElementById('vis_article_url').value=url;
   }
  function reset_article_url(){
       var title = document.getElementById('vis_article_url').value;
	   title = title.replace(/_/, '-');
       title = title.replace(/[&\/\\#,+()$@^!`=;|~%.'":*?<>{}]/g, '');
	   title = title.replace(/_/, '-');
       var url = title.trim().replace(/ +(?=)/g,"-"); 
       document.getElementById('vis_article_url').value=url;
   }
	changetextbylang($("#vis_art_language").val());	
	function changetextbylang(lang_id)
	{
		var data = { 'vis_action': $("#vis_selfhelp_article_form").serialize(), 'vis_module': 'selfhelp', 'vis_operation': 'get_articaldetailsby_language', 'vis_form': 'vis_selfhelp_article_form'};
					$.ajax({
			url: 'index.php',
			data: data,
			type: "POST",
			success: function(data) {
				$('#vis_global_msg_div').html(data); 
				
					var key = $('#vis_keyword').val();
					if(key!=''){
						$('#tokenfield-typeahead').tokenfield('setTokens', key);
					    $('#tokenfield-typeahead').val(key);
					}else {
						$('#tokenfield-typeahead').tokenfield('setTokens', []);
						$('#tokenfield-typeahead').val('');}
						
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
	}
</script>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<script src="<?= VIS_PATH_SCRIPT; ?>tokenfield/bootstrap-tokenfield.min.js"></script>
<script src="<?= VIS_PATH_SCRIPT; ?>tokenfield/typeahead.bundle.min.js"></script>
<script>
		var engine = new Bloodhound({
			local: [{value: ''}],
			datumTokenizer: function(d) {    return Bloodhound.tokenizers.whitespace(d.value);  },
			queryTokenizer: Bloodhound.tokenizers.whitespace
		});

		engine.initialize();

		$('#tokenfield-typeahead').tokenfield({
			minLength: 2,
			createTokensOnBlur: true,
			delimiter: [',', '|',' '],
		    typeahead: [null, { source: engine.ttAdapter() }]
		});
</script>
