<?php
/*
This file is part of EdLite.
Copyright (C) 2005 Philip Spears and Philip Allen
Edlite is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Edlite is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with EdLite; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Version: 2005081900
*/
/*
need error check if directory $directory_entry./files/ does not exist!!!
*/
$student_name = str_replace(dirname(dirname(getcwd()))."/", "", dirname(getcwd()));
$course_name = str_replace(dirname(dirname(dirname(getcwd())))."/", "", dirname(dirname(getcwd())));
$title = "Homework Folder";
//printf ("stu:".$student_name."<br />course:".$course_name."<br />title:".$title."<br />");
if (file_exists("./header.html")) { include ("./header.html"); }
if ($HTTP_POST_VARS['post'] == "delete") {
$delete = $HTTP_POST_VARS['delete'];
foreach ($delete as &$delete_folder) {
/* file count */
$file_count = "0";
$files_dir = dir("./$delete_folder/files");
while (false !== ($files_dir_entry = $files_dir->read())) {
if ($files_dir_entry != "." && $files_dir_entry != ".." && is_dir($files_dir_entry) != "1"){
$file_count++;
} // end if for file count
} // end while for files dir count
if ($file_count != "0") { // if there is files
printf("<div class=\"box_noborder\">");
printf("please delete files from ".$delete_folder." first");
printf("</div><br />");
} else {
// printf("delete:".$delete_folder."<br />");
rmdir($delete_folder."/files");
unlink($delete_folder."/footer.html");
unlink($delete_folder."/header.html");
unlink($delete_folder."/index.php");
rmdir($delete_folder);
// unlink($delete_folder."/files");
} // end if files exist check
}// loop foreach delete[#] check box
/*<div class="box_noborder">
You are not authorized to delete folders.
</div>*/
?>
<?php
}
elseif ($HTTP_POST_VARS['post'] == "create") {
/* recursive copy function */
function copyr($source, $dest)
{
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
copyr("$source/$entry", "$dest/$entry");
}
}
// Clean up
$dir->close();
return true;
}// end recursive copy function
$new_folder = $HTTP_POST_VARS['new_folder'];
if ($new_folder == ""){
?>
<div class="box_noborder">
Error : You must name your new folder!
</div>
<?php
}elseif ($new_folder == "folder_structure") {
?>
<div class="box_noborder">
Error : The folder "folder_structure" is a reserved folder name, please choose another folder name
</div>
<?php
}else{
copyr ("../../../../templates/folder_template", $new_folder);
}
} // end if post == value.
?>
<form action="index.php" method="post">
<div class="box">
<table cellpadding="1" cellspacing="0" width="100%">
<tr class="titlebar">
<td colspan="2"> </td><td><span class="white">Folder Name</span></td><td align="right"><span class="white">Number of Files</span></td>
</tr>
<?php
// $td_highlight = "";// temporary definition until I figure out what I'm doing with uploading.
// $highlight = "false"; // temporary definition read above.
$i = "0";
$row_color = "light";
$directories = dir("./");
while (false !== ($directory_entry = $directories->read())) {
if ($directory_entry != "." && $directory_entry != ".." && is_dir($directory_entry) == "1" && $directory_entry != "folder_structure") {
/* Highlight if file created section */
if ($directory_entry == $new_folder) {
$highlight = "true";
$td_highlight = " class=\"highlight\"";
} else {
$highlight = "false";
$td_highlight = "";
}
/* file count section */
$file_count = "0";
$files_dir = dir("./$directory_entry/files");
while (false !== ($files_dir_entry = $files_dir->read())) {
if ($files_dir_entry != "." && $files_dir_entry != ".." && is_dir($files_dir_entry) != "1"){
$file_count++;
} // end if for file count
} // end while for files dir count
if ($highlight == "true") {
?>
<tr class="highlight">
<?php
} else {
?>
<tr class="<?php printf($row_color); ?>">
<?php
}//end if highlight
?>
<td<?php printf($td_highlight); ?>><input name="delete[<?php printf($i); ?>]" value="<?php printf ($directory_entry); ?>" type="checkbox"></td>
<td<?php printf($td_highlight); ?>><a href="<?php printf ($directory_entry); ?>/index.php"><img alt="Folder" src="../../../../images/folder_icon.gif" title="Folder"></a></td>
<td<?php printf($td_highlight); ?>><a<?php printf($td_highlight); ?> href="<?php printf ($directory_entry); ?>/index.php"><?php printf ($directory_entry); ?></a></td>
<td align="right"<?php printf($td_highlight); ?>><?php printf($file_count); ?></td>
</tr>
<?php
if ($row_color == "light") { $row_color = "white"; } else { $row_color = "light"; };
$i++;
}// end if dir "." and ".." and "isdir" checks
}//end while
$directories->close();
if ($i == "0") {
?>
<tr class="highlight">
<td class="highlight" colspan="4">
No folders have been created.
</td>
</tr>
<?php
}// end if i="0" aka if no files exist!
?>
</table>
</div>
<div class="box_noborder">
<input type="hidden" name="post" value="delete">
<input type="submit" value="Delete">
</div>
</form>
<form action="index.php" method="post">
<div class="box">
<div class="titlebar"> Name and create a folder.</div><br />
<input name="new_folder" type="text">
<input name="post" type="hidden" value="create">
<input type="submit" value="Create">
<br /><br />
</div>
</form>
<?php
if (file_exists("./footer.html")) { include ("./footer.html"); }
?>