From e3fb15de88425466d8501c1e1df8089030ec7f9b Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 31 Jul 2023 20:00:57 +1200 Subject: [PATCH] MDL-63539 mod_scorm: AICC multi-row content not saving correctly. --- mod/scorm/aicc.php | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/mod/scorm/aicc.php b/mod/scorm/aicc.php index 9598e3f17a6..73317cabdb8 100644 --- a/mod/scorm/aicc.php +++ b/mod/scorm/aicc.php @@ -217,8 +217,28 @@ if (!empty($command)) { $datamodel['[comments]'] = 'cmi.comments'; $datarows = explode("\r\n", $aiccdata); reset($datarows); - foreach ($datarows as $datarow) { - if (($equal = strpos($datarow, '=')) !== false) { + $multirowvalue = ''; + $multirowelement = ''; + foreach ($datarows as $did => $datarow) { + $equal = strpos($datarow, '='); + if ($equal === false || !empty($multirowelement)) { + if (empty($multirowelement)) { + if (isset($datamodel[strtolower(trim($datarow))])) { + $multirowelement = $datamodel[strtolower(trim($datarow))]; + } else { + // An element was passed by the external AICC package is not one we care about. + continue; + } + } + $multirowvalue .= $datarow."\r\n"; + if (isset($datarows[$did + 1]) && substr($datarows[$did + 1], 0, 1) != '[') { + // This is a multiline row, we haven't found the end yet. + continue; + } + $value = rawurlencode($multirowvalue); + $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $multirowelement, $value); + $multirowvalue = $multirowelement = ''; + } else { $element = strtolower(trim(substr($datarow, 0, $equal))); $value = trim(substr($datarow, $equal + 1)); if (isset($datamodel[$element])) { @@ -302,17 +322,6 @@ if (!empty($command)) { break; } } - } else { - if (isset($datamodel[strtolower(trim($datarow))])) { - $element = $datamodel[strtolower(trim($datarow))]; - $value = ''; - while ((($datarow = current($datarows)) !== false) && (substr($datarow, 0, 1) != '[')) { - $value .= $datarow."\r\n"; - next($datarows); - } - $value = rawurlencode($value); - $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value); - } } } if (($mode == 'browse') && ($initlessonstatus == 'not attempted')) {