Merge branch 'w43_MDL-29923_m22_removesearch' of git://github.com/skodak/moodle
authorAparup Banerjee <aparup@moodle.com>
Mon, 31 Oct 2011 02:23:59 +0000 (10:23 +0800)
committerAparup Banerjee <aparup@moodle.com>
Mon, 31 Oct 2011 02:23:59 +0000 (10:23 +0800)
92 files changed:
admin/cli/install_database.php
admin/renderer.php
filter/data/db/install.php [new file with mode: 0644]
filter/data/filter.php [new file with mode: 0644]
filter/data/lang/en/filter_data.php [new file with mode: 0644]
filter/data/version.php [new file with mode: 0644]
filter/glossary/db/install.php [new file with mode: 0644]
filter/glossary/filter.php [new file with mode: 0644]
filter/glossary/lang/en/filter_glossary.php [new file with mode: 0644]
filter/glossary/styles.css [new file with mode: 0644]
filter/glossary/version.php [new file with mode: 0644]
filter/glossary/yui/autolinker/autolinker.js [moved from mod/glossary/yui/autolinker/autolinker.js with 90% similarity]
lib/pluginlib.php
mod/assignment/type/upload/assignment.class.php
mod/data/filter.php [deleted file]
mod/data/version.php
mod/feedback/README.txt
mod/feedback/analysis.php
mod/feedback/analysis_course.php
mod/feedback/analysis_to_excel.php
mod/feedback/backup/moodle1/lib.php
mod/feedback/backup/moodle2/backup_feedback_activity_task.class.php
mod/feedback/backup/moodle2/backup_feedback_settingslib.php
mod/feedback/backup/moodle2/backup_feedback_stepslib.php
mod/feedback/backup/moodle2/restore_feedback_activity_task.class.php
mod/feedback/backup/moodle2/restore_feedback_stepslib.php
mod/feedback/choose_group_form.php
mod/feedback/complete.php
mod/feedback/complete_guest.php
mod/feedback/db/access.php
mod/feedback/db/install.php
mod/feedback/db/install.xml
mod/feedback/db/log.php
mod/feedback/db/messages.php
mod/feedback/db/upgrade.php
mod/feedback/delete_completed.php
mod/feedback/delete_completed_form.php
mod/feedback/delete_item.php
mod/feedback/delete_item_form.php
mod/feedback/delete_template.php
mod/feedback/delete_template_form.php
mod/feedback/edit.php
mod/feedback/edit_form.php
mod/feedback/edit_item.php
mod/feedback/export.php
mod/feedback/import.php
mod/feedback/import_form.php
mod/feedback/index.php
mod/feedback/item/captcha/captcha_form.php
mod/feedback/item/captcha/lib.php
mod/feedback/item/captcha/print_captcha.php
mod/feedback/item/feedback_item_class.php
mod/feedback/item/feedback_item_form_class.php
mod/feedback/item/info/info_form.php
mod/feedback/item/info/lib.php
mod/feedback/item/label/label_form.php
mod/feedback/item/label/lib.php
mod/feedback/item/multichoice/lib.php
mod/feedback/item/multichoice/multichoice_form.php
mod/feedback/item/multichoicerated/lib.php
mod/feedback/item/multichoicerated/multichoicerated_form.php
mod/feedback/item/numeric/lib.php
mod/feedback/item/numeric/numeric_form.php
mod/feedback/item/textarea/lib.php
mod/feedback/item/textarea/textarea_form.php
mod/feedback/item/textfield/lib.php
mod/feedback/item/textfield/textfield_form.php
mod/feedback/lang/en/feedback.php
mod/feedback/lib.php
mod/feedback/mapcourse.php
mod/feedback/mod_form.php
mod/feedback/print.php
mod/feedback/settings.php
mod/feedback/show_entries.php
mod/feedback/show_entries_anonym.php
mod/feedback/show_nonrespondents.php
mod/feedback/styles.css
mod/feedback/tabs.php
mod/feedback/unmapcourse.php
mod/feedback/use_templ.php
mod/feedback/use_templ_form.php
mod/feedback/version.php
mod/feedback/view.php
mod/glossary/filter.php [deleted file]
mod/glossary/styles.css
mod/glossary/version.php
mod/scorm/player.php
mod/scorm/report/basic/report.php
mod/workshop/form/accumulative/assessment_form.php
mod/workshop/form/accumulative/lang/en/workshopform_accumulative.php
mod/workshop/form/numerrors/assessment_form.php
mod/workshop/form/numerrors/lib.php

index 2ee2f82..2524c41 100644 (file)
@@ -46,8 +46,8 @@ Options:
 --adminuser=USERNAME  Username for the moodle admin account. Default is admin.
 --adminpass=PASSWORD  Password for the moodle admin account.
 --agree-license       Indicates agreement with software license.
---fullname            Name of the site
---shortname           Name of the site
+--fullname=STRING     Name of the site
+--shortname=STRING    Name of the site
 -h, --help            Print out this help
 
 Example:
