Index: moodle/mod/lamslesson/lib.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/lib.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/lib.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,606 @@ +. + + +/** + * Library of interface functions and constants for module LAMS Lesson + * + * All the core Moodle functions, neeeded to allow the module to work + * integrated in Moodle should be placed here. + * All the lamslesson specific functions, needed to implement all the module + * logic, should go to locallib.php. This will help to save some memory when + * Moodle is performing actions across all modules. + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die(); + +/** Include required files */ +require_once($CFG->libdir.'/datalib.php'); +require_once($CFG->libdir.'/moodlelib.php'); +require_once($CFG->libdir.'/xmlize.php'); + +/// CONSTANTS /////////////////////////////////////////////////////////// + +define('LAMSLESSON_LOGIN_REQUEST', '/LoginRequest'); +define('LAMSLESSON_PARAM_UID', 'uid'); +define('LAMSLESSON_PARAM_SERVERID', 'sid'); +define('LAMSLESSON_PARAM_TIMESTAMP', 'ts'); +define('LAMSLESSON_PARAM_HASH', 'hash'); +define('LAMSLESSON_PARAM_METHOD', 'method'); +define('LAMSLESSON_PARAM_COURSEID', 'courseid'); +define('LAMSLESSON_PARAM_COURSENAME', 'courseName'); +define('LAMSLESSON_PARAM_COUNTRY', 'country'); +define('LAMSLESSON_PARAM_LANG', 'lang'); +define('LAMSLESSON_PARAM_LSID', 'lsid'); +define('LAMSLESSON_PARAM_AUTHOR_METHOD', 'author'); +define('LAMSLESSON_PARAM_MONITOR_METHOD', 'monitor'); +define('LAMSLESSON_PARAM_LEARNER_METHOD', 'learner'); +define('LAMSLESSON_PARAM_CUSTOM_CSV', 'customCSV'); +define('LAMSLESSON_LD_SERVICE', '/services/xml/LearningDesignRepository'); +define('LAMSLESSON_LESSON_MANAGER', '/services/xml/LessonManager'); + +/** + * If you for some reason need to use global variables instead of constants, do not forget to make them + * global as this file can be included inside a function scope. However, using the global variables + * at the module level is not a recommended. + */ +//global $NEWMODULE_GLOBAL_VARIABLE; +//$NEWMODULE_QUESTION_OF = array('Life', 'Universe', 'Everything'); + +/** + * Given an object containing all the necessary data, + * (defined by the form in mod_form.php) this function + * will create a new instance and return the id number + * of the new instance. + * + * @param object $lamslesson An object from the form in mod_form.php + * @return int The id of the newly inserted lamslesson record + */ +function lamslesson_add_instance($lamslesson) { + global $DB; + + $lamslesson->timecreated = time(); + lamslesson_add_lesson($lamslesson); + + # You may have to add extra stuff in here # + + return $DB->insert_record('lamslesson', $lamslesson); +} + +/** + * Given an object containing all the necessary data, + * (defined by the form in mod_form.php) this function + * will update an existing instance with new data. + * + * @param object $lamslesson An object from the form in mod_form.php + * @return boolean Success/Fail + */ +function lamslesson_update_instance($lamslesson) { + global $DB; + + $lamslesson->timemodified = time(); + $lamslesson->id = $lamslesson->instance; + + # You may have to add extra stuff in here # + lamslesson_add_lesson($lamslesson); + + return $DB->update_record('lamslesson', $lamslesson); +} + +/** + * Given an ID of an instance of this module, + * this function will permanently delete the instance + * and any data that depends on it. + * + * @param int $id Id of the module instance + * @return boolean Success/Failure + */ +function lamslesson_delete_instance($id) { + global $DB; + + if (! $lamslesson = $DB->get_record('lamslesson', array('id' => $id))) { + return false; + } + + # Delete any dependent records here # + + $DB->delete_records('lamslesson', array('id' => $lamslesson->id)); + + return true; +} + +/** + * Return a small object with summary information about what a + * user has done with a given particular instance of this module + * Used for user activity reports. + * $return->time = the time they did it + * $return->info = a short text description + * + * @return null + * @todo Finish documenting this function + */ +function lamslesson_user_outline($course, $user, $mod, $lamslesson) { + $return = new stdClass; + $return->time = 0; + $return->info = ''; + return $return; +} + +/** + * Print a detailed representation of what a user has done with + * a given particular instance of this module, for user activity reports. + * + * @return boolean + * @todo Finish documenting this function + */ +function lamslesson_user_complete($course, $user, $mod, $lamslesson) { + return true; +} + +/** + * Given a course and a time, this module should find recent activity + * that has occurred in lamslesson activities and print it out. + * Return true if there was output, or false is there was none. + * + * @return boolean + * @todo Finish documenting this function + */ +function lamslesson_print_recent_activity($course, $viewfullnames, $timestart) { + return false; // True if anything was printed, otherwise false +} + +/** + * Function to be run periodically according to the moodle cron + * This function searches for things that need to be done, such + * as sending out mail, toggling flags etc ... + * + * @return boolean + * @todo Finish documenting this function + **/ +function lamslesson_cron () { + return true; +} + +/** + * Must return an array of users who are participants for a given instance + * of lamslesson. Must include every user involved in the instance, + * independient of his role (student, teacher, admin...). The returned + * objects must contain at least id property. + * See other modules as example. + * + * @param int $lamslessonid ID of an instance of this module + * @return boolean|array false if no participants, array of objects otherwise + */ +function lamslesson_get_participants($lamslessonid) { + return false; +} + +/** + * This function returns if a scale is being used by one lamslesson + * if it has support for grading and scales. Commented code should be + * modified if necessary. See forum, glossary or journal modules + * as reference. + * + * @param int $lamslessonid ID of an instance of this module + * @return mixed + * @todo Finish documenting this function + */ +function lamslesson_scale_used($lamslessonid, $scaleid) { + global $DB; + + $return = false; + + //$rec = $DB->get_record("lamslesson", array("id" => "$lamslessonid", "scale" => "-$scaleid")); + // + //if (!empty($rec) && !empty($scaleid)) { + // $return = true; + //} + + return $return; +} + +/** + * Checks if scale is being used by any instance of lamslesson. + * This function was added in 1.9 + * + * This is used to find out if scale used anywhere + * @param $scaleid int + * @return boolean True if the scale is used by any lamslesson + */ +function lamslesson_scale_used_anywhere($scaleid) { + global $DB; + + if ($scaleid and $DB->record_exists('lamslesson', 'grade', -$scaleid)) { + return true; + } else { + return false; + } +} + +/** + * Execute post-uninstall custom actions for the module + * This function was added in 1.9 + * + * @return boolean true if success, false on error + */ +function lamslesson_uninstall() { + return true; +} + + +/** + * Get sequences(learning designs) for the user in lamslesson using the REST interface + * + * @param string $username The username of the user. Set this to "" if you would just like to get sequences for the currently logged in user. + * @return string to define the tree structure + * + */ +function lamslesson_get_sequences_rest($username,$courseid,$coursename,$coursecreatedate,$country,$lang) { + global $CFG,$USER; + if(!isset($CFG->lamslesson_serverurl)||!isset($CFG->lamslesson_serverid)||!isset($CFG->lamslesson_serverkey)) + { + return get_string('notsetup', 'lamslesson'); + } + + // append month/year to course name + $coursename = $coursename.' '.date('n/Y', $coursecreatedate); + + // generate hash + $datetime = date('F d,Y g:i a'); + $datetime_encoded = urlencode($datetime); + $rawstring = trim($datetime).trim($username).trim($CFG->lamslesson_serverid).trim($CFG->lamslesson_serverkey); + $hashvalue = sha1(strtolower($rawstring)); + + + // Put together REST URL + $request = "$CFG->lamslesson_serverurl".LAMSLESSON_LD_SERVICE."?serverId=" . $CFG->lamslesson_serverid . "&datetime=" . $datetime_encoded . "&hashValue=" . $hashvalue . "&username=" . $username . "&courseId=" . $courseid . "&courseName=" . urlencode($coursename) . "&mode=2&country=" . $country . "&lang=$lang"; + + //print($request); + // GET call to LAMS + $xml = @file_get_contents($request); + + if(!empty($http_response_header[0])) { + // Retrieve HTTP status code + list($version, $status_code, $msg) = explode(' ', $http_response_header[0], 3); + + // Check the HTTP Status code + switch($status_code) { + case 200: + break; + case 503: + print_error('restcall503', 'lamslesson', $CFG->wwwroot.'/course/view.php?id='.$courseid); + break; + case 403: + print_error('restcall403', 'lamslesson', $CFG->wwwroot.'/course/view.php?id='.$courseid); + break; + case 400: + print_error('restcall400', 'lamslesson', $CFG->wwwroot.'/course/view.php?id='.$courseid); + break; + default: + print_error('restcalldefault', 'lamslesson', $CFG->wwwroot.'/course/view.php?id='.$courseid, $status_code); + } + } else { + print_error('restcallfail', 'lamslesson', $CFG->wwwroot.'/course/view.php?id='.$courseid); + } + + $xml_array = xmlize($xml); + + $result = lamslesson_process_array($xml_array['Folder']); + return $result; + +} + +/* + * Convert workspace contents from an xmlize array into a string that YUI Tree + * can use. + */ +function lamslesson_process_array($array) { + $output = ''; + if (empty($array['@']['resourceId'])) { + // it's a folder + $folder_name = preg_replace("/'/", "$1\'", $array['@']['name']); + $output .= "{type:'Text', label:'" . $folder_name . "',id:'0'"; + + if (empty($array['#']['LearningDesign']) && empty($array['#']['Folder'])) { + $output .= ", children: [{type:'HTML', html:'-" . get_string('empty', 'lamslesson') . "-', id:'0'}]}"; + return $output; + } else { + $output .= ", children: ["; + } + + if (!empty($array['#']['LearningDesign'])) { + $lds = $array['#']['LearningDesign']; + for($i=0; $itimemodified = time(); + + $locale = lamslesson_get_locale($form->course); + + // start the lesson + $form->lesson_id = lamslesson_get_lesson( + $USER->username, $form->sequence_id, $form->course, + $form->name, $form->intro, + $locale['country'], $locale['lang'], $form->customCSV + ); + + if (!isset($form->lesson_id) || $form->lesson_id <= 0) { + return false; + } + + $members = lamslesson_get_members($form); + + // call threaded lams servlet to populate the class + $result = lamslesson_fill_lesson($USER->username, $form->lesson_id, + $form->course, $locale['country'], $locale['lang'], $members['learners'], $members['monitors'] + ); + + // log adding of lesson + $cmid = 0; + if ($cm = get_coursemodule_from_instance('lamslesson', $form->coursemodule, $form->course)) { + $cmid = $cm->id; + } + // add_to_log($form->course, 'lamslesson', 'add lesson', 'view.php?id='.$cmid, $form->id, $cmid); + + // return $form->id; +} + +/** + * Return array with 2 keys 'country' and 'lang', to be sent to LAMS as the + * basis for a LAMS locale like en_AU. Makes best effort to choose appropriate + * locale based on course, user, or server setting. + */ +function lamslesson_get_locale($courseid) { + + global $CFG, $USER, $DB; + $locale = array('country' => '', 'lang' => ''); + + if ($CFG->country != '') { + $locale['country'] = trim($CFG->country); + } + + // return course's language and server's country, if either exist + if ($course = $DB->get_record('course', array('id' => $courseid))) { + if ($course->lang != '') { + $locale['lang'] = substr(trim($course->lang), 0, 2); + return $locale; + } + } + + + // use user's country and language if course has no language set + $locale['country'] = trim($USER->country); + $locale['lang'] = substr(trim($USER->lang), 0, 2); + + return $locale; +} + +/* + * Returns a list of learners and monitors in the given course or group. + */ +function lamslesson_get_members($form) { + global $CFG, $DB; + + $learneridstr = ''; + $monitoridstr = ''; + + $context = get_context_instance(CONTEXT_MODULE, $form->coursemodule); + + if (!$form->groupingid) { // get all course members + $userids = lamslesson_get_course_userids($form->coursemodule, $context); + } else { // get members of group + $userids = groups_get_members($forum->groupid); + } + + foreach ($userids as $userid) { + $user = $DB->get_record('user', array('id'=>$userid)); + if (has_capability('mod/lamslesson:manage', $context, $user->id)) { + $monitoridstr .= "$user->username,"; + } + if (has_capability('mod/lamslesson:participate', $context, $user->id)) { + $learneridstr .= "$user->username,"; + } + } + + // remove trailing comma + $learneridstr = substr($learneridstr, 0, strlen($learneridstr)-1); + $monitoridstr = substr($monitoridstr, 0, strlen($monitoridstr)-1); + + //echo "learneridstr: $learneridstr\n"; + //echo "monitoridstr: $monitoridstr\n"; + + $members = array('learners' => $learneridstr, 'monitors' => $monitoridstr); + return $members; +} + +/** + * Get lesson id from lamslesson + * + * @param string $username The username of the user. Set this to "" if you would just like the currently logged in user to create the lesson + * @param int $ldid The id of the learning design that the lesson is based on + * @param int $courseid The id of the course that the lesson is associated with. + * @param string $title The title of the lesson + * @param string $desc The description of the lesson + * @param string $country The Country's ISO code + * @param string $lang The Language's ISO code + * @return int lesson id + */ +function lamslesson_get_lesson($username,$ldid,$courseid,$title,$desc,$country,$lang,$customcsv='') { + //echo "enter lamslesson_get_lesson
"; + global $CFG, $USER; + if (!isset($CFG->lamslesson_serverid, $CFG->lamslesson_serverkey) || $CFG->lamslesson_serverid == "") { + print_error(get_string('notsetup', 'lamslesson')); + return NULL; + } + + $datetime = date("F d,Y g:i a"); + $datetime_encoded = urlencode($datetime); + if(!isset($username)){ + $username = $USER->username; + } + $plaintext = $datetime.$username.$CFG->lamslesson_serverid.$CFG->lamslesson_serverkey; + $hashvalue = sha1(strtolower($plaintext)); + + $title = urlencode($title); + $desc = urlencode($desc); + + $request = "$CFG->lamslesson_serverurl" . LAMSLESSON_LESSON_MANAGER . "?method=start&serverId=" . $CFG->lamslesson_serverid . "&datetime=" . $datetime_encoded . "&hashValue=" . $hashvalue . "&username=" . $username . "&ldId=" . $ldid . "&courseId=" . $courseid . "&title=" . $title . "&desc=" . $desc . "&country=" . $country . "&lang=" . $lang; + + // GET call to LAMS + $xml = file_get_contents($request); + + $xml_array = xmlize($xml); + $lessonId = $xml_array['Lesson']['@']['lessonId']; + return $lessonId; +} + +/* + * Make call to LAMS that will populate the LAMS lesson with students and teachers from Moodle course. + * The method on the LAMS side runs in a separate thread. + */ +function lamslesson_fill_lesson($username,$lsid,$courseid,$country,$lang,$learneridstr,$monitoridstr) { + global $CFG, $USER; + if (!isset($CFG->lamslesson_serverid, $CFG->lamslesson_serverkey) || $CFG->lamslesson_serverid == '') { + print_error(get_string('notsetup', 'lamslesson')); + return NULL; + + } + + $datetime = date('F d,Y g:i a'); + $datetime_encoded = urlencode($datetime); + if(!isset($username)){ + $username = $USER->username; + } + $plaintext = $datetime.$username.$CFG->lamslesson_serverid.$CFG->lamslesson_serverkey; + $hashvalue = sha1(strtolower($plaintext)); + + $learneridstr = urlencode($learneridstr); + $monitoridstr = urlencode($monitoridstr); + + // join lesson + $request = "$CFG->lamslesson_serverurl" . LAMSLESSON_LESSON_MANAGER . "?method=join&serverId=" . $CFG->lamslesson_serverid . "&datetime=" . $datetime_encoded . "&hashValue=" . $hashvalue . "&username=" . $username . "&lsId=" . $lsid . "&courseId=" . $courseid . "&country=" . $country . "&lang=" . $lang . "&learnerIds=" . $learneridstr . "&monitorIds=" . $monitoridstr; + + // GET call to LAMS + return file_get_contents($request); +} + +/** + * Return URL to join a LAMS lesson as a learner or staff depending on method. + * URL redirects LAMS to learner or monitor interface depending on method. + */ +function lamslesson_get_url($username, $lang, $country, $lessonid, $courseid, $coursename, $coursecreatedate, $method, $customcsv='') { + global $CFG, $LAMS2CONSTANTS; + + // append month/year to course name + $coursename = $coursename.' '.date('n/Y', $coursecreatedate); + + $datetime = date('F d,Y g:i a'); + $plaintext = trim($datetime) + .trim($username) + .trim($method) + .trim($CFG->lamslesson_serverid) + .trim($CFG->lamslesson_serverkey); + $hash = sha1(strtolower($plaintext)); + $url = $CFG->lamslesson_serverurl. LAMSLESSON_LOGIN_REQUEST . + '?'.LAMSLESSON_PARAM_UID.'='.$username. + '&'.LAMSLESSON_PARAM_METHOD.'='.$method. + '&'.LAMSLESSON_PARAM_TIMESTAMP.'='.urlencode($datetime). + '&'.LAMSLESSON_PARAM_SERVERID.'='.$CFG->lamslesson_serverid. + '&'.LAMSLESSON_PARAM_HASH.'='.$hash. + ($method==LAMSLESSON_PARAM_AUTHOR_METHOD ? '' : '&'. LAMSLESSON_PARAM_LSID .'='.$lessonid). + '&'. LAMSLESSON_PARAM_COURSEID .'='.$courseid. + '&'. LAMSLESSON_PARAM_COURSENAME .'='.urlencode($coursename). + '&'. LAMSLESSON_PARAM_COUNTRY .'='.trim($country). + '&'. LAMSLESSON_PARAM_LANG .'='.substr(trim($lang),0,2); + if ($customcsv != '') { + $url .= '&'. LAMSLESSON_PARAM_CUSTOM_CSV .'='.urlencode($customcsv); + } + return $url; +} + + +/* + * Returns list of userids of users in the given context + */ +function lamslesson_get_course_userids($lamslessonid, $context=NULL) { + global $CFG, $DB; + + if ($context == NULL) { + $lamslesson = $DB->get_record('lamslesson', array('id' => $lamslessonid)); + if (! $cm = get_coursemodule_from_instance('lamslesson', $lamslesson->id, $lamslesson->course)) { + error('Course Module ID was incorrect'); + } + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + } + + // we are looking for all users assigned in this context or higher + if ($usercontexts = get_parent_contexts($context)) { + $listofcontexts = '('.implode(',', $usercontexts).')'; + } else { + $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $listofcontexts = '('.$sitecontext->id.')'; // must be site + } + $sql = "SELECT u.id + FROM {$CFG->prefix}user u INNER JOIN {$CFG->prefix}role_assignments r ON u.id=r.userid + WHERE r.contextid IN $listofcontexts OR r.contextid=$context->id + AND u.deleted=0 AND u.username!='guest'"; + $users = $DB->get_records_sql($sql); + $userids = array_keys($users); // turn list of id-backed objects into list of ids + return $userids; +} + Index: moodle/mod/lamslesson/mod_form.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/mod_form.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/mod_form.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,184 @@ +. + + +/** + * The main lamslesson configuration form + * + * It uses the standard core Moodle formslib. For more info about them, please + * visit: http://docs.moodle.org/en/Development:lib/formslib.php + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot.'/course/moodleform_mod.php'); + +class mod_lamslesson_mod_form extends moodleform_mod { + + function definition() { + global $COURSE, $USER, $CFG; + $mform =& $this->_form; + +//------------------------------------------------------------------------------- + /// Adding the "general" fieldset, where all the common settings are showed + $mform->addElement('header', 'general', get_string('general', 'form')); + + /// Adding the standard "name" field + $mform->addElement('text', 'name', get_string('lamslessonname', 'lamslesson'), array('size'=>'64')); + if (!empty($CFG->formatstringstriptags)) { + $mform->setType('name', PARAM_TEXT); + } else { + $mform->setType('name', PARAM_CLEAN); + } + $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); + $mform->addHelpButton('name', 'lamslessonname', 'lamslesson'); + + /// Adding the standard "intro" and "introformat" fields + $this->add_intro_editor(); + +//------------------------------------------------------------------------------- + /// Adding the rest of lamslesson settings, spreeading all them into this fieldset + /// or adding more fieldsets ('header' elements) if needed for better logic + + // Set needed vars + $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); + $locale = lamslesson_get_locale($COURSE->id); + $canmanage = has_capability('mod/lamslesson:manage', $context); + + //-- Open URL button + + // Check whether this person has the right permissions to see the open button. + if ($canmanage) { + + $customcsv = "$USER->username,$COURSE->id,$CFG->lamslesson_serverid"; + $authorurl = lamslesson_get_url($USER->username, $locale['lang'], $locale['country'], 0, $COURSE->id, $COURSE->fullname, $COURSE->timecreated, LAMSLESSON_PARAM_AUTHOR_METHOD, $customcsv); + $openauthorlabel = get_string('openauthor', 'lamslesson'); + + // html "chunk" for open Author button + $authorbutton = << + + + +

