--- /dev/null
+<?php // $Id$
+require_once $CFG->libdir.'/formslib.php';
+
+class grade_export_form extends moodleform {
+ function definition (){
+ global $CFG;
+ include_once($CFG->libdir.'/pear/HTML/QuickForm/advcheckbox.php');
+ $mform =& $this->_form;
+ $id = $this->_customdata['id']; // course id
+ $mform->addElement('hidden', 'id', $id);
+ if ($grade_items = grade_get_items($id)) {
+ foreach ($grade_items as $grade_item) {
+ $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->itemname, array('selected'=>'selected'), array(0, $grade_item->id));
+ $element->setChecked(1);
+ $mform->addElement($element);
+ }
+ }
+ $this->add_action_buttons(false, get_string('submit'));
+ }
+}
+?>
\ No newline at end of file
global $CFG;
// print all items for selections
// make this a standard function in lib maybe
- //if ($grade_items = grade_get_items($id)) {
- include_once('grade_export_form.php');
- $mform = new grade_export_form(qualified_me(), array('id'=>$id));
- $mform->display();
- /*
-
- echo '<form action="index.php" method="post">';
- echo '<div>';
- foreach ($grade_items as $grade_item) {
-
- echo '<br/><input type="checkbox" name="itemids[]" value="'.$grade_item->id.'" checked="checked"/>';
-
- if ($grade_item->itemtype == 'category') {
- // grade categories should be displayed bold
- echo '<b>'.$grade_item->itemname.'</b>';
- } else {
- echo $grade_item->itemname;
- }
- }
- echo '<input type="hidden" name="id" value="'.$id.'"/>';
- echo '<input type="hidden" name="sesskey" value="'.sesskey().'"/>';
- echo '<input type="submit" value="'.get_string('submit').'" />';
- echo '</div>';
- echo '</form>';
- */
- //}
+ include_once('grade_export_form.php');
+ $mform = new grade_export_form(qualified_me(), array('id'=>$id));
+ $mform->display();
+
}
/**
* Base export class
--- /dev/null
+<?php // $Id$
+require_once $CFG->libdir.'/formslib.php';
+
+class grade_export_txt_form extends moodleform {
+ function definition (){
+ global $CFG;
+ include_once($CFG->libdir.'/pear/HTML/QuickForm/advcheckbox.php');
+ $mform =& $this->_form;
+ $id = $this->_customdata['id']; // course id
+ $mform->addElement('hidden', 'id', $id);
+ if ($grade_items = grade_get_items($id)) {
+ foreach ($grade_items as $grade_item) {
+ $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->itemname, array('selected'=>'selected'), array(0, $grade_item->id));
+ $element->setChecked(1);
+ $mform->addElement($element);
+ }
+ }
+
+ include_once($CFG->libdir.'/pear/HTML/QuickForm/radio.php');
+ $radio = array();
+ $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('tab'), 'tab');
+ $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('comma'), 'comma');
+ $mform->addGroup($radio, 'separator', get_string('separator'), ' ', false);
+ $mform->setDefault('separator', 'comma');
+
+ $this->add_action_buttons(false, get_string('submit'));
+ }
+}
+?>
\ No newline at end of file
$course = get_record('course', 'id', $id);
$action = 'exporttxt';
print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
+include_once('grade_export_txt_form.php');
+$mform = new grade_export_txt_form(qualified_me(), array('id'=>$id));
+$mform->display();
+/*
// print_gradeitem_selections($id);
// print all items for selections
// make this a standard function in lib maybe
echo '</div>';
echo '</form>';
}
-
+*/
print_footer();
?>
\ No newline at end of file
--- /dev/null
+<?php
+
+$plugin->version = 2007052201;
+$plugin->requires = 2007051801;
+
+?>
<?php
-/*
- This is development code, and it is not finished
-
-$form = new custom_form_subclass(qualified_me(), array('somefield' => 'somevalue', 'someotherfield' => 'someothervalue') );
-and then in your subclass, in definition, you can access
-$this->_customdata['somefield']
-*/
-
require_once('../../../config.php');
// capability check
}
require_once('../grade_import_form.php');
-
-
require_once($CFG->dirroot.'/grade/lib.php');
+
$course = get_record('course', 'id', $id);
$action = 'importcsv';
print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
-
$mform = new grade_import_form();
-//$mform2 = new grade_import_mapping_form();
//if ($formdata = $mform2->get_data() ) {
if (($formdata = data_submitted()) && !empty($formdata->map)) {
- // mapping info here
-
- // reconstruct the mapping
-
- print_object($formdata);
+// i am not able to get the mapping[] and map[] array using the following line
+// they are somehow not returned with get_data()
+// if ($formdata = $mform2->get_data()) {
foreach ($formdata->maps as $i=>$header) {
$map[$header] = $formdata->mapping[$i];
// temporary file name supplied by form
$filename = $CFG->dataroot.'/temp/'.$formdata->filename;
- // 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.
+ // 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("192M");
if (function_exists('apache_child_terminate')) {
foreach ($header as $i => $h) {
$h = trim($h); $header[$i] = $h; // remove whitespace
- // flag events to add columns if needed (?)
}
while (!feof ($fp)) {
// each line is a student record
unset ($studentid);
unset ($studentgrades);
- print_object($map);
+
foreach ($line as $key => $value) {
//decode encoded commas
$eventdata->gradevalue = $studentgrade;
events_trigger('grade_added', $eventdata);
- echo "<br/>triggering event for $idnumber... student id is $studentid and grade is $studentgrade";
-
+ debugging("triggering event for $idnumber... student id is $studentid and grade is $studentgrade");
}
}
}
error ('import file '.$filename.' not readable');
}
-} else if ( $formdata = $mform->get_data() ) {
+} else if ($formdata = $mform->get_data() ) {
$filename = $mform->get_userfile_name();
// --- get header (field names) ---
$header = split($csv_delimiter, fgets($fp,1024));
- echo '<form action="index.php" method="post" />';
-
- $mapfromoptions = array();
- foreach ($header as $h) {
- $mapfromoptions[$h] = $h;
- }
-
- choose_from_menu($mapfromoptions, 'mapfrom');
-
- // one mapfrom (csv column) to mapto (one of 4 choices)
- $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
- choose_from_menu($maptooptions, 'mapto');
-
- $gradeitems = array();
-
- include_once($CFG->libdir.'/gradelib.php');
- if ($grade_items = grade_get_items($id)) {
-
- foreach ($grade_items as $grade_item) {
- $gradeitems[$grade_item->idnumber] = $grade_item->itemname;
- }
- }
-
- foreach ($header as $h) {
- $h = trim($h);
- // this is the order of the headers
- echo "<br/> this field is :".$h." => ";
- echo '<input type="hidden" name="maps[]" value="'.$h.'"/>';
- // this is what they map to
-
- $mapfromoptions = array_merge(array('0'=>'ignore'), $gradeitems);
-
- choose_from_menu($mapfromoptions, 'mapping[]', $h);
-
- }
- $newfilename = 'cvstemp_'.time();
- move_uploaded_file($filename, $CFG->dataroot.'/temp/'.$newfilename);
-
- echo '<input type="hidden" name="map" value="1"/>';
- echo '<input type="hidden" name="id" value="'.$id.'"/>';
- echo '<input name="filename" value='.$newfilename.' type="hidden" />';
- echo '<input type="submit" value="upload" />';
- echo '</form>';
-
- // set the headers
- //$mform2->setup($header, $filename);
- //$mform2->display();
-
- // move file to $CFG->dataroot/temp
-
+ // print mapping form
+ $mform2 = new grade_import_mapping_form(qualified_me(), array('id'=>$id, 'header'=>$header, 'filename'=>$filename));
+ $mform2->display();
} else {
$mform->display();
}
}
}
-
class grade_import_mapping_form extends moodleform {
+
function definition () {
+ global $CFG;
+
$mform =& $this->_form;
- // course id needs to be passed for auth purposes
- $mform->addElement('hidden', 'id', optional_param('id'));
+ // this is an array of headers
+ $header = $this->_customdata['header'];
+ // temporary filename
+ $filename = $this->_customdata['filename'];
+ // course id
+ $id = $this->_customdata['id'];
- $this->add_action_buttons(false, get_string('uploadgrades'));
- }
+ $mform->addElement('header', 'general', get_string('identifier'));
+ $mapfromoptions = array();
+
+ if ($header) {
+ foreach ($header as $h) {
+ $mapfromoptions[$h] = $h;
+ }
+ }
+ $mform->addElement('select', 'mapfrom', get_string('mapfrom'), $mapfromoptions);
+ //choose_from_menu($mapfromoptions, 'mapfrom');
+
+ $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
+ //choose_from_menu($maptooptions, 'mapto');
+ $mform->addElement('select', 'mapto', get_string('mapto'), $maptooptions);
+
+ $mform->addElement('header', 'general', get_string('mappings'));
+
+ $gradeitems = array();
- function setup ($headers = '', $filename = '') {
- $mform =& $this->_form;
- if (is_array($headers)) {
- foreach ($headers as $header) {
- $mform->addElement('hidden', $header, $header);
- $mform->addRule($header, null, 'required');
+ include_once($CFG->libdir.'/gradelib.php');
+
+ if ($id) {
+ if ($grade_items = grade_get_items($id)) {
+ foreach ($grade_items as $grade_item) {
+ $gradeitems[$grade_item->idnumber] = $grade_item->itemname;
+ }
}
}
- if ($filename) {
- $mform->addElement('hidden', 'filename', $filename);
- $mform->addRule('filename', null, 'required');
+
+ if ($header) {
+ foreach ($header as $h) {
+
+ $h = trim($h);
+ // this is the order of the headers
+ $mform->addElement('hidden', 'maps[]', $h);
+ //echo '<input type="hidden" name="maps[]" value="'.$h.'"/>';
+ // this is what they map to
+
+ $mapfromoptions = array_merge(array('0'=>'ignore'), $gradeitems);
+ $mform->addElement('select', 'mapping[]', $h, $mapfromoptions);
+ //choose_from_menu($mapfromoptions, 'mapping[]', $h);
+
+ }
}
+ $newfilename = 'cvstemp_'.time();
+ move_uploaded_file($filename, $CFG->dataroot.'/temp/'.$newfilename);
+
+ // course id needs to be passed for auth purposes
+ $mform->addElement('hidden', 'map', 1);
+ $mform->addElement('hidden', 'id', optional_param('id'));
+ //echo '<input name="filename" value='.$newfilename.' type="hidden" />';
+ $mform->addElement('hidden', 'filename', $newfilename);
+
+ $this->add_action_buttons(false, get_string('uploadgrades'));
- print_object($mform);
-
}
}
?>