<link type="text/css" rel="stylesheet" href="/css/webht/jquery.suggest.css" />
<style type="text/css">
.admin-list-unstyled{top: 35px !important;}
</style>

<form class="form-add-watch col-xs-24 nopadding" method="post" style="" action="<?php echo site_url('apps/workflow/index/do_add_work'); ?>">
  <?php 
    $year=isset($wf_time)?date('Y',strtotime($wf_time)):date('Y',strtotime("+1 month"));
    $month=isset($wf_time)?date('m',strtotime($wf_time)):date('m',strtotime("+1 month"));
    $month_n=isset($wf_time)?date('n',strtotime($wf_time)):date('n',strtotime("+1 month"));
    $days=cal_days_in_month(CAL_GREGORIAN,$month,$year);
    $weekarray=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
  ?>
  <div class="col-xs-24 zhiban-top" style="background:#fafafa;">
    <div class="col-xs-5" style="padding-top:8px;">
      <input type="text" class="noshadow noborder" style="font-size:14px;color:#666;width:100px;" name="wf_time" value="<?php $cdate=date('Y-m-d',strtotime("+1 month"));if(isset($wf_time)) $cdate=$wf_time; echo $cdate; ?>" readonly>
    </div>
    <div class="col-xs-14 text-center">
      <select name="wf_wt_sn" class="noshadow hidden-xs" style="border:1px solid #ddd;height:24px;width:110px;margin-top:8px;">
        <?php foreach ($typelist as $t) { ?>
          <option value="<?php echo $t->wt_sn.'@'.$t->wt_step; ?>" <?php if(isset($wf_wt_sn) && $wf_wt_sn==$t->wt_sn.'@'.$t->wt_step) echo 'selected' ?>><?php echo $t->wt_name; ?></option>
        <?php } ?>
      </select> 
      <input type="text" name="wf_user" class="text-center noshadow hidden" style="border:1px solid #ddd;width:100px;" value="<?php $userdata=$this->session->userdata('admin_chtcdn'); if(!isset($wf_user)) {echo $userdata['OPI_Name'];}else{echo $wf_user;} ?>" placeholder="姓名">
    </div>
    <div class="col-xs-5">
      <input type="hidden" name="wf_sn" value="<?php if(isset($wf_sn)) echo $wf_sn; ?>">
      <button type="button" class="btn btn-danger pull-right btn-add-watch <?php if(isset($nav_type))echo "hidden"; ?>" onclick="$(this).button('loading');setTimeout(function(){ajaxSubmit('.form-add-watch')},500);">提  交</button>
      <a id="btn-genghuan" class="pull-right hidden-xs <?php if(!isset($wf_sn)) echo 'hidden'; ?>" href="javascript:void(0);" data-flag="1" style="padding-top:8px;">更换值班</a>
    </div>
  </div>
  <legend></legend>
  <div class="col-xs-24 table-responsive">
    <table class="table table-bordered rotatable">
    <tr class="rotatable_bg">
      <th width="70">星期</th>
      <th width="60">日期</th>
      <th width="70">英文组中午值班</th>
      <th width="120">CH销售</th>
      <th width="60">CT</th>
      <th width="60">商务</th>
      <th colspan="2">国际</th>
      <th width="80">技术</th>
      <th width="70">计调</th>
      <th width="70">APP</th>
	  <th width="70">目的地</th>
	  <th width="70">亚洲事业部</th>
	  <th width="70">花梨鹰</th>
    </tr>
    <tr class="rotatable_bg">
      <th colspan="2">值班时间</th>
      <th>12点-13点</th>
      <th colspan="2">9:30-12:00,13:00-17:00</th>
      <th colspan="1">10:00-16:00</th>
      <th width="60">到办公室</th>
      <th width="120">VPN</th>
      <th>技术远程值班</th>
      <th>无团电话值班</th>
      <th>VPN(8:30-23:00)</th>
	  <th>VPN(8:30-23:00)</th>
	  <th>VPN(8:30-23:00)</th>
	  <th>VPN(8:30-23:00)</th>
    </tr>
    <?php for ($i=1; $i <= $days; $i++) { ?> 
      <?php 
      $week_no=date('w',strtotime($year.'-'.$month.'-'.$i));
      $ymd=$year.$month.$i;
      if (isset($flow_data)) {
        $en_uname=$flow_data['en_uname_'.$ymd];
        $ch_uname=$flow_data['ch_uname_'.$ymd];
        $ct_uname=$flow_data['ct_uname_'.$ymd];
        $sw_uname=$flow_data['sw_uname_'.$ymd];
        $eu_uname=$flow_data['eu_uname_'.$ymd];
        $vpn_uname=$flow_data['vpn_uname_'.$ymd];
        $js_uname=$flow_data['js_uname_'.$ymd];
        $jd_uname=$flow_data['jd_uname_'.$ymd];
        $app_uname=isset($flow_data['app_uname_'.$ymd])?$flow_data['app_uname_'.$ymd]:'';
		$trippest_uname=isset($flow_data['trippest_uname_'.$ymd])?$flow_data['trippest_uname_'.$ymd]:'';
		$ah_uname=isset($flow_data['ah_uname_'.$ymd])?$flow_data['ah_uname_'.$ymd]:'';
		$peregrine_uname=isset($flow_data['peregrine_uname_'.$ymd])?$flow_data['peregrine_uname_'.$ymd]:'';
        isset($flow_data['weekend_'.$ymd])? $weekend=$flow_data['weekend_'.$ymd]:$weekend=0;
      }
      ?>
    <tr class="rota_tr_box <?php if((!isset($wf_sn) && ($week_no==0 || $week_no==6)) || (isset($weekend) && $weekend==1)) echo 'rotatable_bg'; ?>">
      <td>
        <input class="<?php if(@$userdata['whu_isadmin']!=1) echo 'hidden'; ?>" type="checkbox" name="weekend_<?php echo $year.$month.$i;?>" value="1" <?php if(isset($weekend) && $weekend==1) echo 'checked'; ?>>
        <?php echo $weekarray[$week_no]; ?>
      </td>
      <td><?php echo $month_n.'月'.$i."日"; ?></td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="en_uname_<?php echo $year.$month.$i;?>"><?php if(isset($en_uname))echo $en_uname; ?></textarea>  
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="ch_uname_<?php echo $year.$month.$i;?>"><?php if(isset($ch_uname))echo $ch_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="ct_uname_<?php echo $year.$month.$i;?>"><?php if(isset($ct_uname))echo $ct_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="sw_uname_<?php echo $year.$month.$i;?>"><?php if(isset($sw_uname))echo $sw_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="eu_uname_<?php echo $year.$month.$i;?>"><?php if(isset($eu_uname))echo $eu_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="vpn_uname_<?php echo $year.$month.$i;?>" ><?php if(isset($vpn_uname))echo $vpn_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="js_uname_<?php echo $year.$month.$i;?>" ><?php if(isset($js_uname))echo $js_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="jd_uname_<?php echo $year.$month.$i;?>"><?php if(isset($jd_uname))echo $jd_uname; ?></textarea>
      </td>
      <td>
        <textarea title="双击我进行修改" class="form-control" name="app_uname_<?php echo $year.$month.$i;?>"><?php if(isset($app_uname))echo $app_uname; ?></textarea>
      </td>
	   <td>
        <textarea title="双击我进行修改" class="form-control" name="trippest_uname_<?php echo $year.$month.$i;?>" ><?php if(isset($trippest_uname))echo $trippest_uname; ?></textarea>
      </td>
	  <td>
        <textarea title="双击我进行修改" class="form-control" name="ah_uname_<?php echo $year.$month.$i;?>"><?php if(isset($ah_uname))echo $ah_uname; ?></textarea>
      </td>
	  <td>
        <textarea title="双击我进行修改" class="form-control" name="peregrine_uname_<?php echo $year.$month.$i;?>"><?php if(isset($peregrine_uname))echo $peregrine_uname; ?></textarea>
      </td>
    </tr>
    <?php } ?>
    </table>
  </div>
