Exemplo n.º 1
0
/**
 * This function is to show the added resources when adding an item
 * $showdeleteimg determine if the delete image should appear or not.
 * deleting an added resource is only possible through the resource linker file itself
 */
function display_resources($showdeleteimg)
{
    global $action;
    global $resourceaction;
    global $id;
    global $locationkey;
    global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
    if ($resourceaction == 'removeresource') {
        remove_resource($locationkey);
    }
    $addedresource = $_SESSION['addedresource'];
    $addedresourceid = $_SESSION['addedresourceid'];
    if (is_array($addedresource)) {
        echo '<table>';
        foreach ($addedresource as $resource) {
            echo '<tr><td>';
            display_addedresource_link($resource, $addedresourceid[key($addedresource)]);
            echo '</td><td width="30">';
            // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
            // should also contain this id.
            $test = parse_url($_SERVER['REQUEST_URI']);
            $output = array();
            parse_str($test[query], $output);
            if ($showdeleteimg == 1) {
                echo "<a href=" . api_get_self() . "?showresources=true&amp;source_forum=" . $_GET['source_forum'] . "&amp;resourceaction=removeresource&amp;locationkey=" . key($addedresource) . "&amp;source_id={$source_id}&amp;action={$action}&amp;learnpath_id={$learnpath_id}&amp;chapter_id={$chapter_id}&amp;originalresource=no><img src='../img/delete.gif' border='0' alt='resource " . get_lang('Delete') . "' /></a><br />";
            }
            echo '</td></tr>';
            next($addedresource);
        }
        echo '</table>';
    } else {
        // it is a string
        echo '';
    }
}
/**
* This function is to show the added resources when adding an item
* $showdeleteimg determine if the delete image should appear or not.
* deleting an added resource is only possible through the resource linker file itself
*/
function display_resources($showdeleteimg)
{
	global $action;
	global $resourceaction;
	global $id;
	global $locationkey;
	global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;

	if ($resourceaction=="removeresource")
	{
		/* unneccessary because when editing we delete all the added resources from the
		database and add all these from the session
		if ($action=="edit") // we have an edit and thus we delete from the database and from the session
		{
		echo "remove from database";
		echo $_SESSION['source_type']."/";
		echo $id."/";
		$addedresource=$_SESSION['addedresource'];
		$addedresourceid=$_SESSION['addedresourceid'];
		echo   $addedresource[$key]."/";
		echo   $addedresourceid[$key]."/";
		delete_one_added_resource($_SESSION['source_type'],$id,$addedresource[$key],$addedresourceid[$key]);
		remove_resource($key);
		}
		else // we remove from the session
		{*/
		//echo "remove from session";
		remove_resource($locationkey);
	}
	$addedresource=$_SESSION['addedresource'];
	$addedresourceid=$_SESSION['addedresourceid'];
	if (is_array($addedresource))
	{
		echo '<table>';
		foreach ($addedresource as $resource)
		{
			//echo $resource.":".$addedresourceid[key($addedresource)];
			echo '<tr><td>';
			display_addedresource_link($resource,$addedresourceid[key($addedresource)]);
			echo '</td><td width="30">';

			// if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
			// should also contain this id.
			$test=parse_url($_SERVER['REQUEST_URI']);
			$output = array();
			parse_str($test['query'],$output);

			if ($showdeleteimg==1)
			{
				//if (strstr($_SERVER['REQUEST_URI'],"?id="))
				//	{ echo " <a href='".api_get_self()."?id=".$output['id']."&amp;"; }
				//else
				//	{ echo " <a href='".api_get_self()."?"; }
				//action=$action&id=$id&
				//echo "action=$action&amp;id=$id&amp;originalresource=no&amp;resourceaction=removeresource&amp;key=".key($addedresource)."'><img src='../img/delete.gif' border='0' alt='resource ".get_lang('Delete')."' /></a><br />";
				echo "<a href=".api_get_self()."?showresources=true&amp;source_forum=".$_GET['source_forum']."&amp;resourceaction=removeresource&amp;locationkey=".key($addedresource)."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no><img src='../img/delete.gif' border='0' alt='resource ".get_lang('Delete')."' /></a><br />";
			}
			echo '</td></tr>';
			next($addedresource);
			//$_SESSION['edit']=='';
		}
		echo '</table>';
	}
	else // it is a string
	{
		echo '';
	}
} // end of the display_resources function