Adding backup list feature and multiselect feature to options.inc.php.
[openemr.git] / interface / super / edit_layout.php
blobb94bf5b6f22dc1e779d8419bfcedd8b7b8e8b1f9
1 <?php
2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/log.inc");
12 require_once("$srcdir/formdata.inc.php");
14 $layouts = array(
15 'DEM' => xl('Demographics'),
16 'HIS' => xl('History'),
17 'REF' => xl('Referrals'),
18 'FACUSR' => xl('Facility Specific User Information')
20 if ($GLOBALS['ippf_specific']) {
21 $layouts['GCA'] = xl('Abortion Issues');
22 $layouts['CON'] = xl('Contraception Issues');
23 // $layouts['SRH'] = xl('SRH Visit Form');
26 // Include Layout Based Encounter Forms.
27 $lres = sqlStatement("SELECT * FROM list_options " .
28 "WHERE list_id = 'lbfnames' ORDER BY seq, title");
29 while ($lrow = sqlFetchArray($lres)) {
30 $layouts[$lrow['option_id']] = $lrow['title'];
33 // array of the data_types of the fields
34 $datatypes = array(
35 "1" => xl("List box"),
36 "2" => xl("Textbox"),
37 "3" => xl("Textarea"),
38 "4" => xl("Text-date"),
39 "10" => xl("Providers"),
40 "11" => xl("Providers NPI"),
41 "12" => xl("Pharmacies"),
42 "13" => xl("Squads"),
43 "14" => xl("Organizations"),
44 "15" => xl("Billing codes"),
45 "21" => xl("Checkbox list"),
46 "22" => xl("Textbox list"),
47 "23" => xl("Exam results"),
48 "24" => xl("Patient allergies"),
49 "25" => xl("Checkbox w/text"),
50 "26" => xl("List box w/add"),
51 "27" => xl("Radio buttons"),
52 "28" => xl("Lifestyle status"),
53 "31" => xl("Static Text"),
54 "32" => xl("Smoking Status"),
55 "33" => xl("Race and Ethnicity"),
56 "34" => xl("NationNotes"),
57 "35" => xl("Facilities"),
58 "36" => xl("Multiple Select List")
61 function nextGroupOrder($order) {
62 if ($order == '9') $order = 'A';
63 else if ($order == 'Z') $order = 'a';
64 else $order = chr(ord($order) + 1);
65 return $order;
68 // Check authorization.
69 $thisauth = acl_check('admin', 'super');
70 if (!$thisauth) die(xl('Not authorized'));
72 // The layout ID identifies the layout to be edited.
73 $layout_id = empty($_REQUEST['layout_id']) ? '' : $_REQUEST['layout_id'];
75 // Handle the Form actions
77 if ($_POST['formaction'] == "save" && $layout_id) {
78 // If we are saving, then save.
79 $fld = $_POST['fld'];
80 for ($lino = 1; isset($fld[$lino]['id']); ++$lino) {
81 $iter = $fld[$lino];
82 $field_id = formTrim($iter['id']);
83 $data_type = formTrim($iter['data_type']);
84 $listval = $data_type == 34 ? formTrim($iter['contextName']) : formTrim($iter['list_id']);
85 if ($field_id) {
86 sqlStatement("UPDATE layout_options SET " .
87 "title = '" . formTrim($iter['title']) . "', " .
88 "group_name = '" . formTrim($iter['group']) . "', " .
89 "seq = '" . formTrim($iter['seq']) . "', " .
90 "uor = '" . formTrim($iter['uor']) . "', " .
91 "fld_length = '" . formTrim($iter['lengthWidth']) . "', " .
92 "fld_rows = '" . formTrim($iter['lengthHeight']) . "', " .
93 "max_length = '" . formTrim($iter['maxSize']) . "', " .
94 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
95 "datacols = '" . formTrim($iter['datacols']) . "', " .
96 "data_type= '$data_type', " .
97 "list_id= '" . $listval . "', " .
98 "list_backup_id= '" . formTrim($iter['list_backup_id']) . "', " .
99 "edit_options = '" . formTrim($iter['edit_options']) . "', " .
100 "default_value = '" . formTrim($iter['default']) . "', " .
101 "description = '" . formTrim($iter['desc']) . "' " .
102 "WHERE form_id = '$layout_id' AND field_id = '$field_id'");
107 else if ($_POST['formaction'] == "addfield" && $layout_id) {
108 // Add a new field to a specific group
109 $data_type = formTrim($_POST['newdatatype']);
110 $max_length = $data_type == 3 ? 3 : 255;
111 $listval = $data_type == 34 ? formTrim($_POST['contextName']) : formTrim($_POST['newlistid']);
112 sqlStatement("INSERT INTO layout_options (" .
113 " form_id, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
114 ", titlecols, datacols, data_type, edit_options, default_value, description" .
115 ", max_length, list_id, list_backup_id " .
116 ") VALUES ( " .
117 "'" . formTrim($_POST['layout_id'] ) . "'" .
118 ",'" . formTrim($_POST['newid'] ) . "'" .
119 ",'" . formTrim($_POST['newtitle'] ) . "'" .
120 ",'" . formTrim($_POST['newfieldgroupid']) . "'" .
121 ",'" . formTrim($_POST['newseq'] ) . "'" .
122 ",'" . formTrim($_POST['newuor'] ) . "'" .
123 ",'" . formTrim($_POST['newlengthWidth'] ) . "'" .
124 ",'" . formTrim($_POST['newlengthHeight'] ) . "'" .
125 ",'" . formTrim($_POST['newtitlecols'] ) . "'" .
126 ",'" . formTrim($_POST['newdatacols'] ) . "'" .
127 ",'$data_type'" .
128 ",'" . formTrim($_POST['newedit_options']) . "'" .
129 ",'" . formTrim($_POST['newdefault'] ) . "'" .
130 ",'" . formTrim($_POST['newdesc'] ) . "'" .
131 ",'" . formTrim($_POST['newmaxSize']) . "'" .
132 ",'" . $listval . "'" .
133 ",'" . formTrim($_POST['newbackuplistid']) . "'" .
134 " )");
136 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
137 // Add the field to the table too (this is critical)
138 if ($layout_id == "DEM") { $tablename = "patient_data"; }
139 else if ($layout_id == "HIS") { $tablename = "history_data"; }
140 else if ($layout_id == "REF") { $tablename = "transactions"; }
141 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
142 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
143 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
144 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
145 "`" . formTrim($_POST['newid']) . "`" .
146 " TEXT NOT NULL");
147 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
148 $tablename . " ADD " . formTrim($_POST['newid']));
152 else if ($_POST['formaction'] == "movefields" && $layout_id) {
153 // Move field(s) to a new group in the layout
154 $sqlstmt = "UPDATE layout_options SET ".
155 " group_name='". $_POST['targetgroup']."' ".
156 " WHERE ".
157 " form_id = '".$_POST['layout_id']."' ".
158 " AND field_id IN (";
159 $comma = "";
160 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
161 $sqlstmt .= $comma."'".$onefield."'";
162 $comma = ", ";
164 $sqlstmt .= ")";
165 //echo $sqlstmt;
166 sqlStatement($sqlstmt);
169 else if ($_POST['formaction'] == "deletefields" && $layout_id) {
170 // Delete a field from a specific group
171 $sqlstmt = "DELETE FROM layout_options WHERE ".
172 " form_id = '".$_POST['layout_id']."' ".
173 " AND field_id IN (";
174 $comma = "";
175 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
176 $sqlstmt .= $comma."'".$onefield."'";
177 $comma = ", ";
179 $sqlstmt .= ")";
180 sqlStatement($sqlstmt);
182 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
183 // drop the field from the table too (this is critical)
184 if ($layout_id == "DEM") { $tablename = "patient_data"; }
185 else if ($layout_id == "HIS") { $tablename = "history_data"; }
186 else if ($layout_id == "REF") { $tablename = "transactions"; }
187 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
188 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
189 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
190 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
191 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$onefield."`");
192 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".$onefield);
197 else if ($_POST['formaction'] == "addgroup" && $layout_id) {
198 // all group names are prefixed with a number indicating their display order
199 // this new group is prefixed with the net highest number given the
200 // layout_id
201 $results = sqlStatement("select distinct(group_name) as gname ".
202 " from layout_options where ".
203 " form_id = '".$_POST['layout_id']."'"
205 $maxnum = '1';
206 while ($result = sqlFetchArray($results)) {
207 $tmp = substr($result['gname'], 0, 1);
208 if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
211 $data_type = formTrim($_POST['gnewdatatype']);
212 $max_length = $data_type == 3 ? 3 : 255;
213 $listval = $data_type == 34 ? formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
214 // add a new group to the layout, with the defined field
215 sqlStatement("INSERT INTO layout_options (" .
216 " form_id, field_id, title, group_name, seq, uor, fld_length, fld_rows" .
217 ", titlecols, datacols, data_type, edit_options, default_value, description" .
218 ", max_length, list_id, list_backup_id " .
219 ") VALUES ( " .
220 "'" . formTrim($_POST['layout_id'] ) . "'" .
221 ",'" . formTrim($_POST['gnewid'] ) . "'" .
222 ",'" . formTrim($_POST['gnewtitle'] ) . "'" .
223 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
224 ",'" . formTrim($_POST['gnewseq'] ) . "'" .
225 ",'" . formTrim($_POST['gnewuor'] ) . "'" .
226 ",'" . formTrim($_POST['gnewlengthWidth'] ) . "'" .
227 ",'" . formTrim($_POST['gnewlengthHeight'] ) . "'" .
228 ",'" . formTrim($_POST['gnewtitlecols'] ) . "'" .
229 ",'" . formTrim($_POST['gnewdatacols'] ) . "'" .
230 ",'$data_type'" .
231 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
232 ",'" . formTrim($_POST['gnewdefault'] ) . "'" .
233 ",'" . formTrim($_POST['gnewdesc'] ) . "'" .
234 ",'" . formTrim($_POST['gnewmaxSize']) . "'" .
235 ",'" . $listval . "'" .
236 ",'" . formTrim($_POST['gnewbackuplistid'] ) . "'" .
237 " )");
239 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
240 // Add the field to the table too (this is critical)
241 if ($layout_id == "DEM") { $tablename = "patient_data"; }
242 else if ($layout_id == "HIS") { $tablename = "history_data"; }
243 else if ($layout_id == "REF") { $tablename = "transactions"; }
244 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
245 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
246 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
247 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
248 "`" . formTrim($_POST['gnewid']) . "`" .
249 " TEXT NOT NULL");
250 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
251 $tablename . " ADD " . formTrim($_POST['gnewid']));
255 else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
256 // drop the fields from the related table (this is critical)
257 if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
258 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
259 " form_id = '".$_POST['layout_id']."' ".
260 " AND group_name = '".$_POST['deletegroupname']."'"
262 while ($row = sqlFetchArray($res)) {
263 // drop the field from the table too (this is critical)
264 if ($layout_id == "DEM") { $tablename = "patient_data"; }
265 else if ($layout_id == "HIS") { $tablename = "history_data"; }
266 else if ($layout_id == "REF") { $tablename = "transactions"; }
267 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
268 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
269 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
270 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$row['field_id']."`");
271 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".trim($row['field_id']));
275 // Delete an entire group from the form
276 sqlStatement("DELETE FROM layout_options WHERE ".
277 " form_id = '".$_POST['layout_id']."' ".
278 " AND group_name = '".$_POST['deletegroupname']."'"
282 else if ($_POST['formaction'] == "movegroup" && $layout_id) {
283 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
284 "FROM layout_options WHERE form_id = '$layout_id' " .
285 "ORDER BY gname");
286 $garray = array();
287 $i = 0;
288 while ($result = sqlFetchArray($results)) {
289 if ($result['gname'] == $_POST['movegroupname']) {
290 if ($_POST['movedirection'] == 'up') { // moving up
291 if ($i > 0) {
292 $garray[$i] = $garray[$i - 1];
293 $garray[$i - 1] = $result['gname'];
294 $i++;
296 else {
297 $garray[$i++] = $result['gname'];
300 else { // moving down
301 $garray[$i++] = '';
302 $garray[$i++] = $result['gname'];
305 else if ($i > 1 && $garray[$i - 2] == '') {
306 $garray[$i - 2] = $result['gname'];
308 else {
309 $garray[$i++] = $result['gname'];
312 $nextord = '1';
313 foreach ($garray as $value) {
314 if ($value === '') continue;
315 $newname = $nextord . substr($value, 1);
316 sqlStatement("UPDATE layout_options SET " .
317 "group_name = '$newname' WHERE " .
318 "form_id = '$layout_id' AND " .
319 "group_name = '$value'");
320 $nextord = nextGroupOrder($nextord);
324 else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
325 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
326 // update the database rows
327 sqlStatement("UPDATE layout_options SET " .
328 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
329 "WHERE form_id = '$layout_id' AND ".
330 "group_name = '" . $_POST['renameoldgroupname'] . "'");
333 // Get the selected form's elements.
334 if ($layout_id) {
335 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
336 "form_id = '$layout_id' ORDER BY group_name, seq");
339 // global counter for field numbers
340 $fld_line_no = 0;
342 // Write one option line to the form.
344 function writeFieldLine($linedata) {
345 global $fld_line_no;
346 ++$fld_line_no;
347 $checked = $linedata['default_value'] ? " checked" : "";
349 //echo " <tr bgcolor='$bgcolor'>\n";
350 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no % 2 ? 'even' : 'odd')."'>\n";
352 echo " <td class='optcell' nowrap>";
353 // tuck the group_name INPUT in here
354 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
355 htmlspecialchars($linedata['group_name'], ENT_QUOTES) . "' class='optin' />";
357 echo "<input type='checkbox' class='selectfield' ".
358 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
359 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
360 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES))."'>";
362 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
363 htmlspecialchars($linedata['seq'], ENT_QUOTES) . "' size='2' maxlength='3' class='optin' />";
364 echo "</td>\n";
366 echo " <td align='left' class='optcell'>";
367 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
368 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' size='15' maxlength='63' class='optin noselect' />";
370 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
371 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
372 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
374 echo "</td>\n";
376 echo " <td align='center' class='optcell'>";
377 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
378 htmlspecialchars($linedata['title'], ENT_QUOTES) . "' size='15' maxlength='63' class='optin' />";
379 echo "</td>\n";
381 // if not english and set to translate layout labels, then show the translation
382 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
383 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES) . "</td>\n";
386 echo " <td align='center' class='optcell'>";
387 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
388 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
389 echo "<option value='$key'";
390 if ($key == $linedata['uor']) echo " selected";
391 echo ">$value</option>\n";
393 echo "</select>";
394 echo "</td>\n";
396 echo " <td align='center' class='optcell'>";
397 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
398 echo "<option value=''></option>";
399 GLOBAL $datatypes;
400 foreach ($datatypes as $key=>$value) {
401 if ($linedata['data_type'] == $key)
402 echo "<option value='$key' selected>$value</option>";
403 else
404 echo "<option value='$key'>$value</option>";
406 echo "</select>";
407 echo " </td>";
409 echo " <td align='center' class='optcell'>";
410 if ($linedata['data_type'] == 2 || $linedata['data_type'] == 3 ||
411 $linedata['data_type'] == 21 || $linedata['data_type'] == 22 ||
412 $linedata['data_type'] == 23 || $linedata['data_type'] == 25 ||
413 $linedata['data_type'] == 27 || $linedata['data_type'] == 28 ||
414 $linedata['data_type'] == 32)
416 // Show the width field
417 echo "<input type='text' name='fld[$fld_line_no][lengthWidth]' value='" .
418 htmlspecialchars($linedata['fld_length'], ENT_QUOTES) .
419 "' size='1' maxlength='10' class='optin' title='" . xla('Width') . "' />";
420 if ($linedata['data_type'] == 3) {
421 // Show the height field
422 echo "<input type='text' name='fld[$fld_line_no][lengthHeight]' value='" .
423 htmlspecialchars($linedata['fld_rows'], ENT_QUOTES) .
424 "' size='1' maxlength='10' class='optin' title='" . xla('Height') . "' />";
426 else {
427 // Hide the height field
428 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
431 else {
432 // all other data_types (hide both the width and height fields
433 echo "<input type='hidden' name='fld[$fld_line_no][lengthWidth]' value=''>";
434 echo "<input type='hidden' name='fld[$fld_line_no][lengthHeight]' value=''>";
436 echo "</td>\n";
438 echo " <td align='center' class='optcell'>";
439 echo "<input type='text' name='fld[$fld_line_no][maxSize]' value='" .
440 htmlspecialchars($linedata['max_length'], ENT_QUOTES) .
441 "' size='1' maxlength='10' class='optin' title='" . xla('Maximum Size (entering 0 will allow any size)') . "' />";
442 echo "</td>\n";
444 echo " <td align='center' class='optcell'>";
445 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 21 ||
446 $linedata['data_type'] == 22 || $linedata['data_type'] == 23 ||
447 $linedata['data_type'] == 25 || $linedata['data_type'] == 26 ||
448 $linedata['data_type'] == 27 || $linedata['data_type'] == 32 ||
449 $linedata['data_type'] == 33 || $linedata['data_type'] == 34 ||
450 $linedata['data_type'] == 36)
452 $type = "";
453 $disp = "style='display:none'";
454 if($linedata['data_type'] == 34){
455 $type = "style='display:none'";
456 $disp = "";
458 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
459 htmlspecialchars($linedata['list_id'], ENT_QUOTES) . "'".$type.
460 " size='6' maxlength='30' class='optin listid' style='cursor: pointer'".
461 "title='". xl('Choose list') . "' />";
463 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
464 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
465 while($row = sqlFetchArray($res)){
466 $sel = '';
467 if ($linedata['list_id'] == $row['cl_list_item_long'])
468 $sel = 'selected';
469 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
471 echo "</select>";
473 else {
474 // all other data_types
475 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
477 echo "</td>\n";
479 //Backup List Begin
480 echo " <td align='center' class='optcell'>";
481 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 26 ||
482 $linedata['data_type'] == 33 || $linedata['data_type'] == 36)
485 echo "<input type='text' name='fld[$fld_line_no][list_backup_id]' value='" .
486 htmlspecialchars($linedata['list_backup_id'], ENT_QUOTES) .
487 "' size='3' maxlength='10' class='optin listid' style='cursor: pointer' />";
489 else {
490 echo "<input type='hidden' name='fld[$fld_line_no][list_backup_id]' value=''>";
492 echo "</td>\n";
493 //Backup List End
495 echo " <td align='center' class='optcell'>";
496 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
497 htmlspecialchars($linedata['titlecols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' />";
499 echo "</td>\n";
501 echo " <td align='center' class='optcell'>";
502 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
503 htmlspecialchars($linedata['datacols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' />";
504 echo "</td>\n";
506 echo " <td align='center' class='optcell' title='" .
507 "C = " . xla('Capitalize') .
508 ", D = " . xla('Dup Check') .
509 ", G = " . xla('Graphable') .
510 ", H = " . xla('Read-only from History') .
511 ", L = " . xla('Lab Order') .
512 ", N = " . xla('New Patient Form') .
513 ", O = " . xla('Order Processor') .
514 ", R = " . xla('Distributor') .
515 ", T = " . xla('Description is default text') .
516 ", U = " . xla('Capitalize all') .
517 ", V = " . xla('Vendor') .
518 ", 1 = " . xla('Write Once') .
519 "'>";
520 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
521 htmlspecialchars($linedata['edit_options'], ENT_QUOTES) . "' size='3' maxlength='36' class='optin' />";
522 echo "</td>\n";
524 /*****************************************************************
525 echo " <td align='center' class='optcell'>";
526 if ($linedata['data_type'] == 2) {
527 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
528 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
529 } else {
530 echo "&nbsp;";
532 echo "</td>\n";
534 echo " <td align='center' class='optcell'>";
535 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
536 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
537 echo "</td>\n";
539 // if not english and showing layout labels, then show the translation of Description
540 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
541 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
543 *****************************************************************/
545 if ($linedata['data_type'] == 31) {
546 echo " <td align='center' class='optcell'>";
547 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin'>" .
548 $linedata['description'] . "</textarea>";
549 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
550 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
551 echo "</td>\n";
553 else {
554 echo " <td align='center' class='optcell'>";
555 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
556 htmlspecialchars($linedata['description'], ENT_QUOTES) .
557 "' size='30' maxlength='63' class='optin' />";
558 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
559 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
560 echo "</td>\n";
561 // if not english and showing layout labels, then show the translation of Description
562 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
563 echo "<td align='center' class='translation'>" .
564 htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
568 echo " </tr>\n";
571 <html>
573 <head>
574 <?php html_header_show();?>
576 <!-- supporting javascript code -->
577 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
579 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
581 <title><?php xl('Layout Editor','e'); ?></title>
583 <style>
584 tr.head { font-size:10pt; background-color:#cccccc; }
585 tr.detail { font-size:10pt; }
586 td { font-size:10pt; }
587 input { font-size:10pt; }
588 a, a:visited, a:hover { color:#0000cc; }
589 .optcell { }
590 .optin { background: transparent; }
591 .group {
592 margin: 0pt 0pt 8pt 0pt;
593 padding: 0;
594 width: 100%;
596 .group table {
597 border-collapse: collapse;
598 width: 100%;
600 .odd td {
601 background-color: #ddddff;
602 padding: 3px 0px 3px 0px;
604 .even td {
605 background-color: #ffdddd;
606 padding: 3px 0px 3px 0px;
608 .help { cursor: help; }
609 .layouts_title { font-size: 110%; }
610 .translation {
611 color: green;
612 font-size:10pt;
614 .highlight * {
615 border: 2px solid blue;
616 background-color: yellow;
617 color: black;
619 </style>
621 </head>
623 <body class="body_top">
625 <form method='post' name='theform' id='theform' action='edit_layout.php'>
626 <input type="hidden" name="formaction" id="formaction" value="">
627 <!-- elements used to identify a field to delete -->
628 <input type="hidden" name="deletefieldid" id="deletefieldid" value="">
629 <input type="hidden" name="deletefieldgroup" id="deletefieldgroup" value="">
630 <!-- elements used to identify a group to delete -->
631 <input type="hidden" name="deletegroupname" id="deletegroupname" value="">
632 <!-- elements used to change the group order -->
633 <input type="hidden" name="movegroupname" id="movegroupname" value="">
634 <input type="hidden" name="movedirection" id="movedirection" value="">
635 <!-- elements used to select more than one field -->
636 <input type="hidden" name="selectedfields" id="selectedfields" value="">
637 <input type="hidden" id="targetgroup" name="targetgroup" value="">
639 <p><b><?php xl('Edit layout','e'); ?>:</b>&nbsp;
640 <select name='layout_id' id='layout_id'>
641 <option value=''>-- <?php echo xl('Select') ?> --</option>
642 <?php
643 foreach ($layouts as $key => $value) {
644 echo " <option value='$key'";
645 if ($key == $layout_id) echo " selected";
646 echo ">$value</option>\n";
649 </select></p>
651 <?php if ($layout_id) { ?>
652 <div style='margin: 0 0 8pt 0;'>
653 <input type='button' class='addgroup' id='addgroup' value=<?php xl('Add Group','e','\'','\''); ?>/>
654 </div>
655 <?php } ?>
657 <?php
658 $prevgroup = "!@#asdf1234"; // an unlikely group name
659 $firstgroup = true; // flag indicates it's the first group to be displayed
660 while ($row = sqlFetchArray($res)) {
661 if ($row['group_name'] != $prevgroup) {
662 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
663 echo "<div id='".$row['group_name']."' class='group'>";
664 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
665 // echo preg_replace("/^\d+/", "", $row['group_name']);
666 echo substr($row['group_name'], 1);
667 echo "&nbsp; ";
668 // if not english and set to translate layout labels, then show the translation of group name
669 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
670 // echo "<span class='translation'>>>&nbsp; " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
671 echo "<span class='translation'>>>&nbsp; " . xl(substr($row['group_name'], 1)) . "</span>";
672 echo "&nbsp; ";
674 echo "&nbsp; ";
675 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
676 echo "&nbsp; &nbsp; ";
677 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
678 echo "&nbsp; &nbsp; ";
679 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
680 echo "&nbsp; &nbsp; ";
681 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
682 echo "&nbsp; &nbsp; ";
683 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
684 echo "</div>";
685 $firstgroup = false;
688 <table>
689 <thead>
690 <tr class='head'>
691 <th><?php xl('Order','e'); ?></th>
692 <th><?php xl('ID','e'); ?> <span class="help" title=<?php xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?> >(?)</span></th>
693 <th><?php xl('Label','e'); ?> <span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
694 <?php // if not english and showing layout label translations, then show translation header for title
695 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
696 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'> (?)</span></th>";
697 } ?>
698 <th><?php xl('UOR','e'); ?></th>
699 <th><?php xl('Data Type','e'); ?></th>
700 <th><?php xl('Size','e'); ?></th>
701 <th><?php xl('Maximum Size','e'); ?></th>
702 <th><?php xl('List','e'); ?></th>
703 <th><?php xl('Backup List','e'); ?></th>
704 <th><?php xl('Label Cols','e'); ?></th>
705 <th><?php xl('Data Cols','e'); ?></th>
706 <th><?php xl('Options','e'); ?></th>
707 <th><?php xl('Description','e'); ?></th>
708 <?php // if not english and showing layout label translations, then show translation header for description
709 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
710 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'> (?)</span></th>";
711 } ?>
712 </tr>
713 </thead>
714 <tbody>
716 <?php
717 } // end if-group_name
719 writeFieldLine($row);
720 $prevgroup = $row['group_name'];
722 } // end while loop
725 </tbody>
726 </table></div>
728 <?php if ($layout_id) { ?>
729 <span style="font-size:90%">
730 <?php xl('With selected:', 'e');?>
731 <input type='button' name='deletefields' id='deletefields' value='<?php xl('Delete','e'); ?>' style="font-size:90%" disabled="disabled" />
732 <input type='button' name='movefields' id='movefields' value='<?php xl('Move to...','e'); ?>' style="font-size:90%" disabled="disabled" />
733 </span>
735 <input type='button' name='save' id='save' value='<?php xl('Save Changes','e'); ?>' />
736 </p>
737 <?php } ?>
739 </form>
741 <!-- template DIV that appears when user chooses to rename an existing group -->
742 <div id="renamegroupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
743 <input type="hidden" name="renameoldgroupname" id="renameoldgroupname" value="">
744 <?php xl('Group Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="renamegroupname" id="renamegroupname">
745 <br>
746 <input type="button" class="saverenamegroup" value=<?php xl('Rename Group','e','\'','\''); ?>>
747 <input type="button" class="cancelrenamegroup" value=<?php xl('Cancel','e','\'','\''); ?>>
748 </div>
750 <!-- template DIV that appears when user chooses to add a new group -->
751 <div id="groupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
752 <span class='bold'>
753 <?php xl('Group Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newgroupname" id="newgroupname">
754 <br>
755 <table style="border-collapse: collapse; margin-top: 5px;">
756 <thead>
757 <tr class='head'>
758 <th><?php xl('Order','e'); ?></th>
759 <th><?php xl('ID','e'); ?> <span class="help" title=<?php xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?> >(?)</span></th>
760 <th><?php xl('Label','e'); ?> <span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
761 <th><?php xl('UOR','e'); ?></th>
762 <th><?php xl('Data Type','e'); ?></th>
763 <th><?php xl('Size','e'); ?></th>
764 <th><?php xl('Maximum Size','e'); ?></th>
765 <th><?php xl('List','e'); ?></th>
766 <th><?php xl('Backup List','e'); ?></th>
767 <th><?php xl('Label Cols','e'); ?></th>
768 <th><?php xl('Data Cols','e'); ?></th>
769 <th><?php xl('Options','e'); ?></th>
770 <th><?php xl('Description','e'); ?></th>
771 </tr>
772 </thead>
773 <tbody>
774 <tr class='center'>
775 <td ><input type="textbox" name="gnewseq" id="gnewseq" value="" size="2" maxlength="3"> </td>
776 <td ><input type="textbox" name="gnewid" id="gnewid" value="" size="10" maxlength="20"> </td>
777 <td><input type="textbox" name="gnewtitle" id="gnewtitle" value="" size="20" maxlength="63"> </td>
778 <td>
779 <select name="gnewuor" id="gnewuor">
780 <option value="0"><?php xl('Unused','e'); ?></option>
781 <option value="1" selected><?php xl('Optional','e'); ?></option>
782 <option value="2"><?php xl('Required','e'); ?></option>
783 </select>
784 </td>
785 <td align='center'>
786 <select name='gnewdatatype' id='gnewdatatype'>
787 <option value=''></option>
788 <?php
789 global $datatypes;
790 foreach ($datatypes as $key=>$value) {
791 echo "<option value='$key'>$value</option>";
794 </select>
795 </td>
796 <td><input type="textbox" name="gnewlengthWidth" id="gnewlengthWidth" value="" size="1" maxlength="3" title="<?php echo xla('Width'); ?>">
797 <input type="textbox" name="gnewlengthHeight" id="gnewlengthHeight" value="" size="1" maxlength="3" title="<?php echo xla('Height'); ?>"></td>
798 <td><input type="textbox" name="gnewmaxSize" id="gnewmaxSize" value="" size="1" maxlength="3" title="<?php echo xla('Maximum Size (entering 0 will allow any size)'); ?>"></td>
799 <td><input type="textbox" name="gnewlistid" id="gnewlistid" value="" size="8" maxlength="31" class="listid">
800 <select name='gcontextName' id='gcontextName' style='display:none'>
801 <?php
802 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
803 while($row = sqlFetchArray($res)){
804 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
807 </select>
808 </td>
809 <td><input type="textbox" name="gnewbackuplistid" id="gnewbackuplistid" value="" size="8" maxlength="31" class="listid"></td>
810 <td><input type="textbox" name="gnewtitlecols" id="gnewtitlecols" value="" size="3" maxlength="3"> </td>
811 <td><input type="textbox" name="gnewdatacols" id="gnewdatacols" value="" size="3" maxlength="3"> </td>
812 <td><input type="textbox" name="gnewedit_options" id="gnewedit_options" value="" size="3" maxlength="36">
813 <input type="hidden" name="gnewdefault" id="gnewdefault" value="" /> </td>
814 <td><input type="textbox" name="gnewdesc" id="gnewdesc" value="" size="30" maxlength="63"> </td>
815 </tr>
816 </tbody>
817 </table>
818 <br>
819 <input type="button" class="savenewgroup" value=<?php xl('Save New Group','e','\'','\''); ?>>
820 <input type="button" class="cancelnewgroup" value=<?php xl('Cancel','e','\'','\''); ?>>
821 </span>
822 </div>
824 <!-- template DIV that appears when user chooses to add a new field to a group -->
825 <div id="fielddetail" class="fielddetail" style="display: none; visibility: hidden">
826 <input type="hidden" name="newfieldgroupid" id="newfieldgroupid" value="">
827 <table style="border-collapse: collapse;">
828 <thead>
829 <tr class='head'>
830 <th><?php xl('Order','e'); ?></th>
831 <th><?php xl('ID','e'); ?> <span class="help" title=<?php xl('A unique value to identify this field, not visible to the user','e','\'','\''); ?> >(?)</span></th>
832 <th><?php xl('Label','e'); ?> <span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
833 <th><?php xl('UOR','e'); ?></th>
834 <th><?php xl('Data Type','e'); ?></th>
835 <th><?php xl('Size','e'); ?></th>
836 <th><?php xl('Maximum Size','e'); ?></th>
837 <th><?php xl('List','e'); ?></th>
838 <th><?php xl('Backup List','e'); ?></th>
839 <th><?php xl('Label Cols','e'); ?></th>
840 <th><?php xl('Data Cols','e'); ?></th>
841 <th><?php xl('Options','e'); ?></th>
842 <th><?php xl('Description','e'); ?></th>
843 </tr>
844 </thead>
845 <tbody>
846 <tr class='center'>
847 <td ><input type="textbox" name="newseq" id="newseq" value="" size="2" maxlength="3"> </td>
848 <td ><input type="textbox" name="newid" id="newid" value="" size="10" maxlength="20"> </td>
849 <td><input type="textbox" name="newtitle" id="newtitle" value="" size="20" maxlength="63"> </td>
850 <td>
851 <select name="newuor" id="newuor">
852 <option value="0"><?php xl('Unused','e'); ?></option>
853 <option value="1" selected><?php xl('Optional','e'); ?></option>
854 <option value="2"><?php xl('Required','e'); ?></option>
855 </select>
856 </td>
857 <td align='center'>
858 <select name='newdatatype' id='newdatatype'>
859 <option value=''></option>
860 <?php
861 global $datatypes;
862 foreach ($datatypes as $key=>$value) {
863 echo " <option value='$key'>$value</option>\n";
866 </select>
867 </td>
868 <td><input type="textbox" name="newlengthWidth" id="newlengthWidth" value="" size="1" maxlength="3" title="<?php echo xla('Width'); ?>">
869 <input type="textbox" name="newlengthHeight" id="newlengthHeight" value="" size="1" maxlength="3" title="<?php echo xla('Height'); ?>"></td>
870 <td><input type="textbox" name="newmaxSize" id="newmaxSize" value="" size="1" maxlength="3" title="<?php echo xla('Maximum Size (entering 0 will allow any size)'); ?>"></td>
871 <td><input type="textbox" name="newlistid" id="newlistid" value="" size="8" maxlength="31" class="listid">
872 <select name='contextName' id='contextName' style='display:none'>
873 <?php
874 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
875 while($row = sqlFetchArray($res)){
876 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
879 </select>
880 </td>
881 <td><input type="textbox" name="newbackuplistid" id="newbackuplistid" value="" size="8" maxlength="31" class="listid"></td>
882 <td><input type="textbox" name="newtitlecols" id="newtitlecols" value="" size="3" maxlength="3"> </td>
883 <td><input type="textbox" name="newdatacols" id="newdatacols" value="" size="3" maxlength="3"> </td>
884 <td><input type="textbox" name="newedit_options" id="newedit_options" value="" size="3" maxlength="36">
885 <input type="hidden" name="newdefault" id="newdefault" value="" /> </td>
886 <td><input type="textbox" name="newdesc" id="newdesc" value="" size="30" maxlength="63"> </td>
887 </tr>
888 <tr>
889 <td colspan="9">
890 <input type="button" class="savenewfield" value=<?php xl('Save New Field','e','\'','\''); ?>>
891 <input type="button" class="cancelnewfield" value=<?php xl('Cancel','e','\'','\''); ?>>
892 </td>
893 </tr>
894 </tbody>
895 </table>
896 </div>
898 </body>
900 <script language="javascript">
902 // used when selecting a list-name for a field
903 var selectedfield;
905 // jQuery stuff to make the page a little easier to use
907 $(document).ready(function(){
908 $("#save").click(function() { SaveChanges(); });
909 $("#layout_id").change(function() { $('#theform').submit(); });
911 $(".addgroup").click(function() { AddGroup(this); });
912 $(".savenewgroup").click(function() { SaveNewGroup(this); });
913 $(".deletegroup").click(function() { DeleteGroup(this); });
914 $(".cancelnewgroup").click(function() { CancelNewGroup(this); });
916 $(".movegroup").click(function() { MoveGroup(this); });
918 $(".renamegroup").click(function() { RenameGroup(this); });
919 $(".saverenamegroup").click(function() { SaveRenameGroup(this); });
920 $(".cancelrenamegroup").click(function() { CancelRenameGroup(this); });
922 $(".addfield").click(function() { AddField(this); });
923 $("#deletefields").click(function() { DeleteFields(this); });
924 $(".selectfield").click(function() {
925 var TRparent = $(this).parent().parent();
926 $(TRparent).children("td").toggleClass("highlight");
927 // disable the delete-move buttons
928 $("#deletefields").attr("disabled", "disabled");
929 $("#movefields").attr("disabled", "disabled");
930 $(".selectfield").each(function(i) {
931 // if any field is selected, enable the delete-move buttons
932 if ($(this).attr("checked") == true) {
933 $("#deletefields").removeAttr("disabled");
934 $("#movefields").removeAttr("disabled");
938 $("#movefields").click(function() { ShowGroups(this); });
939 $(".savenewfield").click(function() { SaveNewField(this); });
940 $(".cancelnewfield").click(function() { CancelNewField(this); });
941 $("#newtitle").blur(function() { if ($("#newid").val() == "") $("#newid").val($("#newtitle").val()); });
942 $("#newdatatype").change(function() { ChangeList(this.value);});
943 $("#gnewdatatype").change(function() { ChangeListg(this.value);});
944 $(".listid").click(function() { ShowLists(this); });
946 // special class that skips the element
947 $(".noselect").focus(function() { $(this).blur(); });
949 // Save the changes made to the form
950 var SaveChanges = function () {
951 $("#formaction").val("save");
952 $("#theform").submit();
955 /****************************************************/
956 /************ Group functions ***********************/
957 /****************************************************/
959 // display the 'new group' DIV
960 var AddGroup = function(btnObj) {
961 // show the field details DIV
962 $('#groupdetail').css('visibility', 'visible');
963 $('#groupdetail').css('display', 'block');
964 $(btnObj).parent().append($("#groupdetail"));
965 $('#groupdetail > #newgroupname').focus();
968 // save the new group to the form
969 var SaveNewGroup = function(btnObj) {
970 // the group name field can only have letters, numbers, spaces and underscores
971 // AND it cannot start with a number
972 if ($("#newgroupname").val() == "") {
973 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
974 return false;
976 if ($("#newgroupname").val().match(/^(\d+|\s+)/)) {
977 alert("<?php xl('Group names cannot start with numbers or spaces.','e'); ?>");
978 return false;
980 var validname = $("#newgroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
981 $("#newgroupname").val(validname);
983 // now, check the first group field values
985 // seq must be numeric and less than 999
986 if (! IsNumeric($("#gnewseq").val(), 0, 999)) {
987 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
988 return false;
990 // length must be numeric and less than 999
991 if (! IsNumeric($("#gnewlengthWidth").val(), 0, 999)) {
992 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
993 return false;
995 // titlecols must be numeric and less than 100
996 if (! IsNumeric($("#gnewtitlecols").val(), 0, 999)) {
997 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
998 return false;
1000 // datacols must be numeric and less than 100
1001 if (! IsNumeric($("#gnewdatacols").val(), 0, 999)) {
1002 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1003 return false;
1005 // some fields cannot be blank
1006 if ($("#gnewtitle").val() == "") {
1007 alert("<?php xl('Label cannot be blank','e'); ?>");
1008 return false;
1010 // the id field can only have letters, numbers and underscores
1011 if ($("#gnewid").val() == "") {
1012 alert("<?php xl('ID cannot be blank', 'e'); ?>");
1013 return false;
1015 var validid = $("#gnewid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1016 $("#gnewid").val(validid);
1017 // similarly with the listid field
1018 validid = $("#gnewlistid").val().replace(/(\s|\W)/g, "_");
1019 $("#gnewlistid").val(validid);
1020 // similarly with the backuplistid field
1021 validid = $("#gnewbackuplistid").val().replace(/(\s|\W)/g, "_");
1022 $("#gnewbackuplistid").val(validid);
1025 // submit the form to add a new field to a specific group
1026 $("#formaction").val("addgroup");
1027 $("#theform").submit();
1030 // actually delete an entire group from the database
1031 var DeleteGroup = function(btnObj) {
1032 var parts = $(btnObj).attr("id");
1033 var groupname = parts.replace(/^\d+/, "");
1034 if (confirm("<?php xl('WARNING','e','',' - ') . xl('This action cannot be undone.','e','','\n') . xl('Are you sure you wish to delete the entire group named','e','',' '); ?>'"+groupname+"'?")) {
1035 // submit the form to add a new field to a specific group
1036 $("#formaction").val("deletegroup");
1037 $("#deletegroupname").val(parts);
1038 $("#theform").submit();
1042 // just hide the new field DIV
1043 var CancelNewGroup = function(btnObj) {
1044 // hide the field details DIV
1045 $('#groupdetail').css('visibility', 'hidden');
1046 $('#groupdetail').css('display', 'none');
1047 // reset the new group values to a default
1048 $('#groupdetail > #newgroupname').val("");
1051 // display the 'new field' DIV
1052 var MoveGroup = function(btnObj) {
1053 var btnid = $(btnObj).attr("id");
1054 var parts = btnid.split("~");
1055 var groupid = parts[0];
1056 var direction = parts[1];
1058 // submit the form to change group order
1059 $("#formaction").val("movegroup");
1060 $("#movegroupname").val(groupid);
1061 $("#movedirection").val(direction);
1062 $("#theform").submit();
1065 // show the rename group DIV
1066 var RenameGroup = function(btnObj) {
1067 $('#renamegroupdetail').css('visibility', 'visible');
1068 $('#renamegroupdetail').css('display', 'block');
1069 $(btnObj).parent().append($("#renamegroupdetail"));
1070 $('#renameoldgroupname').val($(btnObj).attr("id"));
1071 $('#renamegroupname').val($(btnObj).attr("id").replace(/^\d+/, ""));
1074 // save the new group to the form
1075 var SaveRenameGroup = function(btnObj) {
1076 // the group name field can only have letters, numbers, spaces and underscores
1077 // AND it cannot start with a number
1078 if ($("#renamegroupname").val().match(/^\d+/)) {
1079 alert("<?php xl('Group names cannot start with numbers.','e'); ?>");
1080 return false;
1082 var validname = $("#renamegroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
1083 $("#renamegroupname").val(validname);
1085 // submit the form to add a new field to a specific group
1086 $("#formaction").val("renamegroup");
1087 $("#theform").submit();
1090 // just hide the new field DIV
1091 var CancelRenameGroup = function(btnObj) {
1092 // hide the field details DIV
1093 $('#renamegroupdetail').css('visibility', 'hidden');
1094 $('#renamegroupdetail').css('display', 'none');
1095 // reset the rename group values to a default
1096 $('#renameoldgroupname').val("");
1097 $('#renamegroupname').val("");
1100 /****************************************************/
1101 /************ Field functions ***********************/
1102 /****************************************************/
1104 // display the 'new field' DIV
1105 var AddField = function(btnObj) {
1106 // update the fieldgroup value to be the groupid
1107 var btnid = $(btnObj).attr("id");
1108 var parts = btnid.split("~");
1109 var groupid = parts[1];
1110 $('#fielddetail > #newfieldgroupid').attr('value', groupid);
1112 // show the field details DIV
1113 $('#fielddetail').css('visibility', 'visible');
1114 $('#fielddetail').css('display', 'block');
1115 $(btnObj).parent().append($("#fielddetail"));
1118 var DeleteFields = function(btnObj) {
1119 if (confirm("<?php xl('WARNING','e','',' - ') . xl('This action cannot be undone.','e','','\n') . xl('Are you sure you wish to delete the selected fields?','e'); ?>")) {
1120 var delim = "";
1121 $(".selectfield").each(function(i) {
1122 // build a list of selected field names to be moved
1123 if ($(this).attr("checked") == true) {
1124 var parts = this.id.split("~");
1125 var currval = $("#selectedfields").val();
1126 $("#selectedfields").val(currval+delim+parts[1]);
1127 delim = " ";
1130 // submit the form to delete the field(s)
1131 $("#formaction").val("deletefields");
1132 $("#theform").submit();
1136 // save the new field to the form
1137 var SaveNewField = function(btnObj) {
1138 // check the new field values for correct formatting
1140 // seq must be numeric and less than 999
1141 if (! IsNumeric($("#newseq").val(), 0, 999)) {
1142 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1143 return false;
1145 // length must be numeric and less than 999
1146 if (! IsNumeric($("#newlengthWidth").val(), 0, 999)) {
1147 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1148 return false;
1150 // titlecols must be numeric and less than 100
1151 if (! IsNumeric($("#newtitlecols").val(), 0, 999)) {
1152 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1153 return false;
1155 // datacols must be numeric and less than 100
1156 if (! IsNumeric($("#newdatacols").val(), 0, 999)) {
1157 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1158 return false;
1160 // some fields cannot be blank
1161 if ($("#newtitle").val() == "") {
1162 alert("<?php xl('Label cannot be blank','e'); ?>");
1163 return false;
1165 // the id field can only have letters, numbers and underscores
1166 var validid = $("#newid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1167 $("#newid").val(validid);
1168 // similarly with the listid field
1169 validid = $("#newlistid").val().replace(/(\s|\W)/g, "_");
1170 $("#newlistid").val(validid);
1171 // similarly with the backuplistid field
1172 validid = $("#newbackuplistid").val().replace(/(\s|\W)/g, "_");
1173 $("#newbackuplistid").val(validid);
1175 // submit the form to add a new field to a specific group
1176 $("#formaction").val("addfield");
1177 $("#theform").submit();
1180 // just hide the new field DIV
1181 var CancelNewField = function(btnObj) {
1182 // hide the field details DIV
1183 $('#fielddetail').css('visibility', 'hidden');
1184 $('#fielddetail').css('display', 'none');
1185 // reset the new field values to a default
1186 ResetNewFieldValues();
1189 // show the popup choice of lists
1190 var ShowLists = function(btnObj) {
1191 window.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1192 selectedfield = btnObj;
1195 // show the popup choice of groups
1196 var ShowGroups = function(btnObj) {
1197 window.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1200 // Show context DD for NationNotes
1201 var ChangeList = function(btnObj){
1202 if(btnObj==34){
1203 $('#newlistid').hide();
1204 $('#contextName').show();
1206 else{
1207 $('#newlistid').show();
1208 $('#contextName').hide();
1211 var ChangeListg = function(btnObj){
1212 if(btnObj==34){
1213 $('#gnewlistid').hide();
1214 $('#gcontextName').show();
1216 else{
1217 $('#gnewlistid').show();
1218 $('#gcontextName').hide();
1224 function NationNotesContext(lineitem,val){
1225 if(val==34){
1226 document.getElementById("fld["+lineitem+"][contextName]").style.display='';
1227 document.getElementById("fld["+lineitem+"][list_id]").style.display='none';
1228 document.getElementById("fld["+lineitem+"][list_id]").value='';
1230 else{
1231 document.getElementById("fld["+lineitem+"][list_id]").style.display='';
1232 document.getElementById("fld["+lineitem+"][contextName]").style.display='none';
1233 document.getElementById("fld["+lineitem+"][list_id]").value='';
1236 function SetList(listid) { $(selectedfield).val(listid); }
1239 /* this is called after the user chooses a new group from the popup window
1240 * it will submit the page so the selected fields can be moved into
1241 * the target group
1243 function MoveFields(targetgroup) {
1244 $("#targetgroup").val(targetgroup);
1245 var delim = "";
1246 $(".selectfield").each(function(i) {
1247 // build a list of selected field names to be moved
1248 if ($(this).attr("checked") == true) {
1249 var parts = this.id.split("~");
1250 var currval = $("#selectedfields").val();
1251 $("#selectedfields").val(currval+delim+parts[1]);
1252 delim = " ";
1255 $("#formaction").val("movefields");
1256 $("#theform").submit();
1260 // set the new-field values to a default state
1261 function ResetNewFieldValues () {
1262 $("#newseq").val("");
1263 $("#newid").val("");
1264 $("#newtitle").val("");
1265 $("#newuor").val(1);
1266 $("#newlengthWidth").val("");
1267 $("#newlengthHeight").val("");
1268 $("#newmaxSize").val("");
1269 $("#newdatatype").val("");
1270 $("#newlistid").val("");
1271 $("#newbackuplistid").val("");
1272 $("#newtitlecols").val("");
1273 $("#newdatacols").val("");
1274 $("#newedit_options").val("");
1275 $("#newdefault").val("");
1276 $("#newdesc").val("");
1279 // is value an integer and between min and max
1280 function IsNumeric(value, min, max) {
1281 if (value == "" || value == null) return false;
1282 if (! IsN(value) ||
1283 parseInt(value) < min ||
1284 parseInt(value) > max)
1285 return false;
1287 return true;
1290 /****************************************************/
1291 /****************************************************/
1292 /****************************************************/
1294 // tell if num is an Integer
1295 function IsN(num) { return !/\D/.test(num); }
1296 </script>
1298 </html>