</form>

<div class="col-xs-24 genghuanbox hidden" style="background:#fff;">
<form class="form-horizontal" id="form-changerota" method="post" action="<?php echo site_url('apps/workflow/index/dochangerota'); ?>">
        <div class="modal-header">
          <h4 class="modal-title">更换值班</h4>
        </div>
        <div class="modal-body">
              <div class="form-group">
                <label class="col-xs-4 control-label">你的名字</label>
                <div class="col-xs-18">
                  <input type="text" class="form-control" name="yusername" autocomplete="off" value="<?php $userdata=$this->session->userdata('admin_chtcdn'); echo $userdata['OPI_Name']; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-xs-4 control-label">你的值班日期</label>
                <div class="col-xs-18">
                  <input type="text" class="form-control" id="y-rotadate" name="yrotadate" style="background: url('/css/nav/img/icon.png') no-repeat right !important;" autocomplete="off" value="" placeholder="如果你当月没有值班，此处请留空" readonly>
                </div>
              </div>
              <div class="form-group">
                <label class="col-xs-4 control-label">TA的名字</label>
                <div class="col-xs-18 msg_list_box" style="position:relative;">
                  <input type="text" class="form-control changeruser" name="tausername" autocomplete="off" value="">
                </div>
              </div>
              <div class="form-group">
                <label class="col-xs-4 control-label">TA的值班日期</label>
                <div class="col-xs-18">
                  <input type="text" class="form-control" id="ta-rotadate" name="tarotadate" style="background: url('/css/nav/img/icon.png') no-repeat right !important;" autocomplete="off" placeholder="如果TA当月没有值班，此处请留空" readonly>
                </div>
              </div>
        </div>
        <div class="modal-footer text-center">
          <input type="hidden" name="wf_sn" value="<?php echo $wf_sn; ?>">
          <button type="button" class="btn btn-danger" id="btn-changerota" onclick="ajaxSubmit('#form-changerota');"> 保存&更换 </button>
        </div>
      </form>
