Files
HotLunches/photo_gallery_images.php
T
2026-10-19 15:22:52 -07:00

191 lines
6.3 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
//
// Process all actions to list and edit records
//
$CurrentTable = "photo_gallery_images";
$DeleteField = "photo";
$dSeparator = "";
$FormFile = "photo_gallery_images.form.php";
$TitleText = getLanguageText('TEXT-PHOTO-GALLERY');
$OrderBy = "sequence,photo";
$Sequence = 'Y';
// Start the template and output buffering
startTemplate();
$templatePageTitle = "$TitleText " . getLanguageText('TEXT-ADMINISTRATION');
// Ensure that only valid user types have access to this module
$AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator');
if (checkPermission($AllowedUserTypes) != 1) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
$action = '';
$naction = '';
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
exit();
}
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
if (array_key_exists('gallery_num',$_GET)) $gallery_num = intval($_GET['gallery_num']);
if (array_key_exists('gallery_num',$_POST)) $gallery_num = intval($_POST['gallery_num']);
if (array_key_exists('record_num',$_GET)) $record_num = intval($_GET['record_num']);
if (array_key_exists('record_num',$_POST)) $record_num = intval($_POST['record_num']);
$school_num = $school_record['record_num'];
// Get gallery name
$gallery_name = db_getVal("SELECT gallery_title FROM photo_galleries WHERE school_num = $school_num AND record_num = $gallery_num");
switch (strtolower($naction)) {
case "edit":
$PageTitle = getLanguageText('RECORD-UPDATE-ENTRY') . " $TitleText";
$ButtonText = $PageTitle;
$next_naction = "update";
// Get current record
$record_num = intval($_GET['record_num']);
$query = "select * from $CurrentTable where record_num = $record_num";
$results = db_query($query);
if (db_num_rows($results) == 1) {
$row = db_fetch_array($results);
extract($row);
include $FormFile;
}
else {
$error_message = getLanguageText('ERRORMSG-NOT-FOUND');
$naction = 'list';
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
exit();
}
break;
case "delete":
$record_num = intval($_GET['record_num']);
// Verify record exists
$query = "select * from $CurrentTable where record_num = $record_num";
$results = db_query($query);
if (db_num_rows($results) == 1) {
$row = db_fetch_array($results);
extract($row);
$dFields = explode(",",$DeleteField);
$dTitle = "$TitleText ";
for ($i = 0; $i < count($dFields); $i++) {
$dTitle .= $row[$dFields[$i]] . $dSeparator;
}
$HiddenFields = " <input type='hidden' name='gallery_num' value='$gallery_num'>";
include "delete.form.php";
}
else {
$error_message = getLanguageText('ERRORMSG-NOT-FOUND');
$naction = 'list';
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
exit();
}
break;
case 'upload':
include "photo_gallery_images.upload.form.php";
break;
case 'delete-image':
$photo = $_POST['selected_image'];
$dTitle = "Photo: $photo";
$HiddenFields = " <input type='hidden' name='iaction' value='delete-image'>\n" .
" <input type='hidden' name='selected_image' value='$photo'>";
include "delete.form.php";
break;
default:
break;
}
//
// List all records if naction is "list"
//
if ($naction == "list" || $naction == 'list-all') {
?>
<script src="include/TableDnD.js" type="text/javascript"></script>
<?php
$scriptName = str_replace("/m/data1/app.hotlunches.net/","",__FILE__);
include "help.docs.php";
// Get records to display
$columnHeaders = array(getLanguageText('TEXT-PHOTO'),
getLanguageText('TEXT-IMAGE'),
getLanguageText('TEXT-UPLOADED-DATE')
);
$columnAlign = array("left","left","left");
$query = "select photo,thumbnail,image_name,date_uploaded,record_num " .
"from photo_gallery_images " .
"where school_num = $school_num " .
"and gallery_num = $gallery_num " .
"order by sequence,photo";
$results = db_query($query);
$data = array();
$otipSpans = '';
while ($row = db_fetch_array($results)) {
extract($row);
$image_size = GetImageSize("$gallerydir/$thumbnail");
$image_width = $image_size[0];
$image_height = $image_size[1];
$span_id = "img_span$record_num";
$otipSpans .= "<span id='$span_id'>" . sprintf($otipIMG,"$galleryurl/$thumbnail",$image_height,$image_width,$image_name) . "</span>\n";
$photo = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$photo</a>";
$data[] = array($photo,
$image_name,
$date_uploaded,
"record_num" => $record_num);
}
$message_width = $default_data_width;
include "form.messages.php";
echo("<center>\n");
echo("<p><b>$gallery_name - $TitleText List</b></p>\n");
echo("</center>\n");
$action = "$action&gallery_num=$gallery_num";
sortData($data,$columnHeaders,$action,array(),'N',$columnAlign);
?>
<table cellpadding='10'>
<tr>
<td align='center'><a href='?action=photo-gallery-images&gallery_num=<?php echo($gallery_num) ?>&naction=upload' class='btn btn--primary>'>&nbsp;&nbsp;Upload Images&nbsp;&nbsp;</a></td>
<td align='center'><a href='?action=photo-gallery&gallery_num=<?php echo($gallery_num) ?>' class='btn btn--primary>'>&nbsp;&nbsp;View Gallery&nbsp;&nbsp;</a></td>
</tr>
</table>
<?php
}
endTemplate();
?>