index 7c23e2c..be5780b 100644 (file)
@@ -598,7 +598,7 @@ class core_admin_renderer extends plugin_renderer_base {
             if (is_null($otherplugin)) {
                 $ok = false;
             }
-            if ($requiredversion != ANY_VERSION and $otherplugin->versiondb < $requiredversion) {
+            if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
                 $ok = false;
             }
 
diff --git a/filter/data/db/install.php b/filter/data/db/install.php
new file mode 100644 (file)
index 0000000..dd171b8
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Database activity filter post install hook
+ *
+ * @package    filter
+ * @subpackage data
+ * @copyright  2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+function xmldb_filter_data_install() {
+    global $DB;
+
+    // If the legacy mod/data filter is installed we need to:
+    //   1- Delete new filter (filter_active and filter_config) information, in order to
+    //   2- Usurpate the identity of the legacy filter by moving all its
+    //      information to filter/data
+    // If the legacy mod/data filter was not installed, no action is needed
+    if ($DB->record_exists('filter_active', array('filter' => 'mod/data'))) {
+        $DB->delete_records('filter_active', array('filter' => 'filter/data'));
+        $DB->set_field('filter_active', 'filter', 'filter/data', array('filter' => 'mod/data'));
+    }
+}
diff --git a/filter/data/filter.php b/filter/data/filter.php
new file mode 100644 (file)
index 0000000..60ca85f
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This filter provides automatic linking to database activity entries
+ * when found inside every Moodle text.
+ *
+ * @package    filter
+ * @subpackage data
+ * @copyright  2006 Vy-Shane Sin Fat
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Database activity filtering
+ */
+class filter_data extends moodle_text_filter {
+
+    public function filter($text, array $options = array()) {
+        global $CFG, $DB;
+
+        // Trivial-cache - keyed on $cachedcontextid
+        static $cachedcontextid;
+        static $contentlist;
+
+        static $nothingtodo;
+
+        // Try to get current course
+        if (!$courseid = get_courseid_from_context($this->context)) {
+            $courseid = 0;
+        }
+
+        // Initialise/invalidate our trivial cache if dealing with a different context
+        if (!isset($cachedcontextid) || $cachedcontextid !== $this->context->id) {
+            $cachedcontextid = $this->context->id;
+            $contentlist = array();
+            $nothingtodo = false;
+        }
+
+        if ($nothingtodo === true) {
+            return $text;
+        }
+
+        // Create a list of all the resources to search for. It may be cached already.
+        if (empty($contentlist)) {
+            $coursestosearch = $courseid ? array($courseid) : array(); // Add courseid if found
+            if (get_site()->id != $courseid) { // Add siteid if was not courseid
+                $coursestosearch[] = get_site()->id;
+            }
+            // We look for text field contents only if have autolink enabled (param1)
+            list ($coursesql, $params) = $DB->get_in_or_equal($coursestosearch);
+            $sql = 'SELECT dc.id AS contentid, dr.id AS recordid, dc.content AS content, d.id AS dataid
+                      FROM {data} d
+                      JOIN {data_fields} df ON df.dataid = d.id
+                      JOIN {data_records} dr ON dr.dataid = d.id
+                      JOIN {data_content} dc ON dc.fieldid = df.id AND dc.recordid = dr.id
+                     WHERE d.course ' . $coursesql . '
+                       AND df.type = \'text\'
+                       AND ' . $DB->sql_compare_text('df.param1', 1) . ' = 1';
+
+            if (!$contents = $DB->get_records_sql($sql, $params)) {
+                $nothingtodo = true;
+                return $text;
+            }
+
+            foreach ($contents as $key => $content) {
+                // Trim empty or unlinkable concepts
+                $currentcontent = trim(strip_tags($content->content));
+                if (empty($currentcontent)) {
+                    unset($contents[$key]);
+                    continue;
+                } else {
+                    $contents[$key]->content = $currentcontent;
+                }
+
+                // Rule out any small integers.  See bug 1446
+                $currentint = intval($currentcontent);
+                if ($currentint && (strval($currentint) == $currentcontent) && $currentint < 1000) {
+                    unset($contents[$key]);
+                }
+            }
+
+            if (empty($contents)) {
+                $nothingtodo = true;
+                return $text;
+            }
+
+            usort($contents, 'filter_data::sort_entries_by_length');
+
+            foreach ($contents as $content) {
+                $href_tag_begin = '<a class="data autolink dataid'.$content->dataid.'" title="'.$content->content.'" '.
+                                  'href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$content->dataid.
+                                  '&amp;rid='.$content->recordid.'">';
+                $contentlist[] = new filterobject($content->content, $href_tag_begin, '</a>', false, true);
+            }
+
+            $contentlist = filter_remove_duplicates($contentlist); // Clean dupes
+        }
+        return filter_phrases($text, $contentlist);  // Look for all these links in the text
+    }
+
+    private static function sort_entries_by_length($content0, $content1) {
+        $len0 = strlen($content0->content);
+        $len1 = strlen($content1->content);
+
+        if ($len0 < $len1) {
+            return 1;
+        } else if ($len0 > $len1) {
+            return -1;
+        } else {
+            return 0;
+        }
+    }
+}
diff --git a/filter/data/lang/en/filter_data.php b/filter/data/lang/en/filter_data.php
new file mode 100644 (file)
index 0000000..a6d1f4d
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Strings for filter_data
+ *
+ * @package    filter
+ * @subpackage data
+ * @copyright  2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$string['filtername'] = 'Database auto-linking';
diff --git a/filter/data/version.php b/filter/data/version.php
new file mode 100644 (file)
index 0000000..a6ec47b
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Data activity filter version information
+ *
+ * @package    filter
+ * @subpackage data
+ * @copyright  2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version  = 2011102800;
+$plugin->requires = 2011102700;  // Requires this Moodle version
+$plugin->component= 'filter_data';
+
+$plugin->dependencies = array('mod_data' => 2011102800);
diff --git a/filter/glossary/db/install.php b/filter/glossary/db/install.php
new file mode 100644 (file)
index 0000000..76bf66f
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Glossary filter post install hook
+ *
+ * @package    filter
+ * @subpackage glossary
+ * @copyright  2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+function xmldb_filter_glossary_install() {
+    global $DB;
+
+    // If the legacy mod/glossary filter is installed we need to:
+    //   1- Delete new filter (filter_active and filter_config) information, in order to
+    //   2- Usurpate the identity of the legacy filter by moving all its
+    //      information to filter/glossary
+    // If the legacy mod/glossary filter was not installed, no action is needed
+    if ($DB->record_exists('filter_active', array('filter' => 'mod/glossary'))) {
+        $DB->delete_records('filter_active', array('filter' => 'filter/glossary'));
+        $DB->set_field('filter_active', 'filter', 'filter/glossary', array('filter' => 'mod/glossary'));
+    }
+}
diff --git a/filter/glossary/filter.php b/filter/glossary/filter.php
new file mode 100644 (file)
index 0000000..8592626
--- /dev/null
@@ -0,0 +1,226 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This filter provides automatic linking to
+ * glossary entries, aliases and categories when
+ * found inside every Moodle text
+ *
+ * @package    filter
+ * @subpackage glossary
+ * @copyright  2004 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Glossary filtering
+ *
+ * TODO: erase the $GLOSSARY_EXCLUDECONCEPTS global => require format_text()
+ *       to be able to pass arbitrary $options['filteroptions']['glossary'] to filter_text()
+ */
+class filter_glossary extends moodle_text_filter {
+
+    public function filter($text, array $options = array()) {
+        global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS, $PAGE;
+
+        // Trivial-cache - keyed on $cachedcontextid
+        static $cachedcontextid;
+        static $conceptlist;
+
+        static $jsinitialised;       // To control unique js init
+        static $nothingtodo;         // To avoid processing if no glossaries / concepts are found
+
+        // Try to get current course
+        if (!$courseid = get_courseid_from_context($this->context)) {
+            $courseid = 0;
+        }
+
+        // Initialise/invalidate our trivial cache if dealing with a different context
+        if (!isset($cachedcontextid) || $cachedcontextid !== $this->context->id) {
+            $cachedcontextid = $this->context->id;
+            $conceptlist = array();
+            $nothingtodo = false;
+        }
+
+        if ($nothingtodo === true) {
+            return $text;
+        }
+
+        // Create a list of all the concepts to search for.  It may be cached already.
+        if (empty($conceptlist)) {
+
+            // Find all the glossaries we need to examine
+            if (!$glossaries = $DB->get_records_sql_menu('
+                    SELECT g.id, g.name
+                      FROM {glossary} g, {course_modules} cm, {modules} m
+                     WHERE m.name = \'glossary\'
+                       AND cm.module = m.id
+                       AND cm.visible = 1
+                       AND g.id = cm.instance
+                       AND g.usedynalink != 0
+                       AND (g.course = ? OR g.globalglossary = 1)
+                  ORDER BY g.globalglossary, g.id', array($courseid))) {
+                $nothingtodo = true;
+                return $text;
+            }
+
+            // Make a list of glossary IDs for searching
+            $glossarylist = implode(',', array_keys($glossaries));
+
+            // Pull out all the raw data from the database for entries, categories and aliases
+            $entries = $DB->get_records_select('glossary_entries',
+                    'glossaryid IN ('.$glossarylist.') AND usedynalink != 0 AND approved != 0 ', null, '',
+                    'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch');
+
+            $categories = $DB->get_records_select('glossary_categories',
+                    'glossaryid IN ('.$glossarylist.') AND usedynalink != 0', null, '',
+                    'id,glossaryid,name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch');
+
+            $aliases = $DB->get_records_sql('
+                    SELECT ga.id, ge.id AS entryid, ge.glossaryid,
+                           ga.alias AS concept, ge.concept AS originalconcept,
+                           casesensitive, 0 AS category, fullmatch
+                      FROM {glossary_alias} ga,
+                           {glossary_entries} ge
+                      WHERE ga.entryid = ge.id
+                        AND ge.glossaryid IN ('.$glossarylist.')
+                        AND ge.usedynalink != 0
+                        AND ge.approved != 0', null);
+
+            // Combine them into one big list
+            $concepts = array();
+            if ($entries and $categories) {
+                $concepts = array_merge($entries, $categories);
+            } else if ($categories) {
+                $concepts = $categories;
+            } else if ($entries) {
+                $concepts = $entries;
+            }
+
+            if ($aliases) {
+                $concepts = array_merge($concepts, $aliases);
+            }
+
+            if (!empty($concepts)) {
+                foreach ($concepts as $key => $concept) {
+                    // Trim empty or unlinkable concepts
+                    $currentconcept = trim(strip_tags($concept->concept));
+                    if (empty($currentconcept)) {
+                        unset($concepts[$key]);
+                        continue;
+                    } else {
+                        $concepts[$key]->concept = $currentconcept;
+                    }
+
+                    // Rule out any small integers.  See bug 1446
+                    $currentint = intval($currentconcept);
+                    if ($currentint && (strval($currentint) == $currentconcept) && $currentint < 1000) {
+                        unset($concepts[$key]);
+                    }
+                }
+            }
+
+            if (empty($concepts)) {
+                $nothingtodo = true;
+                return $text;
+            }
+
+            usort($concepts, 'filter_glossary::sort_entries_by_length');
+
+            $strcategory = get_string('category', 'glossary');
+
+            // Loop through all the concepts, setting up our data structure for the filter
+            $conceptlist = array();    // We will store all the concepts here
+
+            foreach ($concepts as $concept) {
+                $glossaryname = str_replace(':', '-', $glossaries[$concept->glossaryid]);
+                if ($concept->category) {       // Link to a category
+                    // TODO: Fix this string usage
+                    $title = strip_tags($glossaryname.': '.$strcategory.' '.$concept->concept);
+                    $href_tag_begin = '<a class="glossary autolink category glossaryid'.$concept->glossaryid.'" title="'.$title.'" '.
+                                      'href="'.$CFG->wwwroot.'/mod/glossary/view.php?g='.$concept->glossaryid.
+                                      '&amp;mode=cat&amp;hook='.$concept->id.'">';
+                } else { // Link to entry or alias
+                    if (!empty($concept->originalconcept)) {  // We are dealing with an alias (so show and point to original)
+                        $title = str_replace('"', "'", strip_tags($glossaryname.': '.$concept->originalconcept));
+                        $concept->id = $concept->entryid;
+                    } else { // This is an entry
+                        $title = str_replace('"', "'", strip_tags($glossaryname.': '.$concept->concept));
+                    }
+                    // hardcoding dictionary format in the URL rather than defaulting
+                    // to the current glossary format which may not work in a popup.
+                    // for example "entry list" means the popup would only contain
+                    // a link that opens another popup.
+                    $link = new moodle_url('/mod/glossary/showentry.php', array('courseid'=>$courseid, 'eid'=>$concept->id, 'displayformat'=>'dictionary'));
+                    $attributes = array(
+                        'href' => $link,
+                        'title'=> $title,
+                        'class'=> 'glossary autolink concept glossaryid'.$concept->glossaryid);
+
+                    // this flag is optionally set by resource_pluginfile()
+                    // if processing an embedded file use target to prevent getting nested Moodles
+                    if (isset($CFG->embeddedsoforcelinktarget) && $CFG->embeddedsoforcelinktarget) {
+                        $attributes['target'] = '_top';
+                    }
+
+                    $href_tag_begin = html_writer::start_tag('a', $attributes);
+                }
+                $conceptlist[] = new filterobject($concept->concept, $href_tag_begin, '</a>',
+                    $concept->casesensitive, $concept->fullmatch);
+            }
+
+            $conceptlist = filter_remove_duplicates($conceptlist);
+
+            if (empty($jsinitialised)) {
+                // Add a JavaScript event to open popup's here. This only ever need to be
+                // added once!
+                $PAGE->requires->yui_module(
+                        'moodle-filter_glossary-autolinker',
+                        'M.filter_glossary.init_filter_autolinking',
+                        array(array('courseid' => $courseid)));
+                $jsinitialised = true;
+            }
+        }
+
+        if (!empty($GLOSSARY_EXCLUDECONCEPTS)) {
+            $reducedconceptlist=array();
+            foreach($conceptlist as $concept) {
+                if(!in_array($concept->phrase,$GLOSSARY_EXCLUDECONCEPTS)) {
+                    $reducedconceptlist[]=$concept;
+                }
+            }
+            return filter_phrases($text, $reducedconceptlist);
+        }
+
+        return filter_phrases($text, $conceptlist);   // Actually search for concepts!
+    }
+
+
+    private static function sort_entries_by_length($entry0, $entry1) {
+        $len0 = strlen($entry0->concept);
+        $len1 = strlen($entry1->concept);
+
+        if ($len0 < $len1) {
+            return 1;
+        } else if ($len0 > $len1) {
+            return -1;
+        } else {
+            return 0;
+        }
+    }
+}
diff --git a/filter/glossary/lang/en/filter_glossary.php b/filter/glossary/lang/en/filter_glossary.php
new file mode 100644 (file)
index 0000000..5ca0606
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Strings for filter_glossary
+ *
+ * @package    filter
+ * @subpackage glossary
+ * @copyright  2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$string['filtername'] = 'Glossary auto-linking';
diff --git a/filter/glossary/styles.css b/filter/glossary/styles.css
new file mode 100644 (file)
index 0000000..8a78bdb
--- /dev/null
@@ -0,0 +1 @@
+#glossaryfilteroverlayprogress {position:fixed;top:50%;width:100%;text-align:center;}
diff --git a/filter/glossary/version.php b/filter/glossary/version.php
new file mode 100644 (file)
index 0000000..4628335
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Glossary filter version information
+ *
+ * @package    filter
+ * @subpackage glossary
+ * @copyright  2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version  = 2011102800;
+$plugin->requires = 2011102700;  // Requires this Moodle version
+$plugin->component= 'filter_glossary';
+
+$plugin->dependencies = array('mod_glossary' => 2011102800);
similarity index 90%
rename from mod/glossary/yui/autolinker/autolinker.js
rename to filter/glossary/yui/autolinker/autolinker.js
index e8935f3..46d04bc 100644 (file)
@@ -1,6 +1,6 @@
-YUI.add('moodle-mod_glossary-autolinker', function(Y) {
+YUI.add('moodle-filter_glossary-autolinker', function(Y) {
 
-    var AUTOLINKERNAME = 'Glossary autolinker',
+    var AUTOLINKERNAME = 'Glossary filter autolinker',
         URL = 'url',
         POPUPNAME = 'name',
         POPUPOPTIONS = 'options',
@@ -33,7 +33,7 @@ YUI.add('moodle-mod_glossary-autolinker', function(Y) {
 
                 //display a progress indicator
                 var title = '';
-                var content = Y.Node.create('<div id="glossaryoverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>');
+                var content = Y.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>');
                 var o = new Y.Overlay({
                     headerContent :  title,
                     bodyContent : content
@@ -61,7 +61,7 @@ YUI.add('moodle-mod_glossary-autolinker', function(Y) {
                 };
                 Y.io(fullurl, cfg);
 
-            }, Y.one(document.body), 'a.glossary.autolink');
+            }, Y.one(document.body), 'a.glossary.autolink.concept');
         },
         display_callback : function(content) {
             try {
@@ -126,9 +126,9 @@ YUI.add('moodle-mod_glossary-autolinker', function(Y) {
         }
     });
 
-    M.mod_glossary = M.mod_glossary || {};
-    M.mod_glossary.init_filter_autolinking = function(config) {
+    M.filter_glossary = M.filter_glossary || {};
+    M.filter_glossary.init_filter_autolinking = function(config) {
         return new AUTOLINKER(config);
     }
 
-}, '@VERSION@', {requires:['base','node','event-delegate','overlay','moodle-enrol-notification']});
\ No newline at end of file
+}, '@VERSION@', {requires:['base','node','event-delegate','overlay','moodle-enrol-notification']});
index 32bcca0..a1e0ade 100644 (file)
@@ -241,7 +241,7 @@ class plugin_manager {
                 return false;
             }
 
-            if ($requiredversion != ANY_VERSION and $otherplugin->versiondb < $requiredversion) {
+            if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
                 return false;
             }
         }
index a711570..c1d4ffd 100644 (file)
@@ -44,6 +44,7 @@ class assignment_upload extends assignment_base {
         global $USER, $OUTPUT;
 
         require_capability('mod/assignment:view', $this->context);
+        $cansubmit = has_capability('mod/assignment:submit', $this->context);
 
         add_to_log($this->course->id, 'assignment', 'view', "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
 
@@ -67,35 +68,34 @@ class assignment_upload extends assignment_base {
             } else {
                 $filecount = 0;
             }
+            if ($cansubmit or !empty($filecount)) { //if a user has submitted files using a previous role we should still show the files
+                $this->view_feedback();
 
-            $this->view_feedback();
-
-            if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) {
-                echo $OUTPUT->heading(get_string('submission', 'assignment'), 3);
-            } else {
-                echo $OUTPUT->heading(get_string('submissiondraft', 'assignment'), 3);
-            }
+                if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) {
+                    echo $OUTPUT->heading(get_string('submission', 'assignment'), 3);
+                } else {
+                    echo $OUTPUT->heading(get_string('submissiondraft', 'assignment'), 3);
+                }
 
-            if ($filecount and $submission) {
-                echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter', 'userfiles');
-            } else {
-                if (!$this->isopen() or $this->is_finalized($submission)) {
-                    echo $OUTPUT->box(get_string('nofiles', 'assignment'), 'generalbox boxaligncenter nofiles', 'userfiles');
+                if ($filecount and $submission) {
+                    echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter', 'userfiles');
                 } else {
-                    echo $OUTPUT->box(get_string('nofilesyet', 'assignment'), 'generalbox boxaligncenter nofiles', 'userfiles');
+                    if (!$this->isopen() or $this->is_finalized($submission)) {
+                        echo $OUTPUT->box(get_string('nofiles', 'assignment'), 'generalbox boxaligncenter nofiles', 'userfiles');
+                    } else {
+                        echo $OUTPUT->box(get_string('nofilesyet', 'assignment'), 'generalbox boxaligncenter nofiles', 'userfiles');
+                    }
                 }
-            }
 
-            if (has_capability('mod/assignment:submit', $this->context)) {
                 $this->view_upload_form();
-            }
 
-            if ($this->notes_allowed()) {
-                echo $OUTPUT->heading(get_string('notes', 'assignment'), 3);
-                $this->view_notes();
-            }
+                if ($this->notes_allowed()) {
+                    echo $OUTPUT->heading(get_string('notes', 'assignment'), 3);
+                    $this->view_notes();
+                }
 
-            $this->view_final_submission();
+                $this->view_final_submission();
+            }
         }
         $this->view_footer();
     }
diff --git a/mod/data/filter.php b/mod/data/filter.php
deleted file mode 100644 (file)
index 6a81b2b..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-    //
-    // This function provides automatic linking to data contents of text
-    // fields where these fields have autolink enabled.
-    //
-    // Original code by Williams, Stronk7, Martin D.
-    // Modified for data module by Vy-Shane SF.
-
-    function data_filter($courseid, $text) {
-        global $CFG, $DB;
-
-        static $nothingtodo;
-        static $contentlist;
-
-        if (!empty($nothingtodo)) {   // We've been here in this page already
-            return $text;
-        }
-
-        // if we don't have a courseid, we can't run the query, so
-        if (empty($courseid)) {
-            return $text;
-        }
-
-        // Create a list of all the resources to search for. It may be cached already.
-        if (empty($contentlist)) {
-            // We look for text field contents only, and only if the field has
-            // autolink enabled (param1).
-            $sql = 'SELECT dc.id AS contentid, ' .
-                   'dr.id AS recordid, ' .
-                   'dc.content AS content, ' .
-                   'd.id AS dataid ' .
-                        'FROM {data} d, ' .
-                             '{data_fields} df, ' .
-                             '{data_records} dr, ' .
-                             '{data_content} dc ' .
-                            "WHERE (d.course = ? or d.course = '".SITEID."')" .
-                            'AND d.id = df.dataid ' .
-                            'AND df.id = dc.fieldid ' .
-                            'AND d.id = dr.dataid ' .
-                            'AND dr.id = dc.recordid ' .
-                            "AND df.type = 'text' " .
-                            "AND " . $DB->sql_compare_text('df.param1', 1) . " = '1'";
-
-            if (!$datacontents = $DB->get_records_sql($sql, array($courseid))) {
-                return $text;
-            }
-
-            $contentlist = array();
-
-            foreach ($datacontents as $datacontent) {
-                $currentcontent = trim($datacontent->content);
-                $strippedcontent = strip_tags($currentcontent);
-
-                if (!empty($strippedcontent)) {
-                    $contentlist[] = new filterobject(
-                                            $currentcontent,
-                                            '<a class="data autolink" title="'.
-                                            $strippedcontent.'" href="'.
-                                            $CFG->wwwroot.'/mod/data/view.php?d='. $datacontent->dataid .
-                                            '&amp;rid='. $datacontent->recordid .'">',
-                                            '</a>', false, true);
-                }
-            } // End foreach
-        }
-        return  filter_phrases($text, $contentlist);  // Look for all these links in the text
-    }
-
-
index deba450..241c818 100644 (file)
@@ -1,12 +1,30 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-////////////////////////////////////////////////////////////////////////////////
-//  Code fragment to define the module version etc.
-//  This fragment is called by /admin/index.php
-////////////////////////////////////////////////////////////////////////////////
-
-$module->version  = 2011052300;
-$module->requires = 2011052300;  // Requires this Moodle version
-$module->cron     = 60;
+/**
+ * Data module version information
+ *
+ * @package    mod
+ * @subpackage data
+ * @copyright  2005 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
 
+defined('MOODLE_INTERNAL') || die();
 
+$module->version  = 2011102800;
+$module->requires = 2011102700;  // Requires this Moodle version
+$module->cron     = 60;          // Period for cron to check this module (secs)
index 9a0c603..c88bf75 100644 (file)
@@ -135,7 +135,8 @@ Now it only runs on Moodle 1.8 or later
 - roles are full implemented
 - now radiobuttons and checkboxes can be aligned horizontally or vertically
 - now you can insert pagebreakes
-- a feedback what is switch to the next page is saved temporary. the user can cancel the completion and later continue at the last filled page.
+- a feedback what is switch to the next page is saved temporary.
+  the user can cancel the completion and later continue at the last filled page.
 - now you can ex-/import feedbacks into/from a xml-file
 - course-reseting is supported
 
index 78f46d5..da86ecf 100644 (file)
@@ -1,4 +1,18 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * shows an analysed view of feedback
@@ -11,7 +25,6 @@
 require_once("../../config.php");
 require_once("lib.php");
 
-// $SESSION->feedback->current_tab = 'analysis';
 $current_tab = 'analysis';
 
 $id = required_param('id', PARAM_INT);  //the POST dominated the GET
@@ -39,23 +52,23 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
         print_error('badcontext');
 }
 
-if($course->id == SITEID) {
+if ($course->id == SITEID) {
     require_login($course->id, true);
-}else{
+} else {
     require_login($course->id, true, $cm);
 }
 
 //check whether the given courseid exists
-if($courseid AND $courseid != SITEID) {
-    if($course2 = $DB->get_record('course', array('id'=>$courseid))){
+if ($courseid AND $courseid != SITEID) {
+    if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
         require_course_login($course2); //this overwrites the object $course :-(
         $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
-    }else {
+    } else {
         print_error('invalidcourseid');
     }
 }
 
-if( !( ((intval($feedback->publish_stats) == 1) AND
+if ( !( ((intval($feedback->publish_stats) == 1) AND
         has_capability('mod/feedback:viewanalysepage', $context)) OR
         has_capability('mod/feedback:viewreports', $context))) {
     print_error('error');
@@ -65,30 +78,29 @@ if( !( ((intval($feedback->publish_stats) == 1) AND
 $strfeedbacks = get_string("modulenameplural", "feedback");
 $strfeedback  = get_string("modulename", "feedback");
 
-$PAGE->navbar->add(get_string('analysis','feedback'));
+$PAGE->navbar->add(get_string('analysis', 'feedback'));
 $PAGE->set_heading(format_string($course->fullname));
 $PAGE->set_title(format_string($feedback->name));
 echo $OUTPUT->header();
 
 /// print the tabs
-include('tabs.php');
+require('tabs.php');
 
 
 //print analysed items
 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
 
 //get the groupid
-$groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/analysis.php?id=' . $cm->id.'&do_show=analysis', true);
+$myurl = $CFG->wwwroot.'/mod/feedback/analysis.php?id='.$cm->id.'&do_show=analysis';
+$groupselect = groups_print_activity_menu($cm, $myurl, true);
 $mygroupid = groups_get_activity_group($cm);
 
-if( has_capability('mod/feedback:viewreports', $context) ) {
+if ( has_capability('mod/feedback:viewreports', $context) ) {
 
     echo isset($groupselect) ? $groupselect : '';
     echo '<div class="clearer"></div>';
 
     //button "export to excel"
-    //echo '<div class="mdl-align">';
-    // echo '<div class="feedback_centered_button">';
     echo $OUTPUT->container_start('form-buttons');
     $aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id));
     echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
@@ -99,50 +111,55 @@ if( has_capability('mod/feedback:viewreports', $context) ) {
 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
 
 //show the group, if available
-if($mygroupid and $group = $DB->get_record('groups', array('id'=>$mygroupid))) {
+if ($mygroupid and $group = $DB->get_record('groups', array('id'=>$mygroupid))) {
     echo '<b>'.get_string('group').': '.$group->name. '</b><br />';
 }
 //show the count
 echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
 
 // get the items of the feedback
-$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position');
+$items = $DB->get_records('feedback_item',
+                          array('feedback'=>$feedback->id, 'hasvalue'=>1),
+                          'position');
 //show the count
-if(is_array($items)){
-    echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />';
+if (is_array($items)) {
+    echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
 } else {
     $items=array();
 }
 $check_anonymously = true;
-if($mygroupid > 0 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES) {
-    if($completedscount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP) {
+if ($mygroupid > 0 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES) {
+    if ($completedscount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP) {
         $check_anonymously = false;
     }
 }
-// echo '<div class="mdl-align"><table width="80%" cellpadding="10"><tr><td>';
+
 echo '<div><table width="80%" cellpadding="10"><tr><td>';
-if($check_anonymously) {
+if ($check_anonymously) {
     $itemnr = 0;
     //print the items in an analysed form
-    foreach($items as $item) {
-        if($item->hasvalue == 0) continue;
+    foreach ($items as $item) {
+        if ($item->hasvalue == 0) {
+            continue;
+        }
         echo '<table width="100%" class="generalbox">';
-        
+
         //get the class of item-typ
         $itemobj = feedback_get_item_class($item->typ);
-        
+
         $itemnr++;
-        if($feedback->autonumbering) {
+        if ($feedback->autonumbering) {
             $printnr = $itemnr.'.';
         } else {
             $printnr = '';
         }
         $itemobj->print_analysed($item, $printnr, $mygroupid);
-        // $itemnr = $itemobj->print_analysed($item, $itemnr, $mygroupid);
         echo '</table>';
     }
-}else {
-    echo $OUTPUT->heading_with_help(get_string('insufficient_responses_for_this_group', 'feedback'), 'insufficient_responses', 'feedback');
+} else {
+    echo $OUTPUT->heading_with_help(get_string('insufficient_responses_for_this_group', 'feedback'),
+                                    'insufficient_responses',
+                                    'feedback');
 }
 echo '</td></tr></table></div>';
 echo $OUTPUT->box_end();
index 548d4c8..831863b 100644 (file)
@@ -1,24 +1,36 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
-* shows an analysed view of a feedback on the mainsite
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+ * shows an analysed view of a feedback on the mainsite
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
 
 require_once("../../config.php");
 require_once("lib.php");
 
-// $SESSION->feedback->current_tab = 'analysis';
 $current_tab = 'analysis';
 
 $id = required_param('id', PARAM_INT);  //the POST dominated the GET
 $coursefilter = optional_param('coursefilter', '0', PARAM_INT);
 $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
 $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
-// $searchcourse = optional_param('searchcourse', '', PARAM_ALPHAEXT);
 $searchcourse = optional_param('searchcourse', '', PARAM_RAW);
 $courseid = optional_param('courseid', false, PARAM_INT);
 
@@ -40,7 +52,7 @@ if ($searchcourse !== '') {
 }
 $PAGE->set_url($url);
 
-if(($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
+if (($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
     print_error('invalidsesskey');
 }
 
@@ -62,7 +74,7 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
 
 require_login($course->id, true, $cm);
 
-if( !( (intval($feedback->publish_stats) == 1) OR has_capability('mod/feedback:viewreports', $context))) {
+if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
     print_error('error');
 }
 
@@ -75,15 +87,19 @@ $PAGE->set_title(format_string($feedback->name));
 echo $OUTPUT->header();
 
 /// print the tabs
-include('tabs.php');
+require('tabs.php');
 
 //print the analysed items
 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
 
-if( has_capability('mod/feedback:viewreports', $context) ) {
+if (has_capability('mod/feedback:viewreports', $context)) {
     //button "export to excel"
     echo $OUTPUT->container_start('mdl-align');
-    $aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id, 'coursefilter'=>$coursefilter));
+    $aurl = new moodle_url('analysis_to_excel.php',
+                           array('sesskey' => sesskey(),
+                                 'id' => $id,
+                                 'coursefilter' => $coursefilter));
+
     echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
     echo $OUTPUT->container_end();
 }
@@ -98,11 +114,14 @@ $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $c
 echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
 
 // get the items of the feedback
-$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position');
+$params = array('feedback' => $feedback->id, 'hasvalue' => 1);
+$items = $DB->get_records('feedback_item', $params, 'position');
 //show the count
-if(is_array($items)){
-    echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />';
-    echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">'.get_string('show_all', 'feedback').'</a>';
+if (is_array($items)) {
+    echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
+    echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">';
+    echo get_string('show_all', 'feedback');
+    echo '</a>';
 } else {
     $items=array();
 }
@@ -114,12 +133,14 @@ if ($courseitemfilter > 0) {
     if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-)
          $avgvalue = 'avg(cast (value as integer))';
     }
-    if ($courses = $DB->get_records_sql ("SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
-                                            FROM {feedback_value} fv, {course} c, {feedback_item} fi
-                                           WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
-                                        GROUP BY course_id, shortname
-                                        ORDER BY avgvalue desc",
-                                          array($courseitemfiltertyp, $courseitemfilter))) {
+
+    $sql = "SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
+            FROM {feedback_value} fv, {course} c, {feedback_item} fi
+            WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
+            GROUP BY course_id, shortname
+            ORDER BY avgvalue desc";
+
+    if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
         $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
         echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
         echo '<tr><td><table align="left">';
@@ -128,8 +149,15 @@ if ($courseitemfilter > 0) {
         $sep_thous = get_string('separator_thousand', 'feedback');
 
         foreach ($courses as $c) {
-            $shortname = format_string($c->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $c->course_id)));
-            echo '<tr><td>'.$shortname.'</td><td align="right">'.number_format(($c->avgvalue), 2, $sep_dec, $sep_thous).'</td></tr>';
+            $coursecontext = get_context_instance(CONTEXT_COURSE, $c->course_id);
+            $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
+
+            echo '<tr>';
+            echo '<td>'.$shortname.'</td>';
+            echo '<td align="right">'
+            echo number_format(($c->avgvalue), 2, $sep_dec, $sep_thous);
+            echo '</td>';
+            echo '</tr>';
         }
          echo '</table></td></tr>';
     } else {
@@ -138,7 +166,8 @@ if ($courseitemfilter > 0) {
 } else {
 
     echo get_string('search_course', 'feedback') . ': ';
-    echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> <input type="submit" value="'.get_string('search').'"/>';
+    echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> ';
+    echo '<input type="submit" value="'.get_string('search').'"/>';
     echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
     echo '<input type="hidden" name="id" value="'.$id.'" />';
     echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
@@ -158,28 +187,40 @@ if ($courseitemfilter > 0) {
 
          echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
 
-         echo html_writer::select($courses, 'coursefilter', $coursefilter, null, array('id'=>'coursefilterid'));
-         $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('analysis-form', 'coursefilterid', false));
+         echo html_writer::select($courses, 'coursefilter', $coursefilter,
+                                  null, array('id'=>'coursefilterid'));
+
+         $PAGE->requires->js_init_call('M.util.init_select_autosubmit',
+                                        array('analysis-form', 'coursefilterid', false));
     }
     echo '<hr />';
     $itemnr = 0;
     //print the items in an analysed form
     echo '<tr><td>';
-    foreach($items as $item) {
-        if($item->hasvalue == 0) continue;
+    foreach ($items as $item) {
+        if ($item->hasvalue == 0) {
+            continue;
+        }
         echo '<table width="100%" class="generalbox">';
         //get the class from item-typ
         $itemobj = feedback_get_item_class($item->typ);
         $itemnr++;
-        if($feedback->autonumbering) {
+        if ($feedback->autonumbering) {
             $printnr = $itemnr.'.';
         } else {
             $printnr = '';
         }
         $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
         if (preg_match('/rated$/i', $item->typ)) {
-             echo '<tr><td colspan="2"><a href="#" onclick="setcourseitemfilter('.$item->id.',\''.$item->typ.'\'); return false;">'.
-                get_string('sort_by_course', 'feedback').'</a></td></tr>';
+            $onclick = 'onclick="setcourseitemfilter'.
+                        "(".$item->id.",'".$item->typ."');".
+                        ' return false;"';
+
+            $anker = '<a href="#" '.$onclick.'>'.
+                     get_string('sort_by_course', 'feedback').
+                     '</a>';
+
+            echo '<tr><td colspan="2">'.$anker.'</td></tr>';
         }
         echo '</table>';
     }
index 887735e..089bc9d 100644 (file)
@@ -1,16 +1,29 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
-* prints an analysed excel-spreadsheet of the feedback
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+ * prints an analysed excel-spreadsheet of the feedback
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
 
 require_once("../../config.php");
 require_once("lib.php");
-// require_once('easy_excel.php');
 require_once("$CFG->libdir/excellib.class.php");
 
 feedback_load_feedback_items();
@@ -63,12 +76,15 @@ $fstring->username = get_string('username');
 $fstring->fullname = get_string('fullnameuser');
 $fstring->courseid = get_string('courseid', 'feedback');
 $fstring->course = get_string('course');
-$fstring->anonymous_user = get_string('anonymous_user','feedback');
+$fstring->anonymous_user = get_string('anonymous_user', 'feedback');
 ob_end_clean();
 
 //get the questions (item-names)
-if(!$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position')) {
-    print_error('no_items_available_yet', 'feedback', $CFG->wwwroot.'/mod/feedback/view.php?id='.$id);
+$params = array('feedback' => $feedback->id, 'hasvalue' => 1);
+if (!$items = $DB->get_records('feedback_item', $params, 'position')) {
+    print_error('no_items_available_yet',
+                'feedback',
+                $CFG->wwwroot.'/mod/feedback/view.php?id='.$id);
     exit;
 }
 
@@ -77,54 +93,30 @@ $filename = "feedback.xls";
 $mygroupid = groups_get_activity_group($cm);
 
 // Creating a workbook
-// $workbook = new EasyWorkbook("-");
 $workbook = new MoodleExcelWorkbook('-');
-// $workbook->setTempDir($CFG->tempdir.'');
 $workbook->send($filename);
-// $workbook->setVersion(8);
 
 //creating the needed formats
-$xlsFormats = new stdClass();
-$xlsFormats->head1 = $workbook->add_format(array(
+$xls_formats = new stdClass();
+$xls_formats->head1 = $workbook->add_format(array(
                         'bold'=>1,
                         'size'=>12));
 
-$xlsFormats->head2 = $workbook->add_format(array(
+$xls_formats->head2 = $workbook->add_format(array(
                         'align'=>'left',
                         'bold'=>1,
                         'bottum'=>2));
 
-$xlsFormats->default = $workbook->add_format(array(
+$xls_formats->default = $workbook->add_format(array(
                         'align'=>'left',
                         'v_align'=>'top'));
 
-// $xlsFormats->head2_green = $workbook->add_format(array(
-                        // 'align'=>'left',
-                        // 'bold'=>1,
-                        // 'v_align'=>'top',
-                        // 'bottum'=>2,
-                        // 'fg_color'=>'green'));
-
-$xlsFormats->value_bold = $workbook->add_format(array(
+$xls_formats->value_bold = $workbook->add_format(array(
                         'align'=>'left',
                         'bold'=>1,
                         'v_align'=>'top'));
 
-// $xlsFormats->value_blue = $workbook->add_format(array(
-                        // 'align'=>'left',
-                        // 'bold'=>1,
-                        // 'v_align'=>'top',
-                        // 'top'=>2,
-                        // 'fg_color'=>'blue'));
-
-// $xlsFormats->value_red = $workbook->add_format(array(
-                        // 'align'=>'left',
-                        // 'bold'=>1,
-                        // 'v_align'=>'top',
-                        // 'top'=>2,
-                        // 'fg_color'=>'red'));
-
-$xlsFormats->procent = $workbook->add_format(array(
+$xls_formats->procent = $workbook->add_format(array(
                         'align'=>'left',
                         'bold'=>1,
                         'v_align'=>'top',
@@ -134,59 +126,57 @@ $xlsFormats->procent = $workbook->add_format(array(
 $sheetname = clean_param($feedback->name, PARAM_ALPHANUM);
 error_reporting(0);
 $worksheet1 =& $workbook->add_worksheet(substr($sheetname, 0, 31));
-// $worksheet1->set_workbook($workbook);
 $worksheet2 =& $workbook->add_worksheet('detailed');
-// $worksheet2->set_workbook($workbook);
 error_reporting($CFG->debug);
-// $worksheet1->pear_excel_worksheet->set_portrait();
-// $worksheet1->pear_excel_worksheet->set_paper(9);
-// $worksheet1->pear_excel_worksheet->center_horizontally();
 $worksheet1->hide_gridlines();
-// $worksheet1->pear_excel_worksheet->set_header("&\"Arial," . $fstring->bold . "\"&14".$feedback->name);
-// $worksheet1->pear_excel_worksheet->set_footer($fstring->page." &P " . $fstring->of . " &N");
 $worksheet1->set_column(0, 0, 10);
 $worksheet1->set_column(1, 1, 30);
 $worksheet1->set_column(2, 20, 15);
-// $worksheet1->set_margins_LR(0.10);
-
-// $worksheet2->pear_excel_worksheet->set_landscape();
-// $worksheet2->pear_excel_worksheet->set_paper(9);
-// $worksheet2->pear_excel_worksheet->center_horizontally();
 
 //writing the table header
-$rowOffset1 = 0;
-// $worksheet1->setFormat("<f>",12,false);
-$worksheet1->write_string($rowOffset1, 0, UserDate(time()), $xlsFormats->head1);
+$row_offset1 = 0;
+$worksheet1->write_string($row_offset1, 0, userdate(time()), $xls_formats->head1);
 
 ////////////////////////////////////////////////////////////////////////
 //print the analysed sheet
 ////////////////////////////////////////////////////////////////////////
 //get the completeds
 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
-if($completedscount > 0){
+if ($completedscount > 0) {
     //write the count of completeds
-    $rowOffset1++;
-    $worksheet1->write_string($rowOffset1, 0, $fstring->modulenameplural.': '.strval($completedscount), $xlsFormats->head1);
+    $row_offset1++;
+    $worksheet1->write_string($row_offset1,
+                              0,
+                              $fstring->modulenameplural.': '.strval($completedscount),
+                              $xls_formats->head1);
 }
 
-if(is_array($items)){
-    $rowOffset1++;
-    $worksheet1->write_string($rowOffset1, 0, $fstring->questions.': '. strval(sizeof($items)), $xlsFormats->head1);
+if (is_array($items)) {
+    $row_offset1++;
+    $worksheet1->write_string($row_offset1,
+                              0,
+                              $fstring->questions.': '. strval(count($items)),
+                              $xls_formats->head1);
 }
 
-$rowOffset1 += 2;
-$worksheet1->write_string($rowOffset1, 0, $fstring->itemlabel, $xlsFormats->head1);
-$worksheet1->write_string($rowOffset1, 1, $fstring->question, $xlsFormats->head1);
-$worksheet1->write_string($rowOffset1, 2, $fstring->responses, $xlsFormats->head1);
-$rowOffset1++ ;
+$row_offset1 += 2;
+$worksheet1->write_string($row_offset1, 0, $fstring->itemlabel, $xls_formats->head1);
+$worksheet1->write_string($row_offset1, 1, $fstring->question, $xls_formats->head1);
+$worksheet1->write_string($row_offset1, 2, $fstring->responses, $xls_formats->head1);
+$row_offset1++;
 
 if (empty($items)) {
      $items=array();
 }
-foreach($items as $item) {
+foreach ($items as $item) {
     //get the class of item-typ
     $itemobj = feedback_get_item_class($item->typ);
-    $rowOffset1 = $itemobj->excelprint_item($worksheet1, $rowOffset1, $xlsFormats, $item, $mygroupid, $coursefilter);
+    $row_offset1 = $itemobj->excelprint_item($worksheet1,
+                                            $row_offset1,
+                                            $xls_formats,
+                                            $item,
+                                            $mygroupid,
+                                            $coursefilter);
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -199,14 +189,18 @@ $completeds = feedback_get_completeds_group($feedback, $mygroupid, $coursefilter
 //therefor for each completed we have to iterate over all items of the feedback
 //this is done by feedback_excelprint_detailed_items
 
-$rowOffset2 = 0;
+$row_offset2 = 0;
 //first we print the table-header
-$rowOffset2 = feedback_excelprint_detailed_head($worksheet2, $xlsFormats, $items, $rowOffset2);
+$row_offset2 = feedback_excelprint_detailed_head($worksheet2, $xls_formats, $items, $row_offset2);
 
 
-if(is_array($completeds)){
-    foreach($completeds as $completed) {
-        $rowOffset2 = feedback_excelprint_detailed_items($worksheet2, $xlsFormats, $completed, $items, $rowOffset2);
+if (is_array($completeds)) {
+    foreach ($completeds as $completed) {
+        $row_offset2 = feedback_excelprint_detailed_items($worksheet2,
+                                                         $xls_formats,
+                                                         $completed,
+                                                         $items,
+                                                         $row_offset2);
     }
 }
 
@@ -219,100 +213,102 @@ exit;
 ////////////////////////////////////////////////////////////////////////////////
 
 
-function feedback_excelprint_detailed_head(&$worksheet, $xlsFormats, $items, $rowOffset) {
+function feedback_excelprint_detailed_head(&$worksheet, $xls_formats, $items, $row_offset) {
     global $fstring, $feedback;
 
-    if(!$items) return;
-    $colOffset = 0;
-
-    // $worksheet->setFormat('<l><f><ru2>');
+    if (!$items) {
+        return;
+    }
+    $col_offset = 0;
 
-    $worksheet->write_string($rowOffset + 1, $colOffset, $fstring->idnumber, $xlsFormats->head2);
-    $colOffset++;
+    $worksheet->write_string($row_offset + 1, $col_offset, $fstring->idnumber, $xls_formats->head2);
+    $col_offset++;
 
-    $worksheet->write_string($rowOffset + 1, $colOffset, $fstring->username, $xlsFormats->head2);
-    $colOffset++;
+    $worksheet->write_string($row_offset + 1, $col_offset, $fstring->username, $xls_formats->head2);
+    $col_offset++;
 
-    $worksheet->write_string($rowOffset + 1, $colOffset, $fstring->fullname, $xlsFormats->head2);
-    $colOffset++;
+    $worksheet->write_string($row_offset + 1, $col_offset, $fstring->fullname, $xls_formats->head2);
+    $col_offset++;
 
-    foreach($items as $item) {
-        // $worksheet->setFormat('<l><f><ru2>');
-        $worksheet->write_string($rowOffset, $colOffset, $item->name, $xlsFormats->head2);
-        $worksheet->write_string($rowOffset + 1, $colOffset, $item->label, $xlsFormats->head2);
-        $colOffset++;
+    foreach ($items as $item) {
+        $worksheet->write_string($row_offset, $col_offset, $item->name, $xls_formats->head2);
+        $worksheet->write_string($row_offset + 1, $col_offset, $item->label, $xls_formats->head2);
+        $col_offset++;
     }
 
-    // $worksheet->setFormat('<l><f><ru2>');
-    $worksheet->write_string($rowOffset + 1, $colOffset, $fstring->courseid, $xlsFormats->head2);
-    $colOffset++;
+    $worksheet->write_string($row_offset + 1, $col_offset, $fstring->courseid, $xls_formats->head2);
+    $col_offset++;
 
-    // $worksheet->setFormat('<l><f><ru2>');
-    $worksheet->write_string($rowOffset + 1, $colOffset, $fstring->course, $xlsFormats->head2);
-    $colOffset++;
+    $worksheet->write_string($row_offset + 1, $col_offset, $fstring->course, $xls_formats->head2);
+    $col_offset++;
 
-    return $rowOffset + 2;
+    return $row_offset + 2;
 }
 
-function feedback_excelprint_detailed_items(&$worksheet, $xlsFormats, $completed, $items, $rowOffset) {
+function feedback_excelprint_detailed_items(&$worksheet, $xls_formats,
+                                            $completed, $items, $row_offset) {
     global $DB, $fstring;
 
-    if(!$items) return;
-    $colOffset = 0;
+    if (!$items) {
+        return;
+    }
+    $col_offset = 0;
     $courseid = 0;
 
     $feedback = $DB->get_record('feedback', array('id'=>$completed->feedback));
     //get the username
     //anonymous users are separated automatically because the userid in the completed is "0"
-    // $worksheet->setFormat('<l><f><ru2>');
-    if($user = $DB->get_record('user', array('id'=>$completed->userid))) {
+    if ($user = $DB->get_record('user', array('id'=>$completed->userid))) {
         if ($completed->anonymous_response == FEEDBACK_ANONYMOUS_NO) {
-            $worksheet->write_string($rowOffset, $colOffset, $user->idnumber, $xlsFormats->head2);
-            $colOffset++;
+            $worksheet->write_string($row_offset, $col_offset, $user->idnumber, $xls_formats->head2);
+            $col_offset++;
             $userfullname = fullname($user);
-            $worksheet->write_string($rowOffset, $colOffset, $user->username, $xlsFormats->head2);
-            $colOffset++;
+            $worksheet->write_string($row_offset, $col_offset, $user->username, $xls_formats->head2);
+            $col_offset++;
         } else {
             $userfullname = $fstring->anonymous_user;
-            $worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2);
-            $colOffset++;
-            $worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2);
-            $colOffset++;
+            $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
+            $col_offset++;
+            $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
+            $col_offset++;
         }
-    }else {
+    } else {
         $userfullname = $fstring->anonymous_user;
-        $worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2);
-        $colOffset++;
-        $worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2);
-        $colOffset++;
+        $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
+        $col_offset++;
+        $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
+        $col_offset++;
     }
 
-    $worksheet->write_string($rowOffset, $colOffset, $userfullname, $xlsFormats->head2);
+    $worksheet->write_string($row_offset, $col_offset, $userfullname, $xls_formats->head2);
 
-    $colOffset++;
-    foreach($items as $item) {
-        $value = $DB->get_record('feedback_value', array('item'=>$item->id, 'completed'=>$completed->id));
+    $col_offset++;
+    foreach ($items as $item) {
+        $params = array('item' => $item->id, 'completed' => $completed->id);
+        $value = $DB->get_record('feedback_value', $params);
 
         $itemobj = feedback_get_item_class($item->typ);
         $printval = $itemobj->get_printval($item, $value);
         $printval = trim($printval);
 
-        // $worksheet->setFormat('<l><vo>');
-        if(is_numeric($printval)) {
-            $worksheet->write_number($rowOffset, $colOffset, $printval, $xlsFormats->default);
-        } elseif($printval != '') {
-            $worksheet->write_string($rowOffset, $colOffset, $printval, $xlsFormats->default);
+        if (is_numeric($printval)) {
+            $worksheet->write_number($row_offset, $col_offset, $printval, $xls_formats->default);
+        } else if ($printval != '') {
+            $worksheet->write_string($row_offset, $col_offset, $printval, $xls_formats->default);
         }
         $printval = '';
-        $colOffset++;
+        $col_offset++;
         $courseid = isset($value->course_id) ? $value->course_id : 0;
-        if($courseid == 0) $courseid = $feedback->course;
+        if ($courseid == 0) {
+            $courseid = $feedback->course;
+        }
     }
-    $worksheet->write_number($rowOffset, $colOffset, $courseid, $xlsFormats->default);
-    $colOffset++;
+    $worksheet->write_number($row_offset, $col_offset, $courseid, $xls_formats->default);
+    $col_offset++;
     if (isset($courseid) AND $course = $DB->get_record('course', array('id' => $courseid))) {
-        $shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
-        $worksheet->write_string($rowOffset, $colOffset, $shortname, $xlsFormats->default);
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+        $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
+        $worksheet->write_string($row_offset, $col_offset, $shortname, $xls_formats->default);
     }
-    return $rowOffset + 1;
+    return $row_offset + 1;
 }
index 5ddd20f..ad6da8f 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
index acdc227..7fd8ceb 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -53,7 +52,7 @@ class backup_feedback_activity_task extends backup_activity_task {
     static public function encode_content_links($content) {
         global $CFG;
 
-        $base = preg_quote($CFG->wwwroot,"/");
+        $base = preg_quote($CFG->wwwroot, "/");
 
         // Link to the list of feedbacks
         $search="/(".$base."\/mod\/feedback\/index.php\?id\=)([0-9]+)/";
index b66e78a..c683516 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
index 142244a..b4681c9 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -54,7 +53,6 @@ class backup_feedback_activity_structure_step extends backup_activity_structure_
                                                 'timemodified',
                                                 'completionsubmit'));
 
-
         $completeds = new backup_nested_element('completeds');
 
         $completed = new backup_nested_element('completed', array('id'), array(
@@ -92,7 +90,6 @@ class backup_feedback_activity_structure_step extends backup_activity_structure_
                                                 'completed',
                                                 'value'));
 
-
         // Build the tree
         $feedback->add_child($items);
         $items->add_child($item);
index 362b3a8..83c18d0 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
index fea78c1..b2024d4 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
index 07e0f1a..4519aca 100644 (file)
@@ -1,68 +1,25 @@
 <?php
-/**
-* prints the form to choose the group you want to analyse
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
-
-if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
-}
-
-require_once $CFG->libdir.'/formslib.php';
-
-class feedback_choose_group_form extends moodleform {
-    var $feedbackdata;
-
-    function definition() {
-        $this->feedbackdata = new stdClass();
-        //this function can not be called, because not all data are available at this time
-        //I use set_form_elements instead
-    }
-
-    //this function set the data used in set_form_elements()
-    //in this form the only value have to set is course
-    //eg: array('course' => $course)
-    function set_feedbackdata($data) {
-        if(is_array($data)) {
-            foreach($data as $key => $val) {
-                $this->feedbackdata->{$key} = $val;
-            }
-        }
-    }
-
-    //here the elements will be set
-    //this function have to be called manually
-    //the advantage is that the data are already set
-    function set_form_elements(){
-        $mform =& $this->_form;
-
-        $elementgroup = array();
-        //headline
-        // $mform->addElement('header', 'general', get_string('choose_group', 'feedback'));
-        // hidden elements
-        $mform->addElement('hidden', 'id');
-        $mform->setType('id', PARAM_INT);
-        $mform->addElement('hidden', 'do_show');
-        $mform->setType('do-show', PARAM_INT);
-
-        // visible elements
-        $groups_options = array();
-        if(isset($this->feedbackdata->groups)){
-            $groups_options['-1'] = get_string('allgroups');
-            foreach($this->feedbackdata->groups as $group) {
-                $groups_options[$group->id] = $group->name;
-            }
-        }
-        $attributes = 'onChange="this.form.submit()"';
-        $elementgroup[] =& $mform->createElement('select', 'lstgroupid', '', $groups_options, $attributes);
-        // buttons
-        $elementgroup[] =& $mform->createElement('submit', 'switch_group', get_string('switch_group', 'feedback'));
-        $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
-
-//-------------------------------------------------------------------------------
-    }
-}
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+/**
+ * prints the form to choose the group you want to analyse
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+//This file can be deleted
index 7f81b9b..e6fe6cd 100644 (file)
 <?php
-
-    /**
-    * prints the form so the user can fill out the feedback
-    *
-    * @author Andreas Grabs
-    * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-    * @package feedback
-    */
-
-    require_once("../../config.php");
-    require_once("lib.php");
-    require_once($CFG->libdir . '/completionlib.php');
-
-    feedback_init_feedback_session();
-
-    $id = required_param('id', PARAM_INT);
-    $completedid = optional_param('completedid', false, PARAM_INT);
-    $preservevalues  = optional_param('preservevalues', 0,  PARAM_INT);
-    $courseid = optional_param('courseid', false, PARAM_INT);
-    $gopage = optional_param('gopage', -1, PARAM_INT);
-    $lastpage = optional_param('lastpage', false, PARAM_INT);
-    $startitempos = optional_param('startitempos', 0, PARAM_INT);
-    $lastitempos = optional_param('lastitempos', 0, PARAM_INT);
-    $anonymous_response = optional_param('anonymous_response', 0, PARAM_INT); //arb
-
-    $highlightrequired = false;
-
-    if(($formdata = data_submitted()) AND !confirm_sesskey()) {
-        print_error('invalidsesskey');
-    }
-
-    //if the use hit enter into a textfield so the form should not submit
-    if(isset($formdata->sesskey) AND !isset($formdata->savevalues) AND !isset($formdata->gonextpage) AND !isset($formdata->gopreviouspage)) {
-        $gopage = $formdata->lastpage;
-    }
-
-    if(isset($formdata->savevalues)) {
-        $savevalues = true;
-    }else {
-        $savevalues = false;
-    }
-
-    if($gopage < 0 AND !$savevalues) {
-        if(isset($formdata->gonextpage)){
-            $gopage = $lastpage + 1;
-            $gonextpage = true;
-            $gopreviouspage = false;
-        }else if(isset($formdata->gopreviouspage)){
-            $gopage = $lastpage - 1;
-            $gonextpage = false;
-            $gopreviouspage = true;
-        }else {
-            print_error('missingparameter');
-        }
-    }else {
-        $gonextpage = $gopreviouspage = false;
-    }
-
-    if (! $cm = get_coursemodule_from_id('feedback', $id)) {
-        print_error('invalidcoursemodule');
-    }
-
-    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
-        print_error('invalidcoursemodule');
-    }
-
-    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
-            print_error('badcontext');
-    }
-
-    $feedback_complete_cap = false;
-
-    if(has_capability('mod/feedback:complete', $context)) {
-        $feedback_complete_cap = true;
-    }
-
-    //check whether the feedback is located and! started from the mainsite
-    if($course->id == SITEID AND !$courseid) {
-        $courseid = SITEID;
-    }
-
-    //check whether the feedback is mapped to the given courseid
-    if($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
-        if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
-            if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
-                print_error('notavailable', 'feedback');
-            }
-        }
-    }
-
-    if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
-        if($course->id == SITEID) {
-            require_login($course->id, true);
-        }else {
-            require_login($course->id, true, $cm);
-        }
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * prints the form so the user can fill out the feedback
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+require_once("../../config.php");
+require_once("lib.php");
+require_once($CFG->libdir . '/completionlib.php');
+
+feedback_init_feedback_session();
+
+$id = required_param('id', PARAM_INT);
+$completedid = optional_param('completedid', false, PARAM_INT);
+$preservevalues  = optional_param('preservevalues', 0,  PARAM_INT);
+$courseid = optional_param('courseid', false, PARAM_INT);
+$gopage = optional_param('gopage', -1, PARAM_INT);
+$lastpage = optional_param('lastpage', false, PARAM_INT);
+$startitempos = optional_param('startitempos', 0, PARAM_INT);
+$lastitempos = optional_param('lastitempos', 0, PARAM_INT);
+$anonymous_response = optional_param('anonymous_response', 0, PARAM_INT); //arb
+
+$highlightrequired = false;
+
+if (($formdata = data_submitted()) AND !confirm_sesskey()) {
+    print_error('invalidsesskey');
+}
+
+//if the use hit enter into a textfield so the form should not submit
+if (isset($formdata->sesskey) AND
+    !isset($formdata->savevalues) AND
+    !isset($formdata->gonextpage) AND
+    !isset($formdata->gopreviouspage)) {
+
+    $gopage = $formdata->lastpage;
+}
+
+if (isset($formdata->savevalues)) {
+    $savevalues = true;
+} else {
+    $savevalues = false;
+}
+
+if ($gopage < 0 AND !$savevalues) {
+    if (isset($formdata->gonextpage)) {
+        $gopage = $lastpage + 1;
+        $gonextpage = true;
+        $gopreviouspage = false;
+    } else if (isset($formdata->gopreviouspage)) {
+        $gopage = $lastpage - 1;
+        $gonextpage = false;
+        $gopreviouspage = true;
     } else {
-        if($course->id == SITEID) {
-            require_course_login($course, true);
-        }else {
-            require_course_login($course, true, $cm);
-        }
+        print_error('missingparameter');
     }
-
-    //check whether the given courseid exists
-    if($courseid AND $courseid != SITEID) {
-        if($course2 = $DB->get_record('course', array('id'=>$courseid))){
-            require_course_login($course2); //this overwrites the object $course :-(
-            $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
-        }else {
-            print_error('invalidcourseid');
+} else {
+    $gonextpage = $gopreviouspage = false;
+}
+
+if (! $cm = get_coursemodule_from_id('feedback', $id)) {
+    print_error('invalidcoursemodule');
+}
+
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
+    print_error('coursemisconf');
+}
+
+if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+        print_error('badcontext');
+}
+
+$feedback_complete_cap = false;
+
+if (has_capability('mod/feedback:complete', $context)) {
+    $feedback_complete_cap = true;
+}
+
+//check whether the feedback is located and! started from the mainsite
+if ($course->id == SITEID AND !$courseid) {
+    $courseid = SITEID;
+}
+
+//check whether the feedback is mapped to the given courseid
+if ($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
+    if ($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
+        $params = array('feedbackid'=>$feedback->id, 'courseid'=>$courseid);
+        if (!$DB->get_record('feedback_sitecourse_map', $params)) {
+            print_error('notavailable', 'feedback');
         }
     }
+}
 
