Hacked By AnonymousFox

Current Path : /home/missmand/public_html/js/lightbox/
Upload File :
Current File : /home/missmand/public_html/js/lightbox/resourcelinker.tar

resourcelinker.inc.php000064400000216311152003614570011070 0ustar00<?php // $Id: resourcelinker.inc.php 20468 2009-05-11 08:48:25Z ivantcholakov $
/* For licensing terms, see /license.txt */
/**
*	@author Patrick Cool - original version
*	@author Denes Nagy - further improvements for learning path builder
*	@author Roan Embrechts - refactoring to improve code organisation
*	@package chamilo.resourcelinker
*       @todo use the constants for the tools
* 	@todo use Database API instead of creating table names locally.
*       @todo This class is used?
*/


use \ChamiloSession as Session;

/**
 * INIT SECTION
 */

// name of the language file that needs to be included
//$language_file = "resourcelinker";// TODO: Repeated deleting and moving the rest of this lang file to trad4all

//include(api_get_path(SYS_CODE_PATH).'lang/english/resourcelinker.inc.php'); // TODO: Repeated deleting and moving the rest of this lang file to trad4all
//include(api_get_path(SYS_CODE_PATH).'lang/'.$_course['language'].'/resourcelinker.inc.php'); // TODO: Repeated deleting and moving the rest of this lang file to trad4all
include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
include(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');

/**
 * FUNCTIONS
*/

function unset_session_resources() {
	$_SESSION['addedresource']='';
	$_SESSION['addedresourceid']='';
	Session::erase('addedresource');
	Session::erase('addedresourceid');
}

/**
 * Insert description here.
 */
function show_folder_up()
{
	global $folder;
	global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;

	$level = get_levels($folder);

	if ($level == 1)
	{
		echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
	}
	if ($level and $level != 0 and $level != 1)
	{
		$folder_up=$folder;
		$folder_temp=explode('/',$folder);
		$last=count($folder_temp)-1;
		unset($folder_temp[$last]);
		$folder_up=implode('/',$folder_temp);
		echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;folder=$folder_up&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
	}
}

/**
 * Shows the documents of the document tool
 * @param $folder
 */
function show_documents($folder)
{
	global $_course;
	global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;

	// documents are a special case: the teacher can add an invisible document (it will be viewable by the user)
	// other tools do not have this feature. This only counts
	if (api_is_allowed_to_edit())
	{
		$visibility="ip.visibility<>'2'";
	}
	else
	{
		$visibility="ip.visibility='1'";
	}

	$item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
	$document_table = Database::get_course_table(TABLE_DOCUMENT);
	$sql="SELECT * from $document_table docs, $item_property_table ip WHERE docs.id=ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND $visibility AND ip.to_group_id = 0 AND ip.to_user_id IS NULL  ORDER BY docs.path ASC";
	$result=Database::query($sql);
	while ($row=Database::fetch_array($result))
	{
		if (!$folder)
		{
			if (get_levels($row['path'])-1==1)
			{
				// showing the right icon
				if (file_or_folder($row['path']))
				{
						echo '<img src="../img/file.gif" align="middle" />';
				}
				else
				{
					$image = choose_image($row['path']);
					echo "<img src=\"../img/$image\" align=\"middle\" />";
				}

				// folders should be clickable
				if (file_or_folder($row['path']))
				{
					echo "<a href='".api_get_self()."?content=Document";
					echo "&amp;folder=".substr($row['path'],1)."&amp;source_id=$source_id&amp;source_forum=".$_GET['source_forum']."&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'>".substr($row['path'],1).'</a><br />';
				}
				else
				{
					echo substr($row['path'],1).' ';
					echo showorhide_addresourcelink('Document',$row['id']);
					echo '<br />';
				}
			}
		}
		else
		{
			// we calculate the level we are in by using the $folder in the url
			// we put +1 because it does not start with an / and in the database it does
			$level=get_levels($folder)+1;

			// we calculate each level of the database entry
			$file_level=get_levels($row['path'])-1;
			// if the level of the database entry is equal to the level we ar in, we put it into an array
			// as this is a potential good entry
			if ($file_level==$level)
			{
				$good_paths[]=$row['path'];
				$good_ids[]=$row['id'];
			}
			//$haystack=$row['path'];
			//$conform_folder=strstr($haystack, $folder);
			//if (str_replace($folder.'/','',$conform_folder)!==$folder)
			//	{
			//	$good_folders[]=$row['path'];
				//echo str_replace($folder.'/','',$conform_folder);
			//	echo '<br />';
			//	}// if (str_replace($folder.'/','',$conform_folder)!==$folder)
		} // else (if (!$folder))
	} //while ($row=Database::fetch_array($result))

	// this is code for the case that we are in a subfolder
	if ($good_paths)
	{
		// we have all the potential good database entries, the good ones are those that start with $folder
		foreach ($good_paths as $path)
		{
			if (strstr($path,$folder))
			{
				$good_key=key($good_paths);
				// showing the right icon
				if (file_or_folder($path))
				{
					echo '<img src="../img/file.gif" align="middle" />';
				}
				else
				{
					$image = choose_image($path);
					echo "<img src=\"../img/$image\" align=\"middle\" />";
				}

				// folders should be clickable
				if (file_or_folder($path))
				{
					$path=substr($path,1); // remove the first / in folder_up
					$uri=str_replace($folder,$path,$_SERVER['REQUEST_URI']);
					$newuri=str_replace('add=','addnot=',$uri);
					//using the correct name of the folder
					$folder_name=str_replace($folder.'/','',$path);
					echo "<a href='$newuri'>".$folder_name.'</a><br />';
				}
				else
				{
					echo str_replace("/$folder/", '',$path).' ';
					echo showorhide_addresourcelink('Document',$good_ids[$good_key]);
					echo '<br />';
				}
			}
			next($good_paths);
		}
	}
}

/**
 * Checks wether something is a file or a folder
 * 0 means file, 1 means folder
 * @param $filefolder
 * @todo use true and false instead of 1 and 0.
 */
function file_or_folder($filefolder)
{
	global $_course;
	global $baseServDir;

	$courseDir   = $_course['path'].'/document';
	$baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;

	return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
}

/**
 * Inserts a resource into the database
 *
 * @param $source_type
 * @param $source_id
 */
function store_resources($source_type, $source_id)
{
	global $_course;
	$resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);

	$addedresource = $_SESSION['addedresource'];
	$addedresourceid = $_SESSION['addedresourceid'];
	if ($_SESSION['addedresource'])
	{
		foreach ($addedresource as $resource_type)
		{
			$sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
			Database::query($sql);
			$i=key($addedresource);
			next($addedresource);
		}
		$_SESSION['addedresource']='';
		$_SESSION['addedresourceid']='';
	}
}

/**
 * Displays the link that opens a new browser window that views the added resource.
 *
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 * @param $type the type of the tool
 * @param $id the id of the resource
 * @param $style this is used to style the link (for instance when a resource is hidden => the added resources should also be styled like they are hidden)
 * @todo use the constants for the type definitions.
 */
