<?php
// include libraries
require_once("../setup.php");
function list_files($dir) {
$file_list = '';
$stack[] = $dir;
while ($stack) {
$current_dir = array_pop($stack);
if ($dh = opendir($current_dir)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '.' AND $file !== '..') {
$current_file = "{$current_dir}".DIRECTORY_SEPARATOR."{$file}";
if (is_file($current_file)) {
$file_list[] = "{$current_dir}".DIRECTORY_SEPARATOR."{$file}";
} elseif (is_dir($current_file)) {
$stack[] = $current_file;
}
}
}
}
}
return $file_list;
}
if($logged_in != 1) { //not logged
error_catcher(1);
exit;
}else{
// check if the user can access the page
authorized_to_access_page('add_edit_object');
if(isset($_GET['file'])){
updateFirstFile($_GET['file'],$_GET['id']);
if(isset($_SESSION['mode']) && isset($_SESSION['location'])){
if($_SESSION['mode']=='edit'){
header ("Location: http://".$_SERVER['HTTP_HOST'].$_SESSION['location']."?action=object_info&id=".$_GET['id']);
unset($_SESSION['mode']);
unset($_SESSION['location']);
}
}else{
header ("Location: ../home/home.php?action=object_info&id=".$_GET['id']);
}
}else{
// check for parameters
if(!isset($_GET['id'])){
@ob_clean();
error_catcher(44);
exit;
}
?>
<div id="content_area">
<p class="pagetitle"><?php echo get_string('object', 'ObjectFirstFileTitle'); ?></p>
<table width="80%" border="0" cellspacing="4" cellpadding="4" align="center">
<?php
$objID = $_GET['id'];
$files_array=list_files($CFG->uploaddir.DIRECTORY_SEPARATOR.$objID.DIRECTORY_SEPARATOR.$objID);
$num = count($files_array);
for($i=0;$i<$num;$i++){
//Absolute local link to the file
$path_to_file = str_replace($CFG->uploaddir.DIRECTORY_SEPARATOR.$objID.DIRECTORY_SEPARATOR.$objID.DIRECTORY_SEPARATOR,"",$files_array[$i]);
//Link to the file for preview (it's an url)
$current_file = $CFG->main_url."/file.php".substr($files_array[$i],strlen($CFG->uploaddir),strlen($files_array[$i]));
str_replace(DIRECTORY_SEPARATOR,"/",$current_file);
//Print the table entry that shows the file path and the view link
print("<tr class=\"txt\"><td><a href=\"../admin/add_object_first_file.php?file=$path_to_file&id=$objID\">$path_to_file</a></td><td><a href=\"$current_file\" target=\"_blank\">".get_string('object', 'ObjectFirstFileViewLink')."</a></td></tr>");
}
?>
</table>
</div>
<?php
}
}
?>cd