Files
HotLunches/supplier_products.upload.form.php
T
2026-10-19 15:22:52 -07:00

134 lines
4.0 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','Application Administrator');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
unset($supplier_num);
if (array_key_exists('supplier_num',$_GET)) $supplier_num = intval($_GET['supplier_num']);
if (!isset($supplier_num)) {
if (isset($selected_supplier)) $supplier_num = intval($selected_supplier);
else $supplier_num = 0;
}
$PageTitle = getLanguageText('TEXT-UPLOAD-SUPPLIER-PRODUCTS');
$ButtonText = getLanguageText('TEXT-UPLOAD-FILE');
?>
<br>
<form method='post' 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'>&nbsp;</td>
</tr>
<tr>
<td colspan='2' align='center'>
<p><?php displayLanguageText('TEXT-SUPPLIER-PRODUCTS-CSV-EXPLANATION'); ?></p>
</td>
</tr>
<tr>
<td width='40%' align='right' valign='top'><?php displayLanguageText('TEXT-SUPPLIER'); ?>: </td>
<td width='60%' align='left' valign='top'>
<select name='selected_supplier'>
<option value=''>Select a Supplier for the Uploaded Products</option>
<?php BuildDBList("suppliers","record_num","supplier_name","supplier_name",$supplier_num,"ASC","and school_num = $supplier_school_num"); ?>
</select>
</td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-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-SUPPLIER-PRODUCTS-LAYOUT-EXPLANATION'); ?></p>
<p><?php displayLanguageText('TEXT-CSV-COLUMN-SELECTION'); ?></p>
</td>
</tr>
<?php
$fp = fopen("supplier_products.txt","r");
$entry = trim(fgets($fp,1000));
$product_fields = array();
$count = 0;
while (!feof($fp)) {
if (strlen($entry) == 0) break;
list($field,$prompt) = preg_split('/:/',$entry);
$product_fields[$count]['field'] = $field;
$product_fields[$count]['prompt'] = $prompt;
$entry = trim(fgets($fp,1000));
$count++;
}
$fields = '';
for ($i = 0; $i < count($product_fields); $i++) {
$num = $i + 1;
$field = $product_fields[$i]['field'];
$prompt = $product_fields[$i]['prompt'];
if (strlen($fields)) $fields .= ",";
$fields .= $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($product_fields) + 10; $j++) {
$l = $j - 1;
$letter = $Letters[$l];
$selected = "";
// Check for an upload_columns entry
if (isset($student_fields) && $j < count($student_fields)) {
$column = intval(db_getVal("SELECT column_num FROM upload_columns WHERE school_num = $school_num AND action = 'supplier-products' AND field = '$field'"));
if ($j == $column) $selected = " selected='selected'";
}
echo(" <option value='$j' $selected>" . getLanguageText('TEXT-COLUMN') . " $j ($letter)</option>\n");
}
?>
</select>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan='2' align='center'>
<br>
<input type='submit' class='btn btn--primary' value='<?php echo($ButtonText) ?>'>
<input type='hidden' name='action' value='supplier-products'>
<input type='hidden' name='naction' value='upload'>
<input type='hidden' name='num_fields' value='<?php echo(count($product_fields)) ?>'>
<input type='hidden' name='fields' value='<?php echo($fields) ?>'>
<br>
<br>
</td>
</tr>
</table>