function display_addedresource_link($type, $id, $style='')
{
	global $_course;

	// styling the link of the added resource
	if ($style <> '')
	{
		$styling = ' class="'.$style.'"';
	}
    
    $course_id = api_get_course_int_id();

	switch ($type)
	{
		case 'Agenda':
			$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
			$result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
			$myrow = Database::fetch_array($result);
			echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
			break;
		case 'Ad_Valvas':
			$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
			$result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
			$myrow = Database::fetch_array($result);
			echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
			break;
		case 'Link':Database::get_course_table(TABLE_LINK);
			$result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
			$myrow = Database::fetch_array($result);
			echo '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode($myrow['url'])."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
			break;
		case 'Exercise':
			$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
			$result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND  id=$id");
			$myrow = Database::fetch_array($result);
			echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
			break;
		case 'Forum':
			$TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
			$result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
			$myrow = Database::fetch_array($result);
			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow['forum_name']."</a><br />\n";
			break;
		case 'Thread':  //=topics
        //deprecated
			$tbl_posts		= $_course['dbNameGlu'].'bb_posts';
			$tbl_posts_text	= $_course['dbNameGlu'].'bb_posts_text';
			$TBL_FORUMS		= $_course['dbNameGlu'].'bb_forums';
			$result = Database::query("SELECT * FROM $tbl_posts posts, $TBL_FORUMS forum WHERE forum.forum_id=posts.forum_id and post_id=$id");
			$myrow = Database::fetch_array($result);
			// grabbing the title of the post
			$sql_title = "SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow["post_id"];
			$result_title = Database::query($sql_title);
			$myrow_title = Database::fetch_array($result_title);
			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow['topic_id'].'&amp;forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow_title['post_title']."</a><br />\n";
			break;
		case 'Post':
        //deprecated
			$tbl_post = Database::get_course_table(TABLE_FORUM_POST);
			$tbl_post_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
			$sql = "SELECT * FROM $tbl_post p, $tbl_post_text t WHERE p.post_id = t.post_id AND p.post_id = $id";
			$result = Database::query($sql);
			$post = Database::fetch_object($result);
			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post->topic_id.'&amp;forum='.$post->forum_id.'"'.$styling.'>'.$post->post_title."</a><br />\n";
			break;
		case 'Document':
			$dbTable = Database::get_course_table(TABLE_DOCUMENT);
			$result = Database::query("SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id");
			$myrow = Database::fetch_array($result);
			$pathname = explode('/',$myrow['path']); // making a correct name for the link
			$last = count($pathname) - 1;  // making a correct name for the link
			$filename = $pathname[$last];  // making a correct name for the link
			$image = choose_image($filename);
			$ext = explode('.',$filename);
			$ext = strtolower($ext[sizeof($ext)-1]);
			$myrow['path'] = rawurlencode($myrow['path']);
			$in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png'));
			echo '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.'>'.$filename."</a><br />\n";
			break;
		case 'Externallink':
			echo '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.'>'.$id."</a><br />\n";
			break;
	}
}

