changes to how we generate the id attribute of forms and the naming convention of forms

migrate blog edit to formslib
This commit is contained in:
jamiesensei
2006-12-28 09:32:45 +00:00
parent ccbcb1a893
commit f07b9627b6
29 changed files with 428 additions and 366 deletions
-194
View File
@@ -1,194 +0,0 @@
<?php //$Id$
// find all the tags this post uses
$usedtags = array();
if (!empty($post->id)) {
if ($tagsused = get_records('blog_tag_instance', 'entryid', $post->id)) {
foreach ($tagsused as $usedtag) {
$usedtags[] = $usedtag -> tagid;
}
}
}
if ($usehtmleditor) {
// clean and convert to html before editting
$options = new object();
$options->smiley = false;
$options->filter = false;
$options->nocache = true;
$post->summary = format_text($post->summary, $post->format, $options);
}
?>
<form name="entry" method="post" action="edit.php" enctype="multipart/form-data">
<table border="0" cellpadding="5">
<tr valign="top">
<td align="right">&nbsp;
</td>
<td colspan="2"><strong><?php echo $strformheading; ?></strong>
</td>
</tr>
<tr valign="top">
<td align="right"><strong><?php print_string('entrytitle', 'blog'); ?>:</strong></td>
<td colspan="2">
<input type="text" name="subject" size="60" value="<?php p($post->subject) ?>" />
<?php if (isset($errors["subject"])) formerr($errors["subject"]); ?>
</td>
</tr>
<tr valign="top">
<td align="right"><strong>
<?php
print_string('entrybody', 'blog');
?>:
</strong><br /><br />
<small><small>
<?php
helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
echo '<br />';
if ($usehtmleditor) {
helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true);
} else {
emoticonhelpbutton('entry', 'body');
}
?>
</small></small>
</td>
<td align="left" colspan="2">
<?php print_textarea($usehtmleditor, 25, 62, 500, 600, 'summary', $post->summary); ?>
</td>
</tr>
<tr valign="top">
<td align="right"><strong><?php print_string('formattexttype'); ?>:</strong></td>
<td colspan="2">
<?php
if ($usehtmleditor) { /// Trying this out for a while
print_string('formathtml');
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
} else {
choose_from_menu(format_text_menu(), 'format', $post->format, '');
}
?>
<small><small>
<?php
helpbutton('textformat', get_string('helpformatting'));
?>
</small></small>
<?php if (isset($errors["summary"])) formerr($errors["summary"]); ?>
</td>
</tr>
<tr valign="top">
<td align="right">
<strong><?php print_string('tags'); echo ':';?></strong>
</td>
<td>
<table width="100%">
<tr>
<td>
<b><?php print_string('otags','blog'); ?></b>
</td>
<td>
<b><?php print_string('ptags','blog'); ?></b>
</td>
</tr>
<tr>
<td>
<select name="otags[]" multiple="multiple" size="8">
<?php
$otags = get_records_sql('SELECT * from '.$CFG->prefix.'tags WHERE type=\'official\' ORDER by text ASC');
foreach ($otags as $otag) {
if (in_array($otag->id, $usedtags)) {
echo '<option value="'.$otag->id.'" selected="selected">'.$otag->text.'</option>';
} else {
echo '<option value="'.$otag->id.'">'.$otag->text.'</option>';
}
}
?>
</select>
&nbsp;&nbsp;</td>
<td>
<?php
if (!empty($post->id)) {
$idsql = " AND bti.entryid = {$post->id}";
} else {
$idsql = " AND bti.entryid = 0";
}
$pptag = '';
if ($ptags = get_records_sql("SELECT t.* FROM
{$CFG->prefix}tags t,
{$CFG->prefix}blog_tag_instance bti
WHERE t.id = bti.tagid
AND t.type = 'personal'
$idsql")) {
foreach ($ptags as $ptag) {
$pptag .= $ptag->text.',';
}
$pptag = rtrim($pptag, ",");
}
?>
<input type="text" name="ptags" value="<?php echo $pptag;?>"/>
<?php
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
// only make sense to link if the user has capablity
if (has_capability('moodle/blog:managepersonaltags', $sitecontext) || has_capability('moodle/blog:manageofficialtags', $sitecontext)) {
echo "<br/>";
link_to_popup_window("/blog/tags.php",'popup',get_string('tagmanagement'));
}
?>
</td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("attachment", "forum") ?>:<br />(<?php print_string("optional") ?>)&nbsp;</b></td>
<td>
<?php $maxbytes = get_max_upload_file_size($CFG->maxbytes); ?>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>" />
<input type="file" name="attachment" size="40" alt="<?php print_string("attachment", "forum") ?>" />
<?php
print_string("maxsize", "", display_size($maxbytes));
?>
</td>
</tr>
<tr valign="top">
<td align="right">
<strong><?php print_string('publishto', 'blog'); ?>:</strong>
</td>
<td colspan="2">
<?php
$options = blog_applicable_publish_states(); //$blogEntry may be null
choose_from_menu($options, 'publishstate', $post->publishstate, '');
?>
<?php
helpbutton('publish_state', get_string('helppublish', 'blog'), 'blog');
?>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
<input type="hidden" name="action" value="<?php echo $action; ?>" />
<input type="hidden" name="courseid" value="<?php echo $courseid; ?>" />
<?php
if ($action == 'add') {
?>
<input type="hidden" name="action" value="add" />
<input type="submit" value="<?php print_string('add'); ?>" />&nbsp;
<input type="button" value="<?php print_string('cancel'); ?>" onclick="javascript:history.go(-1)" />
<?php
} else { ?>
<input type="hidden" name="id" value="<?php echo $post->id; ?>" />
<input type="submit" value="<?php print_string('savechanges'); ?>" />&nbsp;
<input type="button" value="<?php print_string('cancel'); ?>" onclick="javascript:history.go(-1)" />
<?php } ?>
</td>
</tr>
</table>
</form>
+167 -103
View File
@@ -46,81 +46,104 @@ if (!empty($courseid)) {
$returnurl .= '&amp;courseid='.$courseid;
}
$errors = array();
$post = new object(); // editing form data
$usehtmleditor = can_use_richtext_editor();
$strblogs = get_string('blogs','blog');
/// Main switch for processing blog entry
switch ($action) {
if ($action=='delete'){
if (!$existing) {
error('Incorrect blog post id');
}
if (data_submitted() and $confirm and confirm_sesskey()) {
do_delete($existing);
redirect($returnurl);
} else {
$optionsyes = array('id'=>$id, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'courseid'=>$courseid);
$optionsno = array('userid'=>$existing->userid, 'courseid'=>$courseid);
print_header("$SITE->shortname: $strblogs", $SITE->fullname);
blog_print_entry($existing);
echo '<br />';
notice_yesno(get_string('blogdeleteconfirm', 'blog'), 'edit.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
print_footer();
die;
}
}
case 'add':
if (data_submitted() and confirm_sesskey()) {
do_add($post, $errors);
if (empty($errors)) {
redirect($returnurl);
require_once('edit_form.php');
$blogpostform = new blog_post_form(null, compact('existing', 'sitecontext'));
if ($blogpostform->is_cancelled()){
redirect($returnurl);
} elseif ($blogpostform->no_submit_button_pressed()) {
no_submit_button_actions($blogpostform, $sitecontext);
} elseif ($fromform = $blogpostform->data_submitted()){
//save stuff in db
switch ($action) {
case 'add':
do_add($fromform);
break;
case 'edit':
if (!$existing) {
error('Incorrect blog post id');
}
$post = stripslashes_safe($post); // no db access after this!!
// print form again
} else {
// prepare new empty form
$post->subject = '';
$post->summary = '';
$post->publishstate = 'draft';
$post->format = $usehtmleditor ? FORMAT_HTML : FORMAT_MOODLE;
do_edit($fromform);
break;
default :
error('Unknown action!');
}
redirect($returnurl);
}
}
// gui setup
switch ($action) {
case 'add':
// prepare new empty form
$post->publishstate = 'draft';
$strformheading = get_string('addnewentry', 'blog');
$post->action = $action;
break;
case 'edit':
if (!$existing) {
error('Incorrect blog post id');
}
if (data_submitted() and confirm_sesskey()) {
do_edit($post, $errors);
if (empty($errors)) {
redirect($returnurl);
}
$post = stripslashes_safe($post); // no db access after this!!
// print form again
} else {
$post->id = $existing->id;
$post->subject = $existing->subject;
$post->summary = $existing->summary;
$post->publishstate = $existing->publishstate;
$post->format = $existing->format;
}
$post->id = $existing->id;
$post->subject = $existing->subject;
$post->summary = $existing->summary;
$post->publishstate = $existing->publishstate;
$post->format = $existing->format;
$post->action = $action;
$strformheading = get_string('updateentrywithid', 'blog');
break;
case 'delete':
if (!$existing) {
error('Incorrect blog post id');
}
if (data_submitted() and $confirm and confirm_sesskey()) {
do_delete($existing);
redirect($returnurl);
if ($ptags = get_records_sql_menu("SELECT t.id, t.text FROM
{$CFG->prefix}tags t,
{$CFG->prefix}blog_tag_instance bti
WHERE t.id = bti.tagid
AND t.type = 'personal'
AND bti.entryid = {$post->id}")) {
$post->ptags = implode(', ', $ptags);
} else {
$optionsyes = array('id'=>$id, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'courseid'=>$courseid);
$optionsno = array('userid'=>$existing->userid, 'courseid'=>$courseid);
print_header("$SITE->shortname: $strblogs", $SITE->fullname);
blog_print_entry($existing);
echo '<br />';
notice_yesno(get_string('blogdeleteconfirm', 'blog'), 'edit.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
print_footer();
die;
//$idsql = " AND bti.entryid = 0";
//was used but seems redundant.
$post->ptags = '';
}
if ($otags = get_records_sql_menu("SELECT t.id, t.text FROM
{$CFG->prefix}tags t,
{$CFG->prefix}blog_tag_instance bti
WHERE t.id = bti.tagid
AND t.type = 'official'
AND bti.entryid = {$post->id}")){
$post->otags = array_keys($otags);
}
break;
default:
default :
error('Unknown action!');
break;
}
// gui setup
// done here in order to allow deleting of posts with wrong user id above
if (!$user = get_record('user', 'id', $userid)) {
error('Incorrect user id');
@@ -129,21 +152,87 @@ if (!$user = get_record('user', 'id', $userid)) {
print_header("$SITE->shortname: $strblogs", $SITE->fullname,
'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'">'.fullname($user).'</a> ->
<a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$userid.'">'.$strblogs.'</a> -> '.$strformheading,'','',true);
$blogpostform->set_defaults($post);
$blogpostform->display();
echo '<br />';
print_simple_box_start('center');
require('edit.html');
print_simple_box_end();
if ($usehtmleditor) {
use_html_editor();
}
print_footer();
die;
/***************************** edit.php functions ***************************/
function no_submit_button_actions(&$blogpostform, $sitecontext){
$mform =& $blogpostform->_form;
$data = $mform->exportValues();
//sesskey has been checked already no need to check that
//check for official tags to add
if (!empty($data['addotags']) && !empty($data['otagsadd'])){ // adding official tag
$error = add_otag($data['otagsadd']);
}
if (!empty($error)){
$mform->setElementError('otagsgrp', $error);
}
if (!empty($data['deleteotags']) && !empty($data['otags'])){ // adding official tag
delete_otags($data['otags'], $sitecontext);
}
$blogpostform->otags_select_setup();
}
function delete_otags($tagids, $sitecontext){
foreach ($tagids as $tagid) {
if (!$tag = get_record('tags', 'id', $tagid)) {
error('Can not delete tag, tag doesn\'t exist');
}
if ($tag->type == 'official' and !has_capability('moodle/blog:manageofficialtags', $sitecontext)) {
//can not delete
error('Can not delete tag, you don\'t have permission to delete an official tag');
}
if ($tag->type == 'personal' and !has_capability('moodle/blog:managepersonaltags', $sitecontext)) {
//can not delete
error('Can not delete tag, you don\'t have permission to delete a personal tag');
}
// Delete the tag itself
if (!delete_records('tags', 'id', $tagid)) {
error('Can not delete tag');
}
// Deleteing all references to this tag
if (!delete_records('blog_tag_instance', 'tagid', $tagid)) {
error('Can not delete blog tag instances');
}
}
}
function add_otag($otag){
global $USER;
$error = '';
if ($tag = get_record('tags', 'text', $otag)) {
if ($tag->type == 'official') {
// official tag already exist
$error = get_string('tagalready');
} else {
$tag->type = 'official';
update_record('tags', $tag);
$tagid = $tag->id;
}
} else { // Brand new offical tag
$tag = new object();
$tag->userid = $USER->id;
$tag->text = $otag;
$tag->type = 'official';
if (!$tagid = insert_record('tags', $tag)) {
error('Can not create tag!');
}
}
return $error;
}
/*
* Delete blog post from database
*/
@@ -163,14 +252,9 @@ function do_delete($post) {
/**
* Write a new blog entry into database
*/
function do_add(&$post, &$errors) {
function do_add($post) {
global $CFG, $USER, $returnurl;
$post->subject = required_param('subject', PARAM_MULTILANG);
$post->summary = required_param('summary', PARAM_RAW);
$post->format = required_param('format', PARAM_INT);
$post->publishstate = required_param('publishstate', PARAM_ALPHA);;
if ($post->summary == '<br />') {
$post->summary = '';
}
@@ -190,16 +274,16 @@ function do_add(&$post, &$errors) {
$post->userid = $USER->id;
$post->lastmodified = time();
$post->created = time();
// Insert the new blog entry.
if ($id = insert_record('post', $post)) {
$post->id = $id;
// add blog attachment
if ($post->attachment = blog_add_attachment($post, 'attachment',$message)) {
set_field("post", "attachment", $post->attachment, "id", $post->id);
}
}
add_tags_info($post->id);
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$post->userid.'&postid='.$posz->id, $post->subject);
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject);
} else {
error('There was an error adding this post in the database', $returnurl);
@@ -212,52 +296,32 @@ function do_add(&$post, &$errors) {
* @param . $bloginfo_arg argument is reference to a blogInfo object.
* @todo complete documenting this function. enable trackback and pingback between entries on the same server
*/
function do_edit(&$post, &$errors) {
function do_edit($post) {
global $CFG, $USER, $returnurl;
$post->id = required_param('id', PARAM_INT);
$post->subject = required_param('subject', PARAM_MULTILANG);
$post->summary = required_param('summary', PARAM_RAW);
$post->format = required_param('format', PARAM_INT);
$post->publishstate = required_param('publishstate', PARAM_ALPHA);;
if ($post->summary == '<br />') {
$post->summary = '';
}
if ($post->subject == '') {
$errors['subject'] = get_string('emptytitle', 'blog');
}
if ($post->summary == '') {
$errors['summary'] = get_string('emptybody', 'blog');
}
if (!empty($errors)) {
return; // no saving
}
$post->lastmodified = time();
/* TODO add attachment processing
if ($newfilename = blog_add_attachment($post, 'attachment',$message)) {
$post->attachment = $newfilename;
} else {
unset($post->attachment);
}
}*/
// update record
if (update_record('post', $post)) {
// delete all tags associated with this entry
delete_records('blog_tag_instance', 'entryid', $post->id);
// add them back
add_tags_info($post->id);
add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject);
} else {
error('There was an error updating this post in the database', $returnurl);
}
}
/**
@@ -265,18 +329,18 @@ function do_edit(&$post, &$errors) {
* @param int postid - id of the blog
*/
function add_tags_info($postid) {
global $USER;
$post = get_record('post', 'id', $postid);
$tag = new object();
$tag->entryid = $post->id;
$tag->userid = $post->userid;
$tag->timemodified = time();
/// Attach official tags
if ($otags = optional_param('otags','', PARAM_INT)) {
if ($otags = optional_param('otags', '', PARAM_INT)) {
foreach ($otags as $otag) {
$tag->tagid = $otag;
insert_record('blog_tag_instance', $tag);
@@ -284,8 +348,8 @@ function add_tags_info($postid) {
}
/// Attach Personal Tags
if ($ptags = optional_param('ptags','', PARAM_NOTAGS)) {
$ptags = explode(',',$ptags);
if ($ptags = optional_param('ptags', '', PARAM_NOTAGS)) {
$ptags = explode(',', $ptags);
foreach ($ptags as $ptag) {
$ptag = trim($ptag);
// check for existance
@@ -302,7 +366,7 @@ function add_tags_info($postid) {
if ($tagid = insert_record('tags', $ctag)) {
$tag->tagid = $tagid;
insert_record('blog_tag_instance', $tag);
}
}
}
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php // $Id$
require_once($CFG->libdir.'/formslib.php');
class blog_edit_form extends moodleform {
function definition() {
global $CFG, $COURSE, $USER;
$mform =& $this->_form;
$post = $this->_customdata['existing'];
$sitecontext = $this->_customdata['sitecontext'];
// the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
$this->_upload_manager = new upload_manager('attachment', true, false, $COURSE, false, 0, true, true);
$this->set_max_file_size($COURSE);
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
$mform->addElement('htmleditor', 'summary', get_string('entrybody', 'blog'), array('rows'=>25));
$mform->setType('summary', PARAM_RAW);
$mform->addRule('summary', get_string('emptybody', 'blog'), 'required', null, 'client');
$mform->addElement('format', 'format', get_string('format'));
$mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
$mform->addElement('select', 'publishstate', get_string('publishto', 'blog'), blog_applicable_publish_states());
$mform->setHelpButton('publishstate', array('publish_state', get_string('helppublish', 'blog'), 'blog'));
$mform->addElement('header', 'tagshdr', get_string('tags', 'blog'));
$mform->createElement('select', 'otags', get_string('otags','blog'));
$js_escape = array(
"\r" => '\r',
"\n" => '\n',
"\t" => '\t',
"'" => "\\'",
'"' => '\"',
'\\' => '\\\\'
);
$otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'blog'), array(), 'size="5"');
$otagsselEl->setMultiple(true);
$this->otags_select_setup();
if (has_capability('moodle/blog:manageofficialtags', $sitecontext)){
$deleteotagsmsg = strtr(get_string('deleteotagswarn', 'blog'), $js_escape);
$mform->registerNoSubmitButton('deleteotags');
$mform->addElement('submit', 'deleteotags', get_string('delete'),
array('onclick'=>"return confirm('$deleteotagsmsg');"));
$mform->disabledIf('deleteotags', 'otags[]', 'noitemselected');
$mform->setAdvanced('deleteotags');
$mform->registerNoSubmitButton('addotags');
$otagsgrp = array();
$otagsgrp[] =& $mform->createElement('text', 'otagsadd', get_string('addotags', 'blog'));
$otagsgrp[] =& $mform->createElement('submit', 'addotags', get_string('add'));
$mform->addGroup($otagsgrp, 'otagsgrp', get_string('addotags','blog'), array(' '), false);
$mform->setType('otagsadd', PARAM_NOTAGS);
$mform->setAdvanced('otagsgrp');
}
$mform->addElement('textarea', 'ptags', get_string('ptags', 'blog'), array('wrap'=>'soft'));
$mform->setType('ptagsadd', PARAM_NOTAGS);
$this->add_action_buttons();
$mform->addElement('hidden', 'action');
$mform->setType('action', PARAM_ACTION);
$mform->setDefault('action', '');
$mform->addElement('hidden', 'courseid');
$mform->setType('courseid', PARAM_INT);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', 0);
}
/**
* This function sets up options of otag select element. This is called from definition and also
* after adding new official tags with the add tag button.
*
*/
function otags_select_setup(){
global $CFG;
$mform =& $this->_form;
$otagsselect =& $mform->getElement('otags');
$otagsselect->removeOptions();
if ($otags = get_records_sql_menu('SELECT id, text from '.$CFG->prefix.'tags WHERE type=\'official\' ORDER by text ASC')){
$otagsselect->loadArray($otags);
}
}
}
?>
+1 -1
View File
@@ -125,6 +125,7 @@
$mformclassname=$module->name.'_mod_form';
$cousesection=isset($cw->section)?$cw->section:$section;
$mform=& new $mformclassname($form->instance, $cousesection, ((isset($cm))?$cm:null));
$mform->set_defaults($form);
if ($mform->is_cancelled()) {
if ($return && isset($cm)){
@@ -276,7 +277,6 @@
$icon = '<img align="middle" height="16" width="16" src="'.$CFG->modpixpath.'/'.$module->name.'/icon.gif" alt="" style="vertical-align: middle;" />&nbsp;';
print_heading_with_help($pageheading, "mods", $module->name, $icon);
$mform->set_defaults($form);
$mform->display();
print_footer($course);
}
+1 -1
View File
@@ -2,7 +2,7 @@
require_once($CFG->libdir.'/formslib.php');
class authorize_enrol_form extends moodleform
class enrol_authorize_enrol_form extends moodleform
{
function definition()
{
+3 -1
View File
@@ -1,4 +1,4 @@
<?PHP // $Id$
<?PHP // $Id$
// blog.php - created with Moodle 1.7 beta + (2006101003)
@@ -15,6 +15,7 @@ $string['blogs'] = 'Blogs';
$string['blogtags'] = 'Blog Tags';
$string['courseblog'] = 'Course blog: $a';
$string['courseblogs'] = 'Users can only see blogs for people who share a course';
$string['deleteotagswarn'] = 'Are you sure you want to remove this / these tags \nfrom all blog posts and remove it from the system?';
$string['disableblogs'] = 'Disable blog system completely';
$string['emptybody'] = 'Blog entry body can not be empty';
$string['emptytitle'] = 'Blog entry title can not be empty';
@@ -47,6 +48,7 @@ $string['siteblogs'] = 'All site users can see all blog entries';
$string['tagdatelastused'] = 'Date tag was last used';
$string['tagsort'] = 'Sort the tag display by';
$string['tagtext'] = 'Tag text';
$string['tags'] = 'Tags';
$string['timewithin'] = 'Display tags used within this many days';
$string['updateentrywithid'] = 'Updating entry';
$string['userblog'] = 'User blog: $a';
+5 -4
View File
@@ -928,16 +928,16 @@ $string['newuser'] = 'New user';
$string['newusernewpasswordsubj'] = 'New user account';
$string['newusernewpasswordtext'] = 'Hi $a->firstname,
A new account has been created for you at \'$a->sitename\'
A new account has been created for you at \'$a->sitename\'
and you have been issued with a new temporary password.
Your current login information is now:
username: $a->username
password: $a->newpassword
(you will have to change your password
(you will have to change your password
when you login for the first time)
To start using \'$a->sitename\', login at
To start using \'$a->sitename\', login at
$a->link
In most mail programs, this should appear as a blue link
@@ -975,7 +975,7 @@ $string['nopotentialcreators'] = 'No potential course creators';
$string['nopotentialstudents'] = 'No potential students';
$string['nopotentialteachers'] = 'No potential teachers';
$string['norecentactivity'] = 'No recent activity';
$string['noreplybouncemessage'] = 'You have replied to a no-reply email address. If you were attempting to reply to a forum post, please instead reply using the $a forums.
$string['noreplybouncemessage'] = 'You have replied to a no-reply email address. If you were attempting to reply to a forum post, please instead reply using the $a forums.
Following is the content of your email:';
$string['noreplybouncesubject'] = '$a - bounced email.';
@@ -1325,6 +1325,7 @@ $string['supplyinfo'] = 'Please supply some information about yourself';
$string['switchrolereturn'] = 'Return to my normal role';
$string['switchroleto'] = 'Switch role to...';
$string['tag'] = 'Tag';
$string['tagalready'] = 'This tag already exists';
$string['tagmanagement'] = 'Add/delete tags ...';
$string['tags'] = 'Tags';
$string['targetrole'] = 'Target role';
+100 -12
View File
@@ -49,6 +49,7 @@ if ($CFG->debug >= DEBUG_ALL){
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_handle_error');
}
/**
* Moodle specific wrapper that separates quickforms syntax from moodle code. You won't directly
* use this class you should write a class defintion which extends this class or a more specific
@@ -107,7 +108,8 @@ class moodleform {
if (empty($action)){
$action = strip_querystring(qualified_me());
}
//strip '_form' from the end of class name to make form 'id' attribute.
//strip '_form' from the end of class name to make form name attribute.
$this->_formname = preg_replace('/_form$/', '', get_class($this), 1);
$this->_customdata = $customdata;
$this->_form =& new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes);
@@ -279,6 +281,9 @@ class moodleform {
}
$mform =& $this->_form;
$nosubmit = false;
if (!$this->is_submitted()){
return false;
}
foreach ($mform->_noSubmitButtons as $nosubmitbutton){
if (optional_param($nosubmitbutton, 0, PARAM_RAW)){
$nosubmit = true;
@@ -297,9 +302,7 @@ class moodleform {
function is_validated() {
static $validated = null; // one validation is enough
$mform =& $this->_form;
if ($this->no_submit_button_pressed()){
return false;
}
if ($validated === null) {
$internal_val = $mform->validate();
$moodle_val = $this->validation($mform->exportValues(null, true));
@@ -324,7 +327,11 @@ class moodleform {
}
$validated = ($internal_val and $moodle_val and $file_val);
}
return $validated;
if ($this->no_submit_button_pressed()){
return false;
} else {
return $validated;
}
}
/**
@@ -576,6 +583,15 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
*/
var $_showAdvanced = null;
/**
* The form name is derrived from the class name of the wrapper minus the trailing form
* It is a name with words joined by underscores whereas the id attribute is words joined by
* underscores.
*
* @var unknown_type
*/
var $_formName = '';
/**
* Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless
* @param string $formName Form's name.
@@ -591,8 +607,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
HTML_Common::HTML_Common($attributes);
$target = empty($target) ? array() : array('target' => $target);
$this->_formName = $formName;
//no 'name' atttribute for form in xhtml strict :
$attributes = array('action'=>$action, 'method'=>$method, 'id'=>$formName) + $target;
$attributes = array('action'=>$action, 'method'=>$method, 'id'=>strtr($formName, '_', '-')) + $target;
$this->updateAttributes($attributes);
//this is custom stuff for Moodle :
@@ -648,9 +665,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
return;
} else { //if setShowAdvanced is called without any preference
//make the default to not show advanced elements.
$showadvancedNow = 0;
$showadvancedNow = get_user_preferences(
moodle_strtolower($this->_formName.'_showadvanced', 0));
}
}
//value of hidden element
$hiddenLast = optional_param('mform_showadvanced_last', -1, PARAM_INT);
@@ -665,6 +682,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
$next = $hiddenLast;
}
$this->_showAdvanced = $next;
if ($showadvancedNow != $next){
set_user_preference($this->_formName.'_showadvanced', $next);
}
$this->setConstants(array('mform_showadvanced_last'=>$next));
}
function getShowAdvanced(){
@@ -858,6 +878,74 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
return $unfiltered;
}
}
/**
* Adds a validation rule for the given field
*
* If the element is in fact a group, it will be considered as a whole.
* To validate grouped elements as separated entities,
* use addGroupRule instead of addRule.
*
* @param string $element Form element name
* @param string $message Message to display for invalid data
* @param string $type Rule type, use getRegisteredRules() to get types
* @param string $format (optional)Required for extra rule data
* @param string $validation (optional)Where to perform validation: "server", "client"
* @param boolean $reset Client-side validation: reset the form element to its original value if there is an error?
* @param boolean $force Force the rule to be applied, even if the target form element does not exist
* @since 1.0
* @access public
* @throws HTML_QuickForm_Error
*/
function addRule($element, $message, $type, $format=null, $validation='server', $reset = false, $force = false)
{
parent::addRule($element, $message, $type, $format, $validation, $reset, $force);
if ($validation == 'client') {
$this->updateAttributes(array('onsubmit' => 'try { var myValidator = validate_' . $this->_formName . '; } catch(e) { return true; } return myValidator(this);'));
}
} // end func addRule
/**
* Adds a validation rule for the given group of elements
*
* Only groups with a name can be assigned a validation rule
* Use addGroupRule when you need to validate elements inside the group.
* Use addRule if you need to validate the group as a whole. In this case,
* the same rule will be applied to all elements in the group.
* Use addRule if you need to validate the group against a function.
*
* @param string $group Form group name
* @param mixed $arg1 Array for multiple elements or error message string for one element
* @param string $type (optional)Rule type use getRegisteredRules() to get types
* @param string $format (optional)Required for extra rule data
* @param int $howmany (optional)How many valid elements should be in the group
* @param string $validation (optional)Where to perform validation: "server", "client"
* @param bool $reset Client-side: whether to reset the element's value to its original state if validation failed.
* @since 2.5
* @access public
* @throws HTML_QuickForm_Error
*/
function addGroupRule($group, $arg1, $type='', $format=null, $howmany=0, $validation = 'server', $reset = false)
{
parent::addGroupRule($group, $arg1, $type, $format, $howmany, $validation, $reset);
if (is_array($arg1)) {
foreach ($arg1 as $elementIndex => $rules) {
foreach ($rules as $rule) {
$validation = (isset($rule[3]) && 'client' == $rule[3])? 'client': 'server';
if ('client' == $validation) {
$this->updateAttributes(array('onsubmit' => 'try { var myValidator = validate_' . $this->_formName . '; } catch(e) { return true; } return myValidator(this);'));
}
}
}
} elseif (is_string($arg1)) {
if ($validation == 'client') {
$this->updateAttributes(array('onsubmit' => 'try { var myValidator = validate_' . $formname . '; } catch(e) { return true; } return myValidator(this);'));
}
}
} // end func addGroupRule
// }}}
/**
* Returns the client side validation script
*
@@ -986,7 +1074,7 @@ function qf_errorHandler(element, _qfMsg) {
list($jsArr,$element)=$jsandelement;
//end of fix
$js .= '
function validate_' . $this->_attributes['id'] . '_' . $elementName . '(element) {
function validate_' . $this->_formName . '_' . $elementName . '(element) {
var value = \'\';
var errFlag = new Array();
var _qfGroups = {};
@@ -1000,12 +1088,12 @@ function validate_' . $this->_attributes['id'] . '_' . $elementName . '(element)
}
';
$validateJS .= '
ret = validate_' . $this->_attributes['id'] . '_' . $elementName.'(frm.elements[\''.$elementName.'\']) && ret;';
ret = validate_' . $this->_formName . '_' . $elementName.'(frm.elements[\''.$elementName.'\']) && ret;';
// Fix for bug displaying errors for elements in a group
//unset($element);
//$element =& $this->getElement($elementName);
//end of fix
$valFunc = 'validate_' . $this->_attributes['id'] . '_' . $elementName . '(this)';
$valFunc = 'validate_' . $this->_formName . '_' . $elementName . '(this)';
$onBlur = $element->getAttribute('onBlur');
$onChange = $element->getAttribute('onChange');
$element->updateAttributes(array('onBlur' => $onBlur . $valFunc,
@@ -1013,7 +1101,7 @@ function validate_' . $this->_attributes['id'] . '_' . $elementName . '(element)
}
// do not rely on frm function parameter, because htmlarea breaks it when overloading the onsubmit method
$js .= '
function validate_' . $this->_attributes['id'] . '(frm) {
function validate_' . $this->_formName . '(frm) {
if (skipClientValidation) {
return true;
}
+29 -28
View File
@@ -58,10 +58,24 @@ function lockoptions(form, master, subitems) {
return(true);
}
function lockoption(form,item) {
eval("document."+form+"."+item+".disabled=true");/* IE thing */
if(document.forms[form].elements['h'+item]) {
eval("document."+form+".h"+item+".value=1");
}
}
function unlockoption(form,item) {
eval("document."+form+"."+item+".disabled=false");/* IE thing */
if(document.forms[form].elements['h'+item]) {
eval("document."+form+".h"+item+".value=0");
}
}
function lockoptionsall(formid) {
var lock=new Object();
var items=eval(formid+'items');
var form=document.forms[formid];
var lock = new Object();
var varname = formid.replace(/\-/g, '_');
var items = eval(varname+'items');
var form = document.forms[formid];
for (var master in items){
var subitems=items[master].dependents;
var thislock;
@@ -94,7 +108,8 @@ function lockoptionsall(formid) {
}
function lockoptionsallsetup(formid) {
var items=eval(formid+'items');
var varname = formid.replace(/\-/g, '_');
var items=eval(varname+'items');
var form=document.forms[formid];
for (var i = 0; i < form.elements.length; i++){
var found=false;
@@ -113,26 +128,11 @@ function lockoptionsallsetup(formid) {
}
}
}
if (found){
}
}
return lockoptionsall(formid);
}
function lockoption(form,item) {
eval("document."+form+"."+item+".disabled=true");/* IE thing */
if(document.forms[form].elements['h'+item]) {
eval("document."+form+".h"+item+".value=1");
}
}
function unlockoption(form,item) {
eval("document."+form+"."+item+".disabled=false");/* IE thing */
if(document.forms[form].elements['h'+item]) {
eval("document."+form+".h"+item+".value=0");
}
}
function submitFormById(id) {
var theform = document.getElementById(id);
@@ -219,15 +219,16 @@ function findChildNodes(start, tagName, elementClass, elementID, elementName) {
}
}
}
if( (child.nodeType == 1) &&//element node type
(!tagName || child.nodeName == tagName) &&
(!elementClass || classfound)&&
(!elementID || child.id == elementID) &&
(!elementName || child.name == elementName))
{
children = children.concat(child);
} else {
children = children.concat(findChildNodes(child, tagName, elementClass, elementID, elementName));
if(child.nodeType == 1) { //element node type
if ( (!tagName || child.nodeName == tagName) &&
(!elementClass || classfound)&&
(!elementID || child.id == elementID) &&
(!elementName || child.name == elementName))
{
children = children.concat(child);
} else {
children = children.concat(findChildNodes(child, tagName, elementClass, elementID, elementName));
}
}
}
return children;
+1 -1
View File
@@ -2,7 +2,7 @@
require_once $CFG->libdir.'/formslib.php';
class change_password_form extends moodleform {
class login_change_password_form extends moodleform {
function definition() {
global $USER;
+1 -1
View File
@@ -2,7 +2,7 @@
require_once $CFG->libdir.'/formslib.php';
class forgot_password_form extends moodleform {
class login_forgot_password_form extends moodleform {
function definition() {
$mform =& $this->_form;
@@ -240,7 +240,7 @@ class assignment_online extends assignment_base {
}
class assignment_online_edit_form extends moodleform {
class mod_assignment_online_edit_form extends moodleform {
function definition() {
$mform =& $this->_form;
@@ -914,7 +914,7 @@ class assignment_upload extends assignment_base {
}
class assignment_upload_notes_form extends moodleform {
class mod_assignment_upload_notes_form extends moodleform {
function definition() {
$mform =& $this->_form;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class chat_mod_form extends moodleform_mod {
class mod_chat_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class choice_mod_form extends moodleform_mod {
class mod_choice_mod_form extends moodleform_mod {
function definition() {
global $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY;
+1 -1
View File
@@ -2,7 +2,7 @@
require_once $CFG->libdir.'/formslib.php';
class data_comment_form extends moodleform {
class mod_data_comment_form extends moodleform {
function definition() {
$mform =& $this->_form;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class data_mod_form extends moodleform_mod {
class mod_data_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class exercise_mod_form extends moodleform_mod {
class mod_exercise_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class forum_mod_form extends moodleform_mod {
class mod_forum_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -2,7 +2,7 @@
require_once($CFG->libdir.'/formslib.php');
class forum_post_form extends moodleform {
class mod_forum_post_form extends moodleform {
function definition() {
+1 -1
View File
@@ -2,7 +2,7 @@
require_once $CFG->libdir.'/formslib.php';
class glossary_comment_form extends moodleform {
class mod_glossary_comment_form extends moodleform {
function definition() {
$mform =& $this->_form;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ($CFG->dirroot.'/lib/formslib.php');
class glossary_entry_form extends moodleform {
class mod_glossary_entry_form extends moodleform {
function definition() {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class glossary_mod_form extends moodleform_mod {
class mod_glossary_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
require_once ('moodleform_mod.php');
class journal_mod_form extends moodleform_mod {
class mod_journal_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php // $Id$
require_once ('moodleform_mod.php');
class label_mod_form extends moodleform_mod {
class mod_label_mod_form extends moodleform_mod {
function definition() {
+1 -1
View File
@@ -10,7 +10,7 @@
require_once ('moodleform_mod.php');
require_once('locallib.php');
class lesson_mod_form extends moodleform_mod {
class mod_lesson_mod_form extends moodleform_mod {
function definition() {
-2
View File
@@ -646,8 +646,6 @@ function quiz_after_add_or_update($quiz) {
}
}
// Remember whether this user likes the advanced settings visible or hidden.
set_user_preference('quiz_optionsettingspref', $quiz->mform_showadvanced_last);
// Update the events relating to this quiz.
// This is slightly inefficient, deleting the old events and creating new ones. However,
+1 -2
View File
@@ -3,7 +3,7 @@ require_once ('moodleform_mod.php');
require_once("$CFG->dirroot/mod/quiz/locallib.php");
class quiz_mod_form extends moodleform_mod {
class mod_quiz_mod_form extends moodleform_mod {
var $_feedbacks;
function definition() {
@@ -11,7 +11,6 @@ class quiz_mod_form extends moodleform_mod {
global $COURSE, $CFG, $QUIZ_GRADE_METHOD;
$mform =& $this->_form;
$mform->setShowAdvanced(get_user_preferences('quiz_optionsettingspref', 0));
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
+1 -1
View File
@@ -2,7 +2,7 @@
require_once("../../config.php");
include_once $CFG->libdir.'/formslib.php';
class survey_details_form extends moodleform {
class mod_survey_details_form extends moodleform {
function definition() {
$mform =& $this->_form;