diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php index b87d4b550c..1bae3a5c0d 100755 --- a/main/inc/lib/link.lib.php +++ b/main/inc/lib/link.lib.php @@ -964,20 +964,21 @@ class Link extends Model /** * Displays all the links of a given category. * - * @author Patrick Cool , 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 , 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 = ''; @@ -1137,7 +1138,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 .= '
'; - $content .= '
'.$toolbar.'
'; + if ($showActionLinks) { + $content .= '
'.$toolbar.'
'; + } $content .= '

'; $content .= $iconLink; $content .= Display::tag( @@ -1558,42 +1561,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 ) { $categoryId = (int) $categoryId; - /* Action Links */ - echo '
'; - if (api_is_allowed_to_edit(null, true)) { - echo ''. - Display::return_icon('new_link.png', get_lang('LinkAdd'), '', ICON_SIZE_MEDIUM).''; - echo ''. - Display::return_icon('new_folder.png', get_lang('CategoryAdd'), '', ICON_SIZE_MEDIUM).''; - } + $content = ''; $categories = self::getLinkCategories($course_id, $session_id); $countCategories = count($categories); - if (!empty($countCategories)) { - echo ''; - echo Display::return_icon('forum_listview.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).' '; + $linksPerCategory = self::showLinksPerCategory(0, $course_id, $session_id, $showActionLinks); + + if ($showActionLinks) { + /* Action Links */ + $content = '
'; + if (api_is_allowed_to_edit(null, true)) { + $content .= ''. + Display::return_icon('new_link.png', get_lang('LinkAdd'), '', ICON_SIZE_MEDIUM).''; + $content .= ''. + Display::return_icon('new_folder.png', get_lang('CategoryAdd'), '', ICON_SIZE_MEDIUM).''; + } - echo ''; - echo Display::return_icon('forum_nestedview.png', get_lang('NestedView'), '', ICON_SIZE_MEDIUM).''; + if (!empty($countCategories)) { + $content .= ''; + $content .= Display::return_icon( + 'forum_listview.png', + get_lang('FlatView'), + '', + ICON_SIZE_MEDIUM + ).' '; + + $content .= ''; + $content .= Display::return_icon( + 'forum_nestedview.png', + get_lang('NestedView'), + '', + ICON_SIZE_MEDIUM + ).''; + } + + $content .= Display::url( + Display::return_icon('pdf.png', get_lang('ExportToPdf'), '', ICON_SIZE_MEDIUM), + api_get_self().'?'.api_get_cidreq().'&action=export' + ); + $content .= '
'; } - echo '
'; - $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')); } } @@ -1629,16 +1658,16 @@ class Link extends Model $header .= ''; $header .= Display::return_icon('forum_listview.png'); } - $header .= Security::remove_XSS($myrow['category_title']).''; - $header .= '
'; - 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'); + } } } @@ -1651,10 +1680,12 @@ class Link extends Model ); } - echo Display::panel($myrow['description'].$childrenContent, $header); + $content .= Display::panel($myrow['description'].$childrenContent, $header); $counter++; } + + return $content; } /** diff --git a/main/link/link.php b/main/link/link.php index 3f33c5e335..9a2684769f 100755 --- a/main/link/link.php +++ b/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; }