+ +

+XXX; + } + + + + $mform->addElement('hidden', 'sequence_id'); + $mform->setType('sequence_id', PARAM_INT); + + $mform->addElement('hidden', 'customCSV', $customcsv); + $mform->setType('customCSV', PARAM_TEXT); + + // display user's lams workspace + $lds = lamslesson_get_sequences_rest($USER->username, $COURSE->id, $COURSE->fullname, $COURSE->timecreated, $USER->country, $USER->lang) ; + + // html "chuck" for YUI tree + $html = << + + + + + + + + +
+ + +XXX; + + // Now we put the two html chunks together +$html = $authorbutton . $html; + + $mform->addElement('header', 'selectsequence', get_string('selectsequence', 'lamslesson')); + + $mform->addElement('static', 'sequencemessage', '', $html); + +//------------------------------------------------------------------------------- + // add standard elements, common to all modules + $this->standard_coursemodule_elements(); +//------------------------------------------------------------------------------- + // add standard buttons, common to all modules + $this->add_action_buttons(); + + } + + function validation($data) { + $errors = array(); + // a sequence needs to be selected + if (empty($data['sequence_id']) || $data['sequence_id'] <= 0) { + $errors['sequencemessage'] = get_string('sequencenotselected', 'lamslesson'); + } + return $errors; + } +} Index: moodle/mod/lamslesson/settings.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/settings.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/settings.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,57 @@ +. + +/** + * @package mod-lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + require_once($CFG->dirroot.'/mod/lamslesson/lib.php'); + + $settings->add(new admin_setting_heading('lamslesson_heading', get_string('adminheader', 'lamslesson'), + get_string('admindescription', 'lamslesson'))); + + // Server URL + $settings->add(new admin_setting_configtext('lamslesson_serverurl', get_string('serverurl', 'lamslesson'), + get_string('serverurlinfo', 'lamslesson'), '')); + + // Server id + $settings->add(new admin_setting_configtext('lamslesson_serverid', get_string('serverid', 'lamslesson'), + get_string('serveridinfo', 'lamslesson'), '')); + + // Server key + $settings->add(new admin_setting_configtext('lamslesson_serverkey', get_string('serverkey', 'lamslesson'), + get_string('serverkeyinfo', 'lamslesson'), '')); + + // requestsource + $settings->add(new admin_setting_configtext('lamslesson_requestsource', get_string('requestsource', 'lamslesson'), + get_string('requestsourceinfo', 'lamslesson'), 'My Moodle')); + + + // Validation button + $html = <<bold +XXX; + + $settings->add(new admin_setting_heading('lamslesson_validation', get_string('validationinfo', 'lamslesson'), + $html)); +} + Index: moodle/mod/lamslesson/styles.css =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/styles.css,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/styles.css 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1 @@ +.path-mod-lamslesson .smalltext {font-size: 0.75em;} Index: moodle/mod/lamslesson/userinfo.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/userinfo.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/userinfo.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,46 @@ +libdir.'/datalib.php'); + global $DB; + + if(!isset($CFG->lamslesson_serverid)||!isset($CFG->lamslesson_serverkey)) + { + header('HTTP/1.1 401 Unauthenticated'); + exit(1); + } + $plaintext = trim($_GET['ts']).trim($_GET['un']).trim($CFG->lamslesson_serverid).trim($CFG->lamslesson_serverkey); + $hash = sha1(strtolower($plaintext)); + if($hash!=$_GET['hs']){ + header('HTTP/1.1 401 Unauthenticated'); + exit(1); + } + + //OK, the caller is authenticated. Now let's fulfill its request. + //What it needs is user info in CSV format. It should be like this: + //username,first name,last name,job title, department, organisation, + //address,phone,fax,mobile,email + $user = $DB->get_record('user', array('username'=>$_GET['un'])); + + //return false if none found + if(!$user){ + header('HTTP/1.1 401 Unauthenticated'); + exit(1); + } + $array = array('',$user->firstname,$user->lastname,$user->address,$user->city,'','',$user->country,$user->phone1,'','',$user->email,$user->country,substr($user->lang,0,2)); + $comma_separated = implode(",", $array);//need more sophiscated algorithm to generate CSV formatted string + echo $comma_separated; + +?> \ No newline at end of file Index: moodle/mod/lamslesson/view.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/view.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/view.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,119 @@ +. + + +/** + * Prints a particular instance of lamslesson + * + * You can have a rather longer description of the file as well, + * if you like, and it can span multiple lines. + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +/// (Replace lamslesson with the name of your module and remove this line) + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/lib.php'); + +$id = optional_param('id', 0, PARAM_INT); // course_module ID, or +$n = optional_param('n', 0, PARAM_INT); // lamslesson instance ID - it should be named as the first character of the module + +if ($id) { + $cm = get_coursemodule_from_id('lamslesson', $id, 0, false, MUST_EXIST); + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $lamslesson = $DB->get_record('lamslesson', array('id' => $cm->instance), '*', MUST_EXIST); +} elseif ($n) { + $lamslesson = $DB->get_record('lamslesson', array('id' => $n), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $lamslesson->course), '*', MUST_EXIST); + $cm = get_coursemodule_from_instance('lamslesson', $lamslesson->id, $course->id, false, MUST_EXIST); +} else { + print_error('You must specify a course_module ID or an instance ID'); +} + +require_login($course, true, $cm); + +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +$locale = lamslesson_get_locale($course->id); + +add_to_log($course->id, 'lamslesson', 'view', "view.php?id=$cm->id", $lamslesson->name, $cm->id); + +/// Print the page header + +$PAGE->set_url('/mod/lamslesson/view.php', array('id' => $cm->id)); +$PAGE->set_title($lamslesson->name); +$PAGE->set_heading($course->shortname); +$PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'lamslesson'))); + + +// Main page +$options_html = ''; +$canmanage = has_capability('mod/lamslesson:manage', $context); + +// Log the lamslesson view. +add_to_log($course->id, "lamslesson", "view lamslesson", "view.php?id=$cm->id", "$lamslesson->id", $cm->id); + +// Get raw data +//print("ID:" . $cm->instance); +//$lessons = $DB->get_records('lamslesson', 'id', $cm->instance); + + +// Check capabilities + +$canparticipate = has_capability('mod/lamslesson:participate', $context); +if ($canparticipate) { + + if ($canmanage) { + + } + +} + + +// Output starts here +echo $OUTPUT->header(); + +// Main LAMS region +echo $OUTPUT->heading($lamslesson->name); +echo $OUTPUT->box_start('generalbox', 'instructions'); +echo '

