]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8781 survey converted to new formslib - empty intro now means use default from...
authorskodak <skodak>
Tue, 27 Mar 2007 22:01:17 +0000 (22:01 +0000)
committerskodak <skodak>
Tue, 27 Mar 2007 22:01:17 +0000 (22:01 +0000)
lang/en_utf8/survey.php
mod/survey/details.php [deleted file]
mod/survey/mod.html [deleted file]
mod/survey/mod_form.php [new file with mode: 0644]
mod/survey/view.php

index e0ba38f3c057428b6c1e5c2afb7838d81c11db15..21a3cfc1b700f1e5a82cb7d68bee272b5d8db206 100644 (file)
@@ -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 (file)
index 540d90b..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php // $Id$
-
-    require_once("../../config.php");
-    include_once $CFG->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", "",
-        "<a href=\"index.php?id=$course->id\">$strsurveys</a>".
-        " -> ".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 (file)
index 506cd6e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-    if (!isset($form->name)) {
-        $form->name = "";
-    }
-    if (!isset($form->template)) {
-        $form->template = "";
-    }
-    if (!isset($form->intro)) {
-        $form->intro = "";
-    }
-    $nohtmleditorneeded = true;
-?>
-
-<form id="form" method="post" action="../mod/survey/details.php">
-<fieldset class="invisiblefieldset">
-<table cellpadding="5">
-<tr valign="top">
-    <td align="right"><b><?php  print_string("surveyname", "survey") ?>:</b></td>
-    <td>
-        <input type="text" name="name" size="30" value="<?php p($form->name) ?>" alt="<?php  print_string("surveyname", "survey") ?>" />
-    </td>
-</tr>
-<tr>
-    <td align="right"><b><?php print_string("surveytype", "survey") ?>:</b></td>
-    <td>
-    <?php
-        if ($options = get_records_menu("survey", "template", 0, "name", "id, name")) {
-            foreach ($options as $id => $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!";
-        }
-    ?>
-    </td>
-</tr>
-<?php print_standard_coursemodule_settings($form); ?>
-</table>
-<div class="centerpara">
-<input type="hidden" name="intro"   value="<?php p($form->intro) ?>" />
-<input type="hidden" name="course"     value="<?php p($form->course) ?>" />
-<input type="hidden" name="sesskey"    value="<?php p($form->sesskey) ?>" />
-<input type="hidden" name="coursemodule"  value="<?php p($form->coursemodule) ?>" />
-<input type="hidden" name="section"       value="<?php p($form->section) ?>" />
-<input type="hidden" name="module"     value="<?php p($form->module) ?>" />
-<input type="hidden" name="modulename" value="<?php p($form->modulename) ?>" />
-<input type="hidden" name="instance"   value="<?php p($form->instance) ?>" />
-<input type="hidden" name="mode"       value="<?php p($form->mode) ?>" />
-<input type="submit" value="<?php print_string("savechanges") ?>" />
-<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
-</div>
-</fieldset>
-</form>
diff --git a/mod/survey/mod_form.php b/mod/survey/mod_form.php
new file mode 100644 (file)
index 0000000..9b6a4d2
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+require_once ('moodleform_mod.php');
+
+class mod_survey_mod_form extends moodleform_mod {
+
+    function definition() {
+
+        global $CFG;
+        $mform =& $this->_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
index c171fc0ff145d0adc4905a47def4a778ee93e4a3..0546ff5646c2618ac75fd90c8585209af98889d8 100644 (file)
     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");