Ejemplo n.º 1
0
function getCustomerForm($orderID, $memNum = "0")
{
    global $FANNIE_OP_DB, $TRANS, $FANNIE_TRANS_DB, $canEdit;
    $dbc = FannieDB::get($FANNIE_OP_DB);
    if (empty($orderID)) {
        $orderID = createEmptyOrder();
    }
    $names = array();
    $pn = 1;
    $status_row = array('Type' => 'REG', 'status' => '');
    $table = "PendingSpecialOrder";
    $dbc = FannieDB::get($FANNIE_TRANS_DB);
    $orderModel = new SpecialOrdersModel($dbc);
    $orderModel->specialOrderID($orderID);
    $orderModel->load();
    $dbc = FannieDB::get($FANNIE_OP_DB);
    // detect member UPC entry
    if ($memNum > 9999999) {
        $p = $dbc->prepare_statement("SELECT card_no FROM memberCards WHERE upc=?");
        $r = $dbc->exec_statement($p, array(BarcodeLib::padUPC($memNum)));
        if ($dbc->num_rows($r) > 0) {
            $w = $dbc->fetch_row($r);
            $memNum = $w['card_no'];
        } else {
            $memNum = "";
        }
    }
    // look up member id if applicable
    if ($memNum === "0") {
        $findMem = $dbc->prepare_statement("SELECT card_no,voided FROM {$TRANS}{$table} WHERE order_id=?");
        $memR = $dbc->exec_statement($findMem, array($orderID));
        if ($dbc->num_rows($memR) > 0) {
            $memW = $dbc->fetch_row($memR);
            $memNum = $memW['card_no'];
            $pn = $memW['voided'];
        }
    } else {
        if ($memNum == "") {
            $p = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?,voided=0\n            WHERE order_id=?");
            $r = $dbc->exec_statement($p, array(0, $orderID));
        } else {
            $p = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?\n            WHERE order_id=?");
            $r = $dbc->exec_statement($p, array($memNum, $orderID));
            // clear contact fields if member number changed
            // so that defaults are reloaded from meminfo
            $dbc = FannieDB::get($FANNIE_TRANS_DB);
            $orderModel->street('');
            $orderModel->phone('');
            $orderModel->save();
            $orderModel->specialOrderID($orderID);
            $orderModel->load();
            $dbc = FannieDB::get($FANNIE_OP_DB);
            if ($dbc->table_exists('SpecialOrderContact')) {
                $p = $dbc->prepare_statement("UPDATE {$TRANS}SpecialOrderContact SET\n                street='',phone='' WHERE card_no=?");
                $r = $dbc->exec_statement($p, array($orderID));
            }
            // look up personnum, correct if it hasn't been set
            $pQ = $dbc->prepare_statement("SELECT voided FROM {$TRANS}PendingSpecialOrder\n            WHERE order_id=?");
            $pR = $dbc->exec_statement($pQ, array($orderID));
            $pnW = $dbc->fetch_row($pR);
            $pn = $pnW['voided'];
            if ($pn == 0) {
                $pn = 1;
                $upP = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET voided=?\n                WHERE order_id=?");
                $upR = $dbc->exec_statement($upP, array($pn, $orderID));
            }
        }
    }
    if ($memNum != 0) {
        $namesP = $dbc->prepare_statement("SELECT personNum,FirstName,LastName FROM custdata\n            WHERE CardNo=? ORDER BY personNum");
        $namesR = $dbc->exec_statement($namesP, array($memNum));
        while ($namesW = $dbc->fetch_row($namesR)) {
            $names[$namesW['personNum']] = array($namesW['FirstName'], $namesW['LastName']);
        }
        // load member contact info into order
        // on first go so it can be edited separately
        $current_street = $orderModel->street();
        $current_phone = $orderModel->phone();
        if (empty($current_street) && empty($current_phone)) {
            $contactQ = $dbc->prepare_statement("SELECT street,city,state,zip,phone,email_1,email_2\n                    FROM meminfo WHERE card_no=?");
            $contactR = $dbc->exec_statement($contactQ, array($memNum));
            if ($dbc->num_rows($contactR) > 0) {
                $contact_row = $dbc->fetch_row($contactR);
                $dbc = FannieDB::get($FANNIE_TRANS_DB);
                $orderModel->street($contact_row['street']);
                $orderModel->city($contact_row['city']);
                $orderModel->state($contact_row['state']);
                $orderModel->zip($contact_row['zip']);
                $orderModel->phone($contact_row['phone']);
                $orderModel->altPhone($contact_row['email_2']);
                $orderModel->email($contact_row['email_1']);
                $orderModel->save();
                $orderModel->specialOrderID($orderID);
                $orderModel->load();
                $dbc = FannieDB::get($FANNIE_OP_DB);
                if ($dbc->table_exists($TRANS . 'SpecialOrderContact')) {
                    $upP = $dbc->prepare_statement("UPDATE {$TRANS}SpecialOrderContact SET street=?,city=?,state=?,zip=?,\n                            phone=?,email_1=?,email_2=? WHERE card_no=?");
                    $upR = $dbc->exec_statement($upP, array($contact_row['street'], $contact_row['city'], $contact_row['state'], $contact_row['zip'], $contact_row['phone'], $contact_row['email_1'], $contact_row['email_2'], $orderID));
                }
            }
        }
        $statusQ = $dbc->prepare_statement("SELECT Type FROM custdata WHERE CardNo=?");
        $statusR = $dbc->exec_statement($statusQ, array($memNum));
        $status_row = $dbc->fetch_row($statusR);
        if ($status_row['Type'] == 'INACT') {
            $status_row['status'] = 'Inactive';
        } elseif ($status_row['Type'] == 'INACT2') {
            $status_row['status'] = 'Inactive';
        } elseif ($status_row['Type'] == 'TERM') {
            $status_row['status'] = 'Terminated';
        }
    }
    $q = $dbc->prepare_statement("SELECT entry_date FROM {$TRANS}SpecialOrderHistory \n            WHERE order_id=? AND entry_type='CONFIRMED'");
    $r = $dbc->exec_statement($q, array($orderID));
    $confirm_date = "";
    if ($dbc->num_rows($r) > 0) {
        $confirm_date = array_pop($dbc->fetch_row($r));
    }
    $callback = 2;
    $user = '******';
    $orderDate = "";
    $q = $dbc->prepare_statement("SELECT datetime,numflag,mixMatch FROM \n            {$TRANS}PendingSpecialOrder WHERE order_id=? AND trans_id=0");
    $r = $dbc->exec_statement($q, array($orderID));
    if ($dbc->num_rows($r) > 0) {
        list($orderDate, $callback, $user) = $dbc->fetch_row($r);
    }
    $status = array(0 => "New, No Call", 3 => "New, Call", 1 => "Called/waiting", 2 => "Pending", 4 => "Placed", 5 => "Arrived");
    $order_status = $orderModel->statusFlag();
    $ret = "";
    $ret .= '<table width="95%" cellpadding="4" cellspacing=4" border="0">';
    $ret .= '<tr><td align="left" valign="top">';
    $ret .= sprintf('<input type="hidden" id="orderID" value="%d" />', $orderID);
    $ret .= sprintf('<b>Owner Number</b>: <input type="text" size="6"
            id="memNum" value="%s" onchange="memNumEntered();"
            />', $memNum == 0 ? '' : $memNum);
    $ret .= '<br />';
    $ret .= '<b>Owner</b>: ' . ($status_row['Type'] == 'PC' ? 'Yes' : 'No');
    $ret .= sprintf('<input type="hidden" id="isMember" value="%s" />', $status_row['Type']);
    $ret .= '<br />';
    if (!empty($status_row['status'])) {
        $ret .= '<b>Account status</b>: ' . $status_row['status'];
        $ret .= '<br />';
    }
    $ret .= '</td>';
    $ret .= '<td valign="top">';
    if ($canEdit) {
        $ret .= '<b>Status</b>: ';
        $ret .= sprintf('<select id="orderStatus" onchange="updateStatus(%d, this.value);">', $orderID);
        foreach ($status as $k => $v) {
            $ret .= sprintf('<option %s value="%d">%s</option>', $k == $order_status ? 'selected' : '', $k, $v);
        }
        $ret .= '</select><p />';
    }
    $ret .= '<b>Store</b>: ';
    $ret .= sprintf('<select onchange="updateStore(%d, this.value);">', $orderID);
    $stores = new StoresModel($dbc);
    $ret .= '<option value="0">Choose...</option>';
    $ret .= $stores->toOptions($orderModel->storeID());
    $ret .= '</select>';
    $ret .= '</td>';
    $ret .= '<td align="right" valign="top">';
    $ret .= "<input type=\"submit\" value=\"Done\"\n        onclick=\"validateAndHome();return false;\" />";
    $username = checkLogin();
    $prints = array();
    $cachepath = sys_get_temp_dir() . "/ordercache/";
    if (file_exists("{$cachepath}{$username}.prints")) {
        $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints"));
    } else {
        $fp = fopen("{$cachepath}{$username}.prints", 'w');
        fwrite($fp, serialize($prints));
        fclose($fp);
    }
    $ret .= sprintf('<br />Queue tags <input type="checkbox" %s onclick="togglePrint(\'%s\',%d);" />', isset($prints[$orderID]) ? 'checked' : '', $username, $orderID);
    $ret .= sprintf('<br /><a href="tagpdf.php?oids[]=%d" target="_tags%d">Print Now</a>', $orderID, $orderID);
    $ret .= '</td></tr></table>';
    $extra = "";
    $extra .= '<table width="95%" cellpadding="4" cellspacing=4" border="0">';
    $extra .= '<tr><td align="left" valign="top">';
    $extra .= "<b>Taken by</b>: " . $user . "<br />";
    $extra .= "<b>On</b>: " . date("M j, Y g:ia", strtotime($orderDate)) . "<br />";
    $extra .= '</td><td align="right" valign="top">';
    $extra .= '<b>Call to Confirm</b>: ';
    $extra .= '<select id="ctcselect" onchange="saveCtC(this.value,' . $orderID . ');">';
    $extra .= '<option value="2"></option>';
    if ($callback == 1) {
        $extra .= '<option value="1" selected>Yes</option>';
        $extra .= '<option value="0">No</option>';
    } else {
        if ($callback == 0) {
            $extra .= '<option value="1">Yes</option>';
            $extra .= '<option value="0" selected>No</option>';
        } else {
            $extra .= '<option value="1">Yes</option>';
            $extra .= '<option value="0">No</option>';
        }
    }
    $extra .= '</select><br />';
    $extra .= '<span id="confDateSpan">' . (!empty($confirm_date) ? 'Confirmed ' . $confirm_date : 'Not confirmed') . "</span> ";
    $extra .= '<input type="checkbox" onclick="saveConfirmDate(this.checked,' . $orderID . ');" ';
    if (!empty($confirm_date)) {
        $extra .= "checked";
    }
    $extra .= ' /><br />';
    $extra .= "<input type=\"submit\" value=\"Done\"\n        onclick=\"validateAndHome();return false;\" />";
    $extra .= '</td></tr></table>';
    $ret .= '<table cellspacing="0" cellpadding="4" border="1">';
    // names
    if (empty($names)) {
        $ret .= sprintf('<tr><th>First Name</th><td>
                <input type="text" id="t_firstName" 
                value="%s" onchange="saveFN(%d,this.value);" 
                /></td>', $orderModel->firstName(), $orderID);
        $ret .= sprintf('<th>Last Name</th><td><input 
                type="text" id="t_lastName" value="%s"
                onchange="saveLN(%d,this.value);" /></td>', $orderModel->lastName(), $orderID);
    } else {
        $ret .= sprintf('<tr><th>Name</th><td colspan="2"><select id="s_personNum"
            onchange="savePN(%d,this.value);">', $orderID);
        foreach ($names as $p => $n) {
            $ret .= sprintf('<option value="%d" %s>%s %s</option>', $p, $p == $pn ? 'selected' : '', $n[0], $n[1]);
        }
        $ret .= '</select></td>';
        $ret .= '<td>&nbsp;</td>';
    }
    $ret .= sprintf('<td colspan="4">For Department:
        <select id="nDept" onchange="saveNoteDept(%d,$(this).val());">
        <option value="0">Choose...</option>', $orderID);
    $sQ = $dbc->prepare_statement("select superID,super_name from MasterSuperDepts\n        where superID > 0\n        group by superID,super_name\n        order by super_name");
    $sR = $dbc->exec_statement($sQ);
    while ($sW = $dbc->fetch_row($sR)) {
        $ret .= sprintf('<option value="%d" %s>%s</option>', $sW['superID'], $sW['superID'] == $orderModel->noteSuperID() ? 'selected' : '', $sW['super_name']);
    }
    $ret .= "</select></td></tr>";
    // address
    $street = $orderModel->street();
    $street2 = '';
    if (strstr($street, "\n")) {
        list($street, $street2) = explode("\n", $street, 2);
    }
    $ret .= sprintf('<tr><th>Address</th><td><input type="text" id="t_addr1" value="%s" 
        onchange="saveAddr(%d);" /></td><th>E-mail</th><td><input type="text" 
        id="t_email" value="%s" onchange="saveEmail(%d,this.value);" /></td>
        <td rowspan="2" colspan="4">
        <textarea id="nText" rows="5" cols="25" 
        onchange="saveText(%d,this.value);">%s</textarea>
        </td></tr>
        <tr><th>Addr (2)</th><td><input type="text" id="t_addr2" value="%s" 
        onchange="saveAddr(%d);" /></td><th>City</th><td><input type="text" id="t_city" 
        value="%s" size="10" onchange="saveCity(%d,this.value);" /></td></tr>
        <tr><th>Phone</th><td><input 
        type="text" id="t_ph1" value="%s" onchange="savePh(%d,this.value);" /></td>
        <th>Alt. Phone</th><td><input type="text" id="t_ph2" value="%s" 
        onchange="savePh2(%d,this.value);" /></td>
        <th>State</th>
        <td><input type="text" id="t_state" value="%s" size="2" onchange="saveState(%d,this.value);"
        /></td><th>Zip</th><td><input type="text" id="t_zip" value="%s" size="5" 
        onchange="saveZip(%d,this.value); " /></td></tr>', $street, $orderID, $orderModel->email(), $orderID, $orderID, $orderModel->notes(), $street2, $orderID, $orderModel->city(), $orderID, $orderModel->phone(), $orderID, $orderModel->altPhone(), $orderID, $orderModel->state(), $orderID, $orderModel->zip(), $orderID);
    $ret .= '</table>';
    return $ret . "`" . $extra;
}
Ejemplo n.º 2
0
 protected function get_orderID_customer_handler()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $TRANS = $this->config->get('TRANS_DB') . $dbc->sep();
     $orderID = $this->orderID;
     try {
         $memNum = $this->form->memNum;
     } catch (Exception $ex) {
         $memNum = '0';
     }
     $canEdit = FannieAuth::validateUserQuiet('ordering_edit');
     if (empty($orderID)) {
         $orderID = $this->createEmptyOrder();
     }
     $names = array();
     $personNum = 1;
     $status_row = array('Type' => 'REG', 'status' => '');
     $dbc->selectDB($this->config->get('TRANS_DB'));
     $orderModel = new SpecialOrdersModel($dbc);
     $orderModel->specialOrderID($orderID);
     $orderModel->load();
     $dbc->selectDB($this->config->get('OP_DB'));
     // detect member UPC entry
     if ($memNum > 9999999) {
         $cards = new MemberCardsModel($dbc);
         $cards->upc(BarcodeLib::padUPC($memNum));
         $memNum = '';
         foreach ($cards->find() as $c) {
             $memNum = $c->card_no();
             break;
         }
     }
     // look up member id if applicable
     if ($memNum === "0") {
         $findMem = $dbc->prepare("SELECT card_no,voided FROM {$TRANS}PendingSpecialOrder WHERE order_id=?");
         $memR = $dbc->execute($findMem, array($orderID));
         if ($dbc->numRows($memR) > 0) {
             $memW = $dbc->fetchRow($memR);
             $memNum = $memW['card_no'];
             $personNum = $memW['voided'];
         }
     } elseif ($memNum == "") {
         $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?,voided=0\n                WHERE order_id=?");
         $dbc->execute($prep, array(0, $orderID));
     } else {
         $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?\n                WHERE order_id=?");
         $dbc->execute($prep, array($memNum, $orderID));
         // clear contact fields if member number changed
         // so that defaults are reloaded from meminfo
         $dbc->selectDB($this->config->get('TRANS_DB'));
         $orderModel->street('');
         $orderModel->phone('');
         $orderModel->save();
         $orderModel->specialOrderID($orderID);
         $orderModel->load();
         $dbc->selectDB($this->config->get('OP_DB'));
         // look up personnum, correct if it hasn't been set
         $pendQ = $dbc->prepare_statement("SELECT voided FROM {$TRANS}PendingSpecialOrder\n                WHERE order_id=?");
         $personNum = $dbc->getValue($pendQ, array($orderID));
         if ($personNum == 0) {
             $personNum = 1;
             $upP = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET voided=?\n                    WHERE order_id=?");
             $upR = $dbc->exec_statement($upP, array($personNum, $orderID));
         }
     }
     if ($memNum != 0) {
         $custdata = new CustdataModel($dbc);
         $custdata->CardNo($memNum);
         foreach ($custdata->find('personNum') as $c) {
             $names[$c->personNum()] = array($c->FirstName(), $c->LastName());
         }
         // load member contact info into order
         // on first go so it can be edited separately
         $current_street = $orderModel->street();
         $current_phone = $orderModel->phone();
         if (empty($current_street) && empty($current_phone)) {
             $contactQ = $dbc->prepare_statement("SELECT street,city,state,zip,phone,email_1,email_2\n                        FROM meminfo WHERE card_no=?");
             $contactR = $dbc->exec_statement($contactQ, array($memNum));
             if ($dbc->num_rows($contactR) > 0) {
                 $contact_row = $dbc->fetch_row($contactR);
                 $dbc->selectDB($this->config->get('TRANS_DB'));
                 $orderModel->street($contact_row['street']);
                 $orderModel->city($contact_row['city']);
                 $orderModel->state($contact_row['state']);
                 $orderModel->zip($contact_row['zip']);
                 $orderModel->phone($contact_row['phone']);
                 $orderModel->altPhone($contact_row['email_2']);
                 $orderModel->email($contact_row['email_1']);
                 $orderModel->save();
                 $orderModel->specialOrderID($orderID);
                 $orderModel->load();
                 $dbc->selectDB($this->config->get('OP_DB'));
             }
         }
         if ($custdata->load()) {
             $status_row['Type'] = $custdata->Type();
             if ($status_row['Type'] == 'INACT') {
                 $status_row['status'] = 'Inactive';
             } elseif ($status_row['Type'] == 'INACT2') {
                 $status_row['status'] = 'Inactive';
             } elseif ($status_row['Type'] == 'TERM') {
                 $status_row['status'] = 'Terminated';
             }
         }
     }
     $prep = $dbc->prepare_statement("SELECT entry_date FROM {$TRANS}SpecialOrderHistory \n                WHERE order_id=? AND entry_type='CONFIRMED'");
     $confirm_date = $dbc->getValue($prep, array($orderID));
     $callback = 2;
     $user = '******';
     $orderDate = "";
     $prep = $dbc->prepare_statement("SELECT datetime,numflag,mixMatch FROM \n                {$TRANS}PendingSpecialOrder WHERE order_id=? AND trans_id=0");
     $res = $dbc->exec_statement($prep, array($orderID));
     if ($dbc->num_rows($res) > 0) {
         list($orderDate, $callback, $user) = $dbc->fetch_row($res);
     }
     $status = array(0 => "New, No Call", 3 => "New, Call", 1 => "Called/waiting", 2 => "Pending", 4 => "Placed", 5 => "Arrived");
     $order_status = $orderModel->statusFlag();
     $ret = "";
     $ret .= sprintf('<input type="hidden" id="orderID" value="%d" />', $orderID);
     $ret .= '<div class="row form-inline"><div class="col-sm-4 text-left">';
     $ret .= sprintf('<b>Owner Number</b>: <input type="text" size="6"
             id="memNum" value="%s" class="form-control price-field input-sm" 
             />', $memNum == 0 ? '' : $memNum);
     $ret .= '<br />';
     $ret .= '<b>Owner</b>: ' . ($status_row['Type'] == 'PC' ? 'Yes' : 'No');
     $ret .= sprintf('<input type="hidden" id="isMember" value="%s" />', $status_row['Type']);
     $ret .= '<br />';
     if (!empty($status_row['status'])) {
         $ret .= '<b>Account status</b>: ' . $status_row['status'];
         $ret .= '<br />';
     }
     $ret .= '</div><div class="col-sm-4 text-center">';
     if ($canEdit) {
         $ret .= '<b>Status</b>: ';
         $ret .= '<select id="orderStatus" class="form-control input-sm">';
         foreach ($status as $k => $v) {
             $ret .= sprintf('<option %s value="%d">%s</option>', $k == $order_status ? 'selected' : '', $k, $v);
         }
         $ret .= '</select><p />';
     }
     $ret .= '<b>Store</b>: ';
     $ret .= '<select id="orderStore" class="form-control input-sm">';
     $ret .= '<option value="0">Choose...</option>';
     $stores = new StoresModel($dbc);
     $ret .= $stores->toOptions($orderModel->storeID());
     $ret .= '</select>';
     $ret .= '</div><div class="col-sm-4 text-right">';
     $ret .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>";
     $username = FannieAuth::checkLogin();
     $prints = array();
     $cachepath = sys_get_temp_dir() . "/ordercache/";
     if (file_exists("{$cachepath}{$username}.prints")) {
         $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints"));
     } else {
         $fptr = fopen("{$cachepath}{$username}.prints", 'w');
         fwrite($fptr, serialize($prints));
         fclose($fptr);
     }
     $ret .= sprintf('<br />Queue tags <input type="checkbox" %s class="print-cb" />', isset($prints[$orderID]) ? 'checked' : '', $username, $orderID);
     $ret .= sprintf('<br /><a href="tagpdf.php?oids[]=%d" target="_tags%d">Print Now</a>', $orderID, $orderID);
     $ret .= '</div></div>';
     $extra = "";
     $extra .= '<div class="row"><div class="col-sm-6 text-left">';
     $extra .= "<b>Taken by</b>: " . $user . "<br />";
     $extra .= "<b>On</b>: " . date("M j, Y g:ia", strtotime($orderDate)) . "<br />";
     $extra .= '</div><div class="col-sm-6 text-right form-inline">';
     $extra .= '<b>Call to Confirm</b>: ';
     $extra .= '<select id="ctcselect" class="form-control input-sm">';
     $extra .= '<option value="2"></option>';
     if ($callback == 1) {
         $extra .= '<option value="1" selected>Yes</option>';
         $extra .= '<option value="0">No</option>';
     } else {
         if ($callback == 0) {
             $extra .= '<option value="1">Yes</option>';
             $extra .= '<option value="0" selected>No</option>';
         } else {
             $extra .= '<option value="1">Yes</option>';
             $extra .= '<option value="0">No</option>';
         }
     }
     $extra .= '</select><br />';
     $extra .= '<span id="confDateSpan">' . (!empty($confirm_date) ? 'Confirmed ' . $confirm_date : 'Not confirmed') . "</span> ";
     $extra .= '<input type="checkbox" id="confirm-date" ';
     if (!empty($confirm_date)) {
         $extra .= "checked";
     }
     $extra .= ' /><br />';
     $extra .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>";
     $extra .= '</div></div>';
     $ret .= '<table class="table table-bordered">';
     // names
     if (empty($names)) {
         $ret .= sprintf('<tr><th>First Name</th><td>
                 <input type="text" id="t_firstName" name="fn"
                 class="form-control input-sm conact-field"
                 value="%s" 
                 /></td>', $orderModel->firstName());
         $ret .= sprintf('<th>Last Name</th><td><input 
                 type="text" id="t_lastName" value="%s" name="ln"
                 class="form-control input-sm contact-field"
                 /></td>', $orderModel->lastName());
     } else {
         $ret .= '<tr><th>Name</th><td colspan="2"><select id="s_personNum"
             class="form-control input-sm">';
         foreach ($names as $p => $n) {
             $ret .= sprintf('<option value="%d" %s>%s %s</option>', $p, $p == $personNum ? 'selected' : '', $n[0], $n[1]);
         }
         $ret .= '</select></td>';
         $ret .= '<td>&nbsp;</td>';
     }
     $ret .= '<td colspan="4" class="form-inline">For Department:
         <select id="nDept" class="form-control input-sm contact-field" 
             name="noteDept">
         <option value="0">Choose...</option>';
     $superQ = $dbc->prepare_statement("select superID,super_name from MasterSuperDepts\n            where superID > 0\n            group by superID,super_name\n            order by super_name");
     $superR = $dbc->exec_statement($superQ);
     while ($superW = $dbc->fetch_row($superR)) {
         $ret .= sprintf('<option value="%d" %s>%s</option>', $superW['superID'], $superW['superID'] == $orderModel->noteSuperID() ? 'selected' : '', $superW['super_name']);
     }
     $ret .= "</select></td></tr>";
     // address
     $street = $orderModel->street();
     $street2 = '';
     if (strstr($street, "\n")) {
         list($street, $street2) = explode("\n", $street, 2);
     }
     $ret .= sprintf('
         <tr>
             <th>Address</th>
             <td>
                 <input type="text" id="t_addr1" value="%s" 
                     class="form-control input-sm contact-field"
                     name="addr" />
             </td>
             <th>E-mail</th>
             <td>
                 <input type="text" id="t_email" value="%s" 
                     class="form-control input-sm contact-field"
                     name="email" />
             </td>
             <td rowspan="2" colspan="4">
                 <textarea id="nText" rows="5" cols="25" 
                     class="form-control input-sm contact-field" name="noteText"
                     >%s</textarea>
             </td>
         </tr>
         <tr>
             <th>Addr (2)</th>
             <td>
                 <input type="text" id="t_addr2" value="%s" 
                     class="form-control input-sm contact-field"
                     name="addr2" />
             </td>
             <th>City</th>
             <td>
                 <input type="text" id="t_city" name="city"
                     class="form-control input-sm contact-field"
                     value="%s" size="10" />
             </td>
         </tr>
         <tr>
             <th>Phone</th>
             <td>
                 <input type="text" id="t_ph1" name="ph1"
                     class="form-control input-sm contact-field"
                     value="%s" />
             </td>
             <th>Alt. Phone</th>
             <td>
                 <input type="text" id="t_ph2" value="%s" name="ph2"
                     class="form-control input-sm contact-field" />
             </td>
             <th>State</th>
             <td>
                 <input type="text" id="t_state" value="%s" size="2" 
                     class="form-control input-sm contact-field"
                     name="state"  />
             </td>
             <th>Zip</th>
             <td>
                 <input type="text" id="t_zip" value="%s" size="5" 
                     class="form-control input-sm contact-field"
                     name="zip" />
             </td>
         </tr>', $street, $orderModel->email(), $orderModel->notes(), $street2, $orderModel->city(), $orderModel->phone(), $orderModel->altPhone(), $orderModel->state(), $orderModel->zip());
     $ret .= '</table>';
     echo json_encode(array('customer' => $ret, 'footer' => $extra));
     return false;
 }