/** * The standard form definiton. */ public function definition() { $mform = $this->_form; $selectedfields = $this->_customdata['selectedfields']; $overrides = $this->_customdata['overrides']; $fields = tool_downloaddata_processor::get_valid_course_fields(); if (empty($selectedfields)) { $selectedfields = array(get_string('noselectedfields', 'tool_downloaddata')); } $mform->addElement('header', 'generalhdr', get_string('downloadcourses', 'tool_downloaddata')); $formatchoices = array(tool_downloaddata_processor::FORMAT_CSV => get_string('formatcsv', 'tool_downloaddata'), tool_downloaddata_processor::FORMAT_XLS => get_string('formatxls', 'tool_downloaddata')); $mform->addElement('select', 'format', get_string('format', 'tool_downloaddata'), $formatchoices); $mform->setDefault('format', $this->_customdata['format']); $encodings = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_downloaddata'), $encodings); $mform->setDefault('encoding', $this->_customdata['encoding']); $mform->disabledIf('encoding', 'format', 'noteq', tool_downloaddata_processor::FORMAT_CSV); $delimiters = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_downloaddata'), $delimiters); $mform->setDefault('delimiter_name', $this->_customdata['delimiter_name']); $mform->disabledIf('delimiter_name', 'format', 'noteq', tool_downloaddata_processor::FORMAT_CSV); $useoverrides = array('true' => 'Yes', 'false' => 'No'); $mform->addElement('select', 'useoverrides', get_string('useoverrides', 'tool_downloaddata'), $useoverrides); $mform->setDefault('useoverrides', $this->_customdata['useoverrides']); $mform->addHelpButton('useoverrides', 'useoverrides', 'tool_downloaddata'); $sortbycategorypath = array('true' => 'Yes', 'false' => 'No'); $mform->addElement('select', 'sortbycategorypath', get_string('sortbycategorypath', 'tool_downloaddata'), $sortbycategorypath); $mform->setDefault('sortbycategorypath', $this->_customdata['sortbycategorypath']); $mform->addHelpButton('sortbycategorypath', 'sortbycategorypath', 'tool_downloaddata'); $mform->addElement('header', 'fieldshdr', get_string('fields', 'tool_downloaddata')); $mform->setExpanded('fieldshdr', true); // Creating the field selection elements. $objs = array(); $objs[0] = $mform->createElement('select', 'availablefields', get_string('available', 'tool_downloaddata'), $fields, 'size="10"'); $objs[0]->setMultiple(true); $objs[1] = $mform->createElement('select', 'selectedfields', get_string('selected', 'tool_downloaddata'), $selectedfields, 'size="10"'); $objs[1]->setMultiple(true); $group = $mform->addElement('group', 'fieldsgroup', get_string('fields', 'tool_downloaddata'), $objs, ' ', false); $mform->addHelpButton('fieldsgroup', 'fields', 'tool_downloaddata'); // Creating the buttons for the field selection elements. $objs = array(); $objs[] = $mform->createElement('submit', 'addfieldselection', get_string('addfieldselection', 'tool_downloaddata')); $objs[] = $mform->createElement('submit', 'removefieldselection', get_string('removefieldselection', 'tool_downloaddata')); $objs[] = $mform->createElement('submit', 'addallfields', get_string('addallfields', 'tool_downloaddata')); $objs[] = $mform->createElement('submit', 'removeallfields', get_string('removeallfields', 'tool_downloaddata')); $group = $mform->addElement('group', 'buttonsgroup', '', $objs, array(' ', '<br/>'), false); $mform->addElement('header', 'overrideshdr', get_string('overrides', 'tool_downloaddata')); $mform->addElement('textarea', 'overrides', get_string('overrides', 'tool_downloaddata'), 'wrap="virtual" rows="3" cols="45"'); $mform->setType('overrides', PARAM_RAW); $mform->setDefault('overrides', $overrides); $mform->addHelpButton('overrides', 'overrides', 'tool_downloaddata'); if (empty($overrides)) { $mform->setExpanded('overrideshdr', false); } else { $mform->setExpanded('overrideshdr', true); } $this->add_action_buttons(false, get_string('download', 'tool_downloaddata')); $template = '<label class="qflabel" style="vertical-align:top">{label}</label> {element}'; $mform->defaultRenderer()->setGroupElementTemplate($template, 'fieldsgroup'); }
/** * */ protected function definition_expimp_settings() { $mform =& $this->_form; $mform->addElement('header', 'expimpsettingshdr', get_string('expimpsettings', 'dataformview_csv')); // Enable import (param4). $mform->addElement('advcheckbox', 'param4', get_string('export', 'grades'), get_string('enable'), null, array(0, 1)); $mform->setDefault('param4', 1); // Enable import (param4). $mform->addElement('advcheckbox', 'param5', get_string('import'), get_string('enable'), null, array(0, 1)); $mform->setDefault('param5', 1); // Allow update existing entries (param4) // $mform->addElement('advcheckbox', 'updateexisting', null, get_string('allowupdateexisting', 'dataformview_csv'), null, array(0, 1)); // $mform->disabledIf('updateexisting', 'importenable', 'eq', 0);. // Delimiter. $delimiters = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter', get_string('csvdelimiter', 'dataform'), $delimiters); $mform->setDefault('delimiter', 'comma'); // Enclosure. $mform->addElement('text', 'enclosure', get_string('csvenclosure', 'dataform'), array('size' => '10')); $mform->setType('enclosure', PARAM_NOTAGS); $mform->setDefault('enclosure', ''); // Encoding. $choices = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $choices); $mform->setDefault('encoding', 'UTF-8'); }
/** * Close the grade importer file and optionally delete any temp files * * @param bool $delete */ public function close($delete) { $this->csvreader->close(); if ($delete) { $this->csvreader->cleanup(); } }
/** * Reset the current process. * * @return void. */ protected function reset() { $this->processstarted = false; $this->linenum = 0; $this->cir->init(); $this->errors = array(); }
/** * The form's definition. */ public function definition() { $mform =& $this->_form; $data = $this->_customdata; $mform->addElement('hidden', 'action', 'upload_group_data'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'id', $data['id']); $mform->setType('id', PARAM_INT); $mform->addElement('html', get_string('upload_help', 'block_upload_group')); $mform->addElement('header', 'upload_group_data', get_string('upload_group_data', 'block_upload_group')); // Add a file manager. $mform->addElement('filepicker', 'group_data', ''); // Add the encoding option. $choices = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'block_upload_group'), $choices); $mform->setDefault('encoding', 'UTF-8'); // Add the delimiter option. $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter', get_string('delimiter', 'block_upload_group'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000); $mform->addElement('select', 'preview_num', get_string('row_preview_num', 'block_upload_group'), $choices); $mform->setType('preview_num', PARAM_INT); $this->add_action_buttons(true, get_string('submit_group_data', 'block_upload_group')); }
/** * Reset the current process. * * @return void. */ public function reset() { $this->processstarted = false; $this->linenb = 0; $this->cir->init(); $this->errors = array(); }
function definition() { global $CFG, $USER; $mform =& $this->_form; $this->set_upload_manager(new upload_manager('userfile', false, false, null, false, 0, true, true, false)); $mform->addElement('header', 'settingsheader', get_string('upload')); $mform->addElement('file', 'userfile', get_string('file'), 'size="40"'); $mform->addRule('userfile', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'admin'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $textlib = textlib_get_instance(); $choices = $textlib->get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices); $mform->setDefault('encoding', 'UTF-8'); $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000); $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'admin'), $choices); $mform->setType('previewrows', PARAM_INT); $this->add_action_buttons(false, get_string('uploadusers')); }
/** * Defines the form, which will have: * - Input for courses csv. * - Input for users csv. * - Input for logs csv. * - Select for csv delimiter. * - Select for files encoding. */ public function definition() { $mform = $this->_form; $mform->addElement('header', 'settingsheader', get_string('upload', 'block_mycourse_recommendations')); $mform->addElement('static', 'description', '', get_string('upload_desc', 'block_mycourse_recommendations')); $mform->addElement('static', 'description', get_string('coursefile', 'block_mycourse_recommendations'), get_string('coursefile_desc', 'block_mycourse_recommendations')); $mform->addElement('filepicker', 'courses', ''); $mform->addRule('courses', null, 'required'); $mform->addElement('static', 'description', get_string('usersfile', 'block_mycourse_recommendations'), get_string('usersfile_desc', 'block_mycourse_recommendations')); $mform->addElement('filepicker', 'users', ''); $mform->addRule('users', null, 'required'); $mform->addElement('static', 'description', get_string('logsfile', 'block_mycourse_recommendations'), get_string('logsfile_desc', 'block_mycourse_recommendations')); $mform->addElement('filepicker', 'logs', ''); $mform->addRule('logs', null, 'required'); $choices = \csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $choices = \core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $this->add_action_buttons(false, get_string('uploaddata', 'block_mycourse_recommendations')); }
public function definition() { global $CFG, $USER; $mform =& $this->_form; $mform->addElement('header', 'settingsheader', get_string('upload')); $mform->addElement('filepicker', 'userfile', get_string('file')); $mform->addRule('userfile', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000); $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'tool_uploaduser'), $choices); $mform->setType('previewrows', PARAM_INT); $choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'tool_uploaduser'), UU_ADDINC => get_string('uuoptype_addinc', 'tool_uploaduser'), UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'tool_uploaduser'), UU_UPDATE => get_string('uuoptype_update', 'tool_uploaduser')); $mform->addElement('select', 'uutype', get_string('uuoptype', 'tool_uploaduser'), $choices); $this->add_action_buttons(false, get_string('uploadusers', 'tool_uploaduser')); }
function definition() { global $CFG; $mform = & $this->_form; $course = $this->_customdata['course']; $context = $this->_customdata['context']; // the upload manager is used directly in post precessing, moodleform::save_files() is not used yet //$this->set_upload_manager(new upload_manager('attachment')); $mform->addElement('header', 'general', ''); //fill in the data depending on page params //later using set_data $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); $mform->addRule('attachment', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $roles = get_assignable_roles($context); $mform->addElement('select', 'roleassign', get_string('roleassign', 'local_mass_enroll'), $roles); $mform->setDefault('roleassign', 5); //student $ids = array ( 'idnumber' => get_string('idnumber', 'local_mass_enroll'), 'username' => get_string('username', 'local_mass_enroll'), 'email' => get_string('email') ); $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids); $mform->setDefault('firstcolumn', 'idnumber'); $mform->addElement('selectyesno', 'creategroups', get_string('creategroups', 'local_mass_enroll')); $mform->setDefault('creategroups', 1); $mform->addElement('selectyesno', 'creategroupings', get_string('creategroupings', 'local_mass_enroll')); $mform->setDefault('creategroupings', 1); $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); $mform->setDefault('mailreport', 1); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(true, get_string('enroll', 'local_mass_enroll')); $mform->addElement('hidden', 'id', $course->id); $mform->setType('id', PARAM_INT); }
function definition() { global $DB, $CFG; $mform = $this->_form; $instance = $this->_customdata; $cmid = $instance['cmid']; // Course module id goes hidden as well $mform->addElement('hidden', 'cmid', $cmid); $mform->setType('cmid', PARAM_INT); // Course module id goes hidden as well $mform->addElement('hidden', 'upload', true); $mform->setType('upload', PARAM_BOOL); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'mod_emarking'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $mform->addHelpButton('delimiter_name', 'csvdelimiter', 'mod_emarking'); // Archivo de respuestas a procesar CSV $mform->addElement('filepicker', 'answersfile', get_string('answersfile', 'mod_emarking'), null, array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 10, 'accepted_types' => array('.csv'), 'return_types' => FILE_INTERNAL)); $mform->addRule('answersfile', get_string('answersfileisrequired', 'mod_emarking'), 'required', null, 'client'); $mform->setType('answersfile', PARAM_FILE); $mform->addHelpButton('answersfile', 'answersfile', 'mod_emarking'); $this->add_action_buttons(true, get_string('submit')); }
function definition() { $mform = $this->_form; $mform->addElement('header', 'settingsheader', get_string('upload')); $mform->addElement('filepicker', 'userfile', get_string('file')); $mform->addRule('userfile', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $choices = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000); $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'tool_uploaduser'), $choices); $mform->setType('previewrows', PARAM_INT); $this->add_action_buttons(false, get_string('uploadusers', 'tool_uploaduser')); }
/** * Form definition */ public function definition() { $mform =& $this->_form; $course = $this->_customdata['course']; $config = get_config('local_mass_enroll'); $mform->addElement('header', 'general', ''); // Fill in the data depending on page params. // Later using set_data. $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); $mform->addRule('attachment', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $choices = \core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $ids = array('idnumber' => get_string('idnumber', 'local_mass_enroll'), 'username' => get_string('username', 'local_mass_enroll'), 'email' => get_string('email')); $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids); $mform->setDefault('firstcolumn', 'idnumber'); $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); $mform->setDefault('mailreport', (int) $config->mailreportdefault); // Buttons. $this->add_action_buttons(true, get_string('unenroll', 'local_mass_enroll')); $mform->addElement('hidden', 'id', $course->id); $mform->setType('id', PARAM_INT); }
function definition() { global $CFG; $mform =& $this->_form; $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data')); $choices = csv_import_reader::get_delimiter_list(); $key = array_search(';', $choices); if (! $key === FALSE) { // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon): unset($choices[$key]); } $typesarray = array(); $str = get_string('csvwithselecteddelimiter', 'data'); $typesarray[] = $mform->createElement('radio', 'exporttype', null, $str . ' ', 'csv'); $typesarray[] = $mform->createElement('select', 'delimiter_name', null, $choices); //temporarily commenting out Excel export option. See MDL-19864 //$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls'); $typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods'); $mform->addGroup($typesarray, 'exportar', '', array(''), false); $mform->addRule('exportar', null, 'required'); $mform->setDefault('exporttype', 'csv'); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data')); foreach($this->_datafields as $field) { if($field->text_export_supported()) { $html = '<div title="' . s($field->field->description) . '" ' . 'class="d-inline-block">' . $field->field->name . '</div>'; $name = ' (' . $field->name() . ')'; $mform->addElement('advcheckbox', 'field_' . $field->field->id, $html, $name, array('group' => 1)); $mform->setDefault('field_' . $field->field->id, 1); } else { $a = new stdClass(); $a->fieldtype = $field->name(); $str = get_string('unsupportedexport', 'data', $a); $mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, $str); } } $this->add_checkbox_controller(1, null, null, 1); $context = context_module::instance($this->_cm->id); if (has_capability('mod/data:exportuserinfo', $context)) { $mform->addElement('checkbox', 'exportuser', get_string('includeuserdetails', 'data')); } $mform->addElement('checkbox', 'exporttime', get_string('includetime', 'data')); if ($this->_data->approval) { $mform->addElement('checkbox', 'exportapproval', get_string('includeapproval', 'data')); } $this->add_action_buttons(true, get_string('exportentries', 'data')); }
/** * Load up the above text through the csv import. * * @param string $content Text to be imported into the gradebook. * @return array All text separated by commas now in an array. */ protected function csv_load($content) { // Import the csv strings. $this->iid = csv_import_reader::get_new_iid('grade'); $this->csvimport = new csv_import_reader($this->iid, 'grade'); $this->csvimport->load_csv_content($content, 'utf8', 'comma'); $this->columns = $this->csvimport->get_columns(); $this->csvimport->init(); while ($line = $this->csvimport->next()) { $testarray[] = $line; } return $testarray; }
function definition() { global $CFG; $mform =& $this->_form; $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data')); $choices = csv_import_reader::get_delimiter_list(); $key = array_search(';', $choices); if (!$key === FALSE) { // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon): unset($choices[$key]); } $typesarray = array(); $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . ' ', 'csv'); $typesarray[] =& MoodleQuickForm::createElement('select', 'delimiter_name', null, $choices); $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls'); $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods'); $mform->addGroup($typesarray, 'exportar', '', array(''), false); $mform->addRule('exportar', null, 'required'); $mform->setDefault('exporttype', 'csv'); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data')); foreach ($this->_datafields as $field) { if ($field->text_export_supported()) { $mform->addElement('advcheckbox', 'field_' . $field->field->id, '<div title="' . s($field->field->description) . '">' . $field->field->name . '</div>', ' (' . $field->name() . ')', array('group' => 1)); $mform->setDefault('field_' . $field->field->id, 1); } else { $a = new object(); $a->fieldtype = $field->name(); $mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, get_string('unsupportedexport', 'data', $a)); } } $this->add_checkbox_controller(1, null, null, 1); require_once $CFG->libdir . '/portfoliolib.php'; if (has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->_cm->id))) { if ($portfoliooptions = portfolio_instance_select(portfolio_instances(), call_user_func(array('data_portfolio_caller', 'supported_formats')), 'data_portfolio_caller', '', true, true)) { $mform->addElement('header', 'notice', get_string('portfolionotfile', 'data') . ':'); $portfoliooptions[0] = get_string('none'); ksort($portfoliooptions); $mform->addElement('select', 'portfolio', get_string('portfolio', 'portfolio'), $portfoliooptions); } } $this->add_action_buttons(true, get_string('exportdatabaserecords', 'data')); }
function validation($data, $files) { global $CFG; $errors = array(); // Use csv importer from Moodle $iid = csv_import_reader::get_new_iid('emarking-predefined-comments'); $reader = new csv_import_reader($iid, 'emarking-predefined-comments'); $content = $data['comments']; $reader->load_csv_content($content, 'utf8', "tab"); // Validate columns, minimum number and first two to be userid and attemptid if (count($reader->get_columns()) < 0) { $errors['comments'] = get_string('onecolumnrequired', 'mod_emarking'); } $reader->init(); $current = 0; while ($line = $reader->next()) { $current++; } if ($current < 1) { $errors['comments'] = get_string('twolinesrequired', 'mod_emarking'); } return $errors; }
function definition() { global $CFG; $mform =& $this->_form; $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data')); $choices = csv_import_reader::get_delimiter_list(); $key = array_search(';', $choices); if (!$key === FALSE) { // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon): unset($choices[$key]); } $typesarray = array(); $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . ' ', 'csv'); $typesarray[] =& MoodleQuickForm::createElement('select', 'delimiter_name', null, $choices); $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls'); $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods'); $mform->addGroup($typesarray, 'exportar', '', array(''), false); $mform->addRule('exportar', null, 'required'); $mform->setDefault('exporttype', 'csv'); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else { if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } } $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data')); foreach ($this->_datafields as $field) { if ($field->text_export_supported()) { $mform->addElement('advcheckbox', 'field_' . $field->field->id, '<div title="' . s($field->field->description) . '">' . $field->field->name . '</div>', ' (' . $field->name() . ')', array('group' => 1)); $mform->setDefault('field_' . $field->field->id, 1); } else { $a = new stdClass(); $a->fieldtype = $field->name(); $mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, get_string('unsupportedexport', 'data', $a)); } } $this->add_checkbox_controller(1, null, null, 1); $this->add_action_buttons(true, get_string('exportentries', 'data')); }
function definition() { global $CFG; $mform =& $this->_form; $cmid = $this->_customdata['id']; $mform->addElement('filepicker', 'recordsfile', get_string('csvfile', 'data')); $delimiters = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'fielddelimiter', get_string('fielddelimiter', 'data'), $delimiters); $mform->setDefault('fielddelimiter', 'comma'); $mform->addElement('text', 'fieldenclosure', get_string('fieldenclosure', 'data')); $textlib = textlib_get_instance(); $choices = $textlib->get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices); $mform->setDefault('encoding', 'UTF-8'); $submit_string = get_string('submit'); // data id $mform->addElement('hidden', 'd'); $mform->setType('d', PARAM_INT); $this->add_action_buttons(false, $submit_string); }
public function execute() { global $CFG, $DB; require_once $CFG->libdir . '/csvlib.class.php'; require_once $CFG->libdir . '/moodlelib.php'; $csvfilepath = $this->arguments[0]; if ($csvfilepath[0] != '/') { $csvfilepath = $this->cwd . DIRECTORY_SEPARATOR . $csvfilepath; } $iid = \csv_import_reader::get_new_iid('userprofile'); $type = 'userprofile'; $csvreader = new \csv_import_reader($iid, $type); if (false === ($csvfile = file_get_contents($csvfilepath))) { cli_error('Unable to load csv file. ' . error_get_last()['message']); } if (!$csvreader->load_csv_content($csvfile, 'utf-8', 'comma')) { cli_error('Unalbe to parse csv file. ' . $csvreader->get_error()); } if (!$csvreader->init()) { cli_error('Unable to initialise csv reading'); } $columns = $csvreader->get_columns(); $columnsids = array_flip($columns); while (false !== ($row = $csvreader->next())) { $category = $this->get_or_create_category($row[$columnsids['categoryname']], $row[$columnsids['categorysortorder']]); $userfield = new \stdClass(); $userfield->shortname = $row[$columnsids['shortname']]; $userfield->name = $row[$columnsids['name']]; $userfield->datatype = $row[$columnsids['datatype']]; $userfield->description = $row[$columnsids['description']]; $userfield->descriptionformat = $row[$columnsids['descriptionformat']]; $userfield->categoryid = $category->id; $userfield->sortorder = $row[$columnsids['sortorder']]; $userfield->required = $row[$columnsids['required']]; $userfield->locked = $row[$columnsids['locked']]; $userfield->visible = $row[$columnsids['visible']]; $userfield->forceunique = $row[$columnsids['forceunique']]; $userfield->signup = $row[$columnsids['signup']]; $userfield->defaultdata = $row[$columnsids['defaultdata']]; $userfield->defaultdataformat = $row[$columnsids['defaultdataformat']]; $userfield->param1 = $row[$columnsids['param1']]; $userfield->param2 = $row[$columnsids['param2']]; $userfield->param3 = $row[$columnsids['param3']]; $userfield->param4 = $row[$columnsids['param4']]; $userfield->param5 = $row[$columnsids['param5']]; $this->get_or_create_userfield($userfield); } }
function definition() { global $CFG; $mform = & $this->_form; //$mform->addElement('header', 'general', get_string('bulkenrol','block_learning_plan')); //fill in the data depending on page params //later using set_data $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); $mform->addRule('attachment', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else if (get_string('listsep', 'langconfig') == ';') { $mform->setDefault('delimiter_name', 'semicolon'); } else { $mform->setDefault('delimiter_name', 'comma'); } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $mform->addElement('hidden','roleassign'); $mform->setDefault('roleassign', 5); //student $mform->setType('roleassign','int'); $ids = array ( 'username' => get_string('username', 'local_mass_enroll'), 'idnumber' => get_string('idnumber', 'local_mass_enroll'), 'email' => get_string('email') ); $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'block_learning_plan'), $ids); $mform->setDefault('firstcolumn', 'username'); //$mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); //$mform->setDefault('mailreport', 1); $this->add_action_buttons(true, get_string('enroll_lp', 'block_learning_plan')); }
/** * Load CSV content for previewing. * * @param string $text The grade data being imported. * @param string $encoding The type of encoding the file uses. * @param string $separator The separator being used to define each field. * @param int $previewrows How many rows are being previewed. */ public function load_csv_content($text, $encoding, $separator, $previewrows) { $this->raise_limits(); $this->iid = csv_import_reader::get_new_iid('grade'); $csvimport = new csv_import_reader($this->iid, 'grade'); $csvimport->load_csv_content($text, $encoding, $separator); $this->error = $csvimport->get_error(); // Get header (field names). $this->headers = $csvimport->get_columns(); $this->trim_headers(); $csvimport->init(); $this->previewdata = array(); for ($numlines = 0; $numlines <= $previewrows; $numlines++) { $lines = $csvimport->next(); if ($lines) { $this->previewdata[] = $lines; } } }
$today = time(); $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); // array of all valid fields for validation $STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email', 'city', 'country', 'lang', 'timezone', 'mailformat', 'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe', 'institution', 'department', 'idnumber', 'skype', 'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address', 'url', 'description', 'descriptionformat', 'password', 'auth', 'oldusername', 'deleted'); $PRF_FIELDS = array(); if ($prof_fields = $DB->get_records('user_info_field')) { foreach ($prof_fields as $prof_field) { $PRF_FIELDS[] = 'profile_field_' . $prof_field->shortname; } } unset($prof_fields); if (empty($iid)) { $mform1 = new admin_uploaduser_form1(); if ($formdata = $mform1->get_data()) { $iid = csv_import_reader::get_new_iid('uploaduser'); $cir = new csv_import_reader($iid, 'uploaduser'); $content = $mform1->get_file_content('userfile'); $readcount = $cir->load_csv_content($content, $formdata->encoding, $formdata->delimiter_name); unset($content); if ($readcount === false) { print_error('csvloaderror', '', $returnurl); } else { if ($readcount == 0) { print_error('csvemptyfile', 'error', $returnurl); } } // test if columns ok $filecolumns = uu_validate_user_upload_columns($cir, $STD_FIELDS, $PRF_FIELDS, $returnurl); // continue to form2 } else { echo $OUTPUT->header();
/** * */ protected function definition_csv_settings() { $mform =& $this->_form; $view = $this->_view; $mform->addElement('header', 'csvsettingshdr', get_string('csvsettings', 'dataformview_csv')); $mform->setExpanded('csvsettingshdr'); // Delimiter. $delimiters = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter', get_string('csvdelimiter', 'dataform'), $delimiters); // Enclosure. $mform->addElement('text', 'enclosure', get_string('csvenclosure', 'dataform'), array('size' => '10')); $mform->setType('enclosure', PARAM_NOTAGS); // Encoding. $choices = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $choices); }
// Display the standard upload file form. echo html_writer::start_tag('div', array('class' => 'clearer')); echo html_writer::end_tag('div'); $mform->display(); echo $OUTPUT->footer(); die; } } } // Data has already been submitted so we can use the $iid to retrieve it. $mform2 = new import_mapping_form(null, array('iid' => $iid)); if ($mform2->is_cancelled()) { redirect($url); } else { if ($formdata = $mform2->get_data()) { $csvimport = new csv_import_reader($iid, 'rooms'); $header = $csvimport->get_columns(); @set_time_limit(0); raise_memory_limit(MEMORY_EXTRA); $csvimport->init(); $info = array(); while ($line = $csvimport->next()) { if (count($line) <= 1) { // there is no data on this line, move on continue; } $data = new stdClass(); $data->fecha_reserva = $line[0]; $data->modulo = $line[1]; $data->confirmado = $line[2]; $data->activa = $line[3];
/** * @global object * @param array $export * @param string $delimiter_name * @param object $database * @param int $count * @param bool $return * @return string|void */ function data_export_csv($export, $delimiter_name, $dataname, $count, $return=false) { global $CFG; require_once($CFG->libdir . '/csvlib.class.php'); $delimiter = csv_import_reader::get_delimiter($delimiter_name); $filename = clean_filename("{$dataname}-{$count}_record"); if ($count > 1) { $filename .= 's'; } $filename .= clean_filename('-' . gmdate("Ymd_Hi")); $filename .= clean_filename("-{$delimiter_name}_separated"); $filename .= '.csv'; if (empty($return)) { header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=$filename"); header('Expires: 0'); header('Cache-Control: must-revalidate,post-check=0,pre-check=0'); header('Pragma: public'); } $encdelim = '&#' . ord($delimiter) . ';'; $returnstr = ''; foreach($export as $row) { foreach($row as $key => $column) { $row[$key] = str_replace($delimiter, $encdelim, $column); } $returnstr .= implode($delimiter, $row) . "\n"; } if (empty($return)) { echo $returnstr; return; } return $returnstr; }
/** * Get encoded delimiter character * * @global object * @param string separator name * @return string encoded delimiter char */ static function get_encoded_delimiter($delimiter_name) { global $CFG; if ($delimiter_name == 'cfg' and isset($CFG->CSV_ENCODE)) { return $CFG->CSV_ENCODE; } $delimiter = csv_import_reader::get_delimiter($delimiter_name); return '&#' . ord($delimiter); }
/** * Validation callback function - verified the column line of csv file. * Converts standard column names to lowercase. * @param csv_import_reader $cir * @param array $stdfields standard user fields * @param array $profilefields custom profile fields * @param moodle_url $returnurl return url in case of any error * @return array list of fields */ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $profilefields, moodle_url $returnurl) { $columns = $cir->get_columns(); if (empty($columns)) { $cir->close(); $cir->cleanup(); print_error('cannotreadtmpfile', 'error', $returnurl); } if (count($columns) < 2) { $cir->close(); $cir->cleanup(); print_error('csvfewcolumns', 'error', $returnurl); } // test columns $processed = array(); foreach ($columns as $key => $unused) { $field = $columns[$key]; $lcfield = textlib::strtolower($field); if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) { // standard fields are only lowercase $newfield = $lcfield; } else { if (in_array($field, $profilefields)) { // exact profile field name match - these are case sensitive $newfield = $field; } else { if (in_array($lcfield, $profilefields)) { // hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field $newfield = $lcfield; } else { if (preg_match('/^(cohort|course|group|type|role|enrolperiod)\\d+$/', $lcfield)) { // special fields for enrolments $newfield = $lcfield; } else { $cir->close(); $cir->cleanup(); print_error('invalidfieldname', 'error', $returnurl, $field); } } } } if (in_array($newfield, $processed)) { $cir->close(); $cir->cleanup(); print_error('duplicatefieldname', 'error', $returnurl, $newfield); } $processed[$key] = $newfield; } return $processed; }
foreach ($predefinedcomments as $predefinedcomment) { $deleteurlcomment = new moodle_url('', array('action' => 'delete', 'id' => $cm->id, 'commentid' => $predefinedcomment->id)); $deleteiconcomment = new pix_icon('t/delete', get_string('delete')); $deleteactioncomment = $OUTPUT->action_icon($deleteurlcomment, $deleteiconcomment, new confirm_action(get_string('questiondeletecomment', 'mod_emarking'))); $editurlcomment = new moodle_url('', array('action' => 'edit', 'id' => $cm->id, 'commentid' => $predefinedcomment->id)); $editiconcomment = new pix_icon('i/edit', get_string('edit')); $editactioncomment = $OUTPUT->action_icon($editurlcomment, $editiconcomment); $creatorname = $DB->get_record('user', array('id' => $predefinedcomment->markerid)); $table->data[] = array($predefinedcomment->text, $creatorname->username, $editactioncomment . $deleteactioncomment); } // Form display. $predefinedform = new emarking_import_excel_form(null, array('cmid' => $cm->id)); if ($predefinedform->get_data()) { // Use csv importer from Moodle. $iid = csv_import_reader::get_new_iid('emarking-predefined-comments'); $reader = new csv_import_reader($iid, 'emarking-predefined-comments'); $content = $predefinedform->get_data()->comments; $reader->load_csv_content($content, 'utf8', "tab"); $data = array(); if (isset($predefinedform->get_data()->headers)) { $columns = $reader->get_columns()[0]; } else { $columns = get_string("comment", "mod_emarking"); $data[] = array($reader->get_columns()[0]); } $reader->init(); $current = 0; while ($line = $reader->next()) { if (count($line) > 0) { $data[] = array($line[0]); }
$form = new mod_data_import_form(new moodle_url('/mod/data/import.php')); $formdata = new stdClass(); $formdata->d = $data->id; $form->set_data($formdata); $form->display(); echo $OUTPUT->box_end(); echo $OUTPUT->footer(); die; } else { // Large files are likely to take their time and memory. Let PHP know // that we'll take longer, and that the process should be recycled soon // to free up memory. @set_time_limit(0); raise_memory_limit(MEMORY_EXTRA); $iid = csv_import_reader::get_new_iid('moddata'); $cir = new csv_import_reader($iid, 'moddata'); $readcount = $cir->load_csv_content($form->get_file_content('recordsfile'), $formdata->encoding, $formdata->fielddelimiter); if (empty($readcount)) { print_error('csvfailed', 'data', "{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}"); } else { if (!($fieldnames = $cir->get_columns())) { print_error('cannotreadtmpfile', 'error'); } // check the fieldnames are valid $fields = $DB->get_records('data_fields', array('dataid' => $data->id), '', 'name, id, type'); $errorfield = ''; foreach ($fieldnames as $name) { if (!isset($fields[$name])) { $errorfield .= "'{$name}' "; } }