Revision: 2261
http://mrbs.svn.sourceforge.net/mrbs/?rev=2261&view=rev
Author: cimorrison
Date: 2012-01-27 18:08:32 +0000 (Fri, 27 Jan 2012)
Log Message:
-----------
- added handling for the ORGANIZER property
- fixed bug in export feature (fix should have gone into the trunk, but will
re-integrate soon)
Modified Paths:
--------------
mrbs/branches/ics_import/web/functions_ical.inc
mrbs/branches/ics_import/web/functions_mail.inc
mrbs/branches/ics_import/web/import.php
mrbs/branches/ics_import/web/view_entry.php
Modified: mrbs/branches/ics_import/web/functions_ical.inc
===================================================================
--- mrbs/branches/ics_import/web/functions_ical.inc 2012-01-27 15:57:34 UTC
(rev 2260)
+++ mrbs/branches/ics_import/web/functions_ical.inc 2012-01-27 18:08:32 UTC
(rev 2261)
@@ -277,6 +277,62 @@
}
+// Gets a username given an ORGANIZER value. Returns NULL if none found
+function get_create_by($organizer)
+{
+ global $auth, $mail_settings, $tbl_users;
+
+ // Get the email address. Stripping off the 'mailto' is a very simplistic
+ // method. It will work in the majority of cases, but this needs to be
improved
+ $email = preg_replace('/^mailto:/', '', $organizer);
+
+ // If we're using the 'db' auth rtpe, then look the username up in the users
table
+ if ($auth['type'] == 'db')
+ {
+ $sql = "SELECT name FROM $tbl_users WHERE email='" . addslashes($email) .
"'";
+ $res = sql_query($sql);
+ if ($res === FALSE)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(FALSE, get_vocab("fatal_db_error"));
+ }
+ elseif (sql_count($res) == 0)
+ {
+ return NULL;
+ }
+ else
+ {
+ if (sql_count($res) > 1)
+ {
+ // Could maybe do something better here
+ trigger_error("ORGANIZER email address not unique", E_USER_NOTICE);
+ }
+ $row = sql_row_keyed($res, 0);
+ return $row['name'];
+ }
+ }
+ // If we're using LDAP we can get the username given the email address
+ else if($auth['type'] == 'ldap')
+ {
+ // We need a function that is the inverse of authLdapGetEmail()
+ trigger_error("Cannot yet get username when using LDAP", E_USER_WARNING);
+ return NULL;
+ }
+ // Otherwise we derive the username from the email address
+ else
+ {
+ // We just want the string up to the '@'
+ $name = preg_replace('/@.*$/', '', $email);
+ // And add on the suffix if there is one
+ if (isset($mail_settings['username_suffix']))
+ {
+ $name .= $mail_settings['username_suffix'];
+ }
+ return $name;
+ }
+}
+
+
// Returns an MRBS rep_opt string given an array of RFC 5545 days
function get_rep_opt($byday_days)
{
Modified: mrbs/branches/ics_import/web/functions_mail.inc
===================================================================
--- mrbs/branches/ics_import/web/functions_mail.inc 2012-01-27 15:57:34 UTC
(rev 2260)
+++ mrbs/branches/ics_import/web/functions_mail.inc 2012-01-27 18:08:32 UTC
(rev 2261)
@@ -16,6 +16,7 @@
//
// $Id$
+global $mail_settings;
if ($mail_settings['icalendar'])
{
Modified: mrbs/branches/ics_import/web/import.php
===================================================================
--- mrbs/branches/ics_import/web/import.php 2012-01-27 15:57:34 UTC (rev
2260)
+++ mrbs/branches/ics_import/web/import.php 2012-01-27 18:08:32 UTC (rev
2261)
@@ -158,7 +158,6 @@
$booking = array();
$booking['status'] = 0;
$booking['rep_type'] = REP_NONE;
- $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
@@ -185,6 +184,9 @@
{
switch ($name)
{
+ case 'ORGANIZER':
+ $booking['create_by'] = get_create_by($details['value']);
+ break;
case 'SUMMARY':
$booking['name'] = $details['value'];
break;
@@ -239,7 +241,14 @@
break;
}
}
-
+
+ // If we didn't manage to work out a username then just put the booking
+ // under the name of the current user
+ if (!isset($booking['create_by']))
+ {
+ $booking['create_by'] = getUserName();
+ }
+
// A SUMMARY is optional in RFC 5545, however a brief description is
mandatory
// in MRBS. So if the VEVENT didn't include a name, we'll give it one
if (!isset($booking['name']))
Modified: mrbs/branches/ics_import/web/view_entry.php
===================================================================
--- mrbs/branches/ics_import/web/view_entry.php 2012-01-27 15:57:34 UTC (rev
2260)
+++ mrbs/branches/ics_import/web/view_entry.php 2012-01-27 18:08:32 UTC (rev
2261)
@@ -197,11 +197,7 @@
exit;
}
else
- {
- require_once "functions_ical.inc";
- header("Content-Type: application/ics; charset=" . get_charset(). ";
name=\"" . $mail_settings['ics_filename'] . ".ics\"");
- header("Content-Disposition: attachment; filename=\"" .
$mail_settings['ics_filename'] . ".ics\"");
-
+ {
// Construct the SQL query
$sql = "SELECT E.*, "
. sql_syntax_timestamp_to_unix("E.timestamp") . " AS last_updated, "
@@ -217,16 +213,32 @@
{
$sql .= ", $tbl_repeat T"
. " WHERE E.repeat_id=$repeat_id"
- . " AND E.repeat_id=T.id"
- . " ORDER BY E.ical_recur_id";
+ . " AND E.repeat_id=T.id";
}
else
{
$sql .= " WHERE E.id=$id";
}
+
+ $sql .= " AND E.room_id=R.id
+ AND R.area_id=A.id";
+
+ if ($series)
+ {
+ $sql .= " ORDER BY E.ical_recur_id";
+ }
$res = sql_query($sql);
+ if ($res === FALSE)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(FALSE, get_vocab("fatal_db_error"));
+ }
// Export the calendar
+ require_once "functions_ical.inc";
+ header("Content-Type: application/ics; charset=" . get_charset(). ";
name=\"" . $mail_settings['ics_filename'] . ".ics\"");
+ header("Content-Disposition: attachment; filename=\"" .
$mail_settings['ics_filename'] . ".ics\"");
+
export_icalendar($res, $keep_private);
exit;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits