diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php index 9ba6bc1ac4..fc872a46ba 100755 --- a/main/inc/lib/link.lib.php +++ b/main/inc/lib/link.lib.php @@ -264,6 +264,7 @@ function deletelinkcategory($type) { global $catlinkstatus; global $_course; + $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); @@ -295,6 +296,11 @@ 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); + Display :: display_confirmation_message(get_lang('CategoryDeleted')); } } @@ -609,7 +615,10 @@ function change_visibility($id, $scope) { if ($scope == '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')); + } } /** diff --git a/main/link/link.php b/main/link/link.php index 9d91abbb58..18db122b6e 100755 --- a/main/link/link.php +++ b/main/link/link.php @@ -35,18 +35,18 @@ api_protect_course_script(); $htmlHeadXtra[] = ''; @@ -78,21 +78,21 @@ $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, true); if (isset($_GET['action']) && $_GET['action'] == 'addlink') { - $nameTools = ''; - $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links')); - $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddLink')); + $nameTools = ''; + $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links')); + $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddLink')); } if (isset($_GET['action']) && $_GET['action'] == 'addcategory') { - $nameTools = ''; - $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links')); - $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddCategory')); + $nameTools = ''; + $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links')); + $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddCategory')); } if (isset($_GET['action']) && $_GET['action'] == 'editlink') { - $nameTools = ''; - $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links')); - $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditLink')); + $nameTools = ''; + $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links')); + $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditLink')); } // Database Table definitions @@ -122,49 +122,49 @@ function MM_popupMsg(msg) { //v1.0 $nameTools = get_lang('Links'); if (isset($_GET['action'])) { - $check_token = Security::check_token('request'); - if ($check_token) { - switch ($_GET['action']) { - case 'addlink': - if ($link_submitted) { - if (!addlinkcategory("link")) { // Here we add a link - unset($submit_link); - } - } - break; - case 'addcategory': - if ($category_submitted) { - if (!addlinkcategory('category')) { // Here we add a category - unset($submit_category); - } - } - break; - case 'importcsv': - if ($_POST['submitImport']) { - import_csvfile(); - } - break; - case 'deletelink': - deletelinkcategory('link'); // Here we delete a link - break; - case 'deletecategory': - deletelinkcategory('category'); // Here we delete a category - break; - case 'editlink': - editlinkcategory('link'); // Here we edit a link - break; - case 'editcategory': - editlinkcategory('category'); // Here we edit a category - break; - case 'visible': - change_visibility($_GET['id'], $_GET['scope']); // Here we edit a category - break; - case 'invisible': - change_visibility($_GET['id'], $_GET['scope']); // Here we edit a category - break; - } - Security::clear_token(); - } + $check_token = Security::check_token('request'); + if ($check_token) { + switch ($_GET['action']) { + case 'addlink': + if ($link_submitted) { + if (!addlinkcategory("link")) { // Here we add a link + unset($submit_link); + } + } + break; + case 'addcategory': + if ($category_submitted) { + if (!addlinkcategory('category')) { // Here we add a category + unset($submit_category); + } + } + break; + case 'importcsv': + if ($_POST['submitImport']) { + import_csvfile(); + } + break; + case 'deletelink': + deletelinkcategory('link'); // Here we delete a link + break; + case 'deletecategory': + deletelinkcategory('category'); // Here we delete a category + break; + case 'editlink': + editlinkcategory('link'); // Here we edit a link + break; + case 'editcategory': + editlinkcategory('category'); // Here we edit a category + break; + case 'visible': + change_visibility($_GET['id'], $_GET['scope']); // Here we edit a category + break; + case 'invisible': + change_visibility($_GET['id'], $_GET['scope']); // Here we edit a category + break; + } + Security::clear_token(); + } } $token = Security::get_token(); @@ -173,38 +173,38 @@ $token = Security::get_token(); Display::display_introduction_section(TOOL_LINK); if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) { - echo '
'; - if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])){ - if (!empty($_POST['lp_id'])){ - $lp_id = Security::remove_XSS($_POST['lp_id']); - } else { - $lp_id = Security::remove_XSS($_GET['lp_id']); - } - echo "".Display::return_icon('back.png', get_lang("BackTo").' '.get_lang("LearningPaths"),'',ICON_SIZE_MEDIUM).""; - } else { - //echo ''.Display::return_icon('back.png', get_lang('BackToLinksOverview'),'',ICON_SIZE_MEDIUM).''; - } - echo '
'; - - // Displaying the correct title and the form for adding a category or link. This is only shown when nothing - // has been submitted yet, hence !isset($submit_link) - if (($_GET['action'] == 'addlink' || $_GET['action'] == 'editlink') && empty($_POST['submitLink'])) { - - - - if ($category == '') { - $category = 0; - } - echo '
'; + echo '
'; + if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])){ + if (!empty($_POST['lp_id'])){ + $lp_id = Security::remove_XSS($_POST['lp_id']); + } else { + $lp_id = Security::remove_XSS($_GET['lp_id']); + } + echo "".Display::return_icon('back.png', get_lang("BackTo").' '.get_lang("LearningPaths"),'',ICON_SIZE_MEDIUM).""; + } else { + //echo ''.Display::return_icon('back.png', get_lang('BackToLinksOverview'),'',ICON_SIZE_MEDIUM).''; + } + echo '
'; + + // Displaying the correct title and the form for adding a category or link. This is only shown when nothing + // has been submitted yet, hence !isset($submit_link) + if (($_GET['action'] == 'addlink' || $_GET['action'] == 'editlink') && empty($_POST['submitLink'])) { + + + + if ($category == '') { + $category = 0; + } + echo ''; if ($_GET['action'] == 'addlink') { - echo ''.get_lang('LinkAdd').''; - } else { - echo ''.get_lang('LinkMod').''; - } - echo ''; - - if ($_GET['action'] == 'editlink') { - $clean_link_id = intval($_GET['id']); + echo ''.get_lang('LinkAdd').''; + } else { + echo ''.get_lang('LinkMod').''; + } + echo ''; + + if ($_GET['action'] == 'editlink') { + $clean_link_id = intval($_GET['id']); $link_info = get_link_info($_GET['id']); if ($link_info) { $urllink = $link_info['url']; @@ -217,308 +217,357 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) { } $target_link = $link_info['target']; } - echo ''; - } else { + echo ''; + } else { $target_link = "_blank"; } - echo '
- -
- -
-
'; - echo '
- -
- -
-
'; - echo '
- - -
'; - echo '
- -
- -
-
'; - - $sqlcategories = getSqlFromLinkCategory(); echo $sqlcategories; exit; - $resultcategories = Database::query($sqlcategories); - - if (Database::num_rows($resultcategories)) { - echo '
- -
'; - echo ' '; - echo '
-
'; - } - echo '
- -
- -
-
'; - echo '
- -
- +
+
'; + echo '
+ +
+ +
+
'; + echo '
+ + +
'; + echo '
+ +
+ +
+
'; + + $sqlcategories = getSqlFromLinkCategory(); + $resultcategories = Database::query($sqlcategories); + + if (Database::num_rows($resultcategories)) { + echo '
+ +
'; + echo ' '; + echo '
+
'; + } + echo '
+ +
+ +
+
'; + echo '
+ +
+ - + foreach ($targets as $target_id => $target) { + $selected = ''; + if ($target_id == $target_link) { + $selected = ' selected="selected"'; + } + echo ' '; + } + echo ' + '.get_lang('AddTargetOfLinkOnHomepage').' -
-
'; - - if (api_get_setting('search_enabled') == 'true') { - require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; - $specific_fields = get_specific_field_list(); - - echo '
- -
+
+
'; + + if (api_get_setting('search_enabled') == 'true') { + require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; + $specific_fields = get_specific_field_list(); + + echo '
+ +
-
+
'; - foreach ($specific_fields as $specific_field) { - $default_values = ''; - if ($_GET['action'] == 'editlink') { - $filter = array('field_id' => $specific_field['id'], 'ref_id' => intval($_GET['id']), 'tool_id' => '\''. TOOL_LINK .'\''); - $values = get_specific_field_values_list($filter, array('value')); - if (!empty($values)) { - $arr_str_values = array(); - foreach ($values as $value) { - $arr_str_values[] = $value['value']; - } - $default_values = implode(', ', $arr_str_values); - } - } - - $sf_textbox = ' -
- -
- -
-
'; - - echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values); - } - } - //echo ''; - echo ''; - echo '
- -
- -
-
'; - echo '
'; - } elseif(($_GET['action'] == 'addcategory' || $_GET['action'] == 'editcategory') && !$submit_category) { - echo '
'; + foreach ($specific_fields as $specific_field) { + $default_values = ''; + if ($_GET['action'] == 'editlink') { + $filter = array('field_id' => $specific_field['id'], 'ref_id' => intval($_GET['id']), 'tool_id' => '\''. TOOL_LINK .'\''); + $values = get_specific_field_values_list($filter, array('value')); + if (!empty($values)) { + $arr_str_values = array(); + foreach ($values as $value) { + $arr_str_values[] = $value['value']; + } + $default_values = implode(', ', $arr_str_values); + } + } + + $sf_textbox = ' +
+ +
+ +
+
'; + + echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values); + } + } + //echo ''; + echo ''; + echo '
+ +
+ +
+
'; + echo '
'; + } elseif(($_GET['action'] == 'addcategory' || $_GET['action'] == 'editcategory') && !$submit_category) { + echo '
'; if ($_GET['action'] == 'addcategory') { - echo ''.get_lang('CategoryAdd').''; - $my_cat_title = get_lang('CategoryAdd'); - } else { - echo ''.get_lang('CategoryMod').''; - $my_cat_title = get_lang('CategoryMod'); - } - - echo ''; - if ($_GET['action'] == 'editcategory') { - echo ''; - } - echo '
- -
- -
-
'; - - echo '
- -
- -
-
'; - - echo '
- -
- -
-
'; - echo "
"; - } + echo ''.get_lang('CategoryAdd').''; + $my_cat_title = get_lang('CategoryAdd'); + } else { + echo ''.get_lang('CategoryMod').''; + $my_cat_title = get_lang('CategoryMod'); + } + + echo ''; + if ($_GET['action'] == 'editcategory') { + echo ''; + } + echo '
+ +
+ +
+
'; + + echo '
+ +
+ +
+
'; + + echo '
+ +
+ +
+
'; + echo ""; + } } if (!empty($down)) { - movecatlink($down); + movecatlink($down); } if (!empty($up)) { - movecatlink($up); + movecatlink($up); } if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action'] != 'addcategory' && $_GET['action'] != 'addlink') || $link_submitted || $category_submitted) { - /* Action Links */ + /* Action Links */ - echo '
'; - if (api_is_allowed_to_edit(null, true)) { - $urlview = Security::remove_XSS($urlview); - 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).''; + echo '
'; + if (api_is_allowed_to_edit(null, true)) { + $urlview = Security::remove_XSS($urlview); + 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).''; - /* "".get_lang('CsvImport')."\n", // RH*/ - } - // 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). + /* "".get_lang('CsvImport')."\n", // RH*/ + } + // 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); - $aantalcategories = Database::num_rows($resultcategories); - if ($aantalcategories > 0) { - $resultcategories = Database::query($sqlcategories); - echo ''.Display::return_icon('view_remove.png', $shownone,'',ICON_SIZE_MEDIUM).''; - echo ''.Display::return_icon('view_tree.png', $showall,'',ICON_SIZE_MEDIUM).''; - } - echo '
'; - - // Displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed - $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE c_id = $course_id AND category_id=0 OR category_id IS NULL"; - $result = Database::query($sqlLinks); - $numberofzerocategory = Database::num_rows($result); - - if ($numberofzerocategory !== 0) { - echo ''; - echo ''; - echo '
'.get_lang('General').'
'; - showlinksofcategory(0); - } - - $i = 0; - $catcounter = 1; - $view = '0'; - - while ($myrow = Database::fetch_array($resultcategories)) { - // Validacion when belongs to a session - $session_img = api_get_session_image($myrow['session_id'], $_user['status']); - - //if (!isset($urlview)) { - if ($urlview == '') { - // No $view set in the url, thus for each category link it should be all zeros except it's own - makedefaultviewcode($i); - } else { - $view = $urlview; - $view[$i] = '1'; - } - // If the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a - // - instead of a +, the category is no longer clickable and all the links of this category are displayed - $myrow['description'] = text_filter($myrow['description']); - - if (isset($urlview[$i]) && $urlview[$i] == '1') { - $newurlview = $urlview; - $newurlview[$i] = '0'; - - echo ''; - echo ''; - echo ''; - echo ''; - if (api_is_allowed_to_edit(null, true)) { - if ($session_id == $myrow['session_id']) { - echo ''; - } else { - echo ''; - echo '
'; - echo ''; - echo '  '.Security::remove_XSS($myrow['category_title']).'
   '.$myrow['description']; - echo '
