Files
2026-10-19 15:22:52 -07:00

190 lines
5.7 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
//
// Process all actions to list and edit records
//
$CurrentTable = "wallpapers";
$OrderBy = "gallery_title";
// Start the template and output buffering
startTemplate();
$templatePageTitle = getLanguageText('TEXT-WALLPAPER-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'];
$school_num = $school_record['record_num'];
switch (strtolower($naction)) {
case "update":
$count = $_POST['count'];
$table = new Table("wallpapers");
// Process each image
for ($i = 0; $i < $count; $i++) {
$school_num = db_escape_string($_POST["school_$i"]);
$category = db_escape_string($_POST["category_$i"]);
$thumbnail = db_escape_string($_POST["thumb_$i"]);
$wallpaper = db_escape_string($_POST["image_$i"]);
$inDB = db_escape_string($_POST["in_db_$i"]);
if ($category > 0) {
if ($inDB == 'Y') $query = "UPDATE wallpapers SET school_num = $school_num,category = $category WHERE thumbnail = '$thumbnail'";
else $query = $table->BuildInsert();
db_query($query);
}
else {
// If this image is in the db then remove it to unassign it
if ($inDB == 'Y') {
db_query("DELETE FROM wallpapers WHERE thumbnail = '$thumbnail'");
}
}
}
$form_message = getLanguageText('RECORD-UPDATED-MSG');
$naction = "view";
break;
default:
$naction = "view";
break;
}
//
// List all records if naction is "view"
//
if ($naction == "view") {
$scriptName = str_replace("/m/data1/app.hotlunches.net/","",__FILE__);
include "help.docs.php";
// Get list of images to display
// $query = "SELECT wc.category_title,w.* " .
// "FROM wallpapers AS w, wallpaper_categories AS wc " .
// "WHERE wc.record_num = w.category " .
// "AND school_num IN (0,$school_num) " .
// "ORDER BY category_title,thumbnail";
// $results = db_query($query);
?>
<form method='post'>
<table width='600' class='content-table'>
<tr>
<td colspan='2' align='center' class='heading'><?php displayLanguageText('TEXT-WALLPAPER'); ?></td>
</tr>
<?php
// Get list of images
$dir = opendir("backgrounds");
$file_names = array();
while ($file = readdir($dir)) {
if ($file == ".") continue;
if ($file == "..") continue;
if (strstr($file,"-thumb.jpg")) $file_names[] = $file;
}
sort($file_names);
$count = 0;
for ($i = 0; $i < count($file_names); $i++) {
$thumb = $file_names[$i];
$image = str_replace("-thumb","",$thumb);
$count++;
// Check if this image is already in the database
$results = db_query("SELECT * FROM wallpapers WHERE thumbnail = '$thumb'");
$inDB = 'N';
$schoolNum = 0;
$catNum = 0;
if (db_num_rows($results) > 0) {
$row = db_fetch_array($results);
$schoolNum = $row['school_num'];
$catNum = $row['category'];
$inDB = 'Y';
}
?>
<tr>
<td align='center'><img src='backgrounds/<?php echo($thumb) ?>' align='center' width='200' height='130'></td>
<td align='center'>
<b><?php echo("$image / $thumb") ?></b><br>
<br>
<input type='hidden' name='thumb_<?php echo($i) ?>' value='<?php echo($thumb) ?>'>
<input type='hidden' name='image_<?php echo($i) ?>' value='<?php echo($image) ?>'>
<input type='hidden' name='in_db_<?php echo($i) ?>' value='<?php echo($inDB) ?>'>
<select name='school_<?php echo($i) ?>'>
<option value='0'>All Schools</option>
<?php
$schools = db_query("SELECT school_name,record_num FROM schools WHERE status = 'Active' ORDER BY school_name");
while ($row = db_fetch_array($schools)) {
$snum = $row['record_num'];
$sname = $row['school_name'];
$selected = "";
if ($snum == $schoolNum) $selected = " selected='selected'";
echo(" <option value='$snum'$selected>$sname</option>\n");
}
?>
</select>
<br>
<br>
<select name='category_<?php echo($i) ?>'>
<option value='0'>Not Assigned</option>
<?php
$categories = db_query("SELECT * FROM wallpaper_categories ORDER BY category_title");
while ($row = db_fetch_array($categories)) {
$num = $row['record_num'];
$cat = $row['category_title'];
$selected = "";
if ($num == $catNum) $selected = " selected='selected'";
echo(" <option value='$num'$selected>$cat</option>\n");
}
?>
</select>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan='2' align='center'>
<br>
<input type='submit' value='Update' class='btn btn--primary'>
<input type='hidden' name='action' value='wallpapers'>
<input type='hidden' name='naction' value='update'>
<input type='hidden' name='count' value='<?php echo($count) ?>'>
<br>
<br>
</td>
</tr>
</table>
</form>
<?php
}
endTemplate();
?>