/**
* This function is to display the added resources (lessons) in the learning path player and builder
* this function is a modification of display_addedresource_link($type, $id) function
* the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was
* building upon it. - Denes
*
* Parameters:
* @param completed   - if ="completed" then green presentation with checkbox
* @param id_in_path  - if onclick then this lesson will be considered completed, that is the unique index in the items table
* @param id          - that is the correspondent id in the mirror tool (like Agenda item 2)
* @param type        - that is the correspondent type in the mirror tool (like this is a Link item)
* @param builder     - if ="builder" then onclick shows in new window
* @param icon        - if ="icon" then the small icon will appear
*                      if ="wrap" then wrapped settings are used (and no icon is displayed)
*                      if ="nolink" then only the name is returned with no href and no icon (note:only in this case, the result is not displayed, but returned)
* @todo this function is too long, rewrite
*/
function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0)
{
	global $learnpath_id, $tbl_learnpath_item, $items;
	global $_course, $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;

	$hyperlink_target_parameter = ''; //or e.g. 'target="_blank"'

	$length = ((($builder == 'builder') and ($icon == 'nolink')) ? 65 : 32);

	if ($builder != 'builder') $origin = 'learnpath';	//origin = learnpath in student view
	$linktype = $type;
	if (($type == 'Link _self') or ($type == 'Link _blank')) $type = 'Link';

	switch ($type)
	{
		case "Agenda":
			$TABLEAGENDA 		= Database::get_course_table(TABLE_AGENDA,$_course['dbName']);
			$result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
			$desc=$row['description'];
			$agenda_id=$row['item_id'];
			echo str_repeat("&nbsp;&gt;",$level);
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($myrow["title"]=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); }
			if ($icon == 'icon') { echo "<img src='../img/agenda.gif' align=\"absmiddle\" alt='agenda'>"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path\" class='$completed'>".shorten($myrow["title"],($length-3*$level))."</a>";
        		$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id\" class='$completed' target='_blank'>".shorten($myrow["title"],($length-3*$level))."</a>";
			}
			break;

		case "Ad_Valvas":
			$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['dbName']);
			$result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["content"]=$row['title']; }
			$desc=$row['description'];
			$ann_id=$row['item_id'];
			echo str_repeat("&nbsp;&gt;",$level);

			// the title and the text are in the content field and we only want to display the title
			list($title, $text)=split('<br>',$myrow['content']);
			if ($title=='') { $title=$myrow['content']; }
			$title=$myrow['title'];
			$text=$myrow['content'];
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($title=='') {
				$type="Announcement";
				echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
				return(true);
			}

			if ($icon == 'nolink') { return(shorten($title,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/valves.gif' align=\"absmiddle\" alt='ad valvas'>"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path\" class='$completed'>".shorten($title,($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../announcements/announcements.php?origin=$origin&ann_id=$ann_id\" class='$completed' target='_blank'>".shorten($title,($length-3*$level))."</a>";
			}
			break;

		case "Link" :
			$TABLETOOLLINK	= Database::get_course_table(TABLE_LINK,$_course['dbName']);
			$result= Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($myrow["title"]=='')
			{
				echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
				return(true);
			}

			if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); }
			if ($icon == 'icon')
			{
				if ($linktype=='Link _self') { echo "<img src='../img/links.gif' align=\"absmiddle\" alt='links'>"; }
				   else { echo "<img src='../img/link_blank.gif' align=\"absmiddle\" alt='blank links'>"; }
			}
			$thelink=$myrow["url"];
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path\" class='$completed'>".shorten($myrow["title"],($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"$thelink\" class='$completed' target='_blank'>".shorten($myrow["title"],($length-3*$level))."</a>";
			}
			break;

		case "Exercise":
			$TBL_EXERCICES  = Database::get_course_table(TABLE_QUIZ_TEST,$_course['dbName']);
			$result= Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
			$myrow=Database::fetch_array($result);

			if ($builder=='builder') { $origin='builder'; }
			  //this is needed for the exercise_submit.php can delete the session info about tests

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($myrow["title"]=='') {
				echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
				return(true);
			}

			if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); }
			if ($icon == 'icon') { echo "<img src='../img/quiz.gif' align=\"absmiddle\" alt='quizz'>"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path\" class='$completed'>".shorten($myrow["title"],($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"]."\" class='$completed' target='_blank'>".shorten($myrow["title"],($length-3*$level))."</a>";
			}
			break;

		case "HotPotatoes":
			$TBL_DOCUMENT  = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
			$documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
			$result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id");
			$myrow= Database::fetch_array($result);
			$path=$myrow["path"];
			$name=GetQuizName($path,$documentPath);

			if ($builder=='builder') { $origin='builder'; }
			  //this is needed for the exercise_submit.php can delete the session info about tests

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/jqz.gif' align=\"absmiddle\" alt='hot potatoes'>"; }

			$cid = $_course['official_code'];

			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "&nbsp;<a href=\"../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']."\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;

		case "Forum":
			$TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['dbName']);
			$result= Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($myrow["forum_name"]=='') { $type="Forum"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($myrow["forum_name"],$length)); }
			if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
			$forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path\" class='$completed'>".shorten($myrow["forum_name"],($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../phpbb/viewforum.php?$forumparameters\" class='$completed' target='_blank'>".shorten($myrow["forum_name"],($length-3*$level))."</a>";
			}
			break;

		case "Thread":  //forum post
        //deprecated
			$tbl_topics      = $_course['dbNameGlu'].'bb_topics';
			$tbl_posts		 = $_course['dbNameGlu'].'bb_posts';
			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
			$sql="SELECT * FROM $tbl_topics where topic_id=$id";
			$result= Database::query($sql);
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($myrow["topic_title"]=='') { $type="Forum Post"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($myrow["topic_title"],$length)); }
			if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path\" class='$completed'>".shorten($myrow["topic_title"],($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten($myrow["topic_title"],($length-3*$level))."</a>";
			}
			break;

		case "Post":
        //deprecated
			$tbl_posts       = $_course['dbNameGlu'].'bb_posts';
			$tbl_posts_text  = $_course['dbNameGlu'].'bb_posts_text';
			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
			$result= Database::query("SELECT * FROM $tbl_posts where post_id=$id");
			$myrow=Database::fetch_array($result);
			// grabbing the title of the post
			$sql_titel="SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow["post_id"];
			$result_titel=Database::query($sql_titel);
			$myrow_titel=Database::fetch_array($result_titel);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			$posternom=$myrow['nom'];				$posterprenom=$myrow['prenom'];
			$posttime=$myrow['post_time'];			$posttext=$myrow_titel['post_text'];
			$posttitle=$myrow_titel['post_title'];
			$posttext = str_replace('"',"'",$posttext);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($myrow_titel["post_title"]=='')
			{
				$type="Forum";
				echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
			}

			if ($icon == 'nolink') { return(shorten($myrow_titel["post_title"],$length)); }
			if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path\" class='$completed'>".shorten($myrow_titel["post_title"],($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten($myrow_titel["post_title"],($length-3*$level))."</a>";
			}
			break;

		case "Document":
			$dbTable  = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
			$result=Database::query("SELECT * FROM $dbTable WHERE id=$id");
			$myrow=Database::fetch_array($result);

			$pathname=explode("/",$myrow["path"]); // making a correct name for the link
			$last=count($pathname)-1;  // making a correct name for the link
			$filename=$pathname[$last];  // making a correct name for the link
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }

			echo str_repeat("&nbsp;&gt;",$level);

			if ($icon != 'nolink') {
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
			$image=choose_image($filename);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $filename=$row['title']; }
			$desc=$row['description'];

			if (($myrow["path"]=='') and ($filename=='')) {
				echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
				return(true);
			}

			if ($icon == 'nolink') { return(shorten($filename,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/$image' align=\"absmiddle\" alt='$image'>"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path\" class='$completed'>".shorten($filename,($length-3*$level))."</a>";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				} $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path";
			}
			else
			{
				$enableDocumentParsing='yes';
				if (!$enableDocumentParsing)
				{ //this is the solution for the non-parsing version in the builder
					$file=urlencode($myrow["path"]);
					echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
				}
				else
				{
					echo "<a href=\"../document/download.php?doc_url=".$myrow["path"]."\" class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
				}
			}
			break;

		case "Assignments":
			$name=get_lang('Assignments');
			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink')
			{
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='')
			{
				echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
			}

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/works.gif' align=\"absmiddle\">"; }
			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
				if ($desc != '')
				{
					if ($icon != 'wrap')
					{
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
					}
					else
					{
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
					}
				}
			}
			else
			{
				echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;
		case "Dropbox":
			$name=get_lang('Dropbox');
			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink') {
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/dropbox.gif' align=\"absmiddle\">"; }

			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path";
				if ($desc != '') {
					if ($icon != 'wrap') {
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
					else {
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
				}
			} else {
				echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;
		case "Introduction_text":
			$name=get_lang('IntroductionText');
			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink') {
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/introduction.gif' align=\"absmiddle\" alt='introduction'>"; }

			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>";
				$items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path";
				if ($desc != '') {
					if ($icon != 'wrap') {
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
					else {
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
				}
			} else {
				$s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
				echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;
		case "Course_description":
			$name=get_lang('CourseDescription');
			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink') {
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/info.gif' align=\"absmiddle\" alt='info'>"; }

			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path";
				if ($desc != '') {
					if ($icon != 'wrap') {
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
					else {
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
				}
			} else {
				$s=api_get_path(WEB_CODE_PATH)."course_description";
				echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;
		case "Groups":
			$name=get_lang('Groups');
			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink') {
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/group.gif' align=\"absmiddle\" alt='group'>"; }

			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path";
				if ($desc != '') {
					if ($icon != 'wrap') {
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
					else {
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
				}
			} else {
				echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;
		case "Users":
			$name=get_lang('Users');
			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $name=$row['title']; }
			$desc=$row['description'];
			echo str_repeat("&nbsp;&gt;",$level);

			if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
			if ($icon != 'nolink') {
				if ($completed=='completed') {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
				}	else {
					echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
					//echo "&nbsp;";
				}
			}
			if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }

			if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }

			if ($icon == 'nolink') { return(shorten($name,$length)); }
			if ($icon == 'icon') { echo "<img src='../img/members.gif' align=\"absmiddle\" alt='members'>"; }

			if ($builder != 'builder')
			{
				echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path";
				if ($desc != '') {
					if ($icon != 'wrap') {
						echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
					else {
						echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
				}
			} else {
				echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
			}
			break;
	}//end huge switch-statement
}

/**
* This function is to create and return a link to the added resources (lessons).
* It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
* anything.
*
* Parameters:
* @param type        - that is the correspondent type in the mirror tool (like this is a Link item)
* @param id          - that is the correspondent id in the mirror tool (like Agenda item 2)
* @param id_in_path  - the unique index in the items table
*/
function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
{
	global $_course, $learnpath_id, $tbl_learnpath_item, $items;
	global $curDirPath, $_configuration, $enableDocumentParsing, $_user , $_cid;

	$hyperlink_target_parameter = ""; //or e.g. target='_blank'
 $builder = 'player';
	$origin='learnpath';

	$linktype=$type;
	if (($type=="Link _self") or ($type=="Link _blank")) { $type="Link"; }

 $link = '';

	switch ($type)
	{
		case "Agenda":
			$TABLEAGENDA 		= Database::get_course_table(TABLE_AGENDA,$_course['dbName']);;
			$result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
			$desc=$row['description'];
			$agenda_id=$row['item_id'];

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
			}
			else
			{
				$link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
			}
			break;

		case "Ad_Valvas":
			$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
			$result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
			$myrow=Database::fetch_array($result);

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$id#$id_in_path";
			}
			else
			{
				$link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
			}
			break;

		case "Link" :
			$TABLETOOLLINK	= Database::get_course_table(TABLE_LINK,$_course['dbName']);
			$result= Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);

			$thelink=$myrow["url"];
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
			}
			else
			{
				$link .= $thelink;
			}
			break;

		case "Exercise":
			$TBL_EXERCICES  = Database::get_course_table(TABLE_QUIZ_TEST,$_course['dbName']);
			$result= Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
			$myrow=Database::fetch_array($result);

			if ($builder=='builder') { $origin='builder'; }
			  //this is needed for the exercise_submit.php can delete the session info about tests

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["title"]=$row['title']; }

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
			}
			else
			{
				$link .= "../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"];
			}
			break;

		case "HotPotatoes":
	  	    $TBL_DOCUMENT  = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
		    $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
			$result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id");
		    $myrow= Database::fetch_array($result);
		    $path=$myrow["path"];
		  	$name=GetQuizName($path,$documentPath);

			if ($builder=='builder') { $origin='builder'; }

			$cid = $_course['official_code'];

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
			}
			else
			{
				$link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']."";
			}
			break;

		case "Forum":
        //deprecated
			$TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['dbName']);
			$result= Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
			$myrow=Database::fetch_array($result);

			if ($builder=='builder') { $origin='builder'; }

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }

			if ($myrow["forum_name"]=='') { $type="Forum"; }

			$forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path";
			}
			else
			{
				$link .= "../phpbb/viewforum.php?$forumparameters";
			}
			break;

		case "Thread":  //forum post
        //deprecated
			$tbl_topics      = $_course['dbNameGlu'].'bb_topics';
			$tbl_posts		 = $_course['dbNameGlu'].'bb_posts';
			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
			$sql="SELECT * FROM $tbl_topics where topic_id=$id";
			$result= Database::query($sql);
			$myrow=Database::fetch_array($result);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path";
			}
			else
			{
				$link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
			}
			break;

		case "Post":
			/* todo REVIEW THIS SECTION - NOT USING VALID TABLES ANYMORE
			$tbl_posts       = $_course['dbNameGlu'].'bb_posts';
			$tbl_posts_text  = $_course['dbNameGlu'].'bb_posts_text';
			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
			$result= Database::query("SELECT * FROM $tbl_posts where post_id=$id");
			$myrow=Database::fetch_array($result);
			// grabbing the title of the post
			$sql_titel="SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow["post_id"];
			$result_titel=Database::query($sql_titel);
			$myrow_titel=Database::fetch_array($result_titel);

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);
			if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
			$desc=$row['description'];
    		$link .= str_repeat("&nbsp;&gt;",$level);

			$posternom=$myrow['nom'];				$posterprenom=$myrow['prenom'];
			$posttime=$myrow['post_time'];			$posttext=$myrow_titel['post_text'];
			$posttitle=$myrow_titel['post_title'];
			$posttext = str_replace('"',"'",$posttext);

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path";
			}
			else
			{
				$link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
			}
			*/
			break;

		case "Document":
			$dbTable  = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
			$result=Database::query("SELECT * FROM $dbTable WHERE id=$id",__FILE__,__LINE);
			$myrow=Database::fetch_array($result);

			$pathname=explode("/",$myrow["path"]); // making a correct name for the link
			$last=count($pathname)-1;  // making a correct name for the link
			$filename=$pathname[$last];  // making a correct name for the link

			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
			$result=Database::query($sql);	$row=Database::fetch_array($result);

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path";

			}
			else
			{
				$enableDocumentParsing='yes';
				if (!$enableDocumentParsing)
				{ //this is the solution for the non-parsing version in the builder
					$file=urlencode($myrow["path"]);
					$link .= "../document/showinframes.php?file=$file";
				}
				else
				{
					$link .= "../document/download.php?doc_url=".$myrow["path"];
				}
			}
			break;

		case "Assignments":
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
			}
			else
			{
				$link .= "../work/work.php";
			}
			break;
		case "Dropbox":
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path";
			} else {
				$link .= "../dropbox/index.php";
			}
			break;
		case "Introduction_text":
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path";
			} else {
				$s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
				$link .= $s;
			}
			break;
		case "Course_description":
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path";
			} else {
				$s=api_get_path(WEB_CODE_PATH)."course_description";
				$link .= $s;
			}
			break;
		case "Groups":

			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path";
			} else {
				$link .= "../group/group.php?origin=$origin";
			}
			break;
		case "Users":
			if ($builder != 'builder')
			{
				$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path";
			} else {
				$link .= "../user/user.php?origin=$origin";
			}
			break;
	}//end huge switch-statement
    return $link;
}

