Removing old code scorm.lib.php, scorm_admin.php see #4716

skala
Julio Montoya 13 years ago
parent f088d75e21
commit f55d0cb514
  1. 132
      main/newscorm/learnpath_functions.inc.php
  2. 1
      main/newscorm/lp_impress.php
  3. 1
      main/newscorm/lp_view.php
  4. 5
      main/newscorm/lp_view_item.php
  5. 156
      main/newscorm/scorm.lib.php
  6. 328
      main/newscorm/scorm_admin.php
  7. 38
      tests/main/newscorm/scorm.lib.test.php
  8. 70
      tests/main/scorm/scorm.lib.test.php

@ -1854,138 +1854,6 @@ function deldir($dir) {
return false;
}
/**
* This functions exports the given path. This is the opener function, which is called first
* @deprecated this function is only called in the newscorm/scorm_admin.php which is deprecated
* @param integer The path id
* @return resource A zip file, containing a hopefully Scorm compliant course made from the LP. This might happen when we don't actually exit the function first :-)
*/
function exportpath($learnpath_id) {
// 1. Initialise variables.
global $_course, $circle1_files, $LPnamesafe, $LPname, $expdir;
$course_id = api_get_course_int_id();
//$tbl_learnpath_main, $tbl_learnpath_chapter, $tbl_learnpath_item,
$tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN);
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
// Where applicable, add a scorm "Done" button at the end of all contents.
$add_scorm_button = true;
// 2. Get the name of the LP.
include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$sql = "SELECT * FROM $tbl_learnpath_main WHERE c_id = $course_id AND (lp_id=$learnpath_id)";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$LPname = $row['learnpath_name'];
$LPnamesafe = replace_dangerous_char($LPname, 'strict');
// 3. Get a temporary dir for creating the zip file.
$expdir = api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe;
$fromdir = '../scorm/export/'; //this dir contains some standard files
deldir($expdir); // Make sure the temp dir is cleared.
mkdir($expdir, api_get_permissions_for_new_directories());
mkdir($expdir.'/css', api_get_permissions_for_new_directories());
mkdir($expdir.'/data', api_get_permissions_for_new_directories());
mkdir($expdir.'/js', api_get_permissions_for_new_directories());
mkdir($expdir.'/data/images', api_get_permissions_for_new_directories());
mkdir($expdir.'/data/audio', api_get_permissions_for_new_directories());
mkdir($expdir.'/data/videos', api_get_permissions_for_new_directories());
$circle1 = array( // This array contains the types of elements we want to export.
'Chapter', 'Agenda', 'Ad_Valvas', 'Course_description', 'Document', 'Introduction_text', 'Link _self', 'Link _blank', 'Forum', 'Thread', 'Post', 'Exercise', 'HotPotatoes', 'Assignments', 'Dropbox', 'Users', 'Groups');
//$circle2 = array('');
// 4. Get the first level chapters - YW added parent_item_id condition for multi-level paths.
$sql = "SELECT * FROM $tbl_learnpath_chapter
WHERE c_id = $course_id AND (lp_id=$learnpath_id and parent_item_id=0)
ORDER BY display_order ASC";
// To get all the elements, we should use the function that builds the table of content get_learnpath_tree.
//WHERE (lp_id=$learnpath_id)
//ORDER BY parent_item_id, display_order ASC";
$result = Database::query($sql);
// 5. export the items listed in Circle I one by one.
while ($row = Database::fetch_array($result)) {
// 5.1. Get items data from the database for this chapter.
$parent_item_id = $row['id'];
//$sql2a = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id and parent_item_id=$parent_item_id) ORDER BY display_order ASC";
//$result2a = Database::query($sql);
$sql2b = "SELECT * FROM $tbl_learnpath_item WHERE c_id = $course_id AND (parent_item_id=$parent_item_id) ORDER BY display_order ASC";
$result2b = Database::query($sql2b);
while ($row2 = Database::fetch_array($result2b)) {
// 5.1.1 Check if the element is in the circle1 array.
$tobeexported = false;
for ($i = 0; $i < count($circle1) && !$tobeexported; $i ++) {
// If the type is found in the circle1 array, ask for export.
if ($circle1[$i] == $row2['item_type']) {
$tobeexported = true;
}
}
// 5.1.2 If applicable, export the item to an HTML file (see exportitem function for more details).
if ($tobeexported) {
exportitem($row2['id'], $row2['item_id'], $row2['item_type'], $add_scorm_button);
/*if ($row2['description']) { // Put the description of items to a separate file (.desc).
exportdescription($row2['id'], $row2['item_type'], $row2['description']);
}*/
}
} //end of items loop
} //end of first-level chapters loop
// 6. Export the other necceassary files.
$filename = 'default.css';
copy('../css/'.$filename, $expdir.'/css/'.$filename);
$filename = 'ims_xml.xsd';
copy($fromdir.$filename, $expdir.'/'.$filename);
$filename = 'imscp_v1p1.xsd';
copy($fromdir.$filename, $expdir.'/'.$filename);
$filename = 'imsmd_v1p2.xsd';
copy($fromdir.$filename, $expdir.'/'.$filename);
$filename = 'APIWrapper.js';
copy($fromdir.$filename, $expdir.'/js/'.$filename);
$filename = 'SCOFunctions.js';
copy($fromdir.$filename, $expdir.'/js/'.$filename);
// In case circle1_files is not defined, build it
//$circle1_files
// 7. Create imsmanifest.xml.
createimsmanifest($circle1_files, $learnpath_id);
// 8. Put the files in the exportdir into a zip and force download.
include_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
// Create zipfile of given directory.
$zip_folder = new PclZip(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe.".zip");
$zip_folder->create(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe."/", PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/");
//api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe); // whitout folder
// Modified by imandak80
/* copy(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe.".zip",
api_get_path(SYS_COURSE_PATH).$_course['path']."/document/".$LPnamesafe.".zip");
*/
$zipfoldername = api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe;
$zipfilename = $zipfoldername.".zip";
DocumentManager :: file_send_for_download($zipfilename, false, basename($LPnamesafe.".zip"));
// 9. Delete the temporary zip file and directory.
include_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
// in fileManage.lib.php
my_delete($zipfilename);
my_delete($zipfoldername);
//exit;
// 10. Return the circle_files hash (array).
return ($circle1_files); //has been used before...
}
/**
* Export SCORM content into a zip file
*

@ -16,7 +16,6 @@ $this_section = SECTION_COURSES;
/* Libraries */
require_once 'back_compat.inc.php';
require_once 'scorm.lib.php';
require_once 'learnpath.class.php';
require_once 'learnpathItem.class.php';

