Merge pull request #1761 from sjpadgett/PP2-appointment
[openemr.git] / library / spreadsheet.inc.php
blobf14f69d7e583946ee36a14ec12c7005ba805ff8e
1 <?php
2 /**
3 * spreadsheet.inc.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2006-2011 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once(dirname(__FILE__) . '/api.inc');
15 require_once(dirname(__FILE__) . '/forms.inc');
16 require_once(dirname(__FILE__) . '/../interface/forms/fee_sheet/codes.php');
18 $celltypes = array(
19 '0' => 'Unused',
20 '1' => 'Static',
21 '2' => 'Checkbox',
22 '3' => 'Text',
23 '4' => 'Longtext',
24 // '5' => 'Function',
27 // encode a string from a form field for database writing.
28 function form2db($fldval)
30 $fldval = trim($fldval);
31 $fldval = strip_escape_custom($fldval);
32 return $fldval;
35 // encode a plain string for database writing.
36 function real2db($fldval)
38 return addslashes($fldval);
41 // Get the actual string from a form field.
42 function form2real($fldval)
44 $fldval = trim($fldval);
45 $fldval = strip_escape_custom($fldval);
46 return $fldval;
49 // encode a plain string for html display.
50 function real2form($fldval)
52 return htmlspecialchars($fldval, ENT_QUOTES);
55 if (empty($spreadsheet_title)) {
56 $spreadsheet_title = 'Injury Log';
59 // Putting an error message in here will result in a javascript alert.
60 $alertmsg = '';
62 // Determine the encounter that we are working with.
63 $thisenc = empty($_GET['thisenc']) ? $encounter : $_GET['thisenc'] + 0;
65 // If we are invoked as a popup (not in an encounter):
66 $popup = $_GET['popup'];
68 // The form ID is passed to us when an existing encounter form is loaded.
69 $formid = $_GET['id'];
71 // $tempid is the currently selected template, if any.
72 $tempid = $_POST['form_template'] + 0;
74 // This is the start date to be saved with the spreadsheet.
75 $start_date = '';
77 $form_completed = '0';
79 if (!$popup && !$encounter) { // $encounter comes from globals.php
80 die("Internal error: we do not seem to be in an encounter!");
83 // Get the name of the template selected by the dropdown, if any;
84 // or if we are loading a form then it comes from that.
85 $template_name = '';
86 if ($tempid) {
87 $trow = sqlQuery("SELECT value FROM form_$spreadsheet_form_name WHERE " .
88 "id = $tempid AND rownbr = -1 AND colnbr = -1");
89 $template_name = $trow['value'];
90 } else if ($formid) {
91 $trow = sqlQuery("SELECT value FROM form_$spreadsheet_form_name WHERE " .
92 "id = $formid AND rownbr = -1 AND colnbr = -1");
93 list($form_completed, $start_date, $template_name) = explode('|', $trow['value'], 3);
96 if (!$start_date) {
97 $start_date = form2real($_POST['form_start_date']);
100 // Used rows and columns are those beyond which there are only unused cells.
101 $num_used_rows = 0;
102 $num_used_cols = 0;
104 // If we are saving...
106 if ($_POST['bn_save_form'] || $_POST['bn_save_template']) {
107 // The form data determines how many rows and columns are now used.
108 $cells = $_POST['cell'];
109 for ($i = 0; $i < count($cells); ++$i) {
110 $row = $cells[$i];
111 for ($j = 0; $j < count($row); ++$j) {
112 if (substr($row[$j], 0, 1)) {
113 if ($i >= $num_used_rows) {
114 $num_used_rows = $i + 1;
117 if ($j >= $num_used_cols) {
118 $num_used_cols = $j + 1;
124 if ($_POST['bn_save_form']) {
125 $form_completed = $_POST['form_completed'] ? '1' : '0';
127 // If updating an existing form...
128 if ($formid) {
129 sqlStatement("UPDATE form_$spreadsheet_form_name SET " .
130 "value = '$form_completed|$start_date|$template_name' " .
131 "WHERE id = '$formid' AND rownbr = -1 AND colnbr = -1");
132 sqlStatement("DELETE FROM form_$spreadsheet_form_name WHERE " .
133 "id = '$formid' AND rownbr >= 0 AND colnbr >= 0");
134 } // If adding a new form...
135 else {
136 $tmprow = sqlQuery(
137 "SELECT pid FROM form_encounter WHERE encounter = ? ORDER BY id DESC LIMIT 1",
138 array($thisenc)
140 $thispid = $tmprow['pid'];
141 sqlStatement("LOCK TABLES form_$spreadsheet_form_name WRITE, log WRITE");
142 $tmprow = sqlQuery("SELECT MAX(id) AS maxid FROM form_$spreadsheet_form_name");
143 $formid = $tmprow['maxid'] + 1;
144 if ($formid <= 0) {
145 $formid = 1;
148 sqlInsert("INSERT INTO form_$spreadsheet_form_name ( " .
149 "id, rownbr, colnbr, datatype, value " .
150 ") VALUES ( " .
151 "$formid, -1, -1, 0, " .
152 "'$form_completed|$start_date|$template_name' " .
153 ")");
154 sqlStatement("UNLOCK TABLES");
155 addForm(
156 $thisenc,
157 $spreadsheet_title,
158 $formid,
159 "$spreadsheet_form_name",
160 $thispid,
161 $userauthorized
165 $saveid = $formid;
166 } else { // saving a template
167 // The rule is, we can update the original name, or insert a new name
168 // which must not match any existing template name.
169 $new_template_name = form2real($_POST['form_new_template_name']);
170 if ($new_template_name != $template_name) {
171 $trow = sqlQuery("SELECT id FROM form_$spreadsheet_form_name WHERE " .
172 "id < 0 AND rownbr = -1 AND colnbr = -1 AND value = '" .
173 real2db($new_template_name) . "'");
174 if ($trow['id']) {
175 $alertmsg = "Template \"" . real2form($new_template_name) .
176 "\" already exists!";
177 } else {
178 $tempid = 0; // to force insert of new template
179 $template_name = $new_template_name;
183 if (!$alertmsg) {
184 // If updating an existing template...
185 if ($tempid) {
186 sqlStatement("DELETE FROM form_$spreadsheet_form_name WHERE " .
187 "id = '$tempid' AND rownbr >= 0 AND colnbr >= 0");
188 } // If adding a new template...
189 else {
190 sqlStatement("LOCK TABLES form_$spreadsheet_form_name WRITE, log WRITE");
191 $tmprow = sqlQuery("SELECT MIN(id) AS minid FROM form_$spreadsheet_form_name");
192 $tempid = $tmprow['minid'] - 1;
193 if ($tempid >= 0) {
194 $tempid = -1;
197 sqlInsert("INSERT INTO form_$spreadsheet_form_name ( " .
198 "id, rownbr, colnbr, datatype, value " .
199 ") VALUES ( " .
200 "$tempid, -1, -1, 0, " .
201 "'" . real2db($template_name) . "' " .
202 ")");
203 sqlStatement("UNLOCK TABLES");
206 $saveid = $tempid;
210 if (!$alertmsg) {
211 // Finally, save the table cells.
212 for ($i = 0; $i < $num_used_rows; ++$i) {
213 for ($j = 0; $j < $num_used_cols; ++$j) {
214 $tmp = $cells[$i][$j];
215 $celltype = substr($tmp, 0, 1) + 0;
216 $cellvalue = form2db(substr($tmp, 1));
217 if ($celltype) {
218 sqlInsert("INSERT INTO form_$spreadsheet_form_name ( " .
219 "id, rownbr, colnbr, datatype, value " .
220 ") VALUES ( " .
221 "$saveid, $i, $j, $celltype, '$cellvalue' )");
226 } else if ($_POST['bn_delete_template'] && $tempid) {
227 sqlStatement("DELETE FROM form_$spreadsheet_form_name WHERE " .
228 "id = '$tempid'");
229 $tempid = 0;
230 $template_name = '';
233 if ($_POST['bn_save_form'] && !$alertmsg && !$popup) {
234 formHeader("Redirecting....");
235 formJump();
236 formFooter();
237 exit;
240 // If we get here then we are displaying a spreadsheet, either a template or
241 // an encounter form.
243 // Get the array of template names.
244 $tres = sqlStatement("SELECT id, value FROM form_$spreadsheet_form_name WHERE " .
245 "id < 0 AND rownbr = -1 AND colnbr = -1 ORDER BY value");
247 $dres = false;
249 # If we are reloading a form, get it.
250 if ($formid) {
251 $dres = sqlStatement("SELECT * FROM form_$spreadsheet_form_name WHERE " .
252 "id = '$formid' ORDER BY rownbr, colnbr");
253 $tmprow = sqlQuery("SELECT MAX(rownbr) AS rowmax, MAX(colnbr) AS colmax " .
254 "FROM form_$spreadsheet_form_name WHERE id = '$formid'");
255 $num_used_rows = $tmprow['rowmax'] + 1;
256 $num_used_cols = $tmprow['colmax'] + 1;
257 } # Otherwise if we are editing a template, get it.
258 else if ($tempid) {
259 $dres = sqlStatement("SELECT * FROM form_$spreadsheet_form_name WHERE " .
260 "id = '$tempid' ORDER BY rownbr, colnbr");
261 $tmprow = sqlQuery("SELECT MAX(rownbr) AS rowmax, MAX(colnbr) AS colmax " .
262 "FROM form_$spreadsheet_form_name WHERE id = '$tempid'");
263 $num_used_rows = $tmprow['rowmax'] + 1;
264 $num_used_cols = $tmprow['colmax'] + 1;
267 // Virtual rows and columns are those available when in Edit Structure mode,
268 // and include some additional ones beyond those used. This allows quite a
269 // lot of stuff to be entered before having to save the template.
270 $num_virtual_rows = $num_used_rows ? $num_used_rows + 5 : 10;
271 $num_virtual_cols = $num_used_cols ? $num_used_cols + 5 : 10;
273 <html>
274 <head>
275 <?php html_header_show();?>
276 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
277 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
279 <style>
280 .sstable td {
281 font-family: sans-serif;
282 font-weight: bold;
283 font-size: 9pt;
285 .seltype {
286 font-family: sans-serif;
287 font-weight: normal;
288 font-size: 8pt;
289 background-color: transparent;
291 .selgen {
292 font-family: sans-serif;
293 font-weight: normal;
294 font-size: 8pt;
295 background-color: transparent;
297 .intext {
298 font-family: sans-serif;
299 font-weight: normal;
300 font-size: 9pt;
301 background-color: transparent;
302 width: 100%;
304 .seldiv {
305 margin: 0 0 0 0;
306 padding: 0 0 0 0;
308 </style>
310 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
311 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
312 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
314 <script language="JavaScript">
316 var ssChanged = false; // if they have changed anything in the spreadsheet
317 var startDate = '<?php echo $start_date ? $start_date : date('Y-m-d'); ?>';
319 // In case we are a popup (top level) window, handle top.restoreSession() calls.
320 function restoreSession() {
321 return opener.top.restoreSession();
324 // Helper function to set the contents of a block.
325 function setBlockContent(id, content) {
326 if (document.getElementById) {
327 var x = document.getElementById(id);
328 x.innerHTML = '';
329 x.innerHTML = content;
331 else if (document.all) {
332 var x = document.all[id];
333 x.innerHTML = content;
335 // alert("ID = \"" + id + "\", string = \"" + content + "\"");
338 // Called when a different template name is selected.
339 function newTemplate(sel) {
340 if (ssChanged && !confirm('You have made changes that will be discarded ' +
341 'if you select a new template. Do you really want to do this?'))
343 // Restore the original template selection.
344 for (var i = 0; i < sel.options.length; ++i) {
345 if (sel.options[i].value == '<?php echo $tempid ?>') {
346 sel.options[i].selected = true;
349 return;
351 top.restoreSession();
352 document.forms[0].submit();
355 // Called when the Cancel button is clicked.
356 function doCancel() {
357 if (!ssChanged || confirm('You have made changes that will be discarded ' +
358 'if you close now. Click OK if you really want to exit this form.'))
360 <?php if ($popup) { ?>
361 window.close();
362 <?php } else { ?>
363 top.restoreSession();
364 location='<?php echo $GLOBALS['form_exit_url'] ?>';
365 <?php } ?>
369 // Called when the Edit Structure checkbox is clicked.
370 function editChanged() {
371 var f = document.forms[0];
372 var newdisplay = f.form_edit_template.checked ? '' : 'none';
373 var usedrows = 0;
374 var usedcols = 0;
375 for (var i = 0; i < <?php echo $num_virtual_rows; ?>; ++i) {
376 for (var j = 0; j < <?php echo $num_virtual_cols; ?>; ++j) {
377 if (f['cell['+i+']['+j+']'].value.charAt(0) != '0') {
378 if (i >= usedrows) usedrows = i + 1;
379 if (j >= usedcols) usedcols = j + 1;
383 for (var i = 0; i < <?php echo $num_virtual_rows; ?>; ++i) {
384 for (var j = 0; j < <?php echo $num_virtual_cols; ?>; ++j) {
385 // document.getElementById('div_'+i+'_'+j).style.display = newdisplay;
386 document.getElementById('sel_'+i+'_'+j).style.display = newdisplay;
387 if (i >= usedrows || j >= usedcols) {
388 document.getElementById('td_'+i+'_'+j).style.display = newdisplay;
394 // Prepare a string for use as an HTML value attribute in single quotes.
395 function escQuotes(s) {
396 return s.replace(/'/g, "&#39;");
399 // Parse static text to evaluate possible functions.
400 function genStatic(s) {
401 var i = 0;
403 // Parse "%day(n)".
404 while ((i = s.indexOf('%day(')) >= 0) {
405 var s1 = s.substring(0, i);
406 i += 5;
407 var j = s.indexOf(')', i);
408 if (j < 0) break;
409 var dayinc = parseInt(s.substring(i,j));
410 var mydate = new Date(parseInt(startDate.substring(0,4)),
411 parseInt(startDate.substring(5,7))-1, parseInt(startDate.substring(8)));
412 mydate.setTime(1000 * 60 * 60 * 24 * dayinc + mydate.getTime());
413 var year = mydate.getYear(); if (year < 1900) year += 1900;
414 s = s1 + year + '-' +
415 ('' + (mydate.getMonth() + 101)).substring(1) + '-' +
416 ('' + (mydate.getDate() + 100)).substring(1) +
417 s.substring(j + 1);
420 // Parse "%sel(first,second,third,...,default)".
421 while ((i = s.indexOf('%sel(')) >= 0) {
422 var s1 = s.substring(0, i);
423 i += 5;
424 var j = s.indexOf(')', i);
425 if (j < 0) break;
426 var x = s.substring(0,j);
427 var k = x.lastIndexOf(',');
428 if (k < i) break;
429 var dflt = s.substring(k+1, j);
430 x = "<select class='selgen' onchange='newsel(this)'>";
431 while ((k = s.indexOf(',', i)) > i) {
432 if (k > j) break;
433 var elem = s.substring(i,k);
434 x += "<option value='" + elem + "'";
435 if (elem == dflt) x += " selected";
436 x += ">" + elem + "</option>";
437 i = k + 1;
439 x += "</select>";
440 s = s1 + x + s.substring(j + 1);
441 break; // only one %sel allowed
444 // Parse "%ptp(default)".
445 while ((i = s.indexOf('%ptp(')) >= 0) {
446 var s1 = s.substring(0, i);
447 i += 5;
448 var j = s.indexOf(')', i);
449 if (j < 0) break;
450 var dflt = s.substring(i, j);
451 x = "<select class='selgen' onchange='newptp(this)'>";
452 x += "<option value=''>-- Select --</option>";
453 <?php
454 foreach ($bcodes['Phys']['Physiotherapy Procedures'] as $key => $value) {
455 echo " x += \"<option value='$key'\";\n";
456 echo " if (dflt == '$key') x += ' selected';\n";
457 echo " x += '>$value</option>';\n";
460 x += "</select>";
461 s = s1 + x + s.substring(j + 1);
462 break; // only one %ptp allowed
465 return s;
468 // Called when a cell type selector in the spreadsheet is clicked.
469 function newType(i,j) {
470 ssChanged = true;
471 var f = document.forms[0];
472 var typeval = f['cell['+i+']['+j+']'].value;
473 var thevalue = typeval.substring(1);
474 var thetype = document.getElementById('sel_'+i+'_'+j).value;
475 var s = "<input type='hidden' name='cell[" + i + "][" + j + "]' " +
476 "value='" + thetype + escQuotes(thevalue) + "' />";
478 if (thetype == '1') {
479 s += genStatic(thevalue);
481 else if (thetype == '2') {
482 s += "<input type='checkbox' value='1' onclick='cbClick(this," + i + "," + j + ")'";
483 if (thevalue) s += " checked";
484 s += " />";
486 else if (thetype == '3') {
487 s += "<input type='text' onchange='textChange(this," + i + "," + j + ")'" +
488 " class='intext' value='" + escQuotes(thevalue) + "' size='12' />";
490 else if (thetype == '4') {
491 s += "<textarea rows='3' cols='25' wrap='virtual' class='intext' " +
492 "onchange='longChange(this," + i + "," + j + ")'>" +
493 escQuotes(thevalue) + "</textarea>";
495 setBlockContent('vis_' + i + '_' + j, s);
498 // Called when a checkbox in the spreadsheet is clicked.
499 function cbClick(elem,i,j) {
500 ssChanged = true;
501 var f = document.forms[0];
502 var cell = f['cell['+i+']['+j+']'];
503 cell.value = '2' + (elem.checked ? '1' : '');
506 // Called when a text value in the spreadsheet is changed.
507 function textChange(elem,i,j) {
508 ssChanged = true;
509 var f = document.forms[0];
510 var cell = f['cell['+i+']['+j+']'];
511 cell.value = '3' + elem.value;
514 // Called when a textarea value in the spreadsheet is changed.
515 function longChange(elem,i,j) {
516 ssChanged = true;
517 var f = document.forms[0];
518 var cell = f['cell['+i+']['+j+']'];
519 cell.value = '4' + elem.value;
522 // Helper function to get the value element of a table cell given any
523 // other element within that cell.
524 function getHidden(sel) {
525 var p = sel.parentNode;
526 while (p.tagName != 'TD') {
527 if (!p.parentNode || p.parentNode == p) {
528 alert("JavaScript error, cannot find TD element");
529 return '';
531 p = p.parentNode;
533 // Get the <input type=hidden> element within this table cell.
534 var f = document.forms[0];
535 var s = p.id.substring(3);
536 var uix = s.indexOf('_');
537 var i = s.substring(0, uix);
538 var j = s.substring(uix+1);
539 return f['cell[' + i + '][' + j + ']'];
542 // Called when a user-defined select list has a new selection.
543 // This rewrites the function definition for the select list.
544 function newsel(sel) {
545 var inelem = getHidden(sel);
546 var s = inelem.value;
547 var i = s.indexOf('%sel(');
548 var j = s.indexOf(')', i);
549 var x = s.substring(0, j);
550 var k = x.lastIndexOf(',');
551 inelem.value = s.substring(0, k+1) + sel.value + s.substring(j);
554 // Called when a physiotherapy select list has a new selection.
555 // This rewrites the function definition for the select list.
556 function newptp(sel) {
557 var inelem = getHidden(sel);
558 var s = inelem.value;
559 var i = s.indexOf('%ptp(') + 5;
560 var j = s.indexOf(')', i);
561 inelem.value = s.substring(0, i) + sel.value + s.substring(j);
564 $(document).ready(function() {
565 $('.datepicker').datetimepicker({
566 <?php $datetimepicker_timepicker = false; ?>
567 <?php $datetimepicker_showseconds = false; ?>
568 <?php $datetimepicker_formatInput = false; ?>
569 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
570 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
574 </script>
576 </head>
578 <body class="body_top">
579 <form method="post" action="<?php echo "$rootdir/forms/$spreadsheet_form_name/new.php?id=$formid&thisenc=$thisenc";
580 if ($popup) {
581 echo '&popup=1';
582 } ?>"
583 onsubmit="return top.restoreSession()">
584 <center>
586 <table border='0' cellpadding='5' cellspacing='0' style='margin:8pt'>
587 <tr bgcolor='#ddddff'>
588 <td>
589 <?php xl('Start Date', 'e'); ?>:
590 <input type='text' class='datepicker' name='form_start_date' id='form_start_date'
591 size='10' value='<?php echo $start_date; ?>'
592 title='yyyy-mm-dd'
593 <?php echo ($formid && $start_date) ? 'disabled ' : ''; ?>/>
594 &nbsp;
595 <?php xl('Template:', 'e') ?>
596 <select name='form_template' onchange='newTemplate(this)'<?php echo ($formid) ? ' disabled' : ''; ?>>
597 <option value='0'>-- Select --</option>
598 <?php
599 while ($trow = sqlFetchArray($tres)) {
600 echo " <option value='" . $trow['id'] . "'";
601 if ($tempid && $tempid == $trow['id'] ||
602 $formid && $template_name == $trow['value']) {
603 echo " selected";
606 echo ">" . $trow['value'] . "</option>\n";
609 </select>
610 &nbsp;
611 <input type='checkbox' name='form_edit_template'
612 onclick='editChanged()'
613 title='<?php xl("If you want to change data types, or add rows or columns", "e") ?>' />
614 <?php xl('Edit Structure', 'e') ?>
615 <?php if ($formid) { ?>
616 &nbsp;
617 <input type='checkbox' name='form_completed'
618 title='<?php xl("If all data for all columns are complete for this form", "e") ?>'
619 <?php echo ($form_completed) ? 'checked ' : ''; ?>/>
620 <?php xl('Completed', 'e') ?>
621 <?php } ?>
622 </td>
623 </tr>
624 </table>
626 <table border='1' cellpadding='2' cellspacing='0' class='sstable'>
627 <?php
628 if ($dres) {
629 $drow = sqlFetchArray($dres);
632 $typeprompts = array('unused','static','checkbox','text');
634 for ($i = 0; $i < $num_virtual_rows; ++$i) {
635 echo " <tr>\n";
636 for ($j = 0; $j < $num_virtual_cols; ++$j) {
637 // Match up with the database for cell type and value.
638 $celltype = '0';
639 $cellvalue = '';
640 if ($dres) {
641 while ($drow && $drow['rownbr'] < $i) {
642 $drow = sqlFetchArray($dres);
645 while ($drow && $drow['rownbr'] == $i && $drow['colnbr'] < $j) {
646 $drow = sqlFetchArray($dres);
649 if ($drow && $drow['rownbr'] == $i && $drow['colnbr'] == $j) {
650 $celltype = $drow['datatype'];
651 $cellvalue = real2form($drow['value']);
652 $cellstatic = addslashes($drow['value']);
656 echo " <td id='td_${i}_${j}' valign='top'";
657 if ($i >= $num_used_rows || $j >= $num_used_cols) {
658 echo " style='display:none'";
661 echo ">";
663 /*****************************************************************
664 echo "<span id='div_${i}_${j}' ";
665 echo "style='float:right;cursor:pointer;display:none' ";
666 echo "onclick='newType($i,$j)'>[";
667 echo $typeprompts[$celltype];
668 echo "]</span>";
669 *****************************************************************/
670 echo "<div class='seldiv'>";
671 echo "<select id='sel_${i}_${j}' class='seltype' style='display:none' " .
672 "onchange='newType($i,$j)'>";
673 foreach ($celltypes as $key => $value) {
674 echo "<option value='$key'";
675 if ($key == $celltype) {
676 echo " selected";
679 echo ">$value</option>";
682 echo "</select>";
683 echo "</div>";
684 /****************************************************************/
686 echo "<span id='vis_${i}_${j}'>"; // new //
688 echo "<input type='hidden' name='cell[$i][$j]' value='$celltype$cellvalue' />";
689 if ($celltype == '1') {
690 // So we don't have to write a PHP version of genStatic():
691 echo "<script language='JavaScript'>document.write(genStatic('$cellstatic'));</script>";
692 } else if ($celltype == '2') {
693 echo "<input type='checkbox' value='1' onclick='cbClick(this,$i,$j)'";
694 if ($cellvalue) {
695 echo " checked";
698 echo " />";
699 } else if ($celltype == '3') {
700 echo "<input type='text' class='intext' onchange='textChange(this,$i,$j)'";
701 echo " value='$cellvalue'";
702 echo " size='12' />";
703 } else if ($celltype == '4') {
704 echo "<textarea rows='3' cols='25' wrap='virtual' class='intext' " .
705 "onchange='longChange(this,$i,$j)'>";
706 echo $cellvalue;
707 echo "</textarea>";
710 echo "</span>"; // new //
712 echo "</td>\n";
715 echo " </tr>\n";
718 </table>
721 <input type='submit' name='bn_save_form' value='Save Form' />
722 <?php if (!$formid) { ?>
723 &nbsp;
724 <input type='submit' name='bn_save_template' value='Save as Template:' />
725 &nbsp;
726 <input type='text' name='form_new_template_name' value='<?php echo $template_name ?>' />
727 &nbsp;
728 <input type='submit' name='bn_delete_template' value='Delete Template' />
729 <?php } ?>
730 &nbsp;
731 <input type='button' value='Cancel' onclick="doCancel()" />
732 </p>
734 </center>
735 </form>
736 <script language='JavaScript'>
737 <?php
738 if ($alertmsg) {
739 echo " alert('$alertmsg');\n";
742 </script>
743 </body>
744 </html>