From 4d7a401910b3c0e41564ecaa3315f9d8ad99a6e4 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 27 Mar 2007 22:01:17 +0000 Subject: [PATCH] MDL-8781 survey converted to new formslib - empty intro now means use default from language pack; merged from MOODLE_18_STABLE --- lang/en_utf8/survey.php | 1 + mod/survey/details.php | 68 ----------------------------------------- mod/survey/mod.html | 55 --------------------------------- mod/survey/mod_form.php | 45 +++++++++++++++++++++++++++ mod/survey/view.php | 5 +++ 5 files changed, 51 insertions(+), 123 deletions(-) delete mode 100644 mod/survey/details.php delete mode 100644 mod/survey/mod.html create mode 100644 mod/survey/mod_form.php diff --git a/lang/en_utf8/survey.php b/lang/en_utf8/survey.php index e0ba38f3c0..21a3cfc1b7 100644 --- a/lang/en_utf8/survey.php +++ b/lang/en_utf8/survey.php @@ -163,6 +163,7 @@ Your carefully considered responses will help us improve the way this unit is pr Thanks very much.'; $string['collespname'] = 'COLLES (Preferred)'; +$string['customintro'] = 'Custom intro'; $string['done'] = 'Done'; $string['download'] = 'Download'; $string['downloadexcel'] = 'Download data as Excel spreadsheet'; diff --git a/mod/survey/details.php b/mod/survey/details.php deleted file mode 100644 index 540d90b276..0000000000 --- a/mod/survey/details.php +++ /dev/null @@ -1,68 +0,0 @@ -libdir.'/formslib.php'; - class mod_survey_details_form extends moodleform { - - function definition() { - $mform =& $this->_form; - $lastform = $this->_customdata['lastform']; - $mform->addElement('static','namestatic',get_string('name','survey'),$lastform->name); - - if (!$lastform->intro) { - $tempo = get_field("survey", "intro", "id", $lastform->template); - $lastform->intro = get_string($tempo, "survey"); - } - //TODO fix helpbuttons - //emoticonhelpbutton("form", "intro"); - //helpbutton("writing", get_string("helpwriting"), "moodle", true, true, '', true) - // helpbutton("text", get_string("helptext"), "moodle", true, true, '', true) - - $mform->setDefault('intro',$lastform->intro); - $mform->addElement('textarea','intro',get_string("introtext", "survey"), 'wrap="virtual" rows="20" cols="50"'); - $mform->addElement('hidden', 'name', $lastform->name); - $mform->addElement('hidden', 'template', $lastform->template); - $mform->addElement('hidden', 'course', $lastform->course); - $mform->addElement('hidden', 'coursemodule', $lastform->coursemodule); - $mform->addElement('hidden', 'section', $lastform->section); - $mform->addElement('hidden', 'module', $lastform->module); - $mform->addElement('hidden', 'modulename', $lastform->modulename); - $mform->addElement('hidden', 'instance', $lastform->instance); - $mform->addElement('hidden', 'mode', $lastform->mode); - $mform->addElement('hidden', 'visible', $lastform->visible); - $mform->addElement('hidden', 'groupmode', $lastform->groupmode); -//------------------------------------------------------------------------------- - // buttons - $this->add_action_buttons(false); - - } - } - if ($lastform = data_submitted($CFG->wwwroot.'/course/mod.php')) { - - if (! $course = get_record("course", "id", $lastform->course)) { - error("This course doesn't exist"); - } - - require_login($course->id, false); - require_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)); - - $streditingasurvey = get_string("editingasurvey", "survey"); - $strsurveys = get_string("modulenameplural", "survey"); - - print_header_simple("$streditingasurvey", "", - "id\">$strsurveys". - " -> ".stripslashes_safe($lastform->name)." ($streditingasurvey)"); - - if (!$lastform->name or !$lastform->template) { - // $_SERVER["HTTP_REFERER"] breaks xhtml, urlencode breaks continue button, - // removing $_SERVER["HTTP_REFERER"] - error(get_string("filloutallfields")); - } - $mform = new mod_survey_details_form($CFG->wwwroot.'/course/mod.php', array('lastform'=>stripslashes_safe($lastform))); - $mform->display(); - print_footer($course); - - } else { - error("You can't use this page like that!"); - } -?> diff --git a/mod/survey/mod.html b/mod/survey/mod.html deleted file mode 100644 index 506cd6ec38..0000000000 --- a/mod/survey/mod.html +++ /dev/null @@ -1,55 +0,0 @@ -name)) { - $form->name = ""; - } - if (!isset($form->template)) { - $form->template = ""; - } - if (!isset($form->intro)) { - $form->intro = ""; - } - $nohtmleditorneeded = true; -?> - -
-
- - - - - - - - - - -
: - " /> -
: - $name) { - $options[$id] = get_string($name, "survey"); - } - choose_from_menu($options, "template", $form->template); - helpbutton("surveys", get_string("helpsurveys", "survey")); - } else { - echo "No surveys to choose from!"; - } - ?> -
-
- - - - - - - - - -" /> -" /> -
-
-
diff --git a/mod/survey/mod_form.php b/mod/survey/mod_form.php new file mode 100644 index 0000000000..9b6a4d2158 --- /dev/null +++ b/mod/survey/mod_form.php @@ -0,0 +1,45 @@ +_form; + + $strrequired = get_string('required'); + +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('general', 'form')); + + $mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + + if (!$options = get_records_menu("survey", "template", 0, "name", "id, name")) { + error('No survey templates found!'); + } + + foreach ($options as $id => $name) { + $options[$id] = get_string($name, "survey"); + } + $options = array(''=>get_string('choose').'...') + $options; + $mform->addElement('select', 'template', get_string("surveytype", "survey"), $options); + $mform->addRule('template', $strrequired, 'required', null, 'client'); + $mform->setHelpButton('template', array('surveys', get_string('helpsurveys', 'survey'))); + + + $mform->addElement('textarea', 'intro', get_string('customintro', 'survey'), 'wrap="virtual" rows="20" cols="75"'); + $mform->setType('intro', PARAM_RAW); + + $this->standard_coursemodule_elements(); + +//------------------------------------------------------------------------------- + // buttons + $this->add_action_buttons(); + } + + +} +?> \ No newline at end of file diff --git a/mod/survey/view.php b/mod/survey/view.php index c171fc0ff1..0546ff5646 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -22,6 +22,11 @@ if (! $survey = get_record("survey", "id", $cm->instance)) { error("Survey ID was incorrect"); } + $rimmedintro = trim($survey->intro); + if (empty($rimmedintro)) { + $tempo = get_field("survey", "intro", "id", $survey->template); + $survey->intro = get_string($tempo, "survey"); + } if (! $template = get_record("survey", "id", $survey->template)) { error("Template ID was incorrect"); -- 2.39.5