Revision: 1453
http://mrbs.svn.sourceforge.net/mrbs/?rev=1453&view=rev
Author: cimorrison
Date: 2010-09-15 15:17:08 +0000 (Wed, 15 Sep 2010)
Log Message:
-----------
Simplified code (put the data for an entry into an array). No functionality
change.
Modified Paths:
--------------
mrbs/branches/provisional_bookings_new_style/web/approve_entry_handler.php
mrbs/branches/provisional_bookings_new_style/web/edit_entry_handler.php
mrbs/branches/provisional_bookings_new_style/web/functions_mail.inc
mrbs/branches/provisional_bookings_new_style/web/mrbs_sql.inc
Modified:
mrbs/branches/provisional_bookings_new_style/web/approve_entry_handler.php
===================================================================
--- mrbs/branches/provisional_bookings_new_style/web/approve_entry_handler.php
2010-09-15 09:13:17 UTC (rev 1452)
+++ mrbs/branches/provisional_bookings_new_style/web/approve_entry_handler.php
2010-09-15 15:17:08 UTC (rev 1453)
@@ -85,49 +85,34 @@
if ($result && $need_to_send_mail)
{
// Retrieve the booking details which we will need for the email
- // (notifyAdminOnBooking relies on them being available as globals)
-
- $row = mrbsGetBookingInfo($id, $series);
+ $data = mrbsGetBookingInfo($id, $series);
- $name = $row['name'];
- $description = $row['description'];
- $create_by = $row['create_by'];
- $type = $row['type'];
- $status = $row['status'];
- $starttime = $row['start_time'];
- $endtime = $row['end_time'];
- $room_name = $row['room_name'];
- $room_id = $row['room_id'];
- $area_name = $row['area_name'];
- $duration = ($row['end_time'] - $row['start_time']) -
cross_dst($row['start_time'], $row['end_time']);
- $rep_type = $row['rep_type'];
- $repeat_id = isset($row['repeat_id']) ? $row['repeat_id'] :
NULL;
- $rep_enddate = isset($row['rep_enddate']) ? $row['rep_enddate'] :
NULL;
- $rep_opt = isset($row['rep_opt']) ? $row['rep_opt'] :
NULL;
- $rep_num_weeks = isset($row['rep_num_weeks']) ? $row['rep_num_weeks'] :
NULL;
+ // Process some special fields
+ $data['duration'] = ($data['end_time'] - $data['start_time']) -
cross_dst($data['start_time'], $data['end_time']);
+ $data['end_date'] = isset($data['rep_enddate']) ? $data['rep_enddate']
: NULL;
if ($enable_periods)
{
- list($start_period, $start_date) =
period_date_string($row['start_time']);
+ list($start_period, $start_date) =
period_date_string($data['start_time']);
}
else
{
- $start_date = time_date_string($row['start_time']);
+ $start_date = time_date_string($data['start_time']);
}
if ($enable_periods)
{
- list( , $end_date) = period_date_string($row['end_time'], -1);
+ list( , $end_date) = period_date_string($data['end_time'], -1);
}
else
{
- $end_date = time_date_string($row['end_time']);
+ $end_date = time_date_string($data['end_time']);
}
// The optional last parameters below are set to FALSE because we don't
want the units
// translated - otherwise they will end up getting translated twice,
resulting
// in an undefined index error.
- $enable_periods ? toPeriodString($start_period, $duration, $dur_units,
FALSE) : toTimeString($duration, $dur_units, FALSE);
+ $enable_periods ? toPeriodString($start_period, $data['duration'],
$data['dur_units'], FALSE) : toTimeString($data['duration'],
$data['dur_units'], FALSE);
$result = notifyAdminOnBooking($is_new_entry, $id, $series, $action);
}
Modified:
mrbs/branches/provisional_bookings_new_style/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/provisional_bookings_new_style/web/edit_entry_handler.php
2010-09-15 09:13:17 UTC (rev 1452)
+++ mrbs/branches/provisional_bookings_new_style/web/edit_entry_handler.php
2010-09-15 15:17:08 UTC (rev 1453)
@@ -476,11 +476,10 @@
} // end foreach rooms
-
// If the rooms were free, go ahead an process the bookings
if ($valid_booking)
{
- foreach ( $rooms as $room_id )
+ foreach ($rooms as $room_id)
{
// Set the various bits in the status field as appropriate
$status = 0;
@@ -503,42 +502,45 @@
{
$status |= STATUS_TENTATIVE;
}
-
+
+ // Assemble the data in an array
+ $data = array();
+ $data['start_time'] = $starttime;
+ $data['end_time'] = $endtime;
+ $data['room_id'] = $room_id;
+ $data['create_by'] = $create_by;
+ $data['name'] = $name;
+ $data['type'] = $type;
+ $data['description'] = $description;
+ $data['status'] = $status;
+ $data['custom_fields'] = $custom_fields;
if ($edit_type == "series")
{
- $booking = mrbsCreateRepeatingEntrys($starttime,
- $endtime,
- $rep_type,
- $rep_enddate,
- $rep_opt,
- $room_id,
- $create_by,
- $name,
- $type,
- $description,
- isset($rep_num_weeks) ?
$rep_num_weeks : 0,
- $status,
- $custom_fields);
+ $data['rep_type'] = $rep_type;
+ $data['end_date'] = $rep_enddate;
+ $data['rep_opt'] = $rep_opt;
+ $data['rep_num_weeks'] = (isset($rep_num_weeks)) ? $rep_num_weeks : 0;
+ }
+ else
+ {
+ // Mark changed entry in a series with entry_type 2:
+ $data['entry_type'] = ($repeat_id > 0) ? 2 : 0;
+ $data['repeat_id'] = $repeat_id;
+ }
+ // The following elements are needed for email notifications
+ $data['duration'] = $duration;
+ $data['dur_units'] = $dur_units;
+
+ if ($edit_type == "series")
+ {
+ $booking = mrbsCreateRepeatingEntrys($data);
$new_id = $booking['id'];
$is_repeat_table = $booking['series'];
}
else
{
- // Mark changed entry in a series with entry_type 2:
- $entry_type = ($repeat_id > 0) ? 2 : 0;
-
// Create the entry:
- $new_id = mrbsCreateSingleEntry($starttime,
- $endtime,
- $entry_type,
- $repeat_id,
- $room_id,
- $create_by,
- $name,
- $type,
- $description,
- $status,
- $custom_fields);
+ $new_id = mrbsCreateSingleEntry($data);
$is_repeat_table = FALSE;
}
@@ -552,9 +554,9 @@
(0 != $new_id) )
{
require_once "functions_mail.inc";
- // Get room name and area name. Would be better to avoid
- // a database access just for that. Ran only if we need
- // details
+ // Get room name and area name for email notifications.
+ // Would be better to avoid a database access just for that.
+ // Ran only if we need details
if ($mail_settings['details'])
{
$sql = "SELECT R.room_name, A.area_name
@@ -563,8 +565,8 @@
LIMIT 1";
$res = sql_query($sql);
$row = sql_row_keyed($res, 0);
- $room_name = $row['room_name'];
- $area_name = $row['area_name'];
+ $data['room_name'] = $row['room_name'];
+ $data['area_name'] = $row['area_name'];
}
// If this is a modified entry then call
// getPreviousEntryData to prepare entry comparison.
Modified: mrbs/branches/provisional_bookings_new_style/web/functions_mail.inc
===================================================================
--- mrbs/branches/provisional_bookings_new_style/web/functions_mail.inc
2010-09-15 09:13:17 UTC (rev 1452)
+++ mrbs/branches/provisional_bookings_new_style/web/functions_mail.inc
2010-09-15 15:17:08 UTC (rev 1453)
@@ -282,12 +282,10 @@
*/
function notifyAdminOnBooking($new_entry, $new_id, $series, $action="book")
{
- global $url_base, $returl, $name, $description, $area_name;
- global $room_name, $room_id, $starttime, $duration, $dur_units, $end_date,
$endtime;
- global $rep_enddate, $typel, $type, $status, $create_by, $rep_type,
$enable_periods;
- global $rep_opt, $rep_num_weeks, $custom_fields, $standard_fields;
- global $mail_previous, $auth, $note;
- global $mail_settings, $weekstarts, $approval_enabled, $confirmation_enabled;
+ global $data, $mail_previous, $note;
+ global $url_base, $returl;
+ global $auth, $weekstarts, $typel, $mail_settings, $standard_fields;
+ global $enable_periods, $approval_enabled, $confirmation_enabled;
global $tbl_entry;
$recipients = array();
@@ -312,9 +310,9 @@
// if we're requiring bookings to be approved and this user needs approval
// for this room, then get the email addresses of the approvers
- if ($approval_enabled && !auth_book_admin($user, $room_id))
+ if ($approval_enabled && !auth_book_admin($user, $data['room_id']))
{
- $recipients[] = get_approvers_email($room_id);
+ $recipients[] = get_approvers_email($data['room_id']);
}
($mail_settings['admin_on_bookings']) ? $recipients[] =
$mail_settings['recipients'] : '';
@@ -324,7 +322,7 @@
// Look for list of area admins emails addresses
if ($new_entry)
{
- $email = get_area_admin_email($new_id, ($rep_type != REP_NONE));
+ $email = get_area_admin_email($new_id, ($data['rep_type'] != REP_NONE));
if (!empty($email))
{
$recipients[] = $email;
@@ -343,7 +341,7 @@
// Look for list of room admins email addresses
if ($new_entry)
{
- $email = get_room_admin_email($new_id, ($rep_type != REP_NONE));
+ $email = get_room_admin_email($new_id, ($data['rep_type'] != REP_NONE));
if (!empty($email))
{
$recipients[] = $email;
@@ -366,7 +364,7 @@
$cc = array_merge($cc, $recipients);
$recipients = array();
}
- $booker = ($new_entry) ? $create_by : $mail_previous['createdby'];
+ $booker = ($new_entry) ? $data['create_by'] : $mail_previous['createdby'];
$booker_email = get_email_address($booker);
if (!empty($booker_email))
{
@@ -430,13 +428,13 @@
if ($mail_settings['details'])
{
$body .= "\n" . get_mail_vocab("namebooker") . ": ";
- $body .= compareEntries(convertToMailCharset($name),
+ $body .= compareEntries(convertToMailCharset($data['name']),
convertToMailCharset($mail_previous['namebooker']),
$new_entry) . "\n";
// Description:
$body .= get_mail_vocab("description") . ": ";
- $body .= compareEntries(convertToMailCharset($description),
+ $body .= compareEntries(convertToMailCharset($data['description']),
convertToMailCharset($mail_previous['description']),
$new_entry) . "\n";
@@ -445,7 +443,7 @@
// Confirmation status:
$body .= get_mail_vocab("confirmation_status") . ": ";
$old_status = ($mail_previous['status'] & STATUS_TENTATIVE) ?
get_mail_vocab("tentative") : get_mail_vocab("confirmed");
- $new_status = ($status & STATUS_TENTATIVE) ? get_mail_vocab("tentative")
: get_mail_vocab("confirmed");
+ $new_status = ($data['status'] & STATUS_TENTATIVE) ?
get_mail_vocab("tentative") : get_mail_vocab("confirmed");
$body .= compareEntries($new_status, $old_status, $new_entry) . "\n";
}
@@ -454,16 +452,16 @@
// Approval status:
$body .= get_mail_vocab("approval_status") . ": ";
$old_status = ($mail_previous['status'] & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
- $new_status = ($status & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
+ $new_status = ($data['status'] & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
$body .= compareEntries($new_status, $old_status, $new_entry) . "\n";
}
// Room:
$body .= get_mail_vocab("room") . ": " .
- compareEntries(convertToMailCharset($area_name),
+ compareEntries(convertToMailCharset($data['area_name']),
convertToMailCharset($mail_previous['area_name']),
$new_entry);
- $body .= " - " . compareEntries(convertToMailCharset($room_name),
+ $body .= " - " . compareEntries(convertToMailCharset($data['room_name']),
convertToMailCharset($mail_previous['room_name']),
$new_entry) . "\n";
@@ -471,7 +469,7 @@
if ( $enable_periods )
{
list( $start_period, $start_date) =
- getMailPeriodDateString($starttime);
+ getMailPeriodDateString($data['start_time']);
$body .= get_mail_vocab("start_date") . ": ";
$body .= compareEntries($start_date,
$mail_previous['start_date'],
@@ -479,7 +477,7 @@
}
else
{
- $start_date = getMailTimeDateString($starttime);
+ $start_date = getMailTimeDateString($data['start_time']);
$body .= get_mail_vocab("start_date") . ": " .
compareEntries($start_date,
$mail_previous['start_date'],
@@ -488,17 +486,17 @@
// Duration
$body .= get_mail_vocab("duration") . ": " .
- compareEntries($duration,
+ compareEntries($data['duration'],
$mail_previous['duration'],
$new_entry);
- $body .= " " . compareEntries(get_mail_vocab("$dur_units"),
+ $body .= " " . compareEntries(get_mail_vocab($data['dur_units']),
$mail_previous['dur_units'],
$new_entry) . "\n";
// End time
if ( $enable_periods )
{
- $myendtime = $endtime;
+ $myendtime = $data['end_time'];
$mod_time = -1;
list($end_period, $end_date) = getMailPeriodDateString($myendtime,
$mod_time);
@@ -509,7 +507,7 @@
}
else
{
- $myendtime = $endtime;
+ $myendtime = $data['end_time'];
$end_date = getMailTimeDateString($myendtime);
$body .= get_mail_vocab("end_date") . ": " .
compareEntries($end_date,
@@ -521,19 +519,19 @@
$body .= get_mail_vocab("type") . ": ";
if ($new_entry)
{
- $body .= $typel[$type];
+ $body .= $typel[$data['type']];
}
else
{
$temp = $mail_previous['type'];
- $body .= compareEntries($typel[$type],
+ $body .= compareEntries($typel[$data['type']],
$typel[$temp],
$new_entry);
}
// Created by
$body .= "\n" . get_mail_vocab("createdby") . ": " .
- compareEntries($create_by,
+ compareEntries($data['create_by'],
$mail_previous['createdby'],
$new_entry) . "\n";
@@ -544,7 +542,7 @@
if (!in_array($field['name'], $standard_fields['entry']))
{
$key = $field['name'];
- $value = (isset($custom_fields[$key])) ? $custom_fields[$key] : '';
+ $value = (isset($data['custom_fields'][$key])) ?
$data['custom_fields'][$key] : '';
// Convert any booleans or pseudo-booleans to text strings (in the
mail language)
if (($field['nature'] == 'boolean') ||
(($field['nature'] == 'integer') && isset($field['length']) &&
($field['length'] <= 2)) )
@@ -570,36 +568,36 @@
$body .= "\n" . get_mail_vocab("rep_type");
if ($new_entry)
{
- $body .= ": " . get_mail_vocab("rep_type_$rep_type");
+ $body .= ": " . get_mail_vocab("rep_type_" . $data['rep_type']);
}
else
{
$temp = $mail_previous['rep_type'];
- $body .= ": " . compareEntries(get_mail_vocab("rep_type_$rep_type"),
+ $body .= ": " . compareEntries(get_mail_vocab("rep_type_" .
$data['rep_type']),
get_mail_vocab("rep_type_$temp"),
$new_entry);
}
// Details if a series
- if ($rep_type != REP_NONE)
+ if ($data['rep_type'] != REP_NONE)
{
$opt = "";
- if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
+ if (($data['rep_type'] == REP_WEEKLY) || ($data['rep_type'] ==
REP_N_WEEKLY))
{
// Display day names according to language and preferred weekday start.
for ($i = 0; $i < 7; $i++)
{
$daynum = ($i + $weekstarts) % 7;
- if ($rep_opt[$daynum])
+ if ($data['rep_opt'][$daynum])
{
$opt .= day_name($daynum) . " ";
}
}
}
- if ($rep_type == REP_N_WEEKLY)
+ if ($data['rep_type'] == REP_N_WEEKLY)
{
$body .= "\n" . get_mail_vocab("rep_num_weeks");
- $body .= ": " . compareEntries($rep_num_weeks,
+ $body .= ": " . compareEntries($data['rep_num_weeks'],
$mail_previous["rep_num_weeks"],
$new_entry);
}
@@ -615,11 +613,11 @@
$body .= "\n" . get_mail_vocab("rep_end_date");
if ($new_entry)
{
- $body .= ": " . mail_strftime('%A %d %B %Y',$rep_enddate);
+ $body .= ": " . mail_strftime('%A %d %B %Y',$data['end_date']);
}
else
{
- $temp = mail_strftime('%A %d %B %Y',$rep_enddate);
+ $temp = mail_strftime('%A %d %B %Y',$data['end_date']);
$body .= ": " .
compareEntries($temp,
$mail_previous['rep_end_date'],
Modified: mrbs/branches/provisional_bookings_new_style/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/provisional_bookings_new_style/web/mrbs_sql.inc
2010-09-15 09:13:17 UTC (rev 1452)
+++ mrbs/branches/provisional_bookings_new_style/web/mrbs_sql.inc
2010-09-15 15:17:08 UTC (rev 1453)
@@ -339,45 +339,20 @@
*
* Create a single (non-repeating) entry in the database
*
- * $start_time - Start time of entry
- * $end_time - End time of entry
- * $entry_type - Entry type
- * $repeat_id - Repeat ID
- * $room_id - Room ID
- * $create_by - Owner
- * $name - Name
- * $type - Type (Internal/External)
- * $description - Description
- * $status - Status code of the entry
- * $custom_fields - an array of any custom fields
+ * $data - An array containing the entry details
*
* Returns:
* 0 - An error occured while inserting the entry
* non-zero - The entry's ID
*/
-function mrbsCreateSingleEntry($start_time, $end_time, $entry_type, $repeat_id,
- $room_id, $create_by, $name, $type,
$description,
- $status, $custom_fields)
+function mrbsCreateSingleEntry($data)
{
global $tbl_entry;
- $data = array();
- $data['start_time'] = $start_time;
- $data['end_time'] = $end_time;
- $data['entry_type'] = $entry_type;
- $data['repeat_id'] = $repeat_id;
- $data['room_id'] = $room_id;
- $data['create_by'] = $create_by;
- $data['name'] = $name;
- $data['type'] = $type;
- $data['description'] = $description;
- $data['status'] = $status;
- $data['custom_fields'] = $custom_fields;
-
// make sure that any entry is of a positive duration
// this is to trap potential negative duration created when DST comes
// into effect
- if ($end_time > $start_time)
+ if ($data['end_time'] > $data['start_time'])
{
$result = mrbsCreateEntry($tbl_entry, $data);
return $result;
@@ -392,45 +367,16 @@
*
* Creates a repeat entry in the data base
*
- * $start_time - Start time of entry
- * $end_time - End time of entry
- * $rep_type - The repeat type
- * $end_date - When the repeating ends
- * $rep_opt - Any options associated with the entry
- * $room_id - Room ID
- * $create_by - Owner
- * $name - Name
- * $type - Type (Internal/External)
- * $description - Description
- * $rep_num_weeks - (missing)
- * $status - status code
- * $custom_fields - an array of any custom fields
+ * $data - An array containing the entry details
*
* Returns:
* 0 - An error occured while inserting the entry
* non-zero - The entry's ID
*/
-function mrbsCreateRepeatEntry($start_time, $end_time, $rep_type, $end_date,
- $rep_opt, $room_id, $create_by, $name, $type,
- $description, $rep_num_weeks, $status,
$custom_fields)
+function mrbsCreateRepeatEntry($data)
{
global $tbl_repeat;
- $data = array();
- $data['start_time'] = $start_time;
- $data['end_time'] = $end_time;
- $data['rep_type'] = $rep_type;
- $data['end_date'] = $end_date;
- $data['rep_opt'] = $rep_opt;
- $data['room_id'] = $room_id;
- $data['create_by'] = $create_by;
- $data['name'] = $name;
- $data['type'] = $type;
- $data['description'] = $description;
- $data['rep_num_weeks'] = $rep_num_weeks;
- $data['status'] = $status;
- $data['custom_fields'] = $custom_fields;
-
$result = mrbsCreateEntry($tbl_repeat, $data);
return $result;
}
@@ -634,18 +580,15 @@
* FALSE if the id refers to the entry table
*
*/
-function mrbsCreateRepeatingEntrys($starttime, $endtime, $rep_type,
- $rep_enddate, $rep_opt, $room_id, $owner,
- $name, $type, $description, $rep_num_weeks,
- $status, $custom_fields)
+function mrbsCreateRepeatingEntrys($data)
{
global $max_rep_entrys;
$result = array('id' => 0, 'series' => FALSE);
- $reps = mrbsGetRepeatEntryList($starttime, $rep_enddate,
- $rep_type, $rep_opt,
- $max_rep_entrys, $rep_num_weeks);
+ $reps = mrbsGetRepeatEntryList($data['start_time'], $data['end_date'],
+ $data['rep_type'], $data['rep_opt'],
+ $max_rep_entrys, $data['rep_num_weeks']);
if (count($reps) > $max_rep_entrys)
{
@@ -655,39 +598,32 @@
if (empty($reps))
{
- $id = mrbsCreateSingleEntry($starttime, $endtime, 0, 0,
- $room_id, $owner, $name, $type,
- $description, $status, $custom_fields);
+ $data['entry_type'] = 0;
+ $data['repeat_id'] = 0;
+ $id = mrbsCreateSingleEntry($data);
$result['id'] = $id;
$result['series'] = FALSE;
return $result;
}
- $id = mrbsCreateRepeatEntry($starttime, $endtime, $rep_type,
- $rep_enddate, $rep_opt, $room_id,
- $owner, $name, $type, $description,
- $rep_num_weeks, $status, $custom_fields);
+ $id = mrbsCreateRepeatEntry($data);
if ($id)
{
+ $data['entry_type'] = 1;
+ $data['repeat_id'] = $id;
+ $starttime = $data['start_time'];
+ $endtime = $data['end_time'];
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);
-
- $ent_id = mrbsCreateSingleEntry($reps[$i],
- $reps[$i] + $diff,
- 1,
- $id,
- $room_id,
- $owner,
- $name,
- $type,
- $description,
- $status,
- $custom_fields);
+ $diff += cross_dst($reps[$i], $reps[$i] + $diff);
+ $data['start_time'] = $reps[$i];
+ $data['end_time'] = $reps[$i] + $diff;
+
+ $ent_id = mrbsCreateSingleEntry($data);
}
}
$result['id'] = $id;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits