Переглянути джерело

Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into 1.9.x

Yannick Warnier 10 роки тому
батько
коміт
7d9ce8b73e

+ 101 - 81
main/exercice/question_pool.php

@@ -106,81 +106,79 @@ if ($is_allowedToEdit) {
         $displayMessage = get_lang('ItemAdded');
     }
 
-	// Deletes a question from the database and all exercises
-	if ($delete) {
-		// Construction of the Question object
+    // Deletes a question from the database and all exercises
+    if ($delete) {
+        // Construction of the Question object
         $objQuestionTmp = Question::read($delete);
         // if the question exists
-		if ($objQuestionTmp) {
-			// deletes the question from all exercises
-			$objQuestionTmp->delete();
-		}
-		// destruction of the Question object
-		unset($objQuestionTmp);
-	} elseif($recup && $fromExercise) {
-		// gets an existing question and copies it into a new exercise
-		$objQuestionTmp = Question :: read($recup);
-		// if the question exists
-		if ($objQuestionTmp) {
-			/* Adds the exercise ID represented by $fromExercise into the list
-			of exercises for the current question */
-			$objQuestionTmp->addToList($fromExercise);
-		}
-		// destruction of the Question object
-		unset($objQuestionTmp);
+        if ($objQuestionTmp) {
+            // deletes the question from all exercises
+            $objQuestionTmp->delete();
+        }
+        // destruction of the Question object
+        unset($objQuestionTmp);
+    } elseif($recup && $fromExercise) {
+        // gets an existing question and copies it into a new exercise
+        $objQuestionTmp = Question :: read($recup);
+        // if the question exists
+        if ($objQuestionTmp) {
+            /* Adds the exercise ID represented by $fromExercise into the list
+            of exercises for the current question */
+            $objQuestionTmp->addToList($fromExercise);
+        }
+        // destruction of the Question object
+        unset($objQuestionTmp);
 
         if (!$objExercise instanceOf Exercise) {
-        	$objExercise = new Exercise();
+            $objExercise = new Exercise();
             $objExercise->read($fromExercise);
         }
-		// Adds the question ID represented by $recup into the list of questions for the current exercise
-		$objExercise->addToList($recup);
-		Session::write('objExercise', $objExercise);
-//		header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
-//		exit();
-	} else if( isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) {
-		$list_recup = $_POST['recup'];
-
-		foreach ($list_recup as $course_id => $question_data) {
-			$origin_course_id   = intval($course_id);
-			$origin_course_info = api_get_course_info_by_id($origin_course_id);
-			$current_course     = api_get_course_info();
-
-			foreach ($question_data as $old_question_id) {
-				//Reading the source question
-				$old_question_obj = Question::read($old_question_id, $origin_course_id);
-				if ($old_question_obj) {
+        // Adds the question ID represented by $recup into the list of questions for the current exercise
+        $objExercise->addToList($recup);
+        Session::write('objExercise', $objExercise);
+    } else if( isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) {
+        $list_recup = $_POST['recup'];
+
+        foreach ($list_recup as $course_id => $question_data) {
+            $origin_course_id   = intval($course_id);
+            $origin_course_info = api_get_course_info_by_id($origin_course_id);
+            $current_course     = api_get_course_info();
+
+            foreach ($question_data as $old_question_id) {
+                //Reading the source question
+                $old_question_obj = Question::read($old_question_id, $origin_course_id);
+                if ($old_question_obj) {
                     $old_question_obj->updateTitle(
                         $old_question_obj->selectTitle() . ' - ' . get_lang('Copy')
                     );
 
-					//Duplicating the source question, in the current course
-					$new_id = $old_question_obj->duplicate($current_course);
+                    //Duplicating the source question, in the current course
+                    $new_id = $old_question_obj->duplicate($current_course);
 
-					//Reading new question
-					$new_question_obj = Question::read($new_id);
-					$new_question_obj->addToList($fromExercise);
+                    //Reading new question
+                    $new_question_obj = Question::read($new_id);
+                    $new_question_obj->addToList($fromExercise);
 
-					//Reading Answers obj of the current course
-					$new_answer_obj = new Answer($old_question_id, $origin_course_id);
-					$new_answer_obj->read();
+                    //Reading Answers obj of the current course
+                    $new_answer_obj = new Answer($old_question_id, $origin_course_id);
+                    $new_answer_obj->read();
 
-					//Duplicating the Answers in the current course
-					$new_answer_obj->duplicate($new_id, $current_course);
+                    //Duplicating the Answers in the current course
+                    $new_answer_obj->duplicate($new_id, $current_course);
 
-					// destruction of the Question object
-					unset($new_question_obj);
-					unset($old_question_obj);
+                    // destruction of the Question object
+                    unset($new_question_obj);
+                    unset($old_question_obj);
 
-					if (!$objExercise instanceOf Exercise) {
-						$objExercise = new Exercise();
-						$objExercise->read($fromExercise);
-					}
-				}
-			}
-		}
-		Session::write('objExercise',$objExercise);
-	}
+                    if (!$objExercise instanceOf Exercise) {
+                        $objExercise = new Exercise();
+                        $objExercise->read($fromExercise);
+                    }
+                }
+            }
+        }
+        Session::write('objExercise',$objExercise);
+    }
 }
 
 if (isset($_SESSION['gradebook'])){
@@ -217,23 +215,25 @@ $htmlHeadXtra[] = "
 	}
 </script>";
 
-Display::display_header($nameTools,'Exercise');
+Display::display_header($nameTools, 'Exercise');
 
 // Menu
 echo '<div class="actions">';
