assign( 'section_title', "My Status" ); $serve->assign('headerdiv', "topHeaderBookings" ); // if no type is selected just return to the main screen $sch =& Serve::factory('Scheduler'); $notify =& Serve::factory('Notification'); $adm =& Serve::factory('Admin'); $admins = $adm->get_global_admins(); $car = Serve::factory('Item'); $car->set_table('user_car'); $admin_addr = array(); foreach( $admins as $a ) { $admin_addr[] = $a['email']; } $admin_email_str = implode( ',',$admin_addr ); $my_email_str="jon.burgess@outlook.com"; $my_admin_email_str="info@colesandblackwell.co.uk"; $user = Serve::factory('User'); $username = $user->get_user_info( $_SESSION['_serve_user']['user_id'] ); $serve->assign('username', $username['user'] ); $serve->assign('mypage', "status" ); if( $_REQUEST['request'] == 'cancel' ) { $schedule_info = $sch->get_joined_appointment_by_id( $_REQUEST['scheduled_id'] ); if( $schedule_info['user_id'] != $_SESSION['_serve_user']['user_id'] ) { $serve->safe_redirect(array('url'=>'/colesandblackwell/profile.php' ) ); } if( $sch->delete_appointment( $_REQUEST['scheduled_id'] ) ) { // send cancelled notification $email = $notify->get_notification_by_name('appointment_cancelled_confirmation' ); $schedule_info['service_type'] = $schedule_info['schedule_type_name']; $schedule_info['user_vehicle'] = "{$schedule_info['year']} {$schedule_info['car_make']} {$schedule_info['car_model']}"; $email['email_text'] = $notify->replace_values( $email['email_text'], $schedule_info ); $notify->send( $schedule_info['email'], $email['email_subject'], $email['email_text'] ); //$notify->send( $my_email_str, $email['email_subject'], $email['email_text'] ); $admin_email = $notify->get_notification_by_name('admin_appointment_cancelled_notification' ); $admin_email['email_text'] = $notify->replace_values( $admin_email['email_text'], $schedule_info ); $notify->send( $admin_email_str, $admin_email['email_subject'], $admin_email['email_text'] ); //$notify->send( $my_admin_email_str, $admin_email['email_subject'], $admin_email['email_text'] ); //$serve->safe_redirect( array('url'=>'/bookings/profile.php','success'=>'LANG_APPOINTMENT_cancelled' ) ); $serve->safe_redirect( array('url'=>'/colesandblackwell/schedule.php?request=show_calendar' ) ); } else { $serve->safe_redirect( array('url'=>'/colesandblackwell/profile.php','error'=>'LANG_APPOINTMENT_NOT_cancelled' ) ); } } if( $_REQUEST['request'] == 'select_car' ) { /*if( $scheduled_id = $sch->save_appointment( array( 'scheduled_id' =>$_POST['scheduled_id'], 'user_id' =>$_SESSION['_serve_user']['user_id'], 'user_car_id' =>$_POST['user_car_id'] )) ) { $app_info = $sch->get_joined_appointment_by_id( $scheduled_id ); $serve->assign( 'appointment', $app_info ); } else { $_REQUEST['request'] = 'get_car_list'; }*/ $serve->assign('scheduled', $sch->get_user_appointments( $_SESSION['_serve_user']['user_id'] ) ); } if( $_REQUEST['request'] == 'get_car_list' ) { $car = Serve::factory('Item'); $car->set_table('user_car'); $cars = $car->get_all( 'car_make', false, array('where'=>'user_id=' . $car->dbh->quotesmart($_SESSION['_serve_user']['user_id'] ) ) ); $serve->assign('cars', $cars ); //populate the combo box---written on 24-07-07 $combotype = Serve::factory('Item'); $combotype->set_table('schedule_type'); $combotype = $combotype->get_all( 'schedule_type_name', false, array('where'=>'schedule_booking=1' ) ); $serve->assign('combotype', $combotype ); //end of this /* // a bit of a hack: $app_info = $sch->get_appointment_by_id( $_REQUEST['scheduled_id'] ); $type = Serve::factory('Item'); $type->set_table('schedule_type'); $type_info = $type->get_by_id( $app_info['schedule_type_id'] ); // strtotime never seems to parse for me but this should work list($year,$month,$day) = $sch->cal->parse_mysql_ts( $app_info['scheduled_date'] ); $ts = mktime(0,0,0,$month,$day,$year); $formatted_date = strftime( _DATE_FORMAT, $ts ); $msg = sprintf(LANG_DATE_SELECTED,$type_info['schedule_type_name'], $formatted_date ); $serve->assign('success',$msg);*/ } if( $_REQUEST['request'] == 'confirm_reservation' ) { if( $sch->save_appointment( array( 'scheduled_id'=>$_POST['scheduled_id'], 'confirmed'=>1 ) ) ) { $schedule_info = $sch->get_joined_appointment_by_id( $_POST['scheduled_id'] ); $email = $notify->get_notification_by_name('appointment_confirmation' ); $schedule_info['service_type'] = $schedule_info['schedule_type_name']; $schedule_info['user_vehicle'] = "{$schedule_info['year']} {$schedule_info['car_make']} {$schedule_info['car_model']}"; $split_date=explode("-",$schedule_info['scheduled_date']); $schedule_info['scheduled_date']="{$split_date[2]} {$split_date[1]} {$split_date[0]}"; $email['email_text'] = $notify->replace_values( $email['email_text'], $schedule_info ); $notify->send( $schedule_info['email'], $email['email_subject'], $email['email_text'] ); //$notify->send( $my_email_str, $email['email_subject'], $email['email_text'] ); $admin_email = $notify->get_notification_by_name('admin_appointment_notification' ); $admin_email['email_text'] = $notify->replace_values( $admin_email['email_text'], $schedule_info ); $notify->send( $admin_email_str, $admin_email['email_subject'], $admin_email['email_text'] ); //$notify->send( $my_admin_email_str, $admin_email['email_subject'], $admin_email['email_text'] ); $serve->safe_redirect( array('success'=>'LANG_APPOINTMENT_SCHEDULED','schedule_type_id'=>$_POST['schedule_type_id'] ) ); } else { $_REQUEST['request'] = 'show_calendar'; } } if( $_REQUEST['request'] == 'show_calendar' ) { $_REQUEST['schedule_type_id'] = 0; header( 'Cache-Control: private, max-age=10800, pre-check=10800' ); //if( !isset( $_REQUEST['schedule_type_id'] ) ) //{ //$serve->safe_redirect( array('url'=>'/') ); //} if( !isset( $_REQUEST['month'] ) ) { $_REQUEST['month'] = date('m'); } if( !isset( $_REQUEST['year'] ) ) { $_REQUEST['year'] = date('Y'); } // normalize list( $_REQUEST['year'], $_REQUEST['month'] ) = $sch->cal->Normalize_YM( $_REQUEST['year'], $_REQUEST['month'] ); $prev_month = $_REQUEST['month'] - 1; $next_month = $_REQUEST['month'] + 1; // display the next 3 months $days = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $_REQUEST['month'], $_REQUEST['year'] ,$_REQUEST['user_car_id']); $calendar_html = $sch->cal->generate_calendar( $_REQUEST['year'], $_REQUEST['month'], $days ); $serve->assign( 'month1', $calendar_html ); $month2 = $_REQUEST['month'] + 1; list( $year2, $month2 ) = $sch->cal->Normalize_YM( $_REQUEST['year'], $month2 ); $days2 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month2, $year2,$_REQUEST['user_car_id'] ); $month2_html = $sch->cal->generate_calendar( $year2, $month2, $days2 ); $serve->assign('month2', $month2_html ); $month3 = $month2 + 1; list( $year3, $month3 ) = $sch->cal->Normalize_YM( $year2, $month3 ); $days3 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month3, $year3,$_REQUEST['user_car_id'] ); $month3_html = $sch->cal->generate_calendar( $year3, $month3, $days3 ); $serve->assign( 'month3', $month3_html ); //===========================get booking details $serve->assign('scheduled', $sch->get_user_appointments( $_SESSION['_serve_user']['user_id'] ) ); //================================== //========================get vehicles details====== $serve->assign('cars', $car->get_paginate( 'car_make', array('where'=>'user_id=' . $car->dbh->quotesmart($_SESSION['_serve_user']['user_id']) ) )); //===========end=================== //=========get reminder details================= $remind = Serve::factory('Reminder'); $serve->assign('reminders', $remind->get_user_reminders( $_SESSION['_serve_user']['user_id'] ) ); //============================================== } //===========================my booking==============01-08-007======== if( $_REQUEST['request'] == 'my_booking' ) { if( !isset( $_REQUEST['month'] ) ) { $_REQUEST['month'] = date('m'); } if( !isset( $_REQUEST['year'] ) ) { $_REQUEST['year'] = date('Y'); } // normalize list( $_REQUEST['year'], $_REQUEST['month'] ) = $sch->cal->Normalize_YM( $_REQUEST['year'], $_REQUEST['month'] ); $prev_month = $_REQUEST['month'] - 1; $next_month = $_REQUEST['month'] + 1; //display schedule type if ($_REQUEST['schedule_type_id']==1){$serve->assign('schedule_type_name', "MOT" );} if ($_REQUEST['schedule_type_id']==2){$serve->assign('schedule_type_name', "Service" );} //end of schedule type // display all the 12 months $days = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $_REQUEST['month'], $_REQUEST['year'] ,$_REQUEST['user_car_id']); $calendar_html = $sch->cal->generate_calendar( $_REQUEST['year'], $_REQUEST['month'], $days ); $serve->assign( 'month1', $calendar_html ); $month2 = $_REQUEST['month'] + 1; list( $year2, $month2 ) = $sch->cal->Normalize_YM( $_REQUEST['year'], $month2 ); $days2 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month2, $year2,$_REQUEST['user_car_id'] ); $month2_html = $sch->cal->generate_calendar( $year2, $month2, $days2 ); $serve->assign('month2', $month2_html ); $month3 = $month2 + 1; list( $year3, $month3 ) = $sch->cal->Normalize_YM( $year2, $month3 ); $days3 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month3, $year3,$_REQUEST['user_car_id'] ); $month3_html = $sch->cal->generate_calendar( $year3, $month3, $days3 ); $serve->assign( 'month3', $month3_html ); /* $month4 = $month3 + 1; list( $year4, $month4 ) = $sch->cal->Normalize_YM( $year3, $month4 ); $days4 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month4, $year4,$_REQUEST['user_car_id'] ); $month4_html = $sch->cal->generate_calendar( $year4, $month4, $days4 ); $serve->assign( 'month4', $month4_html ); $month5 = $month4 + 1; list( $year5, $month5 ) = $sch->cal->Normalize_YM( $year4, $month5 ); $days5 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month5, $year5,$_REQUEST['user_car_id'] ); $month5_html = $sch->cal->generate_calendar( $year5, $month5, $days5 ); $serve->assign( 'month5', $month5_html ); $month6 = $month5 + 1; list( $year6, $month6 ) = $sch->cal->Normalize_YM( $year5, $month6 ); $days6 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month6, $year6,$_REQUEST['user_car_id'] ); $month6_html = $sch->cal->generate_calendar( $year6, $month6, $days6 ); $serve->assign( 'month6', $month6_html ); $month7 = $month6 + 1; list( $year7, $month7 ) = $sch->cal->Normalize_YM( $year6, $month7 ); $days7 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month7, $year7,$_REQUEST['user_car_id'] ); $month7_html = $sch->cal->generate_calendar( $year7, $month7, $days7 ); $serve->assign( 'month7', $month7_html ); $month8 = $month7 + 1; list( $year8, $month8 ) = $sch->cal->Normalize_YM( $year7, $month8 ); $days8 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month8, $year8,$_REQUEST['user_car_id'] ); $month8_html = $sch->cal->generate_calendar( $year8, $month8, $days8 ); $serve->assign( 'month8', $month8_html ); $month9 = $month8 + 1; list( $year9, $month9 ) = $sch->cal->Normalize_YM( $year8, $month9 ); $days9 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month9, $year9,$_REQUEST['user_car_id'] ); $month9_html = $sch->cal->generate_calendar( $year9, $month9, $days9 ); $serve->assign( 'month9', $month9_html ); $month10 = $month9 + 1; list( $year10, $month10 ) = $sch->cal->Normalize_YM( $year9, $month10 ); $days10 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month10, $year10,$_REQUEST['user_car_id'] ); $month10_html = $sch->cal->generate_calendar( $year10, $month10, $days10 ); $serve->assign( 'month10', $month10_html ); $month11 = $month10 + 1; list( $year11, $month11 ) = $sch->cal->Normalize_YM( $year10, $month11 ); $days11 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month11, $year11,$_REQUEST['user_car_id'] ); $month11_html = $sch->cal->generate_calendar( $year11, $month11, $days11 ); $serve->assign( 'month11', $month11_html ); $month12 = $month11 + 1; list( $year12, $month12 ) = $sch->cal->Normalize_YM( $year11, $month12 ); $days12 = $sch->get_days_for_calendar( $_REQUEST['schedule_type_id'], $month12, $year12,$_REQUEST['user_car_id'] ); $month12_html = $sch->cal->generate_calendar( $year12, $month12, $days12 ); $serve->assign( 'month12', $month12_html );*/ } //==============================end my booking============================ if( $_REQUEST['request'] == 'select_date' ) { if( !isset( $_REQUEST['schedule_type_id'] ) ) { $serve->safe_redirect( array('url'=>'/colesandblackwell/') ); } //if($_POST['cancel'] || $_POST['cancel_x']) //{ //$serve->safe_redirect( array('url'=>'/bookings/profile.php') ); //$serve->safe_redirect( array('url'=>'/bookings/') ); //} // set the date as schedule (even if there isn't a user_id yet) // the cron script will clean up appointments that aren't completed. $scheduled_id = $sch->save_appointment( array( 'scheduled_date' =>$_REQUEST['date'], 'user_id' =>$_SESSION['_serve_user']['user_id'], 'schedule_type_id' =>$_REQUEST['schedule_type_id'], 'user_car_id' =>$_REQUEST['user_car_id']) ); // confirm email send........ //$schedule_info = $sch->get_joined_appointment_by_id( $_POST['scheduled_id'] ); if ($scheduled_id){ $schedule_info = $sch->get_joined_appointment_by_id( $scheduled_id ); $email = $notify->get_notification_by_name('appointment_confirmation' ); $schedule_info['service_type'] = $schedule_info['schedule_type_name']; $schedule_info['user_vehicle'] = "{$schedule_info['year']} {$schedule_info['car_make']} {$schedule_info['car_model']}"; $split_date=explode("-",$schedule_info['scheduled_date']); $schedule_info['scheduled_date']="{$split_date[2]} /{$split_date[1]}/ {$split_date[0]}"; $email['email_text'] = $notify->replace_values( $email['email_text'], $schedule_info ); $notify->send( $schedule_info['email'], $email['email_subject'], $email['email_text'] ); //$notify->send( $my_email_str, $email['email_subject'], $email['email_text'] ); $admin_email = $notify->get_notification_by_name('admin_appointment_notification' ); $admin_email['email_text'] = $notify->replace_values( $admin_email['email_text'], $schedule_info ); $notify->send( $admin_email_str, $admin_email['email_subject'], $admin_email['email_text'] ); //$notify->send( $my_admin_email_str, $admin_email['email_subject'], $admin_email['email_text'] ); //end of email // a bit of a hack: $app_info = $sch->get_appointment_by_id( $scheduled_id); $type = Serve::factory('Item'); $type->set_table('schedule_type'); $type_info = $type->get_by_id( $app_info['schedule_type_id'] ); // strtotime never seems to parse for me but this should work list($year,$month,$day) = $sch->cal->parse_mysql_ts( $app_info['scheduled_date'] ); $ts = mktime(0,0,0,$month,$day,$year); $formatted_date = strftime( _DATE_FORMAT, $ts ); $msg = sprintf(LANG_DATE_SELECTED,$type_info['schedule_type_name'], $formatted_date ); $serve->assign('success',$msg); $serve->safe_redirect( array('request'=>'show_calendar','schedule_type_id'=>$_REQUEST['schedule_type_id'],'user_car_id'=>$_REQUEST['user_car_id'],'success'=>'LANG_APPOINTMENT_SCHEDULED' ) ); }else{ $serve->safe_redirect( array('request'=>'show_calendar','schedule_type_id'=>$_REQUEST['schedule_type_id'],'user_car_id'=>$_REQUEST['user_car_id'],'success'=>'LANG_ALREADY_SCHEDULED' ) ); } } if( $_REQUEST['request'] == 'select_booking' ) { if( !isset( $_REQUEST['schedule_type_id'] ) ) { $serve->safe_redirect( array('url'=>'/colesandblackwell/') ); } // set the date as schedule (even if there isn't a user_id yet) // the cron script will clean up appointments that aren't completed. /*$scheduled_id = $sch->save_appointment( array( 'scheduled_date' =>$_REQUEST['date'], 'user_id' =>$_SESSION['_serve_user']['user_id'], 'schedule_type_id' =>$_REQUEST['schedule_type_id'],) );*/ $serve->assign('date', $_REQUEST['date'] ); $due_date=$_REQUEST['date']; $datecontents=explode("-",$due_date); $due_date=$datecontents[2]."-".$datecontents[1]."-".$datecontents[0]; $serve->assign('displaydate', $due_date ); $serve->assign('scheduled', $_REQUEST['schedule_type_id'] ); if ($_REQUEST['schedule_type_id']==1){$serve->assign('schedule_type_name', "MOT" );} if ($_REQUEST['schedule_type_id']==2){$serve->assign('schedule_type_name', "Service" );} $serve->assign('user_car_id', $_REQUEST['user_car_id'] ); $car = Serve::factory('Item'); $car->set_table('user_car'); $car_info = $car->get_by_id( $_REQUEST['user_car_id'] ); $serve->assign('cars', $car_info ); //$serve->safe_redirect( array('request'=>'select_booking') ); } $serve->display(); ?>