diff --git a/main/exercise/exercise_submit.php b/main/exercise/exercise_submit.php index f7571aaa00..51e206cf32 100755 --- a/main/exercise/exercise_submit.php +++ b/main/exercise/exercise_submit.php @@ -4,29 +4,29 @@ use ChamiloSession as Session; /** -* Exercise submission -* 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. -* -* One exercise may contain different types of answers (unique or multiple selection, -* matching, fill in blanks, free answer, hot-spot). -* -* Questions are selected randomly or not. -* -* When the user has answered all questions and clicks on the button "Ok", -* it goes to exercise_result.php -* -* Notice : This script is also used to show a question before modifying it by -* the administrator -* @package chamilo.exercise -* @author Olivier Brouckaert -* @author Julio Montoya -* Fill in blank option added (2008) -* Cleaning exercises (2010), -* Adding hotspot delineation support (2011) -* Adding reminder + ajax support (2011) -* Modified by hubert.borderiou (2011-10-21 question category) -*/ + * Exercise submission + * 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. + * + * One exercise may contain different types of answers (unique or multiple selection, + * matching, fill in blanks, free answer, hot-spot). + * + * Questions are selected randomly or not. + * + * When the user has answered all questions and clicks on the button "Ok", + * it goes to exercise_result.php + * + * Notice : This script is also used to show a question before modifying it by + * the administrator + * @package chamilo.exercise + * @author Olivier Brouckaert + * @author Julio Montoya + * Fill in blank option added (2008) + * Cleaning exercises (2010), + * Adding hotspot delineation support (2011) + * Adding reminder + ajax support (2011) + * Modified by hubert.borderiou (2011-10-21 question category) + */ require_once __DIR__.'/../inc/global.inc.php'; $current_course_tool = TOOL_QUIZ; @@ -117,33 +117,43 @@ if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSessi // Construction of Exercise $objExercise = new Exercise(); 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'); // if the specified exercise doesn't exist or is disabled if (!$objExercise->read($exerciseId) || (!$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); $error = get_lang('ExerciseNotFound'); } else { // Saves the object into the session 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 { Session::write('firstTime', false); } //2. Checking if $objExercise is set 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; } //3. $objExercise is not set, then return to the exercise list 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'); exit; } @@ -313,7 +323,9 @@ Session::write('question_list_uncompressed', $questionListUncompressed); $clock_expired_time = null; 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; $questionList = $objExercise->get_validated_question_list(); foreach ($questionListUncompressed as $question_id) { @@ -321,19 +333,28 @@ if (empty($exercise_stat_info)) { $total_weight += floatval($objQuestionTmp->weighting); } - if ($time_control) { - $expected_time = $current_timestamp + $total_seconds; - - if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); - if ($debug) error_log('5.2. $expected_time '.$expected_time); + if ($time_control) { + $expected_time = $current_timestamp + $total_seconds; + if ($debug) { + error_log('5.1. $current_timestamp '.$current_timestamp); + } + if ($debug) { + error_log('5.2. $expected_time '.$expected_time); + } - $clock_expired_time = api_get_utc_datetime($expected_time); - if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); + $clock_expired_time = api_get_utc_datetime($expected_time); + if ($debug) { + error_log('5.3. $expected_time '.$clock_expired_time); + } - //Sessions that contain the 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]); }; - } + //Sessions that contain the 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] + ); + }; + } $exe_id = $objExercise->save_stat_track_exercise_info( $clock_expired_time, @@ -348,9 +369,11 @@ if (empty($exercise_stat_info)) { $learnpath_item_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 { - $exe_id = $exercise_stat_info['exe_id']; + $exe_id = $exercise_stat_info['exe_id']; // Remember last question id position. $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'); @@ -407,21 +432,32 @@ if (!isset($questionListInSession)) { // Array to check in order to block the chat 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'])) { - $my_remind_list = $exercise_stat_info['questions_to_check']; - $my_remind_list = explode(',', $my_remind_list); - $my_remind_list = array_filter($my_remind_list); + $my_remind_list = $exercise_stat_info['questions_to_check']; + $my_remind_list = explode(',', $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(); -if ($debug) { error_log("6.1 params: -> $params"); }; +if ($debug) { + error_log("6.1 params: -> $params"); +} if ($reminder == 2 && empty($my_remind_list)) { - if ($debug) { error_log("6.2 calling the exercise_reminder.php "); }; - header('Location: exercise_reminder.php?'.$params); - exit; + if ($debug) { + error_log("6.2 calling the exercise_reminder.php "); + }; + 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 ($time_control) { - 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.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]); + 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.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]); if (!isset($_SESSION['expired_time'][$current_expired_time_key])) { //Timer - Get expired_time for a student if (!empty($exercise_stat_info)) { - 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']; - if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } - // Get the last attempt of an exercise - $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']); - - /* 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 - the track_et_attempt see #2069 */ - if (empty($last_attempt_date)) { - $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); - } else { - //Recalculate the time control due #2069 - $diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC'); - $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); } - - //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'); - 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; - if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } - - $clock_expired_time = api_get_utc_datetime($expected_time); - if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } - - // First we update the attempt to today - /* How the expired time is changed into "track_e_exercises" table, + 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']; + if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } + // Get the last attempt of an exercise + $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']); + + /* 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 + the track_et_attempt see #2069 */ + if (empty($last_attempt_date)) { + $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); + } else { + //Recalculate the time control due #2069 + $diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC'); + $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); } + + //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'); + 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; + if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } + + $clock_expired_time = api_get_utc_datetime($expected_time); + if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } + + // First we update the attempt to today + /* How the expired time is changed into "track_e_exercises" table, then the last attempt for this student should be changed too */ - $sql = "UPDATE $exercise_attempt_table SET - tms = '".api_get_utc_datetime()."' - WHERE - exe_id = '".$exercise_stat_info['exe_id']."' AND - tms = '".$last_attempt_date."' "; - if ($debug) {error_log('7.10. $sql: '.$sql); } - Database::query($sql); - - //Sessions that contain the 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]); }; + $sql = "UPDATE $exercise_attempt_table SET + tms = '".api_get_utc_datetime()."' + WHERE + exe_id = '".$exercise_stat_info['exe_id']."' AND + tms = '".$last_attempt_date."' "; + if ($debug) {error_log('7.10. $sql: '.$sql); } + Database::query($sql); + + //Sessions that contain the 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]); }; } } else { $clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key]; } } else { - if ($debug) { error_log("7 No time control"); }; + if ($debug) { + error_log("7 No time control"); + } } // 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 */ 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? @@ -503,22 +541,24 @@ if (!isset($_SESSION['questionList'])) { // selects the list of question ID $questionList = $objExercise->get_validated_question_list(); 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); if ($debug > 0) { error_log('$_SESSION[questionList] was set'); } } else { - if (isset($objExercise) && isset($_SESSION['objExercise'])) { - $questionList = $_SESSION['questionList']; - } + if (isset($objExercise) && isset($_SESSION['objExercise'])) { + $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 $question_count = 0; if (!empty($questionList)) { - $question_count = count($questionList); + $question_count = count($questionList); } if ($current_question > $question_count) { @@ -568,11 +608,11 @@ if ($formSent && isset($_POST)) { //saving each question if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) { $nro_question = $current_question; // - 1; - $questionId = $key; + $questionId = $key; // gets the student choice for this question $choice = $exerciseResult[$questionId]; if (isset($exe_id)) { - // Manage the question and answer attempts + // Manage the question and answer attempts if ($debug) { 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++; } - if ($question_count != 0) { - if (($objExercise->type == ALL_ON_ONE_PAGE || + if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question > $question_count) ) { - if (api_is_allowed_to_session_edit()) { - // goes to the script that will show the result of the exercise - if ($objExercise->type == ALL_ON_ONE_PAGE) { - 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 - if ($objExercise->selectAttempts() > 0) { - $attempt_count = Event::get_attempt_count( + if (api_is_allowed_to_session_edit()) { + // goes to the script that will show the result of the exercise + if ($objExercise->type == ALL_ON_ONE_PAGE) { + 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 + if ($objExercise->selectAttempts() > 0) { + $attempt_count = Event::get_attempt_count( api_get_user_id(), $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id ); - if ($attempt_count >= $objExercise->selectAttempts()) { - Display::return_message( + if ($attempt_count >= $objExercise->selectAttempts()) { + Display::return_message( sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false ); - if ($origin != 'learnpath') { - //so we are not in learnpath tool - echo ''; //End glossary div - Display :: display_footer(); - } else { - echo ''; - } - exit; - } - } - } else { - if ($objExercise->review_answers) { - header('Location: exercise_reminder.php?'.$params); - exit; - } else { + if ($origin != 'learnpath') { + //so we are not in learnpath tool + echo ''; //End glossary div + Display :: display_footer(); + } else { + echo ''; + } + exit; + } + } + } else { + if ($objExercise->review_answers) { + header('Location: exercise_reminder.php?'.$params); + exit; + } 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"); exit; - } - } - } else { - if ($debug) { error_log('Redirecting to exercise_submit.php'); } - exit; - } - } + } + } + } else { + if ($debug) { error_log('Redirecting to exercise_submit.php'); } + exit; + } + } } else { - $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 ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) { - $error .= "
".get_lang('PleaseSelectSomeRandomQuestion'); - } + $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 ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) { + $error .= "
".get_lang('PleaseSelectSomeRandomQuestion'); + } } 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') { echo ''; } @@ -804,7 +843,7 @@ if ($limit_time_exists) { $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet'); echo Display::return_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()), 'warning'); if ($origin != 'learnpath') { - Display :: display_footer(); + Display :: display_footer(); } exit; } else { @@ -819,7 +858,7 @@ global $_custom; if (isset($_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( sprintf( get_lang('ExerciseNoStartedYet'), @@ -828,16 +867,16 @@ if (isset($_custom['exercises_hidden_when_no_start_date']) && ), 'warning' ); - if ($origin != 'learnpath') { - Display :: display_footer(); - } - } + if ($origin != 'learnpath') { + Display :: display_footer(); + } + } } //Timer control if ($time_control) { echo $objExercise->return_time_left_div(); - echo ''; + echo ''; } if ($origin != 'learnpath') { @@ -852,53 +891,51 @@ if ($reminder == 2) { $current_question = 1; //set by default the 1st question if (!empty($my_remind_list)) { - //Checking which questions we are going to call from the remind list - for ($i = 0; $i < count($data_tracking); $i++) { - for ($j = 0; $j < count($my_remind_list); $j++) { - - if (!empty($remind_question_id)) { - if ($remind_question_id == $my_remind_list[$j]) { - - if ($remind_question_id == $data_tracking[$i]) { - if (isset($my_remind_list[$j + 1])) { - $remind_question_id = $my_remind_list[$j + 1]; - $current_question = $i + 1; - } else { + //Checking which questions we are going to call from the remind list + for ($i = 0; $i < count($data_tracking); $i++) { + for ($j = 0; $j < count($my_remind_list); $j++) { + if (!empty($remind_question_id)) { + if ($remind_question_id == $my_remind_list[$j]) { + if ($remind_question_id == $data_tracking[$i]) { + if (isset($my_remind_list[$j + 1])) { + $remind_question_id = $my_remind_list[$j + 1]; + $current_question = $i + 1; + } else { // We end the remind list we go to the exercise_reminder.php please - $remind_question_id = -1; - $current_question = $i + 1; // last question - } - break 2; - } - } - } else { - if ($my_remind_list[$j] == $data_tracking[$i]) { - if (isset($my_remind_list[$j + 1])) { - $remind_question_id = $my_remind_list[$j + 1]; - $current_question = $i + 1; // last question - } else { + $remind_question_id = -1; + $current_question = $i + 1; // last question + } + break 2; + } + } + } else { + if ($my_remind_list[$j] == $data_tracking[$i]) { + if (isset($my_remind_list[$j + 1])) { + $remind_question_id = $my_remind_list[$j + 1]; + $current_question = $i + 1; // last question + } else { // We end the remind list we go to the exercise_reminder.php please - $remind_question_id = -1; - $current_question = $i + 1; // last question - } - break 2; - } - } - } + $remind_question_id = -1; + $current_question = $i + 1; // last question + } + break 2; + } + } + } } } else { - if ($objExercise->review_answers) { + if ($objExercise->review_answers) { if ($debug) { error_log('. redirecting to exercise_reminder.php '); } - header("Location: exercise_reminder.php?$params"); - exit; - } + header("Location: exercise_reminder.php?$params"); + exit; + } } } if ($objExercise->review_answers) { - $script_php = 'exercise_reminder.php'; + $script_php = 'exercise_reminder.php'; } else { - $script_php = 'exercise_result.php'; + $script_php = 'exercise_result.php'; } if (!empty($error)) { @@ -1022,10 +1059,10 @@ if (!empty($error)) { }); }); - function previous_question(question_num) { - url = "exercise_submit.php?'.$params.'&num="+question_num; - window.location = url; - } + function previous_question(question_num) { + url = "exercise_submit.php?'.$params.'&num="+question_num; + window.location = url; + } function previous_question_and_save(previous_question_id, question_id_to_save) { url = "exercise_submit.php?'.$params.'&num="+previous_question_id; @@ -1180,7 +1217,7 @@ if (!empty($error)) { '; - // Show list of questions + // Show list of questions $i = 1; $attempt_list = []; if (isset($exe_id)) { @@ -1240,10 +1277,10 @@ if (!empty($error)) { $attributes = array('id' =>'remind_list['.$questionId.']'); if (in_array($questionId, $remind_list)) { - $is_remind_on = true; - $attributes['checked'] = 1; - $remind_question = true; - $remind_highlight = ' remind_highlight '; + $is_remind_on = true; + $attributes['checked'] = 1; + $remind_question = true; + $remind_highlight = ' remind_highlight '; } // Showing the exercise description @@ -1326,8 +1363,8 @@ if (!empty($error)) { } // end foreach() if ($objExercise->type == ALL_ON_ONE_PAGE) { - $exercise_actions = $objExercise->show_button($questionId, $current_question); - echo Display::div($exercise_actions, array('class'=>'exercise_actions')); + $exercise_actions = $objExercise->show_button($questionId, $current_question); + echo Display::div($exercise_actions, array('class'=>'exercise_actions')); echo '
'; } echo ''; diff --git a/main/exercise/question_pool.php b/main/exercise/question_pool.php index 638001a135..b9113a4445 100755 --- a/main/exercise/question_pool.php +++ b/main/exercise/question_pool.php @@ -2,14 +2,14 @@ /* For licensing terms, see /license.txt */ /** -* Question Pool -* This script allows administrators to manage questions and add them into their exercises. -* One question can be in several exercises -* @package chamilo.exercise -* @author Olivier Brouckaert -* @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 -*/ + * Question Pool + * This script allows administrators to manage questions and add them into their exercises. + * One question can be in several exercises + * @package chamilo.exercise + * @author Olivier Brouckaert + * @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 + */ use ChamiloSession as Session; @@ -119,7 +119,7 @@ if ($is_allowedToEdit) { // destruction of the Question object unset($objQuestionTmp); - if (!$objExercise instanceOf Exercise) { + if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } @@ -160,7 +160,7 @@ if ($is_allowedToEdit) { unset($new_question_obj); unset($old_question_obj); - if (!$objExercise instanceOf Exercise) { + if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } @@ -172,11 +172,11 @@ if ($is_allowedToEdit) { } if (isset($_SESSION['gradebook'])) { - $gradebook = $_SESSION['gradebook']; + $gradebook = $_SESSION['gradebook']; } 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 @@ -188,21 +188,21 @@ $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), $htmlHeadXtra[] = " "; Display::display_header($nameTools, 'Exercise'); @@ -227,8 +227,8 @@ if (isset($fromExercise) && $fromExercise > 0) { echo ''; if ($displayMessage != "") { - Display::display_confirmation_message($displayMessage); - $displayMessage = ""; + Display::display_confirmation_message($displayMessage); + $displayMessage = ""; } // Form @@ -236,7 +236,7 @@ echo '
'; + echo ''; } echo ''; @@ -283,11 +283,11 @@ $course_select_list = array(); foreach ($course_list as $item) { $courseItemId = $item['real_id']; $courseInfo = api_get_course_info_by_id($courseItemId); - $course_select_list[$courseItemId] = ""; - if ($courseItemId == api_get_course_int_id()) { - $course_select_list[$courseItemId] = ">    "; - } - $course_select_list[$courseItemId] .= $courseInfo['title']; + $course_select_list[$courseItemId] = ""; + if ($courseItemId == api_get_course_int_id()) { + $course_select_list[$courseItemId] = ">    "; + } + $course_select_list[$courseItemId] .= $courseInfo['title']; } $select_course_html = Display::select( @@ -304,11 +304,11 @@ if (empty($selected_course) || $selected_course == '-1') { // no course selected, reset menu test / difficult� / type de reponse reset_menu_exo_lvl_type(); } 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_id_changed) { - reset_menu_exo_lvl_type(); + reset_menu_exo_lvl_type(); } $course_id = $course_info['real_id']; @@ -356,7 +356,7 @@ if (is_array($exercise_list)) { } if ($exercise_id_changed == 1) { - reset_menu_lvl_type(); + reset_menu_lvl_type(); } $select_exercise_html = Display::select( 'exerciseId', @@ -434,33 +434,33 @@ $mainQuestionList = array(); // if we have selected an exercise in the list-box 'Filter' if ($exerciseId > 0) { - $where = ''; - $from = ''; - if (isset($courseCategoryId) && $courseCategoryId > 0) { - $from = ", $TBL_COURSE_REL_CATEGORY crc "; - $where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId"; - } - if (isset($exerciseLevel) && $exerciseLevel != -1) { - $where .= ' AND level='.$exerciseLevel; - } - if (isset($answerType) && $answerType > 0) { - $where .= ' AND type='.$answerType; - } - $sql = "SELECT DISTINCT - id, - question, - type, - level - FROM - $TBL_EXERCISE_QUESTION qt, - $TBL_QUESTIONS qu - $from - WHERE - qt.question_id = qu.id - AND qt.exercice_id=$exerciseId - AND qt.c_id=$selected_course - AND qu.c_id=$selected_course - $where + $where = ''; + $from = ''; + if (isset($courseCategoryId) && $courseCategoryId > 0) { + $from = ", $TBL_COURSE_REL_CATEGORY crc "; + $where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId"; + } + if (isset($exerciseLevel) && $exerciseLevel != -1) { + $where .= ' AND level='.$exerciseLevel; + } + if (isset($answerType) && $answerType > 0) { + $where .= ' AND type='.$answerType; + } + $sql = "SELECT DISTINCT + id, + question, + type, + level + FROM + $TBL_EXERCISE_QUESTION qt, + $TBL_QUESTIONS qu + $from + WHERE + qt.question_id = qu.id + AND qt.exercice_id=$exerciseId + AND qt.c_id=$selected_course + AND qu.c_id=$selected_course + $where ORDER BY question_order"; $result = Database::query($sql); @@ -468,22 +468,22 @@ if ($exerciseId > 0) { $mainQuestionList[] = $row; } } elseif ($exerciseId == -1) { - // If we have selected the option 'Orphan questions' in the list-box 'Filter' - $level_where = ''; - $from = ''; - 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 "; - $level_where .= " AND - crc.c_id = $selected_course AND - crc.category_id = $courseCategoryId"; - } - if (isset($exerciseLevel) && $exerciseLevel != -1) { - $level_where = ' AND level='.$exerciseLevel; - } - $answer_where = ''; - if (isset($answerType) && $answerType > 0 - 1) { - $answer_where = ' AND type='.$answerType; - } + // If we have selected the option 'Orphan questions' in the list-box 'Filter' + $level_where = ''; + $from = ''; + 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 "; + $level_where .= " AND + crc.c_id = $selected_course AND + crc.category_id = $courseCategoryId"; + } + if (isset($exerciseLevel) && $exerciseLevel != -1) { + $level_where = ' AND level='.$exerciseLevel; + } + $answer_where = ''; + if (isset($answerType) && $answerType > 0 - 1) { + $answer_where = ' AND type='.$answerType; + } // @todo fix this query with the new id field $sql = " ( @@ -525,24 +525,24 @@ if ($exerciseId > 0) { $mainQuestionList[] = $row; } } else { - // All tests for selected course + // All tests for selected course // If we have not selected any option in the list-box 'Filter' - $filter = ''; - $from = ''; - - if (isset($courseCategoryId) && $courseCategoryId > 0) { - $from = ", $TBL_COURSE_REL_CATEGORY crc "; - $filter .= " AND - crc.c_id = $selected_course AND - crc.question_id = qu.id AND - crc.category_id = $courseCategoryId"; - } - if (isset($exerciseLevel) && $exerciseLevel != -1) { - $filter .= ' AND level='.$exerciseLevel.' '; - } - if (isset($answerType) && $answerType > 0) { - $filter .= ' AND qu.type='.$answerType.' '; - } + $filter = ''; + $from = ''; + + if (isset($courseCategoryId) && $courseCategoryId > 0) { + $from = ", $TBL_COURSE_REL_CATEGORY crc "; + $filter .= " AND + crc.c_id = $selected_course AND + crc.question_id = qu.id AND + crc.category_id = $courseCategoryId"; + } + if (isset($exerciseLevel) && $exerciseLevel != -1) { + $filter .= ' AND level='.$exerciseLevel.' '; + } + if (isset($answerType) && $answerType > 0) { + $filter .= ' AND qu.type='.$answerType.' '; + } if (!empty($session_id) && $session_id != '-1') { $mainQuestionList = array(); @@ -565,7 +565,6 @@ if ($exerciseId > 0) { if (!empty($my_exercise)) { if (!empty($my_exercise->questionList)) { foreach ($my_exercise->questionList as $question_id) { - $question_obj = Question::read( $question_id, $courseItemId @@ -644,7 +643,7 @@ if ($exerciseId > 0) { $mainQuestionList[] = $row; } } - // forces the value to 0 + // forces the value to 0 $exerciseId = 0; } @@ -670,33 +669,33 @@ $nbrQuestions = count($mainQuestionList); // if ($fromExercise <= 0) { // NOT IN A TEST - IN THE COURSE - if ($selected_course == api_get_course_int_id()) { - $actionLabel = get_lang('Modify'); - $actionIcon1 = "edit"; - $actionIcon2 = "delete"; + if ($selected_course == api_get_course_int_id()) { + $actionLabel = get_lang('Modify'); + $actionIcon1 = "edit"; + $actionIcon2 = "delete"; // 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 - $actionLabel = get_lang('Reuse'); - $actionIcon1 = get_lang('MustBeInATest'); - $actionIcon2 = ""; + $actionLabel = get_lang('Reuse'); + $actionIcon1 = get_lang('MustBeInATest'); + $actionIcon2 = ""; // We are not in this course, to messy if we link to the question in another course - $questionTagA = 0; - } + $questionTagA = 0; + } } else { // IN A TEST - IN THE COURSE - if ($selected_course == api_get_course_int_id()) { - $actionLabel = get_lang('Reuse'); - $actionIcon1 = "add"; - $actionIcon2 = ""; - $questionTagA = 1; + if ($selected_course == api_get_course_int_id()) { + $actionLabel = get_lang('Reuse'); + $actionIcon1 = "add"; + $actionIcon2 = ""; + $questionTagA = 1; } else { // IN A TEST - NOT IN THE COURSE - $actionLabel = get_lang('Reuse'); - $actionIcon1 = "clone"; - $actionIcon2 = ""; - $questionTagA = 0; - } + $actionLabel = get_lang('Reuse'); + $actionIcon1 = "clone"; + $actionIcon2 = ""; + $questionTagA = 0; + } } // Display table $header = array( @@ -709,15 +708,8 @@ $header = array( $data = array(); -/*$hideDoubles = false; -if (empty($exerciseId) && !empty($session_id) && $session_id != '-1') { - $hideDoubles = true; -} -$questionAdded = array();*/ - if (is_array($mainQuestionList)) { foreach ($mainQuestionList as $question) { - /*if ($hideDoubles) { if (in_array($question['question'], $questionAdded)) { continue; @@ -751,32 +743,31 @@ if (is_array($mainQuestionList)) { $row[] = get_question_categorie_for_question($selected_course, $question['id']); $row[] = $question['level']; $row[] = get_action_icon_for_question( - $actionIcon1, - $fromExercise, - $question['id'], - $question['type'], - $question['question'], - $selected_course, - $courseCategoryId, - $exerciseLevel, - $answerType, - $session_id, - $exerciseId - ). - " ". - get_action_icon_for_question( - $actionIcon2, - $fromExercise, - $question['id'], - $question['type'], - $question['question'], - $selected_course, - $courseCategoryId, - $exerciseLevel, - $answerType, - $session_id, - $exerciseId - ); + $actionIcon1, + $fromExercise, + $question['id'], + $question['type'], + $question['question'], + $selected_course, + $courseCategoryId, + $exerciseLevel, + $answerType, + $session_id, + $exerciseId + )." ". + get_action_icon_for_question( + $actionIcon2, + $fromExercise, + $question['id'], + $question['type'], + $question['question'], + $selected_course, + $courseCategoryId, + $exerciseLevel, + $answerType, + $session_id, + $exerciseId + ); $data[] = $row; } } @@ -789,34 +780,34 @@ Display :: display_sortable_table( ); if (!$nbrQuestions) { - echo get_lang('NoQuestion'); + echo get_lang('NoQuestion'); } Display::display_footer(); /** -* 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 -* @author hubert.borderiou 13-10-2011 -*/ + * 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 + * @author hubert.borderiou 13-10-2011 + */ function reset_menu_lvl_type() { - global $exerciseLevel, $answerType; - $answerType = -1; - $exerciseLevel = -1; + global $exerciseLevel, $answerType; + $answerType = -1; + $exerciseLevel = -1; } /** -* 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 -* @author hubert.borderiou 13-10-2011 -*/ + * 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 + * @author hubert.borderiou 13-10-2011 + */ function reset_menu_exo_lvl_type() { - global $exerciseId, $courseCategoryId; - reset_menu_lvl_type(); - $exerciseId = 0; - $courseCategoryId = 0; + global $exerciseId, $courseCategoryId; + reset_menu_lvl_type(); + $exerciseId = 0; + $courseCategoryId = 0; } /** @@ -838,17 +829,17 @@ function get_a_tag_for_question( $in_questionname, $sessionId ) { - $res = $in_questionname; + $res = $in_questionname; $sessionIcon = null; - if ($in_addA) { + if ($in_addA) { if (!empty($sessionId) && $sessionId != -1) { $sessionIcon = ' '.Display::return_icon('star.png', get_lang('Session')); } - $res = "". + $res = "". $res.$sessionIcon. ""; - } - return $res; + } + return $res; } /** @@ -878,16 +869,16 @@ function get_action_icon_for_question( $in_session_id, $in_exercise_id ) { - $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"; - switch ($in_action) { - case "delete" : - $res = ""; - $res .= Display::return_icon("delete.png", get_lang('Delete')); - $res .= ""; - break; - case "edit" : - $res = get_a_tag_for_question( + $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"; + switch ($in_action) { + case "delete": + $res = ""; + $res .= Display::return_icon("delete.png", get_lang('Delete')); + $res .= ""; + break; + case "edit": + $res = get_a_tag_for_question( 1, $from_exercise, $in_questionid, @@ -895,33 +886,33 @@ function get_action_icon_for_question( Display::return_icon("edit.png", get_lang('Modify')), $in_session_id ); - break; - case "add": - // add if question is not already in test - $myObjEx = new Exercise(); - $myObjEx->read($from_exercise); - if (!$myObjEx->isInList($in_questionid)) { - $res = ""; - $res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise')); - $res .= ""; + break; + case "add": + // add if question is not already in test + $myObjEx = new Exercise(); + $myObjEx->read($from_exercise); + if (!$myObjEx->isInList($in_questionid)) { + $res = ""; + $res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise')); + $res .= ""; } else { - $res = "-"; - } - unset($myObjEx); - break; - case "clone": + $res = "-"; + } + unset($myObjEx); + break; + case "clone": $url = api_get_self()."?".api_get_cidreq().$getParams."&question_copy=$in_questionid&course_id=$in_selected_course&fromExercise=$from_exercise"; $res = Display::url( Display::return_icon('cd.png', get_lang('ReUseACopyInCurrentTest')), $url ); - break; - default: - $res = $in_action; - break; - } + break; + default: + $res = $in_action; + 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) { - $myObjQuestion = Question::read($in_questionid, $in_selectedcourse); + $myObjQuestion = Question::read($in_questionid, $in_selectedcourse); $questionType = null; if (!empty($myObjQuestion)) { list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html(); $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array()); 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) { - $cat = TestCategory::getCategoryNameForQuestion($in_questionid, $in_courseid); - return $cat; + $cat = TestCategory::getCategoryNameForQuestion($in_questionid, $in_courseid); + return $cat; } diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 36f98034c1..3b8cc784a8 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -183,21 +183,21 @@ class Display /** * Displays a table * @param array $header Titles for the table header - * each item in this array can contain 3 values - * - 1st element: the column title - * - 2nd element: true or false (column sortable?) - * - 3th element: additional attributes for - * th-tag (eg for column-width) - * - 4the element: additional attributes for the td-tags + * each item in this array can contain 3 values + * - 1st element: the column title + * - 2nd element: true or false (column sortable?) + * - 3th element: additional attributes for + * th-tag (eg for column-width) + * - 4the element: additional attributes for the td-tags * @param array $content 2D-array with the tables content * @param array $sorting_options Keys are: - * 'column' = The column to use as sort-key - * 'direction' = SORT_ASC or SORT_DESC + * 'column' = The column to use as sort-key + * 'direction' = SORT_ASC or SORT_DESC * @param array $paging_options Keys are: - * 'per_page_default' = items per page when switching from - * full- list to per-page-view - * 'per_page' = number of items to show per page - * 'page_nr' = The page to display + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display * @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' * @author bart.mollet@hogent.be @@ -278,16 +278,16 @@ class Display * @param array header content * @param array array with the information to show * @param array $paging_options Keys are: - * 'per_page_default' = items per page when switching from - * full- list to per-page-view - * 'per_page' = number of items to show per page - * 'page_nr' = The page to display - * 'hide_navigation' = true to hide the navigation + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * 'hide_navigation' = true to hide the navigation * @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 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 - * 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( $name, @@ -319,19 +319,19 @@ class Display * @param array header content * @param array array with the information to show * @param array $paging_options Keys are: - * 'per_page_default' = items per page when switching from - * full- list to per-page-view - * 'per_page' = number of items to show per page - * 'page_nr' = The page to display - * 'hide_navigation' = true to hide the navigation + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * 'hide_navigation' = true to hide the navigation * @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 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 - * 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 array grid classes - * @return string html grid + * @return string html grid */ public static function return_sortable_grid( $name, @@ -382,7 +382,7 @@ class Display * @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_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 * * @author Julio Montoya @@ -433,7 +433,7 @@ class Display * Displays a normal message. It is recommended to use this public function * to display any normal information messages. * @param string $message - * @param bool $filter (true) or not (false) + * @param bool $filter (true) or not (false) * @param bool $returnValue * * @deprecated Use Display::addFlash(Display::return_message($message, 'normal')); @@ -469,7 +469,7 @@ class Display /** * 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')); * @return void */ @@ -487,7 +487,7 @@ class Display * Displays an error message. It is recommended to use this public function if an error occurs * @param string $message - include any additional html * 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')); * * @return void @@ -533,16 +533,16 @@ class Display $class = ''; switch ($type) { case 'warning': - $class .= 'alert alert-warning'; - break; + $class .= 'alert alert-warning'; + break; case 'error': - $class .= 'alert alert-danger'; - break; + $class .= 'alert alert-danger'; + break; case 'confirmation': case 'confirm': case 'success': $class .= 'alert alert-success'; - break; + break; case 'normal': default: $class .= 'alert alert-info'; @@ -629,6 +629,7 @@ class Display * @param char $selected_letter The letter that should be selected * @todo This is English language specific implementation. * It should be adapted for the other languages. + * @return string */ 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 $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 + * @return string * @author Julio Montoya 2010 */ 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 $content the tag's content * @param array $additional_attributes (for instance height, width, onclick, ...) + * + * @return string * @author Julio Montoya 2010 */ public static function tag($tag, $content, $additional_attributes = array()) @@ -910,18 +914,17 @@ class Display /** * Displays an HTML input tag - * */ public static function input($type, $name, $value, $attributes = array()) { - if (isset($type)) { - $attributes['type'] = $type; - } - if (isset($name)) { - $attributes['name'] = $name; - } - if (isset($value)) { - $attributes['value'] = $value; + if (isset($type)) { + $attributes['type'] = $type; + } + if (isset($name)) { + $attributes['name'] = $name; + } + if (isset($value)) { + $attributes['value'] = $value; } return self::tag('input', '', $attributes); } @@ -934,9 +937,9 @@ class Display */ public static function button($name, $value, $attributes = array()) { - if (!empty($name)) { + if (!empty($name)) { $attributes['name'] = $name; - } + } return self::tag('button', $value, $attributes); } @@ -1083,20 +1086,20 @@ class Display */ public static function tabsOnlyLink($headers, $selected = null) { - $id = uniqid(); - $i = 1; - $lis = null; - foreach ($headers as $item) { + $id = uniqid(); + $i = 1; + $lis = null; + foreach ($headers as $item) { $class = null; if ($i == $selected) { $class = 'active'; } - $item = self::tag( - 'a', - $item['content'], - array('id' => $id.'-'.$i, 'href' => $item['url']) - ); - $lis .= self::tag('li', $item, array('class' => $class)); + $item = self::tag( + 'a', + $item['content'], + array('id' => $id.'-'.$i, 'href' => $item['url']) + ); + $lis .= self::tag('li', $item, array('class' => $class)); $i++; } return self::tag('ul', $lis, array('class' => 'nav nav-tabs tabs-margin')); @@ -1144,17 +1147,17 @@ class Display * example --> $(function() { } * 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 $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. - * This is the text that appears in the head of the grid (Header layer). - * 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. - * For a full description of all valid values see colModel API. See the url above. - * @param array $extra_params extra parameters - * @param array $data data that will be loaded - * @param string $formatter A string that will be appended to the JSON returned - * @param bool $fixed_width not implemented yet + * @param string $div_id div id + * @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. + * This is the text that appears in the head of the grid (Header layer). + * 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. + * For a full description of all valid values see colModel API. See the url above. + * @param array $extra_params extra parameters + * @param array $data data that will be loaded + * @param string $formatter A string that will be appended to the JSON returned + * @param bool $fixed_width not implemented yet * @return string the js code * */ @@ -1308,8 +1311,8 @@ class Display */ public static function table($headers, $rows, $attributes = array()) { - if (empty($attributes)) { - $attributes['class'] = 'data_table'; + if (empty($attributes)) { + $attributes['class'] = 'data_table'; } $table = new HTML_Table($attributes); $row = 0; @@ -1317,17 +1320,17 @@ class Display // Course headers if (!empty($headers)) { - foreach ($headers as $item) { - $table->setHeaderContents($row, $column, $item); - $column++; - } - $row = 1; - $column = 0; + foreach ($headers as $item) { + $table->setHeaderContents($row, $column, $item); + $column++; + } + $row = 1; + $column = 0; } if (!empty($rows)) { - foreach ($rows as $content) { - $table->setCellContents($row, $column, $content); + foreach ($rows as $content) { + $table->setCellContents($row, $column, $content); $row++; } } @@ -1661,8 +1664,8 @@ class Display * @param string $id of the rating ul element * @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 bool $add_div_wrapper add a div wrapper - * @return string + * @param bool $add_div_wrapper add a div wrapper + * @return string **/ public static function return_rating_system( $id, @@ -2060,7 +2063,6 @@ class Display } /** - * * @param int $nextValue * @param array $list * @param int $current diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 4ebbb60508..fbb8631331 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -3,12 +3,12 @@ /** * Class DocumentManager - * This is the document library for Chamilo. - * 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. - * Include/require it in your code to use its functionality. + * This is the document library for Chamilo. + * 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. + * Include/require it in your code to use its functionality. * - * @package chamilo.library + * @package chamilo.library */ class DocumentManager { @@ -47,14 +47,14 @@ class DocumentManager } /** - * Get the content type of a file by checking the extension - * We could use mime_content_type() with php-versions > 4.3, - * but this doesn't work as it should on Windows installations + * Get the content type of a file by checking the extension + * We could use mime_content_type() with php-versions > 4.3, + * but this doesn't work as it should on Windows installations * - * @param string $filename or boolean TRUE to return complete array - * @author ? first version - * @author Bert Vanderkimpen - * @return string + * @param string $filename or boolean TRUE to return complete array + * @author ? first version + * @author Bert Vanderkimpen + * @return string * */ public static function file_get_mime_type($filename) @@ -273,12 +273,12 @@ class DocumentManager } /** - * @param string - * @param string - * @return true if the user is allowed to see the document, false otherwise - * @author Sergio A Kessler, first version - * @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?? + * @param string + * @param string + * @return true if the user is allowed to see the document, false otherwise + * @author Sergio A Kessler, first version + * @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?? */ 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'; $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $id = intval($id); - $sessionCondition = api_get_session_condition($session_id, true, true); $sql = "SELECT * FROM $TABLE_DOCUMENT @@ -1512,8 +1511,14 @@ class DocumentManager * @param int $user_id * @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 $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES); $params = [ @@ -1565,7 +1570,7 @@ class DocumentManager * Return true if the documentpath have visibility=1 as * 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 int * @param string @@ -1911,7 +1916,7 @@ class DocumentManager $user_id = intval($user_id); $course_info = api_get_course_info($course_id); - // Portal infor + // Portal info $organization_name = api_get_setting('Institution'); $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 * 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. - * @param string source html (content or path) - * @param bool is file or string html - * @param string type (one of the app tools) - optional (otherwise takes the current item's type) - * @param int level of recursivity we're in - * @return array List of file paths. An additional field containing 'local' or 'remote' helps determine + * @param string source html (content or path) + * @param bool is file or string html + * @param string type (one of the app tools) - optional (otherwise takes the current item's type) + * @param int level of recursivity we're in + * @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 */ 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).'/'; } $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) { $files_list = array_merge($files_list, $in_files_list); } @@ -2331,7 +2341,12 @@ class DocumentManager if (substr($source, 0, 1) === '/') { //link starts with a /, making it absolute (relative to DocumentRoot) $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) { $files_list = array_merge($files_list, $in_files_list); } @@ -3368,6 +3383,7 @@ class DocumentManager * @param bool $showInvisibleFiles * @param bool $showOnlyFolders * @param int $folderId + * * @return string */ public static function get_document_preview( @@ -3814,7 +3830,7 @@ class DocumentManager $onclick = ''; // if in LP, hidden folder are displayed in grey - $folder_class_hidden = ""; + $folder_class_hidden = ''; if ($lp_id) { if (isset($resource['visible']) && $resource['visible'] == 0) { $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 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); $doc_ext = strtolower($extensions[count($extensions) - 1]); if (in_array($doc_ext, $allowed_extensions)) { diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index a366d2c890..264407bf8b 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -717,13 +717,17 @@ class learnpath /** * Static admin function allowing addition of a learnpath to a course. - * @param string Course code - * @param string Learnpath name - * @param string Learnpath description string, if provided - * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) - * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) - * @param string Zip file containing the learnpath or directory containing the learnpath - * @return integer The new learnpath ID on success, 0 on failure + * @param string Course code + * @param string Learnpath name + * @param string Learnpath description string, if provided + * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) + * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) + * @param string $zipname Zip file containing the learnpath or directory containing the learnpath + * @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( $courseCode, @@ -763,14 +767,6 @@ class learnpath $res_name = Database::query($check_name); 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; } else { $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. $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. - 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) { 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! - * @param integer $id Element ID of which children have to be removed - * @return integer Total number of children removed + * @param integer $id Element ID of which children have to be removed + * @return integer Total number of children removed */ public function delete_children_items($id) { @@ -1147,7 +1143,7 @@ class learnpath error_log('New LP - In learnpath::delete_children_items('.$id.')', 0); } $num = 0; - if (empty ($id) || $id != strval(intval($id))) { + if (empty($id) || $id != strval(intval($id))) { return false; } $lp_item = Database::get_course_table(TABLE_LP_ITEM); @@ -1164,10 +1160,10 @@ class learnpath /** * Removes an item from the current learnpath - * @param integer $id Elem ID (0 if first) - * @param integer $remove Whether to remove the resource/data from the + * @param integer $id Elem ID (0 if first) + * @param integer $remove Whether to remove the resource/data from the * system or leave it (default: 'keep', others 'remove') - * @return integer Number of elements moved + * @return integer Number of elements moved * @todo implement resource removal */ public function delete_item($id, $remove = 'keep') @@ -1177,7 +1173,7 @@ class learnpath error_log('New LP - In learnpath::delete_item()', 0); } // TODO: Implement the resource removal. - if (empty ($id) || $id != strval(intval($id))) { + if (empty($id) || $id != strval(intval($id))) { return false; } // First select item to get previous, next, and display order. @@ -1268,10 +1264,10 @@ class learnpath if ($this->debug > 0) { error_log('New LP - In learnpath::edit_item()', 0); } - if (empty ($max_time_allowed)) { + if (empty($max_time_allowed)) { $max_time_allowed = 0; } - if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) { + if (empty($id) || ($id != strval(intval($id))) || empty($title)) { return false; } @@ -1280,7 +1276,7 @@ class learnpath $res_select = Database::query($sql_select); $row_select = Database::fetch_array($res_select); $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. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; if (!is_dir($filepath.'audio')) { @@ -1428,7 +1424,7 @@ class learnpath // TODO: htmlspecialchars to be checked for encoding related problems. // Update the current item with the new data. - $sql = "UPDATE ".$tbl_lp_item." + $sql = "UPDATE $tbl_lp_item SET title = '" . Database::escape_string($title)."', description = '" . Database::escape_string($description)."', @@ -1493,12 +1489,12 @@ class learnpath /** * Updates an item's prereq in place - * @param integer $id Element ID - * @param string $prerequisite_id Prerequisite Element ID - * @param int $mastery_score Prerequisite min score - * @param int $max_score Prerequisite max score + * @param integer $id Element ID + * @param string $prerequisite_id Prerequisite Element ID + * @param int $mastery_score Prerequisite min 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) { @@ -1507,7 +1503,7 @@ class learnpath 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; } @@ -1546,11 +1542,11 @@ class learnpath /** * Static admin function exporting a learnpath into a zip file - * @param string Export type (scorm, zip, cd) - * @param string Course code - * @param integer Learnpath ID - * @param string Zip file name - * @return string Zip file path (or false on error) + * @param string Export type (scorm, zip, cd) + * @param string Course code + * @param integer Learnpath ID + * @param string Zip file name + * @return string Zip file path (or false on error) */ 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 * Can also be called as abstract method - * @param integer $id Item ID - * @return array A list of all the "brother items" (or an empty array on failure) + * @param integer $id Item ID + * @return array A list of all the "brother items" (or an empty array on failure) */ public function getSiblingDirectories($id) { @@ -1617,8 +1613,8 @@ class learnpath /** * Gets all the items belonging to the same parent as the item given * Can also be called as abstract method - * @param integer $id Item ID - * @return array A list of all the "brother items" (or an empty array on failure) + * @param integer $id Item ID + * @return array A list of all the "brother items" (or an empty array on failure) */ public function get_brother_items($id) { @@ -1627,7 +1623,7 @@ class learnpath 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(); } @@ -1707,7 +1703,7 @@ class learnpath /** * 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() { @@ -1726,7 +1722,7 @@ class learnpath /** * 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() { @@ -1739,7 +1735,7 @@ class learnpath /** * 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() { @@ -1751,7 +1747,7 @@ class learnpath /** * 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() { @@ -1770,7 +1766,7 @@ class learnpath /** * Gets the first element URL. - * @return string URL to load into the viewer + * @return string URL to load into the viewer */ public function first() { @@ -4435,6 +4431,7 @@ class learnpath /** * Sets the encoding * @param string New encoding + * @return bool * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed. */ 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; - $lp->setPublicatedOn($this->publicated_on); - $em->persist($lp); $em->flush(); @@ -6849,34 +6844,6 @@ class learnpath $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title']; } } - /*// Commented the prerequisites, only visible in edit (exercise). - $return .= ''; - $return .= ''; - $return .= '"; - */ - /*$return .= ''; - $return .= ''; - $return .= ''; - - // Remove temporarily the test description. - //$return .= ''; - //$return .= ''; - - $return .= ''; */ } if ($action == 'add') { @@ -7194,7 +7161,10 @@ class learnpath //$parent_item_id = $_SESSION['parent_item_id']; for ($i = 0; $i < count($arrLP); $i++) { 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( $arrLP[$i]['title'], $arrLP[$i]['id'], @@ -7621,7 +7591,16 @@ class learnpath $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) { $parent_select->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"'); @@ -7843,7 +7822,10 @@ class learnpath $return .= ''; if (isset($_GET['edit']) && $_GET['edit'] == 'true') { - $return .= Display::return_message(''.get_lang('Warning').' !
'.get_lang('WarningEditingDocument'), false); + $return .= Display::return_message( + ''.get_lang('Warning').' !
'.get_lang('WarningEditingDocument'), + false + ); } $form = new FormValidator( 'form', @@ -7895,7 +7877,10 @@ class learnpath for ($i = 0; $i < count($arrLP); $i++) { 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']]['padding'] = 20 + $arrLP[$i]['depth'] * 20; if ($parent == $arrLP[$i]['id']) { @@ -8707,7 +8692,7 @@ class learnpath /** * Display the form to allow moving an item - * @param integer Item ID + * @param integer $item_id Item ID * @return string HTML form */ public function display_move_item($item_id) @@ -8727,7 +8712,13 @@ class learnpath case 'dir': case 'asset': $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; case TOOL_DOCUMENT: $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); // Try loading document from the base course. 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']; if (file_exists($file_path)) { @@ -10527,7 +10523,10 @@ EOD; $max_order = $row_max_order->display_order; // Get the previous item ID $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); $row_max = Database::fetch_object($rs_max); @@ -10556,8 +10555,15 @@ EOD; //Course restorer $course_restorer = new CourseRestorer($course); $course_restorer->set_add_text_in_items(true); - $course_restorer->set_tool_copy_settings(array('learnpaths' => array('reset_dates' => true))); - $course_restorer->restore(api_get_course_id(), api_get_session_id(), false, false); + $course_restorer->set_tool_copy_settings( + 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) @@ -10895,7 +10901,6 @@ EOD; public function setCategoryId($categoryId) { $this->categoryId = intval($categoryId); - $courseId = api_get_course_int_id(); $lp_table = Database::get_course_table(TABLE_LP_MAIN); $lp_id = $this->get_id(); @@ -10920,6 +10925,7 @@ EOD; * Set whether this is a learning path with the possibility to subscribe * users or not * @param int $subscribeUsers (0 = false, 1 = true) + * @return bool */ public function setSubscribeUsers($value) { @@ -11209,6 +11215,7 @@ EOD; /** * Get the forum for this learning path + * @param int $sessionId * @return boolean */ 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) * * @author Yannick Warnier - * @param string Course code - * @param string The tool type (using constants declared in main_api.lib.php) - * @param integer The resource ID + * @param string Course code + * @param string The tool type (using constants declared in main_api.lib.php) + * @param integer The resource ID + * @return string */ public static function rl_get_resource_name($course_code, $learningPathId, $id_in_path) { diff --git a/main/lp/scorm.class.php b/main/lp/scorm.class.php index bca99452f9..72dfdd839f 100755 --- a/main/lp/scorm.class.php +++ b/main/lp/scorm.class.php @@ -4,7 +4,7 @@ /** * Defines the scorm class, which is meant to contain the scorm items (nuclear elements) * @package chamilo.learnpath - * @author Yannick Warnier + * @author Yannick Warnier */ class scorm extends learnpath { @@ -32,9 +32,9 @@ class scorm extends learnpath /** * Class constructor. Based on the parent constructor. - * @param string Course code - * @param integer Learnpath ID in DB - * @param integer User ID + * @param string Course code + * @param integer Learnpath ID in DB + * @param integer User ID */ public function __construct($course_code = null, $resource_id = null, $user_id = null) { @@ -47,7 +47,7 @@ class scorm extends learnpath /** * Opens a resource - * @param integer $id Database ID of the resource + * @param integer $id Database ID of the resource */ public function open($id) { @@ -78,18 +78,14 @@ class scorm extends learnpath } if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) { - // Parsing using PHP5 DOMXML methods. - 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 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); // UTF-8 is supported by DOMDocument class, this is for sure. $xml = api_utf8_encode_xml($xml, $this->manifest_encoding); - $doc = new DOMDocument(); $res = @$doc->loadXML($xml); if ($res === false) { @@ -213,9 +209,7 @@ class scorm extends learnpath } } unset($doc); - // End parsing using PHP5 DOMXML methods. - } else { 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"); @@ -271,7 +265,7 @@ class scorm extends learnpath * @param int $userMaxScore * @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) { @@ -518,9 +512,9 @@ class scorm extends learnpath /** * 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 Current path (optional) - * @return string Absolute path to the imsmanifest.xml file or empty string on error + * @param string Path to the zip file, from the sys root + * @param string Current path (optional) + * @return string Absolute path to the imsmanifest.xml file or empty string on error */ 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 - * @param string $zip_file_info Zip file info as given by $_FILES['userFile'] + * @param string $zip_file_info Zip file info as given by $_FILES['userFile'] * @param string * @param array * - * @return string $current_dir Absolute path to the imsmanifest.xml file or empty string on error + * @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()) { @@ -628,7 +622,6 @@ class scorm extends learnpath if ($package_type == '') { // && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM) if ($this->debug > 1) { error_log('New LP - Package type is empty', 0); } - Display::addFlash( Display::return_message(get_lang('NotScormContent')) ); @@ -665,7 +658,6 @@ class scorm extends learnpath if (is_dir($course_sys_dir.$new_dir) || @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories()) ) { - // PHP method - slower... if ($this->debug >= 1) { error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir, 0); } $saved_dir = getcwd(); @@ -743,7 +735,7 @@ class scorm extends learnpath /** * Sets the proximity setting in the database - * @param string Proximity setting + * @param string Proximity setting * @param int $courseId */ public function set_proximity($proxy = '', $courseId = null) @@ -764,7 +756,7 @@ class scorm extends learnpath /** * Sets the theme setting in the database - * @param string theme setting + * @param string theme setting */ public function set_theme($theme = '') { @@ -783,7 +775,7 @@ class scorm extends learnpath /** * Sets the image setting in the database - * @param string preview_image setting + * @param string preview_image setting */ public function set_preview_image($preview_image = '') { @@ -802,7 +794,7 @@ class scorm extends learnpath /** * Sets the author setting in the database - * @param string preview_image setting + * @param string preview_image setting */ public function set_author($author = '') { @@ -821,7 +813,7 @@ class scorm extends learnpath /** * Sets the content maker setting in the database - * @param string Proximity setting + * @param string Proximity setting */ 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() - * @param integer Learnpath ID (optional, taken from object context if not defined) + * Exports the current SCORM object's files as a zip. + * 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) { @@ -877,11 +870,9 @@ class scorm extends learnpath $zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip'; // Get a temporary dir for creating the zip file. - //error_log('New LP - cleaning dir '.$zipfoldername, 0); my_delete($zipfoldername); // Make sure the temp dir is cleared. mkdir($zipfoldername, api_get_permissions_for_new_directories()); - //error_log('New LP - made dir '.$zipfoldername, 0); // Create zipfile of given directory. $zip_folder = new PclZip($zipfilename); diff --git a/main/survey/surveyUtil.class.php b/main/survey/surveyUtil.class.php index e7e16eaa11..cd5f2a4074 100755 --- a/main/survey/surveyUtil.class.php +++ b/main/survey/surveyUtil.class.php @@ -308,7 +308,6 @@ class SurveyUtil $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER); - $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0; // 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 * answers of that user. * - * @param array All the survey data - * @return string html code that displays the report by question + * @param array All the survey data + * @return string html code that displays the report by question * @todo allow switching between horizontal and vertical. * @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. @@ -695,9 +694,9 @@ class SurveyUtil /** * Display score data about a survey question - * @param array Question info - * @param integer The offset of results shown - * @return void (direct output) + * @param array Question info + * @param integer The offset of results shown + * @return void (direct output) */ public static function display_question_report_score($survey_data, $question, $offset) { @@ -839,8 +838,7 @@ class SurveyUtil // Getting the number of options per question echo ' '; echo ' '; - if ( - (isset($_POST['submit_question_filter']) && $_POST['submit_question_filter']) || + if ((isset($_POST['submit_question_filter']) && $_POST['submit_question_filter']) || (isset($_POST['export_report']) && $_POST['export_report']) ) { echo ''; @@ -1024,10 +1022,10 @@ class SurveyUtil * This function displays a row (= a user and his/her answers) in the table of the complete report. * * @param array $survey_data - * @param array Possible options - * @param array User answers - * @param mixed User ID or user details string - * @param boolean Whether to show extra user fields or not + * @param array Possible options + * @param array User answers + * @param mixed User ID or user details string + * @param boolean Whether to show extra user fields or not * @author Patrick Cool , Ghent University * @version February 2007 - Updated March 2008 */ @@ -1060,7 +1058,13 @@ class SurveyUtil if ($display_extra_user_fields) { // 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) { echo ''.$value.''; } @@ -1080,18 +1084,16 @@ class SurveyUtil echo $answers_of_user[$question_id][$option_id]['value']; echo ""; } - } - else { + } else { echo ''; if (!empty($answers_of_user[$question_id][$option_id])) { if ($answers_of_user[$question_id][$option_id]['value'] != 0) { echo $answers_of_user[$question_id][$option_id]['value']; - } - else { + } else { echo 'v'; } } - } // + } } } } @@ -1103,7 +1105,7 @@ class SurveyUtil * Quite similar to display_complete_report(), returns an HTML string * that can be used in a csv file * @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 , Ghent University * @version February 2007 */ @@ -1820,9 +1822,8 @@ class SurveyUtil } $tableHtml .= ''; } - } - // The Y axis is NOT a score question type so the number of rows = the number of options - else { + } else { + // The Y axis is NOT a score question type so the number of rows = the number of options $tableHtml .= ''; for ($ii = 0; $ii <= count($question_x['answers']); $ii++) { if ($question_x['type'] == 'score') { @@ -2106,7 +2107,6 @@ class SurveyUtil $counter = 0; // Nr of invitations "sent" (if sendmail option) $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); - $result = CourseManager::separateUsersGroups($users_array); $groupList = $result['groups']; @@ -2156,7 +2156,6 @@ class SurveyUtil $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'] $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']; if ((is_numeric($value) && !in_array($value, $my_alredy_invited)) || (!is_numeric($value) && !in_array($value, $addit_users_array)) @@ -2205,7 +2204,6 @@ class SurveyUtil ) { $insertId = Database::insert($table, $params); if ($insertId) { - $sql = "UPDATE $table SET survey_invitation_id = $insertId WHERE iid = $insertId"; Database::query($sql); @@ -2736,6 +2734,7 @@ class SurveyUtil FROM ".$table_survey.' '.$search_restriction; $res = Database::query($sql); $obj = Database::fetch_object($res); + return $obj->total_number_of_items; }