'; - showcategoryadmintools($myrow['id']); - echo ''.get_lang('EditionNotAvailableFromSession'); - } - } - echo '
'; - echo showlinksofcategory($myrow['id']); - echo ''; - } else { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo ''; - echo ''; - - echo '
  '.Security::remove_XSS($myrow['category_title']).$session_img; - echo'
   '; - echo $myrow['description']; - if (api_is_allowed_to_edit(null, true)) { - echo '
'; - showcategoryadmintools($myrow['id']); - echo '
'; - echo ''; - } - // Displaying the link of the category - $i++; - } - echo ''; + $resultcategories = Database::query($sqlcategories); + $aantalcategories = Database::num_rows($resultcategories); + if ($aantalcategories > 0) { + $resultcategories = Database::query($sqlcategories); + echo ''.Display::return_icon('view_remove.png', $shownone,'',ICON_SIZE_MEDIUM).''; + echo ''.Display::return_icon('view_tree.png', $showall,'',ICON_SIZE_MEDIUM).''; + } + echo '
'; + + // Displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed + $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE c_id = $course_id AND category_id=0 OR category_id IS NULL"; + $result = Database::query($sqlLinks); + $numberofzerocategory = Database::num_rows($result); + + if ($numberofzerocategory !== 0) { + echo ''; + echo ''; + echo '
'.get_lang('General').'
'; + showlinksofcategory(0); + } + + $i = 0; + $catcounter = 1; + $view = '0'; + + while ($myrow = Database::fetch_array($resultcategories)) { + // Validacion when belongs to a session + $session_img = api_get_session_image($myrow['session_id'], $_user['status']); + + //if (!isset($urlview)) { + if ($urlview == '') { + // No $view set in the url, thus for each category link it should be all zeros except it's own + makedefaultviewcode($i); + } else { + $view = $urlview; + $view[$i] = '1'; + } + // If the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a + // - instead of a +, the category is no longer clickable and all the links of this category are displayed + $myrow['description'] = text_filter($myrow['description']); + + + $strVisibility = ''; + if ($myrow['visibility'] == '1') { + $strVisibility = '' . + Display :: return_icon('visible.png', get_lang('Hide'), array (), ICON_SIZE_SMALL) . ''; + } elseif ($myrow['visibility'] == '0') { + $strVisibility = ' ' . + Display :: return_icon('invisible.png', get_lang('Show'), array (), ICON_SIZE_SMALL) . ''; + } + + if ($myrow['visibility'] == '1') { + + if (isset($urlview[$i]) && $urlview[$i] == '1') { + $newurlview = $urlview; + $newurlview[$i] = '0'; + echo ''; + echo ''; + echo ''; + echo ''; + if (api_is_allowed_to_edit(null, true)) { + if ($session_id == $myrow['session_id']) { + echo ''; + } else { + echo ''; + echo '
'; + echo ''; + echo '  '.Security::remove_XSS($myrow['category_title']).'
   '.$myrow['description']; + echo '
