Minor - format code

pull/2487/head
jmontoyaa 8 years ago
parent f334ecd9a1
commit 1451a902b8
  1. 441
      main/exercise/exercise_submit.php
  2. 401
      main/exercise/question_pool.php
  3. 162
      main/inc/lib/display.lib.php
  4. 99
      main/inc/lib/document.lib.php
  5. 192
      main/lp/learnpath.class.php
  6. 47
      main/lp/scorm.class.php
  7. 49
      main/survey/surveyUtil.class.php

@ -4,29 +4,29 @@
use ChamiloSession as Session; use ChamiloSession as Session;
/** /**
* Exercise submission * Exercise submission
* This script allows to run an exercise. According to the exercise type, questions * This script allows to run an exercise. According to the exercise type, questions
* can be on an unique page, or one per page with a Next button. * can be on an unique page, or one per page with a Next button.
* *
* One exercise may contain different types of answers (unique or multiple selection, * One exercise may contain different types of answers (unique or multiple selection,
* matching, fill in blanks, free answer, hot-spot). * matching, fill in blanks, free answer, hot-spot).
* *
* Questions are selected randomly or not. * Questions are selected randomly or not.
* *
* When the user has answered all questions and clicks on the button "Ok", * When the user has answered all questions and clicks on the button "Ok",
* it goes to exercise_result.php * it goes to exercise_result.php
* *
* Notice : This script is also used to show a question before modifying it by * Notice : This script is also used to show a question before modifying it by
* the administrator * the administrator
* @package chamilo.exercise * @package chamilo.exercise
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @author Julio Montoya <gugli100@gmail.com> * @author Julio Montoya <gugli100@gmail.com>
* Fill in blank option added (2008) * Fill in blank option added (2008)
* Cleaning exercises (2010), * Cleaning exercises (2010),
* Adding hotspot delineation support (2011) * Adding hotspot delineation support (2011)
* Adding reminder + ajax support (2011) * Adding reminder + ajax support (2011)
* Modified by hubert.borderiou (2011-10-21 question category) * Modified by hubert.borderiou (2011-10-21 question category)
*/ */
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_QUIZ; $current_course_tool = TOOL_QUIZ;
@ -117,33 +117,43 @@ if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSessi
// Construction of Exercise // Construction of Exercise
$objExercise = new Exercise(); $objExercise = new Exercise();
Session::write('firstTime', true); Session::write('firstTime', true);
if ($debug) {error_log('1. Setting the $objExercise variable'); }; if ($debug) {
error_log('1. Setting the $objExercise variable');
}
Session::erase('questionList'); Session::erase('questionList');
// if the specified exercise doesn't exist or is disabled // if the specified exercise doesn't exist or is disabled
if (!$objExercise->read($exerciseId) || if (!$objExercise->read($exerciseId) ||
(!$objExercise->selectStatus() && !$is_allowedToEdit && $origin != 'learnpath') (!$objExercise->selectStatus() && !$is_allowedToEdit && $origin != 'learnpath')
) { ) {
if ($debug) {error_log('1.1. Error while reading the exercise'); }; if ($debug) {
error_log('1.1. Error while reading the exercise');
}
unset($objExercise); unset($objExercise);
$error = get_lang('ExerciseNotFound'); $error = get_lang('ExerciseNotFound');
} else { } else {
// Saves the object into the session // Saves the object into the session
Session::write('objExercise', $objExercise); Session::write('objExercise', $objExercise);
if ($debug) {error_log('1.1. $exerciseInSession was unset - set now - end'); }; if ($debug) {
error_log('1.1. $exerciseInSession was unset - set now - end');
}
} }
} else { } else {
Session::write('firstTime', false); Session::write('firstTime', false);
} }
//2. Checking if $objExercise is set //2. Checking if $objExercise is set
if (!isset($objExercise) && isset($exerciseInSession)) { if (!isset($objExercise) && isset($exerciseInSession)) {
if ($debug) { error_log('2. Loading $objExercise from session'); }; if ($debug) {
error_log('2. Loading $objExercise from session');
}
$objExercise = $exerciseInSession; $objExercise = $exerciseInSession;
} }
//3. $objExercise is not set, then return to the exercise list //3. $objExercise is not set, then return to the exercise list
if (!is_object($objExercise)) { if (!is_object($objExercise)) {
if ($debug) {error_log('3. $objExercise was not set, kill the script'); }; if ($debug) {
error_log('3. $objExercise was not set, kill the script');
}
header('Location: exercise.php'); header('Location: exercise.php');
exit; exit;
} }
@ -313,7 +323,9 @@ Session::write('question_list_uncompressed', $questionListUncompressed);
$clock_expired_time = null; $clock_expired_time = null;
if (empty($exercise_stat_info)) { if (empty($exercise_stat_info)) {
if ($debug) error_log('5 $exercise_stat_info is empty '); if ($debug) {
error_log('5 $exercise_stat_info is empty ');
}
$total_weight = 0; $total_weight = 0;
$questionList = $objExercise->get_validated_question_list(); $questionList = $objExercise->get_validated_question_list();
foreach ($questionListUncompressed as $question_id) { foreach ($questionListUncompressed as $question_id) {
@ -321,19 +333,28 @@ if (empty($exercise_stat_info)) {
$total_weight += floatval($objQuestionTmp->weighting); $total_weight += floatval($objQuestionTmp->weighting);
} }
if ($time_control) { if ($time_control) {
$expected_time = $current_timestamp + $total_seconds; $expected_time = $current_timestamp + $total_seconds;
if ($debug) {
if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); error_log('5.1. $current_timestamp '.$current_timestamp);
if ($debug) error_log('5.2. $expected_time '.$expected_time); }
if ($debug) {
error_log('5.2. $expected_time '.$expected_time);
}
$clock_expired_time = api_get_utc_datetime($expected_time); $clock_expired_time = api_get_utc_datetime($expected_time);
if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); if ($debug) {
error_log('5.3. $expected_time '.$clock_expired_time);
}
//Sessions that contain the expired time //Sessions that contain the expired time
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key]); }; if ($debug) {
} error_log(
'5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key]
);
};
}
$exe_id = $objExercise->save_stat_track_exercise_info( $exe_id = $objExercise->save_stat_track_exercise_info(
$clock_expired_time, $clock_expired_time,
@ -348,9 +369,11 @@ if (empty($exercise_stat_info)) {
$learnpath_item_id, $learnpath_item_id,
$learnpath_item_view_id $learnpath_item_view_id
); );
if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id"); if ($debug) {
error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
}
} else { } else {
$exe_id = $exercise_stat_info['exe_id']; $exe_id = $exercise_stat_info['exe_id'];
// Remember last question id position. // Remember last question id position.
$isFirstTime = Session::read('firstTime'); $isFirstTime = Session::read('firstTime');
@ -372,7 +395,9 @@ if (empty($exercise_stat_info)) {
} }
} }
if ($debug) error_log("5 exercise_stat_info[] exists getting exe_id $exe_id "); if ($debug) {
error_log("5 exercise_stat_info[] exists getting exe_id $exe_id ");
}
} }
$questionListInSession = Session::read('questionList'); $questionListInSession = Session::read('questionList');
@ -407,21 +432,32 @@ if (!isset($questionListInSession)) {
// Array to check in order to block the chat // Array to check in order to block the chat
ExerciseLib::create_chat_exercise_session($exe_id); ExerciseLib::create_chat_exercise_session($exe_id);
if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); }; if ($debug) {
error_log(
'6. $objExercise->get_stat_track_exercise_info function called:: '.print_r(
$exercise_stat_info,
1
)
);
};
if (!empty($exercise_stat_info['questions_to_check'])) { if (!empty($exercise_stat_info['questions_to_check'])) {
$my_remind_list = $exercise_stat_info['questions_to_check']; $my_remind_list = $exercise_stat_info['questions_to_check'];
$my_remind_list = explode(',', $my_remind_list); $my_remind_list = explode(',', $my_remind_list);
$my_remind_list = array_filter($my_remind_list); $my_remind_list = array_filter($my_remind_list);
} }
$params = "exe_id=$exe_id&exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq(); $params = "exe_id=$exe_id&exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq();
if ($debug) { error_log("6.1 params: -> $params"); }; if ($debug) {
error_log("6.1 params: -> $params");
}
if ($reminder == 2 && empty($my_remind_list)) { if ($reminder == 2 && empty($my_remind_list)) {
if ($debug) { error_log("6.2 calling the exercise_reminder.php "); }; if ($debug) {
header('Location: exercise_reminder.php?'.$params); error_log("6.2 calling the exercise_reminder.php ");
exit; };
header('Location: exercise_reminder.php?'.$params);
exit;
} }
/* /*
@ -429,62 +465,64 @@ if ($reminder == 2 && empty($my_remind_list)) {
* If the expired time is major that zero(0) then the expired time is compute on this time. * If the expired time is major that zero(0) then the expired time is compute on this time.
*/ */
if ($time_control) { if ($time_control) {
if ($debug) error_log('7.1. Time control is enabled'); if ($debug) error_log('7.1. Time control is enabled');
if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key); if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]); if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]);
if (!isset($_SESSION['expired_time'][$current_expired_time_key])) { if (!isset($_SESSION['expired_time'][$current_expired_time_key])) {
//Timer - Get expired_time for a student //Timer - Get expired_time for a student
if (!empty($exercise_stat_info)) { if (!empty($exercise_stat_info)) {
if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); }; if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
$expired_time_of_this_attempt = $exercise_stat_info['expired_time_control']; $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
// Get the last attempt of an exercise // Get the last attempt of an exercise
$last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']); $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']);
/* This means that the user enters the exam but do not answer the /* This means that the user enters the exam but do not answer the
first question we get the date from the track_e_exercises not from first question we get the date from the track_e_exercises not from
the track_et_attempt see #2069 */ the track_et_attempt see #2069 */
if (empty($last_attempt_date)) { if (empty($last_attempt_date)) {
$diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC'); $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'], 'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'], 'UTC') + $diff);
} else { } else {
//Recalculate the time control due #2069 //Recalculate the time control due #2069
$diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC'); $diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date, 'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date, 'UTC') + $diff);
} }
if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); } if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); }
//New expired time - it is due to the possible closure of session //New expired time - it is due to the possible closure of session
$new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date, 'UTC'); $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date, 'UTC');
if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); } if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); }
$expected_time = $current_timestamp + $new_expired_time_in_seconds; $expected_time = $current_timestamp + $new_expired_time_in_seconds;
if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); }
$clock_expired_time = api_get_utc_datetime($expected_time); $clock_expired_time = api_get_utc_datetime($expected_time);
if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
// First we update the attempt to today // First we update the attempt to today
/* How the expired time is changed into "track_e_exercises" table, /* How the expired time is changed into "track_e_exercises" table,
then the last attempt for this student should be changed too */ then the last attempt for this student should be changed too */
$sql = "UPDATE $exercise_attempt_table SET $sql = "UPDATE $exercise_attempt_table SET
tms = '".api_get_utc_datetime()."' tms = '".api_get_utc_datetime()."'
WHERE WHERE
exe_id = '".$exercise_stat_info['exe_id']."' AND exe_id = '".$exercise_stat_info['exe_id']."' AND
tms = '".$last_attempt_date."' "; tms = '".$last_attempt_date."' ";
if ($debug) {error_log('7.10. $sql: '.$sql); } if ($debug) {error_log('7.10. $sql: '.$sql); }
Database::query($sql); Database::query($sql);
//Sessions that contain the expired time //Sessions that contain the expired time
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key]); }; if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key]); };
} }
} else { } else {
$clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key]; $clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key];
} }
} else { } else {
if ($debug) { error_log("7 No time control"); }; if ($debug) {
error_log("7 No time control");
}
} }
// Get time left for expiring time // Get time left for expiring time
@ -495,7 +533,7 @@ $time_left = api_strtotime($clock_expired_time, 'UTC') - time();
* for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock * for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock
*/ */
if ($time_control) { //Sends the exercise form when the expired time is finished if ($time_control) { //Sends the exercise form when the expired time is finished
$htmlHeadXtra[] = $objExercise->show_time_control_js($time_left); $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
} }
//in LP's is enabled the "remember question" feature? //in LP's is enabled the "remember question" feature?
@ -503,22 +541,24 @@ if (!isset($_SESSION['questionList'])) {
// selects the list of question ID // selects the list of question ID
$questionList = $objExercise->get_validated_question_list(); $questionList = $objExercise->get_validated_question_list();
if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) { if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) {
$questionList = explode(',', $exercise_stat_info['data_tracking']); $questionList = explode(',', $exercise_stat_info['data_tracking']);
} }
Session::write('questionList', $questionList); Session::write('questionList', $questionList);
if ($debug > 0) { error_log('$_SESSION[questionList] was set'); } if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
} else { } else {
if (isset($objExercise) && isset($_SESSION['objExercise'])) { if (isset($objExercise) && isset($_SESSION['objExercise'])) {
$questionList = $_SESSION['questionList']; $questionList = $_SESSION['questionList'];
} }
} }
if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1)); if ($debug) {
error_log('8. Question list loaded '.print_r($questionList, 1));
}
//Real question count //Real question count
$question_count = 0; $question_count = 0;
if (!empty($questionList)) { if (!empty($questionList)) {
$question_count = count($questionList); $question_count = count($questionList);
} }
if ($current_question > $question_count) { if ($current_question > $question_count) {
@ -568,11 +608,11 @@ if ($formSent && isset($_POST)) {
//saving each question //saving each question
if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) { if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
$nro_question = $current_question; // - 1; $nro_question = $current_question; // - 1;
$questionId = $key; $questionId = $key;
// gets the student choice for this question // gets the student choice for this question
$choice = $exerciseResult[$questionId]; $choice = $exerciseResult[$questionId];
if (isset($exe_id)) { if (isset($exe_id)) {
// Manage the question and answer attempts // Manage the question and answer attempts
if ($debug) { if ($debug) {
error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice, 1)); error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice, 1));
} }
@ -663,61 +703,60 @@ if (is_null($current_question)) {
$current_question++; $current_question++;
} }
if ($question_count != 0) { if ($question_count != 0) {
if (($objExercise->type == ALL_ON_ONE_PAGE || if (($objExercise->type == ALL_ON_ONE_PAGE ||
$current_question > $question_count) $current_question > $question_count)
) { ) {
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
// goes to the script that will show the result of the exercise // goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); } if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
//We check if the user attempts before sending to the exercise_result.php //We check if the user attempts before sending to the exercise_result.php
if ($objExercise->selectAttempts() > 0) { if ($objExercise->selectAttempts() > 0) {
$attempt_count = Event::get_attempt_count( $attempt_count = Event::get_attempt_count(
api_get_user_id(), api_get_user_id(),
$exerciseId, $exerciseId,
$learnpath_id, $learnpath_id,
$learnpath_item_id, $learnpath_item_id,
$learnpath_item_view_id $learnpath_item_view_id
); );
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
Display::return_message( Display::return_message(
sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()),
'warning', 'warning',
false false
); );
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
//so we are not in learnpath tool //so we are not in learnpath tool
echo '</div>'; //End glossary div echo '</div>'; //End glossary div
Display :: display_footer(); Display :: display_footer();
} else { } else {
echo '</body></html>'; echo '</body></html>';
} }
exit; exit;
} }
} }
} else { } else {
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
header('Location: exercise_reminder.php?'.$params); header('Location: exercise_reminder.php?'.$params);
exit; exit;
} else { } else {
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id"); header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit; exit;
} }
} }
} else { } else {
if ($debug) { error_log('Redirecting to exercise_submit.php'); } if ($debug) { error_log('Redirecting to exercise_submit.php'); }
exit; exit;
} }
} }
} else { } else {
$error = get_lang('ThereAreNoQuestionsForThisExercise'); $error = get_lang('ThereAreNoQuestionsForThisExercise');
// if we are in the case where user select random by category, but didn't choose the number of random question // if we are in the case where user select random by category, but didn't choose the number of random question
if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) { if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) {
$error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion'); $error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion');
} }
} }
if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') { if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
@ -759,9 +798,9 @@ $show_quiz_edition = $objExercise->added_in_lp();
if (api_is_course_admin() && $origin != 'learnpath') { if (api_is_course_admin() && $origin != 'learnpath') {
echo '<div class="actions">'; echo '<div class="actions">';
if ($show_quiz_edition == false) { if ($show_quiz_edition == false) {
echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.Display::return_icon('settings.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>'; echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.Display::return_icon('settings.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>';
} else { } else {
echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>'; echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>';
} }
echo '</div>'; echo '</div>';
} }
@ -804,7 +843,7 @@ if ($limit_time_exists) {
$message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet'); $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet');
echo Display::return_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()), 'warning'); echo Display::return_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()), 'warning');
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
Display :: display_footer(); Display :: display_footer();
} }
exit; exit;
} else { } else {
@ -819,7 +858,7 @@ global $_custom;
if (isset($_custom['exercises_hidden_when_no_start_date']) && if (isset($_custom['exercises_hidden_when_no_start_date']) &&
$_custom['exercises_hidden_when_no_start_date'] $_custom['exercises_hidden_when_no_start_date']
) { ) {
if (empty($objExercise->start_time)) { if (empty($objExercise->start_time)) {
echo Display:: return_message( echo Display:: return_message(
sprintf( sprintf(
get_lang('ExerciseNoStartedYet'), get_lang('ExerciseNoStartedYet'),
@ -828,16 +867,16 @@ if (isset($_custom['exercises_hidden_when_no_start_date']) &&
), ),
'warning' 'warning'
); );
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
Display :: display_footer(); Display :: display_footer();
} }
} }
} }
//Timer control //Timer control
if ($time_control) { if ($time_control) {
echo $objExercise->return_time_left_div(); echo $objExercise->return_time_left_div();
echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>'; echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>';
} }
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
@ -852,53 +891,51 @@ if ($reminder == 2) {
$current_question = 1; //set by default the 1st question $current_question = 1; //set by default the 1st question
if (!empty($my_remind_list)) { if (!empty($my_remind_list)) {
//Checking which questions we are going to call from the remind list //Checking which questions we are going to call from the remind list
for ($i = 0; $i < count($data_tracking); $i++) { for ($i = 0; $i < count($data_tracking); $i++) {
for ($j = 0; $j < count($my_remind_list); $j++) { for ($j = 0; $j < count($my_remind_list); $j++) {
if (!empty($remind_question_id)) {
if (!empty($remind_question_id)) { if ($remind_question_id == $my_remind_list[$j]) {
if ($remind_question_id == $my_remind_list[$j]) { if ($remind_question_id == $data_tracking[$i]) {
if (isset($my_remind_list[$j + 1])) {
if ($remind_question_id == $data_tracking[$i]) { $remind_question_id = $my_remind_list[$j + 1];
if (isset($my_remind_list[$j + 1])) { $current_question = $i + 1;
$remind_question_id = $my_remind_list[$j + 1]; } else {
$current_question = $i + 1;
} else {
// We end the remind list we go to the exercise_reminder.php please // We end the remind list we go to the exercise_reminder.php please
$remind_question_id = -1; $remind_question_id = -1;
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} }
break 2; break 2;
} }
} }
} else { } else {
if ($my_remind_list[$j] == $data_tracking[$i]) { if ($my_remind_list[$j] == $data_tracking[$i]) {
if (isset($my_remind_list[$j + 1])) { if (isset($my_remind_list[$j + 1])) {
$remind_question_id = $my_remind_list[$j + 1]; $remind_question_id = $my_remind_list[$j + 1];
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} else { } else {
// We end the remind list we go to the exercise_reminder.php please // We end the remind list we go to the exercise_reminder.php please
$remind_question_id = -1; $remind_question_id = -1;
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} }
break 2; break 2;
} }
} }
} }
} }
} else { } else {
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
if ($debug) { error_log('. redirecting to exercise_reminder.php '); } if ($debug) { error_log('. redirecting to exercise_reminder.php '); }
header("Location: exercise_reminder.php?$params"); header("Location: exercise_reminder.php?$params");
exit; exit;
} }
} }
} }
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
$script_php = 'exercise_reminder.php'; $script_php = 'exercise_reminder.php';
} else { } else {
$script_php = 'exercise_result.php'; $script_php = 'exercise_result.php';
} }
if (!empty($error)) { if (!empty($error)) {
@ -1022,10 +1059,10 @@ if (!empty($error)) {
}); });
}); });
function previous_question(question_num) { function previous_question(question_num) {
url = "exercise_submit.php?'.$params.'&num="+question_num; url = "exercise_submit.php?'.$params.'&num="+question_num;
window.location = url; window.location = url;
} }
function previous_question_and_save(previous_question_id, question_id_to_save) { function previous_question_and_save(previous_question_id, question_id_to_save) {
url = "exercise_submit.php?'.$params.'&num="+previous_question_id; url = "exercise_submit.php?'.$params.'&num="+previous_question_id;
@ -1180,7 +1217,7 @@ if (!empty($error)) {
<input type="hidden" name="learnpath_item_id" value="'.$learnpath_item_id.'" /> <input type="hidden" name="learnpath_item_id" value="'.$learnpath_item_id.'" />
<input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id.'" />'; <input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id.'" />';
// Show list of questions // Show list of questions
$i = 1; $i = 1;
$attempt_list = []; $attempt_list = [];
if (isset($exe_id)) { if (isset($exe_id)) {
@ -1240,10 +1277,10 @@ if (!empty($error)) {
$attributes = array('id' =>'remind_list['.$questionId.']'); $attributes = array('id' =>'remind_list['.$questionId.']');
if (in_array($questionId, $remind_list)) { if (in_array($questionId, $remind_list)) {
$is_remind_on = true; $is_remind_on = true;
$attributes['checked'] = 1; $attributes['checked'] = 1;
$remind_question = true; $remind_question = true;
$remind_highlight = ' remind_highlight '; $remind_highlight = ' remind_highlight ';
} }
// Showing the exercise description // Showing the exercise description
@ -1326,8 +1363,8 @@ if (!empty($error)) {
} }
// end foreach() // end foreach()
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
$exercise_actions = $objExercise->show_button($questionId, $current_question); $exercise_actions = $objExercise->show_button($questionId, $current_question);
echo Display::div($exercise_actions, array('class'=>'exercise_actions')); echo Display::div($exercise_actions, array('class'=>'exercise_actions'));
echo '<br>'; echo '<br>';
} }
echo '</form>'; echo '</form>';

@ -2,14 +2,14 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Question Pool * Question Pool
* This script allows administrators to manage questions and add them into their exercises. * This script allows administrators to manage questions and add them into their exercises.
* One question can be in several exercises * One question can be in several exercises
* @package chamilo.exercise * @package chamilo.exercise
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @author Julio Montoya adding support to query all questions from all session, courses, exercises * @author Julio Montoya adding support to query all questions from all session, courses, exercises
* @author Modify by hubert borderiou 2011-10-21 Question's category * @author Modify by hubert borderiou 2011-10-21 Question's category
*/ */
use ChamiloSession as Session; use ChamiloSession as Session;
@ -119,7 +119,7 @@ if ($is_allowedToEdit) {
// destruction of the Question object // destruction of the Question object
unset($objQuestionTmp); unset($objQuestionTmp);
if (!$objExercise instanceOf Exercise) { if (!$objExercise instanceof Exercise) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
@ -160,7 +160,7 @@ if ($is_allowedToEdit) {
unset($new_question_obj); unset($new_question_obj);
unset($old_question_obj); unset($old_question_obj);
if (!$objExercise instanceOf Exercise) { if (!$objExercise instanceof Exercise) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
@ -172,11 +172,11 @@ if ($is_allowedToEdit) {
} }
if (isset($_SESSION['gradebook'])) { if (isset($_SESSION['gradebook'])) {
$gradebook = $_SESSION['gradebook']; $gradebook = $_SESSION['gradebook'];
} }
if (!empty($gradebook) && $gradebook == 'view') { if (!empty($gradebook) && $gradebook == 'view') {
$interbreadcrumb[] = array('url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']), 'name' => get_lang('ToolGradebook')); $interbreadcrumb[] = array('url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']), 'name' => get_lang('ToolGradebook'));
} }
// if admin of course // if admin of course
@ -188,21 +188,21 @@ $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),
$htmlHeadXtra[] = " $htmlHeadXtra[] = "
<script> <script>
function submit_form(obj) { function submit_form(obj) {
document.question_pool.submit(); document.question_pool.submit();
} }
function mark_course_id_changed() { function mark_course_id_changed() {
$('#course_id_changed').val('1'); $('#course_id_changed').val('1');
} }
function mark_exercise_id_changed() { function mark_exercise_id_changed() {
$('#exercise_id_changed').val('1'); $('#exercise_id_changed').val('1');
} }
function confirm_your_choice() { function confirm_your_choice() {
return confirm('$confirmYourChoice'); return confirm('$confirmYourChoice');
} }
</script>"; </script>";
Display::display_header($nameTools, 'Exercise'); Display::display_header($nameTools, 'Exercise');
@ -227,8 +227,8 @@ if (isset($fromExercise) && $fromExercise > 0) {
echo '</div>'; echo '</div>';
if ($displayMessage != "") { if ($displayMessage != "") {
Display::display_confirmation_message($displayMessage); Display::display_confirmation_message($displayMessage);
$displayMessage = ""; $displayMessage = "";
} }
// Form // Form
@ -236,7 +236,7 @@ echo '<form class="form-horizontal" name="question_pool" method="GET" action="'.
// Title // Title
echo '<legend>'.$nameTools.' - '.$titleAdd.'</legend>'; echo '<legend>'.$nameTools.' - '.$titleAdd.'</legend>';
if (isset($type)) { if (isset($type)) {
echo '<input type="hidden" name="type" value="1">'; echo '<input type="hidden" name="type" value="1">';
} }
echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">'; echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
@ -283,11 +283,11 @@ $course_select_list = array();
foreach ($course_list as $item) { foreach ($course_list as $item) {
$courseItemId = $item['real_id']; $courseItemId = $item['real_id'];
$courseInfo = api_get_course_info_by_id($courseItemId); $courseInfo = api_get_course_info_by_id($courseItemId);
$course_select_list[$courseItemId] = ""; $course_select_list[$courseItemId] = "";
if ($courseItemId == api_get_course_int_id()) { if ($courseItemId == api_get_course_int_id()) {
$course_select_list[$courseItemId] = ">&nbsp;&nbsp;&nbsp;&nbsp;"; $course_select_list[$courseItemId] = ">&nbsp;&nbsp;&nbsp;&nbsp;";
} }
$course_select_list[$courseItemId] .= $courseInfo['title']; $course_select_list[$courseItemId] .= $courseInfo['title'];
} }
$select_course_html = Display::select( $select_course_html = Display::select(
@ -304,11 +304,11 @@ if (empty($selected_course) || $selected_course == '-1') {
// no course selected, reset menu test / difficult<EFBFBD> / type de reponse // no course selected, reset menu test / difficult<EFBFBD> / type de reponse
reset_menu_exo_lvl_type(); reset_menu_exo_lvl_type();
} else { } else {
$course_info = api_get_course_info_by_id($selected_course); $course_info = api_get_course_info_by_id($selected_course);
} }
// If course has changed, reset the menu default // If course has changed, reset the menu default
if ($course_id_changed) { if ($course_id_changed) {
reset_menu_exo_lvl_type(); reset_menu_exo_lvl_type();
} }
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -356,7 +356,7 @@ if (is_array($exercise_list)) {
} }
if ($exercise_id_changed == 1) { if ($exercise_id_changed == 1) {
reset_menu_lvl_type(); reset_menu_lvl_type();
} }
$select_exercise_html = Display::select( $select_exercise_html = Display::select(
'exerciseId', 'exerciseId',
@ -434,33 +434,33 @@ $mainQuestionList = array();
// if we have selected an exercise in the list-box 'Filter' // if we have selected an exercise in the list-box 'Filter'
if ($exerciseId > 0) { if ($exerciseId > 0) {
$where = ''; $where = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc "; $from = ", $TBL_COURSE_REL_CATEGORY crc ";
$where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId"; $where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
} }
if (isset($exerciseLevel) && $exerciseLevel != -1) { if (isset($exerciseLevel) && $exerciseLevel != -1) {
$where .= ' AND level='.$exerciseLevel; $where .= ' AND level='.$exerciseLevel;
} }
if (isset($answerType) && $answerType > 0) { if (isset($answerType) && $answerType > 0) {
$where .= ' AND type='.$answerType; $where .= ' AND type='.$answerType;
} }
$sql = "SELECT DISTINCT $sql = "SELECT DISTINCT
id, id,
question, question,
type, type,
level level
FROM FROM
$TBL_EXERCISE_QUESTION qt, $TBL_EXERCISE_QUESTION qt,
$TBL_QUESTIONS qu $TBL_QUESTIONS qu
$from $from
WHERE WHERE
qt.question_id = qu.id qt.question_id = qu.id
AND qt.exercice_id=$exerciseId AND qt.exercice_id=$exerciseId
AND qt.c_id=$selected_course AND qt.c_id=$selected_course
AND qu.c_id=$selected_course AND qu.c_id=$selected_course
$where $where
ORDER BY question_order"; ORDER BY question_order";
$result = Database::query($sql); $result = Database::query($sql);
@ -468,22 +468,22 @@ if ($exerciseId > 0) {
$mainQuestionList[] = $row; $mainQuestionList[] = $row;
} }
} elseif ($exerciseId == -1) { } elseif ($exerciseId == -1) {
// If we have selected the option 'Orphan questions' in the list-box 'Filter' // If we have selected the option 'Orphan questions' in the list-box 'Filter'
$level_where = ''; $level_where = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = " INNER JOIN $TBL_COURSE_REL_CATEGORY crc ON crc.question_id=q.id AND crc.c_id= q.c_id "; $from = " INNER JOIN $TBL_COURSE_REL_CATEGORY crc ON crc.question_id=q.id AND crc.c_id= q.c_id ";
$level_where .= " AND $level_where .= " AND
crc.c_id = $selected_course AND crc.c_id = $selected_course AND
crc.category_id = $courseCategoryId"; crc.category_id = $courseCategoryId";
} }
if (isset($exerciseLevel) && $exerciseLevel != -1) { if (isset($exerciseLevel) && $exerciseLevel != -1) {
$level_where = ' AND level='.$exerciseLevel; $level_where = ' AND level='.$exerciseLevel;
} }
$answer_where = ''; $answer_where = '';
if (isset($answerType) && $answerType > 0 - 1) { if (isset($answerType) && $answerType > 0 - 1) {
$answer_where = ' AND type='.$answerType; $answer_where = ' AND type='.$answerType;
} }
// @todo fix this query with the new id field // @todo fix this query with the new id field
$sql = " ( $sql = " (
@ -525,24 +525,24 @@ if ($exerciseId > 0) {
$mainQuestionList[] = $row; $mainQuestionList[] = $row;
} }
} else { } else {
// All tests for selected course // All tests for selected course
// If we have not selected any option in the list-box 'Filter' // If we have not selected any option in the list-box 'Filter'
$filter = ''; $filter = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc "; $from = ", $TBL_COURSE_REL_CATEGORY crc ";
$filter .= " AND $filter .= " AND
crc.c_id = $selected_course AND crc.c_id = $selected_course AND
crc.question_id = qu.id AND crc.question_id = qu.id AND
crc.category_id = $courseCategoryId"; crc.category_id = $courseCategoryId";
} }
if (isset($exerciseLevel) && $exerciseLevel != -1) { if (isset($exerciseLevel) && $exerciseLevel != -1) {
$filter .= ' AND level='.$exerciseLevel.' '; $filter .= ' AND level='.$exerciseLevel.' ';
} }
if (isset($answerType) && $answerType > 0) { if (isset($answerType) && $answerType > 0) {
$filter .= ' AND qu.type='.$answerType.' '; $filter .= ' AND qu.type='.$answerType.' ';
} }
if (!empty($session_id) && $session_id != '-1') { if (!empty($session_id) && $session_id != '-1') {
$mainQuestionList = array(); $mainQuestionList = array();
@ -565,7 +565,6 @@ if ($exerciseId > 0) {
if (!empty($my_exercise)) { if (!empty($my_exercise)) {
if (!empty($my_exercise->questionList)) { if (!empty($my_exercise->questionList)) {
foreach ($my_exercise->questionList as $question_id) { foreach ($my_exercise->questionList as $question_id) {
$question_obj = Question::read( $question_obj = Question::read(
$question_id, $question_id,
$courseItemId $courseItemId
@ -644,7 +643,7 @@ if ($exerciseId > 0) {
$mainQuestionList[] = $row; $mainQuestionList[] = $row;
} }
} }
// forces the value to 0 // forces the value to 0
$exerciseId = 0; $exerciseId = 0;
} }
@ -670,33 +669,33 @@ $nbrQuestions = count($mainQuestionList);
// //
if ($fromExercise <= 0) { if ($fromExercise <= 0) {
// NOT IN A TEST - IN THE COURSE // NOT IN A TEST - IN THE COURSE
if ($selected_course == api_get_course_int_id()) { if ($selected_course == api_get_course_int_id()) {
$actionLabel = get_lang('Modify'); $actionLabel = get_lang('Modify');
$actionIcon1 = "edit"; $actionIcon1 = "edit";
$actionIcon2 = "delete"; $actionIcon2 = "delete";
// We are in the course, question title can be a link to the question edit page // We are in the course, question title can be a link to the question edit page
$questionTagA = 1; $questionTagA = 1;
} else { // NOT IN A TEST - NOT IN THE COURSE } else { // NOT IN A TEST - NOT IN THE COURSE
$actionLabel = get_lang('Reuse'); $actionLabel = get_lang('Reuse');
$actionIcon1 = get_lang('MustBeInATest'); $actionIcon1 = get_lang('MustBeInATest');
$actionIcon2 = ""; $actionIcon2 = "";
// We are not in this course, to messy if we link to the question in another course // We are not in this course, to messy if we link to the question in another course
$questionTagA = 0; $questionTagA = 0;
} }
} else { } else {
// IN A TEST - IN THE COURSE // IN A TEST - IN THE COURSE
if ($selected_course == api_get_course_int_id()) { if ($selected_course == api_get_course_int_id()) {
$actionLabel = get_lang('Reuse'); $actionLabel = get_lang('Reuse');
$actionIcon1 = "add"; $actionIcon1 = "add";
$actionIcon2 = ""; $actionIcon2 = "";
$questionTagA = 1; $questionTagA = 1;
} else { } else {
// IN A TEST - NOT IN THE COURSE // IN A TEST - NOT IN THE COURSE
$actionLabel = get_lang('Reuse'); $actionLabel = get_lang('Reuse');
$actionIcon1 = "clone"; $actionIcon1 = "clone";
$actionIcon2 = ""; $actionIcon2 = "";
$questionTagA = 0; $questionTagA = 0;
} }
} }
// Display table // Display table
$header = array( $header = array(
@ -709,15 +708,8 @@ $header = array(
$data = array(); $data = array();
/*$hideDoubles = false;
if (empty($exerciseId) && !empty($session_id) && $session_id != '-1') {
$hideDoubles = true;
}
$questionAdded = array();*/
if (is_array($mainQuestionList)) { if (is_array($mainQuestionList)) {
foreach ($mainQuestionList as $question) { foreach ($mainQuestionList as $question) {
/*if ($hideDoubles) { /*if ($hideDoubles) {
if (in_array($question['question'], $questionAdded)) { if (in_array($question['question'], $questionAdded)) {
continue; continue;
@ -751,32 +743,31 @@ if (is_array($mainQuestionList)) {
$row[] = get_question_categorie_for_question($selected_course, $question['id']); $row[] = get_question_categorie_for_question($selected_course, $question['id']);
$row[] = $question['level']; $row[] = $question['level'];
$row[] = get_action_icon_for_question( $row[] = get_action_icon_for_question(
$actionIcon1, $actionIcon1,
$fromExercise, $fromExercise,
$question['id'], $question['id'],
$question['type'], $question['type'],
$question['question'], $question['question'],
$selected_course, $selected_course,
$courseCategoryId, $courseCategoryId,
$exerciseLevel, $exerciseLevel,
$answerType, $answerType,
$session_id, $session_id,
$exerciseId $exerciseId
). )."&nbsp;".
"&nbsp;". get_action_icon_for_question(
get_action_icon_for_question( $actionIcon2,
$actionIcon2, $fromExercise,
$fromExercise, $question['id'],
$question['id'], $question['type'],
$question['type'], $question['question'],
$question['question'], $selected_course,
$selected_course, $courseCategoryId,
$courseCategoryId, $exerciseLevel,
$exerciseLevel, $answerType,
$answerType, $session_id,
$session_id, $exerciseId
$exerciseId );
);
$data[] = $row; $data[] = $row;
} }
} }
@ -789,34 +780,34 @@ Display :: display_sortable_table(
); );
if (!$nbrQuestions) { if (!$nbrQuestions) {
echo get_lang('NoQuestion'); echo get_lang('NoQuestion');
} }
Display::display_footer(); Display::display_footer();
/** /**
* Put the menu entry for level and type to default "Choice" * Put the menu entry for level and type to default "Choice"
* It is useful if you change the exercise, you need to reset the other menus * It is useful if you change the exercise, you need to reset the other menus
* @author hubert.borderiou 13-10-2011 * @author hubert.borderiou 13-10-2011
*/ */
function reset_menu_lvl_type() function reset_menu_lvl_type()
{ {
global $exerciseLevel, $answerType; global $exerciseLevel, $answerType;
$answerType = -1; $answerType = -1;
$exerciseLevel = -1; $exerciseLevel = -1;
} }
/** /**
* Put the menu entry for exercise and level and type to default "Choice" * Put the menu entry for exercise and level and type to default "Choice"
* It is useful if you change the course, you need to reset the other menus * It is useful if you change the course, you need to reset the other menus
* @author hubert.borderiou 13-10-2011 * @author hubert.borderiou 13-10-2011
*/ */
function reset_menu_exo_lvl_type() function reset_menu_exo_lvl_type()
{ {
global $exerciseId, $courseCategoryId; global $exerciseId, $courseCategoryId;
reset_menu_lvl_type(); reset_menu_lvl_type();
$exerciseId = 0; $exerciseId = 0;
$courseCategoryId = 0; $courseCategoryId = 0;
} }
/** /**
@ -838,17 +829,17 @@ function get_a_tag_for_question(
$in_questionname, $in_questionname,
$sessionId $sessionId
) { ) {
$res = $in_questionname; $res = $in_questionname;
$sessionIcon = null; $sessionIcon = null;
if ($in_addA) { if ($in_addA) {
if (!empty($sessionId) && $sessionId != -1) { if (!empty($sessionId) && $sessionId != -1) {
$sessionIcon = ' '.Display::return_icon('star.png', get_lang('Session')); $sessionIcon = ' '.Display::return_icon('star.png', get_lang('Session'));
} }
$res = "<a href='admin.php?".api_get_cidreq()."&editQuestion=$in_questionid&type=$in_questiontype&fromExercise=$in_fromex'>". $res = "<a href='admin.php?".api_get_cidreq()."&editQuestion=$in_questionid&type=$in_questiontype&fromExercise=$in_fromex'>".
$res.$sessionIcon. $res.$sessionIcon.
"</a>"; "</a>";
} }
return $res; return $res;
} }
/** /**
@ -878,16 +869,16 @@ function get_action_icon_for_question(
$in_session_id, $in_session_id,
$in_exercise_id $in_exercise_id
) { ) {
$res = ""; $res = "";
$getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercise_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id"; $getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercise_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
switch ($in_action) { switch ($in_action) {
case "delete" : case "delete":
$res = "<a href='".api_get_self()."?".api_get_cidreq().$getParams."&delete=$in_questionid' onclick='return confirm_your_choice()'>"; $res = "<a href='".api_get_self()."?".api_get_cidreq().$getParams."&delete=$in_questionid' onclick='return confirm_your_choice()'>";
$res .= Display::return_icon("delete.png", get_lang('Delete')); $res .= Display::return_icon("delete.png", get_lang('Delete'));
$res .= "</a>"; $res .= "</a>";
break; break;
case "edit" : case "edit":
$res = get_a_tag_for_question( $res = get_a_tag_for_question(
1, 1,
$from_exercise, $from_exercise,
$in_questionid, $in_questionid,
@ -895,33 +886,33 @@ function get_action_icon_for_question(
Display::return_icon("edit.png", get_lang('Modify')), Display::return_icon("edit.png", get_lang('Modify')),
$in_session_id $in_session_id
); );
break; break;
case "add": case "add":
// add if question is not already in test // add if question is not already in test
$myObjEx = new Exercise(); $myObjEx = new Exercise();
$myObjEx->read($from_exercise); $myObjEx->read($from_exercise);
if (!$myObjEx->isInList($in_questionid)) { if (!$myObjEx->isInList($in_questionid)) {
$res = "<a href='".api_get_self()."?".api_get_cidreq().$getParams."&recup=$in_questionid&fromExercise=$from_exercise'>"; $res = "<a href='".api_get_self()."?".api_get_cidreq().$getParams."&recup=$in_questionid&fromExercise=$from_exercise'>";
$res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise')); $res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise'));
$res .= "</a>"; $res .= "</a>";
} else { } else {
$res = "-"; $res = "-";
} }
unset($myObjEx); unset($myObjEx);
break; break;
case "clone": case "clone":
$url = api_get_self()."?".api_get_cidreq().$getParams."&question_copy=$in_questionid&course_id=$in_selected_course&fromExercise=$from_exercise"; $url = api_get_self()."?".api_get_cidreq().$getParams."&question_copy=$in_questionid&course_id=$in_selected_course&fromExercise=$from_exercise";
$res = Display::url( $res = Display::url(
Display::return_icon('cd.png', get_lang('ReUseACopyInCurrentTest')), Display::return_icon('cd.png', get_lang('ReUseACopyInCurrentTest')),
$url $url
); );
break; break;
default: default:
$res = $in_action; $res = $in_action;
break; break;
} }
return $res; return $res;
} }
/** /**
@ -930,14 +921,14 @@ function get_action_icon_for_question(
*/ */
function get_question_type_for_question($in_selectedcourse, $in_questionid) function get_question_type_for_question($in_selectedcourse, $in_questionid)
{ {
$myObjQuestion = Question::read($in_questionid, $in_selectedcourse); $myObjQuestion = Question::read($in_questionid, $in_selectedcourse);
$questionType = null; $questionType = null;
if (!empty($myObjQuestion)) { if (!empty($myObjQuestion)) {
list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html(); list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array()); $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array());
unset($myObjQuestion); unset($myObjQuestion);
} }
return $questionType; return $questionType;
} }
/** /**
@ -946,6 +937,6 @@ function get_question_type_for_question($in_selectedcourse, $in_questionid)
*/ */
function get_question_categorie_for_question($in_courseid, $in_questionid) function get_question_categorie_for_question($in_courseid, $in_questionid)
{ {
$cat = TestCategory::getCategoryNameForQuestion($in_questionid, $in_courseid); $cat = TestCategory::getCategoryNameForQuestion($in_questionid, $in_courseid);
return $cat; return $cat;
} }

@ -183,21 +183,21 @@ class Display
/** /**
* Displays a table * Displays a table
* @param array $header Titles for the table header * @param array $header Titles for the table header
* each item in this array can contain 3 values * each item in this array can contain 3 values
* - 1st element: the column title * - 1st element: the column title
* - 2nd element: true or false (column sortable?) * - 2nd element: true or false (column sortable?)
* - 3th element: additional attributes for * - 3th element: additional attributes for
* th-tag (eg for column-width) * th-tag (eg for column-width)
* - 4the element: additional attributes for the td-tags * - 4the element: additional attributes for the td-tags
* @param array $content 2D-array with the tables content * @param array $content 2D-array with the tables content
* @param array $sorting_options Keys are: * @param array $sorting_options Keys are:
* 'column' = The column to use as sort-key * 'column' = The column to use as sort-key
* 'direction' = SORT_ASC or SORT_DESC * 'direction' = SORT_ASC or SORT_DESC
* @param array $paging_options Keys are: * @param array $paging_options Keys are:
* 'per_page_default' = items per page when switching from * 'per_page_default' = items per page when switching from
* full- list to per-page-view * full- list to per-page-view
* 'per_page' = number of items to show per page * 'per_page' = number of items to show per page
* 'page_nr' = The page to display * 'page_nr' = The page to display
* @param array $query_vars Additional variables to add in the query-string * @param array $query_vars Additional variables to add in the query-string
* @param string The style that the table will show. You can set 'table' or 'grid' * @param string The style that the table will show. You can set 'table' or 'grid'
* @author bart.mollet@hogent.be * @author bart.mollet@hogent.be
@ -278,16 +278,16 @@ class Display
* @param array header content * @param array header content
* @param array array with the information to show * @param array array with the information to show
* @param array $paging_options Keys are: * @param array $paging_options Keys are:
* 'per_page_default' = items per page when switching from * 'per_page_default' = items per page when switching from
* full- list to per-page-view * full- list to per-page-view
* 'per_page' = number of items to show per page * 'per_page' = number of items to show per page
* 'page_nr' = The page to display * 'page_nr' = The page to display
* 'hide_navigation' = true to hide the navigation * 'hide_navigation' = true to hide the navigation
* @param array $query_vars Additional variables to add in the query-string * @param array $query_vars Additional variables to add in the query-string
* @param array $form actions Additional variables to add in the query-string * @param array $form actions Additional variables to add in the query-string
* @param mixed An array with bool values to know which columns show. * @param mixed An array with bool values to know which columns show.
* i.e: $visibility_options= array(true, false) we will only show the first column * i.e: $visibility_options= array(true, false) we will only show the first column
* Can be also only a bool value. TRUE: show all columns, FALSE: show nothing * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
*/ */
public static function display_sortable_grid( public static function display_sortable_grid(
$name, $name,
@ -319,19 +319,19 @@ class Display
* @param array header content * @param array header content
* @param array array with the information to show * @param array array with the information to show
* @param array $paging_options Keys are: * @param array $paging_options Keys are:
* 'per_page_default' = items per page when switching from * 'per_page_default' = items per page when switching from
* full- list to per-page-view * full- list to per-page-view
* 'per_page' = number of items to show per page * 'per_page' = number of items to show per page
* 'page_nr' = The page to display * 'page_nr' = The page to display
* 'hide_navigation' = true to hide the navigation * 'hide_navigation' = true to hide the navigation
* @param array $query_vars Additional variables to add in the query-string * @param array $query_vars Additional variables to add in the query-string
* @param array $form actions Additional variables to add in the query-string * @param array $form actions Additional variables to add in the query-string
* @param mixed An array with bool values to know which columns show. i.e: * @param mixed An array with bool values to know which columns show. i.e:
* $visibility_options= array(true, false) we will only show the first column * $visibility_options= array(true, false) we will only show the first column
* Can be also only a bool value. TRUE: show all columns, FALSE: show nothing * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
* @param bool true for sorting data or false otherwise * @param bool true for sorting data or false otherwise
* @param array grid classes * @param array grid classes
* @return string html grid * @return string html grid
*/ */
public static function return_sortable_grid( public static function return_sortable_grid(
$name, $name,
@ -382,7 +382,7 @@ class Display
* @param array $query_vars Additional variables to add in the query-string * @param array $query_vars Additional variables to add in the query-string
* @param array $column_show Array of binaries 1= show columns 0. hide a column * @param array $column_show Array of binaries 1= show columns 0. hide a column
* @param array $column_order An array of integers that let us decide how the columns are going to be sort. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
* i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
* @param array $form_actions Set optional forms actions * @param array $form_actions Set optional forms actions
* *
* @author Julio Montoya * @author Julio Montoya
@ -433,7 +433,7 @@ class Display
* Displays a normal message. It is recommended to use this public function * Displays a normal message. It is recommended to use this public function
* to display any normal information messages. * to display any normal information messages.
* @param string $message * @param string $message
* @param bool $filter (true) or not (false) * @param bool $filter (true) or not (false)
* @param bool $returnValue * @param bool $returnValue
* *
* @deprecated Use <code>Display::addFlash(Display::return_message($message, 'normal'));</code> * @deprecated Use <code>Display::addFlash(Display::return_message($message, 'normal'));</code>
@ -469,7 +469,7 @@ class Display
/** /**
* Displays an confirmation message. Use this if something has been done successfully * Displays an confirmation message. Use this if something has been done successfully
* @param bool Filter (true) or not (false) * @param bool Filter (true) or not (false)
* @deprecated use Display::addFlash(Display::return_message($message, 'confirm')); * @deprecated use Display::addFlash(Display::return_message($message, 'confirm'));
* @return void * @return void
*/ */
@ -487,7 +487,7 @@ class Display
* Displays an error message. It is recommended to use this public function if an error occurs * Displays an error message. It is recommended to use this public function if an error occurs
* @param string $message - include any additional html * @param string $message - include any additional html
* tags if you need them * tags if you need them
* @param bool Filter (true) or not (false) * @param bool Filter (true) or not (false)
* @deprecated use Display::addFlash(Display::return_message($message, 'error')); * @deprecated use Display::addFlash(Display::return_message($message, 'error'));
* *
* @return void * @return void
@ -533,16 +533,16 @@ class Display
$class = ''; $class = '';
switch ($type) { switch ($type) {
case 'warning': case 'warning':
$class .= 'alert alert-warning'; $class .= 'alert alert-warning';
break; break;
case 'error': case 'error':
$class .= 'alert alert-danger'; $class .= 'alert alert-danger';
break; break;
case 'confirmation': case 'confirmation':
case 'confirm': case 'confirm':
case 'success': case 'success':
$class .= 'alert alert-success'; $class .= 'alert alert-success';
break; break;
case 'normal': case 'normal':
default: default:
$class .= 'alert alert-info'; $class .= 'alert alert-info';
@ -629,6 +629,7 @@ class Display
* @param char $selected_letter The letter that should be selected * @param char $selected_letter The letter that should be selected
* @todo This is English language specific implementation. * @todo This is English language specific implementation.
* It should be adapted for the other languages. * It should be adapted for the other languages.
* @return string
*/ */
public static function get_alphabet_options($selected_letter = '') public static function get_alphabet_options($selected_letter = '')
{ {
@ -802,8 +803,9 @@ class Display
* *
* @param string $image_path the filename of the file (in the main/img/ folder * @param string $image_path the filename of the file (in the main/img/ folder
* @param string $alt_text the alt text (probably a language variable) * @param string $alt_text the alt text (probably a language variable)
* @param array $additional_attributes (for instance height, width, onclick, ...) * @param array $additional_attributes (for instance height, width, onclick, ...)
* @param boolean $filterPath Optional. Whether filter the image path. Default is true * @param boolean $filterPath Optional. Whether filter the image path. Default is true
* @return string
* @author Julio Montoya 2010 * @author Julio Montoya 2010
*/ */
public static function img($image_path, $alt_text = '', $additional_attributes = null, $filterPath = true) public static function img($image_path, $alt_text = '', $additional_attributes = null, $filterPath = true)
@ -849,6 +851,8 @@ class Display
* @param string $tag the tag name * @param string $tag the tag name
* @param string $content the tag's content * @param string $content the tag's content
* @param array $additional_attributes (for instance height, width, onclick, ...) * @param array $additional_attributes (for instance height, width, onclick, ...)
*
* @return string
* @author Julio Montoya 2010 * @author Julio Montoya 2010
*/ */
public static function tag($tag, $content, $additional_attributes = array()) public static function tag($tag, $content, $additional_attributes = array())
@ -910,18 +914,17 @@ class Display
/** /**
* Displays an HTML input tag * Displays an HTML input tag
*
*/ */
public static function input($type, $name, $value, $attributes = array()) public static function input($type, $name, $value, $attributes = array())
{ {
if (isset($type)) { if (isset($type)) {
$attributes['type'] = $type; $attributes['type'] = $type;
} }
if (isset($name)) { if (isset($name)) {
$attributes['name'] = $name; $attributes['name'] = $name;
} }
if (isset($value)) { if (isset($value)) {
$attributes['value'] = $value; $attributes['value'] = $value;
} }
return self::tag('input', '', $attributes); return self::tag('input', '', $attributes);
} }
@ -934,9 +937,9 @@ class Display
*/ */
public static function button($name, $value, $attributes = array()) public static function button($name, $value, $attributes = array())
{ {
if (!empty($name)) { if (!empty($name)) {
$attributes['name'] = $name; $attributes['name'] = $name;
} }
return self::tag('button', $value, $attributes); return self::tag('button', $value, $attributes);
} }
@ -1083,20 +1086,20 @@ class Display
*/ */
public static function tabsOnlyLink($headers, $selected = null) public static function tabsOnlyLink($headers, $selected = null)
{ {
$id = uniqid(); $id = uniqid();
$i = 1; $i = 1;
$lis = null; $lis = null;
foreach ($headers as $item) { foreach ($headers as $item) {
$class = null; $class = null;
if ($i == $selected) { if ($i == $selected) {
$class = 'active'; $class = 'active';
} }
$item = self::tag( $item = self::tag(
'a', 'a',
$item['content'], $item['content'],
array('id' => $id.'-'.$i, 'href' => $item['url']) array('id' => $id.'-'.$i, 'href' => $item['url'])
); );
$lis .= self::tag('li', $item, array('class' => $class)); $lis .= self::tag('li', $item, array('class' => $class));
$i++; $i++;
} }
return self::tag('ul', $lis, array('class' => 'nav nav-tabs tabs-margin')); return self::tag('ul', $lis, array('class' => 'nav nav-tabs tabs-margin'));
@ -1144,17 +1147,17 @@ class Display
* example --> $(function() { <?php echo Display::grid_js('grid' ...); ?> } * example --> $(function() { <?php echo Display::grid_js('grid' ...); ?> }
* In order to work this function needs the Display::grid_html function with the same div id * In order to work this function needs the Display::grid_html function with the same div id
* *
* @param string $div_id div id * @param string $div_id div id
* @param string $url url where the jqgrid will ask for data (if datatype = json) * @param string $url url where the jqgrid will ask for data (if datatype = json)
* @param array $column_names Visible columns (you should use get_lang). An array in which we place the names of the columns. * @param array $column_names Visible columns (you should use get_lang). An array in which we place the names of the columns.
* This is the text that appears in the head of the grid (Header layer). * This is the text that appears in the head of the grid (Header layer).
* Example: colname {name:'date', index:'date', width:120, align:'right'}, * Example: colname {name:'date', index:'date', width:120, align:'right'},
* @param array $column_model the column model : Array which describes the parameters of the columns.This is the most important part of the grid. * @param array $column_model the column model : Array which describes the parameters of the columns.This is the most important part of the grid.
* For a full description of all valid values see colModel API. See the url above. * For a full description of all valid values see colModel API. See the url above.
* @param array $extra_params extra parameters * @param array $extra_params extra parameters
* @param array $data data that will be loaded * @param array $data data that will be loaded
* @param string $formatter A string that will be appended to the JSON returned * @param string $formatter A string that will be appended to the JSON returned
* @param bool $fixed_width not implemented yet * @param bool $fixed_width not implemented yet
* @return string the js code * @return string the js code
* *
*/ */
@ -1308,8 +1311,8 @@ class Display
*/ */
public static function table($headers, $rows, $attributes = array()) public static function table($headers, $rows, $attributes = array())
{ {
if (empty($attributes)) { if (empty($attributes)) {
$attributes['class'] = 'data_table'; $attributes['class'] = 'data_table';
} }
$table = new HTML_Table($attributes); $table = new HTML_Table($attributes);
$row = 0; $row = 0;
@ -1317,17 +1320,17 @@ class Display
// Course headers // Course headers
if (!empty($headers)) { if (!empty($headers)) {
foreach ($headers as $item) { foreach ($headers as $item) {
$table->setHeaderContents($row, $column, $item); $table->setHeaderContents($row, $column, $item);
$column++; $column++;
} }
$row = 1; $row = 1;
$column = 0; $column = 0;
} }
if (!empty($rows)) { if (!empty($rows)) {
foreach ($rows as $content) { foreach ($rows as $content) {
$table->setCellContents($row, $column, $content); $table->setCellContents($row, $column, $content);
$row++; $row++;
} }
} }
@ -1661,8 +1664,8 @@ class Display
* @param string $id of the rating ul element * @param string $id of the rating ul element
* @param string $url that will be added (for jquery see hot_courses.tpl) * @param string $url that will be added (for jquery see hot_courses.tpl)
* @param array $point_info point info array see function CourseManager::get_course_ranking() * @param array $point_info point info array see function CourseManager::get_course_ranking()
* @param bool $add_div_wrapper add a div wrapper * @param bool $add_div_wrapper add a div wrapper
* @return string * @return string
**/ **/
public static function return_rating_system( public static function return_rating_system(
$id, $id,
@ -2060,7 +2063,6 @@ class Display
} }
/** /**
*
* @param int $nextValue * @param int $nextValue
* @param array $list * @param array $list
* @param int $current * @param int $current

@ -3,12 +3,12 @@
/** /**
* Class DocumentManager * Class DocumentManager
* This is the document library for Chamilo. * This is the document library for Chamilo.
* It is / will be used to provide a service layer to all document-using tools. * It is / will be used to provide a service layer to all document-using tools.
* and eliminate code duplication fro group documents, scorm documents, main documents. * and eliminate code duplication fro group documents, scorm documents, main documents.
* Include/require it in your code to use its functionality. * Include/require it in your code to use its functionality.
* *
* @package chamilo.library * @package chamilo.library
*/ */
class DocumentManager class DocumentManager
{ {
@ -47,14 +47,14 @@ class DocumentManager
} }
/** /**
* Get the content type of a file by checking the extension * Get the content type of a file by checking the extension
* We could use mime_content_type() with php-versions > 4.3, * We could use mime_content_type() with php-versions > 4.3,
* but this doesn't work as it should on Windows installations * but this doesn't work as it should on Windows installations
* *
* @param string $filename or boolean TRUE to return complete array * @param string $filename or boolean TRUE to return complete array
* @author ? first version * @author ? first version
* @author Bert Vanderkimpen * @author Bert Vanderkimpen
* @return string * @return string
* *
*/ */
public static function file_get_mime_type($filename) public static function file_get_mime_type($filename)
@ -273,12 +273,12 @@ class DocumentManager
} }
/** /**
* @param string * @param string
* @param string * @param string
* @return true if the user is allowed to see the document, false otherwise * @return true if the user is allowed to see the document, false otherwise
* @author Sergio A Kessler, first version * @author Sergio A Kessler, first version
* @author Roan Embrechts, bugfix * @author Roan Embrechts, bugfix
* @todo not only check if a file is visible, but also check if the user is allowed to see the file?? * @todo not only check if a file is visible, but also check if the user is allowed to see the file??
*/ */
public static function file_visible_to_user($this_course, $doc_url) public static function file_visible_to_user($this_course, $doc_url)
{ {
@ -1428,7 +1428,6 @@ class DocumentManager
$www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'; $www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$id = intval($id); $id = intval($id);
$sessionCondition = api_get_session_condition($session_id, true, true); $sessionCondition = api_get_session_condition($session_id, true, true);
$sql = "SELECT * FROM $TABLE_DOCUMENT $sql = "SELECT * FROM $TABLE_DOCUMENT
@ -1512,8 +1511,14 @@ class DocumentManager
* @param int $user_id * @param int $user_id
* @return bool * @return bool
*/ */
public static function set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $image) public static function set_document_as_template(
{ $title,
$description,
$document_id_for_template,
$course_code,
$user_id,
$image
) {
// Database table definition // Database table definition
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES); $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$params = [ $params = [
@ -1565,7 +1570,7 @@ class DocumentManager
* Return true if the documentpath have visibility=1 as * Return true if the documentpath have visibility=1 as
* item_property (you should use the is_visible_by_id) * item_property (you should use the is_visible_by_id)
* *
* @param string $document_path the relative complete path of the document * @param string $doc_path the relative complete path of the document
* @param array $course the _course array info of the document's course * @param array $course the _course array info of the document's course
* @param int * @param int
* @param string * @param string
@ -1911,7 +1916,7 @@ class DocumentManager
$user_id = intval($user_id); $user_id = intval($user_id);
$course_info = api_get_course_info($course_id); $course_info = api_get_course_info($course_id);
// Portal infor // Portal info
$organization_name = api_get_setting('Institution'); $organization_name = api_get_setting('Institution');
$portal_name = api_get_setting('siteName'); $portal_name = api_get_setting('siteName');
@ -2150,11 +2155,11 @@ class DocumentManager
* The list will generally include pictures, flash objects, java applets, or any other * The list will generally include pictures, flash objects, java applets, or any other
* stuff included in the source of the current item. The current item is expected * stuff included in the source of the current item. The current item is expected
* to be an HTML file or string html. If it is not, then the function will return and empty list. * to be an HTML file or string html. If it is not, then the function will return and empty list.
* @param string source html (content or path) * @param string source html (content or path)
* @param bool is file or string html * @param bool is file or string html
* @param string type (one of the app tools) - optional (otherwise takes the current item's type) * @param string type (one of the app tools) - optional (otherwise takes the current item's type)
* @param int level of recursivity we're in * @param int level of recursivity we're in
* @return array List of file paths. An additional field containing 'local' or 'remote' helps determine * @return array List of file paths. An additional field containing 'local' or 'remote' helps determine
* if the file should be copied into the zip or just linked * if the file should be copied into the zip or just linked
*/ */
public static function get_resources_from_source_html($source_html, $is_file = false, $type = null, $recursivity = 1) public static function get_resources_from_source_html($source_html, $is_file = false, $type = null, $recursivity = 1)
@ -2306,7 +2311,12 @@ class DocumentManager
$dir = dirname($abs_path).'/'; $dir = dirname($abs_path).'/';
} }
$new_abs_path = realpath($dir.$second_part); $new_abs_path = realpath($dir.$second_part);
$in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1); $in_files_list[] = self::get_resources_from_source_html(
$new_abs_path,
true,
TOOL_DOCUMENT,
$recursivity + 1
);
if (count($in_files_list) > 0) { if (count($in_files_list) > 0) {
$files_list = array_merge($files_list, $in_files_list); $files_list = array_merge($files_list, $in_files_list);
} }
@ -2331,7 +2341,12 @@ class DocumentManager
if (substr($source, 0, 1) === '/') { if (substr($source, 0, 1) === '/') {
//link starts with a /, making it absolute (relative to DocumentRoot) //link starts with a /, making it absolute (relative to DocumentRoot)
$files_list[] = array($source, 'local', 'abs'); $files_list[] = array($source, 'local', 'abs');
$in_files_list[] = self::get_resources_from_source_html($source, true, TOOL_DOCUMENT, $recursivity + 1); $in_files_list[] = self::get_resources_from_source_html(
$source,
true,
TOOL_DOCUMENT,
$recursivity + 1
);
if (count($in_files_list) > 0) { if (count($in_files_list) > 0) {
$files_list = array_merge($files_list, $in_files_list); $files_list = array_merge($files_list, $in_files_list);
} }
@ -3368,6 +3383,7 @@ class DocumentManager
* @param bool $showInvisibleFiles * @param bool $showInvisibleFiles
* @param bool $showOnlyFolders * @param bool $showOnlyFolders
* @param int $folderId * @param int $folderId
*
* @return string * @return string
*/ */
public static function get_document_preview( public static function get_document_preview(
@ -3814,7 +3830,7 @@ class DocumentManager
$onclick = ''; $onclick = '';
// if in LP, hidden folder are displayed in grey // if in LP, hidden folder are displayed in grey
$folder_class_hidden = ""; $folder_class_hidden = '';
if ($lp_id) { if ($lp_id) {
if (isset($resource['visible']) && $resource['visible'] == 0) { if (isset($resource['visible']) && $resource['visible'] == 0) {
$folder_class_hidden = "doc_folder_hidden"; // in base.css $folder_class_hidden = "doc_folder_hidden"; // in base.css
@ -4026,7 +4042,26 @@ class DocumentManager
// mime_content_type does not detect correctly some formats that are going to be supported for index, so an extensions array is used for the moment // mime_content_type does not detect correctly some formats that are going to be supported for index, so an extensions array is used for the moment
if (empty($doc_mime)) { if (empty($doc_mime)) {
$allowed_extensions = array('doc', 'docx', 'ppt', 'pptx', 'pps', 'ppsx', 'xls', 'xlsx', 'odt', 'odp', 'ods', 'pdf', 'txt', 'rtf', 'msg', 'csv', 'html', 'htm'); $allowed_extensions = array(
'doc',
'docx',
'ppt',
'pptx',
'pps',
'ppsx',
'xls',
'xlsx',
'odt',
'odp',
'ods',
'pdf',
'txt',
'rtf',
'msg',
'csv',
'html',
'htm',
);
$extensions = preg_split("/[\/\\.]/", $doc_path); $extensions = preg_split("/[\/\\.]/", $doc_path);
$doc_ext = strtolower($extensions[count($extensions) - 1]); $doc_ext = strtolower($extensions[count($extensions) - 1]);
if (in_array($doc_ext, $allowed_extensions)) { if (in_array($doc_ext, $allowed_extensions)) {

@ -717,13 +717,17 @@ class learnpath
/** /**
* Static admin function allowing addition of a learnpath to a course. * Static admin function allowing addition of a learnpath to a course.
* @param string Course code * @param string Course code
* @param string Learnpath name * @param string Learnpath name
* @param string Learnpath description string, if provided * @param string Learnpath description string, if provided
* @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
* @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
* @param string Zip file containing the learnpath or directory containing the learnpath * @param string $zipname Zip file containing the learnpath or directory containing the learnpath
* @return integer The new learnpath ID on success, 0 on failure * @param string $publicated_on
* @param string $expired_on
* @param int $categoryId
* @param int $userId
* @return integer The new learnpath ID on success, 0 on failure
*/ */
public static function add_lp( public static function add_lp(
$courseCode, $courseCode,
@ -763,14 +767,6 @@ class learnpath
$res_name = Database::query($check_name); $res_name = Database::query($check_name);
if (empty($publicated_on)) { if (empty($publicated_on)) {
//by default the publication date is the same that the creation date
//The behaviour above was changed due BT#2800
// global $_custom;
// if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) {
// $publicated_on = null;
// } else {
// $publicated_on = null;
// }
$publicated_on = null; $publicated_on = null;
} else { } else {
$publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on)); $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
@ -1084,7 +1080,7 @@ class learnpath
// No other LP uses that directory, delete it. // No other LP uses that directory, delete it.
$course_rel_dir = api_get_course_path().'/scorm/'; // scorm dir web path starting from /courses $course_rel_dir = api_get_course_path().'/scorm/'; // scorm dir web path starting from /courses
$course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // The absolute system path for this course. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // The absolute system path for this course.
if ($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty ($course_scorm_dir)) { if ($delete == 'remove' && is_dir($course_scorm_dir.$path) && !empty ($course_scorm_dir)) {
if ($this->debug > 2) { if ($this->debug > 2) {
error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path, 0); error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path, 0);
} }
@ -1137,8 +1133,8 @@ class learnpath
/** /**
* Removes all the children of one item - dangerous! * Removes all the children of one item - dangerous!
* @param integer $id Element ID of which children have to be removed * @param integer $id Element ID of which children have to be removed
* @return integer Total number of children removed * @return integer Total number of children removed
*/ */
public function delete_children_items($id) public function delete_children_items($id)
{ {
@ -1147,7 +1143,7 @@ class learnpath
error_log('New LP - In learnpath::delete_children_items('.$id.')', 0); error_log('New LP - In learnpath::delete_children_items('.$id.')', 0);
} }
$num = 0; $num = 0;
if (empty ($id) || $id != strval(intval($id))) { if (empty($id) || $id != strval(intval($id))) {
return false; return false;
} }
$lp_item = Database::get_course_table(TABLE_LP_ITEM); $lp_item = Database::get_course_table(TABLE_LP_ITEM);
@ -1164,10 +1160,10 @@ class learnpath
/** /**
* Removes an item from the current learnpath * Removes an item from the current learnpath
* @param integer $id Elem ID (0 if first) * @param integer $id Elem ID (0 if first)
* @param integer $remove Whether to remove the resource/data from the * @param integer $remove Whether to remove the resource/data from the
* system or leave it (default: 'keep', others 'remove') * system or leave it (default: 'keep', others 'remove')
* @return integer Number of elements moved * @return integer Number of elements moved
* @todo implement resource removal * @todo implement resource removal
*/ */
public function delete_item($id, $remove = 'keep') public function delete_item($id, $remove = 'keep')
@ -1177,7 +1173,7 @@ class learnpath
error_log('New LP - In learnpath::delete_item()', 0); error_log('New LP - In learnpath::delete_item()', 0);
} }
// TODO: Implement the resource removal. // TODO: Implement the resource removal.
if (empty ($id) || $id != strval(intval($id))) { if (empty($id) || $id != strval(intval($id))) {
return false; return false;
} }
// First select item to get previous, next, and display order. // First select item to get previous, next, and display order.
@ -1268,10 +1264,10 @@ class learnpath
if ($this->debug > 0) { if ($this->debug > 0) {
error_log('New LP - In learnpath::edit_item()', 0); error_log('New LP - In learnpath::edit_item()', 0);
} }
if (empty ($max_time_allowed)) { if (empty($max_time_allowed)) {
$max_time_allowed = 0; $max_time_allowed = 0;
} }
if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) { if (empty($id) || ($id != strval(intval($id))) || empty($title)) {
return false; return false;
} }
@ -1280,7 +1276,7 @@ class learnpath
$res_select = Database::query($sql_select); $res_select = Database::query($sql_select);
$row_select = Database::fetch_array($res_select); $row_select = Database::fetch_array($res_select);
$audio_update_sql = ''; $audio_update_sql = '';
if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) { if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error'] === 0) {
// Create the audio folder if it does not exist yet. // Create the audio folder if it does not exist yet.
$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
if (!is_dir($filepath.'audio')) { if (!is_dir($filepath.'audio')) {
@ -1428,7 +1424,7 @@ class learnpath
// TODO: htmlspecialchars to be checked for encoding related problems. // TODO: htmlspecialchars to be checked for encoding related problems.
// Update the current item with the new data. // Update the current item with the new data.
$sql = "UPDATE ".$tbl_lp_item." $sql = "UPDATE $tbl_lp_item
SET SET
title = '" . Database::escape_string($title)."', title = '" . Database::escape_string($title)."',
description = '" . Database::escape_string($description)."', description = '" . Database::escape_string($description)."',
@ -1493,12 +1489,12 @@ class learnpath
/** /**
* Updates an item's prereq in place * Updates an item's prereq in place
* @param integer $id Element ID * @param integer $id Element ID
* @param string $prerequisite_id Prerequisite Element ID * @param string $prerequisite_id Prerequisite Element ID
* @param int $mastery_score Prerequisite min score * @param int $mastery_score Prerequisite min score
* @param int $max_score Prerequisite max score * @param int $max_score Prerequisite max score
* *
* @return boolean True on success, false on error * @return boolean True on success, false on error
*/ */
public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
{ {
@ -1507,7 +1503,7 @@ class learnpath
error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')', 0); error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')', 0);
} }
if (empty($id) || ($id != strval(intval($id))) || empty ($prerequisite_id)) { if (empty($id) || ($id != strval(intval($id))) || empty($prerequisite_id)) {
return false; return false;
} }
@ -1546,11 +1542,11 @@ class learnpath
/** /**
* Static admin function exporting a learnpath into a zip file * Static admin function exporting a learnpath into a zip file
* @param string Export type (scorm, zip, cd) * @param string Export type (scorm, zip, cd)
* @param string Course code * @param string Course code
* @param integer Learnpath ID * @param integer Learnpath ID
* @param string Zip file name * @param string Zip file name
* @return string Zip file path (or false on error) * @return string Zip file path (or false on error)
*/ */
public function export_lp($type, $course, $id, $zipname) public function export_lp($type, $course, $id, $zipname)
{ {
@ -1572,8 +1568,8 @@ class learnpath
/** /**
* Gets all the chapters belonging to the same parent as the item/chapter given * Gets all the chapters belonging to the same parent as the item/chapter given
* Can also be called as abstract method * Can also be called as abstract method
* @param integer $id Item ID * @param integer $id Item ID
* @return array A list of all the "brother items" (or an empty array on failure) * @return array A list of all the "brother items" (or an empty array on failure)
*/ */
public function getSiblingDirectories($id) public function getSiblingDirectories($id)
{ {
@ -1617,8 +1613,8 @@ class learnpath
/** /**
* Gets all the items belonging to the same parent as the item given * Gets all the items belonging to the same parent as the item given
* Can also be called as abstract method * Can also be called as abstract method
* @param integer $id Item ID * @param integer $id Item ID
* @return array A list of all the "brother items" (or an empty array on failure) * @return array A list of all the "brother items" (or an empty array on failure)
*/ */
public function get_brother_items($id) public function get_brother_items($id)
{ {
@ -1627,7 +1623,7 @@ class learnpath
error_log('New LP - In learnpath::get_brother_items('.$id.')', 0); error_log('New LP - In learnpath::get_brother_items('.$id.')', 0);
} }
if (empty ($id) || $id != strval(intval($id))) { if (empty($id) || $id != strval(intval($id))) {
return array(); return array();
} }
@ -1707,7 +1703,7 @@ class learnpath
/** /**
* Gets the current item ID * Gets the current item ID
* @return integer The current learnpath item id * @return integer The current learnpath item id
*/ */
public function get_current_item_id() public function get_current_item_id()
{ {
@ -1726,7 +1722,7 @@ class learnpath
/** /**
* Force to get the first learnpath item id * Force to get the first learnpath item id
* @return integer The current learnpath item id * @return integer The current learnpath item id
*/ */
public function get_first_item_id() public function get_first_item_id()
{ {
@ -1739,7 +1735,7 @@ class learnpath
/** /**
* Gets the total number of items available for viewing in this SCORM * Gets the total number of items available for viewing in this SCORM
* @return integer The total number of items * @return integer The total number of items
*/ */
public function get_total_items_count() public function get_total_items_count()
{ {
@ -1751,7 +1747,7 @@ class learnpath
/** /**
* Gets the total number of items available for viewing in this SCORM but without chapters * Gets the total number of items available for viewing in this SCORM but without chapters
* @return integer The total no-chapters number of items * @return integer The total no-chapters number of items
*/ */
public function getTotalItemsCountWithoutDirs() public function getTotalItemsCountWithoutDirs()
{ {
@ -1770,7 +1766,7 @@ class learnpath
/** /**
* Gets the first element URL. * Gets the first element URL.
* @return string URL to load into the viewer * @return string URL to load into the viewer
*/ */
public function first() public function first()
{ {
@ -4435,6 +4431,7 @@ class learnpath
/** /**
* Sets the encoding * Sets the encoding
* @param string New encoding * @param string New encoding
* @return bool
* TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
*/ */
public function set_encoding($enc = 'UTF-8') public function set_encoding($enc = 'UTF-8')
@ -4879,9 +4876,7 @@ class learnpath
} }
$this->publicated_on = !empty($publicated_on) ? api_get_utc_datetime($publicated_on, false, true) : null; $this->publicated_on = !empty($publicated_on) ? api_get_utc_datetime($publicated_on, false, true) : null;
$lp->setPublicatedOn($this->publicated_on); $lp->setPublicatedOn($this->publicated_on);
$em->persist($lp); $em->persist($lp);
$em->flush(); $em->flush();
@ -6849,34 +6844,6 @@ class learnpath
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title']; $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
} }
} }
/*// Commented the prerequisites, only visible in edit (exercise).
$return .= '<tr>';
$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('LearnpathPrerequisites').'</label></td>';
$return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
foreach($arrHide as $key => $value){
if($key==$s_selected_position && $action == 'add'){
$return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
}
elseif($key==$id_prerequisite && $action == 'edit'){
$return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
}
else{
$return .= '<option value="'.$key.'">'.$value['value'].'</option>';
}
}
$return .= "</select></td>";
*/
/*$return .= '<tr>';
$return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
$return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
// Remove temporarily the test description.
//$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
//$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
$return .= '</tr>'; */
} }
if ($action == 'add') { if ($action == 'add') {
@ -7194,7 +7161,10 @@ class learnpath
//$parent_item_id = $_SESSION['parent_item_id']; //$parent_item_id = $_SESSION['parent_item_id'];
for ($i = 0; $i < count($arrLP); $i++) { for ($i = 0; $i < count($arrLP); $i++) {
if ($action != 'add') { if ($action != 'add') {
if ($arrLP[$i]['item_type'] == 'dir' && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) { if ($arrLP[$i]['item_type'] == 'dir' &&
!in_array($arrLP[$i]['id'], $arrHide) &&
!in_array($arrLP[$i]['parent_item_id'], $arrHide)
) {
$selectParent->addOption( $selectParent->addOption(
$arrLP[$i]['title'], $arrLP[$i]['title'],
$arrLP[$i]['id'], $arrLP[$i]['id'],
@ -7621,7 +7591,16 @@ class learnpath
$form->addElement('hidden', 'title'); $form->addElement('hidden', 'title');
} }
$parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', array('id' => 'idParent', 'onchange' => "javascript: load_cbo(this.value);")); $parent_select = $form->addElement(
'select',
'parent',
get_lang('Parent'),
'',
array(
'id' => 'idParent',
'onchange' => "javascript: load_cbo(this.value);",
)
);
foreach ($arrHide as $key => $value) { foreach ($arrHide as $key => $value) {
$parent_select->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"'); $parent_select->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
@ -7843,7 +7822,10 @@ class learnpath
$return .= '</legend>'; $return .= '</legend>';
if (isset($_GET['edit']) && $_GET['edit'] == 'true') { if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
$return .= Display::return_message('<strong>'.get_lang('Warning').' !</strong><br />'.get_lang('WarningEditingDocument'), false); $return .= Display::return_message(
'<strong>'.get_lang('Warning').' !</strong><br />'.get_lang('WarningEditingDocument'),
false
);
} }
$form = new FormValidator( $form = new FormValidator(
'form', 'form',
@ -7895,7 +7877,10 @@ class learnpath
for ($i = 0; $i < count($arrLP); $i++) { for ($i = 0; $i < count($arrLP); $i++) {
if ($action != 'add') { if ($action != 'add') {
if ($arrLP[$i]['item_type'] == 'dir' && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) { if ($arrLP[$i]['item_type'] == 'dir' &&
!in_array($arrLP[$i]['id'], $arrHide) &&
!in_array($arrLP[$i]['parent_item_id'], $arrHide)
) {
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title']; $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
$arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20; $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
if ($parent == $arrLP[$i]['id']) { if ($parent == $arrLP[$i]['id']) {
@ -8707,7 +8692,7 @@ class learnpath
/** /**
* Display the form to allow moving an item * Display the form to allow moving an item
* @param integer Item ID * @param integer $item_id Item ID
* @return string HTML form * @return string HTML form
*/ */
public function display_move_item($item_id) public function display_move_item($item_id)
@ -8727,7 +8712,13 @@ class learnpath
case 'dir': case 'dir':
case 'asset': case 'asset':
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $row['item_type']);
$return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row); $return .= $this->display_item_form(
$row['item_type'],
get_lang('MoveCurrentChapter'),
'move',
$item_id,
$row
);
break; break;
case TOOL_DOCUMENT: case TOOL_DOCUMENT:
$return .= $this->display_manipulate($item_id, $row['item_type']); $return .= $this->display_manipulate($item_id, $row['item_type']);
@ -10361,7 +10352,12 @@ EOD;
$file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc); $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
// Try loading document from the base course. // Try loading document from the base course.
if (empty($file_data) && !empty($sessionId)) { if (empty($file_data) && !empty($sessionId)) {
$file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc, false, 0); $file_data = DocumentManager::get_document_data_by_id(
$item->path,
$this->cc,
false,
0
);
} }
$file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path']; $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
if (file_exists($file_path)) { if (file_exists($file_path)) {
@ -10527,7 +10523,10 @@ EOD;
$max_order = $row_max_order->display_order; $max_order = $row_max_order->display_order;
// Get the previous item ID // Get the previous item ID
$sql = "SELECT id as previous FROM $table_lp_item $sql = "SELECT id as previous FROM $table_lp_item
WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' AND display_order = '".$max_order."' "; WHERE
c_id = $course_id AND
lp_id = '".$this->lp_id."' AND
display_order = '".$max_order."' ";
$rs_max = Database::query($sql); $rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max); $row_max = Database::fetch_object($rs_max);
@ -10556,8 +10555,15 @@ EOD;
//Course restorer //Course restorer
$course_restorer = new CourseRestorer($course); $course_restorer = new CourseRestorer($course);
$course_restorer->set_add_text_in_items(true); $course_restorer->set_add_text_in_items(true);
$course_restorer->set_tool_copy_settings(array('learnpaths' => array('reset_dates' => true))); $course_restorer->set_tool_copy_settings(
$course_restorer->restore(api_get_course_id(), api_get_session_id(), false, false); array('learnpaths' => array('reset_dates' => true))
);
$course_restorer->restore(
api_get_course_id(),
api_get_session_id(),
false,
false
);
} }
public function verify_document_size($s) public function verify_document_size($s)
@ -10895,7 +10901,6 @@ EOD;
public function setCategoryId($categoryId) public function setCategoryId($categoryId)
{ {
$this->categoryId = intval($categoryId); $this->categoryId = intval($categoryId);
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$lp_table = Database::get_course_table(TABLE_LP_MAIN); $lp_table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id(); $lp_id = $this->get_id();
@ -10920,6 +10925,7 @@ EOD;
* Set whether this is a learning path with the possibility to subscribe * Set whether this is a learning path with the possibility to subscribe
* users or not * users or not
* @param int $subscribeUsers (0 = false, 1 = true) * @param int $subscribeUsers (0 = false, 1 = true)
* @return bool
*/ */
public function setSubscribeUsers($value) public function setSubscribeUsers($value)
{ {
@ -11209,6 +11215,7 @@ EOD;
/** /**
* Get the forum for this learning path * Get the forum for this learning path
* @param int $sessionId
* @return boolean * @return boolean
*/ */
public function getForum($sessionId = 0) public function getForum($sessionId = 0)
@ -11672,9 +11679,10 @@ EOD;
* Gets the name of a resource (generally used in learnpath when no name is provided) * Gets the name of a resource (generally used in learnpath when no name is provided)
* *
* @author Yannick Warnier <ywarnier@beeznest.org> * @author Yannick Warnier <ywarnier@beeznest.org>
* @param string Course code * @param string Course code
* @param string The tool type (using constants declared in main_api.lib.php) * @param string The tool type (using constants declared in main_api.lib.php)
* @param integer The resource ID * @param integer The resource ID
* @return string
*/ */
public static function rl_get_resource_name($course_code, $learningPathId, $id_in_path) public static function rl_get_resource_name($course_code, $learningPathId, $id_in_path)
{ {

@ -4,7 +4,7 @@
/** /**
* Defines the scorm class, which is meant to contain the scorm items (nuclear elements) * Defines the scorm class, which is meant to contain the scorm items (nuclear elements)
* @package chamilo.learnpath * @package chamilo.learnpath
* @author Yannick Warnier <ywarnier@beeznest.org> * @author Yannick Warnier <ywarnier@beeznest.org>
*/ */
class scorm extends learnpath class scorm extends learnpath
{ {
@ -32,9 +32,9 @@ class scorm extends learnpath
/** /**
* Class constructor. Based on the parent constructor. * Class constructor. Based on the parent constructor.
* @param string Course code * @param string Course code
* @param integer Learnpath ID in DB * @param integer Learnpath ID in DB
* @param integer User ID * @param integer User ID
*/ */
public function __construct($course_code = null, $resource_id = null, $user_id = null) public function __construct($course_code = null, $resource_id = null, $user_id = null)
{ {
@ -47,7 +47,7 @@ class scorm extends learnpath
/** /**
* Opens a resource * Opens a resource
* @param integer $id Database ID of the resource * @param integer $id Database ID of the resource
*/ */
public function open($id) public function open($id)
{ {
@ -78,18 +78,14 @@ class scorm extends learnpath
} }
if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) { if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) {
// Parsing using PHP5 DOMXML methods. // Parsing using PHP5 DOMXML methods.
if ($this->debug > 0) { error_log('In scorm::parse_manifest() - Parsing using PHP5 method', 0); } if ($this->debug > 0) { error_log('In scorm::parse_manifest() - Parsing using PHP5 method', 0); }
//$this->manifest_encoding = api_detect_encoding_xml($xml); // This is the usual way for reading the encoding. //$this->manifest_encoding = api_detect_encoding_xml($xml); // This is the usual way for reading the encoding.
// This method reads the encoding, it tries to be correct even in cases of wrong or missing encoding declarations. // This method reads the encoding, it tries to be correct even in cases of wrong or missing encoding declarations.
$this->manifest_encoding = self::detect_manifest_encoding($xml); $this->manifest_encoding = self::detect_manifest_encoding($xml);
// UTF-8 is supported by DOMDocument class, this is for sure. // UTF-8 is supported by DOMDocument class, this is for sure.
$xml = api_utf8_encode_xml($xml, $this->manifest_encoding); $xml = api_utf8_encode_xml($xml, $this->manifest_encoding);
$doc = new DOMDocument(); $doc = new DOMDocument();
$res = @$doc->loadXML($xml); $res = @$doc->loadXML($xml);
if ($res === false) { if ($res === false) {
@ -213,9 +209,7 @@ class scorm extends learnpath
} }
} }
unset($doc); unset($doc);
// End parsing using PHP5 DOMXML methods. // End parsing using PHP5 DOMXML methods.
} else { } else {
if ($this->debug > 1) { error_log('New LP - Could not open/read file '.$file, 0); } if ($this->debug > 1) { error_log('New LP - Could not open/read file '.$file, 0); }
$this->set_error_msg("File $file could not be read"); $this->set_error_msg("File $file could not be read");
@ -271,7 +265,7 @@ class scorm extends learnpath
* @param int $userMaxScore * @param int $userMaxScore
* @param int $sessionId * @param int $sessionId
* *
* @return bool Returns -1 on error * @return bool Returns -1 on error
*/ */
public function import_manifest($courseCode, $userMaxScore = 1, $sessionId = 0, $userId = 0) public function import_manifest($courseCode, $userMaxScore = 1, $sessionId = 0, $userId = 0)
{ {
@ -518,9 +512,9 @@ class scorm extends learnpath
/** /**
* Intermediate to import_package only to allow import from local zip files * Intermediate to import_package only to allow import from local zip files
* @param string Path to the zip file, from the sys root * @param string Path to the zip file, from the sys root
* @param string Current path (optional) * @param string Current path (optional)
* @return string Absolute path to the imsmanifest.xml file or empty string on error * @return string Absolute path to the imsmanifest.xml file or empty string on error
*/ */
public function import_local_package($file_path, $current_dir = '') public function import_local_package($file_path, $current_dir = '')
{ {
@ -534,11 +528,11 @@ class scorm extends learnpath
/** /**
* Imports a zip file into the Chamilo structure * 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 string
* @param array * @param array
* *
* @return string $current_dir Absolute path to the imsmanifest.xml file or empty string on error * @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 = '', $courseInfo = array()) public function import_package($zip_file_info, $current_dir = '', $courseInfo = array())
{ {
@ -628,7 +622,6 @@ class scorm extends learnpath
if ($package_type == '') { if ($package_type == '') {
// && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM) // && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM)
if ($this->debug > 1) { error_log('New LP - Package type is empty', 0); } if ($this->debug > 1) { error_log('New LP - Package type is empty', 0); }
Display::addFlash( Display::addFlash(
Display::return_message(get_lang('NotScormContent')) Display::return_message(get_lang('NotScormContent'))
); );
@ -665,7 +658,6 @@ class scorm extends learnpath
if (is_dir($course_sys_dir.$new_dir) || if (is_dir($course_sys_dir.$new_dir) ||
@mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories()) @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories())
) { ) {
// PHP method - slower... // PHP method - slower...
if ($this->debug >= 1) { error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir, 0); } if ($this->debug >= 1) { error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir, 0); }
$saved_dir = getcwd(); $saved_dir = getcwd();
@ -743,7 +735,7 @@ class scorm extends learnpath
/** /**
* Sets the proximity setting in the database * Sets the proximity setting in the database
* @param string Proximity setting * @param string Proximity setting
* @param int $courseId * @param int $courseId
*/ */
public function set_proximity($proxy = '', $courseId = null) public function set_proximity($proxy = '', $courseId = null)
@ -764,7 +756,7 @@ class scorm extends learnpath
/** /**
* Sets the theme setting in the database * Sets the theme setting in the database
* @param string theme setting * @param string theme setting
*/ */
public function set_theme($theme = '') public function set_theme($theme = '')
{ {
@ -783,7 +775,7 @@ class scorm extends learnpath
/** /**
* Sets the image setting in the database * Sets the image setting in the database
* @param string preview_image setting * @param string preview_image setting
*/ */
public function set_preview_image($preview_image = '') public function set_preview_image($preview_image = '')
{ {
@ -802,7 +794,7 @@ class scorm extends learnpath
/** /**
* Sets the author setting in the database * Sets the author setting in the database
* @param string preview_image setting * @param string preview_image setting
*/ */
public function set_author($author = '') public function set_author($author = '')
{ {
@ -821,7 +813,7 @@ class scorm extends learnpath
/** /**
* Sets the content maker setting in the database * Sets the content maker setting in the database
* @param string Proximity setting * @param string Proximity setting
*/ */
public function set_maker($maker = '', $courseId = null) public function set_maker($maker = '', $courseId = null)
{ {
@ -840,8 +832,9 @@ class scorm extends learnpath
} }
/** /**
* Exports the current SCORM object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath() * Exports the current SCORM object's files as a zip.
* @param integer Learnpath ID (optional, taken from object context if not defined) * Excerpts taken from learnpath_functions.inc.php::exportpath()
* @param integer Learnpath ID (optional, taken from object context if not defined)
*/ */
public function export_zip($lp_id = null) public function export_zip($lp_id = null)
{ {
@ -877,11 +870,9 @@ class scorm extends learnpath
$zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip'; $zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip';
// Get a temporary dir for creating the zip file. // Get a temporary dir for creating the zip file.
//error_log('New LP - cleaning dir '.$zipfoldername, 0); //error_log('New LP - cleaning dir '.$zipfoldername, 0);
my_delete($zipfoldername); // Make sure the temp dir is cleared. my_delete($zipfoldername); // Make sure the temp dir is cleared.
mkdir($zipfoldername, api_get_permissions_for_new_directories()); mkdir($zipfoldername, api_get_permissions_for_new_directories());
//error_log('New LP - made dir '.$zipfoldername, 0);
// Create zipfile of given directory. // Create zipfile of given directory.
$zip_folder = new PclZip($zipfilename); $zip_folder = new PclZip($zipfilename);

@ -308,7 +308,6 @@ class SurveyUtil
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER); $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0; $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
// Actions bar // Actions bar
@ -475,8 +474,8 @@ class SurveyUtil
* You can then click on the name of the person and you will then go to the report by user where you see all the * You can then click on the name of the person and you will then go to the report by user where you see all the
* answers of that user. * answers of that user.
* *
* @param array All the survey data * @param array All the survey data
* @return string html code that displays the report by question * @return string html code that displays the report by question
* @todo allow switching between horizontal and vertical. * @todo allow switching between horizontal and vertical.
* @todo multiple response: percentage are probably not OK * @todo multiple response: percentage are probably not OK
* @todo the question and option text have to be shortened and should expand when the user clicks on it. * @todo the question and option text have to be shortened and should expand when the user clicks on it.
@ -695,9 +694,9 @@ class SurveyUtil
/** /**
* Display score data about a survey question * Display score data about a survey question
* @param array Question info * @param array Question info
* @param integer The offset of results shown * @param integer The offset of results shown
* @return void (direct output) * @return void (direct output)
*/ */
public static function display_question_report_score($survey_data, $question, $offset) public static function display_question_report_score($survey_data, $question, $offset)
{ {
@ -839,8 +838,7 @@ class SurveyUtil
// Getting the number of options per question // Getting the number of options per question
echo ' <tr>'; echo ' <tr>';
echo ' <th>'; echo ' <th>';
if ( if ((isset($_POST['submit_question_filter']) && $_POST['submit_question_filter']) ||
(isset($_POST['submit_question_filter']) && $_POST['submit_question_filter']) ||
(isset($_POST['export_report']) && $_POST['export_report']) (isset($_POST['export_report']) && $_POST['export_report'])
) { ) {
echo '<button class="cancel" type="submit" name="reset_question_filter" value="'.get_lang('ResetQuestionFilter').'">'.get_lang('ResetQuestionFilter').'</button>'; echo '<button class="cancel" type="submit" name="reset_question_filter" value="'.get_lang('ResetQuestionFilter').'">'.get_lang('ResetQuestionFilter').'</button>';
@ -1024,10 +1022,10 @@ class SurveyUtil
* This function displays a row (= a user and his/her answers) in the table of the complete report. * This function displays a row (= a user and his/her answers) in the table of the complete report.
* *
* @param array $survey_data * @param array $survey_data
* @param array Possible options * @param array Possible options
* @param array User answers * @param array User answers
* @param mixed User ID or user details string * @param mixed User ID or user details string
* @param boolean Whether to show extra user fields or not * @param boolean Whether to show extra user fields or not
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007 - Updated March 2008 * @version February 2007 - Updated March 2008
*/ */
@ -1060,7 +1058,13 @@ class SurveyUtil
if ($display_extra_user_fields) { if ($display_extra_user_fields) {
// Show user fields data, if any, for this user // Show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data(intval($user), false, false, false, true); $user_fields_values = UserManager::get_extra_user_data(
intval($user),
false,
false,
false,
true
);
foreach ($user_fields_values as & $value) { foreach ($user_fields_values as & $value) {
echo '<td align="center">'.$value.'</td>'; echo '<td align="center">'.$value.'</td>';
} }
@ -1080,18 +1084,16 @@ class SurveyUtil
echo $answers_of_user[$question_id][$option_id]['value']; echo $answers_of_user[$question_id][$option_id]['value'];
echo "</td>"; echo "</td>";
} }
} } else {
else {
echo '<td align="center">'; echo '<td align="center">';
if (!empty($answers_of_user[$question_id][$option_id])) { if (!empty($answers_of_user[$question_id][$option_id])) {
if ($answers_of_user[$question_id][$option_id]['value'] != 0) { if ($answers_of_user[$question_id][$option_id]['value'] != 0) {
echo $answers_of_user[$question_id][$option_id]['value']; echo $answers_of_user[$question_id][$option_id]['value'];
} } else {
else {
echo 'v'; echo 'v';
} }
} }
} // </hub> }
} }
} }
} }
@ -1103,7 +1105,7 @@ class SurveyUtil
* Quite similar to display_complete_report(), returns an HTML string * Quite similar to display_complete_report(), returns an HTML string
* that can be used in a csv file * that can be used in a csv file
* @todo consider merging this function with display_complete_report * @todo consider merging this function with display_complete_report
* @return string The contents of a csv file * @return string The contents of a csv file
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007 * @version February 2007
*/ */
@ -1820,9 +1822,8 @@ class SurveyUtil
} }
$tableHtml .= '</tr>'; $tableHtml .= '</tr>';
} }
} } else {
// The Y axis is NOT a score question type so the number of rows = the number of options // The Y axis is NOT a score question type so the number of rows = the number of options
else {
$tableHtml .= '<tr>'; $tableHtml .= '<tr>';
for ($ii = 0; $ii <= count($question_x['answers']); $ii++) { for ($ii = 0; $ii <= count($question_x['answers']); $ii++) {
if ($question_x['type'] == 'score') { if ($question_x['type'] == 'score') {
@ -2106,7 +2107,6 @@ class SurveyUtil
$counter = 0; // Nr of invitations "sent" (if sendmail option) $counter = 0; // Nr of invitations "sent" (if sendmail option)
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$result = CourseManager::separateUsersGroups($users_array); $result = CourseManager::separateUsersGroups($users_array);
$groupList = $result['groups']; $groupList = $result['groups'];
@ -2156,7 +2156,6 @@ class SurveyUtil
$new_user = false; // User not already invited $new_user = false; // User not already invited
// Store the invitation if user_id not in $already_invited['course_users'] OR email is not in $already_invited['additional_users'] // Store the invitation if user_id not in $already_invited['course_users'] OR email is not in $already_invited['additional_users']
$addit_users_array = isset($already_invited['additional_users']) && !empty($already_invited['additional_users']) ? explode(';', $already_invited['additional_users']) : array(); $addit_users_array = isset($already_invited['additional_users']) && !empty($already_invited['additional_users']) ? explode(';', $already_invited['additional_users']) : array();
$my_alredy_invited = $already_invited['course_users'] == null ? array() : $already_invited['course_users']; $my_alredy_invited = $already_invited['course_users'] == null ? array() : $already_invited['course_users'];
if ((is_numeric($value) && !in_array($value, $my_alredy_invited)) || if ((is_numeric($value) && !in_array($value, $my_alredy_invited)) ||
(!is_numeric($value) && !in_array($value, $addit_users_array)) (!is_numeric($value) && !in_array($value, $addit_users_array))
@ -2205,7 +2204,6 @@ class SurveyUtil
) { ) {
$insertId = Database::insert($table, $params); $insertId = Database::insert($table, $params);
if ($insertId) { if ($insertId) {
$sql = "UPDATE $table SET survey_invitation_id = $insertId $sql = "UPDATE $table SET survey_invitation_id = $insertId
WHERE iid = $insertId"; WHERE iid = $insertId";
Database::query($sql); Database::query($sql);
@ -2736,6 +2734,7 @@ class SurveyUtil
FROM ".$table_survey.' '.$search_restriction; FROM ".$table_survey.' '.$search_restriction;
$res = Database::query($sql); $res = Database::query($sql);
$obj = Database::fetch_object($res); $obj = Database::fetch_object($res);
return $obj->total_number_of_items; return $obj->total_number_of_items;
} }

Loading…
Cancel
Save