/**
* This function is to remove an resource item from the array
*/
function remove_resource($resource_key)
{
	$addedresource = $_SESSION['addedresource'];
	$addedresourceid = $_SESSION['addedresourceid'];
	unset($addedresource[$resource_key]);
	unset($addedresourceid[$resource_key]);
	$_SESSION['addedresource']=$addedresource;
	$_SESSION['addedresourceid']=$addedresourceid ;
}

/**
* This function is to show the button "click to add resource" on the tool page
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function show_addresource_button($additionalparameters = '')
{
	global $charset;
	echo '<label for="addresources"><img src="../img/attachment.gif" /></label><input class="link_alike" type="submit" name="addresources" id="addresources" value="'.api_htmlentities(get_lang('Attachment'), ENT_QUOTES, $charset).'" '.$additionalparameters.' />';
}

/**
* this function is to delete ONE specific resource that were added to a specific item
* Deprecated
*//*
function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id)
{
	//echo "delete_one_added_resource";
	global $_course;
	$TABLERESOURCE 		= $_course['dbNameGlu']."resource";

	$sql="DELETE FROM $TABLERESOURCE WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
	Database::query($sql);
}
*/
/**
* this function is to delete the resources that were added to a specific item
*/
function delete_added_resource($type, $id)
{
	global $_course;
	$TABLERESOURCE 		= Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);

	$sql="DELETE FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
	Database::query($sql);
}

/**
* this function is te delete all resources of a specific type (only used in announcements -- delete all)
* Author : Frederik Vermeire <frederik.vermeire@pandora.be>
*/
function delete_all_resources_type($type)
{
  global $_course;
  $TABLERESOURCE 		= Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);

  $sql="DELETE FROM $TABLERESOURCE WHERE source_type='$type'";

  Database::query($sql);
}

/**
* this function checks wether there are added resources or not
*/
function check_added_resources($type, $id)
{
	global $_course, $origin;
	$TABLERESOURCE 		= Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
	$sql="SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
	$result=Database::query($sql);
	$number_added=Database::num_rows($result);
	if ($number_added<>0)
		return true;
	else
		return false;
}


/**
* this function is to load the resources that were added to a specific item
* into the session variables
*/
function edit_added_resources($type, $id)
{
	global $_course;
	$TABLERESOURCE 		= Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);

	$sql="SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id=$id";
	$result=Database::query($sql);
	while ($row=Database::fetch_array($result))
	{
		$addedresource[]=$row["resource_type"];
		$addedresourceid[]=$row["resource_id"];
	}
	$_SESSION['addedresource']=$addedresource;
	$_SESSION['addedresourceid']=$addedresourceid;
}

