Commit 0b7b5499 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 17d1c4e9 9fcb614d
......@@ -56,7 +56,7 @@ else {
$now = time();
}
log_dbg('---------- cron running ' . $now . ' ----------');
log_debug('---------- cron running ' . $now . ' ----------');
// for each plugin type
foreach (plugin_types() as $plugintype) {
......@@ -75,7 +75,7 @@ foreach (plugin_types() as $plugintype) {
foreach ($jobs as $job) {
$classname = generate_class_name($plugintype, $job['plugin']);
log_dbg("Running $classname::" . $job['callfunction']);
log_debug("Running $classname::" . $job['callfunction']);
safe_require($plugintype, $job['plugin'], 'lib.php', 'require_once');
call_static_method(
......@@ -276,7 +276,7 @@ function cron_day_of_week($date_array) {
// --------------------------------------------------------
function cron_valid_month($job, $run_date) {
log_dbg('cron_valid_month()');
log_debug('cron_valid_month()');
$propagate = 0;
cron_next_field_value($job['month'], $run_date['mon'], 13, $propagate, $steps, false);
......@@ -289,7 +289,7 @@ function cron_valid_month($job, $run_date) {
}
function cron_valid_day($job, $run_date) {
log_dbg('cron_valid_day()');
log_debug('cron_valid_day()');
$propagate = 0;
cron_next_field_value($job['day'], $run_date['mday'], 32, $propagate, $dayofmonth_steps, false);
......@@ -314,7 +314,7 @@ function cron_valid_day($job, $run_date) {
}
function cron_valid_hour($job, $run_date) {
log_dbg('cron_valid_hour()');
log_debug('cron_valid_hour()');
$propagate = 0;
cron_next_field_value($job['hour'], $run_date['hours'], 24, $propagate, $steps);
......@@ -327,7 +327,7 @@ function cron_valid_hour($job, $run_date) {
}
function cron_valid_minute($job, $run_date) {
log_dbg('cron_valid_minute()');
log_debug('cron_valid_minute()');
$propagate = 0;
cron_next_field_value($job['minute'], $run_date['minutes'], 60, $propagate, $steps);
......@@ -340,7 +340,7 @@ function cron_valid_minute($job, $run_date) {
}
function cron_next_month($job, &$run_date) {
log_dbg('cron_next_month()');
log_debug('cron_next_month()');
$propagate = 1;
$run_date['mon'] = cron_next_field_value($job['month'], $run_date['mon'], 13, $propagate, $steps, false);
......@@ -351,7 +351,7 @@ function cron_next_month($job, &$run_date) {
}
function cron_next_day($job, &$run_date) {
log_dbg('cron_next_day()');
log_debug('cron_next_day()');
// work out which has less steps
$propagate = 1;
......@@ -381,7 +381,7 @@ function cron_next_day($job, &$run_date) {
}
function cron_next_hour($job, &$run_date) {
log_dbg('cron_next_hour()');
log_debug('cron_next_hour()');
$propagate = 1;
$run_date['hours'] = cron_next_field_value($job['hour'], $run_date['hours'], 24, $propagate, $steps);
......@@ -392,7 +392,7 @@ function cron_next_hour($job, &$run_date) {
}
function cron_next_minute($job, &$run_date) {
log_dbg('cron_next_minute()');
log_debug('cron_next_minute()');
$propagate = 1;
$run_date['minutes'] = cron_next_field_value($job['minute'], $run_date['minutes'], 60, $propagate, $steps);
......@@ -403,7 +403,7 @@ function cron_next_minute($job, &$run_date) {
}
function cron_first_day($job, &$run_date) {
log_dbg('cron_first_day()');
log_debug('cron_first_day()');
$propagate = 0;
cron_next_field_value($job['day'], 1, 32, $propagate, $month_steps, false);
......@@ -422,22 +422,22 @@ function cron_first_day($job, &$run_date) {
$run_date['mday'] += $month_steps;
}
else {
log_dbg('using week_steps: ' . $week_steps);
log_debug('using week_steps: ' . $week_steps);
$run_date['mday'] += $week_steps;
}
log_dbg(' setting mday to ' . $run_date['mday']);
log_debug(' setting mday to ' . $run_date['mday']);
}
function cron_first_hour($job, &$run_date) {
log_dbg('cron_first_hour()');
log_debug('cron_first_hour()');
$propagate = 0;
$run_date['hours'] = cron_next_field_value($job['hour'], 0, 24, $propagate, $steps);
}
function cron_first_minute($job, &$run_date) {
log_dbg('cron_first_minute()');
log_debug('cron_first_minute()');
$propagate = 0;
$run_date['minutes'] = cron_next_field_value($job['minute'], 0, 60, $propagate, $steps);
......
......@@ -60,6 +60,7 @@
<TABLE NAME="activity_type">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="admin" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
......@@ -652,10 +653,13 @@
<SENTENCES>
<SENTENCE TEXT="(name) VALUES ('maharamessage')" />
<SENTENCE TEXT="(name) VALUES ('usermessage')" />
<SENTENCE TEXT="(name) VALUES ('adminmessage')" />
<SENTENCE TEXT="(name) VALUES ('feedback')" />
<SENTENCE TEXT="(name) VALUES ('watchlist')" />
<SENTENCE TEXT="(name) VALUES ('newview')" />
<SENTENCE TEXT="(name) VALUES ('contactus')" />
<SENTENCE TEXT="(name, admin) VALUES ('objectionable', 1)" />
<SENTENCE TEXT="(name, admin) VALUES ('virusrepeat', 1)" />
<SENTENCE TEXT="(name, admin) VALUES ('virusrelease', 1)" />
</SENTENCES>
</STATEMENT>
</STATEMENTS>
......
......@@ -81,9 +81,6 @@ function form($data) {
// - handle multipage forms?
// - handle a tabbed interface type of form?
//
//
// @todo: note somewhere that name, method, action are NOT html escaped, you have to
// do it yourself when buliding a form
}
/**
......@@ -140,11 +137,6 @@ class Form {
*/
private $tabindex = 1;
/**
* The form data array. Is this used?
*/
private $data = array();
/**
* The renderer used to build the HTML for the form that each element sits
* in. See the form/renderer package to find out the allowed types.
......@@ -204,10 +196,6 @@ class Form {
if (!isset($data['name']) || !preg_match('/^[a-z_][a-z0-9_]*$/', $data['name'])) {
throw new FormException('Forms must have a name, and that name must be valid (validity test: could you give a PHP function the name?)');
}
if ($data['name'] == 'form') {
// @todo<nigel>: This may not be the case any more, should test this
throw new FormException('You cannot call your form "form" due to namespace collisions with the form library');
}
$this->name = $data['name'];
// Assign defaults for the form
......@@ -248,10 +236,16 @@ class Form {
);
// Set some attributes for all elements
// @todo<nigel>: probably set the description and help for the elements too
foreach ($this->elements as $name => &$element) {
if (count($element) == 0) {
throw new FormException('An element in form "' . $this->name . '" has no data');
}
if (!isset($element['type'])) {
$element['type'] = 'markup';
if (!isset($element['value'])) {
throw new FormException('The markup element "'
. $name . '" has no value');
}
}
if (!isset($element['title'])) {
$element['title'] = '';
......@@ -316,7 +310,7 @@ class Form {
}
// Submit the form if things went OK
if (!$this->errors()) {
if (!$this->has_errors()) {
$function = $this->name . '_submit';
if (function_exists($function)) {
// Call the user defined function for processing a submit
......@@ -389,8 +383,8 @@ class Form {
* Given an element, gets the value for it from this form
*
* @param array $element The element to get the value for
* @return mixed The element's value
* @throws FormException If the element could not be found
* @return mixed The element's value. <kbd>null</kbd> if no value
* is available for the element.
*/
public function get_value($element) {
$global = ($this->method == 'get') ? $_GET : $_POST;
......@@ -403,7 +397,7 @@ class Form {
else if (isset($element['defaultvalue'])) {
return $element['defaultvalue'];
}
throw new FormException('Element "' . $element['name'] . '" cannot be found');
return null;
}
/**
......@@ -515,10 +509,20 @@ class Form {
/**
* Returns whether a field has an error marked on it.
*
* This method should be used in the custom validation functions, to see if
* there is an error on an element before checking for any more validation.
*
* Example:
*
* <code>
* if (!$form->get_error('name') && /* condition {@*}) {
* $form->set_error('name', 'error message');
* }
* </code>
*
* @param string $name The name of the element to check
* @return bool Whether the element has an error
* @throws FormException If the element could not be found
* @todo<nigel>: For consistency, should pass an $element here?
*/
public function get_error($name) {
$element = $this->get_element($name);
......@@ -526,12 +530,17 @@ class Form {
}
/**
* Marks a field has having an error
* Marks a field has having an error.
*
* This method should be used to set an error on an element in a custom
* validation function, if one has occured.
*
* Note that for the Mahara project, your error messages must be passed
* through {@link get_string} to internationalise them.
*
* @param string $name The name of the element to set an error on
* @param string $message The error message
* @throws FormException If the element could not be found
* @todo<nigel>: For consistency, should pass an $element here?
*/
public function set_error($name, $message) {
foreach ($this->elements as &$element) {
......@@ -553,22 +562,6 @@ class Form {
throw new FormException('Element "' . $name . '" could not be found');
}
/**
* Checks if there are errors on any of the form elements.
*
* @return bool Whether there are errors with the form
* @todo<nigel>: rename to has_errors()?
*/
private function errors() {
foreach ($this->get_elements() as $element) {
if (isset($element['error'])) {
return true;
}
}
return false;
}
/**
* Makes an ID for an element.
*
......@@ -662,21 +655,41 @@ class Form {
return $result;
}
/**
* Checks if there are errors on any of the form elements.
*
* @return bool Whether there are errors with the form
*/
private function has_errors() {
foreach ($this->get_elements() as $element) {
if (isset($element['error'])) {
return true;
}
}
return false;
}
}
/**
* This is separate so that child element types can nest other elements inside
* them (like the fieldset element does for example.
* Renders an element, and returns the result.
*
* This function looks in <kbd>form/renderers</kbd> for available overall form
* renderers, and in <kbd>form/elements</kbd> for renderers for each form
* element.
*
* If any of the renderers are not available, this function will throw a
* FormException.
*
* Data guaranteed to be available:
* - type
* - title
* - @todo more when I guarantee description, help
* @todo document properly
* {@internal This is separate so that child element types can nest other
* elements inside them (like the fieldset element does for example).}}
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The rendered element
*/
function form_render_element($element, $form) {
function form_render_element($element, Form $form) {
// Make sure that the function to render the element type is available
$function = 'form_render_' . $element['type'];
if (!function_exists($function)) {
......@@ -690,6 +703,10 @@ function form_render_element($element, $form) {
if ($element['type'] == 'hidden') {
return form_render_hidden($element, $form) . "\n";
}
// If the element is pure markup, don't pass it either
if ($element['type'] == 'markup') {
return $element['value'] . "\n";
}
// Work out the renderer function required and make sure it exists
if ($renderer = $form->get_renderer()) {
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,7 +27,13 @@
defined('INTERNAL') || die();
/**
* Renders a submit button
* Renders a "cancel" button. Custom buttons are rendered nearly the same as
* normal submit buttons, only their name is changed (for use by the Form class
* internally).
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_cancel($element, Form $form) {
return '<input type="submit"'
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,9 +27,13 @@
defined('INTERNAL') || die();
/**
* Provides a basic text field input.
* Provides a basic checkbox input.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_checkbox($element, $form) {
function form_render_checkbox($element, Form $form) {
$checked = false;
if (!empty($element['value'])) {
$checked = true;
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,9 +27,14 @@
defined('INTERNAL') || die();
/**
* Renders a fieldset
* Renders a fieldset. Fieldsets contain other elements, and do not count as a
* "true" element, in that they do not have a value and cannot be validated.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_fieldset($element, $form) {
function form_render_fieldset($element, Form $form) {
$result = "\n<fieldset>\n";
if (isset($element['legend'])) {
$result .= '<legend>' . hsc($element['legend']) . "</legend>\n";
......
......@@ -17,8 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core or plugintype/pluginname
* @author Your Name <you@example.org>
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
......@@ -26,7 +26,14 @@
defined('INTERNAL') || die();
function form_render_file($element) {
/**
* Renders a basic HTML <input type="file"> element.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_file($element, Form $form) {
return '<input type="file"'
. Form::element_attributes($element) . '>';
}
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,7 +27,11 @@
defined('INTERNAL') || die();
/**
* Renders a hidden element
* Renders a hidden element.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_hidden($element, Form $form) {
unset($element['tabindex']);
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -28,6 +28,10 @@ defined('INTERNAL') || die();
/**
* Renders a password field
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_password($element, $form) {
return '<input type="password"'
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -30,7 +30,8 @@ defined('INTERNAL') || die();
* Renders a set of radio buttons for a form
*
* @param array $element The element to render
* @param Form $form The form the element is being rendered on
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_radio($element, Form $form) {
if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -26,7 +26,14 @@
defined('INTERNAL') || die();
function form_render_select($element, $form) {
/**
* Renders a dropdown list, including support for multiple choices.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_select($element, Form $form) {
if (!empty($element['multiple'])) {
$element['name'] .= '[]';
}
......@@ -66,7 +73,7 @@ function form_render_select($element, $form) {
$result .= "\t<option value=\"" . hsc($key) . "\"$selected>" . hsc($value) . "</option>\n";
}
$result .= "</select>\n";
$result .= '</select>';
return $result;
}
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -28,6 +28,10 @@ defined('INTERNAL') || die();
/**
* Renders a submit button
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_submit($element, $form) {
return '<input type="submit"'
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -28,6 +28,10 @@ defined('INTERNAL') || die();
/**
* Provides a basic text field input.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_text($element, $form) {
return '<input type="text"'
......
......@@ -17,8 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core or plugintype/pluginname
* @author Your Name <you@example.org>
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
......@@ -26,6 +26,13 @@
defined('INTERNAL') || die();
/**
* Renders a basic HTML <textarea> element.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_textarea($element, $form) {
$rows = $cols = $style = '';
if (isset($element['height'])) {
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,20 +27,45 @@
defined('INTERNAL') || die();
/**
* The simplest type of form element - pure markup.
* Renders a textarea, but with extra javascript to turn it into a wysigyw
* textarea.
*
* This can be used to add HTML at various points throughtout a form. However,
* this should NOT be used for anything other than basic formatting - please
* use CSS instead.
* Currently this is just a