diff --git a/mod/checklist/README.txt b/mod/checklist/README.txt index bc373f36..138752d5 100644 --- a/mod/checklist/README.txt +++ b/mod/checklist/README.txt @@ -2,48 +2,57 @@ Checklist module ================ ==Introduction== -This is a Moodle plugin for Moodle 1.9 & 2.0+ that allows a teacher to create a checklist for their students to work through. +This is a Moodle plugin for Moodle 1.9 & 2.0+ that allows a teacher to create a checklist for their students + to work through. The teacher can monitor all the student's progress, as they tick off each of the items in the list. Note: This is the Moodle 2.0+ version. -Items can be indented and marked as optional or turned into headings; a range of different colours can be used for the items. -Students are presented with a simple chart showing how far they have progressed through the required/optional items and can add their own, private, items to the list. +Items can be indented and marked as optional or turned into headings; a range of different colours can be used +for the items. +Students are presented with a simple chart showing how far they have progressed through the required/optional +items and can add their own, private, items to the list. -==Changes== - -* 2012-03-05 - Bug fix: grades not updating when new items added to a course (with 'import course activities' on) +== Changes == +* 2012-04-11 - New functionnalities (documents, outcomes) by Jean Fruitet * 2012-01-27 - French translation from Luiggi Sansonetti * 2012-01-02 - Minor tweaks to improve Moodle 2.2+ compatibility (optional_param_array / context_module::instance ) * 2012-01-02 - CONTRIB-2979: remembers report settings (sort order, etc.) until you log out; CONTRIB-3308 - 'viewmenteereport' capability, allowing users to view reports of users they are mentors for ==Installation== -(Note, due to the way the new plugins database works, if you are downloading this from the Moodle.org website, you will need to download the 'checklist block' and 'checklist grade export' plugins separately) +(Note, due to the way the new plugins database works, if you are downloading this from the Moodle.org website, + you will need to download the 'checklist block' and 'checklist grade export' plugins separately) 1. Unzip the contents of file you downloaded to a temporary folder. 2. Upload the files to the your moodle server, placing the 'mod/checklist' files in the '[moodlefolder]/mod/checklist', (optionally) the 'blocks/checklist' files in the '[moodlefolder]/blocks/checklist' folder and (optionally) the 'grade/export/checklist' files in the '[moodlefolder]/grade/export/checklist' folder. 3. Log in as administrator and click on 'Notifications' in the admin area to update the Moodle database, ready to use this plugin. -IMPORTANT: The 'Check-off modules when complete' option now works via cron, by default. This means that there can be a delay of up to 60 seconds (or more - depending on how often your site runs 'cron' updates), between a student completing an activity and their checklist being updated. +IMPORTANT: The 'Check-off modules when complete' option now works via cron, by default. +This means that there can be a delay of up to 60 seconds (or more - depending on how often +your site runs 'cron' updates), between a student completing an activity and their checklist being updated. If you are not happy with this delay, then make the changes found in the file core_modifications.txt -Note: if you are upgrading from a previous version, please delete the file 'mod/checklist/settings.php' from the server, as it is no longer needed. +Note: if you are upgrading from a previous version, please delete the file 'mod/checklist/settings.php' +from the server, as it is no longer needed. ==Adding a checklist block== 1. Click 'Turn editing on', in a course view. 2. Under 'blocks', choose 'Checklist' -3. Click on the 'Edit' icon in the new block to set which checklist to display and (optionally) which group of users to display. +3. Click on the 'Edit' icon in the new block to set which checklist to display and (optionally) +which group of users to display. ==Exporting checklist progress (Excel)== 1. In a course, click 'Grades' 2. From the dropdown menu, choose 'Export => Checklist Export' 3. Choose the checklist you want to export and click 'Export Excel' -If you want to change the user information that is included in the export ('First name', 'Surname', etc.), then edit the file 'grade/export/checklist/columns.php' - instructions can be found inside the file itself. +If you want to change the user information that is included in the export ('First name', 'Surname', etc.), +then edit the file 'grade/export/checklist/columns.php' - instructions can be found inside the file itself. ==Usage== Click on 'Add an activity' and choose 'Checklist'. Enter all the usual information. -You can optionally allow students to add their own, private items to the list (this will not affect the overall progress, but may help students to keep note of anything extra they need to do). +You can optionally allow students to add their own, private items to the list (this will not affect +the overall progress, but may help students to keep note of anything extra they need to do). You can then add items to the list. Click on the 'tick' to toggle an item between required, optional and heading @@ -56,10 +65,13 @@ Click on the '+' icon to insert a new item immediately below the current item. Click on 'Preview', to get some idea of how this will look to students. Click on 'Results', to see a chart of how the students are currently progressing through the checklist. -Students can now log in, click on the checklist, tick any items they have completed and then click 'Save' to update the database. -If you have allowed them to do so, they can click on 'Start Adding Items', then click on the green '+' icons to insert their own, private items to the list. +Students can now log in, click on the checklist, tick any items they have completed and then click 'Save' +to update the database. +If you have allowed them to do so, they can click on 'Start Adding Items', then click on the green '+' +icons to insert their own, private items to the list. -If you allow a checklist to be updated by teachers (either exclusively, or in addition to students), it can be updated by doing the following: +If you allow a checklist to be updated by teachers (either exclusively, or in addition to students), +it can be updated by doing the following: 1. Click 'Results' 2. Click on the little 'Magnifying glass' icon, beside the student's name 3. Choose Yes / No for each item diff --git a/mod/checklist/README_JF_VERSION.txt b/mod/checklist/README_JF_VERSION.txt new file mode 100644 index 00000000..d57a488b --- /dev/null +++ b/mod/checklist/README_JF_VERSION.txt @@ -0,0 +1,120 @@ +CheckList - Moodle module +=========================================================================================== +// Modifications by jean.fruitet@univ-nantes.fr + +I made additions to original code to get some new functionnalities + +CheckList Version : $module->release = 'JF-2.x (Build: 2012041100)'; +This is a fork of master repositoy + + +1) Users may comment their Skills and upload files or URL as prove of practice. +---------------------------------------------------------------------------------- + +a) New DB tables 'checklist_description' and 'checklist_document' + +b) New config parameter : +$CFG->checklist_description_display +New script +./mod/checklist/settings.php + +c) New scripts +edit_description.php +edit_document.php +delete_description.php +delete_document.php +file_api.php + +d) Scripts modification +lib.php : + + // MOODLE 2.0 FILE API + function checklist_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { + //Serves activite documents and other files. + function checklist_send_file($course, $cm, $context, $filearea, $args) { + // Serves activite documents and other files. + +locallib.php : many functions added or modified (Look for "// MODIF JF" tag.) + +Class checklist_class { + +(...) + // MODIF JF 2012/03/18 + /* BEGIN OF FUNCTIONS ADDED BY JF ***** */ + (...) + /* END OF FUNCTIONS ADDED BY JF ** */ + +} + + +2) Import of Outcomes file (csv format) to get Outcomes as Items in CheckList +------------------------------------------------------------------------------ + +Teachers may import Outcomes (outcomes.csv) files in CheckList to get these outcomes as Items. +Furthermore any Item of CheckList may be validated by the way of Moodle activity +(Assignment or Quizz for exemple) which uses the same Outcomes. + +a) This does not affect any CheckList DB tables + +b) New config parameter : +$CFG->checklist_outcomes_input + +c) New scripts : + +importexportoutcomes.php +import_outcomes.php +export_outcomes.php +export_selected_outcomes.php +select_export.php +cron_outcomes.php + +d) Scripts modification +lib.php :: +// MODIF JF 2012/03/18 +define ("USES_OUTCOMES", 1); // Outcomes imported as items + +locallib.php :: +function view_import_export() { +(...) + // MODIF JF 2012/03/18 + if (USES_OUTCOMES && !empty($CFG->checklist_outcomes_input)){ + $importoutcomesurl = new moodle_url('/mod/checklist/import_outcomes.php', array('id' => $this->cm->id)); + $importoutcomesstr = get_string('import_outcomes', 'checklist'); + $exportoutcomesurl = new moodle_url('/mod/checklist/select_export.php', array('id' => $this->cm->id)); + $exportoutcomesstr = get_string('export_outcomes', 'checklist'); + echo "$importstr  $importoutcomesstr  $exportstr  $exportoutcomesstr"; + } + else{ + echo "$importstr     $exportstr"; + } +(...) +} + +autoupdate.php +In function checklist_autoupdate( + // MODIF JF 2012/03/18 + if ($module == 'referentiel') { + return 0; + } + +New localisation strings + +lang/en/checklist.php :: new strings +lang/fr/checklist.php :: new strings and translation + +Functions replacement : +In all scripts +error('error_message') -> print_error(get_string('error_code', 'checklist')); + + +3) Backup / Restore : +------------------------------------------------------------------------------ +./mod/checklist/backup/moodle2 scripts completed for new tables + +4) Installation +------------------------------------------------------------------------------ +./mod/checklist/install.xml +./mod/checklist/upgrade.php + + +=========================================================================================== diff --git a/mod/checklist/add_document.php b/mod/checklist/add_document.php new file mode 100644 index 00000000..977291d4 --- /dev/null +++ b/mod/checklist/add_document.php @@ -0,0 +1,113 @@ +. + +/** + * Add a new document to a description + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +require_once(dirname(__FILE__).'/file_api.php'); // Moodle 2 file API +require_once(dirname(dirname(dirname(__FILE__))).'/repository/lib.php'); // Repository API + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$itemid = optional_param('itemid', 0, PARAM_INT); // Item ID +$userid = optional_param('userid', 0, PARAM_INT); // userID +$descriptionid = optional_param('descriptionid', 0, PARAM_INT); // description ID +$cancel = optional_param('cancel', 0, PARAM_BOOL); + + +$url = new moodle_url('/mod/checklist/add_document.php'); +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + + +// Description ? +if (!$descriptionid && $itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if (!empty($description)){ + $descriptionid=$description->id; + } +} + +$PAGE->set_url($url); +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +require_login($course, true, $cm); + +$context = get_context_instance(CONTEXT_MODULE, $cm->id); + +if (empty($userid)){ + if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; + } +} + + +/// If it's hidden then it's don't show anything. :) +/// Some capability checks. +if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); +} + + +if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } +} + + +if ($chk = new checklist_class($cm->id, 0, $checklist, $cm, $course)) { + $chk->add_document($itemid, $userid, $descriptionid); +} + diff --git a/mod/checklist/autoupdate.php b/mod/checklist/autoupdate.php index 8fdc5f0c..7d0d5442 100644 --- a/mod/checklist/autoupdate.php +++ b/mod/checklist/autoupdate.php @@ -26,6 +26,11 @@ function checklist_autoupdate($courseid, $module, $action, $cmid, $userid, $url, return 0; } + + if ($module == 'referentiel') { + return 0; + } + if ($module == 'course') { return 0; } diff --git a/mod/checklist/backup/moodle2/backup_checklist_stepslib.php b/mod/checklist/backup/moodle2/backup_checklist_stepslib.php index a939124e..0e5928f9 100644 --- a/mod/checklist/backup/moodle2/backup_checklist_stepslib.php +++ b/mod/checklist/backup/moodle2/backup_checklist_stepslib.php @@ -51,6 +51,17 @@ protected function define_structure() { $comment = new backup_nested_element('comment', array('id'), array( 'userid', 'commentby', 'text')); + +// MODIF JF 2012/03/18 + $descriptions = new backup_nested_element('descriptions'); + + $description = new backup_nested_element('description', array('id'), array( + 'userid', 'description', 'timestamp')); + + $documents = new backup_nested_element('documents'); + + $document = new backup_nested_element('document', array('id'), array( + 'descriptionid', 'description_document', 'url_document', 'target', 'title', 'timestamp')); // Build the tree $checklist->add_child($items); @@ -62,6 +73,12 @@ protected function define_structure() { $item->add_child($comments); $comments->add_child($comment); +// MODIF JF 2012/03/18 + $item->add_child($descriptions); + $descriptions->add_child($description); + $description->add_child($documents); + $documents->add_child($document); + // Define sources $checklist->set_source_table('checklist', array('id' => backup::VAR_ACTIVITYID)); @@ -69,6 +86,11 @@ protected function define_structure() { $item->set_source_table('checklist_item', array('checklist' => backup::VAR_PARENTID)); $check->set_source_table('checklist_check', array('item' => backup::VAR_PARENTID)); $comment->set_source_table('checklist_comment', array('itemid' => backup::VAR_PARENTID)); + +// MODIF JF 2012/03/18 + $description->set_source_table('checklist_description', array('itemid' => backup::VAR_PARENTID)); + $document->set_source_table('checklist_document', array('descriptionid' => backup::VAR_PARENTID)); + } else { $item->set_source_sql('SELECT * FROM {checklist_item} WHERE userid = 0 AND checklist = ?', array(backup::VAR_PARENTID)); } @@ -80,10 +102,16 @@ protected function define_structure() { $comment->annotate_ids('user', 'userid'); $comment->annotate_ids('user', 'commentby'); +// MODIF JF 2012/03/18 + $description->annotate_ids('user', 'userid'); + // Define file annotations $checklist->annotate_files('mod_checklist', 'intro', null); // This file area hasn't itemid +// MODIF JF 2012/03/18 + $checklist->annotate_files('mod_checklist', 'document', 'id'); // This file area has itemid + // Return the root element (forum), wrapped into standard activity structure return $this->prepare_activity_structure($checklist); } diff --git a/mod/checklist/backup/moodle2/restore_checklist_activity_task.class.php b/mod/checklist/backup/moodle2/restore_checklist_activity_task.class.php index 342f040b..dcd58903 100644 --- a/mod/checklist/backup/moodle2/restore_checklist_activity_task.class.php +++ b/mod/checklist/backup/moodle2/restore_checklist_activity_task.class.php @@ -71,6 +71,19 @@ static public function define_decode_rules() { $rules[] = new restore_decode_rule('CHECKLISTEDITBYID', '/mod/checklist/edit.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('CHECKLISTEDITBYCHECKLIST', '/mod/checklist/edit.php?checklist=$1', 'checklist'); +// MODIF JF 2012/03/18 + $rules[] = new restore_decode_rule('CHECKLISTEDITBYID', '/mod/checklist/edit_description.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('CHECKLISTEDITBYCHECKLIST', '/mod/checklist/edit_description.php?checklist=$1', 'checklist'); + + $rules[] = new restore_decode_rule('CHECKLISTEDITBYID', '/mod/checklist/edit_document.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('CHECKLISTEDITBYCHECKLIST', '/mod/checklist/edit_document.php?checklist=$1', 'checklist'); + + $rules[] = new restore_decode_rule('CHECKLISTEDITBYID', '/mod/checklist/delete_description.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('CHECKLISTEDITBYCHECKLIST', '/mod/checklist/delete_description.php?checklist=$1', 'checklist'); + + $rules[] = new restore_decode_rule('CHECKLISTEDITBYID', '/mod/checklist/delete_document.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('CHECKLISTEDITBYCHECKLIST', '/mod/checklist/delete_document.php?checklist=$1', 'checklist'); + return $rules; } } diff --git a/mod/checklist/backup/moodle2/restore_checklist_stepslib.php b/mod/checklist/backup/moodle2/restore_checklist_stepslib.php index 18c5df72..2b283182 100644 --- a/mod/checklist/backup/moodle2/restore_checklist_stepslib.php +++ b/mod/checklist/backup/moodle2/restore_checklist_stepslib.php @@ -27,6 +27,10 @@ protected function define_structure() { if ($userinfo) { $paths[] = new restore_path_element('checklist_check', '/activity/checklist/items/item/checks/check'); $paths[] = new restore_path_element('checklist_comment', '/activity/checklist/items/item/comments/comment'); + + + $paths[] = new restore_path_element('checklist_description', '/activity/checklist/items/item/descriptions/description'); + $paths[] = new restore_path_element('checklist_document', '/activity/checklist/items/item/descriptions/description/documents/document'); } // Return the paths wrapped into standard activity structure @@ -119,6 +123,40 @@ protected function process_checklist_comment($data) { $this->set_mapping('checklist_comment', $oldid, $newid); } + + protected function process_checklist_description($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + + $data->itemid = $this->get_new_parentid('checklist_item'); + $data->userid = $this->get_mappingid('user', $data->userid); + if ($data->timestamp > 0) { + $data->timestamp = $this->apply_date_offset($data->timestamp); + } + + $newid = $DB->insert_record('checklist_description', $data); + $this->set_mapping('checklist_description', $oldid, $newid); + } + + + protected function process_checklist_document($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + + $data->descriptionid = $this->get_new_parentid('checklist_description'); + + if ($data->timestamp > 0) { + $data->timestamp = $this->apply_date_offset($data->timestamp); + } + + $newid = $DB->insert_record('checklist_document', $data); + $this->set_mapping('checklist_document', $oldid, $newid); + } + protected function after_execute() { global $DB; diff --git a/mod/checklist/core_modifications.txt b/mod/checklist/core_modifications.txt index 8764cc64..04ebe7a7 100644 --- a/mod/checklist/core_modifications.txt +++ b/mod/checklist/core_modifications.txt @@ -1,7 +1,11 @@ +CheckList - Moodle module + + The changes shown in this file are only needed if you are worried about a short (60 second) delay between students completing an activity and it being checked-off on the checklist. ** If you are happy with this delay, then ignore all of these suggested changes below ** -If this is not acceptable, then you should make the following changes to the Moodle core code (for extra help with this, scroll down to the bottom of this file to see, roughly what the modified files should look like): +If this is not acceptable, then you should make the following changes to the Moodle core code (for extra help +with this, scroll down to the bottom of this file to see, roughly what the modified files should look like): Open the file - moodle/lib/datalib.php Find the function 'add_to_log', then add these lines to the end of it: @@ -26,9 +30,13 @@ $CFG->checklist_autoupdate_use_cron = true; should be changed to: $CFG->checklist_autoupdate_use_cron = false; -To help with modifying the core code to get the 'Check-off modules when complete' feature working, I have included below what the functions will look like after the modification has taken place. Look for the comment '/**** These are the extra lines of code to add for the checklist plugin *****/' to see where the changes have been made. +To help with modifying the core code to get the 'Check-off modules when complete' feature working, +I have included below what the functions will look like after the modification has taken place. +Look for the comment '/**** These are the extra lines of code to add for the checklist plugin *****/' to see +where the changes have been made. -NOTE: This code is taken form Moodle 2.0.1. Do NOT copy and paste the whole functions, as this may not be compatible with your current Moodle version. +NOTE: This code is taken form Moodle 2.0.1. Do NOT copy and paste the whole functions, as this may not +be compatible with your current Moodle version. Please only use this as a guide as to where to insert the extra lines of code. *** lib/datalib.php: diff --git a/mod/checklist/cron_outcomes.php b/mod/checklist/cron_outcomes.php new file mode 100644 index 00000000..3505359d --- /dev/null +++ b/mod/checklist/cron_outcomes.php @@ -0,0 +1,861 @@ +. + +/** + * Get grades and outcomes from modules that are items for checklist module + * uses tables grades_xx and scale_xx + * Select any outcomes used in a Moodle activity + * which belongs to item module checklist + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + +define("CHECKL_MARKING_STUDENT", 0); +define("CHECKL_MARKING_TEACHER", 1); +define("CHECKL_MARKING_BOTH", 2); + +define("CHECKL_TEACHERMARK_NO", 2); +define("CHECKL_TEACHERMARK_YES", 1); +define("CHECKL_TEACHERMARK_UNDECIDED", 0); + +// DEBUG ? +// if to 1 cron trace manythings :)) +define ('CHECKL_DEBUG', 0); // DEBUG INACTIF +// define ('CHECKL_DEBUG', 1); // DEBUG ACTIF : if to 1 cron trace manythings :)) + +define('OUTCOMES_INTERVALLE_JOUR', 2); // cron on 2 last days +// Increase the value to take into account former evaluations + +// ------------------------------------------------- +function checklist_cron_outcomes($starttime=0){ +// Update items of CheckList by the way of outcomes from Moodle activities +global $CFG; +global $DB; +global $scales; +global $OUTPUT; // for icons + + // all users that are subscribed to any post that needs sending + $notations = array(); + $scales = array(); + $n_maj=0; + + $timenow = time(); + if (empty($endtime)){ + $endtime = $timenow; + } + //if (empty($starttime)){ + $starttime = $endtime - OUTCOMES_INTERVALLE_JOUR * 24 * 3600; // Two days earlier + //} + // DEBUG + if (CHECKL_DEBUG){ + $endtime = $timenow; + $starttime = $endtime - OUTCOMES_INTERVALLE_JOUR * 7 * 24 * 3600; // Two weeks earlier + } + + + $scales_list = ''; // for items with a scaleid + + // DEBUG + mtrace("\nCHECKLIST OUTCOMES CRON BEGINNING."); + + + $notations=checklist_get_outcomes($starttime, $endtime); + if (CHECKL_DEBUG){ + mtrace("\nDEBUG :: cron_outcomes.php Line 80 :: \nNOTATIONS\n"); + print_r($notations); + } + + + if ($notations){ + foreach($notations as $notation){ + if ($notation){ + if (CHECKL_DEBUG){ + mtrace("\nDEBUG :: cron_outcomes.php Line 89 :: USERID ".$notation->userid." ; COURSEID ".$notation->courseid."\nNOTATION :\n"); + print_r($notation); + } + + if (!empty($notation->scaleid) && !ereg(" $notation->scaleid\,", $scales_list)){ + $scales_list .= " $notation->scaleid,"; + } + + + if ($m = checklist_get_module_info($notation->module, $notation->moduleinstance, $notation->courseid)){ + // DEBUG + if (CHECKL_DEBUG){ + mtrace("\nDEBUG :: cron_outcomes.php Line 194 :: MODULES \n"); + print_r($m); + } + + $checklist_object= new Object(); + + $checklist_object->competences_activite=$notation->outcomeshortname; + $checklist_object->checklist->id=$notation->instanceid; + $checklist_object->checklist->course=$notation->courseid; + + $checklist_object->checklist_item->checklist=$notation->instanceid; + $checklist_object->checklist_item->id=$notation->itemid; + + $checklist_object->checklist_check->item=$notation->itemid;; + $checklist_object->checklist_check->userid=$notation->userid; + $checklist_object->checklist_check->usertimestamp=$m->date; + $checklist_object->checklist_check->teachermark=CHECKL_MARKING_TEACHER; // A VERIFIER + $checklist_object->checklist_check->teachertimestamp=$m->date; + + $checklist_object->checklist_comment->itemid=$notation->itemid; + $checklist_object->checklist_comment->userid=$notation->userid; + $checklist_object->checklist_comment->commentby=$notation->teacherid; + // add follow_link icon + $checklist_object->checklist_comment->text='['.get_string('modulename', $m->type).' N '.$m->ref_activite + .' '.get_string('linktomodule','checklist').' + '.$m->userdate.'] '.$m->name; + + + $scale = checklist_get_scale($notation->scaleid); + + // DEBUG + // print_object($scale); + + // ------------------ + if ($scale){ + // echo "\n $scale->scale\n"; + // print_r($scale->scaleopt); + // echo $scale->scaleopt[(int)$val]."\n"; + + if ($notation->finalgrade>=$scale->grademax){ + // echo " ---> VALIDE \n"; + $checklist_object->valide=1; + if (checklist_set_outcomes($checklist_object)){ + if (CHECKL_DEBUG){ + mtrace("\nDEBUG :: cron_outcomes.php Line 280\n-----------------\nENREGISTREE\n"); + } + $n_maj++; + } + } + else{ + // echo " ---> INVALIDE \n"; + $checklist_object->valide=0; + } + } + + + + // enregistrer l'activite + // DEBUG + if (CHECKL_DEBUG){ + mtrace("\nDEBUG :: cron_outcomes.php Line 274 ; CHECKLIST OBJECTS\n"); + print_r($checklist_object); + } + + } + } + } + } + + // echo "\n\n"; + mtrace($n_maj.' OUTCOMES-ITEMS CREATED OR MODIFIED.'); + mtrace('END CHECKLIST OUTCOMES CRON.'); + return $n_maj; +} + + +// ------------------------------------------------- +function checklist_get_scale($scaleid){ +// Preload scale objects for items with a scaleid +global $scales; +global $DB; + if ($scaleid){ + if (!empty($scales[$scaleid])){ + // echo "\nDEBUG :: 211 SCALE\n"; + return $scales[$scaleid]; + } + else { + $scale_r = $DB->get_record("scale", array("id" => "$scaleid")); + if ($scale_r){ + $scale = new Object(); + $scale->scaleid = $scaleid; + $scale->scale = $scale_r->scale; + $tscales=explode(',',$scale_r->scale); + // reindex because scale is off 1 + // MDL-12104 some previous scales might have taken up part of the array + // so this needs to be reset + $scale->scaleopt = array(); + $i = 0; + foreach ($tscales as $scaleoption) { + $i++; + $scale->scaleopt[$i] = trim($scaleoption); + } + $scale->grademin=1; + $scale->grademax=$i; + $scales[$scaleid]=$scale; + return $scale; + } + } + } + return NULL; +} + +// ------------------------------------------------- +function checklist_get_module_info($modulename, $moduleinstance, $courseid){ +// retourne les infos concernant ce module +global $CFG; +global $DB; + if (! $course = $DB->get_record("course", array("id" => "$courseid"))) {; + // print_error("DEBUG :: checklist_get_module_info :: This course doesn't exist"); + return false; + } + if (! $module = $DB->get_record("modules", array("name" => "$modulename"))) { + // print_error("DEBUG :: checklist_get_module_info :: This module type doesn't exist"); + return false; + } + if (! $cm = $DB->get_record("course_modules", array("course" => "$course->id", "module" => "$module->id", "instance" => "$moduleinstance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This course module doesn't exist"); + return false; + } + + $mid=0; + $mname=''; + $mdescription=''; + $mlink=''; + + if ($modulename=='forum'){ + if (! $forum = $DB->get_record("forum", array("id" => "$cm->instance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This forum module doesn't exist"); + return false; + } + $mid=$forum->id; + $mname=$forum->name; + $mdescription=$forum->intro; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + // $mlink = $CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id; + } + elseif ($modulename=='assignment'){ + if (! $assignment = $DB->get_record("assignment", array("id" => "$cm->instance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This assignment doesn't exist"); + return false; + } + $mid=$assignment->id; + $mname=$assignment->name; + $mdescription=$assignment->intro; + // $mlink = $CFG->wwwroot.'/mod/assignment/view.php?a='.$assignment->id; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + } + elseif ($modulename=='chat'){ + if (! $chat = $DB->get_record("chat", array("id" => "$cm->instance"))) { + //error("DEBUG :: checklist_get_module_info :: This chat doesn't exist"); + return false; + } + $mid=$chat->id; + $mname=$chat->name; + $mdescription=$chat->intro; + // $mlink = $CFG->wwwroot.'/mod/chat/view.php?id='.$cm->id; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + } + elseif ($modulename=='choice'){ + if (! $choice = $DB->get_record("choice", array("id" => "$cm->instance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This choice module doesn't exist"); + return false; + } + $mid=$choice->id; + $mname=$choice->name; + $mdescription=$choice->intro; + // $mlink = $CFG->wwwroot.'/mod/choice/view.php?id='.$cm->id; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + } + elseif ($modulename=='data'){ + if (! $data = $DB->get_record("data", array("id" => "$cm->instance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This data module doesn't exist"); + return false; + } + $mid=$data->id; + $mname=$data->name; + $mdescription=$data->intro; + // $mlink = $CFG->wwwroot.'/mod/data/view.php?id='.$cm->id; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + +// http://tracker.moodle.org/browse/MDL-15566 +// Notice: Undefined property: stdClass::$cmidnumber in C:\xampp\htdocs\moodle_dev\mod\data\lib.php on line 831 + } + elseif ($modulename=='glossary'){ + if (! $glossary = $DB->get_record("glossary",array("id" => "$cm->instance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This glossary module doesn't exist"); + return false; + } + $mid=$glossary->id; + $mname=$glossary->name; + $mdescription=$glossary->intro; + // $mlink = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + } + else{ + // tentative pour un module generique + if (! $record_module = $DB->get_record($module->name,array("id" => "$cm->instance"))) { + // print_error("DEBUG :: checklist_get_module_info :: This ".$module->name." module doesn't exist"); + return false; + } + $mid=$record_module->id; + $mname=$record_module->name; + if (isset($record_module->intro)){ + $mdescription=$record_module->intro; + } + else if (isset($record_module->info)){ + $mdescription=$record_module->info; + } + else if (isset($record_module->description)){ + $mdescription=$record_module->description; + } + else if (isset($record_module->text)){ + $mdescription=$record_module->text; + } + else{ + $mdescription=get_string('description_inconnue','checklist'); + } + // $mlink = $CFG->wwwroot.'/mod/'.$modulename.'/view.php?id='.$cm->id; + $mlink = new moodle_url('/mod/'.$modulename.'/view.php', array('id' => $cm->id)); + } + + $m=new Object(); + $m->id=$module->id; + $m->type=$modulename; + $m->instance=$moduleinstance; + $m->course=$courseid; + $m->date=$cm->added; + $m->userdate=userdate($cm->added); + $m->ref_activite=$mid; + $m->name=$mname; + $m->description=$mdescription; + $m->link=$mlink; + + return $m; +} + +// ------------------------------------------------- +function checklist_get_outcomes($starttime, $endtime){ +// genere le liste des notations +global $CFG; +global $DB; +global $t_items_records; + + $notations=array(); + $t_referentiels=array(); + + $t_items_records=array(); + + // selectionner tous les codes outcomes + $params=array(); + $sql = "SELECT {checklist_item}.id AS itemid, + {checklist_item}.displaytext AS displaytext, + {checklist}.id AS instanceid, + {checklist}.course AS courseid + FROM {checklist}, {checklist_item} + WHERE {checklist}.id={checklist_item}.checklist + ORDER BY {checklist}.course ASC, {checklist}.id ASC, {checklist_item}.displaytext ASC "; + /* + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("\nDEBUG :: ./mod/checklist/cron_outcomes.php\nLine 353 :: SQL:$sql\n"); + print_r($params); + } + */ + + $r_checklists=$DB->get_records_sql($sql, $params); + if ($r_checklists){ + /* + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php\nLine 363 :: COMPOSITE DATA\n"); + print_r($r_checklists); + } + */ + foreach($r_checklists as $r_checklist){ + $item_outcome=new Object(); + $item_outcome->itemid=$r_checklist->itemid; + $item_outcome->displaytext=$r_checklist->displaytext; + $item_outcome->courseid=$r_checklist->courseid; + $item_outcome->instanceid=$r_checklist->instanceid; + $item_outcome->outcome=''; + $item_outcome->code_referentiel=''; + $item_outcome->code_competence=''; + + + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php\nLine 380 :: COMPOSITE DATA\n"); + print_r($r_checklist); + } + + // First extrac outcomes from items list + // Searched matches + // C2i2e-2011 A.1-1 :: Identifier les personnes resso... + if (preg_match('/(.*)::(.*)/i', $r_checklist->displaytext, $matches)){ + // DEBUG + + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php\nLine 391 :: MATCHES\n"); + print_r($matches); + } + + if ($matches[1]){ + // + $item_outcome->outcome=trim($matches[1]); + if ($keywords = preg_split("/[\s]+/",$matches[1],-1,PREG_SPLIT_NO_EMPTY)){ + + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php\nLine 401 :: REFERENTIELS\n"); + print_r($keywords); + } + + + if ($keywords[0]){ + $item_outcome->code_referentiel=trim($keywords[0]); + } + if ($keywords[1]){ + $item_outcome->code_competence=trim($keywords[1]); + } + } + } + + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php\nLine 417 :: ITEM_OUTCOME\n"); + print_r($item_outcome); + } + + + } + + if (!empty($item_outcome->code_referentiel)){ + +/* + +-- +-- Structure of table 'mdl_grade_outcomes' +-- + +CREATE TABLE mdl_grade_outcomes ( + id bigint(10) unsigned NOT NULL AUTO_INCREMENT, + courseid bigint(10) unsigned DEFAULT NULL, + shortname varchar(255) NOT NULL DEFAULT '', + fullname text NOT NULL, + scaleid bigint(10) unsigned DEFAULT NULL, + description text, + timecreated bigint(10) unsigned DEFAULT NULL, + timemodified bigint(10) unsigned DEFAULT NULL, + usermodified bigint(10) unsigned DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY mdl_gradoutc_cousho_uix (courseid,shortname), + KEY mdl_gradoutc_cou_ix (courseid), + KEY mdl_gradoutc_sca_ix (scaleid), + KEY mdl_gradoutc_use_ix (usermodified) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='This table describes the outcomes used in the system. An out'; +*/ + + $params=array("fullname" => "$item_outcome->outcome%") ; + $sql = "SELECT id, courseid, shortname, fullname, scaleid + FROM {grade_outcomes} + WHERE fullname LIKE :fullname + ORDER BY fullname ASC "; + // DEBUG + + if (CHECKL_DEBUG && false){ + mtrace("\nDEBUG :: ./mod/checklist/cron_outcomes.php\nLine 458 :: SQL:$sql\n"); + print_r($params); + } + + + $r_outcomes=$DB->get_records_sql($sql, $params); + if ($r_outcomes){ + foreach($r_outcomes as $r_outcome){ + // selectionner les items (activites utilisant ces outcomes) + // DEBUG + /* + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php Line 610 :: R_OUTCOMES\n"); + print_r($r_outcome); + echo "\n\n"; + } + */ + +/* + +CREATE TABLE mdl_grade_items ( + id bigint(10) unsigned NOT NULL AUTO_INCREMENT, + courseid bigint(10) unsigned DEFAULT NULL, + categoryid bigint(10) unsigned DEFAULT NULL, + itemname varchar(255) DEFAULT NULL, + itemtype varchar(30) NOT NULL DEFAULT '', + itemmodule varchar(30) DEFAULT NULL, + iteminstance bigint(10) unsigned DEFAULT NULL, + itemnumber bigint(10) unsigned DEFAULT NULL, + iteminfo mediumtext, + idnumber varchar(255) DEFAULT NULL, + calculation mediumtext, + gradetype smallint(4) NOT NULL DEFAULT '1', + grademax decimal(10,5) NOT NULL DEFAULT '100.00000', + grademin decimal(10,5) NOT NULL DEFAULT '0.00000', + scaleid bigint(10) unsigned DEFAULT NULL, + outcomeid bigint(10) unsigned DEFAULT NULL, + gradepass decimal(10,5) NOT NULL DEFAULT '0.00000', + multfactor decimal(10,5) NOT NULL DEFAULT '1.00000', + plusfactor decimal(10,5) NOT NULL DEFAULT '0.00000', + aggregationcoef decimal(10,5) NOT NULL DEFAULT '0.00000', + sortorder bigint(10) NOT NULL DEFAULT '0', + display bigint(10) NOT NULL DEFAULT '0', + decimals tinyint(1) unsigned DEFAULT NULL, + hidden bigint(10) NOT NULL DEFAULT '0', + locked bigint(10) NOT NULL DEFAULT '0', + locktime bigint(10) unsigned NOT NULL DEFAULT '0', + needsupdate bigint(10) NOT NULL DEFAULT '0', + timecreated bigint(10) unsigned DEFAULT NULL, + timemodified bigint(10) unsigned DEFAULT NULL, + PRIMARY KEY (id), + KEY mdl_graditem_locloc_ix (locked,locktime), + KEY mdl_graditem_itenee_ix (itemtype,needsupdate), + KEY mdl_graditem_gra_ix (gradetype), + KEY mdl_graditem_idncou_ix (idnumber,courseid), + KEY mdl_graditem_cou_ix (courseid), + KEY mdl_graditem_cat_ix (categoryid), + KEY mdl_graditem_sca_ix (scaleid), + KEY mdl_graditem_out_ix (outcomeid) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='This table keeps information about gradeable items (ie colum'; + +INSERT INTO `mdl_grade_items` (`id`, `courseid`, `categoryid`, `itemname`, `itemtype`, `itemmodule`, `iteminstance`, `itemnumber`, `iteminfo`, `idnumber`, `calculation`, `gradetype`, `grademax`, `grademin`, `scaleid`, `outcomeid`, `gradepass`, `multfactor`, `plusfactor`, `aggregationcoef`, `sortorder`, `display`, `decimals`, `hidden`, `locked`, `locktime`, `needsupdate`, `timecreated`, `timemodified`) +VALUES(1, 2, NULL, NULL, 'course', NULL, 1, NULL, NULL, NULL, NULL, 1, '100.00000', '0.00000', NULL, NULL, '0.00000', '1.00000', '0.00000', '0.00000', 1, 0, NULL, 0, 0, 0, 0, 1260780703, 1260780703); +... +INSERT INTO `mdl_grade_items` (`id`, `courseid`, `categoryid`, `itemname`, `itemtype`, `itemmodule`, `iteminstance`, `itemnumber`, `iteminfo`, `idnumber`, `calculation`, `gradetype`, `grademax`, `grademin`, `scaleid`, `outcomeid`, `gradepass`, `multfactor`, `plusfactor`, `aggregationcoef`, `sortorder`, `display`, `decimals`, `hidden`, `locked`, `locktime`, `needsupdate`, `timecreated`, `timemodified`) +VALUES (9, 2, 1, 'C2i2e B.4.1', 'mod', 'assignment', 1, 1003, NULL, NULL, NULL, 2, '3.00000', '1.00000', 2, 27, '0.00000', '1.00000', '0.00000', '0.00000', 5, 0, NULL, 0, 0, 0, 0, 1266785659, 1266785659); +*/ + $params=array("outcomeid" => $r_outcome->id, "courseid" => $item_outcome->courseid); + $sql = "SELECT `id`, `courseid`, `categoryid`, `itemname`, `itemtype`, `itemmodule`, `iteminstance`, `itemnumber`, `iteminfo`, `idnumber`, `calculation`, `gradetype`, `grademax`, `grademin`, `scaleid`, `outcomeid`, `timemodified` + FROM {grade_items} WHERE outcomeid= :outcomeid AND courseid=:courseid + ORDER BY courseid, outcomeid ASC "; + + $r_items=$DB->get_records_sql($sql, $params); + if ($r_items){ + foreach($r_items as $r_item){ + // selectionner les items (activites) utilisant ces outcomes + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php\nLine 675 :: ITEMS\n"); + print_r($r_item); + } + + // selectionner les grades (notes attribuées aux utilisateur de ces activités) +/* +-- +-- Structure de la table 'mdl_grade_grades' +-- + +CREATE TABLE mdl_grade_grades ( + id bigint(10) unsigned NOT NULL AUTO_INCREMENT, + itemid bigint(10) unsigned NOT NULL, + userid bigint(10) unsigned NOT NULL, + rawgrade decimal(10,5) DEFAULT NULL, + rawgrademax decimal(10,5) NOT NULL DEFAULT '100.00000', + rawgrademin decimal(10,5) NOT NULL DEFAULT '0.00000', + rawscaleid bigint(10) unsigned DEFAULT NULL, + usermodified bigint(10) unsigned DEFAULT NULL, + finalgrade decimal(10,5) DEFAULT NULL, + hidden bigint(10) unsigned NOT NULL DEFAULT '0', + locked bigint(10) unsigned NOT NULL DEFAULT '0', + locktime bigint(10) unsigned NOT NULL DEFAULT '0', + exported bigint(10) unsigned NOT NULL DEFAULT '0', + overridden bigint(10) unsigned NOT NULL DEFAULT '0', + excluded bigint(10) unsigned NOT NULL DEFAULT '0', + feedback mediumtext, + feedbackformat bigint(10) unsigned NOT NULL DEFAULT '0', + information mediumtext, + informationformat bigint(10) unsigned NOT NULL DEFAULT '0', + timecreated bigint(10) unsigned DEFAULT NULL, + timemodified bigint(10) unsigned DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY mdl_gradgrad_useite_uix (userid,itemid), + KEY mdl_gradgrad_locloc_ix (locked,locktime), + KEY mdl_gradgrad_ite_ix (itemid), + KEY mdl_gradgrad_use_ix (userid), + KEY mdl_gradgrad_raw_ix (rawscaleid), + KEY mdl_gradgrad_use2_ix (usermodified) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='grade_grades This table keeps individual grades for each us'; + +-- +-- Contenu de la table 'mdl_grade_grades' +-- + +INSERT INTO mdl_grade_grades (id, itemid, userid, rawgrade, rawgrademax, rawgrademin, rawscaleid, usermodified, finalgrade, hidden, locked, locktime, exported, overridden, excluded, feedback, feedbackformat, information, informationformat, timecreated, timemodified) VALUES +(1, 3, 2, '2.00000', '3.00000', '1.00000', 1, 4, '2.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266662583), +(2, 1, 2, NULL, '100.00000', '0.00000', NULL, NULL, '50.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL), +(3, 3, 3, '3.00000', '3.00000', '1.00000', 1, 2, '3.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266664474), +(4, 1, 3, NULL, '100.00000', '0.00000', NULL, NULL, '100.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL), +(5, 4, 3, NULL, '100.00000', '0.00000', NULL, 2, '3.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266663872), +(6, 5, 3, '3.00000', '3.00000', '1.00000', 2, 4, '3.00000', 0, 0, 0, 0, 0, 0, 'OK ', 1, NULL, 0, 1266785814, 1266785949), +(7, 6, 3, NULL, '100.00000', '0.00000', NULL, 4, '2.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266785948), +(8, 7, 3, NULL, '100.00000', '0.00000', NULL, 4, '3.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266785949), +(9, 8, 3, NULL, '100.00000', '0.00000', NULL, 4, '3.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266785949), +(10, 9, 3, NULL, '100.00000', '0.00000', NULL, 4, '3.00000', 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL, 1266785949); + +*/ + + + + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php Line 738\n"); + mtrace ("CHECKLIST INSTANCE : ".$item_outcome->instanceid."\nCOURSE ID: ".$item_outcome->courseid."\n"); + mtrace ("DISPLAY : ".$item_outcome->displaytext."\n"); + mtrace ("ITEM CHECKLIST : ".$item_outcome->itemid."\n"); + mtrace ("REFERENTIEL : ".$item_outcome->code_referentiel."\n"); + mtrace ("COMPETENCE : ".$item_outcome->code_competence."\n"); + mtrace ("OUTCOME : ".$item_outcome->outcome."\n"); + mtrace ("OBJECTIF : Id:".$r_outcome->id." Nom:".$r_outcome->fullname."\n"); + mtrace ("GRADE ITEM: Num_Cours:".$r_item->courseid.", Nom_Item:".$r_item->itemname.", module:".$r_item->itemmodule.", instance:".$r_item->iteminstance.", Num_Objectif:".$r_item->outcomeid); + } + + $params=array("itemid"=>$r_item->id, "starttime" =>$starttime, "endtime" => $endtime); + $sql = "SELECT id, itemid, userid, usermodified, rawscaleid, finalgrade, timemodified + FROM {grade_grades} WHERE itemid=:itemid AND ((timemodified>=:starttime) + AND (timemodified < :endtime)) ORDER BY itemid ASC, userid ASC "; + + // DEBUG + if (CHECKL_DEBUG && false){ + mtrace("DEBUG :: ./mod/checklist/cron_outcomes.php Line 739 ::\nSQL = $sql\n"); + print_r($params); + } + + $r_grades=$DB->get_records_sql($sql, $params); + if ($r_grades){ + foreach($r_grades as $r_grade){ + if ($r_grade){ + // stocker l'activite pour traitement + $notation=new Object(); + $notation->instanceid=$item_outcome->instanceid; + $notation->courseid=$item_outcome->courseid; + $notation->itemid=$item_outcome->itemid; + $notation->code_referentiel=$item_outcome->code_referentiel; + $notation->outcomeid= $r_outcome->id; + $notation->outcomeshortname= $r_outcome->shortname; + $notation->scaleid= $r_outcome->scaleid; + $notation->itemname= $r_item->itemname; + $notation->module= $r_item->itemmodule; + $notation->moduleinstance= $r_item->iteminstance; + $notation->userid=$r_grade->userid; + $notation->teacherid=$r_grade->usermodified; + $notation->finalgrade=$r_grade->finalgrade; + $notation->timemodified=$r_grade->timemodified; + $notations[]= $notation; + } + } + } + } + } + } + } + } + } + } + + return $notations; +} + + +/** + * Given an object containing all the necessary data, + * this function will update an outcome-item and return the id number + * + * @param object $checklist_object a special composite checklist object + * @param object $m a special module object + * @return int the id of the newly inserted record or updated + **/ +function checklist_set_outcomes($checklist_object) { +// creation / update item object +global $CFG; +global $DB; + + $ok=false; + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\nDEBUG :: checklist_activite_outcomes :: 705\nDEMANDE DE MISE A JOUR\n"); + print_r($checklist_object); + } + + // Cette CheckList est-elle enregistree ? + $params=array("id"=>$checklist_object->checklist->id, + "course"=>$checklist_object->checklist->course); + + $sql = "SELECT * FROM {checklist} WHERE id=:id AND course=:course"; + if (CHECKL_DEBUG){ + mtrace("\n715 :: SQL:\n$sql\n"); + print_r($params); + } + + $r_checklist=$DB->get_record_sql($sql, $params); + + if ($r_checklist) { + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\nDEBUG :: checklist_activite_outcomes :: 697\n"); + print_r($r_checklist); + } + + // Verify item existence + $params=array("checklist"=>$checklist_object->checklist->id, + "id"=>$checklist_object->checklist_item->id); + + $sql = "SELECT * FROM {checklist_item} WHERE id=:id AND checklist=:checklist"; + if (CHECKL_DEBUG){ + mtrace("\n710 :: SQL:\n$sql\n"); + print_r($params); + } + $r_checklist_item=$DB->get_record_sql($sql, $params); + if ($r_checklist_item) { + $checklist_check=new Object(); + $checklist_check->item=$checklist_object->checklist_check->item; + $checklist_check->userid=$checklist_object->checklist_check->userid; + $checklist_check->usertimestamp=$checklist_object->checklist_check->usertimestamp; + $checklist_check->teachermark=$checklist_object->checklist_check->teachermark; + $checklist_check->teachertimestamp=$checklist_object->checklist_check->teachertimestamp; + + // Verifier si cet utilisateur est deja reférencé pour cet ITEM + $params=array("item"=>$checklist_object->checklist_item->id, + "userid"=>$checklist_object->checklist_check->userid); + + $sql = "SELECT * FROM {checklist_check} WHERE item=:item AND userid=:userid"; + if (CHECKL_DEBUG){ + mtrace("\n728 :: SQL:\n$sql\n"); + print_r($params); + } + $checklist_object_old=$DB->get_record_sql($sql, $params); + if ($checklist_object_old) { + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\n735 :: OLD\n"); + print_r($checklist_object_old); + } + + $checklist_check->id=$checklist_object_old->id; + $checklist_check->usertimestamp=$checklist_object_old->usertimestamp; + if (empty($checklist_check->usertimestamp)){ + $checklist_check->usertimestamp=time(); + } + + if ($checklist_object_old->teachermark==CHECKL_MARKING_STUDENT){ + $checklist_check->teachermark=CHECKL_MARKING_BOTH; + } + else{ + $checklist_check->teachermark=CHECKL_MARKING_TEACHER; + } + + if (empty($checklist_object_old->teachertimestamp) + || ($checklist_object_old->teachertimestamp<$checklist_check->teachertimestamp)){ + $checklist_check->teachertimestamp=time(); + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\n757 :: MISE A JOUR CHECKLIST_CHECK\n"); + print_r($checklist_check); + } + $ok=$DB->update_record("checklist_check", $checklist_check); + + if (CHECKL_DEBUG){ + // DEBUG + if ($ok) mtrace("\n764 :: UPDATE CHECK\n"); + else mtrace("\n65 :: ERREUR UPDATE CHECK\n"); + print_r($checklist_check); + } + } + } + else{ + // add a new line in table + $checklist_check->usertimestamp=0; + if ($checklist_check->teachertimestamp==0){ + $checklist_check->teachertimestamp=time(); + } + $checklist_check->teachermark=CHECKL_TEACHERMARK_YES; + + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\n780 :: NEW CREATED\n"); + print_r($checklist_check); + } + $checklist_check_id=$DB->insert_record("checklist_check", $checklist_check); + if ($checklist_check_id) { + $ok=true; + } + if (CHECKL_DEBUG){ + // DEBUG + if ($ok) mtrace("\n789 :: INSERT CHECK\n"); + else mtrace("\n790 :: ERREUR INSERT CHECK\n"); + print_r($checklist_check); + } + } + + // Commentaires + if ($ok){ + $checklist_comment=new Object(); + $checklist_comment->id=0; + $checklist_comment->itemid=$checklist_object->checklist_comment->itemid; + $checklist_comment->userid=$checklist_object->checklist_comment->userid; + $checklist_comment->commentby=$checklist_object->checklist_comment->commentby; + $checklist_comment->text=$checklist_object->checklist_comment->text; + + // Verifier si cet utilisateur est deja reférencé pour un commentaire + $params=array("item"=>$checklist_object->checklist_item->id, + "userid"=>$checklist_object->checklist_comment->userid); + + $sql = "SELECT * FROM {checklist_comment} WHERE itemid=:item AND userid=:userid"; + if (CHECKL_DEBUG){ + mtrace("\n810 :: SQL:\n$sql\n"); + print_r($params); + } + $checklist_comment_old=$DB->get_record_sql($sql, $params); + if ($checklist_comment_old) { + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\n817 :: OLD COMMENT\n"); + print_r($checklist_comment_old); + } + + $checklist_comment->id=$checklist_comment_old->id; + /* + if (!empty($checklist_comment_old->text)){ + $checklist_comment->text='['.get_string('old_comment', 'checklist').' '.userdate($checklist_comment_old->commentby).' '.$checklist_comment_old->text.']
'.$checklist_comment->text; + } + */ + if (CHECKL_DEBUG){ + // DEBUG + mtrace("\n829 :: MISE A JOUR CHECKLIST_COMMENT\n"); + print_r($checklist_comment); + } + $ok=$ok && $DB->update_record("checklist_comment", $checklist_comment); + } + else{ + $ok=$ok && $DB->insert_record("checklist_comment", $checklist_comment); + } + } + } + else { + // NOTHING TO DO + // We 'll not add any ITEM to CHECKLIST_ITEM NOW... Nop ! + $ok=false; + } + } + else{ + $ok=false; + } + return $ok; +} + + +?> diff --git a/mod/checklist/db/access.php b/mod/checklist/db/access.php index 7bf5b081..6eddcc9b 100644 --- a/mod/checklist/db/access.php +++ b/mod/checklist/db/access.php @@ -20,100 +20,89 @@ */ $capabilities = array( - // Check if user is able to add a checklist module (M2.3+ only) - 'mod/checklist:addinstance' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + // Ability to view and update own checklist + 'mod/checklist:updateown' => array( + 'riskbitmask' => RISK_SPAM, + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'student' => CAP_ALLOW + ) + ), - // Ability to view and update own checklist - 'mod/checklist:updateown' => array( - 'riskbitmask' => RISK_SPAM, - 'captype' => 'write', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'student' => CAP_ALLOW - ) - ), + // Ability to alter the marks on another person's checklist + 'mod/checklist:updateother' => array( + 'riskbitmask' => RISK_PERSONAL | RISK_SPAM, + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), - // Ability to alter the marks on another person's checklist - 'mod/checklist:updateother' => array( - 'riskbitmask' => RISK_PERSONAL | RISK_SPAM, - 'captype' => 'write', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + // Ability to preview a checklist (to check it is OK) + 'mod/checklist:preview' => array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), - // Ability to preview a checklist (to check it is OK) - 'mod/checklist:preview' => array( - 'captype' => 'read', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + // Ability to check up on the progress of all users through + // their checklists + 'mod/checklist:viewreports' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), - // Ability to check up on the progress of all users through - // their checklists - 'mod/checklist:viewreports' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'read', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + // Ability to view reports related to their 'mentees' only + 'mod/checklist:viewmenteereports' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array() // Not assigned by default + ), - // Ability to view reports related to their 'mentees' only - 'mod/checklist:viewmenteereports' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'read', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array() // Not assigned by default - ), + // Ability to create and manage checklists + 'mod/checklist:edit' => array( + 'riskbitmask' => RISK_SPAM, + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), - // Ability to create and manage checklists - 'mod/checklist:edit' => array( - 'riskbitmask' => RISK_SPAM, - 'captype' => 'write', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + // Will receive emails when checklists complete (if checklist is set to do so) + 'mod/checklist:emailoncomplete' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'editingteacher' => CAP_ALLOW, + 'teacher' => CAP_ALLOW + ) + ), - // Will receive emails when checklists complete (if checklist is set to do so) - 'mod/checklist:emailoncomplete' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'read', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'editingteacher' => CAP_ALLOW, - 'teacher' => CAP_ALLOW - ) - ), - - // Can update teacher checklist marks even if locked - 'mod/checklist:updatelocked' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ) + // Can update teacher checklist marks even if locked + 'mod/checklist:updatelocked' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ) ); diff --git a/mod/checklist/db/install.xml b/mod/checklist/db/install.xml index 0fb7ecfa..4a69dd6c 100644 --- a/mod/checklist/db/install.xml +++ b/mod/checklist/db/install.xml @@ -79,7 +79,7 @@ - +
@@ -94,5 +94,41 @@
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + diff --git a/mod/checklist/db/upgrade.php b/mod/checklist/db/upgrade.php index 0c0d8632..226e8f9d 100644 --- a/mod/checklist/db/upgrade.php +++ b/mod/checklist/db/upgrade.php @@ -256,6 +256,57 @@ function xmldb_checklist_upgrade($oldversion=0) { upgrade_mod_savepoint($result, 2011082001, 'checklist'); } + + if ($result && $oldversion < 2012041100) { + + /// Define table checklist_description to be created + $table = new xmldb_table('checklist_description'); + + /// Adding fields to table checklist_description + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_field('description', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); + $table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + + /// Adding keys to table checklist_description + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Adding indexes to table checklist_description + $table->add_index('checklist_item_user', XMLDB_INDEX_UNIQUE, array('itemid', 'userid')); + + /// Conditionally launch create table for checklist_description + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Define table checklist_document to be created + $table = new xmldb_table('checklist_document'); + + /// Adding fields to table checklist_document + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('descriptionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_field('description_document', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); + $table->add_field('url_document', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); + $table->add_field('target', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); + $table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + + /// Adding keys to table checklist_document + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Adding indexes to table checklist_document + $table->add_index('index_description', XMLDB_INDEX_NOTUNIQUE, array('descriptionid')); + + /// Conditionally launch create table for checklist_document + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + upgrade_mod_savepoint($result, 2012041100, 'checklist'); + + } + return $result; } diff --git a/mod/checklist/delete_description.php b/mod/checklist/delete_description.php new file mode 100644 index 00000000..b88ae175 --- /dev/null +++ b/mod/checklist/delete_description.php @@ -0,0 +1,108 @@ +. + +/** + * Delete a description attached to an Item + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +require_once(dirname(__FILE__).'/file_api.php'); // Moodle 2 file API +require_once(dirname(dirname(dirname(__FILE__))).'/repository/lib.php'); // Repository API + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$descriptionid = optional_param('descriptionid', 0, PARAM_INT); // document ID +$cancel = optional_param('cancel', 0, PARAM_BOOL); + + +$url = new moodle_url('/mod/checklist/delete_description.php'); + +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + +$PAGE->set_url($url); +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +require_login($course, true, $cm); + +if ($CFG->version < 2011120100) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); +} else { + $context = context_module::instance($cm->id); +} + +$userid = 0; +if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; +} + + +/// If it's hidden then it's don't show anything. :) +/// Some capability checks. +if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); +} + + +if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } +} + + +if ($chk = new checklist_class($cm->id, 0, $checklist, $cm, $course)) { + $chk->delete_description($descriptionid); +} + + + diff --git a/mod/checklist/delete_document.php b/mod/checklist/delete_document.php new file mode 100644 index 00000000..c439ba84 --- /dev/null +++ b/mod/checklist/delete_document.php @@ -0,0 +1,108 @@ +. + +/** + * Delete a document attached to a description + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +require_once(dirname(__FILE__).'/file_api.php'); // Moodle 2 file API +require_once(dirname(dirname(dirname(__FILE__))).'/repository/lib.php'); // Repository API + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$documentid = optional_param('documentid', 0, PARAM_INT); // document ID +$cancel = optional_param('cancel', 0, PARAM_BOOL); + + +$url = new moodle_url('/mod/checklist/delete_document.php'); + +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + +$PAGE->set_url($url); +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +require_login($course, true, $cm); + +if ($CFG->version < 2011120100) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); +} else { + $context = context_module::instance($cm->id); +} + +$userid = 0; +if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; +} + + +/// If it's hidden then it's don't show anything. :) +/// Some capability checks. +if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); +} + + +if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } +} + + +if ($chk = new checklist_class($cm->id, 0, $checklist, $cm, $course)) { + $chk->delete_document($documentid); +} + + + diff --git a/mod/checklist/developers_documentation.txt b/mod/checklist/developers_documentation.txt new file mode 100644 index 00000000..eb05eb1a --- /dev/null +++ b/mod/checklist/developers_documentation.txt @@ -0,0 +1,123 @@ +CheckList - Moodle module + +This is a developer's documentation +=========================================================================================== + +// Modifications by jean.fruitet@univ-nantes.fr + + +I made additions to original code to get some new functionnalities + +CheckList Version : $module->release = 'JF-2.x (Build: 2012041100)'; +This is a fork of Master repository + + +1) Users may comment their Skills and upload files or URL as prove of practice. +---------------------------------------------------------------------------------- + +a) New DB tables 'checklist_description' and 'checklist_document' + +b) New config parameter : +$CFG->checklist_description_display +New script +./mod/checklist/settings.php + +c) New scripts +edit_description.php +edit_document.php +delete_description.php +delete_document.php +file_api.php + +d) Scripts modification +lib.php : + + // MOODLE 2.0 FILE API + function checklist_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { + //Serves activite documents and other files. + function checklist_send_file($course, $cm, $context, $filearea, $args) { + // Serves activite documents and other files. + +locallib.php : many functions added or modified (Look for "// MODIF JF" tag.) + +Class checklist_class { + +(...) + // MODIF JF 2012/03/18 + /* BEGIN OF FUNCTIONS ADDED BY JF ***** */ + (...) + /* END OF FUNCTIONS ADDED BY JF ** */ + +} + + +2) Import of Outcomes file (csv format) to get Outcomes as Items in CheckList +------------------------------------------------------------------------------ + +Teachers may import Outcomes (outcomes.csv) files in CheckList to get these outcomes as Items. +Furthermore any Item of CheckList may be validated by the way of Moodle activity +(Assignment or Quizz for exemple) which uses the same Outcomes. + +a) This does not affect any CheckList DB tables + +b) New config parameter : +$CFG->checklist_outcomes_input + +c) New scripts : + +importexportoutcomes.php +import_outcomes.php +export_outcomes.php +select_export.php +cron_outcomes.php + +d) Scripts modification +lib.php :: +// MODIF JF 2012/03/18 +define ("USES_OUTCOMES", 1); // Outcomes imported as items + +locallib.php :: +function view_import_export() { +(...) + // MODIF JF 2012/03/18 + if (USES_OUTCOMES && !empty($CFG->checklist_outcomes_input)){ + $importoutcomesurl = new moodle_url('/mod/checklist/import_outcomes.php', array('id' => $this->cm->id)); + $importoutcomesstr = get_string('import_outcomes', 'checklist'); + $exportoutcomesurl = new moodle_url('/mod/checklist/select_export.php', array('id' => $this->cm->id)); + $exportoutcomesstr = get_string('export_outcomes', 'checklist'); + echo "$importstr  $importoutcomesstr  $exportstr  $exportoutcomesstr"; + } + else{ + echo "$importstr     $exportstr"; + } +(...) +} + +autoupdate.php +In function checklist_autoupdate( + // MODIF JF 2012/03/18 + if ($module == 'referentiel') { + return 0; + } + +New localisation strings + +lang/en/checklist.php :: new strings +lang/fr/checklist.php :: new strings and translation + +Functions replacement : +In all scripts +error('error_message') -> print_error(get_string('error_code', 'checklist')); + + +3) Backup / Restore : +------------------------------------------------------------------------------ +./mod/checklist/backup/moodle2 scripts completed for new tables + +4) Installation +------------------------------------------------------------------------------ +./mod/checklist/install.xml +./mod/checklist/upgrade.php + + +=========================================================================================== diff --git a/mod/checklist/edit.php b/mod/checklist/edit.php index 851c6df7..bab9bbc8 100644 --- a/mod/checklist/edit.php +++ b/mod/checklist/edit.php @@ -26,35 +26,24 @@ $url = new moodle_url('/mod/checklist/view.php'); if ($id) { - if (! $cm = get_coursemodule_from_id('checklist', $id)) { - error('Course Module ID was incorrect'); - } - - if (! $course = $DB->get_record('course', array('id' => $cm->course) )) { - error('Course is misconfigured'); - } - - if (! $checklist = $DB->get_record('checklist', array('id' => $cm->instance) )) { - error('Course module is incorrect'); + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); $url->param('id', $id); - } else if ($checklistid) { - if (! $checklist = $DB->get_record('checklist', array('id' => $checklistid) )) { - error('Course module is incorrect'); - } - if (! $course = $DB->get_record('course', array('id' => $checklist->course) )) { - error('Course is misconfigured'); - } - if (! $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { - error('Course Module ID was incorrect'); + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } $url->param('checklist', $checklistid); - } else { - error('You must specify a course_module ID or an instance ID'); + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' } + $PAGE->set_url($url); require_login($course, true, $cm); diff --git a/mod/checklist/edit_description.php b/mod/checklist/edit_description.php new file mode 100644 index 00000000..783d7dee --- /dev/null +++ b/mod/checklist/edit_description.php @@ -0,0 +1,106 @@ +. + + +/** + * Input a description attached to an Item + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +require_once(dirname(__FILE__).'/file_api.php'); // Moodle 2 file API +require_once(dirname(dirname(dirname(__FILE__))).'/repository/lib.php'); // Repository API + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$itemid = optional_param('itemid', 0, PARAM_INT); // Item ID +$userid = optional_param('userid', 0, PARAM_INT); // userID +$cancel = optional_param('cancel', 0, PARAM_BOOL); + + +$url = new moodle_url('/mod/checklist/edit_description.php'); +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + + +$PAGE->set_url($url); +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +require_login($course, true, $cm); + +$context = get_context_instance(CONTEXT_MODULE, $cm->id); + +if (empty($userid)){ + if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; + } +} + + +/// If it's hidden then it's don't show anything. :) +/// Some capability checks. +if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); +} + + +if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } +} + + +if ($chk = new checklist_class($cm->id, 0, $checklist, $cm, $course)) { + $chk->edit_description($itemid, $userid); +} + diff --git a/mod/checklist/edit_document.php b/mod/checklist/edit_document.php new file mode 100644 index 00000000..505e41de --- /dev/null +++ b/mod/checklist/edit_document.php @@ -0,0 +1,113 @@ +. + +/** + * Edit a doccument attached to a Description + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +require_once(dirname(__FILE__).'/file_api.php'); // Moodle 2 file API +require_once(dirname(dirname(dirname(__FILE__))).'/repository/lib.php'); // Repository API + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$itemid = optional_param('itemid', 0, PARAM_INT); // Item ID +$userid = optional_param('userid', 0, PARAM_INT); // userID +$documentid = optional_param('documentid', 0, PARAM_INT); // document ID +$cancel = optional_param('cancel', 0, PARAM_BOOL); + + +$url = new moodle_url('/mod/checklist/edit_document.php'); +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +if ($documentid){ + $document = $DB->get_record('checklist_document', array("id" => $documentid)); +} + +if (empty($document)){ + redirect($returnurl); +} + + $PAGE->set_url($url); + + + require_login($course, true, $cm); + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + if (empty($userid)){ + if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; + } + } + + + /// If it's hidden then it's don't show anything. :) + /// Some capability checks. + if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); + } + + + if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } + } + + if ($chk = new checklist_class($cm->id, 0, $checklist, $cm, $course)) { + $chk->edit_document($itemid, $userid, $document); + } + diff --git a/mod/checklist/export.php b/mod/checklist/export.php index 7fd6cf90..be8282b3 100644 --- a/mod/checklist/export.php +++ b/mod/checklist/export.php @@ -4,19 +4,15 @@ require_once(dirname(__FILE__).'/importexportfields.php'); $id = required_param('id', PARAM_INT); // course module id -if (! $cm = get_coursemodule_from_id('checklist', $id)) { - error('Course Module ID was incorrect'); -} - -if (! $course = $DB->get_record('course', array('id' => $cm->course))) { - error('Course is misconfigured'); -} - -if (! $checklist = $DB->get_record('checklist', array('id' => $cm->instance))) { - error('Course module is incorrect'); +if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } +$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); $url = new moodle_url('/mod/checklist/export.php', array('id' => $cm->id)); +$url->param('id', $id); + $PAGE->set_url($url); require_login($course, true, $cm); @@ -26,12 +22,12 @@ $context = context_module::instance($cm->id); } if (!has_capability('mod/checklist:edit', $context)) { - error('You do not have permission to export items from this checklist'); + print_error(get_string('error_export_items', 'checklist')); // You do not have permission to export items from this checklist' } $items = $DB->get_records_select('checklist_item', "checklist = ? AND userid = 0", array($checklist->id), 'position'); if (!$items) { - error(get_string('noitems', 'checklist')); + print_error(get_string('noitems', 'checklist')); } if (strpos($CFG->wwwroot, 'https://') === 0) { //https sites - watch out for IE! KB812935 and KB316431 diff --git a/mod/checklist/export_selected_outcomes.php b/mod/checklist/export_selected_outcomes.php new file mode 100644 index 00000000..b5974f71 --- /dev/null +++ b/mod/checklist/export_selected_outcomes.php @@ -0,0 +1,163 @@ +. + +/** + * Library of functions and constants for module checklist + * Adapted from export.php to export Skills Repository outcomes files + * + * This script export a selected list of Items of CheckList module as a Skill Repository Outcome file + * exactly like 'referentiel' module + + * ITEMS CSV FILE + * Separator ',' + * Item text,Indent,Type (0 - normal; 1 - optional; 2 - heading),Due Time (timestamp),Colour (red; orange; green; purple; black) + * DES_rhumato,0,0,0,purple + * DES_rhumato UV1.1.1 :: Je sais définir Incidence.,1,0,0,black + * DES_rhumato UV1.1.2 :: Je sais définir Prévalence.,1,0,0,black + * DES_rhumato UV1.2.1 :: Savoir interpréter les résultats d'un essai (...),1,0,0,black + * DES_rhumato UV1.2.2 :: Savoir discuter la pertinence d'un critère d'évaluation.,1,0,0,black + * DES_rhumato UV2.1.1 :: Connaître l’incidence et la prévalence de la (...),1,0,0,black + * DES_rhumato UV2.1.2 :: Connaître les facteurs déclenchant de la PR et les (...),1,0,0,black + * DES_rhumato UV2.1.3 :: Connaître les principaux facteurs d’environnement (...),1,0,0,black + * DES_rhumato UV2.1.4 :: Connaître les principales causes de morbidité et de (...),1,0,0,black + * DES_rhumato UV2.2.1 :: Connaître de façon globale les hypothèses pathogéniques (...),1,0,0,black + * + * OUTCOMES CSV FILE + * Separator ';' + * outcome_name;outcome_shortname;outcome_description;scale_name;scale_items;scale_description + * "DES_rhumato UV1.1.1 :: Je sais définir Incidence.";UV1.1.1;"Je sais définir Incidence.";"Item référentiel";"Non pertinent,Non validé,Validé";"Ce barème est destiné à évaluer l'acquisition des compétences du module référentiel." + * "DES_rhumato UV1.1.2 :: Je sais définir Prévalence.";UV1.1.2;"Je sais définir Prévalence.";"Item référentiel";"Non pertinent,Non validé,Validé";"Ce barème est destiné à évaluer l'acquisition des compétences du module référentiel." + * + * Skills repositoy outcome_name has to match '/(.*)::(.*)/i' regular expression + * That's mandatory + * + * + * @author jfruitet jean.fruitet@univ-nantes.fr + * + * @version $Id: import_outcome.php,v 1.0 2012/03/18 00:00:00 jfruitet Exp $ + * @package checklist 'JF-2.x (Build: 2012041100)'; + **/ + + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/importexportoutcomes.php'); // Outcomes format +require_once(dirname(__FILE__).'/locallib.php'); + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +if ($CFG->version < 2011120100) { + $items = optional_param('items', false, PARAM_INT); +} else { + $items = optional_param_array('items', false, PARAM_INT); +} +$referentielcode = optional_param('referentielcode', '', PARAM_ALPHANUMEXT); +$useitemid = optional_param('useitemid', '', PARAM_INT); +$quit = optional_param('quit', '', PARAM_ALPHANUM); + +$url = new moodle_url('/mod/checklist/export_selected_outcomes.php'); +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + + +if ($quit){ + redirect($urlredirect_suite); +} + +$PAGE->set_url($url); +require_login($course, true, $cm); + +if ($CFG->version < 2011120100) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); +} else { + $context = context_module::instance($cm->id); +} +$userid = $USER->id; +if (!has_capability('mod/checklist:edit', $context)) { + print_error(get_string('error_export_items', 'checklist')); // You do not have permission to export items from this checklist' + die(); +} + +if (!confirm_sesskey()) { + echo get_string('error_sesskey', 'checklist'); // 'Error: invalid sesskey'; + die(); +} + +if (!$items || !is_array($items)) { + print_error('error_select', 'checklist', $urlredirect); // 'You must specify a course_module ID or an instance ID' + // redirect($urlredirect); +} +else{ + // Fichier à creer + $contenu=''; + $chk = new checklist_class($cm->id, $userid, $checklist, $cm, $course); + $selected_items=$chk->exportchecks($items); + if (!empty($selected_items)){ + // Creer le fichier + $ok_referentiel=false; // flag for Skills repository outcomes + + // Output the headings + $contenu = implode($separator_outcomes, array_keys($fields_outcomes))."\n"; + foreach ($selected_items as $an_item) { + if (!empty($an_item->displaytext)){ + $an_outcome=get_outcome_code_from_item($an_item, $referentielcode, $useitemid); + if (!empty($an_outcome) && !empty($an_outcome->outcome) && !empty($an_outcome->code_competence) && !empty($an_outcome->description)){ + $ok_referentiel=true; + $contenu.=str_replace('""','"', $an_outcome->outcome.$separator_outcomes.$an_outcome->code_competence.$separator_outcomes.$an_outcome->description.$separator_outcomes.get_string('scale_name', 'checklist').$separator_outcomes.get_string('scale_items', 'checklist').$separator_outcomes.get_string('scale_description', 'checklist'))."\n"; + } + } + } + + if ($ok_referentiel){ + if (strpos($CFG->wwwroot, 'https://') === 0) { //https sites - watch out for IE! KB812935 and KB316431 + @header('Cache-Control: max-age=10'); + @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT'); + @header('Pragma: '); + } else { //normal http - prevent caching at all cost + @header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'); + @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT'); + @header('Pragma: no-cache'); + } + header("Content-Type: application/download\n"); + $downloadfilename = clean_filename("outcomes_{$course->shortname}_{$checklist->name}_".date("Ymd")); + header("Content-Disposition: attachment; filename=\"$downloadfilename.csv\""); + + echo $contenu; + + // redirect($urlredirect_suite); + } + } +} +exit; diff --git a/mod/checklist/file_api.php b/mod/checklist/file_api.php new file mode 100644 index 00000000..d520b25c --- /dev/null +++ b/mod/checklist/file_api.php @@ -0,0 +1,707 @@ +. + + +/** + * Stores all the functions for manipulating a checklist + * + * @author David Smith + * @package mod/checklist + */ + + /** + * file api package + * @author Jean Fruitet + */ + + +require_once($CFG->libdir.'/formslib.php');//putting this is as a safety as i got a class not found error. + +/** + * @package mod-checklist + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_checklist_description_form extends moodleform { + function definition() { + $mform = & $this->_form; + $instance = $this->_customdata; + // print_object($instance); + // exit; + // visible elements + $mform->addElement('header', 'general', $instance['msg']); + $mform->addHelpButton('general', 'descriptionh','checklist'); + + $mform->addElement('textarea', 'description', get_string('description','checklist'), 'wrap="virtual" rows="6" cols="70"'); + if (!empty($instance['description']) && !empty($instance['description']->description)){ + $mform->setDefault('description', stripslashes($instance['description']->description)); + } + + // hidden params + $mform->addElement('hidden', 'checklist', $instance['checklist']); + $mform->setType('checklist', PARAM_INT); + + + $mform->addElement('hidden', 'descriptionid'); + $mform->setType('descriptionid', PARAM_INT); + if (!empty($instance['description']) && !empty($instance['description']->id)){ + $mform->setDefault('descriptionid', $instance['description']->id); + } + else{ + $mform->setDefault('descriptionid',0); + } + + $mform->addElement('hidden', 'contextid', $instance['contextid']); + $mform->setType('contextid', PARAM_INT); + + $mform->addElement('hidden', 'itemid', $instance['itemid']); + $mform->setType('itemid', PARAM_INT); + + $mform->addElement('hidden', 'userid', $instance['userid']); + $mform->setType('userid', PARAM_INT); + + + // buttons + $this->add_action_buttons(true, get_string('savechanges', 'admin')); + } +} + + + +/** + * @package mod-checklist + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_checklist_add_document_upload_form extends moodleform { + function definition() { + $mform = & $this->_form; + $instance = $this->_customdata; + // print_object($instance); + // exit; + // visible elements + $mform->addElement('header', 'general', $instance['msg']); + $mform->addHelpButton('general', 'documenth','checklist'); + + $mform->addElement('text','description_document',get_string('description_document','checklist')); + $mform->setType('description_document', PARAM_TEXT); + + if (!empty($instance['document']) && isset($instance['document']->description_document)){ + $mform->setDefault('description_document', stripslashes($instance['document']->description_document)); + } + + $mform->addElement('text','title',get_string('title','checklist')); + $mform->setType('title', PARAM_TEXT); + + if (!empty($instance['document']) && isset($instance['document']->title)){ + $mform->setDefault('title', $instance['document']->title); + } + + $mform->addElement('text','url',get_string('url','checklist')); + $mform->setType('url', PARAM_URL); + + if (!empty($instance['document']) && !empty($instance['document']->url_document)){ + $mform->setDefault('url', $instance['document']->url_document); + } + + // $mform->addHelpButton('url', 'documenth','checklist'); + + $radioarray=array(); + $radioarray[] = &MoodleQuickForm::createElement('radio', 'target', '', get_string('yes'), 1, NULL); + $radioarray[] = &MoodleQuickForm::createElement('radio', 'target', '', get_string('no'), 0, NULL); + $mform->addGroup($radioarray, 'target', get_string('target','checklist'), array(' '), false); + if (!empty($instance['document']) && isset($instance['document']->target)){ + $mform->setDefault('target', $instance['document']->target); + }else{ + $mform->setDefault('target', 1); + } + + // Get a file + $mform->addElement('filepicker', 'checklist_file', get_string('uploadafile'), null, $instance['options']); + // $mform->addElement('filemanager', 'checklist_file', get_string('uploadafile'), null, $instance['options']); + + // hidden params + + $mform->addElement('hidden', 'checklist', $instance['checklist']); + $mform->setType('checklist', PARAM_INT); + + + $mform->addElement('hidden', 'descriptionid'); + $mform->setType('descriptionid', PARAM_INT); + if ($instance['descriptionid']){ + $mform->setDefault('descriptionid', $instance['descriptionid']); + } + + $mform->addElement('hidden', 'contextid', $instance['contextid']); + $mform->setType('contextid', PARAM_INT); + + $mform->addElement('hidden', 'itemid', $instance['itemid']); + $mform->setType('itemid', PARAM_INT); + + $mform->addElement('hidden', 'userid', $instance['userid']); + $mform->setType('userid', PARAM_INT); + + $mform->addElement('hidden', 'filearea', $instance['filearea']); + $mform->setType('filearea', PARAM_ALPHA); + + $mform->addElement('hidden', 'action', 'uploadfile'); + $mform->setType('action', PARAM_ALPHA); + + // buttons + $this->add_action_buttons(true, get_string('savechanges', 'admin')); + } +} + + + +/** + * @package mod-checklist + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_checklist_update_document_upload_form extends moodleform { + function definition() { + $mform = & $this->_form; + $instance = $this->_customdata; + // print_object($instance); + // exit; + + // visible elements + $mform->addElement('header', 'general', $instance['msg']); + $mform->addHelpButton('general', 'documenth','checklist'); + + $mform->addElement('text','description_document',get_string('description_document','checklist')); + $mform->setType('description_document', PARAM_TEXT); + + if (!empty($instance['document']) && isset($instance['document']->description_document)){ + $mform->setDefault('description_document', stripslashes($instance['document']->description_document)); + } + + $mform->addElement('text','title',get_string('title','checklist')); + $mform->setType('title', PARAM_TEXT); + + if (!empty($instance['document']) && isset($instance['document']->title)){ + $mform->setDefault('title', $instance['document']->title); + } + + if (!empty($instance['document']) && !empty($instance['document']->url_document)){ + $mform->addElement('html', '        '.get_string('url','checklist').' '.$instance['document']->url_document.''."\n"); + $mform->addElement('hidden', 'url_old', $instance['document']->url_document); + $mform->setType('url_old', PARAM_URL); + } + $mform->addElement('text','url',get_string('url','checklist')); + $mform->setType('url', PARAM_URL); + $mform->setDefault('url', ''); + $mform->addHelpButton('url', 'urlh','checklist'); + + // $mform->addHelpButton('url', 'documenth','checklist'); + + $radioarray=array(); + $radioarray[] = &MoodleQuickForm::createElement('radio', 'target', '', get_string('yes'), 1, NULL); + $radioarray[] = &MoodleQuickForm::createElement('radio', 'target', '', get_string('no'), 0, NULL); + $mform->addGroup($radioarray, 'target', get_string('target','checklist'), array(' '), false); + if (!empty($instance['document']) && isset($instance['document']->target)){ + $mform->setDefault('target', $instance['document']->target); + }else{ + $mform->setDefault('target', 1); + } + + // get a file + $mform->addElement('filepicker', 'checklist_file', get_string('uploadafile'), null, $instance['options']); + + // hidden params + + $mform->addElement('hidden', 'checklist', $instance['checklist']); + $mform->setType('checklist', PARAM_INT); + + $mform->addElement('hidden', 'documentid'); + $mform->setType('documentid', PARAM_INT); + if (!empty($instance['document']) && !empty($instance['document']->id)){ + $mform->setDefault('documentid', $instance['document']->id); + } + + $mform->addElement('hidden', 'descriptionid'); + $mform->setType('descriptionid', PARAM_INT); + if ($instance['descriptionid']){ + $mform->setDefault('descriptionid', $instance['descriptionid']); + } + + $mform->addElement('hidden', 'contextid', $instance['contextid']); + $mform->setType('contextid', PARAM_INT); + + $mform->addElement('hidden', 'itemid', $instance['itemid']); + $mform->setType('itemid', PARAM_INT); + + $mform->addElement('hidden', 'userid', $instance['userid']); + $mform->setType('userid', PARAM_INT); + + $mform->addElement('hidden', 'filearea', $instance['filearea']); + $mform->setType('filearea', PARAM_ALPHA); + + $mform->addElement('hidden', 'action', 'uploadfile'); + $mform->setType('action', PARAM_ALPHA); + + // buttons + $this->add_action_buttons(true, get_string('savechanges', 'admin')); + } +} + +// ############################ MOODLE 2.0 FILE API ######################### + +//------------------ +function checklist_set_description($mform, $checklistid){ +// file form managing +// table checklist_document update +global $CFG, $USER, $DB, $OUTPUT; + + $viewurl=new moodle_url('/mod/checklist/view.php', array('checklist'=>$checklistid)); + + if ($formdata = $mform->get_data()) { + if (empty($formdata->descriptionid)){ + $description = new object(); + $description->itemid=$formdata->itemid; + $description->userid=$formdata->userid; + $description->description=addslashes($formdata->description); + $description->timestamp=time(); + // Insert Description + if ($descid = $DB->insert_record("checklist_description", $description)){ + $description->id=$descid; + } + else{ + return NULL; + } + } + else{ + $description = new object(); + $descid =$formdata->descriptionid; + $description->id=$descid; + $description->itemid=$formdata->itemid; + $description->userid=$formdata->userid; + $description->description=addslashes($formdata->description); + $description->timestamp=time(); + // Update Description + $DB->update_record("checklist_description", $description); + } + + if ($description->itemid && $description->userid && $description->id){ + $documenturl=new moodle_url('/mod/checklist/edit_document.php', array('checklist'=>$checklistid, 'itemid'=>$description->itemid, 'userid'=>$description->userid, 'descriptionid'=>$descid)); + redirect($documenturl); + } + } + redirect($viewurl); +} + + +//------------------ +function checklist_add_upload_document($mform, $checklistid){ +// Document creation form +// checklist_document update +// sets checklist_document table +global $CFG, $USER, $DB, $OUTPUT; + + $viewurl=new moodle_url('/mod/checklist/view.php', array('checklist'=>$checklistid)); + + if ($formdata = $mform->get_data()) { + // document + $fileareas = array('checklist', 'document'); + + if (empty($formdata->filearea) || !in_array($formdata->filearea, $fileareas)) { + return false; + } + + if (($formdata->filearea=='document') && !empty($formdata->descriptionid)) { + + $document = new object(); + $document->descriptionid=$formdata->descriptionid; + if (isset($formdata->description_document)){ + $document->description_document=$formdata->description_document; + } + else{ + $document->description_document=''; + } + $document->url_document=''; // sera mis à jour plus bas + $document->target=$formdata->target; + $document->timestamp=time(); + + $fs = get_file_storage(); + // suppression du fichier existant ? NON + // $fs->delete_area_files($formdata->contextid, 'mod_checklist', $formdata->filearea, $docid); + + // Verifier si un fichier est depose + if ($newfilename = $mform->get_new_filename('checklist_file')) { + // gestion d'un fichier à la fois + + if (!empty($formdata->title)){ + $document->title=$formdata->title; + } + else{ + $document->title=$newfilename; + } + + // get the id for url + if ($docid = $DB->insert_record("checklist_document", $document)){ + $document->id=$docid; + $file = $mform->save_stored_file('checklist_file', $formdata->contextid, + 'mod_checklist', $formdata->filearea, $docid, '/', $newfilename); + // file adresse calculation + $fullpath = "/$formdata->contextid/mod_checklist/$formdata->filearea/$docid/$newfilename"; + $link = new moodle_url($CFG->wwwroot.'/pluginfile.php'.$fullpath); + // Update + $DB->set_field("checklist_document", "url_document", $fullpath, array("id" => "$docid")); + } + } + else if (!empty($formdata->url)){ + $document->url_document = $formdata->url; + $link = $formdata->url; + if (!empty($formdata->title)){ + $document->title=$formdata->title; + } + else{ + $document->title=get_string('url', 'checklist'); + } + if ($docid = $DB->insert_record("checklist_document", $document)){ + $document->id=$docid; + } + } + else if (!empty($formdata->url_old)){ + $document->url_document = $formdata->url_old; + $link = $formdata->url_old; + if (!empty($formdata->title)){ + $document->title=$formdata->title; + } + else{ + $document->title=get_string('url', 'checklist'); + } + if ($docid = $DB->insert_record("checklist_document", $document)){ + $document->id=$docid; + } + } + // echo link ?? NOP + // echo '\n"; + } + } + + redirect($viewurl); +} + + + +//------------------ +function checklist_update_upload_document($mform, $checklistid){ +// Form document +// sets checklist_document table +global $CFG, $USER, $DB, $OUTPUT; + + $viewurl=new moodle_url('/mod/checklist/view.php', array('checklist'=>$checklistid)); + + if ($formdata = $mform->get_data()) { + // document + $fileareas = array('checklist', 'document'); + + if (empty($formdata->filearea) || !in_array($formdata->filearea, $fileareas)) { + return false; + } + + if (($formdata->filearea=='document') && !empty($formdata->descriptionid) && !empty($formdata->documentid)) { + + $document = new object(); + $document->id=$formdata->documentid; + $document->descriptionid=$formdata->descriptionid; + if (isset($formdata->description_document)){ + $document->description_document=$formdata->description_document; + } + else{ + $document->description_document=''; + } + $document->url_document=''; // sera mis à jour plus bas + $document->target=$formdata->target; + $document->timestamp=time(); + + $fs = get_file_storage(); + // suppression du fichier existant ? NON + // $fs->delete_area_files($formdata->contextid, 'mod_checklist', $formdata->filearea, $docid); + + // Verifier si un fichier est depose + if ($newfilename = $mform->get_new_filename('checklist_file')) { + // gestion d'un fichier à la fois + + if (!empty($formdata->title)){ + $document->title=$formdata->title; + } + else{ + $document->title=$newfilename; + } + // echo "
"; + $file = $mform->save_stored_file('checklist_file', $formdata->contextid, + 'mod_checklist', $formdata->filearea, $formdata->documentid, '/', $newfilename); + + // File adress + $fullpath = "/$formdata->contextid/mod_checklist/$formdata->filearea/$formdata->documentid/$newfilename"; + $link = new moodle_url($CFG->wwwroot.'/pluginfile.php'.$fullpath); + // Update + $document->url_document=$fullpath; + } + else if (!empty($formdata->url)){ + $document->url_document = $formdata->url; + $link = $formdata->url; + if (!empty($formdata->title)){ + $document->title=$formdata->title; + } + else{ + $document->title=get_string('url', 'checklist'); + } + } + else if (!empty($formdata->url_old)){ + $document->url_document = $formdata->url_old; + $link = $formdata->url_old; + if (!empty($formdata->title)){ + $document->title=$formdata->title; + } + else{ + $document->title=get_string('url', 'checklist'); + } + } + $DB->update_record("checklist_document", $document); + + // Display link ??? + // echo '\n"; + } + } + + redirect($viewurl); +} + + +// ------------------ +function checklist_get_area_files($contextid, $filearea, $docid){ +// Url list of files in filearea +global $CFG; + // fileareas autorisees + $fileareas = array('checklist', 'document'); + if (!in_array($filearea, $fileareas)) { + return false; + } + + $strfilename=get_string('filename', 'checklist'); + $strfilesize=get_string('filesize', 'checklist'); + $strtimecreated=get_string('timecreated', 'checklist'); + $strtimemodified=get_string('timemodified', 'checklist'); + $strmimetype=get_string('mimetype', 'checklist'); + $strurl=get_string('url'); + + $table = new html_table(); + + $table->head = array ($strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype); + $table->align = array ("center", "left", "left", "left"); + + $fs = get_file_storage(); + if ($files = $fs->get_area_files($contextid, 'mod_checklist', $filearea, $docid, "timemodified", false)) { + foreach ($files as $file) { + // print_object($file); + $filesize = $file->get_filesize(); + $filename = $file->get_filename(); + $mimetype = $file->get_mimetype(); + $filepath = $file->get_filepath(); + $fullpath ='/'.$contextid.'/mod_checklist/'.$filearea.'/'.$docid.$filepath.$filename; + + $timecreated = userdate($file->get_timecreated(),"%Y/%m/%d-%H:%M",99,false); + $timemodified = userdate($file->get_timemodified(),"%Y/%m/%d-%H:%M",99,false); + $link= new moodle_url($CFG->wwwroot.'/pluginfile.php'.$fullpath); + $url=''.$filename.'
'."\n"; + $table->data[] = array ($url, $filesize, $timecreated, $timemodified, $mimetype); + } + } + echo html_writer::table($table); +} + +// ------------------ +function checklist_get_manage_files($contextid, $filearea, $docid, $titre, $appli){ +// Url list of files in filearea +// Delete proposal +global $CFG; +global $OUTPUT; + $total_size=0; + $nfile=0; + // fileareas autorisees + $fileareas = array('checklist', 'document'); + if (!in_array($filearea, $fileareas)) { + return false; + } + $strfilepath='filepath'; + $strfilename=get_string('filename', 'checklist'); + $strfilesize=get_string('filesize', 'checklist'); + $strtimecreated=get_string('timecreated', 'checklist'); + $strtimemodified=get_string('timemodified', 'checklist'); + $strmimetype=get_string('mimetype', 'checklist'); + $strmenu=get_string('delete'); + + $strurl=get_string('url'); + + + $fs = get_file_storage(); + if ($files = $fs->get_area_files($contextid, 'mod_checklist', $filearea, $docid, "timemodified", false)) { + $table = new html_table(); + $table->head = array ($strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype, $strmenu); + $table->align = array ("center", "left", "left", "left", "center"); + + foreach ($files as $file) { + // print_object($file); + $filesize = $file->get_filesize(); + $filename = $file->get_filename(); + $mimetype = $file->get_mimetype(); + $filepath = $file->get_filepath(); + $fullpath ='/'.$contextid.'/mod_checklist/'.$filearea.'/'.$docid.$filepath.$filename; + // echo "
FULPATH :: $fullpath \n"; + $timecreated = userdate($file->get_timecreated(),"%Y/%m/%d-%H:%M",99,false); + $timemodified = userdate($file->get_timemodified(),"%Y/%m/%d-%H:%M",99,false); + + $link= new moodle_url($CFG->wwwroot.'/pluginfile.php'.$fullpath); + $url=''.$filename.'
'."\n"; + + $delete_link=''."\n"; + $table->data[] = array ($url, display_size($filesize), $timecreated, $timemodified, $mimetype, $delete_link); + $total_size+=$filesize; + $nfile++; + } + $table->data[] = array (get_string('nbfile', 'checklist',$nfile), get_string('totalsize', 'checklist', display_size($total_size)),'','','',''); + + echo $OUTPUT->box_start('generalbox boxaligncenter'); + echo '
'."\n"; + echo '

