174 lines
6.3 KiB
PHP
174 lines
6.3 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = getLanguageText('TEXT-FLAG-EMAIL-RECIPIENTS');
|
|
$headerArgs = "";
|
|
|
|
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("email_flag_recipients.php");
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Volunteer Administrator','Communications Administrator','Financial','Financial Team');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
$action = '';
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$action = "email-flag-recipients";
|
|
$CurrentTable = "users";
|
|
$FormFile = "email_flag_recipients.form.php";
|
|
$TitleText = "Flag Email Recipients";
|
|
$OrderBy = "";
|
|
|
|
|
|
$school_num = $school_record['record_num'];
|
|
|
|
$scriptName = str_replace("/m/data1/app.hotlunches.net/","",__FILE__);
|
|
include "help.docs.php";
|
|
|
|
|
|
// Get naction if it has been posted
|
|
$naction = "";;
|
|
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
|
|
?>
|
|
<table cellpadding='3'>
|
|
<tr>
|
|
<td align='center'><a href='?action=email-flag-recipients&naction=list&flag=Y' class='btn btn--primary btn--xsmall'><?php displayLanguageText('TEXT-YES'); ?></a></td>
|
|
<td align='center'><a href='?action=email-flag-recipients&naction=list&flag=N' class='btn btn--primary btn--xsmall'><?php displayLanguageText('TEXT-NO'); ?></a></td>
|
|
</tr>
|
|
</table>
|
|
<?php
|
|
|
|
// If naction is set then perform the next action
|
|
switch ($naction) {
|
|
case 'update-all':
|
|
$flag = $_POST['flag'];
|
|
db_query("UPDATE users SET email_flag = '$flag' WHERE school_num = $school_num");
|
|
|
|
$num = db_affected_rows();
|
|
$form_message = "All User Flags Set to '$flag' - $num Records";
|
|
include $FormFile;
|
|
break;
|
|
|
|
case 'update-by-schedule':
|
|
$flag = $_POST['flag'];
|
|
$schedule = intval($_POST['selected_schedule']);
|
|
$query = "UPDATE users SET email_flag = '$flag' " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND record_num IN (SELECT user_num " .
|
|
"FROM people AS p,hotlunch_order_header AS hloh " .
|
|
"WHERE p.school_num = $base_school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloh.schedule_num = $schedule " .
|
|
"AND hloh.ordered_by_num = p.record_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted'))";
|
|
writeLog($query);
|
|
db_query($query);
|
|
|
|
$num = db_affected_rows();
|
|
$form_message = "Selected User Flags Set to '$flag' - $num Records";
|
|
header("Location: /?action=$action&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'update-by-menu-item':
|
|
$flag = $_POST['flag'];
|
|
$menu_items = $_POST['selected_menu_items'];
|
|
|
|
if (is_array($menu_items) && count($menu_items)) {
|
|
$items = implode(",",$menu_items);
|
|
$query = "UPDATE users SET email_flag = '$flag' " .
|
|
"WHERE school_num = $base_school_num " .
|
|
"AND record_num IN " .
|
|
"(SELECT user_num " .
|
|
"FROM people " .
|
|
"WHERE school_num = $base_school_num " .
|
|
"AND record_num IN " .
|
|
"(SELECT hloh.ordered_by_num FROM hotlunch_order_items AS hloi,hotlunch_order_header AS hloh " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloh.record_num = hloi.order_num " .
|
|
"AND hloi.menu_item_num IN ($items) " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted')))";
|
|
writeLog($query);
|
|
db_query($query);
|
|
|
|
$num = db_affected_rows();
|
|
$form_message = "Selected User Flags Set to '$flag' - $num Records";
|
|
header("Location: /?action=$action&form_message=".urlencode($form_message));
|
|
exit();
|
|
}
|
|
|
|
$error_message = getLanguageText('ERRORMSG-NO-ITEMS-SELECTED');
|
|
header("Location: /?action=$action&error_message=".urlencode($error_message));
|
|
exit();
|
|
|
|
case 'update-by-transaction-type':
|
|
$flag = $_POST['flag'];
|
|
$schedule = $_POST['selected_schedule'];
|
|
$type = $_POST['transaction_type'];
|
|
|
|
$swhere = "";
|
|
if (strlen($schedule) > 0) {
|
|
$swhere = "AND schedule_num = $schedule";
|
|
}
|
|
|
|
$query = "UPDATE users SET email_flag = '$flag' " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND record_num IN (SELECT user_num " .
|
|
"FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND transaction_type = '$type' $swhere)";
|
|
db_query($query);
|
|
|
|
$num = db_affected_rows();
|
|
$form_message = "Selected User Flags Set to '$flag' - $num Records";
|
|
header("Location: /?action=$action&form_message=".urlencode($form_message));
|
|
exit();
|
|
|
|
case 'list':
|
|
$flag = db_escape_string($_GET['flag']);
|
|
$query = "SELECT * FROM users WHERE school_num = $base_school_num AND email_flag = '$flag' ORDER BY last_name";
|
|
$results = db_query($query);
|
|
|
|
$data = array();
|
|
if (db_num_rows($results)) {
|
|
while ($row = db_fetch_assoc($results)) {
|
|
extract($row);
|
|
$data[] = array("$first_name", $userid, $email, $home_phone);
|
|
}
|
|
}
|
|
|
|
$columnHeaders = array(getLanguageText('TEXT-NAME'),
|
|
getLanguageText('TEXT-USERID'),
|
|
getLanguageText('TEXT-PHONE'),
|
|
getLanguageText('TEXT-EMAIL'));
|
|
listDataCustom($data,$columnHeaders,'',array(),'N');
|
|
break;
|
|
|
|
default:
|
|
include $FormFile;
|
|
break;
|
|
}
|
|
|
|
endTemplate();
|
|
?>
|