<?php require_once('includes/requirelogin.inc.php'); require_once('includes/message.inc.php'); require_once('includes/options.inc.php'); require_once('includes/question.inc.php'); $mb_id=current_mb_id(); $timezone_bias_seconds=get_user_time_zone()*60; if ($_SESSION['reserv.inputcache.domain']!='reserve.lecture') { header('Location ./'); return; } $lctr_id=$_SESSION['reserv.inputcache.data']['lctr_id']; $plc_id=$_SESSION['reserv.inputcache.data']['plc_id']; $clsr_id=$_SESSION['reserv.inputcache.data']['clsr_id']; $optc=$_SESSION['reserv.inputcache.data']['optc']; $message=$_SESSION['reserv.inputcache.data']['message']; $errorareas=array(); $DBConn->connect(); $DBConn->begin(true); $reserve_count=db_count_reservations_of_lecture($DBConn,$lctr_id,$mb_id); if ($reserve_count) $errorareas['ERROR-ALREADY-RESERVED']=array(0); $lecture=db_load_lecture_by_id($DBConn,$lctr_id); $place=db_load_place($DBConn,$plc_id); $course=db_load_course_by_id($DBConn,$lecture['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,$lecture['cs_id']); if (!$questionnaire_ok) $errorareas['ERROR-QUESTIONNAIRE-FIRST']=array(0); $options_ok=compute_reservation_options($DBConn,$course,$optc,$optrec,false,$lecture); if (!$options_ok) $errorareas['ERROR-OPTION-SOMEERROR']=array(0); $reservation_count=db_count_reservations_of_compere($DBConn,$course['mb_id_owner']); if ($reservation_count>=get_compere_limit($DBConn,$course['mb_id_owner'],'reservation.count')) $errorareas['ERROR-COUNT-LIMIT']=array(0); if ($mb_id==$course['mb_id_owner']) $errorareas['ERROR-OWNER-RESERVE']=array(0); $size=db_load_lecture_size_by_place_classroom($DBConn,$lctr_id,$plc_id,$clsr_id); $size=$size[0]; $st_id=null; if ($errorareas); else if (!$lecture) $errorareas['ERROR-NO-LECTURE']=array(0); else if (datetime_to_seconds($lecture['lctr_deadline'])<uniwits_time()) $errorareas['ERROR-DEADLINE-OVER']=array(0); else if ($size['lctr_size']<$size['clsr_size']) { $st_ids=db_pick_seat_available_for_lecture($DBConn,$lctr_id,$plc_id,$clsr_id); if ($st_ids) { $st_id=$st_ids[0]; $rsv_id=db_insert_reservation($DBConn,$lctr_id,$st_id,$mb_id,$mb_id); $is_rservation_completed=false; if ($course['cs_autoconfirm']=='YES' || $course['cs_autoconfirm']=='ALLBUTONE' && db_count_reservations_of_lecture($DBConn,$lctr_id,false,true)>0) { db_confirm_reservation($DBConn,$lctr_id,$st_id,$mb_id); $is_rservation_completed=true; } db_set_reservation_option($DBConn,$rsv_id,$optrec); $IDR_fields=db_get_course_info_requests($DBConn,$lecture['cs_id']); db_add_info_disclose($DBConn,$mb_id,$course['mb_id_owner'],array_projection($IDR_fields,'id_field')); db_join_coursecircle($DBConn,$lecture['cs_id'],$mb_id); save_transfered_questionnaire_answer_set_for_reservation($DBConn,$lecture['cs_id'],$mb_id,$rsv_id); $DBConn->commit(); $DBConn->begin(); send_message( $DBConn, 'RESERVE', $mb_id, 'MEMBER', $course['mb_id_owner'], 'COMPERE', $message, false, array( 'msg_lctr_id'=>$lctr_id, 'msg_cs_id'=>$lecture['cs_id'], 'msg_st_id'=>$st_id ) ); $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']); } $DBConn->commit(); purge_array_by_key_prefix($_SESSION,'reserv.inputcache.'); } else $errorareas['ERROR-LECTURE-FULL']=array(0); } else $errorareas['ERROR-LECTURE-FULL']=array(0); if ($errorareas) { $_SESSION['reserv.inputcache.errorareas']=$errorareas; $DBConn->rollback(); if ($errorareas['ERROR-NO-LECTURE']) redirect("./"); else redirect("qx-cmd-reserve.lecture-op-revise-lctr_id-".$lctr_id.".html"); } else { redirect("qx-cmd-reservation.list-op-new.ok-lctr_ids-".$lctr_id.".html"); } ?>