' . 'You need to be registered for reservations.' . '
';
}
}
break;
case "1":
// User data & confirmation
$user_id = get_current_user_id();
$output .= self::display_calendar_confirmation( $user_id );
break;
}
return $output;
}
/**
* Display the reservation calendar.
*
* @param int $user_id If user_id is null, then an extra form is displayed.
*
* @return string
*/
public static function display_calendar ( $user_id = null ) {
global $wp;
$output = "";
$current_url = home_url(add_query_arg(array(),$wp->request));
$day = 0;
if ( isset( $_REQUEST ['offset'] ) ) {
$day = intval( trim( $_REQUEST ['offset'] ) );
}
if ( $day > get_option ( "asw-maxoffset", APPOINTMENTSW_MAX_DAYS_OFFSET_DEFAULT ) ) {
$day = get_option ( "asw-maxoffset", APPOINTMENTSW_MAX_DAYS_OFFSET_DEFAULT );
}
$num_days = get_option ( "asw-numdays", APPOINTMENTSW_NUM_DAYS_DEFAULT );
// Pagination
$output .= '';
$output .= '';
for ( $cnt=0; $cnt < $num_days; $cnt++ ) {
$date = strtotime("+" . intval($day+$cnt) . " day", current_time( 'timestamp' ));
$today = date('Y-m-d', $date);
$today_txt = __( date( 'l', $date ) ) . " " . date('d', $date);
$books = AppointmentSw::get_books_by_day ( $today );
$output .= '
';
$output .= '
| ' . $today_txt . ' |
';
$week_day = date( 'N', $date );
/*
switch ( $week_day ) {
case 1:
$start_time_1 = $today . "10:00";
$end_time_1 = $today . "10:00";
$start_time_2 = $today . "16:05";
$end_time_2 = $today . "21:30";
break;
case 2:
case 3:
case 4:
case 5:
$start_time_1 = $today . "09:35";
$end_time_1 = $today . "13:45";
$start_time_2 = $today . "16:05";
$end_time_2 = $today . "21:30";
break;
case 6:
$start_time_1 = $today . "9:00";
$end_time_1 = $today . "14:00";
$start_time_2 = $today . "16:00";
$end_time_2 = $today . "16:00";
break;
default:
$start_time_1 = $today . "8:00";
$end_time_1 = $today . "8:00";
$start_time_2 = $today . "16:00";
$end_time_2 = $today . "16:00";
}
*/
$start_time_1 = $today . get_option ( "asw-start_time_0", "10:00" );
$end_time_1 = $today . get_option ( "asw-end_time_0", "14:00" );
$start_time_2 = $today . get_option ( "asw-start_time_1", "16:00" );
$end_time_2 = $today . get_option ( "asw-end_time_1", "20:00" );
if ( AppointmentSw::isSlotOnHoliday( $today . "_0" ) && AppointmentSw::isSlotOnHoliday( $today . "_1" ) ) {
$output .= '| ' . __( "Closed all day", 'appointmentsw' ) . ' |
';
} else {
// Primer tramo
if ( !AppointmentSw::isSlotOnHoliday( $today . "_0" ) ) {
$dteStart = new DateTime($start_time_1);
$dteEnd = new DateTime($end_time_1);
$dteDiff = $dteStart->diff($dteEnd);
$horas = $dteDiff->format('%H');
$minutos = $dteDiff->format('%I');
$num_slots = ( $horas * 60 ) + $minutos;
$num_slots = intval( $num_slots / get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) );
for ( $cnt2=0; $cnt2 < $num_slots; $cnt2++ ) {
if ( ( $cnt2 % 4 ) == 0 ) {
$output .= '';
}
$slot_time_ = strtotime( "+" . $cnt2 * get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) . " minute", mktime( $dteStart->format("H"), $dteStart->format("i"), 0, $dteStart->format("m"), $dteStart->format("d"), $dteStart->format("Y") ) );
$slot_time = date('Y-m-d H:i:s', $slot_time_);
$now = current_time( 'timestamp' );
$datetime = new DateTime( $slot_time );
if ( $slot_time_ < $now ) {
$output .= '| ' . $datetime->format("H:i") . ' | ';
} else {
if ( isset( $books[$slot_time] ) ) {
$output .= '' . $datetime->format("H:i") . ' | ';
} else {
$output .= '';
}
}
if ( ( ( $cnt2+1 ) % 4 ) == 0 ) {
$output .= '
';
}
}
} else {
$output .= '| ' . __( "Morning closed", 'appointmentsw' ) . ' |
';
}
// Almuerzo
$output .= '| ' . __( "Lunchtime", 'appointmentsw' ) . ' |
';
// Segundo tramo
if ( !AppointmentSw::isSlotOnHoliday( $today . "_1" ) ) {
$dteStart = new DateTime($start_time_2);
$dteEnd = new DateTime($end_time_2);
$dteDiff = $dteStart->diff($dteEnd);
$horas = $dteDiff->format("%H");
$horas = $dteDiff->format('%H');
$minutos = $dteDiff->format('%I');
$num_slots = ( $horas * 60 ) + $minutos;
$num_slots = intval( $num_slots / get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) );
for ( $cnt2=0; $cnt2 < $num_slots; $cnt2++ ) {
if ( ( $cnt2 % 4 ) == 0 ) {
$output .= '';
}
$slot_time_ = strtotime( "+" . $cnt2 * get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) . " minute", mktime( $dteStart->format("H"), $dteStart->format("i"), 0, $dteStart->format("m"), $dteStart->format("d"), $dteStart->format("Y") ) );
$slot_time = date('Y-m-d H:i:s', $slot_time_);
$now = current_time( 'timestamp' );
$datetime = new DateTime( $slot_time );
if ( $slot_time_ < $now ) {
$output .= '| ' . $datetime->format("H:i") . ' | ';
} else {
if ( isset( $books[$slot_time] ) ) {
$output .= '' . $datetime->format("H:i") . ' | ';
} else {
$output .= '';
}
}
if ( ( ( $cnt2+1 ) % 4 ) == 0 ) {
$output .= '
';
}
}
} else {
$output .= '| ' . __( "closed afternoon", 'appointmentsw' ) . ' |
';
}
}
$output .= '
';
}
$output .= '
';
return $output;
}
public static function display_calendar_confirmation ( $user_id = null ) {
$output = "";
$slot = isset ( $_REQUEST ['slot'] ) ? $_REQUEST ['slot'] : null;
$slot_time = date( 'Y-m-d H:i:s', $slot );
$datetime = new DateTime( $slot_time );
$slot_txt = $datetime->format( 'H:i d-m-Y' );
$user_id = null;
$name = "";
$email = "";
$phone = "";
$name_disabled = '';
$email_disabled = '';
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$user_id = $user->ID;
$name = $user->user_login;
$email = $user->user_email;
$name_disabled = ' disabled ';
$email_disabled = ' disabled ';
}
$output .= '' . sprintf( __( "You'll make an appointment on %s", 'appointmentsw' ), $slot_txt ) . '
';
$output .= '';
$output .= '
';
$output .= self::display_calendar_admin( $user_id );
$output .= '
';
$output .= '
';
$output .= self::display_add_form_admin();
$output .= '
';
$output .= '
';
$output .= self::display_new_user_form_admin( $user_id );
$output .= '
';
$output .= '
';
return $output;
}
}
public static function display_calendar_admin ( $user_id ) {
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
$output = "";
$day = 0;
if ( isset( $_REQUEST ['offset'] ) ) {
$day = intval( trim( $_REQUEST ['offset'] ) );
}
$num_days = get_option ( "asw-numdays", APPOINTMENTSW_NUM_DAYS_DEFAULT );
$output .= '';
$output .= '
';
$output .= __( 'User selected: ', 'appointmentsw' ) . '' . __( "Select a client", 'appointmentsw' ) . '';
$output .= '
';
// Pagination
$output .= '';
$output .= '
';
for ( $cnt=0; $cnt < $num_days; $cnt++ ) {
$date = strtotime("+" . intval($day+$cnt) . " day", current_time( 'timestamp' ));
$today = date('Y-m-d', $date);
$today_txt = __( date( 'l', $date ) ) . " " . date('d', $date);
$books = AppointmentSw::get_books_by_day ( $today );
$output .= '
';
$output .= '
| ' . $today_txt . ' |
';
$week_day = date( 'N', $date );
/*
switch ( $week_day ) {
case 1:
$start_time_1 = $today . "10:00";
$end_time_1 = $today . "10:00";
$start_time_2 = $today . "16:05";
$end_time_2 = $today . "21:30";
break;
case 2:
case 3:
case 4:
case 5:
$start_time_1 = $today . "09:35";
$end_time_1 = $today . "13:45";
$start_time_2 = $today . "16:05";
$end_time_2 = $today . "21:30";
break;
case 6:
$start_time_1 = $today . "9:00";
$end_time_1 = $today . "14:00";
$start_time_2 = $today . "16:00";
$end_time_2 = $today . "16:00";
break;
default:
$start_time_1 = $today . "8:00";
$end_time_1 = $today . "8:00";
$start_time_2 = $today . "16:00";
$end_time_2 = $today . "16:00";
}
*/
$start_time_1 = $today . get_option ( "asw-start_time_0", "10:00" );
$end_time_1 = $today . get_option ( "asw-end_time_0", "14:00" );
$start_time_2 = $today . get_option ( "asw-start_time_1", "16:00" );
$end_time_2 = $today . get_option ( "asw-end_time_1", "20:00" );
// Primer tramo
$dteStart = new DateTime($start_time_1);
$dteEnd = new DateTime($end_time_1);
$dteDiff = $dteStart->diff($dteEnd);
$horas = $dteDiff->format('%H');
$minutos = $dteDiff->format('%I');
$num_slots = ( $horas * 60 ) + $minutos;
$num_slots = intval( $num_slots / get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) );
for ( $cnt2=0; $cnt2 < $num_slots; $cnt2++ ) {
if ( ( $cnt2 % 4 ) == 0 ) {
$output .= '';
}
$slot_time_ = strtotime( "+" . $cnt2 * get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) . " minute", mktime( $dteStart->format("H"), $dteStart->format("i"), 0, $dteStart->format("m"), $dteStart->format("d"), $dteStart->format("Y") ) );
$slot_time = date('Y-m-d H:i:s', $slot_time_);
$now = current_time( 'timestamp' );
$datetime = new DateTime( $slot_time );
if ( $slot_time_ < $now ) {
$output .= '| ' . $datetime->format("H:i") . ' | ';
} else {
if ( isset( $books[$slot_time] ) ) {
$user = get_user_by ( 'id', $books[$slot_time]['user_id'] );
$output .= '';
} else {
$output .= '';
}
}
if ( ( ( $cnt2+1 ) % 4 ) == 0 ) {
$output .= '
';
}
}
// Almuerzo
$output .= '| ' . __( "Lunchtime", 'appointmentsw' ) . ' |
';
// Segundo tramo
$dteStart = new DateTime($start_time_2);
$dteEnd = new DateTime($end_time_2);
$dteDiff = $dteStart->diff($dteEnd);
$horas = $dteDiff->format('%H');
$minutos = $dteDiff->format('%I');
$num_slots = ( $horas * 60 ) + $minutos;
$num_slots = intval( $num_slots / get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) );
for ( $cnt2=0; $cnt2 < $num_slots; $cnt2++ ) {
if ( ( $cnt2 % 4 ) == 0 ) {
$output .= '';
}
$slot_time_ = strtotime( "+" . $cnt2 * get_option ( "asw-duration", APPOINTMENTSW_DURATION_DEFAULT ) . " minute", mktime( $dteStart->format("H"), $dteStart->format("i"), 0, $dteStart->format("m"), $dteStart->format("d"), $dteStart->format("Y") ) );
$slot_time = date('Y-m-d H:i:s', $slot_time_);
$now = current_time( 'timestamp' );
$datetime = new DateTime( $slot_time );
if ( $slot_time_ < $now ) {
$output .= '| ' . $datetime->format("H:i") . ' | ';
} else {
if ( isset( $books[$slot_time] ) && ( $books[$slot_time]['status'] == APPOINTMENTSW_STATUS_ACCEPTED ) ) {
$user = get_user_by ( 'id', $books[$slot_time]['user_id'] );
$output .= '';
} else {
$output .= '';
}
}
if ( ( ( $cnt2+1 ) % 4 ) == 0 ) {
$output .= '
';
}
}
$output .= '
';
}
$output .= '
';
$output .= '
';
return $output;
}
public static function display_add_form_admin () {
$output = "";
$all_users = get_users();
if ( sizeof( $all_users ) > 0 ) {
$output .= '