'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo ''.get_lang('EditionNotAvailableFromSession'); + } + } + echo '
'; + echo showlinksofcategory($myrow['id']); + echo ''; + } else { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo ''; + echo ''; + echo '
  '.Security::remove_XSS($myrow['category_title']).$session_img; + echo'
   '; + echo $myrow['description']; + if (api_is_allowed_to_edit(null, true)) { + echo '
'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo '
'; + echo ''; + } + + } else { // NO VISIBLES + if (api_is_allowed_to_edit(null, true)) { + if (isset($urlview[$i]) && $urlview[$i] == '1') { + $newurlview = $urlview; + $newurlview[$i] = '0'; + echo ''; + echo ''; + echo ''; + echo ''; + if (api_is_allowed_to_edit(null, true)) { + if ($session_id == $myrow['session_id']) { + echo ''; + } else { + echo ''; + echo '
'; + echo ''; + echo '  '.Security::remove_XSS($myrow['category_title']).'
   '.$myrow['description']; + echo '
'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo ''.get_lang('EditionNotAvailableFromSession'); + } + } + echo '
'; + echo showlinksofcategory($myrow['id']); + echo ''; + } else { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo ''; + echo ''; + echo '
  '.Security::remove_XSS($myrow['category_title']).$session_img; + echo'
   '; + echo $myrow['description']; + if (api_is_allowed_to_edit(null, true)) { + echo '
'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo '
'; + echo ''; + } + } + } + // Displaying the link of the category + $i++; + } + echo ''; } Display::display_footer(); \ No newline at end of file