@ -27,7 +27,6 @@ if ($lp_controller_touched != 1) {
/* Libraries */
require_once 'back_compat.inc.php';
require_once 'scorm.lib.php';
require_once 'learnpath.class.php';
require_once 'learnpathItem.class.php';

@ -19,15 +19,10 @@
// libraries are included by default.
require_once 'back_compat.inc.php';
require_once 'scorm.lib.php';
require_once 'learnpath.class.php';
require_once 'learnpathItem.class.php';
require_once 'learnpath_functions.inc.php';
//include '../resourcelinker/resourcelinker.inc.php';
require_once 'resourcelinker.inc.php';
//rewrite the language file, sadly overwritten by resourcelinker.inc.php
// name of the language file that needs to be included
// Including the global initialization file.
require_once '../inc/global.inc.php';

@ -1,156 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
// TODO: Migrate this into the scorm.class.php file.
/**
* This file is a container for functions related to SCORM and other
* standard or common course content types. It might later become a class
* instead of a functions library, as several components are likely to be
* re-used for different content types.
* @package chamilo.learnpath.scorm
* @author Yannick Warnier <ywarnier@beeznest.org>
* @author Based on work from Denes NAgy, Isthvan Mandak and Roan Embrechts
*/
/**
* Delete a scorm directory (check for imsmanifest and if found, deletes the related rows in scorm tables also)
* @param string Dir path
* @return boolean True on success, false otherwise
*/
/*
function removescormDir($dir) {
global $_course;
if(!@$opendir = opendir($dir)) {
return false;
}
while($readdir = readdir($opendir)) {
if($readdir != '..' && $readdir != '.') {
if(is_file($dir.'/'.$readdir)) {
$pos = strpos('/'.$readdir, 'imsmanifest.xml');
if ($pos) { // So we have the imsmanifest in this dir
// from d:/myworks/dokeos/dokeos_cvs/dokeos/dokeos/courses/CVSCODE4/scorm/LP2/LP2
// We have to get /LP2/LP2
$path = api_get_path(SYS_COURSE_PATH).$_course['official_code'].'/scorm';
$pos = strpos($dir, $path);
if ($pos == 0) {
$scormdir = substr($dir, strlen($path), strlen($dir) - strlen($path));
$courseid = $_course['official_code'];
$sql = "SELECT * FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
$c = $row['contentId'];
$sql2 = "DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_SCO_DATA)." where contentId=$c";
$result2 = Database::query($sql2);
}
$sql = "DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
$result = Database::query($sql);
}
}
if (!@unlink($dir.'/'.$readdir)) {
return false;
}
} elseif (is_dir($dir.'/'.$readdir)) {
if(!removescormDir($dir.'/'.$readdir)) {
return false;
}
}
}
}
closedir($opendir);
if (!@rmdir($dir)) {
return false;
}
return true;
}*/
/**
* This function removes a directory if it exists
* @param string Dir path
* @return boolean True on success, false otherwise
* @deprecated
* @uses removescormDir() to actually remove the directory
*/
function scorm_delete($file) {
if (check_name_exist($file)) {
if (is_dir($file)) {
return removescormDir($file);
}
} else {
return false; // No file or directory to delete.
}
}
/**
* This function gets a list of scorm paths located in a given directory
* @param string Base directory path
* @param string Current directory
* @param array Reference to a list of paths that exist in the database
* @return array Array(type=>array(),size=>array(),date=>array())
*/
function get_scorm_paths_from_dir($basedir, $curdir, &$attribute){
$scormcontent = false;
$saved_dir = getcwd();
$res = @chdir (realpath($basedir.$curdir));
if ($res === false) { return(null); }
$handle = opendir('.');
define('A_DIRECTORY', 1);
define('A_FILE', 2);
$fileList = array();
// Fill up $fileList for displaying the files list later on.
while ($file = readdir($handle)) {
if ($file == '.' || $file == '..' || $file == '.htaccess') {
continue; // Skip current and parent directories
}
$fileList['name'][] = $file;
//if ($file=='imsmanifest.xml') { $scormcontent=true; }
if(is_dir($file)) {
$fileList['type'][] = A_DIRECTORY;
$fileList['size'][] = false;
$fileList['date'][] = false;
} elseif (is_file($file)) {
$fileList['type'][] = A_FILE;
$fileList['size'][] = filesize($file);
$fileList['date'][] = filectime($file);
}
/*
* Make the correspondance between
* info given by the file system
* and info given by the DB
*/
if (is_array($attribute) && count($attribute['path']) > 0) {
$keyAttribute = array_search($curdir.'/'.$file, $attribute['path']);
}
if ($keyAttribute !== false) {
$fileList['comment' ][] = $attribute['comment' ][$keyAttribute];
$fileList['visibility'][] = $attribute['visibility'][$keyAttribute];
unset ($attribute['comment' ][$keyAttribute],
$attribute['visibility'][$keyAttribute],
$attribute['path' ][$keyAttribute]);
} else {
$fileList['comment' ][] = false;
$fileList['visibility'][] = false;
}
}
closedir($handle);
chdir($saved_dir);
return $fileList;
}
/**
* Detects the SCORM version from an imsmanifest.xml file
* @param string Path to imsmanifest.xml
* @return string SCORM version (1.0,1.1,1.2,1.3)
* @todo Implement this function
*/
function get_scorm_version($path){
return '1.2';
}

@ -1,328 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
// This file is probably deprecated - 2009-05-14 - ywarnier
// No calls found in Chamilo file is deprecated. Adding an exit - 2011-06 jmontoya
/**
* This script handles SCO administration features
* @package chamilo.learnpath.scorm
* @author Denes Nagy, principal author
* @author Isthvan Mandak, several new features
* @author Roan Embrechts, code improvements and refactoring
* @author Yannick Warnier, complete refactoring <ywarnier@beeznest.org>
*/
/**
* Code (exit)
*/
exit;
// Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true;
// Name of the language file that needs to be included.
$language_file = 'scormdocument';
$uncompress = 1; // TODO: This variable shouldn't be found here (find its usage before removal).
require_once 'back_compat.inc.php';
include 'learnpath_functions.inc.php';
include_once 'scorm.lib.php';
$is_allowedToEdit = api_is_allowed_to_edit();
/* Variables */
// Escapable integers.
if ($_REQUEST['id'] != strval(intval($_REQUEST['id']))) { $id = $_REQUEST['id']; } else { $id = null; }
// Imported strings.
$path = (!empty($_REQUEST['path']) ? $_REQUEST['path'] : null);
$Submit = (!empty($_POST['Submit']) ? $_POST['Submit'] : null);
$submitImage = (!empty($_POST['submitImage']) ? $_POST['submitImage'] : null);
$cancelSubmitImage = (!empty($_POST['cancelSubmitImage']) ? $_POST['cancelSubmitImage'] : null);
$action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : null);
$delete = (!empty($_REQUEST['delete']) ? $_REQUEST['delete'] : null);
$createDir = (!empty($_REQUEST['createDir']) ? $_REQUEST['createDir'] : null);
$make_directory_visible = (!empty($_REQUEST['make_directory_visible']) ? $_REQUEST['make_directory_visible'] : '');
$make_directory_invisible = (!empty($_REQUEST['make_directory_invisible']) ? $_REQUEST['make_directory_invisible'] : '');
// Values from POST form to add directory.
$newDirPath = (!empty($_POST['newDirPath']) ? $_POST['newDirPath'] : null);
$newDirName = (!empty($_POST['newDirName']) ? $_POST['newDirName'] : null);
// Initialising internal variables.
$dialogbox = '';
$course_id = api_get_course_int_id();
api_protect_course_script();
//if (! $is_allowed_in_course) api_not_allowed();
$is_allowedToUnzip = $is_courseAdmin;
/* Main code */
switch ($action) {
case 'exportpath':
if (!empty($id)) {
$export = exportpath($id);
$dialogBox .= "This LP has been exported to the Document folder "
."of your course.";
}
break;
case 'exportscorm':
exportSCORM($path);
break;
case 'deletepath':
/*
DELETE A DOKEOS LEARNPATH
and all the items in it
*/
if (!empty($id)){
$l="learnpath/learnpath_handler.php?learnpath_id=$id";
$sql="DELETE FROM $tbl_tool where (link='$l' AND image='scormbuilder.gif')";
$result=Database::query($sql);
$sql="SELECT * FROM $tbl_learnpath_chapter where learnpath_id=$id";
$result=Database::query($sql);
while ($row=Database::fetch_array($result))
{
$c=$row['id'];
$sql2="DELETE FROM $tbl_learnpath_item where chapter_id=$c";
$result2=Database::query($sql2);
}
$sql="DELETE FROM $tbl_learnpath_chapter where learnpath_id=$id";
$result=Database::query($sql);
deletepath($id);
$dialogBox=get_lang('_learnpath_deleted');
}
break;
case 'publishpath':
/* PUBLISHING (SHOWING) A DOKEOS LEARNPATH */
if (!empty($id)){
$sql = "SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$name = domesticate($row['learnpath_name']);
if ($set_visibility == 'i') {
$s = $name.' '.get_lang('_no_published');
$dialogBox = $s;
$v = 0;
}
if ($set_visibility == 'v') {
$s=$name.' '.get_lang('_published');
$dialogBox = $s;
$v = 1;
}
$sql = "SELECT * FROM $tbl_tool where (name='$name' and image='scormbuilder.gif')";
$result = Database::query($sql);
$row2 = Database::fetch_array($result);
$num = Database::num_rows($result);
if (($set_visibility == 'i') && ($num > 0)) {
// It is visible or hidden but once was published.
if (($row2['visibility']) == 1) {
$sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' AND c_id = $course_id )";
} else {
$sql = "UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif' AND c_id = $course_id)";
}
} elseif (($set_visibility == 'v') && ($num == 0)) {
$sql ="INSERT INTO $tbl_tool (c_id, id, name, link, image, visibility, admin, address, added_tool) VALUES
($course_id, '$theid','$name','learnpath/learnpath_handler.php?learnpath_id=$id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
} else {
// Parameter and database incompatible, do nothing.
}
$result = Database::query($sql);
}
break;
case 'editpath':
/* EDITING A DOKEOS NEW LEARNPATH */
if (!empty($Submit)) {
$l = "learnpath/learnpath_handler.php?learnpath_id=$id";
$sql = "UPDATE $tbl_tool set name='".domesticate($learnpath_name)."' where (link='$l' and image='scormbuilder.gif')";
$result = Database::query($sql);
$sql = "UPDATE $tbl_learnpath_main SET learnpath_name='".domesticate($learnpath_name)."', learnpath_description='".domesticate($learnpath_description)."' WHERE learnpath_id=$id";
$result = Database::query($sql);
$dialogBox = get_lang('_learnpath_edited');
}
break;
case 'add':
/* ADDING A NEW LEARNPATH : treating the form */
if (!empty($Submit)) {
$sql = "INSERT INTO $tbl_learnpath_main (c_id, learnpath_name, learnpath_description) VALUES ($course_id , '".domesticate($learnpath_name)."','".domesticate($learnpath_description)."')";
Database::query($sql);
$my_lp_id = Database::insert_id();
$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool) VALUES ($course_id , '".domesticate($learnpath_name)."','learnpath/learnpath_handler.php?learnpath_id=$my_lp_id','scormbuilder.gif','1','0','pastillegris.gif',0)";
Database::query($sql);
// Instead of displaying this info text, get the user directly to the learnpath edit page.
//$dialogBox = get_lang('_learnpath_added');
header('location:../learnpath/learnpath_handler.php?'.api_get_cidreq().'&learnpath_id='.$my_lp_id);
exit();
}
break;
case 'editscorm':
/* EDITING A SCORM PACKAGE */
if (!empty($Submit)) {
$sql = "UPDATE $tbl_document SET comment='".domesticate($learnpath_description)."', name='".domesticate($learnpath_name)."' WHERE path='$path' AND c_id = $course_id ";
$result = Database::query($sql);
$dialogBox = get_lang('_learnpath_edited');
}
break;
default:
break;
}
if ($is_allowedToEdit) { // TEACHER ONLY
/* UPLOAD SCORM */
/*
* Check the request method instead of a variable from POST
* because if the file size exceeds the maximum file upload
* size set in php.ini, all variables from POST are cleared !
*/
if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && empty($submitImage) && empty($cancelSubmitImage) && empty($action)) {
// A SCORM upload has been detected, now deal with the file...
// Directory creation.
$s = $_FILES['userFile']['name'];
$pathInfo = pathinfo($s);
// Check the filename has at least several letters in it :-)
// This is a very loose check as later on we might accept other formats of packages.
// Sent than just "zip".
if (preg_match('/[\w-_]+/', $pathInfo['basename'])) {
// get the basename without extension.
$newDirName = substr($pathInfo['basename'], 0, strlen($pathInfo['basename']) - (strlen($pathInfo['extension']) + 1));
$newDirName = replace_dangerous_char(trim($newDirName), 'strict');
if (check_name_exist($baseWorkDir.$newDirPath.$openDir.'/'.$newDirName)) {
/** @todo change this output. Inaccurate at least in french. In this case, the
* file might not exist or the transfer might have been wrong (no $_FILES at all)
* but we still get the error message
*/
$dialogBox = get_lang('FileExists');
$createDir = $newDirPath; unset($newDirPath); // Return to step 1.
} else {
if (mkdir($baseWorkDir.$newDirPath.$openDir.'/'.$newDirName, api_get_permissions_for_new_directories())) {
FileManager::set_default_settings($newDirPath.$openDir, $newDirName, 'folder', $tbl_document);
// RH: was: set_default_settings($newDirPath.$openDir, $newDirName, 'folder');
$dialogBox = get_lang('DirCr');
} else {
//Display msg "could not create dir..."
//exit();
}
// Directory creation end.
$uploadPath = $openDir.'/'.$newDirName;
if (!$_FILES['userFile']['size']) {
$dialogBox .= get_lang('FileError').'<br />'.get_lang('Notice').' : '.get_lang('MaxFileSize').' '.ini_get('upload_max_filesize');
} else { // The file size is alright, we can assume the file is OK too.
if ($uncompress == 1 && $is_allowedToUnzip) {
$unzip = 'unzip';
} else {
$unzip = '';
}
if (treat_uploaded_file($_FILES['userFile'], $baseWorkDir, $uploadPath, $maxFilledSpace, $unzip)) {
if ($uncompress == 1) {
//$dialogBox .= get_lang('DownloadAndZipEnd');
// Modified by darkden : I omitted this part, so the user can see
// the scorm content message at once.
} else {
$dialogBox = get_lang('DownloadEnd');
}
// "WHAT'S NEW" notification: update table last_tooledit.
//update_last_tooledit($_course, $nameTools, $id, get_lang('_new_document'), $_user['user_id']);
item_property_update($_course, TOOL_LEARNPATH, $id, "LearnpathAdded", $_user['user_id']);
} else {
if (api_failure::get_last_failure() == 'not_enough_space') {
$dialogBox = get_lang('NoSpace');
} elseif (api_failure::get_last_failure() == 'php_file_in_zip_file') {
$dialogBox = get_lang('ZipNoPhp');
} elseif (api_failure::get_last_failure() == 'not_scorm_content') {
$dialogBox = get_lang('NotScormContent');
}
}
}
$uploadPath = '';
if (api_failure::get_last_failure()) {
rmdir($baseWorkDir.$newDirPath.$openDir.'/'.$newDirName);
}
}
} else { // The filename doesn't contain any alphanum chars (empty filename?)
// Get a more detailed message?
$dialogBox .= get_lang('FileError').'<br />';
}
/* DELETE FILE OR DIRECTORY */
if (isset($delete)) {
if ( scorm_delete($baseWorkDir.$delete)) {
//$tbl_document = substr($tbl_document, 1, strlen($tbl_document) - 2); // RH...
update_db_info('delete', $delete);
$dialogBox = get_lang('DocDeleted');
}
}
/* CREATE DIRECTORY */
/*
* The code begin with STEP 2 so it allows to return to STEP 1 if STEP 2 unsucceds.
*/
/* STEP 2 */
if (isset($newDirPath) && isset($newDirName)) {
// echo $newDirPath . $newDirName;
$newDirName = replace_dangerous_char(trim(stripslashes($newDirName)), 'strict');
if (check_name_exist($baseWorkDir.$newDirPath.'/'.$newDirName)) {
$dialogBox = get_lang('FileExists');
$createDir = $newDirPath; unset($newDirPath);// return to step 1
} else {
if (mkdir($baseWorkDir.$newDirPath.'/'.$newDirName, api_get_permissions_for_new_directories()))
FileManager::set_default_settings($newDirPath, $newDirName, 'folder', $tbl_document);
// RH: was: set_default_settings($newDirPath, $newDirName, 'folder');
$dialogBox = get_lang('DirCr');
}
}
/* STEP 1 */
if (isset($createDir)) {
$dialogBox .= "<!-- create dir -->\n"
."<form name='createdir' action='' method='POST'>\n"
."<input type=\"hidden\" name=\"newDirPath\" value=\"$createDir\" />\n"
.get_lang('NameDir')." : \n"
."<input type=\"text\" name=\"newDirName\" />\n"
."<input type=\"submit\" value=\"".get_lang('Ok')."\" />\n"
."</form>\n";
}
/* VISIBILITY COMMANDS */
if (!empty($make_directory_visible) || !empty($make_directory_invisible)) {
$visibilityPath = $make_directory_visible.$make_directory_invisible;
// At least one of these variables are empty. So it's okay to proceed this way
/* Check if there is yet a record for this file in the DB */
$result = Database::query ("SELECT * FROM $tbl_document WHERE path LIKE '".$visibilityPath."' ");
while($row = Database::fetch_array($result, 'ASSOC')) {
$attribute['path' ] = $row['path' ];
$attribute['visibility'] = $row['visibility'];
$attribute['comment' ] = $row['comment' ];
}
if ($make_directory_visible) {
$newVisibilityStatus = 'v';
} elseif ($make_directory_invisible) {
$newVisibilityStatus = 'i';
}
$query = "UPDATE $tbl_document SET visibility='$newVisibilityStatus' WHERE path=\"".$visibilityPath."\" AND c_id = $course_id "; // Added by Toon.
Database::query($query);
if (Database::affected_rows() == 0) { // Extra check added by Toon, normally not necessary anymore because all files are in the db.
Database::query("INSERT INTO $tbl_document SET
c_id = $course_id,
path=\"".$visibilityPath."\",
visibility=\"".$newVisibilityStatus."\"");
}
unset($attribute);
$dialogBox = get_lang('ViMod');
}
} // END is Allowed to edit;.
}

