Hide dashboard card 2 (#7423)
[openemr.git] / library / spreadsheet.inc.php
blob0e015d5c6de9039b340dd2cd3465a5adc2c6b1d7
1 <?php
3 /**
4 * spreadsheet.inc.php
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2006-2011 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once(dirname(__FILE__) . '/api.inc.php');
16 require_once(dirname(__FILE__) . '/forms.inc.php');
17 require_once(dirname(__FILE__) . '/../interface/forms/fee_sheet/codes.php');
19 use OpenEMR\Core\Header;
21 $celltypes = array(
22 '0' => 'Unused',
23 '1' => 'Static',
24 '2' => 'Checkbox',
25 '3' => 'Text',
26 '4' => 'Longtext',
27 // '5' => 'Function',
30 // encode a string from a form field for database writing.
31 function form2db($fldval)
33 $fldval = trim($fldval);
34 return $fldval;
37 // Get the actual string from a form field.
38 function form2real($fldval)
40 $fldval = trim($fldval);
41 return $fldval;
44 // encode a plain string for html display.
45 function real2form($fldval)
47 return attr($fldval);
50 if (empty($spreadsheet_title)) {
51 $spreadsheet_title = 'Injury Log';
54 // Putting an error message in here will result in a javascript alert.
55 $alertmsg = '';
57 // Determine the encounter that we are working with.
58 $thisenc = empty($_GET['thisenc']) ? $encounter : $_GET['thisenc'] + 0;
60 // If we are invoked as a popup (not in an encounter):
61 $popup = $_GET['popup'];
63 // The form ID is passed to us when an existing encounter form is loaded.
64 $formid = $_GET['id'];
66 // $tempid is the currently selected template, if any.
67 $tempid = $_POST['form_template'] + 0;
69 // This is the start date to be saved with the spreadsheet.
70 $start_date = '';
72 $form_completed = '0';
74 if (!$popup && !$encounter) { // $encounter comes from globals.php
75 die("Internal error: we do not seem to be in an encounter!");
78 // Get the name of the template selected by the dropdown, if any;
79 // or if we are loading a form then it comes from that.
80 $template_name = '';
81 if ($tempid) {
82 $trow = sqlQuery("SELECT value FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
83 " WHERE id = ? AND rownbr = -1 AND colnbr = -1", array($tempid));
84 $template_name = $trow['value'];
85 } elseif ($formid) {
86 $trow = sqlQuery("SELECT value FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
87 " WHERE id = ? AND rownbr = -1 AND colnbr = -1", array($formid));
88 list($form_completed, $start_date, $template_name) = explode('|', $trow['value'], 3);
91 if (!$start_date) {
92 $start_date = form2real($_POST['form_start_date']);
95 // Used rows and columns are those beyond which there are only unused cells.
96 $num_used_rows = 0;
97 $num_used_cols = 0;
99 // If we are saving...
101 if ($_POST['bn_save_form'] || $_POST['bn_save_template']) {
102 // The form data determines how many rows and columns are now used.
103 $cells = $_POST['cell'];
104 for ($i = 0; $i < count($cells); ++$i) {
105 $row = $cells[$i];
106 for ($j = 0; $j < count($row); ++$j) {
107 if (substr($row[$j], 0, 1)) {
108 if ($i >= $num_used_rows) {
109 $num_used_rows = $i + 1;
112 if ($j >= $num_used_cols) {
113 $num_used_cols = $j + 1;
119 if ($_POST['bn_save_form']) {
120 $form_completed = $_POST['form_completed'] ? '1' : '0';
122 // If updating an existing form...
123 if ($formid) {
124 sqlStatement(
125 "UPDATE " . escape_table_name('form_' . $spreadsheet_form_name) .
126 " SET value = ? WHERE id = ? AND rownbr = -1 AND colnbr = -1",
127 array(
128 $form_completed . '|' . $start_date . '|' . $template_name,
129 $formid
132 sqlStatement(
133 "DELETE FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
134 " WHERE id = ? AND rownbr >= 0 AND colnbr >= 0",
135 array($formid)
137 } else { // If adding a new form...
138 $tmprow = sqlQuery(
139 "SELECT pid FROM form_encounter WHERE encounter = ? ORDER BY id DESC LIMIT 1",
140 array($thisenc)
142 $thispid = $tmprow['pid'];
143 sqlStatement(
144 "LOCK TABLES " . escape_table_name('form_' . $spreadsheet_form_name) .
145 " WRITE, log WRITE"
147 $tmprow = sqlQuery("SELECT MAX(id) AS maxid FROM " .
148 escape_table_name('form_' . $spreadsheet_form_name));
149 $formid = $tmprow['maxid'] + 1;
150 if ($formid <= 0) {
151 $formid = 1;
154 sqlStatement(
155 "INSERT INTO " . escape_table_name('form_' . $spreadsheet_form_name) . " ( " .
156 "id, rownbr, colnbr, datatype, value " .
157 ") VALUES ( ?, -1, -1, 0, ? )",
158 array(
159 $formid,
160 $form_completed . '|' . $start_date . '|' . $template_name
163 sqlStatement("UNLOCK TABLES");
164 addForm(
165 $thisenc,
166 $spreadsheet_title,
167 $formid,
168 "$spreadsheet_form_name",
169 $thispid,
170 $userauthorized
174 $saveid = $formid;
175 } else { // saving a template
176 // The rule is, we can update the original name, or insert a new name
177 // which must not match any existing template name.
178 $new_template_name = form2real($_POST['form_new_template_name']);
179 if ($new_template_name != $template_name) {
180 $trow = sqlQuery(
181 "SELECT id FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
182 " WHERE id < 0 AND rownbr = -1 AND colnbr = -1 AND value = ?",
183 array($new_template_name)
185 if ($trow['id']) {
186 $alertmsg = "Template \"" . real2form($new_template_name) .
187 "\" already exists!";
188 } else {
189 $tempid = 0; // to force insert of new template
190 $template_name = $new_template_name;
194 if (!$alertmsg) {
195 // If updating an existing template...
196 if ($tempid) {
197 sqlStatement(
198 "DELETE FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
199 " WHERE id = ? AND rownbr >= 0 AND colnbr >= 0",
200 array($tempid)
202 } else { // If adding a new template...
203 sqlStatement(
204 "LOCK TABLES " . escape_table_name('form_' . $spreadsheet_form_name) .
205 " WRITE, log WRITE"
207 $tmprow = sqlQuery("SELECT MIN(id) AS minid FROM " .
208 escape_table_name('form_' . $spreadsheet_form_name));
209 $tempid = $tmprow['minid'] - 1;
210 if ($tempid >= 0) {
211 $tempid = -1;
214 sqlStatement(
215 "INSERT INTO " . escape_table_name('form_' . $spreadsheet_form_name) . " ( " .
216 "id, rownbr, colnbr, datatype, value " .
217 ") VALUES ( ?, -1, -1, 0, ? )",
218 array(
219 $tempid,
220 $template_name
223 sqlStatement("UNLOCK TABLES");
226 $saveid = $tempid;
230 if (!$alertmsg) {
231 // Finally, save the table cells.
232 for ($i = 0; $i < $num_used_rows; ++$i) {
233 for ($j = 0; $j < $num_used_cols; ++$j) {
234 $tmp = $cells[$i][$j];
235 $celltype = substr($tmp, 0, 1) + 0;
236 $cellvalue = form2db(substr($tmp, 1));
237 if ($celltype) {
238 sqlStatement(
239 "INSERT INTO " . escape_table_name('form_' . $spreadsheet_form_name) .
240 " ( id, rownbr, colnbr, datatype, value ) " .
241 "VALUES ( ?, ?, ?, ?, ? )",
242 array($saveid, $i, $j, $celltype, $cellvalue)
248 } elseif ($_POST['bn_delete_template'] && $tempid) {
249 sqlStatement(
250 "DELETE FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
251 " WHERE id = ?",
252 array($tempid)
254 $tempid = 0;
255 $template_name = '';
258 if ($_POST['bn_save_form'] && !$alertmsg && !$popup) {
259 formHeader("Redirecting....");
260 formJump();
261 formFooter();
262 exit;
265 // If we get here then we are displaying a spreadsheet, either a template or
266 // an encounter form.
268 // Get the array of template names.
269 $tres = sqlStatement("SELECT id, value FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
270 " WHERE id < 0 AND rownbr = -1 AND colnbr = -1 ORDER BY value");
272 $dres = false;
274 # If we are reloading a form, get it.
275 if ($formid) {
276 $dres = sqlStatement("SELECT * FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
277 " WHERE id = ? ORDER BY rownbr, colnbr", array($formid));
278 $tmprow = sqlQuery(
279 "SELECT MAX(rownbr) AS rowmax, MAX(colnbr) AS colmax " .
280 "FROM " . escape_table_name('form_' . $spreadsheet_form_name) . " WHERE id = ?",
281 array($formid)
283 $num_used_rows = $tmprow['rowmax'] + 1;
284 $num_used_cols = $tmprow['colmax'] + 1;
285 } elseif ($tempid) { // Otherwise if we are editing a template, get it.
286 $dres = sqlStatement(
287 "SELECT * FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
288 " WHERE id = ? ORDER BY rownbr, colnbr",
289 array($tempid)
291 $tmprow = sqlQuery(
292 "SELECT MAX(rownbr) AS rowmax, MAX(colnbr) AS colmax " .
293 "FROM " . escape_table_name('form_' . $spreadsheet_form_name) . " WHERE id = ?",
294 array($tempid)
296 $num_used_rows = $tmprow['rowmax'] + 1;
297 $num_used_cols = $tmprow['colmax'] + 1;
300 // Virtual rows and columns are those available when in Edit Structure mode,
301 // and include some additional ones beyond those used. This allows quite a
302 // lot of stuff to be entered before having to save the template.
303 $num_virtual_rows = $num_used_rows ? $num_used_rows + 5 : 10;
304 $num_virtual_cols = $num_used_cols ? $num_used_cols + 5 : 10;
306 <html>
307 <head>
308 <?php Header::setupHeader('datetime-picker'); ?>
310 <style>
311 .sstable td {
312 font-family: sans-serif;
313 font-weight: bold;
314 font-size: 9pt;
316 .seltype {
317 font-family: sans-serif;
318 font-weight: normal;
319 font-size: 8pt;
320 background-color: transparent;
322 .selgen {
323 font-family: sans-serif;
324 font-weight: normal;
325 font-size: 8pt;
326 background-color: transparent;
328 .intext {
329 font-family: sans-serif;
330 font-weight: normal;
331 font-size: 9pt;
332 background-color: transparent;
333 width: 100%;
335 .seldiv {
336 margin: 0 0 0 0;
337 padding: 0 0 0 0;
339 </style>
341 <script>
343 var ssChanged = false; // if they have changed anything in the spreadsheet
344 var startDate = <?php echo js_escape(($start_date ? $start_date : date('Y-m-d'))); ?>;
346 // In case we are a popup (top level) window, handle top.restoreSession() calls.
347 function restoreSession() {
348 return opener.top.restoreSession();
351 // Helper function to set the contents of a block.
352 function setBlockContent(id, content) {
353 if (document.getElementById) {
354 var x = document.getElementById(id);
355 x.innerHTML = '';
356 x.innerHTML = content;
358 else if (document.all) {
359 var x = document.all[id];
360 x.innerHTML = content;
362 // alert("ID = \"" + id + "\", string = \"" + content + "\"");
365 // Called when a different template name is selected.
366 function newTemplate(sel) {
367 if (ssChanged && !confirm('You have made changes that will be discarded ' +
368 'if you select a new template. Do you really want to do this?'))
370 // Restore the original template selection.
371 for (var i = 0; i < sel.options.length; ++i) {
372 if (sel.options[i].value == '<?php echo $tempid ?>') {
373 sel.options[i].selected = true;
376 return;
378 top.restoreSession();
379 document.forms[0].submit();
382 // Called when the Cancel button is clicked.
383 function doCancel() {
384 if (!ssChanged || confirm('You have made changes that will be discarded ' +
385 'if you close now. Click OK if you really want to exit this form.'))
387 <?php if ($popup) { ?>
388 window.close();
389 <?php } else { ?>
390 top.restoreSession();
391 location='<?php echo $GLOBALS['form_exit_url'] ?>';
392 <?php } ?>
396 // Called when the Edit Structure checkbox is clicked.
397 function editChanged() {
398 var f = document.forms[0];
399 var newdisplay = f.form_edit_template.checked ? '' : 'none';
400 var usedrows = 0;
401 var usedcols = 0;
402 for (var i = 0; i < <?php echo $num_virtual_rows; ?>; ++i) {
403 for (var j = 0; j < <?php echo $num_virtual_cols; ?>; ++j) {
404 if (f['cell['+i+']['+j+']'].value.charAt(0) != '0') {
405 if (i >= usedrows) usedrows = i + 1;
406 if (j >= usedcols) usedcols = j + 1;
410 for (var i = 0; i < <?php echo $num_virtual_rows; ?>; ++i) {
411 for (var j = 0; j < <?php echo $num_virtual_cols; ?>; ++j) {
412 // document.getElementById('div_'+i+'_'+j).style.display = newdisplay;
413 document.getElementById('sel_'+i+'_'+j).style.display = newdisplay;
414 if (i >= usedrows || j >= usedcols) {
415 document.getElementById('td_'+i+'_'+j).style.display = newdisplay;
421 // Prepare a string for use as an HTML value attribute in single quotes.
422 function escQuotes(s) {
423 return s.replace(/'/g, "&#39;");
426 // Parse static text to evaluate possible functions.
427 function genStatic(s) {
428 var i = 0;
430 // Parse "%day(n)".
431 while ((i = s.indexOf('%day(')) >= 0) {
432 var s1 = s.substring(0, i);
433 i += 5;
434 var j = s.indexOf(')', i);
435 if (j < 0) break;
436 var dayinc = parseInt(s.substring(i,j));
437 var mydate = new Date(parseInt(startDate.substring(0,4)),
438 parseInt(startDate.substring(5,7))-1, parseInt(startDate.substring(8)));
439 mydate.setTime(1000 * 60 * 60 * 24 * dayinc + mydate.getTime());
440 var year = mydate.getYear(); if (year < 1900) year += 1900;
441 s = s1 + year + '-' +
442 ('' + (mydate.getMonth() + 101)).substring(1) + '-' +
443 ('' + (mydate.getDate() + 100)).substring(1) +
444 s.substring(j + 1);
447 // Parse "%sel(first,second,third,...,default)".
448 while ((i = s.indexOf('%sel(')) >= 0) {
449 var s1 = s.substring(0, i);
450 i += 5;
451 var j = s.indexOf(')', i);
452 if (j < 0) break;
453 var x = s.substring(0,j);
454 var k = x.lastIndexOf(',');
455 if (k < i) break;
456 var dflt = s.substring(k+1, j);
457 x = "<select class='selgen' onchange='newsel(this)'>";
458 while ((k = s.indexOf(',', i)) > i) {
459 if (k > j) break;
460 var elem = s.substring(i,k);
461 x += "<option value='" + elem + "'";
462 if (elem == dflt) x += " selected";
463 x += ">" + elem + "</option>";
464 i = k + 1;
466 x += "</select>";
467 s = s1 + x + s.substring(j + 1);
468 break; // only one %sel allowed
471 // Parse "%ptp(default)".
472 while ((i = s.indexOf('%ptp(')) >= 0) {
473 var s1 = s.substring(0, i);
474 i += 5;
475 var j = s.indexOf(')', i);
476 if (j < 0) break;
477 var dflt = s.substring(i, j);
478 x = "<select class='selgen' onchange='newptp(this)'>";
479 x += "<option value=''>-- Select --</option>";
480 <?php
481 foreach ($bcodes['Phys']['Physiotherapy Procedures'] as $key => $value) {
482 echo " x += \"<option value='$key'\";\n";
483 echo " if (dflt == '$key') x += ' selected';\n";
484 echo " x += '>$value</option>';\n";
487 x += "</select>";
488 s = s1 + x + s.substring(j + 1);
489 break; // only one %ptp allowed
492 return s;
495 // Called when a cell type selector in the spreadsheet is clicked.
496 function newType(i,j) {
497 ssChanged = true;
498 var f = document.forms[0];
499 var typeval = f['cell['+i+']['+j+']'].value;
500 var thevalue = typeval.substring(1);
501 var thetype = document.getElementById('sel_'+i+'_'+j).value;
502 var s = "<input type='hidden' name='cell[" + i + "][" + j + "]' " +
503 "value='" + thetype + escQuotes(thevalue) + "' />";
505 if (thetype == '1') {
506 s += genStatic(thevalue);
508 else if (thetype == '2') {
509 s += "<input type='checkbox' value='1' onclick='cbClick(this," + i + "," + j + ")'";
510 if (thevalue) s += " checked";
511 s += " />";
513 else if (thetype == '3') {
514 s += "<input type='text' onchange='textChange(this," + i + "," + j + ")'" +
515 " class='intext' value='" + escQuotes(thevalue) + "' size='12' />";
517 else if (thetype == '4') {
518 s += "<textarea rows='3' cols='25' wrap='virtual' class='intext' " +
519 "onchange='longChange(this," + i + "," + j + ")'>" +
520 escQuotes(thevalue) + "</textarea>";
522 setBlockContent('vis_' + i + '_' + j, s);
525 // Called when a checkbox in the spreadsheet is clicked.
526 function cbClick(elem,i,j) {
527 ssChanged = true;
528 var f = document.forms[0];
529 var cell = f['cell['+i+']['+j+']'];
530 cell.value = '2' + (elem.checked ? '1' : '');
533 // Called when a text value in the spreadsheet is changed.
534 function textChange(elem,i,j) {
535 ssChanged = true;
536 var f = document.forms[0];
537 var cell = f['cell['+i+']['+j+']'];
538 cell.value = '3' + elem.value;
541 // Called when a textarea value in the spreadsheet is changed.
542 function longChange(elem,i,j) {
543 ssChanged = true;
544 var f = document.forms[0];
545 var cell = f['cell['+i+']['+j+']'];
546 cell.value = '4' + elem.value;
549 // Helper function to get the value element of a table cell given any
550 // other element within that cell.
551 function getHidden(sel) {
552 var p = sel.parentNode;
553 while (p.tagName != 'TD') {
554 if (!p.parentNode || p.parentNode == p) {
555 alert("JavaScript error, cannot find TD element");
556 return '';
558 p = p.parentNode;
560 // Get the <input type=hidden> element within this table cell.
561 var f = document.forms[0];
562 var s = p.id.substring(3);
563 var uix = s.indexOf('_');
564 var i = s.substring(0, uix);
565 var j = s.substring(uix+1);
566 return f['cell[' + i + '][' + j + ']'];
569 // Called when a user-defined select list has a new selection.
570 // This rewrites the function definition for the select list.
571 function newsel(sel) {
572 var inelem = getHidden(sel);
573 var s = inelem.value;
574 var i = s.indexOf('%sel(');
575 var j = s.indexOf(')', i);
576 var x = s.substring(0, j);
577 var k = x.lastIndexOf(',');
578 inelem.value = s.substring(0, k+1) + sel.value + s.substring(j);
581 // Called when a physiotherapy select list has a new selection.
582 // This rewrites the function definition for the select list.
583 function newptp(sel) {
584 var inelem = getHidden(sel);
585 var s = inelem.value;
586 var i = s.indexOf('%ptp(') + 5;
587 var j = s.indexOf(')', i);
588 inelem.value = s.substring(0, i) + sel.value + s.substring(j);
591 $(function () {
592 $('.datepicker').datetimepicker({
593 <?php $datetimepicker_timepicker = false; ?>
594 <?php $datetimepicker_showseconds = false; ?>
595 <?php $datetimepicker_formatInput = false; ?>
596 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
597 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
601 </script>
603 </head>
605 <body class="body_top">
606 <form method="post" action="<?php echo "$rootdir/forms/$spreadsheet_form_name/new.php?id=" . attr_url($formid) . "&thisenc=" . attr_url($thisenc);
607 if ($popup) {
608 echo '&popup=1';
609 } ?>"
610 onsubmit="return top.restoreSession()">
611 <center>
613 <table border='0' cellpadding='5' cellspacing='0' style='margin:8pt'>
614 <tr bgcolor='#ddddff'>
615 <td>
616 <?php echo xlt('Start Date'); ?>:
617 <input type='text' class='datepicker' name='form_start_date' id='form_start_date'
618 size='10' value='<?php echo attr($start_date); ?>'
619 title='yyyy-mm-dd'
620 <?php echo ($formid && $start_date) ? 'disabled ' : ''; ?>/>
621 &nbsp;
622 <?php echo xlt('Template:'); ?>
623 <select name='form_template' onchange='newTemplate(this)'<?php echo ($formid) ? ' disabled' : ''; ?>>
624 <option value='0'>-- Select --</option>
625 <?php
626 while ($trow = sqlFetchArray($tres)) {
627 echo " <option value='" . attr($trow['id']) . "'";
628 if (
629 $tempid && $tempid == $trow['id'] ||
630 $formid && $template_name == $trow['value']
632 echo " selected";
635 echo ">" . text($trow['value']) . "</option>\n";
638 </select>
639 &nbsp;
640 <input type='checkbox' name='form_edit_template'
641 onclick='editChanged()'
642 title='<?php echo xla("If you want to change data types, or add rows or columns"); ?>' />
643 <?php echo xlt('Edit Structure'); ?>
644 <?php if ($formid) { ?>
645 &nbsp;
646 <input type='checkbox' name='form_completed'
647 title='<?php echo xla("If all data for all columns are complete for this form"); ?>'
648 <?php echo ($form_completed) ? 'checked ' : ''; ?>/>
649 <?php echo xlt('Completed'); ?>
650 <?php } ?>
651 </td>
652 </tr>
653 </table>
655 <table border='1' cellpadding='2' cellspacing='0' class='sstable'>
656 <?php
657 if ($dres) {
658 $drow = sqlFetchArray($dres);
661 $typeprompts = array('unused','static','checkbox','text');
663 for ($i = 0; $i < $num_virtual_rows; ++$i) {
664 echo " <tr>\n";
665 for ($j = 0; $j < $num_virtual_cols; ++$j) {
666 // Match up with the database for cell type and value.
667 $celltype = '0';
668 $cellvalue = '';
669 if ($dres) {
670 while ($drow && $drow['rownbr'] < $i) {
671 $drow = sqlFetchArray($dres);
674 while ($drow && $drow['rownbr'] == $i && $drow['colnbr'] < $j) {
675 $drow = sqlFetchArray($dres);
678 if ($drow && $drow['rownbr'] == $i && $drow['colnbr'] == $j) {
679 $celltype = $drow['datatype'];
680 $cellvalue = $drow['value'];
681 $cellstatic = addslashes($drow['value']);
685 echo " <td id='td_${i}_${j}' valign='top'";
686 if ($i >= $num_used_rows || $j >= $num_used_cols) {
687 echo " style='display:none'";
690 echo ">";
692 /*****************************************************************
693 echo "<span id='div_${i}_${j}' ";
694 echo "style='float:right;cursor:pointer;display:none' ";
695 echo "onclick='newType($i,$j)'>[";
696 echo $typeprompts[$celltype];
697 echo "]</span>";
698 *****************************************************************/
699 echo "<div class='seldiv'>";
700 echo "<select id='sel_${i}_${j}' class='seltype' style='display:none' " .
701 "onchange='newType($i,$j)'>";
702 foreach ($celltypes as $key => $value) {
703 echo "<option value='" . attr($key) . "'";
704 if ($key == $celltype) {
705 echo " selected";
708 echo ">" . text($value) . "</option>";
711 echo "</select>";
712 echo "</div>";
713 /****************************************************************/
715 echo "<span id='vis_${i}_${j}'>"; // new //
717 echo "<input type='hidden' name='cell[$i][$j]' value='" . attr($celltype) . attr($cellvalue) . "' />";
718 if ($celltype == '1') {
719 // So we don't have to write a PHP version of genStatic():
720 echo "<script>document.write(genStatic('$cellstatic'));</script>";
721 } elseif ($celltype == '2') {
722 echo "<input type='checkbox' value='1' onclick='cbClick(this,$i,$j)'";
723 if ($cellvalue) {
724 echo " checked";
727 echo " />";
728 } elseif ($celltype == '3') {
729 echo "<input type='text' class='intext' onchange='textChange(this,$i,$j)'";
730 echo " value='" . attr($cellvalue) . "'";
731 echo " size='12' />";
732 } elseif ($celltype == '4') {
733 echo "<textarea rows='3' cols='25' wrap='virtual' class='intext' " .
734 "onchange='longChange(this,$i,$j)'>";
735 echo text($cellvalue);
736 echo "</textarea>";
739 echo "</span>"; // new //
741 echo "</td>\n";
744 echo " </tr>\n";
747 </table>
750 <input type='submit' name='bn_save_form' value='Save Form' />
751 <?php if (!$formid) { ?>
752 &nbsp;
753 <input type='submit' name='bn_save_template' value='Save as Template:' />
754 &nbsp;
755 <input type='text' name='form_new_template_name' value='<?php echo attr($template_name); ?>' />
756 &nbsp;
757 <input type='submit' name='bn_delete_template' value='Delete Template' />
758 <?php } ?>
759 &nbsp;
760 <input type='button' value='Cancel' onclick="doCancel()" />
761 </p>
763 </center>
764 </form>
765 <script>
766 <?php
767 if ($alertmsg) {
768 echo " alert(" . js_escape($alertmsg) . ");\n";
771 </script>
772 </body>
773 </html>