Moved patient picture, if present, to top.
[openemr.git] / contrib / forms / ippf_srh / new.php
blob1ec7cee28ef17387cd74a958c7541d9c4adb7e60
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 if ($formid) {
86 $pprow = sqlQuery ("SELECT * FROM form_ippf_srh WHERE " .
87 "id = '$formid' AND activity = '1'") ;
90 <html>
91 <head>
92 <?php html_header_show();?>
93 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
94 <style>
96 td, input, select, textarea {
97 font-family: Arial, Helvetica, sans-serif;
98 font-size: 10pt;
101 div.section {
102 border: solid;
103 border-width: 1px;
104 border-color: #0000ff;
105 margin: 0 0 0 10pt;
106 padding: 5pt;
109 </style>
111 <script type="text/javascript" src="../../../library/dialog.js"></script>
113 <script language="JavaScript">
115 // Supports customizable forms (currently just for IPPF).
116 function divclick(cb, divid) {
117 var divstyle = document.getElementById(divid).style;
118 if (cb.checked) {
119 divstyle.display = 'block';
120 } else {
121 divstyle.display = 'none';
123 return true;
126 </script>
127 </head>
129 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
130 <form method="post" action="<?php echo $rootdir ?>/forms/ippf_srh/new.php?id=<?php echo $formid ?>"
131 onsubmit="return top.restoreSession()">
133 <p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>IPPF SRH Data</p>
135 <?php
136 $shrow = getHistoryData($pid);
138 // echo "<div id='ippf_srh' style='display:none'>\n";
140 $fres = sqlStatement("SELECT * FROM layout_options " .
141 "WHERE form_id = 'SRH' AND uor > 0 " .
142 "ORDER BY group_name, seq");
143 $last_group = '';
144 $cell_count = 0;
145 $item_count = 0;
146 $display_style = 'block';
148 while ($frow = sqlFetchArray($fres)) {
149 $this_group = $frow['group_name'];
150 $titlecols = $frow['titlecols'];
151 $datacols = $frow['datacols'];
152 $data_type = $frow['data_type'];
153 $field_id = $frow['field_id'];
154 $list_id = $frow['list_id'];
156 $currvalue = '';
158 if ($frow['edit_options'] == 'H') {
159 // This data comes from static history
160 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
161 } else {
162 if (isset($pprow[$field_id])) $currvalue = $pprow[$field_id];
165 // Handle a data category (group) change.
166 if (strcmp($this_group, $last_group) != 0) {
167 end_group();
168 $group_seq = 'srh' . substr($this_group, 0, 1);
169 $group_name = substr($this_group, 1);
170 $last_group = $this_group;
171 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_$group_seq' value='1' " .
172 "onclick='return divclick(this,\"div_$group_seq\");'";
173 if ($display_style == 'block') echo " checked";
174 echo " /><b>$group_name</b></span>\n";
175 echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
176 echo " <table border='0' cellpadding='0' width='100%'>\n";
177 $display_style = 'none';
180 // Handle starting of a new row.
181 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
182 end_row();
183 echo " <tr>";
186 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
188 // Handle starting of a new label cell.
189 if ($titlecols > 0) {
190 end_cell();
191 echo "<td valign='top' colspan='$titlecols' width='1%' nowrap";
192 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
193 if ($cell_count == 2) echo " style='padding-left:10pt'";
194 echo ">";
195 $cell_count += $titlecols;
197 ++$item_count;
199 echo "<b>";
200 if ($frow['title']) echo $frow['title'] . ":"; else echo "&nbsp;";
201 echo "</b>";
203 // Handle starting of a new data cell.
204 if ($datacols > 0) {
205 end_cell();
206 echo "<td valign='top' colspan='$datacols' class='text'";
207 if ($cell_count > 0) echo " style='padding-left:5pt'";
208 echo ">";
209 $cell_count += $datacols;
212 ++$item_count;
214 if ($frow['edit_options'] == 'H')
215 echo generate_display_field($frow, $currvalue);
216 else
217 generate_form_field($frow, $currvalue);
220 end_group();
221 // echo "</div>\n";
224 <p style='text-align:center'>
225 <input type='submit' name='bn_save' value='Save' />
226 &nbsp;
227 <input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
228 &nbsp;
229 </p>
231 </form>
232 <?php
234 // TBD: If $alertmsg, display it with a JavaScript alert().
237 </body>
238 </html>