Browse Source

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

Yannick Warnier 8 years ago
parent
commit
8e738109e0
3 changed files with 138 additions and 54 deletions
  1. 28 4
      main/gradebook/index.php
  2. 16 0
      main/inc/lib/api.lib.php
  3. 94 50
      main/inc/lib/link.lib.php

+ 28 - 4
main/gradebook/index.php

@@ -801,11 +801,19 @@ if (!api_is_allowed_to_edit(null, true)) {
     );
 }
 
-echo $toolbar = Display::toolbarAction('gradebook-student-actions', array($actionsLeft));
+if (!empty($actionsLeft)) {
+    echo $toolbar = Display::toolbarAction(
+        'gradebook-student-actions',
+        array($actionsLeft)
+    );
+}
 
 if (api_is_allowed_to_edit(null, true)) {
     // Tool introduction
-    Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
+    Display::display_introduction_section(
+        TOOL_GRADEBOOK,
+        array('ToolbarSet' => 'AssessmentsIntroduction')
+    );
 
     if (((empty($selectCat)) || (isset($_GET['cidReq']) && $_GET['cidReq'] !== '')) ||
         (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false')
@@ -825,7 +833,15 @@ if (api_is_allowed_to_edit(null, true)) {
 if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null,true)) {
     echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?'.api_get_cidreq().'" />';
 } else {
-    $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
+    $cats = Category::load(
+        null,
+        null,
+        $course_code,
+        null,
+        null,
+        $session_id,
+        false
+    );
 
     if (!empty($cats)) {
         if ((api_get_setting('gradebook_enable_grade_model') === 'true') &&
@@ -874,7 +890,15 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null,true))
                             $gradebook->save($params);
                         }
                         // Reloading cats
-                        $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
+                        $cats = Category:: load(
+                            null,
+                            null,
+                            $course_code,
+                            null,
+                            null,
+                            $session_id,
+                            false
+                        );
                     } else {
                         $form_grade->display();
                     }

+ 16 - 0
main/inc/lib/api.lib.php

@@ -8095,3 +8095,19 @@ function api_number_format($number, $decimals = 0)
 
     return number_format($number, $decimals);
 }
+
+/**
+ * Set location url with a exit break by default
+ *
+ * @param $url
+ * @param bool $exit
+ * @return void
+ */
+function location($url, $exit = true)
+{
+    header('Location: ' . $url);
+
+    if ($exit) {
+        exit;
+    }
+}

+ 94 - 50
main/inc/lib/link.lib.php

@@ -765,7 +765,6 @@ class Link extends Model
                 $_user['user_id']
             );
             Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
