<?php require_once('includes/requirecompere.inc.php'); require_once('includes/requirepost.inc.php'); require_once('includes/reservation.inc.php'); $cs_id=0+TPOST('cs_id'); $operation=TPOST('operation'); $action_next=TPOST('next'); $action_save=TPOST('save'); $mb_id_owner=current_mb_id(); $timezone_bias=get_user_time_zone()*60; $DBConn->connect(); if ($action_save) $DBConn->begin(true); $course=db_load_course_by_id($DBConn,$cs_id); if ($mb_id_owner!=$course['mb_id_owner']) { redirect("./"); $DBConn->rollback(); return; } $l_count=db_count_lectures_of_compere($DBConn,$mb_id_owner); $lecture_data=&$_SESSION['reserv.inputcache.data']; $time_ok=false; if ($action_next) { if (!$lecture_data) $lecture_data=array(); $lecture_data['cs_id']=$cs_id; $since_parts=array( 'since_year'=>TPOST('since_year'), 'since_month'=>TPOST('since_month'), 'since_day'=>TPOST('since_day'), 'since_hour'=>TPOST('since_hour'), 'since_minute'=>TPOST('since_minute'), 'since_second'=>'00' ); $lecture_data+=$since_parts; $lecture_data['lctr_since']=combine_datetime(array_key_cuthead($since_parts,'',6),$timezone_bias,false); $lecture_data['no_of_minutes']=TPOST('no_of_minutes'); $lecture_data['lctr_expire']=bias_datetime($lecture_data['lctr_since'],$lecture_data['no_of_minutes']*60); $lecture_data['lctr_status']=TPOST('lctr_status'); $lecture_data['clsr_id']=TPOST('clsr_id'); } $lctr_id=false; if ($lecture_data['lctr_since'] && $lecture_data['no_of_minutes'] && $lecture_data['lctr_expire']) { $time_ok=true; $clsr_id=$lecture_data['clsr_id']; if ($action_save) $lctr_id=$lecture_data['lctr_id']; else { $lctr_id=$lecture_data['lctr_id']=TPOST('lctr_id'); if ($lctr_id) { $lecture_cur=db_load_lecture_by_id($DBConn,$lctr_id); $clsr_id=$lecture_data['clsr_id']=$lecture_cur['clsr_id']; } } if ($operation=='modify') { $avail_clsr_ids=db_filter_for_available_classroom_grant( $DBConn, $clsr_id, $lecture_data['lctr_since'], $lecture_data['lctr_expire'], $lecture_data['lctr_id'] ); } else { $avail_clsr_ids=db_filter_for_available_classroom( $DBConn, $clsr_id, $lecture_data['lctr_since'], $lecture_data['lctr_expire'] ); $lecture_data['clsr_id']=$avail_clsr_ids?$clsr_id:null; } } if (!$lctr_id) $lctr_id=$lecture_data['lctr_id']; if (!$lctr_id) $lctr_id=0+TPOST('lctr_id'); $data_vacancy=iif_array4(array( array(!$lecture_data['cs_id'],'cs_id',1), array(!$lecture_data['clsr_id'],'clsr_id',1), array(!$lecture_data['lctr_since'],'lctr_since',1), array(!$lecture_data['lctr_expire'],'lctr_expire',1), array(!$lecture_data['lctr_status'],'lctr_status',1), )); $_SESSION['reserv.inputcache.errorareas']=iif_array4(array( array(!$lecture_data['lctr_since'],'ERROR-SINCE-INVALID',array(0)), array($lecture_data['lctr_since']==$lecture_data['lctr_expire'] ,'ERROR-LENGTH-INVALID',array(0)), array(TPOST('clsr_id') && !$lecture_data['clsr_id'] && $time_ok,'ERROR-NOCLASSROOM',array(0)), array($operation=='modify' && !$avail_clsr_ids,'ERROR-CLASSROOM-UNAVAIL',array(0)), array($operation=='addnew' && $l_count>=get_compere_limit($DBConn,$mb_id_owner,'lecture.count'),'ERROR-COUNT-LIMIT',array(0)) )); if (count_true_entries($data_vacancy)==0 && count_true_entries($_SESSION['reserv.inputcache.errorareas'])==0) $_SESSION['reserv.inputcache.okas']='lecture.'.$operation; else $_SESSION['reserv.inputcache.okas']=null; if ($operation=='addnew') { if ($_SESSION['reserv.inputcache.okas']) { if ($action_next) redirect("qx-cmd-course.lecture.addnew-op-confirm-cs_id-".$cs_id.".html"); else if ($action_save) { $lctr_id=db_insert_lecture($DBConn,$lecture_data); set_lecture_unit_income($DBConn,$lctr_id,$lecture_data['no_of_minutes'],$course); $course_staff=db_load_course_staff($DBConn,$cs_id); if (sizeof($course_staff)==1) db_save_lecture_staff($DBConn,$lctr_id,array($course_staff[0]['mb_id'])); $DBConn->commit(); if (sizeof($course_staff)==1) redirect("qx-cmd-course.lecture.detail-op-reserve.ok-lctr_id-".$lctr_id.".html"); else redirect("qx-cmd-course.lecture.staff-op-lecture--added-lctr_id-".$lctr_id.".html"); } else redirect("qx-cmd-course.lecture.addnew-cs_id-".$cs_id.".html"); } else redirect("qx-cmd-course.lecture.addnew-op-revise-cs_id-".$cs_id.".html"); } else if ($operation=='modify') { if ($_SESSION['reserv.inputcache.okas']) { if ($action_next) redirect("qx-cmd-course.lecture.modify-op-confirm-lctr_id-".$lctr_id.".html"); else if ($action_save) { db_update_lecture($DBConn,$lecture_data); $staff_ids=db_load_lecture_staff_ids($DBConn,$lctr_id); $staff_ids=db_filter_for_available_compere_grant( $DBConn, $staff_ids, $cs_id, $lecture_data['lctr_since'], $lecture_data['lctr_expire'], $lctr_id ); db_save_lecture_staff($DBConn,$lctr_id,$staff_ids); $DBConn->commit(); redirect("qx-cmd-course.lecture.detail-op-modified-lctr_id-".$lctr_id.".html"); } else redirect("qx-cmd-course.lecturelist-cs_id-".$cs_id.".html"); } else redirect("qx-cmd-course.lecture.modify-op-revise-lctr_id-".$lctr_id.".html"); } member_refresh_login($DBConn); $DBConn->rollback(); ?>