-	if (isset($type)) {
-		$url = api_get_self().'?type=1';
-	} else {
-		$url = api_get_self();
-	}
-	if (isset($fromExercise) && $fromExercise > 0) {
-		echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
-		$titleAdd = get_lang('AddQuestionToTest');
-    } else {
-		echo '<a href="exercice.php?'.api_get_cidReq().'">'.Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
-		echo "<a href='admin.php?exerciseId=0'>".Display::return_icon('add_question.gif', get_lang('NewQu'), '', 32)."</a>";
-		$titleAdd = get_lang('ManageAllQuestions');
-	}
+if (isset($type)) {
+    $url = api_get_self().'?type=1';
+} else {
+    $url = api_get_self();
+}
+if (isset($fromExercise) && $fromExercise > 0) {
+    echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.
+            Display::return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
+    $titleAdd = get_lang('AddQuestionToTest');
+} else {
+    echo '<a href="exercice.php?'.api_get_cidReq().'">'.
+        Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
+    echo "<a href='admin.php?exerciseId=0'>".Display::return_icon('add_question.gif', get_lang('NewQu'), '', ICON_SIZE_MEDIUM)."</a>";
+    $titleAdd = get_lang('ManageAllQuestions');
+}
 echo '</div>';
 
 if ($displayMessage != "") {
@@ -241,9 +241,9 @@ if ($displayMessage != "") {
 	$displayMessage = "";
 }
 
-//Form
+// Form
 echo '<form class="form-horizontal" name="question_pool" method="GET" action="'.$url.'">';
-//Title
+// Title
 echo '<legend>'.$nameTools.' - '.$titleAdd.'</legend>';
 if (isset($type)) {
 	echo '<input type="hidden" name="type" value="1">';
@@ -252,8 +252,6 @@ echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
 
 // Session list, if sessions are used.
 $sessionList = SessionManager::get_sessions_by_user(api_get_user_id(), api_is_platform_admin());
-//$session_list = SessionManager::get_sessions_by_general_coach(api_get_user_id());
-//var_dump($sessionList, $session_list);
 
 $tabAttrParam = array('class'=>'chzn-select', 'onchange'=>'submit_form(this)');
 $labelFormRow = get_lang('Session');
@@ -277,6 +275,19 @@ if (!empty($session_id) && $session_id != '-1' && !empty($sessionList)) {
     $course_list = CourseManager::get_course_list_of_user_as_course_admin(
         api_get_user_id()
     );
+
+    // Admin fix, add the current course in the question pool.
+    if (api_is_platform_admin()) {
+        $courseInfo = api_get_course_info();
+        if (!empty($course_list)) {
+            $courseIdList = array_keys($course_list);
+            if (!in_array($courseInfo['real_id'], $courseIdList)) {
+                $course_list = array_merge($course_list, array($courseInfo));
+            }
+        } else {
+            $course_list = array($courseInfo);
+        }
+    }
 }
 
 $course_select_list = array();
@@ -312,7 +323,7 @@ if ($course_id_changed) {
 }
 
 $course_id = $course_info['real_id'];
-//Redefining table calls
+// Redefining table calls
 $TBL_EXERCICE_QUESTION      = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
 $TBL_EXERCICES              = Database::get_course_table(TABLE_QUIZ_TEST);
 $TBL_QUESTIONS              = Database::get_course_table(TABLE_QUIZ_QUESTION);
@@ -365,6 +376,7 @@ $select_exercise_html =  Display::select(
     array('class'=>'chzn-select','onchange'=>'mark_exercice_id_changed(); submit_form(this);'),
     false
 );
+
 echo Display::form_row(get_lang('Exercise'), $select_exercise_html);
 
 // Difficulty list (only from 0 to 5)
@@ -407,8 +419,15 @@ foreach ($question_list as $key=>$item) {
     }
 }
 
-//Answer type list
-$select_answer_html = Display::select('answerType', $new_question_list, $answerType, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false);
+// Answer type list
+$select_answer_html = Display::select(
+    'answerType',
+    $new_question_list,
+    $answerType,
+    array('class'=>'chzn-select','onchange'=>'submit_form(this);'),
+    false
+);
+
 echo Display::form_row(get_lang('AnswerType'), $select_answer_html);
 $button = '<button class="save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>';
 echo Display::form_row('', $button);
@@ -423,6 +442,7 @@ echo '<input type="hidden" name="course_id" value="'.$selected_course.'">';
 $main_question_list = array();
 
 // if we have selected an exercise in the list-box 'Filter'
+
 if ($exerciseId > 0) {
 	$where = '';
 	$from = '';

+ 2 - 7
main/group/group_creation.php

@@ -5,8 +5,6 @@
  *	@package chamilo.group
  */
 
-/*	INIT SETTINGS */
-
 // Name of the language file that needs to be included
 $language_file = 'group';
 
@@ -41,7 +39,7 @@ if (isset($_POST['action'])) {
                 }
                 if (api_get_setting('allow_group_categories') == 'false') {
                     $group['category'] = GroupManager::DEFAULT_GROUP_CATEGORY;
-                } elseif ($_POST['same_category']) {
+                } elseif (isset($_POST['same_category']) && $_POST['same_category']) {
                     $group['category'] = $_POST['group_0_category'];
                 }
 
@@ -122,8 +120,7 @@ elseif (isset($_POST['number_of_groups'])) {
 
     function copy_value(key) {
         ref = document.getElementById(key+'_0');
-        for( i=1; i<number_of_groups; i++)
-        {
+        for( i=1; i<number_of_groups; i++) {
             element = document.getElementById(key+'_'+i);
             element.value = ref.value;
         }
@@ -178,7 +175,6 @@ EOT;
 			if (api_get_setting('allow_group_categories') == 'true') {
 				$group_el[] = $form->createElement('checkbox', 'same_category', null, get_lang('SameForAll'), array('onclick' => "javascript: switch_state('category');"));
 			}
-			//$group_el[] = $form->createElement('checkbox', 'same_tutor', null, get_lang('SameForAll'), array ('onclick' => "javascript: switch_state('tutor');"));
 			$group_el[] = $form->createElement('checkbox', 'same_places', null, get_lang('SameForAll'), array ('onclick' => "javascript: switch_state('places');"));
 			$form->addGroup($group_el, 'groups', null, '</td><td>', false);
 		}
@@ -307,5 +303,4 @@ EOT;
 	}
 }
 
-/*	FOOTER */
 Display :: display_footer();

+ 2 - 1
main/inc/lib/banner.lib.php

@@ -116,7 +116,8 @@ function get_tabs() {
             if (api_get_setting($tab['variable'], $tab['subkey']) == 'true') {
                 if (!empty($tab['comment']) && $tab['comment'] !== 'ShowTabsComment') {
                     $navigation[$tab['subkey']]['url'] = $tab['comment'];
-                    $navigation[$tab['subkey']]['title'] = $tab['title'];
+                    // $tab['title'] value must be included in trad4all.inc.php
+                    $navigation[$tab['subkey']]['title'] = get_lang($tab['title']);
                     $navigation[$tab['subkey']]['key'] = $tab['subkey'];
                 }
             }

+ 116 - 70
main/inc/lib/groupmanager.lib.php

@@ -154,21 +154,21 @@ class GroupManager
     /**
      * Create a group
      * @param string $name The name for this group
+     * @param int $category_id
      * @param int $tutor The user-id of the group's tutor
      * @param int $places How many people can subscribe to the new group
      */
     public static function create_group($name, $category_id, $tutor, $places)
     {
         $_course = api_get_course_info();
-        $table_group = Database :: get_course_table(TABLE_GROUP);
-
         $session_id = api_get_session_id();
         $course_id  = api_get_course_int_id();
-        $currentCourseRepository = $_course['path'];
 
+
+        $currentCourseRepository = $_course['path'];
         $category = self :: get_category($category_id);
-        $places = intval($places);
 
+        $places = intval($places);
         if ($places == 0) {
             //if the amount of users per group is not filled in, use the setting from the category
             $places = $category['max_student'];
@@ -178,6 +178,7 @@ class GroupManager
             }
         }
 
+        $table_group = Database :: get_course_table(TABLE_GROUP);
         $sql = "INSERT INTO ".$table_group." SET
                 c_id = $course_id ,
                 category_id='".Database::escape_string($category_id)."',
@@ -192,16 +193,30 @@ class GroupManager
                 self_registration_allowed = '".$category['self_reg_allowed']."',
                 self_unregistration_allowed = '".$category['self_unreg_allowed']."',
                 session_id='".Database::escape_string($session_id)."'";
+
         Database::query($sql);
         $lastId = Database::insert_id();
 
         if ($lastId) {
             $desired_dir_name= '/'.replace_dangerous_char($name,'strict').'_groupdocs';
-            $my_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository.'/document';
-            $unique_name = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, null, $my_path, $desired_dir_name, null,  1);
+            $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
+
+            $unique_name = create_unexisting_directory(
+                $_course,
+                api_get_user_id(),
+                $session_id,
+                $lastId,
+                null,
+                $my_path,
+                $desired_dir_name,
+                null,
+                1
+            );
 
             /* Stores the directory path into the group table */
-            $sql = "UPDATE ".$table_group." SET name = '".Database::escape_string($name)."', secret_directory = '".$unique_name."'
+            $sql = "UPDATE ".$table_group." SET
+                    name = '".Database::escape_string($name)."',
+                    secret_directory = '".$unique_name."'
                     WHERE c_id = $course_id AND id ='".$lastId."'";
 
             Database::query($sql);
@@ -234,7 +249,7 @@ class GroupManager
                 $values['approval_direct_group']['approval_direct'] = 0;
                 $values['allow_attachments_group']['allow_attachments'] = 1;
                 $values['allow_new_threads_group']['allow_new_threads'] = 1;
-                $values['default_view_type_group']['default_view_type']=api_get_setting('default_forum_view');
+                $values['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view');
                 $values['group_forum'] = $lastId;
                 if ($category['forum_state'] == '1') {
                     $values['public_private_group_forum_group']['public_private_group_forum']='public';
@@ -347,7 +362,12 @@ class GroupManager
         $group_ids = array();
         foreach ($classes as $class) {
             $users_ids = $obj->get_users_by_usergroup($class['id']);
-            $group_id = self::create_group($class['name'],$category_id,0,count($users_ids));
+            $group_id = self::create_group(
+                $class['name'],
+                $category_id,
+                0,
+                count($users_ids)
+            );
             self::subscribe_users($users_ids,$group_id);
             $group_ids[] = $group_id;
         }
@@ -418,10 +438,12 @@ class GroupManager
         }
 
         // delete the groups
-        $sql = "DELETE FROM ".$group_table." WHERE c_id = $course_id AND id IN ('".implode("' , '", $group_ids)."')";
+        $sql = "DELETE FROM ".$group_table."
+                WHERE c_id = $course_id AND id IN ('".implode("' , '", $group_ids)."')";
         Database::query($sql);
 
-        $sql = "DELETE FROM ".$forum_table." WHERE c_id = $course_id AND forum_of_group IN ('".implode("' , '", $group_ids)."')";
+        $sql = "DELETE FROM ".$forum_table."
+                WHERE c_id = $course_id AND forum_of_group IN ('".implode("' , '", $group_ids)."')";
         Database::query($sql);
 
         return Database::affected_rows();
@@ -442,7 +464,8 @@ class GroupManager
         }
 
         $table_group = Database :: get_course_table(TABLE_GROUP);
-        $sql = "SELECT * FROM $table_group WHERE c_id = $course_id AND id = ".intval($group_id);
+        $sql = "SELECT * FROM $table_group
+                WHERE c_id = $course_id AND id = ".intval($group_id);
         $db_result = Database::query($sql);
         $db_object = Database::fetch_object($db_result);
 
@@ -614,7 +637,9 @@ class GroupManager
     {
         $course_id = api_get_course_int_id();
         $table_group = Database :: get_course_table(TABLE_GROUP);
-        $sql = "SELECT COUNT(id) AS number_of_groups FROM $table_group WHERE c_id = $course_id ";
+        $sql = "SELECT COUNT(id) AS number_of_groups
+                FROM $table_group
+                WHERE c_id = $course_id ";
         $res = Database::query($sql);
         $obj = Database::fetch_object($res);
         return $obj->number_of_groups;
@@ -630,7 +655,8 @@ class GroupManager
         $course_info = api_get_course_info($course_code);
         $course_id     = $course_info['real_id'];
         $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
-        $sql = "SELECT * FROM $table_group_cat WHERE c_id = $course_id ORDER BY display_order";
+        $sql = "SELECT * FROM $table_group_cat
+                WHERE c_id = $course_id ORDER BY display_order";
         $res = Database::query($sql);
         $cats = array ();
         while ($cat = Database::fetch_array($res)) {
@@ -654,7 +680,8 @@ class GroupManager
         $course_id     = $course_info['real_id'];
         $id = Database::escape_string($id);
         $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
-        $sql = "SELECT * FROM $table_group_cat WHERE c_id = $course_id AND id = $id LIMIT 1";
+        $sql = "SELECT * FROM $table_group_cat
+                WHERE c_id = $course_id AND id = $id LIMIT 1";
         $res = Database::query($sql);
         return Database::fetch_array($res);
     }
@@ -696,8 +723,8 @@ class GroupManager
      */
     public static function get_category_from_group($group_id, $course_code = null)
     {
-        $table_group         = Database :: get_course_table(TABLE_GROUP);
-        $table_group_cat     = Database :: get_course_table(TABLE_GROUP_CATEGORY);
+        $table_group = Database:: get_course_table(TABLE_GROUP);
+        $table_group_cat = Database:: get_course_table(TABLE_GROUP_CATEGORY);
 
         if (empty($group_id)) {
             return array();
@@ -708,9 +735,11 @@ class GroupManager
 
         $group_id = Database::escape_string($group_id);
         $sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g
-                WHERE     gc.c_id = $course_id AND
-                        g.c_id = $course_id AND
-                        gc.id = g.category_id AND g.id= $group_id LIMIT 1";
+                WHERE
+                    gc.c_id = $course_id AND
+                    g.c_id = $course_id AND
+                    gc.id = g.category_id AND g.id= $group_id
+                LIMIT 1";
         $res = Database::query($sql);
         $cat = array();
         if (Database::num_rows($res)) {
@@ -730,10 +759,11 @@ class GroupManager
         $course_info = api_get_course_info($course_code);
         $course_id     = $course_info['real_id'];
 
-        $table_group         = Database :: get_course_table(TABLE_GROUP);
-        $table_group_cat     = Database :: get_course_table(TABLE_GROUP_CATEGORY);
-        $cat_id             = Database::escape_string($cat_id);
-        $sql = "SELECT id FROM $table_group WHERE c_id = $course_id AND category_id='".$cat_id."'";
+        $table_group = Database:: get_course_table(TABLE_GROUP);
+        $table_group_cat = Database:: get_course_table(TABLE_GROUP_CATEGORY);
+        $cat_id = Database::escape_string($cat_id);
+        $sql = "SELECT id FROM $table_group
+                WHERE c_id = $course_id AND category_id='".$cat_id."'";
         $res = Database::query($sql);
         if (Database::num_rows($res) > 0) {
             $groups_to_delete = array ();
@@ -776,7 +806,9 @@ class GroupManager
         $table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY);
         $course_id = api_get_course_int_id();
 
-        $sql = "SELECT MAX(display_order)+1 as new_order FROM $table_group_category WHERE c_id = $course_id ";
+        $sql = "SELECT MAX(display_order)+1 as new_order
+                FROM $table_group_category
+                WHERE c_id = $course_id ";
         $res = Database::query($sql);
         $obj = Database::fetch_object($res);
         if (!isset ($obj->new_order)) {
@@ -801,7 +833,8 @@ class GroupManager
         Database::query($sql);
         $categoryId = Database::insert_id();
         if ($categoryId == self::VIRTUAL_COURSE_CATEGORY) {
-            $sql = "UPDATE  ".$table_group_category." SET id = ". ($categoryId +1)." WHERE c_id = $course_id AND id = $categoryId";
+            $sql = "UPDATE  ".$table_group_category." SET id = ". ($categoryId +1)."
+                    WHERE c_id = $course_id AND id = $categoryId";
             Database::query($sql);
             return $categoryId +1;
         }
@@ -899,7 +932,8 @@ class GroupManager
         $course_info = api_get_course_info ($course_code);
         $group_table = Database :: get_course_table(TABLE_GROUP);
         $group_user_table = Database :: get_course_table(TABLE_GROUP_USER);
-        $sql = 'SELECT COUNT(gu.group_id) AS current_max FROM '.$group_user_table.' gu, '.$group_table.' g
+        $sql = 'SELECT COUNT(gu.group_id) AS current_max
+                FROM '.$group_user_table.' gu, '.$group_table.' g
 				WHERE g.c_id = '.$course_info['real_id'].'
 				AND gu.c_id = g.c_id
 				AND gu.group_id = g.id ';
@@ -923,17 +957,18 @@ class GroupManager
         $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
         $id1 = Database::escape_string($id1);
         $id2 = Database::escape_string($id2);
-
         $course_id = api_get_course_int_id();
 
-
-        $sql = "SELECT id,display_order FROM $table_group_cat WHERE id IN ($id1,$id2) AND c_id = $course_id ";
+        $sql = "SELECT id,display_order FROM $table_group_cat
+                WHERE id IN ($id1,$id2) AND c_id = $course_id ";
         $res = Database::query($sql);
         $cat1 = Database::fetch_object($res);
         $cat2 = Database::fetch_object($res);
-        $sql = "UPDATE $table_group_cat SET display_order=$cat2->display_order WHERE id = $cat1->id AND c_id = $course_id ";
+        $sql = "UPDATE $table_group_cat SET display_order=$cat2->display_order
+                WHERE id = $cat1->id AND c_id = $course_id ";
         Database::query($sql);
-        $sql = "UPDATE $table_group_cat SET display_order=$cat1->display_order WHERE id = $cat2->id AND c_id = $course_id ";
+        $sql = "UPDATE $table_group_cat SET display_order=$cat1->display_order
+                WHERE id = $cat2->id AND c_id = $course_id ";
         Database::query($sql);
     }
 
@@ -1015,7 +1050,8 @@ class GroupManager
         $tutor_user_table = Database :: get_course_table(TABLE_GROUP_TUTOR);
         $course_id = api_get_course_int_id();
         $group_id = intval($group_id);
-        $sql = "SELECT user_id FROM $group_user_table WHERE c_id = $course_id AND group_id = $group_id";
+        $sql = "SELECT user_id FROM $group_user_table
+                WHERE c_id = $course_id AND group_id = $group_id";
         $res = Database::query($sql);
         $users = array();
 
@@ -1023,7 +1059,8 @@ class GroupManager
             $users[] = api_get_user_info($obj->user_id);
         }
 
-        $sql = "SELECT user_id FROM $tutor_user_table WHERE c_id = $course_id AND group_id = $group_id";
+        $sql = "SELECT user_id FROM $tutor_user_table
+                WHERE c_id = $course_id AND group_id = $group_id";
         $res = Database::query($sql);
         while ($obj = Database::fetch_object($res)) {
             $users[] = api_get_user_info($obj->user_id);
@@ -1042,7 +1079,8 @@ class GroupManager
         $course_id = api_get_course_int_id();
         $group_id = intval($group_id);
 
-        $sql = "SELECT user_id FROM $tutor_user_table WHERE c_id = $course_id AND group_id = $group_id";
+        $sql = "SELECT user_id FROM $tutor_user_table
+                WHERE c_id = $course_id AND group_id = $group_id";
         $res = Database::query($sql);
         while ($obj = Database::fetch_object($res)) {
             $users[] = api_get_user_info($obj->user_id);
@@ -1060,7 +1098,8 @@ class GroupManager
         $group_user_table = Database :: get_course_table(TABLE_GROUP_USER);
         $course_id = api_get_course_int_id();
         $group_id = intval($group_id);
-        $sql = "SELECT user_id FROM $group_user_table WHERE c_id = $course_id AND group_id = $group_id";
+        $sql = "SELECT user_id FROM $group_user_table
+                WHERE c_id = $course_id AND group_id = $group_id";
         $res = Database::query($sql);
         $users = array();
 
@@ -1098,19 +1137,19 @@ class GroupManager
     /**
      * Fill the groups with students.
      * The algorithm takes care to first fill the groups with the least # of users.
-     *    Analysis
-     *    There was a problem with the "ALL" setting.
-     *    When max # of groups is set to all, the value is sometimes NULL and sometimes ALL
-     *    and in both cased the query does not work as expected.
-     *    Stupid solution (currently implemented: set ALL to a big number (INFINITE) and things are solved :)
-     *    Better solution: that's up to you.
+     * Analysis
+     * There was a problem with the "ALL" setting.
+     * When max # of groups is set to all, the value is sometimes NULL and sometimes ALL
+     * and in both cased the query does not work as expected.
+     * Stupid solution (currently implemented: set ALL to a big number (INFINITE) and things are solved :)
+     * Better solution: that's up to you.
      *
-     *    Note
-     *    Throughout Dokeos there is some confusion about "course id" and "course code"
-     *    The code is e.g. TEST101, but sometimes a variable that is called courseID also contains a course code string.
-     *    However, there is also a integer course_id that uniquely identifies the course.
-     *    ywarnier:> Now the course_id has been removed (25/1/2005)
-     *    The databases are als very inconsistent in this.
+     * Note
+     * Throughout Dokeos there is some confusion about "course id" and "course code"
+     * The code is e.g. TEST101, but sometimes a variable that is called courseID also contains a course code string.
+     * However, there is also a integer course_id that uniquely identifies the course.
+     * ywarnier:> Now the course_id has been removed (25/1/2005)
+     * The databases are als very inconsistent in this.
      *
      * @author Chrisptophe Gesche <christophe.geshe@claroline.net>,
      *         Hugues Peeters     <hugues.peeters@claroline.net> - original version
@@ -1137,12 +1176,11 @@ class GroupManager
             }
         }
 
-        $category             = self::get_category_from_group($group_ids[0]);
-
-        $groups_per_user     = $category['groups_per_user'];
-        $group_table         = Database :: get_course_table(TABLE_GROUP);
-        $group_user_table     = Database :: get_course_table(TABLE_GROUP_USER);
-        $session_id         = api_get_session_id();
+        $category = self::get_category_from_group($group_ids[0]);
+        $groups_per_user = $category['groups_per_user'];
+        $group_table = Database:: get_course_table(TABLE_GROUP);
+        $group_user_table = Database:: get_course_table(TABLE_GROUP_USER);
+        $session_id = api_get_session_id();
 
         $complete_user_list = CourseManager :: get_real_and_linked_user_list($_course['code'], true, $session_id);
         $number_groups_per_user = ($groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user);
@@ -1232,7 +1270,8 @@ class GroupManager
         } else {
             $course_id = intval($course_id);
         }
-        $sql = "SELECT  COUNT(*) AS number_of_students FROM $table_group_user WHERE c_id = $course_id AND group_id = $group_id";
+        $sql = "SELECT  COUNT(*) AS number_of_students FROM $table_group_user
+                WHERE c_id = $course_id AND group_id = $group_id";
         $db_result = Database::query($sql);
         $db_object = Database::fetch_object($db_result);
         return $db_object->number_of_students;
@@ -1274,11 +1313,13 @@ class GroupManager
             $cat_condition = " AND g.category_id =  $cat_id ";
         }
 
-        $sql = "SELECT  COUNT(*) AS number_of_groups FROM $table_group_user gu, $table_group g
-                WHERE     gu.c_id     = $course_id AND
-                        g.c_id         = $course_id AND
-                        gu.user_id     = $user_id AND
-                        g.id         = gu.group_id  $cat_condition";
+        $sql = "SELECT  COUNT(*) AS number_of_groups
+                FROM $table_group_user gu, $table_group g
+                WHERE
+                    gu.c_id     = $course_id AND
+                    g.c_id         = $course_id AND
+                    gu.user_id     = $user_id AND
+                    g.id         = gu.group_id  $cat_condition";
         $db_result = Database::query($sql);
         $db_object = Database::fetch_object($db_result);
         return $db_object->number_of_groups;
@@ -1299,7 +1340,9 @@ class GroupManager
         $table_group = Database :: get_course_table(TABLE_GROUP);
         $group_id = intval($group_id);
         if (isset($group_id)) {
-            $sql = "SELECT  self_registration_allowed FROM $table_group WHERE c_id = $course_id AND id = $group_id";
+            $sql = "SELECT  self_registration_allowed
+                    FROM $table_group
+                    WHERE c_id = $course_id AND id = $group_id";
             $db_result = Database::query($sql);
             $db_object = Database::fetch_object($db_result);
             return $db_object->self_registration_allowed == 1 && self :: can_user_subscribe($user_id, $group_id);
@@ -1323,7 +1366,9 @@ class GroupManager
         $group_id = Database::escape_string($group_id);
         $course_id = api_get_course_int_id();
         $db_result = Database::query(
-            'SELECT  self_unregistration_allowed FROM '.$table_group.' WHERE c_id = '.$course_id.' AND id = '.$group_id
+            'SELECT  self_unregistration_allowed
+             FROM '.$table_group.'
+             WHERE c_id = '.$course_id.' AND id = '.$group_id
         );
         $db_object = Database::fetch_object($db_result);
 
@@ -1588,7 +1633,8 @@ class GroupManager
         $group_ids = is_array($group_ids) ? $group_ids : array($group_ids);
         if (count($group_ids) > 0) {
             $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR);
-            $sql = 'DELETE FROM '.$table_group_tutor.' WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id;
+            $sql = 'DELETE FROM '.$table_group_tutor.'
+                    WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id;
             $result = Database::query($sql);
             return $result;
         }
@@ -1610,7 +1656,8 @@ class GroupManager
         $group_id = Database::escape_string($group_id);
         $course_id = api_get_course_int_id();
 
-        $sql = "SELECT * FROM ".$table_group_tutor." WHERE c_id = $course_id AND user_id='".$user_id."' AND group_id='".$group_id."'";
+        $sql = "SELECT * FROM ".$table_group_tutor."
+                WHERE c_id = $course_id AND user_id='".$user_id."' AND group_id='".$group_id."'";
         $result = Database::query($sql);
         if (Database::num_rows($result) > 0) {
             return true;
@@ -1621,8 +1668,11 @@ class GroupManager
 
     /**
      * Is the user part of this group? This can be a tutor or a normal member
-     * you should use this function if the access to a tool or functionality is restricted to the people who are actually in the group
-     * before you had to check if the user was 1. a member of the group OR 2. a tutor of the group. This function combines both
+     * you should use this function if the access to a tool or functionality is
+     * restricted to the people who are actually in the group
+     * before you had to check if the user was
+     * 1. a member of the group OR
+     * 2. a tutor of the group. This function combines both
      * @param int $user_id the id of the user
      * @param int $group_id the id of the group
      * @return boolean true/false
@@ -1722,10 +1772,6 @@ class GroupManager
         return $groups;
     }
 
-    /*
-        Group functions - these take virtual/linked courses into account when necessary
-    */
-
     /**
      *    Get a combined list of all users of the real course $course_code
      *        and all users in virtual courses linked to this course $course_code

+ 2 - 2
main/inc/lib/plugin.class.php

@@ -653,7 +653,7 @@ class Plugin
         $pluginName = strtolower($langString);
         $pluginUrl = 'plugin/'.$pluginName.'/'.$filePath;
         if ($showTab === 'true') {
-            $tabAdded = $this->addTab($this->get_lang($langString), $pluginUrl);
+            $tabAdded = $this->addTab($langString, $pluginUrl);
             if ($tabAdded) {
                 // The page must be refreshed to show the recently created tab
                 echo "<script>location.href = '".Security::remove_XSS($_SERVER['REQUEST_URI'])."';</script>";
@@ -663,7 +663,7 @@ class Plugin
             $conditions = array(
                 'where' => array(
                     "variable = 'show_tabs' AND title = ? AND comment = ? " => array(
-                        $this->get_lang($langString),
+                        $langString,
                         $pluginUrl
                     )
                 )

Різницю між файлами не показано, бо вона завелика
+ 951 - 32
main/inc/lib/tracking.lib.php


+ 38 - 53
main/mySpace/lp_tracking.php

@@ -4,10 +4,15 @@
  * Learning paths reporting
  * @package chamilo.reporting
  */
-/**
- * Code
- */
-$language_file = array ('registration', 'index', 'tracking', 'exercice', 'scorm', 'learnpath');
+
+$language_file = array(
+    'registration',
+    'index',
+    'tracking',
+    'exercice',
+    'scorm',
+    'learnpath'
+);
 require_once '../inc/global.inc.php';
 
 // resetting the course id
@@ -26,82 +31,62 @@ require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
 require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
 
 $session_id  = isset($_REQUEST['id_session']) && !empty($_REQUEST['id_session']) ? intval($_REQUEST['id_session']) : api_get_session_id();
-
 $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
-if ($export_csv) {
-	ob_start();
-}
+$user_id = isset($_GET['student_id']) ? intval($_GET['student_id']) : api_get_user_id();
+$courseCode = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : api_get_course_id();
+$origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
+$lp_id = intval($_GET['lp_id']);
 $csv_content = array();
-$user_id = intval($_GET['student_id']);
-
-if (isset($_GET['course'])) {
-	$cidReq = Security::remove_XSS($_GET['course']);
-}
-
-$user_infos = UserManager :: get_user_info_by_id($user_id);
-$name = api_get_person_name($user_infos['firstname'], $user_infos['lastname']);
+$course_info = api_get_course_info($courseCode);
 
-if (!api_is_platform_admin(true) && !CourseManager :: is_course_teacher(api_get_user_id(), $cidReq) && !Tracking :: is_allowed_to_coach_student(api_get_user_id(), $_GET['student_id']) && !api_is_drh() && !api_is_course_tutor()) {
-	api_not_allowed();
+if (empty($course_info) || empty($lp_id)) {
+    api_not_allowed();
 }
-$course_exits = CourseManager::course_exists($cidReq);
+$userInfo = api_get_user_info($user_id);
+$name = $userInfo['complete_name'];
 
-if (!empty($course_exits)) {
-	$course_info = api_get_course_info($cidReq);
-} else {
+if (!api_is_platform_admin(true) &&
+    !CourseManager :: is_course_teacher(api_get_user_id(), $courseCode) &&
+    !Tracking :: is_allowed_to_coach_student(api_get_user_id(), $user_id) && !api_is_drh() && !api_is_course_tutor()) {
 	api_not_allowed();
 }
 
-if (!empty($_GET['origin']) && $_GET['origin'] == 'user_course') {
+if ($origin == 'user_course') {
 	$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$course_info['directory'], 'name' => $course_info['name']);
-	$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".$cidReq, "name" => get_lang("Users"));
-} else if(!empty($_GET['origin']) && $_GET['origin'] == 'tracking_course') {
-	$interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$cidReq.'&id_session='.$session_id, "name" => get_lang("Tracking"));
+	$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".$courseCode, "name" => get_lang("Users"));
+} else if($origin == 'tracking_course') {
+	$interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$courseCode.'&id_session='.$session_id, "name" => get_lang("Tracking"));
 } else {
 	$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
 	$interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang("MyStudents"));
- 	$interbreadcrumb[] = array ("url" => "myStudents.php?student=".Security::remove_XSS($_GET['student_id']), "name" => get_lang("StudentDetails"));
+ 	$interbreadcrumb[] = array ("url" => "myStudents.php?student=".$user_id, "name" => get_lang("StudentDetails"));
  	$nameTools=get_lang("DetailsStudentInCourse");
 }
 
-$interbreadcrumb[] = array("url" => "myStudents.php?student=".Security::remove_XSS($_GET['student_id'])."&course=".$cidReq."&details=true&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("DetailsStudentInCourse"));
+$interbreadcrumb[] = array("url" => "myStudents.php?student=".$user_id."&course=".$courseCode."&details=true&origin=".$origin , "name" => get_lang("DetailsStudentInCourse"));
 $nameTools = get_lang('LearningPathDetails');
-Display :: display_header($nameTools);
-
-$lp_id = intval($_GET['lp_id']);
-
 $sql = 'SELECT name	FROM '.Database::get_course_table(TABLE_LP_MAIN).' WHERE c_id = '.$course_info['real_id'].' AND id='.$lp_id;
 $rs  = Database::query($sql);
 $lp_title = Database::result($rs, 0, 0);
+
+$origin = 'tracking';
+
+$output = require_once api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php';
+
+Display :: display_header($nameTools);
 echo '<div class ="actions">';
 echo '<a href="javascript:history.back();">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '<a href="javascript: void(0);" onclick="javascript: window.print();">
-'.Display::return_icon('printer.png',get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
+        '.Display::return_icon('printer.png',get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '<a href="'.api_get_self().'?export=csv&'.Security::remove_XSS($_SERVER['QUERY_STRING']).'">
-'.Display::return_icon('export_csv.png',get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a>';
+        '.Display::return_icon('export_csv.png',get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '</div>';
-
 echo '<div class="clear"></div>';
-
 $session_name = api_get_session_name($session_id);
 $table_title = ($session_name? Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.$session_name.' ':' ').
-                Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_info['name'].' '.
-                Display::return_icon('user.png', get_lang('User'), array(), ICON_SIZE_SMALL).' '.$name;
+    Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_info['name'].' '.
+    Display::return_icon('user.png', get_lang('User'), array(), ICON_SIZE_SMALL).' '.$name;
 echo Display::page_header($table_title);
 echo Display::page_subheader('<h3>'.Display::return_icon('learnpath.png', get_lang('ToolLearnpath'), array(), ICON_SIZE_SMALL).' '.$lp_title.'</h3>');
-
-//Needed in newscorm/lp_stats.php
-$list = learnpath :: get_flat_ordered_items_list($lp_id, 0, $course_info['real_id']);
-
-$origin = 'tracking';
-if ($export_csv) {
-	require_once api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php';
-} else {
-	ob_start();
-	require_once  api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php';
-	$tracking_content = ob_get_contents();
-	ob_end_clean();
-	echo api_utf8_decode($tracking_content, $charset);
-
-}
+echo $output;
 Display :: display_footer();

+ 2 - 1
main/newscorm/lp_controller.php

@@ -1095,7 +1095,8 @@ switch ($action) {
         else {
             $_SESSION['oLP']->save_current();
             $_SESSION['oLP']->save_last();
-            require 'lp_stats.php';
+            $output = require 'lp_stats.php';
+            echo $output;
         }
         break;
     case 'list':

+ 29 - 984
main/newscorm/lp_stats.php

@@ -6,1002 +6,47 @@
  * This script must be included by lp_controller.php to get basic initialisation
  * @package chamilo.learnpath
  * @author Yannick Warnier <ywarnier@beeznest.org>
- * @todo clean this file like the exercise files J.M
  */
 
 require_once 'learnpath.class.php';
 require_once 'resourcelinker.inc.php';
 require_once '../exercice/exercise.lib.php';
 
-$course_code = api_get_course_id();
-
-if (empty($user_id)) {
-    $user_id = api_get_user_id();
-}
-
-// Declare variables to be used in lp_stats.php
-// When checking the reporting myspace/lp_tracking.php
-
-if (isset($lp_id) && !empty($lp_id)) {
-    $lp_id = intval($lp_id);
-    if (!isset($list)) {
-        $list = learnpath::get_flat_ordered_items_list($lp_id);
-    }
-} else {
-    if (isset($_SESSION['oLP'])) {
-        $lp_id = $_SESSION['oLP']->get_id();
-        $list = learnpath::get_flat_ordered_items_list($lp_id);
-    }
-}
-
-$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
-
-if (isset($_GET['course'])) {
-    $course_code = Security::remove_XSS($_GET['course']);
-}
-
-$course_info = api_get_course_info($course_code);
-$course_id = $course_info['real_id'];
-
-if (isset($_GET['student_id'])) {
-    $student_id = intval($_GET['student_id']);
-}
-$session_id = isset($_GET['id_session']) ? intval($_GET['id_session']) : api_get_session_id();
-$session_condition = api_get_session_condition($session_id);
-
-//When origin is not set that means that the lp_stats are viewed from the "man running" icon
+// When origin is not set that means that the lp_stats are viewed from the "man running" icon
 if (!isset($origin)) {
     $origin = 'learnpath';
 }
 
-//Origin = tracking means that teachers see that info in the Reporting tool
+$sessionId = isset($_GET['id_session']) ? intval($_GET['id_session']) : api_get_session_id();
+$courseCode = isset($_GET['course']) ? intval($_GET['course']) : api_get_course_id();
+$userId = isset($_GET['student_id']) ? intval($_GET['student_id']) : api_get_user_id();
+$lpId = isset($_GET['lp_id']) ? $_GET['lp_id'] : null;
+$lpItemId = isset($_GET['lp_item_id']) ? $_GET['lp_item_id'] : null;
+$extendId = isset($_GET['extend_id']) ? $_GET['extend_id'] : null;
+$extendAttemptId = isset($_GET['extend_attempt_id']) ? $_GET['extend_attempt_id'] : null;
+$extendedAttempt = isset($_GET['extend_attempt']) ? $_GET['extend_attempt'] : null;
+$extendedAll = isset($_GET['extend_all']) ? $_GET['extend_all'] : null;
+$export = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
+
+$courseInfo = api_get_course_info($courseCode);
+$output = Tracking::getLpStats(
+    $userId,
+    $courseInfo,
+    $sessionId,
+    $origin,
+    $export,
+    $lpId,
+    $lpItemId,
+    $extendId,
+    $extendAttemptId,
+    $extendedAttempt,
+    $extendedAll
+);
+
+// Origin = tracking means that teachers see that info in the Reporting tool
 if ($origin != 'tracking') {
     Display::display_reduced_header();
-}
-
-$output = '';
-
-//Extend all button
-$extend_all_link = '';
-$extend_all = 0;
-if ($origin == 'tracking') {
-    $url_suffix = '&session_id=' . $session_id . '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($_GET['lp_id']) . '&origin=' . Security::remove_XSS($_GET['origin']) . $from_link;
-} else {
-    $url_suffix = '&lp_id=' . $lp_id;
-}
-if (!empty($_GET['extend_all'])) {
-    $extend_all_link = '<a href="' . api_get_self() . '?action=stats' . $url_suffix . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="' . get_lang('HideAllAttempts') . '"></a>';
-    $extend_all = 1;
-} else {
-    $extend_all_link = '<a href="' . api_get_self() . '?action=stats&extend_all=1' . $url_suffix . '"><img src="../img/view_more_stats.gif" alt="extend_view" border="0" title="' . get_lang('ShowAllAttempts') . '"></a>';
-}
-
-if ($origin != 'tracking') {
-    $output .= Display::page_header(get_lang('ScormMystatus'));
-}
-
-$output .= '<table class="data_table">
-            <tr>
-                <th width="16">' . $extend_all_link . '</th>
-                <th colspan="4">
-                    ' . get_lang('ScormLessonTitle') .'
-                </th>
-                <th colspan="2">
-                    ' . get_lang('ScormStatus') . '
-                </th>
-                <th colspan="2">
-                    ' . get_lang('ScormScore') . '
-                </th>
-                <th colspan="2">
-                    ' . get_lang('ScormTime') . '
-                </th>
-                <th>
-                    ' . get_lang('Actions') . '
-                </th>
-           </tr>';
-
-// Going through the items using the $items[] array instead of the database order ensures
-// we get them in the same order as in the imsmanifest file, which is rather random when using
-// the database table.
-
-$TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
-$TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
-$TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
-$tbl_quiz_questions = Database :: get_course_table(TABLE_QUIZ_QUESTION);
-$TBL_QUIZ = Database :: get_course_table(TABLE_QUIZ_TEST);
-$tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
-$tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
-
-$sql = "SELECT max(view_count) FROM $TBL_LP_VIEW
-        WHERE
-            c_id = $course_id AND
-            lp_id = $lp_id AND
-            user_id = '" . $user_id . "' $session_condition";
-$res = Database::query($sql);
-$view = '';
-$num = 0;
-if (Database :: num_rows($res) > 0) {
-    $myrow = Database :: fetch_array($res);
-    $view = $myrow[0];
-}
-
-$counter = 0;
-$total_score = 0;
-$total_time = 0;
-$h = get_lang('h');
-
-if (!empty($export_csv)) {
-    $csv_content[] = array(
-        get_lang('ScormLessonTitle'),
-        get_lang('ScormStatus'),
-        get_lang('ScormScore'),
-        get_lang('ScormTime')
-    );
-}
-
-// Get attempts of a exercise.
-if (isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) {
-    $clean_lp_item_id = Database::escape_string($_GET['lp_item_id']);
-    $clean_lp_id = Database::escape_string($_GET['lp_id']);
-    $clean_course_code = Database :: escape_string($course_code);
-    $sql = "SELECT path FROM $TBL_LP_ITEM
-            WHERE c_id = $course_id AND
-            id = '$clean_lp_item_id' AND
-            lp_id = '$clean_lp_id'";
-    $res_path = Database::query($sql);
-    $row_path = Database::fetch_array($res_path);
-
-    if (Database::num_rows($res_path) > 0) {
-        if ($origin != 'tracking') {
-            $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . '
-            				 WHERE
-            				    exe_exo_id="' . (int) $row_path['path'] . '" AND
-                                status <> "incomplete"  AND
-                                exe_user_id="' . api_get_user_id() . '" AND
-                                orig_lp_id = "' . (int) $clean_lp_id . '" AND
-                                orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND
-                                exe_cours_id="' . $clean_course_code . '"  AND
-                                session_id = ' . $session_id . '
-                             ORDER BY exe_date';
-        } else {
-            $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . '
-            				 WHERE
-            				    exe_exo_id="' . (int) $row_path['path'] . '" AND
-                                status <> "incomplete"  AND
-                                exe_user_id="' . $student_id . '" AND
-                                orig_lp_id = "' . (int) $clean_lp_id . '" AND
-                                orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND
-                                exe_cours_id="' . $clean_course_code . '"  AND
-                                session_id = ' . $session_id . '
-                             ORDER BY exe_date';
-        }
-    }
-}
-
-//Show lp items
-if (is_array($list) && count($list) > 0) {
-    foreach ($list as $my_item_id) {
-        $extend_this = 0;
-        $qry_order = 'DESC';
-        if ((!empty($_GET['extend_id']) && $_GET['extend_id'] == $my_item_id) || $extend_all) {
-            $extend_this = 1;
-            $qry_order = 'ASC';
-        }
-
-        // Prepare statement to go through each attempt.
-        if (!empty($view)) {
-            $sql = "SELECT
-                        iv.status as mystatus,
-                        v.view_count as mycount,
-                        iv.score as myscore,
-                        iv.total_time as mytime,
-                        i.id as myid,
-                        i.lp_id as mylpid,
-                        iv.lp_view_id as mylpviewid,
-                        i.title as mytitle,
-                        i.max_score as mymaxscore,
-                        iv.max_score as myviewmaxscore,
-                        i.item_type as item_type,
-                        iv.view_count as iv_view_count,
-                        iv.id as iv_id,
-                        path
-                    FROM $TBL_LP_ITEM as i
-                    INNER JOIN $TBL_LP_ITEM_VIEW as iv
-                    ON (i.id = iv.lp_item_id  AND i.c_id = $course_id AND iv.c_id = $course_id)
-                    INNER JOIN $TBL_LP_VIEW as v
-                    ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
-            WHERE
-                i.id = $my_item_id AND
-                i.lp_id = $lp_id  AND
-                v.user_id = $user_id AND
-                v.view_count = $view AND
-                v.session_id = $session_id
-            ORDER BY iv.view_count $qry_order ";
-
-        } else {
-            $sql = "SELECT
-                        iv.status as mystatus,
-                        v.view_count as mycount,
-                        iv.score as myscore,
-                        iv.total_time as mytime,
-                        i.id as myid,
-                        i.lp_id as mylpid,
-                        iv.lp_view_id as mylpviewid,
-                        i.title as mytitle,
-                        i.max_score as mymaxscore,
-                        iv.max_score as myviewmaxscore,
-                        i.item_type as item_type,
-                        iv.view_count as iv_view_count,
-                        iv.id as iv_id,
-                        path
-                    FROM $TBL_LP_ITEM as i
-                    INNER JOIN $TBL_LP_ITEM_VIEW as iv
-                    ON (i.id = iv.lp_item_id  AND i.c_id = $course_id AND iv.c_id = $course_id)
-                    INNER JOIN $TBL_LP_VIEW as v
-                    ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
-                    WHERE
-                        i.id = $my_item_id AND
-                        i.lp_id = $lp_id AND
-                        v.user_id = $user_id AND
-                        v.session_id = $session_id
-                   ORDER BY iv.view_count $qry_order ";
-        }
-
-        $result = Database::query($sql);
-        $num = Database :: num_rows($result);
-        $time_for_total = 'NaN';
-
-        //Extend all + extend scorm?
-        if (($extend_this || $extend_all) && $num > 0) {
-            $row = Database :: fetch_array($result);
-            $result_disabled_ext_all = false;
-            if ($row['item_type'] == 'quiz') {
-                // Check results_disabled in quiz table.
-                $my_path = Database::escape_string($row['path']);
-
-                $sql = "SELECT results_disabled FROM $TBL_QUIZ
-                        WHERE c_id = $course_id AND id ='" . $my_path . "'";
-                $res_result_disabled = Database::query($sql);
-                $row_result_disabled = Database::fetch_row($res_result_disabled);
-
-                if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
-                    $result_disabled_ext_all = true;
-                }
-            }
-
-            // If there are several attempts, and the link to extend has been clicked, show each attempt...
-            if (($counter % 2) == 0) {
-                $oddclass = 'row_odd';
-            } else {
-                $oddclass = 'row_even';
-            }
-            $extend_link = '';
-            if (!empty($inter_num)) {
-                $extend_link = '<a href="' . api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix . '">
-                                <img src="../img/visible.gif" alt="' . get_lang('HideAttemptView') . '" title="' . get_lang('HideAttemptView') . '"  border="0">
-                                </a>';
-            }
-            $title = $row['mytitle'];
-
-            if (empty($title)) {
-                $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
-            }
-
-            if ($row['item_type'] != 'dokeos_chapter') {
-                $correct_test_link = '-';
-                $title = Security::remove_XSS($title);
-                $output .= '<tr class="'.$oddclass.'">
-                                <td>'.$extend_link.'</td>
-                                <td colspan="4">
-                                    '.$title.'
-                                </td>
-                                <td colspan="2"></td>
-                                <td colspan="2"></td>
-                                <td colspan="2"></td>
-                                <td></td>
-                            </tr>';
-            }
-            $counter++;
-
-            $attemptCount = 1;
-
-            do {
-                // Check if there are interactions below.
-                $extend_attempt_link = '';
-                $extend_this_attempt = 0;
-
-                if ((learnpath :: get_interactions_count_from_db($row['iv_id'], $course_id) > 0 ||
-                    learnpath :: get_objectives_count_from_db($row['iv_id'], $course_id) > 0) &&
-                    !$extend_all
-                ) {
-                    if (!empty($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
-                        // The extend button for this attempt has been clicked.
-                        $extend_this_attempt = 1;
-                        $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix . '">
-                            <img src="../img/visible.gif" alt="' . get_lang('HideAttemptView') . '" title="' . get_lang('HideAttemptView') . '" border="0"></a>';
-                    } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
-                        // The extend button for this attempt has not been clicked.
-                        $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix . '">
-                            <img src="../img/invisible.gif" alt="' . get_lang('ExtendAttemptView') . '" title="' . get_lang('ExtendAttemptView') . '"  border="0"></a>';
-                    }
-                }
-
-                if (($counter % 2) == 0) {
-                    $oddclass = 'row_odd';
-                } else {
-                    $oddclass = 'row_even';
-                }
-
-                $lesson_status = $row['mystatus'];
-                $score = $row['myscore'];
-                $time_for_total = $row['mytime'];
-                $time = learnpathItem :: getScormTimeFromParameter('js', $row['mytime']);
-                $scoIdentifier = $row['myid'];
-
-                if ($score == 0) {
-                    $maxscore = $row['mymaxscore'];
-                } else {
-                    if ($row['item_type'] == 'sco') {
-                        if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
-                            $maxscore = $row['myviewmaxscore'];
-                        } elseif ($row['myviewmaxscore'] === '') {
-                            $maxscore = 0;
-                        } else {
-                            $maxscore = $row['mymaxscore'];
-                        }
-                    } else {
-                        $maxscore = $row['mymaxscore'];
-                    }
-                }
-
-                // Remove "NaN" if any (@todo: locate the source of these NaN)
-                $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
-
-                if ($row['item_type'] != 'dokeos_chapter') {
-                    if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                        $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
-                    } else {
-                        switch ($row['item_type']) {
-                            case 'sco':
-                                if ($maxscore == 0) {
-                                    $view_score = $score;
-                                } else {
-                                    $view_score = show_score($score, $maxscore, false);
-                                }
-                                break;
-                            case 'document':
-                                $view_score = ($score == 0 ? '/' : show_score($score, $maxscore, false));
-                                break;
-                            default:
-                                $view_score = show_score($score, $maxscore, false);
-                                break;
-                        }
-                    }
-
-                    $output .= '<tr class="' . $oddclass . '">
-                                    <td></td>
-                                    <td>' . $extend_attempt_link . '</td>
-                                    <td colspan="3">' . get_lang('Attempt') . ' ' . $attemptCount . '</td>
-                                    <td colspan="2">' . learnpathItem::humanize_status($lesson_status) . '</td>
-                                    <td colspan="2">' . $view_score . '</td>
-                                    <td colspan="2">' . $time . '</td>
-                                    <td></td>
-                                </tr>';
-                    $attemptCount++;
-                    if (!empty($export_csv)) {
-                        $temp = array();
-                        $temp[] = $title = Security::remove_XSS($title);
-                        $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false));
-
-                        if ($row['item_type'] == 'quiz') {
-                            if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                                $temp[] = '/';
-                            } else {
-                                $temp[] = ($score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
-                            }
-                        } else {
-                            $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
-                        }
-                        $temp[] = $time;
-                        $csv_content[] = $temp;
-                    }
-                }
-
-                $counter++;
-
-                if ($extend_this_attempt OR $extend_all) {
-                    $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
-                    foreach ($list1 as $id => $interaction) {
-                        if (($counter % 2) == 0) {
-                            $oddclass = 'row_odd';
-                        } else {
-                            $oddclass = 'row_even';
-                        }
-                        $student_response = urldecode($interaction['student_response']);
-                        $content_student_response = array();
-                        $content_student_response = explode('__|', $student_response);
-
-                        if (count($content_student_response) > 0) {
-                            if (count($content_student_response) >= 3) {
-                                // Pop the element off the end of array.
-                                $new_content_student_response = array_pop($content_student_response);
-                            }
-                            $student_response = implode(',', $content_student_response);
-                        }
-                        $output .= '<tr class="'.$oddclass.'">
-                                        <td></td>
-                                        <td></td>
-                                        <td></td>
-                                        <td>'.$interaction['order_id'] . '</td>
-                                        <td>'.$interaction['id'] . '</td>
-                                        <td colspan="2">' . $interaction['type'].'</td>
-                                        <td>'.$student_response . '</td>
-                                        <td>'.$interaction['result'] . '</td>
-                                        <td>'.$interaction['latency'] . '</td>
-                                        <td>'.$interaction['time'] . '</td>
-                                        <td></td>
-                                    </tr>';
-                        $counter++;
-                    }
-                    $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
-
-                    foreach ($list2 as $id => $interaction) {
-                        if (($counter % 2) == 0) {
-                            $oddclass = 'row_odd';
-                        } else {
-                            $oddclass = 'row_even';
-                        }
-                        $output .= '<tr class="'.$oddclass.'">
-                                        <td></td>
-                                        <td></td>
-                                        <td></td>
-                                        <td>' . $interaction['order_id'] . '</td>
-                                        <td colspan="2">' . $interaction['objective_id'] . '</td>
-                                        <td colspan="2">' . $interaction['status'] .'</td>
-                                        <td>' . $interaction['score_raw'] . '</td>
-                                        <td>' . $interaction['score_max'] . '</td>
-                                        <td>' . $interaction['score_min'] . '</td>
-                                        <td></td>
-                                     </tr>';
-                        $counter++;
-                    }
-                }
-            } while ($row = Database :: fetch_array($result));
-        } elseif ($num > 0) {
-            //Not extended
-
-            $row = Database :: fetch_array($result, 'ASSOC');
-            $my_id = $row['myid'];
-            $my_lp_id = $row['mylpid'];
-            $my_lp_view_id = $row['mylpviewid'];
-            $my_path = $row['path'];
-
-            $result_disabled_ext_all = false;
-
-            if ($row['item_type'] == 'quiz') {
-                // Check results_disabled in quiz table.
-                $my_path = Database::escape_string($my_path);
-
-                $sql = "SELECT results_disabled FROM $TBL_QUIZ
-                        WHERE c_id = $course_id AND id ='" . (int) $my_path . "'";
-                $res_result_disabled = Database::query($sql);
-                $row_result_disabled = Database::fetch_row($res_result_disabled);
-
-                if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
-                    $result_disabled_ext_all = true;
-                }
-            }
-
-            // Check if there are interactions below
-            $extend_this_attempt = 0;
-
-            $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id);
-            $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
-
-            $extend_attempt_link = '';
-            if (($inter_num > 0 || $objec_num > 0)) {
-                if (!empty($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
-                    // The extend button for this attempt has been clicked.
-                    $extend_this_attempt = 1;
-                    $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix . '">
-                        <img src="../img/visible.gif" alt="' . get_lang('HideAttemptView') . '" title="' . get_lang('HideAttemptView') . '" border="0">
-                        </a>';
-                } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
-                    // The extend button for this attempt has not been clicked.
-                    $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix . '">
-                        <img src="../img/invisible.gif" alt="' . get_lang('ExtendAttemptView') . '" title="' . get_lang('ExtendAttemptView') . '" border="0">
-                        </a>';
-                }
-            }
-
-            if (($counter % 2) == 0) {
-                $oddclass = 'row_odd';
-            } else {
-                $oddclass = 'row_even';
-            }
-
-            $extend_link = '';
-            if ($inter_num > 1) {
-                $extend_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix . '">
-                    <img src="../img/invisible.gif" alt="' . get_lang('ExtendAttemptView') . '" title="' . get_lang('ExtendAttemptView') . '"  border="0">
-                </a>';
-            }
-
-            $lesson_status = $row['mystatus'];
-            $score = $row['myscore'];
-            $subtotal_time = $row['mytime'];
-
-            while ($tmp_row = Database :: fetch_array($result)) {
-                $subtotal_time += $tmp_row['mytime'];
-            }
-            $scoIdentifier = $row['myid'];
-            $title = $row['mytitle'];
-
-            // Selecting the exe_id from stats attempts tables in order to look the max score value.
-            if ($origin != 'tracking') {
-                $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
-                                     WHERE
-                                        exe_exo_id="' . $row['path'] . '" AND
-                                        exe_user_id="' . api_get_user_id() . '" AND
-                                        orig_lp_id = "' . $lp_id . '" AND
-                                        orig_lp_item_id = "' . $row['myid'] . '" AND
-                                        exe_cours_id="' . $course_code . '" AND
-                                        status <> "incomplete" AND
-                                        session_id = ' . $session_id . '
-                                     ORDER BY exe_date DESC limit 1';
-            } else {
-                $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
-                                     WHERE
-                                        exe_exo_id="' . $row['path'] . '" AND
-                                        exe_user_id="' . $student_id . '" AND
-                                        orig_lp_id = "' . $lp_id . '" AND
-                                        orig_lp_item_id = "' . $row['myid'] . '" AND
-                                        exe_cours_id="' . $course_code . '" AND
-                                        status <> "incomplete" AND
-                                        session_id = ' . $session_id . '
-                                     ORDER BY exe_date DESC limit 1';
-            }
-
-            $resultLastAttempt = Database::query($sql_last_attempt);
-            $num = Database :: num_rows($resultLastAttempt);
-            if ($num > 0) {
-                while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
-                    $id_last_attempt = $rowLA['exe_id'];
-                }
-            }
-
-            if ($score == 0) {
-                $maxscore = $row['mymaxscore'];
-            } else {
-                if ($row['item_type'] == 'sco') {
-                    if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
-                        $maxscore = $row['myviewmaxscore'];
-                    } elseif ($row['myviewmaxscore'] === '') {
-                        $maxscore = 0;
-                    } else {
-                        $maxscore = $row['mymaxscore'];
-                    }
-                } else {
-                    if ($row['item_type'] == 'quiz') {
-                        // Get score and total time from last attempt of a exercise en lp.
-                        $sql = "SELECT score FROM $TBL_LP_ITEM_VIEW
-                                WHERE
-                                    c_id = $course_id AND
-                                    lp_item_id = '" . (int) $my_id . "' AND
-                                    lp_view_id = '" . (int) $my_lp_view_id . "'
-                                ORDER BY view_count DESC limit 1";
-                        $res_score = Database::query($sql);
-                        $row_score = Database::fetch_array($res_score);
-
-                        $sql = "SELECT SUM(total_time) as total_time FROM $TBL_LP_ITEM_VIEW
-                                WHERE
-                                    c_id = $course_id AND
-                                    lp_item_id = '" . (int) $my_id . "' AND
-                                    lp_view_id = '" . (int) $my_lp_view_id . "'";
-                        $res_time = Database::query($sql);
-                        $row_time = Database::fetch_array($res_time);
-
-                        if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) {
-                            $score = (float) $row_score['score'];
-                            $subtotal_time = (int) $row_time['total_time'];
-                        } else {
-                            $score = 0;
-                            $subtotal_time = 0;
-                        }
-                        // Selecting the max score from an attempt.
-                        $sql = "SELECT SUM(t.ponderation) as maxscore
-                                FROM (
-                        			SELECT distinct question_id, marks, ponderation
-                                    FROM $tbl_stats_attempts as at INNER JOIN  $tbl_quiz_questions as q
-                        			ON (q.id = at.question_id AND q.c_id = $course_id
-                                    )
-                                WHERE exe_id ='$id_last_attempt' ) as t";
-
-                        $result = Database::query($sql);
-                        $row_max_score = Database :: fetch_array($result);
-                        $maxscore = $row_max_score['maxscore'];
-                    } else {
-                        $maxscore = $row['mymaxscore'];
-                    }
-                }
-            }
-
-            $time_for_total = $subtotal_time;
-            $time = learnpathItem :: getScormTimeFromParameter('js', $subtotal_time);
-            if (empty($title)) {
-                $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
-            }
-            // Remove "NaN" if any (@todo: locate the source of these NaN)
-            //$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
-
-            if ($row['item_type'] != 'dokeos_chapter') {
-                if ($row['item_type'] == 'quiz') {
-                    $correct_test_link = '';
-                    $my_url_suffix = '';
-
-                    if ($origin != 'tracking' && $origin != 'tracking_course') {
-                        $my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
-                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
-                                             WHERE  exe_exo_id="' . $row['path'] . '" AND
-                                                    exe_user_id="' . api_get_user_id() . '" AND
-                                                    orig_lp_id = "' . $lp_id . '" AND
-                                                    orig_lp_item_id = "' . $row['myid'] . '" AND
-                                                    exe_cours_id="' . $course_code . '" AND
-                                                    status <> "incomplete" AND
-                                                    session_id = ' . $session_id . '
-                                            ORDER BY exe_date DESC ';
-                    } else {
-                        $my_url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($row['mylpid']) . '&origin=' . Security::remove_XSS($_GET['origin'] . $from_link);
-                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
-                                             WHERE   exe_exo_id="' . $row['path'] . '" AND
-                                                    exe_user_id="' . $student_id . '" AND
-                                                    orig_lp_id = "' . $lp_id . '" AND
-                                                    orig_lp_item_id = "' . $row['myid'] . '" AND
-                                                    exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND
-                                                    status <> "incomplete" AND
-                                                    session_id = ' . $session_id . '
-                                             ORDER BY exe_date DESC ';
-                    }
-
-                    $resultLastAttempt = Database::query($sql_last_attempt);
-                    $num = Database :: num_rows($resultLastAttempt);
-                    if ($num > 0) {
-                        if (isset($_GET['extend_attempt']) && $_GET['extend_attempt'] == 1 && (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id) && (isset($_GET['lp_item_id']) && $_GET['lp_item_id'] == $my_id)) {
-                            $correct_test_link = '<a href="' . api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '">
-                            <img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="' . get_lang('HideAllAttempts') . '"></a>';
-                        } else {
-                            $correct_test_link = '<a href="' . api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '">
-                            <img src="../img/view_more_stats.gif" alt="extend_view" border="0" title="' . get_lang('ShowAllAttemptsByExercise') . '"></a>';
-                        }
-                    } else {
-                        $correct_test_link = '-';
-                    }
-                } else {
-                    $correct_test_link = '-';
-                }
-
-                $title = Security::remove_XSS($title);
-
-                if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id && false)) {
-
-                    $output .= '<tr class =' . $oddclass . '>
-                                    <td>' . $extend_link . '</td>
-                                    <td colspan="4">' . $title . '</td>
-                                    <td colspan="2">&nbsp;</td>
-                                    <td colspan="2">&nbsp;</td>
-                                    <td colspan="2">&nbsp;</td>
-                                    <td>' . $correct_test_link . '</td>
-                                </tr>';
-                    $output .= '</tr>';
-                } else {
-                    if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) &&
-                        (isset($_GET['lp_item_id']) && $_GET['lp_item_id'] == $my_id)
-                    ) {
-                        $output .= "<tr class='$oddclass'>";
-                    } else {
-                        $output .= "<tr class='$oddclass'>";
-                    }
-
-                    if (($is_allowed_to_edit || api_is_drh()) && isset($_GET['lp_id']) && isset($course_code)) {
-                        $lp = new learnpath($course_code, $_GET['lp_id'], api_get_user_id());
-                        $lp->set_course_int_id($course_id);
-                        $item_path_url = $lp->get_link('http', $my_id, false);
-                        $item_path_url .= "&width=600";
-                        $title = Display::url($title, $item_path_url, array('class' => 'ajax'));
-                    }
-
-                    $output .= '<td>'.$extend_link.'</td>
-                                <td colspan="4">' . $title . '</td>
-                                <td colspan="2">' . learnpathitem::humanize_status($lesson_status) .'</td>
-                                <td colspan="2">';
-                    if ($row['item_type'] == 'quiz') {
-                        if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                            $output .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
-                        } else {
-                            $output .= show_score($score, $maxscore, false);
-                        }
-                    } else {
-                        $output .= ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
-                    }
-                    $output .= '</td>
-                                <td colspan="2">'.$time.'</td>
-                                 <td>'.$correct_test_link.'</td>';
-                    $output .= '</tr>';
-                }
-
-                if (!empty($export_csv)) {
-                    $temp = array();
-                    $temp[] = api_html_entity_decode($title, ENT_QUOTES);
-                    $temp[] = api_html_entity_decode($my_lesson_status, ENT_QUOTES);
-
-                    if ($row['item_type'] == 'quiz') {
-                        if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                            $temp[] = '/';
-                        } else {
-                            $temp[] = ($score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
-                        }
-                    } else {
-                        $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
-                    }
-                    $temp[] = $time;
-                    $csv_content[] = $temp;
-                }
-            }
-
-            $counter++;
-            if ($extend_this_attempt OR $extend_all) {
-                $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
-
-                foreach ($list1 as $id => $interaction) {
-                    if (($counter % 2) == 0) {
-                        $oddclass = 'row_odd';
-                    } else {
-                        $oddclass = 'row_even';
-                    }
-                    $output .= '<tr class="'.$oddclass.'">
-                                    <td></td>
-                                    <td></td>
-                                    <td></td>
-                                    <td>'.$interaction['order_id'].'</td>
-                                    <td>'.$interaction['id'].'</td>
-                                    <td colspan="2">' . $interaction['type'].'</td>
-                                    <td>'.urldecode($interaction['student_response']).'</td>
-                                    <td>'.$interaction['result'].'</td>
-                                    <td>'.$interaction['latency'].'</td>
-                                    <td>'.$interaction['time'].'</td>
-                                    <td></td>
-                               </tr>';
-                    $counter++;
-                }
-                $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
-                foreach ($list2 as $id => $interaction) {
-                    if (($counter % 2) == 0) {
-                        $oddclass = 'row_odd';
-                    } else {
-                        $oddclass = 'row_even';
-                    }
-                    $output .= '<tr class="'.$oddclass.'">
-                                    <td></td>
-                                    <td></td>
-                                    <td></td>
-                                    <td>' . $interaction['order_id'] . '</td>
-                                    <td colspan="2">'.$interaction['objective_id'] . '</td>
-                                    <td colspan="2">' . $interaction['status'] . '</td>
-                                    <td>' . $interaction['score_raw'].'</td>
-                                    <td>' . $interaction['score_max'] .'</td>
-                                    <td>' . $interaction['score_min'].'</td>
-                                    <td></td>
-                               </tr>';
-                    $counter++;
-                }
-            }
-
-            // Attempts listing by exercise.
-            if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id) &&
-                (isset($_GET['lp_item_id']) && $_GET['lp_item_id'] == $my_id) &&
-                isset($_GET['extend_attempt'])
-            ) {
-
-                $res_attempts = Database::query($sql_attempts);
-                $num_attempts = Database :: num_rows($res_attempts);
-                if ($row['item_type'] === 'quiz') {
-                    if ($num_attempts > 0) {
-                        $n = 1;
-                        while ($row_attempts = Database :: fetch_array($res_attempts)) {
-                            $my_score = $row_attempts['exe_result'];
-                            $my_maxscore = $row_attempts['exe_weighting'];
-                            $my_exe_id = $row_attempts['exe_id'];
-                            $my_orig_lp = $row_attempts['orig_lp_id'];
-                            $my_orig_lp_item = $row_attempts['orig_lp_item_id'];
-                            $my_exo_exe_id = $row_attempts['exe_exo_id'];
-                            $mktime_start_date = api_strtotime($row_attempts['start_date'], 'UTC');
-                            $mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC');
-                            if ($mktime_start_date && $mktime_exe_date) {
-                                $mytime = ((int) $mktime_exe_date - (int) $mktime_start_date);
-                                $time_attemp = learnpathItem :: getScormTimeFromParameter('js', $mytime);
-                                $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
-                            } else {
-                                $time_attemp = ' - ';
-                            }
-                            if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                                $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
-                            } else {
-                                // Show only float when need it
-                                if ($my_score == 0) {
-                                    $view_score = show_score(0, $my_maxscore, false);
-                                } else {
-                                    if ($my_maxscore == 0) {
-                                        $view_score = $my_score;
-                                    } else {
-                                        $view_score = show_score($my_score, $my_maxscore, false);
-                                    }
-                                }
-                            }
-                            $my_lesson_status = $row_attempts['status'];
-
-                            if ($my_lesson_status == '') {
-                                $my_lesson_status = learnpathitem::humanize_status('completed');
-                            } elseif ($my_lesson_status == 'incomplete') {
-                                $my_lesson_status = learnpathitem::humanize_status('incomplete');
-                            }
-
-                            $output .= '<tr class="' . $oddclass . '" >
-                                            <td></td>
-                                            <td>' . $extend_attempt_link . '</td>
-                                            <td colspan="3">' . get_lang('Attempt').' '. $n.'</td>
-                                            <td colspan="2">' . $my_lesson_status . '</td>
-                                            <td colspan="2">'.$view_score . '</td>
-                                            <td colspan="2">'.$time_attemp . '</td>';
-                            if ($origin != 'tracking') {
-                                if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                                    $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></td>';
-                                } else {
-                                    $output .= '<td><a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $course_code . $from_link . '" target="_parent">
-                                                    <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></a></td>';
-                                }
-                            } else {
-                                if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                                    $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></td>';
-                                } else {
-                                    $output .= '<td><a href="../exercice/exercise_show.php?cidReq=' . $course_code . '&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent">
-                                                     <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>';
-                                }
-                            }
-                            $output .= '</tr>';
-                            $n++;
-                        }
-                    }
-                    $output .= '<tr><td colspan="12">&nbsp;</td></tr>';
-                }
-            }
-        }
-
-        $total_time += $time_for_total;
-        // QUIZZ IN LP
-        $a_my_id = array();
-        if (!empty($my_lp_id)) {
-            $a_my_id[] = $my_lp_id;
-        }
-    }
-}
-//NOT Extend all "left green cross"
-if (!empty($a_my_id)) {
-    $my_studen_id = 0;
-    $my_course_id = '';
-    if ($origin == 'tracking') {
-        $my_studen_id = $student_id;
-        $my_course_id = Database::escape_string($_GET['course']);
-    } else {
-        $my_studen_id = intval(api_get_user_id());
-        $my_course_id = Database::escape_string(api_get_course_id());
-    }
-    if (isset($_GET['extend_attempt'])) {
-        // "Right green cross" extended
-        $total_score = Tracking::get_avg_student_score(
-            $my_studen_id,
-            $my_course_id,
-            $a_my_id,
-            $session_id,
-            false,
-            false
-        );
-
-    } else {
-        // "Left green cross" extended
-        $total_score = Tracking::get_avg_student_score(
-            $my_studen_id,
-            $my_course_id,
-            $a_my_id,
-            $session_id,
-            false,
-            true
-        );
-    }
-} else {
-    // Extend all "left green cross"
-    if ($origin == 'tracking') {
-        $my_course_id = Database::escape_string($_GET['course']);
-        if (!empty($student_id) && !empty($my_course_id)) {
-            $total_score = Tracking::get_avg_student_score(
-                $student_id,
-                $my_course_id,
-                array(intval($_GET['lp_id'])),
-                $session_id,
-                false,
-                false
-            );
-        } else {
-            $total_score = 0;
-        }
-    } else {
-        $total_score = Tracking::get_avg_student_score(
-            api_get_user_id(),
-            api_get_course_id(),
-            array(intval($_GET['lp_id'])),
-            $session_id,
-            false,
-            false
-        );
-    }
-}
-
-$total_time = learnpathItem :: getScormTimeFromParameter('js', $total_time);
-$total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
-
-if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-    $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
-} else {
-    if (is_numeric($total_score)) {
-        $final_score = $total_score . '%';
-    } else {
-        $final_score = $total_score;
-    }
-}
-
-if (($counter % 2) == 0) {
-    $oddclass = 'row_odd';
-} else {
-    $oddclass = 'row_even';
-}
-
-$output .= '<tr class="'.$oddclass.'">
-                <td></td>
-                <td colspan="4">
-                    <i>' . get_lang('AccomplishedStepsTotal') .'</i>
-                </td>
-                <td colspan="2"></td>
-                <td colspan="2">
-                    ' . $final_score.'
-                </td>
-                <td colspan="2">' . $total_time . '</div><td></td>
-           </tr>';
-
-$output .= "</table>";
-
-if (!empty($export_csv)) {
-    $temp = array(
-        '',
-        '',
-        '',
-        ''
-    );
-    $csv_content[] = $temp;
-    $temp = array(
-        get_lang('AccomplishedStepsTotal'),
-        '',
-        $final_score,
-        $total_time
-    );
-    $csv_content[] = $temp;
-    ob_end_clean();
-    Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
-    exit;
-}
-
-if ($origin != 'tracking') {
     $output .= "</body></html>";
 }
 
-if (empty($export_csv)) {
-    echo $output;
-}
+return $output;

Деякі файли не було показано, через те що забагато файлів було змінено