diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php
index 97b9f74e9c..424beba727 100755
--- a/main/inc/lib/link.lib.php
+++ b/main/inc/lib/link.lib.php
@@ -88,6 +88,7 @@ class Link extends Model
$params['display_order'] = $order;
$id = parent::save($params, $show_query);
+
if (!empty($id)) {
// iid
$sql = "UPDATE ".$this->table." SET id = iid WHERE iid = $id";
@@ -161,21 +162,21 @@ class Link extends Model
$session_id = api_get_session_id();
if ($type == 'link') {
- $title = Security:: remove_XSS(stripslashes($_POST['title']));
- $urllink = Security:: remove_XSS($_POST['url']);
- $description = Security:: remove_XSS($_POST['description']);
- $selectcategory = Security:: remove_XSS($_POST['category_id']);
+ $title = Security::remove_XSS(stripslashes($_POST['title']));
+ $urllink = Security::remove_XSS($_POST['url']);
+ $description = Security::remove_XSS($_POST['description']);
+ $selectcategory = Security::remove_XSS($_POST['category_id']);
if (!isset($_POST['on_homepage'])) {
$onhomepage = 0;
} else {
- $onhomepage = Security:: remove_XSS($_POST['on_homepage']);
+ $onhomepage = Security::remove_XSS($_POST['on_homepage']);
}
if (empty($_POST['target'])) {
$target = '_self'; // Default target.
} else {
- $target = Security:: remove_XSS($_POST['target']);
+ $target = Security::remove_XSS($_POST['target']);
}
$urllink = trim($urllink);
@@ -219,15 +220,9 @@ class Link extends Model
if ((api_get_setting('search_enabled') == 'true') &&
$link_id && extension_loaded('xapian')
) {
- require_once api_get_path(
- LIBRARY_PATH
- ) . 'search/ChamiloIndexer.class.php';
- require_once api_get_path(
- LIBRARY_PATH
- ) . 'search/IndexableChunk.class.php';
- require_once api_get_path(
- LIBRARY_PATH
- ) . 'specific_fields_manager.lib.php';
+ require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
+ require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php';
+ require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$course_int_id = $_course['real_id'];
$courseCode = $_course['code'];
@@ -270,7 +265,6 @@ class Link extends Model
'link_id' => (int)$link_id
),
SE_USER => (int)api_get_user_id(),
-
);
$ic_slide->xapian_data = serialize($xapian_data);
$description = $all_specific_terms . ' ' . $description;
@@ -575,7 +569,8 @@ class Link extends Model
$link_title = Database:: escape_string($values['title']);
$link_description = Database:: escape_string($values['description']);
- // Actually, it consists on delete terms from db, insert new ones, create a new search engine document, and remove the old one.
+ // Actually, it consists on delete terms from db,
+ // insert new ones, create a new search engine document, and remove the old one.
// Get search_did.
$tbl_se_ref = Database:: get_main_table(
TABLE_MAIN_SEARCH_ENGINE_REF
@@ -867,33 +862,35 @@ class Link extends Model
*/
public static function showlinksofcategory($catid)
{
- global $urlview, $up, $down, $_user, $token;
+ global $token;
+ $_user = api_get_user_info();
+ $course_id = api_get_course_int_id();
+ $session_id = api_get_session_id();
+ $catid = intval($catid);
$tbl_link = Database:: get_course_table(TABLE_LINK);
$TABLE_ITEM_PROPERTY = 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, 'link.session_id');
- $catid = intval($catid);
- $course_id = api_get_course_int_id();
+ $content = '';
- $sqlLinks = "SELECT *, link.id FROM $tbl_link link
- INNER JOIN $TABLE_ITEM_PROPERTY itemproperties
- ON (link.id=itemproperties.ref AND link.c_id = itemproperties.c_id )
- WHERE
- itemproperties.tool='" . TOOL_LINK . "' AND
- link.category_id='" . $catid . "' AND
- (itemproperties.visibility='0' OR itemproperties.visibility='1')
- $condition_session AND
- link.c_id = " . $course_id . " AND
- itemproperties.c_id = " . $course_id . "
- ORDER BY link.display_order DESC";
- $result = Database:: query($sqlLinks);
+ $sql = "SELECT *, link.id FROM $tbl_link link
+ INNER JOIN $TABLE_ITEM_PROPERTY itemproperties
+ ON (link.id=itemproperties.ref AND link.c_id = itemproperties.c_id )
+ WHERE
+ itemproperties.tool='" . TOOL_LINK . "' AND
+ link.category_id='" . $catid . "' AND
+ (itemproperties.visibility='0' OR itemproperties.visibility='1')
+ $condition_session AND
+ link.c_id = " . $course_id . " AND
+ itemproperties.c_id = " . $course_id . "
+ ORDER BY link.display_order DESC";
+ $result = Database:: query($sql);
$numberoflinks = Database:: num_rows($result);
if ($numberoflinks > 0) {
- echo '
';
+ $content .= '';
+ $content .= '
';
}
+
+ return $content;
}
/**
@@ -1056,7 +1043,7 @@ class Link extends Model
{
$categoryId = $category['id'];
$token = null;
- echo '' .
+ $tools = '' .
Display:: return_icon(
'edit.png',
get_lang('Modify'),
@@ -1066,7 +1053,7 @@ class Link extends Model
// DISPLAY MOVE UP COMMAND only if it is not the top link.
if ($currentCategory != 0) {
- echo '' .
+ $tools .= ''.
Display:: return_icon(
'up.png',
get_lang('Up'),
@@ -1074,7 +1061,7 @@ class Link extends Model
ICON_SIZE_SMALL
) . '';
} else {
- echo Display:: return_icon(
+ $tools .= Display:: return_icon(
'up_na.png',
get_lang('Up'),
array(),
@@ -1084,11 +1071,7 @@ class Link extends Model
// DISPLAY MOVE DOWN COMMAND only if it is not the bottom link.
if ($currentCategory < $countCategories-1) {
- echo '
- ' .
+ $tools .= ''.
Display:: return_icon(
'down.png',
get_lang('Down'),
@@ -1096,7 +1079,7 @@ class Link extends Model
ICON_SIZE_SMALL
) . '';
} else {
- echo Display:: return_icon(
+ $tools .= Display:: return_icon(
'down_na.png',
get_lang('Down'),
array(),
@@ -1104,17 +1087,16 @@ class Link extends Model
) . '';
}
- echo '",
+ $tools .= '".
Display:: return_icon(
'delete.png',
get_lang('Delete'),
array(),
ICON_SIZE_SMALL
) . '';
+
+ return $tools;
}
/**
@@ -1508,6 +1490,13 @@ class Link extends Model
}
}
+ /**
+ * @param int $course_id
+ * @param int $session_id
+ * @param int $categoryId
+ * @param string $show
+ * @param null $token
+ */
public static function listLinksAndCategories($course_id, $session_id, $categoryId, $show = 'none', $token = null)
{
$tbl_link = Database::get_course_table(TABLE_LINK);
@@ -1538,21 +1527,14 @@ class Link extends Model
// Displaying the links which have no category (thus category = 0 or NULL),
// if none present this will not be displayed
$sql = "SELECT * FROM $tbl_link
- WHERE c_id = $course_id AND category_id=0 OR category_id IS NULL";
+ WHERE c_id = $course_id AND (category_id=0 OR category_id IS NULL)";
$result = Database::query($sql);
$count = Database::num_rows($result);
if ($count !== 0) {
- echo '';
- echo '
'.get_lang('General').'
';
- echo '
';
- self::showlinksofcategory(0);
- echo '
';
- echo '
';
+ echo Display::panel(Link::showlinksofcategory(0), get_lang('General'));
}
- $i = 0;
- $view = '0';
$counter = 0;
foreach ($categories as $myrow) {
// Student don't see invisible categories.
@@ -1578,136 +1560,36 @@ class Link extends Model
Display :: return_icon('invisible.png', get_lang('Show'), array (), ICON_SIZE_SMALL) . '';
}
-
-
-
- echo '';
- echo '
';
-
- $counter++;
- /*
- if ($myrow['visibility'] == '1') {
- if (isset($urlview[$i]) && $urlview[$i] == '1') {
- $newurlview = $urlview;
- $newurlview[$i] = '0';
- echo '
';
- echo '
'.Security::remove_XSS($myrow['category_title']).'
-
'.$myrow['description'];
- echo '';
- if (api_is_allowed_to_edit(null, true)) {
- if ($session_id == $myrow['session_id']) {
- echo '
';
- echo $strVisibility;
- Link::showcategoryadmintools($myrow['id']);
- echo ' | ';
- } else {
- echo '
'.get_lang('EditionNotAvailableFromSession');
- }
- }
- echo '';
- echo '';
- echo Link::showlinksofcategory($myrow['id']);
- echo '';
- } else {
- echo ' '.
- Security::remove_XSS($myrow['category_title']).$session_img;
- echo' ';
- echo $myrow['description'];
-
- if (api_is_allowed_to_edit(null, true)) {
- if ($session_id == $myrow['session_id']) {
- echo ' | ';
- echo $strVisibility;
- Link::showcategoryadmintools($myrow['id']);
- echo ' | ';
- }
- }
- echo '';
- echo '';
- echo '';
- echo '';
- }
- } else {
- // NO VISIBLE
- if (api_is_allowed_to_edit(null, true)) {
- if (isset($urlview[$i]) && $urlview[$i] == '1') {
- $newurlview = $urlview;
- $newurlview[$i] = '0';
- echo '
';
- echo '
'.Security::remove_XSS($myrow['category_title']).' '.$myrow['description'];
- echo '';
- if (api_is_allowed_to_edit(null, true)) {
- if ($session_id == $myrow['session_id']) {
- echo '
'; echo $strVisibility; Link::showcategoryadmintools($myrow['id']); echo ' | ';
- } else {
- echo '
'.get_lang('EditionNotAvailableFromSession');
- }
- }
- echo '';
- echo '';
- echo Link::showlinksofcategory($myrow['id']);
- echo '';
- } else {
- echo ' '.Security::remove_XSS($myrow['category_title']).$session_img;
- echo' ';
- echo $myrow['description'];
-
- if (api_is_allowed_to_edit(null, true)) {
- if ($session_id == $myrow['session_id']) {
- echo ' | ';
- echo $strVisibility;
- Link::showcategoryadmintools($myrow['id']);
- echo ' | ';
- }
- }
+ echo Display::panel($myrow['description'].$childrenContent, $header);
- echo '';
- echo '';
- echo '';
- echo '';
- }
- }*/
- //}
- // Displaying the link of the category
+ $counter++;
}
-
}
/**
@@ -1725,7 +1607,6 @@ class Link extends Model
$categoryId = isset($linkInfo['category_id']) ? $linkInfo['category_id'] : '';
$lpId = isset($_GET['lp_id']) ? Security::remove_XSS($_GET['lp_id']) : null;
- $category = 0;
$form = new FormValidator(
'link',
'post',