<?php if(!defined('BASEPATH')) exit('No direct script access allowed');?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查看</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<?php $this->load->view('common/inc_styles.php');?>
<script type="text/javascript">
$(function () {
	//全选
	$("input[name='checkall']").click(function () {
		if ($(this).prop("checked") == true) {
			$(this).parent().parent().siblings(".col").find("input[type='checkbox']").prop("checked", true);
		} else {
			$(this).parent().parent().siblings(".col").find("input[type='checkbox']").prop("checked", false);
		}
		allusers();
	});
});
</script>
</head>
<body class="mainbody">
<div class="mian-page-div"> 
  
  <!--导航栏-->
  <?php $this->load->view('common/inc_head.php');?>
  <!--/导航栏-->
  
  <div class="users-div">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="users-list">
        <tr class="thead">
          <td width="6%" nowrap>部门</td>
          <td width="90%">人员</td>
          <td width="4%" nowrap>全选</td>
        </tr>
        <?php
foreach ($select_group as $arr0=>$row0) { 
$zi_nums = $this->data_model->get_count('set_group', array('isdel' => 0, 'parentid' => $row0['id']));
if($zi_nums>0){?>
        <tr>
          <td nowrap><?php echo $row0['name']?></td>
          <td></td>
          <td nowrap><span class="pretty primary">
            <input type="checkbox" name="checkall" onClick="allusers()"/>
            <label><i class="mdi mdi-check"></i> 全选 </label>
            </span></td>
        </tr>
        <?php 
            $zi_group = $this->mysql_model->get_results('set_group', array('isdel' => 0, 'parentid' => $row0['id'], 'order' => 'id asc'));
            foreach ($zi_group as $arr=>$row) {
            ?>
        <tr>
          <td nowrap style="padding-left:10px;">└─ <?php echo $row['name']?></td>
          <td class="col"><?php 
 foreach ($users as $arr1=>$row1) {
 if ($row1['groupid']==$row['id']) {
 ?>
            <span class="pretty primary">
            <input type="checkbox" name="users_dx[]" value="<?php echo $row1['realname']?>" <?php echo in_array($row1['realname'],$users_dx) ? 'checked' : ''?> <?php if($row1['realname']==$this->common_model->realname){?>disabled="disabled"<?php }?> onClick="allusers()"/>
            <label><i class="mdi mdi-check"></i> <?php echo $row1['realname']?> </label>
            </span>
            <?php }}?></td>
          <td nowrap><span class="pretty primary">
            <input type="checkbox" name="checkall" onClick="allusers()"/>
            <label><i class="mdi mdi-check"></i> 全选 </label>
            </span></td>
        </tr>
        <?php }}else{?>
        <tr>
          <td nowrap><?php echo $row0['name']?></td>
          <td class="col"><?php 
 foreach ($users as $arr1=>$row1) {
 if ($row1['groupid']==$row0['id']) {
 ?>
            <span class="pretty primary">
            <input type="checkbox" name="users_dx[]" value="<?php echo $row1['realname']?>" <?php echo in_array($row1['realname'],$users_dx) ? 'checked' : ''?> <?php if($row1['realname']==$this->common_model->realname){?>disabled="disabled"<?php }?> onClick="allusers()"/>
            <label><i class="mdi mdi-check"></i> <?php echo $row1['realname']?> </label>
            </span>
            <?php }}?></td>
          <td nowrap><span class="pretty primary">
            <input type="checkbox" name="checkall" onClick="allusers()"/>
            <label><i class="mdi mdi-check"></i> 全选 </label>
            </span></td>
        </tr>
        <?php }}?>
      </table>
    </div>
  <!--/内容--> 
  
  <!--工具栏-->
  <div class="h30"></div>
  <div class="page-footer">
    <div class="btn-wrap">
      <input type="hidden" id="users" value="">
      <?php if($this->common_model->is_mobile()==1){ //手机端?>
      <input type="submit" value="确认选择" class="btn submit" onClick="choose_ok()"/>
      <script>
	  function choose_ok(){
		 location.href='/index.php/baogao/add?users='+document.getElementById('users').value; 
	  }
	  </script>
      <?php }else{ //pc端?>
      <input type="submit" value="确认选择" class="btn submit" onClick="has_choose_users()"/>
      <?php }?>
      <input type="button" value="关闭" class="btn close" onclick="art.dialog.close();parent.layclose();" />
    </div>
  </div>
  <!--/工具栏--> 
  
</div>
<script>

function has_choose_users(){
	
var chk_value =[]; 
$('input[name="users_dx[]"]:checked').each(function(){ 
chk_value.push($(this).val()); 
});
var has_choose_users=chk_value.join(',');

$.dialog.open.origin.$('#tousers').val(has_choose_users);art.dialog.close();parent.layclose();
}


function allusers(){
    obj = document.getElementsByName("users_dx[]");
    check_val = [];
    for(k in obj){
        if(obj[k].checked)
            check_val.push(obj[k].value);
    }
	$("#users").val(check_val);
}
</script>
</body>
</html>