Commit c3659b8a authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 8045091d 861e1420
......@@ -147,13 +147,13 @@ function auth_setup () {
// The user's admin rights have been taken away
log_debug("users admin rights have been revoked!");
$USER->set('admin', 0);
$SESSION->add_err_msg(get_string('accessforbiddentoadminsection'));
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
redirect(get_config('wwwroot'));
}
elseif (!$USER->get('admin')) {
// The user never was an admin
log_debug("denying user access to administration");
$SESSION->add_err_msg(get_string('accessforbiddentoadminsection'));
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
redirect(get_config('wwwroot'));
}
}
......@@ -565,7 +565,7 @@ function login_submit($values) {
// Only admins in the admin section!
if (defined('ADMIN') && !$userdata->admin) {
log_debug('user not allowed in admin section');
$SESSION->add_err_msg(get_string('accessforbiddentoadminsection'));
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
redirect(get_config('wwwroot'));
}
......@@ -590,11 +590,11 @@ function login_submit($values) {
}
else {
// Login attempt failed
$SESSION->add_err_msg(get_string('loginfailed'));
$SESSION->add_error_msg(get_string('loginfailed'));
}
}
catch (AuthUnknownUserException $e) {
$SESSION->add_err_msg(get_string('loginfailed'));
$SESSION->add_error_msg(get_string('loginfailed'));
}
}
......
......@@ -121,12 +121,12 @@ class Session {
* @param string $message The message to add
* @param boolean $escape Whether to HTML escape the message
*/
public function add_err_msg($message, $escape=true) {
public function add_error_msg($message, $escape=true) {
$this->ensure_session();
if ($escape) {
$message = self::escape_message($message);
}
$_SESSION['messages'][] = array('type' => 'err', 'msg' => $message);
$_SESSION['messages'][] = array('type' => 'error', 'msg' => $message);
}
/**
......
......@@ -35,7 +35,7 @@ $id = param_integer('id',null);
$group_data = get_record('usr_group', 'id', $id, 'owner', $USER->get('id'));
if (!$group_data) {
$SESSION->add_err_msg(get_string('canteditdontown'));
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('./');
}
......@@ -89,7 +89,7 @@ function editgroup_validate(Pieform $form, $values) {
$id = get_field('usr_group', 'id', 'id', $values['id'], 'owner', $USER->get('id'));
if (!$id) {
$SESSION->add_err_msg(get_string('canteditdontown'));
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('./');
}
}
......
......@@ -177,7 +177,7 @@ function log_message ($message, $loglevel, $escape, $backtrace, $file=null, $lin
$method = 'add_info_msg';
}
else {
$method = 'add_err_msg';
$method = 'add_error_msg';
}
foreach ($loglines as $line) {
......
......@@ -554,15 +554,6 @@ function check_dir_exists($dir, $create=true, $recursive=true) {
return $status;
}
/**
* Checks that a username is in valid form
*
* @todo need such a function for password too.
*/
//function validate_username($username) {
// return preg_match('/^[a-zA-Z0-9_\.@]+$/', $username);
//}
/**
* Function to require a plugin file. This is to avoid doing
* require and include directly with variables.
......@@ -691,7 +682,7 @@ function mixed_array_to_field_array($array, $field) {
/**
* Adds stuff to the log
* @todo write this functino
* @todo write this function
*
* @param string $plugintype plugin type or core
* @param string $pluginname plugin name or core component (eg 'view')
......@@ -820,15 +811,16 @@ function password_validate(Pieform $form, $values, $username, $institution) {
function pieform_configure() {
global $USER;
return array(
'method' => 'post',
'action' => '',
'method' => 'post',
'action' => '',
'autofocus' => true,
'renderer' => 'maharatable',
'preajaxsubmitcallback' => 'processingStart',
'renderer' => 'maharatable',
'preajaxsubmitcallback' => 'processingStart',
'postajaxsubmitcallback' => 'processingStop',
'elements' => array(
'configdirs' => get_config('libroot') . 'form/',
'elements' => array(
'sesskey' => array(
'type' => 'hidden',
'type' => 'hidden',
'value' => $USER->get('sesskey')
)
)
......
......@@ -72,7 +72,6 @@ function pieform($data) {
// - Collapsible js for fieldsets
// - Grippie for textareas
// - javascript validation
// - handle multiple submit buttons
// - handle multipage forms?
// - handle a tabbed interface type of form?
//
......@@ -202,6 +201,13 @@ class Pieform {
*/
private $tabindex = 1;
/**
* Directories to look for elements, renderers and rules
*
* @var array
*/
private $configdirs = array();
/**
* Whether to autofocus fields in this form, and if so, optionally which
* field to focus.
......@@ -332,11 +338,12 @@ class Pieform {
'postajaxsubmitcallback' => '',
'ajaxsuccessfunction' => '',
'ajaxfailurefunction' => '',
'autofocus' => false,
'language' => 'en.utf8',
'validate' => true,
'submit' => true,
'elements' => array(),
'configdirs' => array(),
'autofocus' => false,
'language' => 'en.utf8',
'validate' => true,
'submit' => true,
'elements' => array(),
'submitfunction' => '',
'validatefunction' => '',
);
......@@ -348,12 +355,15 @@ class Pieform {
if ($data['method'] != 'post') {
$data['method'] = 'get';
}
$this->method = $data['method'];
$this->action = $data['action'];
$this->validate = $data['validate'];
$this->submit = $data['submit'];
$this->autofocus = $data['autofocus'];
$this->language = $data['language'];
$this->method = $data['method'];
$this->action = $data['action'];
$this->validate = $data['validate'];
$this->submit = $data['submit'];
$this->configdirs = array_map(
create_function('$a', 'return substr($a, -1) == "/" ? substr($a, 0, -1) : $a;'),
(array) $data['configdirs']);
$this->autofocus = $data['autofocus'];
$this->language = $data['language'];
if ($data['submitfunction']) {
$this->submitfunction = $data['submitfunction'];
......@@ -480,7 +490,7 @@ class Pieform {
// Let each element set and override attributes if necessary
if ($subelement['type'] != 'markup') {
$function = 'pieform_render_' . $subelement['type'] . '_set_attributes';
require_once('pieform/elements/' . $subelement['type'] . '.php');
$this->include_plugin('element', $subelement['type']);
if (function_exists($function)) {
$subelement = $function($subelement);
}
......@@ -506,7 +516,7 @@ class Pieform {
// @todo here, all elements are loaded that will be used, so no
// need to include files for them later (like in pieform_render_element)
// Also, don't use require_once so nicer errors can be thrown
require_once('pieform/elements/' . $element['type'] . '.php');
$this->include_plugin('element', $element['type']);
if (function_exists($function)) {
$element = $function($element);
}
......@@ -683,7 +693,7 @@ class Pieform {
$result .= ">\n";
// @todo masks attempts in pieform_render_element, including the error handling there
@include_once('pieform/renderers/' . $this->renderer . '.php');
$this->include_plugin('renderer', $this->renderer);
// Form header
$function = 'pieform_renderer_' . $this->renderer . '_header';
......@@ -705,7 +715,7 @@ class Pieform {
}
// Hidden elements
require_once('pieform/elements/hidden.php');
$this->include_plugin('element', 'hidden');
foreach ($this->get_elements() as $element) {
if ($element['type'] == 'hidden') {
$result .= pieform_render_hidden($element, $this);
......@@ -737,9 +747,6 @@ class Pieform {
*/
public function get_value($element) {
$function = 'pieform_get_value_' . $element['type'];
if (!function_exists($function)) {
@include_once('pieform/elements/' . $element['type'] . '.php');
}
// @todo for consistency, reverse parameter order - always a Form object first
if (function_exists($function)) {
return $function($element, $this);
......@@ -843,7 +850,7 @@ class Pieform {
// Get the rule
$function = 'pieform_rule_' . $rule;
if (!function_exists($function)) {
@include_once('pieform/rules/' . $rule . '.php');
$this->include_plugin('rule', $rule);
if (!function_exists($function)) {
throw new PieformException('No such form rule "' . $rule . '"');
}
......@@ -963,7 +970,7 @@ EOF;
$js_messages_function = 'pieform_renderer_' . $this->renderer . '_messages_js';
if (!function_exists($js_messages_function)) {
@include_once('pieform/renderers/' . $this->renderer . '.php');
$this->include_plugin('renderer', $this->renderer);
if (!function_exists($js_messages_function)) {
throw new PieformException('No renderer message function "' . $js_messages_function . '"');
}
......@@ -1145,6 +1152,37 @@ EOF;
return false;
}
/**
* Includes a plugin file, checking any configured plugin directories.
*
* @param string $type The type of plugin to include: 'element', 'renderer' or 'rule'
* @param string $name The name of the plugin to include
* @throws PieformException If the given type or plugin could not be found
*/
public function include_plugin($type, $name) {
if (!in_array($type, array('element', 'renderer', 'rule'))) {
throw new PieformException("The type \"$type\" is not allowed for an include plugin");
}
// Check the configured include paths if they are specified
foreach ($this->configdirs as $directory) {
$file = "$directory/{$type}s/$name.php";
if (is_readable($file)) {
include_once($file);
return;
}
}
// Check the default include path
$file = dirname(__FILE__) . "/pieform/{$type}s/{$name}.php";
if (is_readable($file)) {
include_once($file);
return;
}
throw new PieformException("Could not find $type \"$name\"");
}
/**
* Return an internationalised string based on the passed input key
*
......@@ -1272,7 +1310,7 @@ function pieform_render_element($element, Pieform $form) {
if ($renderer = $form->get_renderer()) {
$rendererfunction = 'pieform_renderer_' . $renderer;
if (!function_exists($rendererfunction)) {
include('pieform/renderers/' . $renderer . '.php');
$form->include_plugin('pieform/renderers/' . $renderer . '.php');
if (!function_exists($rendererfunction)) {
throw new PieformException('No such form renderer: "' . $renderer . '"');
}
......
......@@ -32,8 +32,8 @@
* @return string The HTML for the element
*/
function pieform_render_submitcancel($element, Pieform $form) {
require_once('submit.php');
require_once('cancel.php');
$form->include_plugin('element', 'submit');
$form->include_plugin('element', 'cancel');
$submitelement = $element;
$submitelement['value'] = $element['value'][0];
$cancelelement = $element;
......
......@@ -27,7 +27,6 @@
// @todo this renderer needs to take into account potentially being called more
// than once in the same PHP script (clobbering of the $formrenderermct variable).
// Also, not sure what 'static $var' does in global scope...
require_once(dirname(__FILE__) . '/table.php');
static $formrenderermct;
/**
......@@ -43,6 +42,8 @@ static $formrenderermct;
*/
function pieform_renderer_multicolumntable(Pieform $form, $builtelement, $rawelement) {
global $formrenderermct;
// Used by the messages javascript function
$form->include_plugin('renderer', 'table');
$formrenderermct->add_element($builtelement, $rawelement);
}
......
......@@ -27,22 +27,25 @@
/**
* Checks whether the field has been specified.
*
* @param Pieform $form The form the rule is being applied to
* @param string $field The field to check
* @param array $element The element to check
* @param Pieform $form The form the rule is being applied to
* @param string $field The field to check
* @param array $element The element to check
* @param string $check Whether to check the element
* @return string The error message, if the value is invalid.
*/
function pieform_rule_required(Pieform $form, $value, $element) {
$function = 'form_is_empty_' . $element['type'];
if (function_exists($function)) {
if ($function($value, $element)) {
return $form->i18n('required');
function pieform_rule_required(Pieform $form, $value, $element, $check) {
if ($check) {
$function = 'form_is_empty_' . $element['type'];
if (function_exists($function)) {
if ($function($value, $element)) {
return $form->i18n('required');
}
return;
}
return;
}
if ($value == '') {
return $form->i18n('required');
if ($value == '') {
return $form->i18n('required');
}
}
}
......
{include file='header.tpl'}
{include file='header.tpl' nosearch=true}
<div id="column-right">
</div>
......
</div>
<div class="footerright"><img src="{image_path imagelocation='images/footer_navbg_right.gif'}" border="0"></div>
<div id="footer"><a href="http://mahara.org/">Mahara</a> {if $releaseargs}{str section=admin tag=release args=$releaseargs}{/if}<br>
<div id="footer">Hello world</div>
<div class="housekeeping"><a href="http://mahara.org/">Mahara</a> {if $releaseargs}{str section=admin tag=release args=$releaseargs}{/if}<br>
&copy; 2006 onwards, <a href="http://catalyst.net.nz/">Catalyst IT Ltd</a></div>
</div>
<div id="bottom-corners">
......
......@@ -37,6 +37,7 @@
{/if}
<div id="header">
<div class="cornertopright"><img src="{image_path imagelocation='images/header_corner_topright.gif'}" border="0"></div>
{if !$nosearch}
<div class="searchbox">
<table><tr><td>
{$searchform}
......@@ -45,6 +46,7 @@
<a href="{$WWWROOT}user/search.php">{str tag=advancedsearch}</a>
</tr></td></table>
</div>
{/if}
<div class="logo"><a href="{$WWWROOT}"><img src="{image_path imagelocation='images/logo.gif'}" border="0"></a></div>
<h1 class="hiddenStructure"><a href="{$WWWROOT}">{$heading|default:"Mahara"|escape}</a></h1>
</div>
......
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