/**
* this function is store the modified resources
* first we delete all the added resources in the database,
* then we add all the resources from the session object.
*/
function update_added_resources($type, $id)
{
	global $_course;
	$TABLERESOURCE 		= Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
	// delete all the added resources for this item in the database;
	$sql="DELETE FROM $TABLERESOURCE WHERE source_type='$type' AND source_id='$id'";
	//echo $sql;
	Database::query($sql);

	// store the resources from the session into the database
	store_resources($type, $id);

	//delete_added_resource_($type, $id);
	unset_session_resources();
}

/**
* this function is to display the resources that were added to a specific item
*/
function display_added_resources($type, $id, $style='')
{
	// the array containing the icons
	$arr_icons=array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' );

	global $_course, $origin;
	$TABLERESOURCE 		= Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);

	$sql="SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
	$result=Database::query($sql);
	while ($row=Database::fetch_array($result))
	{
		if ($origin != 'learnpath')
		{
			display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ;
		}
		else
		{
			display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "<br>";
		}
	}
}


/**
* 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


/**
* This function checks wether the link add resource should be displayed next the item in the linker page
* So we have to check if the specific id of that tool is already in the array of the added resources
* if it is already in, the link should not be showed since it would make it possible to add
* the same resource a second time (=duplication of added resources)
*/
function showorhide_addresourcelink($type, $id)
{
	global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
	//global $_SESSION['addresource'];
	//global $_SESSION['addresourceid'];
	$addedresource=$_SESSION['addedresource'];
	$addedresourceid=$_SESSION['addedresourceid'];

	if (is_array($_SESSION['addedresource']))
	{
		foreach ($addedresource as $toolcompare)
		{
			//echo $toolcompare;
			//echo "/".$type."/".$id."****";
			//$key=key($addedresource);
			//echo $addedresourceid[$key];
			//print_r($addedresourceid);
			//echo "<br>";

			if ($toolcompare==$type and $addedresourceid[key($addedresource)]==$id)
			{
				$show=0;
			}
			next($addedresource);
		}
		if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); }
		if ($show!==0)
		{
			if ($type=="Document")
			{
				echo "<a href=".api_get_self()."?content=".$type."&folder=".$folder."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".$lang_add_it_or_resource."</a>";
			}
			else
			{
				echo "<a href='".api_get_self()."?content=".$type."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
			}
		}
	}
	else // if it is not an array, it is a string
	{
		if ($_SESSION['addedresource']!==$type or $_SESSION['addedresourceid']!==$id)
		{
			if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); }
			echo "<a href='".api_get_self()."?content=".$type."&folder=".$folder."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
		}
	}
}
?>
index.html000064400000000154152003614570006544 0ustar00<html>
<head>
<meta http-equiv="refresh" content="0; url=resourcelinker.php">
</head>
<body>
</body>
</html>resourcelinker.php000064400000112104152003614570010313 0ustar00<?php
/* For licensing terms, see /license.txt */
/**
* @author Patrick Cool, original code
* @author Denes Nagy - many bugfixes and improvements, adjusted for learning path
* @author Roan Embrechts - refactoring, code cleaning
* @package chamilo.resourcelinker
* @todo reorganise code - This class is used?
* use Database API instead of creating table names locally.
* 
*/

/**
 * INIT SECTION
 */
// name of the language file that needs to be included
//$language_file = 'resourcelinker';// TODO: Repeated deleting and moving the rest of this lang file to trad4all

use \ChamiloSession as Session;

include ('../inc/global.inc.php');
$this_section=SECTION_COURSES;

api_protect_course_script();

/*
-----------------------------------------------------------
	Libraries
-----------------------------------------------------------
*/
include_once (api_get_path(LIBRARY_PATH)."fileUpload.lib.php");
include ('resourcelinker.inc.php');

/*
-----------------------------------------------------------
	Constants and variables
-----------------------------------------------------------
*/

$link_table = Database :: get_course_table(TABLE_LINK);
$item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);

$tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);

$action = $_REQUEST['action'];
$add = $_REQUEST['add'];
$chapter_id = $_REQUEST['chapter_id'];
$content = $_REQUEST['content'];
// Note by Patrick Cool: this has been solved belowd. This piece of code hacking produced too much errors.
/*
if(empty($content)){
	//adds a default to the item-type selection
	$content = 'Document';
}
*/
$folder = $_REQUEST['folder'];
$id = $_REQUEST['id'];
$learnpath_id = $_REQUEST['learnpath_id'];
$originalresource = $_REQUEST['originalresource'];
$show_resources = $_REQUEST['show_resources'];
$source_forum = $_REQUEST['source_forum'];
$source_id = $_REQUEST['source_id'];
$target = $_REQUEST['target'];
$external_link = $_REQUEST['external_link'];

$from_learnpath = $_SESSION['from_learnpath'];

// this variable controls wether the link to add a chapter in a module or
// another chapter is shown. This allows to create multi-level learnpaths,
// but export features are not ready for this, yet, so use at your own risks
// default : false -> do not display link
// This setting should be moved to the platform configuration page in time...
$multi_level_learnpath = true;

/*
==============================================================================
		MAIN CODE
==============================================================================
*/
if ($from_learnpath == 'yes')
{
	//start from clear every time in LearnPath Builder
	$_SESSION['addedresource'] = null;
	$_SESSION['addedresourceid'] = null;
	$_SESSION['addedresourceassigned'] = null;
	unset ($_SESSION['addedresource']);
	unset ($_SESSION['addedresourceid']);
	unset ($_SESSION['addedresourceassigned']);
}

// Process a new chapter?
if (!empty ($_POST['add_chapter']) && !empty ($_POST['title']))
{
	$title = $_POST['title'];
	$description = '';
	if (!empty ($_POST['description']))
	{
		$description = $_POST['description'];
	}

	// get max display_order so far in this parent chapter
	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
	$res = Database::query($sql);
	$row = Database::fetch_array($res);
	$max_temp = $row[0];

	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
	$res = Database::query($sql);
	$row = Database::fetch_array($res);
	$max_temp2 = $row[0];
	if ($max_temp2 > $max_temp)
	{
		$order = $max_temp2 +1;
	}
	else
	{
		$order = $max_temp +1;
	}

	$sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )";
	$res = Database::query($sql);
	if ($res !== false)
	{
		$title = '';
		$description = '';
	}
}

// This if when a external link is submitted
if (!empty ($_POST['external_link_submit']))
{
	$add = true;
	if ($add_2_links != "niet toevoegen")
	{
		// add external link to the links table.
		$pos = strpos($external_link, 'ttp:');
		if ($pos == '')
		{
			$external_link = 'http://'.$external_link;
		}

		$sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
		$result = Database::query($sql);
		$addedresource[] = "Link";
		$addedresourceid[] = Database::insert_id();
		$_SESSION['addedresource'] = $addedresource;
		$_SESSION['addedresourceid'] = $addedresourceid;
	}
	else
	{
		// do not add external link to the links table
		$addedresource[] = "Externallink";
		$addedresourceid[] = $external_link;
		$_SESSION['addedresource'] = $addedresource;
		$_SESSION['addedresourceid'] = $addedresourceid;
	}
}

