Further modification of address book:
[openemr.git] / interface / orders / types.php
blobae536f1e154fb356bd8f099779a0a876a8d7d74f
1 <?php
2 // Copyright (C) 2010 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/acl.inc");
11 require_once("$srcdir/formdata.inc.php");
13 // This script can be run either inside the OpenEMR frameset for order catalog
14 // maintenance, or as a popup window for selecting an item to order. In the
15 // popup case the GET variables 'popup' (a boolean) and 'order' (an optional
16 // item ID to select) will be provided, and maintenance may also be permitted.
18 $popup = empty($_GET['popup']) ? 0 : 1;
19 $order = formData('order', 'G') + 0;
21 // If Save was clicked, set the result, close the window and exit.
23 if ($popup && $_POST['form_save']) {
24 $form_order = formData('form_order') + 0;
25 $ptrow = sqlQuery("SELECT name FROM procedure_type WHERE " .
26 "procedure_type_id = '$form_order'");
27 $name = addslashes($ptrow['name']);
29 <script language="JavaScript">
30 if (opener.closed || ! opener.set_proc_type)
31 alert('<?php xl('The destination form was closed; I cannot act on your selection.','e'); ?>');
32 else
33 opener.set_proc_type(<?php echo "$form_order, '$name'" ?>);
34 window.close();
35 </script>
36 <?php
37 exit();
39 // end Save logic
42 <html>
44 <head>
46 <title><?php xl('Order and Result Types','e'); ?></title>
48 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
50 <style type="text/css">
51 body {
52 font-family:sans-serif;
53 font-size:9pt;
54 font-weight:normal;
55 padding: 5px 3px 5px 3px;
57 #con0 table {
58 margin:0;
59 padding:0;
60 width:100%;
62 #con0 td {
63 padding:0pt;
64 font-family:sans-serif;
65 font-size:9pt;
67 .plusminus {
68 font-family:monospace;
69 font-size:10pt;
71 .haskids {
72 color:#0000dd;
73 cursor:pointer;
74 cursor:hand;
76 tr.head {
77 font-size:10pt;
78 background-color:#cccccc;
79 font-weight:bold;
81 tr.evenrow {
82 background-color:#ddddff;
84 tr.oddrow {
85 background-color:#ffffff;
88 .col1 {width:35%}
89 .col2 {width:8%}
90 .col3 {width:12%}
91 .col4 {width:35%}
92 .col5 {width:10%}
93 </style>
95 <script src="../../library/js/jquery-1.2.2.min.js" type="text/javascript"></script>
96 <?php if ($popup) { ?>
97 <script type="text/javascript" src="../../library/topdialog.js"></script>
98 <?php } ?>
99 <script type="text/javascript" src="../../library/dialog.js"></script>
101 <script language="JavaScript">
103 <?php if ($popup) require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
105 <?php
106 // Create array of IDs to pre-select, leaf to top.
107 echo "preopen = [";
108 echo $order > 0 ? $order : 0;
109 for ($parentid = $order; $parentid > 0;) {
110 $row = sqlQuery("SELECT parent FROM procedure_type WHERE procedure_type_id = '$parentid'");
111 $parentid = $row['parent'] + 0;
112 echo ", $parentid";
114 echo "];\n";
117 // initiate by loading the top-level nodes
118 $(document).ready(function(){
119 nextOpen();
122 // This is called repeatedly at initialization until all desired nodes
123 // have been opened.
124 function nextOpen() {
125 if (preopen.length) {
126 var thisid = preopen.pop();
127 if (thisid == 0 || preopen.length > 0) {
128 if (thisid > 0)
129 toggle(thisid);
130 else
131 $.getScript('types_ajax.php?id=' + thisid + '&order=<?php echo $order; ?>');
133 else {
134 recolor();
137 else {
138 recolor();
142 // toggle expansion indicator from + to - or vice versa
143 function swapsign(td1, from, to) {
144 var s = td1.html();
145 var i = s.indexOf('>' + from + '<');
146 if (i >= 0) td1.html(s.substring(0,i+1) + to + s.substring(i+2));
149 // onclick handler to expand or collapse a node
150 function toggle(id) {
151 var td1 = $('#td' + id);
152 if (!td1.hasClass('haskids')) return;
153 if (td1.hasClass('isExpanded')) {
154 $('#con' + id).remove();
155 td1.removeClass('isExpanded');
156 swapsign(td1, '-', '+');
157 recolor();
159 else {
160 td1.parent().after('<tr class="outertr"><td colspan="5" id="con' + id + '" style="padding:0">Loading...</td></tr>');
161 td1.addClass('isExpanded');
162 swapsign(td1, '+', '-');
163 $.getScript('types_ajax.php?id=' + id + '&order=<?php echo $order; ?>');
167 // Called by the edit window to refresh a given node's children
168 function refreshFamily(id, haskids) {
169 if (id) { // id == 0 means top level
170 var td1 = $('#td' + id);
171 if (td1.hasClass('isExpanded')) {
172 $('#con' + id).remove();
173 td1.removeClass('isExpanded');
174 swapsign(td1, '-', '+');
176 if (td1.hasClass('haskids') && !haskids) {
177 td1.removeClass('haskids');
178 // swapsign(td1, '+', '.');
179 swapsign(td1, '+', '|');
180 return;
182 if (!td1.hasClass('haskids') && haskids) {
183 td1.addClass('haskids');
184 // swapsign(td1, '.', '+');
185 swapsign(td1, '|', '+');
187 if (haskids) {
188 td1.parent().after('<tr class="outertr"><td colspan="5" id="con' + id + '" style="padding:0">Loading...</td></tr>');
189 td1.addClass('isExpanded');
190 swapsign(td1, '+', '-');
193 if (haskids)
194 $.getScript('types_ajax.php?id=' + id + '&order=<?php echo $order; ?>');
195 else
196 recolor();
199 // edit a node
200 function enode(id) {
201 dlgopen('types_edit.php?parent=0&typeid=' + id, '_blank', 700, 550);
204 // add a node
205 function anode(id) {
206 dlgopen('types_edit.php?typeid=0&parent=' + id, '_blank', 700, 550);
209 // call this to alternate row colors when anything changes the number of rows
210 function recolor() {
211 var i = 0;
212 $('#con0 tr').each(function(index) {
213 // skip any row that contains other rows
214 if ($(this).hasClass('outertr')) return;
215 this.className = (i++ & 1) ? "evenrow" : "oddrow";
219 </script>
221 </head>
223 <body class="body_nav">
224 <center>
226 <h3 style='margin-top:0'><?php xl('Types of Orders and Results','e') ?></h3>
228 <form method='post' name='theform' action='types.php?popup=<?php echo $popup ?>&order=<?php echo $order ?>'>
230 <table width='100%' cellspacing='0' cellpadding='0' border='0'>
231 <tr class='head'>
232 <th class='col1' align='left'>&nbsp;&nbsp;<?php xl('Name','e') ?></th>
233 <th class='col2' align='left'><?php xl('Order','e') ?></th>
234 <th class='col3' align='left'><?php xl('Code','e') ?></th>
235 <th class='col4' align='left'><?php xl('Description','e') ?></th>
236 <th class='col5' align='left'>&nbsp;</th>
237 </tr>
238 </table>
240 <div id="con0">
241 </div>
244 <?php if ($popup) { ?>
245 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' />
246 &nbsp;
247 <input type='button' value=<?php xl('Cancel','e'); ?> onclick='window.close()' />
248 &nbsp;
249 <?php } ?>
250 <input type='button' value='<?php xl('Add Top Level','e'); ?>' onclick='anode(0)' />
251 </p>
253 </form>
255 </center>
257 </body>
258 </html>