Designing New Data Type

juggernautsei wrote on Thursday, April 21, 2011:

Below is a snippit of code that I took from the Prescriptions section. I believe this to be the construct for the Drug lookup widget in the prescriptions add fuction. Now, I know just enough to be a little above ignorant with php coding. But I am asking for some brain storming ideas on how to take this or something like this code to build a data_type in the layout based forms section. The over all goal is that I am building an office note for a doctor. The final output of the note will be in paragraph form. But there is a section called Impression Plan. In this section, drugs will have to be prescribed to go in the office note to be sent with the patient. He wants it all in one place instead of having to jump around the program. That is why I am trying to build this into this section. He thinks it is to much to go out of one form into Rx section add drugs then come back. This does not fit his work flow efforts. Of course later the drugs that are put in under the Impression Plan will need to populate into the patients record under prescriptions. Any ideas would be greatly appreciated

<!- for the fancy jQuery stuff ->
<script type=“text/javascript”>
$().ready(function() {
    $("#drug").autocomplete(‘library/ajax/prescription_drugname_lookup.php’,
                            {
                            width: 200,
                            scrollHeight: 100,
                            selectFirst: true
                            });
    $("#drug").focus();
    $("#prescribe").submit(function() { return CheckForErrors(this) });
    $("#druglookup").click(function() { DoDrugLookup(this) });
});

