]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11050 grade export must use formslib properly - no data_submitted()!
authorskodak <skodak>
Wed, 29 Aug 2007 12:38:23 +0000 (12:38 +0000)
committerskodak <skodak>
Wed, 29 Aug 2007 12:38:23 +0000 (12:38 +0000)
grade/export/grade_export_form.php
grade/export/lib.php
grade/export/ods/index.php
grade/export/txt/grade_export_txt_form.php
grade/export/txt/index.php
grade/export/xls/index.php
grade/export/xml/index.php

index c85fed32ba5e33bf4a283a3f7e71af4f0facfd9c..eea55bd678e45498445fa959a20e8828e9cde419 100755 (executable)
@@ -6,7 +6,7 @@ class grade_export_form extends moodleform {
         global $CFG, $COURSE, $USER;
 
         $mform =& $this->_form;
-        if (isset($this->_customdata['plugin'])) {
+        if (isset($this->_customdata['plugin'])) {  // hardcoding plugin names here is hacky
             $plugin = $this->_customdata['plugin'];
         } else {
             $plugin = 'unknown';
@@ -44,18 +44,17 @@ class grade_export_form extends moodleform {
 
         $mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
 
-        $id = $this->_customdata['id']; // course id
-        $mform->addElement('hidden', 'id', $id);
-        if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) {
+        $mform->addElement('hidden', 'id', $COURSE->id);
+        if ($grade_items = grade_item::fetch_all(array('courseid'=>$COURSE->id))) {
             $noidnumber = false;
             foreach ($grade_items as $grade_item) {
 
                 if ($plugin != 'xmlexport' || $grade_item->idnumber) {
-                    $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
+                    $element = new HTML_QuickForm_advcheckbox('itemids['.$grade_item->id.']', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
                     $element->setChecked(1);
                 } else {
                     $noidnumber = true;
-                    $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id));
+                    $element = new HTML_QuickForm_advcheckbox('itemids['.$grade_item->id.']', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id));
                 }
 
                 $mform->addElement($element);
index 082854e3c60ac9c15913df9658913d8475395cc0..c159ddfa0a24fe7916ce5625c7626a68755a6ffe 100755 (executable)
 
 require_once($CFG->dirroot.'/lib/gradelib.php');
 require_once($CFG->dirroot.'/grade/lib.php');
+require_once($CFG->dirroot.'/grade/export/grade_export_form.php');
 
-/**
- * Prints all grade items for selection
- * @input int id - course id
- */
-function print_gradeitem_selections($id, $params = array()) {
-    global $CFG;
-    // print all items for selections
-    // make this a standard function in lib maybe
-    include_once('grade_export_form.php');
-    $mform = new grade_export_form(qualified_me(), array('id'=>$id)+$params);
-    $mform->display();
-
-}
 /**
  * Base export class
  */
index 86edb81be4ea23324538b6438b572ad5ae723ac9..935f15aa75478789c2af10fdf254b8a6edba37ce 100755 (executable)
@@ -47,13 +47,16 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
 
 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
 print_grade_plugin_selector($id, 'export', 'ods');
-// process post information
-if (($data = data_submitted()) && confirm_sesskey()) {
 
-    if (!is_array($data->itemids)) {
-        $itemidsurl = $data->itemids;
-    } else {
+$mform = new grade_export_form();
+
+// process post information
+if ($data = $mform->get_data()) {
+    if ($data->itemids) {
         $itemidsurl = implode(",",$data->itemids);
+    } else {
+        //error?
+        $itemidsurl = '';
     }
 
     // print the grades on screen for feedbacks
@@ -66,6 +69,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
     exit;
 }
 
-print_gradeitem_selections($id);
+$mform->display();
+
 print_footer();
 ?>
index fe123261c082f73d96091427a909de50a12e8790..a035ac639d1eb6841e2f50a527d0735ef5839ea9 100755 (executable)
@@ -3,7 +3,8 @@ require_once $CFG->libdir.'/formslib.php';
 
 class grade_export_txt_form extends moodleform {
     function definition (){
-        global $CFG;
+        global $CFG, $COURSE;
+
         include_once($CFG->libdir.'/pear/HTML/QuickForm/advcheckbox.php');
         $mform =& $this->_form;
 
@@ -13,11 +14,10 @@ class grade_export_txt_form extends moodleform {
                           false, true, false, get_string("exportlettershelp", 'grades')));
 
         $mform->addElement('header', 'general', 'Gradeitems to be included'); // TODO: localize
-        $id = $this->_customdata['id']; // course id
-        $mform->addElement('hidden', 'id', $id);
-        if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) {
+        $mform->addElement('hidden', 'id', $COURSE->id);
+        if ($grade_items = grade_item::fetch_all(array('courseid'=>$COURSE->id))) {
             foreach ($grade_items as $grade_item) {
-                $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
+                $element = new HTML_QuickForm_advcheckbox('itemids['.$grade_item->id.']', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
                 $element->setChecked(1);
                 $mform->addElement($element);
             }
index 878fc86c933528d94f0910a260c3da9930d0274a..84603cb56e4575e571406707b8e346f595d03f55 100755 (executable)
@@ -26,6 +26,7 @@
 require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/export/lib.php';
 require_once 'grade_export_txt.php';
+require_once 'grade_export_txt_form.php';
 
 $id       = required_param('id', PARAM_INT); // course id
 $feedback = optional_param('feedback', '', PARAM_ALPHA);
@@ -47,14 +48,16 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
 
 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
 print_grade_plugin_selector($id, 'export', 'txt');
-// process post information
-if (($data = data_submitted()) && confirm_sesskey()) {
 
-    // $itemids consists of ints and ",", will be cleaned in the main export class
-    if (!is_array($data->itemids)) {
-        $itemidsurl = $data->itemids;
-    } else {
+$mform = new grade_export_txt_form();
+
+// process post information
+if ($data = $mform->get_data()) {
+    if ($data->itemids) {
         $itemidsurl = implode(",",$data->itemids);
+    } else {
+        //error?
+        $itemidsurl = '';
     }
 
     $export = new grade_export($id, $data->itemids, $data->export_letters);
@@ -66,8 +69,6 @@ if (($data = data_submitted()) && confirm_sesskey()) {
 }
 
 // print the form to choose what grade_items to export
-include_once('grade_export_txt_form.php');
-$mform = new grade_export_txt_form(qualified_me(), array('id'=>$id));
 $mform->display();
 
 print_footer();
index 356ca769796af84034b1942c561a5ff3f8e5ffa6..ccad791facb0820a393128db4064c799be5081a7 100755 (executable)
@@ -47,13 +47,16 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
 
 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
 print_grade_plugin_selector($id, 'export', 'xls');
-// process post information
-if (($data = data_submitted()) && confirm_sesskey()) {
 
-    if (!is_array($data->itemids)) {
-        $itemidsurl = $data->itemids;
-    } else {
+$mform = new grade_export_form();
+
+// process post information
+if ($data = $mform->get_data()) {
+    if ($data->itemids) {
         $itemidsurl = implode(",",$data->itemids);
+    } else {
+        //error?
+        $itemidsurl = '';
     }
 
     // print the grades on screen for feedbacks
@@ -66,6 +69,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
     exit;
 }
 
-print_gradeitem_selections($id);
+$mform->display();
+
 print_footer();
 ?>
index 3796b352884b9972a4d335d18240a42f3c436b2b..a1313b9e58d0aef5d4ab6b11ed3c68be68902e6c 100755 (executable)
@@ -48,13 +48,15 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
 print_grade_plugin_selector($id, 'export', 'xml');
 
-// process post information
-if (($data = data_submitted()) && confirm_sesskey()) {
+$mform = new grade_export_form(null, array('plugin'=>'xmlexport'));
 
-    if (!is_array($data->itemids)) {
-        $itemidsurl = $data->itemids;
-    } else {
+// process post information
+if ($data = $mform->get_data()) {
+    if ($data->itemids) {
         $itemidsurl = implode(",",$data->itemids);
+    } else {
+        //error?
+        $itemidsurl = '';
     }
 
     // print the grades on screen for feedbacks
@@ -68,12 +70,16 @@ if (($data = data_submitted()) && confirm_sesskey()) {
         print_continue('export.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;export_letters='.$data->export_letters);
 
     } else {
+        if ($data->key == 1) {
+            $data->key = create_user_key('grade/export', $USER->id, $COURSE->id, $data->iprestriction, $data->validuntil);
+        }
         $link = $CFG->wwwroot.'/grade/export/xml/dump.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;export_letters='.$data->export_letters.'&amp;key='.$data->key;
         echo "<a href=\"$link\">$link</a>";
     }
     exit;
 }
 
-print_gradeitem_selections($id, array('plugin'=>'xmlexport'));
+$mform->display();
+
 print_footer();
 ?>