Update from 1.9.x

1.10.x
Julio Montoya 9 years ago
parent 0f015fbb72
commit 6b88e95b1d
  1. 12
      main/inc/lib/fileUpload.lib.php
  2. 128
      main/newscorm/learnpath.class.php
  3. 39
      main/newscorm/scorm.class.php
  4. 633
      main/webservices/lp.php

@ -412,7 +412,7 @@ function handle_uploaded_document(
);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $documentId);
api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo);
} else {
// There might be cases where the file exists on disk but there is no registration of that in the database
// In this case, and if we are in overwrite mode, overwrite and create the db record
@ -445,7 +445,7 @@ function handle_uploaded_document(
);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $documentId);
api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo);
}
}
@ -492,7 +492,7 @@ function handle_uploaded_document(
);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $documentId);
api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo);
}
// If the file is in a folder, we need to update all parent folders
item_property_update_on_folder($courseInfo, $uploadPath, $userId);
@ -569,7 +569,7 @@ function handle_uploaded_document(
);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $documentId);
api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo);
}
// If the file is in a folder, we need to update all parent folders
@ -631,7 +631,7 @@ function handle_uploaded_document(
$sessionId
);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $documentId);
api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo);
}
// If the file is in a folder, we need to update all parent folders
@ -1237,7 +1237,7 @@ function add_document(
Database::query($sql);
if ($save_visibility) {
api_set_default_visibility($documentId, TOOL_DOCUMENT, $group_id);
api_set_default_visibility($documentId, TOOL_DOCUMENT, $group_id, $_course);
}
return $documentId;

@ -488,12 +488,12 @@ class learnpath
$prerequisites = 0,
$max_time_allowed = 0
) {
$course_id = api_get_course_int_id();
$course_id = $this->course_info['real_id'];
if ($this->debug > 0) {
error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
}
$tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
$_course = api_get_course_info();
$_course = $this->course_info;
$parent = intval($parent);
$previous = intval($previous);
$id = intval($id);
@ -567,7 +567,7 @@ class learnpath
$max_score = Database :: result($rsQuiz, 0, 0);
// Disabling the exercise if we add it inside a LP
$exercise = new Exercise();
$exercise = new Exercise($course_id);
$exercise->read($id);
$exercise->disable();
$exercise->save();
@ -710,7 +710,7 @@ class learnpath
* @return integer The new learnpath ID on success, 0 on failure
*/
public static function add_lp(
$course,
$courseCode,
$name,
$description = '',
$learnpath = 'guess',
@ -721,7 +721,15 @@ class learnpath
$categoryId = 0
) {
global $charset;
$course_id = api_get_course_int_id();
if (!empty($courseCode)) {
$courseInfo = api_get_course_info($courseCode);
$course_id = $courseInfo['real_id'];
} else {
$course_id = api_get_course_int_id();
$courseInfo = api_get_course_info();
}
$tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
// Check course code exists.
// Check lp_name doesn't exist, otherwise append something.
@ -819,16 +827,15 @@ class learnpath
$sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id";
Database::query($sql);
$course_info = api_get_course_info();
// Insert into item_property.
api_item_property_update(
$course_info,
$courseInfo,
TOOL_LEARNPATH,
$id,
'LearnpathAdded',
api_get_user_id()
);
api_set_default_visibility($id, TOOL_LEARNPATH);
api_set_default_visibility($id, TOOL_LEARNPATH, 0, $courseInfo);
return $id;
}
break;
@ -985,14 +992,17 @@ class learnpath
/**
* Static admin function allowing removal of a learnpath
* @param string Course code
* @param array $courseInfo
* @param integer Learnpath ID
* @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
* @return boolean True on success, false on failure (might change that to return number of elements deleted)
*/
public function delete($course = null, $id = null, $delete = 'keep')
public function delete($courseInfo = null, $id = null, $delete = 'keep')
{
$course_id = api_get_course_int_id();
if (!empty($courseInfo)) {
$course_id = isset($courseInfo['real_id']) ? $courseInfo['real_id'] : $course_id;
}
// TODO: Implement a way of getting this to work when the current object is not set.
// In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
@ -3219,7 +3229,7 @@ class learnpath
return $html;
}
/**
/**
* Returns an HTML-formatted string ready to display with teacher buttons
* in LP view menu
* @return string HTML TOC ready to display
@ -5623,13 +5633,13 @@ class learnpath
$edit_icon .= '</a>';
if (
!in_array($arrLP[$i]['item_type'], ['forum', 'thread'])
!in_array($arrLP[$i]['item_type'], ['forum', 'thread'])
) {
if (
$this->items[$arrLP[$i]['id']]->getForumThread(
$this->course_int_id,
$this->lp_session_id
)
$this->items[$arrLP[$i]['id']]->getForumThread(
$this->course_int_id,
$this->lp_session_id
)
) {
$forumIcon = Display::url(
Display::return_icon('forum.png', get_lang('CreateForum'), [], ICON_SIZE_TINY),
@ -5638,10 +5648,10 @@ class learnpath
);
} else {
$forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
'action' => 'create_forum',
'id' => $arrLP[$i]['id'],
'lp_id' => $this->lp_id
]);
'action' => 'create_forum',
'id' => $arrLP[$i]['id'],
'lp_id' => $this->lp_id
]);
$forumIcon = Display::url(
Display::return_icon('forum.png', get_lang('CreateForum'), [], ICON_SIZE_TINY),
$forumIconUrl,
@ -5670,7 +5680,7 @@ class learnpath
}
if ($update_audio != 'true') {
$row = $move_icon . ' ' . $icon .
Display::span($title_cut) .
Display::span($title_cut) .
Display::tag(
'div',
"<div class=\"btn-group btn-group-xs\">$audio $edit_icon $forumIcon $prerequisities_icon $move_item_icon $audio_icon $delete_icon</div>",
@ -5908,14 +5918,24 @@ class learnpath
/**
* Create a new document //still needs some finetuning
* @param array $_course
* @param array $courseInfo
* @param string $content
* @param string $title
* @param string $extension
*
* @return string
*/
public function create_document($_course)
public function create_document($courseInfo, $content = '', $title = '', $extension = 'html')
{
$course_id = api_get_course_int_id();
if (!empty($courseInfo)) {
$course_id = $courseInfo['real_id'];
} else {
$course_id = api_get_course_int_id();
}
global $charset;
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir'];
$postDir = isset($_POST['dir']) ? $_POST['dir'] : '';
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $postDir; // Please, do not modify this dirname formatting.
// Please, do not modify this dirname formatting.
if (strstr($dir, '..'))
$dir = '/';
@ -5926,35 +5946,43 @@ class learnpath
if ($dir[strlen($dir) - 1] != '/')
$dir .= '/';
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
$filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document' . $dir;
if (empty($_POST['dir']) && empty($_GET['dir'])) {
//Generates folder
$result = $this->generate_lp_folder($_course);
$dir = $result['dir'];
$filepath = $result['filepath'];
$result = $this->generate_lp_folder($courseInfo);
$dir = $result['dir'];
$filepath = $result['filepath'];
}
if (!is_dir($filepath)) {
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
$filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document/';
$dir = '/';
}
// stripslashes() before calling api_replace_dangerous_char() because $_POST['title']
// is already escaped twice when it gets here.
$title = api_replace_dangerous_char(stripslashes($_POST['title']));
$originalTitle = !empty($title) ? $title : $_POST['title'];
if (!empty($title)) {
$title = api_replace_dangerous_char(stripslashes($title));
} else {
$title = api_replace_dangerous_char(stripslashes($_POST['title']));
}
$title = disable_dangerous_file($title);
$filename = $title;
$content = $_POST['content_lp'];
$content = isset($content) ? $content : $_POST['content_lp'];
$tmp_filename = $filename;
$i = 0;
while (file_exists($filepath . $tmp_filename . '.html'))
while (file_exists($filepath . $tmp_filename . '.'.$extension))
$tmp_filename = $filename . '_' . ++ $i;
$filename = $tmp_filename . '.html';
$filename = $tmp_filename . '.'.$extension;
$content = stripslashes($content);
$content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH).'courses/', $content);
@ -5962,9 +5990,9 @@ class learnpath
// Change the path of mp3 to absolute.
// The first regexp deals with :// urls.
$content = preg_replace("|(flashvars=\"file=)([^:/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
$content = preg_replace("|(flashvars=\"file=)([^:/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $courseInfo['path'] . '/document/', $content);
// The second regexp deals with audio/ urls.
$content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
$content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $courseInfo['path'] . '/document/$2/', $content);
// For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
$content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
@ -5977,7 +6005,7 @@ class learnpath
$save_file_path = $dir.$filename;
$document_id = add_document(
$_course,
$courseInfo,
$save_file_path,
'file',
$file_size,
@ -5986,7 +6014,7 @@ class learnpath
if ($document_id) {
api_item_property_update(
$_course,
$courseInfo,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
@ -5999,7 +6027,7 @@ class learnpath
);
$new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
$new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
$new_title = $originalTitle;
if ($new_comment || $new_title) {
$tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
@ -6009,8 +6037,9 @@ class learnpath
if ($new_title)
$ct .= ", title='" . Database::escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset))."' ";
$sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE c_id = ".$course_id." AND id = " . $document_id;
Database::query($sql_update);
$sql = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)."
WHERE c_id = ".$course_id." AND id = " . $document_id;
Database::query($sql);
}
}
return $document_id;
@ -6251,6 +6280,7 @@ class learnpath
// Get all the docs.
$documents = $this->get_documents(true);
// Get all the exercises.
$exercises = $this->get_exercises();
@ -8551,7 +8581,7 @@ class learnpath
$return .= '<li class="lp_resource_element">';
$return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
$return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?'.api_get_cidreq().'&lp_id=' . $this->lp_id . '">' .
get_lang('NewExercise') . '</a>';
get_lang('NewExercise') . '</a>';
$return .= '</li>';
// Display hotpotatoes
@ -8624,7 +8654,7 @@ class learnpath
}
$linksHtmlCode =
'<script>
'<script>
function toggle_tool(tool, id){
if(document.getElementById(tool+"_"+id+"_content").style.display == "none"){
document.getElementById(tool+"_"+id+"_content").style.display = "block";
@ -8639,28 +8669,28 @@ class learnpath
<li class="lp_resource_element">
<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px"/>
<a href="'.api_get_path(REL_CODE_PATH).'link/link.php?'.$courseIdReq.
'&action=addlink&lp_id='.$this->lp_id.'" title="'.get_lang('LinkAdd').'">'.get_lang('LinkAdd').'</a>
'&action=addlink&lp_id='.$this->lp_id.'" title="'.get_lang('LinkAdd').'">'.get_lang('LinkAdd').'</a>
</li>';
foreach ($categorizedLinks as $categoryId => $links) {
$linkNodes = null;
foreach ($links as $key => $title) {
if (api_get_item_visibility($course, TOOL_LINK, $key, $session_id) != 2) {
$linkNodes .=
'<li class="lp_resource_element" data_id="'.$key.
'<li class="lp_resource_element" data_id="'.$key.
'" data_type="'.TOOL_LINK.'" title="'.$title.'" >
<a class="moved" href="#">'.
$moveEverywhereIcon.
$moveEverywhereIcon.
'</a>
<img alt="" src="../img/lp_link.gif" style="margin-right:5px;width:16px"/>
<a href="'.$selfUrl.'?'.$courseIdReq.'&action=add_item&type='.
TOOL_LINK.'&file='.$key.'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($title).
TOOL_LINK.'&file='.$key.'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($title).
'</a>
</li>';
}
}
$linksHtmlCode .=
'<li>
'<li>
<a style="cursor:hand" onclick="javascript: toggle_tool(\''.TOOL_LINK.'\','.$categoryId.')"
style="vertical-align:middle">
<img src="'.api_get_path(WEB_IMG_PATH).'add.gif" id="'.TOOL_LINK.'_'.$categoryId.'_opener"

@ -270,9 +270,11 @@ class scorm extends learnpath
* Import the scorm object (as a result from the parse_manifest function) into the database structure
* @param string $courseCode
* @param int $userMaxScore
* @param int $sessionId
*
* @return bool Returns -1 on error
*/
public function import_manifest($courseCode, $userMaxScore = 1)
public function import_manifest($courseCode, $userMaxScore = 1, $sessionId = 0)
{
if ($this->debug > 0) {
error_log('New LP - Entered import_manifest('.$courseCode.')', 0);
@ -285,10 +287,8 @@ class scorm extends learnpath
$new_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$userMaxScore = intval($userMaxScore);
$sessionId = empty($sessionId) ? api_get_session_id() : intval($sessionId);
foreach ($this->organizations as $id => $dummy) {
$is_session = api_get_session_id();
$is_session != 0 ? $session_id = $is_session : $session_id = 0;
$oOrganization = & $this->organizations[$id];
// Prepare and execute insert queries:
// -for learnpath
@ -305,7 +305,7 @@ class scorm extends learnpath
$myname = api_utf8_decode($myname);
$sql = "INSERT INTO $new_lp (c_id, lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib,display_order, session_id, use_max_score)" .
"VALUES ($courseId , 2,'".$myname."', '".$oOrganization->get_ref()."','','".$this->subdir."', 0, 'embedded', '".$this->manifest_encoding."', 'scorm_api.php', $dsp, $session_id, $userMaxScore)";
"VALUES ($courseId , 2,'".$myname."', '".$oOrganization->get_ref()."','','".$this->subdir."', 0, 'embedded', '".$this->manifest_encoding."', 'scorm_api.php', $dsp, $sessionId, $userMaxScore)";
if ($this->debug > 1) { error_log('New LP - In import_manifest(), inserting path: '. $sql, 0); }
Database::query($sql);
@ -501,16 +501,21 @@ class scorm extends learnpath
/**
* Imports a zip file into the Chamilo structure
* @param string $zip_file_info Zip file info as given by $_FILES['userFile']
* @param string $zip_file_info Zip file info as given by $_FILES['userFile']
* @param string
* @param array
*
* @return string $current_dir Absolute path to the imsmanifest.xml file or empty string on error
*/
public function import_package($zip_file_info, $current_dir = '')
public function import_package($zip_file_info, $current_dir = '', $courseInfo = array())
{
if ($this->debug > 0) {
error_log('In scorm::import_package('.print_r($zip_file_info,true).',"'.$current_dir.'") method', 0);
}
$maxFilledSpace = DocumentManager :: get_course_quota();
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$maxFilledSpace = DocumentManager :: get_course_quota($courseInfo['code']);
$zip_file_path = $zip_file_info['tmp_name'];
$zip_file_name = $zip_file_info['name'];
@ -518,9 +523,10 @@ class scorm extends learnpath
if ($this->debug > 1) {
error_log('New LP - import_package() - zip file path = ' . $zip_file_path . ', zip file name = ' . $zip_file_name, 0);
}
$course_rel_dir = api_get_course_path().'/scorm'; // scorm dir web path starting from /courses
$course_rel_dir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses
$course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // Absolute system path for this course.
$current_dir = api_replace_dangerous_char(trim($current_dir)); // Current dir we are in, inside scorm/
$current_dir = api_replace_dangerous_char(trim($current_dir)); // Current dir we are in, inside scorm/
if ($this->debug > 1) {
error_log( 'New LP - import_package() - current_dir = ' . $current_dir, 0);
@ -695,11 +701,12 @@ class scorm extends learnpath
/**
* Sets the proximity setting in the database
* @param string $proxy Proximity setting
* @param string Proximity setting
* @param int $courseId
*/
public function set_proximity($proxy = '')
public function set_proximity($proxy = '', $courseId = null)
{
$courseId = api_get_course_int_id();
$courseId = empty($courseId) ? api_get_course_int_id() : intval($courseId);
if ($this->debug > 0) { error_log('In scorm::set_proximity('.$proxy.') method', 0); }
$lp = $this->get_id();
if ($lp != 0) {
@ -772,11 +779,11 @@ class scorm extends learnpath
/**
* Sets the content maker setting in the database
* @param string $maker
* @param string Proximity setting
*/
public function set_maker($maker = '')
public function set_maker($maker = '', $courseId = null)
{
$courseId = api_get_course_int_id();
$courseId = empty($courseId) ? api_get_course_int_id() : intval($courseId);
if ($this->debug > 0) { error_log('In scorm::set_maker method('.$maker.')', 0); }
$lp = $this->get_id();
if ($lp != 0) {

@ -0,0 +1,633 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.webservices
*/
require_once '../inc/global.inc.php';
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'nusoap/nusoap.php';
require_once $libpath.'fileManage.lib.php';
require_once $libpath.'fileUpload.lib.php';
require_once api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php';
require_once $libpath.'add_course.lib.inc.php';
$debug = true;
define('WS_ERROR_SECRET_KEY', 1);
function return_error($code) {
$fault = null;
switch ($code) {
case WS_ERROR_SECRET_KEY:
$fault = new soap_fault('Server', '', 'Secret key is not correct or params are not correctly set');
break;
}
return $fault;
}
function WSHelperVerifyKey($params)
{
global $_configuration, $debug;
if (is_array($params)) {
$secret_key = $params['secret_key'];
} else {
$secret_key = $params;
}
//error_log(print_r($params,1));
$check_ip = false;
$ip_matches = false;
$ip = trim($_SERVER['REMOTE_ADDR']);
// if we are behind a reverse proxy, assume it will send the
// HTTP_X_FORWARDED_FOR header and use this IP instead
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
list($ip1, $ip2) = split(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ip1);
}
if ($debug)
error_log("ip: $ip");
// Check if a file that limits access from webservices exists and contains
// the restraining check
if (is_file('webservice-auth-ip.conf.php')) {
include 'webservice-auth-ip.conf.php';
if ($debug)
error_log("webservice-auth-ip.conf.php file included");
if (!empty($ws_auth_ip)) {
$check_ip = true;
$ip_matches = api_check_ip_in_range($ip, $ws_auth_ip);
if ($debug)
error_log("ip_matches: $ip_matches");
}
}
if ($debug) {
error_log("checkip " . intval($check_ip));
}
if ($check_ip) {
$security_key = $_configuration['security_key'];
} else {
$security_key = $ip.$_configuration['security_key'];
//error_log($secret_key.'-'.$security_key);
}
$result = api_is_valid_secret_key($secret_key, $security_key);
//error_log($secret_key.'-'.$security_key);
if ($debug)
error_log('WSHelperVerifyKey result: '.intval($result));
return $result;
}
// Create the server instance
$server = new soap_server();
//$server->soap_defencoding = 'UTF-8';
// Initialize WSDL support
$server->configureWSDL('WSLP', 'urn:WSLP');
$server->wsdl->addComplexType(
'params',
'complexType',
'struct',
'all',
'',
array(
'course_id_name' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'course_id_value' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'session_id_name' => array(
'name' => 'session_id_name',
'type' => 'xsd:string',
),
'session_id_value' => array(
'name' => 'session_id_value',
'type' => 'xsd:string',
),
'file_data' => array('name' => 'file', 'type' => 'xsd:string'),
'filename' => array('name' => 'filename', 'type' => 'xsd:string'),
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
)
);
// Register the method to expose
$server->register('WSImportLP', // method name
array('params' => 'tns:params'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:WSLP', // namespace
'urn:WSLP#WSImportLP', // soapaction
'rpc', // style
'encoded', // use
'This service adds users' // documentation
);
/**
* @param array $params
* @return int|string
*/
function WSImportLP($params)
{
global $debug;
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
if ($debug) error_log('WSImportLP');
$courseIdName = $params['course_id_name'];
$courseIdValue = $params['course_id_value'];
$sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
$sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
$courseCode = CourseManager::get_course_id_from_original_id(
$courseIdValue,
$courseIdName
);
$courseInfo = api_get_course_info($courseCode);
$courseId = $courseInfo['real_id'];
if (empty($courseInfo)) {
if ($debug) error_log('Course not found');
return 'Course not found';
}
$sessionId = 0;
if (!empty($sessionIdName) && !empty($sessionIdValue)) {
$sessionId = SessionManager::get_session_id_from_original_id(
$sessionIdValue,
$sessionIdName
);
if (empty($sessionId)) {
if ($debug) error_log('Session not found');
return 'Session not found';
}
}
$proximity = 'local';
$maker = 'Scorm';
$maxScore = ''; //$_REQUEST['use_max_score']
$oScorm = new scorm();
$fileData = base64_decode($params['file_data']);
$uniqueFile = uniqid();
$filePath = api_get_path(SYS_ARCHIVE_PATH) . $uniqueFile;
file_put_contents($filePath, $fileData);
$fileName = $params['filename'];
$fileInfo = array(
'tmp_name' => $filePath,
'name' => $fileName
);
$manifest = $oScorm->import_package($fileInfo, '', $courseInfo);
if (!$manifest) {
if ($debug) error_log('manifest.xml file not found');
//if api_set_failure
return 'manifest.xml file not found';
}
$manifestData = $oScorm->parse_manifest($manifest);
if (!empty($manifestData)) {
$oScorm->import_manifest(
$courseInfo['code'],
$maxScore,
$sessionId
);
$oScorm->set_proximity($proximity, $courseId);
$oScorm->set_maker($maker, $courseId);
//$oScorm->set_jslib('scorm_api.php');
return 1;
} else {
if ($debug) error_log('manifest data empty');
return 'manifest data empty';
}
}
$server->wsdl->addComplexType(
'paramsGetLpList',
'complexType',
'struct',
'all',
'',
array(
'course_id_name' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'course_id_value' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'session_id_name' => array(
'name' => 'session_id_name',
'type' => 'xsd:string',
),
'session_id_value' => array(
'name' => 'session_id_value',
'type' => 'xsd:string',
),
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType(
'lpListItem',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name' => 'id', 'type' => 'xsd:string'),
'name' => array('name' => 'name', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType(
'lpList',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:lpListItem[]')),
'tns:lpListItem'
);
// Register the method to expose
$server->register('WSGetLpList', // method name
array('params' => 'tns:paramsGetLpList'), // input parameters
array('return' => 'tns:lpList'), // output parameters
'urn:WSLP', // namespace
'urn:WSLP#WSGetLpList', // soapaction
'rpc', // style
'encoded', // use
'This service adds users' // documentation
);
/**
* @param array $params
* @return int|string
*/
function WSGetLpList($params)
{
global $debug;
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
$courseIdName = $params['course_id_name'];
$courseIdValue = $params['course_id_value'];
$sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
$sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
$courseCode = CourseManager::get_course_id_from_original_id(
$courseIdValue,
$courseIdName
);
$courseInfo = api_get_course_info($courseCode);
//$courseId = $courseInfo['real_id'];
if (empty($courseInfo)) {
if ($debug) error_log("Course not found: $courseIdName : $courseIdValue");
return 'Course not found';
}
$sessionId = 0;
if (!empty($sessionIdName) && !empty($sessionIdValue)) {
$sessionId = SessionManager::get_session_id_from_original_id(
$sessionIdValue,
$sessionIdName
);
if (empty($sessionId)) {
if ($debug) error_log('Session not found');
return 'Session not found';
}
}
$list = new LearnpathList(null, $courseInfo['code'], $sessionId);
$flatList = $list->get_flat_list();
$result = array();
foreach ($flatList as $id => $lp) {
$result[] = array(
'id' => $id,
'name' => $lp['lp_name']
);
}
return $result;
}
$server->wsdl->addComplexType(
'paramsDeleteLp',
'complexType',
'struct',
'all',
'',
array(
'course_id_name' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'course_id_value' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'lp_id' => array(
'name' => 'lp_id',
'type' => 'xsd:string',
),
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
)
);
// Register the method to expose
$server->register('WSDeleteLp', // method name
array('params' => 'tns:paramsDeleteLp'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:WSLP', // namespace
'urn:WSLP#WSDeleteLp', // soapaction
'rpc', // style
'encoded', // use
'This service deletes a LP' // documentation
);
/**
* @param array $params
* @return int|string
*/
function WSDeleteLp($params)
{
global $debug;
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
$courseIdName = $params['course_id_name'];
$courseIdValue = $params['course_id_value'];
$lpId = $params['lp_id'];
$sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
$sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
$courseCode = CourseManager::get_course_id_from_original_id(
$courseIdValue,
$courseIdName
);
$courseInfo = api_get_course_info($courseCode);
//$courseId = $courseInfo['real_id'];
if (empty($courseInfo)) {
if ($debug) error_log("Course not found: $courseIdName : $courseIdValue");
return 'Course not found';
}
/*$sessionId = 0;
if (!empty($sessionIdName) && !empty($sessionIdValue)) {
$sessionId = SessionManager::get_session_id_from_original_id(
$sessionIdValue,
$sessionIdName
);
if (empty($sessionId)) {
if ($debug) error_log('Session not found');
return 'Session not found';
}
}
*/
$lp = new learnpath($courseInfo['code'], $lpId, null);
if ($lp) {
if ($debug) error_log("LP deleted $lpId");
$lp->delete($courseInfo, $lpId, 'remove');
return 1;
}
return 0;
}
$server->wsdl->addComplexType(
'lpItem',
'complexType',
'struct',
'all',
'',
array(
'data' => array('name' => 'data', 'type' => 'xsd:string'),
'title' => array('name' => 'title', 'type' => 'xsd:string'),
'filename' => array('name' => 'filename', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType(
'lpItemList',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:lpItem[]')),
'tns:lpItemList'
);
$server->wsdl->addComplexType(
'paramsCreateLp',
'complexType',
'struct',
'all',
'',
array(
'course_id_name' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
'course_id_value' => array(
'name' => 'course_id_name',
'type' => 'xsd:string',
),
/*'session_id_name' => array(
'name' => 'session_id_name',
'type' => 'xsd:string',
),
'session_id_value' => array(
'name' => 'session_id_value',
'type' => 'xsd:string',
),*/
'lp_name' => array(
'name' => 'lp_name',
'type' => 'xsd:string',
),
'lp_item_list' => array(
'name' => 'lp_item_list',
'type' => 'tns:lpItemList',
),
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
)
);
// Register the method to expose
$server->register('WSCreateLp', // method name
array('params' => 'tns:paramsCreateLp'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:WSLP', // namespace
'urn:WSLP#WSCreateLp', // soapaction
'rpc', // style
'encoded', // use
'This service creates a LP' // documentation
);
/**
* @param array $params
* @return null|soap_fault
*/
function WSCreateLp($params)
{
global $debug;
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
if ($debug) {
error_log('WSCreateLp');
}
$courseIdName = $params['course_id_name'];
$courseIdValue = $params['course_id_value'];
$lpName = $params['lp_name'];
$lpItemList = $params['lp_item_list'];
/*$sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
$sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;*/
$courseCode = CourseManager::get_course_id_from_original_id(
$courseIdValue,
$courseIdName
);
$courseInfo = api_get_course_info($courseCode);
$courseId = $courseInfo['real_id'];
if (empty($courseInfo)) {
if ($debug) {
error_log('Course not found');
}
}
/*$sessionId = 0;
if (!empty($sessionIdName) && !empty($sessionIdValue)) {
$sessionId = SessionManager::get_session_id_from_original_id(
$sessionIdValue,
$sessionIdName
);
if (empty($sessionId)) {
if ($debug) {
error_log('Session not found');
}
return 'Session not found';
}
}*/
$lpId = learnpath::add_lp($courseCode, $lpName, '', 'chamilo', 'manual');
if ($lpId) {
if ($debug) {
error_log('LP created');
}
$lp = new learnpath($courseCode, $lpId, null);
$previousId = 0;
foreach ($lpItemList as $lpItem) {
$info = pathinfo($lpItem['filename']);
$extension = $info['extension'];
$data = base64_decode($lpItem['data']);
$documentId = $lp->create_document(
$courseInfo,
$data,
$info['filename'],
$extension
);
if ($documentId) {
if ($debug) {
error_log("Document created $documentId");
$itemId = $lp->add_item(
null,
$previousId,
'document',
$documentId,
$lpItem['title'],
'',
''
);
$previousId = $itemId;
if ($itemId) {
if ($debug) {
error_log("Item added");
}
} else {
if ($debug) {
error_log("Item not added");
}
}
}
} else {
if ($debug) {
error_log("Document NOT created");
}
}
}
return 1;
} else {
if ($debug) {
error_log('LP not created');
}
}
return 0;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
// If you send your data in utf8 then this value must be false.
if (isset($_configuration['registration.soap.php.decode_utf8'])) {
if ($_configuration['registration.soap.php.decode_utf8']) {
$server->decode_utf8 = true;
} else {
$server->decode_utf8 = false;
}
}
$server->service($HTTP_RAW_POST_DATA);
Loading…
Cancel
Save