Revision: 1380
http://mrbs.svn.sourceforge.net/mrbs/?rev=1380&view=rev
Author: cimorrison
Date: 2010-07-23 22:12:28 +0000 (Fri, 23 Jul 2010)
Log Message:
-----------
Custom fields are now recognised by edit_entry_handler and written out to the
database (single entries only at this stage).
Still to do
- fix edit_entry for new bookings
- handle repeat bookings
- enhance email notifications to recognise custom fields
- enhance Search and report to recognise custom fields
Modified Paths:
--------------
mrbs/branches/custom_entry_fields/web/edit_entry_handler.php
mrbs/branches/custom_entry_fields/web/mrbs_sql.inc
Modified: mrbs/branches/custom_entry_fields/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/custom_entry_fields/web/edit_entry_handler.php
2010-07-23 21:20:09 UTC (rev 1379)
+++ mrbs/branches/custom_entry_fields/web/edit_entry_handler.php
2010-07-23 22:12:28 UTC (rev 1380)
@@ -30,6 +30,55 @@
$rep_num_weeks = get_form_var('rep_num_weeks', 'int');
$private = get_form_var('private', 'string'); // bool, actually
+// Get the information about the fields in the entry table
+$fields = sql_field_info($tbl_entry);
+
+// Get custom form variables
+$standard_fields = array('id',
+ 'start_time',
+ 'end_time',
+ 'entry_type',
+ 'repeat_id',
+ 'room_id',
+ 'timestamp',
+ 'create_by',
+ 'name',
+ 'type',
+ 'description',
+ 'private',
+ 'status',
+ 'reminded',
+ 'info_time',
+ 'info_user',
+ 'info_text');
+$custom_fields = array();
+
+foreach($fields as $field)
+{
+ if (!in_array($field['name'], $standard_fields))
+ {
+ switch($field['nature'])
+ {
+ case 'character':
+ $f_type = 'string';
+ break;
+ case 'integer':
+ $f_type = 'int';
+ break;
+ // We can only really deal with the types above at the moment
+ default:
+ $f_type = 'string';
+ break;
+ }
+ $var = "f_" . $field['name'];
+ $custom_fields[$field['name']] = get_form_var($var, $f_type);
+ if (($f_type == 'int') && ($custom_fields[$field['name']] === ''))
+ {
+ unset($custom_fields[$field['name']]);
+ }
+ }
+}
+
// Truncate the name field to the maximum length as a precaution.
// Although the MAXLENGTH attribute is used in the <input> tag, this can
// sometimes be ignored by the browser, for example by Firefox when
@@ -532,7 +581,8 @@
$type,
$description,
$isprivate,
- $status);
+ $status,
+ $custom_fields);
// Send a mail to the Administrator
if ($need_to_send_mail)
Modified: mrbs/branches/custom_entry_fields/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/custom_entry_fields/web/mrbs_sql.inc 2010-07-23 21:20:09 UTC
(rev 1379)
+++ mrbs/branches/custom_entry_fields/web/mrbs_sql.inc 2010-07-23 22:12:28 UTC
(rev 1380)
@@ -222,17 +222,18 @@
*
* Create a single (non-repeating) entry in the database
*
- * $starttime - Start time of entry
- * $endtime - End time of entry
- * $entry_type - Entry type
- * $repeat_id - Repeat ID
- * $room_id - Room ID
- * $owner - Owner
- * $name - Name
- * $type - Type (Internal/External)
- * $description - Description
- * $private - Private Booking (TRUE/FALSE)
- * $status - Status code of the entry
+ * $starttime - Start time of entry
+ * $endtime - End time of entry
+ * $entry_type - Entry type
+ * $repeat_id - Repeat ID
+ * $room_id - Room ID
+ * $owner - Owner
+ * $name - Name
+ * $type - Type (Internal/External)
+ * $description - Description
+ * $private - Private Booking (TRUE/FALSE)
+ * $status - Status code of the entry
+ * $custom_fields - an array of any custom fields
*
* Returns:
* 0 - An error occured while inserting the entry
@@ -240,7 +241,7 @@
*/
function mrbsCreateSingleEntry($starttime, $endtime, $entry_type, $repeat_id,
$room_id, $owner, $name, $type, $description,
- $private, $status)
+ $private, $status, $custom_fields)
{
global $tbl_entry;
@@ -255,10 +256,48 @@
// into effect
if ($endtime > $starttime)
{
- $sql = "INSERT INTO $tbl_entry ( start_time, end_time, entry_type,
repeat_id, room_id,
- create_by, name, type,
description, private, status)
- VALUES ($starttime, $endtime, $entry_type,
$repeat_id, $room_id,
- '$owner', '$name', '$type',
'$description', $private, $status)";
+ $sql = "INSERT INTO $tbl_entry (start_time, end_time, entry_type,
repeat_id, room_id,
+ create_by, name, type, description,
private, status";
+ // Add in any custom field names
+ if (count($custom_fields))
+ {
+ foreach ($custom_fields as $key => $value)
+ {
+ $sql .= ", $key";
+ }
+ }
+
+ $sql .= ")";
+ $sql .= " VALUES ($starttime, $endtime, $entry_type, $repeat_id, $room_id,
+ '$owner', '$name', '$type', '$description', $private,
$status";
+ // Add in any custom field values
+ if (count($custom_fields))
+ {
+ $fields = sql_field_info($tbl_entry);
+ $field_natures = array();
+ foreach ($fields as $field)
+ {
+ $field_natures[$field['name']] = $field['nature'];
+ }
+ foreach ($custom_fields as $key => $value)
+ {
+ switch ($field_natures[$key])
+ {
+ case 'integer':
+ if (!isset($value))
+ {
+ $value = 'NULL';
+ }
+ break;
+ default:
+ $value = "'" . addslashes($value) . "'";
+ break;
+ }
+ $sql .= ", $value";
+ }
+ }
+
+ $sql .= ")";
if (sql_command($sql) < 0)
{
@@ -560,6 +599,7 @@
{
global $max_rep_entrys;
+ $custom_fields = array();
$result = array('id' => 0, 'series' => FALSE);
$private = $private ? 1 : 0 ;
@@ -577,7 +617,7 @@
{
$id = mrbsCreateSingleEntry($starttime, $endtime, 0, 0,
$room_id, $owner, $name, $type,
- $description, $private, $status);
+ $description, $private, $status,
$custom_fields);
$result['id'] = $id;
$result['series'] = FALSE;
return $result;
@@ -607,7 +647,8 @@
$type,
$description,
$private,
- $status);
+ $status,
+ $custom_fields);
}
}
$result['id'] = $id;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits