Commit 7538d3c9 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie

Changed most forms to be pieforms 0.2.0 compliant. A _huge_ change! It's

likely some stuff still doesn't work properly...
parent 1f2db621
......@@ -75,7 +75,7 @@ $elements['submit'] = array(
$prefsform = array(
'name' => 'activityprefs',
'method' => 'post',
'ajaxpost' => true,
'jsform' => true,
'renderer' => 'table',
'plugintype ' => 'core',
'pluginname' => 'account',
......@@ -87,7 +87,7 @@ $smarty->assign('prefsdescr', get_string('prefsdescr', 'activity'));
$smarty->assign('form', pieform($prefsform));
$smarty->display('account/activity/preferences/index.tpl');
function activityprefs_submit($values, Pieform $form) {
function activityprefs_submit(Pieform $form, $values) {
global $activitytypes, $admintypes, $USER;
$userid = $USER->get('id');
......
......@@ -129,10 +129,10 @@ $elements['submit'] = array(
$prefsform = array(
'name' => 'accountprefs',
'method' => 'post',
'ajaxpost' => true,
'jsform' => true,
'plugintype' => 'core',
'pluginname' => 'account',
'ajaxsuccessfunction' => 'clearPasswords',
'jssuccesscallback' => 'clearPasswords',
'elements' => $elements
);
......@@ -140,7 +140,8 @@ $prefsform = array(
$smarty = smarty();
$smarty->assign('form', pieform($prefsform));
$smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords() {
function clearPasswords(form, data) {
formSuccess(form, data);
$('accountprefs_oldpassword').value = '';
$('accountprefs_password1').value = '';
$('accountprefs_password2').value = '';
......@@ -161,7 +162,7 @@ function accountprefs_validate(Pieform $form, $values) {
}
}
function accountprefs_submit($values, Pieform $form) {
function accountprefs_submit(Pieform $form, $values) {
global $USER;
db_begin();
......
......@@ -57,8 +57,9 @@ if (isset($form['validatefunction'])) {
$validatefunction = $form['validatefunction'];
}
$form['submitfunction'] = 'pluginconfig_submit';
$form['validatefunction'] = 'pluginconfig_validate';
$form['jsform'] = true;
$form['successcallback'] = 'pluginconfig_submit';
$form['validatecallback'] = 'pluginconfig_validate';
$form['elements']['plugintype'] = array(
'type' => 'hidden',
'value' => $plugintype
......@@ -80,7 +81,7 @@ $smarty->assign('type', $type);
$smarty->display('admin/extensions/pluginconfig.tpl');
function pluginconfig_submit($values) {
function pluginconfig_submit(Pieform $form, $values) {
$success = false;
global $submitfunction, $plugintype, $pluginname, $classname;
if (!empty($submitfunction)) {
......@@ -95,11 +96,12 @@ function pluginconfig_submit($values) {
else {
// call set_plugin_config and stuffs
}
if ($success) {
json_reply(false, get_string('settingssaved'));
$form->json_reply(PIEFORM_OK, get_string('settingssaved'));
}
else {
json_reply('local', get_string('settingssavefailed'));
$form->json_reply(PIEFORM_ERR, array('message' => get_string('settingssavefailed')));
}
}
......
......@@ -39,7 +39,7 @@ $yesno = array(true => get_string('yes'),
$siteoptionform = pieform(array(
'name' => 'siteoptions',
'ajaxpost' => true,
'jsform' => true,
'renderer' => 'table',
'elements' => array(
'sitename' => array(
......@@ -103,25 +103,25 @@ $siteoptionform = pieform(array(
)
));
function siteoptions_fail($field, Pieform $form) {
function siteoptions_fail(Pieform $form, $field) {
$form->json_reply(PIEFORM_ERR, get_string('siteoptionsfailed','admin', get_string($field)), array($field => get_string($field . 'invalid', 'admin')));
}
function siteoptions_submit($values, Pieform $form) {
function siteoptions_submit(Pieform $form, $values) {
$fields = array('sitename','language','theme','pathtoclam',
'allowpublicviews','artefactviewinactivitytime');
foreach ($fields as $field) {
if (!set_config($field, $values[$field])) {
siteoptions_fail($field);
siteoptions_fail($form, $field);
}
}
// submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
siteoptions_fail('sessionlifetime', $form);
siteoptions_fail($form, 'sessionlifetime');
}
// Submitted value is on/off; database entry should be 1/0
if (!set_config('viruschecking', (int) ($values['viruschecking'] == 'on'))) {
siteoptions_fail('viruschecking', $form);
siteoptions_fail($form, 'viruschecking');
}
$form->json_reply(PIEFORM_OK, get_string('siteoptionsset','admin'));
}
......
......@@ -42,8 +42,8 @@ $getstring = array('discardpageedits' => "'" . get_string('discardpageedits','ad
$f = array(
'name' => 'editsitepage',
'ajaxpost' => true,
'ajaxsuccessfunction' => 'contentSaved',
'jsform' => true,
'jssuccescallback' => 'contentSaved',
'elements' => array(
'pagename' => array(
'type' => 'select',
......@@ -71,7 +71,7 @@ $f = array(
$form = pieform($f);
function editsitepage_submit($values, Pieform $form) {
function editsitepage_submit(Pieform $form, $values) {
global $USER;
$data = new StdClass;
$data->name = $values['pagename'];
......@@ -106,9 +106,10 @@ function requestPageText(removeMessage) {
}
processingStart();
if (removeMessage) {
editsitepage_remove_message();
}
// @todo something might need to be done here
//if (removeMessage) {
// removeElement('messages');
//}
editsitepage_remove_all_errors();
logDebug(get_string('loadingpagecontent', 'admin'));
var d = loadJSONDoc('editchangepage.json.php',{'pagename':$('editsitepage_pagename').value});
......@@ -129,9 +130,11 @@ function requestPageText(removeMessage) {
}
// Called from submitForm on successful page save.
function contentSaved () {
function contentSaved (form, data) {
formSuccess(form, data);
originalcontent = getEditorContent();
callLater(2, editsitepage_remove_message);
// @todo something might need to be done here
//callLater(2, function() { removeElement('messages'); });
requestPageText(false);
}
......
......@@ -40,8 +40,6 @@ $adminusers = get_column('usr', 'id', 'admin', 1);
$form = array(
'name' => 'adminusers',
'method' => 'post',
'action' => '',
'elements' => array(
'users' => array(
'type' => 'userlist',
......@@ -59,7 +57,7 @@ $form = array(
)
);
function adminusers_submit($values) {
function adminusers_submit(Pieform $form, $values) {
global $SESSION;
$table = get_config('dbprefix') . 'usr';
......
......@@ -50,7 +50,7 @@ if ($institution || $add) {
redirect(get_config('wwwroot') . 'admin/users/institutions.php');
}
function delete_submit($values) {
function delete_submit(Pieform $form, $values) {
global $SESSION;
db_begin();
......@@ -59,7 +59,7 @@ if ($institution || $add) {
db_commit();
$SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
redirect(get_config('wwwroot') . 'admin/users/institutions.php');
redirect('admin/users/institutions.php');
}
$form = array(
'name' => 'delete',
......@@ -193,7 +193,7 @@ else {
$smarty->assign('institutions', $institutions);
}
function institution_submit($values) {
function institution_submit(Pieform $form, $values) {
global $SESSION, $institution, $add;
log_debug($values);
......@@ -238,7 +238,7 @@ function institution_submit($values) {
}
function institution_cancel_submit() {
redirect(get_config('wwwroot') . 'admin/users/institutions.php');
redirect('admin/users/institutions.php');
}
$smarty->display('admin/users/institutions.tpl');
......
......@@ -59,8 +59,7 @@ foreach ($methods as $m) {
$form = array(
'name' => 'adminnotifications',
'method' => 'post',
'ajaxpost' => true,
'jsform' => true,
'plugintype' => 'core',
'pluginname' => 'admin',
'renderer' => 'multicolumntable',
......@@ -100,7 +99,7 @@ $smarty = smarty();
$smarty->assign('form', pieform($form));
$smarty->display('admin/users/notifications.tpl');
function adminnotifications_submit($values, Pieform $form) {
function adminnotifications_submit(Pieform $form, $values) {
foreach ($values as $key => $value) {
if (!preg_match('/^admin\-(\d+)\-([a-z]+)$/', $key, $m)) {
continue;
......
......@@ -39,8 +39,6 @@ $staffusers = get_column('usr', 'id', 'staff', 1);
$form = array(
'name' => 'staffusers',
'method' => 'post',
'action' => '',
'elements' => array(
'users' => array(
'type' => 'userlist',
......@@ -55,7 +53,7 @@ $form = array(
)
);
function staffusers_submit($values) {
function staffusers_submit(Pieform $form, $values) {
global $SESSION;
$table = get_config('dbprefix') . 'usr';
......
......@@ -77,7 +77,7 @@ $smarty->assign('buttonform', $form->build(false));
$smarty->display('admin/users/suspended.tpl');
function buttons_submit_unsuspend($values) {
function buttons_submit_unsuspend(Pieform $form, $values) {
global $SESSION;
$ids = get_user_ids_from_post();
......@@ -86,17 +86,17 @@ function buttons_submit_unsuspend($values) {
}
$SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
redirect('admin/users/suspended.php');
}
function buttons_submit_export($values) {
function buttons_submit_export(Pieform $form, $values) {
global $SESSION;
$ids = get_user_ids_from_post();
$SESSION->add_info_msg(get_string('exportingnotsupportedyet'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
redirect('admin/users/suspended.php');
}
function buttons_submit_delete($values) {
function buttons_submit_delete(Pieform $form, $values) {
global $SESSION;
$ids = get_user_ids_from_post();
......@@ -105,7 +105,7 @@ function buttons_submit_delete($values) {
}
$SESSION->add_ok_msg(get_string('usersdeletedsuccessfully'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
redirect('admin/users/suspended.php');
}
function get_user_ids_from_post() {
......@@ -119,7 +119,7 @@ function get_user_ids_from_post() {
if (!$ids) {
global $SESSION;
$SESSION->add_info_msg(get_string('nousersselected'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
redirect('admin/users/suspended.php');
}
return $ids;
......
......@@ -58,8 +58,6 @@ else {
$form = array(
'name' => 'uploadcsv',
'method' => 'post',
'action' => '',
'elements' => array(
'institution' => $institutionelement,
'file' => array(
......@@ -158,7 +156,7 @@ function uploadcsv_validate(Pieform $form, $values) {
* Add the users to the system. Make sure that they have to change their
* password on next login also.
*/
function uploadcsv_submit($values) {
function uploadcsv_submit(Pieform $form, $values) {
global $SESSION, $CSVDATA;
log_info('Inserting users from the CSV file');
foreach ($CSVDATA as $record) {
......@@ -181,8 +179,7 @@ function uploadcsv_submit($values) {
log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin'));
// @todo support relative URLs here
redirect(get_config('wwwroot') . 'admin/users/uploadcsv.php');
redirect('admin/users/uploadcsv.php');
}
$smarty = smarty();
......
......@@ -101,7 +101,7 @@ $form = pieform(array(
'description' => array(
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 80,
'cols' => 70,
'title' => get_string('postbody', 'artefact.blog'),
'description' => get_string('postbodydesc', 'artefact.blog'),
'rules' => array(
......@@ -113,7 +113,7 @@ $form = pieform(array(
'type' => 'checkbox',
'title' => get_string('thisisdraft', 'artefact.blog'),
'description' => get_string('thisisdraftdesc', 'artefact.blog'),
'checked' => $checked
'defaultvalue' => $checked
),
)
));
......@@ -150,7 +150,7 @@ $wwwroot = get_config('wwwroot');
* Javascript specific to this page. Creates the list of files
* attached to the blog post.
*/
$javascript = <<< EOF
$javascript = <<<EOF
......@@ -274,7 +274,7 @@ $smarty->display('artefact:blog:editpost.tpl');
*
* @param array
*/
function editpost_submit(array $values) {
function editpost_submit(Pieform $form, array $values) {
global $USER;
$values['published'] = !$values['thisisdraft'];
......
......@@ -34,7 +34,7 @@ safe_require('artefact', 'blog');
$wwwroot = get_config('wwwroot');
// This JavaScript creates a table to display the blog entries.
$js = <<<EOJAVASCRIPT
$js = <<<EOF
var bloglist = new TableRenderer(
'bloglist',
......@@ -56,7 +56,7 @@ var bloglist = new TableRenderer(
bloglist.updateOnLoad();
EOJAVASCRIPT;
EOF;
$smarty = smarty(array('tablerenderer'));
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
......
......@@ -47,7 +47,7 @@ $form = pieform(array(
'description' => array(
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 80,
'cols' => 70,
'title' => get_string('blogdesc', 'artefact.blog'),
'description' => get_string('blogdescdesc', 'artefact.blog'),
'rules' => array(
......@@ -92,7 +92,7 @@ exit;
*
* @param array
*/
function newblog_submit($values) {
function newblog_submit(Pieform $form, $values) {
global $USER;
ArtefactTypeBlog::new_blog($USER, $values);
......
......@@ -56,7 +56,7 @@ $form = pieform(array(
'description' => array(
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 80,
'cols' => 70,
'title' => get_string('postbody', 'artefact.blog'),
'description' => get_string('postbodydesc', 'artefact.blog'),
'rules' => array(
......@@ -91,7 +91,7 @@ exit;
*
* @param array
*/
function newpost_submit_saveandpublish(array $values) {
function newpost_submit_saveandpublish(Pieform $form, array $values) {
global $USER;
$values['published'] = true;
......@@ -104,7 +104,7 @@ function newpost_submit_saveandpublish(array $values) {
*
* @param array
*/
function newpost_submit_saveasdraft(array $values) {
function newpost_submit_saveasdraft(Pieform $form, array $values) {
global $USER;
$values['published'] = false;
......
......@@ -57,7 +57,7 @@ $form = pieform(array(
'description' => array(
'type' => 'wysiwyg',
'rows' => 10,
'cols' => 80,
'cols' => 70,
'title' => get_string('blogdesc', 'artefact.blog'),
'description' => get_string('blogdescdesc', 'artefact.blog'),
'rules' => array(
......@@ -104,7 +104,7 @@ exit;
/**
* This function is called to update the blog details.
*/
function editblog_submit($values) {
function editblog_submit(Pieform $form, $values) {
global $USER;
ArtefactTypeBlog::edit_blog($USER, $values);
......
......@@ -17,11 +17,11 @@
<div class="maincontent">
<div id="myblogs">
<h2>{str section="artefact.blog" tag="myblogs"}</h2>
<div class="newblog">
<a href="{$WWWROOT}/artefact/blog/new/">{str section="artefact.blog" tag="addblog"}</a>
<div class="addicon">
<a href="{$WWWROOT}artefact/blog/new/">{str section="artefact.blog" tag="addblog"}</a>
</div>
<table id="bloglist">
<table id="bloglist" class="tablerenderer">
<thead>
<tr>
<th>{str section="artefact.blog" tag="title"}</th>
......@@ -32,8 +32,8 @@
</tbody>
</table>
<div class="newblog">
<a href="{$WWWROOT}/artefact/blog/new/">{str section="artefact.blog" tag="addblog"}</a>
<div class="addicon">
<a href="{$WWWROOT}artefact/blog/new/">{str section="artefact.blog" tag="addblog"}</a>
</div>
</div>
......
{*
This template displays the settings for a user's blog.
*}{include file="header.tpl"}
{include file="header.tpl"}
<div id="column-right">
{include file="adminmenu.tpl"}
</div>
<div class="content">
<h2>{str section="artefact.blog" tag="blogsettings"}</h2>
<div id="column-left">
<div class="content">
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str section="artefact.blog" tag="blogsettings"}</h2>
<div>
<a href="{$WWWROOT}artefact/blog/view/?id={$blog->get('id')}">{str section="artefact.blog" tag="viewblog"}</a>
</div>
<div>
<a href="{$WWWROOT}artefact/blog/view/?id={$blog->get('id')}">{str section="artefact.blog" tag="viewblog"}</a>
</div>
{$editform}
{$editform}
</div>
</span></span></span></span></div>
</div>
</div>
{include file="footer.tpl"}
......@@ -21,19 +21,19 @@
<a href="{$WWWROOT}artefact/blog/settings/?id={$blog->get('id')}">{str section="artefact.blog" tag="settings"}</a>
</div>
<div class="newpost">
<a href="{$WWWROOT}/artefact/blog/editpost.php?blog={$blog->get('id')}">{str section="artefact.blog" tag="addpost"}</a>
<div class="addicon">
<a href="{$WWWROOT}artefact/blog/editpost.php?blog={$blog->get('id')}">{str section="artefact.blog" tag="addpost"}</a>
</div>
<table id="postlist">
<table id="postlist" class="tablerenderer">
<thead>
</thead>
<tbody>
</tbody>
</table>
<div class="newpost">
<a href="{$WWWROOT}/artefact/blog/editpost.php?blog={$blog->get('id')}">{str section="artefact.blog" tag="addpost"}</a>
<div class="addicon">
<a href="{$WWWROOT}artefact/blog/editpost.php?blog={$blog->get('id')}">{str section="artefact.blog" tag="addpost"}</a>
</div>
</div>
......
......@@ -11,7 +11,7 @@
<h2>{str section="artefact.file" tag="myfiles"}</h2>
<div id="myfiles">
<div id="uploader"></div>
<table id="filelist">
<table id="filelist" class="tablerenderer">
<thead><tr>
<th>{str tag=name section=artefact.file}</th>
<th>{str tag=description section=artefact.file}</th>
......
......@@ -81,6 +81,8 @@ foreach ( $element_list as $element => $type ) {
}
if ($element == 'country') {
$elements[$element]['options'] = getoptions_country();
// @todo configure default country somehow...
$elements[$element]['defaultvalue'] = 'nz';
}
if (isset($profilefields[$element])) {
......@@ -101,7 +103,7 @@ $profileform = pieform(array(
'name' => 'profileform',
'plugintype' => 'artefact',
'pluginname' => 'internal',
'ajaxpost' => true,
'jsform' => true,
'method' => 'post',
'elements' => $elements,
));
......@@ -118,7 +120,7 @@ function profileform_validate(Pieform $form, $values) {
}
}
function profileform_submit($values, Pieform $form) {
function profileform_submit(Pieform $form, $values) {
global $SESSION;
global $USER;
global $element_list;
......
......@@ -8,6 +8,7 @@
<div class="content">
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<div class="fr"><a href="profileicons.php">{str tag="editprofileicons" section="artefact.internal"} &raquo;</a></div>
<h2>{str section="artefact.internal" tag="profile"}</h2>
{$profileform}
......
......@@ -170,10 +170,6 @@ function auth_setup () {
}
auth_draw_login_page(get_string('sessiontimedout'));
// The auth_draw_login_page function may authenticate a user if a login
// request was sent at the same time that the "timed out" message is to
// be displayed.
//return $USER;
}
else {
// There is no session, so we check to see if one needs to be started.
......@@ -463,13 +459,14 @@ function auth_get_login_form() {
}
$form = array(
'name' => 'login',
'method' => 'post',
'action' => $action,
'plugintype' => 'auth',
'pluginname' => 'internal',
'elements' => $elements,
'iscancellable' => false
'name' => 'login',
'method' => 'post',
'action' => $action,
'plugintype' => 'auth',
'pluginname' => 'internal',
'elements' => $elements,
'dieaftersubmit' => false,
'iscancellable' => false
);
return $form;
......@@ -480,8 +477,8 @@ function auth_get_login_form() {
* javascript is used to detect whether cookies are enabled, and not show the
* login form if they are not.