218 lines
7.0 KiB
PHP
218 lines
7.0 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$CurrentTable = "school_contact_list";
|
|
$DeleteField = "contact_name,contact_email";
|
|
$dSeparator = "<br>";
|
|
$FormFile = "application_contacts.form.php";
|
|
$TitleText = getLanguageText('TEXT-CONTACT');
|
|
$OrderBy = "sequence";
|
|
$Sequence = 'Y';
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = getLanguageText('TEXT-CONTACT-ADMIN-TITLE');
|
|
|
|
|
|
// 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');
|
|
include "form.messages.php";
|
|
endTemplate();
|
|
exit();
|
|
}
|
|
|
|
|
|
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
|
|
switch (strtolower($naction)) {
|
|
case "add":
|
|
$next_naction = "insert";
|
|
$level = 'System Administrator';
|
|
|
|
include $FormFile;
|
|
break;
|
|
|
|
case "insert":
|
|
extract($_POST);
|
|
|
|
// Get new sequence number
|
|
if ($Sequence == 'Y') {
|
|
$query = "select max(sequence) sequence " .
|
|
"from $CurrentTable " .
|
|
"where school_num = $school_num";
|
|
$results = db_query($query);
|
|
$row = db_fetch_array($results);
|
|
$sequence = intval($row['sequence']) + 1;
|
|
}
|
|
|
|
// If there is a phone number entered then format it
|
|
if (strlen($contact_phone) > 0) {
|
|
$phone = preg_replace("/[^0-9]/","",$contact_phone);
|
|
if (strlen($phone) == 10) {
|
|
$contact_phone = "(" . substr($phone,0,3) . ")" . substr($phone,3,3) . "-" . substr($phone,6);
|
|
}
|
|
}
|
|
|
|
// If there is a phone number entered then format it
|
|
if (strlen($contact_cell) > 0) {
|
|
$phone = preg_replace("/[^0-9]/","",$contact_cell);
|
|
if (strlen($phone) == 10) {
|
|
$contact_cell = "(" . substr($phone,0,3) . ")" . substr($phone,3,3) . "-" . substr($phone,6);
|
|
}
|
|
}
|
|
|
|
// Insert primary record
|
|
$table = new Table("$CurrentTable");
|
|
$active = 'Y';
|
|
$query = $table->BuildInsert();
|
|
db_query($query);
|
|
|
|
$form_message = getLanguageText('RECORD-INSERTED-MSG');
|
|
$naction = 'list';
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case "edit":
|
|
$next_naction = "update";
|
|
|
|
// Get current record
|
|
$record_num = intval($_GET['record_num']);
|
|
$query = "select * from $CurrentTable where record_num = $record_num";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results) == 1) {
|
|
$row = db_fetch_array($results);
|
|
extract($row);
|
|
$schedule_num = $record_num;
|
|
include $FormFile;
|
|
}
|
|
else {
|
|
$error_message = getLanguageText('ERRORMSG-NOT-FOUND');
|
|
$naction = 'list';
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
break;
|
|
|
|
case "update":
|
|
extract($_POST);
|
|
|
|
// If there is a phone number entered then format it
|
|
if (strlen($contact_phone) > 0) {
|
|
$phone = preg_replace("/[^0-9]/","",$contact_phone);
|
|
if (strlen($phone) == 10) {
|
|
$contact_phone = "(" . substr($phone,0,3) . ")" . substr($phone,3,3) . "-" . substr($phone,6);
|
|
}
|
|
}
|
|
|
|
// If there is a phone number entered then format it
|
|
if (strlen($contact_cell) > 0) {
|
|
$phone = preg_replace("/[^0-9]/","",$contact_cell);
|
|
if (strlen($phone) == 10) {
|
|
$contact_cell = "(" . substr($phone,0,3) . ")" . substr($phone,3,3) . "-" . substr($phone,6);
|
|
}
|
|
}
|
|
|
|
$table = new Table("$CurrentTable");
|
|
$query = $table->BuildUpdate();
|
|
db_query($query);
|
|
|
|
$form_message = getLanguageText('RECORD-UPDATED-MSG');
|
|
$naction = 'list';
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case "delete-confirmed":
|
|
$record_num = intval($_GET['record_num']);
|
|
|
|
// Delete the current record
|
|
$query = "delete from $CurrentTable where school_num = $school_num AND record_num = $record_num";
|
|
db_query($query);
|
|
|
|
$form_message = getLanguageText('RECORD-DELETED-MSG');
|
|
$naction = 'list';
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
default:
|
|
$naction = "list";
|
|
break;
|
|
}
|
|
|
|
|
|
//
|
|
// List all records if naction is "list"
|
|
//
|
|
if ($naction == "list" || $naction == 'list-all') {
|
|
|
|
if ($Sequence == 'Y') {
|
|
// Update the sequence to avoid duplicate keys
|
|
db_query("UPDATE $CurrentTable SET sequence = sequence + 1000 WHERE school_num = $school_num");
|
|
$results = db_query("SELECT * FROM $CurrentTable WHERE school_num = $school_num ORDER BY sequence");
|
|
|
|
// Update the sequence numberequence
|
|
$sequence = 1;
|
|
while ($row = db_fetch_array($results)) {
|
|
$rnum = $row['record_num'];
|
|
db_query("UPDATE $CurrentTable SET sequence = $sequence WHERE record_num = $rnum");
|
|
$sequence++;
|
|
}
|
|
}
|
|
|
|
$scriptName = str_replace("/m/data1/app.hotlunches.net/","",__FILE__);
|
|
include "help.docs.php";
|
|
|
|
// Get records to display
|
|
$columnHeaders = array("Name","Email","Phone","Cell");
|
|
$columnAlign = array('left','left','left','left');
|
|
|
|
$query = "select contact_name,contact_email,contact_phone,contact_cell,sequence,record_num " .
|
|
"from school_contact_list " .
|
|
"where school_num = $school_num " .
|
|
"order by sequence";
|
|
$results = db_query($query);
|
|
|
|
$data = array();
|
|
if (db_num_rows($results)) {
|
|
while ($row = db_fetch_array($results)) {
|
|
$email = $row['contact_email'];
|
|
$data[] = array($row['contact_name'],
|
|
"<a href='mailto:$email'>$email</a>",
|
|
$row['contact_phone'],
|
|
$row['contact_cell'],
|
|
$row['sequence'],
|
|
"record_num" => $row['record_num']);
|
|
}
|
|
}
|
|
|
|
$message_width = $default_data_width;
|
|
include "form.messages.php";
|
|
|
|
$customTableID = "contacts-table";
|
|
$useRowIDS = true;
|
|
include "table.dnd.php";
|
|
|
|
$insert = 'Y';
|
|
$num = count($data);
|
|
if ($num >= 5) $insert = 'N';
|
|
listData($data,$columnHeaders,$action,array(),$insert,$columnAlign);
|
|
|
|
}
|
|
|
|
|
|
endTemplate();
|
|
?>
|