Browse Source

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

Yannick Warnier 10 years ago
parent
commit
e15f228b35

+ 31 - 27
main/calendar/agenda_js.php

@@ -93,8 +93,14 @@ switch ($type) {
         if (api_is_anonymous()) {
             api_not_allowed(true);
         }
-        $extra_field_data = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'google_calendar_url');
-        if (!empty($extra_field_data) && isset($extra_field_data['google_calendar_url']) && !empty($extra_field_data['google_calendar_url'])) {
+        $extra_field_data = UserManager::get_extra_user_data_by_field(
+            api_get_user_id(),
+            'google_calendar_url'
+        );
+        if (!empty($extra_field_data) &&
+            isset($extra_field_data['google_calendar_url']) &&
+            !empty($extra_field_data['google_calendar_url'])
+        ) {
             $tpl->assign('use_google_calendar', 1);
             $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
         }
@@ -149,7 +155,7 @@ $actions = $agenda->displayActions('calendar', $userId);
 
 $tpl->assign('actions', $actions);
 
-//Calendar Type : course, admin, personal
+// Calendar Type : course, admin, personal
 $tpl->assign('type', $type);
 
 $type_event_class = $type.'_event';
@@ -189,37 +195,35 @@ if (!empty($userId)) {
 $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
 $course_code = api_get_course_id();
 
-//if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
+$form = new FormValidator('form', 'get', null, null, array('id' => 'add_event_form'));
+$form->addElement('html', '<div id="visible_to_input">');
 
-    $form = new FormValidator('form', 'get', null, null, array('id' => 'add_event_form'));
-    $form->addElement('html', '<div id="visible_to_input">');
+$sendTo = $agenda->parseAgendaFilter($userId);
+$addOnlyItemsInSendTo = true;
 
-    $sendTo = $agenda->parseAgendaFilter($userId);
-    $addOnlyItemsInSendTo = true;
+if ($sendTo['everyone']) {
+    $addOnlyItemsInSendTo = false;
+}
 
-    if ($sendTo['everyone']) {
-        $addOnlyItemsInSendTo = false;
-    }
+$agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
+$form->addElement('html', '</div>');
 
-    $agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
-    $form->addElement('html', '</div>');
+$form->addElement('html', '<div id="visible_to_read_only" style="display: none">');
+$form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
+$form->addElement('html', '</div>');
 
-    $form->addElement('html', '<div id="visible_to_read_only" style="display: none">');
-    $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
+$form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
+$form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
+$form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
+$form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content'));
+
+if ($agenda->type == 'course') {
+    $form->addElement('html', '<div id="add_as_announcement_div" style="display: none">');
+    $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
     $form->addElement('html', '</div>');
+}
 
-    $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
-    $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
-    $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
-    $form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content'));
-    if ($agenda->type == 'course') {
-        $form->addElement('html', '<div id="add_as_announcement_div" style="display: none">');
-        $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
-        $form->addElement('html', '</div>');
-    }
-
-    $tpl->assign('form_add', $form->return_form());
-//}
+$tpl->assign('form_add', $form->return_form());
 
 // Loading Agenda template.
 $content = $tpl->fetch('default/agenda/month.tpl');

+ 40 - 29
main/exercice/exercise_show.php

@@ -161,37 +161,38 @@ $show_only_total_score  = false;
 
 // Avoiding the "Score 0/0" message  when the exe_id is not set
 if (!empty($track_exercise_info)) {
-	// if the results_disabled of the Quiz is 1 when block the script
-	$result_disabled		= $track_exercise_info['results_disabled'];
-
-	if (!(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) ) {
-		if ($result_disabled == 1) {
-			//api_not_allowed();
-			$show_results = false;
-			//Display::display_warning_message(get_lang('CantViewResults'));
-			if ($origin != 'learnpath') {
-			    echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
+    // if the results_disabled of the Quiz is 1 when block the script
+    $result_disabled		= $track_exercise_info['results_disabled'];
+
+    if (!(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) ) {
+        if ($result_disabled == 1) {
+            $show_results = false;
+            if ($origin != 'learnpath') {
+                echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
                       <tr>
                         <td colspan="2">';
-				Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'<br /><br /><a href="exercice.php">'.(get_lang('BackToExercisesList')).'</a>', false);
-				echo '</td>
-				</tr>
-				</table>';
-			}
-		} elseif ($result_disabled == 2) {
-		    $show_results = false;
-		    $show_only_total_score = true;
-			if ($origin != 'learnpath') {
-			    echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
+                Display::display_warning_message(
+                    get_lang('ThankYouForPassingTheTest').'<br /><br /><a href="exercice.php">'.(get_lang('BackToExercisesList')).'</a>',
+                    false
+                );
+                echo '</td>
+                </tr>
+                </table>';
+            }
+        } elseif ($result_disabled == 2) {
+            $show_results = false;
+            $show_only_total_score = true;
+            if ($origin != 'learnpath') {
+                echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
                       <tr>
                         <td colspan="2">';
-				Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
-				echo '</td>
-				</tr>
-				</table>';
-			}
-		}
-	}
+                Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
+                echo '</td>
+                </tr>
+                </table>';
+            }
+        }
+    }
 } else {
 	Display::display_warning_message(get_lang('CantViewResults'));
 	$show_results = false;
@@ -204,7 +205,10 @@ if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
 if ($show_results || $show_only_total_score) {
     $user_info = api_get_user_info($student_id);
     //Shows exercise header
-    echo $objExercise->show_exercise_result_header($user_info, api_convert_and_format_date($exercise_date));
+    echo $objExercise->show_exercise_result_header(
+        $user_info,
+        api_convert_and_format_date($exercise_date)
+    );
 }
 
 $i = $totalScore = $totalWeighting = 0;
@@ -574,10 +578,17 @@ foreach ($questionList as $questionId) {
     $my_total_score  = $questionScore;
 	$my_total_weight = $questionWeighting;
     $totalWeighting += $questionWeighting;
-
     $category_was_added_for_this_test = false;
 
     if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
+        if (!isset($category_list[$objQuestionTmp->category]['score'])) {
+            $category_list[$objQuestionTmp->category]['score'] = 0;
+        }
+
+        if (!isset($category_list[$objQuestionTmp->category]['total'])) {
+            $category_list[$objQuestionTmp->category]['total'] = 0;
+        }
+
         $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
         $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
         $category_was_added_for_this_test = true;

+ 32 - 4
main/inc/ajax/agenda.ajax.php

@@ -138,13 +138,41 @@ switch ($action) {
             }
             $monthName = $MonthsLong[$month - 1];
 
-            $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year);
-            $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
+            $agendaitems = get_myagendaitems(
+                $user_id,
+                $my_course_list,
+                $month,
+                $year
+            );
+            $agendaitems = get_global_agenda_items(
+                $agendaitems,
+                $day,
+                $month,
+                $year,
+                $week,
+                "month_view"
+            );
 
             if (api_get_setting('allow_personal_agenda') == 'true') {
-                $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view");
+                $agendaitems = get_personal_agenda_items(
+                    $user_id,
+                    $agendaitems,
+                    $day,
+                    $month,
+                    $year,
+                    $week,
+                    "month_view"
+                );
             }
-            display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false);
+            display_mymonthcalendar(
+                $user_id,
+                $agendaitems,
+                $month,
+                $year,
+                array(),
+                $monthName,
+                false
+            );
         }
         break;
     default:

+ 1 - 4
main/inc/lib/course.lib.php

@@ -1381,7 +1381,7 @@ class CourseManager
             }
             $where[] = ' course_rel_user.course_code IS NOT NULL ';
 
-            if (isset($filter_by_status) && $filter_by_status != '') {
+            if (isset($filter_by_status) && is_numeric($filter_by_status)) {
                 $filter_by_status = intval($filter_by_status);
                 $filter_by_status_condition = " course_rel_user.status = $filter_by_status AND ";
             }
@@ -1429,7 +1429,6 @@ class CourseManager
         }
 
         $sql .= ' '.$order_by.' '.$limit;
-
         $rs = Database::query($sql);
         $users = array();
 
