diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php index 5d7f470954..9ba6bc1ac4 100755 --- a/main/inc/lib/link.lib.php +++ b/main/inc/lib/link.lib.php @@ -235,6 +235,11 @@ function addlinkcategory($type) VALUES (".$course_id.", '" .Database::escape_string($category_title) . "', '" . Database::escape_string($description) . "', '$order', '$session_id')"; Database :: query($sql); + $link_id = Database :: insert_id(); + if ($link_id) { + api_set_default_visibility($link_id, TOOL_LINK_CATEGORY); // add link_category + } + $catlinkstatus = get_lang('CategoryAdded'); unset ($category_title, $description); Display :: display_confirmation_message(get_lang('CategoryAdded')); @@ -607,6 +612,34 @@ function change_visibility($id, $scope) { } } +/** + * Generate SQL for select all the category of link + * + */ +function getSqlFromLinkCategory() +{ + $tbl_linkCategory = Database :: get_course_table(TABLE_LINK_CATEGORY); + $tbl_itemProperty = Database :: get_course_table(TABLE_ITEM_PROPERTY); + + // Condition for the session. + $session_id = api_get_session_id(); + $condition_session = api_get_session_condition($session_id, true, true); + + $course_id = api_get_course_int_id(); + + $sql = "SELECT *, linkcat.id FROM " . $tbl_linkCategory . " linkcat, " . $tbl_itemProperty . " itemproperties + WHERE itemproperties.tool = '" . TOOL_LINK_CATEGORY . "' AND + linkcat.id = itemproperties.ref AND + + (itemproperties.visibility = '0' OR itemproperties.visibility = '1') + $condition_session AND + linkcat.c_id = ".$course_id." AND + itemproperties.c_id = ".$course_id." + ORDER BY linkcat.display_order DESC"; + return $sql; + +} + /** * Displays all the links of a given category. * @author Patrick Cool , Ghent University diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 77582de8ba..a652cfe73d 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -81,6 +81,7 @@ define('TOOL_THUMBNAIL', 'thumbnail'); define('TOOL_HOTPOTATOES', 'hotpotatoes'); define('TOOL_CALENDAR_EVENT', 'calendar_event'); define('TOOL_LINK', 'link'); +define('TOOL_LINK_CATEGORY', 'link_category'); define('TOOL_COURSE_DESCRIPTION', 'course_description'); define('TOOL_SEARCH', 'search'); define('TOOL_LEARNPATH', 'learnpath'); @@ -6562,6 +6563,7 @@ function api_set_default_visibility($item_id, $tool_id, $group_id = null) { switch ($tool_id) { case TOOL_LINK: + case TOOL_LINK_CATEGORY: $tool_id = 'links'; break; case TOOL_DOCUMENT: diff --git a/main/link/link.php b/main/link/link.php index 621601e98d..9d91abbb58 100755 --- a/main/link/link.php +++ b/main/link/link.php @@ -255,7 +255,7 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) { '; - $sqlcategories = "SELECT * FROM ".$tbl_categories." WHERE c_id = $course_id $condition_session ORDER BY display_order DESC"; + $sqlcategories = getSqlFromLinkCategory(); echo $sqlcategories; exit; $resultcategories = Database::query($sqlcategories); if (Database::num_rows($resultcategories)) { @@ -421,7 +421,7 @@ if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action'] } // Making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the // number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories). - $sqlcategories = "SELECT * FROM ".$tbl_categories." WHERE c_id = $course_id $condition_session ORDER BY display_order DESC"; + $sqlcategories = getSqlFromLinkCategory(); $resultcategories = Database::query($sqlcategories); $aantalcategories = Database::num_rows($resultcategories); if ($aantalcategories > 0) {