Format code, remove unused code.

1.10.x
Julio Montoya 10 years ago
parent 4dff56a3c7
commit c2d12d632c
  1. 3
      main/admin/sub_language_add.php
  2. 254
      main/newscorm/learnpath_functions.inc.php
  3. 9
      main/survey/fillsurvey.php

@ -38,7 +38,8 @@ function add_sub_language ($original_name,$english_name,$isocode,$sublanguage_av
$sublanguage_available = Database::escape_string($sublanguage_available);
$parent_id = intval($parent_id);
$sql='INSERT INTO '.$tbl_admin_languages.'(original_name,english_name,isocode,dokeos_folder,available,parent_id) VALUES ("'.$original_name.'","'.$english_name.'","'.$isocode.'","'.$english_name.'","'.$sublanguage_available.'","'.$parent_id.'")';
$sql = 'INSERT INTO '.$tbl_admin_languages.'(original_name,english_name,isocode,dokeos_folder,available,parent_id)
VALUES ("'.$original_name.'","'.$english_name.'","'.$isocode.'","'.$english_name.'","'.$sublanguage_available.'","'.$parent_id.'")';
$res = Database::query($sql);
if ($res === false) {
return false;

@ -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)) {

@ -96,11 +96,11 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
$sql = "SELECT * FROM $table_survey
WHERE c_id = $course_id AND code = '".$surveyCode."'";
$result = Database::query($sql);
if (Database :: num_rows($result) > 0) { // Ok
if (Database :: num_rows($result) > 0) {
// Check availability
$row = Database :: fetch_array($result, 'ASSOC');
$tempdata = SurveyManager :: get_survey($row['survey_id']);
//exit if survey not available anymore
check_time_availability($tempdata);
// Check for double invitation records (insert should be done once)
$sql = "SELECT user from $table_survey_invitation
@ -108,9 +108,10 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
c_id = $course_id AND
invitation_code = '".Database::escape_string($autoInvitationcode)."'";
$result = Database::query($sql);
if (Database :: num_rows($result) == 0) { // Ok
$now = api_get_utc_datetime();
if (Database :: num_rows($result) == 0) {
$sql = "INSERT INTO $table_survey_invitation (c_id, survey_code,user, invitation_code, invitation_date) ";
$sql .= " VALUES ($course_id, \"$surveyCode\", \"$userid\", \"$autoInvitationcode\", now())";
$sql .= " VALUES ($course_id, \"$surveyCode\", \"$userid\", \"$autoInvitationcode\", '".$now."')";
Database::query($sql);
}
// From here we use the new invitationcode auto-userid-surveycode string

Loading…
Cancel
Save