Browse Source

Minor - partial merge with 1.11.x

Julio Montoya 5 years ago
parent
commit
88280336fe

+ 1 - 1
main/course_home/course_home.php

@@ -177,7 +177,7 @@ $logInfo = [
 ];
 Event::registerLog($logInfo);
 
-/*Auto launch code */
+/* Auto launch code */
 $autoLaunchWarning = '';
 $showAutoLaunchLpWarning = false;
 $course_id = api_get_course_int_id();

+ 0 - 3
main/forum/forumfunction.inc.php

@@ -453,8 +453,6 @@ function show_add_forum_form($inputvalues = [], $lp_id)
         $defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null;
     }
 
-    // $defaults['skills'] = array_keys($skillList);
-
     $form->setDefaults($defaults);
     // Validation or display
     if ($form->validate()) {
@@ -6937,4 +6935,3 @@ function reportPost($postId, $forumInfo, $threadInfo)
         }
     }
 }
-

+ 2 - 2
main/group/group_creation.php

@@ -134,7 +134,7 @@ if (isset($_POST['number_of_groups'])) {
     <?php
         }
         $group_categories = GroupManager::get_categories();
-        $group_id = GroupManager:: get_number_of_groups() + 1;
+        $group_id = GroupManager::get_number_of_groups() + 1;
         $cat_options = [];
         foreach ($group_categories as $index => $category) {
             $cat_options[$category['id']] = $category['title'];
@@ -233,7 +233,7 @@ EOT;
             $form->addGroup($group_el, 'group_'.$group_number, null, '</td><td>', false);
         }
         $defaults['action'] = 'create_groups';
-        $defaults['number_of_groups'] = intval($_POST['number_of_groups']);
+        $defaults['number_of_groups'] = (int) $_POST['number_of_groups'];
         $form->setDefaults($defaults);
         $form->addButtonCreate(get_lang('CreateGroup'), 'submit');
         $form->display();

+ 37 - 7
main/group/settings.php

@@ -21,12 +21,16 @@ api_protect_course_script(true);
 $group_id = api_get_group_id();
 $current_group = GroupManager::get_group_properties($group_id);
 
+if (empty($current_group)) {
+    api_not_allowed(true);
+}
+
 $nameTools = get_lang('EditGroup');
 $interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
 $interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
-$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
+$groupMember = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
 
-if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
+if (!$groupMember && !api_is_allowed_to_edit(false, true)) {
     api_not_allowed(true);
 }
 
@@ -67,8 +71,21 @@ $form->addElement('html', '<div class="col-md-6">');
 
 // Members per group
 $group = [
-    $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
-    $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, ['id' => 'max_member_selected']),
+    $form->createElement(
+        'radio',
+        'max_member_no_limit',
+        get_lang('GroupLimit'),
+        get_lang('NoLimit'),
+        GroupManager::MEMBER_PER_GROUP_NO_LIMIT
+    ),
+    $form->createElement(
+        'radio',
+        'max_member_no_limit',
+        null,
+        get_lang('MaximumOfParticipants'),
+        1,
+        ['id' => 'max_member_selected']
+    ),
     $form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
     $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis')),
 ];
@@ -81,13 +98,26 @@ $form->addElement('html', '<div class="col-md-6">');
 
 // Self registration
 $group = [
-    $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
-    $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1),
+    $form->createElement(
+        'checkbox',
+        'self_registration_allowed',
+        get_lang('GroupSelfRegistration'),
+        get_lang('GroupAllowStudentRegistration'),
+        1
+    ),
+    $form->createElement(
+        'checkbox',
+        'self_unregistration_allowed',
+        null,
+        get_lang('GroupAllowStudentUnregistration'),
+        1
+    ),
 ];
 $form->addGroup(
     $group,
     '',
-    Display::return_icon('user.png', get_lang('GroupSelfRegistration')).'<span>'.get_lang('GroupSelfRegistration').'</span>',
+    Display::return_icon('user.png', get_lang('GroupSelfRegistration')).
+    '<span>'.get_lang('GroupSelfRegistration').'</span>',
     null,
     false
 );

+ 2 - 1
main/inc/ajax/announcement.ajax.php

@@ -10,6 +10,7 @@ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
 
 $isAllowedToEdit = api_is_allowed_to_edit();
 $courseInfo = api_get_course_info();
+$courseId = api_get_course_int_id();
 $groupId = api_get_group_id();
 $sessionId = api_get_session_id();
 
