fixing all the form names as per new class naming convention (PHP class names are also used for html id for styling)

This commit is contained in:
jamiesensei 2006-12-28 15:43:47 +00:00
parent f07b9627b6
commit 1d284fbd85
23 changed files with 89 additions and 94 deletions

View File

@ -69,15 +69,15 @@ if ($action=='delete'){
}
require_once('edit_form.php');
$blogpostform = new blog_post_form(null, compact('existing', 'sitecontext'));
$blogeditform = new blog_edit_form(null, compact('existing', 'sitecontext'));
if ($blogpostform->is_cancelled()){
if ($blogeditform->is_cancelled()){
redirect($returnurl);
} elseif ($blogpostform->no_submit_button_pressed()) {
no_submit_button_actions($blogpostform, $sitecontext);
} elseif ($blogeditform->no_submit_button_pressed()) {
no_submit_button_actions($blogeditform, $sitecontext);
} elseif ($fromform = $blogpostform->data_submitted()){
} elseif ($fromform = $blogeditform->data_submitted()){
//save stuff in db
switch ($action) {
case 'add':
@ -152,8 +152,8 @@ 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();
$blogeditform->set_defaults($post);
$blogeditform->display();
print_footer();
@ -162,8 +162,8 @@ print_footer();
die;
/***************************** edit.php functions ***************************/
function no_submit_button_actions(&$blogpostform, $sitecontext){
$mform =& $blogpostform->_form;
function no_submit_button_actions(&$blogeditform, $sitecontext){
$mform =& $blogeditform->_form;
$data = $mform->exportValues();
//sesskey has been checked already no need to check that
//check for official tags to add
@ -176,7 +176,7 @@ function no_submit_button_actions(&$blogpostform, $sitecontext){
if (!empty($data['deleteotags']) && !empty($data['otags'])){ // adding official tag
delete_otags($data['otags'], $sitecontext);
}
$blogpostform->otags_select_setup();
$blogeditform->otags_select_setup();
}
function delete_otags($tagids, $sitecontext){
foreach ($tagids as $tagid) {

View File

@ -2,7 +2,7 @@
require_once($CFG->libdir.'/formslib.php');
class activities_import_form_1 extends moodleform {
class course_import_activities_form_1 extends moodleform {
function definition() {
@ -14,11 +14,11 @@ class activities_import_form_1 extends moodleform {
$mform->addElement('header', 'general', '');//fill in the data depending on page params
//later using set_defaults
$mform->addElement('select', 'fromcourse', $text, $options);
// buttons
$submit_string = get_string('usethiscourse');
$this->add_action_buttons(false, true, $submit_string);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setConstants(array('id'=> $courseid));
@ -31,21 +31,21 @@ class activities_import_form_1 extends moodleform {
}
class activities_import_form_2 extends moodleform {
class course_import_activities_form_2 extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$courseid = $this->_customdata['courseid'];
$courseid = $this->_customdata['courseid'];
$mform->addElement('header', 'general', '');//fill in the data depending on page params
//later using set_defaults
$mform->addElement('text', 'fromcoursesearch', get_string('searchcourses'));
// buttons
$this->add_action_buttons(false, true, get_string('searchcourses'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setConstants(array('id'=> $courseid));

View File

@ -6,7 +6,7 @@
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/backup/restorelib.php');
$syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// if we're not a course creator , we can only import from our own courses.
@ -15,9 +15,9 @@
}
$strimport = get_string("importdata");
$tcourseids = '';
if ($teachers = get_user_capability_course('moodle/course:update')) {
foreach ($teachers as $teacher) {
if ($teacher->id != $course->id && $teacher->id != SITEID){
@ -51,31 +51,31 @@
notify(get_string('courseimportnotaught'));
return; // yay , this will pass control back to the file that included or required us.
}
// quick forms
include_once('import_form.php');
$mform_post = new activities_import_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text'=> get_string('coursestaught')));
$mform_post = new course_import_activities_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text'=> get_string('coursestaught')));
$mform_post ->display();
unset($options);
unset($options);
$options = array();
foreach ($cat_courses as $ccourse) {
if ($ccourse->id != $course->id && $ccourse->id != SITEID) {
$options[$ccourse->id] = $ccourse->fullname;
}
}
$cat = get_record("course_categories","id",$course->category);
if (count($options) > 0) {
$mform_post = new activities_import_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text' => get_string('coursescategory')));
$mform_post = new course_import_activities_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text' => get_string('coursescategory')));
$mform_post ->display();
}
if (!empty($creator)) {
$mform_post = new activities_import_form_2($CFG->wwwroot.'/course/import/activities/index.php', array('courseid' => $course->id));
$mform_post ->display();
$mform_post = new course_import_activities_form_2($CFG->wwwroot.'/course/import/activities/index.php', array('courseid' => $course->id));
$mform_post ->display();
}
if (!empty($fromcoursesearch) && !empty($creator)) {

View File

@ -2,7 +2,7 @@
require_once($CFG->libdir.'/formslib.php');
class group_import_form extends moodleform {
class course_import_groups_form extends moodleform {
function definition() {
@ -10,22 +10,22 @@ class group_import_form extends moodleform {
$mform =& $this->_form;
$maxuploadsize = $this->_customdata['maxuploadsize'];
$strimportgroups = get_string("importgroups");
$this->_upload_manager = new upload_manager('userfile', true, false, '', false, $maxuploadsize, true, true);
$this->set_max_file_size('', $maxuploadsize);
$mform->addElement('header', 'general', '');//fill in the data depending on page params
//later using set_defaults
//later using set_defaults
// buttons
$mform->addElement('hidden', 'sesskey');
$mform->setType('sesskey', PARAM_ALPHA);
$mform->setConstants(array('sesskey'=> $USER->sesskey));
$mform->addElement('file', 'userfile', '');
$mform->setHelpButton('userfile', array('attachment', get_string('attachment', 'forum'), 'forum'));
$mform->setHelpButton('userfile', array('attachment', get_string('attachment', 'forum'), 'forum'));
$this->add_action_buttons(false, true, $strimportgroups);
}

View File

@ -15,14 +15,14 @@
$maxuploadsize = get_max_upload_file_size();
echo '<p align="center">';
print_simple_box_start('center','80%');
// use formslib
include_once('import_form.php');
$mform_post = new group_import_form($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize));
$mform_post = new course_import_groups_form($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize));
$mform_post ->display();
print_simple_box_end();
echo '</p>';
?>

View File

@ -122,7 +122,7 @@
error("This module is missing important code! ($modlib)");
}
$mformclassname=$module->name.'_mod_form';
$mformclassname = 'mod_'.$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);

View File

@ -15,7 +15,7 @@
error(get_string('courserequestdisabled'));
}
$requestform = new course_request_form('request.php');
$requestform = new course_request_form();
$strtitle = get_string('courserequest');
print_header($strtitle, $strtitle, $strtitle, $requestform->focus());

View File

@ -74,7 +74,7 @@ class enrolment_plugin_authorize
}
else {
require_once($CFG->dirroot.'/enrol/authorize/enrol_form.php');
$frmenrol = new authorize_enrol_form('enrol.php');
$frmenrol = new enrol_authorize_form();
if ($frmenrol->data_submitted()) {
$authorizeerror = '';
switch ($form->paymentmethod) {

View File

@ -2,7 +2,7 @@
require_once($CFG->libdir.'/formslib.php');
class enrol_authorize_enrol_form extends moodleform
class enrol_authorize_form extends moodleform
{
function definition()
{

View File

@ -512,7 +512,7 @@ class moodleform {
return $repeats;
}
/**
* Use this method to add the standard buttons to the end of your form. Pass a param of false
* Use this method to a cancel and submit button to the end of your form. Pass a param of false
* if you don't want a cancel button in your form. If you have a cancel button make sure you
* check for it being pressed using is_cancelled() and redirecting if it is true before trying to
* get data with data_submitted().
@ -521,21 +521,16 @@ class moodleform {
* @param boolean $revert whether to show revert button, default true
* @param string $submitlabel label for submit button, defaults to get_string('savechanges')
*/
function add_action_buttons($cancel = true, $revert = true, $submitlabel=null){
function add_action_buttons($cancel = true, $submitlabel=null){
if (is_null($submitlabel)){
$submitlabel = get_string('savechanges');
}
$mform =& $this->_form;
if ($revert || $cancel){
//when two or more elements we need a group
if ($cancel){
//when two elements we need a group
$buttonarray=array();
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
if ($revert){
$buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
}
if ($cancel){
$buttonarray[] = &$mform->createElement('cancel');
}
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
} else {
@ -1134,7 +1129,7 @@ function validate_' . $this->_formName . '(frm) {
function getLockOptionEndScript(){
$js = '<script type="text/javascript" language="javascript">'."\n";
$js .= '//<![CDATA['."\n";
$js .= "var ".$this->getAttribute('id')."items= {";
$js .= "var ".$this->_formName."items= {";
foreach ($this->_dependencies as $dependentOn => $elements){
$js .= "'$dependentOn'".' : {dependents :[';
foreach ($elements as $element){

View File

@ -28,7 +28,7 @@
error('Can not use this script when "Logged in as"!');
}
$mform = new change_password_form('change_password.php');
$mform = new login_change_password_form();
$mform->set_defaults(array('id'=>$course->id, 'username'=>$USER->username));
if ($mform->is_cancelled()) {

View File

@ -1,4 +1,4 @@
<?php
<?php
// $Id$
// forgot password routine.
// find the user and call the appropriate routine for their authentication
@ -53,10 +53,10 @@ if (!empty($CFG->changepassword)) {
set_config('auth_'.$auth.'_changepasswordurl', $CFG->changepassword);
}
set_config('changepassword', '');
}
}
$mform = new forgot_password_form('forgot_password.php');
$mform = new login_forgot_password_form();
if ($mform->is_cancelled()) {
redirect($CFG->httpswwwroot.'/login/index.php');
@ -106,7 +106,7 @@ if ($action == 'find' and $param = $mform->data_submitted()) {
$user = $mailuser;
}
}
// if user located (and no errors) take the appropriate action
if (empty($errors) and !empty($user)) {
// check this user isn't 'unconfirmed'
@ -117,7 +117,7 @@ if ($action == 'find' and $param = $mform->data_submitted()) {
$authmethod = $user->auth;
if (is_internal_auth($authmethod) or !empty($CFG->{'auth_'.$authmethod.'_stdchangepassword'})) {
// handle internal authentication
// set 'secret' string
$user->secret = random_string(15);
if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
@ -203,7 +203,7 @@ if ($action == 'find' and $param = $mform->data_submitted()) {
reset_login_count();
$page = 'emailsent';
$changepasswordurl = "{$CFG->httpswwwroot}/login/change_password.php";
$a = new object();
$a->email = $user->email;

View File

@ -11,7 +11,7 @@
error("Sorry, you may not use this page.");
}
$mform_signup = new login_signup_form('signup.php');
$mform_signup = new login_signup_form_1();
if ($mform_signup->is_cancelled()) {
redirect($CFG->httpswwwroot.'/login/index.php');

View File

@ -2,7 +2,7 @@
require_once($CFG->libdir.'/formslib.php');
class login_signup_form extends moodleform {
class login_signup_form_1 extends moodleform {
function definition() {
global $USER, $CFG;

View File

@ -39,7 +39,7 @@ class assignment_online extends assignment_base {
}
/// prepare form and process submitted data
$mform = new assignment_online_edit_form('view.php');
$mform = new mod_assignment_online_edit_form();
$defaults = new object();
$defaults->id = $this->cm->id;

View File

@ -437,7 +437,7 @@ class assignment_upload extends assignment_base {
$returnurl = 'view.php?id='.$this->cm->id;
$mform = new assignment_upload_notes_form('upload.php');
$mform = new mod_assignment_upload_notes_form();
$defaults = new object();
$defaults->id = $this->cm->id;

View File

@ -46,7 +46,7 @@
}
$mform = new data_comment_form('comment.php');
$mform = new mod_data_comment_form();
$mform->set_defaults(array('mode'=>$mode, 'page'=>$page, 'rid'=>$record->id, 'commentid'=>$commentid));
if ($comment) {
$format = $comment->format;

View File

@ -889,12 +889,12 @@ function data_print_template($template, $records, $data, $search='',$page=0, $re
if ($template == 'singletemplate') { //prints ratings options
data_print_ratings($data, $record);
}
/**********************************
* Printing Ratings Form *
*********************************/
if (($template == 'singletemplate') && ($data->comments)) { //prints ratings options
data_print_comments($data, $record, $page);
}
}
@ -1112,7 +1112,7 @@ function data_print_comments($data, $record, $page=0, $mform=false) {
} else {
if (!$mform) {
require_once('comment_form.php');
$mform = new data_comment_form('comment.php');
$mform = new mod_data_comment_form('comment.php');
$mform->set_defaults(array('mode'=>'add', 'page'=>$page, 'rid'=>$record->id));
}
echo '<div class="newcomment" align="center">';

View File

@ -434,7 +434,7 @@
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$mform_post = new forum_post_form('post.php', array('course'=>$course, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
$mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
if ($fromform = $mform_post->data_submitted()) {

View File

@ -51,7 +51,7 @@ function glossary_comment_add() {
error('You can\'t add comments to this glossary!');
}
$mform = new glossary_comment_form('comment.php');
$mform = new mod_glossary_comment_form();
$mform->set_defaults(array('eid'=>$eid, 'action'=>'add'));
if ($mform->is_cancelled()) {
@ -174,7 +174,7 @@ function glossary_comment_edit() {
error('You can\'t edit this. Time expired!');
}
$mform = new glossary_comment_form('comment.php');
$mform = new mod_glossary_comment_form();
trusttext_prepare_edit($comment->entrycomment, $comment->format, can_use_html_editor(), $context);
$mform->set_defaults(array('cid'=>$cid, 'action'=>'edit', 'entrycomment'=>$comment->entrycomment, 'format'=>$comment->format));

View File

@ -39,7 +39,7 @@ if ($e) { // if entry is specified
require_capability('mod/glossary:write', $context);
}
$mform =& new glossary_entry_form(null, compact('cm', 'glossary', 'hook', 'mode', 'e', 'context'));
$mform =& new mod_glossary_entry_form(null, compact('cm', 'glossary', 'hook', 'mode', 'e', 'context'));
if ($mform->is_cancelled()){
if ($e){
redirect("view.php?id=$cm->id&amp;mode=entry&amp;hook=$e");

View File

@ -56,7 +56,7 @@
if (!$lastform->name or !$lastform->template) {
error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]);
}
$mform = new survey_details_form($CFG->wwwroot.'/course/mod.php',array('lastform'=>stripslashes_safe($lastform)));
$mform = new mod_survey_details_form($CFG->wwwroot.'/course/mod.php', array('lastform'=>stripslashes_safe($lastform)));
$mform->display();
print_footer($course);

View File

@ -14,35 +14,35 @@
* class that inherits from this one, and implements the definition_inner()
* method.
*/
class edit_question_form extends moodleform {
class question_edit_form extends moodleform {
/**
* Build the form definition.
*
* This adds all the form files that the default question type supports.
*
* This adds all the form files that the default question type supports.
* If your question type does not support all these fields, then you can
* override this method and remove the ones you don't want with $mform->removeElement().
*/
function definition() {
global $COURSE;
$qtype = $this->qtype();
$langfile = "qtype_$qtype";
$mform =& $this->_form;
$renderer =& $mform->defaultRenderer();
// Standard fields at the start of the form.
$mform->addElement('header', 'formheader', get_string("editing$qtype", $langfile));
$mform->setHelpButton('formheader', array($qtype, get_string($qtype, $qtype), $qtype));
$mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),
array('courseid' => $COURSE->id, 'published' => true, 'only_editable' => true));
$mform->addElement('text', 'name', get_string('questionname', 'quiz'),
array('size' => 50));
$mform->setType('name', PARAM_MULTILANG);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addElement('htmleditor', 'questiontext', get_string('questiontext', 'quiz'),
array('rows' => 15, 'course' => $COURSE->id));
$mform->setType('questiontext', PARAM_RAW);
@ -56,7 +56,7 @@ class edit_question_form extends moodleform {
$mform->addElement('select', 'image', get_string('imagedisplay', 'quiz'), $images);
$mform->setType('image', PARAM_FILE);
}
$mform->addElement('text', 'defaultgrade', get_string('defaultgrade', 'quiz'),
array('size' => 3));
$mform->setType('defaultgrade', PARAM_INT);
@ -72,7 +72,7 @@ class edit_question_form extends moodleform {
array('rows' => 10, 'course' => $COURSE->id));
$mform->setType('generalfeedback', PARAM_RAW);
$mform->setHelpButton('generalfeedback', array('generalfeedback', get_string('generalfeedback', 'quiz'), 'quiz'));
// Any questiontype specific fields.
$this->definition_inner($mform);
@ -99,22 +99,22 @@ class edit_question_form extends moodleform {
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$renderer->addStopFieldsetElements('buttonar');
}
/**
* Add any question-type specific form fields.
*
* @param object $mform the form being built.
*
* @param object $mform the form being built.
*/
function definition_inner(&$mform) {
// By default, do nothing.
}
function set_defaults($question) {
global $QTYPES;
$QTYPES[$question->qtype]->set_default_options($question);
parent::set_defaults($question);
}
/**
* Override this in the subclass to question type name.
* @return the question type name, should be the same as the name() method in the question type class.