00001 <?PHP
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 $page_author = $creator_name;
00018 $page_author_email = $creator_email;
00019 $page_menu = 1;
00020 $page_date = formatTime( time() );
00021 $page_title = i18n("File setup");
00022
00023 function filesetup_compare_title($x, $y) { return arrayColumnCompare($x, $y, "title"); }
00024 function filesetup_compare_size($x, $y) { return arrayColumnCompare($x, $y, "size"); }
00025 function filesetup_compare_mimetype($x, $y) { return arrayColumnCompare($x, $y, "mimetype"); }
00026 function filesetup_compare_mtime($x, $y) { return arrayColumnCompare($x, $y, "mtime"); }
00027
00028 if( !auth($_REQUEST["username"], $_REQUEST["password"]) )
00029 $page_content = loginform($language, thisPageURL(), $auth_messages);
00030 else if( isauth() && !isAllowed("global_files") )
00031 $page_content = "<p>" . i18n("You are not authorised to manage files") . "</p>";
00032 else if( isauth() )
00033 {
00034 $setupPage = new setupPage();
00035 $setupPage->addBreadcrumb( i18n("Files"), globalIDtoURL("setup/filesetup") );
00036 $setupPage->addCommand( i18n("Upload file"), i18n("Upload a new file"), globalIDtoURL("setup/filesetup/upload") );
00037
00038
00039 if( $theAction == "upload" )
00040 {
00041 $setupPage->contents = "<form enctype=\"multipart/form-data\" action=\"" . globalIDtoURL("setup/filesetup/uploadcomplete") . "\" method=\"post\">" .
00042 renderInformationBox( i18n("Upload file"),
00043 "<p>" . i18n("Please select the file you wish to upload.") . "</p>
00044 <input style=\"width: 100%;\" name=\"uploadedfile\" type=\"file\" />
00045 <div align=\"center\">
00046 <input type=\"submit\" value=\"" . i18n("Upload file") . "\" />
00047 </div>" ) . "
00048 </form>
00049 ";
00050 }
00051 else if( $theAction == "uploadcomplete" )
00052 {
00053 $uploadFile = $files_folder . "/" . $_FILES['uploadedfile']['name'];
00054 if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadFile) )
00055 {
00056 chmod($uploadFile, 0664);
00057 $setupPage->contents = "<p>" . i18n("The file has been uploaded.") . "</p>";
00058 header("Location: " . globalIDtoURL("setup/filesetup") );
00059 }
00060 else
00061 {
00062 $setupPage->contents = "<p>" . i18n("The file could not be uploaded. The error message can be found below:") . "</p>
00063 <pre>";
00064 switch( $_FILES['uploadedfile']['error'] )
00065 {
00066 case 1:
00067 $setupPage->contents .= "The uploaded file exceeds the upload_max_filesize directive in php.ini.\nPlease contact your host and rectify this (or better yet, select a smaller file.\nMost often, this directive states 2MB as the maximum upload size).";
00068 break;
00069 case 2:
00070 $setupPage->contents .= "The uploaded file exceeds 1MB in size,\nand is too large to upload in this manner.";
00071 break;
00072 case 3:
00073 $setupPage->contents .= "The uploaded file was only partially uploaded.";
00074 break;
00075 case 4:
00076 $setupPage->contents .= "No file was uploaded.";
00077 break;
00078 }
00079 $setupPage->contents .= "</pre>";
00080 }
00081 }
00082 else if( $theAction == "delete" )
00083 {
00084 $dialog = new confirmDeleteDialog( "confirmDelete", i18n("The file with the filename: ##0##", array($deleteFile)), "setup/filesetup/confirm/$deleteFile" );
00085
00086 if( $dialog->submitted )
00087 {
00088 if( $dialog->confirmed )
00089 {
00090 if( unlink("$files_folder/$deleteFile") )
00091 header( "Location: " . globalIDtoURL("setup/filesetup") );
00092 else
00093 $setupPage->contents = renderErrorBox( i18n("Error during delete!"), i18n("Deletion of the file could not be completed! Click your browser's "Refresh" button to try again, or ##0##.", array( drawCommand( i18n("click here to return to the list of files"), i18n(""), globalIDtoURL("setup/filesetup") ) ) ) );
00094 }
00095 else
00096 header( "Location: " . globalIDtoURL("setup/filesetup") );
00097 }
00098 else
00099 $setupPage->contents = $dialog->render();
00100 }
00101 else if( $theAction == "rename" )
00102 {
00103 if( $_POST["new_filename"] != "" )
00104 {
00105 if( rename("$files_folder/$renameFrom","$files_folder/{$_REQUEST['new_filename']}") )
00106 {
00107 $setupPage->contents = "<p>" . i18n("Renaming of the file was successfully completed.") . "</p>";
00108 header("Location: " . globalIDtoURL("setup/filesetup") );
00109 }
00110 else
00111 $setupPage->contents = renderErrorBox( i18n("Renaming failed!"), i18n("Renaming of the file could not be completed! Please click your browser's "Back" button to return to the edit dialog, or the "Refresh" button to try again.") );
00112 }
00113 else
00114 {
00115 $setupPage->contents = "<form action=\"" . globalIDtoURL("setup/filesetup/rename/$renameFrom") . "\" method=\"post\">" .
00116 renderInformationBox( i18n("Type the new file name below"), "
00117 <div align=\"center\"><input type=\"text\" value=\"$renameFrom\" style=\"width: 80%;\" name=\"new_filename\" /></div>
00118 <br />
00119 <div align=\"center\">
00120 <input type=\"submit\" value=\"" . i18n("Rename") . "\" />
00121 <input type=\"reset\" value=\"" . i18n("Reset changes") . "\" />
00122 </div>") . "
00123 </form>";
00124 }
00125 }
00126 else
00127 {
00128 $fp = opendir($files_folder);
00129 while( $file = readdir($fp) )
00130 {
00131 if( substr( $file, 0, 1) != "." )
00132 {
00133 $title = $file;
00134 $weight = fileweight( $files_folder . "/" . $file );
00135 $size = filesize( $files_folder . "/" . $file );
00136 $mimetype = mime_content_type( $files_folder . "/" . $file );
00137 $mtime = filemtime( $files_folder . "/" . $file );
00138 $files_temp[] = array( "title" => $title, "weight" => $weight, "size" => $size, "mimetype" => $mimetype, "mtime" => $mtime );
00139 }
00140 }
00141 closedir($fp);
00142
00143 if( !empty($files_temp) )
00144 {
00145 $alternateRow = false;
00146
00147 $table = new Table("setup", "setup", "setup");
00148
00149 $table->newRow( null, true );
00150 $table->newCell( drawCommand( i18n("Filename"), i18n("Sort by name"), globalIDtoURL("setup/filesetup/", array("sortBy" => "title") ) ) );
00151 $table->newCell( drawCommand( i18n("Filesize"), i18n("Sort by size"), globalIDtoURL("setup/filesetup/", array("sortBy" => "size") ) ) );
00152 $table->newCell( drawCommand( i18n("Filetype"), i18n("Sort by type"), globalIDtoURL("setup/filesetup/", array("sortBy" => "mimetype") ) ) );
00153 $table->newCell( drawCommand( i18n("Last modified"), i18n("Sort by last modified time"), globalIDtoURL("setup/filesetup/", array("sortBy" => "mtime") ) ) );
00154 $table->newCell( i18n("Functions") );
00155
00156 $sortBy = $_REQUEST["sortBy"];
00157 if( $sortBy != null )
00158 usort( $files_temp, "filesetup_compare_$sortBy" );
00159
00160 foreach( $files_temp as $key => $value )
00161 {
00162 if( !is_dir( "$files_folder/$value" ) )
00163 {
00164 $alternateRow = !$alternateRow;
00165
00166 $table->newRow( $alternateRow ? "alternateRow setup" : null );
00167 $table->newCell($value["title"]);
00168 $table->newCell($value["weight"]);
00169 $table->newCell($value["mimetype"]);
00170 $table->newCell( date( "j M Y H:i", $value["mtime"] ) );
00171 $table->newCell(
00172 drawCommand( i18n("Rename"), i18n("Rename the file"), globalIDtoURL("setup/filesetup/rename/" . $value["title"]) ) . " " .
00173 drawCommand( i18n("Delete"), i18n("Delete the file"), globalIDtoURL("setup/filesetup/delete/" . $value["title"]) )
00174 , null, "setup wikirightalign" );
00175 }
00176 }
00177
00178 $setupPage->contents = $table->render();
00179 }
00180 else
00181 $setupPage->contents = renderInformationBox( "No files found", i18n("There are not currently any files uploaded. ##0##" , array( drawCommand( i18n("Click here to upload a file"), i18n("Click here to upload a file"), globalIDtoURL("setup/filesetup/upload") ) ) ) );
00182 }
00183
00184 $page_content = $setupPage->render();
00185 }
00186 ?>