-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCartToFamily.php
334 lines (279 loc) · 11.4 KB
/
CartToFamily.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
/*******************************************************************************
*
* filename : CartToFamily.php
* last change : 2003-10-09
* description : Add cart records to a family
*
* http://www.infocentral.org/
* Copyright 2003 Chris Gebhardt
*
* 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";
// Security: User must have add records permission
if (!$_SESSION['bAddRecords'])
{
Redirect("Menu.php");
exit;
}
// Was the form submitted?
if (isset($_POST["Submit"]) && count($_SESSION['aPeopleCart']) > 0) {
// Get the FamilyID
$iFamilyID = FilterInput($_POST["FamilyID"],'int');
// Are we creating a new family
if ($iFamilyID == 0)
{
$sFamilyName = FilterInput($_POST["FamilyName"]);
$dWeddingDate = FilterInput($_POST["WeddingDate"]);
if ( strlen($dWeddingDate) > 0 )
$dWeddingDate = "\"" . $dWeddingDate . "\"";
else
$dWeddingDate = "NULL";
$iPersonAddress = FilterInput($_POST["PersonAddress"]);
if ($iPersonAddress != 0)
{
$sSQL = "SELECT * FROM person_per WHERE per_ID = " . $iPersonAddress;
$rsPerson = RunQuery($sSQL);
extract(mysql_fetch_array($rsPerson));
}
SelectWhichAddress($sAddress1, $sAddress2, FilterInput($_POST["Address1"]), FilterInput($_POST["Address2"]), $per_Address1, $per_Address2, false);
$sCity = SelectWhichInfo(FilterInput($_POST["City"]),$per_City);
$sZip = SelectWhichInfo(FilterInput($_POST["Zip"]),$per_Zip);
$sCountry = SelectWhichInfo(FilterInput($_POST["Country"]),$per_Country);
if ($sCountry == "United States" || $sCountry == "Canada")
$sState = FilterInput($_POST["State"]);
else
$sState = FilterInput($_POST["StateTextbox"]);
$sState = SelectWhichInfo($sState,$per_State);
// Get and format any phone data from the form.
$sHomePhone = FilterInput($_POST["HomePhone"]);
$sWorkPhone = FilterInput($_POST["WorkPhone"]);
$sCellPhone = FilterInput($_POST["CellPhone"]);
if (!isset($_POST["NoFormat_HomePhone"])) $sHomePhone = CollapsePhoneNumber($sHomePhone,$sCountry);
if (!isset($_POST["NoFormat_WorkPhone"])) $sWorkPhone = CollapsePhoneNumber($sWorkPhone,$sCountry);
if (!isset($_POST["NoFormat_CellPhone"])) $sCellPhone = CollapsePhoneNumber($sCellPhone,$sCountry);
$sHomePhone = SelectWhichInfo($sHomePhone,$per_HomePhone);
$sWorkPhone = SelectWhichInfo($sWorkPhone,$per_WorkPhone);
$sCellPhone = SelectWhichInfo($sCellPhone,$per_CellPhone);
$sEmail = SelectWhichInfo(FilterInput($_POST["Email"]),$per_Email);
if (strlen($sFamilyName) == 0) {
$sError = "<p class=\"MediumLargeText\" align=\"center\" style=\"color:red;\">" . gettext("No family name entered!") . "</p>";
$bError = true;
}
else
{
$sSQL = "INSERT INTO family_fam (fam_Name, fam_Address1, fam_Address2, fam_City, fam_State, fam_Zip, fam_Country, fam_HomePhone, fam_WorkPhone, fam_CellPhone, fam_Email, fam_WeddingDate, fam_DateEntered, fam_EnteredBy) VALUES ('" . $sFamilyName . "','" . $sAddress1 . "','" . $sAddress2 . "','" . $sCity . "','" . $sState . "','" . $sZip . "','" . $sCountry . "','" . $sHomePhone . "','" . $sWorkPhone . "','" . $sCellPhone . "','" . $sEmail . "'," . $dWeddingDate . ",'" . date("YmdHis") . "'," . $_SESSION['iUserID'] . ")";
RunQuery($sSQL);
//Get the key back
$sSQL = "SELECT MAX(fam_ID) AS iFamilyID FROM family_fam";
$rsLastEntry = RunQuery($sSQL);
extract(mysql_fetch_array($rsLastEntry));
}
}
if (!$bError)
{
// Loop through the cart array
$iCount = 0;
while ($element = each($_SESSION['aPeopleCart']))
{
$iPersonID = $_SESSION['aPeopleCart'][$element[key]];
$sSQL = "SELECT per_fam_ID FROM person_per WHERE per_ID = " . $iPersonID;
$rsPerson = RunQuery($sSQL);
extract(mysql_fetch_array($rsPerson));
// Make sure they are not already in a family
if ($per_fam_ID == 0)
{
$iFamilyRoleID = FilterInput($_POST["role" . $iPersonID],"int");
$sSQL = "UPDATE person_per SET per_fam_ID = " . $iFamilyID . ", per_fmr_ID = " . $iFamilyRoleID . " WHERE per_ID = " . $iPersonID;
RunQuery($sSQL);
$iCount++;
}
}
$sGlobalMessage = $iCount . " records(s) successfully added to selected Family.";
Redirect("FamilyView.php?FamilyID=" . $iFamilyID . "&Action=EmptyCart");
}
}
// Set the page title and include HTML header
$sPageTitle = gettext("Add Cart to Family");
require "Include/Header.php";
echo $sError;
?>
<form method="post">
<p align="center">
<input type="submit" class="icButton" name="Submit" value="<?php echo gettext("Add to Family"); ?>">
</p>
<?php
if (count($_SESSION['aPeopleCart']) > 0)
{
// Get all the families
$sSQL = "SELECT fam_Name, fam_ID FROM family_fam ORDER BY fam_Name";
$rsFamilies = RunQuery($sSQL);
// Get the family roles
$sSQL = "SELECT * FROM list_lst WHERE lst_ID = 2 ORDER BY lst_OptionSequence";
$rsFamilyRoles = RunQuery($sSQL);
$sRoleOptionsHTML = "";
while($aRow = mysql_fetch_array($rsFamilyRoles))
{
extract($aRow);
$sRoleOptionsHTML .= "<option value=\"" . $lst_OptionID . "\">" . $lst_OptionName . "</option>";
}
$sSQL = "SELECT per_Title, per_FirstName, per_MiddleName, per_LastName, per_Suffix, per_fam_ID, per_ID
FROM person_per WHERE per_ID IN (" . ConvertCartToString($_SESSION['aPeopleCart']) . ")
ORDER BY per_LastName";
$rsCartItems = RunQuery($sSQL);
echo "<table align=\"center\" width=\"25%\" cellpadding=\"4\" cellspacing=\"0\">\n";
echo "<tr class=\"TableHeader\">";
echo "<td> </td>";
echo "<td><b>" . gettext("Name") . "</b></td>";
echo "<td align=\"center\"><b>" . gettext("Assign Role") . "</b></td>";
$count = 1;
while ($aRow = mysql_fetch_array($rsCartItems))
{
$sRowClass = AlternateRowStyle($sRowClass);
extract($aRow);
echo "<tr class=\"" . $sRowClass . "\">";
echo "<td align=\"center\">" . $count++ . "</td>";
echo "<td><a href=\"PersonView.php?PersonID=" . $per_ID . "\">" . FormatFullName($per_Title, $per_FirstName, $per_MiddleName, $per_LastName, $per_Suffix, 1) . "</a></td>";
echo "<td align=\"center\">";
if ($per_fam_ID == 0)
echo "<select name=\"role" . $per_ID . "\">" . $sRoleOptionsHTML . "</select>";
else
echo gettext("Already in a family");
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
<BR>
<table align="center">
<tr>
<td class="LabelColumn"><?php echo gettext("Add to Family:"); ?></td>
<td class="TextColumn">
<?php
// Create the family select drop-down
echo "<select name=\"FamilyID\">";
echo "<option value=\"0\">" . gettext("Create new family") . "</option>";
while ($aRow = mysql_fetch_array($rsFamilies)) {
extract($aRow);
echo "<option value=\"" . $fam_ID . "\">" . $fam_Name . "</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td></td>
<td><p class="MediumLargeText"><?php echo gettext("If adding a new family, enter data below.");?></p></td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Family Name:"); ?></td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="FamilyName" value="<?php echo $sName; ?>" maxlength="48"><font color="red"><?php echo $sNameError; ?></font></td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Wedding Date:"); ?></td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="WeddingDate" value="<?php echo $dWeddingDate; ?>" maxlength="10" id="sel1" size="15"> <input type="image" onclick="return showCalendar('sel1', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo "<BR>" . $sWeddingDateError ?></font></td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Use address/contact data from:"); ?></td>
<td class="TextColumn">
<?php
echo "<select name=\"PersonAddress\">";
echo "<option value=\"0\">" . gettext("Only the new data below") . "</option>";
mysql_data_seek($rsCartItems,0);
while ($aRow = mysql_fetch_array($rsCartItems)) {
extract($aRow);
if ($per_fam_ID == 0)
echo "<option value=\"" . $per_ID . "\">" . $per_FirstName . ' ' . $per_LastName . "</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Address1:"); ?></td>
<td class="TextColumn"><input type="text" Name="Address1" value="<?php echo $sAddress1; ?>" size="50" maxlength="250"></td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Address2:"); ?></td>
<td class="TextColumn"><input type="text" Name="Address2" value="<?php echo $sAddress2; ?>" size="50" maxlength="250"></td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("City:"); ?></td>
<td class="TextColumn"><input type="text" Name="City" value="<?php echo $sCity; ?>" maxlength="50"></td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("State:"); ?></td>
<td class="TextColumn">
<?php require "Include/StateDropDown.php"; ?>
OR
<input type="text" name="StateTextbox" value="<?php if ($sCountry != "United States" && $sCountry != "Canada") echo $sState ?>" size="20" maxlength="30">
<BR><?php echo gettext("(Use the textbox for countries other than US and Canada)"); ?>
</td>
</tr>
<tr>
<td class="LabelColumn">
<?php
if($sCountry == "Canada")
echo gettext("Postal Code:");
else
echo gettext("Zip:");
?>
</td>
<td class="TextColumn">
<input type="text" Name="Zip" value="<?php echo $sZip; ?>" maxlength="10" size="8">
</td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Country:"); ?></td>
<td class="TextColumnWithBottomBorder">
<?php require "Include/CountryDropDown.php" ?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Home Phone:"); ?></td>
<td class="TextColumn">
<input type="text" Name="HomePhone" value="<?php echo $sHomePhone; ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_HomePhone" value="1" <?php if ($bNoFormat_HomePhone) echo " checked";?>><?php echo gettext("Do not auto-format"); ?>
</td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Work Phone:"); ?></td>
<td class="TextColumn">
<input type="text" name="WorkPhone" value="<?php echo $sWorkPhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_WorkPhone" value="1" <?php if ($bNoFormat_WorkPhone) echo " checked";?>><?php echo gettext("Do not auto-format"); ?>
</td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Mobile Phone:"); ?></td>
<td class="TextColumn">
<input type="text" name="CellPhone" value="<?php echo $sCellPhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_CellPhone" value="1" <?php if ($bNoFormat_CellPhone) echo " checked";?>><?php echo gettext("Do not auto-format"); ?>
</td>
</tr>
<tr>
<td class="LabelColumn"><?php echo gettext("Email:"); ?></td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="Email" value="<?php echo $sEmail; ?>" size="30" maxlength="50"></td>
</tr>
</table>
<p align="center">
<BR>
<input type="submit" class="icButton" name="Submit" value="<?php echo gettext("Add to Family"); ?>">
<BR><BR>
</p>
</form>
<?php
}
else
echo "<p align=\"center\" class=\"LargeText\">" . gettext("Your cart is empty!") . "</p>";
require "Include/Footer.php";
?>