<? global $vis_language;
    $parent=(isset($operation['vis_parent_id']) && is_numeric($operation['vis_parent_id']))?$operation['vis_parent_id']:0; ?>
<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>
         <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 $operation['view_title']; ?></a></li>
         <li class="active"> <? echo $vis_language['TXTADDCATEGORY'];?></li>
      </ul>
      <div>
      </div>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><? echo $vis_language['TXTADDCATEGORY']; ?></header>
      <div class="panel-body">
         <form  class="form-horizontal" name="vis_new_category_form" id="vis_new_category_form" method="post">
		 <input type="hidden" name="vis_domain" value="<? echo $domain; ?>" />
            <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 vis_input" type="text" name="vis_category_title"  value="">
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTDESCRIPTION']; ?></label>
               <div class="col-sm-10">
                  <textarea class="form-control input-sm" name="vis_description"></textarea>
               </div>
            </div>
            <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 ($operation['vis_parent_id']==0) ? $vis_language['TXTROOT'] : $parent_category_details['selfhelp_title']; ?></span>
				<?if($operation['vis_parent_id']!=0) {?><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;?>"><? echo $vis_language['TXTCHANGE']; ?></span><? } ?>
			</div>
			</div>
           
			<div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTORDERBY']; ?></label>
               <div class="col-sm-10">
                  <select name="vis_order" class="form-control input-sm selectpicker">
                <option value="0"><? echo$vis_language['TXTNEWFIRST']; ?></option>
                <option value="1"><? echo$vis_language['TXTOLDFIRST']; ?></option>
                <option value="2"><? echo$vis_language['TXTMODIFIEDFIRST']; ?></option>
                  </select>
               </div>
            </div>
             <? if($operation['vis_parent_id']==0 ) {?>
			<div class="form-group"  >
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTVISIBLETO']; ?></label>
               <div class="col-sm-10" >
                  <select id="vis_display" name="vis_display" class="form-control input-sm selectpicker"  onchange="access_postarticle($(this).val());">
                <option value="0"><? echo$vis_language['TXTEVERYBODY']; ?></option>
                <option value="1"><? echo$vis_language['TXTLOGGEDINCLIENT']; ?></option>
                <option value="2"><? echo$vis_language['TXTSTAFFONLY']; ?></option>
                  </select>
               </div>
            </div>
			 <? }?>
			<?//THIS ONE FOR SEARCH CLIENTS NAME STARTS ?>
			<?// if($parent_category_details['display_status']==1)
			if($operation['vis_parent_id']==0 ){?>
			<div class="form-group" id="visible" >
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTVISIBLETO']." ".strtolower($vis_language['TXTCLIENTS']); ?></label>
			   <div class="col-sm-10">
                        
						<input type="hidden" name="domain"  value="<? echo $operation['vis_domain_id'];?>">
                              <input type="text" class="form-control" id="vis_assignto" name="vis_assignto" placeholder="<? echo $vis_language['TXTSEARCHCLIENTS'];?>" data-resize="no">
                              <script type="text/javascript">
                                 $(document).ready(function() {
                                 	$("#vis_assignto").tokenInput(	"index.php?vis_module=selfhelp&vis_operation=client_listing&vis_domain_id=<? echo $operation['vis_domain_id'];?>",
                                 		{
                                 			theme: "facebook",
                                 			searchDelay: 300,
                                 			minChars: 1,
                                 			queryParam: "vis_data",
                                 			preventDuplicates: true,
                                 			propertyToSearch: "full_name",
                                 			tokenValue: "full_name",
                                 			searchingText: "<? echo $vis_language['MSGSEARCHING']."..."; ?>",
                                 			noResultsText: "<? echo $vis_language['TXTNOMATCHFOUND']; ?>",
                                 			resultsFormatter: function(item){
											if(item.type=="heading"){
                                 				return "<b>" + "<div style='cursor:pointer;display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.full_name + "</div></div></b>"
                                 			}
                                 			else{ 
											
											return "<li>" + "<div style='display: inline-block; padding-left: 10px;margin-left:30px;'><div class='full_name'>" + item.full_name + "</div></div></li>"	} },
                                 			tokenFormatter: function(item) { if(item.id){$('#vis_task_grp_share').val($('#vis_task_grp_share').val()+item.id+',');}return "<li><p>" + item.full_name + "</p></li>" },
                                 			onDelete: function(item){
                                 if(item.id)
                                 {
                                 var staffs = $('#vis_task_grp_share').val();
                                 var old_staffs = $('#vis_old_staff').val();
                                 var Staffs1 = old_staffs.replace(item.id+',', '');
                                 $('#vis_old_staff').val(Staffs1);
                                 var newStaffs = staffs.replace(item.id+',', '');
                                 $('#vis_task_grp_share').val(newStaffs);

                                 }
                                 else
                                 {
                                 var staffs = $('#vis_task_share').val();
                                 var staffIds = $('#vis_staff').val();
                                 var newStaffs = staffs.replace(item.id+',', '');
                                 $('#vis_task_share').val(newStaffs);
                                 $('#vis_staff').val(newStaffs);
                                 }
                                 },
                                 onAdd: function(item)
                                 {
                                 if(item.type == "heading")
                                 {
                                 $("#vis_assignto").tokenInput("remove", {full_name: item.full_name});
                                 }
                                 }
                                 		}
                                 	);
                                 	<? if($assign_task_details!=-1) for($i=0 ; $i<count($assign_task_details); $i++){?>
                                 		$("#vis_assignto").tokenInput("add", {id: "<?= $assign_task_details[$i]['owner_id']; ?>", full_name: "<?= $assign_task_details[$i]['first_name']." ".$assign_task_details[$i]['last_name']; ?>"});<? } ?>
                                 });
                              </script>
                              <input type="hidden" id="vis_task_grp_share" name="vis_task_grp_share"/>
                              <input type="hidden" id="vis_task_share" name="vis_task_share"/>
                              <input type="hidden" id="vis_staff" name="vis_staff" value=""/>
                              <input type="hidden" id="vis_old_staff" name="vis_old_staff" value="<?echo $old_staff;?>"/>
                           </div>
                       
					 </div>
			
			 <div class="form-group" id="visible_organization">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTVISIBLETO']." ".strtolower($vis_language['TXTORGANIZATION']); ?></label>
               <div class="col-sm-10">
				   <div class="dept_access_list">
                  <?
                     for($i=0; $i<count($client_group); $i++) {
                         $organisation_display_list.=$client_group[$i]['group_id'].",";
                        
                      ?>
                  <label class="checkbox-inline i-checks">
                  <input type="checkbox" value="<? echo $client_group[$i]['group_id']; ?>"  name="vis_staff_team[]" /> <i></i>&nbsp;<? echo $client_group[$i]['group_name']; ?></label><br/>
                  <? } ?>
                  <input type="hidden" value="<? echo $organisation_display_list; ?>" name="org_display_list" style="display:none;" />
               </div>
               </div>
            </div>
			<? } ?>
			<?//THIS ONE FOR THE CLIENT GROUP ENDS ?>
			<? //if($operation['vis_parent_id']==0) {?>
			<!-- /// remove post article from root category :
			<div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTPOSTARTICLE']; ?></label>
               <div class="col-sm-10" id="vis_post_article">
                  <select name="vis_access" class="form-control input-sm selectpicker">
                <option value="0"><? //echo$vis_language['TXTSTAFFONLY']; ?></option>
                <option value="1"><? //echo$vis_language['TXTLOGGEDINCLIENT']; ?></option>
                  </select>
               </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_enabled"  id="vis_enabled" >
                  <span ></span>
                  </label>
               </div>
            </div>
            
            <? if($language_details1!=-1) { ?>
            <div class="form-group">
               <div class="col-sm-3"><h5><? echo $vis_language['MSGLANGTRANSFORCATEGORYTITLE']; ?></h5></div>
            </div>
            <div class="line b-b line-lg pull-in"></div>
            <br/>
            <?
               for($i=0;$i<count($language_details1);$i++) { ?>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $language_details1[$i]['language_name']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_language_<? echo $language_details1[$i]['language_id']; ?>"  value="<? echo $cat_lang[$language_details1[$i]['language_id']]; ?>" >
               </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 ($operation['vis_parent_id']==0) ? 0 : $operation['vis_parent_id'];?>"/>
				    <? if($operation['vis_parent_id']!=0) {?>
				    <input name="vis_type" type="hidden" value="<? echo $parent_category_details['content_type']; ?>" />
				     <input name="vis_display" type="hidden" value="<? echo $parent_category_details['display_status']; ?>" />
				      <input name="vis_access" type="hidden" value="<? echo $parent_category_details['article_access']; ?>" />
				       <input name="vis_language_id" type="hidden" value="<? echo $parent_category_details['language_id']; ?>" /><? } ?>
                  <button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'selfhelp', 'vis_operation':'add_category', 'vis_form':'vis_new_category_form' ,'vis_domain_id':<? echo $domain; ?>})"><? echo $vis_language['TXTADD']; ?></button>
               </div>
            </div>
      </div>
      </form>
      </div>
   </section>
</section>
<script>
   $(".selectpicker").selectpicker();
   function access_postarticle(visible_to)
   {
	   if(visible_to==0){
	   $('#vis_post_article').html('<select name="vis_access" class="form-control input-sm selectpicker"><option value="0"<? echo ($category['article_access']==0)?' selected="selected"':''; ?>><? echo $vis_language['TXTSTAFFONLY']; ?></option><option value="1"<? echo ($category['article_access']==1)?' selected="selected"':''; ?>><? echo $vis_language['TXTLOGGEDINCLIENT']; ?></option></select>');
	     $('#visible').hide();
	   $('#visible_organization').hide();}
	   else if(visible_to==1){
	   $('#vis_post_article').html('<select name="vis_access" class="form-control input-sm selectpicker"><option value="1"<? echo ($category['article_access']==1)?' selected="selected"':''; ?>><? echo $vis_language['TXTLOGGEDINCLIENT']; ?></option></select>');
		$('#visible').show();
	   $('#visible_organization').show();}
	   else if(visible_to==2){
	   $('#vis_post_article').html('<select name="vis_access" class="form-control input-sm selectpicker"><option value="0"<? echo ($category['article_access']==0)?' selected="selected"':''; ?>><? echo $vis_language['TXTSTAFFONLY']; ?></option></select>');
	   $(".selectpicker").selectpicker();
	   $('#visible').hide();
	   $('#visible_organization').hide();}
   }
   
		 
  var vis_visible_to=$("#vis_display").val();
		 if(vis_visible_to==0){
   $('#visible_organization').hide();
   $('#visible').hide();
		 } else if(vis_visible_to==1){
			  $('#visible').show();
	   $('#visible_organization').show();
		 } else if(vis_visible_to==2){
			  $('#visible').hide();
	  $('#visible_organization').hide();
		 }

  
</script>