'; +echo format_module_intro('lamslesson', $lamslesson, $cm->id); +echo '

'; +echo '
'; +echo '' . get_string('lastmodified', 'lamslesson') . ": " . userdate($lamslesson->timemodified) .''; +echo $OUTPUT->box_end(); + +echo $OUTPUT->box_start('generalbox', 'intro'); +if ($canparticipate) { + $learnerurl = lamslesson_get_url($USER->username, $locale['lang'], $locale['country'], $lamslesson->lesson_id, $course->id, $course->fullname, $course->timecreated, LAMSLESSON_PARAM_LEARNER_METHOD); + echo '

'; + echo $OUTPUT->action_link($learnerurl, get_string('openlesson', 'lamslesson'), new popup_action('click', $learnerurl, '', array('height' => 600, 'width' => 996))); + echo '

'; +} +if ($canmanage) { + $monitorurl = lamslesson_get_url($USER->username, $locale['lang'], $locale['country'], $lamslesson->lesson_id, $course->id, $course->fullname, $course->timecreated, LAMSLESSON_PARAM_MONITOR_METHOD); + echo '

'; + echo $OUTPUT->action_link($monitorurl, get_string('openmonitor', 'lamslesson'), new popup_action('click', $monitorurl, '', array('height' => 600, 'width' => 996))); + echo '

