<div class="box-content">
    <form class="form-horizontal bv-form"  role="form"  id="updateAllForm">
        <input type="hidden" name="id" value="{$schedule.id}" id="updateNeedId">
        <fieldset>
            <div class="form-group">
                <label class="col-sm-3 control-label">班级</label>
                <div class="col-sm-5">
                    <select class="form-control" id="freeClassesUpdate" name="schedule_classid" style="height:35px;">
                        {volist name='classes' id='class'}
                        <option value="{$class.id}" {if $schedule.schedule_classid == $class.id} selected {/if}>{$class.classes_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">上课教室</label>
                <div class="col-sm-5">
                    <select class="form-control" id="freeClassroomsUpdate" name="schedule_classroomid" style="height:35px;">
                        {volist name='classroom' id='room'}
                        <option value="{$room.id}" {if $schedule.schedule_classroomid == $room.id} selected {/if}>{$room.classroom_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">开始日期</label>
                <div class="col-sm-5">
                    <input type="text" id="begintimeAll" class="form-control" name="schedule_starttime" value="<?php echo substr($schedule['schedule_starttime'],0,10); ?>"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">结束日期</label>
                <div class="col-sm-5">
                    <input type="text" id="overtimeAll" class="form-control" name="schedule_endtime" value="<?php echo substr($schedule['schedule_endtime'],0,10); ?>"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上课开始时间</label>
                <div class="col-sm-5">
                    <input type="text" id="classBegin" class="form-control" name="schedule_classbegin" value="{$schedule.schedule_classbegin}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上课结束时间</label>
                <div class="col-sm-5">
                    <input type="text" id="classOver" class="form-control" name="schedule_classover" value="{$schedule.schedule_classover}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上课时长</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" name="schedule_classlength" readonly id="lessontime" value="{$schedule.schedule_classlength}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">任课老师</label>
                <div class="col-sm-5">
                    <select class="form-control" id="freeTeachersUpdate" name="schedule_teacherid" style="height:35px;">
                        {volist name='teachers' id='teacher'}
                        <option value="{$teacher.id}" {if $schedule.schedule_teacherid == $teacher.id} selected {/if}>{$teacher.teacher_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上课安排</label>
                {for start='0' end='7'}
                {if $i==4}<div class="col-sm-3"></div>{/if}
                     <div class="col-sm-2">
                        <label class="checkbox">
                            <input type="checkbox"  name="schedule_perweek[]" value="{$i}" <?php if(in_array($i,$schedule['schedule_perweek'])){echo "checked";} ?>/>
                             {if $i==0} 星期天
                             {elseif $i==1}星期一
                             {elseif $i==2}星期二
                             {elseif $i==3}星期三
                             {elseif $i==4}星期四
                             {elseif $i==5}星期五
                             {elseif $i==6}星期六
                             {/if}
                         </label>

                     </div>
                {/for}
            </div>
        </fieldset>
    </form>
</div>
<script>
    $('#begintimeAll').datepicker({
        format : "yyyy-mm-dd",
        todayBtn : "linked",
        autoclose : true,
        todayHighlight : true,
        clearBtn : true,
        minView:'month'
    });
    $('#overtimeAll').datepicker({
        format : "yyyy-mm-dd",
        todayBtn : "linked",
        autoclose : true,
        todayHighlight : true,
        clearBtn : true,
        minView:'month'
    });
    $('#classBegin,#classOver').datetimepicker({
        format : "hh:ii",
        autoclose : true,
        startView:1
    });
    $("#classOver,#classBegin").change(function(){
        var begin = $('#classBegin').val().split(':');
        var over = $('#classOver').val().split(':');
        var beginM = parseInt(begin[0]*60) + parseInt(begin[1]);
        var overM = parseInt(over[0]*60) + parseInt(over[1]);
        if(begin && over && overM > beginM){
            $('#lessontime').val(overM-beginM);
        }else{
            $('#lessontime').val('无效');
        }
    });
    $("#begintimeAll,#overtimeAll").change(function(){
        var begin = $('#begintimeAll').val();
        var over = $('#overtimeAll').val();
        if(over < begin){
            $('#overtimeAll').css('border','1px solid red');
        }else{
            var id = $('#updateNeedId').val();
            $('#overtimeAll').css('borderColor','');
            //处理班级教室老师的空闲关联问题
            $.ajax({
                url: 'admin/Arrange/updateGetFreeDatas',
                type: 'POST',
                data:'start='+begin+'&end='+over+'&id='+id,
                dataType: 'JSON',//返回的数据类型
                success: function (data) {
                    var teachers = data.msg['freeTeachers'];
                    var classes = data.msg['freeClasses'];
                    var rooms = data.msg['freeClassrooms'];
                    $("#freeClassesUpdate").empty();
                    for (var i = 0; i < classes.length; i++) {
                        $("#freeClassesUpdate").append('<option value="' + classes[i].id + '">' + classes[i].classes_name + '</option>');
                    }
                    $("#freeTeachersUpdate").empty();
                    for (var o = 0; o < teachers.length; o++) {
                        $("#freeTeachersUpdate").append('<option value="' + teachers[o].id + '">' + teachers[o].teacher_name + '</option>');
                    }
                    $("#freeClassroomsUpdate").empty();
                    for (var u = 0; u < rooms.length; u++) {
                        $("#freeClassroomsUpdate").append('<option value="' + rooms[u].id + '">' + rooms[u].classroom_name + '</option>');
                    }
                }
            });
        }
    })

</script>