Revision: 2475
https://sourceforge.net/p/mrbs/code/2475/
Author: cimorrison
Date: 2012-10-05 17:10:50 +0000 (Fri, 05 Oct 2012)
Log Message:
-----------
Restructured code
Modified Paths:
--------------
mrbs/branches/improved_repeat_interface/web/edit_entry.php
mrbs/branches/improved_repeat_interface/web/edit_entry_handler.php
mrbs/branches/improved_repeat_interface/web/edit_users.php
mrbs/branches/improved_repeat_interface/web/functions.inc
mrbs/branches/improved_repeat_interface/web/internalconfig.inc.php
Modified: mrbs/branches/improved_repeat_interface/web/edit_entry.php
===================================================================
--- mrbs/branches/improved_repeat_interface/web/edit_entry.php 2012-10-05
15:24:01 UTC (rev 2474)
+++ mrbs/branches/improved_repeat_interface/web/edit_entry.php 2012-10-05
17:10:50 UTC (rev 2475)
@@ -51,7 +51,6 @@
require "defaultincludes.inc";
require_once "mrbs_sql.inc";
-
$fields = sql_field_info($tbl_entry);
$custom_fields = array();
@@ -1271,28 +1270,25 @@
echo "<label>" . get_vocab("rep_end_date") . ":</label>\n";
genDateSelector("rep_end_", $rep_end_day, $rep_end_month, $rep_end_year);
echo "</div>\n";
- ?>
- <div id="rep_day">
- <label><?php echo get_vocab("rep_rep_day")?>:<br><?php echo
get_vocab("rep_for_weekly")?></label>
- <div class="group">
- <?php
- // Display day name checkboxes according to language and preferred
weekday start.
- for ($i = 0; $i < 7; $i++)
- {
- $wday = ($i + $weekstarts) % 7;
- echo " <label><input class=\"checkbox\" name=\"rep_day[]\"
value=\"$wday\" type=\"checkbox\"";
- if (in_array($wday, $rep_day))
- {
- echo " checked=\"checked\"";
- }
- echo ">" . day_name($wday) . "</label>\n";
- }
- ?>
- </div>
- </div>
-
- <?php
+ // Repeat day
+ echo "<div id=\"rep_day\">\n";
+ $params = array('label' => get_vocab("rep_rep_day") . ":<br>" .
get_vocab("rep_for_weekly"),
+ 'name' => 'rep_day[]',
+ 'value' => array(),
+ 'options' => array());
+ for ($i = 0; $i < 7; $i++)
+ {
+ // Display day name checkboxes according to language and preferred
weekday start.
+ $wday = ($i + $weekstarts) % 7;
+ // We need to ensure the index is a string to force the array to be
associative
+ $v = STRING_PREFIX . $wday;
+ $params['options'][$v] = day_name($wday);
+ }
+ generate_checkbox_group($params);
+ echo "</div>\n";
+
+ // Repeat frequency
echo "<div>\n";
$params = array('label' => get_vocab("rep_num_weeks") . ":",
'name' => 'rep_num_weeks',
Modified: mrbs/branches/improved_repeat_interface/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/improved_repeat_interface/web/edit_entry_handler.php
2012-10-05 15:24:01 UTC (rev 2474)
+++ mrbs/branches/improved_repeat_interface/web/edit_entry_handler.php
2012-10-05 17:10:50 UTC (rev 2475)
@@ -70,6 +70,15 @@
foreach($formvars as $var => $var_type)
{
$$var = get_form_var($var, $var_type);
+ // rep_day is a special case: we need to strip off the string prefix,
+ // which was pit there to force an associative array
+ if ($var == 'rep_day')
+ {
+ for ($i=0; $i<count($rep_day); $i++)
+ {
+ $rep_day[$i] = substr($rep_day[$i], strlen(STRING_PREFIX));
+ }
+ }
}
// BACK: we didn't really want to be here - send them to the returl
Modified: mrbs/branches/improved_repeat_interface/web/edit_users.php
===================================================================
--- mrbs/branches/improved_repeat_interface/web/edit_users.php 2012-10-05
15:24:01 UTC (rev 2474)
+++ mrbs/branches/improved_repeat_interface/web/edit_users.php 2012-10-05
17:10:50 UTC (rev 2475)
@@ -40,8 +40,6 @@
require "defaultincludes.inc";
-define ('USER_LEVEL_PREFIX', 'L'); // Just something to ensure the value is a
string
-
// Get non-standard form variables
$Action = get_form_var('Action', 'string');
$Id = get_form_var('Id', 'int');
@@ -370,7 +368,7 @@
{
// We add a string prefix to the level to force the
array to be
// associative. We strip it off when we get the form
variable
- $v = USER_LEVEL_PREFIX . $i;
+ $v = STRING_PREFIX . $i;
$params['options'][$v] = get_vocab("level_$i");
// Work out which option should be selected by default:
// if we're editing an existing entry, then it should
be the current value;
@@ -589,7 +587,7 @@
case 'level':
// level: set a safe default (lowest level of access)
// if there is no value set
- $values[$fieldname] = substr($values[$fieldname],
strlen(USER_LEVEL_PREFIX));
+ $values[$fieldname] = substr($values[$fieldname],
strlen(STRING_PREFIX));
$q_string .= "&$fieldname=" . $values[$fieldname];
if (!isset($values[$fieldname]))
{
Modified: mrbs/branches/improved_repeat_interface/web/functions.inc
===================================================================
--- mrbs/branches/improved_repeat_interface/web/functions.inc 2012-10-05
15:24:01 UTC (rev 2474)
+++ mrbs/branches/improved_repeat_interface/web/functions.inc 2012-10-05
17:10:50 UTC (rev 2475)
@@ -626,6 +626,74 @@
}
+// Generate a group of radio buttons with an associated label
+//
+// $params an associative array holding the function parameters:
+// MANDATORY
+// 'label' The text to be used for the field label.
+// 'name' The name of the input.
+// OPTIONAL
+// 'value' The value of the input. Can be an array. Default
array()
+// 'options' An associative array where the key is the value of the
+// button and the value is the button text
+// 'disabled' Whether the field should be disabled. Default FALSE
+//
+function generate_checkbox_group($params)
+{
+ // some sanity checking on params
+ foreach (array('label', 'name', 'options', 'value', 'disabled') as $key)
+ {
+ if (!isset($params[$key]))
+ {
+ switch ($key)
+ {
+ case 'label':
+ case 'name':
+ trigger_error('Missing mandatory parameters', E_USER_NOTICE);
+ break;
+ case 'options':
+ $params[$key] = array();
+ break;
+ case 'value':
+ $params[$key] = array();
+ break;
+ case 'disabled':
+ $params[$key] = FALSE;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (!is_array($params['value']))
+ {
+ $params['value'] = array($params['value']);
+ }
+
+ // generate the HTML
+ $html = "<label>" . $params['label'] . "</label>\n";
+ $html .= "<div class=\"group\">\n";
+ // Output each checkbox
+ foreach ($params['options'] as $value => $token)
+ {
+ $html .= "<label>";
+ $html .= "<input class=\"checkbox\" type=\"checkbox\" name=\"" .
$params['name'] . "\" value=\"$value\"";
+ $html .= (in_array($value, $params['value'])) ? " checked=\"checked\"" :
"";
+ $html .= ($params['disabled']) ? " disabled=\"disabled\"" : "";
+ $html .= ">" . htmlspecialchars($token);
+ $html .= "</label>\n";
+ if ($params['disabled'] && in_array($value, $params['value']))
+ {
+ $html .= "<input type=\"hidden\" name=\"" . $params['name'] . "\"";
+ $html .= " value=\"$value\">\n";
+ }
+ }
+ $html .= "</div>\n";
+
+ echo $html;
+}
+
+
// Generates a select box with an associated label
//
// $params an associative array holding the function parameters:
Modified: mrbs/branches/improved_repeat_interface/web/internalconfig.inc.php
===================================================================
--- mrbs/branches/improved_repeat_interface/web/internalconfig.inc.php
2012-10-05 15:24:01 UTC (rev 2474)
+++ mrbs/branches/improved_repeat_interface/web/internalconfig.inc.php
2012-10-05 17:10:50 UTC (rev 2475)
@@ -340,7 +340,9 @@
// Interval types used in booking policies
$interval_types = array('day', 'week', 'month', 'year', 'future');
+define('STRING_PREFIX', 'S'); // Just some string - doesn't matter what it is
+
/********************************************************
* JavaScript - internal use, do not change
********************************************************/
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits