added cache clearing support for dialog.js (#411)
[openemr.git] / contrib / forms / ippf_srh / new.php
blobe369a030e8a52e466de4f865f6eb3703c82a1015
1 <?php
2 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../../globals.php");
10 require_once("$srcdir/api.inc");
11 require_once("$srcdir/forms.inc");
12 require_once("$srcdir/options.inc.php");
13 require_once("$srcdir/patient.inc");
15 $CPR = 4; // cells per row
17 $pprow = array();
19 if (! $encounter) { // comes from globals.php
20 die("Internal error: we do not seem to be in an encounter!");
23 function end_cell() {
24 global $item_count, $cell_count;
25 if ($item_count > 0) {
26 echo "</td>";
27 $item_count = 0;
31 function end_row() {
32 global $cell_count, $CPR;
33 end_cell();
34 if ($cell_count > 0) {
35 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
36 echo "</tr>\n";
37 $cell_count = 0;
41 function end_group() {
42 global $last_group;
43 if (strlen($last_group) > 0) {
44 end_row();
45 echo " </table>\n";
46 echo "</div>\n";
50 $formid = $_GET['id'];
52 // If Save was clicked, save the info.
54 if ($_POST['bn_save']) {
55 $sets = "";
56 $fres = sqlStatement("SELECT * FROM layout_options " .
57 "WHERE form_id = 'SRH' AND uor > 0 AND field_id != '' AND " .
58 "edit_options != 'H' " .
59 "ORDER BY group_name, seq");
60 while ($frow = sqlFetchArray($fres)) {
61 $field_id = $frow['field_id'];
62 $value = get_layout_form_value($frow);
63 if ($sets) $sets .= ", ";
64 $sets .= "$field_id = '$value'";
67 if ($formid) {
68 // Updating an existing form.
69 $query = "UPDATE form_ippf_srh SET $sets WHERE id = '$formid'";
70 sqlStatement($query);
72 else {
73 // Adding a new form.
74 $query = "INSERT INTO form_ippf_srh SET $sets";
75 $newid = sqlInsert($query);
76 addForm($encounter, "IPPF SRH Data", $newid, "ippf_srh", $pid, $userauthorized);
79 formHeader("Redirecting....");
80 formJump();
81 formFooter();
82 exit;
85 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date FROM " .
86 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
87 "p.pid = '$pid' AND f.pid = '$pid' AND f.encounter = '$encounter' AND " .
88 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
89 "fe.id = f.form_id LIMIT 1");
91 if ($formid) {
92 $pprow = sqlQuery("SELECT * FROM form_ippf_srh WHERE " .
93 "id = '$formid' AND activity = '1'");
96 <html>
97 <head>
98 <?php html_header_show();?>
99 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
100 <style>
102 td, input, select, textarea {
103 font-family: Arial, Helvetica, sans-serif;
104 font-size: 10pt;
107 div.section {
108 border: solid;
109 border-width: 1px;
110 border-color: #0000ff;
111 margin: 0 0 0 10pt;
112 padding: 5pt;
115 </style>
117 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
119 <script language="JavaScript">
121 // Supports customizable forms (currently just for IPPF).
122 function divclick(cb, divid) {
123 var divstyle = document.getElementById(divid).style;
124 if (cb.checked) {
125 divstyle.display = 'block';
126 } else {
127 divstyle.display = 'none';
129 return true;
132 </script>
133 </head>
135 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
136 <form method="post" action="<?php echo $rootdir ?>/forms/ippf_srh/new.php?id=<?php echo $formid ?>"
137 onsubmit="return top.restoreSession()">
139 <p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>
140 <?php
141 echo xl('IPPF SRH Data for') . ' ';
142 echo $enrow['fname'] . ' ' . $enrow['mname'] . ' ' . $enrow['lname'];
143 echo ' ' . xl('on') . ' ' . substr($enrow['date'], 0, 10);
145 </p>
147 <?php
148 $shrow = getHistoryData($pid);
150 // echo "<div id='ippf_srh' style='display:none'>\n";
152 $fres = sqlStatement("SELECT * FROM layout_options " .
153 "WHERE form_id = 'SRH' AND uor > 0 " .
154 "ORDER BY group_name, seq");
155 $last_group = '';
156 $cell_count = 0;
157 $item_count = 0;
158 $display_style = 'block';
160 while ($frow = sqlFetchArray($fres)) {
161 $this_group = $frow['group_name'];
162 $titlecols = $frow['titlecols'];
163 $datacols = $frow['datacols'];
164 $data_type = $frow['data_type'];
165 $field_id = $frow['field_id'];
166 $list_id = $frow['list_id'];
168 $currvalue = '';
170 if ($frow['edit_options'] == 'H') {
171 // This data comes from static history
172 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
173 } else {
174 if (isset($pprow[$field_id])) $currvalue = $pprow[$field_id];
177 // Handle a data category (group) change.
178 if (strcmp($this_group, $last_group) != 0) {
179 end_group();
180 $group_seq = 'srh' . substr($this_group, 0, 1);
181 $group_name = substr($this_group, 1);
182 $last_group = $this_group;
183 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_$group_seq' value='1' " .
184 "onclick='return divclick(this,\"div_$group_seq\");'";
185 if ($display_style == 'block') echo " checked";
186 echo " /><b>$group_name</b></span>\n";
187 echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
188 echo " <table border='0' cellpadding='0' width='100%'>\n";
189 $display_style = 'none';
192 // Handle starting of a new row.
193 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
194 end_row();
195 echo " <tr>";
198 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
200 // Handle starting of a new label cell.
201 if ($titlecols > 0) {
202 end_cell();
203 echo "<td valign='top' colspan='$titlecols' width='1%' nowrap";
204 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
205 if ($cell_count == 2) echo " style='padding-left:10pt'";
206 echo ">";
207 $cell_count += $titlecols;
209 ++$item_count;
211 echo "<b>";
212 if ($frow['title']) echo $frow['title'] . ":"; else echo "&nbsp;";
213 echo "</b>";
215 // Handle starting of a new data cell.
216 if ($datacols > 0) {
217 end_cell();
218 echo "<td valign='top' colspan='$datacols' class='text'";
219 if ($cell_count > 0) echo " style='padding-left:5pt'";
220 echo ">";
221 $cell_count += $datacols;
224 ++$item_count;
226 if ($frow['edit_options'] == 'H')
227 echo generate_display_field($frow, $currvalue);
228 else
229 generate_form_field($frow, $currvalue);
232 end_group();
233 // echo "</div>\n";
236 <p style='text-align:center'>
237 <input type='submit' name='bn_save' value='Save' />
238 &nbsp;
239 <input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
240 &nbsp;
241 </p>
243 </form>
244 <?php
246 // TBD: If $alertmsg, display it with a JavaScript alert().
249 </body>
250 </html>