--- /dev/null
+<?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;
+ }
+
+}
+?>
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)) {
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)) {
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.'&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
--- /dev/null
+<?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;
+ }
+
+}
+?>
$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>';
?>