-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_essalert_employee_status.php
137 lines (115 loc) · 3.39 KB
/
get_essalert_employee_status.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
<?php
/*
* get_essalert_employee_status.php - Generate a CSV file of all Senate
* employees, including whether or not the employee has entered his/her
* emergency contact information via ESS/Alert.
*
* Project: shell-scripts
* Author: Ken Zalewski
* Organization: New York State Senate
* Date: 2020-03-09
*
* Note: This PHP script expects an XML file as input, and the XML file must
* be in the format required by SendWordNow. This is the XML file that
* we transfer to SendWordNow once a day. It can be generated using the
* following command from the ESS project:
*
* $ bin/swnftp.sh --no-ftp --pretty --keep-tmpfile
*
* The resulting XML file will be in the /tmp directory.
*/
$prog = $argv[0];
if ($argc != 2) {
error_log("Usage: $prog xml_file");
exit(1);
}
$xml_file = $argv[1];
if (!file_exists($xml_file)) {
error_log("$prog: $xml_file: File not found");
exit(1);
}
$xml = simplexml_load_file($xml_file);
if ($xml === false) {
error_log("$prog: $xml_file: Unable to parse XML file");
exit(1);
}
// Sort according to department, then according to last name.
function cmp($a, $b)
{
if ($a['Department'] < $b['Department']) {
return -1;
}
elseif ($a['Department'] > $b['Department']) {
return 1;
}
elseif ($a['LastName'] < $b['LastName']) {
return -1;
}
elseif ($a['LastName'] > $b['LastName']) {
return 1;
}
elseif ($a['FirstName'] < $b['FirstName']) {
return -1;
}
elseif ($a['FirstName'] > $b['FirstName']) {
return 1;
}
else {
return 0;
}
}
$registered_contacts = 0;
$unregistered_contacts = 0;
$total_contacts = 0;
$contacts = [];
echo "DEPARTMENT,LAST_NAME,FIRST_NAME,TITLE,ADDRESS,CITY,ZIP,WORK_PHONE,WORK_EMAIL,REGISTERED\n";
foreach ($xml->batchContactList->contact as $contact) {
$cinfo = [];
$has_nonwork_contact_point = 0;
foreach ($contact->contactField as $field) {
$fldname = (string) $field['name'];
if ($fldname == 'CustomField') {
$fldname = (string) $field['customName'];
}
$cinfo[$fldname] = (string) $field;
}
foreach ($contact->contactPointList->contactPoint as $cpoint) {
$cplabel = $cpvalue = '';
foreach ($cpoint->contactPointField as $cpfield) {
$cpfname = (string) $cpfield['name'];
if ($cpfname == 'Label') {
$cplabel = (string) $cpfield;
}
elseif ($cpfname == 'Address' || $cpfname == 'Number') {
$cpvalue = (string) $cpfield;
}
}
if ($cplabel != '') {
$cinfo[$cplabel] = $cpvalue;
if ($cplabel != 'Work Email' && $cplabel != 'Work Phone') {
$has_nonwork_contact_point = 1;
}
}
}
$cinfo['Registered'] = $has_nonwork_contact_point;
$contacts[] = $cinfo;
$registered_contacts = $registered_contacts + $has_nonwork_contact_point;
$unregistered_contacts = $unregistered_contacts + !$has_nonwork_contact_point;
$total_contacts++;
}
usort($contacts, "cmp");
foreach ($contacts as $contact) {
$got_first = false;
foreach (['Department', 'LastName', 'FirstName', 'Title', 'Address1', 'City', 'PostalCode', 'Work Phone', 'Work Email', 'Registered'] as $fldname) {
if ($got_first) {
echo ',';
}
echo '"'.$contact[$fldname].'"';
$got_first = true;
}
echo "\n";
}
error_log("Total contacts: $total_contacts");
error_log("Registered contacts: $registered_contacts");
error_log("Unregistered contacts: $unregistered_contacts");
exit (0);