'. t("The Simple Reservation module allows to create any number of user-defined bookable items. The items may have a description and a comment.") .'
'; return $output; break; } } /** * Implementation of hook_perm(). */ function simplereservation_perm() { return array( 'access simple reservations', 'add simple reservations', 'add simple reservations for others', 'edit own simple reservations', 'edit simple reservations of others', 'delete own simple reservations', 'delete simple reservations of others', 'unrestricted simple reservations', 'administer simple reservation system', 'administer simple reservation triggers'); } // function newmodule_perm /** * Implementation of hook_menu_alter */ function simplereservation_menu_alter(&$items) { // By default, the trigger system uses the module name // (i.e. example) as the access for the trigger // configuration menu item. we want to change that. $items['admin/build/trigger/simplereservation']['access arguments'] = array('administer simple reservation triggers'); } /** * Implementation of hook_hook_info */ function simplereservation_hook_info() { // Define triggers $items = array( 'simplereservation' => array( 'simplereservation' => array( 'new_reservation' => array( 'runs when' => t('A new (simple) reservation has been created.'), ), 'delete_reservation' => array( 'runs when' => t('A new (simple) reservation has been deleted.'), ), ), ), ); return $items; } /** * Invoke trigger * * This function is a wrapper/helper for triggers/hooks * * @param $hook * string describing hook * @param $op * string describing operation * @return * boolean, true or false if successful */ function simplereservation_invoke_hook($hook = 'example', $op = null, $object = null) { // Perform hook invoke module_invoke_all($hook, $op); // Call trigger/actions if (function_exists('_trigger_get_hook_aids')) { $aids = _trigger_get_hook_aids($hook, $op); } $context = array('hook' => $hook, 'op' => $op); if ($aids) { actions_do(array_keys($aids), $object, $context); } return true; } /** * Implementation of hook_action_info_alter */ function simplereservation_action_info_alter(&$info) { foreach ($info as $type => $data) { if (stripos($type, "user_") === 0 || stripos($type, "system_") === 0) { if (isset($info[$type]['hooks']['application'])) { array_merge($info[$type]['hooks']['simplereservation'], array('new_reservation', 'delete_reservation')); } else { $info[$type]['hooks']['simplereservation'] = array('new_reservation', 'delete_reservation'); } } } } /** * Implementation of hook_menu(). */ function simplereservation_menu() { global $user; $items = array(); $items['admin/settings/simplereservation'] = array( 'title' => 'Simple Reservation', 'description' => 'Configure the reservation system and the items which are available for reservation.', 'page callback' => 'simplereservation_admin_main_page', 'access arguments' => array('administer simple reservation system'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/settings/simplereservation/delete/%'] = array( 'title' => 'Delete item', 'description' => 'Delete an item from the reservation system.', 'page callback' => 'drupal_get_form', 'page arguments' => array('simplereservation_item_delete_confirm', 4), 'access arguments' => array('administer simple reservation system'), 'type' => MENU_CALLBACK, ); $items['admin/settings/simplereservation/edit/%'] = array( 'title' => 'Edit item', 'description' => 'Edit an item from the reservation system.', 'page callback' => 'simplereservation_item_edit', 'page arguments' => array(4), 'access arguments' => array('administer simple reservation system'), 'type' => MENU_CALLBACK, ); $items['admin/settings/simplereservation/showall/%'] = array( 'title' => 'List Reservations', 'description' => 'Display a list of all/upcoming reservations.', 'page callback' => 'simplereservation_showall_reservations', 'access arguments' => array('administer simple reservation system'), 'type' => MENU_CALLBACK, ); $items['simplereservation'] = array( 'title' => 'Reservation', 'description' => 'Main page of the simple reservation system.', 'page callback' => 'simplereservation_main_view', 'access arguments' => array('access simple reservations'), 'type' => MENU_NORMAL_ITEM, ); $items['simplereservation/add'] = array( 'title' => 'Add reservation', 'description' => 'Add a reservation into the simple reservation system.', 'page callback' => 'simplereservation_reservation_add', 'access arguments' => array('add simple reservations'), 'type' => MENU_NORMAL_ITEM, ); $items['simplereservation/edit'] = array( 'title' => 'Edit reservation', 'description' => 'Edit an existing reservation.', 'page callback' => 'simplereservation_reservation_edit', 'access arguments' => array('edit own simple reservations'), 'type' => MENU_CALLBACK, ); $items['simplereservation/delete/%'] = array( 'title' => 'Delete reservation', 'description' => 'Delete a reservation from the reservation system.', 'page callback' => 'drupal_get_form', 'page arguments' => array('simplereservation_reservation_delete_confirm', 2), 'access arguments' => array('delete own simple reservations'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_theme(). */ function simplereservation_theme() { return array( // Custom theme function for preprocessing variables 'simplereservation_theming' => array( 'arguments' => array('config' => NULL), ), // Default block layout 'simplereservation_week' => array( 'template' => 'simplereservation_week', 'arguments' => array('config' => NULL, 'reservations' => NULL), ), ); } /** * Custom theme function for preprocessing the output */ function theme_simplereservation_theming($config) { // Set up variables which might be needed in the templates $week_max = date_iso_weeks_in_year($dateweek[0]); $months = date_month_names(); // get current week and year $week = date("W"); $year = date("Y"); // if given, take the arguments as week/year if ( is_numeric(arg(1) )) $week = arg(1); if ( is_numeric(arg(2) )) $year = arg(2); $dateweek = date_week_range($week+1, $year); $date = strtotime($year ."-W". $week); //print (date_format_date($dateweek[0], "SHORT")." "); $config["week"] = $week; $config["prev_week"] = $week - 1; $config["prev_week_year"] = $year; $config["prev_4week"] = $week - 4; $config["prev_4week_year"] = $year; if (date("z", $date) < 7) { //if ($week == 1) $config["prev_week"] = 52; $config["prev_week_year"] = $year-1; $config["prev_4week"] = 48; $config["prev_4week_year"] = $year-1; } if ($week+4 > $week_max) { $config["next_4week"] = 2; $config["next_4week_year"] = $year+1; } else { $config["next_4week"] = $week + 4; $config["next_4week_year"] = $year; } if ($week+1 > $week_max) { $config["next_week"] = 2; $config["next_week_year"] = $year+1; } else { $config["next_week"] = $week + 1; $config["next_week_year"] = $year; } $config["month"] = $months[(int)date('m', $date)]; $config["week"] = $week; $config["year"] = $year; $d = $dateweek[0]; for ($i = 0; $i<=28; $i++) { $week_dates[$i] = $d; $d = drupal_clone($d); date_modify($d, "+1 day"); } // move forwards to the last day of the week $empty["rid"] = 0; //$reservations = array('a', 'b', 'c', 'd'); $config["calendar"] = array( 0 => $week_dates[0], 1 => $week_dates[1], 2 => $week_dates[2], 3 => $week_dates[3], 4 => $week_dates[4], 5 => $week_dates[5], 6 => $week_dates[6], 7 => $week_dates[7], 8 => $week_dates[8], 9 => $week_dates[9], 10 => $week_dates[10], 11 => $week_dates[11], 12 => $week_dates[12], 13 => $week_dates[13], 14 => $week_dates[14], 15 => $week_dates[15], 16 => $week_dates[16], 17 => $week_dates[17], 18 => $week_dates[18], 19 => $week_dates[19], 20 => $week_dates[20], 21 => $week_dates[21], 22 => $week_dates[22], 23 => $week_dates[23], 24 => $week_dates[24], 25 => $week_dates[25], 26 => $week_dates[26], 27 => $week_dates[27], 28 => $week_dates[28], ); $reservations = array(); $sql = "SELECT * FROM {simplereservation_reservation} "; $sql .= "INNER JOIN {simplereservation_item} ON iid=item_id "; $sql .= "WHERE (begin>=%d AND begin<=%d) "; // Beginn zwischen heute und morgen $sql .= "OR (ending>=%d AND ending<=%d) "; // Ende zwischen heute und morgen $sql .= "OR (begin < %d AND ending > %d) "; // bereits begonnen und Ende in der Zukunft $sql .= "ORDER BY begin;"; for ($day = 0; $day < 28; $day++) { $i=0; $result = db_query($sql, date_format($week_dates[$day], "U"), date_format($week_dates[$day+1], "U"), date_format($week_dates[$day], "U"), date_format($week_dates[$day+1], "U"), date_format($week_dates[$day], "U"), date_format($week_dates[$day+1], "U") ); $reservations[$day][0]=$empty; while ($row = db_fetch_array($result)) { $reservations[$day][$i] = $row; $i++; } } // falls es reservierbare items gibt: $sql = "SELECT COUNT(iid) as countiid FROM {simplereservation_item} where status = 1;"; $result = db_query($sql); $row = db_fetch_array($result); if ($row['countiid'] > 0) { return theme('simplereservation_week', $config, $reservations); } else { drupal_set_message (t('There are no items for reservation.')); } } function simplereservation_main_view() { $month = date_month_names(); $week_day = date_week_days_ordered(date_week_days()); $now = date_now(); $output = ''; $output .= theme('simplereservation_theming', $config); return $output; } /** * Construct a form */ function simplereservation_add_edit_form() { $num_items = db_fetch_object ( db_query("SELECT count(iid) as countiid FROM {simplereservation_item}")); if ($num_items->countiid =='0'){ drupal_set_message (t('Please create an item before try to reseve nothing')); } else { global $user; $rid = 0; $wholedaysonly = variable_get('simplereservation_whole_days', FALSE); $timeresolution = variable_get('simplereservation_time_step', 15); if (arg(1) == "edit") $edit = TRUE; if ($edit) { if (is_numeric(arg(2))) { $rid = arg(2); $sql = "SELECT * FROM {simplereservation_reservation} "; $sql .= "WHERE rid =%d;"; $result = db_query($sql, $rid); $res = db_fetch_array($result); } else return $form; } $form['datetime'] = array( '#type' => 'fieldset', '#title' => t('Date and Time'), '#description' => t('Date and time for this reservation.'), '#collapsible' => FALSE, '#collapsed' => FALSE, '#tree' => TRUE, ); if ($edit) { $year = date("Y", $res["begin"]); $month = date("m", $res["begin"]); $day = date("d", $res["begin"]); $hour = date("H", $res["begin"]); $min = date("i", $res["begin"]); } else { // get the date from the URL if ( is_numeric(arg(2) )) $year = arg(2); if ( is_numeric(arg(3) )) $month = arg(3); if ( is_numeric(arg(4) )) $day = arg(4); $hour = "07"; $min = "00"; } if ($wholedaysonly) { $date_format = 'd.m.Y - H:i'; } else { $date_format = 'd.m.Y - H:i'; } $form['datetime']['start'] = array( '#type' => 'date_popup', '#date_year_range' => '0:+3', '#date_type' => DATE_DATETIME, '#date_timezone' => date_default_timezone_name(), '#date_increment' => $timeresolution, '#date_format' => $date_format, '#title' => t('Start'), '#default_value' => $year .'-'. $month .'-'. $day .' '. $hour .':'. $min .':00', '#description' => t('Start date and time of this reservation.'), ); if ($edit) { $year = date("Y", $res["ending"]); $month = date("m", $res["ending"]); $day = date("d", $res["ending"]); $hour = date("H", $res["ending"]); $min = date("i", $res["ending"]); if ($res["whd"]) { // no date_increment if this is a whole-day-reservation $timeresolution = 0; } } else { $hour = "14"; $min = "00"; } if ($wholedaysonly) { $form['datetime']['end'] = array( '#type' => 'hidden', '#value' => $year .'-'. $month .'-'. $day .' 23:59', ); } else { $form['datetime']['end'] = array( '#type' => 'date_popup', '#date_year_range' => '0:+3', '#date_type' => DATE_UNIX, '#date_timezone' => date_default_timezone_name(), '#date_increment' => $timeresolution, '#date_format' => $date_format, '#title' => t('End'), '#default_value' => $year .'-'. $month .'-'. $day .' '. $hour .':'. $min .':00', '#description' => t('End date and time of this reservation.'), ); } if ($edit) $def = $res["whd"]; else $def = 0; if (!$wholedaysonly) { // do not display this checkbox if there are only whole-day-reservations $form['datetime']['whole_day'] = array( '#type' => 'checkbox', '#title' => t('Reservation for the complete day'), '#description' => t('Enable this reservation if you want to reserve for the whole day. This overwrites the above hour/minute setting.'), '#default_value' => $def, ); } // get the reservation items and fill them in a dropdown // nur die Items anzeigen, die man anzeigen will: status = 1 $sql = "SELECT iid, name, description FROM {simplereservation_item} where status=1 ORDER BY name;"; $result = db_query($sql); while ($data = db_fetch_object($result)) { $period[$data->iid] = $data->name ." (". $data->description .")"; } if ($edit) $def = $res["item_id"]; else $def = 0; $form['item'] = array( '#type' => 'select', '#title' => t('Item'), '#default_value' => $def, '#options' => $period, '#description' => t('The item you want to reserve.'), ); if ($edit) $def = $res["rcomment"]; else $def = ''; $form['comment'] = array( '#type' => 'textfield', '#size' => 50, '#title' => t('Comment'), '#default_value' => $def, '#description' => t('You can add a comment for your reservation.'), ); if ($edit) { $account = user_load(array('uid' => $res["for_uid"])); $def = $account->name; } else $def = ''; $form['reservation_is_for'] = array( '#type' => 'textfield', '#title' => t('This reservation is for'), '#default_value' => $def, // '#autocomplete_path' => 'user/autocomplete', '#size' => '50', '#description' => t('Add a name here if you want to reserve this item for somebody else.'), ); $form['rid'] = array( '#type' => 'hidden', '#value' => $rid, ); if ($edit) { if (($res["for_uid"] == $user->uid || $res["uid"] == $user->uid) && user_access('delete own simple reservations') || user_access('delete simple reservations of others')) $form['delete'] = array('#value' => l("| '. $aktdatum .' | |
| '. $aktdatum .' | |
| '. t('whole day'); } else { // von Beginn $output .= ' | |
| '. (date("H:i", $reservation["begin"])); $output .= ' - '; // bis Ende $output .= date("H:i", $reservation["ending"]); } $output .= " | ". $reservation["name"] .""; $output .= " ". t("booked by") ." ". l($from->name, 'user/'. $from->uid); if ($reservation["for_uid"] != 0) { $foruid = user_load($reservation["for_uid"]); $output .= ' for '. l($foruid->name, 'user/'. $foruid->uid); } if ($reservation["rcomment"] != "") { $output .= " (". $reservation["rcomment"] .")"; } } $output .= ' |