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'] = '