Location: PHPKode > projects > InfoCentral > infocentral/DonationEnvelopes.php
<?php
/*******************************************************************************
 *
 *  filename    : DonationEnvelopes.php
 *  last change : 2003-06-03
 *  webpage     : http://www.infocentral.org
 *  copyright   : Copyright 2003 Chris Gebhardt
 *  description : Manages Donation Envelope assignments
 *
 *  InfoCentral 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, or
 *  (at your option) any later version.
 *
 ******************************************************************************/

//Include the function library
require "Include/Config.php";
require "Include/Functions.php";

if (!$_SESSION['bFinance'])
{
	Redirect("Menu.php");
	exit;
}

//Set the page title
$sPageTitle = gettext("Donation Envelope Manager");

$sMode = $_GET['Mode'];

if ($sMode == 'cartadd')
{
	$sSQL = "SELECT DISTINCT per_Envelope AS iEnvelope FROM person_per WHERE per_Envelope != 'NULL' ORDER BY per_Envelope ASC";
	$result = RunQuery($sSQL);
	$lastEnvelope = 0;
	$numOptions = 0;
	while ($aRow = mysql_fetch_array($result))
	{
		$thisEnvelope = $aRow['iEnvelope'];
		for($iOption = $lastEnvelope + 1; $iOption < $thisEnvelope; $iOption++)
		{
			$aEnvelopeOptions[$numOptions++] = $iOption;
		}
		$lastEnvelope = $thisEnvelope;
	}

	for ($iCount = 0; $iCount <= (count($_SESSION['aPeopleCart']) - 1); $iCount++)
	{
		$thisPerson = $_SESSION['aPeopleCart'][$iCount];
		$sSQL = "SELECT per_Envelope FROM person_per WHERE per_ID = " . $thisPerson;
		$result = RunQuery($sSQL);
		extract(mysql_fetch_array($result));
		if (!isset($per_Envelope))
		{
			// Use up any unassigned envelopes first.  Then, create new (higher) numbers.
			if ($numOptions > 0)
				$newEnvelope = $aEnvelopeOptions[$numOptions-- - 1];
			else
				$newEnvelope = ++$lastEnvelope;
			$sSQL = "UPDATE person_per SET per_Envelope = $newEnvelope WHERE per_ID = $thisPerson";
			RunQuery($sSQL);
		}
	}
}

elseif ($sMode == 'reassign' && isset($_GET['Confirmed']))
{
	$sSQL = "SELECT per_ID FROM person_per WHERE per_Envelope != 'NULL' ORDER BY per_LastName,per_Firstname ASC";
	$result = RunQuery($sSQL);
	$newEnvelope = 1;
	while ($aRow = mysql_fetch_array($result))
	{
		$sSQL = "UPDATE person_per SET per_Envelope = " . $newEnvelope++ . " WHERE per_ID = " . $aRow['per_ID'];
		RunQuery($sSQL);
	}
}

$sSQL = "SELECT DISTINCT per_Envelope AS iEnvelope FROM person_per WHERE per_Envelope != 'NULL' ORDER BY per_Envelope ASC";
$result = RunQuery($sSQL);
$iAssignedEnvelopes = mysql_num_rows($result);

$iYear = date("Y");
$sDate = "$iYear-1-1" ;

$sSQL = "SELECT DISTINCT don_Envelope FROM donations_don WHERE don_Envelope != 'NULL' AND don_Date > '$sDate'";
$result = RunQuery($sSQL);
$iActiveEnvelopes = mysql_num_rows($result);

$sSQL = "SELECT MAX(per_Envelope) AS iMaxEnvelopeID FROM person_per";
$result = RunQuery($sSQL);
extract(mysql_fetch_array($result));

require "Include/Header.php";
?>

<table align="center" cellpadding="5" cellspacing="1" border="0">
	<tr>
		<td class="LabelColumn"><?php echo gettext("Assigned Envelopes:"); ?></td>
		<td class="TextColumn"><?php echo $iAssignedEnvelopes; ?></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Active Envelopes this Year:"); ?></td>
		<td class="TextColumn"><?php echo $iActiveEnvelopes; ?></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Highest Envelope Number:"); ?></td>
		<td class="TextColumn"><?php echo $iMaxEnvelopeID; ?></td>
	</tr>
</table>

<?php
if ($sMode == 'reassign' && !isset($_GET['Confirmed'])) { ?>

<table align="center" cellpadding="5" cellspacing="1" border="0">
	<tr>
		<td>
			<br><p class="LargeText">
			<?php echo gettext("<b>Warning :</b> This envelope re-assignment feature will change <i>everyone's</i> envelope number.<br>"); ?>
			<?php echo gettext("You should only use this if you will be handing out new envelopes. (such as with the beginning"); ?><br>
			<?php echo gettext("of a new fiscal year)  This feature will re-assign envelope numbers alphabetically by Lastname /"); ?><br>
			<?php echo gettext("Firstname <i>only</i> to those who <i>already</i> have an envelope assigned."); ?><br>
			</p><br>
			<h3><a href="DonationEnvelopes.php?Mode=reassign&Confirmed=yes"><?php echo gettext("Yes, re-assign envelopes (This action CANNOT be undone!)"); ?></a></h3>
			<h2><a href="DonationEnvelopes.php"><?php echo gettext("No, cancel this operation."); ?></a></h2>
		</td>
	</tr>
</table>

<?php } else { ?>
<table align="center" cellpadding="5" cellspacing="1" border="0">
	<tr>
		<td>
			<br><br>
			<a href="Reports/DonationEnvelopeList.php"><?php echo gettext("Display a list of all envelope assignments"); ?></a><br><br>
			<a href="DonationEnvelopes.php?Mode=cartadd"><?php echo gettext("Auto-assign envelopes to all persons in the cart without envelopes"); ?></a><br><br>
			<a href="DonationEnvelopes.php?Mode=reassign"><?php echo gettext("Re-assign all existing envelopes by assignees' names in alphabetical order"); ?></a>
		</td>
	</tr>
</table>
<?php
}

require "Include/Footer.php";
?>
Return current item: InfoCentral