]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7861, adding new xhtml compatible import forms
authortoyomoyo <toyomoyo>
Wed, 20 Dec 2006 08:05:26 +0000 (08:05 +0000)
committertoyomoyo <toyomoyo>
Wed, 20 Dec 2006 08:05:26 +0000 (08:05 +0000)
course/import/activities/import_form.php [new file with mode: 0755]
course/import/activities/index.php
course/import/activities/mod.php
course/import/groups/import_form.php [new file with mode: 0755]
course/import/groups/mod.php

diff --git a/course/import/activities/import_form.php b/course/import/activities/import_form.php
new file mode 100755 (executable)
index 0000000..11eca53
--- /dev/null
@@ -0,0 +1,60 @@
+<?php  // $Id$
+
+require_once($CFG->libdir.'/formslib.php');
+
+class activities_import_form_1 extends moodleform {
+
+       function definition() {
+
+               global $CFG;
+               $mform    =& $this->_form;
+               $text = $this->_customdata['text'];
+               $options = $this->_customdata['options'];
+        $courseid = $this->_customdata['courseid'];
+        $mform->addElement('header', 'general', '');//fill in the data depending on page params
+                                                    //later using set_defaults
+               $mform->addElement('select', 'fromcourse', $text, $options);
+         
+        // buttons
+        $submit_string = get_string('usethiscourse');
+        $this->add_action_buttons(false, true, $submit_string);
+        
+        $mform->addElement('hidden', 'id');
+               $mform->setType('id', PARAM_INT);
+               $mform->setConstants(array('id'=> $courseid));
+
+       }
+
+       function validation($data) {
+        return true;
+       }
+
+}
+
+class activities_import_form_2 extends moodleform {
+
+       function definition() {
+
+               global $CFG;
+               $mform    =& $this->_form;
+               $courseid = $this->_customdata['courseid'];        
+
+        $mform->addElement('header', 'general', '');//fill in the data depending on page params
+                                                    //later using set_defaults
+               $mform->addElement('text', 'fromcoursesearch', get_string('searchcourses'));
+         
+        // buttons
+        $this->add_action_buttons(false, true, get_string('searchcourses'));
+        
+        $mform->addElement('hidden', 'id');
+               $mform->setType('id', PARAM_INT);
+               $mform->setConstants(array('id'=> $courseid));
+
+       }
+
+       function validation($data) {
+        return true;
+       }
+
+}
+?>
index 5bae0f15059b45dd3116ce45ec0f1fc06732dd6a..4c312d863ee8bcbf2dbc552fde00e464e46901f9 100644 (file)
@@ -22,7 +22,9 @@
 
     require_login($course->id);
     $tocontext = get_context_instance(CONTEXT_COURSE, $id);
-    $fromcontext = get_context_instance(CONTEXT_COURSE, $fromcourse);
+    if ($fromcourse) {
+        $fromcontext = get_context_instance(CONTEXT_COURSE, $fromcourse);
+    }
     $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
 
     if (!has_capability('moodle/course:manageactivities', $tocontext)) {
index 3230200722aa356421c83ae5f5f5197941a2577e..69eeb7d11b649cb59528c059c16e2a8b73d0d2ef 100644 (file)
         notify(get_string('courseimportnotaught'));
         return; // yay , this will pass control back to the file that included or required us.
     }
-
-    $fm = '<form method="post" action="'.$CFG->wwwroot.'/course/import/activities/index.php"><input type="hidden" name="id" value="'.$course->id.'" />';
-    $submit = '<input type="submit" value="'.get_string('usethiscourse').'" /></form>';
-
-    if (count($options) > 0) {
-        $table->data[] = array($fm.'<b>'.get_string('coursestaught').'</b>',
-                               choose_from_menu($options,"fromcourse","","choose","","0",true),
-                               $submit);
-    }
-
-    unset($options);
-
+    
+    // quick forms
+    include_once('import_form.php');
+        
+    $mform_post = new activities_import_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text'=> get_string('coursestaught')));
+    $mform_post ->display();
+    
+    unset($options); 
     $options = array();
+    
     foreach ($cat_courses as $ccourse) {
         if ($ccourse->id != $course->id && $ccourse->id != SITEID) {
             $options[$ccourse->id] = $ccourse->fullname;
         }
     }
     $cat = get_record("course_categories","id",$course->category);
