@ -24,8 +24,6 @@
* @todo remove code duplication
*/
use ChamiloSession as Session;
/**
* This function returns false if there is at least one item in the path
* @param Learnpath ID
@ -58,179 +56,6 @@ function is_empty($id) {
return ($empty);
}
/**
* This function writes $content to $filename
* @param string Destination filename
* @param string Learnpath name
* @param integer Learnpath ID
* @param string Content to write
* @return void
*/
function exporttofile($filename, $LPname, $LPid, $content) {
global $circle1_files; // This keeps all the files which are exported [0]:filename [1]:LP name.
// The $circle1_files variable is going to be used to a deep extent in the imsmanifest.xml.
global $expdir;
if (!$handle = fopen($expdir.'/'.$filename, 'w')) {
echo "Cannot open file ($filename)";
}
if (fwrite($handle, $content) === false) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
$circle1_files[0][] = $filename;
$circle1_files[1][] = $LPname;
$circle1_files[2][] = $LPid;
}
/**
* This function exports the given Chamilo test
* @param integer Test ID
* @return string The test itself as an HTML string
*/
function export_exercise($item_id) {
global $expdir, $_course, $_configuration, $_SESSION, $_SERVER, $language_interface, $langExerciseNotFound, $langQuestion, $langOk, $origin, $questionNum;
$exerciseId = $item_id;
$TBL_EXERCISES = Database :: get_course_table(TABLE_QUIZ_TEST);
/* Clears the exercise session */
if (isset ($_SESSION['objExercise'])) {
Session::erase('objExercise');
}
if (isset ($_SESSION['objQuestion'])) {
Session::erase('objQuestion');
}
if (isset ($_SESSION['objAnswer'])) {
Session::erase('objAnswer');
}
if (isset ($_SESSION['questionList'])) {
Session::erase('questionList');
}
if (isset ($_SESSION['exerciseResult'])) {
Session::erase('exerciseResult');
}
// If the object is not in the session:
if (!isset ($_SESSION['objExercise'])) {
// Construction of Exercise.
$objExercise = new Exercise();
$sql = "SELECT title,description,sound,type,random,active FROM $TBL_EXERCISES WHERE id='$exerciseId'";
// If the specified exercise doesn't exist or is disabled:
if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() & & !api_is_allowed_to_edit() & & ($origin != 'learnpath'))) {
die($langExerciseNotFound);
}
// Saves the object into the session.
Session::write('objExercise',$objExercise);
}
$exerciseTitle = $objExercise->selectTitle();
$exerciseDescription = $objExercise->selectDescription();
$exerciseSound = $objExercise->selectSound();
$randomQuestions = $objExercise->isRandom();
$exerciseType = $objExercise->selectType();
if (!isset ($_SESSION['questionList'])) {
// Selects the list of question ID.
$questionList = $randomQuestions ? $objExercise->selectRandomList() : $objExercise->selectQuestionList();
// Saves the question list into the session.
Session::write('questionList',$questionList);
}
$nbrQuestions = sizeof($questionList);
// If questionNum comes from POST and not from GET:
if (!$questionNum || $_POST['questionNum']) {
// Only used for sequential exercises (see $exerciseType).
if (!$questionNum) {
$questionNum = 1;
} else {
$questionNum ++;
}
}
$exerciseTitle = text_filter($exerciseTitle);
$test .= "< h3 > ".$exerciseTitle."< / h3 > ";
if (!empty ($exerciseSound)) {
$test .= "< a href = \"../document/download.php?doc_url=%2Faudio%2F".$exerciseSound."\"&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9 target = \"_blank\" > < img src = \"../img/sound.gif\" border = \"0\" align = \"absmiddle\" alt = ".get_lang(" Sound " ) . " \ " / > < / a > ";
}
$exerciseDescription = text_filter($exerciseDescription);
// Writing the .js file with to check the correct answers begin.
$scriptfilename = "Exercice".$item_id.".js";
$s = "< script type = \"text/javascript\" src = '../js/".$scriptfilename."' > < / script > ";
$test .= $s;
$content = "function evaluate() {
alert('Test evaluated.');
}
";
if (!$handle = fopen($expdir.'/js/'.$scriptfilename, 'w')) {
echo "Cannot open file ($scriptfilename)";
}
if (fwrite($handle, $content) === false) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
// Writing the .js file with to check the correct answers end.
$s = "
< p > $exerciseDescription< / p >
< table width = '100%' border = '0' cellpadding = '1' cellspacing = '0' >
< form method = 'post' action = '' > < input type = \"hidden\" name = \"SQMSESSID\" value = \"36812c2dea7d8d6e708d5e6a2f09b0b9\" / >
< input type = 'hidden' name = 'formSent' value = '1' / >
< input type = 'hidden' name = 'exerciseType' value = '".$exerciseType."' / >
< input type = 'hidden' name = 'questionNum' value = '".$questionNum."' / >
< input type = 'hidden' name = 'nbrQuestions' value = '".$nbrQuestions."' / >
< tr >
< td >
< table width = '100%' cellpadding = '4' cellspacing = '2' border = '0' > ";
$test .= $s;
$i = 0;
foreach ($questionList as $questionId) {
$i ++;
echo $s = "< tr bgcolor = '#e6e6e6' > < td valign = 'top' colspan = '2' > ".get_lang('Question')." ";
$test .= ExerciseLib::showQuestion($questionId, false, 'export', $i);
} // end foreach()
$s = "< / table > < / td > < / tr > < tr > < td > < br / > < input type = 'button' value = '".$langOk."' onclick = \"javascript: evaluate ( ) ; alert ( ' Evaluated . ' ) ; \ " > ";
$s .= "< / td > < / tr > < / form > < / table > ";
$s .= "< script type = 'text/javascript' > loadPage ( ) ; < / script > ";
$b = 2;
$test .= $s;
return ($test);
}
/**
* This function exports the given item's description into a separate file
* @param integer Item id
* @param string Item type
* @param string Description
* @return void
*/
function exportdescription($id, $item_type, $description) {
global $expdir;
$filename = $item_type.$id.'.desc';
$expcontent = $description;
exporttofile($expdir.$filename, 'description_of_'.$item_type.$id, 'description_of_item_'.$id, $expcontent);
}
/**
* This function deletes an entire directory
@ -258,85 +83,6 @@ function deldir($dir) {
return false;
}
/**
* This function returns an xml tag
* $data behaves as the content in case of full tags
* $data is an array of attributes in case of returning an opening tag
* @param string
* @param string
* @param array
* @param string
* @return string
*/
function xmltagwrite($tagname, $which, $data, $linebreak = 'yes') {
switch ($which) {
case 'open':
$tag = '< '.$tagname;
$i = 0;
while ($data[0][$i]) {
$tag .= ' '.$data[0][$i]."=\"".$data[1][$i]."\"";
$i ++;
}
if ($tagname == 'file') {
$closing = '/';
}
$tag .= $closing.'>';
if ($linebreak != 'no_linebreak') {
$tag .= "\n";
}
break;
case 'close':
$tag = '< /'.$tagname.'>';
if ($linebreak != 'no_linebreak') {
$tag .= "\n";
}
break;
case 'full':
$tag = '< '.$tagname;
$tag .= '>'.$data.'< /'.$tagname.'>';
if ($linebreak != 'no_linebreak') {
$tag .= "\n";
}
break;
}
return $tag;
}
/**
* Gets the tags of the file given as parameter
*
* if $filename is not found, GetSRCTags(filename) will return FALSE
* @param string File path
* @return mixed Array of strings on success, false on failure
* @author unknown
* @author Included by imandak80
*/
function GetSRCTags($fileName) {
if (!($fp = fopen($fileName, 'r'))) {
// Iif file can't be opened, return false.
return false;
}
// Read file contents.
$contents = fread($fp, filesize($fileName));
fclose($fp);
$matches = array();
$srcList = array();
// Get all src tags contents in this file. Use multi-line search.
preg_match_all('/src(\s)*=(\s)*[\'"]([^\'"]*)[\'"]/mi', $contents, $matches); // Get the img src as contained between " or '
foreach ($matches[3] as $match) {
if (!in_array($match, $srcList)) {
$srcList[] = $match;
}
}
if (count($srcList) == 0) {
return false;
}
return $srcList;
}
function rcopy($source, $dest) {
//error_log($source." -> ".$dest, 0);
if (!file_exists($source)) {