-
         } elseif ($scope == TOOL_LINK_CATEGORY) {
             api_item_property_update(
                 $_course,
@@ -805,7 +804,7 @@ class Link extends Model
         $sql = "SELECT *, linkcat.id
                 FROM $tblLinkCategory linkcat
                 WHERE
-                    linkcat.c_id = " . $courseId . "
+                    linkcat.c_id = $courseId
                     $sessionCondition
                 ORDER BY linkcat.display_order DESC";
 
@@ -862,8 +861,12 @@ class Link extends Model
      *
      * @return array
      */
-    public static function getLinksPerCategory($categoryId, $courseId, $sessionId, $withBaseContent = true)
-    {
+    public static function getLinksPerCategory(
+        $categoryId,
+        $courseId,
+        $sessionId,
+        $withBaseContent = true
+    ) {
         $tbl_link = Database:: get_course_table(TABLE_LINK);
         $TABLE_ITEM_PROPERTY = Database:: get_course_table(TABLE_ITEM_PROPERTY);
         $courseId = (int) $courseId;
@@ -874,22 +877,58 @@ class Link extends Model
         $condition_session = api_get_session_condition(
             $sessionId,
             true,
-            $withBaseContent,
-            'link.session_id'
+            false,
+            'ip.session_id'
         );
 
-        $sql = "SELECT *, link.id 
+        if (!empty($sessionId)) {
+            $conditionBaseSession = api_get_session_condition(
+                0,
+                true,
+                $withBaseContent,
+                'ip.session_id'
+            );
+            $condition = " AND 
+                (
+                    (ip.visibility = '1' $conditionBaseSession) OR
+                     
+                    (
+                        (ip.visibility = '0' OR ip.visibility = '1')
+                        $condition_session
+                    )
+                )
+            ";
+        } else {
+            $condition = api_get_session_condition(
+                0,
+                true,
+                false,
+                'ip.session_id'
+            );
+            $condition .=  " AND (ip.visibility = '0' OR ip.visibility = '1') $condition " ;
+        }
+
+        $sql = "SELECT 
+                    link.id,
+                    ip.session_id,
+                    link.session_id link_session_id,
+                    url,
+                    category_id,
+                    visibility,
+                    description,
+                    title,
+                    target,
+                    on_homepage
                 FROM $tbl_link link
                 INNER JOIN $TABLE_ITEM_PROPERTY ip
                 ON (link.id = ip.ref AND link.c_id = ip.c_id)
                 WHERE
                     ip.tool = '" . TOOL_LINK . "' AND
                     link.category_id = '" . $categoryId . "' AND
-                    (ip.visibility = '0' OR ip.visibility = '1')
-                    $condition_session AND
                     link.c_id = $courseId AND
-                    ip.c_id = $courseId 
-                ORDER BY link.display_order ASC";
+                    ip.c_id = $courseId
+                    $condition
+                ORDER BY link.display_order ASC, ip.session_id DESC";
 
         $result = Database:: query($sql);
 
@@ -914,15 +953,25 @@ class Link extends Model
 
         $links = self::getLinksPerCategory($catid, $courseId, $session_id);
         $content = '';
-        $numberoflinks = count($links);
+        $numberOfLinks = count($links);
 
         if (!empty($links)) {
             $content .= '<div class="link list-group">';
             $i = 1;
+            $linksAdded = [];
             foreach ($links as $myrow) {
+                $linkId = $myrow['id'];
+
+                if (in_array($linkId, $linksAdded)) {
+                    continue;
+                }
+
+                $linksAdded[] = $linkId;
+                $categoryId = $myrow['category_id'];
+
                 // Validation when belongs to a session.
                 $session_img = api_get_session_image(
-                    $myrow['session_id'],
+                    $myrow['link_session_id'],
                     $_user['status']
                 );
 
@@ -935,22 +984,21 @@ class Link extends Model
                         'check-circle-o',
                         'default btn-sm',
                         array(
-                            'onclick' => "check_url('" . $myrow['id'] . "', '" . addslashes($myrow['url']) . "');",
+                            'onclick' => "check_url('" . $linkId . "', '" . addslashes($myrow['url']) . "');",
                             'title' => get_lang('CheckURL')
                         )
                     );
+
                     $link_validator .= Display::span(
                         '',
                         array(
-                        'id' => 'url_id_' . $myrow['id'],
+                        'id' => 'url_id_' . $linkId,
                         'class' => 'check-link'
                         )
                     );
 
-                    if ($session_id == $myrow['session_id']) {
-                        $url = api_get_self().'?' .api_get_cidreq().'&action=editlink&category=' .(!empty ($category) ? $category : '').
-                            '&id=' . $myrow['id'] .
-                            '&category_id=' . $myrow['id'];
+                    if ($session_id == $myrow['link_session_id']) {
+                        $url = api_get_self().'?'.api_get_cidreq().'&action=editlink&id='.$linkId;
                         $title = get_lang('Edit');
                         $toolbar .= Display::toolbarButton(
                             '',
@@ -961,48 +1009,53 @@ class Link extends Model
                                 'title' => $title
                             )
                         );
+                    }
+
+                    $urlVisibility = api_get_self().'?'.api_get_cidreq() .
+                            '&sec_token=' . $token .
+                            '&id=' . $linkId .
+                            '&scope=link&category_id=' . $categoryId;
 
-                        if ($myrow['visibility'] == '1') {
-                            $url .= 'link.php?' . api_get_cidreq() .
-                                '&sec_token=' . $token .
-                                '&action=invisible&id=' . $myrow['id'] .
-                                '&scope=link&category_id=' . $myrow['category_id'];
+                    switch ($myrow['visibility']) {
+                        case '1':
+                            $urlVisibility .= '&action=invisible';
                             $title = get_lang('MakeInvisible');
                             $toolbar .= Display::toolbarButton(
                                 '',
-                                $url,
+                                $urlVisibility,
                                 'eye',
                                 'default btn-sm',
                                 array(
                                     'title' => $title
                                 )
                             );
-                        }
-
-                        if ($myrow['visibility'] == '0') {
-                            $url .= 'link.php?' . api_get_cidreq() .'&sec_token=' . $token .'&action=visible&id=' . $myrow['id'] .'&scope=link&category_id=' . $myrow['category_id'];
+                            break;
+                        case '0':
+                            $urlVisibility .= '&action=visible';
                             $title = get_lang('MakeVisible');
                             $toolbar .= Display::toolbarButton(
                                 '',
-                                $url,
+                                $urlVisibility,
                                 'eye-slash',
                                 'primary btn-sm',
                                 array(
                                     'title' => $title
                                 )
                             );
-                        }
+                            break;
+                    }
 
+                    if ($session_id == $myrow['link_session_id']) {
                         $moveLinkParams = [
-                            'id' => $myrow['id'],
+                            'id' => $linkId,
                             'scope' => 'category',
-                            'category_id' => $myrow['category_id'],
+                            'category_id' => $categoryId,
                             'action' => 'move_link_up'
                         ];
 
                         $toolbar .= Display::toolbarButton(
                             get_lang('MoveUp'),
-                            'link.php?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams),
+                            api_get_self() . '?'.api_get_cidreq() . '&' . http_build_query($moveLinkParams),
                             'level-up',
                             'default',
                             ['class' => 'btn-sm ' . ($i === 1 ? 'disabled' : '')],
@@ -1012,14 +1065,14 @@ class Link extends Model
                         $moveLinkParams['action'] = 'move_link_down';
                         $toolbar .= Display::toolbarButton(
                             get_lang('MoveDown'),
-                            'link.php?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams),
+                            api_get_self().'?' . api_get_cidreq() . '&' . http_build_query($moveLinkParams),
                             'level-down',
                             'default',
-                            ['class' => 'btn-sm ' . ($i === $numberoflinks ? 'disabled' : '')],
+                            ['class' => 'btn-sm ' . ($i === $numberOfLinks ? 'disabled' : '')],
                             false
                         );
 
-                        $url .= api_get_self() . '?' . api_get_cidreq() .'&sec_token=' . $token .'&action=deletelink&id=' . $myrow['id'] .'&category_id=' . $myrow['category_id'];
+                        $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');
 
@@ -1033,19 +1086,9 @@ class Link extends Model
                                 'title' => $title
                             )
                         );
-                    } else {
-                        $title = get_lang('EditionNotAvailableFromSession');
-                        $toolbar .= Display::toolbarButton(
-                            '',
-                            '#',
-                            'trash-o',
-                            'default btn-sm',
-                            array(
-                                'title' => $title
-                            )
-                        );
                     }
                 }
+
                 $iconLink = Display::return_icon(
                     'url.png',
                     get_lang('Link'),
@@ -1058,7 +1101,7 @@ class Link extends Model
                     $content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
                     $content .= '<h4 class="list-group-item-heading">';
                     $content .= $iconLink;
-                    $url =  'link_goto.php?' . api_get_cidreq() .'&link_id=' . $myrow['id'] .'&link_url=' . urlencode($myrow['url']);
+                    $url = api_get_path(WEB_CODE_PATH).'link/link_goto.php?' . api_get_cidreq() .'&link_id=' . $linkId .'&link_url=' . urlencode($myrow['url']);
                     $content .= Display::tag(
                         'a',
                         Security:: remove_XSS($myrow['title']),
@@ -1079,7 +1122,7 @@ class Link extends Model
                         $content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
                         $content .= '<h4 class="list-group-item-heading">';
                         $content .= $iconLink;
-                        $url = 'link_goto.php?' . api_get_cidreq() .'&link_id=' . $myrow['id'] . "&link_url=" . urlencode($myrow['url']);
+                        $url = api_get_path(WEB_CODE_PATH).'link/link_goto.php?' . api_get_cidreq() .'&link_id=' . $linkId . "&link_url=" . urlencode($myrow['url']);
                         $content .= Display::tag(
                             'a',
                             Security:: remove_XSS($myrow['title']),
@@ -1609,6 +1652,7 @@ class Link extends Model
 
             $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;