/
recipientsBillingEmail_2.php
353 lines (242 loc) · 10 KB
/
recipientsBillingEmail_2.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
<?php
//start session
ini_set('session.gc_maxlifetime', 600);
session_start();
require('refundFunctions.php');
include 'connectToDB.php';
/*
$db = mysqli_connect('localhost','ptrefund','x22m3y2k','pt_refund'); //connect to database
if(!$db){die("Can't connect: ". mysqli_connect_error());}
*/
// include 'dump_all_page_contents.php';
if (array_key_exists('userid', $_SESSION)){ //If user is logged, check for access level
if($_SESSION['access']=='S'){
//once user is authenticated, check to see if this form has been submitted
//if($_POST['_submit_check']){ //form has been submitted
if(isset($_POST['_submit_check']) && $_POST['_submit_check']!="" && $_POST['_submit_check']!=NULL){
//check for errors
if(validateNewUser()=='valid') //if no errors, create user in db and show success message
{
//create user in db
//$encrypted_passwd = crypt($_POST['password']);
$query = "INSERT INTO users (first_name, last_name, access_lvl, dept_id, password, username)
VALUES ('{$_POST['first_name']}','{$_POST['last_name']}','{$_POST['access']}','{$_POST['department']}','{$encrypted_passwd}','{$_POST['username']}')";
$result = mysqli_query($db,$query);
if( (isset($_POST['accounting_recipient_1']) && $_POST['accounting_recipient_1']!="" && $_POST['accounting_recipient_1']!=NULL) &&
(isset($_POST['accounting_recipient_2']) && $_POST['accounting_recipient_2']!="" && $_POST['accounting_recipient_2']!=NULL) &&
(isset($_POST['accounting_recipient_3']) && $_POST['accounting_recipient_3']!="" && $_POST['accounting_recipient_3']!=NULL) ){
$query = "UPDATE email_recipients SET
recipient_1='{$_POST['accounting_recipient_1']}',
recipient_2='{$_POST['accounting_recipient_2']}',
recipient_3='{$_POST['accounting_recipient_3']}'
WHERE step='accounting' ";
$result = mysqli_query($db,$query);
/*
echo '<br>';
echo $result;
*/
}elseif( (isset($_POST['accounting_recipient_1']) && $_POST['accounting_recipient_1']!="" && $_POST['accounting_recipient_1']!=NULL) &&
(isset($_POST['accounting_recipient_2']) && $_POST['accounting_recipient_2']!="" && $_POST['accounting_recipient_2']!=NULL) ){
$query = "UPDATE email_recipients SET recipient_1='{$_POST['accounting_recipient_1']}', recipient_2='{$_POST['accounting_recipient_2']}' WHERE step='accounting'";
$result = mysqli_query($db,$query);
/*
echo '<br>';
echo $result;
*/
}elseif(isset($_POST['accounting_recipient_1']) && $_POST['accounting_recipient_1']!="" && $_POST['accounting_recipient_1']!=NULL){
$query = "UPDATE email_recipients SET recipient_1='{$_POST['accounting_recipient_1']}' WHERE step='accounting' ";
$result = mysqli_query($db,$query);
/*
echo '<br>';
echo $query;
echo '<br>';
echo 'the result is';
var_dump($result);
*/
}
//accounting_recipient_1
/*
echo $query ;
echo '<br>';
var_dump($result);
echo '<br>';
*/
//show success message
print '<h3 align="center"> Accounting Department Email Recipients assigned!</h3>';
print '<h4 align="center"><a href="admin.php">Return to Admin Page</a></h4>';
} else {
showPage($_SESSION['username'], $_SESSION['access'],validateNewUser());
}
//if errors exist, show page again & fill in values
} else { //form has not been submitted
showPage($_SESSION['username'],$_SESSION['access']); //show page only if user is a super user
}
} else {
showLogin('The current user is not authorized to view this page.'); //all other users types OWNED!!
}
} elseif($_POST['username']) { //if user has attempted to login, validate login
if(validateLogin($_POST['username'],$_POST['password'])){
showPage($_SESSION['username'], $_SESSION['access']); //valid user! Show page!
} else {
showLogin('Login invalid. Please try again');
}
} else { //Else show login screen (no user is logged in and no login attempt has been made)
showLogin();
}
//Check that new user data submitted is valid that returns array of errors
function validateNewUser (){
global $_POST;
$errors = array();
/*
//check that passwords match
if ($_POST['password']!=$_POST['passwordConfirm']){
$errors[]='Passwords must match';
}
if (strlen($_POST['username'])<3){
$errors[]='Usernames must be at least 3 characters long';
}
if (strlen($_POST['first_name'])<2){
$errors[]='First names must be at least 2 characters long';
}
if (strlen($_POST['last_name'])<2){
$errors[]='Last names must be at least 2 characters long';
}
if (strlen($_POST['password'])<6){
$errors[]='Passwords must be at least 6 characters long';
}
*/
if($errors) {
return $errors;
} else {
return 'valid';
}
}
//Page Header (sometimes different depending on whether page has restricted access or not)
function showHeader($username='',$accessLvl=''){
print <<<HEADER
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="refundStyle.css">
<TITLE>CHCB Patient Refund Manager</TITLE>
</head>
<body>
<table id="head"><tr><td><img src = "logo.png" class="logo" /><td><td><h1 class="title">Patient Refund Manager</h1></td></tr></table>
HEADER;
if($username){
print '<div class="greeting">';
print "<h4>Hi, {$username}!</h4>";
print "<h4> Your access level is: ";
if($accessLvl == 'S'){
print "Superuser </h4>";
} elseif($accessLvl == 'U'){
print "Standard User </h4>";
} elseif($accessLvl =='A'){
print "Approver </h4>";
} else {
print "Unrecognized! </h4>";
}
print "<a href =\"logout.php\">Logout</a></div>";
print "<table class = \"topMenu\"><tr><td><a href=\"index.php\" class = \"button\" >Home</td><td><a href=\"refunds.php\" class = \"button\">Refunds</a></td><td><a href=\"reports.php\" class = \"button\">Reports</a></td><td><a href=\"mngaccount.php\" class = \"button\">My Account</a></td>";
if ($accessLvl == 'S'){
print '<td><a href="admin.php" id = "selected">Admin</a></td></tr></table>';
}else {
print '</tr></table>';
}
}
}
function showPage($username='', $accessLvl = '', $errors = ''){
showHeader($username, $accessLvl);
global $db;
include 'connectToDB.php';
if($errors){
//show errors at top of page
print '<h2 class = "error"> The following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul>';
}
//if(isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['username'])){
print <<<ADDUSERPAGE
<h2 align="center">Add/Edit PAR1 Recipients</h2>
<form method="POST" action="{$_SERVER['PHP_SELF']}" name="add_acc_rec">
<table style="width: 100%" border="1">
<tbody>
<tr>
<td>PAR1 Recipient 1 </td>
<td>
<select name="par1_recipient_1">
ADDUSERPAGE;
$query_users = 'SELECT user_id, first_name, last_name FROM users';
$result_users = mysqli_query($db,$query_users);
$query_users_rec_1 = "SELECT recipient_1 FROM email_recipients WHERE step='par1' ";
$result_users_rec_1 = mysqli_query($db,$query_users_rec_1);
$rec_1 = mysqli_fetch_array($result_users_rec_1);
while($row_users = mysqli_fetch_array($result_users)){
$selected = ($row_users['user_id'] === $rec_1['recipient_1']) ? ' selected="selected"' : '';
print "<option value=\"{$row_users['user_id']}\"";
print " $selected >{$row_users['first_name']} {$row_users['last_name']}</option>";
}
$query_users = 'SELECT user_id, first_name, last_name FROM users';
$result_users = mysqli_query($db,$query_users);
print <<<EDITUSERPAGE
</select>
<br>
</td>
</tr>
<tr>
<td>PAR1 Recipient 2</td>
<td>
<select name="par1_recipient_2">
EDITUSERPAGE;
$query_users = 'SELECT user_id, first_name, last_name FROM users';
$result_users = mysqli_query($db,$query_users);
$query_users_rec_2 = "SELECT recipient_2 FROM email_recipients WHERE step='par1' ";
$result_users_rec_2 = mysqli_query($db,$query_users_rec_2);
$rec_2 = mysqli_fetch_array($result_users_rec_2);
print "<option value=\"\"></option>";
while($row_users = mysqli_fetch_array($result_users)){
$selected = ($row_users['user_id'] === $rec_2['recipient_2']) ? ' selected="selected"' : '';
print "<option value=\"{$row_users['user_id']}\"";
print " $selected>{$row_users['first_name']} {$row_users['last_name']}</option>";
}
$query_users = 'SELECT user_id, first_name, last_name FROM users';
$result_users = mysqli_query($db,$query_users);
print <<<EDITUSERPAGES
</select>
<br>
</td>
</tr>
<td>PAR1 Recipient 3</td>
<td>
<select name="par1_recipient_3">
EDITUSERPAGES;
$query_users = 'SELECT user_id, first_name, last_name FROM users';
$result_users = mysqli_query($db,$query_users);
$selected=1;
$query_users_rec_3 = "SELECT recipient_3 FROM email_recipients WHERE step='par1' ";
$result_users_rec_3 = mysqli_query($db,$query_users_rec_3);
$rec_3 = mysqli_fetch_array($result_users_rec_3);
print "<option value=\"\"></option>";
while($row_users = mysqli_fetch_array($result_users)){
$selected = ($row_users['user_id'] === $rec_3['recipient_3']) ? ' selected="selected"' : '';
print "<option value=\"{$row_users['user_id']}\"";
print " $selected>{$row_users['first_name']} {$row_users['last_name']}</option>";
}
print <<<EDITUSERPAGES
</select>
<br>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="_submit_check" value="1" />
<br>
<center><button formmethod="post" formaction="{$_SERVER['PHP_SELF']}" value="submit" name="Submit">Submit Changes</button></center>
</form>
EDITUSERPAGES;
//}
echo '<br><br>';
print '<h4 align="center"><a href="admin.php">Return to User Administration Page</a></h4>';
showFooter();
}
?>