Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / library / spreadsheet.inc.php
blob7105f13646bb70816e6b8ee47a2b0df8915edfe5
1 <?php
2 /**
3 * spreadsheet.inc.php
5 * @package OpenEMR
6 * @link https://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 return $fldval;
34 // Get the actual string from a form field.
35 function form2real($fldval)
37 $fldval = trim($fldval);
38 return $fldval;
41 // encode a plain string for html display.
42 function real2form($fldval)
44 return htmlspecialchars($fldval, ENT_QUOTES);
47 if (empty($spreadsheet_title)) {
48 $spreadsheet_title = 'Injury Log';
51 // Putting an error message in here will result in a javascript alert.
52 $alertmsg = '';
54 // Determine the encounter that we are working with.
55 $thisenc = empty($_GET['thisenc']) ? $encounter : $_GET['thisenc'] + 0;
57 // If we are invoked as a popup (not in an encounter):
58 $popup = $_GET['popup'];
60 // The form ID is passed to us when an existing encounter form is loaded.
61 $formid = $_GET['id'];
63 // $tempid is the currently selected template, if any.
64 $tempid = $_POST['form_template'] + 0;
66 // This is the start date to be saved with the spreadsheet.
67 $start_date = '';
69 $form_completed = '0';
71 if (!$popup && !$encounter) { // $encounter comes from globals.php
72 die("Internal error: we do not seem to be in an encounter!");
75 // Get the name of the template selected by the dropdown, if any;
76 // or if we are loading a form then it comes from that.
77 $template_name = '';
78 if ($tempid) {
79 $trow = sqlQuery("SELECT value FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
80 " WHERE id = ? AND rownbr = -1 AND colnbr = -1", array($tempid));
81 $template_name = $trow['value'];
82 } else if ($formid) {
83 $trow = sqlQuery("SELECT value FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
84 " WHERE id = ? AND rownbr = -1 AND colnbr = -1", array($formid));
85 list($form_completed, $start_date, $template_name) = explode('|', $trow['value'], 3);
88 if (!$start_date) {
89 $start_date = form2real($_POST['form_start_date']);
92 // Used rows and columns are those beyond which there are only unused cells.
93 $num_used_rows = 0;
94 $num_used_cols = 0;
96 // If we are saving...
98 if ($_POST['bn_save_form'] || $_POST['bn_save_template']) {
99 // The form data determines how many rows and columns are now used.
100 $cells = $_POST['cell'];
101 for ($i = 0; $i < count($cells); ++$i) {
102 $row = $cells[$i];
103 for ($j = 0; $j < count($row); ++$j) {
104 if (substr($row[$j], 0, 1)) {
105 if ($i >= $num_used_rows) {
106 $num_used_rows = $i + 1;
109 if ($j >= $num_used_cols) {
110 $num_used_cols = $j + 1;
116 if ($_POST['bn_save_form']) {
117 $form_completed = $_POST['form_completed'] ? '1' : '0';
119 // If updating an existing form...
120 if ($formid) {
121 sqlStatement(
122 "UPDATE " . escape_table_name('form_' . $spreadsheet_form_name) .
123 " SET value = ? WHERE id = ? AND rownbr = -1 AND colnbr = -1",
124 array(
125 $form_completed . '|' . $start_date . '|' . $template_name,
126 $formid
129 sqlStatement(
130 "DELETE FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
131 " WHERE id = ? AND rownbr >= 0 AND colnbr >= 0",
132 array($formid)
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(
142 "LOCK TABLES " . escape_table_name('form_' . $spreadsheet_form_name) .
143 " WRITE, log WRITE"
145 $tmprow = sqlQuery("SELECT MAX(id) AS maxid FROM " .
146 escape_table_name('form_' . $spreadsheet_form_name));
147 $formid = $tmprow['maxid'] + 1;
148 if ($formid <= 0) {
149 $formid = 1;
152 sqlStatement(
153 "INSERT INTO " . escape_table_name('form_' .$spreadsheet_form_name) . " ( " .
154 "id, rownbr, colnbr, datatype, value " .
155 ") VALUES ( ?, -1, -1, 0, ? )",
156 array(
157 $formid,
158 $form_completed . '|' . $start_date . '|' . $template_name
161 sqlStatement("UNLOCK TABLES");
162 addForm(
163 $thisenc,
164 $spreadsheet_title,
165 $formid,
166 "$spreadsheet_form_name",
167 $thispid,
168 $userauthorized
172 $saveid = $formid;
173 } else { // saving a template
174 // The rule is, we can update the original name, or insert a new name
175 // which must not match any existing template name.
176 $new_template_name = form2real($_POST['form_new_template_name']);
177 if ($new_template_name != $template_name) {
178 $trow = sqlQuery(
179 "SELECT id FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
180 " WHERE id < 0 AND rownbr = -1 AND colnbr = -1 AND value = ?",
181 array($new_template_name)
183 if ($trow['id']) {
184 $alertmsg = "Template \"" . real2form($new_template_name) .
185 "\" already exists!";
186 } else {
187 $tempid = 0; // to force insert of new template
188 $template_name = $new_template_name;
192 if (!$alertmsg) {
193 // If updating an existing template...
194 if ($tempid) {
195 sqlStatement(
196 "DELETE FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
197 " WHERE id = ? AND rownbr >= 0 AND colnbr >= 0",
198 array($tempid)
200 } // If adding a new template...
201 else {
202 sqlStatement(
203 "LOCK TABLES " . escape_table_name('form_' . $spreadsheet_form_name) .
204 " WRITE, log WRITE"
206 $tmprow = sqlQuery("SELECT MIN(id) AS minid FROM " .
207 escape_table_name('form_' . $spreadsheet_form_name));
208 $tempid = $tmprow['minid'] - 1;
209 if ($tempid >= 0) {
210 $tempid = -1;
213 sqlStatement(
214 "INSERT INTO " . escape_table_name('form_' . $spreadsheet_form_name) . " ( " .
215 "id, rownbr, colnbr, datatype, value " .
216 ") VALUES ( ?, -1, -1, 0, ? )",
217 array(
218 $tempid,
219 $template_name
222 sqlStatement("UNLOCK TABLES");
225 $saveid = $tempid;
229 if (!$alertmsg) {
230 // Finally, save the table cells.
231 for ($i = 0; $i < $num_used_rows; ++$i) {
232 for ($j = 0; $j < $num_used_cols; ++$j) {
233 $tmp = $cells[$i][$j];
234 $celltype = substr($tmp, 0, 1) + 0;
235 $cellvalue = form2db(substr($tmp, 1));
236 if ($celltype) {
237 sqlStatement(
238 "INSERT INTO " . escape_table_name('form_' . $spreadsheet_form_name) .
239 " ( id, rownbr, colnbr, datatype, value ) " .
240 "VALUES ( ?, ?, ?, ?, ? )",
241 array($saveid, $i, $j, $celltype, $cellvalue)
247 } else if ($_POST['bn_delete_template'] && $tempid) {
248 sqlStatement(
249 "DELETE FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
250 " WHERE id = ?",
251 array($tempid)
253 $tempid = 0;
254 $template_name = '';
257 if ($_POST['bn_save_form'] && !$alertmsg && !$popup) {
258 formHeader("Redirecting....");
259 formJump();
260 formFooter();
261 exit;
264 // If we get here then we are displaying a spreadsheet, either a template or
265 // an encounter form.
267 // Get the array of template names.
268 $tres = sqlStatement("SELECT id, value FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
269 " WHERE id < 0 AND rownbr = -1 AND colnbr = -1 ORDER BY value");
271 $dres = false;
273 # If we are reloading a form, get it.
274 if ($formid) {
275 $dres = sqlStatement("SELECT * FROM " . escape_table_name('form_' . $spreadsheet_form_name) .
276 " WHERE id = ? ORDER BY rownbr, colnbr", array($formid));
277 $tmprow = sqlQuery(
278 "SELECT MAX(rownbr) AS rowmax, MAX(colnbr) AS colmax " .
279 "FROM " . escape_table_name('form_' . $spreadsheet_form_name) . " WHERE id = ?",
280 array($formid)
282 $num_used_rows = $tmprow['rowmax'] + 1;
283 $num_used_cols = $tmprow['colmax'] + 1;
284 } # Otherwise if we are editing a template, get it.
285 else if ($tempid) {
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 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
309 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
311 <style>
312 .sstable td {
313 font-family: sans-serif;
314 font-weight: bold;
315 font-size: 9pt;
317 .seltype {
318 font-family: sans-serif;
319 font-weight: normal;
320 font-size: 8pt;
321 background-color: transparent;
323 .selgen {
324 font-family: sans-serif;
325 font-weight: normal;
326 font-size: 8pt;
327 background-color: transparent;
329 .intext {
330 font-family: sans-serif;
331 font-weight: normal;
332 font-size: 9pt;
333 background-color: transparent;
334 width: 100%;
336 .seldiv {
337 margin: 0 0 0 0;
338 padding: 0 0 0 0;
340 </style>
342 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script>
343 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
344 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
346 <script language="JavaScript">
348 var ssChanged = false; // if they have changed anything in the spreadsheet
349 var startDate = '<?php echo $start_date ? $start_date : date('Y-m-d'); ?>';
351 // In case we are a popup (top level) window, handle top.restoreSession() calls.
352 function restoreSession() {
353 return opener.top.restoreSession();
356 // Helper function to set the contents of a block.
357 function setBlockContent(id, content) {
358 if (document.getElementById) {
359 var x = document.getElementById(id);
360 x.innerHTML = '';
361 x.innerHTML = content;
363 else if (document.all) {
364 var x = document.all[id];
365 x.innerHTML = content;
367 // alert("ID = \"" + id + "\", string = \"" + content + "\"");
370 // Called when a different template name is selected.
371 function newTemplate(sel) {
372 if (ssChanged && !confirm('You have made changes that will be discarded ' +
373 'if you select a new template. Do you really want to do this?'))
375 // Restore the original template selection.
376 for (var i = 0; i < sel.options.length; ++i) {
377 if (sel.options[i].value == '<?php echo $tempid ?>') {
378 sel.options[i].selected = true;
381 return;
383 top.restoreSession();
384 document.forms[0].submit();
387 // Called when the Cancel button is clicked.
388 function doCancel() {
389 if (!ssChanged || confirm('You have made changes that will be discarded ' +
390 'if you close now. Click OK if you really want to exit this form.'))
392 <?php if ($popup) { ?>
393 window.close();
394 <?php } else { ?>
395 top.restoreSession();
396 location='<?php echo $GLOBALS['form_exit_url'] ?>';
397 <?php } ?>
401 // Called when the Edit Structure checkbox is clicked.
402 function editChanged() {
403 var f = document.forms[0];
404 var newdisplay = f.form_edit_template.checked ? '' : 'none';
405 var usedrows = 0;
406 var usedcols = 0;
407 for (var i = 0; i < <?php echo $num_virtual_rows; ?>; ++i) {
408 for (var j = 0; j < <?php echo $num_virtual_cols; ?>; ++j) {
409 if (f['cell['+i+']['+j+']'].value.charAt(0) != '0') {
410 if (i >= usedrows) usedrows = i + 1;
411 if (j >= usedcols) usedcols = j + 1;
415 for (var i = 0; i < <?php echo $num_virtual_rows; ?>; ++i) {
416 for (var j = 0; j < <?php echo $num_virtual_cols; ?>; ++j) {
417 // document.getElementById('div_'+i+'_'+j).style.display = newdisplay;
418 document.getElementById('sel_'+i+'_'+j).style.display = newdisplay;
419 if (i >= usedrows || j >= usedcols) {
420 document.getElementById('td_'+i+'_'+j).style.display = newdisplay;
426 // Prepare a string for use as an HTML value attribute in single quotes.
427 function escQuotes(s) {
428 return s.replace(/'/g, "&#39;");
431 // Parse static text to evaluate possible functions.
432 function genStatic(s) {
433 var i = 0;
435 // Parse "%day(n)".
436 while ((i = s.indexOf('%day(')) >= 0) {
437 var s1 = s.substring(0, i);
438 i += 5;
439 var j = s.indexOf(')', i);
440 if (j < 0) break;
441 var dayinc = parseInt(s.substring(i,j));
442 var mydate = new Date(parseInt(startDate.substring(0,4)),
443 parseInt(startDate.substring(5,7))-1, parseInt(startDate.substring(8)));
444 mydate.setTime(1000 * 60 * 60 * 24 * dayinc + mydate.getTime());
445 var year = mydate.getYear(); if (year < 1900) year += 1900;
446 s = s1 + year + '-' +
447 ('' + (mydate.getMonth() + 101)).substring(1) + '-' +
448 ('' + (mydate.getDate() + 100)).substring(1) +
449 s.substring(j + 1);
452 // Parse "%sel(first,second,third,...,default)".
453 while ((i = s.indexOf('%sel(')) >= 0) {
454 var s1 = s.substring(0, i);
455 i += 5;
456 var j = s.indexOf(')', i);
457 if (j < 0) break;
458 var x = s.substring(0,j);
459 var k = x.lastIndexOf(',');
460 if (k < i) break;
461 var dflt = s.substring(k+1, j);
462 x = "<select class='selgen' onchange='newsel(this)'>";
463 while ((k = s.indexOf(',', i)) > i) {
464 if (k > j) break;
465 var elem = s.substring(i,k);
466 x += "<option value='" + elem + "'";
467 if (elem == dflt) x += " selected";
468 x += ">" + elem + "</option>";
469 i = k + 1;
471 x += "</select>";
472 s = s1 + x + s.substring(j + 1);
473 break; // only one %sel allowed
476 // Parse "%ptp(default)".
477 while ((i = s.indexOf('%ptp(')) >= 0) {
478 var s1 = s.substring(0, i);
479 i += 5;
480 var j = s.indexOf(')', i);
481 if (j < 0) break;
482 var dflt = s.substring(i, j);
483 x = "<select class='selgen' onchange='newptp(this)'>";
484 x += "<option value=''>-- Select --</option>";
485 <?php
486 foreach ($bcodes['Phys']['Physiotherapy Procedures'] as $key => $value) {
487 echo " x += \"<option value='$key'\";\n";
488 echo " if (dflt == '$key') x += ' selected';\n";
489 echo " x += '>$value</option>';\n";
492 x += "</select>";
493 s = s1 + x + s.substring(j + 1);
494 break; // only one %ptp allowed
497 return s;
500 // Called when a cell type selector in the spreadsheet is clicked.
501 function newType(i,j) {
502 ssChanged = true;
503 var f = document.forms[0];
504 var typeval = f['cell['+i+']['+j+']'].value;
505 var thevalue = typeval.substring(1);
506 var thetype = document.getElementById('sel_'+i+'_'+j).value;
507 var s = "<input type='hidden' name='cell[" + i + "][" + j + "]' " +
508 "value='" + thetype + escQuotes(thevalue) + "' />";
510 if (thetype == '1') {
511 s += genStatic(thevalue);
513 else if (thetype == '2') {
514 s += "<input type='checkbox' value='1' onclick='cbClick(this," + i + "," + j + ")'";
515 if (thevalue) s += " checked";
516 s += " />";
518 else if (thetype == '3') {
519 s += "<input type='text' onchange='textChange(this," + i + "," + j + ")'" +
520 " class='intext' value='" + escQuotes(thevalue) + "' size='12' />";
522 else if (thetype == '4') {
523 s += "<textarea rows='3' cols='25' wrap='virtual' class='intext' " +
524 "onchange='longChange(this," + i + "," + j + ")'>" +
525 escQuotes(thevalue) + "</textarea>";
527 setBlockContent('vis_' + i + '_' + j, s);
530 // Called when a checkbox in the spreadsheet is clicked.
531 function cbClick(elem,i,j) {
532 ssChanged = true;
533 var f = document.forms[0];
534 var cell = f['cell['+i+']['+j+']'];
535 cell.value = '2' + (elem.checked ? '1' : '');
538 // Called when a text value in the spreadsheet is changed.
539 function textChange(elem,i,j) {
540 ssChanged = true;
541 var f = document.forms[0];
542 var cell = f['cell['+i+']['+j+']'];
543 cell.value = '3' + elem.value;
546 // Called when a textarea value in the spreadsheet is changed.
547 function longChange(elem,i,j) {
548 ssChanged = true;
549 var f = document.forms[0];
550 var cell = f['cell['+i+']['+j+']'];
551 cell.value = '4' + elem.value;
554 // Helper function to get the value element of a table cell given any
555 // other element within that cell.
556 function getHidden(sel) {
557 var p = sel.parentNode;
558 while (p.tagName != 'TD') {
559 if (!p.parentNode || p.parentNode == p) {
560 alert("JavaScript error, cannot find TD element");
561 return '';
563 p = p.parentNode;
565 // Get the <input type=hidden> element within this table cell.
566 var f = document.forms[0];
567 var s = p.id.substring(3);
568 var uix = s.indexOf('_');
569 var i = s.substring(0, uix);
570 var j = s.substring(uix+1);
571 return f['cell[' + i + '][' + j + ']'];
574 // Called when a user-defined select list has a new selection.
575 // This rewrites the function definition for the select list.
576 function newsel(sel) {
577 var inelem = getHidden(sel);
578 var s = inelem.value;
579 var i = s.indexOf('%sel(');
580 var j = s.indexOf(')', i);
581 var x = s.substring(0, j);
582 var k = x.lastIndexOf(',');
583 inelem.value = s.substring(0, k+1) + sel.value + s.substring(j);
586 // Called when a physiotherapy select list has a new selection.
587 // This rewrites the function definition for the select list.
588 function newptp(sel) {
589 var inelem = getHidden(sel);
590 var s = inelem.value;
591 var i = s.indexOf('%ptp(') + 5;
592 var j = s.indexOf(')', i);
593 inelem.value = s.substring(0, i) + sel.value + s.substring(j);
596 $(function() {
597 $('.datepicker').datetimepicker({
598 <?php $datetimepicker_timepicker = false; ?>
599 <?php $datetimepicker_showseconds = false; ?>
600 <?php $datetimepicker_formatInput = false; ?>
601 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
602 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
606 </script>
608 </head>
610 <body class="body_top">
611 <form method="post" action="<?php echo "$rootdir/forms/$spreadsheet_form_name/new.php?id=$formid&thisenc=$thisenc";
612 if ($popup) {
613 echo '&popup=1';
614 } ?>"
615 onsubmit="return top.restoreSession()">
616 <center>
618 <table border='0' cellpadding='5' cellspacing='0' style='margin:8pt'>
619 <tr bgcolor='#ddddff'>
620 <td>
621 <?php xl('Start Date', 'e'); ?>:
622 <input type='text' class='datepicker' name='form_start_date' id='form_start_date'
623 size='10' value='<?php echo $start_date; ?>'
624 title='yyyy-mm-dd'
625 <?php echo ($formid && $start_date) ? 'disabled ' : ''; ?>/>
626 &nbsp;
627 <?php xl('Template:', 'e') ?>
628 <select name='form_template' onchange='newTemplate(this)'<?php echo ($formid) ? ' disabled' : ''; ?>>
629 <option value='0'>-- Select --</option>
630 <?php
631 while ($trow = sqlFetchArray($tres)) {
632 echo " <option value='" . $trow['id'] . "'";
633 if ($tempid && $tempid == $trow['id'] ||
634 $formid && $template_name == $trow['value']) {
635 echo " selected";
638 echo ">" . $trow['value'] . "</option>\n";
641 </select>
642 &nbsp;
643 <input type='checkbox' name='form_edit_template'
644 onclick='editChanged()'
645 title='<?php xl("If you want to change data types, or add rows or columns", "e") ?>' />
646 <?php xl('Edit Structure', 'e') ?>
647 <?php if ($formid) { ?>
648 &nbsp;
649 <input type='checkbox' name='form_completed'
650 title='<?php xl("If all data for all columns are complete for this form", "e") ?>'
651 <?php echo ($form_completed) ? 'checked ' : ''; ?>/>
652 <?php xl('Completed', 'e') ?>
653 <?php } ?>
654 </td>
655 </tr>
656 </table>
658 <table border='1' cellpadding='2' cellspacing='0' class='sstable'>
659 <?php
660 if ($dres) {
661 $drow = sqlFetchArray($dres);
664 $typeprompts = array('unused','static','checkbox','text');
666 for ($i = 0; $i < $num_virtual_rows; ++$i) {
667 echo " <tr>\n";
668 for ($j = 0; $j < $num_virtual_cols; ++$j) {
669 // Match up with the database for cell type and value.
670 $celltype = '0';
671 $cellvalue = '';
672 if ($dres) {
673 while ($drow && $drow['rownbr'] < $i) {
674 $drow = sqlFetchArray($dres);
677 while ($drow && $drow['rownbr'] == $i && $drow['colnbr'] < $j) {
678 $drow = sqlFetchArray($dres);
681 if ($drow && $drow['rownbr'] == $i && $drow['colnbr'] == $j) {
682 $celltype = $drow['datatype'];
683 $cellvalue = real2form($drow['value']);
684 $cellstatic = addslashes($drow['value']);
688 echo " <td id='td_${i}_${j}' valign='top'";
689 if ($i >= $num_used_rows || $j >= $num_used_cols) {
690 echo " style='display:none'";
693 echo ">";
695 /*****************************************************************
696 echo "<span id='div_${i}_${j}' ";
697 echo "style='float:right;cursor:pointer;display:none' ";
698 echo "onclick='newType($i,$j)'>[";
699 echo $typeprompts[$celltype];
700 echo "]</span>";
701 *****************************************************************/
702 echo "<div class='seldiv'>";
703 echo "<select id='sel_${i}_${j}' class='seltype' style='display:none' " .
704 "onchange='newType($i,$j)'>";
705 foreach ($celltypes as $key => $value) {
706 echo "<option value='$key'";
707 if ($key == $celltype) {
708 echo " selected";
711 echo ">$value</option>";
714 echo "</select>";
715 echo "</div>";
716 /****************************************************************/
718 echo "<span id='vis_${i}_${j}'>"; // new //
720 echo "<input type='hidden' name='cell[$i][$j]' value='$celltype$cellvalue' />";
721 if ($celltype == '1') {
722 // So we don't have to write a PHP version of genStatic():
723 echo "<script language='JavaScript'>document.write(genStatic('$cellstatic'));</script>";
724 } else if ($celltype == '2') {
725 echo "<input type='checkbox' value='1' onclick='cbClick(this,$i,$j)'";
726 if ($cellvalue) {
727 echo " checked";
730 echo " />";
731 } else if ($celltype == '3') {
732 echo "<input type='text' class='intext' onchange='textChange(this,$i,$j)'";
733 echo " value='$cellvalue'";
734 echo " size='12' />";
735 } else if ($celltype == '4') {
736 echo "<textarea rows='3' cols='25' wrap='virtual' class='intext' " .
737 "onchange='longChange(this,$i,$j)'>";
738 echo $cellvalue;
739 echo "</textarea>";
742 echo "</span>"; // new //
744 echo "</td>\n";
747 echo " </tr>\n";
750 </table>
753 <input type='submit' name='bn_save_form' value='Save Form' />
754 <?php if (!$formid) { ?>
755 &nbsp;
756 <input type='submit' name='bn_save_template' value='Save as Template:' />
757 &nbsp;
758 <input type='text' name='form_new_template_name' value='<?php echo $template_name ?>' />
759 &nbsp;
760 <input type='submit' name='bn_delete_template' value='Delete Template' />
761 <?php } ?>
762 &nbsp;
763 <input type='button' value='Cancel' onclick="doCancel()" />
764 </p>
766 </center>
767 </form>
768 <script language='JavaScript'>
769 <?php
770 if ($alertmsg) {
771 echo " alert('$alertmsg');\n";
774 </script>
775 </body>
776 </html>