Files
HotLunches/welcome.php
T
2026-10-20 17:31:06 -07:00

539 lines
24 KiB
PHP

<?php
require_once("include/globals.php");
// Start the template and output buffering
startTemplate();
// $noTitle = 'Y';
$templatePageTitle = $school_record['school_name'];
//
// Handle special user types
//
if ($_SESSION['UserInfo']['type'] == 'Supplier') {
header("Location: /?action=supplier-dashboard");
exit();
}
if (SessionActive() != 1 || !UserLoggedIn()) {
header("Location: /?action=logout");
exit();
}
// $error_message = "The system will be shutting down at 12:30am PST for a brief database update";
// include "form.messages.php";
// echo("<br>");
//
// Get the school content for the login page
//
$content = getPageContent($school_num,"Welcome Page");
$Pcontent = $content;
$studentText = $GlobalText['Students'];
$studentLink = $GlobalText['StudentLink'];
$displayPaymentForm = false;
switch ($school_record['display_students_button']) {
case 'Top':
case 'Both':
case 'Bottom':
break;
default:
$query = "SELECT column_name FROM information_schema.columns WHERE table_schema = '$db_dbname' AND table_name = 'schools' AND column_name = 'display_students_button'";
$cname = db_getVal($query);
if ($cname == 'display_students_button') {
$query = "UPDATE schools SET display_students_button = 'Bottom' WHERE record_num = $school_num";
db_query($query);
}
}
// Check this account's status for an notifications we need to show parents
$account_messages = "";
if (in_array($_SESSION['UserInfo']['type'], array('Parent','Staff','Administration Team','Guest'))) {
$unum = intval($_SESSION['UserInfo']['record_num']);
if ($_SESSION['UserInfo']['type'] == 'Parent') {
if ($school_record['display_students_button'] == 'Top' || $school_record['display_students_button'] == 'Both') include "bottom-buttons.php";
if ($_SESSION['UserInfo']['status'] == 'Pending') {
$account_messages .= "<p>" . getLanguageText('TEXT-LOGIN-ACCOUNT-MESSAGE') . "</p>";
// Update user status
$rnum = intval($_SESSION['UserInfo']['record_num']);
$query = "update users set status = 'Active' where record_num = $rnum";
db_query($query);
$_SESSION['UserInfo']['status'] = 'Active';
}
else {
$query = "select * from people " .
"where school_num = $base_school_num " .
"and user_num = $unum " .
"and people_type = 'Student' " .
"order by last_name,first_name";
$results = db_query($query);
$number_of_students = db_num_rows($results);
if ($number_of_students == 0) {
$results = db_query("SELECT text_data FROM text_data WHERE school_num = $school_num AND text_id = 'No Students Message'");
if (db_num_rows($results)) {
$row = db_fetch_assoc($results);
$message = $row['text_data'];
if (strlen($account_messages)) $account_messages .= "<p>$message</p>";
}
}
else {
if ($_SESSION['UserInfo']['linked_to_num'] != $number_of_students) {
db_query("UPDATE users SET linked_to_num = $number_of_students WHERE record_num = $unum");
}
}
if (emailCheck() == -1) $error_message = getLanguageText('ERRORMSG-NO-EMAIL-ADDRESS');
}
}
// Check that this account has an email address
if (array_key_exists('UserInfo', $_SESSION) && strlen($_SESSION['UserInfo']['email']) == 0) {
$results = db_query("SELECT text_data FROM text_data WHERE school_num = $school_num AND text_id = 'No Email Message'");
if (db_num_rows($results)) {
$row = db_fetch_assoc($results);
$message = $row['text_data'];
if (strlen($account_messages)) $account_messages .= "<p>$message</p>";
}
else {
$account_messages .= "<p>".getLanguageText('TEXT-MISSING-EMAIL-EDIT-MSG')."</p>";
}
}
// Format account messages
if (strlen($account_messages) > 0) {
$content = "<center>\n";
$content .= "<table width='90%' class='content-table'>\n<tr>\n<td align='center'><br>\n$account_messages</td>\n</tr>\n</table>\n";
$content .= "</center>\n";
$content .= "<br>\n";
$content .= $Pcontent;
}
// Check if there is a balance owing and if we should display a message
$user_balance = floatval(db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $unum AND (deleted != 'Y' OR deleted IS NULL)"));
if ($user_balance <= 0.00 && $_SESSION['UserInfo']['can_order'] != 'Yes') {
db_query("UPDATE users SET can_order = 'Yes' WHERE school_num = $school_num AND record_num = $unum");
$_SESSION['UserInfo']['can_order'] = 'Yes';
}
if ($user_balance > 0.00 && $school_record['allow_ordering_with_balance_owing'] == 'N') {
$cdate = date("Y-m-d 00:00:00",time() - 60 * 60 * 24 * $school_record['balance_calculation_days_ago']);
$charges = floatval(db_getVal("SELECT sum(transaction_amount) FROM user_account " .
"WHERE school_num = $school_num " .
"AND user_num = $unum " .
"AND (deleted != 'Y' OR deleted IS NULL) " .
"AND transaction_amount > 0 " .
"AND transaction_datetime <= '$cdate'"));
$payments = floatval(db_getVal("SELECT sum(transaction_amount) FROM user_account " .
"WHERE school_num = $school_num " .
"AND user_num = $unum " .
"AND (deleted != 'Y' OR deleted IS NULL) " .
"AND transaction_amount < 0"));
$difference = $charges + $payments;
if ($difference > $school_record['maximum_order_balance']) {
db_query("UPDATE users SET can_order = 'Balance' WHERE school_num = $school_num AND record_num = $unum");
$_SESSION['UserInfo']['can_order'] = 'Balance';
}
}
if ($user_balance > $school_record['minimum_display_balance']) {
$displayPaymentForm = true;
}
if ($school_record['display_user_account_balance'] == 'Y' || $school_record['display_user_account_balance'] == 'A') {
if ($user_balance > $school_record['minimum_display_balance'] || ($user_balance > 0 && $school_record['display_user_account_balance'] == 'A')) {
$error_message = getLanguageText('TEXT-ACCOUNT-BALANCE') . ": $currencySymbol" . number_format($user_balance,2);
$displayPaymentForm = true;
}
if (($school_record['display_user_account_balance'] == 'A' || ($school_record['implement_donation_option'] == 'Y' && strlen($school_record['donation_charity']))) && $user_balance < 0) {
$form_message = getLanguageText('TEXT-ACCOUNT-BALANCE') . ": $currencySymbol" . number_format(abs($user_balance),2) . " " . getLanguageText('TEXT-CREDIT');
}
}
}
// Perform some system validation for admin users
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator'))) {
$msg = "We have been experiencing a problem with image management. Someone has hacked into the image management module and have been uploading " .
"images to overwrite existing images. We have temporarily shutdown image uplading in the application while we address this problem. " .
"We hope to have this fixed quickly.<br><br>** No data has been affected or accessed, only images **";
// displayStatusMessage($msg,"errorspan");
$today = date("Y-m-d",time());
if ($today < '2023-03-01') {
$msg = "Image uploading functionality has been restored and the problem we were experiencing has been solved.";
displayStatusMessage($msg,"warningspan");
}
// $msg = "We apologize, but we have been experiencing problems with our Hot Lunches voice mail and messages have not been sent to us " .
// "correctly. If you have left us a message recently and not gotten a response we are very sorry. " .
// "This problem has been corrected now.";
// displayStatusMessage($msg,"errorspan");
if ($school_record['paypal_enabled'] == 'Y' && strlen($school_record['paypal_code']) > 0 && $school_record['bambora_enabled'] == 'N') {
$msg = "Want <b>better payment processing</b> at an affordable rate and no hidden fees? " .
"Switch to <a href='https://www.shift4.com/about-us' target='_blank'>Shift4</a> today. " .
"<a href='mailto:siby.fall@shift4.com' Subject='Hot Lunches School Registration'>Switch Today</a>";
// displayStatusMessage($msg,"warningspan");
}
$month = date("m",time());
if ($month >= "02") {
$year = date("Y",time());
$nyear = $year + 1;
$school_year = "$year/$nyear";
$results = db_query("SELECT * FROM invoice_header WHERE school_num = $school_num AND school_year = '$school_year'");
$cInvoice = db_num_rows($results);
if ($school_num != 3 && $cInvoice == 0 && $school_record['reseller'] == 'hotlunch') {
if ($month <= "07") {
$msg = getLanguageText('TEXT-EARLY-BIRD-RENEWALS-NOW-AVAILABLE');
}
else {
$msg = getLanguageText('TEXT-HOTLUNCH-RENEWALS-NOW-AVAILABLE');
}
displayStatusMessage($msg,"warningspan");
}
if ($month <= "06" && $cInvoice == 1) {
$invoice = db_fetch_assoc($results);
if ($invoice['status'] == 'Open') {
$msg = getLanguageText('TEXT-EARLY-BIRD-THANK-YOU');
$msg .= "<br>";
$msg .= getLanguageText('TEXT-DISCOUNT-AVAILABLE-UNTIL-JULY-31');
displayStatusMessage($msg,"warningspan");
}
}
}
$now = date("Y-m-d H:i",time());
if ($now <= '2024-04-19 17:00') {
$msg = "** Please note that Leann will be away from the office for the week of April 15 to 19 and support responses may delayed **";
displayStatusMessage($msg,"errorspan");
}
$msg = "Hot Lunches Support Email: <a href='mailto:support@hotlunches.net' style='color: white'>support@hotlunches.net</a><br>" .
"If you do not hear from us in 24 to 48 hours please call to follow-up - (888)946-8586<br><br>";
$msg .= "** In order to protect the integrity of your data we will only provide support to people who are listed in the 'Application Contacts' **";
displayStatusMessage($msg,"noticespan");
$month = date("m",time());
switch ($month) {
case '05':
case '06':
case '07':
case '08':
case '09':
case '10':
$msg = "Are you new to the Hot Lunches Application or do you have questions about the system?<br>\n" .
"Please book a complimentary session with a member of our team for an online demo";
// displayStatusMessage($msg,"noticespan");
displayStatusMessage($msg,"warningspan");
break;
}
// if ($currentDBMode == "Current" && $school_record['reseller'] == 'hotlunch') {
if ($currentDBMode == "Current") {
$pwhere = "AND post_active = 'Y' ";
if ($school_num == 3) $pwhere = "AND post_active IN ('Y','T') ";
$today = date("Y-m-d",time());
$query = "SELECT * FROM formatted_content " .
"WHERE school_num = 3 " .
"AND post_from_date <= '$today' " .
"AND post_to_date >= '$today' " .
$pwhere .
"ORDER BY post_from_date DESC";
echo("\n\n<!-- POST: $query -->\n\n");
$emails = db_query($query);
if (db_num_rows($emails)) {
while ($row = db_fetch_assoc($emails)) {
$message = $row['content_id'];
$rnum = $row['record_num'];
$link = "email-preview.php?id=$rnum&template=EmailTemplate.html&category=Bulletin";
$msg = "[ <a href='$link' target='popup' " .
"onclick=\"window.open('$link','popup','width=750,height=600'); return false;\" style='color: white;'>$message</a> ]";
$class = "errorspan";
$class = "bulletinspan";
displayStatusMessage($msg,$class);
}
}
}
$schoolHeader = false;
if ($school_record['status'] != 'Linked') {
$query = "SELECT * FROM school_contact_list WHERE school_num = $school_num";
$results = db_query($query);
$numContacts = db_num_rows($results);
if ($numContacts == 0) {
if (!$schoolHeader) displayApplicationNotificationHeader();
$schoolHeader = true;
$message = getLanguageText('ERRORMSG-NO-CONTACTS-DEFINED');
$message .= " - [<a href='?action=application-contacts' style='color: #0000f0'>".getLanguageText('TEXT-APPLICATION-CONTACTS')."</a>]";
$class = "warningspan";
displayStatusMessage($message,$class);
}
}
if ($school_record['registrations_permitted'] == 'None') {
if (!$schoolHeader) displayApplicationNotificationHeader();
$schoolHeader = true;
$message = "-- " . getLanguageText('MESSAGE-PARENT-REGISTRATION-NOT-PERMITTED') . " --";
$class = "errorspan";
displayStatusMessage($message,$class);
}
// Check for open support requests
$num = db_getVal("SELECT count(*) FROM support_requests WHERE school_num = $school_num AND status = 'Open'");
if ($num > 0) {
if (!$schoolHeader) displayApplicationNotificationHeader();
$schoolHeader = true;
$supportLink = "[<a href='?action=view-support-log' style='color: #0000f0'>".getLanguageText('TEXT-VIEW-SUPPORT-LOG')."</a>]";
$message = getLanguageText('TEXT-CURRENT-OPEN-SUPPORT-REQUESTS').": $num - $supportLink";
$class = "warningspan";
displayStatusMessage($message,$class);
}
if ($school_record['implement_meal_locations'] == 'Y') {
$query = "UPDATE people SET class_num = 0 WHERE school_num = $school_num AND class_num IS NULL";
db_query($query);
$query = "UPDATE people SET meal_location = class_num WHERE school_num = $school_num AND meal_location IS NULL";
db_query($query);
$query = "SELECT count(*) FROM people WHERE school_num = $base_school_num AND people_type = 'Staff' AND meal_location IS NULL";
$locationErrors = db_getVal($query);
if ($locationErrors > 0) {
if (!$schoolHeader) displayApplicationNotificationHeader();
$schoolHeader = true;
$msg = "-- " . getLanguageText('TEXT-STAFF-MEAL-LOCATIONS') . " --";
displayStatusMessage($msg,"warningspan");
}
}
$query = "SELECT column_name FROM information_schema.columns WHERE table_schema = '$db_dbname' AND table_name = 'user_paypal_transactions' AND column_name = 'current_year'";
$cname = db_getVal($query);
if ($cname == 'current_year') $numPayPalErrors = db_getVal("SELECT count(*) FROM user_paypal_transactions WHERE school_num = $school_num AND posting_result = 'Error' AND error_handled = 'N' AND current_year != 'N'");
else $numPayPalErrors = db_getVal("SELECT count(*) FROM user_paypal_transactions WHERE school_num = $school_num AND posting_result = 'Error' AND error_handled = 'N'");
if ($numPayPalErrors > 0) {
$msg = "-- " . getLanguageText('TEXT-THERE-ARE-PAYPAL-POSTING-ERRORS') . " - <a href='?action=paypal-log-errors' style='color: #0000f0'>[" . getLanguageText('TEXT-VIEW') . "]</a> --";
displayStatusMessage($msg,"warningspan");
}
if ($school_record['participant_grouping'] != 'None') {
$query = "SELECT count(*) FROM people AS st, users AS u " .
"WHERE st.school_num = $base_school_num " .
"AND people_type = 'Student' " .
"AND u.school_num = $base_school_num " .
"AND st.user_num = u.record_num " .
"AND (class_num IN (0,1,2) OR class_num IS null)";
$numUnassigned = db_getVal($query);
if ($numUnassigned > 0) {
if (!$schoolHeader) displayApplicationNotificationHeader();
$schoolHeader = true;
$msg = "-- $numUnassigned " . getLanguageText('TEXT-STUDENT-NO-CLASS-NUM-LIST') . " - <a href='?action=students&naction=students-without-class-number' style='color: #0000f0'>[" . getLanguageText('TEXT-VIEW') . "]</a> --";
displayStatusMessage($msg,"warningspan");
}
}
if ($school_record['status'] != 'Special' && $currentDBMode == 'Current') {
$days_left = db_getVal("select datediff(expiry_date,curdate()) from schools where record_num = $base_school_num");
if ($days_left < $grace_period && $_SESSION['UserInfo']['userid'] != 'superuser') {
$expiry_message = "-- Application Access Has Expired ($days_left) --";
UserLogout();
unset($_SESSION['db_mode']);
header("Location: /?error_message=".urlencode($expiry_message));
exit();
}
if ($days_left < 0) {
$expiry_message = "-- Warning: Application Access Has Expired. You Will Have Access to the Application for a Grace Period --<br>" .
"Please contact <a href='mailto:sales@hotlunches.net'>sales@hotlunches.net</a> to ensure that your access to the application continues";
$class = "errorspan";
displayStatusMessage($expiry_message,$class);
}
if ($days_left <= 10 && $days_left >= 0) {
$dtext = ($days_left != 1) ? "Days" : "Day";
if ($days_left > 0) $expiry_message = "-- Warning: Application Access Will Expire in " . number_format($days_left) . " $dtext --";
else $expiry_message = "-- Warning: Application Access Will Expire Today. Contact Support Immediately if You Wish to Continue. --";
$class = "errorspan";
displayStatusMessage($expiry_message,$class);
}
if ($days_left <= 60 && $days_left > 10) {
$expiry_message = "-- Warning: Access to the Application Will Expire in " . number_format($days_left) . " days --";
$class = "warningspan";
displayStatusMessage($expiry_message,$class);
}
// if ($school_record['paypal_enabled'] == 'Y' && $school_record['paypal_verified'] != 'Y') {
// echo("<table width='90%' border='0' cellpadding='5' class='notice'><tr><td>");
// include "paypal-msg.htm";
// echo("</td></tr></table>\n");
// }
// switch ($school_record['province']) {
// case 'BC':
// include "job-posting.htm";
// break;
// }
}
}
$extra_break = 'Y';
include "form.messages.php";
$expiry_date = db_getVal("select expiry_date from schools where record_num = $base_school_num");
$days_left = db_getVal("select datediff(expiry_date,curdate()) from schools where record_num = $base_school_num");
if ($currentDBMode == 'Current' && $days_left < $grace_period && $_SESSION['UserInfo']['userid'] != 'superuser') {
$expiry_message = "-- Application Access Has Expired ($expiry_date) --";
UserLogout();
unset($_SESSION['db_mode']);
header("Location: /?error_message=".urlencode($expiry_message));
exit();
}
if (in_array($_SESSION['UserInfo']['type'], array('Parent','Staff','Administration Team','Guest'))) {
if ($user_balance < 0 && $school_record['implement_donation_option'] == 'Y' && strlen($school_record['donation_charity'])) {
if ($school_record['implement_donation_option'] == 'Y') include "donation-form.php";
}
}
//
// Message for everyone
//
// $msg = "The Hot Lunches Application will be offline today at 3pm PST, 6pm EST, for approximately 1 hour for maintenance";
// displayStatusMessage($msg,"errorspan");
if ($action != 'pay-online') {
$pstyle = "";
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator'))) {
echo("<p align='left' id='show-page-content-span'>[<a href='#' id='show-page-content'>".getLanguageText('TEXT-SHOW-PAGE-CONTENT')."</a>]</p>");
echo("<p align='left' id='hide-page-content-span'>[<a href='#' id='hide-page-content'>".getLanguageText('TEXT-HIDE-PAGE-CONTENT')."</a>]</p>");
$pstyle = "";
if (!array_key_exists('home_page_content', $school_record) || $school_record['home_page_content'] == 'Hidden') $pstyle = " style='display: none;'";
}
echo("<span id='homepage-content' align='left'$pstyle>\n");
echo($content);
echo("</span>\n");
echo("<br>\n");
}
if ($displayPaymentForm == true) {
echo("<table>\n<tr>\n<td align='center'>\n");
include "payment_form.php";
echo("<p><br></p>\n");
if ($action != 'pay-online') {
if (array_key_exists('display_students_button', $school_record) && ($school_record['display_students_button'] == 'Bottom' || $school_record['display_students_button'] == 'Both')) include "bottom-buttons.php";
}
echo("</td>\n</tr>\n</table>\n");
}
else {
if ($action != 'pay-online') {
if ($school_record['display_students_button'] == 'Bottom' || $school_record['display_students_button'] == 'Both') include "bottom-buttons.php";
}
}
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator'))) {
$current_balance_owing = db_getVal("SELECT sum(total - amount_paid) FROM invoice_header WHERE school_num = $school_num AND status = 'Open'");
if ($current_balance_owing > 0) {
// Format school_year value
if (date("m",time()) < '12') {
$cYr = date("Y",time());
$nYr = $cYr + 1;
}
else {
$cYr = date("Y",time()) + 1;
$nYr = $cYr + 1;
}
$open_invoices = db_query("SELECT record_num FROM invoice_header WHERE school_num = $school_num AND status = 'Open' ORDER BY record_num");
$inv_link = "";
while ($row = db_fetch_assoc($open_invoices)) {
$inum = $row['record_num'];
$invoice_num = sprintf("%06d",$row['record_num'] + 500);
$record_num = $row['record_num'];
$inv_link .= "-- <a href='?action=inv-print&invoice_num=$record_num&school_num=$school_num' style='color: #0000f0'>View Open Invoice #$invoice_num</a> --<br>";
$discount = db_getVal("SELECT count(*) FROM invoice_items WHERE school_num = $school_num AND invoice_num = $inum AND description LIKE '- Early Bird%'");
}
$message = "-- Your School Has a Current Balance Owing of :: $" . number_format($current_balance_owing,2) . " --<br>\n$inv_link";
// if ($discount > 0) $message .= "<br><br>NOTE: All \"Earlybird Discounts\" are only valid to July 31. After this date they will be removed from your invoice<br> and your invoice balance will increase as the discount will not be applied";
if ($discount > 0) $message .= "<br>NOTE: All \"Earlybird Discounts\" are only valid to June 30.<br> After this date they will be removed from your invoice if payment is not received.";
$class = "errorspan";
displayStatusMessage($message,$class);
echo("<br>\n");
include "paypal_form.hotlunches.php";
}
include "renewal.form.php";
}
// Display donation button
if (strlen($school_record['paypal_code']) > 0 && $school_record['paypal_donation'] == 'Y') {
include "paypal_donate.php";
}
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') echo("<p><a href='?action=form-test' class='btn btn--primary>'> Form Test </a></p>\n");
// echo($school_record['days_left']);
// echo("<br>");
// echo($grace_period);
$homePageHidden = true;
if (array_key_exists('home_page_content', $school_record) && $school_record['home_page_content'] == 'Visible') $homePageHidden = false;
?>
<script>
$(document).ready(function() {
<?php if ($homePageHidden == true) { ?>
$("#hide-page-content-span").hide();
$("#show-page-content-span").show();
<?php } else { ?>
$("#hide-page-content-span").show();
$("#show-page-content-span").hide();
<?php } ?>
$("#show-page-content").click(function(e) {
e.preventDefault();
$("#homepage-content").show();
$("#show-page-content-span").hide();
$("#hide-page-content-span").show();
});
$("#hide-page-content").click(function(e) {
e.preventDefault();
$("#homepage-content").hide();
$("#show-page-content-span").show();
$("#hide-page-content-span").hide();
});
});
</script>
<?php
endTemplate();
?>