<? global $vis_language; ?>
      <form class="form-horizontal" data-validate="parsley" id="vis_staffgroup_form" name="vis_staffgroup_form" method="post" >
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTDEPARTMENTACCESS']; ?></label>
               <div class="col-sm-10">
                  <label class="checkbox-inline i-checks">
                  <input type="checkbox"  value="0" id="vis_department_all"  name="vis_department_all" onchange="toggle_dept_list();" <? if($staffgroup_details['department_access']==0) echo ' checked="checked"'; ?> ><i></i> <? echo $vis_language['TXTALLDEPARTMENTS']; ?>
                  </label>
               </div>
            </div>
            <div id="vis_dept_list_section" class="form-group" style="<?= ($staffgroup_details['department_access']==0)?'display:none':'';?>">
               <label class="col-sm-2 control-label"></label>
               <div class="col-sm-10">
				<div class="dept_access_list">   
                  <? $dept_list=array();
                     for($i=0;$i<count($department_details);$i++) {?>
                  <label class="checkbox-inline i-checks">
                  <input type="checkbox" id="vis_department" name="vis_department[]" <? if($staffgroup_details['department_access']==0 || in_array($department_details[$i]['department_id'], $department_access)) echo ' checked="checked"'; ?> value="<? echo $department_details[$i]['department_id']; ?>" /> <i></i><? echo $department_details[$i]['domain_name'].' :: '.$department_details[$i]['department_name']; ?></label><br/>
                  <?
                     $dept_list[]=$department_details[$i]['department_id'];
                     } ?>
                </div>     
               </div>
            </div>
            <input type="hidden" name="vis_department_count" id="vis_department_count" value="<? echo count($department_details); ?>" />
            <div class="line b-b line-lg pull-in"></div>
            <br/><br/>
            <div class="form-group">
               <div class="col-sm-4 col-sm-offset-2">
                  <button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'setting', 'vis_operation':'update_staff_group_department', 'vis_form':'vis_staffgroup_form'})"><? echo $vis_language['TXTUPDATE']; ?></button>
               </div>
            </div>
         <input type="hidden" name="vis_staff_id" id="vis_staff_id" value="<? echo $staffgroup_details['group_id']; ?>" /><input type="hidden" name="vis_dept_all_list" value="<?= implode(',',$dept_list) ?>" />
      </form>
<script>
   $(".selectpicker").selectpicker();
   function toggle_dept_list(){
       if($('#vis_department_all').is(":checked")){ $('#vis_dept_list_section').hide();
							}else{ $('#vis_dept_list_section').show();
							$('.dept_access_list').each(function(index) {
        $(this).find('input[type="checkbox"]').removeAttr('checked');
       });
							}
   }
</script>