@ -1,38 +0,0 @@
<?php
require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.lib.php';
class TestScormLib extends UnitTestCase {
public function __construct() {
$this->UnitTestCase('SCORM library - main/newscorm/scorm.lib.test.php');
}
/**
* This public function gets a list of scorm paths located in a given directory
* @param string Base directory path
* @param string Current directory
* @param array Reference to a list of paths that exist in the database
* @return array Array(type=>array(),size=>array(),date=>array())
*/
public function testget_scorm_paths_from_dir() {
$basedir='';
$curdir='';
$attribute=array('abc');
$res=get_scorm_paths_from_dir($basedir, $curdir, &$attribute);
$this->assertTrue(is_array($res));
}
/**
* Detects the SCORM version from an imsmanifest.xml file
* @param string Path to imsmanifest.xml
* @return string SCORM version (1.0,1.1,1.2,1.3)
* @todo Implement this public function
*/
public function testget_scorm_version() {
$path_name = api_get_path(SYS_COURSE_PATH);
$path=$path_name.'scorm/';
$res=get_scorm_version($path);
$this->assertTrue(is_string($res));
//var_dump($res);
}
}

@ -1,70 +0,0 @@
<?php
require_once(api_get_path(SYS_CODE_PATH).'newscorm/scorm.lib.php');
class TestScorm extends UnitTestCase {
/**
* This function gets a list of scorm paths located in a given directory
* @param string Base directory path
* @param string Current directory
* @param array Reference to a list of paths that exist in the database
* @return array Array(type=>array(),size=>array(),date=>array())
*/
function testget_scorm_paths_from_dir(){
$basedir='';
$curdir='';
$attribute=array('abc');
$res=get_scorm_paths_from_dir($basedir, $curdir, &$attribute);
$this->assertTrue(is_array($res));
//var_dump($res);
}
/**
* Detects the SCORM version from an imsmanifest.xml file
* @param string Path to imsmanifest.xml
* @return string SCORM version (1.0,1.1,1.2,1.3)
* @todo Implement this function
*/
function testget_scorm_version(){
$path='/main/erxercice/';
$res=get_scorm_version($path);
$this->assertTrue(is_string($res));
//var_dump($res);
}
/**
* Delete a scorm directory (check for imsmanifest and if found, deletes the related rows in scorm tables also)
* @param string Dir path
* @return boolean True on success, false otherwise
*/
function testremovescormDirFalse() {
global $_course;
$dir='/main/exercice';
$res=removescormDir($dir);
$this->assertFalse($res);
//var_dump($res);
}
function testremovescormDirTrue() {
global $_course;
$dir=api_get_path(SYS_CODE_PATH).'upload/users/';
$res=removescormDir($dir);
$this->assertTrue(is_bool($res));
//var_dump($res);
}
/**
* This function removes a directory if it exists
* @param string Dir path
* @return boolean True on success, false otherwise
* @uses removescormDir() to actually remove the directory
*/
function testscorm_delete() {
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
$file='/tmp/';
$res=scorm_delete($file);
$this->assertTrue(is_bool($res));
//var_dump($res);
}
}
?>
Loading…
Cancel
Save