Ejemplo n.º 1
0
 }
 $row = sql_row($res, 0);
 sql_free($res);
 # Note: Removed stripslashes() calls from name and description. Previous
 # versions of MRBS mistakenly had the backslash-escapes in the actual database
 # records because of an extra addslashes going on. Fix your database and
 # leave this code alone, please.
 $name = $row[0];
 $create_by = $row[1];
 $description = $row[2];
 $start_day = strftime('%d', $row[3]);
 $start_month = strftime('%m', $row[3]);
 $start_year = strftime('%Y', $row[3]);
 $start_hour = strftime('%H', $row[3]);
 $start_min = strftime('%M', $row[3]);
 $duration = $row[4] - $row[3] - cross_dst($row[3], $row[4]);
 $type = $row[5];
 $room_id = $row[6];
 $entry_type = $row[7];
 $rep_id = $row[8];
 if ($entry_type >= 1) {
     $sql = "SELECT rep_type, start_time, end_date, rep_opt, rep_num_weeks\n\t\t        FROM {$tbl_repeat} WHERE id={$rep_id}";
     $res = sql_query($sql);
     if (!$res) {
         fatal_error(1, sql_error());
     }
     if (sql_count($res) != 1) {
         fatal_error(1, get_vocab("repeat_id") . $rep_id . get_vocab("not_found"));
     }
     $row = sql_row($res, 0);
     sql_free($res);
Ejemplo n.º 2
0
function report_row(&$rows, &$data)
{
    global $output_format, $ajax, $ajax_capable;
    global $csv_row_sep, $csv_col_sep;
    global $custom_fields, $field_natures, $field_lengths, $tbl_entry;
    global $approval_somewhere, $confirmation_somewhere;
    global $strftime_format;
    global $select_options;
    global $field_order_list;
    // If we're capable of delivering an Ajax request and this is not Ajax request,
    // then don't do anything.  We're going to save sending the data until we actually
    // get the Ajax request;  we just send the rest of the page at this stage.
    if ($output_format == OUTPUT_HTML && $ajax_capable && !$ajax) {
        return;
    }
    $values = array();
    foreach ($field_order_list as $field) {
        $value = $data[$field];
        // Some fields need some special processing to turn the raw value into something
        // more meaningful
        switch ($field) {
            case 'end_time':
                // Calculate the duration and then fall through to calculating the end date
                // Need the duration in seconds for sorting.  Have to correct it for DST
                // changes so that the user sees what he expects to see
                $duration_seconds = $data['end_time'] - $data['start_time'];
                $duration_seconds -= cross_dst($data['start_time'], $data['end_time']);
                $d = get_duration($data['start_time'], $data['end_time'], $data['enable_periods']);
                $d_string = $d['duration'] . ' ' . $d['dur_units'];
                $d_string = escape($d_string);
            case 'start_time':
                $mod_time = $field == 'start_time' ? 0 : -1;
                if ($data['enable_periods']) {
                    list(, $date) = period_date_string($value, $mod_time);
                } else {
                    $date = time_date_string($value);
                }
                $value = $date;
                break;
            case 'type':
                $value = get_type_vocab($value);
                break;
            case 'confirmation_enabled':
                // Translate the status field bit into meaningful text
                if ($data['confirmation_enabled']) {
                    $value = $data['status'] & STATUS_TENTATIVE ? get_vocab("tentative") : get_vocab("confirmed");
                } else {
                    $value = '';
                }
                break;
            case 'approval_enabled':
                // Translate the status field bit into meaningful text
                if ($data['approval_enabled']) {
                    $value = $data['status'] & STATUS_AWAITING_APPROVAL ? get_vocab("awaiting_approval") : get_vocab("approved");
                } else {
                    $value = '';
                }
                break;
            case 'last_updated':
                $value = time_date_string($value);
                break;
            default:
                // Custom fields
                if (array_key_exists($field, $custom_fields)) {
                    // Output a yes/no if it's a boolean or integer <= 2 bytes (which we will
                    // assume are intended to be booleans)
                    if ($field_natures[$field] == 'boolean' || $field_natures[$field] == 'integer' && isset($field_lengths[$field]) && $field_lengths[$field] <= 2) {
                        $value = empty($value) ? get_vocab("no") : get_vocab("yes");
                    } elseif (isset($value)) {
                        // If the custom field is an associative array then we want
                        // the value rather than the array key (provided the key is not
                        // an empty string)
                        if (isset($select_options["entry.{$field}"]) && is_assoc($select_options["entry.{$field}"]) && array_key_exists($value, $select_options["entry.{$field}"]) && $value !== '') {
                            $value = $select_options["entry.{$field}"][$value];
                        }
                    } else {
                        $value = '';
                    }
                }
                break;
        }
        $value = escape($value);
        // For HTML output we take special action for some fields
        if ($output_format == OUTPUT_HTML) {
            switch ($field) {
                case 'name':
                    // Add a link to the entry and also a data-id value for the Bulk Delete JavaScript
                    $value = "<a href=\"view_entry.php?id=" . $data['id'] . "\"" . " data-id=\"" . $data['id'] . "\"" . " title=\"{$value}\">{$value}</a>";
                    break;
                case 'end_time':
                    // Process the duration and then fall through to the end_time
                    // Include the duration in a seconds as a title in an empty span so
                    // that the column can be sorted and filtered properly
                    $d_string = "<span title=\"{$duration_seconds}\"></span>{$d_string}";
                case 'start_time':
                case 'last_updated':
                    // Include the numeric time as a title in an empty span so
                    // that the column can be sorted and filtered properly
                    $value = "<span title=\"{$data[$field]}\"></span>{$value}";
                    break;
                default:
                    break;
            }
        }
        // Add the value to the array.   We don't bother with some fields if
        // they are going to be irrelevant
        if (($confirmation_somewhere || $field != 'confirmation_enabled') && ($approval_somewhere || $field != 'approval_enabled')) {
            $values[] = $value;
        }
        // Special action for the duration
        if ($field == 'end_time') {
            $values[] = $d_string;
        }
    }
    // foreach
    $rows[] = $values;
}
Ejemplo n.º 3
0
if (sql_count($res) < 1) {
    fatal_error(0, $series ? get_vocab("invalid_series_id") : get_vocab("invalid_entry_id"));
}
$row = sql_row_keyed($res, 0);
sql_free($res);
$name = htmlspecialchars($row['name']);
$description = htmlspecialchars($row['description']);
$create_by = htmlspecialchars($row['create_by']);
$room_name = htmlspecialchars($row['room_name']);
$area_name = htmlspecialchars($row['area_name']);
$type = $row['type'];
$room_id = $row['room_id'];
$updated = time_date_string($row['last_updated']);
// need to make DST correct in opposite direction to entry creation
// so that user see what he expects to see
$duration = $row['duration'] - cross_dst($row['start_time'], $row['end_time']);
if ($enable_periods) {
    list($start_period, $start_date) = period_date_string($row['start_time']);
} else {
    $start_date = time_date_string($row['start_time']);
}
if ($enable_periods) {
    list(, $end_date) = period_date_string($row['end_time'], -1);
} else {
    $end_date = time_date_string($row['end_time']);
}
$rep_type = 0;
if ($series == 1) {
    $rep_type = $row['rep_type'];
    $rep_end_date = utf8_strftime('%A %d %B %Y', $row['end_date']);
    $rep_opt = $row['rep_opt'];
Ejemplo n.º 4
0
}
# Acquire mutex to lock out others trying to book the same slot(s).
if (!sql_mutex_lock("{$tbl_entry}")) {
    fatal_error(1, get_vocab("failed_to_acquire"));
}
# Check for any schedule conflicts in each room we're going to try and
# book in
$err = "";
foreach ($rooms as $room_id) {
    if ($rep_type != 0 && !empty($reps)) {
        if (count($reps) < $max_rep_entrys) {
            for ($i = 0; $i < count($reps); $i++) {
                # calculate diff each time and correct where events
                # cross DST
                $diff = $endtime - $starttime;
                $diff += cross_dst($reps[$i], $reps[$i] + $diff);
                $tmp = mrbsCheckFree($room_id, $reps[$i], $reps[$i] + $diff, $ignore_id, $repeat_id);
                if (!empty($tmp)) {
                    $err = $err . $tmp;
                }
            }
        } else {
            $err .= get_vocab("too_may_entrys") . "<P>";
            $hide_title = 1;
        }
    } else {
        $err .= mrbsCheckFree($room_id, $starttime, $endtime - 1, $ignore_id, 0);
    }
}
# end foreach rooms
if (empty($err)) {
Ejemplo n.º 5
0
        if (isset($ampm) && $ampm == "pm" && $hour < 12) {
            $hour += 12;
        }
        if (isset($ampm) && $ampm == "am" && $hour > 11) {
            $hour -= 12;
        }
    }
    $starttime = mktime($hour, $minute, 0, $month, $day, $year, is_dst($month, $day, $year, $hour));
    $endtime = mktime($hour, $minute, 0, $month, $day, $year, is_dst($month, $day, $year, $hour)) + $units * $duration;
    # Round up the duration to the next whole resolution unit.
    # If they asked for 0 minutes, push that up to 1 resolution unit.
    $diff = $endtime - $starttime;
    if (($tmp = $diff % $resolution) != 0 || $diff == 0) {
        $endtime += $resolution - $tmp;
    }
    $endtime += cross_dst($starttime, $endtime);
}
$sql = "SELECT {$tbl_room}.id, {$tbl_room}.room_name, {$tbl_room}.description, {$tbl_room}.capacity, {$tbl_area}.area_name, {$tbl_room}.area_id FROM {$tbl_room} JOIN {$tbl_area} on {$tbl_room}.area_id={$tbl_area}.id WHERE ( SELECT COUNT(*) FROM {$tbl_entry} ";
//old booking fully inside new booking
$sql .= "WHERE (({$tbl_entry}.start_time>={$starttime} AND {$tbl_entry}.end_time<{$endtime}) ";
//new start time within old booking
$sql .= "OR ({$tbl_entry}.start_time<{$starttime} AND {$tbl_entry}.end_time>{$starttime}) ";
//new end time within old booking
$sql .= "OR ({$tbl_entry}.start_time<{$endtime} AND {$tbl_entry}.end_time>={$endtime})) ";
$sql .= "AND mdl_mrbs_entry.room_id = mdl_mrbs_room.id ) < 1  AND {$tbl_room}.capacity >= {$mincap} ";
if ($computer) {
    $sql .= "AND description like 'Teaching IT%' ";
}
if ($teaching) {
    $sql .= "AND description like 'Teaching%' ";
}
Ejemplo n.º 6
0
function map_add_booking($row, &$column, $am7, $pm7)
{
    // Enters the contents of the booking found in $row into $column, which is
    // a column of the map of the bookings being prepared ready for display.
    //
    // $column    the column of the map that is being prepared (see below)
    // $row       a booking from the database
    // $am7       the start of the first slot of the booking day (Unix timestamp)
    // $pm7       the start of the last slot of the booking day (Unix timestamp)
    // $row is expected to have the following field names, when present:
    //       room_id
    //       start_time
    //       end_time
    //       name
    //       repeat_id
    //       entry_id
    //       type
    //       entry_description
    //       entry_create_by
    //       status
    // $column is a column of the map of the screen that will be displayed
    // It looks like:
    //     $column[s][n][id]
    //                  [is_repeat]
    //                  [is_multiday_start]  a boolean indicating if the booking stretches
    //                                       beyond the day start
    //                  [is_multiday_end]    a boolean indicating if the booking stretches
    //                                          beyond the day end
    //                  [color]
    //                  [data]
    //                  [long_descr]
    //                  [create_by]
    //                  [room_id]
    //                  [start_time]
    //                  [slots]
    //                  [status]
    // s is the number of nominal seconds (ie ignoring DST changes] since the
    // start of the calendar day which has the start of the booking day
    // slots records the duration of the booking in number of time slots.
    // Used to calculate how high to make the block used for clipping
    // overflow descriptions.
    // Fill in the map for this meeting. Start at the meeting start time,
    // or the day start time, whichever is later. End one slot before the
    // meeting end time (since the next slot is for meetings which start then),
    // or at the last slot in the day, whichever is earlier.
    // Time is of the format HHMM without leading zeros.
    //
    // [n] exists because it's possible that there may be multiple bookings
    // in the same time slot.   Normally this won't be the case.   However it
    // can arise legitimately if you increase the resolution, or shift the
    // displayed day.   For example if you previously had a resolution of 1800
    // seconds you might have a booking (A) for 1000-1130 and another (B) for 1130-1230.
    // If you then increase the resolution to 3600 seconds, these two bookings
    // will both occupy the 1100-1200 time slot.   [n] starts at 0.   For
    // the example above the map for the room would look like this
    //
    //       0  1
    // 1000  A
    // 1100  A  B
    // 1200  B
    //
    // Adjust the starting and ending times so that bookings which don't
    // start or end at a recognized time still appear.
    global $resolution;
    global $is_private_field;
    //$user = getUserName();
    /*if (is_private_event($row['status'] & STATUS_PRIVATE) &&
          !getWritable($row['entry_create_by'], $user, $row['room_id']))
      {
          $row['status'] |= STATUS_PRIVATE;   // Set the private bit
          if ($is_private_field['entry.name'])
          {
              $row['name']= "[".get_vocab('unavailable')."]";
          }
          if ($is_private_field['entry.description'])
          {
              $row['entry_description']= "[".get_vocab('unavailable')."]";
          }
      }
      else
      {
          $row['status'] &= ~STATUS_PRIVATE;  // Clear the private bit
      }*/
    $is_multiday_start = $row['start_time'] < $am7;
    $is_multiday_end = $row['end_time'] > $pm7 + $resolution;
    $start_t = max(round_t_down($row['start_time'], $resolution, $am7), $am7);
    $end_t = min(round_t_up($row['end_time'], $resolution, $am7) - $resolution, $pm7);
    // calculate the times used for indexing - we index by nominal seconds since the start
    // of the calendar day which has the start of the booking day
    $start_s = nominal_seconds($start_t);
    $end_s = nominal_seconds($end_t);
    for ($s = $start_s; $s <= $end_s; $s += $resolution) {
        // find the first free index (in case there are multiple bookings in a timeslot)
        $n = 0;
        while (!empty($column[$s][$n]["id"])) {
            $n++;
        }
        // fill in the id, type and start time
        $column[$s][$n]["id"] = $row['entry_id'];
        $column[$s][$n]["is_repeat"] = isset($row['repeat_id']);
        $column[$s][$n]["is_multiday_start"] = $is_multiday_start;
        $column[$s][$n]["is_multiday_end"] = $is_multiday_end;
        $column[$s][$n]["status"] = $row['status'];
        $column[$s][$n]["color"] = $row['type'];
        $column[$s][$n]["start_time"] = hour_min($start_s);
        $column[$s][$n]["slots"] = NULL;
        // to avoid undefined index NOTICE errors
        // if it's a multiple booking also fill in the name and description
        if ($n > 0) {
            $column[$s][$n]["data"] = $row['type'];
            //$column[$s][$n]["long_descr"] = $row['entry_description'];
            //$column[$s][$n]["create_by"] = $row['entry_create_by'];
            //$column[$s][$n]["room_id"] = $row['room_id'];
        } else {
            $column[$s][$n]["data"] = NULL;
            $column[$s][$n]["long_descr"] = NULL;
            $column[$s][$n]["create_by"] = NULL;
            $column[$s][$n]["room_id"] = NULL;
        }
    }
    // end for
    // Show the name of the booker, the description and the number of complete
    // slots in the first complete slot that the booking happens in, or at the
    // start of the day if it started before today.
    // Find the number of time slots that the booking occupies, and the index
    // of the first slot that this booking has entirely to itself
    // We need to adjust the start and end times for DST transitions as the display
    // ignores DST
    $n_slots = intval(($end_t - $start_t - cross_dst($start_t, $end_t)) / $resolution) + 1;
    $first_slot = $start_s;
    // If the last time slot is already occupied, we have a multiple
    // booking in the last slot, so decrement the number of slots that
    // we will display for this booking
    if (isset($column[$end_s][1]["id"])) {
        $n_slots--;
        // If we're only the second booking to land on this time slot
        // then we'll have to adjust the information held for the first booking
        // (unless it's just one slot long in the first place, when it
        // doesn't matter as it will now be part of a multiple booking).
        // If we are the third booking or more, then it will have already
        // been adjusted.
        if (!isset($column[$end_s][2]["id"])) {
            if ($column[$end_s][0]["slots"] > 1) {
                // Move the name and description into the new first slot and decrement the number of slots
                $column[$end_s + $resolution][0]["data"] = $column[$end_s][0]["data"];
                //$column[$end_s + $resolution][0]["long_descr"] = $column[$end_s][0]["long_descr"];
                //$column[$end_s + $resolution][0]["create_by"]  = $column[$end_s][0]["create_by"];
                //$column[$end_s + $resolution][0]["room_id"]    = $column[$end_s][0]["room_id"];
                $column[$end_s + $resolution][0]["slots"] = $column[$end_s][0]["slots"] - 1;
            }
        }
    }
    // and if the first time slot is already occupied, decrement
    // again, adjust the first slot for this booking
    if (isset($column[$start_s][1]["id"])) {
        $n_slots--;
        $first_slot += $resolution;
        // If we're only the second booking to land on this time slot
        // then we'll have to adjust the information held for the first booking
        if (!isset($column[$start_s][2]["id"])) {
            // Find the first slot ($s) of the first booking
            $first_booking_id = $column[$start_s][0]["id"];
            $r = $start_s;
            // If you've got to the first slot of the day then that must be the
            // first slot of the first booking
            while ($r > $am7) {
                // Otherwise, step back one slot.
                $r -= $resolution;
                // If that slot contains the first booking, then step back again
                if (isset($column[$r])) {
                    foreach ($column[$r] as $booking) {
                        if ($booking["id"] == $first_booking_id) {
                            continue 2;
                            // next iteration of the while loop
                        }
                    }
                }
                // If not, then we've stepped back one slot past the start of
                // the first booking, so step forward again and finish
                $r += $resolution;
                break;
            }
            // end while
            // Now we've found the time ($r) of the first slot of the first booking
            // we need to find its index ($i)
            foreach ($column[$r] as $i => $booking) {
                if ($booking["id"] == $first_booking_id) {
                    break;
                }
            }
            // Finally decrement the slot count for the first booking
            // no need to worry about count going < 1: the multiple booking display
            // does not use the slot count.
            $column[$r][$i]["slots"]--;
            // and put the name and description in the multiply booked slot
            $column[$start_s][0]["data"] = $column[$r][$i]["data"];
            //$column[$start_s][0]["long_descr"] = $column[$r][$i]["long_descr"];
            //$column[$start_s][0]["create_by"]  = $column[$r][$i]["create_by"];
            //$column[$start_s][0]["room_id"]    = $column[$r][$i]["room_id"];
        }
    }
    // now we've got all the information we can enter it in the first complete
    // slot for the booking (provided it's not a multiple booking slot)
    if (!isset($column[$first_slot][1]["id"])) {
        $column[$first_slot][0]["data"] = $row['type'];
        //$column[$first_slot][0]["long_descr"] = $row['entry_description'];
        //$column[$first_slot][0]["create_by"]  = $row['entry_create_by'];
        //$column[$first_slot][0]["room_id"]    = $row['room_id'];
        $column[$first_slot][0]["slots"] = $n_slots;
    }
}
Ejemplo n.º 7
0
         $hour = 0;
         $minute = 0;
     }
 } else {
     if (!isset($hour) || !isset($minute)) {
         $hour = $morningstarts;
         $minute = $morningstarts_minutes;
     }
 }
 $start_time = mktime($hour, $minute, 0, $month, $day, $year);
 if (isset($end_seconds)) {
     $end_minutes = intval($end_seconds / 60);
     $end_hour = intval($end_minutes / 60);
     $end_minute = $end_minutes % 60;
     $end_time = mktime($end_hour, $end_minute, 0, $month, $day, $year);
     $duration = $end_time - $start_time - cross_dst($start_time, $end_time);
 } else {
     if (!isset($default_duration)) {
         $default_duration = SECONDS_PER_HOUR;
     }
     $duration = $enable_periods ? 60 : $default_duration;
     $end_time = $start_time + $duration;
     // The end time can't be past the end of the booking day
     $pm7 = get_start_last_slot($month, $day, $year);
     $end_time = min($end_time, $pm7 + $resolution);
 }
 $rep_id = 0;
 if (!isset($rep_type)) {
     $rep_type = REP_NONE;
     $rep_end_day = $day;
     $rep_end_month = $month;
Ejemplo n.º 8
0
    // a series.  ["The "DTSTART" property for a "VEVENT" specifies the inclusive
    // start of the event.  For recurring events, it also specifies the very first
    // instance in the recurrence set."]
    $rep_details = array('rep_type' => $rep_type, 'rep_opt' => $rep_opt, 'rep_num_weeks' => $rep_num_weeks);
    if (isset($month_type)) {
        if ($month_type == REP_MONTH_ABSOLUTE) {
            $rep_details['month_absolute'] = $month_absolute;
        } else {
            $rep_details['month_relative'] = $month_relative;
        }
    }
    // Get the first entry in the series and make that the start time
    $reps = mrbsGetRepeatEntryList($starttime, $end_date, $rep_details, 1);
    if (count($reps) > 0) {
        $duration = $endtime - $starttime;
        $duration -= cross_dst($starttime, $endtime);
        $starttime = $reps[0];
        $endtime = $starttime + $duration;
        $start_day = date('j', $starttime);
        $start_month = date('n', $starttime);
        $start_year = date('Y', $starttime);
    }
}
if (!$ajax || !$commit) {
    // Get the start day/month/year and make them the current day/month/year
    $day = $start_day;
    $month = $start_month;
    $year = $start_year;
}
// Set up the return URL.    As the user has tried to book a particular room and a particular
// day, we must consider these to be the new "sticky room" and "sticky day", so modify the
Ejemplo n.º 9
0
}
# Note: Removed stripslashes() calls from name and description. Previous
# versions of MRBS mistakenly had the backslash-escapes in the actual database
# records because of an extra addslashes going on. Fix your database and
# leave this code alone, please.
$name = htmlspecialchars($row[0]);
$description = htmlspecialchars($row[1]);
$create_by = htmlspecialchars($row[2]);
$room_name = htmlspecialchars($row[3]);
$area_name = htmlspecialchars($row[4]);
$type = $row[5];
$room_id = $row[6];
$updated = time_date_string(MDB_Date::mdbstamp2Unix($row[7]));
# need to make DST correct in opposite direction to entry creation
# so that user see what he expects to see
$duration = $row[8] - cross_dst($row[9], $row[10]);
if ($enable_periods) {
    list($start_period, $start_date) = period_date_string($row[9]);
} else {
    $start_date = time_date_string($row[9]);
}
if ($enable_periods) {
    list(, $end_date) = period_date_string($row[10], -1);
} else {
    $end_date = time_date_string($row[10]);
}
$rep_type = 0;
if ($series == 1) {
    $rep_type = $row[11];
    $rep_end_date = utf8_strftime('%A %d %B %Y', $row[12]);
    $rep_opt = $row[13];
Ejemplo n.º 10
0
# Note: Removed stripslashes() calls from name and description. Previous
# versions of MRBS mistakenly had the backslash-escapes in the actual database
# records because of an extra addslashes going on. Fix your database and
# leave this code alone, please.
$name = htmlspecialchars($row[0]);
$description = htmlspecialchars($row[1]);
$create_by = htmlspecialchars($row[2]);
$room_name = htmlspecialchars($row[3]);
$area_name = htmlspecialchars($row[4]);
$type = $row[5];
$room_id = $row[6];
$repeat_id = $row[7];
$updated = time_date_string($row[8]);
# need to make DST correct in opposite direction to entry creation
# so that user see what he expects to see
$duration = $row[9] - cross_dst($row[10], $row[11]);
if ($enable_periods) {
    list($start_period, $start_date) = period_date_string($row[10]);
} else {
    $start_date = time_date_string($row[10]);
}
if ($enable_periods) {
    list(, $end_date) = period_date_string($row[11], -1);
} else {
    $end_date = time_date_string($row[11]);
}
$rep_type = 0;
if ($repeat_id != 0) {
    $res = sql_query("SELECT rep_type, end_date, rep_opt, rep_num_weeks\n\t                    FROM {$tbl_repeat} WHERE id={$repeat_id}");
    if (!$res) {
        fatal_error(0, sql_error());
Ejemplo n.º 11
0
/** mrbsCreateRepeatingEntrys()
 * 
 * Creates a repeat entry in the data base + all the repeating entrys
 * 
 * $starttime   - Start time of entry
 * $endtime     - End time of entry
 * $rep_type    - The repeat type
 * $rep_enddate - When the repeating ends
 * $rep_opt     - Any options associated with the entry
 * $room_id     - Room ID
 * $owner       - Owner
 * $name        - Name
 * $type        - Type (Internal/External)
 * $description - Description
 * 
 * Returns:
 *   0        - An error occured while inserting the entry
 *   non-zero - The entry's ID
 */
function mrbsCreateRepeatingEntrys($starttime, $endtime, $rep_type, $rep_enddate, $rep_opt, $room_id, $owner, $name, $type, $description, $rep_num_weeks)
{
    global $max_rep_entrys;
    $reps = mrbsGetRepeatEntryList($starttime, $rep_enddate, $rep_type, $rep_opt, $max_rep_entrys, $rep_num_weeks);
    if (count($reps) > $max_rep_entrys) {
        return 0;
    }
    if (empty($reps)) {
        $ent = mrbsCreateSingleEntry($starttime, $endtime, 0, 0, $room_id, $owner, $name, $type, $description);
        return $ent;
    }
    $ent = mrbsCreateRepeatEntry($starttime, $endtime, $rep_type, $rep_enddate, $rep_opt, $room_id, $owner, $name, $type, $description, $rep_num_weeks);
    if ($ent) {
        for ($i = 0; $i < count($reps); $i++) {
            # calculate diff each time and correct where events
            # cross DST
            $diff = $endtime - $starttime;
            $diff += cross_dst($reps[$i], $reps[$i] + $diff);
            mrbsCreateSingleEntry($reps[$i], $reps[$i] + $diff, 1, $ent, $room_id, $owner, $name, $type, $description);
        }
    }
    return $ent;
}
Ejemplo n.º 12
0
/**
 * Gather all fields values for an entry. Used for emails to get previous
 * entry state.
 *
 * @param int     $id       entry id to get data
 * @param int     $series   1 if this is a serie or 0
 * @return bool             TRUE or PEAR error object if fails
 */
function getPreviousEntryData($id, $series)
{
    global $tbl_area, $tbl_entry, $tbl_repeat, $tbl_room, $enable_periods;
    //
    $sql = "\n    SELECT  e.name,\n            e.description,\n            e.create_by,\n            r.room_name,\n            a.area_name,\n            e.type,\n            e.room_id,\n            e.repeat_id,\n            e.timestamp,\n            (e.end_time - e.start_time) AS tbl_e_duration,\n            e.start_time AS tbl_e_start_time,\n            e.end_time AS tbl_e_end_time,\n            a.area_admin_email,\n            r.room_admin_email";
    // Here we could just use $tbl_repeat.start_time, and not use alias,
    // as the last column will take precedence using mysql_fetch_array,
    // but for portability purpose I will not use it.
    if (1 == $series) {
        $sql .= ", re.rep_type, re.rep_opt, re.rep_num_weeks,\n            (re.end_time - re.start_time) AS tbl_r_duration,\n            re.start_time AS tbl_r_start_time,\n            re.end_time AS tbl_r_end_time,\n            re.end_date AS tbl_r_end_date";
    }
    $sql .= "\n    FROM {$tbl_entry} e, {$tbl_room} r, {$tbl_area} a ";
    1 == $series ? $sql .= ', ' . $tbl_repeat . ' re ' : '';
    $sql .= "\n    WHERE e.room_id = r.id\n    AND r.area_id = a.id\n    AND e.id={$id}";
    1 == $series ? $sql .= " AND e.repeat_id = re.id" : '';
    //
    $res = sql_query($sql);
    !$res ? fatal_error(0, sql_error()) : '';
    sql_count($res) < 1 ? fatal_error(0, get_string('invalid_entry_id', 'block_mrbs')) : '';
    $row = sql_row_keyed($res, 0);
    sql_free($res);
    // Store all needed values in $mail_previous array to pass to
    // notifyAdminOnDelete function (shorter than individual variables -:) )
    $mail_previous['namebooker'] = $row['name'];
    $mail_previous['description'] = $row['description'];
    $mail_previous['createdby'] = $row['create_by'];
    $mail_previous['room_name'] = $row['room_name'];
    $mail_previous['area_name'] = $row['area_name'];
    $mail_previous['type'] = $row['type'];
    $mail_previous['room_id'] = $row['room_id'];
    $mail_previous['repeat_id'] = $row['repeat_id'];
    $mail_previous['updated'] = getMailTimeDateString($row[8]);
    $mail_previous['area_admin_email'] = $row['area_admin_email'];
    $mail_previous['room_admin_email'] = $row['room_admin_email'];
    // If we use periods
    if ($enable_periods) {
        // If we delete a serie, start_time and end_time must
        // come from $tbl_repeat, not $tbl_entry.
        //
        // This is not a serie
        if (1 != $series) {
            list($mail_previous['start_period'], $mail_previous['start_date']) = getMailPeriodDateString($row['tbl_e_start_time']);
            list($mail_previous['end_period'], $mail_previous['end_date']) = getMailPeriodDateString($row['tbl_e_end_time'], -1);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_e_duration'] - cross_dst($row['tbl_e_start_time'], $row['tbl_e_end_time']);
        } else {
            list($mail_previous['start_period'], $mail_previous['start_date']) = getMailPeriodDateString($row['tbl_r_start_time']);
            list($mail_previous['end_period'], $mail_previous['end_date']) = getMailPeriodDateString($row['tbl_r_end_time'], 0);
            // use getMailTimeDateString as all I want is the date
            $mail_previous['rep_end_date'] = getMailTimeDateString($row['tbl_r_end_date'], FALSE);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_r_duration'] - cross_dst($row['tbl_r_start_time'], $row['tbl_r_end_time']);
            $mail_previous['rep_opt'] = "";
            switch ($row['rep_type']) {
                case 2:
                case 6:
                    $rep_day[0] = $row['rep_opt'][0] != "0";
                    $rep_day[1] = $row['rep_opt'][1] != "0";
                    $rep_day[2] = $row['rep_opt'][2] != "0";
                    $rep_day[3] = $row['rep_opt'][3] != "0";
                    $rep_day[4] = $row['rep_opt'][4] != "0";
                    $rep_day[5] = $row['rep_opt'][5] != "0";
                    $rep_day[6] = $row['rep_opt'][6] != "0";
                    if ($row['rep_type'] == 6) {
                        $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
                    } else {
                        $mail_previous['rep_num_weeks'] = "";
                    }
                    break;
                default:
                    $rep_day = array(0, 0, 0, 0, 0, 0, 0);
            }
            for ($i = 0; $i < 7; $i++) {
                $wday = ($i + $weekstarts) % 7;
                if ($rep_day[$wday]) {
                    $mail_previous['rep_opt'] .= day_name($wday) . " ";
                }
            }
            $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
        }
        toPeriodString($mail_previous['start_period'], $mail_previous['duration'], $mail_previous['dur_units']);
    } else {
        // This is not a serie
        if (1 != $series) {
            $mail_previous['start_date'] = getMailTimeDateString($row['tbl_e_start_time']);
            $mail_previous['end_date'] = getMailTimeDateString($row['tbl_e_end_time']);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_e_duration'] - cross_dst($row['tbl_e_start_time'], $row['tbl_e_end_time']);
        } else {
            $mail_previous['start_date'] = getMailTimeDateString($row['tbl_r_start_time']);
            $mail_previous['end_date'] = getMailTimeDateString($row['tbl_r_end_time']);
            // use getMailTimeDateString as all I want is the date
            $mail_previous['rep_end_date'] = getMailTimeDateString($row['tbl_r_end_date'], FALSE);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_r_duration'] - cross_dst($row['tbl_r_start_time'], $row['tbl_r_end_time']);
            $mail_previous['rep_opt'] = "";
            switch ($row['rep_type']) {
                case 2:
                case 6:
                    $rep_day[0] = $row['rep_opt'][0] != "0";
                    $rep_day[1] = $row['rep_opt'][1] != "0";
                    $rep_day[2] = $row['rep_opt'][2] != "0";
                    $rep_day[3] = $row['rep_opt'][3] != "0";
                    $rep_day[4] = $row['rep_opt'][4] != "0";
                    $rep_day[5] = $row['rep_opt'][5] != "0";
                    $rep_day[6] = $row['rep_opt'][6] != "0";
                    if ($row['rep_type'] == 6) {
                        $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
                    } else {
                        $mail_previous['rep_num_weeks'] = "";
                    }
                    break;
                default:
                    $rep_day = array(0, 0, 0, 0, 0, 0, 0);
            }
            for ($i = 0; $i < 7; $i++) {
                $wday = ($i + $weekstarts) % 7;
                if ($rep_day[$wday]) {
                    $mail_previous['rep_opt'] .= day_name($wday) . " ";
                }
            }
            $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
        }
        toTimeString($mail_previous['duration'], $mail_previous['dur_units']);
    }
    1 == $series ? $mail_previous['rep_type'] = $row['rep_type'] : ($mail_previous['rep_type'] = 0);
    // return entry previous data as an array
    return $mail_previous;
}
Ejemplo n.º 13
0
    // a series.  ["The "DTSTART" property for a "VEVENT" specifies the inclusive
    // start of the event.  For recurring events, it also specifies the very first
    // instance in the recurrence set."]
    $rep_details = array('rep_type' => $rep_type, 'rep_opt' => $rep_opt, 'rep_num_weeks' => $rep_num_weeks);
    if (isset($month_type)) {
        if ($month_type == REP_MONTH_ABSOLUTE) {
            $rep_details['month_absolute'] = $month_absolute;
        } else {
            $rep_details['month_relative'] = $month_relative;
        }
    }
    // Get the first entry in the series and make that the start time
    $reps = mrbsGetRepeatEntryList($start_time, $end_date, $rep_details, 1);
    if (count($reps) > 0) {
        $duration = $end_time - $start_time;
        $duration -= cross_dst($start_time, $end_time);
        $start_time = $reps[0];
        $end_time = $start_time + $duration;
        $start_day = date('j', $start_time);
        $start_month = date('n', $start_time);
        $start_year = date('Y', $start_time);
    }
}
if (!$ajax || !$commit) {
    // Get the start day/month/year and make them the current day/month/year
    $day = $start_day;
    $month = $start_month;
    $year = $start_year;
}
// Set up the return URL.    As the user has tried to book a particular room and a particular
// day, we must consider these to be the new "sticky room" and "sticky day", so modify the