150 lines
4.4 KiB
PHP
150 lines
4.4 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = "$TitleText " . getLanguageText('TEXT-ATTACHMENT-UPLOAD');
|
|
|
|
|
|
|
|
// Attachments directory set in include/configs.php -- $attachdir
|
|
|
|
// Ensure that only admin users have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Volunteer Administrator','Communications Administrator');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
endTemplate();
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process actions to perform
|
|
//
|
|
//if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
// Cancel a batch is requested
|
|
if ($filename && $naction) {
|
|
|
|
switch ($naction) {
|
|
// delete the file from the attachments folder
|
|
case 'delete':
|
|
@unlink("$attachdir/$filename");
|
|
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case 'save-attach':
|
|
if (isset($_FILES['userfile']['tmp_name'])) {
|
|
$userfile = $_FILES['userfile']['tmp_name'];
|
|
$userfile_name = str_replace(" ","_",$_FILES['userfile']['name']);
|
|
|
|
if (is_uploaded_file($userfile)) {
|
|
if (copy($userfile,"$attachdir/$userfile_name")) {
|
|
$form_message = getLanguageText('MSG-ATTACHMENT-UPLOADED');
|
|
}
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-UNABLE-TO-COPY-UPLOADED');
|
|
}
|
|
}
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-UPLOAD-ERROR');
|
|
}
|
|
}
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-USERFILE-ERROR');
|
|
}
|
|
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// Display form for file upload
|
|
//
|
|
?>
|
|
<table width='60%' class='content-table'>
|
|
<tr>
|
|
<td align='center'>
|
|
<form enctype="multipart/form-data" method="post">
|
|
<p>Attachment to Uploads :: <input type="file" name="userfile"></p>
|
|
<input type="submit" class="button" value="<?php displayLanguageText('TEXT-UPLOAD-FILE'); ?>">
|
|
<input type='hidden' name='action' value='email-attach'>
|
|
<input type='hidden' name='naction' value='save-attach'>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
|
|
|
|
<?php
|
|
// Get set of attachment files
|
|
$files = array();
|
|
$dir = opendir($attachdir);
|
|
$i = 0;
|
|
|
|
while (($file = readdir($dir)) != false) {
|
|
if ($file == ".") continue;
|
|
if ($file == "..") continue;
|
|
$files[] = $file;
|
|
$i+=1;
|
|
}
|
|
sort($files);
|
|
?>
|
|
|
|
<table width='60%' class='content-table'>
|
|
<tr>
|
|
<td align='left' colspan='4'><h3>Attachments List</h3></td>
|
|
</tr>
|
|
<tr bgcolor='#dddddd'>
|
|
<td align='left'><b>File Name</b></td>
|
|
<td align='left'> </td>
|
|
</tr>
|
|
|
|
<?php
|
|
$bgcolors = array("#bbc7c8","#ffffff");
|
|
$count = 0;
|
|
|
|
foreach ($files as $filename) {
|
|
$bgcolor = $bgcolors[$count % 2];
|
|
$count++;
|
|
?>
|
|
|
|
<tr bgcolor='<?php echo($bgcolor) ?>'>
|
|
<td align='left' valign='top' width="80%"><?php echo($filename) ?></td>
|
|
<td align='left' width="20%">
|
|
<table cellpadding='0' cellspacing='2' border='0'>
|
|
<tr>
|
|
<td align='left' class='btn btn--primary btn--xsmall'> <a href="view.php?file=<?php echo $filename ?>" target='_blank'>View</a>
|
|
<td align='left' class='btn btn--primary btn--xsmall'> <a href="/?action=email-attach&filename=<?php echo $filename ?>&naction=delete"
|
|
onClick="return validateDelete();"><?php displayLanguageText('BUTTON-DELETE'); ?></a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
|
|
</table>
|
|
|
|
<script language="JavaScript">
|
|
function validateDelete() {
|
|
return confirm("<?php displayLanguageText('JAVA-DELETE-FILE'); echo('\n'); getLanguageText('JAVA-CONFIRM-DELETE'); ?>");
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
endTemplate();
|
|
?>
|