-
+    
     if (count($options) > 0) {
-        $table->data[] = array($fm.'<b>'.get_string('coursescategory').' ('.$cat->name .')</b>',
-                               choose_from_menu($options,"fromcourse","","choose","","0",true),
-                               $submit);
+        $mform_post = new activities_import_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text' => get_string('coursescategory')));
+        $mform_post ->display();
     }
 
     if (!empty($creator)) {
-        $table->data[] = array($fm.'<b>'.get_string('searchcourses').'</b>',
-                               '<input type="text" name="fromcoursesearch" />',
-                               '<input type="submit" value="'.get_string('searchcourses').'" /></form>');
+        $mform_post = new activities_import_form_2($CFG->wwwroot.'/course/import/activities/index.php', array('courseid' => $course->id));
+        $mform_post ->display();     
     }
 
     if (!empty($fromcoursesearch) && !empty($creator)) {
@@ -91,8 +86,7 @@
             foreach ($courses as $scourse) {
                 if ($course->id != $scourse->id) {
                     $table->data[] = array('',$scourse->fullname,
-                                           '<a href="'.$CFG->wwwroot.'/course/import/activities/index.php?id='.$course->id.'&fromcourse='.$scourse->id.'">'
-                                           .get_string('usethiscourse'));
+                                           '<a href="'.$CFG->wwwroot.'/course/import/activities/index.php?id='.$course->id.'&amp;fromcourse='.$scourse->id.'">'.get_string('usethiscourse').'</a>');
                 }
             }
         }
             $table->data[] = array('',get_string('noresults'),'');
         }
     }
-
-    print_table($table);
-
+    if (!empty($table)) {
+        print_table($table);
+    }
 ?>
\ No newline at end of file
diff --git a/course/import/groups/import_form.php b/course/import/groups/import_form.php
new file mode 100755 (executable)
index 0000000..9c60703
--- /dev/null
@@ -0,0 +1,38 @@
+<?php  // $Id$
+
+require_once($CFG->libdir.'/formslib.php');
+
+class group_import_form extends moodleform {
+
+       function definition() {
+
+               global $CFG, $USER;
+               $mform    =& $this->_form;
+               $maxuploadsize = $this->_customdata['maxuploadsize'];
+               $strimportgroups = get_string("importgroups");
+               
+        $this->_upload_manager = new upload_manager('userfile', true, false, '', false, $maxuploadsize, true, true);
+        $this->set_max_file_size('', $maxuploadsize);
+      
+        $mform->addElement('header', 'general', '');//fill in the data depending on page params
+                                                    //later using set_defaults        
+        // buttons
+        
+        $mform->addElement('hidden', 'sesskey');
+               $mform->setType('sesskey', PARAM_ALPHA);
+               $mform->setConstants(array('sesskey'=> $USER->sesskey));
+               
+               $mform->addElement('file', 'userfile', '');
+        $mform->setHelpButton('userfile', array('attachment', get_string('attachment', 'forum'), 'forum'));            
+               
+               
+        $this->add_action_buttons(false, true, $strimportgroups);
+
+       }
+
+       function validation($data) {
+        return true;
+       }
+
+}
+?>
index 6e745979f207cc3ab892a58324427edefe6a74ef..ee960641ad130177107dd5126ffd8a5dcfb1e9aa 100644 (file)
     $strusers = get_string("users");
     $strusersnew = get_string("usersnew");
     $strimportgroups = get_string("importgroups");
-
     print_heading_with_help($strimportgroups, 'uploadgroups');
     $maxuploadsize = get_max_upload_file_size();
     echo '<p align="center">';
     print_simple_box_start('center','80%');
-    echo '<form method="post" enctype="multipart/form-data" action="'.$CFG->wwwroot.'/course/import/groups/index.php?id='.$id.'">'.
-         $strchoose.':<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">'.
-         '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">'.
-         '<input type="file" name="userfile" size="30">'.
-         '<input type="submit" value="'.$strimportgroups.'">'.
-         '</form></br>';
+    
+    // use formslib
+    include_once('import_form.php');
+    $mform_post = new group_import_form($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize));
+    $mform_post ->display();
+        
     print_simple_box_end();
+   
     echo '</p>';
     
 ?>