</div>

<script type="text/javascript" src="/js/jquery.suggest.js"></script>
<script type="text/javascript">

$('#btn-genghuan').on('click',function() {
  var flag=$(this).attr('data-flag');
  if (flag==1) {
    $(".rotatable").hide();
    $(".genghuanbox").removeClass('hidden');
    $(this).text('返回');
    $(this).attr('data-flag','0');
  }else{
    $(".rotatable").show();
    $(".genghuanbox").addClass('hidden');
    $(this).text('更换值班');
    $(this).attr('data-flag','1');
  }
  
});

$('#y-rotadate').datepicker({"dateFormat":"yy-mm-d"});
$('#ta-rotadate').datepicker({"dateFormat":"yy-mm-d"});

//自动提示
    var auto_complete_url="<?php echo site_url('apps/workflow/index/get_user_list'); ?>";
    $(".changeruser").suggest(auto_complete_url,{
          container: '.msg_list_box',
          onSelect: function() {
            var admin_list=$('.changeruser').val();
            var name_arr=admin_list.split(';');
            $('.changeruser').val(name_arr[0]);
          },
          selectClass: '',
          matchClass: 'active',
          resultsClass: 'list-unstyled admin-list-unstyled'
    });

<?php if(isset($wf_sn) && $userdata['whu_isadmin']!=1){ ?>
$(".rota_tr_box>td>textarea").dblclick(function(){
  $(this).removeAttr('readonly');
}).blur(function(){
  $(this).attr('readonly','readonly');
});
<?php } ?>

</script>