/
add_transaction.php
452 lines (387 loc) · 13.4 KB
/
add_transaction.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
<?php
// add_transaction is a misnomer, as this script will now also edit
// existing transactions.
//SANITIZE ALL ESCAPES
$sanitize_all_escapes=true;
//
//STOP FAKE REGISTER GLOBALS
$fake_register_globals=false;
//
require_once("../../globals.php");
require_once("$srcdir/transactions.inc");
require_once("$srcdir/options.inc.php");
// Referral plugin support.
$fname = "../../../custom/LBF/REF.plugin.php";
if (file_exists($fname)) include_once($fname);
$transid = empty($_REQUEST['transid']) ? 0 : $_REQUEST['transid'] + 0;
$mode = empty($_POST['mode' ]) ? '' : $_POST['mode' ];
$title = empty($_POST['title']) ? '' : $_POST['title'];
$inmode = $_GET['inmode'];
$body_onload_code="";
if ($inmode) { /* For edit func */
$inedit = sqlStatement("SELECT * FROM transactions " .
"WHERE id = ?", array($transid) );
while ($inmoderow = sqlFetchArray($inedit)) {
$body = $inmoderow['body'];
}
}
if ($mode) {
//use sql placemaker
$sets = "title=?, user = ?, groupname = ?, authorized = ?, date = NOW()";
$sqlBindArray = array($_POST['title'], $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = 'REF' AND uor > 0 AND field_id != '' " .
"ORDER BY group_name, seq");
while ($frow = sqlFetchArray($fres)) {
$data_type = $frow['data_type'];
$field_id = $frow['field_id'];
$value = $_POST["form_$field_id"];
if ($field_id == 'body' && $title != 'Referral') {
$value = $_POST["body"];
}
//use sql placemaker (note need to explicitly escape the column label)
$sets .= ", ".add_escape_custom($field_id)." = ?";
array_push($sqlBindArray,$value);
}
if ($transid) {
//use sql placemaker
array_push($sqlBindArray,$transid);
sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
}
else {
//use sql placemaker
array_push($sqlBindArray,$pid);
$sets .= ", pid = ?";
$transid = sqlInsert("INSERT INTO transactions SET $sets", $sqlBindArray);
}
if ($GLOBALS['concurrent_layout'])
$body_onload_code = "javascript:location.href='transactions.php';";
else
$body_onload_code = "javascript:parent.Transactions.location.href='transactions.php';";
}
/************************************
//Migrated this to the list_options engine (transactions list)
$trans_types = array(
'Referral' => xl('Referral'),
'Patient Request' => xl('Patient Request'),
'Physician Request' => xl('Physician Request'),
'Legal' => xl('Legal'),
'Billing' => xl('Billing'),
);
************************************/
$CPR = 4; // cells per row
function end_cell() {
global $item_count, $cell_count;
if ($item_count > 0) {
echo "</td>";
$item_count = 0;
}
}
function end_row() {
global $cell_count, $CPR;
end_cell();
if ($cell_count > 0) {
for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
echo "</tr>\n";
$cell_count = 0;
}
}
function end_group() {
global $last_group;
if (strlen($last_group) > 0) {
end_row();
echo " </table>\n";
echo "</div>\n";
}
}
// If we are editing a transaction, get its ID and data.
$trow = $transid ? getTransById($transid) : array();
?>
<html>
<head>
<?php html_header_show(); ?>
<link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
<link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
<style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
<script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
<?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
<script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
<script type="text/javascript" src="../../../library/textformat.js"></script>
<script type="text/javascript" src="../../../library/dialog.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
<script type="text/javascript">
$(document).ready(function(){
tabbify();
enable_modals();
});
</script>
<script language="JavaScript">
var mypcc = '<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
function titleChanged() {
var sel = document.forms[0].title;
var si = (sel.selectedIndex < 0) ? 0 : sel.selectedIndex;
if (sel.options[si].value == 'Referral') {
document.getElementById('otherdiv').style.display = 'none';
document.getElementById('referdiv').style.display = 'block';
} else {
document.getElementById('referdiv').style.display = 'none';
document.getElementById('otherdiv').style.display = 'block';
}
return true;
}
function divclick(cb, divid) {
var divstyle = document.getElementById(divid).style;
if (cb.checked) {
divstyle.display = 'block';
} else {
divstyle.display = 'none';
}
return true;
}
// This is for callback by the find-code popup.
// Appends to or erases the current list of related codes.
function set_related(codetype, code, selector, codedesc) {
var frc = document.getElementById('form_related_code');
var s = frc.value;
if (code) {
if (s.length > 0) s += ';';
s += codetype + ':' + code;
} else {
s = '';
}
frc.value = s;
}
// This invokes the find-code popup.
function sel_related() {
dlgopen('../encounter/find_code_popup.php<?php if ($GLOBALS['ippf_specific']) echo '?codetype=IPPF' ?>', '_blank', 500, 400);
}
// Process click on Delete link.
function deleteme() {
// onclick='return deleteme()'
dlgopen('../deleter.php?transaction=<?php echo htmlspecialchars( $transid, ENT_QUOTES); ?>', '_blank', 500, 450);
return false;
}
// Called by the deleteme.php window on a successful delete.
function imdeleted() {
top.restoreSession();
location.href = 'transaction/transactions.php';
}
// Compute the length of a string without leading and trailing spaces.
function trimlen(s) {
var i = 0;
var j = s.length - 1;
for (; i <= j && s.charAt(i) == ' '; ++i);
for (; i <= j && s.charAt(j) == ' '; --j);
if (i > j) return 0;
return j + 1 - i;
}
// Validation logic for form submission.
function validate(f) {
var errCount = 0;
var errMsgs = new Array();
var sel = f.title;
var si = (sel.selectedIndex < 0) ? 0 : sel.selectedIndex;
if (sel.options[si].value == 'Referral') {
<?php generate_layout_validation('REF'); ?>
}
var msg = "";
msg += "<?php echo htmlspecialchars( xl('The following fields are required'), ENT_QUOTES); ?>:\n\n";
for ( var i = 0; i < errMsgs.length; i++ ) {
msg += errMsgs[i] + "\n";
}
msg += "\n<?php echo htmlspecialchars( xl('Please fill them in before continuing.'), ENT_QUOTES); ?>";
if ( errMsgs.length > 0 ) {
alert(msg);
}
return errMsgs.length < 1;
}
function submitme() {
var f = document.forms['new_transaction'];
if (validate(f)) {
top.restoreSession();
f.submit();
}
}
<?php if (function_exists('REF_javascript')) call_user_func('REF_javascript'); ?>
</script>
<style type="text/css">
div.tab {
height: auto;
width: auto;
}
</style>
</head>
<body class="body_top" onload="<?php echo $body_onload_code; ?>" >
<form name='new_transaction' method='post' action='add_transaction.php?transid=<?php echo htmlspecialchars( $transid, ENT_QUOTES); ?>' onsubmit='return validate(this)'>
<input type='hidden' name='mode' value='add'>
<table>
<tr>
<td>
<b><?php echo htmlspecialchars( xl('Add/Edit Patient Transaction'), ENT_NOQUOTES); ?></b> </td><td>
<a href="javascript:;" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="submitme();">
<span><?php echo htmlspecialchars( xl('Save'), ENT_NOQUOTES); ?></span>
</a>
</td>
<td>
<a href="transactions.php" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">
<span><?php echo htmlspecialchars( xl('Cancel'), ENT_NOQUOTES); ?></span>
</a>
</td>
</tr>
</table>
<table class="text">
<tr><td>
<?php echo htmlspecialchars( xl('Transaction Type'), ENT_NOQUOTES); ?>: </td><td>
<?php echo generate_select_list('title','transactions',$_REQUEST['title'],'','','','titleChanged()'); ?>
</td></tr>
</table>
<div id='referdiv'>
<div id="DEM">
<ul class="tabNav">
<?php
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = 'REF' AND uor > 0 " .
"ORDER BY group_name, seq");
$last_group = '';
$cell_count = 0;
$item_count = 0;
$display_style = 'block';
while ($frow = sqlFetchArray($fres)) {
$this_group = $frow['group_name'];
$titlecols = $frow['titlecols'];
$datacols = $frow['datacols'];
$data_type = $frow['data_type'];
$field_id = $frow['field_id'];
$list_id = $frow['list_id'];
$currvalue = '';
if (isset($trow[$field_id])) $currvalue = $trow[$field_id];
// Handle special-case default values.
if (!$currvalue && !$transid) {
if ($field_id == 'refer_date') {
$currvalue = date('Y-m-d');
}
else if ($field_id == 'body' ) {
$tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
"pid = ? ORDER BY date DESC LIMIT 1", array($pid) );
if (!empty($tmp)) $currvalue = $tmp['reason'];
}
}
// Handle a data category (group) change.
if (strcmp($this_group, $last_group) != 0) {
$group_seq = substr($this_group, 0, 1);
$group_name = substr($this_group, 1);
$last_group = $this_group;
if($group_seq==1) echo "<li class='current'>";
else echo "<li class=''>";
$group_seq_esc = htmlspecialchars( $group_seq, ENT_QUOTES);
$group_name_show = htmlspecialchars( xl_layout_label($group_name), ENT_NOQUOTES);
echo "<a href='/play/javascript-tabbed-navigation/' id='div_$group_seq_esc'>".
"$group_name_show</a></li>";
}
++$item_count;
}
?>
</ul>
<div class="tabContainer">
<?php
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = 'REF' AND uor > 0 " .
"ORDER BY group_name, seq");
$last_group = '';
$cell_count = 0;
$item_count = 0;
$display_style = 'block';
while ($frow = sqlFetchArray($fres)) {
$this_group = $frow['group_name'];
$titlecols = $frow['titlecols'];
$datacols = $frow['datacols'];
$data_type = $frow['data_type'];
$field_id = $frow['field_id'];
$list_id = $frow['list_id'];
$currvalue = '';
if (isset($trow[$field_id])) $currvalue = $trow[$field_id];
// Handle special-case default values.
if (!$currvalue && !$transid) {
if ($field_id == 'refer_date') {
$currvalue = date('Y-m-d');
}
else if ($field_id == 'body' && $transid > 0 ) {
$tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
"pid = ? ORDER BY date DESC LIMIT 1", array($pid) );
if (!empty($tmp)) $currvalue = $tmp['reason'];
}
}
// Handle a data category (group) change.
if (strcmp($this_group, $last_group) != 0) {
end_group();
$group_seq = substr($this_group, 0, 1);
$group_name = substr($this_group, 1);
$last_group = $this_group;
$group_seq_esc = htmlspecialchars( $group_seq, ENT_QUOTES);
if($group_seq==1) echo "<div class='tab current' id='div_$group_seq_esc'>";
else echo "<div class='tab' id='div_$group_seq_esc'>";
echo " <table border='0' cellpadding='0'>\n";
$display_style = 'none';
}
// Handle starting of a new row.
if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
end_row();
echo " <tr>";
}
if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
// Handle starting of a new label cell.
if ($titlecols > 0) {
end_cell();
$titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
echo "<td width='70' valign='top' colspan='$titlecols_esc'";
echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
if ($cell_count == 2) echo " style='padding-left:10pt'";
echo ">";
$cell_count += $titlecols;
}
++$item_count;
echo "<b>";
// Modified 6-09 by BM - Translate if applicable
if ($frow['title']) echo (htmlspecialchars( xl_layout_label($frow['title']), ENT_NOQUOTES) . ":"); else echo " ";
echo "</b>";
// Handle starting of a new data cell.
if ($datacols > 0) {
end_cell();
$datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
echo "<td valign='top' colspan='$datacols_esc' class='text'";
if ($cell_count > 0) echo " style='padding-left:5pt'";
echo ">";
$cell_count += $datacols;
}
++$item_count;
generate_form_field($frow, $currvalue);
echo "</div>";
}
end_group();
?>
</div></div>
</form>
</div>
<p>
<div id='otherdiv' style='display:none'>
<span class='bold'><?php echo htmlspecialchars( xl('Details'), ENT_NOQUOTES); ?>:</span><br>
<textarea name='body' rows='6' cols='40' wrap='virtual'><?php echo htmlspecialchars( $body, ENT_NOQUOTES); ?>
</textarea>
</div>
</p>
<!-- include support for the list-add selectbox feature -->
<?php include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?>
</body>
<script language="JavaScript">
<?php echo $date_init; ?>
titleChanged();
<?php
if (function_exists('REF_javascript_onload')) {
call_user_func('REF_javascript_onload');
}
?>
</script>
</html>