Revision: 1506
http://mrbs.svn.sourceforge.net/mrbs/?rev=1506&view=rev
Author: jberanek
Date: 2010-10-18 11:30:51 +0000 (Mon, 18 Oct 2010)
Log Message:
-----------
* Added the ability to make a custom entry field mandatory. Introduces
the config variable $mandatory_fields.
* Documented $select_options and $mandatory_fields in INSTALL.
Modified Paths:
--------------
mrbs/trunk/INSTALL
mrbs/trunk/web/edit_entry.php
mrbs/trunk/web/edit_entry_handler.php
mrbs/trunk/web/functions.inc
mrbs/trunk/web/lang.en
Modified: mrbs/trunk/INSTALL
===================================================================
--- mrbs/trunk/INSTALL 2010-10-15 16:26:19 UTC (rev 1505)
+++ mrbs/trunk/INSTALL 2010-10-18 11:30:51 UTC (rev 1506)
@@ -206,6 +206,32 @@
should then do the rest and display your coffee machine field on the room
pages.
+Extra options for custom fields:
+
+1)
+
+You can create dropdown boxes for a custom field by defining an
+entry in the configuration array $select_options. For example:
+
+$select_options['entry.conference_facilities'] = array('Video',
+ 'Telephone',
+ 'None');
+
+would define the 'conference_facilities' custom field to have three
+possible values.
+
+2)
+
+You can specify that a field is mandatory. This will ensure that the
+user specifies a value for a field that may be empty, like a text box
+or a selection, as in 1) above. For example:
+
+$mandatory_fields['entry.conference_facilities'] = true;
+
+would define the 'conference_facilities' custom field to be mandatory.
+In the case of a select field, this adds an empty value to the dropdown
+list.
+
Technical explanation of the restriction on column names for custom fields
--------------------------------------------------------------------------
// Column names for custom fields are used by MRBS in a number of ways:
Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php 2010-10-15 16:26:19 UTC (rev 1505)
+++ mrbs/trunk/web/edit_entry.php 2010-10-18 11:30:51 UTC (rev 1506)
@@ -422,6 +422,40 @@
alert("<?php echo get_vocab("you_have_not_selected") . '\n' .
get_vocab("valid_room") ?>");
return false;
}
+
+ <?php
+ if (count($mandatory_fields))
+ {
+ $m_fields = array();
+ foreach ($mandatory_fields as $field => $value)
+ {
+ if ($value)
+ {
+ $field = preg_replace('/^entry\./', 'f_', $field);
+ $m_fields[] = "'".str_replace("'", "\\'", $field)."'";
+ }
+ }
+ echo "var mandatory_fields = [".implode(', ', $m_fields)."];\n";
+ ?>
+ for (i = 0; i < mandatory_fields.length; i++)
+ {
+ if (form[mandatory_fields[i]].value == '')
+ {
+ label = $("label[for="+mandatory_fields[i]+"]").html();
+ label = label.replace(/:$/, '');
+ alert('"' + label + '" ' +
+ <?php echo '"'.
+ str_replace('"', '\\"',
+ get_vocab("is_mandatory_field")
+ ).
+ '"'; ?>);
+ return false;
+ }
+ }
+ <?php
+
+ }
+ ?>
// Form submit can take some times, especially if mails are enabled and
// there are more than one recipient. To avoid users doing weird things
@@ -884,7 +918,10 @@
// Output a select box if they want one
elseif (count($select_options["entry.$key"]) > 0)
{
- generate_select($label_text, $var_name, $value,
$select_options["entry.$key"]);
+ $mandatory = (array_key_exists("entry.$key", $mandatory_fields) &&
+ $mandatory_fields["entry.$key"]) ? true : false;
+ generate_select($label_text, $var_name, $value,
+ $select_options["entry.$key"], $mandatory);
}
// Output a textarea if it's a character string longer than the limit
for a
// text input
Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php 2010-10-15 16:26:19 UTC (rev
1505)
+++ mrbs/trunk/web/edit_entry_handler.php 2010-10-18 11:30:51 UTC (rev
1506)
@@ -249,6 +249,27 @@
print_footer(TRUE);
}
+if (count($mandatory_fields))
+{
+ foreach ($mandatory_fields as $field => $value)
+ {
+ $field = preg_replace('/^entry\./', '', $field);
+ if ($value && ($custom_fields[$field] == ''))
+ {
+ print_header($day, $month, $year, $area, isset($room) ? $room : "");
+?>
+ <h1><?php echo get_vocab('invalid_booking'); ?></h1>
+ <p>
+ <?php echo get_vocab('missing_mandatory_field')." \"".
+ get_loc_field_name($tbl_entry, $field)."\""; ?>
+ </p>
+<?php
+ // Print footer and exit
+ print_footer(TRUE);
+ }
+ }
+}
+
// Support locales where ',' is used as the decimal point
$duration = preg_replace('/,/', '.', $duration);
Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc 2010-10-15 16:26:19 UTC (rev 1505)
+++ mrbs/trunk/web/functions.inc 2010-10-18 11:30:51 UTC (rev 1506)
@@ -315,11 +315,16 @@
}
// Generates a select box from $options, an array of options
-function generate_select($label_text, $name, $value, $options)
+function generate_select($label_text, $name, $value, $options,
+ $mandatory = false)
{
// generate the HTML
$html = "<label for=\"$name\">$label_text</label>\n";
$html .= "<select id=\"$name\" name=\"$name\">\n";
+ if ($mandatory)
+ {
+ $options = array_merge(array(""),$options);
+ }
foreach ($options as $option)
{
$html .= "<option";
Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en 2010-10-15 16:26:19 UTC (rev 1505)
+++ mrbs/trunk/web/lang.en 2010-10-18 11:30:51 UTC (rev 1506)
@@ -94,6 +94,8 @@
$vocab["useful_n-weekly_value"] = "useful n-weekly value.";
$vocab["private"] = "Private";
$vocab["unavailable"] = "Private";
+$vocab["is_mandatory_field"] = "is a mandatory field, please supply a value";
+$vocab["missing_mandatory_field"] = "You have not supplied a value for the
mandatory field";
// Used in view_entry.php
$vocab["description"] = "Description";
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits