Revision: 2254
http://mrbs.svn.sourceforge.net/mrbs/?rev=2254&view=rev
Author: cimorrison
Date: 2012-01-26 15:41:05 +0000 (Thu, 26 Jan 2012)
Log Message:
-----------
Initial attempt at import utility. Still lots of tidying up to do
Modified Paths:
--------------
mrbs/branches/ics_import/web/Themes/default/header.inc
mrbs/branches/ics_import/web/edit_entry_handler.php
mrbs/branches/ics_import/web/functions_ical.inc
mrbs/branches/ics_import/web/import.php
mrbs/branches/ics_import/web/lang.en
mrbs/branches/ics_import/web/mrbs_sql.inc
Modified: mrbs/branches/ics_import/web/Themes/default/header.inc
===================================================================
--- mrbs/branches/ics_import/web/Themes/default/header.inc 2012-01-26
14:37:24 UTC (rev 2253)
+++ mrbs/branches/ics_import/web/Themes/default/header.inc 2012-01-26
15:41:05 UTC (rev 2254)
@@ -2999,7 +2999,7 @@
// performance for large tables
if (function_exists('json_encode'))
{
- $ajax_url = "http://" . $HTTP_HOST . $PHP_SELF . "?" . $QUERY_STRING .
"&ajax=1&phase=2";
+ $ajax_url = basename($PHP_SELF) . "?" . $QUERY_STRING .
"&ajax=1&phase=2";
?>
tableOptions.sAjaxSource = "<?php echo $ajax_url ?>";
<?php
@@ -3198,7 +3198,7 @@
<?php
// Use an Ajax source - gives much better performance for large tables
- $ajax_url = "http://" . $HTTP_HOST . $PHP_SELF . "?" . $QUERY_STRING .
"&ajax=1";
+ $ajax_url = basename($PHP_SELF) . "?" . $QUERY_STRING . "&ajax=1";
?>
tableOptions.sAjaxSource = "<?php echo $ajax_url ?>";
tableOptions.aoColumnDefs = [{"sType": "title-numeric", "aTargets":
[2]}];
Modified: mrbs/branches/ics_import/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/ics_import/web/edit_entry_handler.php 2012-01-26 14:37:24 UTC
(rev 2253)
+++ mrbs/branches/ics_import/web/edit_entry_handler.php 2012-01-26 15:41:05 UTC
(rev 2254)
@@ -553,7 +553,7 @@
$just_check = $ajax && function_exists('json_encode') && !$commit;
$this_id = (isset($id)) ? $id : NULL;
-$result = mrbsMakeBookings($bookings, $this_id, $just_check,
$original_room_id, $need_to_send_mail, $edit_type);
+$result = mrbsMakeBookings($bookings, $this_id, $just_check, $skip,
$original_room_id, $need_to_send_mail, $edit_type);
// If we weren't just checking and this was a succesful booking and
// we were editing an existing booking, then delete the old booking
Modified: mrbs/branches/ics_import/web/functions_ical.inc
===================================================================
--- mrbs/branches/ics_import/web/functions_ical.inc 2012-01-26 14:37:24 UTC
(rev 2253)
+++ mrbs/branches/ics_import/web/functions_ical.inc 2012-01-26 15:41:05 UTC
(rev 2254)
@@ -292,11 +292,15 @@
// Given an RFC 5545 recurrence rule, returns an array giving the MRBS repeat
// details. Indexed by rep_type, rep_num_weeks, rep_opt, end_date
-function get_repeat_details($rrule, $start_time)
+function get_repeat_details($rrule, $start_time, &$errors)
{
global $RFC_5545_days;
- $result = array();
+ // Set up the result aeeay with safe defaults
+ $result = array('rep_type' => REP_NONE,
+ 'rep_opt' => '0000000',
+ 'rep_num_weeks' => 0,
+ 'end_date' => 0);
$rules = array();
$recur_rule_parts = explode(';', $rrule);
foreach ($recur_rule_parts as $recur_rule_part)
@@ -307,8 +311,7 @@
if (!isset($rules['FREQ']))
{
- trigger_error("Invalid RRULE: missing FREQ part");
- return FALSE;
+ $errors[] = get_vocab("invalid_RRULE");
}
switch ($rules['FREQ'])
@@ -349,7 +352,7 @@
$byday_days = explode(',', $rules['BYDAY']);
if (count($byday_days) > 1)
{
- trigger_error("MRBS does not support more than one BYDAY value when
FREQ=${result['freq']}");
+ $errors[] = get_vocab("more_than_one_BYDAY") . $result['freq'];
}
foreach ($byday_days as $byday_day)
{
@@ -368,13 +371,11 @@
{
if ((int) $nth < 0)
{
- trigger_error("MRBS does not support negative BYDAY values
($nth$day)", E_USER_WARNING);
- $unsupported_rules = TRUE;
+ $errors[] = get_vocab("negative_BYDAY") . " $nth$day";
}
elseif ($nth == '5')
{
- trigger_error("MRBS does not support a BYDAY value of 5
($nth$day)", E_USER_WARNING);
- $unsupported_rules = TRUE;
+ $errors[] = get_vocab("BYDAY_equals_5") . " $nth$day";
}
// otherwise we're OK and we don't need to do anything more
because we know
// we've only got one day and the REP_MONTHLY_SAMEDAY repeat type
will work
@@ -387,16 +388,14 @@
$result['rep_type'] = REP_YEARLY;
break;
default:
- trigger_error("FREQ=${rules['FREQ']} not supported by MRBS",
E_USER_WARNING);
- $unsupported_rules = TRUE;
+ $errors[] = get_vocab("unsupported_FREQ") . $rules['FREQ'];
break;
}
if (isset($rules['interval']) && ($rules['interval'] > 1) &&
!in_array($rules['FREQ'], array('WEEKLY')))
{
- trigger_error("MRBS does not support INTERVAL>1 with
FREQ=${rules['FREQ']}", E_USER_WARNING);
- $unsupported_rules = TRUE;
+ $errors[] = get_vocab("unsupported_INTERVAL") . $rules['FREQ'];
}
if (isset($rules['UNTIL']))
@@ -412,16 +411,14 @@
elseif (isset($rules['COUNT']))
{
// It would be quite easy to support COUNT, but we haven't done so yet
- trigger_error("COUNT not yet supported by MRBS");
- $unsupported_rules = TRUE;
+ $errors[] = get_vocab("unsupported_COUNT");
}
else
{
- trigger_error("Indefinite repeats not yet supported by MRBS");
- $unsupported_rules = TRUE;
+ $errors[] = get_vocab("no_indefinite_repeats");
}
- return (empty($unsupported_rules)) ? $result: FALSE;
+ return (empty($errors)) ? $result: FALSE;
}
Modified: mrbs/branches/ics_import/web/import.php
===================================================================
--- mrbs/branches/ics_import/web/import.php 2012-01-26 14:37:24 UTC (rev
2253)
+++ mrbs/branches/ics_import/web/import.php 2012-01-26 15:41:05 UTC (rev
2254)
@@ -5,7 +5,6 @@
require_once "functions_ical.inc";
require_once "mrbs_sql.inc";
-
function get_room_id($location)
{
global $area_room_order, $area_room_delimiter, $area_room_create, $test;
@@ -181,12 +180,23 @@
function process_event($vevent)
{
+ global $import_default_type, $test, $skip;
+ global $morningstarts, $morningstarts_minutes, $resolution;
+
+ // We are going to cache the settings ($resolution etc.) for the rooms
+ // in order to avoid lots of database lookups
+ static $room_settings = array();
+
+ // Set up the booking with some defaults
$booking = array();
$booking['status'] = 0;
$booking['rep_type'] = REP_NONE;
- $properties = array();
+ $booking['create_by'] = getUserName();
+ $booking['type'] = $import_default_type;
// Parse all the lines first because we'll need to get the start date
// for calculating some of the other settings
+ $properties = array();
+ $problems = array();
foreach ($vevent as $line)
{
$property = parse_ical_property($line);
@@ -217,6 +227,10 @@
break;
case 'LOCATION':
$booking['room_id'] = get_room_id($details['value']);
+ if (empty($booking['room_id']))
+ {
+ $problems[] = get_vocab("could_not_find_room") . "
'${details['value']}'";
+ }
break;
case 'DTEND':
$booking['end_time'] = get_time($details['value'], $details['params']);
@@ -225,11 +239,11 @@
trigger_error("DURATION not yet supported by MRBS", E_USER_WARNING);
break;
case 'RRULE':
- $repeat_details = get_repeat_details($details['value'],
$booking['start_time']);
+ $rrule_errors = array();
+ $repeat_details = get_repeat_details($details['value'],
$booking['start_time'], $rrule_errors);
if ($repeat_details === FALSE)
{
- echo "Could not import event with UID ${booking['ical_uid']}.
Recurrence rule not supported";
- return;
+ $problems = array_merge($problems, $rrule_errors);
}
else
{
@@ -257,7 +271,71 @@
}
}
- mrbsMakeBooking($booking);
+ if (empty($problems))
+ {
+ // Get the area settings for this room, if we haven't got them already
+ if (!isset($room_settings[$booking['room_id']]))
+ {
+ get_area_settings(get_area($booking['room_id']));
+ $room_settings[$booking['room_id']]['morningstarts'] = $morningstarts;
+ $room_settings[$booking['room_id']]['morningstarts_minutes'] =
$morningstarts_minutes;
+ $room_settings[$booking['room_id']]['resolution'] = $resolution;
+ }
+ // Round the start and end times to slot boundaries
+ $date = getdate($booking['start_time']);
+ $m = $date['mon'];
+ $d = $date['mday'];
+ $y = $date['year'];
+ $am7 = mktime($room_settings[$booking['room_id']]['morningstarts'],
+ $room_settings[$booking['room_id']]['morningstarts_minutes'],
+ 0, $m, $d, $y,
+ is_dst($m, $d, $y,
$room_settings[$booking['room_id']]['morningstarts']));
+ $booking['start_time'] = round_t_down($booking['start_time'],
+
$room_settings[$booking['room_id']]['resolution'],
+ $am7);
+ $booking['end_time'] = round_t_up($booking['end_time'],
+
$room_settings[$booking['room_id']]['resolution'],
+ $am7);
+ // Make the bookings
+ $bookings = array($booking);
+ $result = mrbsMakeBookings($bookings, NULL, $test, $skip);
+ if ($result['valid_booking'])
+ {
+ return TRUE;
+ }
+ }
+ // There were problems - list them
+ echo "<div class=\"problem_report\">\n";
+ echo get_vocab("could_not_import") . " UID:" .
htmlspecialchars($booking['ical_uid']);
+ echo "<ul>\n";
+ foreach ($problems as $problem)
+ {
+ echo "<li>" . htmlspecialchars($problem) . "</li>\n";
+ }
+ if (!empty($result['rules_broken']))
+ {
+ echo "<li>" . get_vocab("rules_broken") . "</li>\n";
+ echo "<li><ul>\n";
+ foreach ($result['rules_broken'] as $rule)
+ {
+ echo "<li>$rule</li>\n";
+ }
+ echo "</ul></li>\n";
+ }
+ if (!empty($result['conflicts']))
+ {
+ echo "<li>" . get_vocab("conflict"). "</li>\n";
+ echo "<li><ul>\n";
+ foreach ($result['conflicts'] as $conflict)
+ {
+ echo "<li>$conflict</li>\n";
+ }
+ echo "</ul></li>\n";
+ }
+ echo "</ul>\n";
+ echo "</div>\n";
+
+ return FALSE;
}
@@ -268,23 +346,12 @@
$import = get_form_var('import', 'string');
$test = get_form_var('test', 'string');
-$area_room_order = get_form_var('area_room_order', 'string');
-$area_room_delimiter = get_form_var('area_room_delimiter', 'string');
-$area_room_create = get_form_var('area_room_create', 'string');
+$area_room_order = get_form_var('area_room_order', 'string', 'area_room');
+$area_room_delimiter = get_form_var('area_room_delimiter', 'string', ';');
+$area_room_create = get_form_var('area_room_create', 'string', '0');
+$import_default_type = get_form_var('import_default_type', 'string',
$default_type);
+$skip = get_form_var('skip', 'string', ((empty($skip_default)) ? '0' : '1'));
-// Set defaults
-if (!isset($area_room_order))
-{
- $area_room_order = 'area_room';
-}
-if (!isset($area_room_delimiter))
-{
- $area_room_delimiter = ';';
-}
-if (!isset($area_room_create))
-{
- $area_room_crete = FALSE;
-}
// PHASE 2 - Process the files
// ---------------------------
@@ -354,10 +421,19 @@
}
}
// Process each event, putting it in the database
+ $n_success = 0;
+ $n_failure = 0;
foreach ($vevents as $vevent)
{
- process_event($vevent);
+ (process_event($vevent)) ? $n_success++ : $n_failure++;
}
+ echo "<p>\n";
+ echo "$n_success " . get_vocab("events_imported");
+ if ($n_failure > 0)
+ {
+ echo "<br>\n$n_failure " . get_vocab("events_not_imported");
+ }
+ echo "</p>\n";
}
}
}
@@ -406,6 +482,26 @@
echo "</fieldset>\n";
+echo "<div>\n";
+echo "<label for=\"import_default_type\">" . get_vocab("default_type") .
":</label>\n";
+echo "<select name=\"import_default_type\" id=\"import_default_type\">\n";
+foreach ($booking_types as $type)
+{
+ echo "<option value=\"$type\"" .
+ (($type == $import_default_type) ? " selected=\"selected\"" : '') .
+ ">" . get_vocab("type.$type") . "</option>\n";
+}
+echo "</select>\n";
+echo "</div>\n";
+
+echo "<div>\n";
+echo "<label for=\"skip\">" . get_vocab("skip_conflicts") . ":</label>\n";
+echo "<input type=\"checkbox\" class=\"checkbox\" " .
+ "id=\"skip\" name=\"skip\" value=\"1\" " .
+ (($skip) ? " checked=\"checked\"" : "") .
+ ">\n";
+echo "</div>\n";
+
// The Submit button
echo "<div id=\"import_submit\">\n";
echo "<input class=\"submit default_action\" type=\"submit\" name=\"test\"
value=\"" . get_vocab("test") . "\">\n";
Modified: mrbs/branches/ics_import/web/lang.en
===================================================================
--- mrbs/branches/ics_import/web/lang.en 2012-01-26 14:37:24 UTC (rev
2253)
+++ mrbs/branches/ics_import/web/lang.en 2012-01-26 15:41:05 UTC (rev
2254)
@@ -434,12 +434,25 @@
$vocab["room_area"] = "Room-Area";
$vocab["area_room_delimiter"] = "Delimiter";
$vocab["area_room_create"] = "Create rooms if necessary";
+$vocab["default_type"] = "Default type";
$vocab["area_does_not_exist"] = "Non-existent area:";
$vocab["room_does_not_exist"] = "Non-existent room:";
$vocab["creating_new_area"] = "Creating new area:";
$vocab["creating_new_room"] = "Creating new room:";
$vocab["could_not_create_area"] = "Could not create area";
$vocab["could_not_create_room"] = "Could not create room";
+$vocab["could_not_find_room"] = "Could not find room";
+$vocab["could_not_import"] = "Could not import";
+$vocab["invalid_RRULE"] = "Invalid RRULE: missing FREQ part";
+$vocab["more_than_one_BYDAY"] = "MRBS does not support more than one BYDAY
value when FREQ=";
+$vocab["negative_BYDAY"] = "MRBS does not support negative BYDAY
values";
+$vocab["BYDAY_equals_5"] = "MRBS does not support a BYDAY value of 5";
+$vocab["unsupported_FREQ"] = "MRBS does not support FREQ=";
+$vocab["unsupported_INTERVAL"] = "MRBS does not support INTERVAL>1 with
FREQ=";
+$vocab["unsupported_COUNT"] = "COUNT not yet supported by MRBS";
+$vocab["no_indefinite_repeats"] = "Indefinite repeats not yet supported by
MRBS";
+$vocab["events_imported"] = "events imported";
+$vocab["events_not_imported"] = "events not imported";
// Used in mysql.inc AND pgsql.inc
$vocab["failed_connect_db"] = "Fatal error: failed to connect to database";
Modified: mrbs/branches/ics_import/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/ics_import/web/mrbs_sql.inc 2012-01-26 14:37:24 UTC (rev
2253)
+++ mrbs/branches/ics_import/web/mrbs_sql.inc 2012-01-26 15:41:05 UTC (rev
2254)
@@ -21,6 +21,8 @@
global $enable_periods, $periods, $twentyfourhour_format;
global $strftime_format;
+ get_area_settings(get_area($room_id));
+
$user = getUserName();
// Select any meetings which overlap ($starttime,$endtime) for this room:
$sql = "SELECT id, name, start_time, create_by, status
@@ -1177,8 +1179,11 @@
return $room;
}
-// $id is the id of the current booking when editing an existing entry
-function mrbsMakeBookings($bookings, $id=NULL, $just_check=FALSE,
$original_room_id=NULL, $send_mail=FALSE, $edit_type='')
+
+// Makes bookings
+// $bookings an array of bookings
+// $id the id of the current booking when editing an existing
entry
+function mrbsMakeBookings($bookings, $id=NULL, $just_check=FALSE, $skip=FALSE,
$original_room_id=NULL, $send_mail=FALSE, $edit_type='')
{
global $max_rep_entrys, $enable_periods, $resolution, $mail_settings;
global $tbl_entry, $tbl_room, $tbl_area;
@@ -1474,6 +1479,7 @@
$result['new_details'] = $new_details;
$result['slots'] = intval(($common['end_time'] -
$common['start_time'])/$resolution);
+
return $result;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits