Update from 1.9.x

1.10.x
Julio Montoya 10 years ago
parent 4db070a926
commit e6bc9d32b4
  1. 141
      main/cron/import_csv.php
  2. 80
      main/newscorm/lp_upload.php

@ -113,6 +113,14 @@ class ImportCsv
$isStatic = strpos($method, 'Static');
if ($method == 'importSessionsextidStatic') {
$method = 'importSessionsExtIdStatic';
}
if ($method == 'importUnsubsessionsextidStatic') {
$method = 'importUnsubsessionsExtidStatic';
}
if (method_exists($this, $method)) {
if (($method == 'importUnsubscribeStatic' ||
$method == 'importSubscribeStatic') ||
@ -155,6 +163,7 @@ class ImportCsv
'subscribe-static',
'unsubscribe-static'
);
foreach ($sections as $section) {
$this->logger->addInfo("-- Import $section --");
@ -180,6 +189,8 @@ class ImportCsv
'teachers-static',
'courses-static',
'sessions-static',
'sessionsextid-static',
'unsubsessionsextid-static',
'calendar-static',
);
@ -192,6 +203,7 @@ class ImportCsv
$files = $fileToProcessStatic[$section];
foreach ($files as $fileInfo) {
$method = $fileInfo['method'];
$file = $fileInfo['file'];
echo 'Static file: '.$file.PHP_EOL;
$this->logger->addInfo("Reading static file: $file");
@ -1063,6 +1075,134 @@ class ImportCsv
}
}
/**
* @param string $file
*/
private function importUnsubSessionsExtIdStatic($file)
{
$data = Import::csv_reader($file);
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$chamiloUserName = $row['UserName'];
$chamiloCourseCode = $row['CourseCode'];
$externalSessionId = $row['ExtSessionID'];
$dateStop = $row['DateStop'];
$chamiloSessionId = null;
if (!empty($externalSessionId)) {
$chamiloSessionId = SessionManager::get_session_id_from_original_id(
$externalSessionId,
$this->extraFieldIdNameList['session']
);
}
$sessionInfo = api_get_session_info($chamiloSessionId);
if (empty($sessionInfo)) {
$this->logger->addError('Session does not exists: '.$chamiloSessionId);
continue;
}
$courseInfo = api_get_course_info($chamiloCourseCode);
if (empty($courseInfo)) {
$this->logger->addError('Course does not exists: '.$courseInfo);
continue;
}
$userId = Usermanager::get_user_id_from_username($chamiloUserName);
if (empty($userId)) {
$this->logger->addError('User does not exists: '.$chamiloUserName);
continue;
}
SessionManager::removeUsersFromCourseSession(
array($userId),
$chamiloSessionId,
$courseInfo
);
$this->logger->addError(
"User '$chamiloUserName' was remove from Session: #$chamiloSessionId - Course: " . $courseInfo['code']
);
}
}
}
/**
*
* @param string $file
*/
private function importSessionsExtIdStatic($file)
{
$data = Import::csv_reader($file);
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$chamiloUserName = $row['UserName'];
$chamiloCourseCode = $row['CourseCode'];
$externalSessionId = $row['ExtSessionID'];
$type = $row['Type'];
$chamiloSessionId = null;
if (!empty($externalSessionId)) {
$chamiloSessionId = SessionManager::get_session_id_from_original_id(
$externalSessionId,
$this->extraFieldIdNameList['session']
);
}
$sessionInfo = api_get_session_info($chamiloSessionId);
if (empty($sessionInfo)) {
$this->logger->addError('Session does not exists: '.$chamiloSessionId);
continue;
}
$courseInfo = api_get_course_info($chamiloCourseCode);
if (empty($courseInfo)) {
$this->logger->addError('Course does not exists: '.$courseInfo);
continue;
}
$userId = Usermanager::get_user_id_from_username($chamiloUserName);
if (empty($userId)) {
$this->logger->addError('User does not exists: '.$chamiloUserName);
continue;
}
$status = null;
switch ($type) {
case 'student':
SessionManager::subscribe_users_to_session_course(
array($userId),
$chamiloSessionId,
$courseInfo['code'],
null,
false
);
break;
case 'teacher':
SessionManager::set_coach_to_course_session(
$userId,
$chamiloSessionId,
$courseInfo['code']
);
break;
}
$this->logger->addError(
"User '$chamiloUserName' with status $type was added to session: #$chamiloSessionId - Course: " . $courseInfo['code']
);
}
}
}
/**
* Updates the session synchronize with the csv file.
* @param string $file
@ -1468,6 +1608,7 @@ class ImportCsv
$courseInfo['code'],
$chamiloSessionId
);
$this->logger->addError(
"User '$chamiloUserName' was removed from session: #$chamiloSessionId, Course: ".$courseInfo['code']
);

@ -66,6 +66,86 @@ if (isset($_POST) && $is_error) {
}
if (!empty($manifest)) {
$oScorm->parse_manifest($manifest);
$fixTemplate = api_get_configuration_value('learnpath_fix_xerte_template');
$proxyPath = api_get_configuration_value('learnpath_proxy_url');
if ($fixTemplate && !empty($proxyPath)) {
// Check organisations:
if (isset($oScorm->manifest['organizations'])) {
foreach ($oScorm->manifest['organizations'] as $data) {
if (strpos(strtolower($data), 'xerte') !== false) {
// Check if template.xml exists:
$templatePath = str_replace('imsmanifest.xml', 'template.xml', $manifest);
if (file_exists($templatePath) && is_file($templatePath)) {
$templateContent = file_get_contents($templatePath);
$find = array(
'href="www.',
'href="https://',
'href="http://',
'url="www.',
'pdfs/download.php?'
);
$replace = array(
'href="http://www.',
'target = "_blank" href="'.$proxyPath.'?type=link&src=https://',
'target = "_blank" href="'.$proxyPath.'?type=link&src=http://',
'url="http://www.',
'pdfs/download.php&'
);
$templateContent = str_replace($find, $replace, $templateContent);
file_put_contents($templatePath, $templateContent);
}
// Fix link generation:
$linkPath = str_replace('imsmanifest.xml', 'models_html5/links.html', $manifest);
if (file_exists($linkPath) && is_file($linkPath)) {
$linkContent = file_get_contents($linkPath);
$find = array(
':this.getAttribute("url")'
);
$replace = array(
':"'.$proxyPath.'?type=link&src=" + this.getAttribute("url")'
);
$linkContent = str_replace($find, $replace, $linkContent);
file_put_contents($linkPath, $linkContent);
}
// Fix iframe generation
$framePath = str_replace('imsmanifest.xml', 'models_html5/embedDiv.html', $manifest);
if (file_exists($framePath) && is_file($framePath)) {
$content = file_get_contents($framePath);
$find = array(
'$iFrameHolder.html(iFrameTag);'
);
$replace = array(
'iFrameTag = \'<a target ="_blank" href="'.$proxyPath.'?type=link&src=\'+ pageSrc + \'">Open website. <img src="'.api_get_path(WEB_CODE_PATH).'img/link-external.png"></a>\'; $iFrameHolder.html(iFrameTag); '
);
$content = str_replace($find, $replace, $content);
file_put_contents($framePath, $content);
}
// Fix new window generation
$newWindowPath = str_replace('imsmanifest.xml', 'models_html5/newWindow.html', $manifest);
if (file_exists($newWindowPath) && is_file($newWindowPath)) {
$content = file_get_contents($newWindowPath);
$find = array(
'var src = x_currentPageXML'
);
$replace = array(
'var src = "'.$proxyPath.'?type=link&src=" + x_currentPageXML'
);
$content = str_replace($find, $replace, $content);
file_put_contents($newWindowPath, $content);
}
}
}
}
}
$oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
} else {
// Show error message stored in $oScrom->error_msg.

Loading…
Cancel
Save