First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
// startLog("events.admin.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
$AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team','Staff');
|
||||
if (checkPermission($AllowedUserTypes) != 1) {
|
||||
echo("<br>\n");
|
||||
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
||||
include "form.messages.php";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Process all actions to list and edit records
|
||||
//
|
||||
|
||||
$CurrentTable = "event_calendar";
|
||||
$DeleteField = "title,date_and_time";
|
||||
$dSeparator = "<br>";
|
||||
$FormFile = "event_calendar.form.php";
|
||||
$TitleText = getLanguageText('TEXT-EVENT');
|
||||
$OrderBy = "start_date,end_date,title";
|
||||
$Sequence = 'N';
|
||||
|
||||
// Start the template and output buffering
|
||||
startTemplate();
|
||||
$templatePageTitle = getLanguageText('TEXT-EVENTS-ADMINISTRATION');
|
||||
$headerArgs = "";
|
||||
|
||||
|
||||
|
||||
|
||||
$naction = 'list';
|
||||
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
||||
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
||||
|
||||
unset($event_view);
|
||||
if (array_key_exists('event_view',$_GET)) $event_view = $_GET['event_view'];
|
||||
if (array_key_exists('event_view',$_POST)) $event_view = $_POST['event_view'];
|
||||
|
||||
// writeLog("naction: ".$naction);
|
||||
|
||||
switch (strtolower($naction)) {
|
||||
case "add":
|
||||
$next_naction = "insert";
|
||||
$active = 'Y';
|
||||
$dow = "All";
|
||||
|
||||
include $FormFile;
|
||||
break;
|
||||
|
||||
case "insert":
|
||||
extract($_POST);
|
||||
|
||||
if (strlen($start_date) == 0 || strlen($end_date) == 0 || $end_date < $start_date) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-DATE-RANGE');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!isset($dow) || !is_array($dow) || count($dow) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-MISSING-DATA');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
if (strlen($title) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-MISSING-DATA');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
$dow = implode(',',$dow);
|
||||
|
||||
// Get new sequence number
|
||||
if ($Sequence == 'Y') {
|
||||
$query = "select max(sequence) sequence from $CurrentTable";
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$sequence = intval($row['sequence']) + 1;
|
||||
}
|
||||
|
||||
|
||||
// Insert primary record
|
||||
$table = new Table("$CurrentTable");
|
||||
$query = $table->BuildInsert();
|
||||
db_query($query);
|
||||
|
||||
$form_message = "$TitleText Has Been Inserted";
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&form_message=".urlencode($form_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('RECORD-NOT-FOUND-MSG');
|
||||
}
|
||||
break;
|
||||
|
||||
case "update":
|
||||
extract($_POST);
|
||||
|
||||
if (strlen($start_date) == 0 || strlen($end_date) == 0 || $end_date < $start_date) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-DATE-RANGE');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!is_array($dow) || count($dow) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-MISSING-DATA');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
if (strlen($title) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-MISSING-DATA');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
$dow = implode(',',$dow);
|
||||
|
||||
$table = new Table("$CurrentTable");
|
||||
$query = $table->BuildUpdate();
|
||||
db_query($query);
|
||||
$form_message = "$TitleText Has Been Updated";
|
||||
$action = "events-admin";
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&form_message=".urlencode($form_message));
|
||||
exit();
|
||||
|
||||
case "upload":
|
||||
extract($_POST);
|
||||
|
||||
$temp_name = $_FILES['filename']['tmp_name'];
|
||||
$file_name = str_replace(' ','_',$_FILES['filename']['name']);
|
||||
|
||||
$error_message = '';
|
||||
|
||||
// Ensure a file has been uploaded
|
||||
if (strlen($file_name) == 0) {
|
||||
$error_message = getLanguageText('MSG-NO-SOURCE-DATA-FILE');
|
||||
$new_naction = "upload-form";
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if a file with this name already exists
|
||||
if (is_file("$uploaddir/$file_name")) {
|
||||
unlink("$uploaddir/$file_name");
|
||||
}
|
||||
|
||||
// Validate the file type
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$ftype = finfo_file($finfo,$temp_name);
|
||||
if ($ftype != "text/plain") {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-FILE-FORMAT');
|
||||
$new_naction = "upload-form";
|
||||
break;
|
||||
}
|
||||
|
||||
// Move file to documents folder
|
||||
if (!move_uploaded_file($temp_name,"$uploaddir/$file_name")) {
|
||||
$error_message = getLanguageText('ERRORMSG-UNABLE-TO-COPY-UPLOADED')." - $uploaddir/$file_name";
|
||||
break;
|
||||
}
|
||||
|
||||
// Open and check file format
|
||||
$fp = fopen("$uploaddir/$file_name","r");
|
||||
|
||||
$events = new Table("event_calendar");
|
||||
$posted_by = $_SESSION['UserInfo']['record_num'];
|
||||
if ($_SESSION['UserInfo']['userid'] == 'superuser') $posted_by = db_getVal("SELECT record_num FROM users WHERE school_num = $base_school_num AND userid = 'admin'");
|
||||
|
||||
$posted_date = date("Y-m-d",time());
|
||||
$status = "Approved";
|
||||
$display = "Active";
|
||||
$dow = 'All';
|
||||
|
||||
while (($data = fgetcsv($fp,10000,",")) !== FALSE) {
|
||||
$fields = count($data);
|
||||
if ($fields == 0) continue;
|
||||
if (strlen($data[0]) == 0 && strlen($data[1]) == 0) continue;
|
||||
|
||||
$event_type = trim($data[0]);
|
||||
$start_date = date("Y-m-d",strtotime(trim($data[1])));
|
||||
$end_date = date("Y-m-d",strtotime(trim($data[2])));
|
||||
$title = trim($data[3]);
|
||||
$date_and_time = trim($data[4]);
|
||||
$location = trim($data[5]);
|
||||
$description = trim($data[6]);
|
||||
if (strlen($event_type) == 0 || strtolower($event_type) == "type") continue;
|
||||
|
||||
$query = $events->BuildInsert();
|
||||
db_query($query);
|
||||
}
|
||||
|
||||
$form_message = getLanguageText('TEXT-DATA-FILE-UPLOADED');
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&form_message=".urlencode($form_message));
|
||||
exit();
|
||||
|
||||
case "delete":
|
||||
$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);
|
||||
|
||||
$dFields = explode(",",$DeleteField);
|
||||
$dTitle = "$TitleText ";
|
||||
for ($i = 0; $i < count($dFields); $i++) {
|
||||
$dTitle .= $row[$dFields[$i]] . $dSeparator;
|
||||
}
|
||||
|
||||
include "delete.form.php";
|
||||
}
|
||||
else {
|
||||
$error_message = "Error: Record Not Found";
|
||||
}
|
||||
break;
|
||||
|
||||
case "delete-confirmed":
|
||||
$record_num = intval($_GET['record_num']);
|
||||
|
||||
// Delete the current record
|
||||
$query = "delete from $CurrentTable where record_num = $record_num";
|
||||
db_query($query);
|
||||
|
||||
$form_message = "$TitleText Has Been Deleted";
|
||||
$naction = "list";
|
||||
header("Location: /?action=$action&naction=$naction&form_message=".urlencode($form_message));
|
||||
exit();
|
||||
|
||||
case "up":
|
||||
case "down":
|
||||
// Get current record
|
||||
$record_num = intval($_GET['record_num']);
|
||||
$query = "select * from $CurrentTable where record_num = $record_num";
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$sequence = $row['sequence'];
|
||||
if ($naction == 'up') $nsequence = $sequence - 1;
|
||||
if ($naction == 'down') $nsequence = $sequence + 1;
|
||||
|
||||
// Update other record
|
||||
$query = "update $CurrentTable set sequence = $sequence where sequence = $nsequence";
|
||||
db_query($query);
|
||||
|
||||
// Update current record
|
||||
$query = "update $CurrentTable set sequence = $nsequence where record_num = $record_num";
|
||||
db_query($query);
|
||||
|
||||
$naction = "list";
|
||||
break;
|
||||
|
||||
default:
|
||||
$naction = "list";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// List all records if naction is "list"
|
||||
//
|
||||
if ($naction == "list" || $naction == 'list-all') {
|
||||
|
||||
$scriptName = str_replace("/m/data1/app.hotlunches.net/","",__FILE__);
|
||||
include "help.docs.php";
|
||||
|
||||
// Get records to display
|
||||
$columnHeaders = array(getLanguageText('TEXT-EVENT-TITLE'),
|
||||
getLanguageText('TEXT-START-DATE'),
|
||||
getLanguageText('TEXT-END-DATE'),
|
||||
getLanguageText('TEXT-EVENT-DATE-TIME'),
|
||||
getLanguageText('TEXT-TYPE'),
|
||||
getLanguageText('TEXT-STATUS'),
|
||||
getLanguageText('TEXT-DISPLAY')
|
||||
);
|
||||
$columnAlign = array('left','center','center','left','left','center','center');
|
||||
|
||||
$statusSet = "'Entered','Approved'";
|
||||
if (array_key_exists('show', $_GET)) $show = db_escape_string($_GET['show']);
|
||||
if (isset($show) && $show == 'All') $statusSet = "'Entered','Approved','Rejected'";
|
||||
|
||||
$cuttoff_date = date("Y-m-d",time() - 60 * 60 * 24 * 60);
|
||||
if (isset($event_view) && $event_view == 'all') $today = "2000-01-01";
|
||||
$query = "select * from event_calendar " .
|
||||
"where school_num = $school_num " .
|
||||
"and status in ($statusSet) " .
|
||||
"and end_date >= '$cuttoff_date' " .
|
||||
"order by start_date,end_date,title";
|
||||
echo("<!-- EVENT QUERY: $query -->\n\n");
|
||||
$results = db_query($query);
|
||||
|
||||
$otipSpans = "";
|
||||
$data = array();
|
||||
while ($row = db_fetch_array($results)) {
|
||||
extract($row);
|
||||
$span_id = "event_$record_num";
|
||||
$otipSpans .= "<span id='$span_id'>" . $otipTABLE .
|
||||
sprintf($otipROW2,'<nobr>' . getLanguageText('TEXT-EVENT-TITLE') . ': </nobr>',$title) .
|
||||
sprintf($otipROW2,'<nobr>' . getLanguageText('TEXT-EVENT-DATE-TIME') . ': </nobr>',$date_and_time) .
|
||||
sprintf($otipROW2,'<nobr>' . getLanguageText('TEXT-EVENT-LOCATION') . ': </nobr>',$location) .
|
||||
"</table></span>\n";
|
||||
|
||||
$statusText = getLanguageText('TEXT-'.strtoupper($status));
|
||||
$displayText = getLanguageText('TEXT-'.strtoupper($display));
|
||||
|
||||
$entry = array();
|
||||
$entry[] = "<a href='?action=$action&naction=edit&record_num=$record_num' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$title</a>";
|
||||
$entry[] = $start_date;
|
||||
$entry[] = $end_date;
|
||||
$entry[] = $date_and_time;
|
||||
$entry[] = $event_type;
|
||||
$entry[] = "<span class='event-status' rnum='$record_num' id='event-status-$record_num' status='$status'>$statusText</span>";
|
||||
$entry[] = "<span class='event-display' rnum='$record_num' id='event-display-$record_num' display='$display'>$displayText</span>";
|
||||
$entry['record_num'] = $record_num;
|
||||
|
||||
$data[] = $entry;
|
||||
}
|
||||
|
||||
$message_width = $default_data_width;
|
||||
include "form.messages.php";
|
||||
|
||||
listDataCustom($data,$columnHeaders,$action,array(),'N',$columnAlign);
|
||||
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<center>
|
||||
<p>
|
||||
<a href='?action=events-admin&naction=add' class='btn btn--primary'><?php displayLanguageText('TEXT-INSERT-NEW'); ?></a>
|
||||
<?php if (isset($show) && $show == 'All') { ?>
|
||||
<a href='?action=events-admin&naction=list' class='btn btn--outline'><?php displayLanguageText('TEXT-VIEW-ACTIVE'); ?></a>
|
||||
<?php } else { ?>
|
||||
<a href='?action=events-admin&naction=list&show=All' class='btn btn--outline'><?php displayLanguageText('TEXT-VIEW-ALL-ENTRIES'); ?></a>
|
||||
<?php } ?>
|
||||
<a href='?action=events-calendar' class='btn btn--outline'><?php displayLanguageText('TEXT-EVENT-CALENDAR'); ?></a>
|
||||
</p>
|
||||
</center>
|
||||
<br>
|
||||
<br>
|
||||
<?php
|
||||
include "events.upload.form.php";
|
||||
?>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
<?php include "include/ajax.Setup.php" ?>
|
||||
|
||||
$(".event-status").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var rnum = $(this).attr('rnum');
|
||||
var status = $(this).attr('status');
|
||||
var new_status;
|
||||
var new_text;
|
||||
|
||||
switch (status) {
|
||||
case 'Entered':
|
||||
new_status = 'Approved';
|
||||
new_text = "<?php displayLanguageText('TEXT-APPROVED'); ?>";
|
||||
break;
|
||||
case 'Approved':
|
||||
new_status = 'Rejected';
|
||||
new_text = "<?php displayLanguageText('TEXT-REJECTED'); ?>";
|
||||
break;
|
||||
case 'Rejected':
|
||||
new_status = 'Entered';
|
||||
new_text = "<?php displayLanguageText('TEXT-ENTERED'); ?>";
|
||||
break;
|
||||
}
|
||||
|
||||
var data = "table_name=event_calendar" +
|
||||
"&record_num=" + rnum +
|
||||
"&status=" + new_status;
|
||||
$.getJSON("ajax.DataRecord.Update.php", data,
|
||||
function(results) {
|
||||
$("#event-status-"+rnum).html(new_text);
|
||||
$("#event-status-"+rnum).attr('status', new_status);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$(".event-display").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var rnum = $(this).attr('rnum');
|
||||
var display = $(this).attr('display');
|
||||
var new_display;
|
||||
var new_text;
|
||||
|
||||
switch (display) {
|
||||
case 'Active':
|
||||
new_display = 'Deleted';
|
||||
new_text = "<?php displayLanguageText('TEXT-DELETED'); ?>";
|
||||
break;
|
||||
case 'Deleted':
|
||||
new_display = 'Active';
|
||||
new_text = "<?php displayLanguageText('TEXT-ACTIVE'); ?>";
|
||||
break;
|
||||
}
|
||||
|
||||
var data = "table_name=event_calendar" +
|
||||
"&record_num=" + rnum +
|
||||
"&display=" + new_display;
|
||||
$.getJSON("ajax.DataRecord.Update.php", data,
|
||||
function(results) {
|
||||
$("#event-display-"+rnum).html(new_text);
|
||||
$("#event-display-"+rnum).attr('display', new_display);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
endTemplate();
|
||||
?>
|
||||
Reference in new issue
Block a user