@@ -35,7 +36,7 @@ switch ($action) {
         }
 
         if ($allowToEdit === false && !empty($groupId)) {
-            $groupProperties = GroupManager:: get_group_properties($groupId);
+            $groupProperties = GroupManager::get_group_properties($groupId);
             // Check if user is tutor group
             $isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupProperties, $courseId);
             if ($isTutor) {

+ 3 - 9
main/inc/ajax/document.ajax.php

@@ -20,16 +20,10 @@ switch ($action) {
         $courseQuota = DocumentManager::get_course_quota();
 
         // Calculating the total space
-        $already_consumed_space_course = DocumentManager::documents_total_space(
-            api_get_course_int_id()
-        );
+        $total = DocumentManager::documents_total_space(api_get_course_int_id());
 
         // Displaying the quota
-        echo DocumentManager::displaySimpleQuota(
-            $courseQuota,
-            $already_consumed_space_course
-        );
-
+        echo DocumentManager::displaySimpleQuota($courseQuota, $total);
         break;
     case 'upload_file':
         api_protect_course_script(true);
@@ -47,7 +41,7 @@ switch ($action) {
                 exit;
             }
         } elseif ($is_allowed_to_edit ||
-            DocumentManager::is_my_shared_folder(api_get_user_id(), $_POST['curdirpath'], api_get_session_id())
+            DocumentManager::is_my_shared_folder(api_get_user_id(), $_REQUEST['curdirpath'], api_get_session_id())
         ) {
             // ??
         } else {

+ 31 - 0
main/inc/ajax/exercise.ajax.php

@@ -762,6 +762,37 @@ switch ($action) {
             true
         );
         break;
+    case 'get_quiz_embeddable':
+        $exercises = ExerciseLib::get_all_exercises_for_course_id(
+            api_get_course_info(),
+            api_get_session_id(),
+            api_get_course_int_id(),
+            false
+        );
+
+        $exercises = array_filter(
+            $exercises,
+            function (array $exercise) {
+                return ExerciseLib::isQuizEmbeddable($exercise);
+            }
+        );
+
+        $result = [];
+
+        $codePath = api_get_path(WEB_CODE_PATH);
+
+        foreach ($exercises as $exercise) {
+            $title = Security::remove_XSS(api_html_entity_decode($exercise['title']));
+
+            $result[] = [
+                'id' => $exercise['iid'],
+                'title' => strip_tags($title),
+            ];
+        }
+
+        header('Content-Type: application/json');
+        echo json_encode($result);
+        break;
     default:
         echo '';
 }

+ 41 - 1
main/inc/ajax/work.ajax.php

@@ -8,14 +8,54 @@ require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
 
 $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
 $isAllowedToEdit = api_is_allowed_to_edit();
+$courseInfo = api_get_course_info();
 
 switch ($action) {
+    case 'show_student_work':
+        api_protect_course_script(true);
+        if ($isAllowedToEdit) {
+            $itemList = isset($_REQUEST['item_list']) ? $_REQUEST['item_list'] : [];
+            $itemList = explode(',', $itemList);
+            if (!empty($itemList)) {
+                foreach ($itemList as $itemId) {
+                    makeVisible($itemId, $courseInfo);
+                }
+                echo '1';
+                exit;
+            }
+        }
+        echo '0';
+        break;
+    case 'hide_student_work':
+        api_protect_course_script(true);
+        if ($isAllowedToEdit) {
+            $itemList = isset($_REQUEST['item_list']) ? $_REQUEST['item_list'] : [];
+            $itemList = explode(',', $itemList);
+            if (!empty($itemList)) {
+                foreach ($itemList as $itemId) {
+                    makeInvisible($itemId, $courseInfo);
+                }
+                echo '1';
+                exit;
+            }
+        }
+        echo '0';
+        break;
+    case 'delete_student_work':
+        api_protect_course_script(true);
+        if ($isAllowedToEdit) {
+            $itemId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
+            deleteWorkItem($itemId, $courseInfo);
+            echo '1';
+            exit;
+        }
+        echo '0';
+        break;
     case 'upload_file':
         api_protect_course_script(true);
         $workId = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
 
         $workInfo = get_work_data_by_id($workId);
-        $courseInfo = api_get_course_info();
         $sessionId = api_get_session_id();
         $userId = api_get_user_id();
         $groupId = api_get_group_id();

+ 13 - 18
main/inc/lib/CoursesAndSessionsCatalog.class.php

@@ -571,27 +571,23 @@ class CoursesAndSessionsCatalog
         $em = Database::getManager();
         $urlId = api_get_current_access_url_id();
 
-        $sql = "SELECT s.id FROM session s ";
-        $sql .= "
-            INNER JOIN access_url_rel_session ars
-            ON s.id = ars.session_id
-        ";
-
-        $sql .= "
-            WHERE s.nbr_courses > 0
-                AND ars.access_url_id = $urlId
-        ";
+        $sql = "SELECT s.id FROM session s 
+                INNER JOIN access_url_rel_session ars
+                ON s.id = ars.session_id
+                WHERE 
+                      s.nbr_courses > 0 AND 
+                      ars.access_url_id = $urlId";
 
         if (!is_null($date)) {
             $date = Database::escape_string($date);
             $sql .= "
                 AND (
-                    ('$date' BETWEEN DATE(s.access_start_date) AND DATE(s.access_end_date))
-                    OR (s.access_end_date IS NULL)
-                    OR (
-                        s.access_start_date IS NULL
-                        AND s.access_end_date IS NOT NULL
-                        AND DATE(s.access_end_date) >= '$date'
+                    ('$date' BETWEEN DATE(s.access_start_date) AND DATE(s.access_end_date)) OR 
+                    (s.access_end_date IS NULL) OR 
+                    (
+                        s.access_start_date IS NULL AND 
+                        s.access_end_date IS NOT NULL AND 
+                        DATE(s.access_end_date) >= '$date'
                     )
                 )
             ";
@@ -606,8 +602,7 @@ class CoursesAndSessionsCatalog
         $list = Database::store_result(Database::query($sql), 'ASSOC');
         $sessions = [];
         foreach ($list as $sessionData) {
-            $id = $sessionData['id'];
-            $sessions[] = $em->find('ChamiloCoreBundle:Session', $id);
+            $sessions[] = $em->find('ChamiloCoreBundle:Session', $sessionData['id']);
         }
 
         return $sessions;

+ 3 - 6
main/inc/lib/MoodleImport.php

@@ -85,11 +85,10 @@ class MoodleImport
                 break;
         }
 
-        $coursePath = api_get_course_path();
+        $courseInfo = api_get_course_info();
         $sessionId = api_get_session_id();
         $groupId = api_get_group_id();
-        $documentPath = api_get_path(SYS_COURSE_PATH).$coursePath.'/document';
-        $courseInfo = api_get_course_info();
+        $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
 
         create_unexisting_directory(
             $courseInfo,
@@ -107,9 +106,7 @@ class MoodleImport
         $filesXml = @file_get_contents($destinationDir.'/files.xml');
         $mainFileModuleValues = $this->getAllQuestionFiles($filesXml);
         $currentResourceFilePath = $destinationDir.'/files/';
-
         $importedFiles = [];
-
         foreach ($mainFileModuleValues as $fileInfo) {
             $dirs = new RecursiveDirectoryIterator($currentResourceFilePath);
             foreach (new RecursiveIteratorIterator($dirs) as $file) {
@@ -270,7 +267,7 @@ class MoodleImport
                         // Replace the path from @@PLUGINFILE@@ to a correct chamilo path
                         $questionText = str_replace(
                             '@@PLUGINFILE@@',
-                            '/courses/'.$coursePath.'/document/moodle',
+                            '/courses/'.$courseInfo['path'].'/document/moodle',
                             $questionText
                         );
 

+ 0 - 1
main/inc/lib/ScheduledAnnouncement.php

@@ -265,7 +265,6 @@ class ScheduledAnnouncement extends Model
     {
         $file = $this->getAttachment($id);
         if (!empty($file) && !empty($file['value'])) {
-            //$file = api_get_uploaded_web_url('schedule_announcement', $id, basename($file['value']));
             $url = api_get_path(WEB_UPLOAD_PATH).$file['value'];
 
             return get_lang('Attachment').': '.Display::url(basename($file['value']), $url, ['target' => '_blank']);

+ 2 - 2
main/inc/lib/add_course.lib.inc.php

@@ -684,7 +684,7 @@ class AddCourse
                 'id' => 2,
                 'title' => get_lang('DefaultGroupCategory'),
                 'description' => '',
-                'max_student' => 8,
+                'max_student' => 0,
                 'self_reg_allowed' => 0,
                 'self_unreg_allowed' => 0,
                 'groups_per_user' => 0,
@@ -704,6 +704,7 @@ class AddCourse
         $files = [
             ['path' => '/shared_folder', 'title' => get_lang('UserFolders'), 'filetype' => 'folder', 'size' => 0],
             ['path' => '/chat_files', 'title' => get_lang('ChatFiles'), 'filetype' => 'folder', 'size' => 0],
+            ['path' => '/certificates', 'title' => get_lang('CertificatesFiles'), 'filetype' => 'folder', 'size' => 0],
         ];
 
         $counter = 1;
@@ -730,7 +731,6 @@ class AddCourse
                 ['path' => '/audio', 'title' => get_lang('Audio'), 'filetype' => 'folder', 'size' => 0],
                 ['path' => '/flash', 'title' => get_lang('Flash'), 'filetype' => 'folder', 'size' => 0],
                 ['path' => '/video', 'title' => get_lang('Video'), 'filetype' => 'folder', 'size' => 0],
-                ['path' => '/certificates', 'title' => get_lang('Certificates'), 'filetype' => 'folder', 'size' => 0],
             ];
 
             foreach ($files as $file) {

+ 13 - 3
main/inc/lib/api.lib.php

@@ -407,6 +407,7 @@ define('SCORE_CUSTOM', 10); // Good!
 define('SCORE_DIV_SIMPLE_WITH_CUSTOM', 11); // X - Good!
 define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS', 12); // X - Good!
 define('SCORE_ONLY_SCORE', 13); // X - Good!
+define('SCORE_NUMERIC', 14);
 
 define('SCORE_BOTH', 1);
 define('SCORE_ONLY_DEFAULT', 2);
@@ -4951,8 +4952,12 @@ function api_get_language_from_type($lang_type)
  */
 function api_get_language_info($languageId)
 {
+    if (empty($languageId)) {
+        return [];
+    }
+
     $language = Database::getManager()
-        ->find('ChamiloCoreBundle:Language', intval($languageId));
+        ->find('ChamiloCoreBundle:Language', $languageId);
 
     if (!$language) {
         return [];
@@ -9543,13 +9548,18 @@ function api_get_language_translate_html()
     $userInfo = api_get_user_info();
     $languageId = api_get_language_id($userInfo['language']);
     $languageInfo = api_get_language_info($languageId);
+    $isoCode = 'en';
+
+    if (!empty($languageInfo)) {
+        $isoCode = $languageInfo['isocode'];
+    }
 
     return '
             $(function() {
                 '.$hideAll.'                 
-                var defaultLanguageFromUser = "'.$languageInfo['isocode'].'";   
+                var defaultLanguageFromUser = "'.$isoCode.'";   
                                              
-                $("span:lang('.$languageInfo['isocode'].')").filter(
+                $("span:lang('.$isoCode.')").filter(
                     function() {
                         // Ignore ckeditor classes
                         return !this.className.match(/cke(.*)/);

+ 0 - 1
main/inc/lib/certificate.lib.php

@@ -67,7 +67,6 @@ class Certificate extends Model
         if ($this->user_id) {
             // Need to be called before any operation
             $this->check_certificate_path();
-
             // To force certification generation
             if ($this->force_certificate_generation) {
                 $this->generate([], $sendNotification);

+ 77 - 46
main/inc/lib/link.lib.php

@@ -861,7 +861,6 @@ class Link extends Model
                     'LinkCategoryAdded',
                     api_get_user_id()
                 );
-                //api_set_default_visibility($category['id'], TOOL_LINK_CATEGORY);
             }
         }
 
@@ -966,20 +965,21 @@ class Link extends Model
     /**
      * Displays all the links of a given category.
      *
-     * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-     * @author Julio Montoya
-     *
-     * @param $catid
-     * @param int $courseId
-     * @param int $session_id
+     * @param int  $catid
+     * @param int  $courseId
+     * @param int  $session_id
+     * @param bool $showActionLinks
      *
      * @return string
+     *
+     * @author Julio Montoya
+     * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
      */
-    public static function showLinksPerCategory($catid, $courseId, $session_id)
+    public static function showLinksPerCategory($catid, $courseId, $session_id, $showActionLinks = true)
     {
         global $token;
         $_user = api_get_user_info();
-        $catid = intval($catid);
+        $catid = (int) $catid;
 
         $links = self::getLinksPerCategory($catid, $courseId, $session_id);
         $content = '';
@@ -1102,7 +1102,7 @@ class Link extends Model
                             false
                         );
 
-                        $url .= api_get_self().'?'.api_get_cidreq().'&sec_token='.$token.'&action=deletelink&id='.$linkId.'&category_id='.$categoryId;
+                        $url = api_get_self().'?'.api_get_cidreq().'&sec_token='.$token.'&action=deletelink&id='.$linkId.'&category_id='.$categoryId;
                         $event = "javascript: if(!confirm('".get_lang('LinkDelconfirm')."'))return false;";
                         $title = get_lang('Delete');
 
@@ -1139,7 +1139,9 @@ class Link extends Model
                     );
                     $url = api_get_path(WEB_CODE_PATH).'link/link_goto.php?'.api_get_cidreq().'&link_id='.$linkId.'&link_url='.urlencode($myrow['url']);
                     $content .= '<div class="list-group-item">';
-                    $content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
+                    if ($showActionLinks) {
+                        $content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
+                    }
                     $content .= '<h4 class="list-group-item-heading">';
                     $content .= $iconLink;
                     $content .= Display::tag(
@@ -1517,7 +1519,7 @@ class Link extends Model
      */
     public static function isVimeoLink($url)
     {
-        $isLink = strrpos($url, "vimeo.com");
+        $isLink = strrpos($url, 'vimeo.com');
 
         return $isLink;
     }
@@ -1556,9 +1558,9 @@ class Link extends Model
      */
     public static function is_youtube_link($url)
     {
-        $is_youtube_link = strrpos($url, "youtube") || strrpos(
+        $is_youtube_link = strrpos($url, 'youtube') || strrpos(
             $url,
-            "youtu.be"
+            'youtu.be'
         );
 
         return $is_youtube_link;
@@ -1635,44 +1637,68 @@ class Link extends Model
      * @param int    $categoryId
      * @param string $show
      * @param null   $token
+     * @param bool   $showActionLinks
+     *
+     * @return string
      */
     public static function listLinksAndCategories(
         $course_id,
         $session_id,
         $categoryId,
         $show = 'none',
-        $token = null
+        $token = null,
+        $showActionLinks = true
     ) {
-        $tbl_link = Database::get_course_table(TABLE_LINK);
-        $tblCIP = Database::get_course_table(TABLE_ITEM_PROPERTY);
-        $categoryId = intval($categoryId);
-
-        /*	Action Links */
-        echo '<div class="actions">';
-        if (api_is_allowed_to_edit(null, true)) {
-            echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addlink&category_id='.$categoryId.'">'.
-                Display::return_icon('new_link.png', get_lang('LinkAdd'), '', ICON_SIZE_MEDIUM).'</a>';
-            echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addcategory&category_id='.$categoryId.'">'.
-                Display::return_icon('new_folder.png', get_lang('CategoryAdd'), '', ICON_SIZE_MEDIUM).'</a>';
-        }
+        $categoryId = (int) $categoryId;
+
+        $content = '';
 
         $categories = self::getLinkCategories($course_id, $session_id);
         $countCategories = count($categories);
-        if (!empty($countCategories)) {
-            echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=list&show=none">';
-            echo Display::return_icon('forum_listview.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).' </a>';
+        $linksPerCategory = self::showLinksPerCategory(0, $course_id, $session_id, $showActionLinks);
+
+        if ($showActionLinks) {
+            /*	Action Links */
+            $content = '<div class="actions">';
+            if (api_is_allowed_to_edit(null, true)) {
+                $content .= '<a href="'.api_get_self().'?'.api_get_cidreq(
+                    ).'&action=addlink&category_id='.$categoryId.'">'.
+                    Display::return_icon('new_link.png', get_lang('LinkAdd'), '', ICON_SIZE_MEDIUM).'</a>';
+                $content .= '<a href="'.api_get_self().'?'.api_get_cidreq(
+                    ).'&action=addcategory&category_id='.$categoryId.'">'.
+                    Display::return_icon('new_folder.png', get_lang('CategoryAdd'), '', ICON_SIZE_MEDIUM).'</a>';
+            }
 
-            echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=list&show=all">';
-            echo Display::return_icon('forum_nestedview.png', get_lang('NestedView'), '', ICON_SIZE_MEDIUM).'</a>';
+            if (!empty($countCategories)) {
+                $content .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=list&show=none">';
+                $content .= Display::return_icon(
+                        'forum_listview.png',
+                        get_lang('FlatView'),
+                        '',
+                        ICON_SIZE_MEDIUM
+                    ).' </a>';
+
+                $content .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=list&show=all">';
+                $content .= Display::return_icon(
+                        'forum_nestedview.png',
+                        get_lang('NestedView'),
+                        '',
+                        ICON_SIZE_MEDIUM
+                    ).'</a>';
+            }
+
+            $content .= Display::url(
+                Display::return_icon('pdf.png', get_lang('ExportToPdf'), '', ICON_SIZE_MEDIUM),
+                api_get_self().'?'.api_get_cidreq().'&action=export'
+            );
+            $content .= '</div>';
         }
-        echo '</div>';
-        $linksPerCategory = self::showLinksPerCategory(0, $course_id, $session_id);
 
         if (empty($countCategories)) {
-            echo $linksPerCategory;
+            $content .= $linksPerCategory;
         } else {
             if (!empty($linksPerCategory)) {
-                echo Display::panel($linksPerCategory, get_lang('NoCategory'));
+                $content .= Display::panel($linksPerCategory, get_lang('NoCategory'));
             }
         }
 
@@ -1708,16 +1734,16 @@ class Link extends Model
                 $header .= '<a class="'.$visibilityClass.'" href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$myrow['id'].'">';
                 $header .= Display::return_icon('forum_listview.png');
             }
-
             $header .= Security::remove_XSS($myrow['category_title']).'</a>';
-            $header .= '<div class="pull-right">';
 
-            if (api_is_allowed_to_edit(null, true)) {
-                if ($session_id == $myrow['session_id']) {
-                    $header .= $strVisibility;
-                    $header .= self::showCategoryAdminTools($myrow, $counter, count($categories));
-                } else {
-                    $header .= get_lang('EditionNotAvailableFromSession');
+            if ($showActionLinks) {
+                if (api_is_allowed_to_edit(null, true)) {
+                    if ($session_id == $myrow['session_id']) {
+                        $header .= $strVisibility;
+                        $header .= self::showCategoryAdminTools($myrow, $counter, count($categories));
+                    } else {
+                        $header .= get_lang('EditionNotAvailableFromSession');
+                    }
                 }
             }
 
@@ -1730,10 +1756,12 @@ class Link extends Model
                 );
             }
 
-            echo Display::panel($myrow['description'].$childrenContent, $header);
+            $content .= Display::panel($myrow['description'].$childrenContent, $header);
 
             $counter++;
         }
+
+        return $content;
     }
 
     /**
@@ -1870,6 +1898,9 @@ class Link extends Model
      */
     public static function getCategoryForm($id, $action)
     {
+        $id = (int) $id;
+        $action = Security::remove_XSS($action);
+
         $form = new FormValidator(
             'category',
             'post',
@@ -1902,7 +1933,7 @@ class Link extends Model
     public static function getCategory($id)
     {
         $table = Database::get_course_table(TABLE_LINK_CATEGORY);
-        $id = intval($id);
+        $id = (int) $id;
         $courseId = api_get_course_int_id();
 
         if (empty($id) || empty($courseId)) {

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

@@ -226,7 +226,8 @@ class Promotion extends Model
         if ($action == 'edit') {
             $header = get_lang('Modify');
         }
-        $id = isset($_GET['id']) ? intval($_GET['id']) : '';
+
+        $id = isset($_GET['id']) ? (int) $_GET['id'] : '';
 
         $form->addElement('header', '', $header);
         $form->addElement('hidden', 'id', $id);

+ 49 - 36
main/inc/lib/skill.lib.php

@@ -37,7 +37,7 @@ class SkillProfile extends Model
     {
         $sql = "SELECT * FROM $this->table p
                 INNER JOIN $this->table_rel_profile sp
-                ON(p.id = sp.profile_id) ";
+                ON (p.id = sp.profile_id) ";
         $result = Database::query($sql);
         $profiles = Database::store_result($result, 'ASSOC');
 
@@ -147,7 +147,7 @@ class SkillRelProfile extends Model
      */
     public function getSkillsByProfile($profileId)
     {
-        $profileId = intval($profileId);
+        $profileId = (int) $profileId;
         $skills = $this->get_all(['where' => ['profile_id = ? ' => $profileId]]);
         $return = [];
         if (!empty($skills)) {
@@ -168,10 +168,11 @@ class SkillRelProfile extends Model
      */
     public function getProfileInfo($profileId)
     {
+        $profileId = (int) $profileId;
         $sql = "SELECT * FROM $this->table p
                 INNER JOIN $this->tableProfile pr
                 ON (pr.id = p.profile_id)
-                WHERE p.profile_id = ".intval($profileId);
+                WHERE p.profile_id = ".$profileId;
         $result = Database::query($sql);
         $profileData = Database::fetch_array($result, 'ASSOC');
 
@@ -204,13 +205,16 @@ class SkillRelSkill extends Model
      */
     public function getSkillInfo($id)
     {
+        $id = (int) $id;
+
         if (empty($id)) {
             return [];
         }
+
         $result = Database::select(
             '*',
             $this->table,
-            ['where' => ['skill_id = ?' => intval($id)]],
+            ['where' => ['skill_id = ?' => $id]],
             'first'
         );
 
@@ -225,7 +229,7 @@ class SkillRelSkill extends Model
      */
     public function getSkillParents($skillId, $add_child_info = true)
     {
-        $skillId = intval($skillId);
+        $skillId = (int) $skillId;
         $sql = 'SELECT child.* FROM '.$this->table.' child
                 LEFT JOIN '.$this->table.' parent
                 ON child.parent_id = parent.skill_id
@@ -569,10 +573,10 @@ class SkillRelUser extends Model
             return [];
         }
 
-        $courseId = intval($courseId);
-        $sessionId = $sessionId ? intval($sessionId) : null;
+        $courseId = (int) $courseId;
+        $sessionId = $sessionId ? (int) $sessionId : null;
         $whereConditions = [
-            'user_id = ? ' => intval($userId),
+            'user_id = ? ' => (int) $userId,
         ];
 
         if ($courseId > 0) {
@@ -727,12 +731,12 @@ class Skill extends Model
         $path = api_get_path(WEB_UPLOAD_PATH).'badges/';
         if (!empty($result['icon'])) {
             $iconSmall = sprintf(
-                "%s-small.png",
+                '%s-small.png',
                 sha1($result['name'])
             );
 
             $iconBig = sprintf(
-                "%s.png",
+                '%s.png',
                 sha1($result['name'])
             );
 
@@ -875,7 +879,7 @@ class Skill extends Model
         $skillInfo = $this->get($id);
         if (!empty($skillInfo)) {
             $skillInfo['extra'] = $skillRelSkill->getSkillInfo($id);
-            $skillInfo['gradebooks'] = self::getGradebooksBySkill($id);
+            $skillInfo['gradebooks'] = $this->getGradebooksBySkill($id);
         }
 
         return $skillInfo;
@@ -903,7 +907,7 @@ class Skill extends Model
             }
 
             $skill['icon_small'] = sprintf(
-                "badges/%s-small.png",
+                'badges/%s-small.png',
                 sha1($skill['name'])
             );
             $skill['name'] = self::translateName($skill['name']);
@@ -929,12 +933,12 @@ class Skill extends Model
     ) {
         $id_condition = '';
         if (!empty($id)) {
-            $id = intval($id);
+            $id = (int) $id;
             $id_condition = " WHERE s.id = $id";
         }
 
         if (!empty($parent_id)) {
-            $parent_id = intval($parent_id);
+            $parent_id = (int) $parent_id;
             if (empty($id_condition)) {
                 $id_condition = " WHERE ss.parent_id = $parent_id";
             } else {
@@ -972,7 +976,7 @@ class Skill extends Model
                 $skillRelSkill = new SkillRelSkill();
                 $parents = $skillRelSkill->getSkillParents($row['id']);
                 $row['level'] = count($parents) - 1;
-                $row['gradebooks'] = self::getGradebooksBySkill($row['id']);
+                $row['gradebooks'] = $this->getGradebooksBySkill($row['id']);
                 $skills[$row['id']] = $row;
             }
         }
@@ -998,7 +1002,7 @@ class Skill extends Model
      */
     public function getGradebooksBySkill($skill_id)
     {
-        $skill_id = intval($skill_id);
+        $skill_id = (int) $skill_id;
         $sql = "SELECT g.* FROM {$this->table_gradebook} g
                 INNER JOIN {$this->table_skill_rel_gradebook} sg
                 ON g.id = sg.gradebook_id
@@ -1118,14 +1122,14 @@ class Skill extends Model
         // Saving name, description
         $skill_id = $this->save($params);
         if ($skill_id) {
-            //Saving skill_rel_skill (parent_id, relation_type)
+            // Saving skill_rel_skill (parent_id, relation_type)
             foreach ($params['parent_id'] as $parent_id) {
                 $relation_exists = $skillRelSkill->relationExists($skill_id, $parent_id);
                 if (!$relation_exists) {
                     $attributes = [
                         'skill_id' => $skill_id,
                         'parent_id' => $parent_id,
-                        'relation_type' => (isset($params['relation_type']) ? $params['relation_type'] : 0),
+                        'relation_type' => isset($params['relation_type']) ? $params['relation_type'] : 0,
                         //'level'         => $params['level'],
                     ];
                     $skillRelSkill->save($attributes);
@@ -1261,7 +1265,7 @@ class Skill extends Model
     /**
      * Get user's skills.
      *
-     * @param int  $userId       User's id
+     * @param int  $userId
      * @param bool $getSkillData
      * @param int  $courseId
      * @param int  $sessionId
@@ -1770,8 +1774,6 @@ class Skill extends Model
                         $depth + 1,
                         $max_depth
                     );
-                } else {
-                    //$tmp['colour'] = $this->colours[$depth][rand(0,3)];
                 }
 
                 if ($depth > $max_depth) {
@@ -1803,8 +1805,9 @@ class Skill extends Model
      */
     public function getUserSkillRanking($user_id)
     {
-        $user_id = intval($user_id);
-        $sql = "SELECT count(skill_id) count FROM {$this->table} s
+        $user_id = (int) $user_id;
+        $sql = "SELECT count(skill_id) count 
+                FROM {$this->table} s
                 INNER JOIN {$this->table_skill_rel_user} su
                 ON (s.id = su.skill_id)
                 WHERE user_id = $user_id";
@@ -1834,8 +1837,9 @@ class Skill extends Model
         $sord,
         $where_condition
     ) {
-        $start = intval($start);
-        $limit = intval($limit);
+        $start = (int) $start;
+        $limit = (int) $limit;
+
         /*  ORDER BY $sidx $sord */
         $sql = "SELECT *, @rownum:=@rownum+1 rank FROM (
                     SELECT u.user_id, firstname, lastname, count(username) skills_acquired
@@ -1908,7 +1912,7 @@ class Skill extends Model
      */
     public function getCoursesBySkill($skillId)
     {
-        $skillId = intval($skillId);
+        $skillId = (int) $skillId;
         $sql = "SELECT c.title, c.code
                 FROM {$this->table_gradebook} g
                 INNER JOIN {$this->table_skill_rel_gradebook} sg
@@ -1934,12 +1938,12 @@ class Skill extends Model
      */
     public function userHasSkill($userId, $skillId, $courseId = 0, $sessionId = 0)
     {
-        $courseId = intval($courseId);
-        $sessionId = intval($sessionId);
+        $courseId = (int) $courseId;
+        $sessionId = (int) $sessionId;
 
         $whereConditions = [
-            'user_id = ? ' => intval($userId),
-            'AND skill_id = ? ' => intval($skillId),
+            'user_id = ? ' => (int) $userId,
+            'AND skill_id = ? ' => (int) $skillId,
         ];
 
         if ($courseId > 0) {
@@ -1974,7 +1978,7 @@ class Skill extends Model
      */
     public static function isSearched($id)
     {
-        $id = intval($id);
+        $id = (int) $id;
 
         if (empty($id)) {
             return false;
@@ -2013,7 +2017,7 @@ class Skill extends Model
      */
     public function listAchievedByCourse($courseId)
     {
-        $courseId = intval($courseId);
+        $courseId = (int) $courseId;
 
         if ($courseId == 0) {
             return [];
@@ -2060,7 +2064,7 @@ class Skill extends Model
      */
     public function listUsersWhoAchieved($skillId)
     {
-        $skillId = intval($skillId);
+        $skillId = (int) $skillId;
 
         if ($skillId == 0) {
             return [];
@@ -2105,7 +2109,7 @@ class Skill extends Model
      */
     public function getSessionsBySkill($skillId)
     {
-        $skillId = intval($skillId);
+        $skillId = (int) $skillId;
 
         $sql = "SELECT s.id, s.name
                 FROM {$this->table_gradebook} g
@@ -2233,8 +2237,8 @@ class Skill extends Model
     }
 
     /**
-     * @param $currentUserId
-     * @param $studentId
+     * @param int $currentUserId
+     * @param int $studentId
      *
      * @return bool
      */
@@ -2245,6 +2249,13 @@ class Skill extends Model
                 return true;
             }
 
+            $currentUserId = (int) $currentUserId;
+            $studentId = (int) $studentId;
+
+            if ($currentUserId === $studentId) {
+                return true;
+            }
+
             if (api_is_student_boss()) {
                 $isBoss = UserManager::userIsBossOfStudent($currentUserId, $studentId);
                 if ($isBoss) {
@@ -2283,6 +2294,8 @@ class Skill extends Model
      */
     public function getStudentSkills($userId, $level = 0)
     {
+        $userId = (int) $userId;
+
         $sql = "SELECT s.id, s.name, sru.acquired_skill_at
                 FROM {$this->table} s
                 INNER JOIN {$this->table_skill_rel_user} sru

+ 16 - 4
main/inc/lib/social.lib.php

@@ -1058,6 +1058,7 @@ class SocialManager extends UserManager
                         </a>
                     </li>';
                 $links .= $personalData;
+
                 $links .= '</ul>';
             }
 
@@ -1082,7 +1083,7 @@ class SocialManager extends UserManager
         if ($show === 'shared_profile') {
             $links = '<ul class="nav nav-pills nav-stacked">';
             // My own profile
-            if ($show_full_profile && $user_id == intval(api_get_user_id())) {
+            if ($show_full_profile && $user_id == api_get_user_id()) {
                 $links .= '
                     <li class="home-icon '.$active.'">
                         <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">
@@ -1150,6 +1151,18 @@ class SocialManager extends UserManager
                         </li>
                     ';
                 }
+
+                if (!api_get_configuration_value('disable_gdpr')) {
+                    $active = $show == 'personal-data' ? 'active' : null;
+                    $personalData = '
+                    <li class="personal-data-icon '.$active.'">
+                        <a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php">
+                            '.$personalDataIcon.' '.get_lang('PersonalDataReport').'
+                        </a>
+                    </li>';
+                    $links .= $personalData;
+                    $links .= '</ul>';
+                }
             }
 
             // My friend profile.
@@ -1215,7 +1228,7 @@ class SocialManager extends UserManager
                 'sn-sidebar-collapse'
             );
 
-            if ($show_full_profile && $user_id == intval(api_get_user_id())) {
+            if ($show_full_profile && $user_id == api_get_user_id()) {
                 $personal_course_list = UserManager::get_personal_session_course_list($user_id);
                 $course_list_code = [];
                 $i = 1;
@@ -1233,14 +1246,13 @@ class SocialManager extends UserManager
                 }
 
                 // Announcements
-                $my_announcement_by_user_id = intval($user_id);
                 $announcements = [];
                 foreach ($course_list_code as $course) {
                     $course_info = api_get_course_info($course['code']);
                     if (!empty($course_info)) {
                         $content = AnnouncementManager::get_all_annoucement_by_user_course(
                             $course_info['code'],
-                            $my_announcement_by_user_id
+                            $user_id
                         );
 
                         if (!empty($content)) {

+ 17 - 5
main/link/link.php

@@ -20,7 +20,6 @@
  */
 require_once __DIR__.'/../inc/global.inc.php';
 $current_course_tool = TOOL_LINK;
-
 $this_section = SECTION_COURSES;
 api_protect_course_script(true);
 
@@ -93,7 +92,7 @@ Event::event_access_tool(TOOL_LINK);
 $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
 $scope = isset($_REQUEST['scope']) ? $_REQUEST['scope'] : null;
 $show = isset($_REQUEST['show']) && in_array(trim($_REQUEST['show']), ['all', 'none']) ? $_REQUEST['show'] : '';
-$categoryId = isset($_REQUEST['category_id']) ? intval($_REQUEST['category_id']) : '';
+$categoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] : '';
 $linkListUrl = api_get_self().'?'.api_get_cidreq().'&category_id='.$categoryId.'&show='.$show;
 $content = '';
 $token = Security::get_existing_token();
@@ -212,11 +211,24 @@ switch ($action) {
         header('Location: '.$linkListUrl);
         exit;
         break;
+    case 'export':
+        $content = Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show, null, false);
+        $pdf = new PDF();
+        $pdf->content_to_pdf(
+            $content,
+            null,
+            $courseInfo['code'].get_lang('Link'),
+            $courseInfo['code'],
+            'D',
+            false,
+            null,
+            false,
+            true
+        );
+        break;
     case 'list':
     default:
-        ob_start();
-        Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show);
-        $content = ob_get_clean();
+        $content = Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show);
         break;
 }
 

+ 11 - 9
main/link/link_goto.php

@@ -19,15 +19,17 @@
 require_once __DIR__.'/../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 
-$linkId = intval($_GET['link_id']);
+$linkId = isset($_GET['link_id']) ? $_GET['link_id'] : 0;
 
 $linkInfo = Link::getLinkInfo($linkId);
-$linkUrl = html_entity_decode(Security::remove_XSS($linkInfo['url']));
-// Launch event
-Event::event_link($linkId);
+if ($linkInfo) {
+    $linkUrl = html_entity_decode(Security::remove_XSS($linkInfo['url']));
+    // Launch event
+    Event::event_link($linkId);
 
-header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
-header("Cache-Control: post-check=0, pre-check=0", false);
-header("Pragma: no-cache"); // HTTP/1.0
-header("Location: $linkUrl");
-exit;
+    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
+    header("Cache-Control: post-check=0, pre-check=0", false);
+    header("Pragma: no-cache"); // HTTP/1.0
+    header("Location: $linkUrl");
+    exit;
+}