From 0714f0c5656ee92cfec3960717cb961ac02fac37 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 12 Dec 2011 16:23:33 +0100 Subject: [PATCH] Should fix bug when editing a link from the course home page see #4135 --- main/inc/lib/link.lib.php | 24 +++++++++++++++++++++++- main/link/link.php | 26 +++++++++++++++++++------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php index 2b8aeff22a..ae4a4666a6 100644 --- a/main/inc/lib/link.lib.php +++ b/main/inc/lib/link.lib.php @@ -271,7 +271,29 @@ function delete_link_from_search_engine($course_id, $link_id) { } } + +/** + * + * Get link info + * @param int link id + * @return array link info + * + * */ + +function get_link_info($id) { + $tbl_link = Database :: get_course_table(TABLE_LINK); + $course_id = api_get_course_int_id(); + $sql = "SELECT * FROM " . $tbl_link . " WHERE c_id = $course_id AND id='" . intval($id) . "' "; + $result = Database::query($sql); + + if (Database::num_rows($result)) { + $data = Database::fetch_array($result); + } + return $data; +} + /** + * Used to edit a link or a category * @todo Rewrite the whole links tool because it is becoming completely cluttered, * code does not follow the coding conventions, does not use html_quickform, ... @@ -298,7 +320,7 @@ function editlinkcategory($type) { global $onhomepage; global $target_link; - $tbl_link = Database :: get_course_table(TABLE_LINK); + $tbl_link = Database :: get_course_table(TABLE_LINK); $tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY); $course_id = api_get_course_int_id(); diff --git a/main/link/link.php b/main/link/link.php index 607df12306..99c6e3456c 100644 --- a/main/link/link.php +++ b/main/link/link.php @@ -120,7 +120,7 @@ function MM_popupMsg(msg) { //v1.0 $nameTools = get_lang('Links'); if (isset($_GET['action'])) { - $check_token = Security::check_token('request'); + $check_token = Security::check_token('request'); if ($check_token) { switch ($_GET['action']) { case 'addlink': @@ -146,9 +146,9 @@ if (isset($_GET['action'])) { deletelinkcategory('link'); // Here we delete a link break; case 'deletecategory': - deletelinkcategory('category'); // Here we delete a category + deletelinkcategory('category'); // Here we delete a category break; - case 'editlink': + case 'editlink': editlinkcategory('link'); // Here we edit a link break; case 'editcategory': @@ -196,13 +196,25 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) { echo ''; if ($category == '') { $category = 0; - } + } echo '
'; echo ''; if ($_GET['action'] == 'editlink') { - echo ''; - - $clean_link_id = trim(Security::remove_XSS($_GET['id'])); + $clean_link_id = intval($_GET['id']); + $link_info = get_link_info($_GET['id']); + if ($link_info) { + $urllink = $link_info['url']; + $title = $link_info['title']; + $description = $link_info['description']; + $category = $link_info['category_id']; + $onhomepage = ''; + if ($link_info['on_homepage'] != 0) { + $onhomepage = 'checked'; + } + $target_link = $link_info['target']; + } + + echo ''; } echo '