mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-22574, fixed outcomes import form
This commit is contained in:
parent
15dd3edbcf
commit
c46aeeab9c
@ -15,15 +15,18 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/// THIS SCRIPT IS CALLED WITH "require_once()" FROM index.php
|
require_once(dirname(__FILE__).'/../../../config.php');
|
||||||
if (!defined('MOODLE_INTERNAL')) {
|
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||||
die('Direct access to this script is forbidden.');
|
require_once($CFG->dirroot.'/grade/lib.php');
|
||||||
}
|
require_once($CFG->libdir.'/gradelib.php');
|
||||||
|
require_once('import_outcomes_form.php');
|
||||||
|
|
||||||
$courseid = optional_param('id', 0, PARAM_INT);
|
$courseid = optional_param('courseid', 0, PARAM_INT);
|
||||||
$action = optional_param('action', '', PARAM_ALPHA);
|
$action = optional_param('action', '', PARAM_ALPHA);
|
||||||
$scope = optional_param('scope', 'global', PARAM_ALPHA);
|
$scope = optional_param('scope', 'global', PARAM_ALPHA);
|
||||||
|
|
||||||
|
$PAGE->set_url('/grade/edit/outcome/import.php', array('courseid' => $courseid));
|
||||||
|
|
||||||
/// Make sure they can even access this course
|
/// Make sure they can even access this course
|
||||||
if ($courseid) {
|
if ($courseid) {
|
||||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||||
@ -46,31 +49,27 @@ require_capability('moodle/grade:manageoutcomes', $context);
|
|||||||
|
|
||||||
$navigation = grade_build_nav(__FILE__, get_string('outcomes', 'grades'), $courseid);
|
$navigation = grade_build_nav(__FILE__, get_string('outcomes', 'grades'), $courseid);
|
||||||
|
|
||||||
if (!confirm_sesskey()) {
|
$upload_form = new import_outcomes_form();
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
// display import form
|
||||||
$caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext);
|
if (!$upload_form->get_data()) {
|
||||||
|
|
||||||
if ($courseid) {
|
|
||||||
print_grade_page_head($courseid, 'outcome', 'import', get_string('importoutcomes', 'grades'));
|
print_grade_page_head($courseid, 'outcome', 'import', get_string('importoutcomes', 'grades'));
|
||||||
|
$upload_form->display();
|
||||||
$caneditcoursescales = has_capability('moodle/course:managescales', $context);
|
echo $OUTPUT->footer();
|
||||||
|
die;
|
||||||
} else {
|
|
||||||
echo $OUTPUT->header();
|
|
||||||
$caneditcoursescales = $caneditsystemscales;
|
|
||||||
}
|
}
|
||||||
|
print_grade_page_head($courseid, 'outcome', 'import', get_string('importoutcomes', 'grades'));
|
||||||
|
|
||||||
$imported_file = $upload_form->_upload_manager->files;
|
$imported_file = $CFG->dataroot . '/temp/outcomeimport/importedfile_'.time().'.csv';
|
||||||
|
make_upload_directory('temp/outcomeimport');
|
||||||
|
|
||||||
if ($imported_file['userfile']['size'] == 0) {
|
// copying imported file
|
||||||
redirect('index.php'. ($courseid ? "?id=$courseid" : ''), get_string('importfilemissing', 'grades'));
|
if (!$upload_form->save_file('userfile', $imported_file, true)) {
|
||||||
|
redirect('import.php'. ($courseid ? "?courseid=$courseid" : ''), get_string('importfilemissing', 'grades'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// which scope are we importing the outcomes in?
|
/// which scope are we importing the outcomes in?
|
||||||
if (isset($courseid) && ($scope == 'local')) {
|
if (isset($courseid) && ($scope == 'custom')) {
|
||||||
// custom scale
|
// custom scale
|
||||||
$local_scope = true;
|
$local_scope = true;
|
||||||
} elseif (($scope == 'global') && has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
} elseif (($scope == 'global') && has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
@ -82,7 +81,7 @@ if (isset($courseid) && ($scope == 'local')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// open the file, start importing data
|
// open the file, start importing data
|
||||||
if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
|
if ($handle = fopen($imported_file, 'r')) {
|
||||||
$line = 0; // will keep track of current line, to give better error messages.
|
$line = 0; // will keep track of current line, to give better error messages.
|
||||||
$file_headers = '';
|
$file_headers = '';
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
|
|||||||
if ($error) {
|
if ($error) {
|
||||||
echo $OUTPUT->box_start('generalbox importoutcomenofile buttons');
|
echo $OUTPUT->box_start('generalbox importoutcomenofile buttons');
|
||||||
echo get_string('importoutcomenofile', 'grades', $line);
|
echo get_string('importoutcomenofile', 'grades', $line);
|
||||||
echo $OUTPUT->single_button(new moodle_url('/grade/edit/outcome/index.php', array('id'=> $courseid)), get_string('back'), 'get');
|
echo $OUTPUT->single_button(new moodle_url('/grade/edit/outcome/import.php', array('courseid'=> $courseid)), get_string('back'), 'get');
|
||||||
echo $OUTPUT->box_end();
|
echo $OUTPUT->box_end();
|
||||||
$fatal_error = true;
|
$fatal_error = true;
|
||||||
break;
|
break;
|
||||||
@ -138,7 +137,7 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
|
|||||||
if ( count($csv_data) != count($file_headers) ) {
|
if ( count($csv_data) != count($file_headers) ) {
|
||||||
echo $OUTPUT->box_start('generalbox importoutcomenofile');
|
echo $OUTPUT->box_start('generalbox importoutcomenofile');
|
||||||
echo get_string('importoutcomenofile', 'grades', $line);
|
echo get_string('importoutcomenofile', 'grades', $line);
|
||||||
echo $OUTPUT->single_button(new moodle_url('/grade/edit/outcome/index.php', array('id'=> $courseid)), get_string('back'), 'get');
|
echo $OUTPUT->single_button(new moodle_url('/grade/edit/outcome/import.php', array('courseid'=> $courseid)), get_string('back'), 'get');
|
||||||
echo $OUTPUT->box_end();
|
echo $OUTPUT->box_end();
|
||||||
$fatal_error = true;
|
$fatal_error = true;
|
||||||
//echo $OUTPUT->box(var_export($csv_data, true) ."<br />". var_export($header, true));
|
//echo $OUTPUT->box(var_export($csv_data, true) ."<br />". var_export($header, true));
|
||||||
@ -150,15 +149,13 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
|
|||||||
if ($csv_data[$imported_headers[$header]] == '') {
|
if ($csv_data[$imported_headers[$header]] == '') {
|
||||||
echo $OUTPUT->box_start('generalbox importoutcomenofile');
|
echo $OUTPUT->box_start('generalbox importoutcomenofile');
|
||||||
echo get_string('importoutcomenofile', 'grades', $line);
|
echo get_string('importoutcomenofile', 'grades', $line);
|
||||||
echo $OUTPUT->single_button(new moodle_url('/grade/edit/outcome/index.php', array('id'=> $courseid)), get_string('back'), 'get');
|
echo $OUTPUT->single_button(new moodle_url('/grade/edit/outcome/import.php', array('courseid'=> $courseid)), get_string('back'), 'get');
|
||||||
echo $OUTPUT->box_end();
|
echo $OUTPUT->box_end();
|
||||||
$fatal_error = true;
|
$fatal_error = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//var_dump($csv_data);
|
|
||||||
|
|
||||||
// MDL-17273 errors in csv are not preventing import from happening. We break from the while loop here
|
// MDL-17273 errors in csv are not preventing import from happening. We break from the while loop here
|
||||||
if ($fatal_error) {
|
if ($fatal_error) {
|
||||||
break;
|
break;
|
||||||
@ -236,5 +233,7 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
|
|||||||
|
|
||||||
// finish
|
// finish
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
// delete temp file
|
||||||
|
unlink($imported_file);
|
||||||
|
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
@ -24,25 +24,25 @@ require_once($CFG->dirroot.'/lib/formslib.php');
|
|||||||
class import_outcomes_form extends moodleform {
|
class import_outcomes_form extends moodleform {
|
||||||
|
|
||||||
public function definition() {
|
public function definition() {
|
||||||
global $COURSE, $USER;
|
global $PAGE, $USER;
|
||||||
|
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
//$this->set_upload_manager(new upload_manager('importfile', false, false, null, false, 0, true, true, false));
|
|
||||||
|
|
||||||
$mform->addElement('hidden', 'action', 'upload');
|
$mform->addElement('hidden', 'action', 'upload');
|
||||||
$mform->setType('action', PARAM_ACTION);
|
$mform->setType('action', PARAM_ACTION);
|
||||||
$mform->addElement('hidden', 'id', $COURSE->id);
|
$mform->addElement('hidden', 'courseid', $PAGE->course->id);
|
||||||
$mform->setType('id', PARAM_INT);
|
$mform->setType('id', PARAM_INT);
|
||||||
|
|
||||||
$scope = array();
|
$scope = array();
|
||||||
if (($COURSE->id > 1) && has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
if (($PAGE->course->id > 1) && has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
$mform->addElement('radio', 'scope', get_string('importcustom', 'grades'), null, 'custom');
|
$mform->addElement('radio', 'scope', get_string('importcustom', 'grades'), null, 'custom');
|
||||||
$mform->addElement('radio', 'scope', get_string('importstandard', 'grades'), null, 'global');
|
$mform->addElement('radio', 'scope', get_string('importstandard', 'grades'), null, 'global');
|
||||||
$mform->setDefault('scope', 'custom');
|
$mform->setDefault('scope', 'custom');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mform->addElement('file', 'userfile', get_string('importoutcomes', 'grades'));
|
$mform->addElement('filepicker', 'userfile', get_string('importoutcomes', 'grades'));
|
||||||
$mform->addHelpButton('userfile', 'importoutcomes', 'grades');
|
$mform->addRule('userfile', get_string('required'), 'required', null, 'server');
|
||||||
|
$mform->setHelpButton('userfile', array('importoutcomes', get_string('importoutcomes', 'grades'), 'grade'));
|
||||||
|
|
||||||
$mform->addElement('submit', 'save', get_string('uploadthisfile'));
|
$mform->addElement('submit', 'save', get_string('uploadthisfile'));
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../../../config.php');
|
require_once(dirname(__FILE__).'/../../../config.php');
|
||||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
|
||||||
require_once($CFG->dirroot.'/grade/lib.php');
|
require_once($CFG->dirroot.'/grade/lib.php');
|
||||||
require_once($CFG->libdir.'/gradelib.php');
|
require_once($CFG->libdir.'/gradelib.php');
|
||||||
|
|
||||||
@ -57,14 +56,6 @@ if ($courseid) {
|
|||||||
/// return tracking object
|
/// return tracking object
|
||||||
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid));
|
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid));
|
||||||
|
|
||||||
require_once('import_outcomes_form.php');
|
|
||||||
$upload_form = new import_outcomes_form();
|
|
||||||
|
|
||||||
if ($upload_form_data = $upload_form->get_data()) {
|
|
||||||
require_once('import.php');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$strgrades = get_string('grades');
|
$strgrades = get_string('grades');
|
||||||
$pagename = get_string('outcomes', 'grades');
|
$pagename = get_string('outcomes', 'grades');
|
||||||
@ -253,8 +244,6 @@ if ( !empty($outcomes_tables) ) {
|
|||||||
}
|
}
|
||||||
echo $OUTPUT->container_end();
|
echo $OUTPUT->container_end();
|
||||||
|
|
||||||
$upload_form->display();
|
|
||||||
|
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,4 +259,3 @@ function grade_print_scale_link($courseid, $scale, $gpr) {
|
|||||||
$url = $gpr->add_url_params($url);
|
$url = $gpr->add_url_params($url);
|
||||||
return html_writer::link($url, $scale->get_name());
|
return html_writer::link($url, $scale->get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +472,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
|
|||||||
if ($reports = grade_helper::get_plugins_reports($courseid)) {
|
if ($reports = grade_helper::get_plugins_reports($courseid)) {
|
||||||
$plugin_info['report'] = $reports;
|
$plugin_info['report'] = $reports;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($edittree = grade_helper::get_info_edit_structure($courseid)) {
|
if ($edittree = grade_helper::get_info_edit_structure($courseid)) {
|
||||||
$plugin_info['edittree'] = $edittree;
|
$plugin_info['edittree'] = $edittree;
|
||||||
}
|
}
|
||||||
@ -483,9 +483,6 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
|
|||||||
|
|
||||||
if ($outcomes = grade_helper::get_info_outcomes($courseid)) {
|
if ($outcomes = grade_helper::get_info_outcomes($courseid)) {
|
||||||
$plugin_info['outcome'] = $outcomes;
|
$plugin_info['outcome'] = $outcomes;
|
||||||
if ($active_type == 'outcome' && $active_plugin == 'import') {
|
|
||||||
$plugin_info['outcome']['import'] = new grade_plugin_info('import', null, get_string('importoutcomes', 'grades'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($letters = grade_helper::get_info_letters($courseid)) {
|
if ($letters = grade_helper::get_info_letters($courseid)) {
|
||||||
@ -495,7 +492,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
|
|||||||
if ($imports = grade_helper::get_plugins_import($courseid)) {
|
if ($imports = grade_helper::get_plugins_import($courseid)) {
|
||||||
$plugin_info['import'] = $imports;
|
$plugin_info['import'] = $imports;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exports = grade_helper::get_plugins_export($courseid)) {
|
if ($exports = grade_helper::get_plugins_export($courseid)) {
|
||||||
$plugin_info['export'] = $exports;
|
$plugin_info['export'] = $exports;
|
||||||
}
|
}
|
||||||
@ -513,7 +510,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put settings last
|
// Put settings last
|
||||||
if ($setting = grade_helper::get_info_manage_settings($courseid)) {
|
if ($setting = grade_helper::get_info_manage_settings($courseid)) {
|
||||||
$plugin_info['settings'] = array('course'=>$setting);
|
$plugin_info['settings'] = array('course'=>$setting);
|
||||||
@ -615,9 +612,9 @@ function print_grade_page_head($courseid, $active_type, $active_plugin=null,
|
|||||||
$heading = false, $return=false,
|
$heading = false, $return=false,
|
||||||
$buttons=false) {
|
$buttons=false) {
|
||||||
global $CFG, $OUTPUT, $PAGE;
|
global $CFG, $OUTPUT, $PAGE;
|
||||||
|
|
||||||
$plugin_info = grade_get_plugin_info($courseid, $active_type, $active_plugin);
|
$plugin_info = grade_get_plugin_info($courseid, $active_type, $active_plugin);
|
||||||
|
|
||||||
// Determine the string of the active plugin
|
// Determine the string of the active plugin
|
||||||
$stractive_plugin = ($active_plugin) ? $plugin_info['strings']['active_plugin_str'] : $heading;
|
$stractive_plugin = ($active_plugin) ? $plugin_info['strings']['active_plugin_str'] : $heading;
|
||||||
$stractive_type = $plugin_info['strings'][$active_type];
|
$stractive_type = $plugin_info['strings'][$active_type];
|
||||||
@ -2297,6 +2294,8 @@ abstract class grade_helper {
|
|||||||
$outcomes['course'] = new grade_plugin_info('course', $url, get_string('outcomescourse', 'grades'));
|
$outcomes['course'] = new grade_plugin_info('course', $url, get_string('outcomescourse', 'grades'));
|
||||||
$url = new moodle_url('/grade/edit/outcome/index.php', array('id'=>$courseid));
|
$url = new moodle_url('/grade/edit/outcome/index.php', array('id'=>$courseid));
|
||||||
$outcomes['edit'] = new grade_plugin_info('edit', $url, get_string('editoutcomes', 'grades'));
|
$outcomes['edit'] = new grade_plugin_info('edit', $url, get_string('editoutcomes', 'grades'));
|
||||||
|
$url = new moodle_url('/grade/edit/outcome/import.php', array('courseid'=>$courseid));
|
||||||
|
$outcomes['import'] = new grade_plugin_info('import', $url, get_string('importoutcomes', 'grades'));
|
||||||
} else {
|
} else {
|
||||||
$url = new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid));
|
$url = new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid));
|
||||||
$outcomes['edit'] = new grade_plugin_info('edit', $url, get_string('outcomescourse', 'grades'));
|
$outcomes['edit'] = new grade_plugin_info('edit', $url, get_string('outcomescourse', 'grades'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user