Commit d9d010b3 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files
parents 76183257 559601df
......@@ -29,7 +29,7 @@
<INDEX NAME="usernameuk" UNIQUE="true" FIELDS="LOWER(username)"/>
</INDEXES>
</TABLE>
<TABLE NAME="event">
<TABLE NAME="event_type">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" />
</FIELDS>
......@@ -101,7 +101,7 @@
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="auth_installed" REFFIELDS="name" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event" REFFIELDS="name" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event_type" REFFIELDS="name" />
<KEY NAME="subscruk" TYPE="unique" FIELDS="plugin,event,callfunction" />
</KEYS>
</TABLE>
......@@ -186,7 +186,7 @@
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="artefact_installed" REFFIELDS="name" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event" REFFIELDS="name" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event_type" REFFIELDS="name" />
<KEY NAME="subscruk" TYPE="unique" FIELDS="plugin,event,callfunction" />
</KEYS>
</TABLE>
......@@ -202,7 +202,7 @@
<SENTENCE TEXT="(username, password, password_change) VALUES ('root', 'mahara', 1)"/>
</SENTENCES>
</STATEMENT>
<STATEMENT NAME="insert events" TYPE="insert" TABLE="event">
<STATEMENT NAME="insert events" TYPE="insert" TABLE="event_type">
<SENTENCES>
<SENTENCE TEXT="(name) VALUES ('createuser')" />
<SENTENCE TEXT="(name) VALUES ('updateuser')" />
......
......@@ -331,9 +331,12 @@ class Form {
}
$global = ($this->method == 'get') ? $_GET : $_POST;
foreach ($global as $key => $value) {
if (in_array($key, $elementnames)) {
$result[$key] = $value;
foreach ($elementnames as $name) {
if (isset($global[$name])) {
$result[$name] = $global[$name];
}
else {
$result[$name] = null;
}
}
return $result;
......@@ -345,21 +348,21 @@ class Form {
*/
private function validate($values) {
foreach ($this->get_elements() as $element) {
if (!empty($element['rules']['required']) && (!isset($values[$element['name']]) || $values[$element['name']] == '')) {
$this->set_error($element['name'], get_string('This field is required', 'mahara'));
}
if (!empty($element['rules']['minlength'])) {
$minlength = intval($element['rules']['minlength']);
if (!isset($values[$element['name']]) || strlen($values[$element['name']]) < $minlength) {
$this->set_error($element['name'], get_string('You must put a minimum of '
. $minlength . ' characters in this field'));
}
}
if (!empty($element['rules']['maxlength'])) {
$maxlength = intval($element['rules']['maxlength']);
if (!isset($values[$element['name']]) || strlen($values[$element['name']]) > $maxlength) {
$this->set_error($element['name'], get_string('You must put a maximum of '
. $maxlength . ' characters in this field'));
if (isset($element['rules']) && is_array($element['rules'])) {
foreach ($element['rules'] as $rule => $data) {
if (!$this->get_error($element['name'])) {
// Get the rule
$function = 'form_rule_' . $rule;
if (!function_exists($function)) {
@include_once('form/rules/' . $rule . '.php');
if (!function_exists($function)) {
throw new FormException('No such form rule "' . $rule . '"');
}
}
if ($error = $function($values[$element['name']], $data)) {
$this->set_error($element['name'], $error);
}
}
}
}
}
......
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @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
*
*/
defined('INTERNAL') || die();
function form_rule_email($address) {
if (!preg_match('/(.*)@(.*)/', $address)) {
return get_string('E-mail address is invalid');
}
}
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @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
*
*/
defined('INTERNAL') || die();
function form_rule_maxlength($value, $maxlength) {
if (strlen($value) > $maxlength) {
return get_string('This field can only be ' . $maxlength . ' characters long');
}
}
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @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
*
*/
defined('INTERNAL') || die();
function form_rule_minlength($value, $minlength) {
if (strlen($value) < $minlength) {
return get_string('This field must be at least ' . $minlength . ' characters long');
}
}
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @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
*
*/
defined('INTERNAL') || die();
function form_rule_required($field) {
if ($field == '') {
return get_string('This field is required');
}
}
?>
......@@ -543,7 +543,7 @@ function redirect($location) {
}
function handle_event($event) {
if (!$e = get_record('event','name',$event)) {
if (!$e = get_record('event_type','name',$event)) {
throw new Exception("Invalid event");
}
$plugintypes = plugin_types();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment