You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
872 lines
32 KiB
872 lines
32 KiB
<?php |
|
/** |
|
* @file |
|
* This module creates a room reservation application. |
|
* |
|
* @author Bob Humphrey, Web and Applications Developer, UNCW Randall Library |
|
*/ |
|
|
|
module_load_include('inc', 'room_reservations', 'room_reservations'); |
|
module_load_include('inc', 'room_reservations', 'room_reservations.node'); |
|
module_load_include('inc', 'room_reservations', 'room_reservations.views'); |
|
module_load_include('inc', 'room_reservations', 'room_reservations.series'); |
|
|
|
/** |
|
* Implements hook_views_api(). |
|
*/ |
|
function room_reservations_views_api($module, $api) { |
|
if ($module == 'views' && $api == 'views_default') { |
|
return array('version' => 2); |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_menu(). |
|
*/ |
|
function room_reservations_menu() { |
|
$app_title = variable_get('room_reservations_title', 'Room Reservations'); |
|
$items['admin/config/system/room_reservations'] = array( |
|
'title' => $app_title, |
|
'description' => 'Configure room reservation options', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_NORMAL_ITEM, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 0, |
|
); |
|
$items['admin/config/system/room_reservations/settings'] = array( |
|
'title' => 'Settings', |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'access arguments' => array('administer room reservations system'), |
|
'weight' => 10, |
|
); |
|
$items['admin/config/system/room_reservations/settings/general'] = array( |
|
'title' => 'General', |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'access arguments' => array('administer room reservations system'), |
|
'weight' => 10, |
|
); |
|
$items['admin/config/system/room_reservations/hours'] = array( |
|
'title' => 'Hours', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_default_hours'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 20, |
|
); |
|
$items['admin/config/system/room_reservations/hours/default_hours'] = array( |
|
'title' => 'Default Hours', |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'access arguments' => array('administer room reservations system'), |
|
'weight' => 10, |
|
); |
|
$items['admin/config/system/room_reservations/hours/daily_hours'] = array( |
|
'title' => 'Daily Hours', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_daily_hours'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 20, |
|
); |
|
$items['admin/config/system/room_reservations/page'] = array( |
|
'title' => 'Display Text', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_page'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 30, |
|
); |
|
/*$items['admin/config/system/room_reservations/sms'] = array( |
|
'title' => 'SMS', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_sms'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 40, |
|
); |
|
$items['admin/config/system/room_reservations/sms/networks'] = array( |
|
'title' => 'Wireless Carriers', |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'access arguments' => array('administer room reservations system'), |
|
'weight' => 10, |
|
); |
|
$items['admin/config/system/room_reservations/sms/add'] = array( |
|
'title' => 'Add Carrier', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_sms_add'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 20, |
|
); |
|
$items['admin/config/system/room_reservations/sms/delete'] = array( |
|
'title' => 'Delete Carrier', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_sms_delete'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 30, |
|
); |
|
$items['admin/config/system/room_reservations/messages'] = array( |
|
'title' => 'Messages', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_email'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 50, |
|
); |
|
$items['admin/config/system/room_reservations/messages/email'] = array( |
|
'title' => 'Email Messages', |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'weight' => 10, |
|
); |
|
$items['admin/config/system/room_reservations/messages/text'] = array( |
|
'title' => 'SMS Messages', |
|
'page callback' => 'drupal_get_form', |
|
'page arguments' => array('room_reservations_admin_settings_text'), |
|
'access arguments' => array('administer room reservations system'), |
|
'type' => MENU_LOCAL_TASK, |
|
'file' => 'room_reservations.admin.inc', |
|
'weight' => 20, |
|
); |
|
*/ |
|
|
|
/* |
|
$items['room_reservations/add'] = array( |
|
'title' => 'Reservation Details', |
|
'page callback' => 'room_reservations_res_add', |
|
'access callback' => TRUE, |
|
'type' => MENU_CALLBACK, |
|
'file' => '/controller/room_reservations_reservation.controller.inc', |
|
); |
|
$items['room_reservations/view'] = array( |
|
'title' => 'Reservation Details', |
|
'page callback' => 'room_reservations_res_view', |
|
'access callback' => TRUE, |
|
'type' => MENU_CALLBACK, |
|
'file' => '/controller/room_reservations_reservation.controller.inc', |
|
); |
|
$items['room_reservations/delete'] = array( |
|
'title' => 'Reservation Details', |
|
'page callback' => 'room_reservations_res_delete', |
|
'access callback' => TRUE, |
|
'type' => MENU_CALLBACK, |
|
'file' => '/controller/room_reservations_reservation.controller.inc', |
|
); */ |
|
$items['room_reservations'] = array( |
|
'title' => variable_get('room_reservations_title', 'Room Reservations'), |
|
'page callback' => 'room_reservations', |
|
'access arguments' => array('view room reservations calendar'), |
|
'type' => MENU_NORMAL_ITEM, |
|
'file' => '/controller/room_reservations_calendar.controller.inc', |
|
); |
|
$items['room_reservations/calendar'] = array( |
|
'title' => 'Calendar', |
|
'access arguments' => array('view room reservations calendar'), |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'weight' => 10, |
|
); |
|
$items['room_reservations/policies'] = array( |
|
'title' => 'Policies', |
|
'page callback' => 'room_reservations_policies', |
|
'access arguments' => array('view room reservations calendar'), |
|
'type' => MENU_LOCAL_TASK, |
|
'weight' => 30, |
|
'file' => '/controller/room_reservations.controller.inc', |
|
); |
|
return $items; |
|
} |
|
|
|
/** |
|
* Implements hook_init(). |
|
(). |
|
*/ |
|
function room_reservations_init() { |
|
// Add javascript. |
|
drupal_add_js(drupal_get_path('module', 'room_reservations') . '/room_reservations.js'); |
|
// Add css. |
|
drupal_add_css(drupal_get_path('module', 'room_reservations') . '/room_reservations.css'); |
|
// Prevent this module from caching. |
|
if ((drupal_match_path($_GET['q'], 'room_reservations')) || (drupal_match_path($_GET['q'], 'room_reservations/*'))) { |
|
$GLOBALS['conf']['cache'] = FALSE; |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_permission(). |
|
*/ |
|
function room_reservations_permission() { |
|
return array( |
|
'administer room reservations system' => array( |
|
'title' => t('Administer the room reservations system'), |
|
'description' => t('Allows administration of room categories, rooms and reservations. Allows administering all system configuration settings.'), |
|
), |
|
'edit any room reservation' => array( |
|
'title' => t('Edit any room reservation'), |
|
'description' => t('Allows editing of all room reservations in the system.'), |
|
), |
|
'delete any room reservation' => array( |
|
'title' => t('Delete any room reservation'), |
|
'description' => t('Allows deleting of any room reservation in the system.'), |
|
), |
|
'create room reservations standard' => array( |
|
'title' => t('Create room reservations as well as edit or cancel your own reservations. Book in advance standard limit.'), |
|
'description' => t('Create room reservations as well as edit or cancel your own reservations'), |
|
), |
|
'create room reservations extended' => array( |
|
'title' => t('Create room reservations as well as edit or cancel your own reservations. Book in advance extended limit.'), |
|
'description' => t('Create room reservations as well as edit or cancel your own reservations'), |
|
), |
|
'bypass minimum advance booking' => array( |
|
'title' => t('Bypass minimum advanced booking limit.'), |
|
'description' => t('Bypass minimum advanced booking limit.'), |
|
), |
|
'bypass reservations limiters' => array( |
|
'title' => t('Bypass number of reservations limiters.'), |
|
'description' => t('Bypass open reservations per user and reservations per day limits.'), |
|
), |
|
'book over buffer' => array( |
|
'title' => t('Allow booking over setup/takedown buffers.'), |
|
'description' => t('Allow user to book over top of the setup/takedown buffer for an existing reservation.'), |
|
), |
|
'create room reservations extended length' => array( |
|
'title' => t('Create extended maximum length room reservations.'), |
|
'description' => t('Create extended length reservations.'), |
|
), |
|
'view room reservations calendar' => array( |
|
'title' => t('View the room reservations calendar'), |
|
'description' => t('Allowed to view the reservations calendar but does not allow creating new reservations.'), |
|
), |
|
); |
|
} |
|
|
|
/** |
|
* Implements hook_validate(). |
|
*/ |
|
function room_reservations_validate($node, $form, &$form_state) { |
|
// If this is not a room reservation or we are not actually creating a new |
|
// node we don't need to check for max reservations so return TRUE. |
|
if ($node->type != 'room_reservations_reservation' || |
|
$form_state['values']['op'] == 'Cancel Reservation' || !empty($node->nid)) { |
|
return TRUE; |
|
} |
|
// TODO pull into a function as this code is duplicated here and in the form function. |
|
if ($nid = $form['nid']['#value']) { |
|
$res = $form['#node']; |
|
$d = $res->reservation_date['und'][0]['value']; |
|
$yyyymmdd = date('Y-m-d', strtotime($d)); |
|
} |
|
|
|
// Group name must be 25 characters or less. |
|
if ($node->type == 'room_reservations_reservation' && strlen($node->title) > 25 |
|
&& $form_state['values']['op'] == 'Save') { |
|
form_error($form, t('Group name must be less than 25 characters.')); |
|
} |
|
|
|
// CREATE NEW. |
|
else { |
|
// Determine if this year or next year. |
|
$yearnow = date('Y'); |
|
$absdaynow = date('z'); |
|
$absdaydefault = date('z', mktime(0, 0, 0, arg(3), arg(4), $yearnow)); |
|
if ($absdaynow > $absdaydefault) { |
|
$year = $yearnow + 1; |
|
} |
|
else { |
|
$year = $yearnow; |
|
} |
|
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . arg(3) . '-' . arg(4))); |
|
} |
|
|
|
|
|
if (user_access('bypass reservations limiters')) { |
|
return; |
|
} |
|
else { |
|
if (_room_reservations_daily_max_exceeded($yyyymmdd)) { |
|
form_error($form, t('You have exceeded your daily reservation limit.')); |
|
} |
|
if (_room_reservations_user_max_exceeded()) { |
|
form_error($form, t('You have exceeded your total number of reservations allowed.')); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_node_access() |
|
* |
|
* rev 1.3 - change all node access deny to node access ignore so that other modules may better integrate |
|
* - i.e. if DENY is set no other module can override that |
|
* |
|
* NOTE - this hook is not called for user 1 |
|
*/ |
|
function room_reservations_node_access($nodetype_or_node, $op, $account) { |
|
if (is_object($nodetype_or_node)) { |
|
$nodetype = $nodetype_or_node->type; |
|
} |
|
else { |
|
$nodetype = $nodetype_or_node; |
|
} |
|
switch ($nodetype) { |
|
case 'room_reservations_category': |
|
case 'room_reservations_room': |
|
switch ($op) { |
|
case 'create': |
|
case 'update': |
|
case 'delete': |
|
return user_access('administer room reservations system') ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE; |
|
} |
|
break; |
|
|
|
case 'room_reservations_reservation': |
|
global $user; |
|
// if it is my reservation; do nothing (let Drupal handle as usual) |
|
if ((is_object($nodetype_or_node) && $nodetype_or_node->uid == $user->uid)) { |
|
return NODE_ACCESS_ALLOW; |
|
} |
|
else { |
|
switch ($op) { |
|
case 'create': |
|
// if we are trying to create a reservation let's make sure user hasn't just entered dates via url |
|
// since available lengths takes allowed dates into account; lets just use that |
|
$yyyymmdd = _room_reservations_yyyymmdd(arg(3), arg(4)); |
|
$lengths = _room_reservations_valid_lengths(arg(6), $yyyymmdd, arg(5)); |
|
if (count($lengths)) { |
|
foreach ($lengths as $length) { |
|
if ($length['is_valid']) { |
|
return (user_access('create room reservations standard') || user_access('create room reservations extended') |
|
|| user_access('administer room reservations system')) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE; |
|
} |
|
} |
|
} |
|
return NODE_ACCESS_DENY; |
|
case 'update': |
|
return (user_access('administer room reservations system') || user_access('edit any room reservation')) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE; |
|
case 'delete': |
|
return (user_access('administer room reservations system') || user_access('delete any room reservation')) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE; |
|
case 'view': |
|
return user_access('administer room reservations system') ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE; |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
|
|
/** |
|
* remove std Node perms for all types associated with Room Reservations |
|
* |
|
* @param mixed $form |
|
* @param mixed $form_state |
|
* @param mixed $form_id |
|
*/ |
|
function room_reservations_form_user_admin_permissions_alter(&$form, &$form_state, $form_id) { |
|
foreach ($form['permission'] as $perm => $value) { |
|
if (stristr($perm, 'content') && stristr($perm, 'room_reservations_')) { |
|
unset($form['permission'][$perm]); |
|
} |
|
} |
|
|
|
foreach ($form['checkboxes'] as $box => $settings) { |
|
foreach ($settings['#options'] as $index => $option) { |
|
if (stristr($index, 'content') && stristr($index, 'room_reservations_')) { |
|
unset($form['checkboxes'][$box]['#options'][$index]); |
|
} |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* Description. |
|
* |
|
* @param mixed $form |
|
* $form |
|
* @param mixed $form_state |
|
* $form_state |
|
* @param mixed $form_id |
|
* $form_id |
|
*/ |
|
function room_reservations_form_room_reservations_reservation_node_form_alter(&$form, &$form_state, $form_id) { |
|
// Params either passed in on url - CREATE or pulled from node - EDIT. |
|
// EDIT. |
|
if (user_access('administer site configuration') && isset($_GET['edit']) && $_GET['edit'] == 'standard') { |
|
return; |
|
} |
|
|
|
// EDIT |
|
if ($nid = $form['nid']['#value']) { |
|
$res = $form['#node']; |
|
$rid = $res->reservation_room[LANGUAGE_NONE][0]['target_id']; |
|
$d = $res->reservation_date[LANGUAGE_NONE][0]['value']; |
|
$yyyymmdd = date('Y-m-d', strtotime($d)); |
|
$t = $res->reservation_time[LANGUAGE_NONE][0]['value']; |
|
} |
|
|
|
// CREATE NEW |
|
else { |
|
// if no parameters passed; lets redirect to calendar page |
|
if (!arg(3) && !arg(4)) { |
|
drupal_goto('room_reservations'); |
|
} |
|
// determine if this year or next year |
|
$yearnow = date('Y'); |
|
$absdaynow = date('z'); |
|
$absdaydefault = date('z', mktime(0, 0, 0, arg(3), arg(4), $yearnow)); |
|
if ($absdaynow > $absdaydefault) { |
|
$year = $yearnow + 1; |
|
} |
|
else { |
|
$year = $yearnow; |
|
} |
|
$rid = arg(6); |
|
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . arg(3) . '-' . arg(4))); |
|
$d = $yyyymmdd . ' 00:00:00'; |
|
$t = arg(5); |
|
} |
|
|
|
$room = node_load($rid); |
|
$date = date('l, M d, Y', strtotime($d)); |
|
$time = _room_reservations_display_time($t); |
|
|
|
$form['reservation_heading']['#type'] = 'markup'; |
|
$form['reservation_heading']['#markup'] = ' |
|
<h2 class="reservation-h2">' . t('Reservation booking for') . ':</h2><div><strong>' . t('Room') . ': ' . $room->title . '</strong></div> |
|
<div><strong>' . t('Date') . ': ' . $date . '</strong></div> |
|
<div><strong>' . t('Time') . ': ' . $time . '</strong></div><br/>'; |
|
|
|
$form['reservation_room']['#access'] = 0; |
|
$form['reservation_date']['#access'] = 0; |
|
$form['reservation_time']['#access'] = 0; |
|
$form['reservation_room'][LANGUAGE_NONE]['#default_value'] = $room->nid; |
|
|
|
// Date fields are a major pita, setting default does nothing here; |
|
// we need to carry this forward to the node_presave hook |
|
$form['#node']->date_default = $d; |
|
$form['reservation_time'][LANGUAGE_NONE][0]['value']['#default_value'] = $t; |
|
|
|
// remove Preview - can likely do this in node def |
|
unset($form['actions']['preview']); |
|
|
|
// hide Series ID field |
|
$form['reservation_series_id']['#access'] = FALSE; |
|
|
|
// if we are editing; let's do some extra things: |
|
// - disable Repeat options |
|
// - (series) add msg that we are editing a series and link to edit just that entry |
|
if ($nid) { |
|
$form['reservation_repeat_type']['#disabled'] = TRUE; |
|
$form['reservation_repeat_until']['#disabled'] = TRUE; |
|
|
|
// not sure why this was here; if req i don't think structure during edit is correct here |
|
/* |
|
if ($form['reservation_repeat_type'][LANGUAGE_NONE][0]['#value'] > 1) { |
|
$form['reservation_repeat_until'][LANGUAGE_NONE][0]['#value'] = $form['reservation_repeat_until'][LANGUAGE_NONE][0]['#default_value']['value']; |
|
} |
|
*/ |
|
|
|
$form['reservation_repeat_until']['und'][0]['#value'] = $form['reservation_repeat_until']['und'][0]['#default_value']['value']; |
|
|
|
// Form alter is hit in/out of form so we alter only in so we don't show |
|
// messages after form is submitted - !count($form_state['input']). |
|
if ($form['reservation_series_id'][LANGUAGE_NONE][0]['value']['#default_value'] && !count($form_state['input'])) { |
|
if (isset($_GET['single'])) { |
|
$series_link = l(t('Click here'), "node/$nid/edit"); |
|
drupal_set_message(t('NOTE: you are editing a SINLGE day in a SERIES of reservations. Any changes made here will impact only the reservation |
|
for this day. !link if you want to edit the entire series.', array('!link' => $series_link)), 'warning'); |
|
} |
|
else { |
|
$single_link = l(t('Click here'), "node/$nid/edit", array('query' => array('single' => 1))); |
|
drupal_set_message(t('NOTE: you are editing a SERIES of reservations. Any changes made here will impact all reservations in this |
|
series. !link if you only want to edit this specific day in this series.', array('!link' => $single_link)), 'warning'); |
|
} |
|
} |
|
|
|
// And then parts that have to be here on both passes. |
|
if ($form['reservation_series_id'][LANGUAGE_NONE][0]['value']['#default_value']) { |
|
if (isset($_GET['single'])) { |
|
// Re-label Delete to Cancel Reservation. |
|
$form['actions']['delete']['#value'] = t('Cancel Reservation for This Day'); |
|
} |
|
else { |
|
// Remove single node delete and add Delete Series button. |
|
unset($form['actions']['delete']); |
|
$form['actions']['delete_series'] = array( |
|
'#type' => 'submit', |
|
'#value' => t('Cancel Entire Series Reservation'), |
|
'#weight' => 20, |
|
'#submit' => array('_room_reservations_series_delete'), |
|
); |
|
} |
|
} |
|
|
|
// And if not part of a series; let's change DELETE button. |
|
if (!$form['reservation_series_id'][LANGUAGE_NONE][0]['value']['#default_value']) { |
|
$form['actions']['delete']['#value'] = t('Cancel Reservation'); |
|
} |
|
} |
|
|
|
// Only show repeat reservation controls to users with 'Bypass number of reservations limiters' permission. |
|
if (!user_access('Bypass number of reservations limiters')) { |
|
$form['reservation_repeat_type']['#disabled'] = TRUE; |
|
$form['reservation_repeat_until']['#disabled'] = TRUE; |
|
$form['reservation_repeat_type']['#type'] = 'hidden'; |
|
$form['reservation_repeat_until']['#type'] = 'hidden'; |
|
} |
|
|
|
// Always redirect back to reservations calendar page. |
|
$form['actions']['submit']['#submit'][] = 'return_to_reservations_page'; |
|
|
|
// Limit valid lengths so we have no overlaps. |
|
$validlengths = _room_reservations_valid_lengths($rid, $yyyymmdd, $t); |
|
foreach ($validlengths as $length) { |
|
if ($length['is_valid']) { |
|
$lengths[] = $length['length']; |
|
} |
|
} |
|
foreach ($form['reservation_length'][LANGUAGE_NONE]['#options'] as $slot => &$option) { |
|
if (!in_array($slot, $lengths)) { |
|
unset($form['reservation_length'][LANGUAGE_NONE]['#options'][$slot]); |
|
} |
|
} |
|
|
|
$form['reservation_repeat_type'][LANGUAGE_NONE]['#default_value'] = $form['reservation_repeat_type'][LANGUAGE_NONE]['#default_value'] ? $form['reservation_repeat_type'][LANGUAGE_NONE]['#default_value'] : 1; |
|
$form['reservation_repeat_until']['#states'] = array( |
|
'visible' => array( |
|
':input[name="reservation_repeat_type[und]"]' => array('!value' => '1'), |
|
), |
|
); |
|
|
|
// CHANGE - empty return not needed. |
|
// return; |
|
} |
|
|
|
/** |
|
* Description. |
|
* |
|
* @param mixed $form |
|
* $form |
|
* @param mixed $form_state |
|
* $form_state |
|
* @param mixed $form_id |
|
* $form_id |
|
*/ |
|
function room_reservations_form_node_delete_confirm_alter(&$form, &$form_state, $form_id) { |
|
if ($form['#node']->type == 'room_reservations_reservation') { |
|
$form['#submit'][] = 'return_to_reservations_page'; |
|
} |
|
|
|
// CHANGE - empty return statement not needed here. |
|
// return; |
|
} |
|
|
|
/** |
|
* Description. |
|
* |
|
* @param mixed $node |
|
* $node |
|
*/ |
|
function room_reservations_node_presave($node) { |
|
switch ($node->type) { |
|
case 'room_reservations_reservation': |
|
if (isset($node->date_default)) { |
|
$node->reservation_date[LANGUAGE_NONE][0]['value'] = $node->date_default; |
|
} |
|
break; |
|
} |
|
} |
|
|
|
/** |
|
* Description. |
|
* |
|
* @param mixed &$element |
|
* $element |
|
* @param mixed $form_state |
|
* $form_state |
|
* @param mixed &$context |
|
* $context |
|
*/ |
|
function room_reservations_date_popup_process_alter(&$element, &$form_state, &$context) { |
|
if (isset($element['#field']['field_name'])) { |
|
switch ($element['#field']['field_name']) { |
|
case "reservation_repeat_until": { |
|
if (user_access('create room reservations extended')) { |
|
$advancedays = variable_get('room_reservations_advance_extended', 180); |
|
} |
|
else { |
|
$advancedays = variable_get('room_reservations_advance_standard', 14); |
|
} |
|
$element['#datepicker_options'] = array( |
|
'minDate' => '+0d', |
|
'maxDate' => $advancedays . 'D', |
|
); |
|
$element['date'] = date_popup_process_date_part($element); |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* Description. |
|
* |
|
* @param mixed $form |
|
* $form |
|
* @param mixed $form_state |
|
* $form_state |
|
*/ |
|
function return_to_reservations_page($form, &$form_state) { |
|
// Can't set redirect here for DELETE function; |
|
// see delete confirm form alter above |
|
if ($form_state['clicked_button']['#id'] == 'edit-delete') { |
|
return; |
|
} |
|
|
|
if(isset($form_state['values']['reservation_room'][LANGUAGE_NONE][0]['target_id'])) { |
|
$rid = $form_state['values']['reservation_room'][LANGUAGE_NONE][0]['target_id']; |
|
$rooms = _room_reservations_rooms(); |
|
$categories = _room_reservations_categories(); |
|
$room = $rooms[$rid]; |
|
$catid = $room['reservations_room_category'][LANGUAGE_NONE][0]['target_id']; |
|
$category = $categories[$catid]; |
|
$anchor = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $category['title'])); |
|
} |
|
|
|
// Need to handle both update and delete case. |
|
$date = (empty($form_state['values']['reservation_date'][LANGUAGE_NONE][0]['value'])) ? NULL : $form['#node']->reservation_date[LANGUAGE_NONE][0]['value']; |
|
if ($date) { |
|
$return = date('n/d', strtotime($date)); |
|
$form_state['redirect'] = array('room_reservations/' . $return, array('fragment' => $anchor)); |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_theme(). |
|
*/ |
|
function room_reservations_theme() { |
|
return array( |
|
'room_reservations' => array( |
|
'variables' => array( |
|
'dates', |
|
'categories', |
|
'hours', |
|
'building_hours', |
|
'building_hours_display', |
|
'rooms', |
|
'selected_category', |
|
'user_reservations', |
|
), |
|
'file' => '/view/room_reservations_calendar.view.inc', |
|
), |
|
'room_reservations_descriptions' => array( |
|
'variables' => array('categories, rooms'), |
|
'file' => '/view/room_reservations.view.inc', |
|
), |
|
'room_reservations_list' => array( |
|
'variables' => array('user, base_url, user_reservations, count'), |
|
'file' => '/view/room_reservations.view.inc', |
|
), |
|
); |
|
} |
|
|
|
/** |
|
* Implements hook_mail(). |
|
*/ |
|
function room_reservations_mail($key, &$message, $params) { |
|
global $base_url; |
|
$modified_base_url = str_replace('https', 'http', $base_url); |
|
$headers = array( |
|
'MIME-Version' => '1.0', |
|
'Content-Type' => 'text/html; charset=UTF-8; format=flowed', |
|
'Content-Transfer-Encoding' => '8Bit', |
|
'X-Mailer' => 'Drupal', |
|
); |
|
switch ($key) { |
|
case 'confirmation': |
|
foreach ($headers as $key => $value) { |
|
$message['headers'][$key] = $value; |
|
} |
|
$message['subject'] = _room_reservations_replace_tokens(check_plain( |
|
_room_reservations_get_variable('confirmation_header_text')), $params); |
|
$body = _room_reservations_replace_tokens(check_markup( |
|
_room_reservations_get_variable('confirmation_owner_text')), $params); |
|
$message['body'][] = '<html><body>' . $body . '</body></html>'; |
|
break; |
|
|
|
case 'notification': |
|
foreach ($headers as $key => $value) { |
|
$message['headers'][$key] = $value; |
|
} |
|
$message['subject'] = _room_reservations_replace_tokens(check_plain( |
|
_room_reservations_get_variable('confirmation_header_text')), $params); |
|
$body = _room_reservations_replace_tokens(check_markup( |
|
_room_reservations_get_variable('confirmation_group_text')), $params); |
|
$message['body'][] = '<html><body>' . $body . '</body></html>'; |
|
break; |
|
|
|
case 'owner reminder': |
|
foreach ($headers as $key => $value) { |
|
$message['headers'][$key] = $value; |
|
} |
|
$message['subject'] = _room_reservations_replace_tokens(check_plain( |
|
_room_reservations_get_variable('reminder_header_text')), $params); |
|
$body = _room_reservations_replace_tokens(check_markup( |
|
_room_reservations_get_variable('reminder_owner_text')), $params); |
|
$message['body'][] = '<html><body>' . $body . '</body></html>'; |
|
break; |
|
|
|
case 'group reminder': |
|
foreach ($headers as $key => $value) { |
|
$message['headers'][$key] = $value; |
|
} |
|
$message['subject'] = _room_reservations_replace_tokens(check_plain( |
|
_room_reservations_get_variable('reminder_header_text')), $params); |
|
$body = _room_reservations_replace_tokens(check_markup( |
|
_room_reservations_get_variable('reminder_group_text')), $params); |
|
$message['body'][] = '<html><body>' . $body . '</body></html>'; |
|
break; |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_cron(). |
|
*/ |
|
function xxxroom_reservations_cron() { |
|
// Send reservation reminders. |
|
$send_reminders = _room_reservations_get_variable('send_reminders'); |
|
$last_reminders_sent = _room_reservations_get_variable('last_reminders_sent'); |
|
$reminder_time = (_room_reservations_get_variable('reminder_time') / 100); |
|
$reminder_cutoff = (_room_reservations_get_variable('reminder_cutoff') / 100) . ':00:00'; |
|
$reminders_sent_today = FALSE; |
|
// Reminders are sent once a day. Have they been sent today? |
|
if ($last_reminders_sent) { |
|
if ($last_reminders_sent == date("Y-m-d")) { |
|
$reminders_sent_today = TRUE; |
|
} |
|
} |
|
$current_hour = date("G"); |
|
if (($send_reminders) && (!$reminders_sent_today) && ($current_hour >= $reminder_time)) { |
|
$today = date("Y-m-d"); |
|
$cutoff = $today . ' ' . $reminder_cutoff; |
|
$tomorrow = date('Y-m-d', strtotime("now +1 days")); |
|
$no_reminder_sent = '0000-00-00 00:00:00'; |
|
$not_deleted = 'N'; |
|
$sql = " |
|
SELECT * |
|
FROM {room_reservations} |
|
WHERE date = '%s' |
|
AND reminder_date = '%s' |
|
AND create_date < '%s' |
|
AND deleted = '%s' |
|
"; |
|
$record_count = 0; |
|
$hours = _room_reservations_hours(); |
|
$result = db_query($sql, $tomorrow, $no_reminder_sent, $cutoff, $not_deleted); |
|
if ($result) { |
|
while ($data = db_fetch_object($result)) { |
|
$id = $data->id; |
|
$date = $data->date; |
|
$time = $data->time; |
|
$length = $data->length; |
|
$room = $data->room; |
|
$name = check_plain($data->name); |
|
$group_size = $data->group_size; |
|
$user_name = $data->user_name; |
|
$email_addresses = check_plain($data->email_addresses); |
|
$textmsg = $data->textmsg; |
|
$carrier = $data->carrier; |
|
$phone = check_plain($data->phone); |
|
$record_count++; |
|
$month_name = date("F", strtotime($date)); |
|
$month_number = date("n", strtotime($date)); |
|
$day = date("j", strtotime($date)); |
|
$day_of_week = date("l", strtotime($date)); |
|
foreach ($hours as $individual_hour) { |
|
if ($individual_hour['time'] == $time) { |
|
$display_time = $individual_hour['display']; |
|
break; |
|
} |
|
} |
|
// Send email reminders. |
|
$params = array( |
|
'room' => $room, |
|
'month' => $month_name, |
|
'month_number' => $month_number, |
|
'day' => $day, |
|
'day_of_week' => $day_of_week, |
|
'time' => $display_time, |
|
'minutes' => $length, |
|
'name' => $name, |
|
'id' => $id, |
|
'carrier' => $carrier, |
|
'phone' => $phone, |
|
); |
|
$from = check_plain(_room_reservations_get_variable('from_address')); |
|
// Send an email to each person in the group. If the person is the one |
|
// who made the reservation, send the owner reminder message. |
|
// Otherwise, send the group reminder message. |
|
if (drupal_strlen($email_addresses)) { |
|
$to_addresses = explode(',', $email_addresses); |
|
foreach ($to_addresses as $to_address) { |
|
$to_address = trim($to_address); |
|
$pos = strpos($to_address, $user_name); |
|
if ($pos === FALSE) { |
|
$key = 'group reminder'; |
|
} |
|
else { |
|
$key = 'owner reminder'; |
|
} |
|
$response = drupal_mail('room_reservations', $key, $to_address, language_default(), $params, $from, TRUE); |
|
} |
|
} |
|
// Send a text message if requested. |
|
if ($textmsg == 'Y') { |
|
_room_reservations_send_sms('reminder', $params); |
|
} |
|
// Update the reminder_date field in the db record. |
|
$now = date("Y-m-d H:i"); |
|
$sql2 = "UPDATE {room_reservations} SET reminder_date = '%s' WHERE id = %d"; |
|
$result2 = db_query($sql2, $now, $id); |
|
} |
|
} |
|
_room_reservations_set_variable('last_reminders_sent', $today); |
|
} |
|
// End code to send reminders. |
|
// Update the building hours records. |
|
$update_building_hours = FALSE; |
|
$today = date("Y-m-d"); |
|
$building_hours_update_date = _room_reservations_get_variable('building hours update'); |
|
if ($building_hours_update_date) { |
|
if ($building_hours_update_date < $today) { |
|
$update_building_hours = TRUE; |
|
} |
|
} |
|
if (!$building_hours_update_date) { |
|
$update_building_hours = TRUE; |
|
} |
|
if ($update_building_hours) { |
|
_room_reservations_set_variable('building hours update', $today); |
|
$months = _room_reservations_current_months(); |
|
$x = 0; |
|
foreach ($months as $month) { |
|
// Delete first month - previous month. |
|
if (!$x) { |
|
$result = _room_reservations_delete_variable('MONTHLY_HOURS_' . $month['YYYY_MM']); |
|
$x++; |
|
} |
|
else { |
|
// Create current three months if they don't exist. |
|
$month_hours = _room_reservations_get_variable('MONTHLY_HOURS_' . $month['YYYY_MM']); |
|
if (!$month_hours) { |
|
_room_reservations_create_mo_hours($month['year'], $month['month'], $month['YYYY_MM']); |
|
} |
|
} |
|
} |
|
} |
|
}
|
|
|