<? global $vis_language;
   $parent=(isset($operation['vis_category_id']) && is_numeric($operation['vis_category_id']))?$operation['vis_category_id']:0; ?>
   <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']; ?>/1"><? echo $vis_language['TXTSELFHELP']; ?></a></li>
		 <? if(isset($operation['vis_category_id'])) { ?>
         <li> <a href="#/selfhelp/view_categories/<? echo $vis_language['TXTCATEGORIES'];?>/1" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTCATEGORIES'].'/1'; ?>',{'vis_module':'selfhelp','vis_operation':'view_categories'});" class="link"><? echo $vis_language['TXTCATEGORIES']; ?></a></li>
		 <? }else{ ?>
         <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 class="active"> <? echo $vis_language['TXTADDARTICLE'];?></li>
      </ul>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><? echo $vis_language['TXTADDARTICLE']; ?></header>
      <div class="panel-body">
         <form  class="form-horizontal" name="vis_selfhelp_new_article_form" id="vis_selfhelp_new_article_form" method="post" enctype="multipart/form-data">
         
          
            
            <? if(isset($operation['vis_category_id'])){?>
				 <div class="form-group">
			<label class="col-sm-2 text-right"><?= $vis_language['TXTPARENTCATEGORY']; ?></label>
			<div class="col-sm-10">
				<span id="vis_parent_category" name="vis_parent_category" style="margin-top:20px;"><? echo $category['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 $domain;?>&vis_category_id=<? echo $operation['vis_category_id'];?>"><? echo $vis_language['TXTCHANGE']; ?></span>
			</div>
			</div>
			<? } else { ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTDOMAIN']; ?></label>
               <div class="col-sm-10">
                  <select id="vis_domain_id" name="vis_domain_id"  class="form-control input-sm selectpicker" <? if(count($domains)>10) echo 'data-live-search="true"';?>>
                     <?
                     if($domains!=-1) for($i=0;$i<count($domains); $i++){  ?>
					 <option value="<? echo $domains[$i]['domain_id']; ?>" ><? echo $domains[$i]['domain_name']; ?> </option>
					 <? } ?>
                  </select>
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label p-d-sm"><? echo $vis_language['TXTCATEGORY']; ?></label>
               <div class="col-sm-10" id="category">

				  <span id="vis_parent_category" name="vis_parent_category" style="margin-top:20px;"></span>
				  <span class="vis_button label vh-success-bg vis-pointer" id="category_list" onclick="get_category_list();"><? echo $vis_language['TXTSELECT']; ?></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_language" name="vis_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="" 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="" 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="text" class="form-control" id="tokenfield-typeahead" name="vis_article_keywords" value=""  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" rows="6" class="form-control"></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_new_selfhelp_attachments"></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_new_selfhelp_attachments', 'vis_form':'vis_selfhelp_new_article_form', 'vis_form_attachment_area':'#vis_selfhelp_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_selfhelp_attachments" id="vis_selfhelp_attachments" value="" />
						</div>
				    </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">
                  <input type="checkbox" checked="checked" name="vis_status"  id="vis_status">
                  <span ></span>
                  </label>
               </div>
            </div>
               <div class="form-group">
				  <label class="col-sm-12 setting-list">
				  <h4><? echo $vis_language['TXTPERMISSION']; ?></h4>
				  </label>
				</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" 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" checked="checked" ><i></i>
                  <?  echo $vis_language['TXTALLOWRATINGS']; ?>
                  </label>
               </div>
            </div>
            <?if($category['display_status']!=2){?>
			<div class="form-group" id="vis_permissions">
               <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" ><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"  ><i></i>
                  <?  echo $vis_language['TXTLOGINCOMPULSORYTOCLIENT']; ?>
                  </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 (isset($operation['vis_category_id']))?$operation['vis_category_id']:0;?>"/>
				    <?if(isset($operation['vis_article']) && $operation['vis_article']==1){?>
						<button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'selfhelp', 'vis_operation':'add_article', 'vis_form':'vis_selfhelp_new_article_form'})"><? echo $vis_language['TXTADD']; ?></button>
						<? } else {?>
                  <button type="button" class="btn btn-primary" onclick="reset_article_url();$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'selfhelp', 'vis_operation':'add_article', 'vis_form':'vis_selfhelp_new_article_form' ,'vis_article':'<? echo (isset($operation['vis_category_id']))?0:1; ?>','vis_domain_id':'<? echo $domain; ?>'})"><? echo $vis_language['TXTADD']; ?></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, // pixels
			imageUpload: "index.php?vis_tmpst="+new Date().getTime()+"&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",           
			imageUploadParam: 'files',
			plugins: ['source'],
			deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet']
		});
	});
	<? } ?>
    function vis_remove_attachment(ticket_id, attach_location){
		var loc = '';
		loc = (attach_location != "" && typeof(attach_location) != "undefined") ? attach_location : "vis_selfhelp_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(/_/, '-');
       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;
   }
   function get_category_list()
   {
	   var domain_id=document.getElementById("vis_domain_id").value;
	    $('#category_list').attr('data-toggle','ajaxModal');
		$('#category_list').attr('data-modal-arguments','vis_module=selfhelp&vis_operation=view_categories&vis_static_area=vis_client_merge_area&vis_domain_id='+domain_id+'&vis_set=1');
   }
			function changetextbylang(lang_id)
			{
				$("#vis_article_title").val("");
				$("#vis_article_url").val("");
				<? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>
							$("#vis_new_article_content").redactor("code.set", "");
						<? }else{ ?>
							$("#vis_new_article_content").val("");
					<?	}	?>
			}
</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() }]
		});
		
		$(function(){
			$("#vis_domain_id").change(function(){
				$("#vis_parent_category").html('');
				$("#vis_parent").val(0);
			});
		});
</script>
