removed call time *pass by reference* and made sure pass by reference specified in...
[openemr.git] / interface / super / edit_layout.php
blobe24b9d48453c7f4ebceb5ff0f298dcbe26598119
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'),
19 if ($GLOBALS['ippf_specific']) {
20 $layouts['GCA'] = xl('Abortion Issues');
21 $layouts['CON'] = xl('Contraception Issues');
22 // $layouts['SRH'] = xl('SRH Visit Form');
25 // Include Layout Based Encounter Forms.
26 $lres = sqlStatement("SELECT * FROM list_options " .
27 "WHERE list_id = 'lbfnames' ORDER BY seq, title");
28 while ($lrow = sqlFetchArray($lres)) {
29 $layouts[$lrow['option_id']] = $lrow['title'];
32 // array of the data_types of the fields
33 $datatypes = array(
34 "1" => xl("List box"),
35 "2" => xl("Textbox"),
36 "3" => xl("Textarea"),
37 "4" => xl("Text-date"),
38 "10" => xl("Providers"),
39 "11" => xl("Providers NPI"),
40 "12" => xl("Pharmacies"),
41 "13" => xl("Squads"),
42 "14" => xl("Organizations"),
43 "15" => xl("Billing codes"),
44 "21" => xl("Checkbox list"),
45 "22" => xl("Textbox list"),
46 "23" => xl("Exam results"),
47 "24" => xl("Patient allergies"),
48 "25" => xl("Checkbox w/text"),
49 "26" => xl("List box w/add"),
50 "27" => xl("Radio buttons"),
51 "28" => xl("Lifestyle status"),
52 "31" => xl("Static Text"),
53 "32" => xl("Smoking Status"),
54 "33" => xl("Race and Ethnicity"),
55 "34" => xl("NationNotes"),
56 "35" => xl("Facilities")
59 function nextGroupOrder($order) {
60 if ($order == '9') $order = 'A';
61 else if ($order == 'Z') $order = 'a';
62 else $order = chr(ord($order) + 1);
63 return $order;
66 // Check authorization.
67 $thisauth = acl_check('admin', 'super');
68 if (!$thisauth) die(xl('Not authorized'));
70 // The layout ID identifies the layout to be edited.
71 $layout_id = empty($_REQUEST['layout_id']) ? '' : $_REQUEST['layout_id'];
73 // Handle the Form actions
75 if ($_POST['formaction'] == "save" && $layout_id) {
76 // If we are saving, then save.
77 $fld = $_POST['fld'];
78 for ($lino = 1; isset($fld[$lino]['id']); ++$lino) {
79 $iter = $fld[$lino];
80 $field_id = formTrim($iter['id']);
81 $data_type = formTrim($iter['data_type']);
82 // For a textarea (data type 3) max_length has a special meaning, to
83 // specify its height (in rows). This kludge assigns a fixed height,
84 // but this GUI really needs to support max_length directly.
85 $max_length = $data_type == 3 ? 3 : 255;
86 $listval = $data_type == 34 ? formTrim($iter['contextName']) : formTrim($iter['list_id']);
87 if ($field_id) {
88 sqlStatement("UPDATE layout_options SET " .
89 "title = '" . formTrim($iter['title']) . "', " .
90 "group_name = '" . formTrim($iter['group']) . "', " .
91 "seq = '" . formTrim($iter['seq']) . "', " .
92 "uor = '" . formTrim($iter['uor']) . "', " .
93 "fld_length = '" . formTrim($iter['length']) . "', " .
94 "max_length = '$max_length', " .
95 "titlecols = '" . formTrim($iter['titlecols']) . "', " .
96 "datacols = '" . formTrim($iter['datacols']) . "', " .
97 "data_type= '$data_type', " .
98 "list_id= '" . $listval . "', " .
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" .
114 ", titlecols, datacols, data_type, edit_options, default_value, description" .
115 ", max_length, list_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['newlength'] ) . "'" .
124 ",'" . formTrim($_POST['newtitlecols'] ) . "'" .
125 ",'" . formTrim($_POST['newdatacols'] ) . "'" .
126 ",'$data_type'" .
127 ",'" . formTrim($_POST['newedit_options']) . "'" .
128 ",'" . formTrim($_POST['newdefault'] ) . "'" .
129 ",'" . formTrim($_POST['newdesc'] ) . "'" .
130 ",'$max_length'" .
131 ",'" . $listval . "'" .
132 " )");
134 if (substr($layout_id,0,3) != 'LBF') {
135 // Add the field to the table too (this is critical)
136 if ($layout_id == "DEM") { $tablename = "patient_data"; }
137 else if ($layout_id == "HIS") { $tablename = "history_data"; }
138 else if ($layout_id == "REF") { $tablename = "transactions"; }
139 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
140 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
141 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
142 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
143 "`" . formTrim($_POST['newid']) . "`" .
144 " VARCHAR( 255 )");
145 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
146 $tablename . " ADD " . formTrim($_POST['newid']));
150 else if ($_POST['formaction'] == "movefields" && $layout_id) {
151 // Move field(s) to a new group in the layout
152 $sqlstmt = "UPDATE layout_options SET ".
153 " group_name='". $_POST['targetgroup']."' ".
154 " WHERE ".
155 " form_id = '".$_POST['layout_id']."' ".
156 " AND field_id IN (";
157 $comma = "";
158 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
159 $sqlstmt .= $comma."'".$onefield."'";
160 $comma = ", ";
162 $sqlstmt .= ")";
163 //echo $sqlstmt;
164 sqlStatement($sqlstmt);
167 else if ($_POST['formaction'] == "deletefields" && $layout_id) {
168 // Delete a field from a specific group
169 $sqlstmt = "DELETE FROM layout_options WHERE ".
170 " form_id = '".$_POST['layout_id']."' ".
171 " AND field_id IN (";
172 $comma = "";
173 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
174 $sqlstmt .= $comma."'".$onefield."'";
175 $comma = ", ";
177 $sqlstmt .= ")";
178 sqlStatement($sqlstmt);
180 if (substr($layout_id,0,3) != 'LBF') {
181 // drop the field from the table too (this is critical)
182 if ($layout_id == "DEM") { $tablename = "patient_data"; }
183 else if ($layout_id == "HIS") { $tablename = "history_data"; }
184 else if ($layout_id == "REF") { $tablename = "transactions"; }
185 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
186 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
187 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
188 foreach (explode(" ", $_POST['selectedfields']) as $onefield) {
189 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$onefield."`");
190 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".$onefield);
195 else if ($_POST['formaction'] == "addgroup" && $layout_id) {
196 // all group names are prefixed with a number indicating their display order
197 // this new group is prefixed with the net highest number given the
198 // layout_id
199 $results = sqlStatement("select distinct(group_name) as gname ".
200 " from layout_options where ".
201 " form_id = '".$_POST['layout_id']."'"
203 $maxnum = '1';
204 while ($result = sqlFetchArray($results)) {
205 $tmp = substr($result['gname'], 0, 1);
206 if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
209 $data_type = formTrim($_POST['gnewdatatype']);
210 $max_length = $data_type == 3 ? 3 : 255;
211 $listval = $data_type == 34 ? formTrim($_POST['gcontextName']) : formTrim($_POST['gnewlistid']);
212 // add a new group to the layout, with the defined field
213 sqlStatement("INSERT INTO layout_options (" .
214 " form_id, field_id, title, group_name, seq, uor, fld_length" .
215 ", titlecols, datacols, data_type, edit_options, default_value, description" .
216 ", max_length, list_id " .
217 ") VALUES ( " .
218 "'" . formTrim($_POST['layout_id'] ) . "'" .
219 ",'" . formTrim($_POST['gnewid'] ) . "'" .
220 ",'" . formTrim($_POST['gnewtitle'] ) . "'" .
221 ",'" . formTrim($maxnum . $_POST['newgroupname']) . "'" .
222 ",'" . formTrim($_POST['gnewseq'] ) . "'" .
223 ",'" . formTrim($_POST['gnewuor'] ) . "'" .
224 ",'" . formTrim($_POST['gnewlength'] ) . "'" .
225 ",'" . formTrim($_POST['gnewtitlecols'] ) . "'" .
226 ",'" . formTrim($_POST['gnewdatacols'] ) . "'" .
227 ",'$data_type'" .
228 ",'" . formTrim($_POST['gnewedit_options']) . "'" .
229 ",'" . formTrim($_POST['gnewdefault'] ) . "'" .
230 ",'" . formTrim($_POST['gnewdesc'] ) . "'" .
231 ",'$max_length'" .
232 ",'" . $listval . "'" .
233 " )");
235 if (substr($layout_id,0,3) != 'LBF') {
236 // Add the field to the table too (this is critical)
237 if ($layout_id == "DEM") { $tablename = "patient_data"; }
238 else if ($layout_id == "HIS") { $tablename = "history_data"; }
239 else if ($layout_id == "REF") { $tablename = "transactions"; }
240 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
241 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
242 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
243 sqlStatement("ALTER TABLE `" . $tablename . "` ADD ".
244 "`" . formTrim($_POST['gnewid']) . "`" .
245 " VARCHAR( 255 )");
246 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1,
247 $tablename . " ADD " . formTrim($_POST['gnewid']));
251 else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
252 // drop the fields from the related table (this is critical)
253 if (substr($layout_id,0,3) != 'LBF') {
254 $res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
255 " form_id = '".$_POST['layout_id']."' ".
256 " AND group_name = '".$_POST['deletegroupname']."'"
258 while ($row = sqlFetchArray($res)) {
259 // drop the field from the table too (this is critical)
260 if ($layout_id == "DEM") { $tablename = "patient_data"; }
261 else if ($layout_id == "HIS") { $tablename = "history_data"; }
262 else if ($layout_id == "REF") { $tablename = "transactions"; }
263 else if ($layout_id == "SRH") { $tablename = "lists_ippf_srh"; }
264 else if ($layout_id == "CON") { $tablename = "lists_ippf_con"; }
265 else if ($layout_id == "GCA") { $tablename = "lists_ippf_gcac"; }
266 sqlStatement("ALTER TABLE `".$tablename."` DROP `".$row['field_id']."`");
267 newEvent("alter_table", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $tablename." DROP ".trim($row['field_id']));
271 // Delete an entire group from the form
272 sqlStatement("DELETE FROM layout_options WHERE ".
273 " form_id = '".$_POST['layout_id']."' ".
274 " AND group_name = '".$_POST['deletegroupname']."'"
278 else if ($_POST['formaction'] == "movegroup" && $layout_id) {
279 $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
280 "FROM layout_options WHERE form_id = '$layout_id' " .
281 "ORDER BY gname");
282 $garray = array();
283 $i = 0;
284 while ($result = sqlFetchArray($results)) {
285 if ($result['gname'] == $_POST['movegroupname']) {
286 if ($_POST['movedirection'] == 'up') { // moving up
287 if ($i > 0) {
288 $garray[$i] = $garray[$i - 1];
289 $garray[$i - 1] = $result['gname'];
290 $i++;
292 else {
293 $garray[$i++] = $result['gname'];
296 else { // moving down
297 $garray[$i++] = '';
298 $garray[$i++] = $result['gname'];
301 else if ($i > 1 && $garray[$i - 2] == '') {
302 $garray[$i - 2] = $result['gname'];
304 else {
305 $garray[$i++] = $result['gname'];
308 $nextord = '1';
309 foreach ($garray as $value) {
310 if ($value === '') continue;
311 $newname = $nextord . substr($value, 1);
312 sqlStatement("UPDATE layout_options SET " .
313 "group_name = '$newname' WHERE " .
314 "form_id = '$layout_id' AND " .
315 "group_name = '$value'");
316 $nextord = nextGroupOrder($nextord);
320 else if ($_POST['formaction'] == "renamegroup" && $layout_id) {
321 $currpos = substr($_POST['renameoldgroupname'], 0, 1);
322 // update the database rows
323 sqlStatement("UPDATE layout_options SET " .
324 "group_name = '" . $currpos . $_POST['renamegroupname'] . "' ".
325 "WHERE form_id = '$layout_id' AND ".
326 "group_name = '" . $_POST['renameoldgroupname'] . "'");
329 // Get the selected form's elements.
330 if ($layout_id) {
331 $res = sqlStatement("SELECT * FROM layout_options WHERE " .
332 "form_id = '$layout_id' ORDER BY group_name, seq");
335 // global counter for field numbers
336 $fld_line_no = 0;
338 // Write one option line to the form.
340 function writeFieldLine($linedata) {
341 global $fld_line_no;
342 ++$fld_line_no;
343 $checked = $linedata['default_value'] ? " checked" : "";
345 //echo " <tr bgcolor='$bgcolor'>\n";
346 echo " <tr id='fld[$fld_line_no]' class='".($fld_line_no % 2 ? 'even' : 'odd')."'>\n";
348 echo " <td class='optcell' nowrap>";
349 // tuck the group_name INPUT in here
350 echo "<input type='hidden' name='fld[$fld_line_no][group]' value='" .
351 htmlspecialchars($linedata['group_name'], ENT_QUOTES) . "' class='optin' />";
353 echo "<input type='checkbox' class='selectfield' ".
354 "name='".$linedata['group_name']."~".$linedata['field_id']."' ".
355 "id='".$linedata['group_name']."~".$linedata['field_id']."' ".
356 "title='".htmlspecialchars(xl('Select field', ENT_QUOTES))."'>";
358 echo "<input type='text' name='fld[$fld_line_no][seq]' id='fld[$fld_line_no][seq]' value='" .
359 htmlspecialchars($linedata['seq'], ENT_QUOTES) . "' size='2' maxlength='3' class='optin' />";
360 echo "</td>\n";
362 echo " <td align='left' class='optcell'>";
363 echo "<input type='text' name='fld[$fld_line_no][id]' value='" .
364 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' size='15' maxlength='63' class='optin noselect' />";
366 echo "<input type='hidden' name='fld[$fld_line_no][id]' value='" .
367 htmlspecialchars($linedata['field_id'], ENT_QUOTES) . "' />";
368 echo htmlspecialchars($linedata['field_id'], ENT_QUOTES);
370 echo "</td>\n";
372 echo " <td align='center' class='optcell'>";
373 echo "<input type='text' id='fld[$fld_line_no][title]' name='fld[$fld_line_no][title]' value='" .
374 htmlspecialchars($linedata['title'], ENT_QUOTES) . "' size='15' maxlength='63' class='optin' />";
375 echo "</td>\n";
377 // if not english and set to translate layout labels, then show the translation
378 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
379 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['title']), ENT_QUOTES) . "</td>\n";
382 echo " <td align='center' class='optcell'>";
383 echo "<select name='fld[$fld_line_no][uor]' class='optin'>";
384 foreach (array(0 =>xl('Unused'), 1 =>xl('Optional'), 2 =>xl('Required')) as $key => $value) {
385 echo "<option value='$key'";
386 if ($key == $linedata['uor']) echo " selected";
387 echo ">$value</option>\n";
389 echo "</select>";
390 echo "</td>\n";
392 echo " <td align='center' class='optcell'>";
393 echo "<select name='fld[$fld_line_no][data_type]' id='fld[$fld_line_no][data_type]' onchange=NationNotesContext('".$fld_line_no."',this.value)>";
394 echo "<option value=''></option>";
395 GLOBAL $datatypes;
396 foreach ($datatypes as $key=>$value) {
397 if ($linedata['data_type'] == $key)
398 echo "<option value='$key' selected>$value</option>";
399 else
400 echo "<option value='$key'>$value</option>";
402 echo "</select>";
403 echo " </td>";
405 echo " <td align='center' class='optcell'>";
406 if ($linedata['data_type'] == 2 || $linedata['data_type'] == 3 ||
407 $linedata['data_type'] == 21 || $linedata['data_type'] == 22 ||
408 $linedata['data_type'] == 23 || $linedata['data_type'] == 25 ||
409 $linedata['data_type'] == 27 || $linedata['data_type'] == 28 ||
410 $linedata['data_type'] == 32)
412 echo "<input type='text' name='fld[$fld_line_no][length]' value='" .
413 htmlspecialchars($linedata['fld_length'], ENT_QUOTES) .
414 "' size='1' maxlength='10' class='optin' />";
416 else {
417 // all other data_types
418 echo "<input type='hidden' name='fld[$fld_line_no][length]' value=''>";
420 echo "</td>\n";
422 echo " <td align='center' class='optcell'>";
423 if ($linedata['data_type'] == 1 || $linedata['data_type'] == 21 ||
424 $linedata['data_type'] == 22 || $linedata['data_type'] == 23 ||
425 $linedata['data_type'] == 25 || $linedata['data_type'] == 26 ||
426 $linedata['data_type'] == 27 || $linedata['data_type'] == 32 ||
427 $linedata['data_type'] == 33 || $linedata['data_type'] == 34)
429 $type = "";
430 $disp = "style='display:none'";
431 if($linedata['data_type'] == 34){
432 $type = "style='display:none'";
433 $disp = "";
435 echo "<input type='text' name='fld[$fld_line_no][list_id]' id='fld[$fld_line_no][list_id]' value='" .
436 htmlspecialchars($linedata['list_id'], ENT_QUOTES) . "'".$type.
437 " size='6' maxlength='30' class='optin listid' style='cursor: pointer'".
438 "title='". xl('Choose list') . "' />";
440 echo "<select name='fld[$fld_line_no][contextName]' id='fld[$fld_line_no][contextName]' ".$disp.">";
441 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
442 while($row = sqlFetchArray($res)){
443 $sel = '';
444 if ($linedata['list_id'] == $row['cl_list_item_long'])
445 $sel = 'selected';
446 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."' ".$sel.">".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
448 echo "</select>";
450 else {
451 // all other data_types
452 echo "<input type='hidden' name='fld[$fld_line_no][list_id]' value=''>";
454 echo "</td>\n";
456 echo " <td align='center' class='optcell'>";
457 echo "<input type='text' name='fld[$fld_line_no][titlecols]' value='" .
458 htmlspecialchars($linedata['titlecols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' />";
459 echo "</td>\n";
461 echo " <td align='center' class='optcell'>";
462 echo "<input type='text' name='fld[$fld_line_no][datacols]' value='" .
463 htmlspecialchars($linedata['datacols'], ENT_QUOTES) . "' size='3' maxlength='10' class='optin' />";
464 echo "</td>\n";
466 echo " <td align='center' class='optcell' title='C = " . xl('Capitalize') .
467 ", D = " . xl('Dup Check') . ", G = " . xl('Graphable') .
468 ", N = " . xl('New Patient Form') . ", O = " . xl('Order Processor') .
469 ", V = " . xl('Vendor') . "'>";
470 echo "<input type='text' name='fld[$fld_line_no][edit_options]' value='" .
471 htmlspecialchars($linedata['edit_options'], ENT_QUOTES) . "' size='3' maxlength='36' class='optin' />";
472 echo "</td>\n";
474 /*****************************************************************
475 echo " <td align='center' class='optcell'>";
476 if ($linedata['data_type'] == 2) {
477 echo "<input type='text' name='fld[$fld_line_no][default]' value='" .
478 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' size='10' maxlength='63' class='optin' />";
479 } else {
480 echo "&nbsp;";
482 echo "</td>\n";
484 echo " <td align='center' class='optcell'>";
485 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
486 htmlspecialchars($linedata['description'], ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
487 echo "</td>\n";
489 // if not english and showing layout labels, then show the translation of Description
490 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
491 echo "<td align='center' class='translation'>" . htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
493 *****************************************************************/
495 if ($linedata['data_type'] == 31) {
496 echo " <td align='center' class='optcell'>";
497 echo "<textarea name='fld[$fld_line_no][desc]' rows='3' cols='35' class='optin'>" .
498 $linedata['description'] . "</textarea>";
499 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
500 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
501 echo "</td>\n";
503 else {
504 echo " <td align='center' class='optcell'>";
505 echo "<input type='text' name='fld[$fld_line_no][desc]' value='" .
506 htmlspecialchars($linedata['description'], ENT_QUOTES) .
507 "' size='30' maxlength='63' class='optin' />";
508 echo "<input type='hidden' name='fld[$fld_line_no][default]' value='" .
509 htmlspecialchars($linedata['default_value'], ENT_QUOTES) . "' />";
510 echo "</td>\n";
511 // if not english and showing layout labels, then show the translation of Description
512 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
513 echo "<td align='center' class='translation'>" .
514 htmlspecialchars(xl($linedata['description']), ENT_QUOTES) . "</td>\n";
518 echo " </tr>\n";
521 <html>
523 <head>
524 <?php html_header_show();?>
526 <!-- supporting javascript code -->
527 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
529 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
531 <title><?php xl('Layout Editor','e'); ?></title>
533 <style>
534 tr.head { font-size:10pt; background-color:#cccccc; }
535 tr.detail { font-size:10pt; }
536 td { font-size:10pt; }
537 input { font-size:10pt; }
538 a, a:visited, a:hover { color:#0000cc; }
539 .optcell { }
540 .optin { background: transparent; }
541 .group {
542 margin: 0pt 0pt 8pt 0pt;
543 padding: 0;
544 width: 100%;
546 .group table {
547 border-collapse: collapse;
548 width: 100%;
550 .odd td {
551 background-color: #ddddff;
552 padding: 3px 0px 3px 0px;
554 .even td {
555 background-color: #ffdddd;
556 padding: 3px 0px 3px 0px;
558 .help { cursor: help; }
559 .layouts_title { font-size: 110%; }
560 .translation {
561 color: green;
562 font-size:10pt;
564 .highlight * {
565 border: 2px solid blue;
566 background-color: yellow;
567 color: black;
569 </style>
571 </head>
573 <body class="body_top">
575 <form method='post' name='theform' id='theform' action='edit_layout.php'>
576 <input type="hidden" name="formaction" id="formaction" value="">
577 <!-- elements used to identify a field to delete -->
578 <input type="hidden" name="deletefieldid" id="deletefieldid" value="">
579 <input type="hidden" name="deletefieldgroup" id="deletefieldgroup" value="">
580 <!-- elements used to identify a group to delete -->
581 <input type="hidden" name="deletegroupname" id="deletegroupname" value="">
582 <!-- elements used to change the group order -->
583 <input type="hidden" name="movegroupname" id="movegroupname" value="">
584 <input type="hidden" name="movedirection" id="movedirection" value="">
585 <!-- elements used to select more than one field -->
586 <input type="hidden" name="selectedfields" id="selectedfields" value="">
587 <input type="hidden" id="targetgroup" name="targetgroup" value="">
589 <p><b><?php xl('Edit layout','e'); ?>:</b>&nbsp;
590 <select name='layout_id' id='layout_id'>
591 <option value=''>-- <?php echo xl('Select') ?> --</option>
592 <?php
593 foreach ($layouts as $key => $value) {
594 echo " <option value='$key'";
595 if ($key == $layout_id) echo " selected";
596 echo ">$value</option>\n";
599 </select></p>
601 <?php if ($layout_id) { ?>
602 <div style='margin: 0 0 8pt 0;'>
603 <input type='button' class='addgroup' id='addgroup' value=<?php xl('Add Group','e','\'','\''); ?>/>
604 </div>
605 <?php } ?>
607 <?php
608 $prevgroup = "!@#asdf1234"; // an unlikely group name
609 $firstgroup = true; // flag indicates it's the first group to be displayed
610 while ($row = sqlFetchArray($res)) {
611 if ($row['group_name'] != $prevgroup) {
612 if ($firstgroup == false) { echo "</tbody></table></div>\n"; }
613 echo "<div id='".$row['group_name']."' class='group'>";
614 echo "<div class='text bold layouts_title' style='position:relative; background-color: #eef'>";
615 // echo preg_replace("/^\d+/", "", $row['group_name']);
616 echo substr($row['group_name'], 1);
617 echo "&nbsp; ";
618 // if not english and set to translate layout labels, then show the translation of group name
619 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
620 // echo "<span class='translation'>>>&nbsp; " . xl(preg_replace("/^\d+/", "", $row['group_name'])) . "</span>";
621 echo "<span class='translation'>>>&nbsp; " . xl(substr($row['group_name'], 1)) . "</span>";
622 echo "&nbsp; ";
624 echo "&nbsp; ";
625 echo " <input type='button' class='addfield' id='addto~".$row['group_name']."' value='" . xl('Add Field') . "'/>";
626 echo "&nbsp; &nbsp; ";
627 echo " <input type='button' class='renamegroup' id='".$row['group_name']."' value='" . xl('Rename Group') . "'/>";
628 echo "&nbsp; &nbsp; ";
629 echo " <input type='button' class='deletegroup' id='".$row['group_name']."' value='" . xl('Delete Group') . "'/>";
630 echo "&nbsp; &nbsp; ";
631 echo " <input type='button' class='movegroup' id='".$row['group_name']."~up' value='" . xl('Move Up') . "'/>";
632 echo "&nbsp; &nbsp; ";
633 echo " <input type='button' class='movegroup' id='".$row['group_name']."~down' value='" . xl('Move Down') . "'/>";
634 echo "</div>";
635 $firstgroup = false;
638 <table>
639 <thead>
640 <tr class='head'>
641 <th><?php xl('Order','e'); ?></th>
642 <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>
643 <th><?php xl('Label','e'); ?> <span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
644 <?php // if not english and showing layout label translations, then show translation header for title
645 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
646 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translated label that will appear on the form in current language') . "'> (?)</span></th>";
647 } ?>
648 <th><?php xl('UOR','e'); ?></th>
649 <th><?php xl('Data Type','e'); ?></th>
650 <th><?php xl('Size','e'); ?></th>
651 <th><?php xl('List','e'); ?></th>
652 <th><?php xl('Label Cols','e'); ?></th>
653 <th><?php xl('Data Cols','e'); ?></th>
654 <th><?php xl('Options','e'); ?></th>
655 <th><?php xl('Description','e'); ?></th>
656 <?php // if not english and showing layout label translations, then show translation header for description
657 if ($GLOBALS['translate_layout'] && $_SESSION['language_choice'] > 1) {
658 echo "<th>" . xl('Translation')."<span class='help' title='" . xl('The translation of description in current language')."'> (?)</span></th>";
659 } ?>
660 </tr>
661 </thead>
662 <tbody>
664 <?php
665 } // end if-group_name
667 writeFieldLine($row);
668 $prevgroup = $row['group_name'];
670 } // end while loop
673 </tbody>
674 </table></div>
676 <?php if ($layout_id) { ?>
677 <span style="font-size:90%">
678 <?php xl('With selected:', 'e');?>
679 <input type='button' name='deletefields' id='deletefields' value='<?php xl('Delete','e'); ?>' style="font-size:90%" disabled="disabled" />
680 <input type='button' name='movefields' id='movefields' value='<?php xl('Move to...','e'); ?>' style="font-size:90%" disabled="disabled" />
681 </span>
683 <input type='button' name='save' id='save' value='<?php xl('Save Changes','e'); ?>' />
684 </p>
685 <?php } ?>
687 </form>
689 <!-- template DIV that appears when user chooses to rename an existing group -->
690 <div id="renamegroupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
691 <input type="hidden" name="renameoldgroupname" id="renameoldgroupname" value="">
692 <?php xl('Group Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="renamegroupname" id="renamegroupname">
693 <br>
694 <input type="button" class="saverenamegroup" value=<?php xl('Rename Group','e','\'','\''); ?>>
695 <input type="button" class="cancelrenamegroup" value=<?php xl('Cancel','e','\'','\''); ?>>
696 </div>
698 <!-- template DIV that appears when user chooses to add a new group -->
699 <div id="groupdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
700 <span class='bold'>
701 <?php xl('Group Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newgroupname" id="newgroupname">
702 <br>
703 <table style="border-collapse: collapse; margin-top: 5px;">
704 <thead>
705 <tr class='head'>
706 <th><?php xl('Order','e'); ?></th>
707 <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>
708 <th><?php xl('Label','e'); ?> <span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
709 <th><?php xl('UOR','e'); ?></th>
710 <th><?php xl('Data Type','e'); ?></th>
711 <th><?php xl('Size','e'); ?></th>
712 <th><?php xl('List','e'); ?></th>
713 <th><?php xl('Label Cols','e'); ?></th>
714 <th><?php xl('Data Cols','e'); ?></th>
715 <th><?php xl('Options','e'); ?></th>
716 <th><?php xl('Description','e'); ?></th>
717 </tr>
718 </thead>
719 <tbody>
720 <tr class='center'>
721 <td ><input type="textbox" name="gnewseq" id="gnewseq" value="" size="2" maxlength="3"> </td>
722 <td ><input type="textbox" name="gnewid" id="gnewid" value="" size="10" maxlength="20"> </td>
723 <td><input type="textbox" name="gnewtitle" id="gnewtitle" value="" size="20" maxlength="63"> </td>
724 <td>
725 <select name="gnewuor" id="gnewuor">
726 <option value="0"><?php xl('Unused','e'); ?></option>
727 <option value="1" selected><?php xl('Optional','e'); ?></option>
728 <option value="2"><?php xl('Required','e'); ?></option>
729 </select>
730 </td>
731 <td align='center'>
732 <select name='gnewdatatype' id='gnewdatatype'>
733 <option value=''></option>
734 <?php
735 global $datatypes;
736 foreach ($datatypes as $key=>$value) {
737 echo "<option value='$key'>$value</option>";
740 </select>
741 </td>
742 <td><input type="textbox" name="gnewlength" id="gnewlength" value="" size="1" maxlength="3"> </td>
743 <td><input type="textbox" name="gnewlistid" id="gnewlistid" value="" size="8" maxlength="31" class="listid">
744 <select name='gcontextName' id='gcontextName' style='display:none'>
745 <?php
746 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
747 while($row = sqlFetchArray($res)){
748 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
751 </select>
752 </td>
753 <td><input type="textbox" name="gnewtitlecols" id="gnewtitlecols" value="" size="3" maxlength="3"> </td>
754 <td><input type="textbox" name="gnewdatacols" id="gnewdatacols" value="" size="3" maxlength="3"> </td>
755 <td><input type="textbox" name="gnewedit_options" id="gnewedit_options" value="" size="3" maxlength="36">
756 <input type="hidden" name="gnewdefault" id="gnewdefault" value="" /> </td>
757 <td><input type="textbox" name="gnewdesc" id="gnewdesc" value="" size="30" maxlength="63"> </td>
758 </tr>
759 </tbody>
760 </table>
761 <br>
762 <input type="button" class="savenewgroup" value=<?php xl('Save New Group','e','\'','\''); ?>>
763 <input type="button" class="cancelnewgroup" value=<?php xl('Cancel','e','\'','\''); ?>>
764 </span>
765 </div>
767 <!-- template DIV that appears when user chooses to add a new field to a group -->
768 <div id="fielddetail" class="fielddetail" style="display: none; visibility: hidden">
769 <input type="hidden" name="newfieldgroupid" id="newfieldgroupid" value="">
770 <table style="border-collapse: collapse;">
771 <thead>
772 <tr class='head'>
773 <th><?php xl('Order','e'); ?></th>
774 <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>
775 <th><?php xl('Label','e'); ?> <span class="help" title=<?php xl('The label that appears to the user on the form','e','\'','\''); ?> >(?)</span></th>
776 <th><?php xl('UOR','e'); ?></th>
777 <th><?php xl('Data Type','e'); ?></th>
778 <th><?php xl('Size','e'); ?></th>
779 <th><?php xl('List','e'); ?></th>
780 <th><?php xl('Label Cols','e'); ?></th>
781 <th><?php xl('Data Cols','e'); ?></th>
782 <th><?php xl('Options','e'); ?></th>
783 <th><?php xl('Description','e'); ?></th>
784 </tr>
785 </thead>
786 <tbody>
787 <tr class='center'>
788 <td ><input type="textbox" name="newseq" id="newseq" value="" size="2" maxlength="3"> </td>
789 <td ><input type="textbox" name="newid" id="newid" value="" size="10" maxlength="20"> </td>
790 <td><input type="textbox" name="newtitle" id="newtitle" value="" size="20" maxlength="63"> </td>
791 <td>
792 <select name="newuor" id="newuor">
793 <option value="0"><?php xl('Unused','e'); ?></option>
794 <option value="1" selected><?php xl('Optional','e'); ?></option>
795 <option value="2"><?php xl('Required','e'); ?></option>
796 </select>
797 </td>
798 <td align='center'>
799 <select name='newdatatype' id='newdatatype'>
800 <option value=''></option>
801 <?php
802 global $datatypes;
803 foreach ($datatypes as $key=>$value) {
804 echo " <option value='$key'>$value</option>\n";
807 </select>
808 </td>
809 <td><input type="textbox" name="newlength" id="newlength" value="" size="1" maxlength="3"> </td>
810 <td><input type="textbox" name="newlistid" id="newlistid" value="" size="8" maxlength="31" class="listid">
811 <select name='contextName' id='contextName' style='display:none'>
812 <?php
813 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
814 while($row = sqlFetchArray($res)){
815 echo "<option value='".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
818 </select>
819 </td>
820 <td><input type="textbox" name="newtitlecols" id="newtitlecols" value="" size="3" maxlength="3"> </td>
821 <td><input type="textbox" name="newdatacols" id="newdatacols" value="" size="3" maxlength="3"> </td>
822 <td><input type="textbox" name="newedit_options" id="newedit_options" value="" size="3" maxlength="36">
823 <input type="hidden" name="newdefault" id="newdefault" value="" /> </td>
824 <td><input type="textbox" name="newdesc" id="newdesc" value="" size="30" maxlength="63"> </td>
825 </tr>
826 <tr>
827 <td colspan="9">
828 <input type="button" class="savenewfield" value=<?php xl('Save New Field','e','\'','\''); ?>>
829 <input type="button" class="cancelnewfield" value=<?php xl('Cancel','e','\'','\''); ?>>
830 </td>
831 </tr>
832 </tbody>
833 </table>
834 </div>
836 </body>
838 <script language="javascript">
840 // used when selecting a list-name for a field
841 var selectedfield;
843 // jQuery stuff to make the page a little easier to use
845 $(document).ready(function(){
846 $("#save").click(function() { SaveChanges(); });
847 $("#layout_id").change(function() { $('#theform').submit(); });
849 $(".addgroup").click(function() { AddGroup(this); });
850 $(".savenewgroup").click(function() { SaveNewGroup(this); });
851 $(".deletegroup").click(function() { DeleteGroup(this); });
852 $(".cancelnewgroup").click(function() { CancelNewGroup(this); });
854 $(".movegroup").click(function() { MoveGroup(this); });
856 $(".renamegroup").click(function() { RenameGroup(this); });
857 $(".saverenamegroup").click(function() { SaveRenameGroup(this); });
858 $(".cancelrenamegroup").click(function() { CancelRenameGroup(this); });
860 $(".addfield").click(function() { AddField(this); });
861 $("#deletefields").click(function() { DeleteFields(this); });
862 $(".selectfield").click(function() {
863 var TRparent = $(this).parent().parent();
864 $(TRparent).children("td").toggleClass("highlight");
865 // disable the delete-move buttons
866 $("#deletefields").attr("disabled", "disabled");
867 $("#movefields").attr("disabled", "disabled");
868 $(".selectfield").each(function(i) {
869 // if any field is selected, enable the delete-move buttons
870 if ($(this).attr("checked") == true) {
871 $("#deletefields").removeAttr("disabled");
872 $("#movefields").removeAttr("disabled");
876 $("#movefields").click(function() { ShowGroups(this); });
877 $(".savenewfield").click(function() { SaveNewField(this); });
878 $(".cancelnewfield").click(function() { CancelNewField(this); });
879 $("#newtitle").blur(function() { if ($("#newid").val() == "") $("#newid").val($("#newtitle").val()); });
880 $("#newdatatype").change(function() { ChangeList(this.value);});
881 $("#gnewdatatype").change(function() { ChangeListg(this.value);});
882 $(".listid").click(function() { ShowLists(this); });
884 // special class that skips the element
885 $(".noselect").focus(function() { $(this).blur(); });
887 // Save the changes made to the form
888 var SaveChanges = function () {
889 $("#formaction").val("save");
890 $("#theform").submit();
893 /****************************************************/
894 /************ Group functions ***********************/
895 /****************************************************/
897 // display the 'new group' DIV
898 var AddGroup = function(btnObj) {
899 // show the field details DIV
900 $('#groupdetail').css('visibility', 'visible');
901 $('#groupdetail').css('display', 'block');
902 $(btnObj).parent().append($("#groupdetail"));
903 $('#groupdetail > #newgroupname').focus();
906 // save the new group to the form
907 var SaveNewGroup = function(btnObj) {
908 // the group name field can only have letters, numbers, spaces and underscores
909 // AND it cannot start with a number
910 if ($("#newgroupname").val() == "") {
911 alert("<?php xl('Group names cannot be blank', 'e'); ?>");
912 return false;
914 if ($("#newgroupname").val().match(/^(\d+|\s+)/)) {
915 alert("<?php xl('Group names cannot start with numbers or spaces.','e'); ?>");
916 return false;
918 var validname = $("#newgroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
919 $("#newgroupname").val(validname);
921 // now, check the first group field values
923 // seq must be numeric and less than 999
924 if (! IsNumeric($("#gnewseq").val(), 0, 999)) {
925 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
926 return false;
928 // length must be numeric and less than 999
929 if (! IsNumeric($("#gnewlength").val(), 0, 999)) {
930 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
931 return false;
933 // titlecols must be numeric and less than 100
934 if (! IsNumeric($("#gnewtitlecols").val(), 0, 999)) {
935 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
936 return false;
938 // datacols must be numeric and less than 100
939 if (! IsNumeric($("#gnewdatacols").val(), 0, 999)) {
940 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
941 return false;
943 // some fields cannot be blank
944 if ($("#gnewtitle").val() == "") {
945 alert("<?php xl('Label cannot be blank','e'); ?>");
946 return false;
948 // the id field can only have letters, numbers and underscores
949 if ($("#gnewid").val() == "") {
950 alert("<?php xl('ID cannot be blank', 'e'); ?>");
951 return false;
953 var validid = $("#gnewid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
954 $("#gnewid").val(validid);
955 // similarly with the listid field
956 validid = $("#gnewlistid").val().replace(/(\s|\W)/g, "_");
957 $("#gnewlistid").val(validid);
959 // submit the form to add a new field to a specific group
960 $("#formaction").val("addgroup");
961 $("#theform").submit();
964 // actually delete an entire group from the database
965 var DeleteGroup = function(btnObj) {
966 var parts = $(btnObj).attr("id");
967 var groupname = parts.replace(/^\d+/, "");
968 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+"'?")) {
969 // submit the form to add a new field to a specific group
970 $("#formaction").val("deletegroup");
971 $("#deletegroupname").val(parts);
972 $("#theform").submit();
976 // just hide the new field DIV
977 var CancelNewGroup = function(btnObj) {
978 // hide the field details DIV
979 $('#groupdetail').css('visibility', 'hidden');
980 $('#groupdetail').css('display', 'none');
981 // reset the new group values to a default
982 $('#groupdetail > #newgroupname').val("");
985 // display the 'new field' DIV
986 var MoveGroup = function(btnObj) {
987 var btnid = $(btnObj).attr("id");
988 var parts = btnid.split("~");
989 var groupid = parts[0];
990 var direction = parts[1];
992 // submit the form to change group order
993 $("#formaction").val("movegroup");
994 $("#movegroupname").val(groupid);
995 $("#movedirection").val(direction);
996 $("#theform").submit();
999 // show the rename group DIV
1000 var RenameGroup = function(btnObj) {
1001 $('#renamegroupdetail').css('visibility', 'visible');
1002 $('#renamegroupdetail').css('display', 'block');
1003 $(btnObj).parent().append($("#renamegroupdetail"));
1004 $('#renameoldgroupname').val($(btnObj).attr("id"));
1005 $('#renamegroupname').val($(btnObj).attr("id").replace(/^\d+/, ""));
1008 // save the new group to the form
1009 var SaveRenameGroup = function(btnObj) {
1010 // the group name field can only have letters, numbers, spaces and underscores
1011 // AND it cannot start with a number
1012 if ($("#renamegroupname").val().match(/^\d+/)) {
1013 alert("<?php xl('Group names cannot start with numbers.','e'); ?>");
1014 return false;
1016 var validname = $("#renamegroupname").val().replace(/[^A-za-z0-9 ]/g, "_"); // match any non-word characters and replace them
1017 $("#renamegroupname").val(validname);
1019 // submit the form to add a new field to a specific group
1020 $("#formaction").val("renamegroup");
1021 $("#theform").submit();
1024 // just hide the new field DIV
1025 var CancelRenameGroup = function(btnObj) {
1026 // hide the field details DIV
1027 $('#renamegroupdetail').css('visibility', 'hidden');
1028 $('#renamegroupdetail').css('display', 'none');
1029 // reset the rename group values to a default
1030 $('#renameoldgroupname').val("");
1031 $('#renamegroupname').val("");
1034 /****************************************************/
1035 /************ Field functions ***********************/
1036 /****************************************************/
1038 // display the 'new field' DIV
1039 var AddField = function(btnObj) {
1040 // update the fieldgroup value to be the groupid
1041 var btnid = $(btnObj).attr("id");
1042 var parts = btnid.split("~");
1043 var groupid = parts[1];
1044 $('#fielddetail > #newfieldgroupid').attr('value', groupid);
1046 // show the field details DIV
1047 $('#fielddetail').css('visibility', 'visible');
1048 $('#fielddetail').css('display', 'block');
1049 $(btnObj).parent().append($("#fielddetail"));
1052 var DeleteFields = function(btnObj) {
1053 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'); ?>")) {
1054 var delim = "";
1055 $(".selectfield").each(function(i) {
1056 // build a list of selected field names to be moved
1057 if ($(this).attr("checked") == true) {
1058 var parts = this.id.split("~");
1059 var currval = $("#selectedfields").val();
1060 $("#selectedfields").val(currval+delim+parts[1]);
1061 delim = " ";
1064 // submit the form to delete the field(s)
1065 $("#formaction").val("deletefields");
1066 $("#theform").submit();
1070 // save the new field to the form
1071 var SaveNewField = function(btnObj) {
1072 // check the new field values for correct formatting
1074 // seq must be numeric and less than 999
1075 if (! IsNumeric($("#newseq").val(), 0, 999)) {
1076 alert("<?php xl('Order must be a number between 1 and 999','e'); ?>");
1077 return false;
1079 // length must be numeric and less than 999
1080 if (! IsNumeric($("#newlength").val(), 0, 999)) {
1081 alert("<?php xl('Size must be a number between 1 and 999','e'); ?>");
1082 return false;
1084 // titlecols must be numeric and less than 100
1085 if (! IsNumeric($("#newtitlecols").val(), 0, 999)) {
1086 alert("<?php xl('LabelCols must be a number between 1 and 999','e'); ?>");
1087 return false;
1089 // datacols must be numeric and less than 100
1090 if (! IsNumeric($("#newdatacols").val(), 0, 999)) {
1091 alert("<?php xl('DataCols must be a number between 1 and 999','e'); ?>");
1092 return false;
1094 // some fields cannot be blank
1095 if ($("#newtitle").val() == "") {
1096 alert("<?php xl('Label cannot be blank','e'); ?>");
1097 return false;
1099 // the id field can only have letters, numbers and underscores
1100 var validid = $("#newid").val().replace(/(\s|\W)/g, "_"); // match any non-word characters and replace them
1101 $("#newid").val(validid);
1102 // similarly with the listid field
1103 validid = $("#newlistid").val().replace(/(\s|\W)/g, "_");
1104 $("#newlistid").val(validid);
1106 // submit the form to add a new field to a specific group
1107 $("#formaction").val("addfield");
1108 $("#theform").submit();
1111 // just hide the new field DIV
1112 var CancelNewField = function(btnObj) {
1113 // hide the field details DIV
1114 $('#fielddetail').css('visibility', 'hidden');
1115 $('#fielddetail').css('display', 'none');
1116 // reset the new field values to a default
1117 ResetNewFieldValues();
1120 // show the popup choice of lists
1121 var ShowLists = function(btnObj) {
1122 window.open("./show_lists_popup.php", "lists", "width=300,height=500,scrollbars=yes");
1123 selectedfield = btnObj;
1126 // show the popup choice of groups
1127 var ShowGroups = function(btnObj) {
1128 window.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", "groups", "width=300,height=300,scrollbars=yes");
1131 // Show context DD for NationNotes
1132 var ChangeList = function(btnObj){
1133 if(btnObj==34){
1134 $('#newlistid').hide();
1135 $('#contextName').show();
1137 else{
1138 $('#newlistid').show();
1139 $('#contextName').hide();
1142 var ChangeListg = function(btnObj){
1143 if(btnObj==34){
1144 $('#gnewlistid').hide();
1145 $('#gcontextName').show();
1147 else{
1148 $('#gnewlistid').show();
1149 $('#gcontextName').hide();
1155 function NationNotesContext(lineitem,val){
1156 if(val==34){
1157 document.getElementById("fld["+lineitem+"][contextName]").style.display='';
1158 document.getElementById("fld["+lineitem+"][list_id]").style.display='none';
1159 document.getElementById("fld["+lineitem+"][list_id]").value='';
1161 else{
1162 document.getElementById("fld["+lineitem+"][list_id]").style.display='';
1163 document.getElementById("fld["+lineitem+"][contextName]").style.display='none';
1164 document.getElementById("fld["+lineitem+"][list_id]").value='';
1167 function SetList(listid) { $(selectedfield).val(listid); }
1170 /* this is called after the user chooses a new group from the popup window
1171 * it will submit the page so the selected fields can be moved into
1172 * the target group
1174 function MoveFields(targetgroup) {
1175 $("#targetgroup").val(targetgroup);
1176 var delim = "";
1177 $(".selectfield").each(function(i) {
1178 // build a list of selected field names to be moved
1179 if ($(this).attr("checked") == true) {
1180 var parts = this.id.split("~");
1181 var currval = $("#selectedfields").val();
1182 $("#selectedfields").val(currval+delim+parts[1]);
1183 delim = " ";
1186 $("#formaction").val("movefields");
1187 $("#theform").submit();
1191 // set the new-field values to a default state
1192 function ResetNewFieldValues () {
1193 $("#newseq").val("");
1194 $("#newid").val("");
1195 $("#newtitle").val("");
1196 $("#newuor").val(1);
1197 $("#newlength").val("");
1198 $("#newdatatype").val("");
1199 $("#newlistid").val("");
1200 $("#newtitlecols").val("");
1201 $("#newdatacols").val("");
1202 $("#newedit_options").val("");
1203 $("#newdefault").val("");
1204 $("#newdesc").val("");
1207 // is value an integer and between min and max
1208 function IsNumeric(value, min, max) {
1209 if (value == "" || value == null) return false;
1210 if (! IsN(value) ||
1211 parseInt(value) < min ||
1212 parseInt(value) > max)
1213 return false;
1215 return true;
1218 /****************************************************/
1219 /****************************************************/
1220 /****************************************************/
1222 // tell if num is an Integer
1223 function IsN(num) { return !/\D/.test(num); }
1224 </script>
1226 </html>