Browse Source

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

Angel Fernando Quiroz Campos 6 years ago
parent
commit
49dc8baf15

+ 5 - 3
main/exercise/question_pool.php

@@ -256,9 +256,11 @@ if (!empty($session_id) && $session_id != '-1' && !empty($sessionList)) {
     }
     $course_list = $sessionInfo['courses'];
 } else {
-    $course_list = CourseManager::get_course_list_of_user_as_course_admin(
-        api_get_user_id()
-    );
+    if (api_is_platform_admin()) {
+        $course_list = CourseManager::get_courses_list(0, 0, 'title');
+    } else {
+        $course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
+    }
 
     // Admin fix, add the current course in the question pool.
     if (api_is_platform_admin()) {

+ 78 - 15
main/forum/forumfunction.inc.php

@@ -670,7 +670,7 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
 function store_forum($values, $courseInfo = [], $returnId = false)
 {
     $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
-    $course_id = $courseInfo['real_id'];
+    $courseId = $courseInfo['real_id'];
     $session_id = api_get_session_id();
     $group_id = api_get_group_id();
     if (isset($values['group_id']) && !empty($values['group_id'])) {
@@ -690,7 +690,7 @@ function store_forum($values, $courseInfo = [], $returnId = false)
         $sql = "SELECT MAX(forum_order) as sort_max
                 FROM $table_forums
                 WHERE
-                    c_id = $course_id AND
+                    c_id = $courseId AND
                     forum_category='".Database::escape_string($values['forum_category'])."'";
         $result = Database::query($sql);
         $row = Database::fetch_array($result);
@@ -770,10 +770,62 @@ function store_forum($values, $courseInfo = [], $returnId = false)
             delete_forum_image($values['forum_id']);
         }
 
+        // Move groups from one group to another
+        if (isset($values['group_forum'])) {
+            $forumData = get_forums($values['forum_id']);
+            $currentGroupId = $forumData['forum_of_group'];
+            if ($currentGroupId != $values['group_forum']) {
+                $threads = get_threads($values['forum_id']);
+                $toGroupId = 'NULL';
+                if (!empty($values['group_forum'])) {
+                    $toGroupId = $values['group_forum'];
+                }
+                $tableItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
+                foreach ($threads as $thread) {
+                    $sql = "UPDATE $tableItemProperty 
+                            SET to_group_id = $toGroupId
+                            WHERE 
+                                tool = '".TOOL_FORUM_THREAD."' AND
+                                ref = ".$thread['thread_id']." AND
+                                c_id = ".$courseId;
+                    Database::query($sql);
+
+                    $posts = getPosts(
+                        $forumData,
+                        $thread['thread_id']
+                    );
+
+                    foreach ($posts as $post) {
+                        $postId = $post['post_id'];
+                        $attachMentList = getAllAttachment($postId);
+                        if (!empty($attachMentList)) {
+                            foreach ($attachMentList as $attachMent) {
+                                $sql = "UPDATE $tableItemProperty 
+                                        SET to_group_id = $toGroupId
+                                        WHERE 
+                                            tool = '".TOOL_FORUM_ATTACH."' AND 
+                                            ref = ".$attachMent['iid']." AND
+                                            c_id = ".$courseId;
+                                Database::query($sql);
+                            }
+                        }
+
+                        $sql = "UPDATE $tableItemProperty 
+                                SET to_group_id = $toGroupId
+                                WHERE 
+                                    tool = '".TOOL_FORUM_POST."' AND
+                                    ref = $postId AND
+                                    c_id = $courseId";
+                        Database::query($sql);
+                    }
+                }
+            }
+        }
+
         Database::update(
             $table_forums,
             $params,
-            ['c_id = ? AND forum_id = ?' => [$course_id, $values['forum_id']]]
+            ['c_id = ? AND forum_id = ?' => [$courseId, $values['forum_id']]]
         );
 
         api_item_property_update(
@@ -792,7 +844,7 @@ function store_forum($values, $courseInfo = [], $returnId = false)
             $new_file_name = isset($new_file_name) ? $new_file_name : '';
         }
         $params = [
-            'c_id' => $course_id,
+            'c_id' => $courseId,
             'forum_title' => $values['forum_title'],
             'forum_image' => $new_file_name,
             'forum_comment' => isset($values['forum_comment']) ? $values['forum_comment'] : null,
@@ -1917,12 +1969,12 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
 function get_threads($forum_id, $courseId = null, $sessionId = null)
 {
     $groupId = api_get_group_id();
-    $sessionId = $sessionId !== null ? intval($sessionId) : api_get_session_id();
+    $sessionId = $sessionId !== null ? (int) $sessionId : api_get_session_id();
     $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
     $table_users = Database::get_main_table(TABLE_MAIN_USER);
 
-    $courseId = $courseId !== null ? intval($courseId) : api_get_course_int_id();
+    $courseId = $courseId !== null ? (int) $courseId : api_get_course_int_id();
     $groupInfo = GroupManager::get_group_properties($groupId);
     $groupCondition = '';
 
@@ -3984,10 +4036,11 @@ function increase_thread_view($thread_id)
  *
  * @version february 2006, dokeos 1.8
  *
+ * @param int    $threadId
  * @param string $lastPostId
  * @param string $post_date
  */
-function updateThreadInfo($thread_id, $lastPostId, $post_date)
+function updateThreadInfo($threadId, $lastPostId, $post_date)
 {
     $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
     $course_id = api_get_course_int_id();
@@ -3997,7 +4050,7 @@ function updateThreadInfo($thread_id, $lastPostId, $post_date)
             thread_date = '".Database::escape_string($post_date)."'
             WHERE 
                 c_id = $course_id AND  
-                thread_id='".Database::escape_string($thread_id)."'"; // this needs to be cleaned first
+                thread_id='".Database::escape_string($threadId)."'"; // this needs to be cleaned first
     Database::query($sql);
 }
 
@@ -5041,7 +5094,7 @@ function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
 /**
  * Show a list with all the attachments according to the post's id.
  *
- * @param int $post_id
+ * @param int $postId
  *
  * @return array with the post info
  *
@@ -5049,15 +5102,20 @@ function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
  *
  * @version avril 2008, dokeos 1.8.5
  */
-function get_attachment($post_id)
+function get_attachment($postId)
 {
-    $forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
+    $table = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
     $course_id = api_get_course_int_id();
     $row = [];
-    $post_id = intval($post_id);
+    $postId = (int) $postId;
+
+    if (empty($postId)) {
+        return [];
+    }
+
     $sql = "SELECT iid, path, filename, comment 
-            FROM $forum_table_attachment
-            WHERE c_id = $course_id AND post_id = $post_id";
+            FROM $table
+            WHERE c_id = $course_id AND post_id = $postId";
     $result = Database::query($sql);
     if (Database::num_rows($result) != 0) {
         $row = Database::fetch_array($result);
@@ -5075,7 +5133,12 @@ function getAllAttachment($postId)
 {
     $forumAttachmentTable = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
     $courseId = api_get_course_int_id();
-    $postId = intval($postId);
+    $postId = (int) $postId;
+
+    if (empty($postId)) {
+        return [];
+    }
+
     $columns = ['iid', 'path', 'filename', 'comment'];
     $conditions = [
         'where' => [

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

@@ -169,7 +169,7 @@ class CourseManager
         $conditionsLike = [],
         $onlyThisCourseList = []
     ) {
-        $sql = "SELECT course.* FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." course ";
+        $sql = "SELECT course.*, id as real_id FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." course ";
 
         if (!empty($urlId)) {
             $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);

+ 4 - 2
main/lp/learnpath.class.php

@@ -9456,12 +9456,14 @@ class learnpath
      * @param string $title
      * @param int    $parentId
      *
-     * @return int
      * @throws \Doctrine\ORM\ORMException
      * @throws \Doctrine\ORM\OptimisticLockException
      * @throws \Doctrine\ORM\TransactionRequiredException
+     *
+     * @return int
      */
-    public function createReadOutText($courseInfo, $content = '', $title = '', $parentId = 0) {
+    public function createReadOutText($courseInfo, $content = '', $title = '', $parentId = 0)
+    {
         $creatorId = api_get_user_id();
         $sessionId = api_get_session_id();
 

+ 3 - 3
main/lp/lp_ajax_save_item.php

@@ -85,7 +85,7 @@ function save_item(
 
     if (!is_a($myLP, 'learnpath')) {
         if ($debug) {
-            error_log("mylp variable is not an learnpath object");
+            error_log('mylp variable is not an learnpath object');
         }
 
         return null;
@@ -146,7 +146,7 @@ function save_item(
             }
         } else {
             if ($debug > 1) {
-                error_log("Score not updated");
+                error_log('Score not updated');
             }
         }
 
@@ -164,7 +164,7 @@ function save_item(
             }
         } else {
             if ($debug > 1) {
-                error_log("Status not updated");
+                error_log('Status not updated');
             }
         }
 

+ 2 - 4
main/lp/lp_nav.php

@@ -53,13 +53,11 @@ if ($myLP) {
 
     if ($mediaplayer) {
         echo $mediaplayer;
-        ?>
-        <script>
+        echo "<script>
             $(function() {
                 jQuery('video:not(.skip), audio:not(.skip)').mediaelementplayer();
             });
-        </script>
-        <?php
+        </script>";
     }
 }
 session_write_close();

+ 5 - 6
main/lp/readout_text.php

@@ -1,14 +1,13 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Chamilo\CourseBundle\Entity\CDocument;
+
 /**
- * Print a read-out text inside a session
+ * Print a read-out text inside a session.
  *
  * @package chamilo.learnpath
  */
-
-use Chamilo\CourseBundle\Entity\CDocument;
-
 $_in_course = true;
 
 require_once __DIR__.'/../inc/global.inc.php';
@@ -17,8 +16,8 @@ $current_course_tool = TOOL_LEARNPATH;
 
 api_protect_course_script(true);
 
-$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
-$lpId = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : 0;
+$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
+$lpId = isset($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
 $courseInfo = api_get_course_info();
 $courseCode = $courseInfo['code'];
 $courseId = $courseInfo['real_id'];

+ 1 - 1
main/survey/reporting.php

@@ -125,7 +125,7 @@ if ($action == 'overview') {
     ];
     switch ($action) {
         case 'questionreport':
-            $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0;
+            $singlePage = isset($_GET['single_page']) ? (int) $_GET['single_page'] : 0;
             $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion');
             break;
         case 'userreport':

+ 8 - 10
main/survey/surveyUtil.class.php

@@ -235,7 +235,7 @@ class SurveyUtil
         $questions_data = [];
 
         foreach ($my_temp_questions_data as $key => &$value) {
-            if ($value['type'] != 'comment' && $value['type'] != 'pagebreak') {
+            if ($value['type'] != 'pagebreak') {
                 $questions_data[$value['sort']] = $value;
             }
         }
@@ -519,18 +519,18 @@ class SurveyUtil
     public static function display_question_report($survey_data)
     {
         $singlePage = isset($_GET['single_page']) ? (int) $_GET['single_page'] : 0;
+        // Determining the offset of the sql statement (the n-th question of the survey)
+        $offset = !isset($_GET['question']) ? 0 : (int) $_GET['question'];
+        $currentQuestion = isset($_GET['question']) ? (int) $_GET['question'] : 0;
+        $surveyId = (int) $_GET['survey_id'];
+        $action = Security::remove_XSS($_GET['action']);
         $course_id = api_get_course_int_id();
+
         // Database table definitions
         $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
         $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
         $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
-
-        // Determining the offset of the sql statement (the n-th question of the survey)
-        $offset = !isset($_GET['question']) ? 0 : (int) $_GET['question'];
-        $currentQuestion = isset($_GET['question']) ? (int) $_GET['question'] : 0;
         $questions = [];
-        $surveyId = (int) $_GET['survey_id'];
-        $action = Security::remove_XSS($_GET['action']);
 
         echo '<div class="actions">';
         echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$surveyId.'&'.api_get_cidreq().'">'.
@@ -575,8 +575,7 @@ class SurveyUtil
 			        WHERE
 			            c_id = $course_id AND
                         survey_id='".$surveyId."' AND
-                        type <>'pagebreak'  
-                        
+                        type <>'pagebreak'                        
                     ORDER BY sort ASC
                     $limitStatement";
             $result = Database::query($sql);
@@ -584,7 +583,6 @@ class SurveyUtil
                 $questions[$row['question_id']] = $row;
             }
         }
-
         foreach ($questions as $question) {
             $chartData = [];
             $options = [];