diff --git a/mod/checklist/README_CheckListPlus.txt b/mod/checklist/README_CheckListPlus.txt new file mode 100644 index 00000000..fbaf6db5 --- /dev/null +++ b/mod/checklist/README_CheckListPlus.txt @@ -0,0 +1,126 @@ +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: 2012072614)'; +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 + New function view_select_export, select_items, *_description, *_document, checklist_affiche_url + Functions modified : view_tabs, view, deleteitem, etc. + + +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 :: + // Process Outcomes as Items + $outcomesupdate = 0; + if (!empty($CFG->enableoutcomes)){ + require_once($CFG->dirroot.'/mod/checklist/cron_outcomes.php'); + $outcomesupdate+=checklist_cron_outcomes($lastlogtime); + } + if ($outcomesupdate) { + mtrace(" Updated $outcomesupdate checkmark(s) from outcomes changes"); + } + + // 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 :: +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 cd13b7ee..eb3cf057 100644 --- a/mod/checklist/autoupdate.php +++ b/mod/checklist/autoupdate.php @@ -31,7 +31,9 @@ function checklist_autoupdate($courseid, $module, $action, $cmid, $userid, $url, if ($userid == 0) { return 0; } - + if ($module == 'referentiel') { // Skills repository module + 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..1a3c2025 100644 --- a/mod/checklist/backup/moodle2/backup_checklist_stepslib.php +++ b/mod/checklist/backup/moodle2/backup_checklist_stepslib.php @@ -52,7 +52,17 @@ protected function define_structure() { $comment = new backup_nested_element('comment', array('id'), array( 'userid', 'commentby', 'text')); - // Build the tree + $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); $items->add_child($item); @@ -62,6 +72,11 @@ protected function define_structure() { $item->add_child($comments); $comments->add_child($comment); + $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 +84,8 @@ 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)); + $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)); } @@ -79,10 +96,12 @@ protected function define_structure() { $check->annotate_ids('user', 'userid'); $comment->annotate_ids('user', 'userid'); $comment->annotate_ids('user', 'commentby'); - + $description->annotate_ids('user', 'userid'); + // Define file annotations $checklist->annotate_files('mod_checklist', 'intro', null); // This file area hasn't itemid + $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..ed0c602f 100644 --- a/mod/checklist/backup/moodle2/restore_checklist_activity_task.class.php +++ b/mod/checklist/backup/moodle2/restore_checklist_activity_task.class.php @@ -70,6 +70,14 @@ static public function define_decode_rules() { // Checklist edit by cm->id and forum->id $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'); + $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..383855e6 100644 --- a/mod/checklist/backup/moodle2/restore_checklist_stepslib.php +++ b/mod/checklist/backup/moodle2/restore_checklist_stepslib.php @@ -27,6 +27,8 @@ 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 +121,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/cron_outcomes.php b/mod/checklist/cron_outcomes.php new file mode 100644 index 00000000..dbf0da32 --- /dev/null +++ b/mod/checklist/cron_outcomes.php @@ -0,0 +1,862 @@ +. + +/** + * 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 ? +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."); + if (CHECKL_DEBUG){ + mtrace("\nSTARTTIME: ".date("Y/m/d H-i-s", $starttime)." ENDTIME: ".date("Y/m/d H-i-s", $endtime)); + } + + $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){ + mtrace("\nDEBUG :: ./mod/checklist/cron_outcomes.php\nLine 372 :: SQL:$sql\n"); + print_r($params); + } + + + $r_checklists=$DB->get_records_sql($sql, $params); + if ($r_checklists){ + /* + // DEBUG + if (CHECKL_DEBUG){ + 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){ + 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){ + 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){ + 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){ + 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){ + 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){ + 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){ + 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){ + 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){ + 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/install.xml b/mod/checklist/db/install.xml index 0fb7ecfa..034a0b9e 100644 --- a/mod/checklist/db/install.xml +++ b/mod/checklist/db/install.xml @@ -79,7 +79,7 @@ - +
@@ -94,5 +94,40 @@
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ diff --git a/mod/checklist/db/upgrade.php b/mod/checklist/db/upgrade.php index 0c0d8632..6c632b22 100644 --- a/mod/checklist/db/upgrade.php +++ b/mod/checklist/db/upgrade.php @@ -256,6 +256,58 @@ function xmldb_checklist_upgrade($oldversion=0) { upgrade_mod_savepoint($result, 2011082001, 'checklist'); } + + + if ($result && $oldversion < 2012072614) { + + /// 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, 2012072614, 'checklist'); + + } + return $result; } 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..7d9bed91 --- /dev/null +++ b/mod/checklist/developers_documentation.txt @@ -0,0 +1,132 @@ +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 : + // Process Outcomes as Items + $outcomesupdate = 0; + if (!empty($CFG->enableoutcomes)){ + require_once($CFG->dirroot.'/mod/checklist/cron_outcomes.php'); + $outcomesupdate+=checklist_cron_outcomes($lastlogtime); + } + if ($outcomesupdate) { + mtrace(" Updated $outcomesupdate checkmark(s) from outcomes changes"); + } + + // 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..1ca85443 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 @@ -56,7 +52,7 @@ foreach ($items as $item) { $output = array(); foreach ($fields as $field => $title) { - $output[] = $item->$field; + $output[] = str_replace(',',' ',$item->$field); // MODIF JF ',' is a separator } echo implode($separator, $output)."\n"; } diff --git a/mod/checklist/export_selected_outcomes.php b/mod/checklist/export_selected_outcomes.php new file mode 100644 index 00000000..664da8b8 --- /dev/null +++ b/mod/checklist/export_selected_outcomes.php @@ -0,0 +1,167 @@ +. + +/** + * 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'); +$urlredirect = 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); + $urlredirect->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); + $urlredirect->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); +} + +$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); + } + } +} +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 140e6d63..cb787535 100644 --- a/mod/checklist/lang/en/checklist.php +++ b/mod/checklist/lang/en/checklist.php @@ -184,3 +184,111 @@ $string['yesnooverride'] = 'Yes, cannot override'; $string['yesoverride'] = 'Yes, can override'; + +// CheckListPlus +$string['a_completer'] = 'TO COMPLETE'; +$string['add_link'] = 'Add a link or a document'; +$string['addreferentielname'] = 'Skill repository code name'; +$string['argumentation'] = 'Argumentation'; +$string['checklist_check'] = 'Evaluation '; +$string['checklist_description'] = 'Allows students to upload files as prove of practice'; +$string['clicktopreview'] = 'click to preview in full-size popup'; +$string['clicktoselect'] = 'click to select page'; +$string['commentby'] = 'Comment by '; +$string['config_description'] = 'Permet aux utilisateurs de déposer des documents comme trace de pratique.'; +$string['config_outcomes_input'] = 'Allows teachers to import in Checklist the outcomes checked in course\'s activities'; +$string['confirmreferentielname'] = 'Confirm skills repository code name '; +$string['delete_description'] = 'Delete the description'; +$string['delete_document'] = 'Delete a document'; +$string['delete_link'] = 'Delete a link'; +$string['description_document'] = 'Document description '; +$string['description'] = 'Type in your argumentation'; +$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['descriptionh'] = 'Argumentation Help'; +$string['doc_num'] = 'Document N°{$a} '; +$string['document_associe'] = 'Linked 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 uploaded from your computer). + +* Title of the link + +* Targeted frame'; +$string['edit_description'] = 'Edit the description'; +$string['edit_document'] = 'Edit the document'; +$string['edit_link'] = 'Edit a link'; +$string['error_action'] = 'Error: Invalid action - "{a}"'; +$string['error_checklist_id'] = 'Checklist ID was incorrect'; +$string['error_cm'] = 'Course Module is incorrect'; +$string['error_cmid'] = 'Course Module ID was incorrect'; +$string['error_course'] = 'Course is misconfigured'; +$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_import_items'] = 'You do not have permission to import items to this checklist'; +$string['error_insert_db'] = 'Unable to insert DB record for item'; +$string['error_itemlist'] = 'Error: invalid (or missing) items list'; +$string['error_number_columns_outcomes'] = 'Row Outcome has incorrect number of columns in it:
{$a}'; +$string['error_number_columns'] = 'Row has incorrect number of columns in it:
{$a}'; +$string['error_select'] = 'Error: At least one Item has to be selected'; +$string['error_sesskey'] = 'Error: Invalid sesskey'; +$string['error_specif_id'] = 'You must specify a course_module ID or an instance ID'; +$string['error_update'] = 'Error: you do not have permission to update this checklist'; +$string['error_user'] = 'No such user!'; +$string['export_outcomes'] = 'Export items as outcomes'; +$string['id'] = 'ID# '; +$string['import_outcomes'] = 'Import outcomes as items'; +$string['input_description'] = 'Draft your argument'; +$string['items_exporth_help'] = 'Selected items will be exported in the same Outcomes file.'; +$string['items_exporth'] = 'Exported Items'; +$string['mustprovideexportformat'] = 'You must provide an export format'; +$string['mustprovideinstanceid'] = 'You must provide an instance id'; +$string['mustprovideuser'] = 'You must provide an user id'; +$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['OK'] = 'OK'; +$string['old_comment'] = 'Previous comment:'; +$string['outcome_description'] = 'Outcome Description'; +$string['outcome_link'] = ' {$a->name} '; +$string['outcome_name'] = 'Outcome name'; +$string['outcome_shortname'] = 'Outcome shortname'; +$string['outcomes_input'] = 'Activate Outcomes files'; +$string['outcomes'] = 'outcomes'; // DO NOT TRANSLATE. NE PAS TRADUIRE +$string['pluginname'] = 'Mahara portfolio'; +$string['previewmahara'] = 'Preview'; +$string['quit'] = 'Quit'; +$string['referentiel_codeh_help'] = 'This code name identify the outcomes matching the same Skills repository.
If Items names are not keys check "Use Item ID as key"'; +$string['referentiel_codeh'] = 'Type in a skills repository code name (Optional)'; +$string['scale_description'] = 'This scale is intended to estimate the acquisition of the skills by the way of Outcomes.'; +$string['scale_items'] = 'Not relevent,Non validated,Validated'; +$string['scale_name'] = 'Skill Item'; +$string['select_all'] = 'Check all Items'; +$string['select_items_export'] = 'Selection items to exporte'; +$string['select_not_any'] = 'Uncheck all Items'; +$string['select'] = 'Select'; +$string['selectedview'] = 'Submitted Page'; +$string['selectexport'] = 'Export Outcomes'; +$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['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['site'] = 'Site'; +$string['target'] = 'Open that link in a new window'; +$string['teachermark'] = 'Appreciation '; +$string['teachertimestamp'] = 'Evaluated the '; +$string['timecreated'] = 'Created the '; +$string['timemodified'] = 'Modified the '; +$string['title'] = 'Document title'; +$string['titlemahara'] = 'Title'; +$string['typemahara'] = 'Mahara portfolio'; +$string['upload_portfolio'] = 'Link to a page of my portfolio'; +$string['url'] = 'URL'; +$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['urlh'] = 'Selection of a Web link'; +$string['useitemid'] = 'Use Item ID as key '; +$string['usertimestamp'] = 'Demanded the '; +$string['viewmahara'] = 'Mahara view'; +$string['views'] = 'Pages'; +$string['viewsby'] = 'Pages by {$a}'; diff --git a/mod/checklist/lang/fr/checklist.php b/mod/checklist/lang/fr/checklist.php index 97bdc5f9..bebae61e 100644 --- a/mod/checklist/lang/fr/checklist.php +++ b/mod/checklist/lang/fr/checklist.php @@ -182,3 +182,113 @@ $string['yesnooverride'] = 'Oui ne peut pas remplacer'; $string['yesoverride'] = 'Oui, peut remplacer'; + +// CheckListPlus +$string['a_completer'] = 'A COMPLETER'; +$string['add_link'] = 'Ajouter un lien ou un document'; +$string['addreferentielname'] = 'Saisir un code de référentiel '; +$string['argumentation'] = 'Argumentation'; +$string['checklist_check'] = 'Evaluation '; +$string['checklist_description'] = 'Autoriser le dépôt de fichiers'; +$string['clicktopreview'] = 'cliquez pour un aperçu pleine taille dans un fenêtre surgissante'; +$string['clicktoselect'] = 'cliquez pour sélectionner la vue'; +$string['commentby'] = 'Commenté par '; +$string['config_description'] = 'Permet aux utilisateurs de déposer des documents comme trace de pratique.'; +$string['config_outcomes_input'] = 'Permet d\'importer dans Checklist les objectifs validés dans les activités Moodle du cours'; +$string['confirmreferentielname'] = 'Confirmer le code de référentiel '; +$string['delete_description'] = 'Supprimer la description'; +$string['delete_document'] = 'Supprimer un document'; +$string['delete_link'] = 'Supprimer un lien'; +$string['description_document'] = 'Information sur le document'; +$string['description'] = 'Rédigez votre argumentaire'; +$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['descriptionh'] = 'Aide pour l\'argumentation'; +$string['doc_num'] = 'Document N°{$a} '; +$string['document_associe'] = 'Document associé'; +$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['edit_description'] = 'Editer la description'; +$string['edit_document'] = 'Editer le document'; +$string['edit_link'] = 'Editer un lien'; +$string['error_action'] = 'Erreur : Action invalide - "{a}"'; +$string['error_checklist_id'] = 'Checklist ID incorrect'; +$string['error_cm'] = 'Course Module incorrect'; +$string['error_cmid'] = 'Course Module ID incorrect'; +$string['error_course'] = 'Course ID incorrect'; +$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_import_items'] = 'Vous n\'êtes pas autorisé à importer des items dans cette CheckList'; +$string['error_insert_db'] = 'Insertion d\'un item impossible dans la base de données'; +$string['error_itemlist'] = 'Erreur : liste d\'items invalide ou absente'; +$string['error_number_columns_outcomes'] = 'Cette ligne d\'Objectifs a un nombre incorrect de colonnes :
{$a}'; +$string['error_number_columns'] = 'Nombre de colonnes incorrect pour cette ligne :
{$a}'; +$string['error_select'] = 'Erreur: Veuillez sélectionner au moins un Item'; +$string['error_sesskey'] = 'Erreur : Clé de session invalide'; +$string['error_specif_id'] = 'Vous devez spécifier un course_module ID ou un instance ID'; +$string['error_update'] = 'Erreur: Vous n\'êtes pas autorisé à mettre à jour cette CheckList'; +$string['error_user'] = 'Compte utilisateur inexistant !'; +$string['export_outcomes'] = 'Exporter des objectifs'; +$string['id'] = 'ID# '; +$string['import_outcomes'] = 'Importer des objectifs'; +$string['input_description'] = 'Rédigez votre argumentaire'; +$string['items_exporth_help'] = 'Les items sélectionnés seront exportés dans le même fichier d\'Objectifs.'; +$string['items_exporth'] = 'Item exportés'; +$string['mustprovideexportformat'] = 'Vous devez fournir un formaat d\'export'; +$string['mustprovideinstanceid'] = 'Vous devez fournir un identifiant d\'instance'; +$string['mustprovideuser'] = 'Vous devez fournir un identifiant d\'utilisateur'; +$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['OK'] = 'OK'; +$string['old_comment'] = 'Commentaire antérieur:'; +$string['outcome_description'] = 'Description'; +$string['outcome_link'] = ' {$a->name} '; +$string['outcome_name'] = 'Nom d\'objectif'; +$string['outcome_shortname'] = 'Code de compétence'; +$string['outcomes_input'] = 'Activer les fichiers d\'objectifs'; +$string['outcomes'] = 'outcomes'; // NE PAS TRADUIRE +$string['previewmahara'] = 'Aperçu'; +$string['quit'] = 'Quitter'; +$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 "Utiliser l\'ID de l\'Item comme clé"'; +$string['referentiel_codeh'] = 'Aide pour la saisie d\'un code de référentiel'; +$string['scale_description'] = 'Ce barème est destiné à évaluer l\'acquisition d\'objectifs de compétences.'; +$string['scale_items'] = 'Non pertinent,Non validé,Validé'; +$string['scale_name'] = 'Item référentiel'; +$string['select_all'] = 'Tout cocher'; +$string['select_items_export'] = 'Sélectionnez des items à exporter'; +$string['select_not_any'] = 'Tous décocher'; +$string['select'] = 'Sélectionner'; +$string['selectedview'] = 'Page soumissionnée'; +$string['selectexport'] = 'Exporter Objectifs'; +$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['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['site'] = 'Site'; +$string['target'] = 'Ouvrir ce lien dans une nouvelle fenêtre'; +$string['teachermark'] = 'Appréciation '; +$string['teachertimestamp'] = 'Evalué le '; +$string['timecreated'] = 'Créé le '; +$string['timemodified'] = 'Modifié le '; +$string['title'] = 'Titre du document'; +$string['titlemahara'] = 'Titre'; +$string['typemahara'] = 'Portfolio Mahara'; +$string['upload_portfolio'] = 'Lier à une page de mon portfolio'; +$string['url'] = 'URL'; +$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['urlh'] = 'Sélection d\'un lien Web'; +$string['useitemid'] = 'Utiliser l\'ID de l\'Item comme clé '; +$string['usertimestamp'] = 'Réclamé le '; +$string['viewmahara'] = 'Vue Mahara'; +$string['views'] = 'Vues '; +$string['viewsby'] = 'Vues proposées par {$a}'; diff --git a/mod/checklist/lib.php b/mod/checklist/lib.php index a570f357..e32a5161 100644 --- a/mod/checklist/lib.php +++ b/mod/checklist/lib.php @@ -51,6 +51,92 @@ 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 @@ -555,6 +641,18 @@ function checklist_cron () { $lastlogtime = $lastcron - 5; // Subtract 5 seconds just in case a log slipped through during the last cron update + // Process Outcomes as Items + $outcomesupdate = 0; + // mtrace(" OUTOMES: ".$CFG->enableoutcomes); + + if (!empty($CFG->enableoutcomes)){ + require_once($CFG->dirroot.'/mod/checklist/cron_outcomes.php'); + $outcomesupdate+=checklist_cron_outcomes($lastlogtime); + } + if ($outcomesupdate) { + mtrace(" Updated $outcomesupdate checkmark(s) from outcomes changes"); + } + // Find all autoupdating checklists $checklists = $DB->get_records_select('checklist', 'autopopulate > 0 AND autoupdate > 0'); if (!$checklists) { @@ -728,6 +826,16 @@ function checklist_reset_userdata($data) { $DB->delete_records_list('checklist_check', 'item', $items); $DB->delete_records_list('checklist_comment', 'itemid', $items); + // Descriptions + list($descsql, $descparams) = $DB->get_in_or_equal(array_keys($items)); + $descriptions = $DB->get_records_select('checklist_description', 'itemid '.$descsql, $descparams); + if ($descriptions) { + // Documents + $DB->delete_records_list('checklist_document', 'descriptionid', $descriptions); + // Descriptions + $DB->delete_records_list('checklist_description', 'id', $descriptions); + } + list($isql, $iparams) = $DB->get_in_or_equal(array_keys($items)); $sql = "checklist $isql AND userid != 0"; $DB->delete_records_select('checklist_item', $sql, $iparams); diff --git a/mod/checklist/locallib.php b/mod/checklist/locallib.php index 2d6c37e0..31aaa027 100644 --- a/mod/checklist/locallib.php +++ b/mod/checklist/locallib.php @@ -19,6 +19,11 @@ * Stores all the functions for manipulating a checklist * * @author David Smith + * + * New function view_select_export + * New function select_items, *_description, *_document + * Functions modified : view_tabs, view, deleteitem + * @author Jean Fruitet * @package mod/checklist */ @@ -51,6 +56,8 @@ class checklist_class { 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; @@ -64,7 +71,7 @@ function checklist_class($cmid='staticonly', $userid=0, $checklist=null, $cm=nul 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) { @@ -464,7 +471,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 +506,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(); @@ -737,7 +753,7 @@ function get_teachermark($itemid) { function view_items($viewother = false, $userreport = false) { global $DB, $OUTPUT, $PAGE; - + global $CFG, $USER; echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); $comments = $this->checklist->teachercomments; @@ -1007,7 +1023,7 @@ function view_items($viewother = false, $userreport = false) { } echo ''; } else { - echo s($comment->text); + echo $comment->text; // echo s($comment->text); } echo ' '; } @@ -1016,6 +1032,12 @@ 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 @@ -1204,6 +1226,7 @@ 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)); @@ -1211,7 +1234,16 @@ function view_import_export() { $exportstr = get_string('export', 'checklist'); echo "
"; - echo "$importstr   $exportstr"; + if (!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 "
"; } @@ -1925,7 +1957,7 @@ function process_view_actions() { break; default: - error('Invalid action - "'.s($action).'"'); + print_error(get_string('error_action', 'checklist', s($action))); // 'Invalid action - "{a}"' } if ($action != 'updatechecks') { @@ -2028,7 +2060,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) { @@ -2086,7 +2118,7 @@ function process_report_actions() { } if (!confirm_sesskey()) { - error('Invalid sesskey'); + print_error('error_sesskey', 'checklist'); // 'Invalid sesskey'; } switch ($action) { @@ -2350,7 +2382,7 @@ function toggledisableitem($itemid) { } } - function deleteitem($itemid, $forcedelete=false) { + function deleteitem($itemid, $forcedelete=false) { global $DB; if (isset($this->items[$itemid])) { @@ -2372,6 +2404,19 @@ function deleteitem($itemid, $forcedelete=false) { $DB->delete_records('checklist_item', array('id' => $itemid) ); $DB->delete_records('checklist_check', array('item' => $itemid) ); + // Descriptions + $descriptions = $DB->get_records('checklist_description', array('itemid' => $itemid)); + if ($descriptions) { + foreach($descriptions as $description){ + if (!empty($description)){ + // Documents + $DB->delete_records('checklist_document', array('descriptionid' => $description->id)); + // Descriptions + $DB->delete_records('checklist_description', array('id' => $description->id)); + } + } + } + $this->update_item_positions(); } @@ -2927,7 +2972,7 @@ function update_all_autoupdate_checks() { $check->teachertimestamp = 0; $check->teachermark = CHECKLIST_TEACHERMARK_UNDECIDED; - $check->id = $DB->insert_record('checklist_check', $check); + $check->id = $DB->insert_record('checklist_check', $check); } } } @@ -3162,8 +3207,774 @@ 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; + } + +/** + * Items selection for exporting 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; + } + +/** + * New features : description and documents linked to items + * @author Jean Fruitet + * @package mod/checklist + */ + + + 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){ // no separator + $etiquette=$url; + } + else if ($posr==$l-1){ // ending separator + $etiquette=get_string("etiquette_inconnue", "checklist"); + } + else if ($posr==0){ // heading and ending separator ! + $etiquette=get_string("etiquette_inconnue", "checklist"); + } + else { + $etiquette=substr($url,$posr+1); + } + } + + if ($cible){ + return "$etiquette"; + } + else{ + return "$etiquette"; + } + } + function checklist_itemcompare($item1, $item2) { if ($item1->position < $item2->position) { return -1; 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..8d306c66 --- /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; + + + // 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/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..a2dd6b48 100644 --- a/mod/checklist/report.php +++ b/mod/checklist/report.php @@ -35,30 +35,18 @@ $url = new moodle_url('/mod/checklist/report.php'); if ($id) { if (! $cm = get_coursemodule_from_id('checklist', $id)) { - error('Course Module ID was incorrect'); + 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'); + $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' } - if (! $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id)) { - error('Course Module ID was incorrect'); - } - $url->param('checklist', $checklistid); } else { 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..c936b720 --- /dev/null +++ b/mod/checklist/settings.php @@ -0,0 +1,36 @@ +fulltree) { + + +$options = array(); + + +// user can add description and documents +$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)); +} + +// user can import or export outcomes files as item list +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 a1dbce98..7f3d0716 100644 --- a/mod/checklist/styles.css +++ b/mod/checklist/styles.css @@ -224,4 +224,16 @@ p.checklistwarning { .checklist_progress_percent { padding-left: 0.5em; +} + +/* 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..0afcf2f1 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); @@ -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..49831b03 --- /dev/null +++ b/mod/checklist/upload.php @@ -0,0 +1,148 @@ +. + +/** + * + * @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'); +$returnurl=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); + $returnurl->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); + $returnurl->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); +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 3f2299fe..43d726df 100644 --- a/mod/checklist/version.php +++ b/mod/checklist/version.php @@ -23,9 +23,9 @@ * @package mod/checklist */ -$module->version = 2012070700; // The current module version (Date: YYYYMMDDXX) -$module->cron = 60; // Period for cron to check this module (secs) +$module->version = 2012072614; // 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: 2012070700)'; +$module->release = '2.x (Build JF: 2012072614)'; $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);