106 lines
3.2 KiB
PHP
106 lines
3.2 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');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
|
|
$templatePageTitle = "School Referrals";
|
|
|
|
include "schools.options.php";
|
|
|
|
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
switch (strtolower($naction)) {
|
|
case "edit":
|
|
include "schools-referrals.form.php";
|
|
break;
|
|
|
|
case "save":
|
|
// Delete any existing entries
|
|
$school_num = intval($_POST["school_num"]);
|
|
db_query("DELETE FROM school_referrals WHERE school_num = $school_num");
|
|
|
|
$table = new Table("school_referrals");
|
|
|
|
// Save defined entries
|
|
for ($n = 0; $n < 2; $n++) {
|
|
if (array_key_exists("rschool$n",$_POST) && $_POST["rschool$n"] > 0) {
|
|
$referring_school_num = intval($_POST["rschool$n"]);
|
|
$credit_amount = $_POST["credit_amount$n"];
|
|
$credit_given = $_POST["credit_given$n"];
|
|
$invoice_num = $_POST["invoice_num$n"];
|
|
$sequence = $n;
|
|
|
|
$query = $table->BuildInsert();
|
|
db_query($query);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
// Get records to display
|
|
$columnHeaders = array("School Name","Referred By","Credit Amount","Credited","Invoice Num");
|
|
$columnAlign = array('left','left','right','center','center');
|
|
|
|
$query = "select concat('<a href=http://',url,' target=_blank>',school_name,'</a>') as name,record_num " .
|
|
"from schools " .
|
|
"where status in ('Pending','Trial','Active') " .
|
|
"order by school_name";
|
|
$schools = db_query($query);
|
|
$data = array();
|
|
|
|
$count = 0;
|
|
while ($row = db_fetch_array($schools)) {
|
|
$data[$count][0] = $row['name'];
|
|
$data[$count]['record_num'] = $row['record_num'];
|
|
$snum = $row['record_num'];
|
|
|
|
$results = db_query("SELECT * FROM school_referrals WHERE school_num = $snum");
|
|
if (db_num_rows($results) == 0) {
|
|
$count++;
|
|
continue;
|
|
}
|
|
|
|
while ($referral = db_fetch_array($results)) {
|
|
$data[$count][0] = $row['name'];
|
|
$data[$count]['record_num'] = $row['record_num'];
|
|
$data[$count][2] = $referral['credit_amount'];
|
|
$data[$count][3] = $referral['credit_given'];
|
|
$data[$count][4] = $referral['invoice_num'];
|
|
|
|
$rnum = $referral['referring_school_num'];
|
|
$data[$count][1] = db_getVal("SELECT school_name FROM schools WHERE record_num = $rnum");
|
|
$count++;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$edit_icon = "<img src='images/icons/edit24.png' alt='Edit Referral' border='0'>";
|
|
$commands = array("<a href=?action=schools-referrals&naction=edit&school_num=%s>$edit_icon</a>");
|
|
listDataCustom($data,$columnHeaders,'schools-referrals',$commands,'N',$columnAlign);
|
|
|
|
echo("<br>\n");
|
|
|
|
include "schools.options.php";
|
|
endTemplate();
|
|
?>
|