Code:/************************************************************************/
/* NukeTreasury - MOD / Tweak to allow transaction maintenance */
/* Copyright (c) 2005 by Kevin Guske (kguske) */
/* Posted at RavenPHPScripts.com */
/* See license below */
/************************************************************************/
/* NukeTreasury - Financial management for PHP-Nuke */
/* Copyright (c) 2004 by Dave Lawrence AKA Thrash */
/* thrash@fragnastika.com */
/* thrashn8r@hotmail.com */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/************************************************************************/
This tweak allows the maintenance of transactions table records in the Nuke Treasury database that appear, if configured to do so, in the Donat-o-meter block. A simple "Transactions" link is added to the Admin Treasury page that displays the Transaction Transaction Register, which has the ability to add, change or delete transaction table records much in the same way the main Treasury admin page maintains financial table records.
If you find this useful (or otherwise feel charitable, appreciative and / or blessed), please consider contributing, even small amounts, to:
http://ravenphpscripts.com - for the best PHP-Nuke support
and / or
http://www.google.com/tsunami_relief.html - for the survivors of one of the worst disasters in history
and / or
http://nuketreasury.sourceforge.net/donate.html - to the creator of Nuke Treasury
Here are the changes:
------------------------------------------------------------------------------------------------------
In /admin/case/case.treasury.php, before (line 27 in the version 1.0 distribution):
case "FinRegAdd":
insert:
case "TransAdd":
case "TransEdit":
case "TransDel":
case "TransList":
to get:
switch($op) {
case "TransAdd":
case "TransEdit":
case "TransDel":
case "TransList":
case "FinRegAdd":
case "FinRegEdit":
case "FinRegDel":
case "ConfigUpdate":
case "Treasury":
case "UpdateGoals":
case "Config":
case "IpnRec":
include ("admin/modules/treasury.php");
break;
}
------------------------------------------------------------------------------------------------------
In /admin/modules/treasury.php, there are 3 additions (see below).
IMPORTANT: These changes use a configuration parameter, $ntprefix, which was added to the /modules/Donations/config.php to allow database sharing and table prefixes. If you use the table names defined with the standard Nuke Treasury 1.0 distribution, you can add this line to your /modules/Donations/config.php:
$ntprefix = "";
If you added a prefix to the standard database tables, add something like the following to your /modules/Donations/config.php, but change the parameter string to match your database prefix:
$ntprefix = "nuke_nt_"; // assumes Nuke Treasury tables have names like nuke_nt_financial, nuke_nt_transactions, and nuke_nt_config
-----------------------------------------------------
1. In function Treasury, after (line 128 in the version 1.0 distribution):
echo "<form action=\"admin.php?op=Config#AdminTop\" method=\"post\">";
insert:
// BEG MOD - Maintain Transactions
echo "<a href=\"admin.php?op=TransList\">Transactions</a> ";
// END MOD - Maintain Transactions
-----------------------------------------------------
2. At the bottom, after (lines 924-926 in the version 1.0 distribution):
case "IpnRec":
IpnRec();
break;
insert:
// BEG MOD - Maintain Transactions
case "TransAdd":
TransAdd();
break;
case "TransEdit":
TransEdit();
break;
case "TransDel":
TransDel();
break;
case "TransList":
TransList();
break;
// END MOD - Maintain Transactions
-----------------------------------------------------
3. At the bottom, before (line 898 in the version 1.0 distribution):
Switch($op)
insert the following 4 functions (quite a bit of code, just copy to the bottom):
// BEG MOD - Maintain Transactions
function TransList()
{
global $admin, $bgcolor2, $prefix, $dbi, $currentlang, $multilingual;
include ("header.php");
include("modules/Donations/config.php");
if( !$ipnppd )
{
echo "<br><br>NukeTreasury FATAL ERROR: Unable to connect to SQL database. Please check your settings in modules/Donations/config.php<br><br>";
return;
}
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
// Register paging
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_POST['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_POST['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_ipnppd, $ipnppd);
$query_Recordset1 = "SELECT id, payment_date, DATE_FORMAT(payment_date, '%d-%b-%Y') as fdate, txn_id, custom as name, option_selection1 as showname, mc_gross as gross, mc_fee as fee FROM " . $prefix . "_nt_transactions order by payment_date DESC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $ipnppd) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_POST['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_POST['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d#AdminTop", $totalRows_Recordset1);
// Output the page
OpenTable();
echo "<center><font class=\"option\"><b>Treasury Transaction Register</b></font></center><br>";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo "<tr><td width=\"100%\">";
echo "<form action=\"admin.php?op=Config#AdminTop\" method=\"post\">";
echo "<a href=\"admin.php?op=Treasury#AdminTop\">Treasury Admin</a> ";
echo "<a href=\"admin.php\">PHP-Nuke Admin</a> ";
echo "<a href=\"admin.php?op=TransList\">Transactions</a> ";
echo "<input type=\"hidden\" name=\"op\" value=\"Config\"><input type=\"submit\" value=\"Config\"></form>";
echo "</td></tr></table>";
$currentPage = "admin.php?op=Treasury";
echo "<center><table border=\"0\"><tr>";
if( $pageNum_Recordset1 > 0 )
{
echo '<td><form action="admin.php#AdminTop" method="post">'
. '<input type="hidden" name="op" value="TransList">'
. '<input type="hidden" name="pageNum_Recordset1" value="0">'
. '<input type="hidden" name="totalRows_Recordset1" value="' . $totalRows_Recordset1 . '">'
. '<input type="submit" name="navig" value="|<" title="Current"></form></td>';
echo '<td><form action="admin.php#AdminTop" method="post">'
. '<input type="hidden" name="op" value="TransList">'
. '<input type="hidden" name="pageNum_Recordset1" value="' . max(0, $pageNum_Recordset1 - 1) . '">'
. '<input type="hidden" name="totalRows_Recordset1" value="' . $totalRows_Recordset1 . '">'
. '<input type="submit" name="navig" value="<" title="Next newest"></form></td>';
}
if( $pageNum_Recordset1 < $totalPages_Recordset1 )
{
echo '<td><form action="admin.php#AdminTop" method="post">'
. '<input type="hidden" name="op" value="TransList">'
. '<input type="hidden" name="pageNum_Recordset1" value="' . min($totalPages_Recordset1, $pageNum_Recordset1 + 1) . '">'
. '<input type="hidden" name="totalRows_Recordset1" value="' . $totalRows_Recordset1 . '">'
. '<input type="submit" name="navig" value=">" title="Next Oldest"></form></td>';
echo '<td><form action="admin.php#AdminTop" method="post">'
. '<input type="hidden" name="op" value="TransList">'
. '<input type="hidden" name="pageNum_Recordset1" value="' . $totalPages_Recordset1 . '">'
. '<input type="hidden" name="totalRows_Recordset1" value="' . $totalRows_Recordset1 . '">'
. '<input type="submit" name="navig" value=">|" title="Oldest"></form></td>';
}
echo "</tr></table></center>";
echo "<table border=\"1\" width=\"100%\" align=\"center\"><tr>"
."<td bgcolor=\"$bgcolor2\" align=\"center\" width=\"4\"><b> </b></td>"
."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>Date</b></td>"
."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>Transaction ID</b></td>"
."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>Name</b></td>"
."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>Show<br>name?</b></td>"
."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>Gross</b></td>"
."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>Fee</b></td></tr><tr>";
echo ""
."<form action=\"admin.php\" method=\"post\" name=\"txnedit\"><td>"
."<input name=\"\" type=\"reset\" value=\"Reset\" onclick=\""
."document.txnedit.Submit.value = 'Add'; "
."document.txnedit.op.value = 'TransAdd'; "
."return true;\"><br>"
."<input type=\"hidden\" name=\"op\" value=\"TransAdd\"><input name=\"Submit\" type=\"submit\" value=\"Add\"></td>"
."<td align=\"left\" width=\"8\"><input name=\"id\" type=\"hidden\">"
."<input name=\"Date\" type=\"text\" size=\"11\" maxlength=\"11\"></td>"
."<td align=\"left\"><input name=\"TxnID\" type=\"text\" size=\"21\" maxlength=\"20\"></td>"
."<td align=\"left\"><input name=\"Name\" type=\"text\" size=\"21\" maxlength=\"20\"></td>"
."<td align=\"left\"><input name=\"ShowName\" type=\"text\" size=\"4\" maxlength=\"3\"></td>"
."<td align=\"right\"><input name=\"Gross\" type=\"text\" size=\"8\" style=\"text-align: right\"></td>"
."<td align=\"right\"><input name=\"Fee\" type=\"text\" size=\"8\" style=\"text-align: right\"></td></tr>";
echo "</form></tr></tr>";
$row=0;
do {
$row += 1;
echo "<tr>"
."<td align=\"center\">"
."<A HREF=\"javascript: void 0\" onclick=\""
."document.txnedit.id.value = '$row_Recordset1[id]'; "
."document.txnedit.Date.value = '$row_Recordset1[fdate]'; "
."document.txnedit.TxnID.value = '$row_Recordset1[txn_id]'; "
."document.txnedit.Name.value = '$row_Recordset1[name]'; "
."document.txnedit.ShowName.value = '$row_Recordset1[showname]'; "
."document.txnedit.Gross.value = '$row_Recordset1[gross]'; "
."document.txnedit.Fee.value = '$row_Recordset1[fee]'; "
."document.txnedit.Submit.value = 'Modify'; "
."document.txnedit.op.value = 'TransEdit'; "
."return false;\">"
."<img border=\"0\" width=\"12\" height=\"13\" src=\"images/admin/treasury_edit.png\"></a> "
."<a href=\"admin.php?op=TransDel&id=$row_Recordset1[id]\">"
."<img border=\"0\" width=\"12\" height=\"13\" src=\"images/admin/treasury_drop.png\" onClick=\"return confirm('Are you sure you want to delete this record?" . '\n\n' . "Are you sure you want to do this now?')\""
."></a></td>"
."<td align=\"left\">$row_Recordset1[fdate]</td>"
."<td align=\"left\" width=\"8\">$row_Recordset1[txn_id]</td>"
."<td align=\"left\">$row_Recordset1[name]</td>"
."<td align=\"left\">$row_Recordset1[showname]</td>"
."<td align=\"right\"><font ";
$amt = sprintf("%10.2f",$row_Recordset1[gross]);
if( $amt < 0 )
echo "color=\"#FF0000\"";
echo ">\$$amt</font></td>";
echo "<td align=\"right\"><font ";
$amt = sprintf("%10.2f",$row_Recordset1[fee]);
if( $amt < 0 )
echo "color=\"#FF0000\"";
echo ">\$$amt</font></td></tr>";
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
echo "</table>";
CloseTable();
echo "<br>";
include("footer.php");
mysql_free_result($Recordset1);
}
function TransAdd()
{
global $admin, $bgcolor2, $prefix, $dbi, $currentlang, $multilingual;
include ("header.php");
include("modules/Donations/config.php");
$PP_RECEIVER_EMAIL = $tr_config['receiver_email'];
$PP_ITEMNAME = $tr_config['pp_itemname'];
$ipnppd = mysql_pconnect($hostname_ipnppd, $username_ipnppd, $password_ipnppd) or die(mysql_error());
OpenTable();
echo "<center><font class=\"title\"><b>Treasury Transaction Record Add</b></font></center>";
CloseTable();
echo "<br>";
OpenTable();
$nTime = strtotime($_POST[Date]);
if($nTime == -1)
echo "Invalid Date format<br>";
else
if( strlen($_POST[Name]) == 0)
echo "The Name field cannot be blank<br>";
else
if( !is_numeric('0' .$_POST[Gross]))
echo "Invalid Gross Amount field<br>";
else
if( !is_numeric('0' .$_POST[Fee]))
echo "Invalid Fee Amount field<br>";
else
{
echo "Fields passed validation!<br>";
mysql_select_db($database_ipnppd, $ipnppd);
$insert_Recordset = "INSERT INTO `" . $prefix . "_nt_transactions` "
."(`id`,`business`,`txn_id`,`item_name`, `quantity`, `custom`, `option_name1`, `option_selection1`, `payment_status`, `payment_date`, `txn_type`, `mc_gross`, `mc_fee`, `mc_currency`)"
."VALUES "
."(NULL, '$PP_RECEIVER_EMAIL','" . $_POST[TxnID] . "', '$PP_ITEMNAME', '1','" . $_POST[Name] ."', 'Reveal Name?','" . $_POST[ShowName] . "', 'Completed', '" . strftime("%Y-%m-%d", $nTime) . "', 'web_accept', '" . $_POST[Gross] . "', '" . $_POST[Fee] . "', 'USD')";
$rvalue = mysql_query($insert_Recordset, $ipnppd) or die(mysql_error());
CloseTable();
Header("Location: admin.php?op=TransList");
}
}
function TransDel()
{
global $admin, $bgcolor2, $prefix, $dbi, $currentlang, $multilingual;
include ("header.php");
include("modules/Donations/config.php");
$ipnppd = mysql_pconnect($hostname_ipnppd, $username_ipnppd, $password_ipnppd) or die(mysql_error());
OpenTable();
echo "<center><font class=\"title\"><b>Treasury Transaction Record Delete</b></font></center>";
mysql_select_db($database_ipnppd, $ipnppd);
if( !(is_numeric($_GET[id]) && $_GET[id]>0))
{
echo "<br>Invalid record id specified, operation aborted<br>";
} else
{
$del_Recordset = "DELETE FROM `" . $prefix . "_nt_transactions` WHERE `id`='$_GET[id]' LIMIT 1";
$rvalue = mysql_query($del_Recordset, $ipnppd) or die(mysql_error());
CloseTable();
Header("Location: admin.php?op=TransList");
}
}
function TransEdit()
{
global $admin, $bgcolor2, $prefix, $dbi, $currentlang, $multilingual;
include ("header.php");
include("modules/Donations/config.php");
$ipnppd = mysql_pconnect($hostname_ipnppd, $username_ipnppd, $password_ipnppd) or die(mysql_error());
OpenTable();
echo "<center><font class=\"title\"><b>Treasury Transaction Record Edit</b></font></center>";
CloseTable();
echo "<br>";
OpenTable();
$nTime = strtotime($_POST[Date]);
if($nTime == -1)
echo "Invalid Date format<br>";
else
if( strlen($_POST[Name]) == 0)
echo "The Name field cannot be blank<br>";
else
if( !is_numeric('0' .$_POST[Gross]))
echo "Invalid Gross Amount field<br>";
else
if( !is_numeric('0' .$_POST[Fee]))
echo "Invalid Fee Amount field<br>";
else
{
echo "Field passed validation!<br>";
mysql_select_db($database_ipnppd, $ipnppd);
$insert_Recordset = "UPDATE `" . $prefix . "_nt_transactions` SET payment_date='". strftime("%Y-%m-%d", $nTime) . "', custom='$_POST[Name]', txn_id='$_POST[TxnID]', "
."option_selection1='$_POST[ShowName]', mc_gross='$_POST[Gross]', mc_fee='$_POST[Fee]' WHERE id='$_POST[id]' LIMIT 1";
$rvalue = mysql_query($insert_Recordset, $ipnppd) or die(mysql_error());
CloseTable();
Header("Location: admin.php?op=TransList");
}
}
// END MOD - Maintain Transactions
|