377 lines
16 KiB
PHP
377 lines
16 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$action = "paypal-log";
|
|
$CurrentTable = "user_paypal_transactions";
|
|
$FormFile = "";
|
|
$TitleText = getLanguageText('TEXT-PAYPAL-LOG');
|
|
$OrderBy = "posting_time";
|
|
|
|
if (array_key_exists('type',$_REQUEST) && strlen($_REQUEST['type']) > 0 && $_REQUEST['type'] == 'deleted') {
|
|
$TitleText .= " (" . getLanguageText('TEXT-DELETED') . ")";
|
|
}
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = $TitleText;
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
$school_num = $school_record['record_num'];
|
|
|
|
?>
|
|
<br>
|
|
<?php
|
|
|
|
// Handle selected date ranges
|
|
$start_date = date("Y-m-d 00:00:00",time());
|
|
$end_date = date("Y-m-d 23:59:59",time());
|
|
|
|
$sdate = substr($start_date,0,10);
|
|
$edate = substr($end_date,0,10);
|
|
|
|
$twhere = "AND posting_time BETWEEN '$start_date' AND '$end_date' ";
|
|
|
|
|
|
if (array_key_exists('action',$_POST) && strlen($_POST['action']) > 0) {
|
|
if (array_key_exists('start_date',$_POST) && strlen($_POST['start_date']) > 0) $start_date = date("Y-m-d 00:00:00",strtotime($_POST['start_date']));
|
|
if (array_key_exists('end_date',$_POST) && strlen($_POST['end_date']) > 0) {
|
|
$end_date = $_POST['end_date'];
|
|
if ($end_date < substr($start_date,0,10)) {
|
|
$end_date = substr($start_date,0,10);
|
|
$error_message = getLanguageText('ERRORMSG-INVALID-DATE-RANGE');
|
|
}
|
|
|
|
$end_date = date("Y-m-d 23:59:59",strtotime($end_date));
|
|
}
|
|
|
|
$sdate = substr($start_date,0,10);
|
|
$edate = substr($end_date,0,10);
|
|
|
|
$twhere = "AND posting_time BETWEEN '$start_date' AND '$end_date' ";
|
|
|
|
|
|
// View only a selected userid
|
|
$uwhere = "";
|
|
unset($selected_user);
|
|
if (array_key_exists('selected_user',$_POST) && strlen($_POST['selected_user']) > 0) {
|
|
$selected_user = $_POST['selected_user'];
|
|
$uwhere = "AND payer_email = '$selected_user' ";
|
|
}
|
|
|
|
|
|
// Build argument string for GET
|
|
$args = "&start_date=" . urlencode($start_date);
|
|
$args .= "&end_date=" . urlencode($end_date);
|
|
if (isset($selected_user)) $args .= "&selected_user=$selected_user";
|
|
$args .= "&error_message=" . urlencode($error_message);
|
|
header("Location: /?action=$action$args");
|
|
exit();
|
|
}
|
|
|
|
if (array_key_exists('action',$_GET) && array_key_exists('start_date', $_GET)) {
|
|
$start_date = $_GET['start_date'];
|
|
$end_date = $_GET['end_date'];
|
|
|
|
$sdate = substr($start_date,0,10);
|
|
$edate = substr($end_date,0,10);
|
|
|
|
$twhere = "AND posting_time BETWEEN '$start_date' AND '$end_date' ";
|
|
|
|
// View only a selected userid
|
|
$uwhere = "";
|
|
unset($selected_user);
|
|
if (array_key_exists('selected_user',$_GET) && strlen($_GET['selected_user']) > 0) {
|
|
$selected_user = $_GET['selected_user'];
|
|
$uwhere = "AND payer_email = '$selected_user' ";
|
|
}
|
|
}
|
|
|
|
|
|
$message_width = 600;
|
|
include "form.messages.php";
|
|
|
|
?>
|
|
<form method='post' name='transactions'>
|
|
<table width='600' cellpadding='3' class='content-table'>
|
|
<tr>
|
|
<td align='right'><?php displayLanguageText('TEXT-START-DATE'); ?>: </td>
|
|
<td align='left'><input type='text' name='start_date' id='start_date' value='<?php echo($sdate) ?>' size='15' class='date-field'></td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right'><?php displayLanguageText('TEXT-END-DATE'); ?>: </td>
|
|
<td align='left'><input type='text' name='end_date' id='end_date' value='<?php echo($edate) ?>' size='15' class='date-field'></td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right' valign='top'><?php displayLanguageText('TEXT-USER'); ?>: </td>
|
|
<td align='left'>
|
|
<select name='selected_user'>
|
|
<option value=''><?php displayLanguageText('TEXT-VIEW-ALL'); ?></option>
|
|
<?php
|
|
// List userid's from user_paypal_transactions table
|
|
$results = db_query("select distinct payer_email,first_name,last_name from user_paypal_transactions where school_num = $school_num and current_year != 'N' order by last_name,first_name");
|
|
while ($row = db_fetch_array($results)) {
|
|
$email = $row['payer_email'];
|
|
$fname = $row['first_name'];
|
|
$lname = $row['last_name'];
|
|
|
|
$selected = "";
|
|
if (isset($selected_user) && $selected_user == $email) $selected = " selected='selected'";
|
|
echo(" <option value='$email'$selected>$fname $lname ($email)</option>\n");
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align='right' valign='top'></td>
|
|
<td align='left' valign='top'><a href='#' class='btn btn--primary btn--xsmall' onClick='document.transactions.submit();'><span><?php displayLanguageText('TEXT-VIEW'); ?></span></a></td>
|
|
</tr>
|
|
</table>
|
|
<input type='hidden' name='action' value='paypal-log'>
|
|
</form>
|
|
<?php
|
|
|
|
|
|
//
|
|
// List all requested records
|
|
//
|
|
if (!isset($uwhere)) $uwhere = '';
|
|
if (!isset($swhere)) $swhere = '';
|
|
$query = "SELECT posting_time,payment_date,first_name,last_name,payer_email,mc_currency,mc_gross,mc_fee,payment_type,payment_status,pending_reason," .
|
|
"item_name,business,receiver_email,txn_id,receipt_id,trx_num,user_num,posting_result,posting_message,record_num " .
|
|
"FROM user_paypal_transactions " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND current_year != 'N' " .
|
|
$uwhere . $twhere . $swhere .
|
|
"ORDER BY posting_time,last_name";
|
|
$transactions = db_query($query);
|
|
|
|
$num_transactions = db_num_rows($transactions);
|
|
if ($num_transactions > 0) {
|
|
?>
|
|
<p><b><?php displayLanguageText('TEXT-ACCOUNT-TRANSACTIONS'); ?> - <?php echo($num_transactions) ?></b></p>
|
|
<table width='900' class='content-table'>
|
|
<tr>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-PAYMENT-DATE'); ?></b></td>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-NAME'); ?></b></td>
|
|
<td align='right' class='data-header'><b><?php displayLanguageText('TEXT-AMOUNT'); ?></b></td>
|
|
<td align='right' class='data-header'><b><?php displayLanguageText('TEXT-FEE'); ?></b></td>
|
|
<td align='center' class='data-header'><b><?php displayLanguageText('TEXT-TYPE'); ?></b></td>
|
|
<td align='center' class='data-header'><b><?php displayLanguageText('TEXT-STATUS'); ?></b></td>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-TRX-ID'); ?></b></td>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-EMAIL'); ?></b></td>
|
|
<td align='center' class='data-header'><b><?php displayLanguageText('TEXT-POSTING-RESULT'); ?></b></td>
|
|
</tr>
|
|
<?php
|
|
$count = 1;
|
|
$otipSpans = "";
|
|
$otipSpanIDs = array();
|
|
|
|
while ($row = db_fetch_array($transactions)) {
|
|
extract($row);
|
|
$trxID = $record_num;
|
|
|
|
$bgclass = "data-even";
|
|
if ($count % 2) $bgclass = "data-odd";
|
|
$count++;
|
|
|
|
// Format amounts
|
|
if ($mc_gross > 0) $mc_gross = "$" . number_format($mc_gross,2);
|
|
if ($mc_fee > 0) $mc_fee = "$" . number_format($mc_fee,2);
|
|
|
|
// Add info tips
|
|
if ($payment_status == 'Pending') {
|
|
$span_id = "status_$record_num";
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,'Pending Reason:',$pending_reason) . "</table></span>\n";
|
|
$otipSpanIDs[] = $span_id;
|
|
$payment_status = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Pending</a>";
|
|
}
|
|
|
|
// Unknown posting results
|
|
if ($posting_result == '') {
|
|
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND payment_reference = '$txn_id'");
|
|
if (db_num_rows($results) > 0) {
|
|
$posting_result = 'Posted';
|
|
}
|
|
else {
|
|
$posting_result = 'Error';
|
|
}
|
|
}
|
|
|
|
// Error postings
|
|
if ($posting_result == 'Error') {
|
|
$span_id = "result_$record_num";
|
|
if (strlen($posting_message) == 0) $posting_message = "Unknown Posting Error";
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,'Posting Error:',$posting_message) . "</table></span>\n";
|
|
$otipSpanIDs[] = $span_id;
|
|
$msg = getLanguageText('TEXT-CONFIRM-UPDATE');
|
|
$posting_result = "<span class='error'><a href='?action=pp-post&trx_num=$record_num' onClick='return confirm(\"$msg\");' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Error</a></span>";
|
|
}
|
|
|
|
// Successful postings
|
|
if ($posting_result == 'Posted') {
|
|
$span_id = "result_$record_num";
|
|
|
|
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND payment_reference = '$txn_id'");
|
|
if (db_num_rows($results) > 0) {
|
|
$otipSpanIDs[] = $span_id;
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE;
|
|
$otipSpans .= sprintf($otipROW2,"Transaction Num:",$trx_num);
|
|
$otipSpans .= sprintf($otipROW2,"Item:",$item_name);
|
|
$otipSpans .= sprintf($otipROW2,"Business:",$business);
|
|
$otipSpans .= sprintf($otipROW2,"Receiver:",$receiver_email);
|
|
|
|
$row = db_fetch_array($results);
|
|
$otipSpans .= sprintf($otipROW2,"User Acct TRX:",$record_num);
|
|
$order_payments = $row['order_payments'];
|
|
$orders = explode("|",$order_payments);
|
|
|
|
for ($i = 0; $i < count($orders); $i++) {
|
|
$order_num = preg_replace('/\{(\d+):\d+.\d+\}/','{$1}',$orders[$i]);
|
|
|
|
if (!is_numeric($order_num)) continue;
|
|
|
|
// Get order info
|
|
$results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
|
|
$row = db_fetch_array($results);
|
|
|
|
// Get schedule info
|
|
$schedule_num = $row['schedule_num'];
|
|
$schedule_name = "Unknown";
|
|
if (is_numeric($schedule_num) && $schedule_num > 0) {
|
|
$schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
|
|
}
|
|
|
|
// Get person info
|
|
$person_num = $row['ordered_by_num'];
|
|
$oname = "Unknown";
|
|
if (is_numeric($person_num) && $person_num > 0) {
|
|
$oname = db_getVal("SELECT concat(first_name,' ',last_name) FROM people WHERE school_num = $base_school_num AND record_num = $person_num");
|
|
}
|
|
|
|
$otipSpans .= "<tr><td align='center' colspan='2'><hr></td></tr>\n";
|
|
|
|
$otipSpans .= sprintf($otipROW2,"Order Number: ",$order_num);
|
|
$otipSpans .= sprintf($otipROW2,"Ordered By: ",$oname);
|
|
$otipSpans .= sprintf($otipROW2,"Order Schedule: ",$schedule_name);
|
|
// $otipSpans .= sprintf($otipROW2,"Order Status: ",$row['status']);
|
|
$otipSpans .= sprintf($otipROW2,"Order Date: ",$row['added_date']);
|
|
// $otipSpans .= sprintf($otipROW2,"Last Updated: ",$row['updated_date']);
|
|
}
|
|
|
|
$otipSpans .= "</table></span>\n";
|
|
$posting_result = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Posted</a>";
|
|
}
|
|
else {
|
|
if ($row['payment_status'] != 'Pending') {
|
|
$otipSpanIDs[] = $span_id;
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE;
|
|
$otipSpans .= sprintf($otipROW2,"Transaction Num:",$trx_num);
|
|
$otipSpans .= "<tr><td align='center' colspan='2'><hr></td></tr>\n";
|
|
$otipSpans .= "<tr><td align='center' colspan='2'><b>Unable to locate the<br>user account transaction<br>for this PayPal payment</b></td></tr>\n";
|
|
$otipSpans .= "</table></span>\n";
|
|
$posting_result = "<span class='warning'>" .
|
|
"<a href='?action=pp-post&trx_num=$record_num' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Warning</a></span>";
|
|
}
|
|
else {
|
|
$posting_result = "Pending";
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($posting_result == 'Pending') {
|
|
$ppFields = array("payment_date","item_name","business","receiver_email","transaction_subject","txn_type","first_name","last_name","payer_email","payer_status",
|
|
"mc_currency","mc_gross","mc_fee","reference","payment_type","payment_status","pending_reason","trx_num","posting_message");
|
|
$results = db_query("SELECT * FROM user_paypal_transactions WHERE school_num = $school_num AND txn_id = '$txn_id' ORDER BY record_num");
|
|
$span_id = "pending_$record_num";
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE;
|
|
|
|
$num = 0;
|
|
while ($row = db_fetch_array($results)) {
|
|
if ($num > 0) $otipSpans .= "<tr><td align='center' colspan='2'><hr></td></tr>\n";
|
|
for ($i = 0; $i < count($ppFields); $i++) {
|
|
$field = $ppFields[$i];
|
|
$otipSpans .= sprintf($otipROW2,"$field:",$row[$field]);
|
|
}
|
|
$num++;
|
|
}
|
|
$otipSpans .= "</table></span>\n";
|
|
$posting_result = "Pending";
|
|
$posting_result = "<span class='warning'>" .
|
|
"<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Pending</a></span>";
|
|
}
|
|
|
|
|
|
// Format name
|
|
$name = "$first_name $last_name";
|
|
if (is_numeric($user_num) && $user_num > 0) {
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND record_num = $user_num");
|
|
if (db_num_rows($results)) {
|
|
$row = db_fetch_array($results);
|
|
$span_id = "user_$user_num";
|
|
if (!in_array($span_id,$otipSpanIDs)) {
|
|
$user_balance = db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)");
|
|
$user_balance = floatval($user_balance);
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,"User Num: ",$user_num) .
|
|
sprintf($otipROW2,"User ID: ",$row['userid']) .
|
|
sprintf($otipROW2,"User Type: ",$row['type']) .
|
|
sprintf($otipROW2,"Name: ",$row['first_name'] . ' ' . $row['last_name']) .
|
|
sprintf($otipROW2,"Email: ",$row['email']) .
|
|
sprintf($otipROW2,"Phone: ",$row['home_phone']) .
|
|
sprintf($otipROW2,'<nobr>' . getLanguageText('TEXT-CURRENT-BALANCE') . ': </nobr>',$currencySymbol . number_format($user_balance,2)) .
|
|
"</table></span>\n";
|
|
$otipSpanIDs[] = $span_id;
|
|
}
|
|
$name = "<a href='?action=user-account&naction=list&user_num=$user_num' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$name</a>";
|
|
}
|
|
|
|
$pemail = $payer_email;
|
|
if (strlen($pemail) > 20) $pemail = substr($pemail,0,20) . "...";
|
|
$payer_email = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$pemail</a>";
|
|
}
|
|
|
|
?>
|
|
<tr>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($payment_date); ?></td>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($name); ?></td>
|
|
<td align='right' class='<?php echo($bgclass) ?>'><?php echo($mc_gross); ?></td>
|
|
<td align='right' class='<?php echo($bgclass) ?>'><?php echo($mc_fee); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($payment_type); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($payment_status); ?></td>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($txn_id); ?></td>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($payer_email); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($posting_result); ?></td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
?>
|
|
</table>
|
|
<?php
|
|
}
|
|
|
|
endTemplate();
|
|
?>
|