@@ -2866,7 +2865,6 @@ class CourseManager
                 $rowcfv = Database::fetch_array($rescfv);
                 if ($rowcfv['field_value'] != $fvalues) {
                     $sqlu = "UPDATE $t_cfv SET field_value = '$fvalues', tms = FROM_UNIXTIME($tms) WHERE id = ".$rowcfv['id'];
-                    //error_log('UM::update_extra_field_value: '.$sqlu);
                     $resu = Database::query($sqlu);
                     return ($resu ? true : false);
                 }
@@ -2874,7 +2872,6 @@ class CourseManager
             } else {
                 $sqli = "INSERT INTO $t_cfv (course_code,field_id,field_value,tms) " .
                     "VALUES ('$course_code',".$rowcf['id'].",'$fvalues',FROM_UNIXTIME($tms))";
-                //error_log('UM::update_extra_field_value: '.$sqli);
                 $resi = Database::query($sqli);
                 return ($resi ? true : false);
             }

+ 18 - 12
main/inc/lib/display.lib.php

@@ -1340,18 +1340,28 @@ class Display
                   //  var_dump($item_property);
                 }
                 // Also drop announcements and events that are not for the user or his group.
-                if (($item_property['tool'] == TOOL_ANNOUNCEMENT
-                         || $item_property['tool'] == TOOL_CALENDAR_EVENT)
-                   && (($item_property['to_user_id'] != $user_id )
-                         && (!isset($item_property['to_group_id'])
-                             || !in_array($item_property['to_group_id'], $group_ids)))) {
+                if ((
+                        $item_property['tool'] == TOOL_ANNOUNCEMENT ||
+                        $item_property['tool'] == TOOL_CALENDAR_EVENT
+                    ) &&
+                    (
+                        ($item_property['to_user_id'] != $user_id) &&
+                        (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))
+                ) {
                    continue;
                 }
                 // If it's a survey, make sure the user's invited. Otherwise drop it.
                 if ($item_property['tool'] == TOOL_SURVEY) {
                     $survey_info = survey_manager::get_survey($item_property['ref'], 0, $course_code);
-                    $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code);
-                    if (!in_array($user_id, $invited_users['course_users'])) continue;
+                    if (!empty($survey_info)) {
+                        $invited_users = SurveyUtil::get_invited_users(
+                            $survey_info['code'],
+                            $course_code
+                        );
+                        if (!in_array($user_id, $invited_users['course_users'])) {
+                            continue;
+                        }
+                    }
                 }
                 // If it's a learning path, ensure it is currently visible to the user
                 if ($item_property['tool'] == TOOL_LEARNPATH) {
@@ -1367,11 +1377,6 @@ class Display
             }
         }
 
-        if ($course_info['real_id'] == 1) {
-            /*var_dump($notifications);
-            exit;*/
-        }
-
         // Show all tool icons where there is something new.
         $retvalue = '&nbsp;';
         while (list($key, $notification) = each($notifications)) {
@@ -1386,6 +1391,7 @@ class Display
             $retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$course_code.'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.
                             Display::return_icon($notification['image'], $label).'</a>&nbsp;';
         }
+
         return $retvalue;
     }
 

+ 10 - 14
main/inc/lib/mail.lib.inc.php

