Beispiel #1
0
/**
 * For a UTC timestamp, find the equivalent virtualised local timestamp.
 *
 * @param  TIME				UTC time
 * @param  string				Timezone (boring style)
 * @return TIME				Virtualised local time
 */
function tz_time($time, $zone)
{
    if ($zone == '') {
        $zone = get_server_timezone();
    }
    if (function_exists('date_default_timezone_set')) {
        date_default_timezone_set($zone);
    } else {
        @ini_set('date.timezone', $zone);
    }
    $ret = $time + intval(60.0 * 60.0 * floatval(date('O', $time)) / 100.0);
    if (function_exists('date_default_timezone_set')) {
        date_default_timezone_set('UTC');
    } else {
        @ini_set('date.timezone', 'UTC');
    }
    return $ret;
}
Beispiel #2
0
 /**
  * Get a form for entering a booking.
  *
  * @param  ?array		Details of the booking (NULL: new).
  * @param  ?MEMBER	Who the booking is for (NULL: current member).
  * @return array		Tuple: form fields, hidden fields.
  */
 function get_form_fields($details = NULL, $member_id = NULL)
 {
     $hidden = new ocp_tempcode();
     $fields = new ocp_tempcode();
     if (is_null($details)) {
         $bookable_id = get_param_integer('bookable_id', NULL);
         if (is_null($bookable_id)) {
             // Form to choose bookable
             @ob_end_clean();
             $bookables = $GLOBALS['SITE_DB']->query_select('bookable', array('*'), NULL, 'ORDER BY sort_order');
             if (count($bookables) == 0) {
                 inform_exit(do_lang_tempcode('NO_CATEGORIES'));
             }
             $bookables_list = new ocp_tempcode();
             foreach ($bookables as $bookable) {
                 $bookables_list->attach(form_input_list_entry(strval($bookable['id']), false, get_translated_text($bookable['title'])));
             }
             $fields = form_input_list(do_lang_tempcode('BOOKABLE'), '', 'bookable_id', $bookables_list, NULL, true);
             $post_url = get_self_url(false, false, NULL, false, true);
             $submit_name = do_lang_tempcode('PROCEED');
             $hidden = build_keep_post_fields();
             $title = get_page_title('ADD_BOOKING');
             $tpl = do_template('FORM_SCREEN', array('TARGET' => '_self', 'GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => '', 'URL' => $post_url, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name));
             $echo = globalise($tpl, NULL, '', true);
             $echo->evaluate_echo();
             exit;
         }
         $details = array('bookable_id' => $bookable_id, 'start_day' => get_param_integer('day', intval(date('d'))), 'start_month' => get_param_integer('month', intval(date('m'))), 'start_year' => get_param_integer('year', intval(date('Y'))), 'end_day' => get_param_integer('day', intval(date('d'))), 'end_month' => get_param_integer('month', intval(date('m'))), 'end_year' => get_param_integer('year', intval(date('Y'))), 'quantity' => 1, 'notes' => '', 'supplements' => array());
     }
     if (is_null($member_id)) {
         $member_id = get_member();
     }
     $_bookable = $GLOBALS['SITE_DB']->query_select('bookable', array('*'), array('id' => $details['bookable_id']), '', 1);
     if (!array_key_exists(0, $_bookable)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $bookable = $_bookable[0];
     $fields->attach(form_input_date(do_lang_tempcode('FROM'), '', 'bookable_' . strval($details['bookable_id']) . '_date_from', false, false, false, array(0, 0, $details['start_month'], $details['start_day'], $details['start_year']), 10, NULL, NULL, NULL, true, get_server_timezone()));
     if ($bookable['dates_are_ranges'] == 1) {
         $fields->attach(form_input_date(do_lang_tempcode('TO'), '', 'bookable_' . strval($details['bookable_id']) . '_date_to', false, false, false, array(0, 0, $details['end_month'], $details['end_day'], $details['end_year']), 10, NULL, NULL, NULL, true, get_server_timezone()));
     }
     $fields->attach(form_input_integer(do_lang_tempcode('QUANTITY'), '', 'bookable_' . strval($details['bookable_id']) . '_quantity', $details['quantity'], true));
     $fields->attach(form_input_text(do_lang_tempcode('NOTES'), '', 'bookable_' . strval($details['bookable_id']) . '_notes', $details['notes'], false));
     $member_directory_url = build_url(array('page' => 'members'), get_module_zone('members'));
     $fields->attach(form_input_username(do_lang_tempcode('BOOKING_FOR'), do_lang_tempcode('DESCRIPTION_BOOKING_FOR', escape_html($member_directory_url->evaluate())), 'username', $GLOBALS['FORUM_DRIVER']->get_username($member_id), true, false));
     $supplement_rows = $GLOBALS['SITE_DB']->query_select('bookable_supplement a JOIN ' . get_table_prefix() . 'bookable_supplement_for b ON a.id=b.supplement_id', array('a.*'), array('bookable_id' => $details['bookable_id']), 'ORDER BY sort_order');
     foreach ($supplement_rows as $supplement_row) {
         $quantity = 0;
         $notes = '';
         if (array_key_exists($supplement_row['id'], $details['supplements'])) {
             $quantity = $details['supplements'][$supplement_row['id']]['quantity'];
             $notes = $details['supplements'][$supplement_row['id']]['notes'];
         }
         $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('SUPPLEMENT', escape_html(get_translated_text($supplement_row['title']))))));
         if ($supplement_row['supports_quantities'] == 1) {
             $fields->attach(form_input_integer(do_lang_tempcode('QUANTITY'), '', 'bookable_' . strval($details['bookable_id']) . '_supplement_' . strval($supplement_row['id']) . '_quantity', $quantity, true));
         } else {
             $fields->attach(form_input_tick(get_translated_text($supplement_row['title']), '', 'bookable_' . strval($details['bookable_id']) . '_supplement_' . strval($supplement_row['id']) . '_quantity', $quantity == 1));
         }
         $fields->attach(form_input_text(do_lang_tempcode('NOTES'), '', 'bookable_' . strval($details['bookable_id']) . '_supplement_' . strval($supplement_row['id']) . '_notes', $notes, false));
     }
     return array($fields, $hidden);
 }