added option to skip authorizations of patient notes
[openemr.git] / interface / super / edit_layout.php
blob01d4e5146c17fb0ea85e0f4da7064a9d6e4b25b8
1 <?php
2 // Copyright (C) 2007 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");
12 $layouts = array(
13 'DEM' => xl('Demographics'),
14 'HIS' => xl('History'),
15 'REF' => xl('Referrals'),
17 if ($GLOBALS['ippf_specific']) {
18 $layouts['GCA'] = xl('Abortion Issues');
19 $layouts['CON'] = xl('Contraception Issues');
20 $layouts['SRH'] = xl('SRH Visit Form');
23 // array of the data_types of the fields
24 $datatypes = array("1"=>"list box",
25 "2"=>"textbox",
26 "3"=>"textarea",
27 "4"=>"text-date",
28 "10"=>"Providers",
29 "11"=>"Providers NPI",
30 "12"=>"Pharmacies",
31 "13"=>"Squads",
32 "14"=>"Organizations",
33 "15"=>"Billing codes",
34 "21"=>"checkbox list",
35 "22"=>"textbox list",
36 "23"=>"Exam results",
37 "24"=>"Patient allergies",
38 "25"=>"checkbox w/ text"
41 // Check authorization.
42 $thisauth = acl_check('admin', 'super');
43 if (!$thisauth) die("Not authorized.");
45 // the layout ID defaults to DEM (demographics)
46 $layout_id = empty($_REQUEST['layout_id']) ? 'DEM' : $_REQUEST['layout_id'];
48 // Handle the Form actions
50 if ($_POST['formaction']=="save" && $layout_id) {
51 // If we are saving, then save.
52 $fld = $_POST['fld'];
53 for ($lino = 1; isset($fld[$lino]['id']); ++$lino) {
54 $iter = $fld[$lino];
55 $field_id = trim($iter['id']);
56 if ($field_id) {
57 sqlStatement("UPDATE layout_options SET " .
58 "title = '" . trim($iter['title']) . "', " .
59 "group_name = '" . trim($iter['group']) . "', " .
60 "seq = '" . trim($iter['seq']) . "', " .
61 "uor = '" . trim($iter['uor']) . "', " .
62 "fld_length = '" . trim($iter['length']) . "', " .
63 "titlecols = '" . trim($iter['titlecols']) . "', " .
64 "datacols = '" . trim($iter['datacols']) . "', " .
65 "data_type= '" . trim($iter['data_type']) . "', " .
66 "list_id= '" . trim($iter['list_id']) . "', " .
67 "default_value = '" . trim($iter['default']) . "', " .
68 "description = '" . trim($iter['desc']) . "' " .
69 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
74 else if ($_POST['formaction']=="addfield" && $layout_id) {
75 // Add a new field to a specific group
76 sqlStatement("INSERT INTO layout_options (".
77 "form_id, field_id, title, group_name, seq, uor, fld_length ".
78 ",titlecols, datacols, data_type, default_value, description ".
79 ", max_length".
80 ") VALUES (".
81 "'".trim($_POST['layout_id'])."'".
82 ",'".trim($_POST['newid'])."'".
83 ",'".trim($_POST['newtitle'])."'".
84 ",'".trim($_POST['newfieldgroupid'])."'".
85 ",'".trim($_POST['newseq'])."'".
86 ",'".trim($_POST['newuor'])."'".
87 ",'".trim($_POST['newlength'])."'".
88 ",'".trim($_POST['newtitlecols'])."'".
89 ",'".trim($_POST['newdatacols'])."'".
90 ",'".trim($_POST['newdatatype'])."'".
91 ",'".trim($_POST['newdefault'])."'".
92 ",'".trim($_POST['newdesc'])."'".
93 ",'".trim($_POST['newlength'])."'". // maxlength = length
94 ")");
98 else if ($_POST['formaction']=="deletefield" && $layout_id) {
99 // Delete a field from a specific group
100 sqlStatement("DELETE FROM layout_options WHERE ".
101 " form_id = '".$_POST['layout_id']."' ".
102 " AND field_id = '".$_POST['deletefieldid']."'".
103 " AND group_name = '".$_POST['deletefieldgroup']."'"
107 else if ($_POST['formaction']=="addgroup" && $layout_id) {
108 // all group names are prefixed with a number indicating their display order
109 // this new group is prefixed with the net highest number given the
110 // layout_id
111 $results = sqlStatement("select distinct(group_name) as gname ".
112 " from layout_options where ".
113 " form_id = '".$_POST['layout_id']."'"
115 $maxnum = 0;
116 while ($result = sqlFetchArray($results)) {
117 // split the number from the group name
118 $parts = preg_split("/([A-Z]|[a-z])/", $result['gname']);
119 if ($parts[0] >= $maxnum) { $maxnum = $parts[0] + 1; }
122 // add a new group to the layout, with a default field
123 sqlStatement("INSERT INTO layout_options (".
124 "form_id, field_id, title, group_name".
125 ") VALUES (".
126 "'".trim($_POST['layout_id'])."'".
127 ",'field1'".
128 ",'New Field'".
129 ",'".trim($maxnum . $_POST['newgroupname'])."'".
130 ")");
133 else if ($_POST['formaction']=="deletegroup" && $layout_id) {
134 // Delete an entire group from the form
135 sqlStatement("DELETE FROM layout_options WHERE ".
136 " form_id = '".$_POST['layout_id']."' ".
137 " AND group_name = '".$_POST['deletegroupname']."'"
141 else if ($_POST['formaction']=="movegroup" && $layout_id) {
143 // split the numeric order out of the group name
144 $parts = preg_split("/(^\d)/", $_POST['movegroupname'], -1, PREG_SPLIT_DELIM_CAPTURE);
145 $currpos = $newpos = $parts[1];
146 $groupname = $parts[2];
148 // inc/dec the order number
149 if ($_POST['movedirection'] == 'up') {
150 $newpos--;
151 if ($newpos < 0) { $newpos = 0; }
153 else if ($_POST['movedirection'] == 'down') {
154 $newpos++;
157 // if we can't determine a position, then assign it a zero
158 if ($newpos == "") $newpos = "0";
160 // update the database rows
161 sqlStatement("UPDATE layout_options SET ".
162 "group_name='".$newpos.$groupname."'".
163 " WHERE ".
164 "group_name='".$currpos.$groupname."'"
168 else if ($_POST['formaction']=="renamegroup" && $layout_id) {
170 // split the numeric order out of the group name
171 $parts = preg_split("/(^\d)/", $_POST['renameoldgroupname'], -1, PREG_SPLIT_DELIM_CAPTURE);
172 $currpos = $parts[1];
174 // if we can't determine a position, then assign it a zero
175 if ($currpos == "") $currpos = "0";
177 // update the database rows
178 sqlStatement("UPDATE layout_options SET ".
179 "group_name='".$currpos.$_POST['renamegroupname']."'".
180 " WHERE ".
181 "group_name='".$_POST['renameoldgroupname']."'"
186 // Get the selected form's elements.
187 if ($layout_id) {
188 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
189 "form_id = '$layout_id' ORDER BY group_name, seq");
193 // global counter for field numbers
194 $fld_line_no = 0;
196 // Write one option line to the form.
198 function writeFieldLine($linedata) {
199 global $fld_line_no;
200 ++$fld_line_no;
201 $checked = $linedata['default_value'] ? " checked" : "";
203 //echo " <tr bgcolor='$bgcolor'>\n";
204 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no % 2 ? 'even' : 'odd')."'>\n";
206 echo " <td align='center' class='optcell' nowrap>";
207 // tuck the group_name INPUT in here
208 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
209 htmlspecialchars($linedata['group_name'], ENT_QUOTES) . "' class='optin' />";
210 echo "<input type='button' class='deletefield' ".
211 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
212 "id='".$linedata['group_name']."~".$linedata['field_id']."' value='X' title='Delete field'>";
213 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
214 htmlspecialchars($linedata['seq'], ENT_QUOTES) . "' size='2' maxlength='3' class='optin' />";
215 echo "</td>\n";
217 echo " <td align='left' class='optcell'>";
218 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
219 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin noselect' />";
221 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
222 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
223 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
225 echo "</td>\n";
227 echo " <td align='center' class='optcell'>";
228 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
229 htmlspecialchars($linedata['title'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
230 echo "</td>\n";
232 echo " <td align='center' class='optcell'>";
233 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
234 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
235 echo "<option value='$key'";
236 if ($key == $linedata['uor']) echo " selected";
237 echo ">$value</option>\n";
239 echo "</select>";
240 echo "</td>\n";
242 echo " <td align='center' class='optcell'>";
243 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]'>";
244 echo "<option value=''></option>";
245 GLOBAL $datatypes;
246 foreach ($datatypes as $key=>$value) {
247 if ($linedata['data_type'] == $key)
248 echo "<option value='$key' selected>$value</option>";
249 else
250 echo "<option value='$key'>$value</option>";
252 echo "</select>";
253 echo " </td>";
255 echo " <td align='center' class='optcell'>";
256 if ($linedata['data_type'] == 2 || $linedata['data_type'] == 3)
258 // textbox or textarea
259 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
260 echo "<input type='text' name='fld[$fld_line_no][length]' value='" .
261 htmlspecialchars($linedata['fld_length'], ENT_QUOTES) . "' size='1' maxlength='10' class='optin' />";
263 else if ($linedata['data_type'] == 4) {
264 // text-date
265 echo "<input type='hidden' name='fld[$fld_line_no][length]' value=''>";
266 echo "<span>(date)</span>";
268 else if ($linedata['data_type'] == 1 || $linedata['data_type'] == 21 ||
269 $linedata['data_type'] == 22 || $linedata['data_type'] == 23 ||
270 $linedata['data_type'] == 25)
272 // select, checkbox, textbox list, or checkbox list w/ text
273 echo "<input type='hidden' name='fld[$fld_line_no][length]' value=''>";
274 echo "<input type='text' name='fld[$fld_line_no][list_id]' value='" .
275 htmlspecialchars($linedata['list_id'], ENT_QUOTES) . "'".
276 "size='6' maxlength='30' class='optin listid' style='cursor: pointer'".
277 "title='Choose list' />";
279 else {
280 // all other data_types
281 echo "<input type='hidden' name='fld[$fld_line_no][length]' value=''>";
282 if ($linedata['list_id'] != "") {
283 echo "<span title='".$linedata['list_id']."'>(list)</span>";
286 echo "</td>\n";
288 echo " <td align='center' class='optcell'>";
289 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
290 htmlspecialchars($linedata['titlecols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' />";
291 echo "</td>\n";
293 echo " <td align='center' class='optcell'>";
294 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
295 htmlspecialchars($linedata['datacols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' />";
296 echo "</td>\n";
298 echo " <td align='center' class='optcell'>";
299 if ($linedata['data_type'] == 2) {
300 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
301 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
302 } else {
303 echo "&nbsp;";
305 echo "</td>\n";
307 echo " <td align='center' class='optcell'>";
308 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
309 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
310 echo "</td>\n";
312 echo " </tr>\n";
315 <html>
317 <head>
318 <?php html_header_show();?>
320 <!-- supporting javascript code -->
321 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
323 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
324 <title><?php xl('Layout Editor','e'); ?></title>
326 <style>
327 tr.head { font-size:10pt; background-color:#cccccc; }
328 tr.detail { font-size:10pt; }
329 td { font-size:10pt; }
330 input { font-size:10pt; }
331 a, a:visited, a:hover { color:#0000cc; }
332 .optcell { }
333 .optin { background: transparent; }
334 .group {
335 margin: 10px;
336 width: 100%;
338 .group table {
339 border-collapse: collapse;
340 width: 100%;
342 .odd td {
343 background-color: #ddddff;
344 padding: 3px 0px 3px 0px;
346 .even td {
347 background-color: #ffdddd;
348 padding: 3px 0px 3px 0px;
350 .moveup {
351 cursor: pointer;
353 .movedown {
354 cursor: pointer;
356 .help {
357 cursor: help;
359 .layouts_title {
360 font-size: 110%;
362 </style>
365 </head>
367 <body class="body_top">
370 <form method='post' name='theform' id='theform' action='edit_layout.php'>
371 <input type="hidden" name="formaction" id="formaction" value="">
372 <!-- elements used to identify a field to delete -->
373 <input type="hidden" name="deletefieldid" id="deletefieldid" value="">
374 <input type="hidden" name="deletefieldgroup" id="deletefieldgroup" value="">
375 <!-- elements used to identify a group to delete -->
376 <input type="hidden" name="deletegroupname" id="deletegroupname" value="">
377 <!-- elements used to change the group order -->
378 <input type="hidden" name="movegroupname" id="movegroupname" value="">
379 <input type="hidden" name="movedirection" id="movedirection" value="">
381 <p><b>Edit layout:</b>&nbsp;
382 <select name='layout_id' id='layout_id'>
383 <?php
384 foreach ($layouts as $key => $value) {
385 echo "<option value='$key'";
386 if ($key == $layout_id) echo " selected";
387 echo ">$value</option>\n";
390 </select></p>
392 <div>
393 <input type='button' class='addgroup' id='addgroup' value='Add Group'/>
394 </div>
396 <?php
397 $prevgroup = "!@#asdf1234"; // an unlikely group name
398 $firstgroup = true; // flag indicates it's the first group to be displayed
399 while ($row = sqlFetchArray($res)) {
402 <?php
403 if ($row['group_name'] != $prevgroup) {
404 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
405 echo "<div id='".$row['group_name']."' class='group'>";
406 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
407 echo preg_replace("/^\d+/", "", $row['group_name']);
408 echo "&nbsp; &nbsp; ";
409 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='Add Field'/>";
410 echo "&nbsp; &nbsp; ";
411 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='Rename Group'/>";
412 echo "&nbsp; &nbsp; ";
413 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='Delete Group'/>";
414 echo "&nbsp; &nbsp; ";
415 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='Move Up'/>";
416 echo "&nbsp; &nbsp; ";
417 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='Move Down'/>";
418 echo "</div>";
419 $firstgroup = false;
422 <table>
423 <thead>
424 <tr class='head'>
425 <th><?php xl('Order','e'); ?></th>
426 <th><?php xl('ID','e'); ?> <span class="help" title="A unique value to identify this field, not visible to the user">(?)</span></th>
427 <th><?php xl('Label','e'); ?> <span class="help" title="The label that appears to the user on the form">(?)</span></th>
428 <th><?php xl('UOR','e'); ?></th>
429 <th><?php xl('Data Type','e'); ?></th>
430 <th><?php xl('Size/List','e'); ?></th>
431 <th><?php xl('Label Cols','e'); ?></th>
432 <th><?php xl('Data Cols','e'); ?></th>
433 <th><?php xl('Default Value','e'); ?></th>
434 <th><?php xl('Description','e'); ?></th>
435 </tr>
436 </thead>
437 <tbody>
439 <?php
440 } // end if-group_name
442 writeFieldLine($row);
443 $prevgroup = $row['group_name'];
445 } // end while loop
448 </tbody>
449 </table></div>
451 <input type='button' name='save' id='save' value='<?php xl('Save Changes','e'); ?>' />
453 </form>
455 <!-- template DIV that appears when user chooses to rename an existing group -->
456 <div id="renamegroupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
457 <input type="hidden" name="renameoldgroupname" id="renameoldgroupname" value="">
458 Group Name: <input type="textbox" size="20" maxlength="30" name="renamegroupname" id="renamegroupname">
459 <br>
460 <input type="button" class="saverenamegroup" value="Rename group">
461 <input type="button" class="cancelrenamegroup" value="Cancel">
462 </div>
464 <!-- template DIV that appears when user chooses to add a new group -->
465 <div id="groupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
466 Group Name: <input type="textbox" size="20" maxlength="30" name="newgroupname" id="newgroupname">
467 <br>
468 <input type="button" class="savenewgroup" value="Save new group">
469 <input type="button" class="cancelnewgroup" value="Cancel">
470 </div>
472 <!-- template DIV that appears when user chooses to add a new field to a group -->
473 <div id="fielddetail" class="fielddetail" style="display: none; visibility: hidden">
474 <input type="hidden" name="newfieldgroupid" id="newfieldgroupid" value="">
475 <table style="border-collapse: collapse;">
476 <thead>
477 <tr class='head'>
478 <th><?php xl('Order','e'); ?></th>
479 <th><?php xl('ID','e'); ?> <span class="help" title="A unique value to identify this field, not visible to the user">(?)</span></th>
480 <th><?php xl('Label','e'); ?> <span class="help" title="The label that appears to the user on the form">(?)</span></th>
481 <th><?php xl('UOR','e'); ?></th>
482 <th><?php xl('Data Type','e'); ?></th>
483 <th><?php xl('Size/List','e'); ?></th>
484 <th><?php xl('Label Cols','e'); ?></th>
485 <th><?php xl('Data Cols','e'); ?></th>
486 <th><?php xl('Default Value','e'); ?></th>
487 <th><?php xl('Description','e'); ?></th>
488 </tr>
489 </thead>
490 <tbody>
491 <tr class='center'>
492 <td ><input type="textbox" name="newseq" id="newseq" value="" size="2" maxlength="3"> </td>
493 <td ><input type="textbox" name="newid" id="newid" value="" size="10" maxlength="20"> </td>
494 <td><input type="textbox" name="newtitle" id="newtitle" value="" size="20" maxlength="63"> </td>
495 <td>
496 <select name="newuor" id="newuor">
497 <option value="0">Unused</option>
498 <option value="1" selected>Optional</option>
499 <option value="2">Required</option>
500 </select>
501 </td>
502 <td align='center'>
503 <select name='newdatatype' id='newdatatype'>
504 <option value=''></option>
505 <?php
506 global $datatypes;
507 foreach ($datatypes as $key=>$value) {
508 echo "<option value='$key'>$value</option>";
511 </select>
512 </td>
513 <td><input type="textbox" name="newlength" id="newlength" value="" size="1" maxlength="3"> </td>
514 <td><input type="textbox" name="newtitlecols" id="newtitlecols" value="" size="3" maxlength="3"> </td>
515 <td><input type="textbox" name="newdatacols" id="newdatacols" value="" size="3" maxlength="3"> </td>
516 <td><input type="textbox" name="newdefault" id="newdefault" value="" size="20" maxlength="63"> </td>
517 <td><input type="textbox" name="newdesc" id="newdesc" value="" size="20" maxlength="63"> </td>
518 </tr>
519 <tr>
520 <td colspan="9">
521 <input type="button" class="savenewfield" value="Save new field">
522 <input type="button" class="cancelnewfield" value="Cancel">
523 </td>
524 </tr>
525 </tbody>
526 </table>
527 </div>
529 </body>
531 <script language="javascript">
533 var selectedfield;
535 // jQuery stuff to make the page a little easier to use
537 $(document).ready(function(){
538 $("#save").click(function() { SaveChanges(); });
539 $("#layout_id").change(function() { $('#theform').submit(); });
541 $(".addgroup").click(function() { AddGroup(this); });
542 $(".savenewgroup").click(function() { SaveNewGroup(this); });
543 $(".deletegroup").click(function() { DeleteGroup(this); });
544 $(".cancelnewgroup").click(function() { CancelNewGroup(this); });
546 $(".movegroup").click(function() { MoveGroup(this); });
548 $(".renamegroup").click(function() { RenameGroup(this); });
549 $(".saverenamegroup").click(function() { SaveRenameGroup(this); });
550 $(".cancelrenamegroup").click(function() { CancelRenameGroup(this); });
552 $(".addfield").click(function() { AddField(this); });
553 $(".deletefield").click(function() { DeleteField(this); });
554 $(".savenewfield").click(function() { SaveNewField(this); });
555 $(".cancelnewfield").click(function() { CancelNewField(this); });
556 $("#newtitle").blur(function() { if ($("#newid").val() == "") $("#newid").val($("#newtitle").val()); });
558 $(".listid").click(function() { ShowLists(this); });
560 // special class that skips the element
561 $(".noselect").focus(function() { $(this).blur(); });
564 // Save the changes made to the form
565 var SaveChanges = function () {
566 $("#formaction").val("save");
567 $("#theform").submit();
570 /****************************************************/
571 /************ Group functions ***********************/
572 /****************************************************/
574 // display the 'new group' DIV
575 var AddGroup = function(btnObj) {
576 // show the field details DIV
577 $('#groupdetail').css('visibility', 'visible');
578 $('#groupdetail').css('display', 'block');
579 $(btnObj).parent().append($("#groupdetail"));
580 $('#groupdetail > #newgropuname').focus();
583 // save the new group to the form
584 var SaveNewGroup = function(btnObj) {
585 // the group name field can only have letters, numbers, spaces and underscores
586 // AND it cannot start with a number
587 if ($("#newgroupname").val().match(/^\d+/)) {
588 alert("Group names cannot start with numbers.");
589 return false;
591 var validname = $("#newgroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
592 $("#newgroupname").val(validname);
594 // submit the form to add a new field to a specific group
595 $("#formaction").val("addgroup");
596 $("#theform").submit();
599 // actually delete an entire group from the database
600 var DeleteGroup = function(btnObj) {
601 var parts = $(btnObj).attr("id");
602 var groupname = parts.replace(/^\d+/, "");
603 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
604 // submit the form to add a new field to a specific group
605 $("#formaction").val("deletegroup");
606 $("#deletegroupname").val(parts);
607 $("#theform").submit();
611 // just hide the new field DIV
612 var CancelNewGroup = function(btnObj) {
613 // hide the field details DIV
614 $('#groupdetail').css('visibility', 'hidden');
615 $('#groupdetail').css('display', 'none');
616 // reset the new group values to a default
617 $('#groupdetail > #newgroupname').val("");
620 // display the 'new field' DIV
621 var MoveGroup = function(btnObj) {
622 var btnid = $(btnObj).attr("id");
623 var parts = btnid.split("~");
624 var groupid = parts[0];
625 var direction = parts[1];
627 // submit the form to change group order
628 $("#formaction").val("movegroup");
629 $("#movegroupname").val(groupid);
630 $("#movedirection").val(direction);
631 $("#theform").submit();
635 // show the rename group DIV
636 var RenameGroup = function(btnObj) {
637 $('#renamegroupdetail').css('visibility', 'visible');
638 $('#renamegroupdetail').css('display', 'block');
639 $(btnObj).parent().append($("#renamegroupdetail"));
640 $('#renameoldgroupname').val($(btnObj).attr("id"));
641 $('#renamegroupname').val($(btnObj).attr("id").replace(/^\d+/, ""));
644 // save the new group to the form
645 var SaveRenameGroup = function(btnObj) {
646 // the group name field can only have letters, numbers, spaces and underscores
647 // AND it cannot start with a number
648 if ($("#renamegroupname").val().match(/^\d+/)) {
649 alert("Group names cannot start with numbers.");
650 return false;
652 var validname = $("#renamegroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
653 $("#renamegroupname").val(validname);
655 // submit the form to add a new field to a specific group
656 $("#formaction").val("renamegroup");
657 $("#theform").submit();
660 // just hide the new field DIV
661 var CancelRenameGroup = function(btnObj) {
662 // hide the field details DIV
663 $('#renamegroupdetail').css('visibility', 'hidden');
664 $('#renamegroupdetail').css('display', 'none');
665 // reset the rename group values to a default
666 $('#renameoldgroupname').val("");
667 $('#renamegroupname').val("");
671 /****************************************************/
672 /************ Field functions ***********************/
673 /****************************************************/
675 // display the 'new field' DIV
676 var AddField = function(btnObj) {
677 // update the fieldgroup value to be the groupid
678 var btnid = $(btnObj).attr("id");
679 var parts = btnid.split("~");
680 var groupid = parts[1];
681 $('#fielddetail > #newfieldgroupid').attr('value', groupid);
683 // show the field details DIV
684 $('#fielddetail').css('visibility', 'visible');
685 $('#fielddetail').css('display', 'block');
686 $(btnObj).parent().append($("#fielddetail"));
689 var DeleteField = function(btnObj) {
690 var parts = $(btnObj).attr("id").split("~");
691 var groupname = parts[0].replace(/^\d+/, "");
692 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the field in '"+groupname+"' identified as '"+parts[1]+"'?")) {
693 // submit the form to add a new field to a specific group
694 $("#formaction").val("deletefield");
695 $("#deletefieldgroup").val(parts[0]);
696 $("#deletefieldid").val(parts[1]);
697 $("#theform").submit();
701 // save the new field to the form
702 var SaveNewField = function(btnObj) {
703 // check the new field values for correct formatting
705 // seq must be numeric and less than 999
706 if (! IsNumeric($("#newseq").val(), 0, 999)) {
707 alert("Order must be a number between 1 and 999");
708 return false;
710 // length must be numeric and less than 999
711 if (! IsNumeric($("#newlength").val(), 0, 999)) {
712 alert("Size must be a number between 1 and 999");
713 return false;
715 // titlecols must be numeric and less than 100
716 if (! IsNumeric($("#newtitlecols").val(), 0, 999)) {
717 alert("TitleCols must be a number between 1 and 999");
718 return false;
720 // datacols must be numeric and less than 100
721 if (! IsNumeric($("#newdatacols").val(), 0, 999)) {
722 alert("DataCols must be a number between 1 and 999");
723 return false;
725 // some fields cannot be blank
726 if ($("#newtitle").val() == "") {
727 alert("Label cannot be blank");
728 return false;
730 // the id field can only have letters, numbers and underscores
731 var validid = $("#newid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
732 $("#newid").val(validid);
734 // submit the form to add a new field to a specific group
735 $("#formaction").val("addfield");
736 $("#theform").submit();
739 // just hide the new field DIV
740 var CancelNewField = function(btnObj) {
741 // hide the field details DIV
742 $('#fielddetail').css('visibility', 'hidden');
743 $('#fielddetail').css('display', 'none');
744 // reset the new field values to a default
745 ResetNewFieldValues();
748 // show the popup choice of lists
749 var ShowLists = function(btnObj) {
750 window.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
751 selectedfield = btnObj;
756 function SetList(listid) {
757 $(selectedfield).val(listid);
760 // set the new-field values to a default state
761 function ResetNewFieldValues () {
762 $("#newseq").val("");
763 $("#newid").val("");
764 $("#newtitle").val("");
765 $("#newuor").val(1);
766 $("#newlength").val("");
767 $("#newdatatype").val("");
768 $("#newlistid").val("");
769 $("#newtitlecols").val("");
770 $("#newdatacols").val("");
771 $("#newdefault").val("");
772 $("#newdesc").val("");
775 // is value an integer and between min and max
776 function IsNumeric(value, min, max) {
777 if (! IsN(value) ||
778 parseInt(value) < min ||
779 parseInt(value) > max)
780 return false;
782 return true;
785 /****************************************************/
786 /****************************************************/
787 /****************************************************/
789 // tell if num is an Integer
790 function IsN(num) { return !/\D/.test(num); }
791 </script>
793 </html>