@@ -79,8 +79,8 @@ function api_mail_html(
     $recipient_email,
     $subject,
     $message,
-    $sender_name = '',
-    $sender_email = '',
+    $senderName = '',
+    $senderEmail = '',
     $extra_headers = array(),
     $data_file = array(),
     $embedded_image = false,
@@ -106,23 +106,19 @@ function api_mail_html(
     $mail->Priority = 3;
     $mail->SMTPKeepAlive = true;
 
-    // Default values:
-    $mail->From = api_get_setting('emailAdministrator');
-    $mail->Sender = api_get_setting('emailAdministrator');
-    $mail->FromName = api_get_setting('administratorName').' '.api_get_setting('administratorSurname');
+    // Default values
+    $notification = new Notification();
+    $defaultEmail = $notification->getDefaultPlatformSenderEmail();
+    $defaultName = $notification->getDefaultPlatformSenderName();
 
     // Error to admin.
-    $mail->AddCustomHeader('Errors-To: '.$mail->From);
+    $mail->AddCustomHeader('Errors-To: '.$defaultEmail);
 
     // If the parameter is set don't use the admin.
-    $mail->From = !empty($sender_email) ? $sender_email : $mail->From;
-    $mail->Sender = !empty($sender_email) ? $sender_email : $mail->Sender;
-    $mail->FromName =  !empty($sender_name) ? $sender_name : $mail->FromName;
+    $senderName = !empty($senderName) ? $senderName : $defaultEmail;
+    $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultName;
 
-    // Add reply
-    if (!empty($sender_email) && !empty($sender_name)) {
-        $mail->AddReplyTo($sender_email, $sender_name);
-    }
+    $mail->SetFrom($senderEmail, $senderName, false);
 
     if (isset($extra_headers['reply_to'])) {
         $mail->AddReplyTo(

+ 48 - 28
main/inc/lib/message.lib.php

@@ -18,11 +18,10 @@ define('MESSAGE_STATUS_INVITATION_DENIED', '7');
 /**
  * Class MessageManager
  *
- * 	This class provides methods for messages management.
- * 	Include/require it in your code to use its features.
- *
- * 	@package chamilo.library
+ * This class provides methods for messages management.
+ * Include/require it in your code to use its features.
  *
+ * @package chamilo.library
  */
 class MessageManager
 {
@@ -48,8 +47,9 @@ class MessageManager
      */
     public static function display_success_message($uid)
     {
-        if ($_SESSION['social_exist'] === true) {
-            $redirect = "#remote-tab-2";
+        if (isset($_SESSION['social_exist']) &&
+            $_SESSION['social_exist'] === true
+        ) {
             if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
                 $success = get_lang('MessageSentTo').
                     "&nbsp;<b>".
@@ -192,15 +192,15 @@ class MessageManager
     /**
      * Sends a message to a user/group
      *
-     * @param int 	  $receiver_user_id
+     * @param int 	   $receiver_user_id
      * @param string  $subject
      * @param string  $content
      * @param array   $file_attachments files array($_FILES) (optional)
      * @param array   $file_comments about attachment files (optional)
-     * @param int     $group_id id (optional)
-     * @param int     $parent_id id (optional)
-     * @param int 	  $edit_message_id id for updating the message (optional)
-     * @param int     $topic_id id (optional) the default value is the current user_id
+     * @param int     $group_id (optional)
+     * @param int     $parent_id (optional)
+     * @param int 	   $edit_message_id id for updating the message (optional)
+     * @param int     $topic_id (optional) the default value is the current user_id
      * @param int     $sender_id
      * @return bool
      */
@@ -249,7 +249,10 @@ class MessageManager
         if (empty($subject) && empty($group_id)) {
             return get_lang('YouShouldWriteASubject');
         } else if ($total_filesize > intval(api_get_setting('message_max_upload_filesize'))) {
-            return sprintf(get_lang("FilesSizeExceedsX"), format_file_size(api_get_setting('message_max_upload_filesize')));
+            return sprintf(
+                get_lang("FilesSizeExceedsX"),
+                format_file_size(api_get_setting('message_max_upload_filesize'))
+            );
         }
 
         $inbox_last_id = null;
@@ -267,7 +270,9 @@ class MessageManager
             //message in inbox for user friend
             //@todo it's possible to edit a message? yes, only for groups
             if ($edit_message_id) {
-                $query = " UPDATE $table_message SET update_date = '".$now."', content = '$clean_content'
+                $query = " UPDATE $table_message SET
+                                update_date = '".$now."',
+                                content = '$clean_content'
                            WHERE id = '$edit_message_id' ";
                 Database::query($query);
                 $inbox_last_id = $edit_message_id;
@@ -283,7 +288,14 @@ class MessageManager
                 $i = 0;
                 foreach ($file_attachments as $file_attach) {
                     if ($file_attach['error'] == 0) {
-                        self::save_message_attachment_file($file_attach, $file_comments[$i], $inbox_last_id, null, $receiver_user_id, $group_id);
+                        self::save_message_attachment_file(
+                            $file_attach,
+                            $file_comments[$i],
+                            $inbox_last_id,
+                            null,
+                            $receiver_user_id,
+                            $group_id
+                        );
                     }
                     $i++;
                 }
@@ -301,7 +313,12 @@ class MessageManager
                     $o = 0;
                     foreach ($file_attachments as $file_attach) {
                         if ($file_attach['error'] == 0) {
-                            self::save_message_attachment_file($file_attach, $file_comments[$o], $outbox_last_id, $user_sender_id);
+                            self::save_message_attachment_file(
+                                $file_attach,
+                                $file_comments[$o],
+                                $outbox_last_id,
+                                $user_sender_id
+                            );
                         }
                         $o++;
                     }
@@ -327,7 +344,7 @@ class MessageManager
 
                 $user_list = GroupPortalManager::get_users_by_group($group_id, false, array(), 0, 1000);
 
-                //Adding more sens to the message group
+                // Adding more sense to the message group
                 $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'), $group_info['name']);
 
                 $new_user_list = array();
@@ -393,10 +410,10 @@ class MessageManager
         // get message id from data found early for other receiver user
         $sql = "SELECT id FROM $table_message
                 WHERE
-                  user_sender_id ='{$row_message[user_sender_id]}' AND
-                  title='{$row_message[title]}' AND
-                  content='{$row_message[content]}' AND
-                  group_id='{$row_message[group_id]}' AND
+                  user_sender_id ='{$row_message['user_sender_id']}' AND
+                  title='{$row_message['title']}' AND
+                  content='{$row_message['content']}' AND
+                  group_id='{$row_message['group_id']}' AND
                   user_receiver_id='$receiver_user_id'";
         $rs_msg_id = Database::query($sql);
         $row = Database::fetch_array($rs_msg_id);
@@ -423,9 +440,8 @@ class MessageManager
         $rs = Database::query($sql);
 
         if (Database::num_rows($rs) > 0) {
-            $row = Database::fetch_array($rs);
             // delete attachment file
-            $res = self::delete_message_attachment_file($id, $user_receiver_id);
+            self::delete_message_attachment_file($id, $user_receiver_id);
             // delete message
             $query = "UPDATE $table_message SET msg_status=3
                       WHERE user_receiver_id=".$user_receiver_id." AND id=".$id;
@@ -458,9 +474,8 @@ class MessageManager
         $rs = Database::query($sql);
 
         if (Database::num_rows($rs) > 0) {
-            $row = Database::fetch_array($rs);
             // delete attachment file
-            $res = self::delete_message_attachment_file($id, $user_sender_id);
+            self::delete_message_attachment_file($id, $user_sender_id);
             // delete message
             $query = "UPDATE $table_message SET msg_status=3
                     WHERE user_sender_id='$user_sender_id' AND id='$id'";
@@ -579,6 +594,7 @@ class MessageManager
     {
         if ($message_id != strval(intval($message_id)) || $user_id != strval(intval($user_id)))
             return false;
+
         $table_message = Database::get_main_table(TABLE_MESSAGE);
         $sql = "UPDATE $table_message SET msg_status = '0'
                 WHERE
@@ -636,7 +652,9 @@ class MessageManager
         $table_message = Database::get_main_table(TABLE_MESSAGE);
         $group_id = intval($group_id);
         $query = "SELECT * FROM $table_message
-                  WHERE group_id= $group_id AND msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
+                  WHERE
+                    group_id= $group_id AND
+                    msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
                   ORDER BY id";
         $rs = Database::query($query);
         $data = array();
@@ -661,7 +679,9 @@ class MessageManager
         $table_message = Database::get_main_table(TABLE_MESSAGE);
         $group_id = intval($group_id);
         $query = "SELECT * FROM $table_message
-                  WHERE group_id = $group_id AND msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
+                  WHERE
+                    group_id = $group_id AND
+                    msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
                   ORDER BY id ";
 
         $rs = Database::query($query);
@@ -752,7 +772,6 @@ class MessageManager
      */
     public static function get_message_data_sent($from, $number_of_items, $column, $direction)
     {
-        global $charset;
         $from = intval($from);
         $number_of_items = intval($number_of_items);
         if (!isset($direction)) {
@@ -765,7 +784,8 @@ class MessageManager
         }
         $table_message = Database::get_main_table(TABLE_MESSAGE);
         $request = api_is_xml_http_request();
-        $sql = "SELECT id as col0, user_sender_id as col1, title as col2, send_date as col3, user_receiver_id as col4, msg_status as col5
+        $sql = "SELECT
+                    id as col0, user_sender_id as col1, title as col2, send_date as col3, user_receiver_id as col4, msg_status as col5
                 FROM $table_message
                 WHERE
                     user_sender_id=".api_get_user_id()." AND

+ 115 - 66
main/inc/lib/notification.lib.php

@@ -4,13 +4,22 @@
 /**
  * Notification class
  * This class provides methods for the Notification management.
- * 	Include/require it in your code to use its features.
+ * Include/require it in your code to use its features.
  * @package chamilo.library
  */
 class Notification extends Model
 {
     public $table;
-    public $columns = array('id', 'dest_user_id', 'dest_mail', 'title', 'content', 'send_freq', 'created_at', 'sent_at');
+    public $columns = array(
+        'id',
+        'dest_user_id',
+        'dest_mail',
+        'title',
+        'content',
+        'send_freq',
+        'created_at',
+        'sent_at'
+    );
 
     //Max length of the notification.content field
     public $max_content_length = 254;
@@ -54,17 +63,41 @@ class Notification extends Model
         // If no-reply  email doesn't exist use the admin email
         if (empty($this->admin_email)) {
             $this->admin_email = api_get_setting('emailAdministrator');
-            $this->admin_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
+            $this->admin_name = api_get_person_name(
+                api_get_setting('administratorName'),
+                api_get_setting('administratorSurname'),
+                null,
+                PERSON_NAME_EMAIL_ADDRESS
+            );
         }
     }
 
+    /**
+     * @return string
+     */
+    public function getDefaultPlatformSenderEmail()
+    {
+        return $this->admin_email;
+    }
+
+    /**
+     * @return string
+     */
+    public function getDefaultPlatformSenderName()
+    {
+        return $this->admin_name;
+    }
+
     /**
      *  Send the notifications
      *  @param int notification frequency
      */
     public function send($frequency = 8)
     {
-        $notifications = $this->find('all', array('where' => array('sent_at IS NULL AND send_freq = ?' => $frequency)));
+        $notifications = $this->find(
+            'all',
+            array('where' => array('sent_at IS NULL AND send_freq = ?' => $frequency))
+        );
 
         if (!empty($notifications)) {
             foreach ($notifications as $item_to_send) {
@@ -93,14 +126,23 @@ class Notification extends Model
 
     /**
      * Save message notification
-     * @param	array	message type NOTIFICATION_TYPE_MESSAGE, NOTIFICATION_TYPE_INVITATION, NOTIFICATION_TYPE_GROUP
-     * @param	array	recipients: user list of ids
-     * @param	string	title
-     * @param	string	content of the message
-     * @param	array	result of api_get_user_info() or GroupPortalManager:get_group_data()
+     * @param	int	$type message type
+     * NOTIFICATION_TYPE_MESSAGE,
+     * NOTIFICATION_TYPE_INVITATION,
+     * NOTIFICATION_TYPE_GROUP
+     * @param	array	$user_list recipients: user list of ids
+     * @param	string	$title
+     * @param	string	$content
+     * @param	array	$sender_info
+     * result of api_get_user_info() or GroupPortalManager:get_group_data()
      */
-    public function save_notification($type, $user_list, $title, $content, $sender_info = array())
-    {
+    public function save_notification(
+        $type,
+        $user_list,
+        $title,
+        $content,
+        $sender_info = array()
+    ) {
         $this->type = intval($type);
         $content = $this->format_content($content, $sender_info);
 
@@ -142,47 +184,26 @@ class Notification extends Model
                     $user_setting = $extra_data[$setting_to_check];
                 }
 
-                $params = array();
-
+                $sendDate = null;
                 switch ($user_setting) {
-                    //No notifications
+                    // No notifications
                     case self::NOTIFY_MESSAGE_NO:
                     case self::NOTIFY_INVITATION_NO:
                     case self::NOTIFY_GROUP_NO:
                         break;
-                    //Send notification right now!
+                    // Send notification right now!
                     case self::NOTIFY_MESSAGE_AT_ONCE:
                     case self::NOTIFY_INVITATION_AT_ONCE:
                     case self::NOTIFY_GROUP_AT_ONCE:
-                        $mail = api_get_setting('noreply_email_address');
-                        if ($user_setting == self::NOTIFY_INVITATION_AT_ONCE) {
-                            $sender_info['complete_name'] = $this->admin_name;
-                            $extra_headers = array();
-                            $extra_headers['reply_to']['name'] = $this->admin_name;
-                            if (!empty($mail)) {
-                                $sender_info['email'] = $mail;
-                                $extra_headers['reply_to']['mail'] = $mail;
-                                
-                            } else {
-                                $sender_info['email'] = $this->admin_email;
-                                $extra_headers['reply_to']['mail'] = $this->admin_email;
-                            }
-                        }
-                        if (!empty($user_info['mail']) || !empty($mail)) {
-                            $name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
-                            if (!empty($sender_info['complete_name']) && !empty($sender_info['email'])) {
-                                if ($user_setting != self::NOTIFY_INVITATION_AT_ONCE) {
-                                    $extra_headers = array();
-                                    $extra_headers['reply_to']['mail'] = $sender_info['email'];
-                                    $extra_headers['reply_to']['name'] = $sender_info['complete_name'];
-                                }
-                            } else {
-                                $extra_headers = array();
-                                $sender_info['complete_name'] = $this->admin_name;
-                                $sender_info['email'] = $this->admin_email;
-                            }
+                        $extra_headers = array();
+                        $sender_info['complete_name'] = $this->admin_name;
+                        $sender_info['email'] = $this->admin_email;
+                        $extra_headers['reply_to']['name'] = $user_info['complete_name'];
+                        $extra_headers['reply_to']['mail'] = $user_info['email'];
+
+                        if (!empty($user_info['email'])) {
                             api_mail_html(
-                                $name,
+                                $user_info['complete_name'],
                                 $user_info['mail'],
                                 Security::filter_terms($title),
                                 Security::filter_terms($content),
@@ -190,27 +211,29 @@ class Notification extends Model
                                 $sender_info['email'],
                                 $extra_headers
                             );
-                    
                         }
-                        $params['sent_at'] = api_get_utc_datetime();
-                        // Saving the notification to be sent some day.
-                    default:
-                        $params['dest_user_id'] = $user_id;
-                        $params['dest_mail'] = $user_info['mail'];
-                        $params['title'] = $title;
-                        $params['content'] = cut($content, $this->max_content_length);
-                        $params['send_freq'] = $user_setting;
-                        $this->save($params);
-                        break;
+                        $sendDate = api_get_utc_datetime();
                 }
+
+                // Saving the notification to be sent some day.
+                $params = array();
+                $params['sent_at'] = $sendDate;
+                $params['dest_user_id'] = $user_id;
+                $params['dest_mail'] = $user_info['email'];
+                $params['title'] = $title;
+                $params['content'] = cut($content, $this->max_content_length);
+                $params['send_freq'] = $user_setting;
+                $this->save($params);
             }
         }
     }
 
     /**
-     * Formats the content in order to add the welcome message, the notification preference, etc
-     * @param   string 	the content
-     * @param   array	result of api_get_user_info() or GroupPortalManager:get_group_data()
+     * Formats the content in order to add the welcome message,
+     * the notification preference, etc
+     * @param   string 	$content
+     * @param   array	$sender_info result of api_get_user_info() or
+     * GroupPortalManager:get_group_data()
      * @return string
      * */
     public function format_content($content, $sender_info)
@@ -220,27 +243,49 @@ class Notification extends Model
         switch ($this->type) {
             case self::NOTIFICATION_TYPE_MESSAGE:
                 if (!empty($sender_info)) {
-                    $sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
-                    //$sender_mail = $sender_info['email'] ;
+                    $sender_name = api_get_person_name(
+                        $sender_info['firstname'],
+                        $sender_info['lastname'],
+                        null,
+                        PERSON_NAME_EMAIL_ADDRESS
+                    );
                     $new_message_text = sprintf(get_lang('YouHaveANewMessageFromX'), $sender_name);
                 }
-                $link_to_new_message = Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'messages/inbox.php');
+                $link_to_new_message = Display::url(
+                    get_lang('SeeMessage'),
+                    api_get_path(WEB_CODE_PATH) . 'messages/inbox.php'
+                );
                 break;
             case self::NOTIFICATION_TYPE_INVITATION:
                 if (!empty($sender_info)) {
-                    $sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
-                    //$sender_mail = $sender_info['email'] ;
+                    $sender_name = api_get_person_name(
+                        $sender_info['firstname'],
+                        $sender_info['lastname'],
+                        null,
+                        PERSON_NAME_EMAIL_ADDRESS
+                    );
                     $new_message_text = sprintf(get_lang('YouHaveANewInvitationFromX'), $sender_name);
                 }
-                $link_to_new_message = Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php');
+                $link_to_new_message = Display::url(
+                    get_lang('SeeInvitation'),
+                    api_get_path(WEB_CODE_PATH) . 'social/invitations.php'
+                );
                 break;
             case self::NOTIFICATION_TYPE_GROUP:
                 $topic_page = intval($_REQUEST['topics_page_nr']);
                 if (!empty($sender_info)) {
                     $sender_name = $sender_info['group_info']['name'];
                     $new_message_text = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name);
-                    $sender_name = api_get_person_name($sender_info['user_info']['firstname'], $sender_info['user_info']['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
-                    $sender_name = Display::url($sender_name, api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']);
+                    $sender_name = api_get_person_name(
+                        $sender_info['user_info']['firstname'],
+                        $sender_info['user_info']['lastname'],
+                        null,
+                        PERSON_NAME_EMAIL_ADDRESS
+                    );
+                    $sender_name = Display::url(
+                        $sender_name,
+                        api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']
+                    );
                     $new_message_text .= '<br />'.get_lang('User').': '.$sender_name;
                 }
                 $group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$sender_info['group_info']['id'].'&topic_id='.$sender_info['group_info']['topic_id'].'&msg_id='.$sender_info['group_info']['msg_id'].'&topics_page_nr='.$topic_page;
@@ -261,7 +306,11 @@ class Notification extends Model
 
         // You have received this message because you are subscribed text
         $content = $content.'<br /><hr><i>'.
-            sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).'</i>';
+            sprintf(
+                get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'),
+                Display::url($preference_url, $preference_url)
+            ).'</i>';
+
         return $content;
     }
 }

+ 16 - 9
main/inc/lib/sortable_table.class.php

@@ -1,11 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * @package chamilo.library
- */
-/**
- * Code
- */
+
 require_once 'pear/HTML/Table.php';
 require_once 'pear/Pager/Pager.php';
 
@@ -260,7 +255,7 @@ class SortableTable extends HTML_Table
             $form  = $this->get_page_select_form();
             $nav   = $this->get_navigation_html();
 
-            //Only show pagination info when there are items to paginate
+            // Only show pagination info when there are items to paginate
 
             if ($this->get_total_number_of_items() > $this->default_items_per_page) {
                 $html  = '<table class="data_table_pagination">';
@@ -907,8 +902,20 @@ class SortableTableFromArray extends SortableTable
      * @param int $default_column
      * @param int $default_items_per_page
      */
-    public function __construct($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename', $get_total_number_function = null) {
-        parent :: __construct ($tablename, $get_total_number_function, null, $default_column, $default_items_per_page);
+    public function __construct(
+        $table_data,
+        $default_column = 1,
+        $default_items_per_page = 20,
+        $tablename = 'tablename',
+        $get_total_number_function = null
+    ) {
+        parent:: __construct(
+            $tablename,
+            $get_total_number_function,
+            null,
+            $default_column,
+            $default_items_per_page
+        );
         $this->table_data = $table_data;
     }
 

+ 210 - 174
main/inc/lib/tracking.lib.php

@@ -24,6 +24,7 @@ class Tracking
      * @param int $extendAttemptId
      * @param string $extendedAttempt
      * @param string $extendedAll
+     * @param string $type classic or simple
      * @return null|string
      */
     public static function getLpStats(
@@ -37,19 +38,21 @@ class Tracking
         $extendId = null,
         $extendAttemptId = null,
         $extendedAttempt = null,
-        $extendedAll = null
+        $extendedAll = null,
+        $type = 'classic'
     ) {
-        if (empty($courseInfo)) {
+        if (empty($courseInfo) || empty($lp_id)) {
             return null;
         }
 
-        $list = learnpath :: get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']);
-
         $lp_id = intval($lp_id);
         $lp_item_id = intval($lp_item_id);
         $user_id = intval($user_id);
+        $session_id = intval($session_id);
         $origin = Security::remove_XSS($origin);
 
+        $list = learnpath :: get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']);
+
         $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
         $course_id = $courseInfo['real_id'];
         $courseCode = $courseInfo['code'];
@@ -66,12 +69,17 @@ class Tracking
         }
 
         if (!empty($extendedAll)) {
-            $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_link = Display::url(
+                Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')),
+                api_get_self() . '?action=stats' . $url_suffix
+            );
+
             $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>';
+            $extend_all_link = Display::url(
+                Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttempts')),
+                api_get_self() . '?action=stats&extend_all=1' . $url_suffix
+            );
         }
 
         if ($origin != 'tracking') {
@@ -110,11 +118,13 @@ class Tracking
         $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
+        $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";
+                    user_id = $user_id
+                    $session_condition";
         $res = Database::query($sql);
         $view = '';
         if (Database :: num_rows($res) > 0) {
@@ -137,80 +147,57 @@ class Tracking
 
         $result_disabled_ext_all = true;
 
+        $chapterTypes = learnpath::getChapterTypes();
+
         // Show lp items
         if (is_array($list) && count($list) > 0) {
             foreach ($list as $my_item_id) {
                 $extend_this = 0;
-                $qry_order = 'DESC';
+                $order = 'DESC';
                 if ((!empty($extendId) && $extendId == $my_item_id) || $extend_all) {
                     $extend_this = 1;
-                    $qry_order = 'ASC';
+                    $order = 'ASC';
                 }
 
                 // Prepare statement to go through each attempt.
+                $viewCondition = null;
                 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 ";
+                    $viewCondition =  " AND v.view_count = $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.session_id = $session_id
+                    $viewCondition
+                ORDER BY iv.view_count $order ";
+
                 $result = Database::query($sql);
                 $num = Database :: num_rows($result);
                 $time_for_total = 'NaN';
 
-                //Extend all + extend scorm?
+                // Extend all
                 if (($extend_this || $extend_all) && $num > 0) {
                     $row = Database :: fetch_array($result);
                     $result_disabled_ext_all = false;
@@ -220,7 +207,9 @@ class Tracking
 
                         $sql = "SELECT results_disabled
                                 FROM $TBL_QUIZ
-                                WHERE c_id = $course_id AND id ='" . $my_path . "'";
+                                WHERE
+                                    c_id = $course_id AND
+                                    id ='" . $my_path . "'";
                         $res_result_disabled = Database::query($sql);
                         $row_result_disabled = Database::fetch_row($res_result_disabled);
 
@@ -237,25 +226,44 @@ class Tracking
                     } 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>';
+                        $extend_link = Display::url(
+                              Display::return_icon('visible.gif', get_lang('HideAttemptView')),
+                              api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix
+                        );
                     }
                     $title = $row['mytitle'];
 
                     if (empty($title)) {
-                        $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
+                        $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
                     }
 
-                    if ($row['item_type'] != 'dokeos_chapter') {
-                        $correct_test_link = '-';
-                        $title = Security::remove_XSS($title);
+                    if (in_array($row['item_type'], $chapterTypes)) {
+                        $title = "<h4> $title </h4>";
+                    }
+                    $lesson_status = $row['mystatus'];
+                    $title = Security::remove_XSS($title);
+                    $counter++;
+
+                    if (in_array($row['item_type'], $chapterTypes)) {
+                        $output .= '<tr class="'.$oddclass.'">
+                                <td>'.$extend_link.'</td>
+                                <td colspan="4">
+                                   '.$title.'
+                                </td>
+                                <td colspan="2">'.learnpathItem::humanize_status($lesson_status, true, $type).'</td>
+                                <td colspan="2"></td>
+                                <td colspan="2"></td>
+                                <td></td>
+                            </tr>';
+                        continue;
+                    } else {
                         $output .= '<tr class="'.$oddclass.'">
                                 <td>'.$extend_link.'</td>
                                 <td colspan="4">
-                                    '.$title.'
+                                   '.$title.'
                                 </td>
                                 <td colspan="2"></td>
                                 <td colspan="2"></td>
@@ -263,7 +271,6 @@ class Tracking
                                 <td></td>
                             </tr>';
                     }
-                    $counter++;
 
                     $attemptCount = 1;
 
@@ -272,19 +279,23 @@ class Tracking
                         $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) &&
+                        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 ($extendAttemptId == $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>';
+                                $extend_attempt_link = Display::url(
+                                    Display::return_icon('visible.gif', get_lang('HideAttemptView')),
+                                    api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix
+                                );
                             } 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>';
+                                $extend_attempt_link = Display::url(
+                                    Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')),
+                                    api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix
+                                );
                             }
                         }
 
@@ -343,7 +354,7 @@ class Tracking
                                     <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">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td>
                                     <td colspan="2">' . $view_score . '</td>
                                     <td colspan="2">' . $time . '</td>
                                     <td></td>
@@ -352,7 +363,7 @@ class Tracking
                             if (!empty($export_csv)) {
                                 $temp = array();
                                 $temp[] = $title = Security::remove_XSS($title);
-                                $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false));
+                                $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false, $type));
 
                                 if ($row['item_type'] == 'quiz') {
                                     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
@@ -384,7 +395,7 @@ class Tracking
                                 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);
+                                        array_pop($content_student_response);
                                     }
                                     $student_response = implode(',', $content_student_response);
                                 }
@@ -428,7 +439,7 @@ class Tracking
                         }
                     } while ($row = Database :: fetch_array($result));
                 } elseif ($num > 0) {
-                    //Not extended
+                    // Not extended.
 
                     $row = Database :: fetch_array($result, 'ASSOC');
                     $my_id = $row['myid'];
@@ -441,9 +452,9 @@ class Tracking
                     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 . "'";
+                        $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);
 
@@ -461,18 +472,21 @@ class Tracking
                     $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
 
                     $extend_attempt_link = '';
-                    if (($inter_num > 0 || $objec_num > 0)) {
+                    if ($inter_num > 0 || $objec_num > 0) {
                         if (!empty($extendAttemptId) && $extendAttemptId == $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.
+                            $extend_attempt_link = Display::url(
+                                Display::return_icon('visible.gif', get_lang('HideAttemptView')),
+                                api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix
+                            );
+                        } 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>';
+                            $extend_attempt_link = Display::url(
+                                Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')),
+                                api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix
+                            );
                         }
                     }
 
@@ -484,9 +498,10 @@ class Tracking
 
                     $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>';
+                        $extend_link = Display::url(
+                            Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')),
+                            api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix
+                        );
                     }
 
                     $lesson_status = $row['mystatus'];
@@ -496,7 +511,7 @@ class Tracking
                     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.
@@ -535,24 +550,28 @@ class Tracking
                         } 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";
+                                $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 . "'";
+                                $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) {
+                                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 {
@@ -561,11 +580,11 @@ class Tracking
                                 }
                                 // 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
-                                    )
+                                        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);
@@ -580,17 +599,25 @@ class Tracking
                     $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']);
+                        $title = rl_get_resource_name($courseInfo['code'], $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 (in_array($row['item_type'], $chapterTypes)) {
+                        $title = Security::remove_XSS($title);
+                        $output .= '<tr class="'.$oddclass.'">
+                                <td>'.$extend_link.'</td>
+                                <td colspan="4">
+                                <h4>'.$title.'</h4>
+                                </td>
+                                <td colspan="2">'.learnpathitem::humanize_status($lesson_status).'</td>
+                                <td colspan="2"></td>
+                                <td colspan="2"></td>
+                                <td></td>
+                            </tr>';
+                    } else {
+                        $correct_test_link = '-';
                         if ($row['item_type'] == 'quiz') {
-                            $correct_test_link = '';
-                            $my_url_suffix = '';
-
-                            $my_url_suffix = '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . intval($row['mylpid']) . '&origin=' . Security::remove_XSS($origin);
+                            $my_url_suffix = '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . intval($row['mylpid']) . '&origin=' . $origin;
                             $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                                      WHERE
                                         exe_exo_id="' . $row['path'] . '" AND
@@ -605,18 +632,21 @@ class Tracking
                             $resultLastAttempt = Database::query($sql);
                             $num = Database :: num_rows($resultLastAttempt);
                             if ($num > 0) {
-                                if ($extendedAttempt == 1 && ($lp_id == $my_lp_id) && $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>';
+                                if ($extendedAttempt == 1 &&
+                                    $lp_id == $my_lp_id &&
+                                    $lp_item_id == $my_id
+                                ) {
+                                    $correct_test_link = Display::url(
+                                        Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')),
+                                        api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id
+                                    );
                                 } 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>';
+                                    $correct_test_link = Display::url(
+                                        Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttemptsByExercise')),
+                                        api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id
+                                    );
                                 }
-                            } else {
-                                $correct_test_link = '-';
                             }
-                        } else {
-                            $correct_test_link = '-';
                         }
 
                         $title = Security::remove_XSS($title);
@@ -647,20 +677,24 @@ class Tracking
                                 $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">';
+                            $scoreItem = null;
                             if ($row['item_type'] == 'quiz') {
                                 if (!$is_allowed_to_edit && $result_disabled_ext_all) {
-                                    $output .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
+                                    $scoreItem .= Display::return_icon(
+                                        'invisible.gif',
+                                        get_lang('ResultsHiddenByExerciseSetting')
+                                    );
                                 } else {
-                                    $output .= show_score($score, $maxscore, false);
+                                    $scoreItem .= show_score($score, $maxscore, false);
                                 }
                             } else {
-                                $output .= ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
+                                $scoreItem .= $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore);
                             }
-                            $output .= '</td>
+
+                            $output .= '<td>'.$extend_link.'</td>
+                                <td colspan="4">' . $title . '</td>
+                                <td colspan="2">' . learnpathitem::humanize_status($lesson_status) .'</td>
+                                <td colspan="2">'.$scoreItem.'</td>
                                 <td colspan="2">'.$time.'</td>
                                  <td>'.$correct_test_link.'</td>';
                             $output .= '</tr>';
@@ -669,7 +703,7 @@ class Tracking
                         if (!empty($export_csv)) {
                             $temp = array();
                             $temp[] = api_html_entity_decode($title, ENT_QUOTES);
-                            $temp[] = api_html_entity_decode($my_lesson_status, ENT_QUOTES);
+                            $temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES);
 
                             if ($row['item_type'] == 'quiz') {
                                 if (!$is_allowed_to_edit && $result_disabled_ext_all) {
@@ -688,7 +722,6 @@ class Tracking
                     $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';
@@ -735,9 +768,7 @@ class Tracking
 
                     // Attempts listing by exercise.
                     if ($lp_id == $my_lp_id && $lp_item_id== $my_id && $extendedAttempt) {
-
                         // Get attempts of a exercise.
-                        $num_attempts = 0;
                         if (!empty($lp_id) && !empty($lp_item_id) && $row['item_type'] === 'quiz') {
                             $sql = "SELECT path FROM $TBL_LP_ITEM
                                     WHERE
@@ -845,7 +876,7 @@ class Tracking
         if (!empty($a_my_id)) {
             if ($extendedAttempt) {
                 // "Right green cross" extended
-                $total_score = Tracking::get_avg_student_score(
+                $total_score = self::get_avg_student_score(
                     $user_id,
                     $course_id,
                     $a_my_id,
@@ -855,7 +886,7 @@ class Tracking
                 );
             } else {
                 // "Left green cross" extended
-                $total_score = Tracking::get_avg_student_score(
+                $total_score = self::get_avg_student_score(
                     $user_id,
                     $course_id,
                     $a_my_id,
@@ -866,7 +897,7 @@ class Tracking
             }
         } else {
             // Extend all "left green cross"
-            $total_score = Tracking::get_avg_student_score(
+            $total_score = self::get_avg_student_score(
                 $user_id,
                 $course_id,
                 array($lp_id),
@@ -876,7 +907,7 @@ class Tracking
             );
         }
 
-        $total_time = learnpathItem :: getScormTimeFromParameter('js', $total_time);
+        $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) {
@@ -889,6 +920,8 @@ class Tracking
             }
         }
 
+        $progress = learnpath::getProgress($lp_id, $user_id, $course_id, $session_id);
+
         if (($counter % 2) == 0) {
             $oddclass = 'row_odd';
         } else {
@@ -900,7 +933,7 @@ class Tracking
                 <td colspan="4">
                     <i>' . get_lang('AccomplishedStepsTotal') .'</i>
                 </td>
-                <td colspan="2"></td>
+                <td colspan="2">'.$progress.'%</td>
                 <td colspan="2">
                     ' . $final_score.'
                 </td>
@@ -1755,7 +1788,7 @@ class Tracking
      * get teacher progress by course and session
      * @param int course id
      * @param int session id
-     * @return data array
+     * @return array
      */
     static function get_teachers_progress_by_course($courseId, $sessionId)
     {
@@ -1778,6 +1811,7 @@ class Tracking
         while ($teacher = Database::fetch_array($rs,'ASSOC')) {
             $teachers[] = $teacher;
         }
+        $data = array();
         foreach ($teachers as $teacher) {
             //total documents added
             $sql = "SELECT count(*) as total
@@ -1911,19 +1945,26 @@ class Tracking
         return $data;
     }
 
-
     /**
      * Returns the average student progress in the learning paths of the given
      * course.
-     * @param   int/array    Student id(s)
-     * @param   string        Course code
-     * @param     array         Limit average to listed lp ids
-     * @param    int            Session id (optional), if parameter $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
-     * @param    bool        Will return an array of the type: [sum_of_progresses, number] if it is set to true
-     * @return double        Average progress of the user in this course
+     * @param int|array $student_id
+     * @param string    $course_code
+     * @param array     $lp_ids Limit average to listed lp ids
+     * @param int       $session_id     Session id (optional),
+     * if parameter $session_id is null(default) it'll return results including
+     * sessions, 0 = session is not filtered
+     * @param bool      $return_array Will return an array of the type:
+     * [sum_of_progresses, number] if it is set to true
+     * @return double   Average progress of the user in this course
      */
-    public static function get_avg_student_progress($student_id, $course_code = null, $lp_ids = array(), $session_id = null, $return_array = false)
-    {
+    public static function get_avg_student_progress(
+        $student_id,
+        $course_code = null,
+        $lp_ids = array(),
+        $session_id = null,
+        $return_array = false
+    ) {
         $conditions = array();
         $session_id = intval($session_id);
 
@@ -3404,9 +3445,8 @@ class Tracking
      * @author     isaac flores paz
      * @deprecated get_avg_student_score should be use
      */
-    public static function get_average_test_scorm_and_lp ($user_id, $course_id)
+    public static function get_average_test_scorm_and_lp($user_id, $course_id)
     {
-
         //the score inside the Reporting table
         $course_info      = api_get_course_info($course_id);
         $course_id        = $course_info['real_id'];
@@ -3420,6 +3460,7 @@ class Tracking
         $rs_type=Database::query($sql_type);
         $average_data=0;
         $count_loop=0;
+        $average_data_sum = 0;
         $lp_list = array();
         while ($row_type = Database::fetch_array($rs_type)) {
             $lp_list[] = $row_type['id'];
@@ -3453,12 +3494,10 @@ class Tracking
                     $tot=1;
                 }
                 $average_data1=$sum/$tot;
-                $sql_list_view='';
-                $rs_last_lp_view_id='';
-
             } elseif ($row_type['lp_type']==2) {
                 //lp scorm
-                $sql = "SELECT id FROM $lp_view_table  WHERE c_id = $course_id AND user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
+                $sql = "SELECT id FROM $lp_view_table
+                        WHERE c_id = $course_id AND user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
                 $rs_last_lp_view_id = Database::query($sql);
                 $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
 
@@ -3494,7 +3533,7 @@ class Tracking
 
         //We only count the LP that have an exercise to get the average
         $lp_with_quiz = 0;
-        foreach($lp_list as $lp_id) {
+        foreach ($lp_list as $lp_id) {
 
             //check if LP have a score
             $sql = "SELECT count(id) as count FROM $lp_item_table
@@ -3651,7 +3690,6 @@ class Tracking
                 }
             }
 
-
             //query
             $sql = "SELECT %s as user, count(*) as total
                 FROM %s
@@ -6504,6 +6542,4 @@ class TrackingUserLogCSV
             'html' => $courseToolInformationTotal
         );
     }
-
-
 }

+ 2 - 0
main/install/configuration.dist.php

@@ -247,3 +247,5 @@ $_configuration['system_stable']     = NEW_VERSION_STABLE;
 //$_configuration['theme_fallback'] = 'chamilo'; // (main/css/chamilo)
 // The default template that will be use in the system.
 //$_configuration['default_template'] = 'default'; // (main/template/default)
+// Show reduce LP report
+//$_configuration['lp_show_reduced_report'] = false;

File diff suppressed because it is too large
+ 219 - 131
main/newscorm/learnpath.class.php


+ 27 - 17
main/newscorm/learnpathItem.class.php

@@ -1779,9 +1779,9 @@ class learnpathItem
         $h = get_lang('h');
         if (!isset($time)) {
             if ($origin == 'js') {
-                return '00:00:00';
+                return '00 : 00: 00';
             } else {
-                return '00' . $h . '00\'00"';
+                return '00 ' . $h . ' 00 \' 00"';
             }
         } else {
             return self::calculateScormTime($origin, $time);
@@ -1859,12 +1859,11 @@ class learnpathItem
         $secs = ($time % 60);
 
         if ($origin == 'js') {
-            $scormTime = trim(sprintf("%4d:%02d:%02d", $hours, $mins, $secs));
+            $scormTime = trim(sprintf("%02d : %02d : %02d", $hours, $mins, $secs));
         } else {
-            $scormTime = trim(
-                sprintf("%4d$h%02d'%02d\"", $hours, $mins, $secs)
-            );
+            $scormTime = trim(sprintf("%02d$h%02d'%02d\"", $hours, $mins, $secs));
         }
+
         if (self::debug > 2) {
             error_log('learnpathItem::get_scorm_time(' . $scormTime . ')', 0);
         }
@@ -3308,7 +3307,9 @@ class learnpathItem
 
     /**
      * Sets the status for this item
-     * @param   string $status must be one of the values defined in $this->possible_status
+     * @param   string      $status must be one of the values defined
+     * in $this->possible_status
+     * (this affects the status setting)
      * @return  boolean True on success, false on error
      */
     public function set_status($status)
@@ -4291,11 +4292,12 @@ class learnpathItem
      * in different user languages
      * @param $status
      * @param bool $decorate
+     * @param string $type classic|simple
      * @return array|string
      */
-    static function humanize_status($status, $decorate = true)
+    static function humanize_status($status, $decorate = true, $type = 'classic')
     {
-        $mylanglist = array(
+        $statusList = array(
             'completed' => 'ScormCompstatus',
             'incomplete' => 'ScormIncomplete',
             'failed' => 'ScormFailed',
@@ -4304,30 +4306,38 @@ class learnpathItem
             'not attempted' => 'ScormNotAttempted'
         );
 
-        $my_lesson_status = get_lang($mylanglist[$status]);
+        $myLessonStatus = get_lang($statusList[$status]);
 
         switch ($status) {
             case 'completed':
             case 'browsed':
-                $class_status = 'info';
+                $classStatus = 'info';
                 break;
             case 'incomplete':
-                $class_status = 'warning';
+                $classStatus = 'warning';
                 break;
             case 'passed':
-                $class_status = 'success';
+                $classStatus = 'success';
                 break;
             case 'failed':
-                $class_status = 'important';
+                $classStatus = 'important';
                 break;
             default:
-                $class_status = 'default';
+                $classStatus = 'default';
                 break;
         }
+
+        if ($type == 'simple') {
+            if (in_array($status, array('failed', 'passed', 'browsed'))) {
+                $myLessonStatus = get_lang('ScormIncomplete');;
+                $classStatus = 'warning';
+            }
+        }
+
         if ($decorate) {
-            return Display::label($my_lesson_status, $class_status);
+            return Display::label($myLessonStatus, $classStatus);
         } else {
-            return $my_lesson_status;
+            return $myLessonStatus;
         }
     }
 }

+ 13 - 7
main/newscorm/lp_edit.php

@@ -193,8 +193,12 @@ if (api_is_platform_admin()) {
     $defaults['use_max_score'] = $_SESSION['oLP']->use_max_score;
 }
 
-$extraField = new ExtraField('lp');
-$extra = $extraField->addElements($form, $_SESSION['oLP']->get_id());
+$enableLpExtraFields = false;
+
+if ($enableLpExtraFields) {
+    $extraField = new ExtraField('lp');
+    $extra = $extraField->addElements($form, $_SESSION['oLP']->get_id());
+}
 
 //Submit button
 $form->addElement('style_submit_button', 'Submit',get_lang('SaveLPSettings'),'class="save"');
@@ -205,11 +209,13 @@ $form->addElement('hidden', 'lp_id', $_SESSION['oLP']->get_id());
 
 $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
 $htmlHeadXtra[] = '<link  href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
-$htmlHeadXtra[] ='<script>
-$(function() {
-    '.$extra['jquery_ready_content'].'
-});
-</script>';
+if ($enableLpExtraFields) {
+    $htmlHeadXtra[] = '<script>
+    $(function() {
+        ' . $extra['jquery_ready_content'] . '
+    });
+    </script>';
+}
 
 
 $defaults['publicated_on']  = ($publicated_on!='0000-00-00 00:00:00' && !empty($publicated_on))? api_get_local_time($publicated_on) : date('Y-m-d 12:00:00');

+ 13 - 8
main/newscorm/lp_list.php

@@ -66,8 +66,6 @@ Display::display_introduction_section(TOOL_LEARNPATH, array(
 $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
 
 if ($is_allowed_to_edit) {
-    /* DIALOG BOX SECTION */
-
     if (!empty($dialog_box)) {
         switch ($_GET['dialogtype']) {
             case 'confirmation':
@@ -162,7 +160,7 @@ if (!empty($flat_list)) {
             }
 
             if ($time_limits) {
-                // check if start time
+                // Check if start time
                 if (!empty($details['publicated_on']) && $details['publicated_on'] != '0000-00-00 00:00:00' &&
                     !empty($details['expired_on']) && $details['expired_on'] != '0000-00-00 00:00:00') {
                     $start_time = api_strtotime($details['publicated_on'], 'UTC');
@@ -366,9 +364,15 @@ if (!empty($flat_list)) {
 
             /* Export */
             if ($details['lp_type'] == 1) {
-                $dsp_disk = Display::url(Display::return_icon('cd.gif', get_lang('Export'), array(), ICON_SIZE_SMALL), api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id");
+                $dsp_disk = Display::url(
+                    Display::return_icon('cd.gif', get_lang('Export'), array(), ICON_SIZE_SMALL),
+                    api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id"
+                );
             } elseif ($details['lp_type'] == 2) {
-                $dsp_disk = Display::url(Display::return_icon('cd.gif', get_lang('Export'), array(), ICON_SIZE_SMALL), api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id&export_name=".replace_dangerous_char($name, 'strict').".zip");
+                $dsp_disk = Display::url(
+                    Display::return_icon('cd.gif', get_lang('Export'), array(), ICON_SIZE_SMALL),
+                    api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id&export_name=".replace_dangerous_char($name, 'strict').".zip"
+                );
             } else {
                 $dsp_disk = Display::return_icon('cd_gray.gif', get_lang('Export'), array(), ICON_SIZE_SMALL);
             }
@@ -434,8 +438,9 @@ if (!empty($flat_list)) {
                 $start_time = $end_time = '';
             }
         } else {
-            //Student
-            $export_icon = ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&lp_id='.$id.'">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>';
+            // Student
+            $export_icon = ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&lp_id='.$id.'">'.
+                Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>';
         }
 
         global $_configuration;
@@ -474,7 +479,7 @@ if (!empty($flat_list)) {
 $course_info = api_get_course_info();
 learnpath::generate_learning_path_folder($course_info);
 
-//Deleting the objects
+// Deleting the objects
 Session::erase('oLP');
 Session::erase('lpobject');
 DocumentManager::removeGeneratedAudioTempFile();

+ 7 - 1
main/newscorm/lp_stats.php

@@ -28,6 +28,11 @@ $extendedAttempt = isset($_GET['extend_attempt']) ? $_GET['extend_attempt'] : nu
 $extendedAll = isset($_GET['extend_all']) ? $_GET['extend_all'] : null;
 $export = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
 
+$lpReportType = api_get_configuration_value('lp_show_reduced_report');
+$type = 'classic';
+if ($lpReportType) {
+    $type = 'simple';
+}
 $courseInfo = api_get_course_info($courseCode);
 $output = Tracking::getLpStats(
     $userId,
@@ -40,7 +45,8 @@ $output = Tracking::getLpStats(
     $extendId,
     $extendAttemptId,
     $extendedAttempt,
-    $extendedAll
+    $extendedAll,
+    $type
 );
 
 // Origin = tracking means that teachers see that info in the Reporting tool

+ 0 - 1
main/newscorm/lp_view.php

@@ -439,7 +439,6 @@ if ($is_allowed_to_edit) {
     <!-- right zone -->
     <div id="learning_path_right_zone" style="margin-left:<?php echo $margin_left;?>;height:100%">
     <?php
-    $src = !empty($src) ? str_replace('&amp;', '&', $src) : '';
         // hub 26-05-2010 Fullscreen or not fullscreen
         $height = '100%';
         if ($_SESSION['oLP']->mode == 'fullscreen') {

+ 5 - 2
main/newscorm/resourcelinker.inc.php

@@ -1750,12 +1750,15 @@ function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
     $_course = Database::get_course_info($course_code);
     $course_id = $_course['real_id'];
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
+    $learnpath_id = intval($learnpath_id);
+    $id_in_path = intval($id_in_path);
 
-    $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
+    $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item
+                 WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
     $res_item = Database::query($sql_item);
 
     if (Database::num_rows($res_item) < 1) {
-        return ''; //exit
+        return '';
     }
     $row_item = Database::fetch_array($res_item);
     $type = strtolower($row_item['item_type']);

+ 83 - 19
main/work/work.lib.php

@@ -453,8 +453,14 @@ function getUniqueStudentAttemptsTotal($workId, $groupId, $course_id, $sessionId
  * @param array $onlyUserList only parse this user list
  * @return mixed
  */
-function getUniqueStudentAttempts($workId, $groupId, $course_id, $sessionId, $userId = null, $onlyUserList = array())
-{
+function getUniqueStudentAttempts(
+    $workId,
+    $groupId,
+    $course_id,
+    $sessionId,
+    $userId = null,
+    $onlyUserList = array()
+) {
     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     $user_table = Database::get_main_table(TABLE_MAIN_USER);
 
@@ -484,28 +490,27 @@ function getUniqueStudentAttempts($workId, $groupId, $course_id, $sessionId, $us
     }
 
     $sql = "SELECT count(*) FROM (
-                SELECT count(*)
+                SELECT count(*), w.parent_id
                 FROM $work_table w
                 INNER JOIN $user_table u
                     ON w.user_id = u.user_id
                 WHERE
+                    w.filetype = 'file' AND
                     w.c_id = $course_id AND
                     w.session_id = $sessionId AND
                    $workCondition
                     w.post_group_id = ".$groupId." AND
                     w.active IN (0, 1) $studentCondition
                 ";
-
     if (!empty($userId)) {
         $userId = intval($userId);
         $sql .= " AND u.user_id = ".$userId;
     }
-    $sql .= " GROUP BY u.user_id) as t";
-
-    $res_document = Database::query($sql);
-    $rowCount = Database::fetch_row($res_document);
+    $sql .= " GROUP BY u.user_id, w.parent_id) as t";
+    $result = Database::query($sql);
+    $row = Database::fetch_row($result);
 
-    return $rowCount[0];
+    return $row[0];
 }
 
 /**
@@ -710,7 +715,14 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 
             if ($origin != 'learnpath') {
                 if ($is_allowed_to_edit) {
-                    $cant_files_per_user = getUniqueStudentAttempts($work_data['id'], $group_id, $course_id, api_get_session_id(), null, $userList);
+                    $cant_files_per_user = getUniqueStudentAttempts(
+                        $work_data['id'],
+                        $group_id,
+                        $course_id,
+                        api_get_session_id(),
+                        null,
+                        $userList
+                    );
 
                     $row[] = $cant_files_per_user.'/'.count($userList);
                     if (api_resource_is_locked_by_gradebook($workId, LINK_STUDENTPUBLICATION)) {
@@ -2887,12 +2899,16 @@ function getStudentSubscribedToWork(
 
     if (empty($groupId)) {
         $courseInfo = api_get_course_info_by_id($courseId);
+        $status = STUDENT;
+        if (!empty($sessionId)) {
+            $status = 0;
+        }
         $usersInCourse = CourseManager::get_user_list_from_course_code(
             $courseInfo['code'],
             $sessionId,
             null,
             null,
-            0,
+            $status,
             $getCount
         );
     } else {
@@ -3364,10 +3380,22 @@ function sendAlertToTeacher($workId, $courseInfo, $session_id)
         // Lets predefine some variables. Be sure to change the from address!
         if (empty($session_id)) {
             //Teachers
-            $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), null, null, null, COURSEMANAGER);
+            $user_list = CourseManager::get_user_list_from_course_code(
+                api_get_course_id(),
+                null,
+                null,
+                null,
+                COURSEMANAGER
+            );
         } else {
-            //Coaches
-            $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, 2);
+            // Coaches
+            $user_list = CourseManager::get_user_list_from_course_code(
+                api_get_course_id(),
+                $session_id,
+                null,
+                null,
+                2
+            );
         }
 
         $subject = "[" . api_get_setting('siteName') . "] ".get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$courseInfo['name']."  ";
@@ -4153,7 +4181,16 @@ function showStudentList($workId)
 function getWorkUserList($courseCode, $sessionId, $groupId, $start, $limit, $sidx, $sord, $getCount = false)
 {
     if (!empty($groupId)) {
-        $userList = GroupManager::get_users($groupId, false, $start, $limit, $getCount, null, $sidx, $sord);
+        $userList = GroupManager::get_users(
+            $groupId,
+            false,
+            $start,
+            $limit,
+            $getCount,
+            null,
+            $sidx,
+            $sord
+        );
     } else {
         $limitString = null;
         if (!empty($start) && !empty($limit)) {
@@ -4187,6 +4224,7 @@ function getWorkUserList($courseCode, $sessionId, $groupId, $start, $limit, $sid
                 $getCount
             );
         }
+
         if ($getCount == false) {
             $userList = array_keys($userList);
         }
@@ -4206,8 +4244,17 @@ function getWorkUserList($courseCode, $sessionId, $groupId, $start, $limit, $sid
  * @param bool $getCount
  * @return array|int
  */
-function getWorkUserListData($workId, $courseCode, $sessionId, $groupId, $start, $limit, $sidx, $sord, $getCount = false)
-{
+function getWorkUserListData(
+    $workId,
+    $courseCode,
+    $sessionId,
+    $groupId,
+    $start,
+    $limit,
+    $sidx,
+    $sord,
+    $getCount = false
+) {
     $my_folder_data = get_work_data_by_id($workId);
     $workParents = array();
     if (empty($my_folder_data)) {
@@ -4222,7 +4269,18 @@ function getWorkUserListData($workId, $courseCode, $sessionId, $groupId, $start,
     }
 
     $courseInfo = api_get_course_info($courseCode);
-    $userList = getWorkUserList($courseCode, $sessionId, $groupId, $start, $limit, $sidx, $sord, $getCount);
+
+    $userList = getWorkUserList(
+        $courseCode,
+        $sessionId,
+        $groupId,
+        $start,
+        $limit,
+        $sidx,
+        $sord,
+        $getCount
+    );
+
     if ($getCount) {
         return $userList;
     }
@@ -4234,7 +4292,13 @@ function getWorkUserListData($workId, $courseCode, $sessionId, $groupId, $start,
             $url = Display::url(api_get_person_name($user['firstname'], $user['lastname']), $link);
             $userWorks = 0;
             if (!empty($workIdList)) {
-                $userWorks = getUniqueStudentAttempts($workIdList, $groupId, $courseInfo['real_id'], $sessionId, $user['user_id']);
+                $userWorks = getUniqueStudentAttempts(
+                    $workIdList,
+                    $groupId,
+                    $courseInfo['real_id'],
+                    $sessionId,
+                    $user['user_id']
+                );
             }
             $works = $userWorks." / ".count($workParents);
             $results[] = array('student' => $url, 'works' => $works);

Some files were not shown because too many files changed in this diff