Fix function naming, use of non-uppercase new variables, better filtering in api_item_property_update() and use non-global variables in function call - refs #7249

1.9.x
Yannick Warnier 10 years ago
parent b1f62cb6d2
commit 42c7fb6590
  1. 53
      main/inc/lib/link.lib.php
  2. 8
      main/inc/lib/main_api.lib.php
  3. 10
      main/link/link.php

@ -235,9 +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
$linkId = Database :: insert_id();
if ($linkId) {
// add link_category visibility
// course ID is taken from context in api_set_default_visibility
api_set_default_visibility($linkId, TOOL_LINK_CATEGORY);
}
$catlinkstatus = get_lang('CategoryAdded');
@ -264,7 +266,7 @@ function deletelinkcategory($type)
{
global $catlinkstatus;
global $_course;
$session_id = api_get_session_id();
$session_id = api_get_session_id();
$tbl_link = Database :: get_course_table(TABLE_LINK);
$tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
$TABLE_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@ -296,11 +298,7 @@ function deletelinkcategory($type)
$catlinkstatus = get_lang('CategoryDeleted');
unset ($id);
Database :: query($sql);
// Delete relation link_category : item_property : link_category not exist delete Logic.
$sqlP = "DELETE FROM $TABLE_ITEM_PROPERTY WHERE c_id = $course_id AND tool = '". TOOL_LINK_CATEGORY ."' "
. "AND ref = '" . intval($_GET['id']) . "' AND id_session = '$session_id' ";
Database :: query($sqlP);
api_item_property_update($_course, TOOL_LINK_CATEGORY, $_GET['id'], 'delete', api_get_user_id());
Display :: display_confirmation_message(get_lang('CategoryDeleted'));
}
}
@ -612,41 +610,38 @@ function makedefaultviewcode($locatie) {
*/
function change_visibility($id, $scope) {
global $_course, $_user;
if ($scope == 'link') {
if ($scope == TOOL_LINK) {
api_item_property_update($_course, TOOL_LINK, $id, $_GET['action'], $_user['user_id']);
Display :: display_confirmation_message(get_lang('VisibilityChanged'));
} elseif ($scope == TOOL_LINK_CATEGORY) {
api_item_property_update($_course, TOOL_LINK_CATEGORY, $id, $_GET['action'], $_user['user_id']);
Display :: display_confirmation_message(get_lang('VisibilityChanged'));
}
api_item_property_update($_course, TOOL_LINK_CATEGORY, $id, $_GET['action'], $_user['user_id']);
Display :: display_confirmation_message(get_lang('VisibilityChanged'));
}
}
/**
* Generate SQL for select all the category of link
*
* Generate SQL to select all the links categories in the current course and
* session
* @return string SQL query (to be executed)
*/
function getSqlFromLinkCategory()
function getLinkCategories($courseId, $sessionId)
{
$tbl_linkCategory = Database :: get_course_table(TABLE_LINK_CATEGORY);
$tbl_itemProperty = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$tblLinkCategory = Database :: get_course_table(TABLE_LINK_CATEGORY);
$tblItemProperty = 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();
$sessionCondition = api_get_session_condition($sessionId, true, true);
$sql = "SELECT *, linkcat.id FROM " . $tbl_linkCategory . " linkcat, " . $tbl_itemProperty . " itemproperties
$sql = "SELECT *, linkcat.id FROM $tblLinkCategory linkcat,
$tblItemProperty 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."
$sessionCondition AND
linkcat.c_id = ".$courseId." AND
itemproperties.c_id = ".$courseId."
ORDER BY linkcat.display_order DESC";
return $sql;
return Database::query($sql);
}
/**

@ -3374,11 +3374,11 @@ function api_item_property_update(
// Definition of variables.
$tool = Database::escape_string($tool);
$item_id = Database::escape_string($item_id);
$item_id = intval($item_id);
$lastedit_type = Database::escape_string($lastedit_type);
$user_id = Database::escape_string($user_id);
$to_group_id = Database::escape_string($to_group_id);
$to_user_id = Database::escape_string($to_user_id);
$user_id = intval($user_id);
$to_group_id = intval($to_group_id);
$to_user_id = intval($to_user_id);
$start_visible = Database::escape_string($start_visible);
$end_visible = Database::escape_string($end_visible);
$start_visible = ($start_visible == 0) ? '0000-00-00 00:00:00' : $start_visible;

@ -73,6 +73,7 @@ $target_link = !empty($_REQUEST['target_link']) ? $_REQUEST['target_link'] : '_s
$nameTools = get_lang('Links');
$course_id = api_get_course_int_id();
// Condition for the session
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id, true, true);
@ -99,8 +100,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'editlink') {
$tbl_link = Database::get_course_table(TABLE_LINK);
$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
$course_id = api_get_course_int_id();
// Statistics
event_access_tool(TOOL_LINK);
@ -255,8 +254,7 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) {
</div>
</div>';
$sqlcategories = getSqlFromLinkCategory();
$resultcategories = Database::query($sqlcategories);
$resultcategories = getLinkCategories($course_id, $session_id);
if (Database::num_rows($resultcategories)) {
echo ' <div class="control-group category">
@ -421,11 +419,9 @@ 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 = getSqlFromLinkCategory();
$resultcategories = Database::query($sqlcategories);
$resultcategories = getLinkCategories($course_id, $session_id);
$aantalcategories = Database::num_rows($resultcategories);
if ($aantalcategories > 0) {
$resultcategories = Database::query($sqlcategories);
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&urlview=';
for ($j = 1; $j <= $aantalcategories; $j++) {
echo '0';

Loading…
Cancel
Save