[svn r10401] consistency: action links

consistency: return messages
code cleanup
adding some @todo information
skala
Patrick Cool 19 years ago
parent 377b994385
commit 33d942b6ee
  1. 128
      main/link/link.php
  2. 49
      main/link/linkfunctions.php

@ -47,23 +47,25 @@
*/
// name of the language file that needs to be included
$language_file = "link";
// including libraries
include("../inc/global.inc.php");
include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
include("linkfunctions.php");
$this_section=SECTION_COURSES;
api_protect_course_script();
// Database Table definitions
$tbl_link = Database::get_course_table(TABLE_LINK);
$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
$nameTools = get_lang("Links");
//statistics
include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
event_access_tool(TOOL_LINK);
Display::display_header($nameTools,"Links");
$is_allowedToEdit = is_allowed_to_edit();
Display::display_header('', 'Links');
?>
<script type="text/javascript">
/* <![CDATA[ */
@ -81,13 +83,13 @@ function MM_popupMsg(msg) { //v1.0
/*
-----------------------------------------------------------
Introduction section
(editable by course admins)
-----------------------------------------------------------
*/
Display::display_introduction_section(TOOL_LINK);
include("linkfunctions.php");
// @todo change the $_REQUEST into $_POST or $_GET
// @todo remove this code
$link_submitted = $_POST["submitLink"];
$category_submitted = $_POST["submitCategory"];
$urlview = $_GET["urlview"];
@ -106,10 +108,16 @@ $action = $_REQUEST['action'];
$category_title = $_REQUEST['category_title'];
$submitCategory = $_REQUEST['submitCategory'];
// treating the post date by calling the relevant function depending of the action querystring.
/*
-----------------------------------------------------------
Action Handling
-----------------------------------------------------------
*/
switch($_GET['action'])
{
case "addlink": if($link_submitted)
case "addlink":
if($link_submitted)
{
if(!addlinkcategory("link")) // here we add a link
{
@ -117,7 +125,8 @@ switch($_GET['action'])
}
}
break;
case "addcategory": if($category_submitted)
case "addcategory":
if($category_submitted)
{
if(!addlinkcategory("category")) // here we add a category
{
@ -125,39 +134,38 @@ switch($_GET['action'])
}
}
break;
case "importcsv": if($submitImport) import_csvfile();
case "importcsv":
if($_POST["submitImport"])
{
import_csvfile();
}
break;
case "deletelink": deletelinkcategory("link"); // here we delete a link
case "deletelink":
deletelinkcategory("link"); // here we delete a link
break;
case "deletecategory": deletelinkcategory("category"); // here we delete a category
case "deletecategory":
deletelinkcategory("category"); // here we delete a category
break;
case "editlink": editlinkcategory("link"); // here we edit a link
case "editlink":
editlinkcategory("link"); // here we edit a link
break;
case "editcategory": editlinkcategory("category"); // here we edit a category
case "editcategory":
editlinkcategory("category"); // here we edit a category
break;
case "visible": change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
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
case "invisible":
change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
break;
}
if($is_allowedToEdit)
{
echo "<ul>\n";
echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=addlink&amp;category=".$category."&amp;urlview=$urlview\">".get_lang("LinkAdd")."</a></li>\n",
"<li><a href=\"".$_SERVER['PHP_SELF']."?action=addcategory&amp;urlview=".$urlview."\">".get_lang("CategoryAdd")."</a></li>\n",
/* "<li><a href=\"".$_SERVER['PHP_SELF']."?action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a></li>\n", // RH*/
"</ul>\n\n";
//displaying the error / status messages if there is one
if (!empty($catlinkstatus) or !empty($msgErr))
{
Display :: display_normal_message($catlinkstatus.$msgErr);
unset($catlinkstatus);
unset($msgErr);
}
if (is_allowed_to_edit())
{
// 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($submitLink)
if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and !$_POST['submitLink'])
@ -246,37 +254,51 @@ if($is_allowedToEdit)
"</form>";
echo get_lang('CsvExplain');
}*/
echo "<hr/>";
}
if (isset($down))
{
movecatlink($down);
}
if (isset($up))
{
movecatlink($up);
}
/*
-----------------------------------------------------------
Action Links
-----------------------------------------------------------
*/
if(is_allowed_to_edit())
{
echo Display::return_icon('linksnew.gif')." <a href=\"".$_SERVER['PHP_SELF']."?action=addlink&amp;category=".$category."&amp;urlview=$urlview\">".get_lang("LinkAdd")."</a>\n";
echo Display::return_icon('folder_new.gif')." <a href=\"".$_SERVER['PHP_SELF']."?action=addcategory&amp;urlview=".$urlview."\">".get_lang("CategoryAdd")."</a>\n";
/* "<a href=\"".$_SERVER['PHP_SELF']."?action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\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="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
$resultcategories=api_sql_query($sqlcategories);
$aantalcategories = @mysql_num_rows($resultcategories);
echo "<a href=\"".$_SERVER['PHP_SELF']."?urlview=";
for($j = 1; $j <= $aantalcategories; $j++)
{
echo Display::return_icon('remove.gif')." <a href=\"".$_SERVER['PHP_SELF']."?urlview=";
for($j = 1; $j <= $aantalcategories; $j++)
{
echo "0";
}
}
echo "\">$shownone</a>";
echo " | <a href=\"".$_SERVER['PHP_SELF']."?urlview=";
for($j = 1; $j <= $aantalcategories; $j++)
{
echo "1";
}
echo Display::return_icon('add.gif')." <a href=\"".$_SERVER['PHP_SELF']."?urlview=";
for($j = 1; $j <= $aantalcategories; $j++)
{
echo "1";
}
echo "\">$showall</a>";
if (isset($down))
{
movecatlink($down);
}
if (isset($up))
{
movecatlink($up);
}
$sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
$resultcategories=api_sql_query($sqlcategories);
@ -318,7 +340,7 @@ while ($myrow=@mysql_fetch_array($resultcategories))
$newurlview[$i]="0";
echo "<tr>",
"<td bgcolor=\"#e6e6e6\"><b>- <a href=\"".$_SERVER['PHP_SELF']."?urlview=".$newurlview."\">".htmlentities($myrow["category_title"])."</a></b><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
if ($is_allowedToEdit)
if (is_allowed_to_edit())
{
showcategoryadmintools($myrow["id"]);
}
@ -337,7 +359,7 @@ while ($myrow=@mysql_fetch_array($resultcategories))
echo "\">".htmlentities($myrow["category_title"])."</a></b><br>&nbsp;&nbsp;&nbsp;";
echo $myrow["description"];
if ($is_allowedToEdit)
if (is_allowed_to_edit())
{
showcategoryadmintools($myrow["id"]);
}

@ -77,6 +77,8 @@ function addlinkcategory($type)
{
$msgErr = get_lang('GiveURL');
Display::display_error_message(get_lang('GiveURL'));
$ok = false;
}
// if the title is empty, we use the url as the title
@ -104,6 +106,8 @@ function addlinkcategory($type)
$catlinkstatus = get_lang('LinkAdded');
api_sql_query($sql, __FILE__, __LINE__);
unset ($urllink, $title, $description, $selectcategory);
Display::display_confirmation_message(get_lang('LinkAdded'));
}
}
elseif ($type == "category")
@ -117,6 +121,8 @@ function addlinkcategory($type)
{
$msgErr = get_lang('GiveCategoryName');
Display::display_error_message(get_lang('GiveCategoryName'));
$ok = false;
}
else
@ -134,6 +140,8 @@ function addlinkcategory($type)
$catlinkstatus = get_lang('CategoryAdded');
unset ($category_title, $description);
Display::display_confirmation_message(get_lang('CategoryAdded'));
}
}
@ -173,6 +181,8 @@ function deletelinkcategory($type)
api_item_property_update($_course, TOOL_LINK, $id, "delete", $_user['user_id']);
$catlinkstatus = get_lang("LinkDeleted");
unset ($id);
Display::display_confirmation_message(get_lang('LinkDeleted'));
}
if ($type == "category")
{
@ -185,6 +195,8 @@ function deletelinkcategory($type)
$catlinkstatus = get_lang('CategoryDeleted');
unset ($id);
api_sql_query($sql, __FILE__, __LINE__);
Display::display_confirmation_message(get_lang('CategoryDeleted'));
}
}
@ -194,6 +206,7 @@ function deletelinkcategory($type)
* code does not follow the coding conventions, does not use html_quickform, ...
* some features were patched in
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @todo replace the globals with the appropriate $_POST or $_GET values
*/
function editlinkcategory($type)
{
@ -201,17 +214,23 @@ function editlinkcategory($type)
global $id;
global $submitLink;
global $submitCategory;
$tbl_link = Database :: get_course_table(TABLE_LINK);
$tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
if ($type == "link")
{
global $_user;
global $_course;
global $nameTools;
global $urllink;
global $title;
global $description;
global $category;
global $onhomepage;
global $selectcategory;
global $description;
global $category_title;
$tbl_link = Database :: get_course_table(TABLE_LINK);
$tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
if ($type == "link")
{
// this is used to populate the link-form with the info found in the database
$sql = "SELECT * FROM ".$tbl_link." WHERE id='".$_GET['id']."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
@ -229,8 +248,6 @@ function editlinkcategory($type)
// this is used to put the modified info of the link-form into the database
if ($_POST['submitLink'])
{
global $selectcategory;
// finding the old category_id
$sql = "SELECT * FROM ".$tbl_link." WHERE id='".$_POST['id']."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
@ -251,21 +268,15 @@ function editlinkcategory($type)
$sql = "UPDATE ".$tbl_link." set url='".$_POST['urllink']."', title='".$_POST['title']."', description='".$_POST['description']."', category_id='".$_POST['selectcategory']."', display_order='".$max_display_order."', on_homepage='".$_POST['onhomepage']."' WHERE id='".$_POST['id']."'";
api_sql_query($sql, __FILE__, __LINE__);
$catlinkstatus = get_lang('LinkModded');
// "WHAT'S NEW" notification: update table last_toolEdit
global $_user;
global $_course;
global $nameTools;
api_item_property_update($_course, TOOL_LINK, $_POST['id'], "LinkUpdated", $_user['user_id']);
Display::display_confirmation_message(get_lang('LinkModded'));
}
}
if ($type == "category")
{
global $description;
global $category_title;
// this is used to populate the category-form with the info found in the database
if (!$submitCategory)
{
@ -282,8 +293,10 @@ function editlinkcategory($type)
{
$sql = "UPDATE ".$tbl_categories." set category_title='".$_POST['category_title']."', description='".$_POST['description']."' WHERE id='".$_POST['id']."'";
api_sql_query($sql, __FILE__, __LINE__);
$catlinkstatus = get_lang('CategoryModded');
Display::display_confirmation_message(get_lang('CategoryModded'));
}
}
}
// END of function editlinkcat
@ -323,6 +336,8 @@ function change_visibility($id, $scope)
$row = mysql_fetch_array($result);
api_item_property_update($_course, TOOL_LINK, $id, $_GET['action'], $_user['user_id']);
}
Display::display_confirmation_message('VisibilityChanged');
}
/**
@ -492,6 +507,8 @@ function movecatlink($catlinkid)
}
}
}
Display::display_confirmation_message('Moved');
}
/**

Loading…
Cancel
Save