// loading the session variables into local array
$addedresource = $_SESSION['addedresource'];
$addedresourceid = $_SESSION['addedresourceid'];

// This is when a resource was added to the session
if ($add)
{
	// adding the new variable to the local array
	if (empty ($_POST['external_link_submit']))
	{
		//that case is already arranged, see upwards
		$addedresource[] = $content;
		$addedresourceid[] = $add;
	}
	$addedresourceassigned[] = 0;

	// loading the local array into the session variable
	$_SESSION['addedresource'] = $addedresource;
	$_SESSION['addedresourceid'] = $addedresourceid;

	//---------------------------------------
	//we assign to chapters immediately !
	//---------------------------------------
	$resource_added = false;
	if ($from_learnpath == 'yes')
	{
		$i = 0;
		//calculating the last order of the items of this chapter
		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id";
		$result = Database::query($sql);
		if(Database::num_rows($result)==0){
			$lastorder_item = 0;
		}else{
			$row = Database::fetch_array($result);
			$lastorder_item = ($row[0]);
		}
		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
		$result = Database::query($sql);
		if(Database::num_rows($result)==0){
			$lastorder_chapter = 0;
		}else{
			$row = Database::fetch_array($result);
			$lastorder_chapter = ($row[0]);
		}
		$lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);

		foreach ($addedresource as $addedresource_item)
		{
			// in the case we added a chapter, add this into the chapters list with the correct parent_id
			if ($addedresource_item == "Chap")
			{
				$sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")";
				Database::query($sql);
			}

			if (!$addedresourceassigned[$i])
			{
				//not to assign it twice
				if ($addedresource_item == "Ass")
				{
					$addedresource_item = "Assignments";
				}
				if ($addedresource_item == "Drop")
				{
					$addedresource_item = "Dropbox";
				}
				if ($addedresource_item == "Intro")
				{
					$addedresource_item = "Introduction_text";
				}
				if ($addedresource_item == "Course_desc")
				{
					$addedresource_item = "Course_description";
				}
				if ($addedresource_item == "Group")
				{
					$addedresource_item = "Groups";
				}
				if ($addedresource_item == "User")
				{
					$addedresource_item = "Users";
				}
				if ($target == '')
				{
					$target = '_self';
				}
				if ($addedresource_item == 'Link')
				{
					$addedresource_item .= ' '.$target;
				}
				$sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')";
				$result = Database::query($sql);
				$addedresourceassigned[$i] = 1;
				$resource_added = true;
			}
			$i ++;
			$lastorder ++;
		}
		//$_SESSION['addedresource']=null;
		//$_SESSION['addedresourceid']=null;
		// cleaning up the session once again
		$_SESSION['addedresource'] = null;
   		$_SESSION['addedresourceid'] = null;
   		$_SESSION['addedresourceassigned'] = null;
   		unset ($_SESSION['addedresource']);
   		unset ($_SESSION['addedresourceid']);
   		unset ($_SESSION['addedresourceassigned']);
	}
}

/*
==============================================================================
	BREADCRUMBS
	This part is to allow going back to the tool where you came from
	in a previous version I used the table tool_list, but since the forum can access the
	resource_linker from two different pages (newtopic.php and editpost.php) and this is different
	from the link field in tool_list, I decide to hardcode this stuff here.
	By doing this, you can easily control which pages can access the toollinker and which not.
==============================================================================
*/
if ($_GET["source_id"])
{
	switch ($_GET["source_id"])
	{
		case "1" : // coming from Agenda
			if ($action == "edit")
			{
				$url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource";
			}
			elseif ($action == "add")
		{
				$url = "../calendar/agenda.php?action=add&originalresource=$originalresource";
			}
			else
			{
				$url = "../calendar/agenda.php?action=add";
			}
			$originaltoolname = get_lang("Agenda");
			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
			session_unregister('from_learnpath');
			unset ($from_learnpath);
			break;
		case "2" : // coming from forum: new topic
			$url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5";
			$originaltoolname = get_lang("ForumAddNewTopic");
			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
			session_unregister('from_learnpath');
			unset ($from_learnpath);
			break;
		case "3" : // coming from forum: edit topic
			$url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no";
			$originaltoolname = get_lang("ForumEditTopic");
			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
			session_unregister('from_learnpath');
			unset ($from_learnpath);
			break;
		case "4" : // coming from exercises: edit topic
			$url = "../exercice/admin.php?modifyAnswers=$modifyAnswers";
			$originaltoolname = get_lang("ExerciseAnswers");
			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
			session_unregister('from_learnpath');
			unset ($from_learnpath);
			break;
		case "5" : // coming from learning path
			$from_learnpath = 'yes';
			Session::write('from_learnpath',$from_learnpath);
			break;
		case "6" : // coming from forum: reply
			$url = "../phpbb/reply.php?topic=$topic&forum=$forum&parentid=$parentid";
			$url = $_SESSION['origintoolurl'];
			$originaltoolname = get_lang("ForumReply");
			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
			session_unregister('from_learnpath');
			unset ($from_learnpath);
			break;
			/*************************************** add Frederik.Vermeire@pandora.be *************************************/

		case "7" : // coming from Ad_Valvas
			if ($action == "edit")
			{
				$url = "../announcements/announcements.php?action=edit&id=49&originalresource=$originalresource";
			}
			elseif ($action == "add")
		{
				$url = "../announcements/announcements.php?action=add&originalresource=$originalresource";
			}
			else
			{
				$url = "../announcements/announcements.php?action=add";
			}
			$originaltoolname = get_lang("AdValvas");
			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
			session_unregister('from_learnpath');
			unset ($from_learnpath);
			break;
			/*************************************** end add Frederik.Vermeire@pandora.be *********************************/

	}
	// We do not come from the learning path. We store the name of the tool & url in a session.
	if ($from_learnpath != 'yes')
	{
		if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"])
		{
			$_SESSION["origintoolurl"] = $breadcrumbelement["url"];
			$_SESSION["origintoolname"] = $breadcrumbelement["name"];
			$interbreadcrumb = "";
		}
	}

}

// This part of the code is the actual breadcrumb mechanism. If we do not come from the learning path we use
// the information from the session. Else we use the information of the learningpath itself.
if ($from_learnpath != 'yes')
{
	$nameTools = get_lang('AddResource');
	$interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]);
}
else
{
	$learnpath_select_query = "	SELECT * FROM $tbl_learnpath_main
		  								WHERE learnpath_id=$learnpath_id";
	$sql_result = Database::query($learnpath_select_query);
	$therow = Database::fetch_array($sql_result);

	$learnpath_chapter_query = "	SELECT * FROM $tbl_learnpath_chapter
		  								WHERE (learnpath_id = '$learnpath_id' and id = '$chapter_id')";
	$sql_result = Database::query($learnpath_chapter_query);
	$therow2 = Database::fetch_array($sql_result);

	$from_learnpath = 'yes';
	session_register('from_learnpath');
	$interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath'));
	$interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}");
	$interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}");

}

$htmlHeadXtra[] = '<script type="text/javascript">
/* <![CDATA[ */
	function targetfunc(input)
	{
		window.location=window.location+"&amp;target="+document.learnpath_link.target.value;
	}
/* ]]> */
</script>';

Display :: display_header($nameTools);

