/
SelectList.php
1544 lines (1332 loc) · 58.9 KB
/
SelectList.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*******************************************************************************
*
* filename : SelectList.php
* website : http://www.churchdb.org
* copyright : Copyright 2001-2003 Deane Barker and Chris Gebhardt
*
* Additional Contributors:
* 2006 Ed Davis
*
*
* Copyright Contributors
*
* 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.
*
* This file best viewed in a text editor with tabs stops set to 4 characters
*
******************************************************************************/
//Include the function library
require "Include/Config.php";
require "Include/Functions.php";
$iTenThousand = 10000; // Constant used to offset negative choices in drop down lists
// Create array with Classification Information (lst_ID = 1)
$sClassSQL = "SELECT * FROM list_lst WHERE lst_ID=1 ORDER BY lst_OptionSequence";
$rsClassification = RunQuery($sClassSQL);
unset($aClassificationName);
$aClassificationName[0] = "Unassigned";
while ($aRow = mysql_fetch_array($rsClassification))
{
extract($aRow);
$aClassificationName[intval($lst_OptionID)]=$lst_OptionName;
}
// Create array with Family Role Information (lst_ID = 2)
$sFamRoleSQL = "SELECT * FROM list_lst WHERE lst_ID=2 ORDER BY lst_OptionSequence";
$rsFamilyRole = RunQuery($sFamRoleSQL);
unset($aFamilyRoleName);
$aFamilyRoleName[0] = "Unassigned";
while ($aRow = mysql_fetch_array($rsFamilyRole))
{
extract($aRow);
$aFamilyRoleName[intval($lst_OptionID)]=$lst_OptionName;
}
// Create array with Person Property
// Get the total number of Person Properties (p) in table Property_pro
$sSQL = "SELECT * FROM property_pro WHERE pro_Class=\"p\"";
$rsPro = RunQuery($sSQL);
$ProRows = mysql_num_rows($rsPro);
// Set a count variable
$i = 1;
$sPersonPropertySQL = "SELECT * FROM property_pro WHERE pro_Class=\"p\" ORDER BY pro_Name";
$rsPersonProperty = RunQuery($sPersonPropertySQL);
unset($aPersonPropertyName);
$aPersonPropertyName[0] = "Unassigned";
while ( $i <= $ProRows ) {
$aRow = mysql_fetch_array($rsPersonProperty);
extract($aRow);
$aPersonPropertyName[intval($pro_ID)]=$pro_Name;
$i++;
}
// Create array with Group Type Information (lst_ID = 3)
$sGroupTypeSQL = "SELECT * FROM list_lst WHERE lst_ID=3 ORDER BY lst_OptionSequence";
$rsGroupTypes = RunQuery($sGroupTypeSQL);
unset($aGroupTypes);
while ($aRow = mysql_fetch_array($rsGroupTypes))
{
extract($aRow);
$aGroupTypes[intval($lst_OptionID)]=$lst_OptionName;
}
// Filter received user input as needed
if (strlen($_GET["Sort"]))
$sSort = FilterInput($_GET["Sort"]);
else
$sSort = "name";
if (isset($_GET["PrintView"]))
$bPrintView = true;
if (strlen($_GET["Filter"]))
$sFilter = FilterInput($_GET["Filter"]);
if (strlen($_GET["Letter"]))
$sLetter = mb_strtoupper(FilterInput($_GET["Letter"]));
if (strlen($_GET["mode"]))
$sMode = FilterInput($_GET["mode"]);
elseif (isset($_SESSION['SelectListMode']))
$sMode = $_SESSION['SelectListMode'];
switch ($sMode)
{
case ('groupassign'):
$_SESSION['SelectListMode'] = $sMode;
break;
case ('family'):
$_SESSION['SelectListMode'] = $sMode;
break;
default:
$_SESSION['SelectListMode'] = 'person';
break;
}
// Save default search mode
$_SESSION['bSearchFamily'] = ($sMode != 'person');
if (isset($_GET["Number"]))
{
$_SESSION['SearchLimit'] = FilterInput($_GET["Number"],'int');
$uSQL = " UPDATE user_usr SET usr_SearchLimit = " . $_SESSION['SearchLimit'] .
" WHERE usr_per_ID = " . $_SESSION['iUserID'];
$rsUser = RunQuery($uSQL);
}
if (isset($_GET["PersonColumn3"])){
$_SESSION['sPersonColumn3'] = FilterInput($_GET["PersonColumn3"]);
}
if (isset($_GET["PersonColumn5"])){
$_SESSION['sPersonColumn5'] = FilterInput($_GET["PersonColumn5"]);
}
// Set the page title
if ($sMode == 'person')
{
$sPageTitle = gettext("Person Listing");
$iMode = 1;
if (strlen($_GET["Classification"]))
$iClassification = FilterInput($_GET["Classification"],'int');
if (strlen($_GET["FamilyRole"]))
$iFamilyRole = FilterInput($_GET["FamilyRole"],'int');
if (strlen($_GET["Gender"]))
$iGender = FilterInput($_GET["Gender"],'int');
if (strlen($_GET["PersonProperties"]))
$iPersonProperty = FilterInput($_GET["PersonProperties"],'int');
if (strlen($_GET["grouptype"]))
{
$iGroupType = FilterInput($_GET["grouptype"],'int');
if (strlen($_GET["groupid"]))
{
$iGroupID = FilterInput($_GET["groupid"],'int');
if ($iGroupID == 0) unset($iGroupID);
}
if (strlen($_GET["grouproleid"]))
{
$iRoleID = FilterInput($_GET["grouproleid"],'int');
if ($iRoleID == 0) unset($iRoleID);
}
}
}
elseif ($sMode == 'groupassign')
{
$sPageTitle = gettext("Group Assignment Helper");
$iMode = 2;
if (strlen($_GET["Classification"]))
$iClassification = FilterInput($_GET["Classification"],'int');
if (strlen($_GET["FamilyRole"]))
$iFamilyRole = FilterInput($_GET["FamilyRole"],'int');
if (strlen($_GET["Gender"]))
$iGender = FilterInput($_GET["Gender"],'int');
if (isset($_GET["type"]))
$iGroupTypeMissing = FilterInput($_GET["type"],'int');
else
$iGroupTypeMissing = 1;
}
else
{
$sPageTitle = gettext("Family Listing");
$iMode = 3;
}
$iPerPage = $_SESSION['SearchLimit'];
if (!$PrintView)
$sHeaderFile = "Include/Header.php";
else
$sHeaderFile = "Include/Header-Short.php";
if ($iMode == 1 || $iMode == 2)
{
// SQL for group-assignment helper
if ($iMode == 2)
{
$sBaseSQL = "SELECT *, IF(LENGTH(per_Zip) > 0,per_Zip,fam_Zip) AS zip " .
"FROM person_per LEFT JOIN family_fam " .
"ON person_per.per_fam_ID = family_fam.fam_ID ";
// Find people who are part of a group of the specified type.
// MySQL doesn't have subqueries until version 4.1.. for now, do it the hard way
$sSQLsub = "SELECT per_ID FROM person_per LEFT JOIN person2group2role_p2g2r " .
"ON p2g2r_per_ID = per_ID LEFT JOIN group_grp " .
"ON grp_ID = p2g2r_grp_ID " .
"WHERE grp_Type = $iGroupTypeMissing GROUP BY per_ID";
$rsSub = RunQuery($sSQLsub);
if (mysql_num_rows($rsSub) > 0)
{
$sExcludedIDs = "";
while ($aTemp = mysql_fetch_row($rsSub))
{
$sExcludedIDs .= $aTemp[0] . ",";
}
$sExcludedIDs = mb_substr($sExcludedIDs,0,-1);
$sGroupWhereExt = " AND per_ID NOT IN (" . $sExcludedIDs . ")";
}
}
// SQL for standard Person List
if ($iMode == 1)
{
// Set the base SQL
$sBaseSQL = "SELECT *, IF(LENGTH(per_Zip) > 0,per_Zip,fam_Zip) AS zip " .
"FROM person_per LEFT JOIN family_fam " .
"ON per_fam_ID = family_fam.fam_ID ";
$sGroupWhereExt = ""; // Group Filtering Logic
$sJoinExt = "";
if (isset($iGroupType))
{
if ($iGroupType >= 0)
{
$sJoinExt = " LEFT JOIN person2group2role_p2g2r ON per_ID = p2g2r_per_ID ".
" LEFT JOIN group_grp ON grp_ID = p2g2r_grp_ID ";
$sGroupWhereExt = " AND grp_type = ".$iGroupType." ";
if (isset($iGroupID))
if ($iGroupID >= 0)
{
if (isset($iRoleID))
{
$sJoinExt = " LEFT JOIN person2group2role_p2g2r ".
" ON per_ID = p2g2r_per_ID ".
" LEFT JOIN list_lst ".
" ON p2g2r_grp_ID = lst_ID ";
$sGroupWhereExt = " AND p2g2r_grp_ID=".$iGroupID." " .
" AND p2g2r_per_ID=per_ID " .
" AND p2g2r_rle_ID=".$iRoleID." ";
}
else
{
$sJoinExt = " LEFT JOIN person2group2role_p2g2r ".
" ON per_ID = p2g2r_per_ID ";
$sGroupWhereExt = " AND p2g2r_grp_ID=".$iGroupID." ".
" AND p2g2r_per_ID = per_ID ";
}
}
else
{
$sJoinExt = " LEFT JOIN person2group2role_p2g2r ".
" ON per_ID = p2g2r_per_ID " .
" LEFT JOIN group_grp ON grp_ID = p2g2r_grp_ID ";
$sGroupWhereExt = " AND grp_type=".$iGroupType." ".
" AND per_ID NOT IN ".
" (SELECT p2g2r_per_ID FROM person2group2role_p2g2r ".
" WHERE p2g2r_grp_ID=".($iGroupID+$iTenThousand).") ";
}
}
else
{
$sJoinExt = " ";
$sGroupWhereExt = " AND per_ID NOT IN (SELECT p2g2r_per_ID ".
" FROM person2group2role_p2g2r ".
" LEFT JOIN group_grp ON grp_ID = p2g2r_grp_ID ".
" WHERE grp_type = ".($iGroupType+$iTenThousand).")";
}
}
}
$sPersonPropertyWhereExt = ""; // Person Property Filtering Logic
$sJoinExt2 = "";
if (isset($iPersonProperty)) {
if ($iPersonProperty >= 0)
{
$sJoinExt2 = " LEFT JOIN record2property_r2p ON per_ID = r2p_record_ID "; // per_ID should match the r2p_record_ID
$sPersonPropertyWhereExt = " AND r2p_pro_ID = ".$iPersonProperty." ";
}
else // >>>> THE SQL CODE BELOW IS NOT TESTED PROPERLY <<<<<
{
$sJoinExt2 = " ";
$sPersonPropertyWhereExt = " AND per_ID NOT IN (SELECT r2p_record_ID ".
" FROM record2property_r2p ".
" WHERE r2p_pro_ID = ".($iPersonProperty+$iTenThousand).")";
}
$sJoinExt .= $sJoinExt2; // We add our new SQL statement to the JoinExt variable from the group type.
}
if (isset($sFilter))
{
// Check if there's a space
if (strstr($sFilter," "))
{
// break on the space...
$aFilter = explode(" ",$sFilter);
// use the results to check the first and last names
$sFilterWhereExt = " AND per_FirstName LIKE '%" . $aFilter[0] . "%' " .
" AND per_LastName LIKE '%" . $aFilter[1] . "%' ";
} else
{
$sFilterWhereExt = " AND (per_FirstName LIKE '%" . $sFilter . "%' " .
//add callsign search (Jeff Wigal added 4/11/2007)
" OR per_LastName LIKE '%" . $sFilter . "%' OR per_suffix LIKE '%" . $sFilter . "%' ";
}
}
$sClassificationWhereExt = "";
if (isset($iClassification))
if ($iClassification >= 0)
$sClassificationWhereExt = " AND per_cls_ID=".$iClassification." ";
else
$sClassificationWhereExt = " AND per_cls_ID!=".
($iClassification+$iTenThousand)." ";
$sFamilyRoleWhereExt = "";
if (isset($iFamilyRole))
if ($iFamilyRole >= 0)
$sFamilyRoleWhereExt = " AND per_fmr_ID=".$iFamilyRole." ";
else
$sFamilyRoleWhereExt = " AND per_fmr_ID!=".($iFamilyRole+$iTenThousand)." ";
if (isset($iGender))
$sGenderWhereExt = " AND per_Gender = " . $iGender;
else
$sGenderWhereExt = "";
if (isset($sLetter))
$sLetterWhereExt = " AND per_LastName LIKE '" . $sLetter . "%'";
else
$sLetterWhereExt = "";
$sGroupBySQL = " GROUP BY per_ID";
$sWhereExt = $sGroupWhereExt . $sFilterWhereExt . $sClassificationWhereExt .
$sFamilyRoleWhereExt . $sGenderWhereExt . $sLetterWhereExt . $sPersonPropertyWhereExt;
$sSQL = $sBaseSQL . $sJoinExt . " WHERE 1" . $sWhereExt . $sGroupBySQL;
// URL to redirect back to this same page
$sRedirect = "SelectList.php?";
if (isset($_GET["mode"])) $sRedirect .= "mode=" . $_GET["mode"] . "&";
if (isset($_GET["type"])) $sRedirect .= "type=" . $_GET["type"] . "&";
if (isset($_GET["Filter"])) $sRedirect .= "Filter=" . $_GET["Filter"] . "&";
if (isset($_GET["Sort"])) $sRedirect .= "Sort=" . $_GET["Sort"] . "&";
if (isset($_GET["Letter"])) $sRedirect .= "Letter=" . $_GET["Letter"] . "&";
if (isset($_GET["Classification"])) $sRedirect .= "Classification=" . $_GET["Classification"] . "&";
if (isset($_GET["FamilyRole"])) $sRedirect .= "FamilyRole=" . $_GET["FamilyRole"] . "&";
if (isset($_GET["Gender"])) $sRedirect .= "Gender=" . $_GET["Gender"] . "&";
if (isset($_GET["grouptype"])) $sRedirect .= "grouptype=" . $_GET["grouptype"] . "&";
if (isset($_GET["groupid"])) $sRedirect .= "groupid=" . $_GET["groupid"] . "&";
if (isset($_GET["grouproleid"])) $sRedirect .= "grouproleid=" . $_GET["grouproleid"] . "&";
if (isset($_GET["Number"])) $sRedirect .= "Number=" . $_GET["Number"] . "&";
if (isset($_GET["Result_Set"])) $sRedirect .= "Result_Set=" . $_GET["Result_Set"] . "&";
if (isset($_GET["PersonProperties"])) $sRedirect .= "PersonProperties=" . $_GET["PersonProperties"] . "&";
$sRedirect = mb_substr($sRedirect,0,-5); // Chop off last &
// If AddToCart submit button was used, run the query, add people to cart, and view cart
if (isset($_GET["AddAllToCart"]))
{
$rsPersons = RunQuery($sSQL);
while ($aRow = mysql_fetch_row($rsPersons))
{
AddToPeopleCart($aRow[0]);
}
} elseif (isset($_GET["IntersectCart"]))
{
$rsPersons = RunQuery($sSQL);
while ($aRow = mysql_fetch_row($rsPersons))
$aItemsToProcess[] = $aRow[0];
if (isset($_SESSION['aPeopleCart']))
$_SESSION['aPeopleCart'] = array_intersect($_SESSION['aPeopleCart'],$aItemsToProcess);
} elseif (isset($_GET["RemoveFromCart"]))
{
$rsPersons = RunQuery($sSQL);
while ($aRow = mysql_fetch_row($rsPersons))
$aItemsToProcess[] = $aRow[0];
if (isset($_SESSION['aPeopleCart']))
$_SESSION['aPeopleCart'] = array_diff($_SESSION['aPeopleCart'],$aItemsToProcess);
}
// Get the total number of persons
$rsPer = RunQuery($sSQL);
$Total = mysql_num_rows($rsPer);
// Select the proper sort SQL
switch($sSort)
{
case "family":
$sOrderSQL = " ORDER BY fam_Name";
break;
case "zip":
$sOrderSQL = " ORDER BY zip, per_LastName, per_FirstName";
break;
case "entered":
$sOrderSQL = " ORDER BY per_DateEntered DESC";
break;
case "edited";
$sOrderSQL = " ORDER BY per_DateLastEdited DESC";
break;
default:
$sOrderSQL = " ORDER BY per_LastName, per_FirstName";
break;
}
// Regular PersonList display
if (!$bPrintView)
{
// Append a LIMIT clause to the SQL statement
if (empty($_GET['Result_Set']))
$Result_Set = 0;
else
$Result_Set = FilterInput($_GET['Result_Set'],'int');
$sLimitSQL .= " LIMIT $Result_Set, $iPerPage";
// Run the query with order and limit to get the final result for this list page
$finalSQL = $sSQL . $sOrderSQL . $sLimitSQL;
$rsPersons = RunQuery($finalSQL);
// Run query to get first letters of last name.
$sSQL = "SELECT DISTINCT LEFT(per_LastName,1) AS letter FROM person_per ".
$sJoinExt . " WHERE 1 $sWhereExt ORDER BY letter";
$rsLetters = RunQuery($sSQL);
require "$sHeaderFile";
echo "<form method=\"get\" action=\"SelectList.php\" name=\"PersonList\">";
if ($iMode == 1)
{
echo "<p align=\"center\">";
if ($_SESSION['bAddRecords'])
{
echo "<a href=\"PersonEditor.php\">";
echo gettext("Add a New Person Record") . "</a><BR>";
}
echo "<a href=\"SelectList.php?mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID&PersonProperties=$iPersonProperty";
if($sSort)
echo "&Sort=$sSort";
echo "&Letter=$sLetter&PrintView=1\">" . gettext("View Printable Page of this Listing") . "</a>";
} else
{
$sSQLtemp = "SELECT * FROM list_lst WHERE lst_ID = 3";
$rsGroupTypes = RunQuery($sSQLtemp);
echo '<p align="center" class="MediumText">' . gettext("Show people <b>not</b> in this group type:");
echo '<select name="type" onchange="this.form.submit()">';
while ($aRow = mysql_fetch_array($rsGroupTypes))
{
extract($aRow);
echo '<option value="' . $lst_OptionID . '"';
if ($iGroupTypeMissing == $lst_OptionID) { echo ' selected'; }
echo '>' . $lst_OptionName . ' ';
}
echo "</select></p>";
}
?>
<table align="center"><tr><td align="center">
<?php echo gettext("Sort order:"); ?>
<select name="Sort" onchange="this.form.submit()">
<option value="name" <?php if ($sSort == "name" || empty($sSort)) echo "selected";?>><?php echo gettext("By Name"); ?></option>
<option value="family" <?php if ($sSort == "family") echo "selected";?>><?php echo gettext("By Family"); ?></option>
<option value="zip" <?php if ($sSort == "zip") echo "selected";?>><?php echo gettext("By ZIP/Postal Code"); ?></option>
<option value="entered" <?php if ($sSort == "entered") echo "selected";?>><?php echo gettext("By Newest Entries"); ?></option>
<option value="edited" <?php if ($sSort == "edited") echo "selected";?>><?php echo gettext("By Recently Edited"); ?></option>
</select>
<input type="text" name="Filter" value="<?php echo $sFilter;?>">
<input type="hidden" name="mode" value="<?php echo $sMode;?>">
<input type="hidden" name="Letter" value="<?php echo $sLetter;?>">
<input type="submit" class="icButton" <?php echo 'value="' . gettext("Apply Filter") . '"'; ?>>
</td></tr>
<?php
echo ' <tr><td align="center">
<select name="Gender" onchange="this.form.submit()">
<option value="" ';
if (!isset($iGender))
echo " selected ";
echo '> ' . gettext ("Male & Female") . '</option>';
echo '<option value="1"';
if ($iGender == 1)
echo ' selected ';
echo '> ' . gettext ("Male") . '</option>';
echo '<option value="2"';
if ($iGender == 2)
echo ' selected ';
echo '> ' . gettext ("Female") . '</option></select>';
// **********
// Classification drop down list
echo ' <select name="Classification" onchange="this.form.submit()">
<option value="" ';
if (!isset($iClassification))
echo ' selected ';
echo '>' . gettext("All Classifications") . '</option>';
foreach ($aClassificationName as $key => $value)
{
echo '<option value="'.$key.'"';
if (isset($iClassification))
if ($iClassification == $key)
echo ' selected ';
echo '>'.$value.'</option>';
}
foreach ($aClassificationName as $key => $value)
{
echo '<option value="'.($key-$iTenThousand).'"';
if (isset($iClassification))
if ($iClassification == ($key-$iTenThousand))
echo ' selected ';
echo '>! '.$value.'</option>';
}
echo '</select>';
// **********
// Family Role Drop Down Box
echo '<select name="FamilyRole" onchange="this.form.submit()">';
echo '<option value="" ';
if (!isset($iFamilyRole))
echo ' selected ';
echo '>' . gettext("All Family Roles") . '</option>';
foreach ($aFamilyRoleName as $key => $value)
{
echo '<option value="'.$key.'"';
if (isset($iFamilyRole))
if ($iFamilyRole == $key)
echo ' selected ';
echo '>'.$value.'</option>';
}
foreach ($aFamilyRoleName as $key => $value)
{
echo '<option value="'.($key-$iTenThousand).'"';
if (isset($iFamilyRole))
if ($iFamilyRole == ($key-$iTenThousand))
echo ' selected ';
echo '>! '.$value.'</option>';
}
echo '</select>';
// Person Property Drop Down Box
echo '<select name="PersonProperties" onchange="this.form.submit()">';
echo '<option value="" ';
if (!isset($iPersonProperty))
echo ' selected ';
echo '>' . gettext("All Contact Properties") . '</option>';
foreach ($aPersonPropertyName as $key => $value)
{
echo '<option value="'.$key.'"';
if (isset($iPersonProperty))
if ($iPersonProperty == $key)
echo ' selected ';
echo '>'.$value.'</option>';
}
foreach ($aPersonPropertyName as $key => $value)
{
echo '<option value="'.($key-$iTenThousand).'"';
if (isset($iPersonProperty))
if ($iPersonProperty == ($key-$iTenThousand))
echo ' selected ';
echo '>! '.$value.'</option>';
}
echo '</select>';
//grouptype drop down box
if ($iMode == 1) {
echo '<select name="grouptype" onchange="this.form.submit()">';
echo '<option value="" ';
if (!isset($iGroupType))
echo ' selected ';
echo '>' . gettext("All Group Types") . '</option>';
foreach ($aGroupTypes as $key => $value)
{
echo '<option value="'.$key.'"';
if (isset($iGroupType))
if ($iGroupType == $key)
echo ' selected ';
echo '>'.$value.'</option>';
}
foreach ($aGroupTypes as $key => $value)
{
echo '<option value="'.($key-$iTenThousand).'"';
if (isset($iGroupType))
if ($iGroupType == ($key-$iTenThousand))
echo ' selected ';
echo '>! '.$value.'</option>';
}
echo '</select>';
if (isset($iGroupType) && ($iGroupType > -1))
{
// Create array with Group Information
$sGroupsSQL = "SELECT * FROM group_grp WHERE grp_Type = $iGroupType " .
"ORDER BY grp_Name ";
$rsGroups = RunQuery($sGroupsSQL);
unset($aGroupNames);
while ($aRow = mysql_fetch_array($rsGroups))
{
extract($aRow);
$aGroupNames[intval($grp_ID)]=$grp_Name;
}
echo ' <select name="groupid" onchange="this.form.submit()">
<option value="" ';
if (!isset($iGroupType)) echo ' selected ';
echo '>' . gettext("All Groups") . '</option>';
foreach ($aGroupNames as $key => $value)
{
echo '<option value="'.$key.'"';
if (isset($iGroupType))
if ($iGroupID == $key)
echo ' selected ';
echo '>'.$value.'</option>';
}
foreach ($aGroupNames as $key => $value)
{
echo '<option value="'.($key-$iTenThousand).'"';
if (isset($iGroupType))
if ($iGroupID == ($key-$iTenThousand))
echo ' selected ';
echo '>! '.$value.'</option>';
}
echo '</select>';
}
// *********
// Create Group Role drop down box
if (isset($iGroupID) && ($iGroupID > -1))
{
// Get the group's role list ID
$sSQL = "SELECT grp_RoleListID ".
"FROM group_grp WHERE grp_ID =" . $iGroupID;
$aTemp = mysql_fetch_array(RunQuery($sSQL));
$iRoleListID = $aTemp[0];
// Get the roles
$sSQL = "SELECT * FROM list_lst WHERE lst_ID = " . $iRoleListID .
" ORDER BY lst_OptionSequence";
$rsRoles = RunQuery($sSQL);
unset($aGroupRoles);
while ($aRow = mysql_fetch_array($rsRoles))
{
extract($aRow);
$aGroupRoles[intval($lst_OptionID)]=$lst_OptionName;
}
echo ' <select name="grouproleid" onchange="this.form.submit()">
<option value="" ';
if (!isset($iRoleID)) echo ' selected ';
echo '>' . gettext("All Roles") . '</option>';
foreach ($aGroupRoles as $key => $value)
{
echo '<option value="'.$key.'"';
if (isset($iRoleID))
if ($iRoleID == $key)
echo ' selected ';
echo '>'.$value.'</option>';
}
/*
foreach ($aGroupNames as $key => $value)
{
echo '<option value="'.($key-$iTenThousand).'"';
if (isset($iGroupType))
if ($iGroupID == ($key-$iTenThousand))
echo ' selected ';
echo '>! '.$value.'</option>';
}*/
echo '</select>';
}
} ?>
<input type="button" class="icButton" value="<?php echo gettext("Clear Filters"); ?>" onclick="javascript:document.location='SelectList.php?mode=<?php echo $sMode; ?>&Sort=<?php echo $sSort; ?>&type=<?php echo $iGroupTypeMissing; ?>'"><BR><BR>
<input name="AddAllToCart" type="submit" class="icButton" <?php echo 'value="' . gettext("Add to Cart") . '"'; ?>>
<input name="IntersectCart" type="submit" class="icButton" <?php echo 'value="' . gettext("Intersect with Cart") . '"'; ?>>
<input name="RemoveFromCart" type="submit" class="icButton" <?php echo 'value="' . gettext("Remove from Cart") . '"'; ?>>
</td></tr>
</table></form>
<?php
// Create Sort Links
echo '<div align="center">';
echo "<a href=\"SelectList.php?mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID&PersonProperties=$iPersonProperty";
if($sSort) echo "&Sort=$sSort";
echo "\">" . gettext("View All") . "</a>";
while ($aLetter = mysql_fetch_row($rsLetters))
{
$aLetter[0] = mb_strtoupper($aLetter[0]);
if ($aLetter[0] == $sLetter) {
echo " | " . $aLetter[0];
} else {
echo " | <a href=\"SelectList.php?mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID";
if($sSort) echo "&Sort=$sSort";
echo "&Letter=" . $aLetter[0] . "\">" . $aLetter[0] . "</a>";
}
}
echo "</div><BR>";
// Create Next / Prev Links and $Result_Set Value
if ($Total > 0)
{
echo "<div align=\"center\">";
echo "<form method=\"get\" action=\"SelectList.php\" name=\"ListNumber\">";
// Show previous-page link unless we're at the first page
if ($Result_Set < $Total && $Result_Set > 0)
{
$thisLinkResult = $Result_Set - $iPerPage;
echo "<a href=\"SelectList.php?Result_Set=$thisLinkResult&mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Sort=$sSort&Letter=$sLetter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID\">". gettext("Previous Page") . "</A> ";
}
// Calculate starting and ending Page-Number Links
$Pages = ceil($Total / $iPerPage);
$startpage = (ceil($Result_Set / $iPerPage)) - 6;
if ($startpage <= 2)
$startpage = 1;
$endpage = (ceil($Result_Set / $iPerPage)) + 9;
if ($endpage >= ($Pages - 1))
$endpage = $Pages;
// Show Link "1 ..." if startpage does not start at 1
if ($startpage != 1)
echo "<a href=\"SelectList.php?Result_Set=0&mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Sort=$sSort&Letter=$sLetter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID\">1</a> ... \n";
// Display page links
if ($Pages > 1)
{
for ($c = $startpage; $c <= $endpage; $c++)
{
$b = $c - 1;
$thisLinkResult = $iPerPage * $b;
if ($thisLinkResult != $Result_Set)
echo " <a href=\"SelectList.php?Result_Set=$thisLinkResult&mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Sort=$sSort&Letter=$sLetter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID\">$c</a> \n";
else
echo " [ " . $c . " ] ";
}
}
// Show Link "... xx" if endpage is not the maximum number of pages
if ($endpage != $Pages)
{
$thisLinkResult = ($Pages - 1) * $iPerPage;
echo " ... <a href=\"SelectList.php?Result_Set=$thisLinkResult&mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Sort=$sSort&Letter=$sLetter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID\">$Pages</a>\n";
}
// Show next-page link unless we're at the last page
if ($Result_Set >= 0 && $Result_Set < $Total)
{
$thisLinkResult=$Result_Set+$iPerPage;
if ($thisLinkResult<$Total)
echo " <a href=\"SelectList.php?Result_Set=$thisLinkResult&mode=$sMode&type=$iGroupTypeMissing&Filter=$sFilter&Sort=$sSort&Letter=$sLetter&Classification=$iClassification&FamilyRole=$iFamilyRole&Gender=$iGender&grouptype=$iGroupType&groupid=$iGroupID&grouproleid=$iRoleID\">" . gettext("Next Page") . "</a>";
}
echo '<input type="hidden" name="mode" value="';
echo $sMode . '">';
if($iGroupTypeMissing > 0) {
echo '<input type="hidden" name="type" value="';
echo $iGroupTypeMissing . '">'; }
if(isset($sFilter)) {
echo '<input type="hidden" name="Filter" value="';
echo $sFilter . '">'; }
if(isset($sSort)) {
echo '<input type="hidden" name="Sort" value="';
echo $sSort . '">'; }
if(isset($sLetter)) {
echo '<input type="hidden" name="Letter" value="';
echo $sLetter . '">'; }
if(isset($iClassification)) {
echo '<input type="hidden" name="Classification" value="';
echo $iClassification . '">'; }
if(isset($iFamilyRole)) {
echo '<input type="hidden" name="FamilyRole" value="';
echo $iFamilyRole . '">'; }
if(isset($iGender)) {
echo '<input type="hidden" name="Gender" value="';
echo $iGender . '">'; }
if(isset($iGroupType)) {
echo '<input type="hidden" name="grouptype" value="'; echo $iGroupType . '">'; }
if(isset($iPersonProperty)) {
echo '<input type="hidden" name="PersonProperties" value="';
echo $iPersonProperty . '">'; }
if(isset($iGroupID)) {
echo '<input type="hidden" name="groupid" value="';
echo $iGroupID . '">'; }
// Display record limit per page
if ($_SESSION['SearchLimit'] == "5")
$sLimit5 = "selected";
if ($_SESSION['SearchLimit'] == "10")
$sLimit10 = "selected";
if ($_SESSION['SearchLimit'] == "20")
$sLimit20 = "selected";
if ($_SESSION['SearchLimit'] == "25")
$sLimit25 = "selected";
if ($_SESSION['SearchLimit'] == "50")
$sLimit50 = "selected";
echo ' '. gettext("Display:") . '
<select class="SmallText" name="Number" onchange="this.form.submit()">
<option value="5" '.$sLimit5.'>5</option>
<option value="10" '.$sLimit10.'>10</option>
<option value="20" '.$sLimit20.'>20</option>
<option value="25" '.$sLimit25.'>25</option>
<option value="50" '.$sLimit50.'>50</option>
</select>
</form>
</div>
<BR>';
} ?>
<?php
// At this point we have finished the forms at the top of SelectList.
// Now begin the table displaying results.
// Read if sort by person is selected columns 3 and 5 are user selectable. If the
// user has not selected a value then read from session variable.
if (!isset($sPersonColumn3)) {
switch ($_SESSION['sPersonColumn3'])
{
case ("Family Role"):
$sPersonColumn3 = "Family Role";
break;
case ("Gender"):
$sPersonColumn3 = "Gender";
break;
default:
$sPersonColumn3 = "Classification";
break;
}
}
if (!isset($sPersonColumn5)) {
switch ($_SESSION['sPersonColumn5'])
{
case ("Home Phone"):
$sPersonColumn5 = "Home Phone";
break;
case ("Work Phone"):
$sPersonColumn5 = "Work Phone";
break;
case ("Mobile Phone"):
$sPersonColumn5 = "Mobile Phone";
break;
default:
$sPersonColumn5 = "Zip/Postal Code";
break;
}
}
// Header Row for results table
echo '<form method="get" action="SelectList.php" name="ColumnOptions">';
echo '<table cellpadding="4" align="center" cellspacing="0" width="100%">';
echo '<tr class="TableHeader">';
if ($_SESSION['bEditRecords'])
echo '<td width="25">' . gettext("Edit") . '</td>';
echo '<td><a href="SelectList.php?mode=' .$sMode. '&type=' .$iGroupTypeMissing;
echo '&Sort=name&Filter=' .$sFilter. '">' . gettext("Name") . '</a></td>';
echo '<td><input type="hidden" name="mode" value="' .$sMode. '">';
if($iGroupTypeMissing > 0)
echo '<input type="hidden" name="type" value="' .$iGroupTypeMissing. '">';
if(isset($sFilter))
echo '<input type="hidden" name="Filter" value="' .$sFilter. '">';
if(isset($sSort))
echo '<input type="hidden" name="Sort" value="' .$sSort. '">';
if(isset($sLetter))
echo '<input type="hidden" name="Letter" value="' .$sLetter. '">';
if(isset($iClassification))
echo '<input type="hidden" name="Classification" value="' .$iClassification. '">';
if(isset($iFamilyRole))
echo '<input type="hidden" name="FamilyRole" value="' .$iFamilyRole. '">';
if(isset($iGender))
echo '<input type="hidden" name="Gender" value="' .$iGender. '">';
if(isset($iPersonProperty)) {
echo '<input type="hidden" name="PersonProperties" value="';
echo $iPersonProperty . '">'; }
if(isset($iGroupType))
echo '<input type="hidden" name="grouptype" value="' .$iGroupType. '">';
if(isset($iGroupID))
echo '<input type="hidden" name="groupid" value="' .$iGroupID. '">';
echo '<select class="SmallText" name="PersonColumn3" onchange="this.form.submit()">';
$aPersonCol3 = array("Classification","Family Role","Gender");
foreach($aPersonCol3 as $s)
{
$sel = "";
if($sPersonColumn3 == $s)
$sel = " selected";
echo '<option value="'.$s.'"'.$sel.'>'.gettext($s).'</option>';
}
echo '</select></td>';
echo '<td><a href="SelectList.php?mode=' .$sMode. '&type=' .$iGroupTypeMissing;
echo '&Sort=family&Filter=' .$sFilter. '">' . gettext("Family") . '</a></td>';
echo '<td>';
echo '<select class="SmallText" name="PersonColumn5" onchange="this.form.submit()">';
$aPersonCol5 = array("Home Phone","Work Phone","Mobile Phone","Zip/Postal Code");
foreach($aPersonCol5 as $s)
{
$sel = "";
if($sPersonColumn5 == $s)
$sel = " selected";
echo '<option value="'.$s.'"'.$sel.'>'.gettext($s).'</option>';
}
echo "</select></td>";
echo "<td>" . gettext("Cart") . "</td>";
if ($iMode == 1)
{
echo "<td>" . gettext("vCard") . "</td>";
echo "<td>" . gettext("Printable Record") . "</td>";
} else
{
echo "<td>" . gettext("Assign") . "</td>";
}
// Table for results begins here
echo '</tr><tr><td> </td></tr>';
$sRowClass = "RowColorA";
$iPrevFamily = -1;
//Loop through the person recordset
while ($aRow = mysql_fetch_array($rsPersons))
{
$per_Title = "";
$per_FirstName = "";
$per_MiddleName = "";
$per_LastName = "";
$per_Suffix = "";
$per_Gender = "";
$fam_Name = "";
$fam_Address1 = "";
$fam_Address2 = "";
$fam_City = "";
$fam_State = "";
extract($aRow);
// Add alphabetical headers based on sort
$sBlankLine = "<tr><td> </td></tr>";
switch($sSort)
{
case "family":