276 lines
8.7 KiB
PHP
276 lines
8.7 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
$PageTitle = getLanguageText('TEXT-STUDENT-UPLOAD');
|
|
$ButtonText = getLanguageText('TEXT-UPLOAD-FILE');
|
|
|
|
?>
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
<?php include "include/ajax.Setup.php" ?>
|
|
|
|
$("#upload-form").submit(function(e) {
|
|
var csvFile = $("#filename").val();
|
|
var grade = $("#grade").val();
|
|
var division = $("#division").val();
|
|
|
|
if (csvFile.length == 0) {
|
|
alert("<?php displayLanguageText('ERRORMSG-DATA-FILE-NOT-SPECIFIED'); ?>");
|
|
return false;
|
|
}
|
|
|
|
if (grade == 0 && division == 0) {
|
|
alert("<?php displayLanguageText('ERRORMSG-CLASS-OR-GRADE-MUST-BE-SPECIFIED'); ?>");
|
|
return false;
|
|
}
|
|
});
|
|
|
|
$(".delete-existing").click(function(e) {
|
|
var dVal = $(this).val();
|
|
var msg = "<?php displayLanguageText('TEXT-CONFIRM-DELETE'); ?>";
|
|
if (dVal == 'Y') {
|
|
if (confirm(msg)) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
|
|
});
|
|
</script>
|
|
<br>
|
|
<form method='post' id='upload-form' enctype='multipart/form-data' action='/'>
|
|
<?php
|
|
$message_width = $default_form_width;
|
|
include "form.messages.php";
|
|
?>
|
|
<table width='<?php echo($default_form_width) ?>' class='content-table'>
|
|
<tr>
|
|
<td colspan='2' align='center' class='heading'><?php echo($PageTitle) ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan='2' align='center'>
|
|
<p><b><?php displayLanguageText('TEXT-REQUIRED-MESSAGE'); ?></b></p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan='2' align='center'>
|
|
<p><?php displayLanguageText('TEXT-UP-LOAD-FILE-FORMAT'); ?></p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width='40%' align='right' valign='top'>File: </td>
|
|
<td align='left' valign='top'><input type='file' name='filename' id='filename' size='40'></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan='2' align='center'>
|
|
<br>
|
|
<p><?php displayLanguageText('TEXT-CSV-COLUMN-SELECTION'); ?></p>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
$fp = fopen("students_upload.txt","r");
|
|
$entry = trim(fgets($fp,1000));
|
|
|
|
$student_fields = array();
|
|
$count = 0;
|
|
$fields = "";
|
|
|
|
while (!feof($fp)) {
|
|
if (strlen($entry) == 0) break;
|
|
|
|
list($field,$prompt,$additional) = preg_split('/:/',$entry);
|
|
$student_fields[$count]['field'] = $field;
|
|
if (strlen($fields)) $fields .= ",";
|
|
$fields .= $field;
|
|
|
|
if (str_match("TEXT-",$prompt)) $code = $prompt;
|
|
else $code = "TEXT-" . str_replace(" ","-",strtoupper($prompt));
|
|
$text = getLanguageText($code);
|
|
$student_fields[$count]['prompt'] = $text;
|
|
|
|
$atext = "";
|
|
if (strlen($additional)) $atext = " (" . getLanguageText($additional) . ")";
|
|
$student_fields[$count]['additional'] = $atext;
|
|
|
|
$entry = trim(fgets($fp,1000));
|
|
$count++;
|
|
}
|
|
|
|
for ($i = 0; $i < count($student_fields); $i++) {
|
|
$prompt = $student_fields[$i]['prompt'];
|
|
$field = $student_fields[$i]['field'];
|
|
$column = intval(db_getVal("SELECT column_num FROM upload_columns WHERE school_num = $school_num AND action = 'students' AND field = '$field'"));
|
|
?>
|
|
<tr>
|
|
<td align='right' valign='top'><?php echo($prompt) ?>: </td>
|
|
<td align='left' valign='top'>
|
|
<select name='<?php echo($field) ?>' id='<?php echo($field) ?>'>
|
|
<option value='0'></option>
|
|
<?php
|
|
for ($j = 1; $j <= count($student_fields) + 12; $j++) {
|
|
$l = $j - 1;
|
|
$letter = $Letters[$l];
|
|
$selected = "";
|
|
if ($j == $column) $selected = " selected='selected'";
|
|
|
|
echo(" <option value='$j' $selected>Column $j ($letter)</option>\n");
|
|
}
|
|
?>
|
|
</select> <span class='small'><?php echo($student_fields[$i]['additional']) ?></span>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
$num = $i + 1;
|
|
}
|
|
|
|
if ($school_record['user_defined_values'] == 'Y') {
|
|
$field = "user_defined_value";
|
|
$prompt = $school_record['user_defined_title'];
|
|
?>
|
|
<tr height='10'>
|
|
<td colspan='2'> </td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right' valign='top'><?php echo($prompt) ?>: </td>
|
|
<td align='left' valign='top'>
|
|
<select name='<?php echo($field) ?>'>
|
|
<option value='0'></option>
|
|
<?php
|
|
for ($j = 1; $j <= count($student_fields) + 10; $j++) {
|
|
$l++;
|
|
$letter = $Letters[$l];
|
|
echo(" <option value='$j'>Column $j ($letter)</option>\n");
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
|
|
if ($school_record['user_defined_values2'] == 'Y') {
|
|
$field = "user_defined_value2";
|
|
$prompt = $school_record['user_defined_title2'];
|
|
?>
|
|
<tr height='10'>
|
|
<td colspan='2'> </td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right' valign='top'><?php echo($prompt) ?>: </td>
|
|
<td align='left' valign='top'>
|
|
<select name='<?php echo($field) ?>'>
|
|
<option value='0'></option>
|
|
<?php
|
|
for ($k = 1; $k <= count($student_fields) + 10; $k++) {
|
|
$l++;
|
|
$letter = $Letters[$l];
|
|
echo(" <option value='$k'>Column $k ($letter)</option>\n");
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
?>
|
|
<tr>
|
|
<td colspan='2'> </td>
|
|
</tr>
|
|
<?php
|
|
$skip_first_row = db_getVal("SELECT value FROM upload_columns WHERE school_num = $school_num AND action = 'students' AND field = 'skip_first_row'");
|
|
if (strlen($skip_first_row) == 0) $skip_first_row = "N";
|
|
?>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-SKIP-FIRST-ROW'); ?>: </td>
|
|
<td align='left' valign='top'><?php BuildFileRadio("yn.txt","skip_first_row","$skip_first_row") ?></td>
|
|
</tr>
|
|
<!--
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-CLASS'); ?>: </td>
|
|
<td align='left' valign='top'><?php BuildFileRadio("students_upload.class.txt","class_data","Generate Classes","<br>") ?></td>
|
|
</tr>
|
|
-->
|
|
<?php
|
|
$userid_source = db_getVal("SELECT value FROM upload_columns WHERE school_num = $school_num AND action = 'students' AND field = 'userid_source'");
|
|
if (strlen($userid_source) == 0) $userid_source = "Email Address";
|
|
?>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-USER-ID'); ?>: </td>
|
|
<td align='left' valign='top'><?php BuildFileRadio("students_upload.userid.txt","userid_source","$userid_source","<br>") ?></td>
|
|
</tr>
|
|
<?php
|
|
$password_source = db_getVal("SELECT value FROM upload_columns WHERE school_num = $school_num AND action = 'students' AND field = 'password_source'");
|
|
if (strlen($password_source) == 0) $password_source = "User ID";
|
|
?>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-PASSWORD'); ?>: </td>
|
|
<td align='left' valign='top'><?php BuildFileRadio("students_upload.password.txt","password_source","$password_source","<br>") ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-SAVE-SECOND-EMAIL-ADDRESS'); ?>: </td>
|
|
<td align='left' valign='top'><?php BuildFileRadio("yn.txt","save_second_email_address","Y","<br>") ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-DATE-FORMAT'); ?>: </td>
|
|
<td align='left' valign='top'>
|
|
<?php
|
|
$date_format = db_getVal("SELECT value FROM upload_columns WHERE school_num = $school_num AND action = 'students' AND field = 'date_format'");
|
|
?>
|
|
<select name='date_format' id='date_format'>
|
|
<?php BuildFileList("upload_date_format.txt",$date_format) ?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
$today = date("Y-m-d",time());
|
|
$now = date("Y-m-d H:i:00",time());
|
|
$query = "SELECT count(*) FROM hotlunch_schedules " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND status IN ('Active','Closed') " .
|
|
"AND (end_order_datetime > '$now' OR schedule_end_date > '$today')";
|
|
$active = db_getVal($query);
|
|
|
|
if ($active == 0) {
|
|
?>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-DELETE-EXISTING-ENTRIES'); ?>: </td>
|
|
<td align='left' valign='top'><?php BuildFileRadio("yn.txt","delete_existing","N","","delete-existing") ?></td>
|
|
</tr>
|
|
<?php
|
|
} else {
|
|
echo(" <input type='hidden' name='delete_existing' value='N'>\n");
|
|
}
|
|
?>
|
|
<tr>
|
|
<td colspan='2' align='center'>
|
|
<br>
|
|
<input type='submit' id='submitButton' class='btn btn--primary' value='<?php echo($ButtonText) ?>'>
|
|
<input type='hidden' name='action' value='students'>
|
|
<input type='hidden' name='naction' value='upload'>
|
|
<input type='hidden' name='fields' value='<?php echo($fields) ?>'>
|
|
<input type='hidden' name='num_fields' value='<?php echo(count($student_fields)) ?>'>
|
|
<br>
|
|
<br>
|
|
</td>
|
|
</tr>
|
|
</table>
|