Browse Source

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

Yannick Warnier 10 years ago
parent
commit
62a44f7335

+ 21 - 0
main/course_info/infocours.php

@@ -306,6 +306,27 @@ if (api_get_setting('allow_course_theme') == 'true') {
     $form->addGroup($group, '', array(get_lang("AllowLearningPathTheme")), '');
 }
 
+global $_configuration;
+if (isset($_configuration['allow_lp_return_link']) && $_configuration['allow_lp_return_link']) {
+    $group = array(
+        $form->createElement(
+            'radio',
+            'lp_return_link',
+            get_lang('LpReturnLink'),
+            get_lang('RedirectToTheLearningPathList'),
+            1
+        ),
+        $form->createElement(
+            'radio',
+            'lp_return_link',
+            null,
+            get_lang('RedirectToCourseHome'),
+            0
+        )
+    );
+    $form->addGroup($group, '', array(get_lang("LpReturnLink")), '');
+}
+
 if (is_settings_editable()) {
     $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
 } else {

+ 7 - 2
main/inc/lib/course.lib.php

@@ -4611,9 +4611,14 @@ class CourseManager
             'email_alert_to_teacher_on_new_user_in_course',
             'enable_lp_auto_launch',
             'pdf_export_watermark_text',
-            'show_system_folders',
-            //'lp_return_link'
+            'show_system_folders'
         );