// pop up a drug lookup window with the value of the drug name, if we have one
function DoDrugLookup(eObj) {
    drugname = “”;
    if ($(’#drug’).val() != “”) { drugname = $(’#drug’).val(); }
    drugPopup = window.open(‘controller.php?prescription&lookup&drug=’+drugname, ‘drugPopup’, ‘width=400,height=50,menubar=no,titlebar=no,left = 825,top = 400’);
    drugPopup.opener = self;
    return true;
}

// check the form for required fields before submitting
var CheckForErrors = function(eObj) {
    // REQUIRED FIELDS
    if (CheckRequired(‘drug’) == false) { return false; }
    //if (CheckRequired(‘quantity’) == false) { return false; }
    //if (CheckRequired(‘unit’) == false) { return false; }
    //if (CheckRequired(‘size’) == false) { return false; }
    //if (CheckRequired(‘dosage’) == false) { return false; }
    //if (CheckRequired(‘form’) == false) { return false; }
    //if (CheckRequired(‘route’) == false) { return false; }
    //if (CheckRequired(‘interval’) == false) { return false; }

    return top.restoreSession();
};

function CheckRequired(objID) {

    // for text boxes
    if ($(’#’+objID).is(‘text’)) {
        if ($(’#’+objID).val() == “”) {
            alert(“Missing a required field”);
            $(’#’+objID).css(“backgroundColor”, “pink”);
            return false;
        }
    }

    // for select boxes
    if ($(’#’+objID).is(‘select’)) {
        if ($(’#’+objID).val() == “0”) {
            alert(“Missing a required field”);
            $(’#’+objID).css(“backgroundColor”, “pink”);
            return false;
        }
    }

    return true;
}

</script>

Sherwin
www.openmedpractice.com

juggernautsei wrote on Thursday, April 21, 2011:

Below is the Edit_Layout.php code. I am getting an error message

Fatal error: Call to undefined function x1() in C:\xampp\htdocs\east-test\interface\super\edit_layout.php on line 51

What am I missing?

<?php
// Copyright (C) 2007-2009 Rod Roark <rod@sunsetsystems.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

require_once("…/globals.php");
require_once("$srcdir/acl.inc");
require_once("$srcdir/log.inc");
require_once("$srcdir/formdata.inc.php");

$layouts = array(
  ‘DEM’ => xl(‘Demographics’),
  ‘HIS’ => xl(‘History’),
  ‘REF’ => xl(‘Referrals’),
);
if ($GLOBALS) {
  $layouts = xl(‘Abortion Issues’);
  $layouts = xl(‘Contraception Issues’);
  // $layouts = xl(‘SRH Visit Form’);
}

// Include Layout Based Encounter Forms.
$lres = sqlStatement("SELECT * FROM list_options " .
  “WHERE list_id = ‘lbfnames’ ORDER BY seq, title”);
while ($lrow = sqlFetchArray($lres)) {
  $layouts[$lrow] = $lrow;
}

// array of the data_types of the fields
$datatypes = array(
  “1”  => xl(“List box”),
  “2”  => xl(“Textbox”),
  “3”  => xl(“Textarea”),
  “4”  => xl(“Text-date”),
  “10” => xl(“Providers”),
  “11” => xl(“Providers NPI”),
  “12” => xl(“Pharmacies”),
  “13” => xl(“Squads”),
  “14” => xl(“Organizations”),
  “15” => xl(“Billing codes”),
  “21” => xl(“Checkbox list”),
  “22” => xl(“Textbox list”),
  “23” => xl(“Exam results”),
  “24” => xl(“Patient allergies”),
  “25” => xl(“Checkbox w/text”),
  “26” => xl(“List box w/add”),
  “27” => xl(“Radio buttons”),
  “28” => x1(“Drug List”),
);

function nextGroupOrder($order) {
  if ($order == ‘9’) $order = ‘A’;
  else if ($order == ‘Z’) $order = ‘a’;
  else $order = chr(ord($order) + 1);
  return $order;
}

// Check authorization.
$thisauth = acl_check(‘admin’, ‘super’);
if (!$thisauth) die(xl(‘Not authorized’));

// The layout ID identifies the layout to be edited.
$layout_id = empty($_REQUEST) ? ‘’ : $_REQUEST;

// Handle the Form actions

if ($_POST == “save” && $layout_id) {
    // If we are saving, then save.
    $fld = $_POST;
    for ($lino = 1; isset($fld); ++$lino) {
        $iter = $fld;
        $field_id = formTrim($iter);
        $data_type = formTrim($iter);
        // For a textarea (data type 3) max_length has a special meaning, to
        // specify its height (in rows).  This kludge assigns a fixed height,
        // but this GUI really needs to support max_length directly.
        $max_length = $data_type == 3 ? 3 : 255;
        if ($field_id) {
            sqlStatement("UPDATE layout_options SET " .
                “title = '”         . formTrim($iter)     . "’, " .
                “group_name = '”    . formTrim($iter)     . "’, " .
                “seq = '”           . formTrim($iter)       . "’, " .
                “uor = '”           . formTrim($iter)       . "’, " .
                “fld_length = '”    . formTrim($iter)    . "’, " .
                "max_length = ‘$max_length’, "                             .
                “titlecols = '”     . formTrim($iter) . "’, " .
                “datacols = '”      . formTrim($iter)  . "’, " .
                "data_type= ‘$data_type’, "                                .
                “list_id= '”        . formTrim($iter)   . "’, " .
                “default_value = '” . formTrim($iter)   . "’, " .
                “description = '”   . formTrim($iter)      . "’ " .
                “WHERE form_id = ‘$layout_id’ AND field_id = ‘$field_id’”);
        }
    }
}

else if ($_POST == “addfield” && $layout_id) {
    // Add a new field to a specific group
    $data_type = formTrim($_POST);
    $max_length = $data_type == 3 ? 3 : 255;
    sqlStatement(“INSERT INTO layout_options (” .
      " form_id, field_id, title, group_name, seq, uor, fld_length" .
      “, titlecols, datacols, data_type, default_value, description” .
      ", max_length, list_id " .
      “) VALUES ( " .
      “’”  . formTrim($_POST      ) . “’” .
      “,’” . formTrim($_POST          ) . “’” .
      “,’” . formTrim($_POST       ) . “’” .
      “,’” . formTrim($_POST) . “’” .
      “,’” . formTrim($_POST         ) . “’” .
      “,’” . formTrim($_POST         ) . “’” .
      “,’” . formTrim($_POST      ) . “’” .
      “,’” . formTrim($_POST   ) . “’” .
      “,’” . formTrim($_POST    ) . “’” .
      “,’$data_type’”                                  .
      “,’” . formTrim($_POST     ) . “’” .
      “,’” . formTrim($_POST        ) . “’” .
      “,’$max_length’”                                 .
      “,’” . formTrim($_POST      ) . “’” .
      " )”);

    if (substr($layout_id,0,3) != ‘LBF’) {
      // Add the field to the table too (this is critical)
      if ($layout_id == “DEM”) { $tablename = “patient_data”; }
      else if ($layout_id == “HIS”) { $tablename = “history_data”; }
      else if ($layout_id == “REF”) { $tablename = “transactions”; }
      else if ($layout_id == “SRH”) { $tablename = “lists_ippf_srh”; }
      else if ($layout_id == “CON”) { $tablename = “lists_ippf_con”; }
      else if ($layout_id == “GCA”) { $tablename = “lists_ippf_gcac”; }
      sqlStatement(“ALTER TABLE `” . $tablename . "` ADD “.
                      “`” . formTrim($_POST) . “`” .
                      " VARCHAR( 255 )”);
      newEvent(“alter_table”, $_SESSION, $_SESSION,
        $tablename . " ADD " . formTrim($_POST));
    }
}

else if ($_POST == “movefields” && $layout_id) {
    // Move field(s) to a new group in the layout
    $sqlstmt = “UPDATE layout_options SET “.
                " group_name=’”. $_POST.”’ “.
                " WHERE “.
                " form_id = '”.$_POST.”’ “.
                " AND field_id IN (”;
    $comma = “”;
    foreach (explode(" “, $_POST) as $onefield) {
        $sqlstmt .= $comma.”’".$onefield."’";
        $comma = ", ";
    }
    $sqlstmt .= “)”;
    //echo $sqlstmt;
    sqlStatement($sqlstmt);
}

else if ($_POST == “deletefields” && $layout_id) {
    // Delete a field from a specific group
    $sqlstmt = “DELETE FROM layout_options WHERE “.
                " form_id = '”.$_POST.”’ “.
                " AND field_id IN (”;
    $comma = “”;
    foreach (explode(" “, $_POST) as $onefield) {
        $sqlstmt .= $comma.”’".$onefield."’";
        $comma = ", ";
    }
    $sqlstmt .= “)”;
    sqlStatement($sqlstmt);

    if (substr($layout_id,0,3) != ‘LBF’) {
        // drop the field from the table too (this is critical)
        if ($layout_id == “DEM”) { $tablename = “patient_data”; }
        else if ($layout_id == “HIS”) { $tablename = “history_data”; }
        else if ($layout_id == “REF”) { $tablename = “transactions”; }
        else if ($layout_id == “SRH”) { $tablename = “lists_ippf_srh”; }
        else if ($layout_id == “CON”) { $tablename = “lists_ippf_con”; }
        else if ($layout_id == “GCA”) { $tablename = “lists_ippf_gcac”; }
        foreach (explode(" “, $_POST) as $onefield) {
            sqlStatement(“ALTER TABLE `”.$tablename.”` DROP `".$onefield."`");
            newEvent(“alter_table”, $_SESSION, $_SESSION, $tablename." DROP ".$onefield);
        }
    }
}

else if ($_POST == “addgroup” && $layout_id) {
    // all group names are prefixed with a number indicating their display order
    // this new group is prefixed with the net highest number given the
    // layout_id
    $results = sqlStatement(“select distinct(group_name) as gname “.
                        " from layout_options where “.
                        " form_id = '”.$_POST.”’”
                        );
    $maxnum = ‘1’;
    while ($result = sqlFetchArray($results)) {
      $tmp = substr($result, 0, 1);
      if ($tmp >= $maxnum) $maxnum = nextGroupOrder($tmp);
    }

    $data_type = formTrim($_POST);
    $max_length = $data_type == 3 ? 3 : 255;

    // add a new group to the layout, with the defined field
    sqlStatement(“INSERT INTO layout_options (” .
      " form_id, field_id, title, group_name, seq, uor, fld_length" .
      “, titlecols, datacols, data_type, default_value, description” .
      ", max_length, list_id " .
      “) VALUES ( " .
      “’”  . formTrim($_POST      ) . “’” .
      “,’” . formTrim($_POST          ) . “’” .
      “,’” . formTrim($_POST       ) . “’” .
      “,’” . formTrim($maxnum . $_POST) . “’” .
      “,’” . formTrim($_POST         ) . “’” .
      “,’” . formTrim($_POST         ) . “’” .
      “,’” . formTrim($_POST      ) . “’” .
      “,’” . formTrim($_POST   ) . “’” .
      “,’” . formTrim($_POST    ) . “’” .
      “,’$data_type’”                                   .
      “,’” . formTrim($_POST     ) . “’” .
      “,’” . formTrim($_POST        ) . “’” .
      “,’$max_length’”                                  .
      “,’” . formTrim($_POST      ) . “’” .
      " )”);

    if (substr($layout_id,0,3) != ‘LBF’) {
      // Add the field to the table too (this is critical)
      if ($layout_id == “DEM”) { $tablename = “patient_data”; }
      else if ($layout_id == “HIS”) { $tablename = “history_data”; }
      else if ($layout_id == “REF”) { $tablename = “transactions”; }
      else if ($layout_id == “SRH”) { $tablename = “lists_ippf_srh”; }
      else if ($layout_id == “CON”) { $tablename = “lists_ippf_con”; }
      else if ($layout_id == “GCA”) { $tablename = “lists_ippf_gcac”; }
      sqlStatement(“ALTER TABLE `” . $tablename . "` ADD “.
                      “`” . formTrim($_POST) . “`” .
                      " VARCHAR( 255 )”);
      newEvent(“alter_table”, $_SESSION, $_SESSION,
        $tablename . " ADD " . formTrim($_POST));
    }
}

else if ($_POST == “deletegroup” && $layout_id) {
    // drop the fields from the related table (this is critical)
    if (substr($layout_id,0,3) != ‘LBF’) {
        $res = sqlStatement(“SELECT field_id FROM layout_options WHERE " .
                            " form_id = '”.$_POST."’ “.
                            " AND group_name = '”.$_POST."’"
                            );
        while ($row = sqlFetchArray($res)) {
            // drop the field from the table too (this is critical)
            if ($layout_id == “DEM”) { $tablename = “patient_data”; }
            else if ($layout_id == “HIS”) { $tablename = “history_data”; }
            else if ($layout_id == “REF”) { $tablename = “transactions”; }
            else if ($layout_id == “SRH”) { $tablename = “lists_ippf_srh”; }
            else if ($layout_id == “CON”) { $tablename = “lists_ippf_con”; }
            else if ($layout_id == “GCA”) { $tablename = “lists_ippf_gcac”; }
            sqlStatement(“ALTER TABLE `”.$tablename."` DROP `".$row."`");
            newEvent(“alter_table”, $_SESSION, $_SESSION, $tablename." DROP ".trim($row));
        }
    }

    // Delete an entire group from the form
    sqlStatement(“DELETE FROM layout_options WHERE “.
                " form_id = '”.$_POST.”’ “.
                " AND group_name = '”.$_POST."’"
                );
}

else if ($_POST == “movegroup” && $layout_id) {
  $results = sqlStatement("SELECT DISTINCT(group_name) AS gname " .
    "FROM layout_options WHERE form_id = ‘$layout_id’ " .
    “ORDER BY gname”);
  $garray = array();
  $i = 0;
  while ($result = sqlFetchArray($results)) {
    if ($result == $_POST) {
      if ($_POST == ‘up’) { // moving up
        if ($i > 0) {
          $garray = $garray;
          $garray = $result;
          $i++;
        }
        else {
          $garray = $result;
        }
      }
      else { // moving down
        $garray = ‘’;
        $garray = $result;
      }
    }
    else if ($i > 1 && $garray == ‘’) {
      $garray = $result;
    }
    else {
      $garray = $result;
    }
  }
  $nextord = ‘1’;
  foreach ($garray as $value) {
    if ($value === ‘’) continue;
    $newname = $nextord . substr($value, 1);
    sqlStatement("UPDATE layout_options SET " .
      "group_name = ‘$newname’ WHERE " .
      "form_id = ‘$layout_id’ AND " .
      “group_name = ‘$value’”);
    $nextord = nextGroupOrder($nextord);
  }
}

else if ($_POST == “renamegroup” && $layout_id) {
  $currpos = substr($_POST, 0, 1);
  // update the database rows
  sqlStatement("UPDATE layout_options SET " .
    “group_name = '” . $currpos . $_POST . "’ ".
    "WHERE form_id = ‘$layout_id’ AND ".
    “group_name = '” . $_POST . “’”);
}

// Get the selected form’s elements.
if ($layout_id) {
  $res = sqlStatement("SELECT * FROM layout_options WHERE " .
    “form_id = ‘$layout_id’ ORDER BY group_name, seq”);
}

// global counter for field numbers
$fld_line_no = 0;

// Write one option line to the form.
//
function writeFieldLine($linedata) {
    global $fld_line_no;
    ++$fld_line_no;
    $checked = $linedata ? " checked" : “”;
 
    //echo " <tr bgcolor=’$bgcolor’>\n";
    echo " <tr id=‘fld’ class=’".($fld_line_no % 2 ? ‘even’ : ‘odd’)."’>\n";
 
    echo "  <td class=‘optcell’ nowrap>";
    // tuck the group_name INPUT in here
    echo “<input type=‘hidden’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ class=‘optin’ />”;

    echo “<input type=‘checkbox’ class=‘selectfield’ “.
            “name=’”.$linedata.”~”.$linedata."’ “.
            “id=’”.$linedata.”~".$linedata."’ “.
            “title=’”.htmlspecialchars(xl(‘Select field’, ENT_QUOTES)).”’>";

    echo “<input type=‘text’ name=‘fld’ id=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘2’ maxlength=‘3’ class=‘optin’ />”;
    echo “</td>\n”;
 
    echo "  <td align=‘left’ class=‘optcell’>";
    echo “<input type=‘text’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘15’ maxlength=‘63’ class=‘optin noselect’ />”;
    /*
    echo “<input type=‘hidden’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ />”;
    echo htmlspecialchars($linedata, ENT_QUOTES);
    */
    echo “</td>\n”;
 
    echo "  <td align=‘center’ class=‘optcell’>";
    echo “<input type=‘text’ id=‘fld’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘15’ maxlength=‘63’ class=‘optin’ />”;
    echo “</td>\n”;

    // if not english and set to translate layout labels, then show the translation
    if ($GLOBALS && $_SESSION > 1) {
        echo “<td align=‘center’ class=‘translation’>” . htmlspecialchars(xl($linedata), ENT_QUOTES) . “</td>\n”;
    }

    echo "  <td align=‘center’ class=‘optcell’>";
    echo “<select name=‘fld’ class=‘optin’>”;
    foreach (array(0 =>xl(‘Unused’), 1 =>xl(‘Optional’), 2 =>xl(‘Required’)) as $key => $value) {
        echo “<option value=’$key’”;
        if ($key == $linedata) echo " selected";
        echo “>$value</option>\n”;
    }
    echo “</select>”;
    echo “</td>\n”;
 
    echo "  <td align=‘center’ class=‘optcell’>";
    echo “<select name=‘fld’ id=‘fld’>”;
    echo “<option value=’’></option>”;
    GLOBAL $datatypes;
    foreach ($datatypes as $key=>$value) {
        if ($linedata == $key)
            echo “<option value=’$key’ selected>$value</option>”;
        else
            echo “<option value=’$key’>$value</option>”;
    }
    echo “</select>”;
    echo "  </td>";

    echo "  <td align=‘center’ class=‘optcell’>";
    if ($linedata == 2 || $linedata == 3 ||
      $linedata == 21 || $linedata == 22 ||
      $linedata == 23 || $linedata == 25 ||
      $linedata == 27 || $linedata == 28)
    {
      echo “<input type=‘text’ name=‘fld’ value=’” .
        htmlspecialchars($linedata, ENT_QUOTES) .
        “’ size=‘1’ maxlength=‘10’ class=‘optin’ />”;
    }
    else {
      // all other data_types
      echo “<input type=‘hidden’ name=‘fld’ value=’’>”;
    }
    echo “</td>\n”;

    echo "  <td align=‘center’ class=‘optcell’>";
    if ($linedata ==  1 || $linedata == 21 ||
      $linedata == 22 || $linedata == 23 ||
      $linedata == 25 || $linedata == 26 ||
      $linedata == 27 || $linedata == 28)
    {
      echo “<input type=‘text’ name=‘fld’ value=’” .
        htmlspecialchars($linedata, ENT_QUOTES) . “’”.
        “size=‘6’ maxlength=‘30’ class=‘optin listid’ style=‘cursor: pointer’”.
        “title=’”. xl(‘Choose list’) . “’ />”;
    }
    else {
      // all other data_types
      echo “<input type=‘hidden’ name=‘fld’ value=’’>”;
    }
    echo “</td>\n”;

    echo "  <td align=‘center’ class=‘optcell’>";
    echo “<input type=‘text’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘3’ maxlength=‘10’ class=‘optin’ />”;
    echo “</td>\n”;
 
    echo "  <td align=‘center’ class=‘optcell’>";
    echo “<input type=‘text’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘3’ maxlength=‘10’ class=‘optin’ />”;
    echo “</td>\n”;

    echo "  <td align=‘center’ class=‘optcell’>";
    if ($linedata == 2) {
      echo “<input type=‘text’ name=‘fld’ value=’” .
           htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘10’ maxlength=‘63’ class=‘optin’ />”;
    } else {
      echo “&nbsp;”;
    }
    echo “</td>\n”;
 
    echo "  <td align=‘center’ class=‘optcell’>";
    echo “<input type=‘text’ name=‘fld’ value=’” .
         htmlspecialchars($linedata, ENT_QUOTES) . “’ size=‘20’ maxlength=‘63’ class=‘optin’ />”;
    echo “</td>\n”;

    // if not english and showing layout labels, then show the translation of Description
    if ($GLOBALS && $_SESSION > 1) {
     echo “<td align=‘center’ class=‘translation’>” . htmlspecialchars(xl($linedata), ENT_QUOTES) . “</td>\n”;
    }
   
    echo " </tr>\n";
}
?>
<html>

<head>
<?php html_header_show();?>

<!- supporting javascript code ->
<script type=“text/javascript” src="<?php echo $GLOBALS ?>/library/js/jquery.js"></script>

<link rel=“stylesheet” href=’<?php  echo $css_header ?>’ type=‘text/css’>

<title><?php  xl(‘Layout Editor’,‘e’); ?></title>

<style>
tr.head   { font-size:10pt; background-color:#cccccc; }
tr.detail { font-size:10pt; }
td        { font-size:10pt; }
input     { font-size:10pt; }
a, a:visited, a:hover { color:#0000cc; }
.optcell  { }
.optin    { background: transparent; }
.group {
    margin: 0pt 0pt 8pt 0pt;
    padding: 0;
    width: 100%;
}
.group table {
    border-collapse: collapse;
    width: 100%;
}
.odd td {
    background-color: #ddddff;
    padding: 3px 0px 3px 0px;
}
.even td {
    background-color: #ffdddd;
    padding: 3px 0px 3px 0px;
}
.help { cursor: help; }
.layouts_title { font-size: 110%; }
.translation {
    color: green;
    font-size:10pt;
}
.highlight * {
    border: 2px solid blue;
    background-color: yellow;
    color: black;
}
</style>

</head>

<body class=“body_top”>

<form method=‘post’ name=‘theform’ id=‘theform’ action=‘edit_layout.php’>
<input type=“hidden” name=“formaction” id=“formaction” value="">
<!- elements used to identify a field to delete ->
<input type=“hidden” name=“deletefieldid” id=“deletefieldid” value="">
<input type=“hidden” name=“deletefieldgroup” id=“deletefieldgroup” value="">
<!- elements used to identify a group to delete ->
<input type=“hidden” name=“deletegroupname” id=“deletegroupname” value="">
<!- elements used to change the group order ->
<input type=“hidden” name=“movegroupname” id=“movegroupname” value="">
<input type=“hidden” name=“movedirection” id=“movedirection” value="">
<!- elements used to select more than one field ->
<input type=“hidden” name=“selectedfields” id=“selectedfields” value="">
<input type=“hidden” id=“targetgroup” name=“targetgroup” value="">

<p><b><?php xl(‘Edit layout’,‘e’); ?>:</b>&nbsp;
<select name=‘layout_id’ id=‘layout_id’>
<option value=’’>- <?php echo xl(‘Select’) ?> -</option>
<?php
foreach ($layouts as $key => $value) {
  echo " <option value=’$key’";
  if ($key == $layout_id) echo " selected";
  echo “>$value</option>\n”;
}
?>
</select></p>

<?php if ($layout_id) { ?>
<div style=‘margin: 0 0 8pt 0;’>
<input type=‘button’ class=‘addgroup’ id=‘addgroup’ value=<?php xl(‘Add Group’,‘e’,’’’,’’’); ?>/>
</div>
<?php } ?>

<?php
$prevgroup = “!@#asdf1234”; // an unlikely group name
$firstgroup = true; // flag indicates it’s the first group to be displayed
while ($row = sqlFetchArray($res)) {
  if ($row != $prevgroup) {
    if ($firstgroup == false) { echo “</tbody></table></div>\n”; }
    echo “<div id=’”.$row."’ class=‘group’>";
    echo “<div class=‘text bold layouts_title’ style=‘position:relative; background-color: #eef’>”;
    // echo preg_replace("/^\d+/", “”, $row);
    echo substr($row, 1);
    echo “&nbsp; “;
    // if not english and set to translate layout labels, then show the translation of group name
    if ($GLOBALS && $_SESSION > 1) {
      // echo “<span class=‘translation’>>>&nbsp; " . xl(preg_replace(”/^\d+/”, “”, $row)) . “</span>”;
      echo “<span class=‘translation’>>>&nbsp; " . xl(substr($row, 1)) . “</span>”;
      echo “&nbsp; “;
    }
    echo “&nbsp; “;
    echo " <input type=‘button’ class=‘addfield’ id='addto~”.$row.”’ value=’” . xl(‘Add Field’) . “’/>”;
    echo “&nbsp; &nbsp; “;
    echo " <input type=‘button’ class=‘renamegroup’ id=’”.$row.”’ value=’” . xl(‘Rename Group’) . “’/>”;
    echo “&nbsp; &nbsp; “;
    echo " <input type=‘button’ class=‘deletegroup’ id=’”.$row.”’ value=’” . xl(‘Delete Group’) . “’/>”;
    echo “&nbsp; &nbsp; “;
    echo " <input type=‘button’ class=‘movegroup’ id=’”.$row.”~up’ value=’” . xl(‘Move Up’) . “’/>”;
    echo “&nbsp; &nbsp; “;
    echo " <input type=‘button’ class=‘movegroup’ id=’”.$row.”~down’ value=’" . xl(‘Move Down’) . “’/>”;
    echo “</div>”;
    $firstgroup = false;
?>

<table>
<thead>
<tr class=‘head’>
  <th><?php xl(‘Order’,‘e’); ?></th>
  <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>
  <th><?php xl(‘Label’,‘e’); ?> <span class=“help” title=<?php xl(‘The label that appears to the user on the form’,‘e’,’’’,’’’); ?> >(?)</span></th>
  <?php // if not english and showing layout label translations, then show translation header for title
  if ($GLOBALS && $_SESSION > 1) {
   echo “<th>” . xl(‘Translation’)."<span class=‘help’ title=’" . xl(‘The translated label that will appear on the form in current language’) . “’> (?)</span></th>”;
  } ?>  
  <th><?php xl(‘UOR’,‘e’); ?></th>
  <th><?php xl(‘Data Type’,‘e’); ?></th>
  <th><?php xl(‘Size’,‘e’); ?></th>
  <th><?php xl(‘List’,‘e’); ?></th>
  <th><?php xl(‘Label Cols’,‘e’); ?></th>
  <th><?php xl(‘Data Cols’,‘e’); ?></th>
  <th><?php xl(‘Default Value’,‘e’); ?></th>
  <th><?php xl(‘Description’,‘e’); ?></th>
  <?php // if not english and showing layout label translations, then show translation header for description
  if ($GLOBALS && $_SESSION > 1) {
   echo “<th>” . xl(‘Translation’)."<span class=‘help’ title=’" . xl(‘The translation of description in current language’)."’> (?)</span></th>";
  } ?>
</tr>
</thead>
<tbody>

<?php
    } // end if-group_name

    writeFieldLine($row);
    $prevgroup = $row;

} // end while loop

?>
</tbody>
</table></div>

<?php if ($layout_id) { ?>
<span style=“font-size:90%”>
<?php xl(‘With selected:’, ‘e’);?>
<input type=‘button’ name=‘deletefields’ id=‘deletefields’ value=’<?php xl(‘Delete’,‘e’); ?>’ style=“font-size:90%” disabled=“disabled” />
<input type=‘button’ name=‘movefields’ id=‘movefields’ value=’<?php xl(‘Move to…’,‘e’); ?>’ style=“font-size:90%” disabled=“disabled” />
</span>
<p>
<input type=‘button’ name=‘save’ id=‘save’ value=’<?php xl(‘Save Changes’,‘e’); ?>’ />
</p>
<?php } ?>

</form>

<!- template DIV that appears when user chooses to rename an existing group ->
<div id=“renamegroupdetail” style=“border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;”>
<input type=“hidden” name=“renameoldgroupname” id=“renameoldgroupname” value="">
<?php xl(‘Group Name’,‘e’); ?>: <input type=“textbox” size=“20” maxlength=“30” name=“renamegroupname” id=“renamegroupname”>
<br>
<input type=“button” class=“saverenamegroup” value=<?php xl(‘Rename Group’,‘e’,’’’,’’’); ?>>
<input type=“button” class=“cancelrenamegroup” value=<?php xl(‘Cancel’,‘e’,’’’,’’’); ?>>
</div>

<!- template DIV that appears when user chooses to add a new group ->
<div id=“groupdetail” style=“border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;”>
<span class=‘bold’>
<?php xl(‘Group Name’,‘e’); ?>: <input type=“textbox” size=“20” maxlength=“30” name=“newgroupname” id=“newgroupname”>
<br>
<table style=“border-collapse: collapse; margin-top: 5px;”>
<thead>
<tr class=‘head’>
  <th><?php xl(‘Order’,‘e’); ?></th>
  <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>
  <th><?php xl(‘Label’,‘e’); ?> <span class=“help” title=<?php xl(‘The label that appears to the user on the form’,‘e’,’’’,’’’); ?> >(?)</span></th>
  <th><?php xl(‘UOR’,‘e’); ?></th>
  <th><?php xl(‘Data Type’,‘e’); ?></th>
  <th><?php xl(‘Size’,‘e’); ?></th>
  <th><?php xl(‘List’,‘e’); ?></th>
  <th><?php xl(‘Label Cols’,‘e’); ?></th>
  <th><?php xl(‘Data Cols’,‘e’); ?></th>
  <th><?php xl(‘Default Value’,‘e’); ?></th>
  <th><?php xl(‘Description’,‘e’); ?></th>
</tr>
</thead>
<tbody>
<tr class=‘center’>
<td ><input type=“textbox” name=“gnewseq” id=“gnewseq” value="" size=“2” maxlength=“3”> </td>
<td ><input type=“textbox” name=“gnewid” id=“gnewid” value="" size=“10” maxlength=“20”> </td>
<td><input type=“textbox” name=“gnewtitle” id=“gnewtitle” value="" size=“20” maxlength=“63”> </td>
<td>
<select name=“gnewuor” id=“gnewuor”>
<option value=“0”><?php xl(‘Unused’,‘e’); ?></option>
<option value=“1” selected><?php xl(‘Optional’,‘e’); ?></option>
<option value=“2”><?php xl(‘Required’,‘e’); ?></option>
</select>
</td>
<td align=‘center’>
<select name=‘gnewdatatype’ id=‘gnewdatatype’>
<option value=’’></option>
<?php
global $datatypes;
foreach ($datatypes as $key=>$value) {
    echo “<option value=’$key’>$value</option>”;
}
?>
</select>
</td>
<td><input type=“textbox” name=“gnewlength” id=“gnewlength” value="" size=“1” maxlength=“3”> </td>
<td><input type=“textbox” name=“gnewlistid” id=“gnewlistid” value="" size=“8” maxlength=“31” class=“listid”> </td>
<td><input type=“textbox” name=“gnewtitlecols” id=“gnewtitlecols” value="" size=“3” maxlength=“3”> </td>
<td><input type=“textbox” name=“gnewdatacols” id=“gnewdatacols” value="" size=“3” maxlength=“3”> </td>
<td><input type=“textbox” name=“gnewdefault” id=“gnewdefault” value="" size=“20” maxlength=“63”> </td>
<td><input type=“textbox” name=“gnewdesc” id=“gnewdesc” value="" size=“20” maxlength=“63”> </td>
</tr>
</tbody>
</table>
<br>
<input type=“button” class=“savenewgroup” value=<?php xl(‘Save New Group’,‘e’,’’’,’’’); ?>>
<input type=“button” class=“cancelnewgroup” value=<?php xl(‘Cancel’,‘e’,’’’,’’’); ?>>
</span>
</div>

<!- template DIV that appears when user chooses to add a new field to a group ->
<div id=“fielddetail” class=“fielddetail” style=“display: none; visibility: hidden”>
<input type=“hidden” name=“newfieldgroupid” id=“newfieldgroupid” value="">
<table style=“border-collapse: collapse;”>
<thead>
  <tr class=‘head’>
   <th><?php xl(‘Order’,‘e’); ?></th>
   <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>
   <th><?php xl(‘Label’,‘e’); ?> <span class=“help” title=<?php xl(‘The label that appears to the user on the form’,‘e’,’’’,’’’); ?> >(?)</span></th>
   <th><?php xl(‘UOR’,‘e’); ?></th>
   <th><?php xl(‘Data Type’,‘e’); ?></th>
   <th><?php xl(‘Size’,‘e’); ?></th>
   <th><?php xl(‘List’,‘e’); ?></th>
   <th><?php xl(‘Label Cols’,‘e’); ?></th>
   <th><?php xl(‘Data Cols’,‘e’); ?></th>
   <th><?php xl(‘Default Value’,‘e’); ?></th>
   <th><?php xl(‘Description’,‘e’); ?></th>
  </tr>
</thead>
<tbody>
  <tr class=‘center’>
   <td ><input type=“textbox” name=“newseq” id=“newseq” value="" size=“2” maxlength=“3”> </td>
   <td ><input type=“textbox” name=“newid” id=“newid” value="" size=“10” maxlength=“20”> </td>
   <td><input type=“textbox” name=“newtitle” id=“newtitle” value="" size=“20” maxlength=“63”> </td>
   <td>
    <select name=“newuor” id=“newuor”>
     <option value=“0”><?php xl(‘Unused’,‘e’); ?></option>
     <option value=“1” selected><?php xl(‘Optional’,‘e’); ?></option>
     <option value=“2”><?php xl(‘Required’,‘e’); ?></option>
    </select>
   </td>
   <td align=‘center’>
    <select name=‘newdatatype’ id=‘newdatatype’>
     <option value=’’></option>
<?php
global $datatypes;
foreach ($datatypes as $key=>$value) {
    echo "     <option value=’$key’>$value</option>\n";
}
?>
    </select>
   </td>
   <td><input type=“textbox” name=“newlength” id=“newlength” value="" size=“1” maxlength=“3”> </td>
   <td><input type=“textbox” name=“newlistid” id=“newlistid” value="" size=“8” maxlength=“31” class=“listid”> </td>
   <td><input type=“textbox” name=“newtitlecols” id=“newtitlecols” value="" size=“3” maxlength=“3”> </td>
   <td><input type=“textbox” name=“newdatacols” id=“newdatacols” value="" size=“3” maxlength=“3”> </td>
   <td><input type=“textbox” name=“newdefault” id=“newdefault” value="" size=“20” maxlength=“63”> </td>
   <td><input type=“textbox” name=“newdesc” id=“newdesc” value="" size=“20” maxlength=“63”> </td>
  </tr>
  <tr>
   <td colspan=“9”>
    <input type=“button” class=“savenewfield” value=<?php xl(‘Save New Field’,‘e’,’’’,’’’); ?>>
    <input type=“button” class=“cancelnewfield” value=<?php xl(‘Cancel’,‘e’,’’’,’’’); ?>>
   </td>
  </tr>
</tbody>
</table>
</div>

</body>

<script language=“javascript”>

// used when selecting a list-name for a field
var selectedfield;

// jQuery stuff to make the page a little easier to use

$(document).ready(function(){
    $("#save").click(function() { SaveChanges(); });
    $("#layout_id").change(function() { $(’#theform’).submit(); });

    $(".addgroup").click(function() { AddGroup(this); });
    $(".savenewgroup").click(function() { SaveNewGroup(this); });
    $(".deletegroup").click(function() { DeleteGroup(this); });
    $(".cancelnewgroup").click(function() { CancelNewGroup(this); });

    $(".movegroup").click(function() { MoveGroup(this); });

    $(".renamegroup").click(function() { RenameGroup(this); });
    $(".saverenamegroup").click(function() { SaveRenameGroup(this); });
    $(".cancelrenamegroup").click(function() { CancelRenameGroup(this); });

    $(".addfield").click(function() { AddField(this); });
    $("#deletefields").click(function() { DeleteFields(this); });
    $(".selectfield").click(function() {
        var TRparent = $(this).parent().parent();
        $(TRparent).children(“td”).toggleClass(“highlight”);
        // disable the delete-move buttons
        $("#deletefields").attr(“disabled”, “disabled”);
        $("#movefields").attr(“disabled”, “disabled”);
        $(".selectfield").each(function(i) {
            // if any field is selected, enable the delete-move buttons
            if ($(this).attr(“checked”) == true) {
                $("#deletefields").removeAttr(“disabled”);
                $("#movefields").removeAttr(“disabled”);
            }
        });
    });
    $("#movefields").click(function() { ShowGroups(this); });
    $(".savenewfield").click(function() { SaveNewField(this); });
    $(".cancelnewfield").click(function() { CancelNewField(this); });
    $("#newtitle").blur(function() { if ($("#newid").val() == “”) $("#newid").val($("#newtitle").val()); });

    $(".listid").click(function() { ShowLists(this); });

    // special class that skips the element
    $(".noselect").focus(function() { $(this).blur(); });

    // Save the changes made to the form
    var SaveChanges = function () {
        $("#formaction").val(“save”);
        $("#theform").submit();
    }

    /****************************************************/
    /************ Group functions ***********************/
    /****************************************************/

    // display the ‘new group’ DIV
    var AddGroup = function(btnObj) {
        // show the field details DIV
        $(’#groupdetail’).css(‘visibility’, ‘visible’);
        $(’#groupdetail’).css(‘display’, ‘block’);
        $(btnObj).parent().append($("#groupdetail"));
        $(’#groupdetail > #newgroupname’).focus();
    };

    // save the new group to the form
    var SaveNewGroup = function(btnObj) {
        // the group name field can only have letters, numbers, spaces and underscores
        // AND it cannot start with a number
        if ($("#newgroupname").val() == “”) {
            alert("<?php xl(‘Group names cannot be blank’, ‘e’); ?>");
            return false;
        }
        if ($("#newgroupname").val().match(/^(\d+|\s+)/)) {
            alert("<?php xl(‘Group names cannot start with numbers or spaces.’,‘e’); ?>");
            return false;
        }
        var validname = $("#newgroupname").val().replace(//g, “_”); // match any non-word characters and replace them
        $("#newgroupname").val(validname);

        // now, check the first group field values
       
        // seq must be numeric and less than 999
        if (! IsNumeric($("#gnewseq").val(), 0, 999)) {
            alert("<?php xl(‘Order must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // length must be numeric and less than 999
        if (! IsNumeric($("#gnewlength").val(), 0, 999)) {
            alert("<?php xl(‘Size must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // titlecols must be numeric and less than 100
        if (! IsNumeric($("#gnewtitlecols").val(), 0, 999)) {
            alert("<?php xl(‘LabelCols must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // datacols must be numeric and less than 100
        if (! IsNumeric($("#gnewdatacols").val(), 0, 999)) {
            alert("<?php xl(‘DataCols must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // some fields cannot be blank
        if ($("#gnewtitle").val() == “”) {
            alert("<?php xl(‘Label cannot be blank’,‘e’); ?>");
            return false;
        }
        // the id field can only have letters, numbers and underscores
        if ($("#gnewid").val() == “”) {
            alert("<?php xl(‘ID cannot be blank’, ‘e’); ?>");
            return false;
        }
        var validid = $("#gnewid").val().replace(/(\s|\W)/g, “_”); // match any non-word characters and replace them
        $("#gnewid").val(validid);
        // similarly with the listid field
        validid = $("#gnewlistid").val().replace(/(\s|\W)/g, “_”);
        $("#gnewlistid").val(validid);

        // submit the form to add a new field to a specific group
        $("#formaction").val(“addgroup”);
        $("#theform").submit();
    }

    // actually delete an entire group from the database
    var DeleteGroup = function(btnObj) {
        var parts = $(btnObj).attr(“id”);
        var groupname = parts.replace(/^\d+/, “”);
        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+"’?")) {
            // submit the form to add a new field to a specific group
            $("#formaction").val(“deletegroup”);
            $("#deletegroupname").val(parts);
            $("#theform").submit();
        }
    };

    // just hide the new field DIV
    var CancelNewGroup = function(btnObj) {
        // hide the field details DIV
        $(’#groupdetail’).css(‘visibility’, ‘hidden’);
        $(’#groupdetail’).css(‘display’, ‘none’);
        // reset the new group values to a default
        $(’#groupdetail > #newgroupname’).val("");
    };

    // display the ‘new field’ DIV
    var MoveGroup = function(btnObj) {
        var btnid = $(btnObj).attr(“id”);
        var parts = btnid.split("~");
        var groupid = parts;
        var direction = parts;

        // submit the form to change group order
        $("#formaction").val(“movegroup”);
        $("#movegroupname").val(groupid);
        $("#movedirection").val(direction);
        $("#theform").submit();
    }

    // show the rename group DIV
    var RenameGroup = function(btnObj) {
        $(’#renamegroupdetail’).css(‘visibility’, ‘visible’);
        $(’#renamegroupdetail’).css(‘display’, ‘block’);
        $(btnObj).parent().append($("#renamegroupdetail"));
        $(’#renameoldgroupname’).val($(btnObj).attr(“id”));
        $(’#renamegroupname’).val($(btnObj).attr(“id”).replace(/^\d+/, “”));
    }

    // save the new group to the form
    var SaveRenameGroup = function(btnObj) {
        // the group name field can only have letters, numbers, spaces and underscores
        // AND it cannot start with a number
        if ($("#renamegroupname").val().match(/^\d+/)) {
            alert("<?php xl(‘Group names cannot start with numbers.’,‘e’); ?>");
            return false;
        }
        var validname = $("#renamegroupname").val().replace(//g, “_”); // match any non-word characters and replace them
        $("#renamegroupname").val(validname);

        // submit the form to add a new field to a specific group
        $("#formaction").val(“renamegroup”);
        $("#theform").submit();
    }

    // just hide the new field DIV
    var CancelRenameGroup = function(btnObj) {
        // hide the field details DIV
        $(’#renamegroupdetail’).css(‘visibility’, ‘hidden’);
        $(’#renamegroupdetail’).css(‘display’, ‘none’);
        // reset the rename group values to a default
        $(’#renameoldgroupname’).val("");
        $(’#renamegroupname’).val("");
    };

    /****************************************************/
    /************ Field functions ***********************/
    /****************************************************/

    // display the ‘new field’ DIV
    var AddField = function(btnObj) {
        // update the fieldgroup value to be the groupid
        var btnid = $(btnObj).attr(“id”);
        var parts = btnid.split("~");
        var groupid = parts;
        $(’#fielddetail > #newfieldgroupid’).attr(‘value’, groupid);
   
        // show the field details DIV
        $(’#fielddetail’).css(‘visibility’, ‘visible’);
        $(’#fielddetail’).css(‘display’, ‘block’);
        $(btnObj).parent().append($("#fielddetail"));
    };

    var DeleteFields = function(btnObj) {
        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’); ?>")) {
            var delim = “”;
            $(".selectfield").each(function(i) {
                // build a list of selected field names to be moved
                if ($(this).attr(“checked”) == true) {
                    var parts = this.id.split("~");
                    var currval = $("#selectedfields").val();
                    $("#selectedfields").val(currval+delim+parts);
                    delim = " “;
                }
            });
            // submit the form to delete the field(s)
            $(”#formaction").val(“deletefields”);
            $("#theform").submit();
        }
    };
   
    // save the new field to the form
    var SaveNewField = function(btnObj) {
        // check the new field values for correct formatting
   
        // seq must be numeric and less than 999
        if (! IsNumeric($("#newseq").val(), 0, 999)) {
            alert("<?php xl(‘Order must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // length must be numeric and less than 999
        if (! IsNumeric($("#newlength").val(), 0, 999)) {
            alert("<?php xl(‘Size must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // titlecols must be numeric and less than 100
        if (! IsNumeric($("#newtitlecols").val(), 0, 999)) {
            alert("<?php xl(‘LabelCols must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // datacols must be numeric and less than 100
        if (! IsNumeric($("#newdatacols").val(), 0, 999)) {
            alert("<?php xl(‘DataCols must be a number between 1 and 999’,‘e’); ?>");
            return false;
        }
        // some fields cannot be blank
        if ($("#newtitle").val() == “”) {
            alert("<?php xl(‘Label cannot be blank’,‘e’); ?>");
            return false;
        }
        // the id field can only have letters, numbers and underscores
        var validid = $("#newid").val().replace(/(\s|\W)/g, “_”); // match any non-word characters and replace them
        $("#newid").val(validid);
        // similarly with the listid field
        validid = $("#newlistid").val().replace(/(\s|\W)/g, “_”);
        $("#newlistid").val(validid);
   
        // submit the form to add a new field to a specific group
        $("#formaction").val(“addfield”);
        $("#theform").submit();
    };
   
    // just hide the new field DIV
    var CancelNewField = function(btnObj) {
        // hide the field details DIV
        $(’#fielddetail’).css(‘visibility’, ‘hidden’);
        $(’#fielddetail’).css(‘display’, ‘none’);
        // reset the new field values to a default
        ResetNewFieldValues();
    };

    // show the popup choice of lists
    var ShowLists = function(btnObj) {
        window.open("./show_lists_popup.php", “lists”, “width=300,height=500,scrollbars=yes”);
        selectedfield = btnObj;
    };
   
    // show the popup choice of groups
    var ShowGroups = function(btnObj) {
        window.open("./show_groups_popup.php?layout_id=<?php echo $layout_id;?>", “groups”, “width=300,height=300,scrollbars=yes”);
    };

});

function SetList(listid) { $(selectedfield).val(listid); }

/* this is called after the user chooses a new group from the popup window
* it will submit the page so the selected fields can be moved into
* the target group
*/
function MoveFields(targetgroup) {
    $("#targetgroup").val(targetgroup);
    var delim = “”;
    $(".selectfield").each(function(i) {
        // build a list of selected field names to be moved
        if ($(this).attr(“checked”) == true) {
            var parts = this.id.split("~");
            var currval = $("#selectedfields").val();
            $("#selectedfields").val(currval+delim+parts);
            delim = " “;
        }
    });
    $(”#formaction").val(“movefields”);
    $("#theform").submit();
};

// set the new-field values to a default state
function ResetNewFieldValues () {
    $("#newseq").val("");
    $("#newid").val("");
    $("#newtitle").val("");
    $("#newuor").val(1);
    $("#newlength").val("");
    $("#newdatatype").val("");
    $("#newlistid").val("");
    $("#newtitlecols").val("");
    $("#newdatacols").val("");
    $("#newdefault").val("");
    $("#newdesc").val("");
}

// is value an integer and between min and max
function IsNumeric(value, min, max) {
    if (value == “” || value == null) return false;
    if (! IsN(value) ||
        parseInt(value) < min ||
        parseInt(value) > max)
        return false;

    return true;
}

/****************************************************/
/****************************************************/
/****************************************************/

// tell if num is an Integer
function IsN(num) { return !/\D/.test(num); }
</script>

</html>

Sherwin Gaddis
757-328-2736
Juggernaut Systems Express      Open Med Practice
www.jse.net                             www.openmedpractice.com

mike-h30 wrote on Thursday, April 21, 2011:

The over all goal is that I am building an office note for a doctor. The final output of the note will be in paragraph form.
[/quote

CAMOS is the best “note building” tool in my opinion. Output can be customized any way you want in notegen.php with the use of the EZPDF class. I have customized the creation of 1 to 5 page length doctor notes to print to PDF in paragraph form with a couple of button clicks in CAMOS. In  the past, we have actually have been denied payment due to “doctor notes not being long enough” in the opinion of insurance company personal.  Not anymore though thanks to CAMOS.  CAMOS also handles prescriptions although we are not using CAMOS for scripts at the moment.  I believe CAMOS could be customized to create your doctor note, write your script, and update the medications table.  If you haven’t looked at CAMOS, I would highly recommend it.  Since we implemented CAMOS, documenting a patient visit takes seconds and allows our physician to focus on patient care instead of wasting time fulfilling the BS requirements of insurance companies whose staff never attended medical school yet have the audacity to dictate how a physician should practice medicine.

PS -  Thanks Dr. Mark Leeds for creating CAMOS!!

-Mike

mike-h30 wrote on Thursday, April 21, 2011:

Definitely need a “edit post” feature.

The over all goal is that I am building an office note for a doctor. The final output of the note will be in paragraph form.

CAMOS is the best “note building” tool in my opinion.  Output can be customized any way you want in notegen.php with the use of the EZPDF class.  I have customized the creation of 1 to 5 page length doctor notes to print to PDF in paragraph form with a couple of button clicks in CAMOS.  In  the past, we have actually have been denied payment due to “doctor notes not being long enough” in the opinion of insurance company personal.  Not anymore though thanks to CAMOS.  CAMOS also handles prescriptions although we are not using CAMOS for scripts at the moment.  I believe CAMOS could be customized to create your doctor note, write your script, and update the medications table.  If you haven’t looked at CAMOS, I would highly recommend it.  Since we implemented CAMOS, documenting a patient visit takes seconds and allows our physician to focus on patient care instead of wasting time fulfilling the BS requirements of insurance companies whose staff never attended medical school yet have the audacity to dictate how a physician should practice medicine.

PS -  Thanks Dr. Mark Leeds for creating CAMOS!!

-Mike

yehster wrote on Thursday, April 21, 2011:

I tried to post a response before in the forum, but something weird happened I think.
Anyway, the error you are getting is because the function for translation is called
xl  (the letter x and the letter L)
not
x1 (the letter x and the number one)

juggernautsei wrote on Thursday, April 21, 2011:

Thanks that fixed the problem with the code and got me going again.

I will look at the CAMOS and see what it does.

sherwin

juggernautsei wrote on Monday, May 30, 2011:

Hi, I need help with building this new data type for the LBF in version 4 construct.

The piece of code below is from the options.inc.php file. This is the data_type that I am trying to code.

  // multiple-selection from list box with ability to add to it - Sherwin 2011
  else if ($data_type == 34) {
    echo “<select class=‘addtolistclass_$list_id_esc’ name=‘form_$field_id_esc’ multiple=’$multiple’ id=‘form_$field_id_esc’ title=’$description’>”;
    if ($showEmpty) echo “<option value=’’>” . htmlspecialchars( xl($empty_title), ENT_QUOTES) . “</option>”;
    $lres = sqlStatement(“SELECT * FROM list_options " .
      “WHERE list_id = ? ORDER BY seq, title”, array($list_id) );
    $got_selected = FALSE;
    while ($lrow = sqlFetchArray($lres)) {
      $optionValue = htmlspecialchars( $lrow, ENT_QUOTES);
      echo “<option value=’$optionValue’”;
      if ((strlen($currvalue) == 0 && $lrow) ||
          (strlen($currvalue)  > 0 && $lrow == $currvalue))
      {
        echo " selected”;
        $got_selected = TRUE;
      }
      // Added 5-09 by BM - Translate label if applicable
      echo “>” . htmlspecialchars( xl_list_label($lrow), ENT_NOQUOTES) . “</option>\n”;
    }
    if (!$got_selected && strlen($currvalue) > 0) {
      echo “<option value=’$currescaped’ selected>* $currescaped *</option>”;
      echo “</select>”;
      $fontTitle = htmlspecialchars( xl(‘Please choose a valid selection from the list.’), ENT_NOQUOTES);
      $fontText = htmlspecialchars( xl(‘Fix this’), ENT_NOQUOTES);
      echo " <font color=‘red’ title=’$fontTitle’>$fontText!</font>";
    }
    else {
      echo “</select>”;
    }

I am missing how to get the selected items back to the data base. I know that I need to use a FOR Each command but I don’t really know where to put it.

Could someone point me in the right direction?

Thanks!

Sherwin
www.openmedpractice.com

tmccormi wrote on Tuesday, May 31, 2011:

I just had to do this for a customer, perhaps my code will help?  https://github.com/tmccormi/openemr/commits/LBF_datatype_29
-Tony

juggernautsei wrote on Tuesday, May 31, 2011:

Tony,

Thanks! 

This will push me in a different direction. I was looking to put he foreach clause below. Defining it at the top is a better way to go. I see I have to first define a new array. Instead of just sticking in the html function. I am writing this down as I learn how to build functions and arrays. I did notice also that you said this is datatype_29 but you have not included it in your list of data_types yet in the edit_layout.php file. I checked it against the orginal and only the orginal 33 are there but there is no 29. Just an observation.

Sherwin
www.openmedpractice.com

tmccormi wrote on Tuesday, May 31, 2011:

it’s there: // array of the data_types of the fields

$datatypes = array(
  "1"  => xl("List box"), 
  "2"  => xl("Textbox"),
  "3"  => xl("Textarea"),
  "4"  => xl("Text-date"),
  "10" => xl("Providers"),
  "11" => xl("Providers NPI"),
  "12" => xl("Pharmacies"),
  "13" => xl("Squads"),
  "14" => xl("Organizations"),
  "15" => xl("Billing codes"),
  "21" => xl("Checkbox list"),
  "22" => xl("Textbox list"),
  "23" => xl("Exam results"),
  "24" => xl("Patient allergies"),
  "25" => xl("Checkbox w/text"),
  "26" => xl("List box w/add"),
  "27" => xl("Radio buttons"),
  "28" => xl("Lifestyle status"), // add for smoking status task
  "29" => xl("History w/Notes"),                           <<< ----------------------------- here
  "31" => xl("Static Text"),
  "32" => xl("Smoking Status"),
  "33" => xl("Race and Ethnicity"),
);

acmoore wrote on Tuesday, May 31, 2011:

Hi Tony -

I tried to look at the code that you pointed Sherwin to, but I don’t  see in your code in github the datatype #29 that you refer to above. Here’s where I’ve looked so far:

Here’s the file off of the tip of that branch:

https://github.com/tmccormi/openemr/blob/LBF_datatype_29/interface/super/edit_layout.php

It appears to me also to skip datatype #29.

This is the only commit on that branch that’s different from your master, and it doesn’t really appear relevant:
https://github.com/tmccormi/openemr/commit/2217e9da29b6451718f2d90d7a8447f7da9bdfba

Could you give us just a little more help to find the similar code that you’ve written, please?

Thanks for your help, Tony!

-Andy

tmccormi wrote on Tuesday, May 31, 2011:

Looks like what’s up on github is not the same as what I have in branch locally.   I’ll redo the push.
-Tony

tmccormi wrote on Tuesday, May 31, 2011:

Try it now.
https://github.com/tmccormi/openemr/commits/LBF_datatype_29
-Tony

acmoore wrote on Tuesday, May 31, 2011:

Thanks, Tony. I see how you’re making one datatype display as several HTML elements there. That may help me out.

-Andy

ajperezcrespo wrote on Wednesday, June 01, 2011:

Hi,

  How will this affect what happens to the history page when you move items around?  Especially the tobacco info?
I just tried it on the demo site.  I moved the Relative group below Lifestyle, saved, and then moved it back.  Now Tobacco doesnt work.

Thanks.

tmccormi wrote on Wednesday, June 01, 2011:

the changes to the history_full.php and edit_layout.php are an example (done for a customer, not for the general release).   Moving things around in the layout tool might have undesired effects.  It is pretty limited when it comes to that.  I usually end up resorting to direct edits in the table for anything fancy.

Some future hot programmer could make the data types be a ‘plugin’ model where you could create one and drop it into a directory without all the insane repetitious code and squirrelly if-blocks for exceptions …

-Tony

vpsubramanian wrote on Friday, June 03, 2011:

Hi
I am new to openemr. I tried to make a layout based form. I got stuck in datatype. I need a LASA type data type where patient can select intensity of symptom on a line. Intensity goes from left to right on the line  from none to maximum severity. Any help will be greatly appreciated

vpsubramanian wrote on Friday, June 03, 2011:

Hi
I am new to openemr. I tried to make a layout based form. I got stuck in datatype. I need a LASA type data type where patient can select intensity of symptom on a line. Intensity goes from left to right on the line  from none to maximum severity. Any help will be greatly appreciated

vpsubramanian wrote on Friday, June 03, 2011:

Hi
I am new to openemr. I tried to make a layout based form. I got stuck in datatype. I need a LASA type data type where patient can select intensity of symptom on a line. Intensity goes from left to right on the line  from none to maximum severity. Any help will be greatly appreciated

vpsubramanian wrote on Friday, June 03, 2011:

Hi
I am new to openemr. I tried to make a layout based form. I got stuck in datatype. I need a LASA type data type where patient can select intensity of symptom on a line. Intensity goes from left to right on the line  from none to maximum severity. Any help will be greatly appreciated