-    if(!$feedback_complete_cap) {
-        print_error('error');
-    }
-
-    // Mark activity viewed for completion-tracking
-    $completion = new completion_info($course);
-    $completion->set_module_viewed($cm);
-
-    /// Print the page header
-    $strfeedbacks = get_string("modulenameplural", "feedback");
-    $strfeedback  = get_string("modulename", "feedback");
-
-    if($course->id == SITEID) {
-        $PAGE->set_cm($cm, $course); // set's up global $COURSE
-        $PAGE->set_pagelayout('incourse');
+if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
+    if ($course->id == SITEID) {
+        require_login($course->id, true);
+    } else {
+        require_login($course->id, true, $cm);
     }
-
-    $PAGE->navbar->add(get_string('feedback:complete', 'feedback'));
-    $PAGE->set_url('/mod/feedback/complete.php', array('id'=>$cm->id, 'gopage'=>$gopage, 'courseid'=>$course->id));
-    $PAGE->set_heading(format_string($course->fullname));
-    $PAGE->set_title(format_string($feedback->name));
-    echo $OUTPUT->header();
-
-    //ishidden check.
-    //feedback in courses
-    if ((empty($cm->visible) AND
-            !has_capability('moodle/course:viewhiddenactivities', $context)) AND
-            $course->id != SITEID) {
-        notice(get_string("activityiscurrentlyhidden"));
+} else {
+    if ($course->id == SITEID) {
+        require_course_login($course, true);
+    } else {
+        require_course_login($course, true, $cm);
     }
+}
 
-    //ishidden check.
-    //feedback on mainsite
-    if ((empty($cm->visible) AND
-            !has_capability('moodle/course:viewhiddenactivities', $context)) AND
-            $courseid == SITEID) {
-        notice(get_string("activityiscurrentlyhidden"));
+//check whether the given courseid exists
+if ($courseid AND $courseid != SITEID) {
+    if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
+        require_course_login($course2); //this overwrites the object $course :-(
+        $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
+    } else {
+        print_error('invalidcourseid');
     }
-
-    feedback_print_errors();
-
-    //check, if the feedback is open (timeopen, timeclose)
-    $checktime = time();
-    if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
-        echo $OUTPUT->box_start('generalbox boxaligncenter');
-            echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
-            echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
-        echo $OUTPUT->box_end();
-        echo $OUTPUT->footer();
-        exit;
+}
+
+if (!$feedback_complete_cap) {
+    print_error('error');
+}
+
+// Mark activity viewed for completion-tracking
+$completion = new completion_info($course);
+$completion->set_module_viewed($cm);
+
+/// Print the page header
+$strfeedbacks = get_string("modulenameplural", "feedback");
+$strfeedback  = get_string("modulename", "feedback");
+
+if ($course->id == SITEID) {
+    $PAGE->set_cm($cm, $course); // set's up global $COURSE
+    $PAGE->set_pagelayout('incourse');
+}
+
+$PAGE->navbar->add(get_string('feedback:complete', 'feedback'));
+$urlparams = array('id'=>$cm->id, 'gopage'=>$gopage, 'courseid'=>$course->id);
+$PAGE->set_url('/mod/feedback/complete.php', $urlparams);
+$PAGE->set_heading(format_string($course->fullname));
+$PAGE->set_title(format_string($feedback->name));
+echo $OUTPUT->header();
+
+//ishidden check.
+//feedback in courses
+if ((empty($cm->visible) AND
+        !has_capability('moodle/course:viewhiddenactivities', $context)) AND
+        $course->id != SITEID) {
+    notice(get_string("activityiscurrentlyhidden"));
+}
+
+//ishidden check.
+//feedback on mainsite
+if ((empty($cm->visible) AND
+        !has_capability('moodle/course:viewhiddenactivities', $context)) AND
+        $courseid == SITEID) {
+    notice(get_string("activityiscurrentlyhidden"));
+}
+
+//check, if the feedback is open (timeopen, timeclose)
+$checktime = time();
+$feedback_is_closed = ($feedback->timeopen > $checktime) OR
+                      ($feedback->timeclose < $checktime AND
+                            $feedback->timeclose > 0);
+
+if ($feedback_is_closed) {
+    echo $OUTPUT->box_start('generalbox boxaligncenter');
+        echo '<h2><font color="red">';
+        echo get_string('feedback_is_not_open', 'feedback');
+        echo '</font></h2>';
+        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
+    echo $OUTPUT->box_end();
+    echo $OUTPUT->footer();
+    exit;
+}
+
+//additional check for multiple-submit (prevent browsers back-button).
+//the main-check is in view.php
+$feedback_can_submit = true;
+if ($feedback->multiple_submit == 0 ) {
+    if (feedback_is_already_submitted($feedback->id, $courseid)) {
+        $feedback_can_submit = false;
     }
-
-    //additional check for multiple-submit (prevent browsers back-button). the main-check is in view.php
-    $feedback_can_submit = true;
-    if($feedback->multiple_submit == 0 ) {
-        if(feedback_is_already_submitted($feedback->id, $courseid)) {
-            $feedback_can_submit = false;
+}
+if ($feedback_can_submit) {
+    //preserving the items
+    if ($preservevalues == 1) {
+        if (!isset($SESSION->feedback->is_started) OR !$SESSION->feedback->is_started == true) {
+            print_error('error', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
         }
-    }
-    if($feedback_can_submit) {
-        //preserving the items
-        if($preservevalues == 1){
-            if(!$SESSION->feedback->is_started == true)
-                print_error('error', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
-            //checken, ob alle required items einen wert haben
-            if(feedback_check_values($startitempos, $lastitempos)) {
-                    $userid = $USER->id; //arb
-                if($completedid = feedback_save_values($USER->id, true)){
-                    if($userid > 0) {
-                        add_to_log($course->id, 'feedback', 'startcomplete', 'view.php?id='.$cm->id, $feedback->id, $cm->id, $userid);
-                    }
-                    if(!$gonextpage AND !$gopreviouspage) $preservevalues = false;//es kann gespeichert werden
-
-                }else {
-                    $savereturn = 'failed';
-                    if(isset($lastpage)) {
-                        $gopage = $lastpage;
-                    }else {
-                        print_error('missingparameter');
-                    }
+        //checken, ob alle required items einen wert haben
+        if (feedback_check_values($startitempos, $lastitempos)) {
+            $userid = $USER->id; //arb
+            if ($completedid = feedback_save_values($USER->id, true)) {
+                if ($userid > 0) {
+                    add_to_log($course->id,
+                               'feedback',
+                               'startcomplete',
+                               'view.php?id='.$cm->id,
+                               $feedback->id,
+                               $cm->id,
+                               $userid);
                 }
-            }else {
-                $savereturn = 'missing';
-                $highlightrequired = true;
-                if(isset($lastpage)) {
+                if (!$gonextpage AND !$gopreviouspage) {
+                    $preservevalues = false;//es kann gespeichert werden
+                }
+
+            } else {
+                $savereturn = 'failed';
+                if (isset($lastpage)) {
                     $gopage = $lastpage;
-                }else {
+                } else {
                     print_error('missingparameter');
                 }
-
             }
+        } else {
+            $savereturn = 'missing';
+            $highlightrequired = true;
+            if (isset($lastpage)) {
+                $gopage = $lastpage;
+            } else {
+                print_error('missingparameter');
+            }
+
         }
+    }
 
-        //saving the items
-        if($savevalues AND !$preservevalues){
-            //exists there any pagebreak, so there are values in the feedback_valuetmp
-            $userid = $USER->id; //arb
+    //saving the items
+    if ($savevalues AND !$preservevalues) {
+        //exists there any pagebreak, so there are values in the feedback_valuetmp
+        $userid = $USER->id; //arb
 
-            if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
-                $feedbackcompleted = feedback_get_current_completed($feedback->id, false, $courseid);
-            }else{
-                $feedbackcompleted = false;
-            }
-            $feedbackcompletedtmp = $DB->get_record('feedback_completedtmp', array('id'=>$completedid));
-            //fake saving for switchrole
-            $is_switchrole = feedback_check_is_switchrole();
-            if($is_switchrole) {
-                $savereturn = 'saved';
-                feedback_delete_completedtmp($completedid);
-            }else if($new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp, $feedbackcompleted, $userid)) {
+        if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
+            $feedbackcompleted = feedback_get_current_completed($feedback->id, false, $courseid);
+        } else {
+            $feedbackcompleted = false;
+        }
+        $params = array('id' => $completedid);
+        $feedbackcompletedtmp = $DB->get_record('feedback_completedtmp', $params);
+        //fake saving for switchrole
+        $is_switchrole = feedback_check_is_switchrole();
+        if ($is_switchrole) {
+            $savereturn = 'saved';
+            feedback_delete_completedtmp($completedid);
+        } else {
+            $new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp,
+                                                         $feedbackcompleted,
+                                                         $userid);
+            if ($new_completed_id) {
                 $savereturn = 'saved';
-                if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
-                    add_to_log($course->id, 'feedback', 'submit', 'view.php?id='.$cm->id, $feedback->id, $cm->id, $userid);
+                if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
+                    add_to_log($course->id,
+                              'feedback',
+                              'submit',
+                              'view.php?id='.$cm->id,
+                              $feedback->id,
+                              $cm->id,
+                              $userid);
+
                     feedback_send_email($cm, $feedback, $course, $userid);
-                }else {
+                } else {
                     feedback_send_email_anonym($cm, $feedback, $course, $userid);
                 }
                 //tracking the submit
                 $tracking->completed = $new_completed_id;
                 $DB->insert_record('feedback_tracking', $tracking);
                 unset($SESSION->feedback->is_started);
-                
+
                 // Update completion state
                 $completion = new completion_info($course);
                 if ($completion->is_enabled($cm) && $feedback->completionsubmit) {
                     $completion->update_state($cm, COMPLETION_COMPLETE);
                 }
 
-            }else {
+            } else {
                 $savereturn = 'failed';
             }
-
         }
 
+    }
 
-        if($allbreaks = feedback_get_all_break_positions($feedback->id)){
-            if($gopage <= 0) {
-                $startposition = 0;
-            }else {
-                if(!isset($allbreaks[$gopage - 1])) {
-                    $gopage = count($allbreaks);
-                }
-                $startposition = $allbreaks[$gopage - 1];
-            }
-            $ispagebreak = true;
-        }else {
+
+    if ($allbreaks = feedback_get_all_break_positions($feedback->id)) {
+        if ($gopage <= 0) {
             $startposition = 0;
-            $newpage = 0;
-            $ispagebreak = false;
+        } else {
+            if (!isset($allbreaks[$gopage - 1])) {
+                $gopage = count($allbreaks);
+            }
+            $startposition = $allbreaks[$gopage - 1];
         }
+        $ispagebreak = true;
+    } else {
+        $startposition = 0;
+        $newpage = 0;
+        $ispagebreak = false;
+    }
 
-        //get the feedbackitems after the last shown pagebreak
-        $feedbackitems = $DB->get_records_select('feedback_item', 'feedback = ? AND position > ?', array($feedback->id, $startposition), 'position');
+    //get the feedbackitems after the last shown pagebreak
+    $select = 'feedback = ? AND position > ?';
+    $params = array($feedback->id, $startposition);
+    $feedbackitems = $DB->get_records_select('feedback_item', $select, $params, 'position');
 
-        //get the first pagebreak
-        if($pagebreaks = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'typ'=>'pagebreak'), 'position')) {
-            $pagebreaks = array_values($pagebreaks);
-            $firstpagebreak = $pagebreaks[0];
-        }else {
-            $firstpagebreak = false;
-        }
-        $maxitemcount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
-
-        //get the values of completeds before done. Anonymous user can not get these values.
-        if((!isset($SESSION->feedback->is_started)) AND (!isset($savereturn)) AND ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO)) {
-            if(!$feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid)) {
-                if($feedbackcompleted = feedback_get_current_completed($feedback->id, false, $courseid)) {
-                    //copy the values to feedback_valuetmp create a completedtmp
-                    $feedbackcompletedtmp = feedback_set_tmp_values($feedbackcompleted);
-                }
+    //get the first pagebreak
+    $params = array('feedback' => $feedback->id, 'typ' => 'pagebreak');
+    if ($pagebreaks = $DB->get_records('feedback_item', $params, 'position')) {
+        $pagebreaks = array_values($pagebreaks);
+        $firstpagebreak = $pagebreaks[0];
+    } else {
+        $firstpagebreak = false;
+    }
+    $maxitemcount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
+
+    //get the values of completeds before done. Anonymous user can not get these values.
+    if ((!isset($SESSION->feedback->is_started)) AND
+                          (!isset($savereturn)) AND
+                          ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO)) {
+
+        $feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid);
+        if (!$feedbackcompletedtmp) {
+            $feedbackcompleted = feedback_get_current_completed($feedback->id, false, $courseid);
+            if ($feedbackcompleted) {
+                //copy the values to feedback_valuetmp create a completedtmp
+                $feedbackcompletedtmp = feedback_set_tmp_values($feedbackcompleted);
             }
-        }else {
-            $feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid);
         }
+    } else {
+        $feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid);
+    }
 
-        /// Print the main part of the page
-        ///////////////////////////////////////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////
-        $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id));
-        if($courseid > 0) {
-            $analysisurl->param('courseid', $courseid);
+    /// Print the main part of the page
+    ///////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////
+    $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id));
+    if ($courseid > 0) {
+        $analysisurl->param('courseid', $courseid);
+    }
+    echo $OUTPUT->heading(format_text($feedback->name));
+
+    if ( (intval($feedback->publish_stats) == 1) AND
+            ( has_capability('mod/feedback:viewanalysepage', $context)) AND
+            !( has_capability('mod/feedback:viewreports', $context)) ) {
+
+        $params = array('userid' => $USER->id, 'feedback' => $feedback->id);
+        if ($multiple_count = $DB->count_records('feedback_tracking', $params)) {
+            echo $OUTPUT->box_start('mdl-align');
+            echo '<a href="'.$analysisurl->out().'">';
+            echo get_string('completed_feedbacks', 'feedback').'</a>';
+            echo $OUTPUT->box_end();
         }
-        echo $OUTPUT->heading(format_text($feedback->name));
-
-        if( (intval($feedback->publish_stats) == 1) AND
-                ( has_capability('mod/feedback:viewanalysepage', $context)) AND
-                !( has_capability('mod/feedback:viewreports', $context)) ) {
-            if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
-                echo $OUTPUT->box_start('mdl-align');
-                echo '<a href="'.$analysisurl->out().'">';
+    }
+
+    if (isset($savereturn) && $savereturn == 'saved') {
+        if ($feedback->page_after_submit) {
+            echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
+            echo format_text($feedback->page_after_submit,
+                             $feedback->page_after_submitformat,
+                             array('overflowdiv' => true));
+            echo $OUTPUT->box_end();
+        } else {
+            echo '<p align="center">';
+            echo '<b><font color="green">';
+            echo get_string('entries_saved', 'feedback');
+            echo '</font></b>';
+            echo '</p>';
+            if ( intval($feedback->publish_stats) == 1) {
+                echo '<p align="center"><a href="'.$analysisurl->out().'">';
                 echo get_string('completed_feedbacks', 'feedback').'</a>';
-                echo $OUTPUT->box_end();
+                echo '</p>';
             }
         }
 
-        if(isset($savereturn) && $savereturn == 'saved') {
-            if($feedback->page_after_submit) {
-                echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-                echo format_text($feedback->page_after_submit, $feedback->page_after_submitformat, array('overflowdiv'=>true));
-                echo $OUTPUT->box_end();
+        if ($feedback->site_after_submit) {
+            $url = feedback_encode_target_url($feedback->site_after_submit);
+        } else {
+            if ($courseid) {
+                if ($courseid == SITEID) {
+                    $url = $CFG->wwwroot;
+                } else {
+                    $url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
+                }
             } else {
-                echo '<p align="center"><b><font color="green">'.get_string('entries_saved','feedback').'</font></b></p>';
-                if( intval($feedback->publish_stats) == 1) {
-                    echo '<p align="center"><a href="'.$analysisurl->out().'">';
-                    echo get_string('completed_feedbacks', 'feedback').'</a>';
-                    echo '</p>';
+                if ($course->id == SITEID) {
+                    $url = $CFG->wwwroot;
+                } else {
+                    $url = $CFG->wwwroot.'/course/view.php?id='.$course->id;
                 }
             }
+        }
+        echo $OUTPUT->continue_button($url);
+    } else {
+        if (isset($savereturn) && $savereturn == 'failed') {
+            echo $OUTPUT->box_start('mform error');
+            echo get_string('saving_failed', 'feedback');
+            echo $OUTPUT->box_end();
+        }
 
-            if($feedback->site_after_submit) {
-                echo $OUTPUT->continue_button(feedback_encode_target_url($feedback->site_after_submit));
-            }else {
-                if($courseid) {
-                    if($courseid == SITEID) {
-                        echo $OUTPUT->continue_button($CFG->wwwroot);
-                    }else {
-                        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
-                    }
-                }else {
-                    if($course->id == SITEID) {
-                        echo $OUTPUT->continue_button($CFG->wwwroot);
-                    } else {
-                        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
-                    }
-                }
-            }
-        }else {
-            if(isset($savereturn) && $savereturn == 'failed') {
-                echo $OUTPUT->box_start('mform error');
-                echo get_string('saving_failed','feedback');
-                echo $OUTPUT->box_end();
-            }
+        if (isset($savereturn) && $savereturn == 'missing') {
+            echo $OUTPUT->box_start('mform error');
+            echo get_string('saving_failed_because_missing_or_false_values', 'feedback');
+            echo $OUTPUT->box_end();
+        }
 
-            if(isset($savereturn) && $savereturn == 'missing') {
-                echo $OUTPUT->box_start('mform error');
-                echo get_string('saving_failed_because_missing_or_false_values','feedback');
-                echo $OUTPUT->box_end();
+        //print the items
+        if (is_array($feedbackitems)) {
+            echo $OUTPUT->box_start('feedback_form');
+            echo '<form action="complete.php" method="post" onsubmit=" ">';
+            echo '<fieldset>';
+            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+            echo $OUTPUT->box_start('feedback_anonymousinfo');
+            switch ($feedback->anonymous) {
+                case FEEDBACK_ANONYMOUS_YES:
+                    echo '<input type="hidden" name="anonymous" value="1" />';
+                    $inputvalue = 'value="'.FEEDBACK_ANONYMOUS_YES.'"';
+                    echo '<input type="hidden" name="anonymous_response" '.$inputvalue.' />';
+                    echo get_string('mode', 'feedback').': '.get_string('anonymous', 'feedback');
+                    break;
+                case FEEDBACK_ANONYMOUS_NO:
+                    echo '<input type="hidden" name="anonymous" value="0" />';
+                    $inputvalue = 'value="'.FEEDBACK_ANONYMOUS_NO.'"';
+                    echo '<input type="hidden" name="anonymous_response" '.$inputvalue.' />';
+                    echo get_string('mode', 'feedback').': ';
+                    echo get_string('non_anonymous', 'feedback');
+                    break;
             }
+            echo $OUTPUT->box_end();
+            //check, if there exists required-elements
+            $params = array('feedback' => $feedback->id, 'required' => 1);
+            $countreq = $DB->count_records('feedback_item', $params);
+            if ($countreq > 0) {
+                echo '<span class="feedback_required_mark">(*)';
+                echo get_string('items_are_required', 'feedback');
+                echo '</span>';
+            }
+            echo $OUTPUT->box_start('feedback_items');
+
+            unset($startitem);
+            $select = 'feedback = ? AND hasvalue = 1 AND position < ?';
+            $params = array($feedback->id, $startposition);
+            $itemnr = $DB->count_records_select('feedback_item', $select, $params);
+            $lastbreakposition = 0;
+            $align = right_to_left() ? 'right' : 'left';
+
+            foreach ($feedbackitems as $feedbackitem) {
+                if (!isset($startitem)) {
+                    //avoid showing double pagebreaks
+                    if ($feedbackitem->typ == 'pagebreak') {
+                        continue;
+                    }
+                    $startitem = $feedbackitem;
+                }
 
-            //print the items
-            if(is_array($feedbackitems)){
-                // echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-                echo $OUTPUT->box_start('feedback_form');
-                echo '<form action="complete.php" method="post" onsubmit=" ">';
-                echo '<fieldset>';
-                echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-                echo $OUTPUT->box_start('feedback_anonymousinfo');
-                switch ($feedback->anonymous) {
-                    case FEEDBACK_ANONYMOUS_YES:
-                        echo '<input type="hidden" name="anonymous" value="1" />';
-                        echo '<input type="hidden" name="anonymous_response" value="'.FEEDBACK_ANONYMOUS_YES.'" />';
-                        echo get_string('mode', 'feedback').': '.get_string('anonymous', 'feedback');
-                        break;
-                    case FEEDBACK_ANONYMOUS_NO:
-                        echo '<input type="hidden" name="anonymous" value="0" />';
-                        echo '<input type="hidden" name="anonymous_response" value="'.FEEDBACK_ANONYMOUS_NO.'" />';
-                        echo get_string('mode', 'feedback').': '.get_string('non_anonymous', 'feedback');
-                        break;
+                if ($feedbackitem->dependitem > 0) {
+                    //chech if the conditions are ok
+                    $fb_compare_value = feedback_compare_item_value($feedbackcompletedtmp->id,
+                                                                    $feedbackitem->dependitem,
+                                                                    $feedbackitem->dependvalue,
+                                                                    true);
+                    if (!isset($feedbackcompletedtmp->id) OR !$fb_compare_value) {
+                        $lastitem = $feedbackitem;
+                        $lastbreakposition = $feedbackitem->position;
+                        continue;
+                    }
                 }
-                echo $OUTPUT->box_end();
-                //check, if there exists required-elements
-                $countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=>1));
-                if($countreq > 0) {
-                    echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>';
+
+                if ($feedbackitem->dependitem > 0) {
+                    $dependstyle = ' feedback_complete_depend';
+                } else {
+                    $dependstyle = '';
                 }
-                echo $OUTPUT->box_start('feedback_items');
-
-                unset($startitem);
-                $itemnr = $DB->count_records_select('feedback_item', 'feedback = ? AND hasvalue = 1 AND position < ?', array($feedback->id, $startposition));
-                $lastbreakposition = 0;
-                $align = right_to_left() ? 'right' : 'left';
-
-                foreach($feedbackitems as $feedbackitem){
-                    if(!isset($startitem)) {
-                        //avoid showing double pagebreaks
-                        if($feedbackitem->typ == 'pagebreak') {
-                            continue;
-                        }
-                        $startitem = $feedbackitem;
-                    }
 
-                    if($feedbackitem->dependitem > 0) {
-                        //chech if the conditions are ok
-                        if(!isset($feedbackcompletedtmp->id) OR !feedback_compare_item_value($feedbackcompletedtmp->id, $feedbackitem->dependitem, $feedbackitem->dependvalue, true)) {
-                            $lastitem = $feedbackitem;
-                            $lastbreakposition = $feedbackitem->position;
-                            continue;
-                        }
+                echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
+                $value = '';
+                //get the value
+                $frmvaluename = $feedbackitem->typ . '_'. $feedbackitem->id;
+                if (isset($savereturn)) {
+                    if (isset($formdata->{$frmvaluename})) {
+                        $value = $formdata->{$frmvaluename};
+                    } else {
+                        $value = null;
                     }
-
-                    if($feedbackitem->dependitem > 0) {
-                        $dependstyle = ' feedback_complete_depend';
-                    }else {
-                        $dependstyle = '';
+                } else {
+                    if (isset($feedbackcompletedtmp->id)) {
+                        $value = feedback_get_item_value($feedbackcompletedtmp->id,
+                                                         $feedbackitem->id,
+                                                         true);
                     }
-
-                    echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
-                        $value = '';
-                        //get the value
-                        $frmvaluename = $feedbackitem->typ . '_'. $feedbackitem->id;
-                        if(isset($savereturn)) {
-                            $value =  isset($formdata->{$frmvaluename})?$formdata->{$frmvaluename}:NULL;
-                        }else {
-                            if(isset($feedbackcompletedtmp->id)) {
-                                $value = feedback_get_item_value($feedbackcompletedtmp->id, $feedbackitem->id, true);
-                            }
-                        }
-                        if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
-                            $itemnr++;
-                            echo $OUTPUT->box_start('feedback_item_number_'.$align);
-                            echo $itemnr;
-                            echo $OUTPUT->box_end();
-                        }
-                        if($feedbackitem->typ != 'pagebreak') {
-                            echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
-                                feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
-                            echo $OUTPUT->box_end();
-                        }
+                }
+                if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
+                    $itemnr++;
+                    echo $OUTPUT->box_start('feedback_item_number_'.$align);
+                    echo $itemnr;
                     echo $OUTPUT->box_end();
-
-                    $lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
-                    if($feedbackitem->typ == 'pagebreak'){
-                        break;
-                    }else {
-                        $lastitem = $feedbackitem;
-                    }
                 }
-                echo $OUTPUT->box_end();
-                echo '<input type="hidden" name="id" value="'.$id.'" />';
-                echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
-                echo '<input type="hidden" name="lastpage" value="'.$gopage.'" />';
-                echo '<input type="hidden" name="completedid" value="'.(isset($feedbackcompletedtmp->id)?$feedbackcompletedtmp->id:'').'" />';
-                echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
-                echo '<input type="hidden" name="preservevalues" value="1" />';
-                if(isset($startitem)) {
-                    echo '<input type="hidden" name="startitempos" value="'. $startitem->position . '" />';
-                    echo '<input type="hidden" name="lastitempos" value="'. $lastitem->position . '" />';
+                if ($feedbackitem->typ != 'pagebreak') {
+                    echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
+                    feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
+                    echo $OUTPUT->box_end();
                 }
+                echo $OUTPUT->box_end();
 
-                if( $ispagebreak AND $lastbreakposition > $firstpagebreak->position) {
-                    echo '<input name="gopreviouspage" type="submit" value="'.get_string('previous_page','feedback').'" />';
-                }
-                if($lastbreakposition < $maxitemcount){
-                    echo '<input name="gonextpage" type="submit" value="'.get_string('next_page','feedback').'" />';
-                }
-                if($lastbreakposition >= $maxitemcount) { //last page
-                    echo '<input name="savevalues" type="submit" value="'.get_string('save_entries','feedback').'" />';
+                $lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
+                if ($feedbackitem->typ == 'pagebreak') {
+                    break;
+                } else {
+                    $lastitem = $feedbackitem;
                 }
+            }
+            echo $OUTPUT->box_end();
+            echo '<input type="hidden" name="id" value="'.$id.'" />';
+            echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
+            echo '<input type="hidden" name="lastpage" value="'.$gopage.'" />';
+            if (isset($feedbackcompletedtmp->id)) {
+                $inputvalue = 'value="'.$feedbackcompletedtmp->id.'"';
+            } else {
+                $inputvalue = 'value=""';
+            }
+            echo '<input type="hidden" name="completedid" '.$inputvalue.' />';
+            echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
+            echo '<input type="hidden" name="preservevalues" value="1" />';
+            if (isset($startitem)) {
+                echo '<input type="hidden" name="startitempos" value="'.$startitem->position.'" />';
+                echo '<input type="hidden" name="lastitempos" value="'.$lastitem->position.'" />';
+            }
 
-                echo '</fieldset>';
-                echo '</form>';
-                echo $OUTPUT->box_end();
+            if ( $ispagebreak AND $lastbreakposition > $firstpagebreak->position) {
+                $inputvalue = 'value="'.get_string('previous_page', 'feedback').'"';
+                echo '<input name="gopreviouspage" type="submit" '.$inputvalue.' />';
+            }
+            if ($lastbreakposition < $maxitemcount) {
+                $inputvalue = 'value="'.get_string('next_page', 'feedback').'"';
+                echo '<input name="gonextpage" type="submit" '.$inputvalue.' />';
+            }
+            if ($lastbreakposition >= $maxitemcount) { //last page
+                $inputvalue = 'value="'.get_string('save_entries', 'feedback').'"';
+                echo '<input name="savevalues" type="submit" '.$inputvalue.' />';
+            }
 
-                echo $OUTPUT->box_start('feedback_complete_cancel');
-                if($courseid) {
-                    echo '<form action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'" method="post" onsubmit=" ">';
-                }else{
-                    if($course->id == SITEID) {
-                        echo '<form action="'.$CFG->wwwroot.'" method="post" onsubmit=" ">';
-                    } else {
-                        echo '<form action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'" method="post" onsubmit=" ">';
-                    }
+            echo '</fieldset>';
+            echo '</form>';
+            echo $OUTPUT->box_end();
+
+            echo $OUTPUT->box_start('feedback_complete_cancel');
+            if ($courseid) {
+                $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'"';
+            } else {
+                if ($course->id == SITEID) {
+                    $action = 'action="'.$CFG->wwwroot.'"';
+                } else {
+                    $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'"';
                 }
-                echo '<fieldset>';
-                echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-                echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
-                echo '<button type="submit">'.get_string('cancel').'</button>';
-                echo '</fieldset>';
-                echo '</form>';
-                echo $OUTPUT->box_end();
-                $SESSION->feedback->is_started = true;
-                // echo $OUTPUT->box_end();
             }
+            echo '<form '.$action.' method="post" onsubmit=" ">';
+            echo '<fieldset>';
+            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+            echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
+            echo '<button type="submit">'.get_string('cancel').'</button>';
+            echo '</fieldset>';
+            echo '</form>';
+            echo $OUTPUT->box_end();
+            $SESSION->feedback->is_started = true;
         }
-    }else {
-        echo $OUTPUT->box_start('generalbox boxaligncenter');
-            echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
-            echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
-        echo $OUTPUT->box_end();
     }
-    /// Finish the page
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    echo $OUTPUT->footer();
-
+} else {
+    echo $OUTPUT->box_start('generalbox boxaligncenter');
+        echo '<h2>';
+        echo '<font color="red">';
+        echo get_string('this_feedback_is_already_submitted', 'feedback');
+        echo '</font>';
+        echo '</h2>';
+        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
+    echo $OUTPUT->box_end();
+}
+/// Finish the page
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+
+echo $OUTPUT->footer();
index a25946d..a1d8586 100644 (file)
 <?php
-
-    /**
-    * prints the form so an anonymous user can fill out the feedback on the mainsite
-    *
-    * @author Andreas Grabs
-    * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-    * @package feedback
-    */
-
-    require_once("../../config.php");
-    require_once("lib.php");
-
-    feedback_init_feedback_session();
-
-    $id = required_param('id', PARAM_INT);
-    $completedid = optional_param('completedid', false, PARAM_INT);
-    $preservevalues  = optional_param('preservevalues', 0,  PARAM_INT);
-    $courseid = optional_param('courseid', false, PARAM_INT);
-    $gopage = optional_param('gopage', -1, PARAM_INT);
-    $lastpage = optional_param('lastpage', false, PARAM_INT);
-    $startitempos = optional_param('startitempos', 0, PARAM_INT);
-    $lastitempos = optional_param('lastitempos', 0, PARAM_INT);
-
-    $url = new moodle_url('/mod/feedback/complete_guest.php', array('id'=>$id));
-    if ($completedid !== false) {
-        $url->param('completedid', $completedid);
-    }
-    if ($preservevalues !== 0) {
-        $url->param('preservevalues', $preservevalues);
-    }
-    if ($courseid !== false) {
-        $url->param('courseid', $courseid);
-    }
-    if ($gopage !== -1) {
-        $url->param('gopage', $gopage);
-    }
-    if ($lastpage !== false) {
-        $url->param('lastpage', $lastpage);
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * prints the form so an anonymous user can fill out the feedback on the mainsite
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+require_once("../../config.php");
+require_once("lib.php");
+
+feedback_init_feedback_session();
+
+$id = required_param('id', PARAM_INT);
+$completedid = optional_param('completedid', false, PARAM_INT);
+$preservevalues  = optional_param('preservevalues', 0,  PARAM_INT);
+$courseid = optional_param('courseid', false, PARAM_INT);
+$gopage = optional_param('gopage', -1, PARAM_INT);
+$lastpage = optional_param('lastpage', false, PARAM_INT);
+$startitempos = optional_param('startitempos', 0, PARAM_INT);
+$lastitempos = optional_param('lastitempos', 0, PARAM_INT);
+
+$url = new moodle_url('/mod/feedback/complete_guest.php', array('id'=>$id));
+if ($completedid !== false) {
+    $url->param('completedid', $completedid);
+}
+if ($preservevalues !== 0) {
+    $url->param('preservevalues', $preservevalues);
+}
+if ($courseid !== false) {
+    $url->param('courseid', $courseid);
+}
+if ($gopage !== -1) {
+    $url->param('gopage', $gopage);
+}
+if ($lastpage !== false) {
+    $url->param('lastpage', $lastpage);
+}
+if ($startitempos !== 0) {
+    $url->param('startitempos', $startitempos);
+}
+if ($lastitempos !== 0) {
+    $url->param('lastitempos', $lastitempos);
+}
+$PAGE->set_url($url);
+
+$highlightrequired = false;
+
+if (($formdata = data_submitted()) AND !confirm_sesskey()) {
+    print_error('invalidsesskey');
+}
+
+//if the use hit enter into a textfield so the form should not submit
+if (isset($formdata->sesskey) AND
+   !isset($formdata->savevalues) AND
+   !isset($formdata->gonextpage) AND
+   !isset($formdata->gopreviouspage)) {
+
+    $gopage = $formdata->lastpage;
+}
+if (isset($formdata->savevalues)) {
+    $savevalues = true;
+} else {
+    $savevalues = false;
+}
+
+if ($gopage < 0 AND !$savevalues) {
+    if (isset($formdata->gonextpage)) {
+        $gopage = $lastpage + 1;
+        $gonextpage = true;
+        $gopreviouspage = false;
+    } else if (isset($formdata->gopreviouspage)) {
+        $gopage = $lastpage - 1;
+        $gonextpage = false;
+        $gopreviouspage = true;
+    } else {
+        print_error('parameters_missing', 'feedback');
     }
-    if ($startitempos !== 0) {
-        $url->param('startitempos', $startitempos);
-    }
-    if ($lastitempos !== 0) {
-        $url->param('lastitempos', $lastitempos);
-    }
-    $PAGE->set_url($url);
-
-    $highlightrequired = false;
-
-    if(($formdata = data_submitted()) AND !confirm_sesskey()) {
-        print_error('invalidsesskey');
-    }
-
-    //if the use hit enter into a textfield so the form should not submit
-    if(isset($formdata->sesskey) AND !isset($formdata->savevalues) AND !isset($formdata->gonextpage) AND !isset($formdata->gopreviouspage)) {
-        $gopage = $formdata->lastpage;
-    }
-    if(isset($formdata->savevalues)) {
-        $savevalues = true;
-    }else {
-        $savevalues = false;
-    }
-
-    if($gopage < 0 AND !$savevalues) {
-        if(isset($formdata->gonextpage)){
-            $gopage = $lastpage + 1;
-            $gonextpage = true;
-            $gopreviouspage = false;
-        }else if(isset($formdata->gopreviouspage)){
-            $gopage = $lastpage - 1;
-            $gonextpage = false;
-            $gopreviouspage = true;
-        }else {
-            print_error('parameters_missing', 'feedback');
-        }
-    }else {
-        $gonextpage = $gopreviouspage = false;
-    }
-
-    if (! $cm = get_coursemodule_from_id('feedback', $id)) {
-        print_error('invalidcoursemodule');
-    }
-
-    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
-        print_error('invalidcoursemodule');
-    }
-
-    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
-            print_error('badcontext');
-    }
-
-    $feedback_complete_cap = false;
-
-    if(isset($CFG->feedback_allowfullanonymous)
+} else {
+    $gonextpage = $gopreviouspage = false;
+}
+
+if (! $cm = get_coursemodule_from_id('feedback', $id)) {
+    print_error('invalidcoursemodule');
+}
+
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
+    print_error('coursemisconf');
+}
+
+if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+        print_error('badcontext');
+}
+
+$feedback_complete_cap = false;
+
+if (isset($CFG->feedback_allowfullanonymous)
+            AND $CFG->feedback_allowfullanonymous
+            AND $course->id == SITEID
+            AND (!$courseid OR $courseid == SITEID)
+            AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
+    $feedback_complete_cap = true;
+}
+
+//check whether the feedback is anonymous
+if (isset($CFG->feedback_allowfullanonymous)
                 AND $CFG->feedback_allowfullanonymous
-                AND $course->id == SITEID
-                AND (!$courseid OR $courseid == SITEID)
-                AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
-        $feedback_complete_cap = true;
-    }
-
-    //check whether the feedback is anonymous
-    if(isset($CFG->feedback_allowfullanonymous)
-                    AND $CFG->feedback_allowfullanonymous
-                    AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES
-                    AND $course->id == SITEID ) {
-        $feedback_complete_cap = true;
-    }
-    if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
-        print_error('feedback_is_not_for_anonymous', 'feedback');
-    }
-
-    //check whether the user has a session
-    // there used to be a sesskey test - this could not work - sorry
-
-    //check whether the feedback is located and! started from the mainsite
-    if($course->id == SITEID AND !$courseid) {
-        $courseid = SITEID;
-    }
-
-    require_course_login($course);
-
-    if($courseid AND $courseid != SITEID) {
-        $course2 = $DB->get_record('course', array('id'=>$courseid));
-        require_course_login($course2); //this overwrites the object $course :-(
-        $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
-    }
-
-    if(!$feedback_complete_cap) {
-        print_error('error');
-    }
-
-
-    /// Print the page header
-    $strfeedbacks = get_string("modulenameplural", "feedback");
-    $strfeedback  = get_string("modulename", "feedback");
-
-    $PAGE->set_cm($cm, $course); // set's up global $COURSE
-    $PAGE->set_pagelayout('incourse');
-
-    $PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id)));
-    $PAGE->navbar->add(format_string($feedback->name));
-    $PAGE->set_heading(format_string($course->fullname));
-    $PAGE->set_title(format_string($feedback->name));
-    echo $OUTPUT->header();
-
-    //ishidden check. hidden feedbacks except feedbacks on mainsite are only accessible with related capabilities
-    if ((empty($cm->visible) AND
-            !has_capability('moodle/course:viewhiddenactivities', $context)) AND
-            $course->id != SITEID) {
-        notice(get_string("activityiscurrentlyhidden"));
-    }
-
-    feedback_print_errors();
-
-    //check, if the feedback is open (timeopen, timeclose)
-    $checktime = time();
-    if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
-        echo $OUTPUT->box_start('generalbox boxaligncenter');
-            echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
-            echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
-        echo $OUTPUT->box_end();
-        echo $OUTPUT->footer();
-        exit;
+                AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES
+                AND $course->id == SITEID ) {
+    $feedback_complete_cap = true;
+}
+if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
+    print_error('feedback_is_not_for_anonymous', 'feedback');
+}
+
+//check whether the user has a session
+// there used to be a sesskey test - this could not work - sorry
+
+//check whether the feedback is located and! started from the mainsite
+if ($course->id == SITEID AND !$courseid) {
+    $courseid = SITEID;
+}
+
+require_course_login($course);
+
+if ($courseid AND $courseid != SITEID) {
+    $course2 = $DB->get_record('course', array('id'=>$courseid));
+    require_course_login($course2); //this overwrites the object $course :-(
+    $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
+}
+
+if (!$feedback_complete_cap) {
+    print_error('error');
+}
+
+
+/// Print the page header
+$strfeedbacks = get_string("modulenameplural", "feedback");
+$strfeedback  = get_string("modulename", "feedback");
+
+$PAGE->set_cm($cm, $course); // set's up global $COURSE
+$PAGE->set_pagelayout('incourse');
+
+$urlparams = array('id'=>$course->id);
+$PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', $urlparams));
+$PAGE->navbar->add(format_string($feedback->name));
+$PAGE->set_heading(format_string($course->fullname));
+$PAGE->set_title(format_string($feedback->name));
+echo $OUTPUT->header();
+
+//ishidden check.
+//hidden feedbacks except feedbacks on mainsite are only accessible with related capabilities
+if ((empty($cm->visible) AND
+        !has_capability('moodle/course:viewhiddenactivities', $context)) AND
+        $course->id != SITEID) {
+    notice(get_string("activityiscurrentlyhidden"));
+}
+
+//check, if the feedback is open (timeopen, timeclose)
+$checktime = time();
+
+$feedback_is_closed = ($feedback->timeopen > $checktime) OR
+                      ($feedback->timeclose < $checktime AND
+                            $feedback->timeclose > 0);
+
+if ($feedback_is_closed) {
+    echo $OUTPUT->box_start('generalbox boxaligncenter');
+        echo '<h2><font color="red">';
+        echo get_string('feedback_is_not_open', 'feedback');
+        echo '</font></h2>';
+        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
+    echo $OUTPUT->box_end();
+    echo $OUTPUT->footer();
+    exit;
+}
+
+//additional check for multiple-submit (prevent browsers back-button).
+//the main-check is in view.php
+$feedback_can_submit = true;
+if ($feedback->multiple_submit == 0 ) {
+    if (feedback_is_already_submitted($feedback->id, $courseid)) {
+        $feedback_can_submit = false;
     }
-
-    //additional check for multiple-submit (prevent browsers back-button). the main-check is in view.php
-    $feedback_can_submit = true;
-    if($feedback->multiple_submit == 0 ) {
-        // if($multiple_count = $DB->get_record('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
-        if(feedback_is_already_submitted($feedback->id, $courseid)) {
-            $feedback_can_submit = false;
+}
+if ($feedback_can_submit) {
+    //preserving the items
+    if ($preservevalues == 1) {
+        if (!$SESSION->feedback->is_started == true) {
+            print_error('error', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
         }
-    }
-    if($feedback_can_submit) {
-        //preserving the items
-        if($preservevalues == 1){
-            if (!$SESSION->feedback->is_started == true) {
-                print_error('error', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
-            }
-            //check, if all required items have a value
-            if(feedback_check_values($startitempos, $lastitempos)) {
-                $userid = $USER->id; //arb
-                if($completedid = feedback_save_guest_values(sesskey())){
-                    add_to_log($course->id, 'feedback', 'startcomplete', 'view.php?id='.$cm->id, $feedback->id); //arb: log even guest submissions or at least the startcomplete since the other add log event is elsewhere
-
-                    if(!$gonextpage AND !$gopreviouspage) $preservevalues = false;//es kann gespeichert werden
-
-                }else {
-                    $savereturn = 'failed';
-                    if(isset($lastpage)) {
-                        $gopage = $lastpage;
-                    }else {
-                        print_error('parameters_missing', 'feedback');
-                    }
+        //check, if all required items have a value
+        if (feedback_check_values($startitempos, $lastitempos)) {
+            $userid = $USER->id; //arb
+            if ($completedid = feedback_save_guest_values(sesskey())) {
+                add_to_log($course->id,
+                           'feedback',
+                           'startcomplete',
+                           'view.php?id='.$cm->id,
+                           $feedback->id);
+
+                //now it can be saved
+                if (!$gonextpage AND !$gopreviouspage) {
+                    $preservevalues = false;
                 }
-            }else {
-                $savereturn = 'missing';
-                $highlightrequired = true;
-                if(isset($lastpage)) {
+
+            } else {
+                $savereturn = 'failed';
+                if (isset($lastpage)) {
                     $gopage = $lastpage;
-                }else {
+                } else {
                     print_error('parameters_missing', 'feedback');
                 }
             }
+        } else {
+            $savereturn = 'missing';
+            $highlightrequired = true;
+            if (isset($lastpage)) {
+                $gopage = $lastpage;
+            } else {
+                print_error('parameters_missing', 'feedback');
+            }
         }
+    }
 
-        //saving the items
-        if($savevalues AND !$preservevalues){
-            //exists there any pagebreak, so there are values in the feedback_valuetmp
-            $userid = $USER->id; //arb changed from 0 to $USER->id - no strict anonymous feedbacks - if it is a guest taking it then I want to know that it was a guest (at least in the data saved in the feedback tables)
-
-            $feedbackcompletedtmp = $DB->get_record('feedback_completedtmp', array('id'=>$completedid));
-
-            //fake saving for switchrole
-            $is_switchrole = feedback_check_is_switchrole();
-            if($is_switchrole) {
-                $savereturn = 'saved';
-                feedback_delete_completedtmp($completedid);
-            }else if($new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp, false, $userid)) {
+    //saving the items
+    if ($savevalues AND !$preservevalues) {
+        //exists there any pagebreak, so there are values in the feedback_valuetmp
+        //arb changed from 0 to $USER->id
+        //no strict anonymous feedbacks
+        //if it is a guest taking it then I want to know that it was
+        //a guest (at least in the data saved in the feedback tables)
+        $userid = $USER->id;
+
+        $params = array('id'=>$completedid);
+        $feedbackcompletedtmp = $DB->get_record('feedback_completedtmp', $params);
+
+        //fake saving for switchrole
+        $is_switchrole = feedback_check_is_switchrole();
+        if ($is_switchrole) {
+            $savereturn = 'saved';
+            feedback_delete_completedtmp($completedid);
+        } else {
+            $new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp, false, $userid);
+            if ($new_completed_id) {
                 $savereturn = 'saved';
                 feedback_send_email_anonym($cm, $feedback, $course, $userid);
                 unset($SESSION->feedback->is_started);
 
-            }else {
+            } else {
                 $savereturn = 'failed';
             }
         }
+    }
 
-        if($allbreaks = feedback_get_all_break_positions($feedback->id)){
-            if($gopage <= 0) {
-                $startposition = 0;
-            }else {
-                if(!isset($allbreaks[$gopage - 1])) {
-                    $gopage = count($allbreaks);
-                }
-                $startposition = $allbreaks[$gopage - 1];
-            }
-            $ispagebreak = true;
-        }else {
+    if ($allbreaks = feedback_get_all_break_positions($feedback->id)) {
+        if ($gopage <= 0) {
             $startposition = 0;
-            $newpage = 0;
-            $ispagebreak = false;
+        } else {
+            if (!isset($allbreaks[$gopage - 1])) {
+                $gopage = count($allbreaks);
+            }
+            $startposition = $allbreaks[$gopage - 1];
         }
+        $ispagebreak = true;
+    } else {
+        $startposition = 0;
+        $newpage = 0;
+        $ispagebreak = false;
+    }
+
+    //get the feedbackitems after the last shown pagebreak
+    $select = 'feedback = ? AND position > ?';
+    $params = array($feedback->id, $startposition);
+    $feedbackitems = $DB->get_records_select('feedback_item', $select, $params, 'position');
+
+    //get the first pagebreak
+    $params = array('feedback'=>$feedback->id, 'typ'=>'pagebreak');
+    if ($pagebreaks = $DB->get_records('feedback_item', $params, 'position')) {
+        $pagebreaks = array_values($pagebreaks);
+        $firstpagebreak = $pagebreaks[0];
+    } else {
+        $firstpagebreak = false;
+    }
+    $maxitemcount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
+    $feedbackcompletedtmp = feedback_get_current_completed($feedback->id,
+                                                           true,
+                                                           $courseid,
+                                                           sesskey());
 
-        //get the feedbackitems after the last shown pagebreak
-        $feedbackitems = $DB->get_records_select('feedback_item', 'feedback = ? AND position > ?', array($feedback->id, $startposition), 'position');
+    /// Print the main part of the page
+    ///////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////
+    $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id));
+    if ($courseid > 0) {
+        $analysisurl->param('courseid', $courseid);
+    }
+    echo $OUTPUT->heading(format_text($feedback->name));
+
+    if ( (intval($feedback->publish_stats) == 1) AND
+            ( has_capability('mod/feedback:viewanalysepage', $context)) AND
+            !( has_capability('mod/feedback:viewreports', $context)) ) {
+        echo $OUTPUT->box_start('mdl-align');
+        echo '<a href="'.$analysisurl->out().'">';
+        echo get_string('completed_feedbacks', 'feedback');
+        echo '</a>';
+        echo $OUTPUT->box_end();
+    }
 
-        //get the first pagebreak
-        if($pagebreaks = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'typ'=>'pagebreak'), 'position')) {
-            $pagebreaks = array_values($pagebreaks);
-            $firstpagebreak = $pagebreaks[0];
-        }else {
-            $firstpagebreak = false;
+    if (isset($savereturn) && $savereturn == 'saved') {
+        if ($feedback->page_after_submit) {
+            echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
+            echo format_text($feedback->page_after_submit,
+                             $feedback->page_after_submitformat,
+                             array('overflowdiv' => true));
+            echo $OUTPUT->box_end();
+        } else {
+            echo '<p align="center"><b><font color="green">';
+            echo get_string('entries_saved', 'feedback');
+            echo '</font></b></p>';
+            if ( intval($feedback->publish_stats) == 1) {
+                echo '<p align="center"><a href="'.$analysisurl->out().'">';
+                echo get_string('completed_feedbacks', 'feedback').'</a>';
+                echo '</p>';
+            }
+        }
+        if ($feedback->site_after_submit) {
+            $url = feedback_encode_target_url($feedback->site_after_submit);
+        } else {
+            if ($courseid) {
+                if ($courseid == SITEID) {
+                    $url = $CFG->wwwroot;
+                } else {
+                    $url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
+                }
+            } else {
+                if ($course->id == SITEID) {
+                    $url = $CFG->wwwroot;
+                } else {
+                    $url = $CFG->wwwroot.'/course/view.php?id='.$course->id;
+                }
+            }
         }
-        $maxitemcount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
-        $feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, sesskey());
-
-        /// Print the main part of the page
-        ///////////////////////////////////////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////
-        $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id));
-        if($courseid > 0) {
-            $analysisurl->param('courseid', $courseid);
+        echo $OUTPUT->continue_button($url);
+    } else {
+        if (isset($savereturn) && $savereturn == 'failed') {
+            echo $OUTPUT->box_start('mform error');
+            echo get_string('saving_failed', 'feedback');
+            echo $OUTPUT->box_end();
         }
-        echo $OUTPUT->heading(format_text($feedback->name));
 
-        if( (intval($feedback->publish_stats) == 1) AND
-                ( has_capability('mod/feedback:viewanalysepage', $context)) AND
-                !( has_capability('mod/feedback:viewreports', $context)) ) {
-            echo $OUTPUT->box_start('mdl-align');
-            echo '<a href="'.$analysisurl->out().'">'.get_string('completed_feedbacks', 'feedback').'</a>';
+        if (isset($savereturn) && $savereturn == 'missing') {
+            echo $OUTPUT->box_start('mform error');
+            echo get_string('saving_failed_because_missing_or_false_values', 'feedback');
             echo $OUTPUT->box_end();
         }
 
-        if(isset($savereturn) && $savereturn == 'saved') {
-            if($feedback->page_after_submit) {
-                echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-                echo format_text($feedback->page_after_submit, $feedback->page_after_submitformat, array('overflowdiv'=>true));
-                echo $OUTPUT->box_end();
-            } else {
-                echo '<p align="center"><b><font color="green">'.get_string('entries_saved','feedback').'</font></b></p>';
-                if( intval($feedback->publish_stats) == 1) {
-                    echo '<p align="center"><a href="'.$analysisurl->out().'">';
-                    echo get_string('completed_feedbacks', 'feedback').'</a>';
-                    echo '</p>';
-                }
+        //print the items
+        if (is_array($feedbackitems)) {
+            echo $OUTPUT->box_start('feedback_form');
+            echo '<form action="complete_guest.php" method="post" onsubmit=" ">';
+            echo '<fieldset>';
+            echo '<input type="hidden" name="anonymous" value="0" />';
+            $inputvalue = 'value="'.FEEDBACK_ANONYMOUS_YES.'"';
+            echo '<input type="hidden" name="anonymous_response" '.$inputvalue.' />';
+            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+            //check, if there exists required-elements
+            $params = array('feedback'=>$feedback->id, 'required'=>1);
+            $countreq = $DB->count_records('feedback_item', $params);
+            if ($countreq > 0) {
+                echo '<span class="feedback_required_mark">(*)';
+                echo get_string('items_are_required', 'feedback');
+                echo '</span>';
             }
-            if($feedback->site_after_submit) {
-                echo $OUTPUT->continue_button(feedback_encode_target_url($feedback->site_after_submit));
-            }else {
-                if($courseid) {
-                    if($courseid == SITEID) {
-                        echo $OUTPUT->continue_button($CFG->wwwroot);
-                    }else {
-                        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
-                    }
-                }else {
-                    if($course->id == SITEID) {
-                        echo $OUTPUT->continue_button($CFG->wwwroot);
-                    } else {
-                        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
+            echo $OUTPUT->box_start('feedback_items');
+
+            $startitem = null;
+            $select = 'feedback = ? AND hasvalue = 1 AND position < ?';
+            $params = array($feedback->id, $startposition);
+            $itemnr = $DB->count_records_select('feedback_item', $select, $params);
+            $lastbreakposition = 0;
+            $align = right_to_left() ? 'right' : 'left';
+
+            foreach ($feedbackitems as $feedbackitem) {
+                if (!isset($startitem)) {
+                    //avoid showing double pagebreaks
+                    if ($feedbackitem->typ == 'pagebreak') {
+                        continue;
                     }
+                    $startitem = $feedbackitem;
                 }
-            }
-        }else {
-            if(isset($savereturn) && $savereturn == 'failed') {
-                echo $OUTPUT->box_start('mform error');
-                echo get_string('saving_failed','feedback');
-                echo $OUTPUT->box_end();
-            }
 
-            if(isset($savereturn) && $savereturn == 'missing') {
-                echo $OUTPUT->box_start('mform error');
-                echo get_string('saving_failed_because_missing_or_false_values','feedback');
-                echo $OUTPUT->box_end();
-            }
+                if ($feedbackitem->dependitem > 0) {
+                    //chech if the conditions are ok
+                    $fb_compare_value = feedback_compare_item_value($feedbackcompletedtmp->id,
+                                                                    $feedbackitem->dependitem,
+                                                                    $feedbackitem->dependvalue,
+                                                                    true);
+                    if (!isset($feedbackcompletedtmp->id) OR !$fb_compare_value) {
+                        $lastitem = $feedbackitem;
+                        $lastbreakposition = $feedbackitem->position;
+                        continue;
+                    }
+                }
 
-            //print the items
-            if(is_array($feedbackitems)){
-                // echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-                echo $OUTPUT->box_start('feedback_form');
-                echo '<form action="complete_guest.php" method="post" onsubmit=" ">';
-                echo '<fieldset>';
-                echo '<input type="hidden" name="anonymous" value="0" />';
-                echo '<input type="hidden" name="anonymous_response" value="'.FEEDBACK_ANONYMOUS_YES.'" />';
-                echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-                //check, if there exists required-elements
-                $countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=>1));
-                if($countreq > 0) {
-                    echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>';
+                if ($feedbackitem->dependitem > 0) {
+                    $dependstyle = ' feedback_complete_depend';
+                } else {
+                    $dependstyle = '';
                 }
-                echo $OUTPUT->box_start('feedback_items');
-
-                $startitem = null;
-                $itemnr = $DB->count_records_select('feedback_item', 'feedback = ? AND hasvalue = 1 AND position < ?', array($feedback->id, $startposition));
-                $lastbreakposition = 0;
-                $align = right_to_left() ? 'right' : 'left';
-
-                foreach($feedbackitems as $feedbackitem){
-                    if(!isset($startitem)) {
-                        //avoid showing double pagebreaks
-                        if($feedbackitem->typ == 'pagebreak') {
-                            continue;
-                        }
-                        $startitem = $feedbackitem;
-                    }
 
-                    if($feedbackitem->dependitem > 0) {
-                        //chech if the conditions are ok
-                        if(!isset($feedbackcompletedtmp->id) OR !feedback_compare_item_value($feedbackcompletedtmp->id, $feedbackitem->dependitem, $feedbackitem->dependvalue, true)) {
-                            $lastitem = $feedbackitem;
-                            $lastbreakposition = $feedbackitem->position;
-                            continue;
-                        }
+                echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
+                $value = '';
+                //get the value
+                $frmvaluename = $feedbackitem->typ.'_'.$feedbackitem->id;
+                if (isset($savereturn)) {
+                    if (isset($formdata->{$frmvaluename})) {
+                        $value = $formdata->{$frmvaluename};
+                    } else {
+                        $value = null;
                     }
-
-                    if($feedbackitem->dependitem > 0) {
-                        $dependstyle = ' feedback_complete_depend';
-                    }else {
-                        $dependstyle = '';
+                } else {
+                    if (isset($feedbackcompletedtmp->id)) {
+                        $value = feedback_get_item_value($feedbackcompletedtmp->id,
+                                                         $feedbackitem->id,
+                                                         sesskey());
                     }
-
-                    echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
-                        $value = '';
-                        //get the value
-                        $frmvaluename = $feedbackitem->typ . '_'. $feedbackitem->id;
-                        if(isset($savereturn)) {
-                            $value =  isset($formdata->{$frmvaluename})?$formdata->{$frmvaluename}:NULL;
-                        }else {
-                            if(isset($feedbackcompletedtmp->id)) {
-                                $value = feedback_get_item_value($feedbackcompletedtmp->id, $feedbackitem->id, sesskey());
-                            }
-                        }
-                        if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
-                            $itemnr++;
-                            echo $OUTPUT->box_start('feedback_item_number_'.$align);
-                            echo $itemnr;
-                            echo $OUTPUT->box_end();
-                        }
-                        if($feedbackitem->typ != 'pagebreak') {
-                            echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
-                                feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
-                            echo $OUTPUT->box_end();
-                        }
+                }
+                if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
+                    $itemnr++;
+                    echo $OUTPUT->box_start('feedback_item_number_'.$align);
+                    echo $itemnr;
                     echo $OUTPUT->box_end();
-
-                    $lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
-                    if($feedbackitem->typ == 'pagebreak'){
-                        break;
-                    }else {
-                        $lastitem = $feedbackitem;
-                    }
                 }
-                echo $OUTPUT->box_end();
-                echo '<input type="hidden" name="id" value="'.$id.'" />';
-                echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
-                echo '<input type="hidden" name="lastpage" value="'.$gopage.'" />';
-                echo '<input type="hidden" name="completedid" value="'.(isset($feedbackcompletedtmp->id)?$feedbackcompletedtmp->id:'').'" />';
-                echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
-                echo '<input type="hidden" name="preservevalues" value="1" />';
-                if(isset($startitem)) {
-                    echo '<input type="hidden" name="startitempos" value="'. $startitem->position . '" />';
-                    echo '<input type="hidden" name="lastitempos" value="'. $lastitem->position . '" />';
+                if ($feedbackitem->typ != 'pagebreak') {
+                    echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
+                    feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
+                    echo $OUTPUT->box_end();
                 }
+                echo $OUTPUT->box_end();
 
-                if($ispagebreak AND $lastbreakposition > $firstpagebreak->position) {
-                    echo '<input name="gopreviouspage" type="submit" value="'.get_string('previous_page','feedback').'" />';
-                }
-                if($lastbreakposition < $maxitemcount){
-                    echo '<input name="gonextpage" type="submit" value="'.get_string('next_page','feedback').'" />';
-                }
-                if($lastbreakposition >= $maxitemcount) { //last page
-                    echo '<input name="savevalues" type="submit" value="'.get_string('save_entries','feedback').'" />';
+                $lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
+                if ($feedbackitem->typ == 'pagebreak') {
+                    break;
+                } else {
+                    $lastitem = $feedbackitem;
                 }
+            }
+            echo $OUTPUT->box_end();
+            echo '<input type="hidden" name="id" value="'.$id.'" />';
+            echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
+            echo '<input type="hidden" name="lastpage" value="'.$gopage.'" />';
+            if (isset($feedbackcompletedtmp->id)) {
+                $inputvalue = 'value="'.$feedbackcompletedtmp->id;
+            } else {
+                $inputvalue = 'value=""';
+            }
+            echo '<input type="hidden" name="completedid" '.$inputvalue.' />';
+            echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
+            echo '<input type="hidden" name="preservevalues" value="1" />';
+            if (isset($startitem)) {
+                echo '<input type="hidden" name="startitempos" value="'.$startitem->position.'" />';
+                echo '<input type="hidden" name="lastitempos" value="'.$lastitem->position.'" />';
+            }
 
-                echo '</fieldset>';
-                echo '</form>';
-                echo $OUTPUT->box_end();
+            if ($ispagebreak AND $lastbreakposition > $firstpagebreak->position) {
+                $inputvalue = 'value="'.get_string('previous_page', 'feedback').'"';
+                echo '<input name="gopreviouspage" type="submit" '.$inputvalue.' />';
+            }
+            if ($lastbreakposition < $maxitemcount) {
+                $inputvalue = 'value="'.get_string('next_page', 'feedback').'"';
+                echo '<input name="gonextpage" type="submit" '.$inputvalue.' />';
+            }
+            if ($lastbreakposition >= $maxitemcount) { //last page
+                $inputvalue = 'value="'.get_string('save_entries', 'feedback').'"';
+                echo '<input name="savevalues" type="submit" '.$inputvalue.' />';
+            }
 
-                echo $OUTPUT->box_start('feedback_complete_cancel');
-                if($courseid) {
-                    echo '<form action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'" method="post" onsubmit=" ">';
-                }else{
-                    if($course->id == SITEID) {
-                        echo '<form action="'.$CFG->wwwroot.'" method="post" onsubmit=" ">';
-                    } else {
-                        echo '<form action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'" method="post" onsubmit=" ">';
-                    }
+            echo '</fieldset>';
+            echo '</form>';
+            echo $OUTPUT->box_end();
+
+            echo $OUTPUT->box_start('feedback_complete_cancel');
+            if ($courseid) {
+                $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'"';
+            } else {
+                if ($course->id == SITEID) {
+                    $action = 'action="'.$CFG->wwwroot.'"';
+                } else {
+                    $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'"';
                 }
-                echo '<fieldset>';
-                echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-                echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
-                echo '<button type="submit">'.get_string('cancel').'</button>';
-                echo '</fieldset>';
-                echo '</form>';
-                echo $OUTPUT->box_end();
-                $SESSION->feedback->is_started = true;
             }
+            echo '<form '.$action.' method="post" onsubmit=" ">';
+            echo '<fieldset>';
+            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+            echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
+            echo '<button type="submit">'.get_string('cancel').'</button>';
+            echo '</fieldset>';
+            echo '</form>';
+            echo $OUTPUT->box_end();
+            $SESSION->feedback->is_started = true;
         }
-    }else {
-        echo $OUTPUT->box_start('generalbox boxaligncenter');
-            echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
-            echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
-        echo $OUTPUT->box_end();
     }
-    /// Finish the page
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    echo $OUTPUT->footer();
+} else {
+    echo $OUTPUT->box_start('generalbox boxaligncenter');
+        echo '<h2><font color="red">';
+        echo get_string('this_feedback_is_already_submitted', 'feedback');
+        echo '</font></h2>';
+        echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
+    echo $OUTPUT->box_end();
+}
+/// Finish the page
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+
+echo $OUTPUT->footer();
 
index 16986b5..9921b2a 100644 (file)
@@ -1,4 +1,19 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
 //
 // Capability definitions for the feedback module.
 //
index 696d3f3..05f6665 100644 (file)
@@ -1,9 +1,23 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 function xmldb_feedback_install() {
     global $DB;
 
-/// Disable this module by default (because it's not technically part of Moodle 2.0)
+    /// Disable this module by default (because it's not technically part of Moodle 2.0)
     $DB->set_field('modules', 'visible', 0, array('name'=>'feedback'));
 
 }
index 97d31b3..9aaba27 100644 (file)
       </INDEXES>
     </TABLE>
   </TABLES>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index 79f1891..a27ce3e 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
index e99c919..a325eac 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
index b0a6fcf..e81cfa0 100644 (file)
@@ -1,4 +1,18 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 // This file keeps track of upgrades to
 // the feedback module
@@ -31,15 +45,18 @@ function xmldb_feedback_upgrade($oldversion) {
         $table = new xmldb_table('feedback_completedtmp');
 
         $field = new xmldb_field('id');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, true, null, null);
         $table->addField($field);
 
         $field = new xmldb_field('feedback');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $field = new xmldb_field('userid');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $field = new xmldb_field('guestid');
@@ -47,7 +64,8 @@ function xmldb_feedback_upgrade($oldversion) {
         $table->addField($field);
 
         $field = new xmldb_field('timemodified');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $key = new xmldb_key('PRIMARY');
@@ -65,23 +83,28 @@ function xmldb_feedback_upgrade($oldversion) {
         $table = new xmldb_table('feedback_valuetmp');
 
         $field = new xmldb_field('id');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, true, null, null);
         $table->addField($field);
 
         $field = new xmldb_field('course_id');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $field = new xmldb_field('item');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $field = new xmldb_field('completed');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $field = new xmldb_field('tmp_completed');
-        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
+                                XMLDB_NOTNULL, false, '0', null);
         $table->addField($field);
 
         $field = new xmldb_field('value');
@@ -105,25 +128,29 @@ function xmldb_feedback_upgrade($oldversion) {
 
         /// Define field random_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completed');
-        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
         /// Launch add field1
         $dbman->add_field($table, $field);
 
         /// Define field anonymous_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completed');
-        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
+        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
         /// Launch add field2
         $dbman->add_field($table, $field);
 
         /// Define field random_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completedtmp');
-        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
+        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
         /// Launch add field1
         $dbman->add_field($table, $field);
 
         /// Define field anonymous_response to be added to feedback_completed
         $table = new xmldb_table('feedback_completedtmp');
-        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
+        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
         /// Launch add field2
         $dbman->add_field($table, $field);
 
@@ -135,7 +162,8 @@ function xmldb_feedback_upgrade($oldversion) {
         // public is a reserved word on Oracle
 
         $table = new xmldb_table('feedback_template');
-        $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
+        $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
+                                    XMLDB_NOTNULL, false, '1', null);
         if (!$dbman->field_exists($table, $field)) {
             $dbman->add_field($table, $field);
         }
@@ -144,7 +172,9 @@ function xmldb_feedback_upgrade($oldversion) {
 
     if ($oldversion < 2008042400) { //New version in version.php
         if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous'=>2))) {
-            $update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = ';
+            $update_sql = 'UPDATE {feedback_completed}
+                            SET anonymous_response = 2
+                            WHERE feedback = ';
             foreach ($all_nonanonymous_feedbacks as $fb) {
                 $DB->execute($update_sql.$fb->id);
             }
@@ -153,20 +183,34 @@ function xmldb_feedback_upgrade($oldversion) {
     }
 
     if ($oldversion < 2008042401) { //New version in version.php
-        $concat_radio    = $DB->sql_concat("'r>>>>>'",'presentation');
-        $concat_check    = $DB->sql_concat("'c>>>>>'",'presentation');
-        $concat_dropdown = $DB->sql_concat("'d>>>>>'",'presentation');
+        $concat_radio    = $DB->sql_concat("'r>>>>>'", 'presentation');
+        $concat_check    = $DB->sql_concat("'c>>>>>'", 'presentation');
+        $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation');
+
+        $update_sql1 = "UPDATE {feedback_item}
+                        SET presentation = ".$concat_radio."
+                        WHERE typ IN('radio','radiorated')";
 
-        $update_sql1 = "UPDATE {feedback_item} SET presentation = ".$concat_radio." WHERE typ IN('radio','radiorated')";
-        $update_sql2 = "UPDATE {feedback_item} SET presentation = ".$concat_dropdown." WHERE typ IN('dropdown','dropdownrated')";
-        $update_sql3 = "UPDATE {feedback_item} SET presentation = ".$concat_check." WHERE typ = 'check'";
+        $update_sql2 = "UPDATE {feedback_item}
+                        SET presentation = ".$concat_dropdown."
+                        WHERE typ IN('dropdown','dropdownrated')";
+
+        $update_sql3 = "UPDATE {feedback_item}
+                        SET presentation = ".$concat_check."
+                        WHERE typ = 'check'";
 
         $DB->execute($update_sql1);
         $DB->execute($update_sql2);
         $DB->execute($update_sql3);
 
-        $update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
-        $update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
+        $update_sql1 = "UPDATE {feedback_item}
+                        SET typ = 'multichoice'
+                        WHERE typ IN('radio','check','dropdown')";
+
+        $update_sql2 = "UPDATE {feedback_item}
+                        SET typ = 'multichoicerated'
+                        WHERE typ IN('radiorated','dropdownrated')";
+
         $DB->execute($update_sql1);
         $DB->execute($update_sql2);
 
@@ -176,7 +220,8 @@ function xmldb_feedback_upgrade($oldversion) {
     if ($oldversion < 2008042900) {
         /// Define field autonumbering to be added to feedback
         $table = new xmldb_table('feedback');
-        $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
+        $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
         /// Launch add field2
         $dbman->add_field($table, $field);
 
@@ -186,7 +231,8 @@ function xmldb_feedback_upgrade($oldversion) {
     if ($oldversion < 2008050104) {
         /// Define field site_after_submit to be added to feedback
         $table = new xmldb_table('feedback');
-        $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering');
+        $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255',
+                                    null, null, false, '', 'autonumbering');
         /// Launch add field2
         $dbman->add_field($table, $field);
 
@@ -203,7 +249,11 @@ function xmldb_feedback_upgrade($oldversion) {
     }
 
     if ($oldversion < 2008073002) {
-        $update_sql = "UPDATE {feedback_item} SET presentation = '-|-' WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND typ = 'numeric'";
+        $update_sql = "UPDATE {feedback_item}
+                        SET presentation = '-|-'
+                        WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND
+                            typ = 'numeric'";
+
         $DB->execute($update_sql);
 
         upgrade_mod_savepoint(true, 2008073002, 'feedback');
@@ -221,34 +271,37 @@ function xmldb_feedback_upgrade($oldversion) {
 
     if ($oldversion < 2009042000) {
 
-    /// Rename field summary on table feedback to intro
+        /// Rename field summary on table feedback to intro
         $table = new xmldb_table('feedback');
-        $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
+        $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null,
+                                    XMLDB_NOTNULL, null, null, 'name');
 
-    /// Launch rename field summary
+        /// Launch rename field summary
         $dbman->rename_field($table, $field, 'intro');
 
-    /// feedback savepoint reached
+        /// feedback savepoint reached
         upgrade_mod_savepoint(true, 2009042000, 'feedback');
     }
 
     if ($oldversion < 2009042001) {
 
-    /// Define field introformat to be added to feedback
+        /// Define field introformat to be added to feedback
         $table = new xmldb_table('feedback');
-        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
+        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
 
-    /// Launch add field introformat
+        /// Launch add field introformat
         $dbman->add_field($table, $field);
 
-    /// feedback savepoint reached
+        /// feedback savepoint reached
         upgrade_mod_savepoint(true, 2009042001, 'feedback');
     }
 
     if ($oldversion < 2009112000) {
         /// Define field page_after_submitformat to be added to feedback
         $table = new xmldb_table('feedback');
-        $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
+        $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
 
         if (!$dbman->field_exists($table, $field)) {
             // Launch add field page_after_submitformat
@@ -262,7 +315,8 @@ function xmldb_feedback_upgrade($oldversion) {
     if ($oldversion < 2010051101) {
         /// Define field options to be added to feedback_item
         $table = new xmldb_table('feedback_item');
-        $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'required');
+        $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255',
+                                    null, null, false, '', 'required');
         /// Launch add field
         $dbman->add_field($table, $field);
 
@@ -272,7 +326,8 @@ function xmldb_feedback_upgrade($oldversion) {
     if ($oldversion < 2010051600) {
         /// Define field options to be added to feedback_item
         $table = new xmldb_table('feedback_item');
-        $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
+        $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10',
+                                    XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
         /// Launch add field
         $dbman->add_field($table, $field);
 
@@ -282,7 +337,8 @@ function xmldb_feedback_upgrade($oldversion) {
     if ($oldversion < 2010051601) {
         /// Define field options to be added to feedback_item
         $table = new xmldb_table('feedback_item');
-        $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'dependitem');
+        $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255',
+                                    null, null, false, '', 'dependitem');
         /// Launch add field
         $dbman->add_field($table, $field);
 
@@ -293,7 +349,8 @@ function xmldb_feedback_upgrade($oldversion) {
 
         // Define field completionsubmit to be added to feedback
         $table = new xmldb_table('feedback');
-        $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timemodified');
+        $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1',
+                                    null, XMLDB_NOTNULL, null, '0', 'timemodified');
 
         // Conditionally launch add field completionsubmit
         if (!$dbman->field_exists($table, $field)) {
@@ -303,7 +360,6 @@ function xmldb_feedback_upgrade($oldversion) {
         // feedback savepoint reached
         upgrade_mod_savepoint(true, 2010102300, 'feedback');
     }
-    
 
     // Moodle v2.1.0 release upgrade line
     // Put any upgrade step following this
index cbc3a02..a571b2a 100644 (file)
 <?php
-
-    /**
-    * prints the form to confirm the deleting of a completed
-    *
-    * @author Andreas Grabs
-    * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-    * @package feedback
-    */
-
-    require_once("../../config.php");
-    require_once("lib.php");
-    require_once('delete_completed_form.php');
-
-    $id = required_param('id', PARAM_INT);
-    $completedid = optional_param('completedid', 0, PARAM_INT);
-    $return = optional_param('return', 'entries', PARAM_ALPHA);
-
-    if($completedid == 0){
-        print_error('no_complete_to_delete', 'feedback', 'show_entries.php?id='.$id.'&do_show=showentries');
-    }
-
-    $PAGE->set_url('/mod/feedback/delete_completed.php', array('id'=>$id, 'completed'=>$completedid));
-
-    if (! $cm = get_coursemodule_from_id('feedback', $id)) {
-        print_error('invalidcoursemodule');
-    }
-
-    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
-        print_error('invalidcoursemodule');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * prints the form to confirm the deleting of a completed
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+require_once("../../config.php");
+require_once("lib.php");
+require_once('delete_completed_form.php');
+
+$id = required_param('id', PARAM_INT);
+$completedid = optional_param('completedid', 0, PARAM_INT);
+$return = optional_param('return', 'entries', PARAM_ALPHA);
+
+if ($completedid == 0) {
+    print_error('no_complete_to_delete',
+                'feedback',
+                'show_entries.php?id='.$id.'&do_show=showentries');
+}
+
+$PAGE->set_url('/mod/feedback/delete_completed.php', array('id'=>$id, 'completed'=>$completedid));
+
+if (! $cm = get_coursemodule_from_id('feedback', $id)) {
+    print_error('invalidcoursemodule');
+}
+
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
+    print_error('coursemisconf');
+}
+
+if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+        print_error('badcontext');
+}
+
+require_login($course->id, true, $cm);
+
+require_capability('mod/feedback:deletesubmissions', $context);
+
+$mform = new mod_feedback_delete_completed_form();
+$newformdata = array('id'=>$id,
+                    'completedid'=>$completedid,
+                    'confirmdelete'=>'1',
+                    'do_show'=>'edit',
+                    'return'=>$return);
+$mform->set_data($newformdata);
+$formdata = $mform->get_data();
+
+if ($mform->is_cancelled()) {
+    if ($return == 'entriesanonym') {
+        redirect('show_entries_anonym.php?id='.$id);
+    } else {
+        redirect('show_entries.php?id='.$id.'&do_show=showentries');
     }
-
-    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
-            print_error('badcontext');
-    }
-
-    require_login($course->id, true, $cm);
-
-    require_capability('mod/feedback:deletesubmissions', $context);
-
-    $mform = new mod_feedback_delete_completed_form();
-    $newformdata = array('id'=>$id,
-                        'completedid'=>$completedid,
-                        'confirmdelete'=>'1',
-                        'do_show'=>'edit',
-                        'return'=>$return);
-    $mform->set_data($newformdata);
-    $formdata = $mform->get_data();
-
-    if ($mform->is_cancelled()) {
-        if($return == 'entriesanonym') {
+}
+
+if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
+    if ($completed = $DB->get_record('feedback_completed', array('id'=>$completedid))) {
+        feedback_delete_completed($completedid);
+        add_to_log($course->id,
+                   'feedback',
+                   'delete',
+                   'view.php?id='.$cm->id,
+                   $feedback->id,
+                   $cm->id);
+
+        if ($return == 'entriesanonym') {
             redirect('show_entries_anonym.php?id='.$id);
-        }else {
+        } else {
             redirect('show_entries.php?id='.$id.'&do_show=showentries');
         }
     }
+}
 
-    if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
-        if($completed = $DB->get_record('feedback_completed', array('id'=>$completedid))) {
-            feedback_delete_completed($completedid);
-            add_to_log($course->id, 'feedback', 'delete', 'view.php?id='.$cm->id, $feedback->id,$cm->id);
-            
-            if($return == 'entriesanonym') {
-                redirect('show_entries_anonym.php?id='.$id);
-            }else {
-                redirect('show_entries.php?id='.$id.'&do_show=showentries');
-            }
-        }
-    }
-
-    /// Print the page header
-    $strfeedbacks = get_string("modulenameplural", "feedback");
-    $strfeedback  = get_string("modulename", "feedback");
-    
-    $PAGE->navbar->add(get_string('delete_entry', 'feedback'));
-    $PAGE->set_heading(format_string($course->fullname));
-    $PAGE->set_title(format_string($feedback->name));
-    echo $OUTPUT->header();
-
-    /// Print the main part of the page
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    echo $OUTPUT->heading(format_text($feedback->name));
-    echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
-    echo $OUTPUT->heading(get_string('confirmdeleteentry', 'feedback'));
-    $mform->display();
-    echo $OUTPUT->box_end();
+/// Print the page header
+$strfeedbacks = get_string("modulenameplural", "feedback");
+$strfeedback  = get_string("modulename", "feedback");
 
+$PAGE->navbar->add(get_string('delete_entry', 'feedback'));
+$PAGE->set_heading(format_string($course->fullname));
+$PAGE->set_title(format_string($feedback->name));
+echo $OUTPUT->header();
 
-    echo $OUTPUT->footer();
+/// Print the main part of the page
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+echo $OUTPUT->heading(format_text($feedback->name));
+echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
+echo $OUTPUT->heading(get_string('confirmdeleteentry', 'feedback'));
+$mform->display();
+echo $OUTPUT->box_end();
 
 
+echo $OUTPUT->footer();
index f53197e..a0f677d 100644 (file)
@@ -1,25 +1,38 @@
 <?php
-/**
-* prints the form to confirm delete a completed
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+/**
+ * prints the form to confirm delete a completed
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+//It must be included from a Moodle page
 if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    die('Direct access to this script is forbidden.');
 }
 
-require_once $CFG->libdir.'/formslib.php';
+require_once($CFG->libdir.'/formslib.php');
 
 class mod_feedback_delete_completed_form extends moodleform {
-    function definition() {
+    public function definition() {
         $mform =& $this->_form;
 
-        //headline
-        //$mform->addElement('header', 'general', '');
-
         // hidden elements
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
index 3cbf200..cbd36bf 100644 (file)
@@ -1,78 +1,93 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
 /**
-* deletes an item of the feedback
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
-
-    require_once("../../config.php");
-    require_once("lib.php");
-    require_once('delete_item_form.php');
-
-    $id = required_param('id', PARAM_INT);
-    $deleteitem = required_param('deleteitem', PARAM_INT);
-
-    $PAGE->set_url('/mod/feedback/delete_item.php', array('id'=>$id, 'deleteitem'=>$deleteitem));
-
-    if (! $cm = get_coursemodule_from_id('feedback', $id)) {
-        print_error('invalidcoursemodule');
-    }
-
-    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
-        print_error('invalidcoursemodule');
-    }
-    
-    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
-            print_error('badcontext');
-    }
-
-    require_login($course->id, true, $cm);
-
-    require_capability('mod/feedback:edititems', $context);
-
-    $mform = new mod_feedback_delete_item_form();
-    $newformdata = array('id'=>$id,
-                        'deleteitem'=>$deleteitem,
-                        'confirmdelete'=>'1');
-    $mform->set_data($newformdata);
-    $formdata = $mform->get_data();
-
-    if ($mform->is_cancelled()) {
-        redirect('edit.php?id='.$id);
-    }
-
-    if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
-        feedback_delete_item($formdata->deleteitem);
-        redirect('edit.php?id=' . $id);
-    }
-
-
-    /// Print the page header
-    $strfeedbacks = get_string("modulenameplural", "feedback");
-    $strfeedback  = get_string("modulename", "feedback");
-    
-    $PAGE->navbar->add(get_string('delete_item', 'feedback'));
-    $PAGE->set_heading(format_string($course->fullname));
-    $PAGE->set_title(format_string($feedback->name));
-    echo $OUTPUT->header();
-
-    /// Print the main part of the page
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    echo $OUTPUT->heading(format_text($feedback->name));
-    echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
-    echo $OUTPUT->heading(get_string('confirmdeleteitem', 'feedback'));
-    print_string('relateditemsdeleted','feedback');
-    $mform->display();
-    echo $OUTPUT->box_end();
-
-    echo $OUTPUT->footer();
+ * deletes an item of the feedback
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+require_once("../../config.php");
+require_once("lib.php");
+require_once('delete_item_form.php');
+
+$id = required_param('id', PARAM_INT);
+$deleteitem = required_param('deleteitem', PARAM_INT);
+
+$PAGE->set_url('/mod/feedback/delete_item.php', array('id'=>$id, 'deleteitem'=>$deleteitem));
+
+if (! $cm = get_coursemodule_from_id('feedback', $id)) {
+    print_error('invalidcoursemodule');
+}
+
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
+    print_error('coursemisconf');
+}
+
+if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+        print_error('badcontext');
+}
+
+require_login($course->id, true, $cm);
+
+require_capability('mod/feedback:edititems', $context);
+
+$mform = new mod_feedback_delete_item_form();
+$newformdata = array('id'=>$id,
+                    'deleteitem'=>$deleteitem,
+                    'confirmdelete'=>'1');
+$mform->set_data($newformdata);
+$formdata = $mform->get_data();
+
+if ($mform->is_cancelled()) {
+    redirect('edit.php?id='.$id);
+}
+
+if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
+    feedback_delete_item($formdata->deleteitem);
+    redirect('edit.php?id=' . $id);
+}
+
+
+/// Print the page header
+$strfeedbacks = get_string("modulenameplural", "feedback");
+$strfeedback  = get_string("modulename", "feedback");
+
+$PAGE->navbar->add(get_string('delete_item', 'feedback'));
+$PAGE->set_heading(format_string($course->fullname));
+$PAGE->set_title(format_string($feedback->name));
+echo $OUTPUT->header();
+
+/// Print the main part of the page
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+echo $OUTPUT->heading(format_text($feedback->name));
+echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
+echo $OUTPUT->heading(get_string('confirmdeleteitem', 'feedback'));
+print_string('relateditemsdeleted', 'feedback');
+$mform->display();
+echo $OUTPUT->box_end();
+
+echo $OUTPUT->footer();
 
 
index 0d0b0d4..f7b43d7 100644 (file)
@@ -1,25 +1,38 @@
 <?php
-/**
-* prints the form to confirm delete a completed
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+/**
+ * prints the form to confirm delete a completed
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+//It must be included from a Moodle page
 if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    die('Direct access to this script is forbidden.');
 }
 
-require_once $CFG->libdir.'/formslib.php';
+require_once($CFG->libdir.'/formslib.php');
 
 class mod_feedback_delete_item_form extends moodleform {
-    function definition() {
+    public function definition() {
         $mform =& $this->_form;
 
-        //headline
-        //$mform->addElement('header', 'general', '');
-
         // hidden elements
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
index f108a27..2d36e82 100644 (file)
@@ -1,26 +1,38 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
-* deletes a template
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+ * deletes a template
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
 
 require_once("../../config.php");
 require_once("lib.php");
 require_once('delete_template_form.php');
 require_once($CFG->libdir.'/tablelib.php');
 
-// $SESSION->feedback->current_tab = 'templates';
 $current_tab = 'templates';
 
 $id = required_param('id', PARAM_INT);
 $canceldelete = optional_param('canceldelete', false, PARAM_INT);
 $shoulddelete = optional_param('shoulddelete', false, PARAM_INT);
 $deletetempl = optional_param('deletetempl', false, PARAM_INT);
-// $formdata = data_submitted();
 
 $url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
 if ($canceldelete !== false) {
@@ -34,11 +46,11 @@ if ($deletetempl !== false) {
 }
 $PAGE->set_url($url);
 
-if(($formdata = data_submitted()) AND !confirm_sesskey()) {
+if (($formdata = data_submitted()) AND !confirm_sesskey()) {
     print_error('invalidsesskey');
 }
 
-if($canceldelete == 1){
+if ($canceldelete == 1) {
     $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates'));
     redirect($editurl->out(false));
 }
@@ -77,12 +89,12 @@ if ($mform->is_cancelled()) {
     redirect($deleteurl->out(false));
 }
 
-if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
-    if(!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) {
+if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
+    if (!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) {
         print_error('error');
     }
 
-    if($template->ispublic) {
+    if ($template->ispublic) {
         $systemcontext = get_system_context();
         require_capability('mod/feedback:createpublictemplate', $systemcontext);
         require_capability('mod/feedback:deletetemplate', $systemcontext);
@@ -95,32 +107,33 @@ if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
 /// Print the page header
 $strfeedbacks = get_string("modulenameplural", "feedback");
 $strfeedback  = get_string("modulename", "feedback");
-$strdeletefeedback = get_string('delete_template','feedback');
+$strdeletefeedback = get_string('delete_template', 'feedback');
 
 $PAGE->set_heading(format_string($course->fullname));
 $PAGE->set_title(format_string($feedback->name));
 echo $OUTPUT->header();
 
 /// print the tabs
-include('tabs.php');
+require('tabs.php');
 
 /// Print the main part of the page
 ///////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////
 echo $OUTPUT->heading($strdeletefeedback);
-if($shoulddelete == 1) {
+if ($shoulddelete == 1) {
 
     echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
     echo $OUTPUT->heading(get_string('confirmdeletetemplate', 'feedback'));
     $mform->display();
     echo $OUTPUT->box_end();
-}else {
+} else {
     //first we get the own templates
     $templates = feedback_get_template_list($course, 'own');
-    if(!is_array($templates)) {
-        echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
-    }else {
+    if (!is_array($templates)) {
+        echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
+                         'generalbox boxaligncenter');
+    } else {
         echo $OUTPUT->heading(get_string('course'), 3);
         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
         $tablecolumns = array('template', 'action');
@@ -137,7 +150,7 @@ if($shoulddelete == 1) {
         $tablecourse->set_attribute('class', 'generaltable');
         $tablecourse->setup();
 
-        foreach($templates as $template) {
+        foreach ($templates as $template) {
             $data = array();
             $data[] = $template->name;
             $url = new moodle_url($deleteurl, array(
@@ -154,12 +167,13 @@ if($shoulddelete == 1) {
     }
     //now we get the public templates if it is permitted
     $systemcontext = get_system_context();
-    if(has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
+    if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
         has_capability('mod/feedback:deletetemplate', $systemcontext)) {
         $templates = feedback_get_template_list($course, 'public');
-        if(!is_array($templates)) {
-            echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
-        }else {
+        if (!is_array($templates)) {
+            echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
+                              'generalbox boxaligncenter');
+        } else {
             echo $OUTPUT->heading(get_string('public', 'feedback'), 3);
             echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
             $tablecolumns = array('template', 'action');
@@ -176,9 +190,7 @@ if($shoulddelete == 1) {
             $tablepublic->set_attribute('class', 'generaltable');
             $tablepublic->setup();
 
-            // echo $OUTPUT->heading(get_string('public', 'feedback'), 3);
-            // echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-            foreach($templates as $template) {
+            foreach ($templates as $template) {
                 $data = array();
                 $data[] = $template->name;
                 $url = new moodle_url($deleteurl, array(
index fcb07d7..e061317 100644 (file)
@@ -1,25 +1,38 @@
 <?php
-/**
-* prints the form to confirm delete a completed
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+/**
+ * prints the form to confirm delete a completed
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+//It must be included from a Moodle page
 if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    die('Direct access to this script is forbidden.');
 }
 
-require_once $CFG->libdir.'/formslib.php';
+require_once($CFG->libdir.'/formslib.php');
 
 class mod_feedback_delete_template_form extends moodleform {
-    function definition() {
+    public function definition() {
         $mform =& $this->_form;
 
-        //headline
-        //$mform->addElement('header', 'general', '');
-
         // hidden elements
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
@@ -34,4 +47,3 @@ class mod_feedback_delete_template_form extends moodleform {
 
     }
 }
-
index 98632b1..3eeb7a4 100644 (file)
@@ -1,12 +1,26 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
-* prints the form to edit the feedback items such moving, deleting and so on
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+ * prints the form to edit the feedback items such moving, deleting and so on
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
 
 require_once("../../config.php");
 require_once("lib.php");
@@ -16,7 +30,7 @@ feedback_init_feedback_session();
 
 $id = required_param('id', PARAM_INT);
 
-if(($formdata = data_submitted()) AND !confirm_sesskey()) {
+if (($formdata = data_submitted()) AND !confirm_sesskey()) {
     print_error('invalidsesskey');
 }
 
@@ -27,7 +41,6 @@ $moveitem = optional_param('moveitem', false, PARAM_INT);
 $movehere = optional_param('movehere', false, PARAM_INT);
 $switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT);
 
-// $SESSION->feedback->current_tab = $do_show;
 $current_tab = $do_show;
 
 $url = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>$do_show));
@@ -53,22 +66,22 @@ require_login($course->id, true, $cm);
 require_capability('mod/feedback:edititems', $context);
 
 //move up/down items
-if($moveupitem){
+if ($moveupitem) {
     $item = $DB->get_record('feedback_item', array('id'=>$moveupitem));
     feedback_moveup_item($item);
 }
-if($movedownitem){
+if ($movedownitem) {
     $item = $DB->get_record('feedback_item', array('id'=>$movedownitem));
     feedback_movedown_item($item);
 }
 
 //moving of items
-if($movehere && isset($SESSION->feedback->moving->movingitem)){
+if ($movehere && isset($SESSION->feedback->moving->movingitem)) {
     $item = $DB->get_record('feedback_item', array('id'=>$SESSION->feedback->moving->movingitem));
     feedback_move_item($item, intval($movehere));
     $moveitem = false;
 }
-if($moveitem){
+if ($moveitem) {
     $item = $DB->get_record('feedback_item', array('id'=>$moveitem));
     $SESSION->feedback->moving->shouldmoving = 1;
     $SESSION->feedback->moving->movingitem = $moveitem;
@@ -76,7 +89,7 @@ if($moveitem){
     unset($SESSION->feedback->moving);
 }
 
-if($switchitemrequired) {
+if ($switchitemrequired) {
     $item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired));
     @feedback_switch_item_required($item);
     redirect($url->out(false));
@@ -89,24 +102,26 @@ $create_template_form->set_feedbackdata(array('context'=>$context, 'course'=>$co
 $create_template_form->set_form_elements();
 $create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates'));
 $create_template_formdata = $create_template_form->get_data();
-if(isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
+if (isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
     //check the capabilities to create templates
-    if(!has_capability('mod/feedback:createprivatetemplate', $context) AND
+    if (!has_capability('mod/feedback:createprivatetemplate', $context) AND
             !has_capability('mod/feedback:createpublictemplate', $context)) {
         print_error('cannotsavetempl', 'feedback');
     }
-    if(trim($create_template_formdata->templatename) == '') {
+    if (trim($create_template_formdata->templatename) == '') {
         $savereturn = 'notsaved_name';
-    }else {
+    } else {
         //if the feedback is located on the frontpage then templates can be public
-        if(has_capability('mod/feedback:createpublictemplate', get_system_context())) {
+        if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
             $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
-        }else {
+        } else {
             $create_template_formdata->ispublic = 0;
         }
-        if(!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic)) {
+        if (!feedback_save_as_template($feedback,
+                                      $create_template_formdata->templatename,
+                                      $create_template_formdata->ispublic)) {
             $savereturn = 'failed';
-        }else {
+        } else {
             $savereturn = 'saved';
         }
     }
@@ -115,12 +130,12 @@ if(isset($create_template_formdata->savetemplate) && $create_template_formdata->
 //get the feedbackitems
 $lastposition = 0;
 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
-if(is_array($feedbackitems)){
+if (is_array($feedbackitems)) {
     $feedbackitems = array_values($feedbackitems);
-    if(count($feedbackitems) > 0) {
+    if (count($feedbackitems) > 0) {
         $lastitem = $feedbackitems[count($feedbackitems)-1];
         $lastposition = $lastitem->position;
-    }else {
+    } else {
         $lastposition = 0;
     }
 }
@@ -137,9 +152,6 @@ $use_template_form->set_feedbackdata(array('course' => $course));
 $use_template_form->set_form_elements();
 $use_template_form->set_data(array('id'=>$id));
 
-//the create_template-form
-//$create_template_form = new feedback_edit_create_template_form('use_templ.php');
-
 /// Print the page header
 $strfeedbacks = get_string("modulenameplural", "feedback");
 $strfeedback  = get_string("modulename", "feedback");
@@ -150,7 +162,7 @@ $PAGE->set_title(format_string($feedback->name));
 echo $OUTPUT->header();
 
 /// print the tabs
-include('tabs.php');
+require('tabs.php');
 
 /// Print the main part of the page
 ///////////////////////////////////////////////////////////////////////////
@@ -160,38 +172,45 @@ include('tabs.php');
 $savereturn=isset($savereturn)?$savereturn:'';
 
 //print the messages
-if($savereturn == 'notsaved_name') {
-    echo '<p align="center"><b><font color="red">'.get_string('name_required','feedback').'</font></b></p>';
+if ($savereturn == 'notsaved_name') {
+    echo '<p align="center"><b><font color="red">'.
+          get_string('name_required', 'feedback').
+          '</font></b></p>';
 }
 
-if($savereturn == 'saved') {
-    echo '<p align="center"><b><font color="green">'.get_string('template_saved','feedback').'</font></b></p>';
+if ($savereturn == 'saved') {
+    echo '<p align="center"><b><font color="green">'.
+          get_string('template_saved', 'feedback').
+          '</font></b></p>';
 }
 
-if($savereturn == 'failed') {
-    echo '<p align="center"><b><font color="red">'.get_string('saving_failed','feedback').'</font></b></p>';
+if ($savereturn == 'failed') {
+    echo '<p align="center"><b><font color="red">'.
+          get_string('saving_failed', 'feedback').
+          '</font></b></p>';
 }
 
-feedback_print_errors();
-
 ///////////////////////////////////////////////////////////////////////////
 ///print the template-section
 ///////////////////////////////////////////////////////////////////////////
-if($do_show == 'templates') {
+if ($do_show == 'templates') {
     echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
     $use_template_form->display();
 
-    if(has_capability('mod/feedback:createprivatetemplate', $context) OR
+    if (has_capability('mod/feedback:createprivatetemplate', $context) OR
                 has_capability('mod/feedback:createpublictemplate', $context)) {
-        $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
+        $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id));
         $create_template_form->display();
-        echo '<p><a href="'.$deleteurl->out().'">'.get_string('delete_templates', 'feedback').'</a></p>';
-    }else {
+        echo '<p><a href="'.$deleteurl->out().'">'.
+             get_string('delete_templates', 'feedback').
+             '</a></p>';
+    } else {
         echo '&nbsp;';
     }
 
-    if(has_capability('mod/feedback:edititems', $context)) {
-        $exporturl = new moodle_url('/mod/feedback/export.php', array('action'=>'exportfile', 'id'=>$id));
+    if (has_capability('mod/feedback:edititems', $context)) {
+        $urlparams = array('action'=>'exportfile', 'id'=>$id);
+        $exporturl = new moodle_url('/mod/feedback/export.php', $urlparams);
         $importurl = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
         echo '<p>
             <a href="'.$exporturl->out().'">'.get_string('export_questions', 'feedback').'</a>/
@@ -203,11 +222,11 @@ if($do_show == 'templates') {
 ///////////////////////////////////////////////////////////////////////////
 ///print the Item-Edit-section
 ///////////////////////////////////////////////////////////////////////////
-if($do_show == 'edit') {
+if ($do_show == 'edit') {
 
     $add_item_form->display();
 
-    if(is_array($feedbackitems)){
+    if (is_array($feedbackitems)) {
         $itemnr = 0;
 
         $align = right_to_left() ? 'right' : 'left';
@@ -215,156 +234,180 @@ if($do_show == 'edit') {
         $helpbutton = $OUTPUT->help_icon('preview', 'feedback');
 
         echo $OUTPUT->heading($helpbutton . get_string('preview', 'feedback'));
-        if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
-            echo $OUTPUT->heading('<a href="edit.php?id='.$id.'">'.get_string('cancel_moving', 'feedback').'</a>');
+        if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
+            $anker = '<a href="edit.php?id='.$id.'">';
+            $anker .= get_string('cancel_moving', 'feedback');
+            $anker .= '</a>';
+            echo $OUTPUT->heading($anker);
         }
-        // echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
 
         //check, if there exists required-elements
-        $countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=> 1));
-        if($countreq > 0) {
-            // echo '<font color="red">(*)' . get_string('items_are_required', 'feedback') . '</font>';
-            echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>';
+        $params = array('feedback' => $feedback->id, 'required' => 1);
+        $countreq = $DB->count_records('feedback_item', $params);
+        if ($countreq > 0) {
+            echo '<span class="feedback_required_mark">(*)';
+            echo get_string('items_are_required', 'feedback');
+            echo '</span>';
         }
 
         //use list instead a table
         echo $OUTPUT->box_start('feedback_items');
-            if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
-                $moveposition = 1;
-                $movehereurl = new moodle_url($url, array('movehere'=>$moveposition));
-                echo $OUTPUT->box_start('feedback_item_box_'.$align.' clipboard'); //only shown if shouldmoving = 1
-                    $buttonlink = $movehereurl->out();
-                    echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
-                            <img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->pix_url('movehere') . '" />
-                          </a>';
-                echo $OUTPUT->box_end();
-            }
-            //print the inserted items
-            $itempos = 0;
-            foreach($feedbackitems as $feedbackitem){
-                $itempos++;
-                if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->movingitem == $feedbackitem->id){ //hiding the item to move
+        if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
+            $moveposition = 1;
+            $movehereurl = new moodle_url($url, array('movehere'=>$moveposition));
+            //only shown if shouldmoving = 1
+            echo $OUTPUT->box_start('feedback_item_box_'.$align.' clipboard');
+            $buttonlink = $movehereurl->out();
+            $strbutton = get_string('move_here', 'feedback');
+            $src = $OUTPUT->pix_url('movehere');
+            echo '<a title="'.$strbutton.'" href="'.$buttonlink.'">
+                    <img class="movetarget" alt="'.$strbutton.'" src="'.$src.'" />
+                  </a>';
+            echo $OUTPUT->box_end();
+        }
+        //print the inserted items
+        $itempos = 0;
+        foreach ($feedbackitems as $feedbackitem) {
+            $itempos++;
+            //hiding the item to move
+            if (isset($SESSION->feedback->moving)) {
+                if ($SESSION->feedback->moving->movingitem == $feedbackitem->id) {
                     continue;
                 }
-                if($feedbackitem->dependitem > 0) {
-                    $dependstyle = ' feedback_depend';
-                }else {
-                    $dependstyle = '';
-                }
-                echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
-                    //items without value only are labels
-                    if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
-                        $itemnr++;
-                        echo $OUTPUT->box_start('feedback_item_number_'.$align) . $itemnr . $OUTPUT->box_end();
-                    }
-                    echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
-                        echo $OUTPUT->box_start('feedback_item_commands_'.$align);
-                            echo '<span class="feedback_item_commands">('.get_string('position', 'feedback').':'.$itempos .')</span>';
-                            //print the moveup-button
-                            if($feedbackitem->position > 1){
-                                echo '<span class="feedback_item_command_moveup">';
-                                $moveupurl = new moodle_url($url, array('moveupitem'=>$feedbackitem->id));
-                                $buttonlink = $moveupurl->out();
-                                echo '<a class="icon up" title="'.get_string('moveup_item','feedback').'" href="'.$buttonlink.'">
-                                        <img alt="'.get_string('moveup_item','feedback').'" src="'.$OUTPUT->pix_url('t/up') . '" />
-                                      </a>';
-                                echo '</span>';
-                            }
-                            //print the movedown-button
-                            if($feedbackitem->position < $lastposition - 1){
-                                echo '<span class="feedback_item_command_movedown">';
-                                $movedownurl = new moodle_url($url, array('movedownitem'=>$feedbackitem->id));
-                                $buttonlink = $movedownurl->out();
-                                echo '<a class="icon down" title="'.get_string('movedown_item','feedback').'" href="'.$buttonlink.'">
-                                        <img alt="'.get_string('movedown_item','feedback').'" src="'.$OUTPUT->pix_url('t/down') . '" />
-                                      </a>';
-                                echo '</span>';
-                            }
-                            //print the move-button
-                            echo '<span class="feedback_item_command_move">';
-                            $moveurl = new moodle_url($url, array('moveitem'=>$feedbackitem->id));
-                            $buttonlink = $moveurl->out();
-                            echo '<a class="editing_move" title="'.get_string('move_item','feedback').'" href="'.$buttonlink.'">
-                                    <img alt="'.get_string('move_item','feedback').'" src="'.$OUTPUT->pix_url('t/move') . '" />
-                                  </a>';
-                            echo '</span>';
-                            //print the button to edit the item
-                            if($feedbackitem->typ != 'pagebreak') {
-                                echo '<span class="feedback_item_command_edit">';
-                                $editurl = new moodle_url('/mod/feedback/edit_item.php');
-                                $editurl->params(array('do_show'=>$do_show,
-                                                         'cmid'=>$id,
-                                                         'id'=>$feedbackitem->id,
-                                                         'typ'=>$feedbackitem->typ));
-                                
-                                // in edit_item.php the param id is used for the itemid and the cmid is the id to get the module
-                                $buttonlink = $editurl->out();
-                                echo '<a class="editing_update" title="'.get_string('edit_item','feedback').'" href="'.$buttonlink.'">
-                                        <img alt="'.get_string('edit_item','feedback').'" src="'.$OUTPUT->pix_url('t/edit') . '" />
-                                      </a>';
-                                echo '</span>';
-                            }
-
-                            //print the toggle-button to switch required yes/no
-                            if($feedbackitem->hasvalue == 1) {
-                                echo '<span class="feedback_item_command_toggle">';
-                                // echo '<form action="edit.php" method="post"><fieldset>';
-                                if($feedbackitem->required == 1) {
-                                    // echo '<input title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" hspace="1" height="11" width="11" border="0" />';
-                                    // echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" />';
-                                    $buttontitle = get_string('switch_item_to_not_required','feedback');
-                                    $buttonimg = 'pics/required.gif';
-                                } else {
-                                    // echo '<input title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" hspace="1" height="11" width="11" border="0" />';
-                                    // echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" />';
-                                    $buttontitle = get_string('switch_item_to_required','feedback');
-                                    $buttonimg = 'pics/notrequired.gif';
-                                }
-                                $requiredurl = new moodle_url($url, array('switchitemrequired'=>$feedbackitem->id));
-                                $buttonlink = $requiredurl->out();
-                                echo '<a class="icon feedback_switchrequired" title="'.$buttontitle.'" href="'.$buttonlink.'">
-                                        <img alt="'.$buttontitle.'" src="'.$buttonimg.'" />
-                                      </a>';
-                                echo '</span>';
-                            }
-                            
-                            //print the delete-button
-                            echo '<span class="feedback_item_command_toggle">';
-                            $deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
-                            $deleteitemurl->params(array('id'=>$id,
-                                                         'do_show'=>$do_show,
-                                                         'deleteitem'=>$feedbackitem->id));
-                                                         
-                            $buttonlink = $deleteitemurl->out();
-                            echo '<a class="icon delete" title="'.get_string('delete_item','feedback').'" href="'.$buttonlink.'">
-                                    <img alt="'.get_string('delete_item','feedback').'" src="'.$OUTPUT->pix_url('t/delete') . '" />
-                                  </a>';
-                            echo '</span>';
-                        echo $OUTPUT->box_end();
-                    if($feedbackitem->typ != 'pagebreak') {
-                        feedback_print_item_preview($feedbackitem);
-                    }else {
-                        echo $OUTPUT->box_start('feedback_pagebreak');
-                        echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
-                        echo $OUTPUT->box_end();
-                    }
-                    echo $OUTPUT->box_end();
+            }
+            if ($feedbackitem->dependitem > 0) {
+                $dependstyle = ' feedback_depend';
+            } else {
+                $dependstyle = '';
+            }
+            echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
+            //items without value only are labels
+            if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
+                $itemnr++;
+                echo $OUTPUT->box_start('feedback_item_number_'.$align);
+                echo $itemnr;
                 echo $OUTPUT->box_end();
-                if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
-                    $moveposition++;
-                    $movehereurl->param('movehere', $moveposition);
-                    echo $OUTPUT->box_start('clipboard'); //only shown if shouldmoving = 1
-                            $buttonlink = $movehereurl->out();
-                            echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
-                                    <img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->pix_url('movehere') . '" />
-                                  </a>';
-                    echo $OUTPUT->box_end();
+            }
+            echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
+            echo $OUTPUT->box_start('feedback_item_commands_'.$align);
+            echo '<span class="feedback_item_commands">';
+            echo '('.get_string('position', 'feedback').':'.$itempos .')';
+            echo '</span>';
+            //print the moveup-button
+            if ($feedbackitem->position > 1) {
+                echo '<span class="feedback_item_command_moveup">';
+                $moveupurl = new moodle_url($url, array('moveupitem'=>$feedbackitem->id));
+                $buttonlink = $moveupurl->out();
+                $strbutton = get_string('moveup_item', 'feedback');
+                echo '<a class="icon up" title="'.$strbutton.'" href="'.$buttonlink.'">
+                        <img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/up') . '" />
+                      </a>';
+                echo '</span>';
+            }
+            //print the movedown-button
+            if ($feedbackitem->position < $lastposition - 1) {
+                echo '<span class="feedback_item_command_movedown">';
+                $urlparams = array('movedownitem'=>$feedbackitem->id);
+                $movedownurl = new moodle_url($url, $urlparams);
+                $buttonlink = $movedownurl->out();
+                $strbutton = get_string('movedown_item', 'feedback');
+                echo '<a class="icon down" title="'.$strbutton.'" href="'.$buttonlink.'">
+                        <img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/down') . '" />
+                      </a>';
+                echo '</span>';
+            }
+            //print the move-button
+            echo '<span class="feedback_item_command_move">';
+            $moveurl = new moodle_url($url, array('moveitem'=>$feedbackitem->id));
+            $buttonlink = $moveurl->out();
+            $strbutton = get_string('move_item', 'feedback');
+            echo '<a class="editing_move" title="'.$strbutton.'" href="'.$buttonlink.'">
+                    <img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/move') . '" />
+                  </a>';
+            echo '</span>';
+            //print the button to edit the item
+            if ($feedbackitem->typ != 'pagebreak') {
+                echo '<span class="feedback_item_command_edit">';
+                $editurl = new moodle_url('/mod/feedback/edit_item.php');
+                $editurl->params(array('do_show'=>$do_show,
+                                         'cmid'=>$id,
+                                         'id'=>$feedbackitem->id,
+                                         'typ'=>$feedbackitem->typ));
+
+                // in edit_item.php the param id is used for the itemid
+                // and the cmid is the id to get the module
+                $buttonlink = $editurl->out();
+                $strbutton = get_string('edit_item', 'feedback');
+                echo '<a class="editing_update" title="'.$strbutton.'" href="'.$buttonlink.'">
+                        <img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/edit') . '" />
+                      </a>';
+                echo '</span>';
+            }
+
+            //print the toggle-button to switch required yes/no
+            if ($feedbackitem->hasvalue == 1) {
+                echo '<span class="feedback_item_command_toggle">';
+                if ($feedbackitem->required == 1) {
+                    $buttontitle = get_string('switch_item_to_not_required', 'feedback');
+                    $buttonimg = 'pics/required.gif';
+                } else {
+                    $buttontitle = get_string('switch_item_to_required', 'feedback');
+                    $buttonimg = 'pics/notrequired.gif';
                 }
-                echo '<div class="clearer">&nbsp;</div>';
+                $urlparams = array('switchitemrequired'=>$feedbackitem->id);
+                $requiredurl = new moodle_url($url, $urlparams);
+                $buttonlink = $requiredurl->out();
+                echo '<a class="icon '.
+                        'feedback_switchrequired" '.
+                        'title="'.$buttontitle.'" '.
+                        'href="'.$buttonlink.'">'.
+                        '<img alt="'.$buttontitle.'" src="'.$buttonimg.'" />'.
+                        '</a>';
+                echo '</span>';
+            }
+
+            //print the delete-button
+            echo '<span class="feedback_item_command_toggle">';
+            $deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
+            $deleteitemurl->params(array('id'=>$id,
+                                         'do_show'=>$do_show,
+                                         'deleteitem'=>$feedbackitem->id));
+
+            $buttonlink = $deleteitemurl->out();
+            $strbutton = get_string('delete_item', 'feedback');
+            $src = $OUTPUT->pix_url('t/delete');
+            echo '<a class="icon delete" title="'.$strbutton.'" href="'.$buttonlink.'">
+                    <img alt="'.$strbutton.'" src="'.$src.'" />
+                  </a>';
+            echo '</span>';
+            echo $OUTPUT->box_end();
+            if ($feedbackitem->typ != 'pagebreak') {
+                feedback_print_item_preview($feedbackitem);
+            } else {
+                echo $OUTPUT->box_start('feedback_pagebreak');
+                echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
+                echo $OUTPUT->box_end();
             }
+            echo $OUTPUT->box_end();
+            echo $OUTPUT->box_end();
+            if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
+                $moveposition++;
+                $movehereurl->param('movehere', $moveposition);
+                echo $OUTPUT->box_start('clipboard'); //only shown if shouldmoving = 1
+                $buttonlink = $movehereurl->out();
+                $strbutton = get_string('move_here', 'feedback');
+                $src = $OUTPUT->pix_url('movehere');
+                echo '<a title="'.$strbutton.'" href="'.$buttonlink.'">
+                        <img class="movetarget" alt="'.$strbutton.'" src="'.$src.'" />
+                      </a>';
+                echo $OUTPUT->box_end();
+            }
+            echo '<div class="clearer">&nbsp;</div>';
+        }
         echo $OUTPUT->box_end();
-    }else{
-        echo $OUTPUT->box(get_string('no_items_available_yet','feedback'),'generalbox boxaligncenter');
+    } else {
+        echo $OUTPUT->box(get_string('no_items_available_yet', 'feedback'),
+                         'generalbox boxaligncenter');
     }
 }
 /// Finish the page
index 0af2868..88354c7 100644 (file)
@@ -1,31 +1,41 @@
 <?php
-/**
-* prints the forms to choose an item-typ to create items and to choose a template to use
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+/**
+ * prints the forms to choose an item-typ to create items and to choose a template to use
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+//It must be included from a Moodle page
 if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    die('Direct access to this script is forbidden.');
 }
 
-require_once $CFG->libdir.'/formslib.php';
+require_once($CFG->libdir.'/formslib.php');
 
 class feedback_edit_add_question_form extends moodleform {
-    function definition() {
+    public function definition() {
         $mform =& $this->_form;
 
         //headline
         $mform->addElement('header', 'general', get_string('add_items', 'feedback'));
         // visible elements
-        // $feedback_names = feedback_load_feedback_items('mod/feedback/item');
-        // $feedback_names_options = array();
-        // $feedback_names_options[' '] = get_string('select');
-        // foreach($feedback_names as $fn) {
-            // $feedback_names_options[$fn] = get_string($fn,'feedback');
-        // }
         $feedback_names_options = feedback_load_feedback_items_options();
 
         $attributes = 'onChange="this.form.submit()"';
@@ -36,16 +46,16 @@ class feedback_edit_add_question_form extends moodleform {
         $mform->setType('cmid', PARAM_INT);
         $mform->addElement('hidden', 'position');
         $mform->setType('position', PARAM_INT);
-//-------------------------------------------------------------------------------
+
         // buttons
         $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'));
     }
 }
 
 class feedback_edit_use_template_form extends moodleform {
-    var $feedbackdata;
+    private $feedbackdata;
 
-    function definition() {
+    public function definition() {
         $this->feedbackdata = new stdClass();
         //this function can not be called, because not all data are available at this time
         //I use set_form_elements instead
@@ -54,9 +64,9 @@ class feedback_edit_use_template_form extends moodleform {
     //this function set the data used in set_form_elements()
     //in this form the only value have to set is course
     //eg: array('course' => $course)
-    function set_feedbackdata($data) {
-        if(is_array($data)) {
-            foreach($data as $key => $val) {
+    public function set_feedbackdata($data) {
+        if (is_array($data)) {
+            foreach ($data as $key => $val) {
                 $this->feedbackdata->{$key} = $val;
             }
         }
@@ -65,7 +75,7 @@ class feedback_edit_use_template_form extends moodleform {
     //here the elements will be set
     //this function have to be called manually
     //the advantage is that the data are already set
-    function set_form_elements(){
+    public function set_form_elements() {
         $mform =& $this->_form;
 
         $elementgroup = array();
@@ -81,58 +91,63 @@ class feedback_edit_use_template_form extends moodleform {
         $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
 
         $options = array();
-        if($owntemplates or $publictemplates) {
+        if ($owntemplates or $publictemplates) {
             $options[''] = array('' => get_string('choose'));
-        
-            if($owntemplates) {
+
+            if ($owntemplates) {
                 $courseoptions = array();
-                foreach($owntemplates as $template) {
+                foreach ($owntemplates as $template) {
                     $courseoptions[$template->id] = $template->name;
                 }
                 $options[get_string('course')] = $courseoptions;
             }
-        
-            if($publictemplates) {
+
+            if ($publictemplates) {
                 $publicoptions = array();
-                foreach($publictemplates as $template) {
+                foreach ($publictemplates as $template) {
                     $publicoptions[$template->id] = $template->name;
                 }
                 $options[get_string('public', 'feedback')] = $publicoptions;
             }
 
             $attributes = 'onChange="this.form.submit()"';
-            $elementgroup[] =& $mform->createElement('selectgroups', 'templateid', '', $options, $attributes);
-            $elementgroup[] =& $mform->createElement('submit', 'use_template', get_string('use_this_template', 'feedback'));
-        }else {
+            $elementgroup[] =& $mform->createElement('selectgroups',
+                                                     'templateid',
+                                                     '',
+                                                     $options,
+                                                     $attributes);
+
+            $elementgroup[] =& $mform->createElement('submit',
+                                                     'use_template',
+                                                     get_string('use_this_template', 'feedback'));
+        } else {
             $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
         }
         $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
 
-    //-------------------------------------------------------------------------------
     }
 }
 
 class feedback_edit_create_template_form extends moodleform {
-    var $feedbackdata;
+    private $feedbackdata;
 
-    function definition() {
+    public function definition() {
     }
 
-    function data_preprocessing(&$default_values){
+    public function data_preprocessing(&$default_values) {
         $default_values['templatename'] = '';
     }
 
-    function set_feedbackdata($data) {
-        if(is_array($data)) {
-            foreach($data as $key => $val) {
+    public function set_feedbackdata($data) {
+        if (is_array($data)) {
+            foreach ($data as $key => $val) {
                 $this->feedbackdata->{$key} = $val;
             }
         }
     }
 
-    function set_form_elements(){
+    public function set_form_elements() {
         $mform =& $this->_form;
-        // $capabilities = $this->feedbackdata->capabilities;
 
         // hidden elements
         $mform->addElement('hidden', 'id');
@@ -148,20 +163,35 @@ class feedback_edit_create_template_form extends moodleform {
         // visible elements
         $elementgroup = array();
 
-        $elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback'));
-        $elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200'));
+        $elementgroup[] =& $mform->createElement('static',
+                                                 'templatenamelabel',
+                                                 get_string('name', 'feedback'));
+
+        $elementgroup[] =& $mform->createElement('text',
+                                                 'templatename',
+                                                 get_string('name', 'feedback'),
+                                                 array('size'=>'40', 'maxlength'=>'200'));
 
-        if(has_capability('mod/feedback:createpublictemplate', get_system_context())) {
-            $elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
+        if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
+            $elementgroup[] =& $mform->createElement('checkbox',
+                                                     'ispublic',
+                                                     get_string('public', 'feedback'),
+                                                     get_string('public', 'feedback'));
         }
 
         // buttons
-        $elementgroup[] =& $mform->createElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
-        $mform->addGroup($elementgroup, 'elementgroup', get_string('name', 'feedback'), array(' '), false);
+        $elementgroup[] =& $mform->createElement('submit',
+                                                 'create_template',
+                                                 get_string('save_as_new_template', 'feedback'));
+
+        $mform->addGroup($elementgroup,
+                         'elementgroup',
+                         get_string('name', 'feedback'),
+                         array(' '),
+                         false);
 
         $mform->setType('templatename', PARAM_TEXT);
 
-//-------------------------------------------------------------------------------
     }
 }
 
index 2a0807f..28bd0c0 100644 (file)
@@ -1,4 +1,18 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * prints the form to edit a dedicated item
@@ -13,7 +27,6 @@ require_once("lib.php");
 
 feedback_init_feedback_session();
 
-// $cmid = optional_param('cmid', NULL, PARAM_INT);
 $cmid = required_param('cmid', PARAM_INT);
 $typ = optional_param('typ', false, PARAM_ALPHA);
 $id = optional_param('id', false, PARAM_INT);
@@ -21,7 +34,9 @@ $action = optional_param('action', false, PARAM_ALPHA);
 
 $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
 
-if(!$typ)redirect($editurl->out(false));
+if (!$typ) {
+    redirect($editurl->out(false));
+}
 
 $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
 if ($typ !== false) {
@@ -36,7 +51,7 @@ $PAGE->set_url($url);
 $usehtmleditor = can_use_html_editor();
 
 
-if(($formdata = data_submitted()) AND !confirm_sesskey()) {
+if (($formdata = data_submitted()) AND !confirm_sesskey()) {
     print_error('invalidsesskey');
 }
 
@@ -61,7 +76,7 @@ require_login($course->id, true, $cm);
 require_capability('mod/feedback:edititems', $context);
 
 //if the typ is pagebreak so the item will be saved directly
-if($typ == 'pagebreak') {
+if ($typ == 'pagebreak') {
     feedback_create_pagebreak($feedback->id);
     redirect($editurl->out(false));
     exit;
@@ -69,9 +84,9 @@ if($typ == 'pagebreak') {
 
 //get the existing item or create it
 // $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
-if($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
+if ($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
     $typ = $item->typ;
-}else {
+} else {
     $item = new stdClass();
     $item->id = null;
     $item->position = -1;
@@ -88,12 +103,12 @@ $itemobj = feedback_get_item_class($typ);
 
 $itemobj->build_editform($item, $feedback, $cm);
 
-if($itemobj->is_cancelled()) {
+if ($itemobj->is_cancelled()) {
     redirect($editurl->out(false));
     exit;
 }
-if($itemobj->get_data()) {
-    if($item = $itemobj->save_item()) {
+if ($itemobj->get_data()) {
+    if ($item = $itemobj->save_item()) {
         feedback_move_item($item, $item->position);
         redirect($editurl->out(false));
     }
@@ -113,18 +128,15 @@ $PAGE->set_heading(format_string($course->fullname));
 $PAGE->set_title(format_string($feedback->name));
 echo $OUTPUT->header();
 /// print the tabs
-include('tabs.php');
+require('tabs.php');
 /// Print the main part of the page
 echo $OUTPUT->heading(format_text($feedback->name));
 //print errormsg
-if(isset($error)) {
+if (isset($error)) {
     echo $error;
 }
-feedback_print_errors();
 $itemobj->show_editform();
 
-// echo $OUTPUT->box_end();
-
 if ($typ!='label') {
     $PAGE->requires->js('/mod/feedback/feedback.js');
     $PAGE->requires->js_function_call('set_item_focus', Array('id_itemname'));
@@ -136,4 +148,3 @@ if ($typ!='label') {
 ///////////////////////////////////////////////////////////////////////////
 
 echo $OUTPUT->footer();
-
index 2e50327..705db01 100644 (file)
 <?php
-
-    /**
-     * prints the form to export the items as xml-file
-     *
-     * @author Andreas Grabs
-     * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-     * @package feedback
-     */
-
-    require_once("../../config.php");
-    require_once("lib.php");
-
-    // get parameters
-    $id = required_param('id', PARAM_INT);
-    $action = optional_param('action', false, PARAM_ALPHA);
-
-    $url = new moodle_url('/mod/feedback/export.php', array('id'=>$id));
-    if ($action !== false) {
-        $url->param('action', $action);
-    }
-    $PAGE->set_url($url);
-
-    if (! $cm = get_coursemodule_from_id('feedback', $id)) {
-        print_error('invalidcoursemodule');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * prints the form to export the items as xml-file
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
+
+require_once("../../config.php");
+require_once("lib.php");
+
+// get parameters
+$id = required_param('id', PARAM_INT);
+$action = optional_param('action', false, PARAM_ALPHA);
+
+$url = new moodle_url('/mod/feedback/export.php', array('id'=>$id));
+if ($action !== false) {
+    $url->param('action', $action);
+}
+$PAGE->set_url($url);
+
+if (! $cm = get_coursemodule_from_id('feedback', $id)) {
+    print_error('invalidcoursemodule');
+}
+
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
+    print_error('coursemisconf');
+}
+
+if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+        print_error('badcontext');
+}
+
+require_login($course->id, true, $cm);
+
+require_capability('mod/feedback:edititems', $context);
+
+if ($action == 'exportfile') {
+    if (!$exportdata = feedback_get_xml_data($feedback->id)) {
+        print_error('nodata');
     }
+    @feedback_send_xml_data($exportdata, 'feedback_'.$feedback->id.'.xml');
+    exit;
+}
 
-    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-        print_error('coursemisconf');
-    }
+redirect('view.php?id='.$id);
+exit;
 
-    if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
-        print_error('invalidcoursemodule');
-    }
+function feedback_get_xml_data($feedbackid) {
+    global $DB;
 
-    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
-            print_error('badcontext');
+    $space = '     ';
+    //get all items of the feedback
+    if (!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
+        return false;
     }
 
-    require_login($course->id, true, $cm);
-
-    require_capability('mod/feedback:edititems', $context);
-
-    if ($action == 'exportfile') {
-        if(!$exportdata = feedback_get_xml_data($feedback->id)) {
-            print_error('nodata');
-        }
-        @feedback_send_xml_data($exportdata, 'feedback_'.$feedback->id.'.xml');
-        exit;
+    //writing the header of the xml file including the charset of the currrent used language
+    $data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
+    $data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n";
+    $data .= $space.'<ITEMS>'."\n";
+
+    //writing all the items
+    foreach ($items as $item) {
+        //start of item
+        $data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
+
+        //start of itemid
+        $data .= $space.$space.$space.'<ITEMID>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->id;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of itemid
+        $data .= $space.$space.$space.'</ITEMID>'."\n";
+
+        //start of itemtext
+        $data .= $space.$space.$space.'<ITEMTEXT>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->name;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of itemtext
+        $data .= $space.$space.$space.'</ITEMTEXT>'."\n";
+
+        //start of itemtext
+        $data .= $space.$space.$space.'<ITEMLABEL>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->label;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of itemtext
+        $data .= $space.$space.$space.'</ITEMLABEL>'."\n";
+
+        //start of presentation
+        $data .= $space.$space.$space.'<PRESENTATION>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->presentation;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of presentation
+        $data .= $space.$space.$space.'</PRESENTATION>'."\n";
+
+        //start of options
+        $data .= $space.$space.$space.'<OPTIONS>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->options;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of options
+        $data .= $space.$space.$space.'</OPTIONS>'."\n";
+
+        //start of dependitem
+        $data .= $space.$space.$space.'<DEPENDITEM>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->dependitem;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of dependitem
+        $data .= $space.$space.$space.'</DEPENDITEM>'."\n";
+
+        //start of dependvalue
+        $data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
+        //start of CDATA
+        $data .= $space.$space.$space.$space.'<![CDATA[';
+        $data .= $item->dependvalue;
+        //end of CDATA
+        $data .= ']]>'."\n";
+        //end of dependvalue
+        $data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
+
+        //end of item
+        $data .= $space.$space.'</ITEM>'."\n";
     }
 
-    redirect('view.php?id='.$id);
-    exit;
+    //writing the footer of the xml file
+    $data .= $space.'</ITEMS>'."\n";
+    $data .= '</FEEDBACK>'."\n";
 
-    function feedback_get_xml_data($feedbackid) {
-        global $DB;
-
-        $space = '     ';
-        //get all items of the feedback
-        if(!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
-            return false;
-        }
-
-        //writing the header of the xml file including the charset of the currrent used language
-        $data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
-        $data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n";
-        $data .= $space.'<ITEMS>'."\n";
-
-        //writing all the items
-        foreach($items as $item) {
-            //start of item
-            $data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
-
-            //start of itemid
-            $data .= $space.$space.$space.'<ITEMID>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->id;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of itemid
-            $data .= $space.$space.$space.'</ITEMID>'."\n";
-
-            //start of itemtext
-            $data .= $space.$space.$space.'<ITEMTEXT>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->name;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of itemtext
-            $data .= $space.$space.$space.'</ITEMTEXT>'."\n";
-
-            //start of itemtext
-            $data .= $space.$space.$space.'<ITEMLABEL>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->label;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of itemtext
-            $data .= $space.$space.$space.'</ITEMLABEL>'."\n";
-
-            //start of presentation
-            $data .= $space.$space.$space.'<PRESENTATION>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->presentation;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of presentation
-            $data .= $space.$space.$space.'</PRESENTATION>'."\n";
-
-            //start of options
-            $data .= $space.$space.$space.'<OPTIONS>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->options;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of options
-            $data .= $space.$space.$space.'</OPTIONS>'."\n";
-
-            //start of dependitem
-            $data .= $space.$space.$space.'<DEPENDITEM>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->dependitem;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of dependitem
-            $data .= $space.$space.$space.'</DEPENDITEM>'."\n";
-
-            //start of dependvalue
-            $data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
-            //start of CDATA
-            $data .= $space.$space.$space.$space.'<![CDATA[';
-            $data .= $item->dependvalue;
-            //end of CDATA
-            $data .= ']]>'."\n";
-            //end of dependvalue
-            $data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
-
-            //end of item
-            $data .= $space.$space.'</ITEM>'."\n";
-        }
-
-        //writing the footer of the xml file
-        $data .= $space.'</ITEMS>'."\n";
-        $data .= '</FEEDBACK>'."\n";
-
-        return $data;
-    }
+    return $data;
+}
 
-    function feedback_send_xml_data($data, $filename) {
-        @header('Content-Type: application/xml; charset=UTF-8');
-        @header('Content-Disposition: attachment; filename='.$filename);
-        print($data);
-    }
+function feedback_send_xml_data($data, $filename) {
+    @header('Content-Type: application/xml; charset=UTF-8');
+    @header('Content-Disposition: attachment; filename='.$filename);
+    print($data);
+}
index 73cd145..e8a1c20 100644 (file)
@@ -1,4 +1,18 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * prints the form to import items from xml-file
  * @package feedback
  */
 
-    require_once("../../config.php");
-    require_once("lib.php");
-    require_once('import_form.php');
-
-    // get parameters
-    $id = required_param('id', PARAM_INT);
-    $choosefile = optional_param('choosefile', false, PARAM_PATH);
-    $action = optional_param('action', false, PARAM_ALPHA);
-
-    $url = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
-    if ($choosefile !== false) {
-        $url->param('choosefile', $choosefile);
-    }
-    if ($action !== false) {
-        $url->param('action', $action);
-    }
-    $PAGE->set_url($url);
-
-    if (! $cm = get_coursemodule_from_id('feedback', $id)) {
-        print_error('invalidcoursemodule');
+require_once("../../config.php");
+require_once("lib.php");
+require_once('import_form.php');
+
+// get parameters
+$id = required_param('id', PARAM_INT);
+$choosefile = optional_param('choosefile', false, PARAM_PATH);
+$action = optional_param('action', false, PARAM_ALPHA);
+
+$url = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
+if ($choosefile !== false) {
+    $url->param('choosefile', $choosefile);
+}
+if ($action !== false) {
+    $url->param('action', $action);
+}
+$PAGE->set_url($url);
+
+if (! $cm = get_coursemodule_from_id('feedback', $id)) {
+    print_error('invalidcoursemodule');
+}
+
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
+    print_error('coursemisconf');
+}
+
+if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+    print_error('badcontext');
+}
+
+require_login($course->id, true, $cm);
+
+require_capability('mod/feedback:edititems', $context);
+
+$mform = new feedback_import_form();
+$newformdata = array('id'=>$id,
+                    'deleteolditems'=>'1',
+                    'action'=>'choosefile',
+                    'confirmadd'=>'1',
+                    'do_show'=>'templates');
+$mform->set_data($newformdata);
+$formdata = $mform->get_data();
+
+if ($mform->is_cancelled()) {
+    redirect('edit.php?id='.$id.'&do_show=templates');
+}
+
+// process if we are happy file is ok
+if ($choosefile) {
+    $xmlcontent = $mform->get_file_content('choosefile');
+
+    if (!$xmldata = feedback_load_xml_data($xmlcontent)) {
+        print_error('cannotloadxml', 'feedback', 'edit.php?id='.$id);
     }
 
-    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-        print_error('coursemisconf');
+    $importerror = feedback_import_loaded_data($xmldata, $feedback->id);
+    if ($importerror->stat == true) {
+        $url = 'edit.php?id='.$id.'&do_show=templates';
+        redirect($url, get_string('import_successfully', 'feedback'), 3);
+        exit;
     }
+}
 
-    if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
-        print_error('invalidcoursemodule');
-    }
 
-    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
-        print_error('badcontext');
-    }
+/// Print the page header
+$strfeedbacks = get_string("modulenameplural", "feedback");
+$strfeedback  = get_string("modulename", "feedback");
 
-    require_login($course->id, true, $cm);
+$PAGE->set_heading(format_string($course->fullname));
+$PAGE->set_title(format_string($feedback->name));
+echo $OUTPUT->header();
 
-    require_capability('mod/feedback:edititems', $context);
+/// print the tabs
+require('tabs.php');
 
-    $mform = new feedback_import_form();
-    $newformdata = array('id'=>$id,
-                        'deleteolditems'=>'1',
-                        'action'=>'choosefile',
-                        'confirmadd'=>'1',
-                        'do_show'=>'templates');
-    $mform->set_data($newformdata);
-    $formdata = $mform->get_data();
+/// Print the main part of the page
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+echo $OUTPUT->heading(get_string('import_questions', 'feedback'));
 
-    if ($mform->is_cancelled()) {
-        redirect('edit.php?id='.$id.'&do_show=templates');
+if (isset($importerror->msg) AND is_array($importerror->msg)) {
+    echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter');
+    foreach ($importerror->msg as $msg) {
+        echo $msg.'<br />';
     }
+    echo $OUTPUT->box_end();
+}
 
+$mform->display();
 
-    // unset($filename);
-    // if ($action == 'choosefile' AND confirm_sesskey() ) {
-
-        ////file checks out ok
-        // $fileisgood = false;
+echo $OUTPUT->footer();
 
-        ////work out if this is an uploaded file
-        ////or one from the filesarea.
-        // if ($choosefile) {
-            // $filename = "{$CFG->dataroot}/{$course->id}/{$choosefile}";
-        // }
-    // }
+function feedback_load_xml_data($xmlcontent) {
+    global $CFG;
+    require_once($CFG->dirroot.'/lib/xmlize.php');
 
-    // process if we are happy file is ok
-    if ($choosefile) {
-        $xmlcontent = $mform->get_file_content('choosefile');
-
-        if(!$xmldata = feedback_load_xml_data($xmlcontent)) {
-            print_error('cannotloadxml', 'feedback', 'edit.php?id='.$id);
-        }
-
-        $importerror = feedback_import_loaded_data($xmldata, $feedback->id);
-        if($importerror->stat == true) {
-            redirect('edit.php?id='.$id.'&do_show=templates', get_string('import_successfully', 'feedback'), 3);
-            exit;
-        }
+    if (!$xmlcontent = feedback_check_xml_utf8($xmlcontent)) {
+        return false;
     }
 
+    $data = xmlize($xmlcontent, 1, 'UTF-8');
 
-    /// Print the page header
-    $strfeedbacks = get_string("modulenameplural", "feedback");
-    $strfeedback  = get_string("modulename", "feedback");
-
-    $PAGE->set_heading(format_string($course->fullname));
-    $PAGE->set_title(format_string($feedback->name));
-    echo $OUTPUT->header();
-
-    /// print the tabs
-    include('tabs.php');
-
-    /// Print the main part of the page
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-    echo $OUTPUT->heading(get_string('import_questions','feedback'));
-
-    if(isset($importerror->msg) AND is_array($importerror->msg)) {
-        echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter');
-        foreach($importerror->msg as $msg) {
-            echo $msg.'<br />';
-        }
-        echo $OUTPUT->box_end();
+    if (intval($data['FEEDBACK']['@']['VERSION']) != 200701) {
+        return false;
     }
+    $data = $data['FEEDBACK']['#']['ITEMS'][0]['#']['ITEM'];
+    return $data;
+}
 
-    $mform->display();
+function feedback_import_loaded_data(&$data, $feedbackid) {
+    global $CFG, $DB;
 
-    // echo $OUTPUT->container_start('mdl-align');
-    // echo $OUTPUT->single_button(new moodle_url('edit.php', array('id'=>$id, 'do_show'=>'templates')), get_string('cancel'));
-    // echo $OUTPUT->container_end();
-    echo $OUTPUT->footer();
+    feedback_load_feedback_items();
 
-    function feedback_load_xml_data($xmlcontent) {
-        global $CFG;
-        require_once($CFG->dirroot.'/lib/xmlize.php');
+    $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
 
-        if(!$xmlcontent = feedback_check_xml_utf8($xmlcontent)) return false;
+    $error = new stdClass();
+    $error->stat = true;
+    $error->msg = array();
 
-        $data = xmlize($xmlcontent, 1, 'UTF-8');
-
-        if(intval($data['FEEDBACK']['@']['VERSION']) != 200701) {
-            return false;
-        }
-        $data = $data['FEEDBACK']['#']['ITEMS'][0]['#']['ITEM'];
-        return $data;
+    if (!is_array($data)) {
+        $error->msg[] = get_string('data_is_not_an_array', 'feedback');
+        $error->stat = false;
+        return $error;
     }
 
-    function feedback_import_loaded_data(&$data, $feedbackid){
-        global $CFG, $DB;
-
-        feedback_load_feedback_items();
-
-        $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
+    if ($deleteolditems) {
+        feedback_delete_all_items($feedbackid);
+        $position = 0;
+    } else {
+        //items will be add to the end of the existing items
+        $position = $DB->count_records('feedback_item', array('feedback'=>$feedbackid));
+    }
 
-        $error = new stdClass();
-        $error->stat = true;
-        $error->msg = array();
+    //depend items we are storing temporary in an mapping list array(new id => dependitem)
+    //we also store a mapping of all items array(oldid => newid)
+    $dependitemsmap = array();
+    $itembackup = array();
+    foreach ($data as $item) {
+        $position++;
+        //check the typ
+        $typ = $item['@']['TYPE'];
+
+        //check oldtypes first
+        switch($typ) {
+            case 'radio':
+                $typ = 'multichoice';
+                $oldtyp = 'radio';
+                break;
+            case 'dropdown':
+                $typ = 'multichoice';
+                $oldtyp = 'dropdown';
+                break;
+            case 'check':
+                $typ = 'multichoice';
+                $oldtyp = 'check';
+                break;
+            case 'radiorated':
+                $typ = 'multichoicerated';
+                $oldtyp = 'radiorated';
+                break;
+            case 'dropdownrated':
+                $typ = 'multichoicerated';
+                $oldtyp = 'dropdownrated';
+                break;
+            default:
+                $oldtyp = $typ;
+        }
 
-        if(!is_array($data)) {
-            $error->msg[] = get_string('data_is_not_an_array', 'feedback');
+        $itemclass = 'feedback_item_'.$typ;
+        if ($typ != 'pagebreak' AND !class_exists($itemclass)) {
             $error->stat = false;
-            return $error;
+            $error->msg[] = 'type ('.$typ.') not found';
+            continue;
+        }
+        $itemobj = new $itemclass();
+
+        $newitem = new stdClass();
+        $newitem->feedback = $feedbackid;
+        $newitem->template = 0;
+        $newitem->typ = $typ;
+        $newitem->name = trim($item['#']['ITEMTEXT'][0]['#']);
+        $newitem->label = trim($item['#']['ITEMLABEL'][0]['#']);
+        $newitem->options = trim($item['#']['OPTIONS'][0]['#']);
+        $newitem->presentation = trim($item['#']['PRESENTATION'][0]['#']);
+        //check old types of radio, check, and so on
+        switch($oldtyp) {
+            case 'radio':
+                $newitem->presentation = 'r>>>>>'.$newitem->presentation;
+                break;
+            case 'dropdown':
+                $newitem->presentation = 'd>>>>>'.$newitem->presentation;
+                break;
+            case 'check':
+                $newitem->presentation = 'c>>>>>'.$newitem->presentation;
+                break;
+            case 'radiorated':
+                $newitem->presentation = 'r>>>>>'.$newitem->presentation;
+                break;
+            case 'dropdownrated':
+                $newitem->presentation = 'd>>>>>'.$newitem->presentation;
+                break;
         }
 
-        if($deleteolditems) {
-            feedback_delete_all_items($feedbackid);
-            $position = 0;
+        if (isset($item['#']['DEPENDITEM'][0]['#'])) {
+            $newitem->dependitem = intval($item['#']['DEPENDITEM'][0]['#']);
         } else {
-            //items will be add to the end of the existing items
-            $position = $DB->count_records('feedback_item', array('feedback'=>$feedbackid));
+            $newitem->dependitem = 0;
         }
+        if (isset($item['#']['DEPENDVALUE'][0]['#'])) {
+            $newitem->dependvalue = trim($item['#']['DEPENDVALUE'][0]['#']);
+        } else {
+            $newitem->dependvalue = '';
+        }
+        $olditemid = intval($item['#']['ITEMID'][0]['#']);
 
-        //depend items we are storing temporary in an mapping list array(new id => dependitem)
-        //we also store a mapping of all items array(oldid => newid)
-        $dependitemsmap = array();
-        $itembackup = array();
-        foreach($data as $item) {
-            $position++;
-            //check the typ
-            $typ = $item['@']['TYPE'];
-
-            //check oldtypes first
-            switch($typ) {
-                case 'radio':
-                    $typ = 'multichoice';
-                    $oldtyp = 'radio';
-                    break;
-                case 'dropdown':
-                    $typ = 'multichoice';
-                    $oldtyp = 'dropdown';
-                    break;
-                case 'check':
-                    $typ = 'multichoice';
-                    $oldtyp = 'check';
-                    break;
-                case 'radiorated':
-                    $typ = 'multichoicerated';
-                    $oldtyp = 'radiorated';
-                    break;
-                case 'dropdownrated':
-                    $typ = 'multichoicerated';
-                    $oldtyp = 'dropdownrated';
-                    break;
-                default:
-                    $oldtyp = $typ;
-            }
-
-            $itemclass = 'feedback_item_'.$typ;
-            if($typ != 'pagebreak' AND !class_exists($itemclass)) {
-                $error->stat = false;
-                $error->msg[] = 'type ('.$typ.') not found';
-                continue;
-            }
-            $itemobj = new $itemclass();
-
-            $newitem = new stdClass();
-            $newitem->feedback = $feedbackid;
-            $newitem->template = 0;
-            $newitem->typ = $typ;
-            $newitem->name = trim($item['#']['ITEMTEXT'][0]['#']);
-            $newitem->label = trim($item['#']['ITEMLABEL'][0]['#']);
-            $newitem->options = trim($item['#']['OPTIONS'][0]['#']);
-            $newitem->presentation = trim($item['#']['PRESENTATION'][0]['#']);
-            //check old types of radio, check, and so on
-            switch($oldtyp) {
-                case 'radio':
-                    $newitem->presentation = 'r>>>>>'.$newitem->presentation;
-                    break;
-                case 'dropdown':
-                    $newitem->presentation = 'd>>>>>'.$newitem->presentation;
-                    break;
-                case 'check':
-                    $newitem->presentation = 'c>>>>>'.$newitem->presentation;
-                    break;
-                case 'radiorated':
-                    $newitem->presentation = 'r>>>>>'.$newitem->presentation;
-                    break;
-                case 'dropdownrated':
-                    $newitem->presentation = 'd>>>>>'.$newitem->presentation;
-                    break;
-            }
-
-            if(isset($item['#']['DEPENDITEM'][0]['#'])) {
-                $newitem->dependitem = intval($item['#']['DEPENDITEM'][0]['#']);
-            }else {
-                $newitem->dependitem = 0;
-            }
-            if(isset($item['#']['DEPENDVALUE'][0]['#'])) {
-                $newitem->dependvalue = trim($item['#']['DEPENDVALUE'][0]['#']);
-            }else {
-                $newitem->dependvalue = '';
-            }
-            $olditemid = intval($item['#']['ITEMID'][0]['#']);
-
-            if($typ != 'pagebreak') {
-                $newitem->hasvalue = $itemobj->get_hasvalue();
-            }else {
-                $newitem->hasvalue = 0;
-            }
-            $newitem->required = intval($item['@']['REQUIRED']);
-            $newitem->position = $position;
-            $newid = $DB->insert_record('feedback_item', $newitem);
-
-            $itembackup[$olditemid] = $newid;
-            if($newitem->dependitem) {
-                $dependitemsmap[$newid] = $newitem->dependitem;
-            }
-
+        if ($typ != 'pagebreak') {
+            $newitem->hasvalue = $itemobj->get_hasvalue();
+        } else {
+            $newitem->hasvalue = 0;
         }
-        //remapping the dependency
-        foreach($dependitemsmap as $key => $dependitem) {
-            $newitem = $DB->get_record('feedback_item', array('id'=>$key));
-            $newitem->dependitem = $itembackup[$newitem->dependitem];
-            $DB->update_record('feedback_item', $newitem);
+        $newitem->required = intval($item['@']['REQUIRED']);
+        $newitem->position = $position;
+        $newid = $DB->insert_record('feedback_item', $newitem);
+
+        $itembackup[$olditemid] = $newid;
+        if ($newitem->dependitem) {
+            $dependitemsmap[$newid] = $newitem->dependitem;
         }
 
-        return $error;
+    }
+    //remapping the dependency
+    foreach ($dependitemsmap as $key => $dependitem) {
+        $newitem = $DB->get_record('feedback_item', array('id'=>$key));
+        $newitem->dependitem = $itembackup[$newitem->dependitem];
+        $DB->update_record('feedback_item', $newitem);
     }
 
-    function feedback_check_xml_utf8($text) {
-        //find the encoding
-        $searchpattern = '/^\<\?xml.+(encoding=\"([a-z0-9-]*)\").+\?\>/is';
+    return $error;
+}
 
-        if(!preg_match($searchpattern, $text, $match)) return false; //no xml-file
+function feedback_check_xml_utf8($text) {
+    //find the encoding
+    $searchpattern = '/^\<\?xml.+(encoding=\"([a-z0-9-]*)\").+\?\>/is';
 
-        //$match[0] = \<\? xml ... \?\> (without \)
-        //$match[1] = encoding="...."
-        //$match[2] = ISO-8859-1 or so on
-        if(isset($match[0]) AND !isset($match[1])){ //no encoding given. we assume utf-8
-            return $text;
-        }
+    if (!preg_match($searchpattern, $text, $match)) {
+        return false; //no xml-file
+    }
 
-        if(isset($match[0]) AND isset($match[1]) AND isset($match[2])) { //encoding is given in $match[2]
-            $enc = $match[2];
-            $textlib = textlib_get_instance();
-            return $textlib->convert($text, $enc);
-        }
+    //$match[0] = \<\? xml ... \?\> (without \)
+    //$match[1] = encoding="...."
+    //$match[2] = ISO-8859-1 or so on
+    if (isset($match[0]) AND !isset($match[1])) { //no encoding given. we assume utf-8
+        return $text;
+    }
+
+    //encoding is given in $match[2]
+    if (isset($match[0]) AND isset($match[1]) AND isset($match[2])) {
+        $enc = $match[2];
+        $textlib = textlib_get_instance();
+        return $textlib->convert($text, $enc);
     }
+}
index 1b2e4e8..97d4ef0 100644 (file)
@@ -1,28 +1,47 @@
 <?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
 /**
-* prints the forms to choose an xml-template file to import items
-*
-* @author Andreas Grabs
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package feedback
-*/
+ * prints the forms to choose an xml-template file to import items
+ *
+ * @author Andreas Grabs
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package feedback
+ */
 
+//It must be included from a Moodle page
 if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    die('Direct access to this script is forbidden.');
 }
 
-require_once $CFG->libdir.'/formslib.php';
+require_once($CFG->libdir.'/formslib.php');
 
 class feedback_import_form extends moodleform {
-    function definition() {
+    public function definition() {
         global $CFG;</