+
+        global $_configuration;
+        if (isset($_configuration['allow_lp_return_link']) && $_configuration['allow_lp_return_link']) {
+            $courseSettings[] = 'lp_return_link';
+        }
+
         if (!empty($pluginCourseSettings)) {
             $courseSettings = array_merge(
                 $courseSettings,

+ 5 - 2
main/inc/lib/display.lib.php

@@ -1389,12 +1389,15 @@ class Display
                     $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info['firstname'], $session_info['lastname']);
                 }
                 if (isset($session_info['duration']) && !empty($session_info['duration'])) {
-
                     $userDurationData = SessionManager::getUserSession(
                             api_get_user_id(),
                             $session_id
                     );
-                    $totalDuration = $session_info['duration'] + intval($userDurationData['duration']);
+                    $userDuration = 0;
+                    if (isset($userDurationData['duration'])) {
+                        $userDuration = intval($userDurationData['duration']);
+                    }
+                    $totalDuration = $session_info['duration'] + $userDuration;
 
                     $daysLeft = SessionManager::getDayLeftInSession(
                         $session_id,

+ 21 - 8
main/inc/lib/main_api.lib.php

@@ -2030,12 +2030,21 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
                             return SESSION_AVAILABLE;
                         }
                         $currentTime = time();
-                        $firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
+                        $firstAccess = 0;
+                        if (isset($courseAccess['login_course_date'])) {
+                            $firstAccess = api_strtotime(
+                                $courseAccess['login_course_date'],
+                                'UTC'
+                            );
+                        }
                         $userDurationData = SessionManager::getUserSession(
                             api_get_user_id(),
                             $session_id
                         );
-                        $userDuration = intval($userDurationData['duration'])*24*60*60;
+                        $userDuration = 0;
+                        if (isset($userDurationData['duration'])) {
+                            $userDuration = intval($userDurationData['duration']) * 24 * 60 * 60;
+                        }
 
                         $totalDuration = $firstAccess + $duration + $userDuration;
                         if ($totalDuration > $currentTime) {
@@ -2520,7 +2529,7 @@ function api_is_course_session_coach($user_id, $course_code, $session_id)
  * @param string - optional, course code
  * @return boolean True if current user is a course or session coach
  */
-function api_is_coach($session_id = 0, $course_code = null) {
+function api_is_coach($session_id = 0, $course_code = null, $check_student_view = true) {
     if (!empty($session_id)) {
         $session_id = intval($session_id);
     } else {
@@ -2528,7 +2537,9 @@ function api_is_coach($session_id = 0, $course_code = null) {
     }
 
     // The student preview was on
-    if (isset($_SESSION['studentview']) && $_SESSION['studentview'] == "studentview") {
+    if ($check_student_view &&
+        isset($_SESSION['studentview']) && $_SESSION['studentview'] == "studentview"
+    ) {
         return false;
     }
 
@@ -2563,6 +2574,7 @@ function api_is_coach($session_id = 0, $course_code = null) {
 	    } else {
 	    	$sessionIsCoach = Database::store_result($result);
 	    }
+
 	}
     return (count($sessionIsCoach) > 0);
 }
@@ -2812,10 +2824,10 @@ function api_display_debug_info($debug_info) {
 function api_is_allowed_to_edit($tutor = false, $coach = false, $session_coach = false, $check_student_view = true)
 {
     $my_session_id 				= api_get_session_id();
-    $is_allowed_coach_to_edit 	= api_is_coach();
+    $is_allowed_coach_to_edit 	= api_is_coach(null, null, $check_student_view);
     $session_visibility 		= api_get_session_visibility($my_session_id);
 
-    //Admins can edit anything
+    // Admins can edit anything.
     if (api_is_platform_admin(false)) {
         //The student preview was on
         if ($check_student_view && isset($_SESSION['studentview']) && $_SESSION['studentview'] == "studentview") {
@@ -2848,16 +2860,17 @@ function api_is_allowed_to_edit($tutor = false, $coach = false, $session_coach =
     }
 
     if (!$is_courseAdmin && $session_coach) {
-        $is_courseAdmin = $is_courseAdmin || api_is_coach();
+        $is_courseAdmin = $is_courseAdmin || $is_allowed_coach_to_edit;
     }
 
     // Check if the student_view is enabled, and if so, if it is activated.
     if (api_get_setting('student_view_enabled') == 'true') {
         if (!empty($my_session_id)) {
-            // Check if session visibility is read only for coachs
+            // Check if session visibility is read only for coaches.
             if ($session_visibility == SESSION_VISIBLE_READ_ONLY) {
                 $is_allowed_coach_to_edit = false;
             }
+
             if (api_get_setting('allow_coach_to_edit_course_session') == 'true') {
                 // Check if coach is allowed to edit a course.
                 $is_allowed = $is_allowed_coach_to_edit;

+ 1 - 1
main/inc/lib/usermanager.lib.php

@@ -2483,7 +2483,7 @@ class UserManager
                     WHERE id_user = $user_id AND status = 2 ";
 
             if (SessionManager::orderCourseIsEnabled()) {
-                $sql .= "ORDER BY position";
+                //$sql .= "ORDER BY position";
             }
 
             $result = Database::query($sql);

+ 13 - 9
main/newscorm/learnpath.class.php

@@ -8527,7 +8527,6 @@ class learnpath
                                 $my_dep_file->setAttribute('href', $doc_info[0]);
                                 $my_dep->setAttribute('xml:base', '');
 
-                                //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
                                 // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
                                 // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
                                 $abs_img_path_without_subdir = $doc_info[0];
@@ -8536,11 +8535,10 @@ class learnpath
                                 if ($pos === 0) {
                                     $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
                                 }
-                                //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
                                 $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
                                 $file_path = str_replace('\\', '/', $file_path);
                                 $file_path = str_replace('//', '/', $file_path);
-                                //error_log(__LINE__.'Abs path: '.$file_path, 0);
+
                                 // Prepare the current directory path (until just under 'document') with a trailing slash.
                                 $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
                                 // Check if the current document is in that path.
@@ -8551,7 +8549,8 @@ class learnpath
                                     $orig_file_path = str_replace('\\', '/', $orig_file_path);
                                     $relative_path = '';
                                     if (strstr($file_path, $cur_path) !== false) {
-                                        $relative_path = substr($file_path, strlen($orig_file_path));
+                                        //$relative_path = substr($file_path, strlen($orig_file_path));
+                                        $relative_path = str_replace($cur_path, '', $file_path);
                                         $file_path = substr($file_path, strlen($cur_path));
                                     } else {
                                         // This case is still a problem as it's difficult to calculate a relative path easily
@@ -8700,11 +8699,9 @@ class learnpath
                             $url = $link['url'];
                             $title = stripslashes($link['title']);
                             $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
-                            //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
                             $my_xml_file_path = $my_file_path;
                             $my_sub_dir = dirname($my_file_path);
                             $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
-                            //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
                             $my_xml_sub_dir = $my_sub_dir;
                             // Give a <resource> child to the <resources> element.
                             $my_resource = $xmldoc->createElement('resource');
@@ -8806,7 +8803,6 @@ class learnpath
                             $my_dep->setAttribute('adlcp:scormtype', 'asset');
                             $my_dep_file = $xmldoc->createElement('file');
                             // Check type of URL.
-                            //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
                             if ($doc_info[1] == 'remote') {
                                 // Remote file. Save url as is.
                                 $my_dep_file->setAttribute('href', $doc_info[0]);
@@ -8968,6 +8964,8 @@ class learnpath
         // TODO: Add a readme file here, with a short description and a link to the Reload player
         // then add the file to the zip, then destroy the file (this is done automatically).
         // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
+        global $_configuration;
+        $append = $_configuration['url_append'];
 
         foreach ($zip_files as $file_path) {
             if (empty($file_path)) {
@@ -8975,6 +8973,9 @@ class learnpath
             }
 
             $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
+            if (!empty($path_to_remove) && !empty($path_to_replace)) {
+                $dest_file = str_replace($path_to_remove, $path_to_replace, $dest_file);
+            }
             $this->create_path($dest_file);
             @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
             // Check if the file needs a link update.
@@ -8995,19 +8996,22 @@ class learnpath
                     if (strpos("main/default_course_document", $old_new['dest'] === false)) {
                         $new_dest = str_replace('document/', $mult.'document/', $old_new['dest']);
                     } else {
-                        $new_dest = $old_new['dest'];
+                        //$new_dest = $old_new['dest'];
+                        $new_dest = str_replace('document/', '', $old_new['dest']);
                     }
                     $string = str_replace($old_new['orig'], $new_dest, $string);
 
                     //Add files inside the HTMLs
                     $new_path = str_replace('/courses/', '', $old_new['orig']);
+                    $destinationFile = $archive_path.$temp_dir_short.'/'.$old_new['dest'];
                     if (file_exists($sys_course_path.$new_path)) {
-                        copy($sys_course_path.$new_path, $archive_path.$temp_dir_short.'/'.$old_new['dest']);
+                        copy($sys_course_path.$new_path, $destinationFile);
                     }
                 }
                 file_put_contents($dest_file, $string);
             }
         }
+
         foreach ($zip_files_abs as $file_path) {
             if (empty($file_path)) {
                 continue;

+ 3 - 2
main/newscorm/lp_view.php

@@ -319,7 +319,7 @@ $sql = "SELECT audio FROM " . $tbl_lp_item . " WHERE c_id = $course_id AND lp_id
 $res_media= Database::query($sql);
 
 if (Database::num_rows($res_media) > 0) {
-    while ($row_media= Database::fetch_array($res_media)) {
+    while ($row_media = Database::fetch_array($res_media)) {
         if (!empty($row_media['audio'])) {
             $show_audioplayer = true;
             break;
@@ -328,7 +328,8 @@ if (Database::num_rows($res_media) > 0) {
 }
 
 echo '<div id="learning_path_main" style="width:100%;height:100%;">';
-$is_allowed_to_edit = api_is_allowed_to_edit(null, true, false, false);
+$is_allowed_to_edit = api_is_allowed_to_edit(false, true, true, false);
+
 if ($is_allowed_to_edit) {
     echo '<div id="learning_path_breadcrumb_zone">';
     global $interbreadcrumb;