Commit 72b2651d authored by Penny Leach's avatar Penny Leach
Browse files
parents 8a1a242e b21675f2
......@@ -256,15 +256,16 @@ function setmenu(menu) {
var pub = get_string('loggedoutmenu');
var priv = get_string('loggedinmenu');
if (menu == 'public') {
priv = A({'href':'#'},priv);
priv.onclick = function (e) {stop(e); setmenu('private');};
priv = A({'href':''},priv);
priv.onclick = function () {return setmenu('private');};
}
else {
pub = A({'href':'#'},pub);
pub.onclick = function (e) {stop(e); setmenu('public');};
pub = A({'href':''},pub);
pub.onclick = function () {return setmenu('public');};
}
replaceChildNodes($('menuselect'), [pub, priv]);
getitems();
return false;
}
var selectedmenu = 'public';
......
......@@ -91,9 +91,11 @@ function editsitepage_submit($values) {
exit;
}
$js = array();
if (use_html_editor()) {
array_unshift($js,'tinymce');
$js = array('tinymce');
}
else {
$js = array();
}
$ijs = <<< EOJS
......
......@@ -29,9 +29,111 @@ define('ADMIN',1);
define('MENUITEM','siteoptions');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
$smarty = smarty();
$langoptions = get_languages();
$themeoptions = get_themes();
$yesno = array(true => get_string('yes'),
false => get_string('no'));
$siteoptionform = form(array(
'name' => 'siteoptions',
'method' => 'post',
'action' => '',
'ajaxpost' => true,
'elements' => array(
'language' => array(
'type' => 'select',
'title' => get_string('language'),
'description' => get_string('sitelanguagedescription'),
'defaultvalue' => get_config('language'),
'options' => $langoptions,
),
'theme' => array(
'type' => 'select',
'title' => get_string('theme'),
'description' => get_string('sitethemedescription'),
'defaultvalue' => get_config('theme'),
'options' => $themeoptions,
),
'viruschecking' => array(
'type' => 'checkbox',
'title' => get_string('viruschecking'),
'description' => get_string('viruscheckingdescription'),
'defaultvalue' => get_config('viruschecking'),
),
'pathtoclam' => array(
'type' => 'text',
'title' => get_string('pathtoclam'),
'description' => get_string('pathtoclamdescription'),
'defaultvalue' => get_config('pathtoclam'),
),
'sessionlifetime' => array(
'type' => 'text',
'size' => 4,
'title' => get_string('sessionlifetime'),
'description' => get_string('sessionlifetimedescription'),
'defaultvalue' => get_config('session_timeout') / 60,
),
'allowpublicviews' => array(
'type' => 'select',
'title' => get_string('allowpublicviews'),
'description' => get_string('allowpublicviewsdescription'),
'defaultvalue' => get_config('allowpublicviews'),
'options' => $yesno,
),
'artefactviewinactivitytime' => array(
'type' => 'expiry',
'title' => get_string('artefactviewinactivitytime'),
'description' => get_string('artefactviewinactivitytimedescription'),
'defaultvalue' => get_config('artefactviewinactivitytime'),
),
'contactaddress' => array(
'type' => 'text',
'title' => get_string('contactaddress'),
'description' => get_string('contactaddressdescription'),
'defaultvalue' => get_config('contactaddress'),
'rules' => array(
'email' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('updatesiteoptions')
),
)
));
function siteoptions_fail($field) {
$result['error'] = 'local';
$result['message'] = get_string('setsiteoptionsfailed', $field);
error_log($result['message']);
json_headers();
echo json_encode($result);
exit;
}
function siteoptions_submit($values) {
$fields = array('language','theme','viruschecking','pathtoclam',
'allowpublicviews','artefactviewinactivitytime',
'contactaddress');
foreach ($fields as $field) {
if (!set_config($field, $values[$field])) {
siteoptions_fail($field);
}
}
if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
siteoptions_fail($field);
}
$result['error'] = false;
$result['message'] = get_string('siteoptionsset');
error_log($result['message']);
json_headers();
echo json_encode($result);
exit;
}
$smarty = smarty(array(),array(),array('siteoptionsset'));
$smarty->assign('SITEOPTIONFORM',$siteoptionform);
$smarty->display('admin/options/index.tpl');
?>
<?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 core
* @author Martyn Smith <martyn@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'mygroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
$id = param_integer('id',null);
$group_data = get_record('usr_group', 'id', $id, 'owner', $USER->id);
if (!$group_data) {
$SESSION->add_err_msg(get_string('canteditdontown'));
redirect('./');
}
$group_members = get_column('usr_group_member', 'member', 'grp', $group_data->id);
$editgroup = form(array(
'name' => 'editgroup',
'method' => 'post',
'elements' => array(
'name' => array(
'type' => 'text',
'title' => get_string('groupname'),
'rules' => array( 'required' => true ),
'defaultvalue' => $group_data->name,
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('groupdescription'),
'rows' => 10,
'cols' => 80,
'defaultvalue' => $group_data->description,
),
'members' => array(
'type' => 'userlist',
'title' => get_string('groupmembers'),
'rules' => array( 'required' => true ),
'defaultvalue' => $group_members,
),
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('savegroup'), get_string('cancel')),
),
),
));
function editgroup_validate(Form $form, $values) {
global $USER;
global $SESSION;
$gid = get_field('usr_group', 'id', 'owner', $USER->id, 'name', $values['name']);
if ($gid && $gid != $values['id']) {
$form->set_error('name', get_string('groupalreadyexists'));
}
// check owner
$id = get_field('usr_group', 'id', 'id', $values['id'], 'owner', $USER->id);
if (!$id) {
$SESSION->add_err_msg(get_string('canteditdontown'));
redirect('./');
}
}
function editgroup_cancel_submit() {
redirect('./');
}
function editgroup_submit($values) {
global $USER;
global $SESSION;
db_begin();
$now = db_format_timestamp(time());
update_record(
'usr_group',
(object) array(
'id' => $values['id'],
'name' => $values['name'],
'owner' => $USER->id,
'description' => $values['description'],
'mtime' => $now,
),
'id'
);
delete_records('usr_group_member', 'grp', $values['id']);
foreach ($values['members'] as $member) {
insert_record(
'usr_group_member',
(object) array(
'grp' => $values['id'],
'member'=> $member,
'ctime' => $now,
)
);
}
$SESSION->add_ok_msg(get_string('groupsaved'));
db_commit();
redirect('./');
}
$smarty = smarty();
$smarty->assign('editgroup', $editgroup);
$smarty->display('contacts/groups/edit.tpl');
?>
......@@ -36,7 +36,7 @@ if (!empty($_SERVER['MAHARA_LIBDIR'])) {
else {
$CFG->libroot = dirname(__FILE__) . '/lib/';
}
set_include_path('.' . PATH_SEPARATOR . $CFG->libroot);
set_include_path('.' . PATH_SEPARATOR . $CFG->libroot . PATH_SEPARATOR . $CFG->libroot . 'pear/');
// Set up error handling
require('errors.php');
......
......@@ -103,6 +103,36 @@ $string['forgotpassemailmessagehtml'] = '<p>Dear $fullname,</p>
<p><a href="' . get_config('wwwroot') . 'forgotpass.php?key=%s">' . get_config('wwwroot') . 'forgotpass.php?key=%s</a></p>';
// Site options
$string['allowpublicviews'] = 'Allow public views';
$string['allowpublicviewsdescription'] = 'If set to yes, views are accessable by the public. If set to no, only logged in users will be able to look at views';
$string['artefactviewinactivitytime'] = 'Artefact view inactivity time';
$string['artefactviewinactivitytimedescription'] = 'The time after which an inactive view or artefact will be moved to the InactiveContent area';
$string['contactaddress'] = 'Contact address';
$string['contactaddressdescription'] = 'The email address to which messages from the Contact Us form will be sent';
$string['language'] = 'Language';
$string['sitelanguagedescription'] = 'The default language for the site';
$string['pathtoclam'] = 'Path to clam';
$string['pathtoclamdescription'] = 'The filesystem path to clamscan or clamdscan';
$string['sessionlifetime'] = 'Session lifetime';
$string['sessionlifetimedescription'] = 'Time in minutes after which an inactive logged in user will be automatically logged out';
$string['theme'] = 'Theme';
$string['sitethemedescription'] = 'The theme for the site';
$string['viruschecking'] = 'Virus checking';
$string['viruscheckingdescription'] = 'If checked, virus checking will be enabled for all uploaded files using ClamAV';
$string['updatesiteoptions'] = 'Update site options';
$string['siteoptionsset'] = 'Site options have been updated';
$string['setsiteoptionsfailed'] = 'Failed setting the %s option';
// Expiry times
$string['noenddate'] = 'No end date';
$string['days'] = 'days';
$string['weeks'] = 'weeks';
$string['months'] = 'months';
$string['years'] = 'years';
// Boolean site option
$string['no'] = 'no';
$string['yes'] = 'yes';
// Admin menu editor
//$string['menueditor'] = 'Menu editor';
$string['adminfile'] = 'Admin file';
......
......@@ -70,6 +70,7 @@ function form($data) {
//
// - more form element types (inc. types like autocomplete and date picker and wyswiyg)
// - support processing of data before validation occurs (e.g. trim(), strtoupper())
// - do onsubmit for ajax stuff by mochikit connect()
// - Basic validation is possible as there's a callback function for checking,
// but some helper functions could be written to make people's job validating
// stuff much easier (form_validate_email, form_validate_date etc).
......@@ -138,13 +139,6 @@ class Form {
*/
private $submit = true;
/**
* The javascript function that the form will be submitted to.
*
* @var string
*/
//private $onsubmit = '';
/**
* Whether to submit the form via ajax
*
......@@ -166,13 +160,6 @@ class Form {
*/
private $ajaxfailurefunction = '';
/**
* Name of a php script to handle an ajax-submitted form
*
* @var string
*/
//private $ajaxformhandler = '';
/**
* The tab index for this particular form.
*
......@@ -424,6 +411,14 @@ class Form {
// finished processing the form.
// @todo maybe it should do just that...
$function($values);
// This will only work if I can make the login_submit function stuff work in login_validate
//if ($this->ajaxpost) {
// $message = 'Your ' . $this->name . '_submit function should output some json and exit';
//}
//else {
// $message = 'Your ' . $this->name . '_submit function should redirect when it is finished';
//}
//throw new FormException($message);
}
else {
throw new FormException('No function registered to handle form submission for form "' . $this->name . '"');
......@@ -466,6 +461,15 @@ class Form {
return $this->method;
}
/**
* Is the form being submitted by ajax?
*
* @return bool
*/
public function get_ajaxpost() {
return $this->ajaxpost;
}
/**
* Returns the renderer used on to render the form
*
......@@ -504,7 +508,7 @@ class Form {
$result .= ' enctype="multipart/form-data"';
}
if ($this->ajaxpost) {
$result .= ' onsubmit="return ' . $this->name . '_submit();"';
$result .= ' onsubmit="' . $this->name . '_submit(); return false;"';
}
$result .= ">\n";
......@@ -696,20 +700,32 @@ function {$this->name}_submit() {
var data = {};
EOF;
foreach ($this->get_elements() as $element) {
$result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].$element[name].value;\n";
if (!empty($element['ajaxmessages'])) {
$messageelement = $element['name'];
// Get values for each element from the form via the DOM
foreach ($this->get_elements() as $element) {
if ($element['type'] != 'markup') {
$function = 'form_get_value_js_' . $element['type'];
if (function_exists($function)) {
$result .= $function($element, $this);
}
else {
$result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].elements['{$element['name']}'].value;\n";
}
if (!empty($element['ajaxmessages'])) {
$messageelement = $element['name'];
}
}
}
}
$result .= " data['form_{$this->name}'] = '';\n";
if (!isset($messageelement)) {
throw new FormException('At least one submit-type element is required for AJAX forms');
}
$action = ($this->action) ? $this->action : basename($_SERVER['PHP_SELF']);
$method = ($this->get_method() == 'get') ? 'GET' : 'POST';
$result .= <<<EOF
if (!isset($messageelement)) {
throw new FormException('At least one submit-type element is required for AJAX forms');
}
// Add the hidden element for detecting form submission
$result .= " data['form_{$this->name}'] = '';\n";
$action = ($this->action) ? $this->action : basename($_SERVER['PHP_SELF']);
$method = ($this->get_method() == 'get') ? 'GET' : 'POST';
$result .= <<<EOF
var req = getXMLHttpRequest();
req.open('{$method}', '{$action}');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
......@@ -724,29 +740,30 @@ EOF;
}
EOF;
if (!empty($this->ajaxfailurefunction)) {
$result .= " {$this->ajaxfailurefunction}();\n";
}
$result .= <<<EOF
if (!empty($this->ajaxfailurefunction)) {
$result .= " {$this->ajaxfailurefunction}();\n";
}
$result .= <<<EOF
}
else {
{$this->name}_message(data.message, 'ok');
EOF;
if (!empty($this->ajaxsuccessfunction)) {
$result .= " {$this->ajaxsuccessfunction}();\n";
}
$result .= <<<EOF
if (!empty($this->ajaxsuccessfunction)) {
$result .= " {$this->ajaxsuccessfunction}();\n";
}
$result .= <<<EOF
}
processingStop();
EOF;
$strunknownerror = get_string('unknownerror');
$strprocessingform = get_string('processingform');
$result .= <<<EOF
$strunknownerror = get_string('unknownerror');
$strprocessingform = get_string('processingform');
$result .= <<<EOF
},
function() {
{$this->name}_message('{$strunknownerror}', 'error');
......@@ -758,16 +775,16 @@ EOF;
EOF;
$js_messages_function = 'form_renderer_' . $this->renderer . '_messages_js';
if (!function_exists($js_messages_function)) {
@include_once('form/renderers/' . $this->renderer . '.php');
$js_messages_function = 'form_renderer_' . $this->renderer . '_messages_js';
if (!function_exists($js_messages_function)) {
throw new FormException('No renderer message function "' . $js_messages_function . '"');
@include_once('form/renderers/' . $this->renderer . '.php');
if (!function_exists($js_messages_function)) {
throw new FormException('No renderer message function "' . $js_messages_function . '"');
}
}
}
return $result . $js_messages_function($this->name, $messageelement);
}
return $result . $js_messages_function($this->name, $messageelement);
}
/**
* Returns whether a field has an error marked on it.
......
......@@ -44,4 +44,10 @@ function form_render_cancel($element, Form $form) {
. ' value="' . hsc($form->get_value($element)) . '">';
}
function form_get_value_js_cancel($element, $form) {
$formname = $form->get_name();
$name = $element['name'];
return " data['$name'] = document.forms['$formname'].elements['{$name}_cancel'].value;\n";
}
?>
......@@ -79,6 +79,17 @@ function form_get_value_date($element, Form $form) {
return $time;
}
function form_get_value_js_date($element, Form $form) {
$formname = $form->get_name();
$name = $element['name'];
return <<<EOF
data['{$name}_year'] = document.forms['$formname'].elements['{$name}_year'].value;
data['{$name}_month'] = document.forms['$formname'].elements['{$name}_month'].value;
data['{$name}_day'] = document.forms['$formname'].elements['{$name}_day'].value;
EOF;
}
/** helper: used when rendering the element, to get the value for it */
function form_render_select_get_value($timeperiod, $min, $max, $element, Form $form) {
static $lookup = array(
......
<?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-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
*
*/
defined('INTERNAL') || die();
/**
* Provides a duration chooser, with a text box for a number and a
* select box to choose the units, in days, weeks, months, years, or 'no end date'.
*
* @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_expiry($element, Form $form) {
$result = '';
$name = $element['name'];
if (!isset($element['defaultvalue'])) {
$element['defaultvalue'] = null;
}
$global = ($form->get_method() == 'get') ? $_GET : $_POST;
// Get the value of the element for rendering. The values of the
// two inputs are rendered, and the total time in seconds is
// stored in a hidden input.
if (isset($element['value'])) {
$seconds = $element['value'];
$values = get_expiry_from_seconds($element['value']);