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

64 lines
1.6 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
logExit("Session is not active",$moduleName);
exit();
}
// Set userType
$userType = "Parent";
if (array_key_exists('type', $_SESSION['UserInfo']) && in_array($_SESSION['UserInfo']['type'],$AllAdminUserTypes)) $userType = "Admin";
if ($userType != 'Admin') return;
// Ensure that only valid user types have access to this module
if ($userType != 'Admin') {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
logExit($error_message);
exit;
}
// CSRF token validation
include "include/ajax.csrfToken.php";
// Set default timezone
date_default_timezone_set("Canada/Pacific");
$now = date("Y-m-d H:i:s",time());
$return_data = array();
$moduleName = "ajax.deleteSelectedImage.php";
// startLog($moduleName);
// Get parameters
if (array_key_exists('selected_image', $_GET)) $selected_image = db_escape_string($_GET['selected_image']);
if (!isset($selected_image)) logExit("selected_image is not set");
writeLog("selected_image: $selected_image");
$image_path = "files/$subpath/image";
if (!is_file($image_path.'/'.$selected_image)) {
$return_data['ajax_message'] = getLanguageText('ERRORMSG-FILE-NOT-FOUND');
$return_data['ajax_return_code'] = -1;
writeLog("Image not found");
}
else {
unlink($image_path.'/'.$selected_image);
$return_data['ajax_message'] = getLanguageText('MSG-IMAGE-DELETED').": $selected_image";
$return_data['ajax_return_code'] = 0;
writeLog("Image deleted");
}
writeLog("complete\n");
echo(json_encode($return_data));
?>