312 lines
16 KiB
PHP
312 lines
16 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$action = "system-cleanup";
|
|
$CurrentTable = "";
|
|
$FormFile = "";
|
|
$TitleText = "Application and System Cleanup";
|
|
$OrderBy = "";
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = getLanguageText('TEXT-SYSTEM-CLEANUP');
|
|
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
endTemplate();
|
|
exit();
|
|
}
|
|
|
|
|
|
$school_num = $school_record['record_num'];
|
|
|
|
|
|
// Get naction if it has been posted
|
|
unset($naction);
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
|
|
// If naction is set then perform the next action
|
|
if (isset($naction) && strlen($naction) > 0) {
|
|
|
|
if ($_SESSION['UserInfo']['type'] != 'SuperUser' && $school_num == 3) {
|
|
header("Location: /?error_message=".urlencode("System Reset Not Permitted on Demo Site $school_num"));
|
|
exit();
|
|
}
|
|
|
|
switch ($naction) {
|
|
case 'delete-schedules':
|
|
if (array_key_exists('selected_schedule',$_POST) && strlen($_POST['selected_schedule']) > 0) $selected_schedule = $_POST['selected_schedule'];
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM');
|
|
include "system_cleanup.options.php";
|
|
header("Location: /?action=system-cleanup&error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
// Get menu numbers for this schedule
|
|
$menus = db_query("SELECT record_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
if (db_num_rows($menus) > 0) {
|
|
while ($row = db_fetch_array($menus)) {
|
|
$menu_num = $row['record_num'];
|
|
|
|
// Get all items for this menu date
|
|
$items = db_query("SELECT record_num FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num");
|
|
if (db_num_rows($items) > 0) {
|
|
while ($row = db_fetch_array($items)) {
|
|
$item_num = $row['record_num'];
|
|
db_query("DELETE FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $item_num");
|
|
}
|
|
}
|
|
|
|
db_query("DELETE FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num");
|
|
}
|
|
}
|
|
|
|
db_query("DELETE FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_menu_transactions WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM supplier_order_items WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM supplier_order_header WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $selected_schedule");
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM user_account_detail WHERE school_num = $school_num AND posted_schedule = $selected_schedule");
|
|
|
|
$form_message = getLanguageText('MSG-SCHEDULE-DELETED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'delete-all-schedules':
|
|
$today = date("Y-m-d",time());
|
|
$query = "SELECT * FROM hotlunch_schedules WHERE school_num = $school_num AND schedule_end_date < '$today'";
|
|
$schedules = db_query($query);
|
|
|
|
while ($srow = db_fetch_assoc($schedules)) {
|
|
$selected_schedule = $srow['record_num'];
|
|
|
|
// Get menu numbers for this schedule
|
|
$menus = db_query("SELECT record_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
if (db_num_rows($menus) > 0) {
|
|
while ($row = db_fetch_array($menus)) {
|
|
$menu_num = $row['record_num'];
|
|
|
|
// Get all items for this menu date
|
|
$items = db_query("SELECT record_num FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num");
|
|
if (db_num_rows($items) > 0) {
|
|
while ($row = db_fetch_array($items)) {
|
|
$item_num = $row['record_num'];
|
|
db_query("DELETE FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $item_num");
|
|
}
|
|
}
|
|
|
|
db_query("DELETE FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num");
|
|
}
|
|
}
|
|
|
|
db_query("DELETE FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_menu_transactions WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM supplier_order_items WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM supplier_order_header WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $selected_schedule");
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM user_account_detail WHERE school_num = $school_num AND posted_schedule = $selected_schedule");
|
|
}
|
|
|
|
$form_message = getLanguageText('MSG-SCHEDULE-DELETED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'delete-schedule-orders':
|
|
if (array_key_exists('selected_schedule',$_POST) && strlen($_POST['selected_schedule']) > 0) $selected_schedule = intval($_POST['selected_schedule']);
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM');
|
|
header("Location: /?action=system-cleanup&error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
if ($selected_schedule > 0) {
|
|
db_query("DELETE FROM hotlunch_menu_transactions WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM supplier_order_items WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM supplier_order_header WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $selected_schedule");
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num AND schedule_num = $selected_schedule AND transaction_amount >= 0");
|
|
db_query("DELETE FROM user_account_detail WHERE school_num = $school_num AND posted_schedule = $selected_schedule");
|
|
}
|
|
|
|
if ($selected_schedule == -1) {
|
|
db_query("DELETE FROM hotlunch_menu_transactions WHERE school_num = $school_num");
|
|
db_query("DELETE FROM supplier_order_items WHERE school_num = $school_num");
|
|
db_query("DELETE FROM supplier_order_header WHERE school_num = $school_num");
|
|
db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num");
|
|
db_query("DELETE FROM hotlunch_order_header WHERE school_num = $school_num");
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num");
|
|
db_query("DELETE FROM user_account_detail WHERE school_num = $school_num");
|
|
}
|
|
|
|
$form_message = getLanguageText('MSG-SCHEDULE-ORDERS-DELETED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'delete-parents':
|
|
if ($_SESSION['UserInfo']['type'] != 'SuperUser') {
|
|
$dt = date("md",time());
|
|
if ($dt <= '0501' || $dt >= '1031') {
|
|
$error_message = getLanguageText('TEXT-SYSTEM-RESET-AVAILABILITY');
|
|
header("Location: /?action=system-cleanup&error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
}
|
|
|
|
|
|
$linked_sites = $school_record['linked_sites'];
|
|
|
|
db_query("delete from users where school_num = $base_school_num and type in ('Parent','Administration Team','Schedule Team','Volunteer Administrator','Guest')");
|
|
db_query("delete from user_account where school_num IN ($linked_sites)");
|
|
db_query("DELETE FROM user_account_detail WHERE school_num IN ($linked_sites)");
|
|
|
|
db_query("delete from user_online_payments where school_num IN ($linked_sites)");
|
|
// db_query("delete from user_paypal_transactions where school_num IN ($linked_sites)");
|
|
db_query("update user_paypal_transactions set error_handled = 'Y', current_year = 'N' where school_num IN ($linked_sites)");
|
|
db_query("delete from user_exact_transactions where school_num IN ($linked_sites)");
|
|
db_query("delete from user_merchant_account_transactions where school_num IN ($linked_sites)");
|
|
|
|
db_query("delete from people where school_num = $base_school_num and people_type = 'Student'");
|
|
db_query("delete from people where school_num = $base_school_num and people_type = 'Customer'");
|
|
db_query("delete from allergies where school_num = $base_school_num");
|
|
|
|
db_query("delete from hotlunch_order_items where school_num IN ($linked_sites)");
|
|
db_query("delete from hotlunch_order_header where school_num IN ($linked_sites)");
|
|
db_query("delete from hotlunch_order_items_save where school_num IN ($linked_sites)");
|
|
db_query("delete from hotlunch_order_header_deleted where school_num IN ($linked_sites)");
|
|
// db_query("delete from hotlunch_order_log where school_num IN ($linked_sites)");
|
|
|
|
db_query("delete from login_log where school_num IN ($linked_sites)");
|
|
db_query("delete from support_requests where school_num IN ($linked_sites)");
|
|
|
|
db_query("delete from hotlunch_volunteers where school_num IN ($linked_sites)");
|
|
db_query("delete from hotlunch_volunteer_tasks where school_num IN ($linked_sites)");
|
|
|
|
$today = date("Y-m-d",time());
|
|
$now = date("Y-m-d H:i:00",time());
|
|
db_query("update hotlunch_schedules set status = 'Completed' where school_num = $school_num and status = 'Open' and end_order_datetime < '$now'");
|
|
|
|
db_query("delete from event_calendar where school_num = $school_num and end_date < '$today'");
|
|
db_query("delete from classified_ads where school_num = $school_num");
|
|
db_query("delete from forums where school_num = $school_num");
|
|
db_query("delete from forum_threads where school_num = $school_num");
|
|
|
|
$form_message = getLanguageText('MSG-PARENTS-DELETED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'delete-transactions':
|
|
db_query("delete from hotlunch_order_items where school_num = $school_num");
|
|
db_query("delete from hotlunch_order_items_save where school_num = $school_num");
|
|
db_query("delete from hotlunch_order_header where school_num = $school_num");
|
|
db_query("delete from hotlunch_order_header_deleted where school_num = $school_num");
|
|
// db_query("delete from hotlunch_order_log where school_num = $school_num");
|
|
|
|
db_query("delete from hotlunch_volunteers where school_num = $school_num");
|
|
db_query("delete from hotlunch_volunteer_tasks where school_num = $school_num");
|
|
|
|
$today = date("Y-m-d",time());
|
|
$now = date("Y-m-d H:i:00",time());
|
|
db_query("update hotlunch_schedules set status = 'Completed' where school_num = $school_num and status = 'Open' and end_order_datetime < '$now'");
|
|
|
|
db_query("delete from user_online_payments where school_num = $school_num");
|
|
// db_query("delete from user_paypal_transactions where school_num = $school_num");
|
|
db_query("update user_paypal_transactions set error_handled = 'Y', current_year = 'N' where school_num = $school_num");
|
|
db_query("delete from user_account where school_num = $school_num");
|
|
db_query("delete from user_account_detail where school_num = $school_num");
|
|
db_query("delete from user_exact_transactions where school_num = $school_num");
|
|
db_query("delete from user_merchant_account_transactions where school_num = $school_num");
|
|
|
|
db_query("update people set status = 'Unverified' where school_num = $school_num and people_type = 'Student'");
|
|
|
|
$form_message = getLanguageText('MSG-TRANSACTIONS-DELETED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'clear-student-classes':
|
|
db_query("UPDATE people SET class_num = 0, meal_location = 0, school_grade = '' WHERE school_num = $school_num AND people_type = 'Student'");
|
|
db_query("UPDATE schools SET allow_parents_to_edit_grade = 'Y', allow_parents_to_edit_students = 'Y' WHERE record_num = $school_num");
|
|
|
|
$form_message = getLanguageText('TEXT-STUDENTS-UPDATED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'delete-staff':
|
|
db_query("delete from users where school_num = $base_school_num and type = 'Staff'");
|
|
db_query("delete from people where school_num = $base_school_num and people_type = 'Staff'");
|
|
db_query("delete from classes where school_num = $school_num");
|
|
|
|
$form_message = getLanguageText('MSG-STAFF-DELETED');
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'delete-suppliers':
|
|
// Delete hotlunch_menu_products entries
|
|
$query = "DELETE FROM hotlunch_menu_products " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND supplier_product_num IN (".
|
|
"SELECT record_num FROM supplier_products " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND supplier_num IN (" .
|
|
"SELECT record_num FROM suppliers " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND status = 'Deleted'))";
|
|
db_query($query);
|
|
|
|
// Delete supplier products
|
|
$query = "DELETE FROM supplier_products " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND supplier_num IN (" .
|
|
"SELECT record_num FROM suppliers " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND status = 'Deleted')";
|
|
db_query($query);
|
|
|
|
// Delete suppliers
|
|
db_query("DELETE FROM suppliers WHERE school_num = $school_num AND status = 'Deleted'");
|
|
$count = db_affected_rows();
|
|
|
|
|
|
if ($count > 0) {
|
|
$form_message = getLanguageText('MSG-SUPPLIERS-DELETED') . " - $count";
|
|
header("Location: /?action=system-cleanup&form_message=".urlencode($form_message));
|
|
exit();
|
|
}
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-NO-FLAGGED-SUPPLIERS');
|
|
header("Location: /?action=system-cleanup&error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
include "system_cleanup.options.php";
|
|
}
|
|
|
|
endTemplate();
|
|
?>
|