echo "<h3>".$nameTools;
if ($from_learnpath == 'yes')
{
	echo get_lang("AddResource")." - {$therow2['chapter_name']}";
}
echo "</h3>";

// we retrieve the tools that are active.
// We use this to check which resources a student may add (only the modules that are active)
// see http://www.dokeos.com/forum/viewtopic.php?t=4858
$active_modules=array();
$tool_table = Database::get_course_table(TABLE_TOOL_LIST);
$sql_select_active="SELECT * FROM $tool_table WHERE visibility='1'";
$result_select_active=Database::query($sql_select_active);
while ($row=Database::fetch_array($result_select_active))
{
	$active_modules[]=$row['name'];
}


?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="300" valign="top" style='padding-right:15px;'>
      <table width="300" border="0" cellspacing="0" cellpadding="0" style='border-right:1px solid grey;'>
		<?php if ($from_learnpath != 'yes') { ?>
		<tr>
          <td width="26%"><b><?php echo get_lang('CourseResources'); ?></b></td>
        </tr>
        <?php
        if (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))
        {
        ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Document&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Document')."</a>"; ?></td>
        </tr>
        <?php
        }
        if (api_is_allowed_to_edit() OR in_array(TOOL_CALENDAR_EVENT,$active_modules))
        {
        ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Agenda&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Agenda')."</a>"; ?></td>
        </tr>
        <?php
        }
        if (api_is_allowed_to_edit() OR in_array(TOOL_ANNOUNCEMENT,$active_modules))
        {
        ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Ad_Valvas&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('AdValvas')."</a>"; ?></td>
        </tr>
        <?php
        }
        if (api_is_allowed_to_edit() OR in_array(TOOL_BB_FORUM,$active_modules))
        {
        ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Forum&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Forum')."</a>"; ?></td>
        </tr>
        <?php
        }
        if (api_is_allowed_to_edit() OR in_array(TOOL_LINK,$active_modules))
        {
        ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Link&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Link')."</a>"; ?></td>
        </tr>
        <?php
        }
        if (api_is_allowed_to_edit() OR in_array(TOOL_QUIZ,$active_modules))
        {
        ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Exercise&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Exercise')."</a>"; ?></td>
        </tr>

		<?php
        }

}
else
{
?>



		<tr>
          <td width="26%"><b><?php echo get_lang('ExportableCourseResources'); ?></b></td>
        </tr>
<?php if ($multi_level_learnpath === true ) { ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=chapter&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Chapter')."</a>"; ?></td>
        </tr>
<?php } ?>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Document&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Document')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Exercise&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Exercise')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Link&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Link')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Forum&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Forum')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Agenda&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Agenda')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Ad_Valvas&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('AdValvas')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Course_description&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('CourseDescription')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Introduction_text&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('IntroductionText')."</a>"; ?></td>
        </tr>
		<tr>
          <td>&nbsp;</td>
        </tr>
		<tr>
          <td width="26%"><b><?php echo get_lang('DokeosRelatedCourseMaterial'); ?></b></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Dropbox&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Dropbox')."</a>"; ?></td>
        </tr>
		<tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Assignment&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Assignments')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Groups&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Groups')."</a>"; ?></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Users&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Users')."</a>"; ?></td>
        </tr>

		<?php

}
?>



		<tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td><b><?php echo get_lang("ExternalResources"); ?></b></td>
        </tr>
        <tr>
          <td><?php echo "<a href=\"".api_get_self()."?content=Externallink&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ExternalLink')."</a>"; ?></td>
        </tr>
		<?php

if ($from_learnpath != 'yes')
{
	echo "<tr><td>&nbsp;</td></tr>";
	echo "<tr><td><b>".get_lang('ResourcesAdded')." (";
	echo count($addedresource);
	echo ")</b></td></tr>";
	echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>";
	echo "</td></tr>";
}
?>
        <tr>
          <td>&nbsp;</td>
        </tr>
        <!--<tr>
          <td><b><?php echo get_lang('BackTo'); ?></b></td>
        </tr>//-->
        <tr>
          <td>

		  <?php

if ($from_learnpath != 'yes')
{
	echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>";
}
else
{
	echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".'  '.get_lang('Ok').'  '."\"></form>";
}
?>

          </td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
    </td>
    <td valign="top">
      <?php

if ($resource_added)
{
	Display :: display_normal_message(get_lang("ResourceAdded"));
}

if ($from_learnpath != 'yes')
{
	echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>";
}
//echo "<hr>";

// Agenda items -->
if ($content == "Agenda")
{
	$TABLEAGENDA 			= Database::get_course_table(TABLE_AGENDA);
	$TABLE_ITEM_PROPERTY 	= Database::get_course_table(TABLE_ITEM_PROPERTY);

	$sql="SELECT agenda.*, toolitemproperties.*
					FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
					WHERE agenda.id = toolitemproperties.ref
					AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
					AND toolitemproperties.to_group_id='0'
					AND toolitemproperties.visibility='1'";

	$result = Database::query($sql);

	while ($myrow = Database::fetch_array($result))
	{
		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
		echo "<img src='../img/agenda.gif' alt='agenda'>";
		echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />";
		echo "<b>".$myrow["title"]."</b></td></tr><tr><td>";
		echo $myrow["content"]."<br />";
		showorhide_addresourcelink($content, $myrow["id"]);
		echo "</td></tr></table><br />";
	}
} // end if ($_GET["resource"]=="Agenda")

/*
-----------------------------------------------------------
	chapter
-----------------------------------------------------------
*/
if ($content == "chapter")
{
	echo '<table><form name="add_chapter" action="'.'" method="POST">'."\n";
	echo '  <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n";
	echo '  <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n";
	echo '  <tr><td></td><td><input type="submit" name="add_chapter" value="'.get_lang('AddIt').'"/></td></tr>'."\n";
	echo '</form></table>'."\n";
	//echo "<hr>";
}

/*
-----------------------------------------------------------
	Documents
-----------------------------------------------------------
*/
// We show the documents in the following cases
// 1. the link to add documenets in the resource linker was clicked
// 2. we come to the resource linker for the first time (documents = default). In this case it can only be shown if
//  			a. one is a teacher (documents can be shown even if the tool is inactive)
//				b. one is a student AND the documents tool is active. Student cannot add documents if the documents tool is inactive (teacher can do this)
if ($content == "Document" OR (empty($content) AND (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))) AND !$_GET['showresources'])
{
	// setting variables for file locations
	$baseServDir = $_configuration['root_sys'];
	$courseDir = $_course['path']."/document";
	$baseWorkDir = $baseServDir.$courseDir;
	// showing the link to move one folder up (when not in the root folder)
	show_folder_up();
	// showing the blue bar with the path in it when we are not in the root
	if (get_levels($folder))
	{
		echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">";
		echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>";
		echo $folder."</b></font></td></tr></table>";
	}

	// showing the documents and subfolders of the folder we are in.
	show_documents($folder);
	//echo "<hr>";
}