'.$titre.'

'."\n"; + echo '
'."\n"; + echo html_writer::table($table); + echo "\n".''."\n"; + echo ''."\n"; + echo '
'."\n"; + echo '
'."\n"; + echo $OUTPUT->box_end(); + } +} + +// ------------------ +function checklist_get_a_file($filename, $contextid, $filearea, $itemid=0){ +// Get un file + +global $CFG; + // fileareas autorisees + $fileareas = array('checklist', 'document'); + if (!in_array($filearea, $fileareas)) { + return false; + } + + $strfilename=get_string('filename', 'checklist'); + $strfilesize=get_string('filesize', 'checklist'); + $strtimecreated=get_string('timecreated', 'checklist'); + $strtimemodified=get_string('timemodified', 'checklist'); + $strmimetype=get_string('mimetype', 'checklist'); + $strurl=get_string('url'); + + $table = new html_table(); + + $table->head = array ($strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype); + $table->align = array ("center", "left", "left", "left"); + $fs = get_file_storage(); + $file = $fs->get_file($contextid, 'mod_checklist', $filearea, $itemid,'/', $filename); + if ($file) { + // DEBUG + // echo "
DEBUG :: 621 :: $filename\n"; + // print_object($file); + // echo "
CONTENU\n"; + // $contents = $file->get_content(); + // echo htmlspecialchars($contents); + $filesize = $file->get_filesize(); + $filename = $file->get_filename(); + $mimetype = $file->get_mimetype(); + $filepath = $file->get_filepath(); + $fullpath ='/'.$contextid.'/mod_checklist/'.$filearea.'/'.$docid.$filepath.$filename; + + $timecreated = userdate($file->get_timecreated(),"%Y/%m/%d-%H:%M",99,false); + $timemodified = userdate($file->get_timemodified(),"%Y/%m/%d-%H:%M",99,false); + $link= new moodle_url($CFG->wwwroot.'/pluginfile.php'.$fullpath); + $url=''.$filename.'
'."\n"; + $table->data[] = array ($url, $filesize, $timecreated, $timemodified, $mimetype); + } + + echo html_writer::table($table); +} + +/** + * This function wil delete a file + * fullpath of the form /contextid/mod_checklist/filearea/itemid.path.filename + * path : any path beginning and ending in / like '/' or '/rep1/rep2/' + * @fullpath string + * @return nothing + */ + +// --------------------------------- +function checklist_delete_a_file($fullpath){ +// supprime un fichier +// case 0 : $fullpath matches "jf44.png"; +// case 1 : $fullpath matches "/30/mod_checklist/checklist/0/rep1/rep2/jf44.png" +// case 2 : $fullpath matches "/51/mod_checklist/checklist/12/jf44.png" +global $CFG; + + // initialisation par defaut + $contextid=0; + $component='mod_checklist'; + $filearea='checklist'; + $itemid=0; + $path='/'; + $filename=$fullpath; + + // Traitement de $fullpath + if ($fullpath && preg_match('/\//', $fullpath)){ + $t_fullpath=explode('/',$fullpath,6); + if (!empty($t_fullpath) && empty($t_fullpath[0])){ + $garbage=array_shift($t_fullpath); + } + if (!empty($t_fullpath)){ + list($contextid, $component, $filearea, $itemid, $path ) = $t_fullpath; + if ($path){ + if (preg_match('/\//', $path)){ + $filename=substr($path, strrpos($path, '/')+1); + $path='/'.substr($path, 0, strrpos($path, '/')+1); + } + else{ + $filename=$path; + $path='/'; + } + } + } + } + + // echo "
DEBUG :: lib.php :: Ligne 687 ::
$contextid, $component, $filearea, $itemid, $path, $filename\n"; + // display case 0 :: 0, mod_checklist, checklist, 0, /, jf44.png + // display case 1 :: 30, mod_checklist, checklist, 0, /rep1/rep2/, jf44.png + // dispay case 2 :: 51, mod_checklist, checklist, 12, /, jf44.png + + require_once($CFG->libdir.'/filelib.php'); + $fs = get_file_storage(); + + // Get file + $file = $fs->get_file($contextid, $component, $filearea, $itemid, $path, $filename); + + // Delete it if exists + if ($file) { + $file->delete(); + } + +} + + +?> + diff --git a/mod/checklist/functions.js b/mod/checklist/functions.js new file mode 100644 index 00000000..57a9fc58 --- /dev/null +++ b/mod/checklist/functions.js @@ -0,0 +1,126 @@ +// JavaScript Document + + function uncheckall() { + var inputs = document.getElementsByTagName('input'); + for(var i = 0; i < inputs.length; i++) { + inputs[i].checked = false; + } + } + + function checkall() { + var inputs = document.getElementsByTagName('input'); + for(var i = 0; i < inputs.length; i++) { + inputs[i].checked = true; + } + } + + function checkAllCheckBox() + { + var docInputs = new Array(); + docInputs = document.getElementsByTagName('input'); + for (var i=0;iget_record('course', array('id' => $cm->course))) { - error('Course is misconfigured'); -} - -if (! $checklist = $DB->get_record('checklist', array('id' => $cm->instance))) { - error('Course module is incorrect'); + print_error(get_string('error_cmid', 'checklist')); // 'Course Module ID was incorrect' } +$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); $url = new moodle_url('/mod/checklist/import.php', array('id' => $cm->id)); $PAGE->set_url($url); @@ -33,7 +27,7 @@ $context = context_module::instance($cm->id); } if (!has_capability('mod/checklist:edit', $context)) { - error('You do not have permission to import items to this checklist'); + print_error(get_string('error_import_items', 'checklist')); // 'You do not have permission to import items to this checklist'); } $returl = new moodle_url('/mod/checklist/edit.php', array('id' => $cm->id)); @@ -55,6 +49,16 @@ function definition() { function cleanrow($separator, $row) { // Convert and $separator inside quotes into [!SEPARATOR!] (to skip it during the 'explode') +/* +ITEMS CSV FILE +Separator ',' +Item text,Indent,Type (0 - normal; 1 - optional; 2 - heading),Due Time (timestamp),Colour (red; orange; green; purple; black) +Savoir Installer une Webcam,0,0,0,black +Savoir Choisir une WebCam,1,0,0,black +Savoir Participer à une Webconférence,0,0,0,black +Savoir Organiser et piloter une Webconférence,0,0,0,black +*/ + $state = STATE_WAITSTART; $chars = str_split($row); $cleanrow = ''; @@ -102,7 +106,7 @@ function cleanrow($separator, $row) { $filename = $form->save_temp_file('importfile'); if (!file_exists($filename)) { - $errormsg = "Something went wrong with the file upload"; + $errormsg = get_string('error_file_upload', 'checklist');// "Something went wrong with the file upload"; } else { if (is_readable($filename)) { $filearray = file($filename); @@ -129,7 +133,7 @@ function cleanrow($separator, $row) { $item = explode($separator, $row); if (count($item) != count($fields)) { - $errormsg = "Row has incorrect number of columns in it:
$row"; + $errormsg = get_string('error_number_columns', 'checklist', $row);// "Row has incorrect number of columns in it:
$row"; $ok = false; break; } @@ -192,7 +196,7 @@ function cleanrow($separator, $row) { if ($newitem->displaytext) { // Don't insert items without any text in them if (!$DB->insert_record('checklist_item', $newitem)) { $ok = false; - $errormsg = 'Unable to insert DB record for item'; + $errormsg = get_string('error_insert_db', 'checklist'); // 'Unable to insert DB record for item'; break; } } @@ -203,7 +207,7 @@ function cleanrow($separator, $row) { } } else { - $errormsg = "Something went wrong with the file upload"; + $errormsg = get_string('error_file_upload', 'checklist'); // "Something went wrong with the file upload"; } } } diff --git a/mod/checklist/import_outcomes.php b/mod/checklist/import_outcomes.php new file mode 100644 index 00000000..285acf8f --- /dev/null +++ b/mod/checklist/import_outcomes.php @@ -0,0 +1,299 @@ + + * @package mod/checklist + * + * @author Jean.fruitet@univ-nantes.fr + * @author jfruitet + * @version $Id: import_outcome.php,v 1.0 2012/03/18 00:00:00 jfruitet Exp $ + * @package checklist 'JF-2.x (Build: 2012041100)'; + **/ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +// require_once(dirname(__FILE__).'/importexportfields.php'); // Items format +require_once(dirname(__FILE__).'/importexportoutcomes.php'); // Outcomes format +require_once($CFG->libdir.'/formslib.php'); + +define('STATE_WAITSTART', 0); +define('STATE_INQUOTES', 1); +define('STATE_ESCAPE', 2); +define('STATE_NORMAL', 3); + +$id = required_param('id', PARAM_INT); // course module id + +if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' +} +$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + +$url = new moodle_url('/mod/checklist/import_outcomes.php', array('id' => $cm->id)); +$PAGE->set_url($url); +require_login($course, true, $cm); + +if ($CFG->version < 2011120100) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); +} else { + $context = context_module::instance($cm->id); +} +if (!has_capability('mod/checklist:edit', $context)) { + print_error(get_string('error_import_items', 'checklist')); // 'You do not have permission to import items to this checklist'); +} + +$returl = new moodle_url('/mod/checklist/edit.php', array('id' => $cm->id)); + +class checklist_import_outcomes_form extends moodleform { + function definition() { + $mform = $this->_form; + + $mform->addElement('hidden', 'id', 0); + $mform->setType('id', PARAM_INT); + + $mform->addElement('header', 'formheading', get_string('import_outcomes', 'checklist')); + + $mform->addElement('filepicker', 'importfile', get_string('importfile', 'checklist'), null, array('accepted_types'=>array('*.csv'))); + + $this->add_action_buttons(true, get_string('import', 'checklist')); + } +} + + + +function cleanrow_outcomes($separator, $row) { + // Convert and $separator inside quotes into [!SEPARATOR!] (to skip it during the 'explode') + + $state = STATE_WAITSTART; + $chars = str_split($row); + $cleanrow = ''; + $quotes = '"'; + foreach ($chars as $char) { + switch ($state) { + case STATE_WAITSTART: + if ($char == ' ' || $char == $separator) { } // Still in STATE_WAITSTART + else if ($char == '"') { $quotes = '"'; $state = STATE_INQUOTES; } + else if ($char == "'") { $quotes = "'"; $state = STATE_INQUOTES; } + else { $state = STATE_NORMAL; } + break; + case STATE_INQUOTES: + if ($char == $quotes) { $state = STATE_NORMAL; } // End of quotes + else if ($char == '\\') { $state = STATE_ESCAPE; continue 2; } // Possible escaped quotes skip (for now) + else if ($char == $separator) { $cleanrow .= '[!SEPARATOR!]'; continue 2; } // Replace $separator and continue loop + break; + case STATE_ESCAPE: + // Retain escape char, unless escaping a quote character + if ($char != $quotes) { $cleanrow .= '\\'; } + $state = STATE_INQUOTES; + break; + default: + if ($char == $separator) { $state = STATE_WAITSTART; } + break; + } + $cleanrow .= $char; + } + + return $cleanrow; +} + +$form = new checklist_import_outcomes_form(); +$defaults = new stdClass; +$defaults->id = $cm->id; + +$form->set_data($defaults); + +if ($form->is_cancelled()) { + redirect($returl); +} + +$errormsg = ''; + +$debug=false; // Histoire d'avoir un affichage + +if ($data = $form->get_data()) { + $filename = $form->save_temp_file('importfile'); + + if (!file_exists($filename)) { + $errormsg = get_string('error_file_upload', 'checklist');// "Something went wrong with the file upload"; + } else { + if (is_readable($filename)) { + $filearray = file($filename); + unlink($filename); + + /// Check for Macintosh OS line returns (ie file on one line), and fix + if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { + $filearray = explode("\r", $filearray[0]); + } + + $skipheading = true; + $ok = true; + $position = $DB->count_records('checklist_item', array('checklist' => $checklist->id, 'userid' => 0)) + 1; + + $ok_referentiel=false; // flag for Skills repository outcomes + + foreach ($filearray as $row) { + if ($skipheading) { + $skipheading = false; + continue; + } + + // Separator defined in importexportoutcomes.php (currently ';') + // Split $row into array $outcomes, by $separator, but ignore $separator when it occurs within "" + $row = cleanrow_outcomes($separator_outcomes, $row); + $outcome = explode($separator_outcomes, $row); + + if (count($outcome) != count($fields_outcomes)) { + $errormsg = get_string('error_number_columns_outcomes', 'checklist', $row);// "Row Outcome has incorrect number of columns in it:
$row"; + $ok = false; + break; + } + + $outcomefield = reset($outcome); + + // $fields defined in importexportfields.php + foreach ($fields_outcomes as $field => $fieldtext) { + $outcomefield = trim($outcomefield); + if (substr($outcomefield, 0, 1) == '"' && substr($outcomefield, -1) == '"') { + $outcomefield = substr($outcomefield, 1, -1); + } + $outcomefield = trim($outcomefield); + $outcomefield = str_replace('[!SEPARATOR!]', $separator_outcomes, $outcomefield); + + switch ($field) { + + case 'outcome_name': + $an_outcome=get_outcome_code(trim($outcomefield)); + + if (!empty($an_outcome)){ + + if (!empty($an_outcome->code_referentiel)){ + if (!empty($an_outcome->code_referentiel) && !$ok_referentiel){ + $newitem_ref = new stdClass; + $newitem_ref->checklist = $checklist->id; + $newitem_ref->position = $position++; + $newitem_ref->userid = 0; + $newitem_ref->displaytext = $an_outcome->code_referentiel; + $newitem_ref->indent = 0; + $newitem_ref->itemoptional = 0; + $newitem_ref->duetime = 0; + $newitem_ref->colour = 'purple'; + $ok_referentiel=true; + + if (!empty($newitem_ref->displaytext)) { // Don't insert items without any text in them + if (!$DB->insert_record('checklist_item', $newitem_ref)) { + $ok = false; + $errormsg = get_string('error_insert_db', 'checklist'); // 'Unable to insert DB record for item'; + break; + } + } + } + $newitem = new stdClass; + $newitem->checklist = $checklist->id; + $newitem->position = $position++; + $newitem->userid = 0; + + $newitem->displaytext = trim($outcomefield); + $newitem->indent = 1; + $newitem->itemoptional = 0; + $newitem->duetime = 0; + $newitem->colour = 0; + } + } + else{ + $newitem = new stdClass; + $newitem->checklist = $checklist->id; + $newitem->position = $position++; + $newitem->userid = 0; + + $newitem->displaytext = trim($outcomefield); + $newitem->indent = 1; + $newitem->itemoptional = 0; + $newitem->duetime = 0; + $newitem->colour = 0; + } + break; + default: + break; + } + $outcomefield = next($outcome); + } + + if ($newitem->displaytext) { // Don't insert items without any text in them + if (!$DB->insert_record('checklist_item', $newitem)) { + $ok = false; + $errormsg = get_string('error_insert_db', 'checklist'); // 'Unable to insert DB record for item'; + break; + } + } + } + + if ($ok) { + redirect($returl); + } + + } else { + $errormsg = get_string('error_file_upload', 'checklist'); // "Something went wrong with the file upload"; + } + } +} + +$strchecklist = get_string('modulename', 'checklist'); +$pagetitle = strip_tags($course->shortname.': '.$strchecklist.': '.format_string($checklist->name, true)); + +$PAGE->set_title($pagetitle); +$PAGE->set_heading($course->fullname); + +echo $OUTPUT->header(); + +if ($errormsg) { + echo '

'.$errormsg.'

'; +} + +$form->display(); + +echo $OUTPUT->footer(); + diff --git a/mod/checklist/importexportoutcomes.php b/mod/checklist/importexportoutcomes.php new file mode 100644 index 00000000..07040f73 --- /dev/null +++ b/mod/checklist/importexportoutcomes.php @@ -0,0 +1,166 @@ + + * @package mod/checklist + */ + + +$separator_outcomes = ';'; + +// fieldname => output string +$fields_outcomes = array('outcome_name' => 'Outcome name', + 'outcome_shortname' => 'Outcome shortname', + 'outcome_description' => 'Outcome Description', + 'scale_name' => 'Scale name [Item référentiel]', + 'scale_items' => 'Item Values [Non pertinent, Non validé, Validé]', + 'scale_description' => 'Scale description [Ce barème est destiné à évaluer l\'acquisition des compétences du module référentiel.]'); + + +/** + * Extract skill repository and competency codes from a displaytext field + * outcome_name;outcome_shortname;outcome_description;scale_name;scale_items;scale_description + * "C2i2e-2011 A.1-1 :: Identifier les personnes ressources Tic et leurs rôles respectifs (...)";A.1-1;"Identifier les personnes ressources Tic et leurs rôles respectifs au niveau local, régional et national.";"Item référentiel";"Non pertinent,Non validé,Validé";"Ce barème est destiné à évaluer l'acquisition des compétences du module référentiel." + * | | | description + * | | ^ separator 2 '::' + * ^ separator 1 ' ' + * | | competence_code + * | referentiel_code + * @imput displaytext string + * @output object + **/ + +function get_outcome_code($a_text, $referentielcode=''){ +// extract skill repository code and competency code from an outcome_name field + $item_outcome = new stdClass; + if (!empty($a_text)){ + if (preg_match('/(.*)::(.*)/i', $a_text, $matches)){ + if ($matches[1]){ + if ($keywords = preg_split("/[\s]+/",$matches[1],-1,PREG_SPLIT_NO_EMPTY)){ + if ($keywords[0] && $keywords[1]){ + if ($referentielcode){ + $item_outcome->code_referentiel=$referentielcode; + }else{ + $item_outcome->code_referentiel=trim($keywords[0]); + } + $item_outcome->code_competence=trim($keywords[1]); + } + else if ($keywords[0]){ + if ($referentielcode){ + $item_outcome->code_referentiel=$referentielcode; + }else{ + $item_outcome->code_referentiel='REF_'.get_string('a_completer', 'checklist'); + } + $item_outcome->code_competence=trim($keywords[0]); + } + else{ + return NULL; + } + } + } + else{ + return NULL; + } + + if (!empty($matches[2])){ + $item_outcome->description=trim($matches[2]); + } + else{ + $item_outcome->description=get_string('a_completer', 'checklist'); + } + $item_outcome->outcome=$item_outcome->code_referentiel.' '. $item_outcome->code_competence.' :: '.$item_outcome->description; + } + + } + /* + print_r($item_outcome); + echo "
importexportoutcome.php :: 84 ::EXIT\n"; + exit; + */ + return $item_outcome; +} + +/** + * uses get_outcome_code() + * @imput string + * @output object + **/ +function get_outcome_code_from_item($item, $referentielcode='', $useitemid=false){ + if (!empty($item) && !empty($item->checklist) && !empty($item->displaytext)){ + $item_outcome=get_outcome_code($item->displaytext, $referentielcode); + /* + // DEBUG + echo "
INPUT\n"; + print_object($item_outcome); + echo "
\n"; + */ + if (empty($item_outcome) || empty($item_outcome->code_competence)){ + $chaine=trim($item->displaytext); + $chaine1=str_replace(array("\n","\r","\r\n"),'. ',$chaine); + $chaine=str_replace(array("\n","\r","\r\n"),' ',$chaine); + $keywords = preg_split("/[\s]+/",$chaine,-1,PREG_SPLIT_NO_EMPTY); + if ($keywords){ + if (!empty($keywords[1])){ + if ($referentielcode){ + $item_outcome->code_referentiel=$referentielcode; + }else{ + $item_outcome->code_referentiel=trim($keywords[0]); + } + if ($useitemid){ + $item_outcome->code_competence='#ID_'.$item->id; + } + else{ + $item_outcome->code_competence=trim($keywords[1]); + } + } + else if (!empty($keywords[0])){ + if ($useitemid){ + $item_outcome->code_competence='#ID_'.$item->id; + } + else{ + $item_outcome->code_competence=trim($keywords[0]); + } + if ($referentielcode){ + $item_outcome->code_referentiel=$referentielcode; + } + else{ + $item_outcome->code_referentiel='REF_'.$item->checklist; + } + } + } + else{ + if ($useitemid){ + $item_outcome->code_competence='#ID_'.$item->id; + } + else{ + $item_outcome->code_competence=$chaine; + } + + if ($referentielcode){ + $item_outcome->code_referentiel=$referentielcode; + } + else{ + $item_outcome->code_referentiel='REF_'.$item->checklist; + } + } + $item_outcome->description=$chaine1.' ['.get_string('a_completer', 'checklist').']'; + $item_outcome->outcome=$item_outcome->code_referentiel.' '. $item_outcome->code_competence.' :: '.$item_outcome->description; + } + /* + // DEBUG + echo "
SORTIE\n"; + print_object($item_outcome); + echo "
\n"; + */ + return $item_outcome; + } + return NULL; +} + diff --git a/mod/checklist/lang/en/checklist.php b/mod/checklist/lang/en/checklist.php index 8b35be7d..7d321cd2 100644 --- a/mod/checklist/lang/en/checklist.php +++ b/mod/checklist/lang/en/checklist.php @@ -15,6 +15,136 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// MODIF JF 2012/03/18 ////////////////////////////////////////////////////////////// + +// Mahara portfolio +$string['mustprovideinstanceid'] = 'You must provide an instance id'; +$string['mustprovideexportformat'] = 'You must provide an export format'; +$string['mustprovideuser'] = 'You must provide an user id'; +$string['pluginname'] = 'Mahara portfolio'; +$string['clicktopreview'] = 'click to preview in full-size popup'; +$string['clicktoselect'] = 'click to select page'; +$string['nomaharahostsfound'] = 'No mahara hosts found.'; +$string['noviewscreated'] = 'You have not created any pages in {$a}.'; +$string['noviewsfound'] = 'No matching pages found in {$a}.'; +$string['previewmahara'] = 'Preview'; +$string['site'] = 'Site'; +$string['site_help'] = 'This setting lets you select which Mahara site your students should submit their pages from. (The Mahara site must already be configured for mnet networking with this Moodle site.)'; +$string['selectedview'] = 'Submitted Page'; +$string['selectmaharaview'] = 'Select one of your {$a->name} portfolio pages from this complete list, or click here to visit {$a->name} and create a page right now.'; +$string['titlemahara'] = 'Title'; +$string['typemahara'] = 'Mahara portfolio'; +$string['views'] = 'Pages'; +$string['viewsby'] = 'Pages by {$a}'; +$string['viewmahara'] = 'Mahara view'; +$string['select'] = 'Select'; + +$string['upload_portfolio'] = 'Link to a page of my portfolio'; +$string['timecreated'] = 'Created the '; +$string['timemodified'] = 'Modified the '; +$string['id'] = 'ID# '; +$string['checklist_check'] = 'Evaluation '; +$string['teachermark'] = 'Appreciation '; +$string['usertimestamp'] = 'Demanded the '; +$string['teachertimestamp'] = 'Evaluated the '; +$string['commentby'] = 'Comment by '; +$string['argumentation'] = 'Argumentation'; + +// Config +$string['outcomes_input'] = 'Activate Outcomes files'; +$string['config_outcomes_input'] = 'Allows teachers to import in Checklist the outcomes checked in course\'s activities'; +$string['checklist_description'] = 'Allows students to upload files as prove of practice'; +$string['config_description'] = 'Permet aux utilisateurs de déposer des documents comme trace de pratique.'; + +// error strings +$string['error_cmid'] = 'Course Module ID was incorrect'; +$string['error_cm'] = 'Course Module is incorrect'; +$string['error_course'] = 'Course is misconfigured'; +$string['error_specif_id'] = 'You must specify a course_module ID or an instance ID'; + +$string['error_checklist_id'] = 'Checklist ID was incorrect'; +$string['error_user'] = 'No such user!'; +$string['error_sesskey'] = 'Error: Invalid sesskey'; +$string['error_action'] = 'Error: Invalid action - "{a}"'; +$string['error_itemlist'] = 'Error: invalid (or missing) items list'; + +$string['error_import_items'] = 'You do not have permission to import items to this checklist'; +$string['error_export_items'] = 'You do not have permission to export items from this checklist'; +$string['error_file_upload'] = 'Something went wrong with the file upload'; +$string['error_number_columns'] = 'Row has incorrect number of columns in it:
{$a}'; +$string['error_insert_db'] = 'Unable to insert DB record for item'; +$string['error_update'] = 'Error: you do not have permission to update this checklist'; +$string['error_select'] = 'Error: At least one Item has to be selected'; +$string['OK'] = 'OK'; +$string['quit'] = 'Quit'; + +// Outcomes +$string['useitemid'] = 'Use Item ID as key '; +$string['a_completer'] = 'TO COMPLETE'; +$string['selectexport'] = 'Export Outcomes'; +$string['addreferentielname'] = 'Skill repository code name'; +$string['confirmreferentielname'] = 'Confirm skills repository code name '; +$string['referentiel_codeh'] = 'Type in a skills repository code name (Optional)'; +$string['referentiel_codeh_help'] = 'This code name identify the outcomes matching the same Skills repository. +
If Items names are not keys check "'.$string['useitemid'].'"'; +$string['select_items_export'] = 'Selection items to exporte'; +$string['items_exporth'] = 'Exported Items'; +$string['items_exporth_help'] = 'Selected items will be exported in the same Outcomes file.'; + +$string['select_all'] = 'Check all Items'; +$string['select_not_any'] = 'Uncheck all Items'; +$string['export_outcomes'] = 'Export items as outcomes'; +$string['import_outcomes'] = 'Import outcomes as items'; +$string['error_number_columns_outcomes'] = 'Row Outcome has incorrect number of columns in it:
{$a}'; +$string['old_comment'] = 'Previous comment:'; +$string['outcome_link'] = ' {$a->name} '; +$string['outcomes'] = 'outcomes'; // DO NOT TRANSLATE. NE PAS TRADUIRE +$string['outcome_name'] = 'Outcome name'; +$string['outcome_shortname'] = 'Outcome shortname'; +$string['outcome_description'] = 'Outcome Description'; +// Scale / Bareme +$string['scale_name'] = 'Skill Item'; +$string['scale_items'] = 'Not relevent,Non validated,Validated'; +$string['scale_description'] = 'This scale is intended to estimate the acquisition of the skills by the way of Outcomes.'; + +// Description +$string['edit_description'] = 'Edit the description'; +$string['input_description'] = 'Draft your argument'; +$string['descriptionh'] = 'Argumentation Help'; +$string['descriptionh_help'] = 'Indicate in a brief way the motives which allow you to assert that this task is finished or the skill acquired.'; +$string['description'] = 'Type in your argumentation'; +$string['delete_description'] = 'Delete the description'; + +// Document +$string['urlh'] = 'Selection of a Web link'; +$string['urlh_help'] = 'You may copy / paste a link
(beginning by "http://" or "https://") +inthe field URL, or you may upload a file from your computer...'; + +$string['add_link'] = 'Add a link or a document'; +$string['delete_link'] = 'Delete a link'; +$string['edit_link'] = 'Edit a link'; +$string['doc_num'] = 'Document N°{$a} '; +$string['edit_document'] = 'Edit the document'; +$string['document_associe'] = 'Linked Document'; +$string['url'] = 'URL'; +$string['description_document'] = 'Document description '; +$string['target'] = 'Open that link in a new window'; +$string['title'] = 'Document title'; +$string['delete_document'] = 'Delete a document'; + +$string['documenth'] = 'Document Help'; +$string['documenth_help'] = 'Documents linked to a description are "prove of pratice oriented". +
+You may link to each Item a description and one or many files ou URLs (Web links). +
Document description : a short notice. +
URL : Web link +
    (or a file upload from your computer). +
Title of the link +
Targeted frame'; + + +///////////////////////////////////////////////////////////////////////////////////// + $string['addcomments'] = 'Add comments'; $string['additem'] = 'Add'; diff --git a/mod/checklist/lang/fr/checklist.php b/mod/checklist/lang/fr/checklist.php index 479ccf26..6492de6d 100644 --- a/mod/checklist/lang/fr/checklist.php +++ b/mod/checklist/lang/fr/checklist.php @@ -15,116 +15,250 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Modifié par JF - jean.fruitet@univ-nantes.fr 2012/03/18 +// MODIF JF 2012/03/18 ////////////////////////////////////////////////////////////// + +// Mahara portfolio +$string['mustprovideinstanceid'] = 'Vous devez fournir un identifiant d\'instance'; +$string['mustprovideexportformat'] = 'Vous devez fournir un formaat d\'export'; +$string['mustprovideuser'] = 'Vous devez fournir un identifiant d\'utilisateur'; +$string['clicktopreview'] = 'cliquez pour un aperçu pleine taille dans un fenêtre surgissante'; +$string['clicktoselect'] = 'cliquez pour sélectionner la vue'; +$string['nomaharahostsfound'] = 'Aucun hôte Mahara n\'a été trouvé.'; +$string['noviewscreated'] = 'Vous n\'avez créé aucune vue dans {$a}.'; +$string['noviewsfound'] = 'Aucune vue ne correspond dans {$a}'; +$string['previewmahara'] = 'Aperçu'; +$string['site'] = 'Site'; +$string['site_help'] = 'Ce paramètre vous permet de sélectionner depuis quel site Mahara vos étudiants pourront soumettre leurs pages. (Ce site Mahara doit être déjà configuré pour fonctionner en réseau MNET avec ce site Moodle.)'; +$string['selectedview'] = 'Page soumissionnée'; +$string['selectmaharaview'] = 'Sélectionnez dans cette liste l\'une des vues de votre portfolio {$a->name} ou cliquez ici pour créer directement une nouvelle vue sur {$a->name}.'; +$string['titlemahara'] = 'Titre'; +$string['typemahara'] = 'Portfolio Mahara'; +$string['views'] = 'Vues '; +$string['viewsby'] = 'Vues proposées par {$a}'; +$string['viewmahara'] = 'Vue Mahara'; +$string['select'] = 'Sélectionner'; + +$string['upload_portfolio'] = 'Lier à une page de mon portfolio'; + +$string['timecreated'] = 'Créé le '; +$string['timemodified'] = 'Modifié le '; +$string['id'] = 'ID# '; +$string['checklist_check'] = 'Evaluation '; +$string['teachermark'] = 'Appréciation '; +$string['usertimestamp'] = 'Réclamé le '; +$string['teachertimestamp'] = 'Evalué le '; +$string['commentby'] = 'Commenté par '; +$string['argumentation'] = 'Argumentation'; + +// Config +$string['outcomes_input'] = 'Activer les fichiers d\'objectifs'; +$string['config_outcomes_input'] = 'Permet d\'importer dans Checklist les objectifs validés dans les activités Moodle du cours'; +$string['checklist_description'] = 'Autoriser le dépôt de fichiers'; +$string['config_description'] = 'Permet aux utilisateurs de déposer des documents comme trace de pratique.'; + +// error strings +$string['error_cmid'] = 'Course Module ID incorrect'; +$string['error_cm'] = 'Course Module incorrect'; +$string['error_course'] = 'Course ID incorrect'; +$string['error_specif_id'] = 'Vous devez spécifier un course_module ID ou un instance ID'; + +$string['error_checklist_id'] = 'Checklist ID incorrect'; +$string['error_user'] = 'Compte utilisateur inexistant !'; +$string['error_sesskey'] = 'Erreur : Clé de session invalide'; +$string['error_action'] = 'Erreur : Action invalide - "{a}"'; +$string['error_itemlist'] = 'Erreur : liste d\'items invalide ou absente'; + +$string['error_import_items'] = 'Vous n\'êtes pas autorisé à importer des items dans cette CheckList'; +$string['error_export_items'] = 'Vous n\'êtes pas autorisé à exporter des items dans cette CheckList'; +$string['error_file_upload'] = 'Erreur au chargement du fichierd'; +$string['error_number_columns'] = 'Nombre de colonnes incorrect pour cette ligne :
{$a}'; +$string['error_insert_db'] = 'Insertion d\'un item impossible dans la base de données'; +$string['error_update'] = 'Erreur: Vous n\'êtes pas autorisé à mettre à jour cette CheckList'; +$string['error_select'] = 'Erreur: Veuillez sélectionner au moins un Item'; +$string['OK'] = 'OK'; +$string['quit'] = 'Quitter'; + +// Outcomes +$string['useitemid'] = 'Utiliser l\'ID de l\'Item comme clé '; +$string['a_completer'] = 'A COMPLETER'; +$string['selectexport'] = 'Exporter Objectifs'; +$string['addreferentielname'] = 'Saisir un code de référentiel '; +$string['confirmreferentielname'] = 'Confirmer le code de référentiel '; +$string['referentiel_codeh'] = 'Aide pour la saisie d\'un code de référentiel'; +$string['referentiel_codeh_help'] = 'Le code de référentiel (une chaîne de caractères non accentués sans virgule ni sans espace) permet d\'identifier les compétences (outcomes) participant du même référentiel de compétences. +
Quand les intitulés d\'Items ne sont pas discriminants cocher "'.$string['useitemid'].'"'; +$string['select_items_export'] = 'Sélectionnez des items à exporter'; +$string['items_exporth'] = 'Item exportés'; +$string['items_exporth_help'] = 'Les items sélectionnés seront exportés dans le même fichier d\'Objectifs.'; +$string['select_all'] = 'Tout cocher'; +$string['select_not_any'] = 'Tous décocher'; + +$string['export_outcomes'] = 'Exporter des objectifs'; +$string['import_outcomes'] = 'Importer des objectifs'; +$string['error_number_columns_outcomes'] = 'Cette ligne d\'Objectifs a un nombre incorrect de colonnes :
{$a}'; +$string['old_comment'] = 'Commentaire antérieur:'; +$string['outcomes'] = 'outcomes'; // NE PAS TRADUIRE +$string['outcome_link'] = ' {$a->name} '; +$string['outcome_name'] = 'Nom d\'objectif'; +$string['outcome_shortname'] = 'Code de compétence'; +$string['outcome_description'] = 'Description'; +// Scale / Bareme +$string['scale_name'] = 'Item référentiel'; +$string['scale_items'] = 'Non pertinent,Non validé,Validé'; +$string['scale_description'] = 'Ce barème est destiné à évaluer l\'acquisition d\'objectifs de compétences.'; + +// Description +$string['edit_description'] = 'Editer la description'; +$string['input_description'] = 'Rédigez votre argumentaire'; +$string['descriptionh'] = 'Aide pour l\'argumentation'; +$string['descriptionh_help'] = 'Indiquez de façon succincte les motifs qui vous permettent +d\'affirmer que cette tâche est achevée ou la compétence acquise.'; +$string['description'] = 'Rédigez votre argumentaire'; +$string['delete_description'] = 'Supprimer la description'; + +// Document +$string['urlh'] = 'Sélection d\'un lien Web'; +$string['urlh_help'] = 'Vous pouvez copier / coller un lien
(commençant par "http://"" ou par "https://"") +directement dans le champ URL ou bien vous pouvez télécharger un fichier depuis votre poste de travail'; +$string['add_link'] = 'Ajouter un lien ou un document'; +$string['delete_link'] = 'Supprimer un lien'; +$string['edit_link'] = 'Editer un lien'; +$string['doc_num'] = 'Document N°{$a} '; +$string['edit_document'] = 'Editer le document'; +$string['document_associe'] = 'Document associé'; +$string['url'] = 'URL'; +$string['description_document'] = 'Information sur le document'; +$string['target'] = 'Ouvrir ce lien dans une nouvelle fenêtre'; +$string['title'] = 'Titre du document'; +$string['delete_document'] = 'Supprimer un document'; + +$string['documenth'] = 'Aide pour les documents associés'; +$string['documenth_help'] = 'Les documents attachés à une description sont destinés à fournir +des traces observables de votre pratique. +
+A chaque Item vous pouvez associer une description et un ou plusieurs documents, soit en recopiant son adresse Web (URL), +soit en déposant un fichier dans l\'espace Moodle du cours. +
Description du document : Une courte notice d\'information. +
URL : Adresse Web du document +
    (ou fichier déposé par vos soins dans l\'espace Moodle). +
Titre ou étiquette +
Fenêtre cible où s\'ouvrira le document'; + + + +///////////////////////////////////////////////////////////////////////////////////// + $string['addcomments'] = 'Ajouter des commentaires'; $string['additem'] = 'Ajouter'; -$string['additemalt'] = 'Ajouter un nouvel item à la liste'; -$string['additemhere'] = 'Insérer le nouvel item après celui-ci'; +$string['additemalt'] = 'Ajouter un nouvel item à la liste'; +$string['additemhere'] = 'Insérer le nouvel item après celui-ci'; $string['addownitems'] = 'Ajouter vos propres items'; -$string['addownitems-stop'] = 'Arrêt d\'ajout d\'items'; +$string['addownitems-stop'] = 'Arrêt d\'ajout d\'items'; -$string['allowmodulelinks'] = 'Autoriser les liens vers les éléments'; +$string['allowmodulelinks'] = 'Autoriser les liens vers les éléments'; $string['anygrade'] = 'Tout'; -$string['autopopulate'] = 'Montrer les éléments du cours dans la Liste des tâches'; -$string['autopopulate_help'] = 'Cela ajoutera automatiquement une liste de toutes les ressources et les activités dans le cadre actuel dans la liste.
-Cette liste sera mise à jour avec tous les changements en cours, lorsque vous visitez la page "Modifier" pour la Liste des tâches.
-Les items peuvent être cachés dans la liste, en cliquant sur l\'icône \Cacher" à côté d\'eux.
-Pour supprimer les items automatiques de la liste, modifier cette option en cliquant sur "Non", puis cliquez sur "Supprimer des éléments de cours" sur la page "Modifier".'; +$string['autopopulate'] = 'Montrer les éléments du cours dans la CheckList'; +$string['autopopulate_help'] = 'Cela ajoutera automatiquement une liste de toutes les ressources et les activités dans le cadre actuel dans la liste.
+Cette liste sera mise à jour avec tous les changements en cours, lorsque vous visitez la page "Modifier" pour la CheckList.
+Les items peuvent être cachés dans la liste, en cliquant sur l\'icône \Cacher" à côté d\'eux.
+Pour supprimer les items automatiques de la liste, modifier cette option en cliquant sur "Non", puis cliquez sur "Supprimer des éléments de cours" sur la page "Modifier".'; $string['autoupdate'] = 'Cochez quand les modules sont complets'; -$string['autoupdate_help'] = 'Cela va automatiquement cocher les éléments de votre Liste des tâches lorsque vous terminez l\'activité concernée dans le cours.
-"Finir" une activité varie d\'une activité à l\'autre - "voir" une ressource, "envoyer" un quiz ou un fichier, "répondre" à un forum ou participez à un chat, etc
-Si un suivi de fin de Moodle 2.0 est activé pour une activité particulière, il sera utilisé pour les cocher l\'élément dans la liste
-Pour plus de détails sur la cause exacte qu\'une activité peut être marqué comme "achevée", demandez à votre administrateur du site pour regarder dans le fichier "mod / liste / autoupdate.php"
-Remarque: cel peut prendre jusqu\'à 60 secondes pour que l\'activité d\'un étudiant se mette à jour dans leur Liste des tâches'; +$string['autoupdate_help'] = 'Cela va automatiquement cocher les éléments de votre CheckList lorsque vous terminez l\'activité concernée dans le cours.
+"Finir" une activité varie d\'une activité à l\'autre - "voir" une ressource, "envoyer" un quiz ou un fichier, "répondre" à un forum ou participez à un chat, etc
+Si un suivi de fin de Moodle 2.0 est activé pour une activité particulière, il sera utilisé pour les cocher l\'élément dans la liste
+Pour plus de détails sur la cause exacte qu\'une activité peut être marqué comme "achevée", demandez à votre administrateur du site pour regarder dans le fichier "mod / liste / autoupdate.php"
+Remarque: cel peut prendre jusqu\'à 60 secondes pour que l\'activité d\'un étudiant se mette à jour dans leur CheckList'; -$string['autoupdatewarning_both'] = 'Il ya des items sur cette liste qui seront automatiquement mis à jour (comme ceux que les étudiants disent "complet"). Cependant, dans le cas d\'une Liste des tâches commune "étudiant et enseignant", les barres de progression ne seront pas mise à jour tant qu\'un enseignant accepte les notes attribuées.'; -$string['autoupdatewarning_student'] = 'Il ya des items sur cette liste qui seront automatiquement mis à jour (comme ceux que les étudiants disent "complet").'; -$string['autoupdatewarning_teacher'] = 'La mise à jour automatique a été activée pour cette liste, mais ces remarques ne seront pas affichée tant que l\'enseignant ne les montrent pas.'; +$string['autoupdatewarning_both'] = 'Il ya des items sur cette liste qui seront automatiquement mis à jour (comme ceux que les étudiants disent "complet"). Cependant, dans le cas d\'une CheckList commune "étudiant et enseignant", les barres de progression ne seront pas mise à jour tant qu\'un enseignant accepte les notes attribuées.'; +$string['autoupdatewarning_student'] = 'Il ya des items sur cette liste qui seront automatiquement mis à jour (comme ceux que les étudiants disent "complet").'; +$string['autoupdatewarning_teacher'] = 'La mise à jour automatique a été activée pour cette liste, mais ces remarques ne seront pas affichée tant que l\'enseignant ne les montrent pas.'; $string['canceledititem'] = 'Effacer'; -$string['calendardescription'] = 'Cet élément a été ajouté par la Liste des tâches : {$a}'; +$string['calendardescription'] = 'Cet élément a été ajouté par la CheckList : {$a}'; $string['changetextcolour'] = 'Prochaine couleur de texte'; -$string['checkeditemsdeleted'] = 'Items de la Liste des tâches supprimés'; +$string['checkeditemsdeleted'] = 'Items de la CheckList supprimés'; -$string['checklist'] = 'Liste des tâches'; -$string['pluginadministration'] = 'Administration de la Liste des tâches'; +$string['checklist'] = 'CheckList'; +$string['pluginadministration'] = 'Administration de la CheckList'; -$string['checklist:edit'] = 'Créer et éditer des Liste des tâches'; +$string['checklist:edit'] = 'Créer et éditer des CheckList'; $string['checklist:emailoncomplete'] = 'Recevoir par mail quand c\'est complet'; -$string['checklist:preview'] = 'Prévisualisation d\'une Liste des tâches'; -$string['checklist:updatelocked'] = 'Mise à jour des marques verrouillée'; -$string['checklist:updateother'] = 'Mise à jour des marques des Liste des tâches des étudiants'; -$string['checklist:updateown'] = 'Mise à jour de vos marques des Liste des tâches'; -$string['checklist:viewreports'] = 'Voir la progression des étudiants'; +$string['checklist:preview'] = 'Prévisualisation d\'une CheckList'; +$string['checklist:updatelocked'] = 'Mise à jour des marques verrouillée'; +$string['checklist:updateother'] = 'Mise à jour des marques des CheckList des étudiants'; +$string['checklist:updateown'] = 'Mise à jour de vos marques des CheckList'; +$string['checklist:viewreports'] = 'Voir la progression des étudiants'; -$string['checklistautoupdate'] = 'Autoriser les Liste des tâches à se mettre à jour automatiquement'; +$string['checklistautoupdate'] = 'Autoriser les CheckList à se mettre à jour automatiquement'; -$string['checklistfor'] = 'Liste des tâches pour'; +$string['checklistfor'] = 'CheckList pour'; $string['checklistintro'] = 'Introduction'; -$string['checklistsettings'] = 'Paramètres'; +$string['checklistsettings'] = 'Paramètres'; $string['checks'] = 'Marques'; $string['comments'] = 'Commentaires'; $string['completionpercentgroup'] = 'A cocher obligatoirement'; -$string['completionpercent'] = 'Pourcentage d\'items qui doivent être cochés :'; +$string['completionpercent'] = 'Pourcentage d\'items qui doivent être cochés :'; -$string['configchecklistautoupdate'] = 'Avant de permettre cela, vous devez faire quelques modifications au code Moodle, merci de voir le "mod / liste / README.txt" pour plus de détails'; +$string['configchecklistautoupdate'] = 'Avant de permettre cela, vous devez faire quelques modifications au code Moodle, merci de voir le "mod / liste / README.txt" pour plus de détails'; -$string['confirmdeleteitem'] = 'Etes-vous sûr de vouloir effacer définitivement cet item de la Liste des tâches?'; +$string['confirmdeleteitem'] = 'Etes-vous sûr de vouloir effacer définitivement cet item de la CheckList ?'; $string['deleteitem'] = 'Effacer cet item'; -$string['duedatesoncalendar'] = 'Ajouter les dates d\'échéance au calendrier'; +$string['duedatesoncalendar'] = 'Ajouter les dates d\'échéance au calendrier'; -$string['edit'] = 'Editer la Liste des tâches'; +$string['edit'] = 'Editer la CheckList'; $string['editchecks'] = 'Editer les coches'; $string['editdatesstart'] = 'Editer les dates'; -$string['editdatesstop'] = 'Arrêt de l\édition des dates'; +$string['editdatesstop'] = 'Arrêt de l\édition des dates'; $string['edititem'] = 'Editer cet item'; -$string['emailoncomplete'] = 'Envoyer un courriel à l\'enseignant quand la liste des tâches est complète'; -$string['emailoncomplete_help'] = 'Quand une liste est complète, un courriel de notification est envoyé à tous les enseignants du cours.
-Un administrateur peut contrôler qui reçoit ce courriel en utilisant la capacité "mod: check-list / emailoncomplete" - par défaut, tous les enseignants et non enseignants non éditeur ont cette capacité.'; -$string['emailoncompletesubject'] = 'L\utilisateur {$a->user} a complété sa Liste de tâches \'{$a->checklist}\''; -$string['emailoncompletebody'] = 'L\utilisateur {$a->user} a complété sa Liste de tâches \'{$a->checklist}\' -Voir la Liste des tâches ici :'; +$string['emailoncomplete'] = 'Envoyer un courriel à l\'enseignant quand la CheckList est complète'; +$string['emailoncomplete_help'] = 'Quand une liste est complète, un courriel de notification est envoyé à tous les enseignants du cours.
+Un administrateur peut contrôler qui reçoit ce courriel en utilisant la capacité "mod: check-list / emailoncomplete" - par défaut, tous les enseignants et non enseignants non éditeur ont cette capacité.'; +$string['emailoncompletesubject'] = 'L\utilisateur {$a->user} a complété sa Liste de items \'{$a->checklist}\''; +$string['emailoncompletebody'] = 'L\utilisateur {$a->user} a complété sa Liste de items \'{$a->checklist}\' +Voir la CheckList ici :'; -$string['export'] = 'Exportation des items'; +$string['export'] = 'Exporter des items'; -$string['forceupdate'] = 'Mise à jour des coches pour les items automatiques'; +$string['forceupdate'] = 'Mise à jour des coches pour les items automatiques'; $string['gradetocomplete'] = 'Evaluation pour terminer'; -$string['guestsno'] = 'Vous n\'avez pas la permission de voir cette Liste des tâches'; +$string['guestsno'] = 'Vous n\'avez pas la permission de voir cette CheckList'; -$string['headingitem'] = 'Cet item est une étiquette, il n\'y aura pas de case à cocher à côté'; +$string['headingitem'] = 'Cet item est une étiquette, il n\'y aura pas de case à cocher à côté'; -$string['import'] = 'Import d\'items'; -$string['importfile'] = 'Choisir le fichier à importer'; +$string['import'] = 'Importer des items'; +$string['importfile'] = 'Choisir le fichier à importer'; $string['importfromsection'] = 'Section courante'; $string['importfromcourse'] = 'Tout le cours'; -$string['indentitem'] = 'Décaller l\'item'; -$string['itemcomplete'] = 'Terminé'; -$string['items'] = 'Items de la Liste des tâches'; +$string['indentitem'] = 'Décaller l\'item'; +$string['itemcomplete'] = 'Terminé'; +$string['items'] = 'Items de la CheckList'; -$string['linktomodule'] = 'Lien de la ressource ou de l\'activité'; +$string['linktomodule'] = 'Lien de la ressource ou de l\'activité'; $string['lockteachermarks'] = 'Verrouillage des coches de l\'enseignant'; -$string['lockteachermarks_help'] = 'Lorsque ce paramètre est activé, une fois qu\'un enseignant a sauvé une coche "Oui", il ne sera plus possible de changer la valeur. Les utilisateurs ayant la capacité "mod / check-list: updatelocked" sera toujours en mesure de changer la coche.'; -$string['lockteachermarkswarning'] = 'Remarque: Une fois que vous avez enregistré ces coches, il vous sera impossible de changer toutes les coches "Oui"'; +$string['lockteachermarks_help'] = 'Lorsque ce paramètre est activé, une fois qu\'un enseignant a sauvé une coche "Oui", il ne sera plus possible de changer la valeur. Les utilisateurs ayant la capacité "mod / check-list: updatelocked" sera toujours en mesure de changer la coche.'; +$string['lockteachermarkswarning'] = 'Remarque: Une fois que vous avez enregistré ces coches, il vous sera impossible de changer toutes les coches "Oui"'; -$string['modulename'] = 'Liste des tâches'; -$string['modulenameplural'] = 'Listes des tâches'; +$string['modulename'] = 'CheckList'; +$string['modulenameplural'] = 'CheckLists'; $string['moveitemdown'] = 'Descendre l\'item'; $string['moveitemup'] = 'Monter l\'item'; -$string['noitems'] = 'Pas d\'items dans la Liste des tâches'; +$string['noitems'] = 'Pas d\'items dans la CheckList'; $string['optionalitem'] = 'Cet item est optionnel'; $string['optionalhide'] = 'Cacher les options des items'; @@ -132,53 +266,53 @@ $string['percentcomplete'] = 'Items obligatoires'; $string['percentcompleteall'] = 'Tous les items'; -$string['pluginname'] = 'Liste des tâches'; -$string['preview'] = 'Prévisualisation'; +$string['pluginname'] = 'CheckList'; +$string['preview'] = 'Prévisualisation'; $string['progress'] = 'Progression'; -$string['removeauto'] = 'Supprimer les items des éléments du cours'; +$string['removeauto'] = 'Supprimer les items des éléments du cours'; $string['report'] = 'Voir la progression'; -$string['reporttablesummary'] = 'Table showing the items on the checklist that each student has completed'; +$string['reporttablesummary'] = 'Table affichant les éléments de la CheckList que chaque étudiant a complétées'; -$string['requireditem'] = 'Tableau montrant les éléments de la liste que chaque étudiant a complété'; +$string['requireditem'] = 'Tableau montrant les éléments de la liste que chaque étudiant a complété'; -$string['resetchecklistprogress'] = 'Réinitialiser la progression et les items de l\'utilisateur'; +$string['resetchecklistprogress'] = 'Réinitialiser la progression et les items de l\'utilisateur'; $string['savechecks'] = 'Sauvegarder'; -$string['showfulldetails'] = 'Afficher tous les détailsShow full details'; +$string['showfulldetails'] = 'Afficher tous les détailsShow full details'; $string['showprogressbars'] = 'Afficher les barres de progression'; /// $string['teachercomments'] = 'Les enseignants peuvent ajouter des commentaires'; -$string['teacheredit'] = 'Mises à jour par'; +$string['teacheredit'] = 'Mises à jour par'; -$string['teachermarkundecided'] = 'L\'enseignant n\'a pas encore coché cet item'; -$string['teachermarkyes'] = 'L\enseignant confirme que cet item est complet'; -$string['teachermarkno'] = 'L\enseignant ne confirme pas que cet item est complet'; +$string['teachermarkundecided'] = 'L\'enseignant n\'a pas encore coché cet item'; +$string['teachermarkyes'] = 'L\'enseignant confirme que cet item est complet'; +$string['teachermarkno'] = 'L\'enseignant ne confirme pas que cet item est complet'; -$string['teachernoteditcheck'] = 'Seulement l\'étudiant'; +$string['teachernoteditcheck'] = 'Seulement l\'étudiant'; $string['teacheroverwritecheck'] = 'Seulement l\'enseignant'; $string['teacheralongsidecheck'] = 'Etudiant et Enseignant'; $string['toggledates'] = 'Basculer les dates'; -$string['theme'] = 'Thème graphique pour afficher la Liste des tâches'; +$string['theme'] = 'Thème graphique pour afficher la CheckList'; -$string['updatecompletescore'] = 'Sauvegarder les notes d\'achèvement'; -$string['unindentitem'] = 'Item non indenté'; -$string['updateitem'] = 'Mise à jour'; +$string['updatecompletescore'] = 'Sauvegarder les notes d\'achèvement'; +$string['unindentitem'] = 'Item non indenté'; +$string['updateitem'] = 'Mise à jour'; $string['useritemsallowed'] = 'L\'utilisateur peut ajouter ses propres items'; -$string['useritemsdeleted'] = 'Items de l\'utilisateur supprimés'; +$string['useritemsdeleted'] = 'Items de l\'utilisateur supprimés'; -$string['view'] = 'Voir la Liste des tâches'; -$string['viewall'] = 'Voir tous les étudiants'; +$string['view'] = 'Voir la CheckList'; +$string['viewall'] = 'Voir tous les étudiants'; $string['viewallcancel'] = 'Effacer'; $string['viewallsave'] = 'Sauvegarder'; $string['viewsinglereport'] = 'Voir la progression de cet utilisateur'; -$string['viewsingleupdate'] = 'Mettre à jour la progression de cet utilisateur'; +$string['viewsingleupdate'] = 'Mettre à jour la progression de cet utilisateur'; $string['yesnooverride'] = 'Oui ne peut pas remplacer'; $string['yesoverride'] = 'Oui, peut remplacer'; diff --git a/mod/checklist/lib.php b/mod/checklist/lib.php index 00178d6a..a845347a 100644 --- a/mod/checklist/lib.php +++ b/mod/checklist/lib.php @@ -30,6 +30,9 @@ * actions across all modules. */ + +define ("USES_OUTCOMES", 1); // Outcomes imported as items + define("CHECKLIST_TEACHERMARK_NO", 2); define("CHECKLIST_TEACHERMARK_YES", 1); define("CHECKLIST_TEACHERMARK_UNDECIDED", 0); @@ -51,6 +54,93 @@ require_once(dirname(__FILE__).'/locallib.php'); require_once($CFG->libdir.'/completionlib.php'); +// ############################ MOODLE 2.0 FILE API ######################### +/** + * @author JF 2012/03/18 + * @author jean.fruitet@univ-nantes.fr + **/ + + +/** + * Serves activite documents and other files. + * + * @param object $course + * @param object $cm + * @param object $context + * @param string $filearea + * @param array $args + * @param bool $forcedownload + * @return bool false if file not found, does not return if found - just send the file + */ +function checklist_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +// fonction appelée par le gestionnaire de fichier + global $CFG, $DB; + + if ($context->contextlevel != CONTEXT_MODULE) { + return false; + } + + require_login($course, false, $cm); + + // verifier qu'un checklist est installé dans ce cours + if (! $checklist = $DB->get_record("checklist", array("id" => "$cm->instance"))) { + return false; + } + + return checklist_send_file($course, $cm, $context, $filearea, $args); +} + +/** + * Serves activite documents and other files. + * + * @param object $course + * @param object $cm + * @param object $context + * @param string $filearea + * @param array $args + * @return bool false if file not found, does not return if found - just send the file + */ + +function checklist_send_file($course, $cm, $context, $filearea, $args) { +// affiche le contenu d'un fichier + global $CFG, $DB, $USER; + require_once($CFG->libdir.'/filelib.php'); + + require_login($course, false, $cm); + + // DEBUG + // echo "
DEBUG :: lib.php :: 110 ::
CONTEXT : $context->id :: FILEAREA : $filearea
ARGS:\n"; + // print_r($args); + // + $docid = (int)array_shift($args); + + // verifier les fileareas acceptables + $fileareas = array('checklist', 'document'); + if (!in_array($filearea, $fileareas)) { + return false; + } + + if ($filearea=='document'){ + if (!$document = $DB->get_record('checklist_document', array('id'=>$docid))) { + return false; + } + } + + $relativepath = implode('/', $args); + $fullpath = '/'.$context->id.'/mod_checklist/'.$filearea.'/'.$docid.'/'.$relativepath; + + $fs = get_file_storage(); + + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + return false; + } + + send_stored_file($file, 0, 0, true); // download MUST be forced - security! +} +// END FILE API +// ############################################################################################### + + /** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function @@ -547,13 +637,25 @@ function checklist_cron () { return true; } + + $lastlogtime = $lastcron - 5; // Subtract 5 seconds just in case a log slipped through during the last cron update + + + // Process Outcomes as Items + $outcomesupdate = 0; + if (!empty($CFG->enableoutcomes) && USES_OUTCOMES){ + require_once($CFG->dirroot.'/mod/checklist/cron_outcomes.php'); + $outcomesupdate+=checklist_cron_outcomes($lastlogtime); + } + if ($outcomesupdate) { + mtrace(" Updated $outcomesupdate checkmark(s) from outcomes changes"); + } + require_once($CFG->dirroot.'/mod/checklist/autoupdate.php'); if (!$CFG->checklist_autoupdate_use_cron) { return true; } - $lastlogtime = $lastcron - 5; // Subtract 5 seconds just in case a log slipped through during the last cron update - // Find all autoupdating checklists $checklists = $DB->get_records_select('checklist', 'autopopulate > 0 AND autoupdate > 0'); if (!$checklists) { @@ -586,6 +688,7 @@ function checklist_cron () { mtrace(" Updated $logupdate checkmark(s) from log changes"); } + // Process all the completion changes since the last cron update // Need the cmid, userid and newstate $completionupdate = 0; @@ -605,6 +708,7 @@ function checklist_cron () { mtrace(" Updated $completionupdate checkmark(s) from completion changes"); } + return true; } @@ -782,3 +886,5 @@ function checklist_get_completion_state($course, $cm, $userid, $type) { return $result; } + + diff --git a/mod/checklist/locallib.php b/mod/checklist/locallib.php index 41f8263f..7c711e48 100644 --- a/mod/checklist/locallib.php +++ b/mod/checklist/locallib.php @@ -19,9 +19,16 @@ * Stores all the functions for manipulating a checklist * * @author David Smith - * @package mod/checklist + * + * New function view_select_export + * New function select_items, *_description, *_document + * Function modified : view_tabs, view + * @author Jean Fruitet + * @package mod/checklist */ + + require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once(dirname(__FILE__).'/lib.php'); @@ -37,6 +44,7 @@ define("CHECKLIST_HIDDEN_BYMODULE", 2); class checklist_class { + var $cm; var $course; var $checklist; @@ -50,21 +58,22 @@ class checklist_class { var $additemafter; var $editdates; var $groupings; - + + var $description = array(array()); // for each item, each user, id of description object; + function checklist_class($cmid='staticonly', $userid=0, $checklist=null, $cm=null, $course=null) { - global $COURSE, $DB, $CFG; + global $COURSE, $DB, $CFG, $USER; if ($cmid == 'staticonly') { //use static functions only! return; } - $this->userid = $userid; if ($cm) { $this->cm = $cm; } else if (! $this->cm = get_coursemodule_from_id('checklist', $cmid)) { - error('Course Module ID was incorrect'); + print_error(get_string('error_cmid', 'checklist')); // 'Course Module ID was incorrect' } if ($CFG->version < 2011120100) { @@ -78,13 +87,13 @@ function checklist_class($cmid='staticonly', $userid=0, $checklist=null, $cm=nul } else if ($this->cm->course == $COURSE->id) { $this->course = $COURSE; } else if (! $this->course = $DB->get_record('course', array('id' => $this->cm->course) )) { - error('Course is misconfigured'); + print_error(get_string('error_course', 'checklist')); // 'Course is misconfigured' } if ($checklist) { $this->checklist = $checklist; } else if (! $this->checklist = $DB->get_record('checklist', array('id' => $this->cm->instance) )) { - error('checklist ID was incorrect'); + print_error(get_string('error_checklist_id', 'checklist')); // 'checklist ID was incorrect' } if (isset($CFG->enablegroupmembersonly) && $CFG->enablegroupmembersonly && $checklist->autopopulate && $userid) { @@ -311,7 +320,6 @@ function update_items_from_course() { reset($this->items); $this->items[$itemid]->stillexists = true; $this->items[$itemid]->grouping = ($groupmembersonly && $mods->cms[$cmid]->groupmembersonly) ? $mods->cms[$cmid]->groupingid : 0; - $item = $this->items[$itemid]; } $item->modulelink = new moodle_url('/mod/'.$mods->cms[$cmid]->modname.'/view.php', array('id' => $cmid)); $nextpos++; @@ -464,7 +472,7 @@ static function filter_mentee_users($userids) { } function view() { - global $CFG, $OUTPUT; + global $CFG, $OUTPUT, $USER; if ((!$this->items) && $this->canedit()) { redirect(new moodle_url('/mod/checklist/edit.php', array('id' => $this->cm->id)) ); @@ -499,6 +507,15 @@ function view() { if ($this->canupdateown()) { $this->process_view_actions(); } + // Mahara && Portofolio stuff + if (!empty($CFG->enableportfolios) && !empty($this->userid)){ + require_once($CFG->libdir.'/portfoliolib.php'); + $button = new portfolio_add_button(); + $button->set_callback_options('checklist_portfolio_caller', + array('instanceid' => $this->checklist->id, 'userid' => $this->userid, 'export_format' => ''), '/mod/checklist/mahara/locallib_portfolio.php'); + $button->set_formats(array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A)); + echo "
".$button->to_html(PORTFOLIO_ADD_ICON_LINK)."
\n"; + } $this->view_items(); @@ -645,6 +662,9 @@ function view_progressbar() { $allcompleteitems = 0; $checkgroupings = $this->checklist->autopopulate && ($this->groupings !== false); foreach ($this->items as $item) { + //echo "
DEBUG :: locallib.php :: 667 :: ITEM
\n"; + //print_r($item); + //echo "
\n"; if (($item->itemoptional == CHECKLIST_OPTIONAL_HEADING)||($item->hidden)) { continue; } @@ -656,8 +676,9 @@ function view_progressbar() { if ($item->itemoptional == CHECKLIST_OPTIONAL_NO) { $requireditems++; if ($teacherprogress) { + // if (isset($item->teachermark) && ($item->teachermark == CHECKLIST_TEACHERMARK_YES)) { if ($item->teachermark == CHECKLIST_TEACHERMARK_YES) { - $completeitems++; + $completeitems++; $allcompleteitems++; } } else if ($item->checked) { @@ -665,7 +686,7 @@ function view_progressbar() { $allcompleteitems++; } } else if ($teacherprogress) { - if ($item->teachermark == CHECKLIST_TEACHERMARK_YES) { + if (isset($item->teachermark) && ($item->teachermark == CHECKLIST_TEACHERMARK_YES)) { $allcompleteitems++; } } else if ($item->checked) { @@ -737,6 +758,8 @@ function get_teachermark($itemid) { function view_items($viewother = false, $userreport = false) { global $DB, $OUTPUT, $PAGE; + global $CFG; + global $USER; echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); @@ -753,7 +776,7 @@ function view_items($viewother = false, $userreport = false) { $thispage = new moodle_url('/mod/checklist/report.php', array('id' => $this->cm->id, 'studentid' => $this->userid) ); if (!$student = $DB->get_record('user', array('id' => $this->userid) )) { - error('No such user!'); + print_error(get_string('error_user','checklist')); // 'No such user!' } $info = $this->checklist->name.' ('.fullname($student, true).')'; @@ -773,6 +796,7 @@ function view_items($viewother = false, $userreport = false) { echo ' '; echo ''; } + echo '
'; echo html_writer::input_hidden_params($thispage); echo ''; @@ -994,7 +1018,7 @@ function view_items($viewother = false, $userreport = false) { if (array_key_exists($item->id, $comments)) { $comment = $comments[$item->id]; $foundcomment = true; - echo '  '; + echo '
 '; if ($comment->commentby) { $userurl = new moodle_url('/user/view.php', array('id'=>$comment->commentby, 'course'=>$this->course->id) ); echo ''.fullname($commentusers[$comment->commentby]).': '; @@ -1007,7 +1031,7 @@ function view_items($viewother = false, $userreport = false) { } echo ''; } else { - echo s($comment->text); + echo $comment->text; } echo ' '; } @@ -1016,6 +1040,11 @@ function view_items($viewother = false, $userreport = false) { echo ' '; } + // Display descriptions + $editdescription=$CFG->checklist_description_display; + if ($editdescription) { + $this->display_description_documents($item->id, $this->userid, ($USER->id==$this->userid)); + } echo ''; // Output any user-added items @@ -1159,6 +1188,8 @@ function view_items($viewother = false, $userreport = false) { echo $OUTPUT->box_end(); } + + function print_edit_date($ts=0) { // TODO - use fancy JS calendar instead @@ -1204,14 +1235,26 @@ function print_edit_date($ts=0) { } function view_import_export() { + global $CFG; + $importurl = new moodle_url('/mod/checklist/import.php', array('id' => $this->cm->id)); $exporturl = new moodle_url('/mod/checklist/export.php', array('id' => $this->cm->id)); - $importstr = get_string('import', 'checklist'); $exportstr = get_string('export', 'checklist'); echo "
"; - echo "$importstr   $exportstr"; + + if (USES_OUTCOMES && !empty($CFG->checklist_outcomes_input)){ + $importoutcomesurl = new moodle_url('/mod/checklist/import_outcomes.php', array('id' => $this->cm->id)); + $importoutcomesstr = get_string('import_outcomes', 'checklist'); + $exportoutcomesurl = new moodle_url('/mod/checklist/select_export.php', array('id' => $this->cm->id)); + $exportoutcomesstr = get_string('export_outcomes', 'checklist'); + echo "$importstr  $importoutcomesstr  $exportstr  $exportoutcomesstr"; + } + else{ + echo "$importstr     $exportstr"; + } + echo "
"; } @@ -1878,7 +1921,7 @@ function process_view_actions() { } if (!confirm_sesskey()) { - error('Invalid sesskey'); + print_error('error_sesskey', 'checklist'); // 'Invalid sesskey'; } $itemid = optional_param('itemid', 0, PARAM_INT); @@ -1924,8 +1967,9 @@ function process_view_actions() { $this->updateitemtext($itemid, $displaytext); break; + default: - error('Invalid action - "'.s($action).'"'); + print_error(get_string('error_action', 'checklist', s($action))); // 'Invalid action - "{a}"' } if ($action != 'updatechecks') { @@ -1942,7 +1986,7 @@ function process_edit_actions() { // Remove any automatically generated items from the list // (if no longer using automatic items) if (!confirm_sesskey()) { - error('Invalid sesskey'); + print_error(get_string('error_sesskey', 'checklist')); // 'Invalid sesskey' } $this->removeauto(); return; @@ -1955,7 +1999,7 @@ function process_edit_actions() { } if (!confirm_sesskey()) { - error('Invalid sesskey'); + print_error(get_string('error_sesskey', 'checklist')); // 'Invalid sesskey' } $itemid = optional_param('itemid', 0, PARAM_INT); @@ -2025,7 +2069,7 @@ function process_edit_actions() { $this->nextcolour($itemid); break; default: - error('Invalid action - "'.s($action).'"'); + print_error(get_string('error_action', 'checklist', s($action))); // 'Invalid action - "{a}"' } if ($additemafter) { @@ -2083,7 +2127,7 @@ function process_report_actions() { } if (!confirm_sesskey()) { - error('Invalid sesskey'); + print_error('error_sesskey', 'checklist'); // 'Invalid sesskey'; } switch ($action) { @@ -2682,6 +2726,7 @@ function updatechecks($newchecks) { } } + function updateteachermarks() { global $USER, $DB, $CFG; @@ -2698,7 +2743,7 @@ function updateteachermarks() { $updategrades = false; if ($this->checklist->teacheredit != CHECKLIST_MARKING_STUDENT) { if (!$student = $DB->get_record('user', array('id' => $this->userid))) { - error('No such user!'); + print_error(get_string('error_user','checklist')); // 'No such user!' } $info = $this->checklist->name.' ('.fullname($student, true).')'; add_to_log($this->course->id, 'checklist', 'update checks', "report.php?id={$this->cm->id}&studentid={$this->userid}", $info, $this->cm->id); @@ -2889,6 +2934,7 @@ function update_all_autoupdate_checks() { return; } $userids = implode(',',array_keys($users)); + $updategrades = false; // Get a list of all the checklist items with a module linked to them (ignoring headings) $sql = "SELECT cm.id AS cmid, m.name AS mod_name, i.id AS itemid, cm.completion AS completion @@ -2914,6 +2960,7 @@ function update_all_autoupdate_checks() { } $check->usertimestamp = time(); $DB->update_record('checklist_check', $check); + $updategrades = true; } else { $check = new stdClass; $check->item = $item->itemid; @@ -2923,6 +2970,7 @@ function update_all_autoupdate_checks() { $check->teachermark = CHECKLIST_TEACHERMARK_UNDECIDED; $check->id = $DB->insert_record('checklist_check', $check); + $updategrades = true; } } } @@ -3020,6 +3068,7 @@ function update_all_autoupdate_checks() { } $check->usertimestamp = time(); $DB->update_record('checklist_check', $check); + $updategrades = true; } else { $check = new stdClass; $check->item = $item->itemid; @@ -3029,11 +3078,13 @@ function update_all_autoupdate_checks() { $check->teachermark = CHECKLIST_TEACHERMARK_UNDECIDED; $check->id = $DB->insert_record('checklist_check', $check); + $updategrades = true; } } - // Always update the grades - checklist_update_grades($this->checklist); + if ($updategrades) { + checklist_update_grades($this->checklist); + } } } @@ -3157,6 +3208,765 @@ function get_user_groupings($userid, $courseid) { } return array(); } + + +/** + * Extract skill repository and competency codes from a displaytext field + * outcome_name;outcome_shortname;outcome_description;scale_name;scale_items;scale_description + * "C2i2e-2011 A.1-1 :: Identifier les personnes ressources Tic et leurs rôles respectifs (...)";A.1-1;"Identifier les personnes ressources Tic et leurs rôles respectifs au niveau local, régional et national.";"Item référentiel";"Non pertinent,Non validé,Validé";"Ce barème est destiné à évaluer l'acquisition des compétences du module référentiel." + * | | | description + * | | ^ separator 2 '::' + * ^ separator 1 ' ' + * | | competence_code + * | referentiel_code + * @imput displaytext string + * @output object + **/ + function get_referentiel_code($displaytext){ + // extract skill repository code and competency code from an outcome_name field + $item_outcome = new stdClass; + if (!empty($displaytext)){ + if (preg_match('/(.*)::(.*)/i', trim($displaytext), $matches)){ + if ($matches[1]){ + if ($keywords = preg_split("/[\s]+/",$matches[1],-1,PREG_SPLIT_NO_EMPTY)){ + if ($keywords[0] && $keywords[1]){ + $item_outcome->code_referentiel=trim($keywords[0]); + $item_outcome->code_competence=trim($keywords[1]); + } + else{ + return NULL; + } + } + } + } + } + return $item_outcome; + } + +/** + * Selection des items pour exporter les outcomes + * + **/ + function view_select_export() { + global $CFG, $OUTPUT; + + if (!$this->canedit()) { + redirect(new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)) ); + } + + if ((!$this->items) && $this->canedit()) { + redirect(new moodle_url('/mod/checklist/edit.php', array('id' => $this->cm->id)) ); + } + + // $currenttab = 'selectexport'; + $currenttab = 'edit'; + + $this->view_header(); + + echo $OUTPUT->heading(format_string($this->checklist->name)); + + $this->view_tabs($currenttab); + + add_to_log($this->course->id, 'checklist', 'view', "selectexport.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + $this->select_items(); + + $this->view_footer(); + } + + function select_items($viewother = false) { + global $DB, $OUTPUT, $PAGE; + + echo '

'.get_string('export_outcomes', 'checklist').'

'."\n"; + + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + + $thispage = new moodle_url('/mod/checklist/export_selected_outcomes.php', array('id' => $this->cm->id) ); + + echo format_text($this->checklist->intro, $this->checklist->introformat); + echo '
'; + + $showcheckbox=true; + $checkclass = ''; + $optional = CHECKLIST_OPTIONAL_NO; + + if (!$this->items) { + print_string('noitems','checklist'); + } else { + // looks for referentiel_code + $referentiel_code=''; + $useitemid=true; + foreach ($this->items as $item) { + $outcome=$this->get_referentiel_code($item->displaytext); + if (!empty($outcome) && !empty($outcome->code_referentiel)){ + $referentiel_code=$outcome->code_referentiel; + if (!empty($outcome->code_competence)){ + $useitemid=false; + } + break; + } + } + + $focusitem = false; + if ($referentiel_code){ + echo get_string('confirmreferentielname','checklist').'     '."\n"; + } + else{ + echo get_string('addreferentielname','checklist').'     '."\n"; + } + echo $OUTPUT->help_icon('referentiel_codeh','checklist')."\n"; + + echo ''; + echo html_writer::input_hidden_params($thispage); + echo ''; + echo '
'.get_string('useitemid','checklist').'    '; + if ($useitemid){ + echo ''.get_string('yes')."\n"; + echo ''.get_string('no')."\n"; + } + else{ + echo ''.get_string('yes')."\n"; + echo ''.get_string('no')."\n"; + } + echo '
'."\n"; + + echo ''; + echo ''; + echo '
'.get_string('select_items_export','checklist'); + echo $OUTPUT->help_icon('items_exporth','checklist')."\n"; + + // selection des checkbox + echo '
'."\n"; + echo ''."\n"; + echo '      '."\n"; + echo '
'."\n"; + + + echo '
    '; + $currindent = 0; + + + foreach ($this->items as $item) { + + if ($item->hidden) { + continue; + } + + while ($item->indent > $currindent) { + $currindent++; + echo '
      '; + } + while ($item->indent < $currindent) { + $currindent--; + echo '
    '; + } + $itemname = '"item'.$item->id.'"'; + $checked = ($item->checked) ? ' checked="checked" ' : ''; + + switch ($item->colour) { + case 'red': + $itemcolour = 'itemred'; + break; + case 'orange': + $itemcolour = 'itemorange'; + break; + case 'green': + $itemcolour = 'itemgreen'; + break; + case 'purple': + $itemcolour = 'itempurple'; + break; + default: + $itemcolour = 'itemblack'; + } + + echo '
  1. '; + if ($showcheckbox) { + if ($item->itemoptional == CHECKLIST_OPTIONAL_HEADING) { + //echo ''; + } else { + echo ''; + } + } + echo ''; + if (isset($item->modulelink)) { + echo ' '.get_string('linktomodule','checklist').''; + } + + echo '
  2. '; + + // Output any user-added items + if ($this->useritems) { + $useritem = current($this->useritems); + + if ($useritem && ($useritem->position == $item->position)) { + + echo '
      '; + while ($useritem && ($useritem->position == $item->position)) { + $itemname = '"item'.$useritem->id.'"'; + echo '
    1. '; + if ($showcheckbox) { + echo ''; + } + $splittext = explode("\n",s($useritem->displaytext),2); + $splittext[] = ''; + $text = $splittext[0]; + $note = str_replace("\n",'
      ',$splittext[1]); + echo ''; + if ($note != '') { + echo '
      '.$note.'
      '; + } + + echo '
    2. '; + + $useritem = next($this->useritems); + } + echo '
    '; + } + } + + } + echo '
'; + + echo ''; + echo '    '; + + if ($viewother) { + echo ' '; + echo ' '; + } + echo ''; + + + if ($focusitem) { + echo ''; + } + } + + echo $OUTPUT->box_end(); + } + + + + /** + * @input an array of items ids + * @output ? + * + **/ + + function exportchecks($newchecks) { + $t_selected_items=array(); + + if (is_array($newchecks) && !empty($newchecks)) { + + if ($this->items) { + foreach ($this->items as $item) { + $newval = in_array($item->id, $newchecks); + if ($newval) { + // stocker + $t_selected_items[]=$item; + } + } + } + if ($this->useritems) { + foreach ($this->useritems as $item) { + $newval = in_array($item->id, $newchecks); + + if ($newval) { + // stocker + $t_selected_items[]=$item; + } + } + } + } + return $t_selected_items; + } + + function get_item_description($itemid, $userid){ + // + global $DB; + return ($DB->select_record_sql("SELECT * FROM {checklist_description} WHERE itemid=? AND userid=?", array($itemid, $userid))); + } + + + function edit_description($itemid, $userid) { + global $DB; + global $CFG; + global $OUTPUT; + global $PAGE; + + $description = NULL; + $document = NULL; + + $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + + $thispage = new moodle_url('/mod/checklist/edit_description.php', array('id' => $this->cm->id) ); + $returl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + + $currenttab = 'view'; + + add_to_log($this->course->id, 'checklist', 'view', "edit_description.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + if ($itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if (!empty($description)){ + $documents = $DB->get_records('checklist_document', array("descriptionid" => $description->id)); + } + + $mform = new mod_checklist_description_form(null, + array('checklist'=>$this->checklist->id, + 'contextid'=>$context->id, + 'itemid'=>$itemid, + 'userid'=>$userid, + 'description'=>$description, + 'msg' => get_string('input_description', 'checklist'))); + + if ($mform->is_cancelled()) { + redirect($returnurl); + } else if ($mform->get_data()) { + checklist_set_description($mform, $this->checklist->id); + die(); + } + + $this->view_header(); + + echo '

'.get_string('edit_description', 'checklist').'

'."\n"; + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + echo format_text($this->checklist->intro, $this->checklist->introformat); + echo '
'; + + $mform->display(); + + echo $OUTPUT->box_end(); + $this->view_footer(); + } + } + + + function edit_upload_document($itemid, $userid, $descriptionid, $documentid=0) { + global $DB; + global $CFG; + global $OUTPUT; + global $PAGE; + + $document=NULL; + + $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + + $thispage = new moodle_url('/mod/checklist/edit_document.php', array('id' => $this->cm->id) ); + $returl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + + $currenttab = 'view'; + + add_to_log($this->course->id, 'checklist', 'view', "edit_document.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + if (empty($descriptionid) && $itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if ($description){ + $descriptionid=$description; + } + } + + if ($descriptionid){ + // Is there any document attached to that description + if ($documentid) { + $document = $DB->get_record('checklist_document', array("descriptionid" => $description->id, "id" => $documentid)); + } + else{ + // $documents = $DB->get_records('checklist_document', array("descriptionid" => $description->id)); + $params=array("descriptionid" => $descriptionid); + $sql="SELECT * FROM {checklist_document} WHERE descriptionid=:descriptionid ORDER BY id DESC "; + $documents = $DB->get_records_sql($sql, $params); + if ($documents){ + foreach($documents as $document){ + break; // renvoyer le plus récent + } + } + } + + $options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $this->course->maxbytes), 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); + + $mform = new mod_checklist_add_document_upload_form(null, + array('checklist'=>$this->checklist->id, + 'contextid'=>$context->id, + 'itemid'=>$itemid, + 'userid'=>$userid, + 'descriptionid'=>$descriptionid, + 'document'=>$document, + 'filearea'=>'document', + 'msg' => get_string('document_associe', 'checklist'), + 'options'=>$options)); + + if ($mform->is_cancelled()) { + redirect($returnurl); + } else if ($mform->get_data()) { + checklist_add_upload_document($mform, $this->checklist->id); + die(); + // redirect(new moodle_url('/mod/checklist/view.php', array('id'=>$cm->id))); + } + + $this->view_header(); + echo '

'.get_string('edit_document', 'checklist').'

'."\n"; + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + echo format_text($this->checklist->intro, $this->checklist->introformat); + echo '
'; + + $mform->display(); + + echo $OUTPUT->box_end(); + $this->view_footer(); + } + } + + + function add_document($itemid, $userid, $descriptionid) { + global $DB; + global $CFG; + global $OUTPUT; + global $PAGE; + + $document=NULL; + + $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + + $thispage = new moodle_url('/mod/checklist/add_document.php', array('id' => $this->cm->id) ); + $returl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + + $currenttab = 'view'; + + add_to_log($this->course->id, 'checklist', 'view', "add_document.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + if (empty($descriptionid) && $itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if ($description){ + $descriptionid=$description; + } + } + + if ($descriptionid){ + $options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $this->course->maxbytes), 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); + + $mform = new mod_checklist_add_document_upload_form(null, + array('checklist'=>$this->checklist->id, + 'contextid'=>$context->id, + 'itemid'=>$itemid, + 'userid'=>$userid, + 'descriptionid'=>$descriptionid, + 'document'=>NULL, + 'filearea'=>'document', + 'msg' => get_string('document_associe', 'checklist'), + 'options'=>$options)); + + if ($mform->is_cancelled()) { + redirect($returnurl); + } else if ($mform->get_data()) { + checklist_add_upload_document($mform, $this->checklist->id); + die(); + // redirect(new moodle_url('/mod/checklist/view.php', array('id'=>$cm->id))); + } + + $this->view_header(); + echo '

'.get_string('edit_document', 'checklist').'

'."\n"; + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + echo format_text($this->checklist->intro, $this->checklist->introformat); + echo '
'; + + $mform->display(); + + echo $OUTPUT->box_end(); + $this->view_footer(); + } + } + + + + function edit_document($itemid, $userid, $document) { + global $DB; + global $CFG; + global $OUTPUT; + global $PAGE; + + $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + + $thispage = new moodle_url('/mod/checklist/edit_document.php', array('id' => $this->cm->id) ); + $returl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + + $currenttab = 'view'; + + add_to_log($this->course->id, 'checklist', 'view', "add_document.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + if ($document){ + $options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $this->course->maxbytes), 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); + + $mform = new mod_checklist_update_document_upload_form(null, + array('checklist'=>$this->checklist->id, + 'contextid'=>$context->id, + 'itemid'=>$itemid, + 'userid'=>$userid, + 'descriptionid'=>$document->descriptionid, + 'document'=>$document, + 'filearea'=>'document', + 'msg' => get_string('document_associe', 'checklist'), + 'options'=>$options)); + + + + if ($mform->is_cancelled()) { + redirect($returnurl); + } else if ($mform->get_data()) { + checklist_update_upload_document($mform, $this->checklist->id); + die(); + // redirect(new moodle_url('/mod/checklist/view.php', array('id'=>$cm->id))); + } + + $this->view_header(); + echo '

'.get_string('edit_document', 'checklist').'

'."\n"; + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + echo format_text($this->checklist->intro, $this->checklist->introformat); + echo '
'; + $mform->display(); + echo $OUTPUT->box_end(); + $this->view_footer(); + } + } + + + + function delete_document($documentid) { + // $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + + // $thispage = new moodle_url('/mod/checklist/delete_document.php', array('id' => $this->cm->id) ); + $returnurl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + add_to_log($this->course->id, 'checklist', 'view', "delete_document.php?id={$this->cm->id}&documentid=$documentid", $this->checklist->name, $this->cm->id); + + if ($documentid){ + $this->delete_document_record($documentid); + } + redirect($returnurl); + } + + + function delete_document_record($documentid) { + global $DB; + if ($documentid){ + // get from table + if ($document=$DB->get_record('checklist_document', array("id" => $documentid))){ + // delete file + // print_r($document); + if ($document->url_document){ + checklist_delete_a_file($document->url_document); + } + // delete row entry + $DB->delete_records('checklist_document', array("id" => $documentid)); + } + } + } + + function delete_description($descriptionid) { + $returnurl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + add_to_log($this->course->id, 'checklist', 'view', "delete_description.php?id={$this->cm->id}&descriptionid=$descriptionid", $this->checklist->name, $this->cm->id); + + if ($descriptionid){ + $this->delete_description_record($descriptionid); + } + redirect($returnurl); + } + + function delete_description_record($descriptionid) { + global $DB; + if ($descriptionid){ + // get from table + if ($description=$DB->get_record('checklist_description', array("id" => $descriptionid))){ + // get all documents + if ($documents = $DB->get_records('checklist_document', array("descriptionid" => $description->id))){ + foreach($documents as $document){ + $this->delete_document_record($document->id); + } + } + // delete table checklist_description record + $DB->delete_records('checklist_description', array("id" => $description->id)); + } + } + } + + function display_description_documents($itemid, $userid, $edition=false){ + // Display a description record and any document linked with it + global $DB; + global $OUTPUT; + global $CFG; + + if ($itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if (!empty($description)){ + echo '
  '; + $this->display_description($description); + echo '   '; + if ($edition){ + // icon edition + $editurl = new moodle_url('/mod/checklist/edit_description.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&itemid='.$itemid.'&userid='.$userid.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('edit_description','checklist').'"'; + echo '.$title.'; + // icon delete + $editurl = new moodle_url('/mod/checklist/delete_description.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&descriptionid='.$description->id.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('delete_description','checklist').'"'; + echo '.$title.'; + // icon edition link + $editurl = new moodle_url('/mod/checklist/add_document.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&itemid='.$itemid.'&userid='.$userid.'&descriptionid='.$description->id.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('add_link','checklist').'"'; + echo '.$title.'; + + if (!empty($CFG->enableportfolios)){ + // portfolio upload link + $editurl = new moodle_url('/mod/checklist/mahara/upload_mahara.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&itemid='.$itemid.'&userid='.$userid.'&descriptionid='.$description->id.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('upload_portfolio','checklist').'"'; + echo '.$title.'; + } + + } + $documents = $DB->get_records('checklist_document', array("descriptionid" => $description->id)); + if ($documents){ + echo '
    '."\n"; + foreach($documents as $document){ + if ($document){ + // Display link + $this->display_document($itemid, $userid, $document, $edition); + } + } + echo '
'."\n"; + } + + } + else{ + if ($edition){ + // icon edition + $editurl = new moodle_url('/mod/checklist/edit_description.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&itemid='.$itemid.'&userid='.$userid.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('edit_description','checklist').'"'; + echo '.$title.'; + } + } + } + } + + function display_description($description){ + // Display a description record + if (!empty($description)){ + echo stripslashes($description->description); + echo ' ['.userdate($description->timestamp).'] '."\n"; + } + } + + function display_document($itemid, $userid, $document, $edition=false){ + // Display a document record + global $CFG; + global $OUTPUT; + if (!empty($document)){ + if ($document->target==1){ + $cible_document='_blank'; // fenêtre cible + } + else{ + $cible_document=''; + } + if ($document->title){ + $etiquette_document=$document->title; // fenêtre cible + } + else{ + $etiquette_document=''; + } + echo '
  • '.get_string('doc_num','checklist',$document->id).'   '.$document->description_document."\n"; + echo checklist_affiche_url($document->url_document, $etiquette_document, $cible_document); + echo ' ['.userdate($document->timestamp).'] '."\n"; + if ($edition){ + // icon edition + $editurl = new moodle_url('/mod/checklist/edit_document.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&itemid='.$itemid.'&userid='.$userid.'&documentid='.$document->id.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('edit_link','checklist').'"'; + echo '.$title.'; + // icon delete + $editurl = new moodle_url('/mod/checklist/delete_document.php', array('id' => $this->cm->id) ); + $baseurl = $editurl.'&documentid='.$document->id.'&sesskey='.sesskey(); + echo ' '; + $title = '"'.get_string('delete_link','checklist').'"'; + echo '.$title.'; + } + echo '
  • '."\n"; + } + } + + +} // End of class + +// ################################ URL ############################### + +/** + * display an url accorging to moodle file management API + * @return string active link + * @ input $url : an uri + * @ input $etiquette : a label + * @ input $cible : a targeted frame +*/ + +function checklist_affiche_url($url, $etiquette="", $cible="") { + // MOODLE2 API + global $CFG; + // Moodle 1.9 + /* + $importfile = "{$CFG->dataroot}/{$url}"; + if (file_exists($importfile)) { + if ($CFG->slasharguments) { + $efile = "{$CFG->wwwroot}/file.php/$url"; + } + else { + $efile = "{$CFG->wwwroot}/file.php?file=/$url"; + } + } + else{ + $efile = "$url"; + } + */ + // Moodle 2.0 + if (!ereg("http",$url)){ // fichier telecharge + // l'URL a été correctement formée lors de la création du fichier + $efile = $CFG->wwwroot.'/pluginfile.php'.$url; + } + else{ + $efile = $url; + } + + if ($etiquette==""){ + $l=strlen($url); + $posr=strrpos($url,'/'); + if ($posr===false){ // pas de separateur + $etiquette=$url; + } + else if ($posr==$l-1){ // separateur en fin + $etiquette=get_string("etiquette_inconnue", "checklist"); + } + else if ($posr==0){ // separateur en tete et en fin ! + $etiquette=get_string("etiquette_inconnue", "checklist"); + } + else { + $etiquette=substr($url,$posr+1); + } + } + + if ($cible){ + return "$etiquette"; + } + else{ + return "$etiquette"; + } + } function checklist_itemcompare($item1, $item2) { @@ -3172,3 +3982,6 @@ function checklist_itemcompare($item1, $item2) { } return 0; } + + + diff --git a/mod/checklist/mahara/locallib_portfolio.php b/mod/checklist/mahara/locallib_portfolio.php new file mode 100644 index 00000000..29cfb9c2 --- /dev/null +++ b/mod/checklist/mahara/locallib_portfolio.php @@ -0,0 +1,426 @@ +. + +/** + * Library of functions for forum outside of the core api + */ + +require_once($CFG->dirroot . '/mod/checklist/lib.php'); +require_once($CFG->dirroot . '/mod/checklist/locallib.php'); +require_once($CFG->libdir . '/portfolio/caller.php'); +require_once($CFG->libdir . '/filelib.php'); + + +/** + * @package mod-referentiel + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @copyright 2011 Jean Fruitet {@link http://univ-nantes.fr} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class checklist_portfolio_caller extends portfolio_module_caller_base { + + protected $instanceid; + protected $export_format; + + protected $cm; + protected $course; + protected $checklist; + protected $userid; + + private $adresse_retour; + + /** + * @return array + */ + public static function expected_callbackargs() { + return array( + 'instanceid' => false, + 'userid' => false, + 'export_format' => false, + ); + } + /** + * @param array $callbackargs + */ + function __construct($callbackargs) { + parent::__construct($callbackargs); + if (!$this->instanceid) { + throw new portfolio_caller_exception('mustprovideinstanceid', 'checklist'); + } + if (!$this->userid) { + throw new portfolio_caller_exception('mustprovideuser', 'checklist'); + } + if (!isset($this->export_format)) { + throw new portfolio_caller_exception('mustprovideexportformat', 'checklist'); + } + else{ + // echo "
    :: 86 ::$this->export_format\n"; + if ($this->export_format!=PORTFOLIO_FORMAT_FILE) { + // depending on whether there are files or not, we might have to change richhtml/plainhtml + $this->supportedformats = array_merge(array($this->supportedformats), array(PORTFOLIO_FORMAT_RICH, PORTFOLIO_FORMAT_LEAP2A)); + } + } + } + /** + * @global object + */ + public function load_data() { + global $DB; + global $CFG; + if ($this->instanceid) { + if (!$this->checklist = $DB->get_record('checklist', array('id' => $this->instanceid))) { + throw new portfolio_caller_exception('invalidinstanceid', 'checklist'); + } + } + + if (!$this->cm = get_coursemodule_from_instance('checklist', $this->checklist->id)) { + throw new portfolio_caller_exception('invalidcoursemodule'); + } + $this->adresse_retour= '/mod/checklist/view.php?id='.$this->cm->id; + } + + /** + * @global object + * @return string + */ + function get_return_url() { + global $CFG; + return $CFG->wwwroot . $this->adresse_retour; + } + + /** + * @global object + * @return array + */ + function get_navigation() { + global $CFG; + + $navlinks = array(); + $navlinks[] = array( + 'name' => format_string($this->checklist->name), + 'link' => $CFG->wwwroot . $this->adresse_retour, + 'type' => 'title' + ); + return array($navlinks, $this->cm); + } + + /** + * either a whole discussion + * a single post, with or without attachment + * or just an attachment with no post + * + * @global object + * @global object + * @uses PORTFOLIO_FORMAT_HTML + * @return mixed + */ + function prepare_package() { + global $CFG; + global $OUTPUT; + global $USER; + // exporting a single HTML certificat + $content_to_export = $this->prepare_checklist(); + $name = 'checklist'.'_'.$this->checklist->name.'_'.$this->checklist->id.'_'.$this->userid.'.html'; + // $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_PLAINHTML); + $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH); + + // DEBUG + /* + echo "
    DEBUG :: 179 :: CONTENT
    \n"; + echo($content_to_export); + echo "
    MANIFEST : $manifest
    \n"; + echo "
    FORMAT ".$this->exporter->get('formatclass')."\n"; + */ + + $content=$content_to_export; + + if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { + $leapwriter = $this->exporter->get('format')->leap2a_writer($USER); + // DEBUG + //echo "
    DEBUG :: 169 :: LEAPWRITER
    \n"; + //print_object($leapwriter); + // exit; + if ($leapwriter){ + if ($this->prepare_certificat_leap2a($leapwriter, $content_to_export)){ + // echo "
    DEBUG :: 175\n"; + $content = $leapwriter->to_xml(); + // DEBUG + // echo "

    DEBUG :: mod/checklist/mahara/locallib_portfolio.php :: 167
    \n"; + // echo htmlspecialchars($content); + $name = $this->exporter->get('format')->manifest_name(); + } + } + } + /* + // DEBUG + echo "
    DEBUG :: 176
    \n"; + print_object($content); + */ + $this->get('exporter')->write_new_file($content, $name, $manifest); + + } + + + + /** + * @return string + */ + function get_sha1() { + $filesha = ''; + try { + $filesha = $this->get_sha1_file(); + } catch (portfolio_caller_exception $e) { } // no files + + if ($this->checklist && $this->userid){ + return sha1($filesha . ',' . $this->checklist->id. ',' . $this->checklist->name. ',' . $this->userid); + } + return 0; + } + + function expected_time() { + // a file based export + if ($this->singlefile) { + return portfolio_expected_time_file($this->singlefile); + } + else{ + return PORTFOLIO_TIME_LOW; + } + } + + /** + * @uses CONTEXT_MODULE + * @return bool + */ + function check_permissions() { + $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + return true; + } + + /** + * @return string + */ + public static function display_name() { + return get_string('modulename', 'checklist'); + } + + public static function base_supported_formats() { + //return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A); + return array(PORTFOLIO_FORMAT_FILE); + } + + /** + * helper function to add a leap2a entry element + * that corresponds to a single certificate, + * + * the entry/ies are added directly to the leapwriter, which is passed by ref + * + * @global object $checklist $userid the stdclass object representing the database record + * @param portfolio_format_leap2a_writer $leapwriter writer object to add entries to + * @param string $content the content of the certificate (prepared by {@link prepare_checklist} + * + * @return int id of new entry + */ + private function prepare_certificat_leap2a(portfolio_format_leap2a_writer $leapwriter, $content) { + global $USER; + $order = array( " ", "\r\n", "\n", "\r"); + $replace = ' '; + $content=str_replace($order, $replace, $content); + + $title=get_string('modulename', 'checklist').' '.$this->checklist->name. ' '. $this->userid; + $entry = new portfolio_format_leap2a_entry('checklist_id' . $this->checklist->id .'_user'. $this->userid, $title, 'leap2', $content); // proposer ability ? + $entry->published = time(); + $entry->updated = time(); + $entry->author->id = $this->userid; + $entry->summary = $this->checklist->name.' '.strip_tags($this->checklist->intro); + $entry->add_category('web', 'any_type', 'CheckList'); + // DEBUG + /* + echo "
    246 :: ENTRY
    \n"; + print_object($entry); + */ + $leapwriter->add_entry($entry); + /* + echo "
    286 :: LEAPWRITER
    \n"; + print_object($leapwriter); + */ + return $entry->id; + } + + /** + * this is a very cut down version of what is in checklist_certificat print_lib + * + * @global object + * @return string + */ + private function prepare_checklist() { + global $DB; + $output=''; + $info_checklist=''; + $info_items=''; + $fullname =''; + $login=''; + + if(!empty($this->userid)){ + $user= $DB->get_record('user', array('id' => $this->userid)); + if ($user){ + $fullname = fullname($user, true); + $login=$user->username; + } + } + + if (!empty($this->checklist) && !empty($this->userid) ) { + $info_checklist = "

    ".$this->checklist->name."

    \n

    ".strip_tags($this->checklist->intro)."\n"; + if (!empty($this->checklist->timecreated)){ + $info_checklist .= "
    ".get_string('timecreated', 'checklist')." ".userdate($this->checklist->timecreated)." "; + } + if (!empty($this->checklist->timemodified)){ + $info_checklist .= "
    ".get_string('timemodified', 'checklist')." ".userdate($this->checklist->timemodified)." "; + } + $info_checklist .= "

    \n"; + + $info_items=''; + $items=$DB->get_records('checklist_item', array('checklist' => $this->checklist->id), 'position ASC', '*'); + if ($items){ + $info_items.= "

    ".get_string('items', 'checklist')."

    \n"; + $info_items.= "
      \n"; + foreach ($items as $item){ + if ($item){ + $info_items.="
    • ".get_string('id', 'checklist').$item->id." ".stripslashes($item->displaytext)."\n"; + + // checks + $checks=$DB->get_records('checklist_check', array('item' => $item->id, 'userid' => $this->userid)); + if ($checks){ + foreach ($checks as $check){ + switch ($check->teachermark) { + case CHECKLIST_TEACHERMARK_YES: + $info_items.="
      ".get_string('teachermarkyes','checklist'); + break; + case CHECKLIST_TEACHERMARK_NO: + $info_items.="
      ".get_string('teachermarkno','checklist'); + break; + default: + $info_items.="
      ".get_string('teachermarkundecided','checklist'); + break; + } + + if (!empty($check->usertimestamp)){ + $info_items.= " (".get_string('usertimestamp', 'checklist')." ".userdate($check->usertimestamp).") "; + } + if (!empty($check->teachertimestamp)){ + $info_items.= " (".get_string('teachertimestamp', 'checklist')." ".userdate($check->teachertimestamp).") "; + } + $info_items.= "
      \n"; + } + } + + // comments + $comments=$DB->get_records('checklist_comment', array('itemid' => $item->id, 'userid' => $this->userid)); + if ($comments){ + $info_items.= "

      ".get_string('comments', 'checklist')."

      \n"; + foreach ($comments as $comment){ + if (!empty($comment->text)){ + $info_items.= "
            ". stripslashes($comment->text)." "; + } + if ($comment->commentby){ + $teacher= $DB->get_record('user', array('id' => $comment->commentby)); + if ($teacher){ + $fullnameteacher =fullname($teacher, true); + } + } + if (!empty($fullnameteacher)){ + $info_items.="
      (".get_string('commentby', 'checklist')." ".$fullnameteacher.") "; + } + $info_items.= "\n"; + } + } + // description + $descriptions=$DB->get_records('checklist_description', array('itemid' => $item->id, 'userid' => $this->userid)); + if ($descriptions){ + $info_items.= "

      ".get_string('argumentation', 'checklist')."

      \n"; + + foreach ($descriptions as $description){ + if (!empty($description->description)){ + $info_items.= "

      ".stripslashes($description->description)." "; + } + if (!empty($description->timestamp)){ + $info_items.= " (".userdate($description->timestamp).") \n"; + } + // documents + $documents=$DB->get_records('checklist_document', array('descriptionid' => $description->id)); + if ($documents){ + $info_items.= "

        \n"; + foreach ($documents as $document){ + if (!empty($document)){ + if ($document->target==1){ + $cible_document='_blank'; // fenêtre cible + } + else{ + $cible_document=''; + } + if ($document->title){ + $etiquette_document=$document->title; // fenêtre cible + } + else{ + $etiquette_document=''; + } + $info_items.="
      1.         ".get_string('doc_num','checklist',$document->id).'   '.stripslashes($document->description_document)." "; + $info_items.=checklist_affiche_url($document->url_document, $etiquette_document, $cible_document); + $info_items.=' ['.userdate($document->timestamp).'] '."
      2. \n"; + } + } + $info_items.= "
      \n"; + } + $info_items.= "

      \n"; + } + + } + $info_items.= "
    • \n"; + } + } + $info_items.= "
    \n"; + } + // format the body + $s='

    '.get_string('modulename','checklist').'

    '."\n"; + $s.='

    '.$fullname.' ('.$login.')

    '; + $s.=$info_checklist; + $s.=$info_items; + + // DEBUG + // echo $s; + // exit; + $options = portfolio_format_text_options(); + $format = $this->get('exporter')->get('format'); + $formattedtext = format_text($s, FORMAT_HTML, $options); + + // $formattedtext = portfolio_rewrite_pluginfile_urls($formattedtext, $this->context->id, 'mod_checklist', 'document', $item->id, $format); + + $output = ''; + $output .= ''; + $output .= '
    '; + $output .= '
    '.get_string('modulename', 'checklist').' '. format_string($this->checklist->name).'
    '; + $output .= '
    '; + $output .= $formattedtext; + $output .= '
    '."\n\n"; + + } + return $output; + } + + + +} + diff --git a/mod/checklist/mahara/mahara.php b/mod/checklist/mahara/mahara.php new file mode 100644 index 00000000..156daf78 --- /dev/null +++ b/mod/checklist/mahara/mahara.php @@ -0,0 +1,472 @@ +libdir.'/formslib.php'); + + +/** + * @package mod-checklist + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_checklist_mahara_upload_form extends moodleform { + function definition() { + global $CFG, $COURSE, $DB; + + $mform = & $this->_form; + $instance = $this->_customdata; + // print_object($instance); + // exit; + // visible elements + $mform->addElement('header', 'general', $instance['msg']); + $mform->addHelpButton('general', 'documenth','checklist'); + + + // Get Mahara hosts we are doing SSO with + $sql = " + SELECT DISTINCT + h.id, + h.name + FROM + {mnet_host} h, + {mnet_application} a, + {mnet_host2service} h2s_IDP, + {mnet_service} s_IDP, + {mnet_host2service} h2s_SP, + {mnet_service} s_SP + WHERE + h.id != :mnet_localhost_id AND + h.id = h2s_IDP.hostid AND + h.deleted = 0 AND + h.applicationid = a.id AND + h2s_IDP.serviceid = s_IDP.id AND + s_IDP.name = 'sso_idp' AND + h2s_IDP.publish = '1' AND + h.id = h2s_SP.hostid AND + h2s_SP.serviceid = s_SP.id AND + s_SP.name = 'sso_idp' AND + h2s_SP.publish = '1' AND + a.name = 'mahara' + ORDER BY + h.name"; + + if ($hosts = $DB->get_records_sql($sql, array('mnet_localhost_id'=>$CFG->mnet_localhost_id))) { + foreach ($hosts as &$h) { + $h = $h->name; + } + $mform->addElement('select', 'hostid', get_string("site"), $hosts); + $mform->addHelpButton('hostid', 'site', 'checklist'); + $mform->setDefault('hostid', key($hosts)); + } + else { + // TODO: Should probably error out if no mahara hosts found? + $mform->addElement('static', '', '', get_string('nomaharahostsfound', 'checklist')); + } + + $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + + // hidden params + + $mform->addElement('hidden', 'checklist', $instance['checklist']); + $mform->setType('checklist', PARAM_INT); + + + $mform->addElement('hidden', 'descriptionid'); + $mform->setType('descriptionid', PARAM_INT); + if ($instance['descriptionid']){ + $mform->setDefault('descriptionid', $instance['descriptionid']); + } + + $mform->addElement('hidden', 'contextid', $instance['contextid']); + $mform->setType('contextid', PARAM_INT); + + $mform->addElement('hidden', 'itemid', $instance['itemid']); + $mform->setType('itemid', PARAM_INT); + + $mform->addElement('hidden', 'userid', $instance['userid']); + $mform->setType('userid', PARAM_INT); + + $mform->addElement('hidden', 'action', 'uploadfile'); + $mform->setType('action', PARAM_ALPHA); + + // buttons + $this->add_action_buttons(true, get_string('savechanges', 'admin')); + + } +} + + +/** + * checklist class for mahara portfolio + * + */ +class checklist_mahara_class extends checklist_class { + + private $remotehost; + private $remotehostid; + + function checklist_mahara_class($cmid='staticonly', $userid=0, $checklist=NULL, $cm=NULL, $course=NULL) { + parent::checklist_class($cmid, $userid, $checklist, $cm, $course); + } + + /* **************** + function view() { + global $CFG, $OUTPUT; + + if ((!$this->items) && $this->canedit()) { + redirect(new moodle_url('/mod/checklist/edit.php', array('id' => $this->cm->id)) ); + } + + $currenttab = 'view'; + + $this->view_header(); + + echo $OUTPUT->heading(format_string($this->checklist->name)); + + $this->view_tabs($currenttab); + + add_to_log($this->course->id, 'checklist', 'view', "view.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + // Mahara && Portofolio stuff + if (empty($CFG->enableportfolios)){ + redirect(new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)) ); + } + else{ + // DEBUG + // echo "
    DEBUG :: assigment/type/mahara/assigment.class.php :: 75\n"; + + $query = optional_param('q', null, PARAM_TEXT); + // echo "
    QUERY : $query\n"; + + list($error, $views) = $this->get_views($query); + + // DEBUG + // echo "
    DEBUG :: assigment/type/mahara/assigment.class.php :: 83
    ERROR
    \n"; + // print_object($error); + // echo "
    VIEWS\n"; + // print_object($views); + // echo "
    \n"; + // exit; + + if ($error) { + echo $error; + } else { + $this->remotehost = $DB->get_record('mnet_host', array('id'=>$this->remote_mnet_host_id())); + $this->remotehost->jumpurl = $CFG->wwwroot . '/auth/mnet/jump.php?hostid=' . $this->remotehost->id; + echo '
    ' . get_string('selectmaharaview', 'checklist', $this->remotehost) . '

    ' + . '' + . ' ' + . '
    '; + if ($views['count'] < 1) { + if ($query){ + echo get_string('noviewsfound', 'checklist', $this->remotehost->name); + } else { + echo get_string('noviewscreated', 'checklist', $this->remotehost->name); + } + } else { + echo '

    ' . $this->remotehost->name . ': ' . get_string('viewsby', 'checklist', $views['displayname']) . '

    '; + echo '' + . '' + . '' + . '' + . '' + . ''; + foreach ($views['data'] as &$v) { + $windowname = 'view' . $v['id']; + $viewurl = $this->remotehost->jumpurl . '&wantsurl=' . urlencode($v['url']); + $js = "this.target='$windowname';window.open('" . $viewurl . "', '$windowname', 'resizable,scrollbars,width=920,height=600');return false;"; + echo '' + . ''; + } + echo '
    ' . get_string('previewmahara', 'checklist') . '' . get_string('submit') . '
    (' . get_string('clicktopreview', 'checklist') . ')(' . get_string('clicktoselect', 'checklist') . ')
    ' + . 'html ' . $v['title'] . '' . get_string('submit') . '
    '; + } + } + } + + + $this->view_footer(); + } + ***************/ + + function add_mahara_document($itemid, $userid, $descriptionid, $hostid=0, $viewid=0) { + global $DB; + global $CFG; + global $OUTPUT; + global $PAGE; + + $document=NULL; + + $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); + + $thispage = new moodle_url('/mod/checklist/mahara/upload_mahara.php', array('id' => $this->cm->id) ); + $returnurl = new moodle_url('/mod/checklist/view.php', array('id' => $this->cm->id)); + + $currenttab = 'view'; + + add_to_log($this->course->id, 'checklist', 'view', "upload_mahara.php?id={$this->cm->id}", $this->checklist->name, $this->cm->id); + + // Mahara && Portofolio stuff + if (empty($CFG->enableportfolios)){ + redirect($returnurl); + } + + if (empty($descriptionid) && $itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if ($description){ + $descriptionid=$description; + } + } + + if ($descriptionid){ + if (!empty($hostid) && !empty($viewid)) { + $this->set_remote_mnet_host_id($hostid); + if ($this->submit_view($descriptionid, $hostid, $viewid)) { + + //TODO fix log actions - needs db upgrade + //redirect + redirect($returnurl); + } + } + else{ + + $options = array(); + + $mform = new mod_checklist_mahara_upload_form(null, + array('checklist'=>$this->checklist->id, + 'contextid'=>$context->id, + 'itemid'=>$itemid, + 'userid'=>$userid, + 'descriptionid'=>$descriptionid, + 'msg' => get_string('typemahara', 'checklist'), + 'options'=>$options)); + + if ($mform->is_cancelled()) { + redirect($returnurl); + } else if ($mform->get_data()) { + $this->upload($mform, $this->checklist->id); + die(); + //redirect(new moodle_url('/mod/checklist/view.php', array('id'=>$cm->id))); + } + } + $this->view_header(); + echo '

    '.get_string('edit_document', 'checklist').'

    '."\n"; + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + echo format_text($this->checklist->intro, $this->checklist->introformat); + echo '
    '; + + $mform->display(); + + echo $OUTPUT->box_end(); + $this->view_footer(); + } + } + + + function upload($mform, $checklistid) { + // Document creation form + // checklist_document update + // sets checklist_document table + global $CFG, $USER, $DB, $OUTPUT; + + $currenttab = 'view'; + $viewurl=new moodle_url('/mod/checklist/view.php', array('checklist'=>$checklistid)); + + if ($formdata = $mform->get_data()) { + // DEBUG + // print_object($formdata); + // exit; + if (!empty($formdata->descriptionid)) { + + if (!empty($formdata->hostid)) { + $this->set_remote_mnet_host_id($formdata->hostid); + + $this->view_header(); + echo $OUTPUT->heading(format_string($this->checklist->name)); + $this->view_tabs($currenttab); + + // DEBUG + // echo "
    DEBUG :: assigment/type/mahara/assigment.class.php :: 75\n"; + + $query = optional_param('q', null, PARAM_TEXT); + // echo "
    QUERY : $query\n"; + + list($error, $views) = $this->get_views($query); + + // DEBUG + // echo "
    DEBUG :: assigment/type/mahara/assigment.class.php :: 83
    ERROR
    \n"; + // print_object($error); + // echo "
    VIEWS\n"; + // print_object($views); + // echo "
    \n"; + // exit; + + if ($error) { + echo $error; + } + else { + $this->remotehost = $DB->get_record('mnet_host', array('id'=>$this->remote_mnet_host_id())); + $this->remotehost->jumpurl = $CFG->wwwroot . '/auth/mnet/jump.php?hostid=' . $this->remotehost->id; + echo '
    ' . get_string('selectmaharaview', 'checklist', $this->remotehost) . '

    ' + . '' + . ' ' + . '
    '; + if ($views['count'] < 1) { + if ($query){ + echo get_string('noviewsfound', 'checklist', $this->remotehost->name); + } else { + echo get_string('noviewscreated', 'checklist', $this->remotehost->name); + } + } else { + echo '

    ' . $this->remotehost->name . ': ' . get_string('viewsby', 'checklist', $views['displayname']) . '

    '; + echo '' + . '' + . '' + . '' + . '' + . ''; + foreach ($views['data'] as &$v) { + $windowname = 'view' . $v['id']; + $viewurl = $this->remotehost->jumpurl . '&wantsurl=' . urlencode($v['url']); + $js = "this.target='$windowname';window.open('" . $viewurl . "', '$windowname', 'resizable,scrollbars,width=920,height=600');return false;"; + echo '' + . ''; + } + echo '
    ' . get_string('previewmahara', 'checklist') . '' . get_string('submit') . '
    (' . get_string('clicktopreview', 'checklist') . ')(' . get_string('clicktoselect', 'checklist') . ')
    ' + . 'html ' . $v['title'] . '' . get_string('submit') . '
    '; + } + } + $this->view_footer(); + } + } + } + } + + + + + function set_remote_mnet_host_id($var) { + $this->remotehostid=$var; + } + + function remote_mnet_host_id() { + return $this->remotehostid; + } + + function get_mnet_sp() { + global $CFG, $MNET; + require_once $CFG->dirroot . '/mnet/peer.php'; + $mnet_sp = new mnet_peer(); + $mnet_sp->set_id($this->remote_mnet_host_id()); + return $mnet_sp; + } + + function submit_view($descriptionid, $hostid, $viewid) { + global $CFG, $USER, $MNET, $DB; + + require_once $CFG->dirroot . '/mnet/xmlrpc/client.php'; + $mnet_sp = $this->get_mnet_sp(); + $mnetrequest = new mnet_xmlrpc_client(); + $mnetrequest->set_method('mod/mahara/rpclib.php/submit_view_for_assessment'); + $mnetrequest->add_param($USER->username); + $mnetrequest->add_param($viewid); + + if ($mnetrequest->send($mnet_sp) !== true) { + return false; + } + $data = $mnetrequest->response; + + // DEBUG + //echo "
    DEBUG :: ./mod/checklist/mahara/mahara.php :: 378 :: DATA
    \n"; + //print_object($data); + //echo "
    \n"; + + +/**************** + $rawoutcomes = isset($data['outcome']) ? $data['outcome'] : array(); + + $mahara_outcomes = array(); + + foreach ($rawoutcomes as &$o) { + $scale1 = array(); + foreach ($o['scale'] as &$item) { + $scale1[$item['value']] = $item['name']; + } + $mahara_outcomes[$o['outcome']][] = array('scale' => $scale1, 'grade' => $o['grade']); + } + + unset($data['outcome']); + unset($rawoutcomes); +*************************/ + + $document = new object(); + $document->descriptionid=$descriptionid; + $document->description_document=get_string('viewmahara','checklist'); + // $document->url_document="http://localhost/moodle2/auth/mnet/jump.php?hostid=".$hostid."&wantsurl=".urlencode($data['url']); + $document->url_document=$CFG->wwwroot ."/auth/mnet/jump.php?hostid=".$hostid."&wantsurl=".urlencode($data['url']); + + $document->title=clean_text($data['title']); + $document->target=1; + $document->timestamp=time(); + // document + if ($newdocid=$DB->insert_record("checklist_document", $document)){ + // DEBUG + $document->id=$newdocid; + } + //print_object($document); + //echo "
    EXIT :: 410\n"; + //exit; + + // MODIF 25/04/2012 + // Release Mahara page + // We don't lock the page ; that's not an assigment stuff + $mnet_sp = $this->get_mnet_sp(); + $mnetrequest = new mnet_xmlrpc_client(); + $mnetrequest->set_method('mod/mahara/rpclib.php/release_submitted_view'); + $mnetrequest->add_param($data['id']); + $mnetrequest->add_param($viewid); + $mnetrequest->add_param($USER->username); + // Do something if this fails? Or use cron to export the same data later? + if ($mnetrequest->send($mnet_sp) === false) { + $error = "RPC mod/mahara/rpclib.php/release_submitted_view:
    "; + foreach ($mnetrequest->error as $errormessage) { + list($code, $errormessage) = array_map('trim',explode(':', $errormessage, 2)); + $error .= "ERROR $code:
    $errormessage
    "; + } + } + + return $newdocid; + } + + function get_views($query) { + global $CFG, $USER, $MNET; + + $error = false; + $viewdata = array(); + if (!is_enabled_auth('mnet')) { + $error = get_string('authmnetdisabled', 'mnet'); + } else if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) { + $error = get_string('notpermittedtojump', 'mnet'); + } else { + // set up the RPC request + require_once $CFG->dirroot . '/mnet/xmlrpc/client.php'; + $mnet_sp = $this->get_mnet_sp(); + $mnetrequest = new mnet_xmlrpc_client(); + $mnetrequest->set_method('mod/mahara/rpclib.php/get_views_for_user'); + $mnetrequest->add_param($USER->username); + $mnetrequest->add_param($query); + + if ($mnetrequest->send($mnet_sp) === true) { + $viewdata = $mnetrequest->response; + } else { + $error = "RPC mod/mahara/rpclib.php/get_views_for_user:
    "; + foreach ($mnetrequest->error as $errormessage) { + list($code, $errormessage) = array_map('trim',explode(':', $errormessage, 2)); + $error .= "ERROR $code:
    $errormessage
    "; + } + } + } + return array($error, $viewdata); + } + + +} diff --git a/mod/checklist/mahara/upload_mahara.php b/mod/checklist/mahara/upload_mahara.php new file mode 100644 index 00000000..487d3614 --- /dev/null +++ b/mod/checklist/mahara/upload_mahara.php @@ -0,0 +1,116 @@ +. + +/** + * Add a new document to a description + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + +require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); +require_once(dirname(dirname(__FILE__)).'/lib.php'); +require_once(dirname(dirname(__FILE__)).'/locallib.php'); + +require_once(dirname(__FILE__).'/mahara.php'); // mahara class +require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/repository/lib.php'); // Repository API + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$itemid = optional_param('itemid', 0, PARAM_INT); // Item ID +$userid = optional_param('userid', 0, PARAM_INT); // userID +$descriptionid = optional_param('descriptionid', 0, PARAM_INT); // description ID +$cancel = optional_param('cancel', 0, PARAM_BOOL); + +// POUR MAHARA +$hostid = optional_param('hostid', 0, PARAM_INT); // le nouveau document recupérer sur Mahara +$view = optional_param('view', 0, PARAM_INT); // le nouveau document recupérer sur Mahara + +$url = new moodle_url('/mod/checklist/mahara/upload_mahara.php'); +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + + +// Description ? +if (!$descriptionid && $itemid && $userid) { + $description = $DB->get_record('checklist_description', array("itemid"=>$itemid, "userid"=>$userid)); + if (!empty($description)){ + $descriptionid=$description->id; + } +} + +$PAGE->set_url($url); +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +require_login($course, true, $cm); + +$context = get_context_instance(CONTEXT_MODULE, $cm->id); + +if (empty($userid)){ + if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; + } +} + + +/// If it's hidden then it's don't show anything. :) +/// Some capability checks. +if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); +} + + +if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } +} + + +if ($chk = new checklist_mahara_class($cm->id, 0, $checklist, $cm, $course)) { + $chk->add_mahara_document($itemid, $userid, $descriptionid, $hostid, $view); +} + diff --git a/mod/checklist/pix/edit.gif b/mod/checklist/pix/edit.gif new file mode 100644 index 00000000..80d3344a Binary files /dev/null and b/mod/checklist/pix/edit.gif differ diff --git a/mod/checklist/pix/feedback.gif b/mod/checklist/pix/feedback.gif new file mode 100644 index 00000000..8ec73dc7 Binary files /dev/null and b/mod/checklist/pix/feedback.gif differ diff --git a/mod/checklist/pix/link.png b/mod/checklist/pix/link.png new file mode 100644 index 00000000..85e53886 Binary files /dev/null and b/mod/checklist/pix/link.png differ diff --git a/mod/checklist/pix/upload_portfolio.png b/mod/checklist/pix/upload_portfolio.png new file mode 100644 index 00000000..3797f64b Binary files /dev/null and b/mod/checklist/pix/upload_portfolio.png differ diff --git a/mod/checklist/report.php b/mod/checklist/report.php index d461574c..7e704c2a 100644 --- a/mod/checklist/report.php +++ b/mod/checklist/report.php @@ -34,35 +34,21 @@ $url = new moodle_url('/mod/checklist/report.php'); if ($id) { - if (! $cm = get_coursemodule_from_id('checklist', $id)) { - error('Course Module ID was incorrect'); + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } - - if (! $course = $DB->get_record('course', array('id' => $cm->course) )) { - error('Course is misconfigured'); - } - - if (! $checklist = $DB->get_record('checklist', array('id' => $cm->instance) )) { - error('Course module is incorrect'); - } - + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); $url->param('id', $id); - } else if ($checklistid) { - if (! $checklist = $DB->get_record('checklist', array('id' => $checklistid) )) { - error('Course module is incorrect'); - } - if (! $course = $DB->get_record('course', array('id' => $checklist->course) )) { - error('Course is misconfigured'); - } - if (! $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { - error('Course Module ID was incorrect'); + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } - $url->param('checklist', $checklistid); - } else { - error('You must specify a course_module ID or an instance ID'); + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' } $url->param('studentid', $studentid); diff --git a/mod/checklist/select_export.php b/mod/checklist/select_export.php new file mode 100644 index 00000000..cbc38c23 --- /dev/null +++ b/mod/checklist/select_export.php @@ -0,0 +1,71 @@ +. + +/** + * This page prints a particular instance of checklist + * + * @author David Smith + * @author Jean Fruitet + * @package mod/checklist + */ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID + +$url = new moodle_url('/mod/checklist/view.php'); +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + +$PAGE->set_url($url); +$PAGE->requires->js('/mod/checklist/functions.js'); +require_login($course, true, $cm); + +if ($CFG->version < 2011120100) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); +} else { + $context = context_module::instance($cm->id); +} +$userid = 0; +if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; +} + +$chk = new checklist_class($cm->id, $userid, $checklist, $cm, $course); + +$chk->view_select_export(); diff --git a/mod/checklist/settings.php b/mod/checklist/settings.php new file mode 100644 index 00000000..152b8c55 --- /dev/null +++ b/mod/checklist/settings.php @@ -0,0 +1,36 @@ +fulltree) { + + +$options = array(); + + +// user can add description and doucments +$options[0] = 0; +$options[1] = 1; +if (isset($CFG->checklist_description_display)){ + $settings->add(new admin_setting_configselect('checklist_description_display', get_string('checklist_description', 'checklist'), + get_string('config_description', 'checklist'), $CFG->checklist_description_display, $options)); +} +else{ + $settings->add(new admin_setting_configselect('checklist_description_display', get_string('checklist_description', 'checklist'), + get_string('config_description', 'checklist'), 1, $options)); +} + +// outcomes +unset($options); +$options[0] = 0; +$options[1] = 1; +if (isset($CFG->checklist_outcomes_input)){ + $settings->add(new admin_setting_configselect('checklist_outcomes_input', get_string('outcomes_input', 'checklist'), + get_string('config_outcomes_input', 'checklist'), $CFG->checklist_outcomes_input, $options)); +} +else{ + $settings->add(new admin_setting_configselect('checklist_outcomes_input', get_string('outcomes_input', 'checklist'), + get_string('config_outcomes_input', 'checklist'), 1, $options)); +} +} +?> \ No newline at end of file diff --git a/mod/checklist/styles.css b/mod/checklist/styles.css index c681aae7..3a4ab2a3 100644 --- a/mod/checklist/styles.css +++ b/mod/checklist/styles.css @@ -207,4 +207,16 @@ ol.checklist li .itemteacherdate { .checklistwarning { margin-top: 1em; color: #800000; +} + +/* MODIF JF 2012/03/18 */ +.usercomment { + color: black; + background-color: #c0ffc0; + border: solid black 1px; + margin: 0 0 0 20px; +} + +span.small { + font-size : 80%; } \ No newline at end of file diff --git a/mod/checklist/updatechecks.php b/mod/checklist/updatechecks.php index 71293a0c..b23ca1a6 100644 --- a/mod/checklist/updatechecks.php +++ b/mod/checklist/updatechecks.php @@ -38,33 +38,21 @@ $url = new moodle_url('/mod/checklist/view.php'); if ($id) { - if (! $cm = get_coursemodule_from_id('checklist', $id)) { - error('Course Module ID was incorrect'); - } - - if (! $course = $DB->get_record('course', array('id' => $cm->course) )) { - error('Course is misconfigured'); - } - - if (! $checklist = $DB->get_record('checklist', array('id' => $cm->instance) )) { - error('Course module is incorrect'); + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); $url->param('id', $id); - } else if ($checklistid) { - if (! $checklist = $DB->get_record('checklist', array('id' => $checklistid) )) { - error('Course module is incorrect'); - } - if (! $course = $DB->get_record('course', array('id' => $checklist->course) )) { - error('Course is misconfigured'); - } - if (! $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { - error('Course Module ID was incorrect'); + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } $url->param('checklist', $checklistid); - } else { - error('You must specify a course_module ID or an instance ID'); + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' } $PAGE->set_url($url); @@ -77,15 +65,15 @@ } $userid = $USER->id; if (!has_capability('mod/checklist:updateown', $context)) { - echo 'Error: you do not have permission to update this checklist'; + echo get_string('error_update', 'checklist'); // 'Error: you do not have permission to update this checklist'; die(); } if (!confirm_sesskey()) { - echo 'Error: invalid sesskey'; + echo get_string('error_sesskey', 'checklist'); // 'Error: invalid sesskey'; die(); } if (!$items || !is_array($items)) { - echo 'Error: invalid (or missing) items list'; + echo get_string('error_itemlist', 'checklist'); // 'Error: invalid (or missing) items list'; die(); } if (!empty($items)) { @@ -93,4 +81,4 @@ $chk->ajaxupdatechecks($items); } -echo 'OK'; +echo get_string('OK', 'checklist'); // 'OK' diff --git a/mod/checklist/upload.php b/mod/checklist/upload.php new file mode 100644 index 00000000..da9abc7e --- /dev/null +++ b/mod/checklist/upload.php @@ -0,0 +1,147 @@ +. + +/** + * + * @package mod-checklist + * @author JFRUITET + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); +require_once(dirname(__FILE__).'file_api.php'); +require_once(dirname(dirname(dirname(__FILE__))).'/repository/lib.php'); + +global $DB; + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$checklistid = optional_param('checklist', 0, PARAM_INT); // checklist instance ID +$itemid = optional_param('itemid', 0, PARAM_INT); // checklist instance ID +$userid = optional_param('userid', 0, PARAM_INT); // checklist instance ID + +$url = new moodle_url('/mod/checklist/upload.php'); + +if ($id) { + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); + $url->param('id', $id); +} else if ($checklistid) { + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' + } + $url->param('checklist', $checklistid); +} else { + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' +} + +$returnurl=new moodle_url('/mod/checklist/view.php?checklist='.$checklist->id); + +$PAGE->set_url($url); +require_login($course, true, $cm); + +$context = get_context_instance(CONTEXT_MODULE, $cm->id); + +if (empty($userid)){ + if (has_capability('mod/checklist:updateown', $context)) { + $userid = $USER->id; + } +} + + +if ($descriptionid) { // description associee + if (! $record = $DB->get_record('checklist_activite', array("id" => "$descriptionid"))) { + print_error('error_description', 'checklist'); + } +} +if ($documentid) { // current document + if (! $record_document = $DB->get_record('checklist_document', array("id" => "$documentid"))) { + print_error('Document ID is incorrect'); + } +} + +/ Taille des telechargements +if (!empty($checklist->maxbytes)){ + $maxbytes=$checklist->maxbytes; +} +else{ + $maxbytes=0; +} + +/// If it's hidden then it's don't show anything. :) +/// Some capability checks. +if (empty($cm->visible) + && ( + !has_capability('moodle/course:viewhiddenactivities', $context) + && + !has_capability('mod/checklist:updateown', $context) + ) + + ) { + print_error('activityiscurrentlyhidden','error',$returnurl); +} + + +if ($cancel) { + if (!empty($SESSION->returnpage)) { + $return = $SESSION->returnpage; + unset($SESSION->returnpage); + redirect($return); + } else { + redirect($returnurl); + } +} + + + +$PAGE->set_url($url); +$PAGE->set_context($context); +$title = strip_tags($course->fullname.': '.get_string('modulename', 'checklist').': '.format_string($checklist->name,true)); +$PAGE->set_title($title); +$PAGE->set_heading($title); + +$options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $maxbytes), 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); + +$mform = new mod_checklist_upload_form(null, + array('checklist'=>$checklist->id, 'contextid'=>$context->id, + 'userid'=>$USER->id, 'activiteid'=>$activite_id, + 'filearea'=>'document', 'msg' => get_string('document_associe', 'checklist'), + 'mailnow' => $mailnow, 'options'=>$options)); + +if ($mform->is_cancelled()) { + redirect($returnurl); +} else if ($mform->get_data()) { + checklist_upload_document($mform, $checklist->id); + die(); +// redirect(new moodle_url('/mod/checklist/view.php', array('id'=>$cm->id))); +} + +echo $OUTPUT->header(); +echo $OUTPUT->box_start('generalbox'); +$mform->display(); +echo $OUTPUT->box_end(); +echo $OUTPUT->footer(); +die(); + +?> \ No newline at end of file diff --git a/mod/checklist/version.php b/mod/checklist/version.php index 69e10d76..6efeefc9 100644 --- a/mod/checklist/version.php +++ b/mod/checklist/version.php @@ -9,23 +9,24 @@ // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . +// along with Moodle. If not, see . /** - * Code fragment to define the version of checklist - * This fragment is called by moodle_needs_upgrading() and /admin/index.php - * - * @author David Smith - * @package mod/checklist - */ +* Code fragment to define the version of checklist +* This fragment is called by moodle_needs_upgrading() and /admin/index.php +* +* @author David Smith +* @package mod/checklist +*/ -$module->version = 2012040700; // The current module version (Date: YYYYMMDDXX) -$module->cron = 60; // Period for cron to check this module (secs) +$module->version = 2012041100; // The current module version (Date: YYYYMMDDXX) +$module->cron = 60; // Period for cron to check this module (secs) $module->maturity = MATURITY_STABLE; -$module->release = '2.x (Build: 2012040700)'; +$module->release = 'JF-2.x (Build: 2012041100)'; $module->requires = 2010112400; -$module->component = 'mod_checklist'; \ No newline at end of file +$module->component = 'mod_checklist'; + diff --git a/mod/checklist/view.php b/mod/checklist/view.php index c6b509f2..b5a0664f 100644 --- a/mod/checklist/view.php +++ b/mod/checklist/view.php @@ -33,33 +33,21 @@ $url = new moodle_url('/mod/checklist/view.php'); if ($id) { - if (! $cm = get_coursemodule_from_id('checklist', $id)) { - error('Course Module ID was incorrect'); - } - - if (! $course = $DB->get_record('course', array('id' => $cm->course) )) { - error('Course is misconfigured'); - } - - if (! $checklist = $DB->get_record('checklist', array('id' => $cm->instance) )) { - error('Course module is incorrect'); + if (!$cm = get_coursemodule_from_id('checklist', $id)){ + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST); $url->param('id', $id); - } else if ($checklistid) { - if (! $checklist = $DB->get_record('checklist', array('id' => $checklistid) )) { - error('Course module is incorrect'); - } - if (! $course = $DB->get_record('course', array('id' => $checklist->course) )) { - error('Course is misconfigured'); - } - if (! $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { - error('Course Module ID was incorrect'); + $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST); + if (!$cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { + print_error('error_cmid', 'checklist'); // 'Course Module ID was incorrect' } $url->param('checklist', $checklistid); - } else { - error('You must specify a course_module ID or an instance ID'); + print_error('error_specif_id', 'checklist'); // 'You must specify a course_module ID or an instance ID' } $PAGE->set_url($url);