<?php require_once('includes/requirelogin.inc.php'); require_once('includes/message.inc.php'); require_once('includes/reservation.inc.php'); require_once('includes/options.inc.php'); require_once('includes/question.inc.php'); $cs_id=TGET('cs_id'); $mb_id_staff=TGET('mb_id_staff'); $mb_id=current_mb_id(); $time=TGET('time'); $minutes=TGET('minutes'); $clsr_id=TGET('clsr_id'); $plc_id=TGET('plc_id'); $optc=TGET('optc'); $message=$_SESSION['reserv.inputcache.domain']=='reserve.addlecture'?$_SESSION['reserv.inputcache.data']['message']:NULL; $_SESSION['reserv.inputcache.data']['message']=NULL; $timezone_bias_seconds=get_user_time_zone()*60; $lctr_since=seconds_to_datetime($time); $lctr_expire=seconds_to_datetime($time+$minutes*60); $DBConn->connect(); $DBConn->begin(true); $course=db_load_course_by_id($DBConn,$cs_id); $circlepart=db_load_course_circle($DBConn,$cs_id,current_mb_id()); if (!db_is_compere_qualified($DBConn,$course['mb_id_owner']) || $course['cs_visibleto']=='CIRCLE' && !$circlepart) { $DBConn->rollback(); redirect("./"); return; } $questionnaire_ok=questionnaire_reserve_guide($DBConn,$cs_id); $deadline=datetime_to_seconds(db_query_deadline($DBConn,$cs_id,$lctr_since)); $IDR_fields=db_get_course_info_requests($DBConn,$cs_id); $mb_id_staffs=db_filter_for_available_compere($DBConn,$mb_id_staff,$cs_id,$lctr_since,$lctr_expire); $clsr_ids=db_filter_for_available_classroom($DBConn,$clsr_id,$lctr_since,$lctr_expire); $cs_minutes_limit=db_load_course_minutes_limit($DBConn,$cs_id,$lctr_since); $lecture_count=db_count_lectures_of_compere($DBConn,$course['mb_id_owner']); $options_ok=compute_reservation_options($DBConn,$course,$optc,$optrec,$minutes); $errorareas=iif_array4(array( array($mb_id==$course['mb_id_owner'],'ERROR-OWNER-RESERVE',array(0)), array(!$course || $course['cs_status']!='VALID','ERROR-COURSE-NA',array(0)), array(!$mb_id_staffs,'ERROR-STAFF-NA',array(0)), array(!$clsr_ids,'ERROR-CLASSROOM-NA',array(0)), array($minutes>$cs_minutes_limit,'ERROR-MINUTES-LIMIT',array(0)), array($lecture_count>=get_compere_limit($DBConn,$course['mb_id_owner'],'lecture.count'),'ERROR-COUNT-LIMIT',array(0)), array(!$options_ok,'ERROR-OPTION-SOMEERROR',array(0)), array($deadline<uniwits_time(),'ERROR-DEADLINE-OVER',array(0)), array(!$questionnaire_ok,'ERROR-QUESTIONNAIRE-FIRST',array(0)) )); if (count_true_entries($errorareas)>0) { $_SESSION['reserv.inputcache.domain']='reserve.addlecture'; $_SESSION['reserv.inputcache.errorareas']=$errorareas; $_SESSION['reserv.inputcache.data']=array( 'cs_id'=>$cs_id, 'lctr_since'=>$lctr_since, 'lctr_expire'=>$lctr_expire ); redirect("qx-cmd-reserve.addlecture-op-revise-cs_id-".$cs_id.".html"); $DBConn->rollback(); return; } $lecture=array( 'cs_id'=>$cs_id, 'clsr_id'=>$clsr_id, 'lctr_since'=>$lctr_since, 'lctr_expire'=>$lctr_expire, 'lctr_status'=>'OPEN' ); $lctr_id=db_insert_lecture($DBConn,$lecture); set_lecture_unit_income($DBConn,$lctr_id,$minutes,$course); $st_ids=db_pick_seat_available_for_lecture($DBConn,$lctr_id,$plc_id,$clsr_id); $rsv_id=db_insert_reservation($DBConn,$lctr_id,$st_ids[0],$mb_id,$mb_id); db_save_lecture_staff($DBConn,$lctr_id,$mb_id_staffs); if ($course['cs_autoconfirm']=='YES') { db_confirm_reservation($DBConn,$lctr_id,$st_ids[0],$mb_id); $is_rservation_completed=true; } else $is_rservation_completed=false; db_set_reservation_option($DBConn,$rsv_id,$optrec); db_add_info_disclose($DBConn,$mb_id,$course['mb_id_owner'],array_projection($IDR_fields,'id_field')); db_join_coursecircle($DBConn,$cs_id,$mb_id); save_transfered_questionnaire_answer_set_for_reservation($DBConn,$cs_id,$mb_id,$rsv_id); $DBConn->commit(); $DBConn->begin(); send_message( $DBConn, 'RESERVE', $mb_id, 'MEMBER', $course['mb_id_owner'], 'COMPERE', $message?$message:'', false, array( 'msg_lctr_id'=>$lctr_id, 'msg_cs_id'=>$cs_id, 'msg_st_id'=>$st_ids[0] ) ); $email=db_load_member_notifiable_email($DBConn,$mb_id); if ($email) { $compere=db_load_compere($DBConn,$course['mb_id_owner']); $maildata=array( 'recipient.nickname'=>current_mb_nickname(), 'ROOT-URL'=>$dataset['ROOT-URL'], 'cs_name'=>$course['cs_name'], 'cp_name'=>$compere['cp_name'], 'ST-PROVISIONAL'=>$is_rservation_completed?array():array(0), 'ST-COMPLETE'=>$is_rservation_completed?array(0):array() ); $maildata+=array_key_prepend(split_datetime($lecture['lctr_since'],$timezone_bias_seconds),'since_'); $maildata+=array_key_prepend(split_datetime($lecture['lctr_expire'],$timezone_bias_seconds),'expire_'); $mail=prepare_email_from_templates('reservedconfirm.email.subject','reservedconfirm.email.content',$maildata); @sendmail($Config->MailerAddress,$email,$mail['subject'],$mail['body']); } purge_array_by_key_prefix($_SESSION,'reserv.inputcache.'); redirect("qx-cmd-reservation.list-op-new.ok-lctr_ids-".$lctr_id.".html"); $DBConn->commit(); ?>