'; +} +echo $OUTPUT->box_end(); +// echo html_writer::table($table); +//print_table($table); +// Finish the page +echo $OUTPUT->footer(); Index: moodle/mod/lamslesson/db/access.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/db/access.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/db/access.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,73 @@ +. + + +/** + * Capability definitions for the lamslesson module + * + * The capabilities are loaded into the database table when the module is + * installed or updated. Whenever the capability definitions are updated, + * the module version number should be bumped up. + * + * The system has four possible values for a capability: + * CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set). + * + * It is important that capability names are unique. The naming convention + * for capabilities that are specific to modules and blocks is as follows: + * [mod/block]/: + * + * component_name should be the same as the directory name of the mod or block. + * + * Core moodle capabilities are defined thus: + * moodle/: + * + * Examples: mod/forum:viewpost + * block/recent_activity:view + * moodle/site:deleteuser + * + * The variable name for the capability definitions array is $capabilities + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + + 'mod/lamslesson:participate' => array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'student' => CAP_ALLOW + ) + ), + + 'mod/lamslesson:manage' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + + ) + ), + +); + Index: moodle/mod/lamslesson/db/install.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/db/install.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/db/install.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,34 @@ +. + +/** + * This file replaces the legacy STATEMENTS section in db/install.xml, + * lib.php/modulename_install() post installation hook and partially defaults.php + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +/** + * Post installation procedure + */ +function xmldb_lamslesson_install() { + + /// insert here code to perform some actions + +} Index: moodle/mod/lamslesson/db/install.xml =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/db/install.xml,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/db/install.xml 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+
+ + + + + + + + + +
Index: moodle/mod/lamslesson/db/log.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/db/log.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/db/log.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,38 @@ +. + +/** + * Definition of log events + * NOTE: this is an example how to insert log event during installation/update. + * It is not really essential to know about it, but these logs were created as example + * in the previous 1.9 NEWMODULE. + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die(); + +global $DB; + +$logs = array( + array('module'=>'lamslesson', 'action'=>'add', 'mtable'=>'lamslesson', 'field'=>'name'), + array('module'=>'lamslesson', 'action'=>'update', 'mtable'=>'lamslesson', 'field'=>'name'), + array('module'=>'lamslesson', 'action'=>'view', 'mtable'=>'lamslesson', 'field'=>'name'), + array('module'=>'lamslesson', 'action'=>'view all', 'mtable'=>'lamslesson', 'field'=>'name') +); Index: moodle/mod/lamslesson/db/upgrade.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/db/upgrade.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/db/upgrade.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,157 @@ +. + + +/** + * This file keeps track of upgrades to the lamslesson module + * + * Sometimes, changes between versions involve alterations to database + * structures and other major things that may break installations. The upgrade + * function in this file will attempt to perform all the necessary actions to + * upgrade your older installation to the current version. If there's something + * it cannot do itself, it will tell you what you need to do. The commands in + * here will all be database-neutral, using the functions defined in DLL libraries. + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * xmldb_lamslesson_upgrade + * + * @param int $oldversion + * @return bool + */ +function xmldb_lamslesson_upgrade($oldversion) { + + global $DB; + + $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes + +/// And upgrade begins here. For each one, you'll need one +/// block of code similar to the next one. Please, delete +/// this comment lines once this file start handling proper +/// upgrade code. + +/// if ($oldversion < YYYYMMDD00) { //New version in version.php +/// +/// } + +/// Lines below (this included) MUST BE DELETED once you get the first version +/// of your module ready to be installed. They are here only +/// for demonstrative purposes and to show how the lamslesson +/// iself has been upgraded. + +/// For each upgrade block, the file lamslesson/version.php +/// needs to be updated . Such change allows Moodle to know +/// that this file has to be processed. + +/// To know more about how to write correct DB upgrade scripts it's +/// highly recommended to read information available at: +/// http://docs.moodle.org/en/Development:XMLDB_Documentation +/// and to play with the XMLDB Editor (in the admin menu) and its +/// PHP generation posibilities. + +/// First example, some fields were added to install.xml on 2007/04/01 + if ($oldversion < 2007040100) { + + /// Define field course to be added to lamslesson + $table = new xmldb_table('lamslesson'); + $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); + + /// Add field course + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define field intro to be added to lamslesson + $table = new xmldb_table('lamslesson'); + $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null,'name'); + + /// Add field intro + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define field introformat to be added to lamslesson + $table = new xmldb_table('lamslesson'); + $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', + 'intro'); + + /// Add field introformat + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + } + +/// Second example, some hours later, the same day 2007/04/01 +/// two more fields and one index were added to install.xml (note the micro increment +/// "01" in the last two digits of the version + if ($oldversion < 2007040101) { + + /// Define field timecreated to be added to lamslesson + $table = new xmldb_table('lamslesson'); + $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', + 'introformat'); + + /// Add field timecreated + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define field timemodified to be added to lamslesson + $table = new xmldb_table('lamslesson'); + $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', + 'timecreated'); + + /// Add field timemodified + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define index course (not unique) to be added to lamslesson + $table = new xmldb_table('lamslesson'); + $index = new xmldb_index('courseindex', XMLDB_INDEX_NOTUNIQUE, array('course')); + + /// Add index to course field + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + } + +/// Third example, the next day, 2007/04/02 (with the trailing 00), some actions were performed to install.php, +/// related with the module + if ($oldversion < 2007040200) { + /// insert here code to perform some actions (same as in install.php) + } + +/// And that's all. Please, examine and understand the 3 example blocks above. Also +/// it's interesting to look how other modules are using this script. Remember that +/// the basic idea is to have "blocks" of code (each one being executed only once, +/// when the module version (version.php) is updated. + +/// Lines above (this included) MUST BE DELETED once you get the first version of +/// yout module working. Each time you need to modify something in the module (DB +/// related, you'll raise the version and add one upgrade block here. + +/// Final return of upgrade result (true, all went good) to Moodle. + return true; +} Index: moodle/mod/lamslesson/lang/en/lamslesson.php =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/lang/en/lamslesson.php,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/lang/en/lamslesson.php 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,90 @@ +. + + +/** + * English strings for lamslesson + * + * You can have a rather longer description of the file as well, + * if you like, and it can span multiple lines. + * + * @package mod_lamslesson + * @copyright 2011 LAMS Foundation - Ernie Ghiglione (ernieg@lamsfoundation.org) + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + */ + +defined('MOODLE_INTERNAL') || die(); + +$string['modulename'] = 'LAMS Lesson'; +$string['modulenameplural'] = 'LAMS Lessons'; +$string['modulename_help'] = 'The LAMS Lesson module allows teachers to create LAMS lessons in Moodle.'; +$string['modulename_link'] = 'lamslesson'; +$string['lamslessonfieldset'] = 'Custom example fieldset'; +$string['lamslessonname'] = 'Lesson name'; +$string['lamslessonname_help'] = 'This is the content of the help tooltip associated with the lamslessonname field. Markdown syntax is supported.'; +$string['lamslesson'] = 'LAMS Lesson'; +$string['pluginadministration'] = 'LAMS Lesson administration'; +$string['pluginname'] = 'LAMS Lesson'; +$string['selectsequence'] = 'Select sequence'; +$string['availablesequences'] = 'Sequences'; +$string['openauthor'] = 'Author new LAMS lessons'; + +// Admin interface +$string['adminheader'] = 'LAMS Server Configuration'; +$string['admindescription'] = 'Configure your LAMS server settings. Make sure that the values you enter here correspond with the once you already entered in your LAMS server. Otherwise the integration might not work.'; + +$string['serverurl'] = 'LAMS Server URL:'; +$string['serverurlinfo'] = 'Here you need to enter the URL for your LAMS server. ie: http://localhost:8080/lams/.'; + +$string['serverid'] = 'Server ID:'; +$string['serveridinfo'] = 'What is the Server ID you entered in your LAMS server?'; + +$string['serverkey'] = 'Server Key:'; +$string['serverkeyinfo'] = 'What is the Server Key you entered in your LAMS server?'; + +$string['requestsource'] = 'Moodle instance name:'; +$string['requestsourceinfo'] = 'What is the name of your Moodle instance?. This value will appear after saving a sequence and will be used to prompt the user to "return to ". So here you can put the name you give your Moodle server. ie: "Virtual Campus"'; + +$string['validationbutton'] = "Validate settings"; +$string['validationinfo'] = 'Press the button to validate your settings.'; + + +// + +$string['notsetup'] = 'Configuration is not complete'; + + +// Labels for errors when calling LAMS Server +$string['restcall503'] = 'Call to LAMS failed: received an HTTP status of 503. This might mean that LAMS is unavailable. Please wait a minute and try again, or contact your system administrator.'; +$string['restcall403'] = 'Call to LAMS failed: received an HTTP status of 403 Forbidden. Please check the configurations settings and/or contact your system administrator.'; +$string['restcall400'] = 'Call to LAMS failed: received an HTTP status of 400 Bad Request. Please check the configurations settings and/or contact your system administrator.'; +$string['restcall500'] = 'Call to LAMS failed: received an HTTP status of 500 Internal Error. Please check the configurations settings and/or contact your system administrator.'; +$string['restcalldefault'] = 'Call to LAMS failed: received an HTTP status of: $a'; +$string['restcallfail'] = 'Call to LAMS failed: received no response or connection was refused. Please check that you have the correct LAMS server URL and that it is online.'; + +$string['sequencenotselected'] = 'You must select a sequence to proceed.'; + +// view.php + +$string['nolessons'] = 'There are no LAMS lessons yet in this instance.'; +$string['lessonname'] = 'Lesson name'; +$string['links'] = 'Links'; +$string['introduction'] = 'Introduction'; +$string['openmonitor'] = 'Monitor this lesson'; +$string['lastmodified'] = 'Last modified'; +$string['openlesson'] = 'Click here to open the lesson now'; +$string['empty'] = 'empty'; Index: moodle/mod/lamslesson/pix/icon.gif =================================================================== RCS file: /usr/local/cvsroot/moodle/mod/lamslesson/pix/icon.gif,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ moodle/mod/lamslesson/pix/icon.gif 16 Jan 2011 23:29:52 -0000 1.1 @@ -0,0 +1,5 @@ +GIF89a�l;71SMB\VI^WKd\PngWojXqkZpppzp_{q^vvw{xm�yf�zh�}k�}i��m��n��l�����u�����p��r��q����u��v�����~��y��y��|������������������������������������������������������������������������´�������������Ż�ɻ�п��������������ȱ�ȥ����ɦ�ͱ�Ͷ�̩�ͬ����Ϋ�������Э�Ю�Ե�Դ�յ�׶�ؽ����غ���������������������������������������������������������������������������������������������������������������!�Created with GIMP!� +,���� ;���BHl"%��gcdiejl��El%k]l.9 �-I+=D1hBk(',� +Z\F`_07*!K�Gab��bM� +S��U� ���W�$O��Y�@h/�d@��v`�$�hvXt$�$�� &" +; \ No newline at end of file