$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 
    $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.jpg'>" . 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>
/**
 * 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.
    if (api_is_allowed_to_edit()) {
        $visibility = "ip.visibility<>'2'";
    } else {
        $visibility = "ip.visibility='1'";
    }
    $course_id = api_get_course_int_id();
    $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\n            WHERE\n                docs.c_id = {$course_id} AND\n                ip.c_id = {$course_id} AND\n                docs.id=ip.ref AND\n                ip.tool = '" . TOOL_DOCUMENT . "' AND\n                {$visibility} AND\n                (ip.to_group_id = 0 OR ip.to_group_id IS NULL)AND\n                ip.to_user_id IS NULL\n            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 "&folder=" . substr($row['path'], 1) . "&source_id={$source_id}&source_forum=" . $_GET['source_forum'] . "&action={$action}&lp_id={$learnpath_id}&parent_item_id={$chapter_id}&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);
        }
    }
}
/**
 * Shows the documents of the document tool
 * @param $folder
 */
function show_documents($folder)
{
    $_course = api_get_course_info();
    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 (FileManager::get_levels($row['path']) - 1 == 1) {
                // showing the right icon
                if (file_or_folder($row['path'])) {
                    echo Display::return_icon('file.gif');
                } else {
                    $image = FileManager::choose_image($row['path']);
                    echo Display::return_icon($image);
                }
                // 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 = FileManager::get_levels($folder) + 1;
            // we calculate each level of the database entry
            $file_level = FileManager::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 Display::return_icon('file.gif');
                } else {
                    $image = FileManager::choose_image($path);
                    echo Display::return_icon($image);
                }
                // 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);
        }
    }
}