/*
-----------------------------------------------------------
	Ad Valvas
-----------------------------------------------------------
*/
if ($content == "Ad_Valvas")
{
	$tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT);
	$sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i  WHERE i.tool = '".TOOL_ANNOUNCEMENT."' AND a.id=i.ref AND i.visibility='1' AND i.to_group_id = 0 AND i.to_user_id IS NULL ORDER BY a.display_order ASC";

	$result = Database::query($sql);
	while ($myrow = Database::fetch_array($result))
	{
		echo "<table width=\"100%\"><tr><td>";
		echo "<img src='../img/valves.gif' alt='advalvas'>";
		echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get());
		echo "</td></tr><tr><td>";
		echo $myrow["title"]."<br />";
		showorhide_addresourcelink($content, $myrow["id"]);
		echo "</td></tr></table>";
	}
}

/*
-----------------------------------------------------------
	Forums
-----------------------------------------------------------
*/
if ($content == "Forum")
{
	$TBL_FORUMS 		= Database::get_course_table(TABLE_FORUM);
	$TBL_CATAGORIES 	= Database::get_course_table(TABLE_FORUM_CATEGORY);
	$TBL_FORUMTOPICS 	= Database::get_course_table(TABLE_FORUM_POST);
	$tbl_posts 			= Database::get_course_table(TABLE_FORUM_POST);
	$tbl_posts_text 	= Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);

	echo "<table width='100%'>";

	// displaying the categories and the forums
	if (!$forum and !$thread)
	{
		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
		$result = Database::query($sql);
		while ($myrow = Database::fetch_array($result))
		{
			if ($myrow["cat_title"] !== $old_cat_title)
			{
				echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
			}
			$old_cat_title = $myrow["cat_title"];
			echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>";
			showorhide_addresourcelink("Forum", $myrow["forum_id"]);
			echo "</td></tr>";
		}
	}
	//displaying all the threads of one forum
	if ($forum)
	{
		// displaying the category title
		$sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
		$result = Database::query($sql);
		$myrow = Database::fetch_array($result);
		echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";

		// displaying the forum title
		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
		$result = Database::query($sql);
		$myrow = Database::fetch_array($result);
		echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";

		if (!$thread)
		{
			// displaying all the threads of this forum
			$sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
			$result = Database::query($sql);
			while ($myrow = Database::fetch_array($result))
			{
				echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
				showorhide_addresourcelink("Thread", $myrow["topic_id"]);
				echo "</td></tr>";
			}
		}
		else
		{
			// displaying all the replies
			$sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
			$result = Database::query($sql);
			while ($myrow = Database::fetch_array($result))
			{
				echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
				echo $myrow["post_text"]."</td>";
				echo "<td>";
				showorhide_addresourcelink("Post", $myrow["post_id"]);
				echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>";
			}

		}
	}
	echo "</table>";
}

/*
-----------------------------------------------------------
	Links
-----------------------------------------------------------
*/
if ($content == "Link")
{
	// including the links language file
	include ("../lang/$language/link.inc.php");

	// including the links functions file
	require_once api_get_path(LIBRARY_PATH).'link.lib.php';

	$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
	if (($learnpath_id != '') and ($content == 'Link'))
	{
		echo "<form name='learnpath_link'><table>";
		echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' ";
		if ($target == '_self')
		{
			echo "selected";
		}
		echo ">".get_lang('SameWindow')."</option><option value='_blank'";
		if ($target == '_blank')
		{
			echo "selected";
		}
		echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>";
	}

	// showing the links that are in the root (having no category)
	$sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'";
	$result = Database::query($sql);
	if (Database::num_rows($result) > 0)
	{
		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
		while ($myrow = Database::fetch_array($result))
		{
			echo "<img src='../img/links.gif'>".$myrow["title"];
			echo "<br>";
			showorhide_addresourcelink($content, $myrow["id"]);
			echo "<br><br>";
		}
	}

	// showing the categories and the links in it.
	$sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
	$resultcategories = Database::query($sqlcategories) or die;
	while ($myrow = @ Database::fetch_array($resultcategories))
	{
		$sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC";
		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
		$result_links = Database::query($sql_links);
		while ($myrow = Database::fetch_array($result_links))
		{
			echo "<img src='../img/links.gif' />".$myrow["title"];
			echo "<br>";
			showorhide_addresourcelink($content, $myrow["id"]);
			echo "<br><br>";
		}
	}
}

/*
-----------------------------------------------------------
	Exercise
-----------------------------------------------------------
*/
if (($content == "Exercise") or ($content == "HotPotatoes"))
{
	$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
	$result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
	while ($myrow = Database::fetch_array($result))
	{
		echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
		showorhide_addresourcelink($content, $myrow["id"]);
		echo "<br><br>";
	}

	if ($from_learnpath == 'yes')
	{
		$uploadPath = "/HotPotatoes_files";
		$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
		$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
		$sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC";
		$result = Database::query($sql);
		while ($myrow = Database::fetch_array($result))
		{
			$path = $myrow["path"];
			echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
			showorhide_addresourcelink("HotPotatoes", $myrow["id"]);
			echo "<br><br>";

		}
	}
}

/*
-----------------------------------------------------------
	External Links
-----------------------------------------------------------
*/
if ($content == "Externallink")
{
?>
  <form name="form1" method="post" action="">
  <table width="80%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="right"><?php echo get_lang('ExternalLink'); ?> : &nbsp;</td>
      <td align="left"><input name="external_link" type="text" id="external_link" value="http://"></td>
	  <?php

	if ($learnpath_id != '')
	{
		echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>";
	}
?>
	</tr>
    <tr>
      <td><?php if ($is_allowedToEdit) {echo get_lang('AddToLinks');} ?></td>
      <td>
  	  <?php if ($is_allowedToEdit){?>
	  <select name="add_2_links" id="add_2_links">
      <option value="niet toevoegen" selected="selected">-<?php echo get_lang('DontAdd'); ?>-</option>
	  <option value="0"><?php echo get_lang('MainCategory'); ?></option>
		<?php

	$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
	$sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC";
	echo $sql;
	$result = Database::query($sql);
	while ($row = Database::fetch_array($result))
	{
		echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
	}
?>

      </select><?php } ?></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="external_link_submit" type="submit" id="external_link_submit" value="<?php echo get_lang('AddIt'); ?>"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
  </table>
</form>
	<?php

}

/*
-----------------------------------------------------------
	Assignments
-----------------------------------------------------------
*/
if ($content == "Assignment")
{
	echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>";
}

/*
-----------------------------------------------------------
	Dropbox
-----------------------------------------------------------
*/
if ($content == "Dropbox")
{
	echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>";
}

/*
-----------------------------------------------------------
	Introduction text
-----------------------------------------------------------
*/
if ($content == "Introduction_text")
{
	echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>";
}

/*
-----------------------------------------------------------
	Course description
-----------------------------------------------------------
*/
if ($content == "Course_description")
{
	echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>";
}

/*
-----------------------------------------------------------
	Groups
-----------------------------------------------------------
*/
if ($content == "Groups")
{
	echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>";
}

/*
-----------------------------------------------------------
	Users
-----------------------------------------------------------
*/
if ($content == "Users")
{
	echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>";
}

if ($showresources)
{
	//echo "<h4>".get_lang('ResourceAdded')."</h4>";
	display_resources(1);
}

echo "</td></tr></table>";

/*
		FOOTER
*/
Display :: display_footer();
?>

Hacked By AnonymousFox1.0, Coded By AnonymousFox