-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageEnvelopes.php
223 lines (190 loc) · 6.34 KB
/
ManageEnvelopes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/*******************************************************************************
*
* filename : ManageEnvelopes.php
* last change : 2005-02-21
* website : http://www.churchdb.org
* copyright : Copyright 2006 Michael Wilt
*
* ChurchInfo 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";
require "Include/EnvelopeFunctions.php";
//Set the page title
$sPageTitle = gettext("Envelope Manager");
// Security: User must have finance permission to use this form
if (!$_SESSION['bFinance']) {
Redirect("Menu.php");
exit;
}
if (isset($_POST["Confirm"]) or isset($_POST["Confirm"])) {
$updateEnvelopes = 0;
if (isset($_POST["Confirm"])) {
$envelopesToWrite = $_SESSION['envelopesToWrite'];
foreach ($envelopesToWrite as $fam_ID => $envelope) {
$dSQL = "UPDATE family_fam SET fam_Envelope='" . $envelope . "' WHERE fam_ID='" . $fam_ID . "'";
RunQuery($dSQL);
}
}
}
if (!$updateEnvelopes) {
if (isset($_POST["Classification"])) {
$iClassification = $_POST["Classification"];
$_SESSION['classification'] = $iClassification;
} else {
$iClassification = $_SESSION['classification'];
}
if (isset($_POST["SortBy"])) {
$sSortBy = $_POST["SortBy"];
} else {
$sSortBy = "name";
}
if (isset($_POST["AssignStartNum"])) {
$iAssignStartNum = $_POST["AssignStartNum"];
} elseif (!$iAssignStartNum) {
$iAssignStartNum = 1;
}
$envelopesHash = getEnvelopes($iClassification);
$familyArray = getFamilyList($sDirRoleHead, $sDirRoleSpouse, $iClassification);
asort($familyArray);
//Get Classifications for the drop-down
$sSQL = "SELECT * FROM list_lst WHERE lst_ID = 1 ORDER BY lst_OptionSequence";
$rsClassifications = RunQuery($sSQL);
while ($aRow = mysql_fetch_array($rsClassifications)) {
extract($aRow);
$classification[$lst_OptionID] = $lst_OptionName;
}
}
require "Include/Header.php";
?>
<form method="post" action="ManageEnvelopes.php" name="ManageEnvelopes">
<?php
$duplicateEnvelopeHash = array();
// Service the action buttons
if (isset($_POST["PrintReport"])) {
redirect ("Reports/EnvelopeReport.php");
} elseif (isset($_POST["AssignAllFamilies"])) {
$newEnvNum = $iAssignStartNum;
$envelopesToWrite = array(); // zero it out
foreach ($familyArray as $fam_ID => $fam_Data) {
$envelopesHash[$fam_ID] = $newEnvNum;
$envelopesToWrite[$fam_ID] = $newEnvNum++;
}
} elseif (isset($_POST["ZeroAll"])) {
$envelopesHash = array(); // zero it out
foreach ($familyArray as $fam_ID => $fam_Data) {
$envelopesHash[$fam_ID] = 0;
$envelopesToWrite[$fam_ID] = 0;
}
} elseif (isset($_POST["UpdateEnvelopes"])) {
$updateEnvelopes = 1;
foreach ($familyArray as $fam_ID => $fam_Data) {
$key = "EnvelopeID_" . $fam_ID;
if (isset($_POST[$key])) {
$newEnvelope = $_POST[$key];
$priorEnvelope = $envelopesHash[$fam_ID];
if ($newEnvelope <> $priorEnvelope) {
$envelopesToWrite[$fam_ID] = $newEnvelope;
}
}
}
$_SESSION['envelopesToWrite'] = $envelopesToWrite;
?>
<input type="submit" class="icButton" value="<?php echo gettext("Confirm"); ?>"
name="Confirm">
<input type="submit" class="icButton" value="<?php echo gettext("Cancel"); ?>"
name="Cancel">
<?php
}
if (!$updateEnvelopes) {
if ($envelopesToWrite) {
$_SESSION['envelopesToWrite'] = $envelopesToWrite;
}
?>
<input type="submit" class="icButton" value="<?php echo gettext("Print Report"); ?>"
name="PrintReport">
<br><br>
<input type="submit" class="icButton" value="<?php echo gettext("Update Family Records"); ?>"
name="UpdateEnvelopes"> <-- Envelope #'s are not written to DB until this button is pressed
<br><br>
<table border=1>
<tr>
<td><b>Family Select</b> with at least one:
<select name="Classification">
<option value="0"><?php echo gettext("All"); ?></option>
<?php
foreach ($classification as $lst_OptionID => $lst_OptionName) {
echo "<option value=\"" . $lst_OptionID . "\"";
if ($iClassification == $lst_OptionID) echo " selected";
echo ">" . $lst_OptionName . " ";
}
?>
</select>
<input type="submit" class="icButton" value="<?php echo gettext("Sort by"); ?>" name="Sort">
<input type="radio" Name="SortBy" value="name"
<?php if ($sSortBy == "name") echo " checked"; ?>><?php echo gettext("Last Name"); ?>
<input type="radio" Name="SortBy" value="envelope"
<?php if ($sSortBy == "envelope") echo " checked"; ?>><?php echo gettext("Envelope #"); ?>
</td>
<td><b>Envelope</b>
<input type="submit" class="icButton" value="<?php echo gettext("Zero"); ?>"
name="ZeroAll">
<input type="submit" class="icButton" value="<?php echo gettext("Assign starting at #"); ?>"
name="AssignAllFamilies">
<input type="text" name="AssignStartNum" value="<?php echo $iAssignStartNum; ?>" maxlength="5">
</td></tr>
<?php
if ($_POST["SortBy"] == "envelope") {
asort($envelopesHash);
$arrayToLoop = $envelopesHash;
} else {
$arrayToLoop = $familyArray;
}
foreach ($arrayToLoop as $fam_ID => $value) {
if ($_POST["SortBy"] == "envelope") {
$envelope = $value;
$fam_Data = $familyArray[$fam_ID];
} else {
$fam_Data = $value;
$envelope = $envelopesHash[$fam_ID];
}
echo "<tr>";
echo "<td>" . $fam_Data . " </td>";
if ($envelope and $duplicateEnvelopeHash and array_key_exists($envelope, $duplicateEnvelopeHash)) {
$tdTag = "<td bgcolor='red'>";
} else {
$duplicateEnvelopeHash[$envelope] = $fam_ID;
$tdTag = "<td>";
}
echo $tdTag;?><class="TextColumn">
<input type="text" name="EnvelopeID_<?php echo $fam_ID; ?>" value="<?php echo $envelope; ?>" maxlength="10">
</td></tr>
<?php
}
}
?>
</table><br>
</form>
<?php
function getEnvelopes($classification) {
if ($classification) {
$sSQL = "SELECT fam_ID, fam_Envelope FROM family_fam LEFT JOIN person_per ON fam_ID = per_fam_ID WHERE per_cls_ID='" . $classification . "'";
} else {
$sSQL = "SELECT fam_ID, fam_Envelope FROM family_fam";
}
$sSQL .= " ORDER by fam_Envelope";
$dEnvelopes = RunQuery($sSQL);
while ($aRow = mysql_fetch_array($dEnvelopes)) {
extract($aRow);
$envelopes[$fam_ID] = $fam_Envelope;
}
return $envelopes;
}
require "Include/Footer.php";
?>