Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 402 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 // Prevent Caching Headers. 18 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 19 header("Cache-Control: no-cache"); 20 header("Pragma: no-cache"); 21 22 require_once('../../config.php'); 23 require_once($CFG->dirroot.'/mod/scorm/lib.php'); 24 require_once($CFG->dirroot.'/mod/scorm/locallib.php'); 25 require_once($CFG->dirroot.'/mod/scorm/datamodels/aicclib.php'); 26 27 foreach ($_POST as $key => $value) { 28 $tempkey = strtolower($key); 29 $_POST[$tempkey] = $value; 30 } 31 32 $command = required_param('command', PARAM_ALPHA); 33 $sessionid = required_param('session_id', PARAM_ALPHANUM); 34 $aiccdata = optional_param('aicc_data', '', PARAM_RAW); 35 36 $cfgscorm = get_config('scorm'); 37 38 $url = new moodle_url('/mod/scorm/aicc.php', array('command' => $command, 'session_id' => $sessionid)); 39 if ($aiccdata !== 0) { 40 $url->param('aicc_data', $aiccdata); 41 } 42 $PAGE->set_url($url); 43 44 if (empty($cfgscorm->allowaicchacp)) { 45 require_login(); 46 if (!confirm_sesskey($sessionid)) { 47 throw new \moodle_exception('invalidsesskey'); 48 } 49 $aiccuser = $USER; 50 $scormsession = $SESSION->scorm; 51 } else { 52 $scormsession = scorm_aicc_confirm_hacp_session($sessionid); 53 if (empty($scormsession)) { 54 throw new \moodle_exception('invalidhacpsession', 'scorm'); 55 } 56 $aiccuser = $DB->get_record('user', array('id' => $scormsession->userid), 'id,username,lastname,firstname', MUST_EXIST); 57 } 58 59 if (!empty($command)) { 60 $command = strtolower($command); 61 62 if (isset($scormsession->scoid)) { 63 $scoid = $scormsession->scoid; 64 } else { 65 throw new \moodle_exception('cannotcallscript'); 66 } 67 $mode = 'normal'; 68 if (isset($scormsession->scormmode)) { 69 $mode = $scormsession->scormmode; 70 } 71 $status = 'Not Initialized'; 72 if (isset($scormsession->scormstatus)) { 73 $status = $scormsession->scormstatus; 74 } 75 if (isset($scormsession->attempt)) { 76 $attempt = $scormsession->attempt; 77 } else { 78 $attempt = 1; 79 } 80 81 if ($sco = scorm_get_sco($scoid, SCO_ONLY)) { 82 if (!$scorm = $DB->get_record('scorm', array('id' => $sco->scorm))) { 83 throw new \moodle_exception('cannotcallscript'); 84 } 85 } else { 86 throw new \moodle_exception('cannotcallscript'); 87 } 88 $aiccrequest = "MOODLE scoid: $scoid" 89 . "\r\nMOODLE mode: $mode" 90 . "\r\nMOODLE status: $status" 91 . "\r\nMOODLE attempt: $attempt" 92 . "\r\nAICC sessionid: $sessionid" 93 . "\r\nAICC command: $command" 94 . "\r\nAICC aiccdata:\r\n$aiccdata"; 95 scorm_debug_log_write("aicc", "HACP Request:\r\n$aiccrequest", $scoid); 96 ob_start(); 97 98 if ($scorm = $DB->get_record('scorm', array('id' => $sco->scorm))) { 99 switch ($command) { 100 case 'getparam': 101 if ($status == 'Not Initialized') { 102 $scormsession->scormstatus = 'Running'; 103 $status = 'Running'; 104 } 105 if ($status != 'Running') { 106 echo "error=101\r\nerror_text=Terminated\r\n"; 107 } else { 108 if ($usertrack = scorm_get_tracks($scoid, $aiccuser->id, $attempt)) { 109 $userdata = $usertrack; 110 } else { 111 $userdata->status = ''; 112 $userdata->score_raw = ''; 113 } 114 $aiccuserid = get_config('scorm', 'aiccuserid'); 115 if (!empty($aiccuserid)) { 116 $userdata->student_id = $aiccuser->id; 117 } else { 118 $userdata->student_id = $aiccuser->username; 119 } 120 $userdata->student_name = $aiccuser->lastname .', '. $aiccuser->firstname; 121 $userdata->mode = $mode; 122 if ($userdata->mode == 'normal') { 123 $userdata->credit = 'credit'; 124 } else { 125 $userdata->credit = 'no-credit'; 126 } 127 128 if ($sco = scorm_get_sco($scoid)) { 129 $userdata->course_id = $sco->identifier; 130 $userdata->datafromlms = isset($sco->datafromlms) ? $sco->datafromlms : ''; 131 $userdata->mastery_score = isset($sco->mastery_score) && is_numeric($sco->mastery_score) ? 132 trim($sco->mastery_score) : ''; 133 $userdata->max_time_allowed = isset($sco->max_time_allowed) ? $sco->max_time_allowed : ''; 134 $userdata->time_limit_action = isset($sco->time_limit_action) ? $sco->time_limit_action : ''; 135 136 echo "error=0\r\nerror_text=Successful\r\naicc_data="; 137 echo "[Core]\r\n"; 138 echo 'Student_ID='.$userdata->student_id."\r\n"; 139 echo 'Student_Name='.$userdata->student_name."\r\n"; 140 if (isset($userdata->{'cmi.core.lesson_location'})) { 141 echo 'Lesson_Location='.$userdata->{'cmi.core.lesson_location'}."\r\n"; 142 } else { 143 echo 'Lesson_Location='."\r\n"; 144 } 145 echo 'Credit='.$userdata->credit."\r\n"; 146 if (isset($userdata->status)) { 147 if ($userdata->status == '') { 148 $userdata->entry = ', ab-initio'; 149 } else { 150 if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) { 151 $userdata->entry = ', resume'; 152 } else { 153 $userdata->entry = ''; 154 } 155 } 156 } 157 if (isset($userdata->{'cmi.core.lesson_status'})) { 158 echo 'Lesson_Status='.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\r\n"; 159 $scormsession->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'}; 160 } else { 161 echo 'Lesson_Status=not attempted'.$userdata->entry."\r\n"; 162 $scormsession->scorm_lessonstatus = 'not attempted'; 163 } 164 if (isset($userdata->{'cmi.core.score.raw'})) { 165 $max = ''; 166 $min = ''; 167 if (isset($userdata->{'cmi.core.score.max'}) && !empty($userdata->{'cmi.core.score.max'})) { 168 $max = ', '.$userdata->{'cmi.core.score.max'}; 169 if (isset($userdata->{'cmi.core.score.min'}) && !empty($userdata->{'cmi.core.score.min'})) { 170 $min = ', '.$userdata->{'cmi.core.score.min'}; 171 } 172 } 173 echo 'Score='.$userdata->{'cmi.core.score.raw'}.$max.$min."\r\n"; 174 } else { 175 echo 'Score='."\r\n"; 176 } 177 if (isset($userdata->{'cmi.core.total_time'})) { 178 echo 'Time='.$userdata->{'cmi.core.total_time'}."\r\n"; 179 } else { 180 echo 'Time='.'00:00:00'."\r\n"; 181 } 182 echo 'Lesson_Mode='.$userdata->mode."\r\n"; 183 if (isset($userdata->{'cmi.suspend_data'})) { 184 echo "[Core_Lesson]\r\n".rawurldecode($userdata->{'cmi.suspend_data'})."\r\n"; 185 } else { 186 echo "[Core_Lesson]\r\n"; 187 } 188 echo "[Core_Vendor]\r\n".$userdata->datafromlms."\r\n"; 189 echo "[Evaluation]\r\nCourse_ID = {".$userdata->course_id."}\r\n"; 190 echo "[Student_Data]\r\n"; 191 echo 'Mastery_Score='.$userdata->mastery_score."\r\n"; 192 echo 'Max_Time_Allowed='.$userdata->max_time_allowed."\r\n"; 193 echo 'Time_Limit_Action='.$userdata->time_limit_action."\r\n"; 194 } else { 195 throw new \moodle_exception('cannotfindsco', 'scorm'); 196 } 197 } 198 break; 199 case 'putparam': 200 if ($status == 'Running') { 201 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $scorm->course)) { 202 echo "error=1\r\nerror_text=Unknown\r\n"; // No one must see this error message if not hacked. 203 } 204 $savetrack = has_capability('mod/scorm:savetrack', context_module::instance($cm->id), $aiccuser->id); 205 if (!empty($aiccdata) && $savetrack) { 206 $initlessonstatus = 'not attempted'; 207 $lessonstatus = 'not attempted'; 208 if (isset($scormsession->scorm_lessonstatus)) { 209 $initlessonstatus = $scormsession->scorm_lessonstatus; 210 } 211 $score = ''; 212 $datamodel['lesson_location'] = 'cmi.core.lesson_location'; 213 $datamodel['lesson_status'] = 'cmi.core.lesson_status'; 214 $datamodel['score'] = 'cmi.core.score.raw'; 215 $datamodel['time'] = 'cmi.core.session_time'; 216 $datamodel['[core_lesson]'] = 'cmi.suspend_data'; 217 $datamodel['[comments]'] = 'cmi.comments'; 218 $datarows = explode("\r\n", $aiccdata); 219 reset($datarows); 220 $multirowvalue = ''; 221 $multirowelement = ''; 222 foreach ($datarows as $did => $datarow) { 223 $equal = strpos($datarow, '='); 224 if ($equal === false || !empty($multirowelement)) { 225 if (empty($multirowelement)) { 226 if (isset($datamodel[strtolower(trim($datarow))])) { 227 $multirowelement = $datamodel[strtolower(trim($datarow))]; 228 } else { 229 // An element was passed by the external AICC package is not one we care about. 230 continue; 231 } 232 } 233 $multirowvalue .= $datarow."\r\n"; 234 if (isset($datarows[$did + 1]) && substr($datarows[$did + 1], 0, 1) != '[') { 235 // This is a multiline row, we haven't found the end yet. 236 continue; 237 } 238 $value = rawurlencode($multirowvalue); 239 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $multirowelement, $value); 240 $multirowvalue = $multirowelement = ''; 241 } else { 242 $element = strtolower(trim(substr($datarow, 0, $equal))); 243 $value = trim(substr($datarow, $equal + 1)); 244 if (isset($datamodel[$element])) { 245 $element = $datamodel[$element]; 246 switch ($element) { 247 case 'cmi.core.lesson_location': 248 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 249 $attempt, $element, $value); 250 break; 251 case 'cmi.core.lesson_status': 252 $statuses = array( 253 'passed' => 'passed', 254 'completed' => 'completed', 255 'failed' => 'failed', 256 'incomplete' => 'incomplete', 257 'browsed' => 'browsed', 258 'not attempted' => 'not attempted', 259 'p' => 'passed', 260 'c' => 'completed', 261 'f' => 'failed', 262 'i' => 'incomplete', 263 'b' => 'browsed', 264 'n' => 'not attempted' 265 ); 266 $exites = array( 267 'logout' => 'logout', 268 'time-out' => 'time-out', 269 'suspend' => 'suspend', 270 'l' => 'logout', 271 't' => 'time-out', 272 's' => 'suspend', 273 ); 274 $values = explode(',', $value); 275 $value = ''; 276 if (count($values) > 1) { 277 $value = trim(strtolower($values[1])); 278 $value = $value[0]; 279 if (isset($exites[$value])) { 280 $value = $exites[$value]; 281 } 282 } 283 if (empty($value) || isset($exites[$value])) { 284 $subelement = 'cmi.core.exit'; 285 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 286 $attempt, $subelement, $value); 287 } 288 $value = trim(strtolower($values[0])); 289 $value = $value[0]; 290 if (isset($statuses[$value]) && ($mode == 'normal')) { 291 $value = $statuses[$value]; 292 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 293 $attempt, $element, $value); 294 } 295 $lessonstatus = $value; 296 break; 297 case 'cmi.core.score.raw': 298 $values = explode(',', $value); 299 if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) { 300 $subelement = 'cmi.core.score.max'; 301 $value = trim($values[1]); 302 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 303 $attempt, $subelement, $value); 304 if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) { 305 $subelement = 'cmi.core.score.min'; 306 $value = trim($values[2]); 307 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 308 $attempt, $subelement, $value); 309 } 310 } 311 312 $value = ''; 313 if (is_numeric($values[0])) { 314 $value = trim($values[0]); 315 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 316 $attempt, $element, $value); 317 } 318 $score = $value; 319 break; 320 case 'cmi.core.session_time': 321 $scormsession->sessiontime = $value; 322 break; 323 } 324 } 325 } 326 } 327 if (($mode == 'browse') && ($initlessonstatus == 'not attempted')) { 328 $lessonstatus = 'browsed'; 329 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 330 $attempt, 'cmi.core.lesson_status', 'browsed'); 331 } 332 if ($mode == 'normal') { 333 if ($sco = scorm_get_sco($scoid)) { 334 if (isset($sco->mastery_score) && is_numeric($sco->mastery_score)) { 335 if ($score != '') { // Score is correctly initialized w/ an empty string, see above. 336 if ($score >= trim($sco->mastery_score)) { 337 $lessonstatus = 'passed'; 338 } else { 339 $lessonstatus = 'failed'; 340 } 341 } 342 } 343 $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, 344 $attempt, 'cmi.core.lesson_status', $lessonstatus); 345 } 346 } 347 } 348 echo "error=0\r\nerror_text=Successful\r\n"; 349 } else if ($status == 'Terminated') { 350 echo "error=1\r\nerror_text=Terminated\r\n"; 351 } else { 352 echo "error=1\r\nerror_text=Not Initialized\r\n"; 353 } 354 break; 355 case 'putcomments': 356 if ($status == 'Running') { 357 echo "error=0\r\nerror_text=Successful\r\n"; 358 } else if ($status == 'Terminated') { 359 echo "error=1\r\nerror_text=Terminated\r\n"; 360 } else { 361 echo "error=1\r\nerror_text=Not Initialized\r\n"; 362 } 363 break; 364 case 'putinteractions': 365 if ($status == 'Running') { 366 echo "error=0\r\nerror_text=Successful\r\n"; 367 } else if ($status == 'Terminated') { 368 echo "error=1\r\nerror_text=Terminated\r\n"; 369 } else { 370 echo "error=1\r\nerror_text=Not Initialized\r\n"; 371 } 372 break; 373 case 'putobjectives': 374 if ($status == 'Running') { 375 echo "error=0\r\nerror_text=Successful\r\n"; 376 } else if ($status == 'Terminated') { 377 echo "error=1\r\nerror_text=Terminated\r\n"; 378 } else { 379 echo "error=1\r\nerror_text=Not Initialized\r\n"; 380 } 381 break; 382 case 'putpath': 383 if ($status == 'Running') { 384 echo "error=0\r\nerror_text=Successful\r\n"; 385 } else if ($status == 'Terminated') { 386 echo "error=1\r\nerror_text=Terminated\r\n"; 387 } else { 388 echo "error=1\r\nerror_text=Not Initialized\r\n"; 389 } 390 break; 391 case 'putperformance': 392 if ($status == 'Running') { 393 echo "error=0\r\nerror_text=Successful\r\n"; 394 } else if ($status == 'Terminated') { 395 echo "error=1\r\nerror_text=Terminated\r\n"; 396 } else { 397 echo "error=1\r\nerror_text=Not Initialized\r\n"; 398 } 399 break; 400 case 'exitau': 401 if ($status == 'Running') { 402 if (isset($scormsession->sessiontime) && ($scormsession->sessiontime != '')) { 403 if ($track = $DB->get_record('scorm_scoes_track', array("userid" => $aiccuser->id, 404 "scormid" => $scorm->id, 405 "scoid" => $sco->id, 406 "attempt" => $attempt, 407 "element" => 'cmi.core.total_time'))) { 408 // Add session_time to total_time. 409 $value = scorm_add_time($track->value, $scormsession->sessiontime); 410 $track->value = $value; 411 $track->timemodified = time(); 412 $DB->update_record('scorm_scoes_track', $track); 413 } else { 414 $track = new stdClass(); 415 $track->userid = $aiccuser->id; 416 $track->scormid = $scorm->id; 417 $track->scoid = $sco->id; 418 $track->element = 'cmi.core.total_time'; 419 $track->value = $scormsession->sessiontime; 420 $track->attempt = $attempt; 421 $track->timemodified = time(); 422 $id = $DB->insert_record('scorm_scoes_track', $track); 423 } 424 scorm_update_grades($scorm, $aiccuser->id); 425 } 426 $scormsession->scormstatus = 'Terminated'; 427 $scormsession->session_time = ''; 428 echo "error=0\r\nerror_text=Successful\r\n"; 429 } else if ($status == 'Terminated') { 430 echo "error=1\r\nerror_text=Terminated\r\n"; 431 } else { 432 echo "error=1\r\nerror_text=Not Initialized\r\n"; 433 } 434 break; 435 default: 436 echo "error=1\r\nerror_text=Invalid Command\r\n"; 437 break; 438 } 439 } 440 } else { 441 if (empty($command)) { 442 echo "error=1\r\nerror_text=Invalid Command\r\n"; 443 } else { 444 echo "error=3\r\nerror_text=Invalid Session ID\r\n"; 445 } 446 } 447 if (empty($cfgscorm->allowaicchacp)) { 448 $SESSION->scorm = $scormsession; 449 } else { 450 $scormsession->timemodified = time(); 451 $DB->update_record('scorm_aicc_session', $scormsession); 452 } 453 454 $aiccresponse = ob_get_contents(); 455 scorm_debug_log_write("aicc", "HACP Response:\r\n$aiccresponse", $scoid); 456 ob_end_flush();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body