function itemParse($upc)
{
    global $FANNIE_OP_DB, $FANNIE_URL;
    global $FANNIE_STORE_ID;
    global $FANNIE_COOP_ID;
    global $FANNIE_COMPOSE_PRODUCT_DESCRIPTION;
    global $FANNIE_COMPOSE_LONG_PRODUCT_DESCRIPTION;
    $dbc = FannieDB::get($FANNIE_OP_DB);
    //global $FANNIE_ITEM_MODULES;
    // This is both whether-or-not and sequence-on-page
    //"ThreeForDollar",
    $Fannie_Item_Modules = array("Operations", "ItemFlags", "ExtraInfo", "ThreeForDollar", "Cost", "Sale", "Margin", "LikeCode", "LaneStatus");
    $logged_in = checkLogin();
    // 1. Lookup on the request argument.
    $queryItem = "";
    $numType = isset($_REQUEST['ntype']) ? $_REQUEST['ntype'] : 'UPC';
    // 8Mar13 EL || SKU
    if (is_numeric($upc) || $numType == 'SKU') {
        switch ($numType) {
            case 'UPC':
                $upc = str_pad($upc, 13, 0, STR_PAD_LEFT);
                $savedUPC = $upc;
                $queryItem = "SELECT p.*,x.distributor,x.manufacturer\n                    ,v.sku,v.vendorDept\n                    FROM products AS p LEFT JOIN\n                    prodExtra AS x ON p.upc=x.upc\n                    LEFT JOIN vendorItems AS v ON v.upc=p.upc\n                    WHERE (p.upc = '{$upc}' or x.upc = '{$upc}')\n                    AND p.store_id=0";
                break;
            case 'SKU':
                $queryItem = "SELECT p.*,x.distributor,x.manufacturer\n                    ,v.sku,v.vendorDept\n                    FROM products AS p INNER JOIN\n                    vendorItems AS v ON p.upc=v.upc\n                    LEFT JOIN prodExtra AS x on p.upc=x.upc\n                    WHERE v.sku='{$upc}'\n                    AND p.store_id=0";
                break;
            case 'Brand Prefix':
                $queryItem = "SELECT p.*,x.distributor,x.manufacturer\n                    ,v.sku,v.vendorDept\n                    FROM products AS p LEFT JOIN\n                    prodExtra AS x ON p.upc=x.upc\n                    LEFT JOIN vendorItems AS v ON v.upc=p.upc\n                    WHERE p.upc like '%{$upc}%'\n                    AND p.store_id=0\n                    ORDER BY p.upc";
                break;
        }
    } else {
        /* note: only search by HQ records (store_id=0) to avoid duplicates */
        $queryItem = "SELECT p.*,x.distributor,x.manufacturer\n        FROM products AS p LEFT JOIN\n        prodExtra AS x ON p.upc=x.upc\n        WHERE description LIKE '%{$upc}%'\n        AND p.store_id=0\n        ORDER BY description";
    }
    $resultItem = $dbc->query($queryItem);
    $num = $dbc->num_rows($resultItem);
    $likeCodeQ = "SELECT u.*,l.likeCodeDesc FROM upcLike as u, likeCodes as l\n            WHERE u.likeCode = l.likeCode and u.upc = '{$upc}'";
    $likeCodeR = $dbc->query($likeCodeQ);
    $likeCodeRow = $dbc->fetch_row($likeCodeR);
    $likeCodeNum = $dbc->num_rows($likeCodeR);
    $likecode = $likeCodeNum > 0 ? $likeCodeRow[1] : '';
    // 2. Compose code in the HEAD of the HTML page.
    echo "<script type=\"text/javascript\">";
    echo "function shelftag(u){";
    echo "testwindow= window.open (\"addShelfTag.php?upc=\"+u, \"New Shelftag\",\"location=0,status=1,scrollbars=1,width=300,height=220\");";
    echo "testwindow.moveTo(50,50);";
    echo "}";
    echo "</script>";
    echo "<script type='text/javascript'>\n        \$(document).ready(function(){\n            \$('#start_date').datepicker(); \n            \$('#end_date').datepicker(); \n        });\n        </script>";
    // 3. No match. Compose form for creation of a new item.
    if ($num == 0 || !$num) {
        $data = array();
        if (is_numeric($upc) || $numType == 'SKU') {
            $searchField = $numType == 'SKU' ? 'sku' : 'upc';
            $dataQ = "SELECT description,brand,cost/units as cost,vendorName,margin,i.vendorID,\n                    i.size,i.units,i.cost as case_cost,i.sku,i.upc\n                FROM vendorItems AS i LEFT JOIN vendors AS v ON i.vendorID=v.vendorID\n                LEFT JOIN vendorDepartments AS d ON i.vendorDept=d.deptID\n                WHERE {$searchField} = '{$upc}'";
            // When would this be set?
            if (isset($_REQUEST['vid'])) {
                $dataQ .= " AND i.vendorID=" . (int) $_REQUEST['vid'];
            }
            $dataR = $dbc->query($dataQ);
            if ($dbc->num_rows($dataR) > 0) {
                $data = $dbc->fetch_row($dataR);
                // ->EL vendorItems.cost is case_cost but data[cost] is unit_cost.
                if (is_numeric($data['cost']) && is_numeric($data['margin'])) {
                    $data['srp'] = getSRP($data['cost'], $data['margin']);
                }
                if (preg_match("/(\\d+) *([a-z]+)/", $data['size'], $matches)) {
                    $numeric_size = $matches[1];
                    $unitofmeasure = $matches[2];
                }
            }
        }
        $char_count_class = "char_count";
        if (isset($FANNIE_COMPOSE_PRODUCT_DESCRIPTION) && $FANNIE_COMPOSE_PRODUCT_DESCRIPTION == "1") {
            $char_count_class = "char_count_pkg";
        }
        // Is <head> ever closed for Create?
        echo "<BODY onLoad='putFocus(0,1);'>";
        noItem();
        if (count($data) > 0) {
            echo "<br /><i>This product is in the " . $data['vendorName'] . " catalog. Values have\n                been filled in where possible</i><br />";
            while ($vendorW = $dbc->fetch_row($dataR)) {
                printf('This product is also in <a href="?upc=%s&vid=%d">%s</a><br />', $upc, $vendorW['vendorID'], $vendorW['vendorName']);
            }
        }
        echo "<form name=pickSubDepartment action=insertItem_WEFC_Toronto.php method=post>";
        // 3a. Create - First Block
        echo "<div id='createBlock'><table style=\"margin-bottom:5px;\" width=\"100%\" border=1 cellpadding=5 cellspacing=0>";
        // 8Mar13 Use looked-up upc if there was one.
        echo "<tr><td align=right><b>UPC</b></td><td><font color='red'></font><input type=text value='";
        echo empty($data['upc']) ? $upc : $data['upc'];
        echo "' name=upc></td><td colspan=2>&nbsp;</td>";
        echo "</tr><tr><td><b>Description</b></td><td><input type=text size=30 name='descript' id='descript' class='{$char_count_class}' ";
        echo isset($data['description']) ? "value=\"{$data['description']}\"" : "";
        echo " />";
        echo '<div id="descript_count" style="width:1.5em; height:1.4em; text-align:center; padding-top: 0.1em; float:right; margin:0em 3em 0em 0em; border:1px solid #666666;">Char ct</div>';
        echo "</td>";
        echo "<td align=right><b>Price</b> \$</td>";
        echo "<td><input type=text id=price name=price size=6 value='" . showAsMoney($data, "srp") . "' /></td></tr>";
        //New{
        echo "<tr><td align=right><b>Package Size</b></td><td colspan=1><input type=text name=size id=size size=4 value=\"" . (isset($numeric_size) ? $numeric_size : "") . "\" /> &nbsp; <span title='g oz qt l ml ct'><b>Unit of measure</b></span> <input type=text name=unitofmeasure id=unitofmeasure size=4 value=\"" . (isset($unitofmeasure) ? $unitofmeasure : "") . "\" /></td>";
        echo "<td align=right><b>Vendor SKU</b></td><td colspan=1><input type=text name=sku size=8 ";
        printf("value=\"%s\"", isset($data['sku']) ? $data['sku'] : '');
        echo "></td></tr>";
        echo "<tr><td align=right><b>Long Desc.</b></td><td colspan=2><input type=text name=puser_description size=60 ";
        echo isset($data['description']) ? "value=\"{$data['description']}\"" : "";
        echo " /></td>";
        echo "<td colspan=1> &nbsp; </td></tr>";
        //new}
        echo "<tr><td><b>Manufacturer</b></td><td><input type=text name=manufacturer size=30 ";
        echo isset($data['brand']) ? "value=\"{$data['brand']}\"" : "";
        echo "/></td>\n        <td><b>Distributor</b></td><td><input type=text size=8 name=distributor ";
        echo isset($data['vendorName']) ? "value=\"{$data['vendorName']}\"" : "";
        echo "/></td></tr>";
        echo "</table>";
        // 3b. Create - Second Block
        echo "<table style=\"margin-bottom:5px;\" width='100%' border=1 cellpadding=5 cellspacing=0><tr>";
        echo "<th>Department - Sub-Depts</th><th>Tax</th><th>FS</th><th>Scale</th><th>QtyFrc</th><th>NoDisc</th>";
        echo "</tr>";
        echo "<tr align=top>";
        echo "<td align=left width=5px>";
        /**
         **    BEGIN CHAINEDSELECTOR CLASS
         **/
        require '../src/chainedSelectors.php';
        //prepare names
        $selectorNames = array(CS_FORM => "pickSubDepartment", CS_FIRST_SELECTOR => "department", CS_SECOND_SELECTOR => "subdepartment");
        //        $department = $rowItem[12] ['department'];
        //        $subdepartment = $rowItem[27] ['subdept'];
        //query database, assemble data for selectors
        $Query = "SELECT d.dept_no AS dept_no, d.dept_name AS dept_name,\n                    CASE WHEN s.subdept_no IS NULL THEN 0 ELSE s.subdept_no END as subdept_no,\n                    CASE WHEN s.subdept_name IS NULL THEN 'None' ELSE s.subdept_name END AS subdept_name\n                    FROM departments AS d LEFT JOIN\n                    subdepts AS s ON d.dept_no=s.dept_ID\n                    ORDER BY d.dept_no,s.subdept_no";
        if (!($DatabaseResult = $dbc->query($Query))) {
            print "The chained-selector query failed!<br>\n";
            return;
        }
        while ($row = $dbc->fetch_object($DatabaseResult)) {
            $selectorData[] = array(CS_SOURCE_ID => $row->dept_no, CS_SOURCE_LABEL => $row->dept_name, CS_TARGET_ID => $row->subdept_no, CS_TARGET_LABEL => $row->subdept_name);
        }
        //instantiate class
        $subdept = new chainedSelectors($selectorNames, $selectorData);
        ?>
                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html40/loose.dtd">
                    <html>
                    <head>
                    <script type="text/javascript" language="JavaScript">
                    <?php 
        $subdept->printUpdateFunction($row);
        //rowItem
        ?>
                    </script>
                    </head>
                    <body>
                    <!-- <form name="pickSubDepartment" action="insertItem.php"> -->
                    <?php 
        $subdept->printSelectors($row);
        //rowItem
        ?>
                    <script type="text/javascript" language="JavaScript">
                    <?php 
        $subdept->initialize();
        ?>
                    </script>
                    </body>
                    </html>
                <?php 
        /**
         **    CHAINEDSELECTOR CLASS ENDS . . . . . . . NOW
         **/
        echo "</td><td align=left>";
        $taxQ = "SELECT id,description FROM taxrates ORDER BY id";
        $taxR = $dbc->query($taxQ);
        $rates = array();
        while ($taxW = $dbc->fetch_row($taxR)) {
            array_push($rates, array($taxW[0], $taxW[1]));
        }
        array_push($rates, array("0", "NoTax"));
        echo "<select name=tax>";
        foreach ($rates as $r) {
            echo "<option value={$r['0']}";
            if ($r[0] == "0") {
                echo " selected";
            }
            echo ">{$r['1']}</option>";
        }
        echo "</select></td>";
        echo "<td align=center><input type=checkbox value=1 name=FS";
        echo "></td><td align=center><input type=checkbox value=1 name=Scale";
        echo "></td><td align=center><input type=checkbox value=1 name=QtyFrc";
        echo "></td><td align=center><input type=checkbox value=1 name=NoDisc";
        echo "></td>";
        echo "</tr></table><!-- /div #createBlock?-->";
        echo "<div style='margin: 1.0em 0.0em 0.5em 0.0em;'>";
        echo "<input type=submit value=\"Create Item\" />\n            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n            <a href='../item/itemMaint_WEFC_Toronto.php'><span style='font-size:1.1em;'>Back</span></a>";
        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n                        <span style='color:darkmagenta;'>Last modified: " . date('r') . "</span>";
        echo "</div>";
        echo "</div><!-- /#createBlock --> ";
        // 's Create - Deli scale item
        if (substr($upc, 0, 3) == "002") {
            // 3c. Create - Deli-Scale Fieldset
            echo "<br /><div align=center><fieldset><legend>Scale</legend>";
            echo "<input type=hidden value=\"{$upc}\" name=s_plu />";
            echo "<table style=\"background:#ffffcc;\" cellpadding=5 cellspacing=0 border=1>";
            echo "<tr><th colspan=2>Longer description</th><td colspan=4><input size=35 type=text name=s_longdesc maxlength=100";
            echo " /></td></tr>";
            echo "<tr><td colspan=6 style=\"font-size:1px;\">&nbsp;</td></tr>";
            echo "<tr><th>Weight</th><th>By Count</th><th>Tare</th><th>Shelf Life</th>";
            echo "<th>Label</th><th>Safehandling</th></tr>";
            echo "<tr>";
            echo "<td>";
            echo "<input type=radio name=s_type value=\"Random Weight\" checked /> Random<br />";
            echo "<input type=radio name=s_type value=\"Fixed Weight\" /> Fixed<br />";
            echo "</td>";
            echo "<td align=center><input type=checkbox name=s_bycount ";
            echo "/></td>";
            echo "<td align=center><input type=text size=5 name=s_tare ";
            echo "value=0 /></td>";
            echo "<td align=center><input type=text size=5 name=s_shelflife ";
            echo "value=0 /></td>";
            echo "<td><select name=s_label size=2>";
            echo "<option value=horizontal selected>Horizontal</option>";
            echo "<option value=vertical>Vertical</option>";
            echo "</td>";
            echo "<td align=center><input type=checkbox name=s_graphics ";
            echo "/></td>";
            echo "</tr>";
            echo "<tr><td colspan=6 style=\"font-size:1px;\">&nbsp;</td></tr>";
            echo "<tr><td colspan=6>";
            echo "<b>Expanded text:<br /><textarea name=s_text rows=4 cols=50>";
            echo "</textarea></td></tr>";
            echo "</table></fieldset></div>";
            // Create - Deli-Scale
        }
        $fieldsetWidth = 13;
        // 3d. Create - Operations Fieldset
        echo "<div id='Operations' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Operations', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Operations</legend>";
        echo "<div style=\"float:left;\"><ul style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<li style='margin-left:-2.0em;'><input type=checkbox name=newshelftag /> New Shelf Tag</a></li>";
        echo "<li style='margin-left:-2.0em;'>Recent Sales<br />History</li>";
        echo "<li style='margin-left:-2.0em;'>Price History</li>";
        echo "</ul></div>";
        echo "</fieldset>";
        echo "</div><!-- /#Operations -->";
        //'c 3ea. Create - Item Flags Fieldset
        echo "<div id='Flags' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('ItemFlags', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Item Flags</legend>";
        echo "<table>";
        $q = "SELECT f.description,\n        f.bit_number,\n        (1<<(f.bit_number-1)) & p.numflag AS flagIsSet\n        FROM products AS p, prodFlags AS f\n        WHERE p.upc={$upc}";
        $r = $dbc->query($q);
        // item does not exist. Just get the flag names.
        if ($dbc->num_rows($r) == 0) {
            $q = 'SELECT f.description,f.bit_number,0 AS flagIsSet
                FROM prodFlags AS f';
            $r = $dbc->query($q);
        }
        $ret = '';
        $i = 0;
        while ($w = $dbc->fetch_row($r)) {
            if ($i == 0) {
                $ret .= '<tr>';
            }
            // n-column table
            if ($i != 0 && $i % 2 == 0) {
                $ret .= '</tr><tr>';
            }
            $ret .= sprintf('<td><input type="checkbox" name="flags[]" value="%d" %s /></td>
            <td>%s</td>', $w['bit_number'], $w['flagIsSet'] == 0 ? '' : 'checked', $w['description']);
            $i++;
        }
        if (strlen($ret) > 0) {
            $ret .= "</tr>";
        }
        echo "{$ret}";
        echo "</table>";
        echo "</fieldset>";
        echo "</div><!-- /#ItemFlags -->";
        // 3eb. Create - Extra Info Fieldset
        echo "<div id='ExtraInfo' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('ExtraInfo', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Extra Info</legend>";
        echo "<table><th align=right>Deposit</th>";
        echo "<td> <input type='text'";
        echo "name='deposit' size='5' value=0></td>";
        echo "</tr><th align-right>Location</th>";
        echo "<td><input type=text size=5 value=\"\" name=location /></td>";
        echo "</tr><th align=right>Local</th>";
        echo "<td><input type=checkbox name=local /></td>";
        echo "</tr><th align=right>InUse</th>";
        echo "<td><input type=checkbox name=inUse checked /></td>";
        echo "</tr></table>";
        echo "</fieldset>";
        echo "</div><!-- /#ExtraInfo -->";
        // 3f. Create - Multiples Fieldset
        // There will never be existing values.
        echo "<div id='ThreeForDollar' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('ThreeForDollar', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo '<fieldset><legend>"Three for a dollar"</legend>';
        echo "<div id='ThreeForDollarRegIn' style='display:block;'>";
        echo "<table style='margin:0.0em 0.0em 0.8em 0.0em;'>";
        echo "<tr><th align-right>#items</th>";
        echo "<td> <input type='text' name='quantity' size='5' value='0'></td>";
        echo "</tr><tr><th align=right>For <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text name='groupprice' size=5 value='0.00'></td>";
        // ?pricemethod must default to 0.
        echo "</tr><th align-right>Method</th>";
        echo "<td><input type='text' name='pricemethod' size='5' value='0'></td>";
        echo "</tr><th align-right>MixMatch</th>";
        echo "<td><input type='text' name='mixmatchcode' size='5' value='0'></td>";
        echo "</tr></table>";
        echo "</div><!-- /#ThreeForDollarRegIn -->";
        echo "</fieldset>";
        echo "</div><!-- /#ThreeForDollar -->";
        // 3g. Create - Cost Fieldset
        echo "<div id='Cost' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Cost', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Cost</legend>";
        echo "<!-- div style=\"float:left;margin-left:20px;\" -->";
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<tr><th align=right>Single <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text size=5 value='" . showAsMoney($data, 'cost') . "' id=cost name=cost onchange='cscallback();' /></td>";
        echo "</tr><tr><th align=right>Case <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text name='case_cost' size=5 value='" . showAsMoney($data, 'case_cost') . "' /></td>";
        echo "</tr><tr><th align=right>Items/case</th>";
        printf("<td><input type=text name='case_quantity' size=5 value=\"%s\" /></td>", isset($data['units']) && is_numeric($data['units']) ? $data['units'] : '');
        echo "</tr></table>";
        echo "<!-- /div -->";
        echo "</fieldset>";
        echo "</div><!-- /#Cost -->";
        // 3h. Create - Sale Fieldset
        echo "<div id='Sale' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Sale', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo '<fieldset><legend>Sale</legend>';
        echo "<!-- div style=\"float:left;margin-left:20px;\" -->";
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<tr><th align-right>Start Date</th>";
        echo "<td><input type=text size=6 value='" . date('Y-m-d') . "' name=start_date id=start_date /></td>";
        echo "</tr><tr><th align-right>End Date</th>";
        echo "<td><input type=text size=6 value='" . date('Y-m-d') . "' name=end_date id=end_date /></td>";
        echo "</tr><tr><th align-right>Sale for</th>";
        // This should really be in the db and be per-coop-configurable.
        $discounttypes = array(0 => "None", 1 => "All", 2 => "Mem.");
        echo "<td><select name=discounttype>";
        $data['discounttype'] = 0;
        for ($n = 0; $n < 3; $n++) {
            echo "<option value='{$n}'";
            if ($n == $data['discounttype']) {
                echo " SELECTED";
            }
            echo ">{$discounttypes[$n]}</option>";
        }
        echo "</select></td>";
        echo "</tr><tr><th align=right>Price <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text size=5 value='0.00' id=special_price name=special_price /></td>";
        echo "</tr></table>";
        echo '<fieldset><legend>"Three for a dollar"</legend>';
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        // quantity must default to 0.
        echo "<tr><th align-right>#Items</th>";
        echo "<td> <input type='text' name='specialquantity' size='5' value='0'></td>";
        echo "</tr><tr><th align=right>For <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text name='specialgroupprice' size=5 value='0.00'></td>";
        // ?pricemethod must default to 0.
        echo "</tr><th align-right>Method</th>";
        echo "<td><input type='text' name='specialpricemethod' size='5' value='0'></td>";
        echo "</tr></table>";
        echo '</fieldset><!-- 3/$1 -->';
        echo "<!-- /div -->";
        echo '</fieldset><!-- /#sale -->';
        echo "</div><!-- /#Sale -->";
        // 3i. Create - Margin Fieldset
        echo "<div id='Margin' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Margin', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset id=marginfs>";
        echo "<legend>Margin</legend>";
        echo "</fieldset>";
        echo "<script type=\"text/javascript\">cscallback();</script>";
        echo "</div><!-- /#Margin -->";
        // 3j. Create - Likecode Fieldset
        echo "<div id='LikeCode' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('LikeCode', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo '<fieldset><legend>Likecode</legend>';
        echo "<table border=0><tr><td><b>Like code</b> ";
        $lcWidth = $fieldsetWidth - 4;
        // Was 175px
        echo "<tr><td><select name=likeCode style=\"width: {$lcWidth}em;\"\n        onchange=\"updateLC(this.value);\">";
        echo "<option value=-1>(none)</option>";
        $likelistQ = "select * from likeCodes order by likecode";
        $likelistR = $dbc->query($likelistQ);
        while ($llRow = $dbc->fetch_array($likelistR)) {
            echo "<option value={$llRow[0]}";
            echo ">{$llRow[0]} {$llRow[1]}</option>";
        }
        echo "</select></td></tr>";
        echo "<tr><td><input type=checkbox name=update value='no'>Check to not update like code items</td></tr>";
        echo "<tr id=lchidden style=\"display:none;\"";
        echo "><td><b>Like Code Linked Items</b><div id=lctable>";
        echo '</div></td><td valign=top><a href="../reports/RecentSales/?likecode=' . $likeCodeRow[1] . '" target="_recentlike">';
        echo 'Likecode Sales History</td>';
        echo '</tr></table></fieldset>';
        echo "</div><!-- /#LikeCode -->";
        // Form for Create.
    } elseif ($num > 1) {
        moreItems($upc);
        for ($i = 0; $i < $num; $i++) {
            $rowItem = $dbc->fetch_array($resultItem);
            $upc = $rowItem['upc'];
            echo "<a href='../item/itemMaint_WEFC_Toronto.php?upc={$upc}'>" . $upc . " </a>- " . $rowItem['description'];
            if ($rowItem['discounttype'] == 0) {
                echo "-- \$" . $rowItem['normal_price'] . "<br>";
            } else {
                echo "-- <font color=green>\$" . $rowItem['special_price'] . " onsale</font><br>";
            }
        }
    } else {
        if ($FANNIE_STORE_ID != 0) {
            /* if this isn't HQ, revise the lookup query to search
               for HQ records AND store records
               ordering by store_id descending means we'll get the
               store record if there is one and the HQ record if
               there isn't */
            $clause = sprintf("p.store_id IN (0,%d)", $FANNIE_STORE_ID);
            $queryItem = str_replace("p.store_id=0", $clause, $queryItem);
            if (strstr($queryItem, "ORDER BY")) {
                $queryItem = array_shift(explode("ORDER BY", $queryItem));
            }
            $queryItem .= " ORDER BY p.store_id DESC";
            $resultItem = $dbc->query($queryItem);
        }
        // products.* and prodExtra .manufacturer and .distributor
        $rowItem = $dbc->fetch_array($resultItem);
        // All of prodExtra
        $upc = $rowItem['upc'];
        $xtraQ = "SELECT * FROM prodExtra WHERE upc='{$upc}'";
        $xtraR = $dbc->query($xtraQ);
        $xtraRow = $dbc->fetch_row($xtraR);
        //EL+ All of productUser
        $userQ = "SELECT * FROM productUser WHERE upc='{$upc}'";
        $userR = $dbc->query($userQ);
        $userRow = $dbc->fetch_row($userR);
        /* For WEFC_Toronto only
         * Raw versions of products.description and productUser.descriptio
         *  are in products_WEFC_Toronto
         */
        if (isset($FANNIE_COOP_ID) && $FANNIE_COOP_ID == "WEFC_Toronto") {
            $coopQ = "SELECT * FROM products_{$FANNIE_COOP_ID} WHERE upc='{$upc}'";
            $coopR = $dbc->query($coopQ);
            $coopRow = $dbc->fetch_row($coopR);
            if (!empty($coopRow['description'])) {
                $rowItem['description'] = $coopRow['description'];
            }
            if (!empty($coopRow['search_description'])) {
                $userRow['description'] = $coopRow['search_description'];
            }
        }
        $char_count_class = "char_count";
        if (isset($FANNIE_COMPOSE_PRODUCT_DESCRIPTION) && $FANNIE_COMPOSE_PRODUCT_DESCRIPTION == "1") {
            $char_count_class = "char_count_pkg";
        }
        // Get the previous and next upc from the same department.
        $pnQ = "SELECT upc FROM products WHERE department=" . $rowItem['department'] . " ORDER BY upc";
        $prevUPC = False;
        $nextUPC = False;
        $passed_it = False;
        $pnR = $dbc->query($pnQ);
        while ($pnW = $dbc->fetch_row($pnR)) {
            if (!$passed_it && $upc != $pnW[0]) {
                $prevUPC = $pnW[0];
            } else {
                if (!$passed_it && $upc == $pnW[0]) {
                    $passed_it = True;
                } else {
                    if ($passed_it) {
                        $nextUPC = $pnW[0];
                        break;
                    }
                }
            }
        }
        echo "<head><title>Update Item</title>";
        echo "</head>";
        echo "<body onload='putFocus(0,3);'>";
        oneItem($upc);
        echo "<form name=pickSubDepartment action='updateItems_WEFC_Toronto.php' method=post>";
        // 5a. Update - First Block
        echo "<div id='updateBlock' style=''><table border=1 cellpadding=5 cellspacing=0>";
        echo "<tr><td align=right><b>UPC</b></td><td><font color='red'>" . $rowItem['upc'] . "</font><input type=hidden value='{$rowItem['upc']}' id=upc name=upc>";
        if ($prevUPC) {
            echo " <a style=\"font-size:85%;\" href=itemMaint_WEFC_Toronto.php?upc={$prevUPC}>Previous</a>";
        }
        if ($nextUPC) {
            echo " <a style=\"font-size:85%;\" href=itemMaint_WEFC_Toronto.php?upc={$nextUPC}>Next</a>";
        }
        echo '</td>';
        echo '<td colspan=2>';
        echo '<input type="hidden" name="store_id" value="' . $rowItem['store_id'] . '" />';
        echo ($rowItem['store_id'] == 0 ? 'Master' : 'Store') . ' record';
        echo '</td></tr><tr><td align=right><b>Description</b></td><td>';
        echo '<input type=text size=30 value="' . $rowItem['description'] . '" name="descript" id="descript" ' . "class='{$char_count_class}' />";
        echo '<div id="descript_count" style="width:1.5em; height:1.4em; text-align:center; padding-top: 0.1em; float:right; margin:0em 3em 0em 0em; border:1px solid #666666;">Char ct</div>';
        echo '</td>';
        // If the ThreeForDollar (Multiples) fieldset/module is enabled support only normal_price editing here.
        if (array_search('ThreeForDollar', $Fannie_Item_Modules) !== False) {
            echo "<td align=right><b>Price</b></td>";
            echo '<td><span id=price1 style="display:' . (True ? 'inline' : 'none') . ';">$ <input id=price type=text value="' . showAsMoney($rowItem, 'normal_price') . '" name=price size=6></span></td></tr>';
        } else {
            echo "<td><select onchange=\"if(this.value=='Price'){\n                document.getElementById('price2').style.display='none';\n                document.getElementById('price1').style.display='inline';\n                }else{\n                document.getElementById('price1').style.display='none';\n                document.getElementById('price2').style.display='inline';\n                }\">\n                <option" . ($rowItem['groupprice'] == 0 ? ' SELECTED' : '') . ">Price</option>\n                <option" . ($rowItem['groupprice'] != 0 ? ' SELECTED' : '') . ">Volume Price</option></select></td>";
            echo '<td><span id=price1 style="display:' . ($rowItem['groupprice'] == 0 ? 'inline' : 'none') . ';">$ <input id=price type=text value="' . showAsMoney($rowItem, 'normal_price') . '" name=price size=6></span>';
            echo '<span id=price2 style="display:' . ($rowItem['groupprice'] == 0 ? 'none' : 'inline') . ';"><input type=text size=4 name=vol_qtty value="' . ($rowItem['quantity'] != 0 ? $rowItem['quantity'] : '') . '" />';
            echo " for \$<input type=text size=4 name=vol_price value=" . ($rowItem['groupprice'] != 0 ? $rowItem['groupprice'] : "\"\"") . " />";
            echo '<input type=checkbox name=doVolume ' . ($rowItem['groupprice'] != 0 ? 'checked' : '') . ' /></span>';
            echo '<input type=hidden name=vol_pricemethod value=' . $rowItem['pricemethod'] . ' />';
            echo '</td></tr>';
        }
        echo "<tr><td align=right><b>Package Size</b></td><td colspan=1><input type=text name=size id=size size=4 value=\"" . (isset($rowItem['size']) ? $rowItem['size'] : "") . "\" /> &nbsp; <span title='g oz qt l ml ct'><b>Unit of measure</b></span> <input type=text name=unitofmeasure id=unitofmeasure size=4 value=\"" . (isset($rowItem['unitofmeasure']) ? $rowItem['unitofmeasure'] : "") . "\" /></td>";
        echo "<td align=right><b>Vendor SKU</b></td><td colspan=1><input type=text name=sku size=8 value=\"" . (isset($rowItem['sku']) ? $rowItem['sku'] : "") . "\" /></td></tr>";
        echo "<tr><td align=right><b>Long Desc.</b></td><td colspan=2><input type=text name=puser_description size=60 value=\"" . (isset($userRow['description']) ? $userRow['description'] : "") . "\" /></td>";
        echo "<td colspan=1> &nbsp; </td></tr>";
        echo "<tr><td align=right><b>Manufacturer</b></td><td><input type=text name=manufacturer size=30 value=\"" . (isset($xtraRow['manufacturer']) ? $xtraRow['manufacturer'] : "") . "\" /></td>";
        echo "<td align=right><b>Distributor</b></td><td><input type=text name=distributor size=8 value=\"" . (isset($xtraRow['distributor']) ? $xtraRow['distributor'] : "") . "\" /></td></tr>";
        // If the item is on sale.
        if ($rowItem['special_price'] != 0) {
            $batchQ = "SELECT b.batchName FROM batches AS b\n                LEFT JOIN batchList as l ON b.batchID=l.batchID\n                WHERE '" . date('Y-m-d') . "' BETWEEN b.startDate\n                AND b.endDate AND (l.upc='{$upc}' OR l.upc='LC{$likecode}')";
            $batchR = $dbc->query($batchQ);
            $batch = "Unknown";
            if ($dbc->num_rows($batchR) > 0) {
                $batch = array_pop($dbc->fetch_row($batchR));
            }
            echo "<tr><td><font color=green><b>Sale Price:</b></font></td>" . "<td><font color=green>{$rowItem['special_price']}</font> (<em>Batch: {$batch}</em>)</td>";
            echo "<td><font color=green>End Date:</td><td><font color=green>{$rowItem['end_date']}</font></td><tr>";
        }
        echo "</table>";
        // 5b. Update - Second Block
        echo "<table style=\"margin-top:5px;margin-bottom:5px;\" border=1 cellpadding=5 cellspacing=0 width='100%'><tr>";
        echo "<th>Deparment - Sub-Depts</th><th>Tax</th><th>FS</th><th>Scale</th><th>QtyFrc</th><th>NoDisc</th>";
        echo "</tr>";
        echo "<tr align=top>";
        echo "<td align=left>";
        /**
         **  BEGIN CHAINEDSELECTOR CLASS
         **/
        $selectorNames = array(CS_FORM => "pickSubDepartment", CS_FIRST_SELECTOR => "department", CS_SECOND_SELECTOR => "subdepartment");
        $Query = "SELECT d.dept_no AS dept_no, d.dept_name AS dept_name,\n                CASE WHEN s.subdept_no IS NULL THEN 0 ELSE s.subdept_no END as subdept_no,\n                CASE WHEN s.subdept_name IS NULL THEN 'None' ELSE s.subdept_name END AS subdept_name\n                FROM departments AS d LEFT JOIN\n                subdepts AS s ON d.dept_no=s.dept_ID\n                ORDER BY d.dept_no,s.subdept_no";
        $DatabaseResult = False;
        if (!($DatabaseResult = $dbc->query($Query))) {
            print "The query failed!<br>\n";
            return;
        }
        while ($row = $dbc->fetch_object($DatabaseResult)) {
            $selectorData[] = array(CS_SOURCE_ID => $row->dept_no, CS_SOURCE_LABEL => $row->dept_no . " - " . $row->dept_name, CS_TARGET_ID => $row->subdept_no, CS_TARGET_LABEL => $row->subdept_name);
        }
        $subdept = new chainedSelectors($selectorNames, $selectorData);
        ?>
                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html40/loose.dtd">
                <html>
                <head>
                <script type="text/javascript" language="JavaScript">
                <?php 
        $subdept->printUpdateFunction($rowItem);
        ?>
                </script>
                </head>
                <body>
                <!-- <form name="pickSubDepartment" action="updateItems.php"> -->
                <?php 
        $subdept->printSelectors($rowItem);
        ?>
                <script type="text/javascript" language="JavaScript">
                <?php 
        $subdept->initialize();
        ?>
                </script>
                </body>
                </html>
            <?php 
        /**
         **  CHAINEDSELECTOR CLASS ENDS . . . . . . . NOW
         **/
        //                echo " </td>";
        echo "</td><td align=left>";
        $taxQ = "SELECT id,description FROM taxrates ORDER BY id";
        $taxR = $dbc->query($taxQ);
        $rates = array();
        while ($taxW = $dbc->fetch_row($taxR)) {
            array_push($rates, array($taxW[0], $taxW[1]));
        }
        array_push($rates, array("0", "NoTax"));
        echo "<select name=tax>";
        foreach ($rates as $r) {
            echo "<option value={$r['0']}";
            if ($rowItem['tax'] == $r[0]) {
                echo " selected";
            }
            echo ">{$r['1']}</option>";
        }
        echo "</select>";
        echo "</td><td align=center><input type=checkbox value=1 name=FS";
        if ($rowItem["foodstamp"] == 1) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=1 name=Scale";
        if ($rowItem['scale'] == 1) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=1 name=QtyFrc";
        if ($rowItem["qttyEnforced"] == 1) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=0 name=NoDisc";
        if ($rowItem["discount"] == 0) {
            echo " checked";
        }
        echo "></td>";
        echo "</tr><tr></table>";
        echo "<div style='margin: 1.0em 0.0em 0.5em 0.0em;'>";
        echo "<input type='submit' name='submit' value='Update Item'>\n            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n            <a href='../item/itemMaint_WEFC_Toronto.php'><span style='font-size:1.1em;'>Back</span></a>";
        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n                        <span style='color:darkmagenta;'>Last modified: {$rowItem['modified']}</span>";
        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n                     <a href=\"deleteItem_WEFC_Toronto.php?upc={$upc}&submit=submit\">Delete this item</a>";
        echo "</div> ";
        echo "</div><!-- /#updateBlock --> ";
        if (substr($upc, 0, 3) == "002") {
            // 5c. Update - Deli-Scale Fieldset
            // Might be better to do top whitespace with margin.
            echo "<br /><div align=center><fieldset><legend>Scale</legend>";
            echo "<input type=hidden value=\"{$upc}\" name=s_plu />";
            $scaleR = $dbc->query("SELECT * FROM scaleItems WHERE plu='{$upc}'");
            $scale = array();
            if ($dbc->num_rows($scaleR) > 0) {
                $scale = $dbc->fetch_row($scaleR);
            }
            echo "<table style=\"background:#ffffcc;\" cellpadding=5 cellspacing=0 border=1>";
            echo "<tr><th colspan=2>Longer description</th><td colspan=4><input size=35 type=text name=s_longdesc maxlength=100";
            if (isset($scale['itemdesc']) && $scale['itemdesc'] != $rowItem['description']) {
                echo " value=\"" . $scale['itemdesc'] . "\"";
            }
            echo " /></td></tr>";
            echo "<tr><td colspan=6 style=\"font-size:1px;\">&nbsp;</td></tr>";
            echo "<tr><th>Weight</th><th>By Count</th><th>Tare</th><th>Shelf Life</th>";
            echo "<th>Label</th><th>Safehandling</th></tr>";
            echo "<tr>";
            echo "<td>";
            if (!isset($scale['weight']) || $scale['weight'] == 0) {
                echo "<input type=radio name=s_type value=\"Random Weight\" checked /> Random<br />";
                echo "<input type=radio name=s_type value=\"Fixed Weight\" /> Fixed<br />";
            } else {
                echo "<input type=radio name=s_type value=\"Random Weight\" /> Random<br />";
                echo "<input type=radio name=s_type value=\"Fixed Weight\" checked /> Fixed<br />";
            }
            echo "</td>";
            echo "<td align=center><input type=checkbox name=s_bycount ";
            if (isset($scale['bycount']) && $scale['bycount'] == 1) {
                echo "checked ";
            }
            echo "/></td>";
            echo "<td align=center><input type=text size=5 name=s_tare ";
            echo "value=" . (isset($scale['tare']) ? $scale['tare'] : '0');
            echo " /></td>";
            echo "<td align=center><input type=text size=5 name=s_shelflife ";
            echo "value=" . (isset($scale['shelflife']) ? $scale['shelflife'] : '0');
            echo " /></td>";
            echo "<td><select name=s_label size=2>";
            if (isset($scale['label']) && ($scale['label'] == 133 || $scale['label'] == 63)) {
                echo "<option value=horizontal selected>Horizontal</option>";
                echo "<option value=vertical>Vertical</option>";
            } else {
                if (!isset($scale['label'])) {
                    echo "<option value=horizontal selected>Horizontal</option>";
                    echo "<option value=vertical>Vertical</option>";
                } else {
                    echo "<option value=horizontal>Horizontal</option>";
                    echo "<option value=vertical selected>Vertical</option>";
                }
            }
            echo "</td>";
            echo "<td align=center><input type=checkbox name=s_graphics ";
            if (isset($scale['graphics']) && $scale['graphics'] == 1) {
                echo "checked ";
            }
            echo "/></td>";
            echo "</tr>";
            echo "<tr><td colspan=6 style=\"font-size:1px;\">&nbsp;</td></tr>";
            echo "<tr><td colspan=6>";
            echo "<b>Expanded text:<br /><textarea name=s_text rows=4 cols=50>";
            echo isset($scale['text']) ? $scale['text'] : '';
            echo "</textarea></td></tr>";
            echo "</table></fieldset></div>";
            // Update - Deli-Scale
        }
        // 5d. Update - Operations Fieldset
        $fieldsetWidth = 13;
        echo "<div id='Operations' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Operations', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Operations</legend>";
        echo "<div style=\"float:left;\"><ul style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<li style='margin-left:-2.0em;'><a href=\"javascript:shelftag('{$upc}');\" title='Using the un-edited data.' >Current Shelf Tag</a></li>";
        echo "<li style='margin-left:-2.0em;'><input type=checkbox name=newshelftag title='Using the edited data, after you click Update.' /> <span title='Using the edited data, after you click Update.'>New Shelf Tag</span></li>";
        echo "<li style='margin-left:-2.0em;'><a href=\"../reports/RecentSales/?upc={$upc}\" target='_recentsales'>";
        echo "Recent Sales<br /> History</a></li>";
        //echo "</ul></div>";
        //echo "<div style=\"float:left;\"><ul style='margin-top:0.0em;'>";
        echo "<li style='margin-left:-2.0em;'><a href=\"../reports/PriceHistory/?upc={$upc}\" target=\"_price_history\">Price History</a></li>";
        echo "</ul></div>";
        echo "</fieldset>";
        echo "</div>";
        echo "</div><!-- /#Operations -->";
        //'u 5ea. Update - Item Flags Fieldset
        echo "<div id='Flags' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('ItemFlags', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Item Flags</legend>";
        echo "<table>";
        $q = "SELECT f.description,\n            f.bit_number,\n            (1<<(f.bit_number-1)) & p.numflag AS flagIsSet\n            FROM products AS p, prodFlags AS f\n            WHERE p.upc={$upc}\n            ORDER BY f.bit_number";
        $r = $dbc->query($q);
        // item does not exist. Just get the flag names.
        if ($dbc->num_rows($r) == 0) {
            $q = 'SELECT f.description,f.bit_number,0 AS flagIsSet
                    FROM prodFlags AS f';
            $r = $dbc->query($q);
        }
        $ret = '';
        $i = 0;
        while ($w = $dbc->fetch_row($r)) {
            if ($i == 0) {
                $ret .= '<tr>';
            }
            // n-column table
            if ($i != 0 && $i % 2 == 0) {
                $ret .= '</tr><tr>';
            }
            $ret .= sprintf('<td><input type="checkbox" name="flags[]" value="%d" %s /></td>
                <td>%s</td>', $w['bit_number'], $w['flagIsSet'] == 0 ? '' : 'checked', $w['description']);
            $i++;
        }
        if (strlen($ret) > 0) {
            $ret .= "</tr>";
        }
        echo "{$ret}";
        echo "</table>";
        echo "</fieldset>";
        echo "</div><!-- /#ItemFlags -->";
        // 5e. Update - Extra Info Fieldset
        // ->EL Why does the top of this fieldset align below the top of Operations here but even with it in Create?
        echo "<div id='ExtraInfo' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('ExtraInfo', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Extra Info</legend>";
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<tr><th align=right>Deposit</th>";
        echo "<td> <input type='text' name='deposit' ";
        if (!isset($rowItem['deposit']) || $rowItem['deposit'] == 0) {
            echo "value='0'";
        } else {
            echo "value='{$rowItem['deposit']}'";
        }
        echo " size='5'></td>";
        echo "</tr><th align-right>Location</th>";
        echo "<td><input type=text name=location size=5 value=\"{$xtraRow['location']}\" /></td>";
        echo "</tr><th align=right>Local</th>";
        echo "<td><input type=checkbox name=local " . ($rowItem['local'] == 1 ? 'checked' : '') . " /></td>";
        echo "</tr><th align=right>InUse</th>";
        echo "<td><input type=checkbox name=inUse " . ($rowItem['inUse'] == 1 ? 'checked' : '') . " /></td>";
        echo "</tr></table>";
        echo "</fieldset>";
        echo "</div><!-- /#ExtraInfo -->";
        // 5f. Update - Multiples Fieldset
        echo "<div id='ThreeForDollar' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('ThreeForDollar', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo '<fieldset><legend>"Three for a dollar"</legend>';
        echo "<div id='ThreeForDollarRegIn' style='display:block;'>";
        echo "<table style='margin:0.0em 0.0em 0.8em 0.0em;'>";
        echo "<tr><th align-right>#items</th>";
        echo "<td> <input type='text'";
        if (!isset($rowItem['quantity']) || $rowItem['quantity'] == 0) {
            echo "value='0'";
        } else {
            echo "value='{$rowItem['quantity']}'";
        }
        echo "name='quantity' size='5'></td>";
        echo "</tr><tr><th align=right>For <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text size=5 value='" . showAsMoney($rowItem, "groupprice") . "' id=groupprice name=groupprice /></td>";
        // ?pricemethod must default to 0.
        echo "</tr><th align-right>Method</th>";
        echo "<td> <input type='text'";
        if (!isset($rowItem['pricemethod']) || $rowItem['pricemethod'] == 0) {
            echo "value='0'";
        } else {
            echo "value='{$rowItem['pricemethod']}'";
        }
        echo "id='pricemethod' name='pricemethod' size='5'></td>";
        echo "</tr><th align-right>MixMatch</th>";
        echo "<td><input type=text size=5 value=\"{$rowItem['mixmatchcode']}\" name=mixmatchcode /></td>";
        echo "</tr></table>";
        echo "</div><!-- /#ThreeForDollarRegIn -->";
        echo "</fieldset>";
        echo "</div><!-- /#ThreeForDollar -->";
        // 5g. Update - Cost Fieldset
        echo "<div id='Cost' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Cost', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Cost</legend>";
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<tr><th align=right>Single <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text size=5 value='" . showAsMoney($rowItem, 'cost') . "' id=cost name=cost onchange='cscallback();' /></td>";
        echo "</tr><tr><th align=right>Case <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text name='case_cost' size=5 value='" . showAsMoney($xtraRow, 'case_cost') . "' /></td>";
        echo "</tr><tr><th align=right>Items/case</th>";
        printf("<td><input type=text name='case_quantity' size=5 value=\"%s\" /></td>", isset($xtraRow['case_quantity']) && is_numeric($xtraRow['case_quantity']) ? $xtraRow['case_quantity'] : '');
        echo "</tr></table>";
        echo "</fieldset>";
        echo "</div><!-- /#Cost -->";
        // 5h. Update - Sale Fieldset
        echo "<div id='Sale' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Sale', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo '<fieldset><legend>Sale</legend>';
        echo "<!-- div style=\"float:left;margin-left:20px;\" -->";
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        echo "<tr><th align-right>Start Date</th>";
        echo "<td><input type=text name=start_date size=6 value=\"{$rowItem['start_date']}\" id=start_date /></td>";
        echo "</tr><tr><th align-right>End Date</th>";
        echo "<td><input type=text name=end_date size=6 value=\"{$rowItem['end_date']}\" id=end_date /></td>";
        echo "</tr><tr><th align-right>Sale for</th>";
        // This should really be in the db and be per-coop-configurable.
        $discounttypes = array(0 => "None", 1 => "All", 2 => "Mem.");
        echo "<td><select name=discounttype>";
        if ($rowItem['discounttype'] == "") {
            $rowItem['discounttype'] = 0;
        }
        for ($n = 0; $n < 3; $n++) {
            echo "<option value='{$n}'";
            if ($n == $rowItem['discounttype']) {
                echo " SELECTED";
            }
            echo ">{$discounttypes[$n]}</option>";
        }
        echo "</select></td>";
        echo "</tr><tr><th align=right>Price <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text size=5 value='" . showAsMoney($rowItem, "special_price") . "' id=special_price name=special_price /></td>";
        echo "</tr></table>";
        echo '<fieldset><legend>"Three for a dollar"</legend>';
        echo "<table style='margin:0.0em 0.0em 0.0em 0.0em;'>";
        // quantity must default to 0.
        echo "<tr><th align-right>#Items</th>";
        echo "<td> <input type='text'";
        if (!isset($rowItem['specialquantity']) || $rowItem['specialquantity'] == 0) {
            echo "value='0'";
        } else {
            echo "value='{$rowItem['specialquantity']}'";
        }
        echo "name='specialquantity' size='5'></td>";
        echo "</tr><tr><th align=right>For <span style='font-weight:400;'>\$</span></th>";
        echo "<td><input type=text size=5 value='" . showAsMoney($rowItem, "specialgroupprice") . "' id=specialgroupprice name=specialgroupprice /></td>";
        // ?pricemethod must default to 0.
        echo "</tr><th align-right>Method</th>";
        echo "<td> <input type='text'";
        if (!isset($rowItem['specialpricemethod']) || $rowItem['specialpricemethod'] == 0) {
            echo "value='0'";
        } else {
            echo "value='{$rowItem['specialpricemethod']}'";
        }
        echo "name='specialpricemethod' size='5'></td>";
        echo "</tr></table>";
        echo '</fieldset><!-- 3/$1 -->';
        echo "<!-- /div -->";
        echo '</fieldset><!-- /#sale -->';
        echo "</div><!-- /#Sale -->";
        // 5i. Update - Margin Fieldset
        echo "<div id='Margin' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('Margin', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset id=marginfs>";
        echo "<legend>Margin</legend>";
        MarginFS($rowItem['upc'], $rowItem['cost'], $rowItem['department']);
        echo "</fieldset>";
        echo '</div>';
        //of what?
        echo "</div><!-- /#Margin -->";
        // 5j. Update - Likecode Fieldset
        echo "<div id='LikeCode' style='float:left; margin-left:10px; width:{$fieldsetWidth}em; " . "display:" . (array_search('LikeCode', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo "<fieldset><legend>Likecode</legend>";
        echo "<table border=0>";
        echo "<tr><td><b>Like code</b></td></tr>";
        $lcWidth = $fieldsetWidth - 4;
        // Was 175px
        echo "<tr><td><select name=likeCode style=\"width: {$lcWidth}em;\"\n            onchange=\"updateLC(this.value);\">";
        echo "<option value=-1>(none)</option>";
        $likelistQ = "select * from likeCodes order by likecode";
        $likelistR = $dbc->query($likelistQ);
        while ($llRow = $dbc->fetch_array($likelistR)) {
            echo "<option value={$llRow[0]}";
            if ($llRow[0] == $likecode) {
                echo " selected";
            }
            echo ">{$llRow[0]} {$llRow[1]}</option>";
        }
        echo "</select></td></tr>";
        echo "<tr><td><input type=checkbox name=update value='no'>Check to not update like code items</td></tr>";
        echo "<tr id=lchidden";
        if ($likeCodeNum <= 0) {
            echo ' style="display:none;"';
        }
        echo "><td><b>Like Code Linked Items</b><div id=lctable>";
        GetLikecodeItems($likecode);
        echo '</div></td></tr>';
        echo '<tr><td valign=top><a href="../reports/RecentSales/?likecode=' . $likeCodeRow[1] . '" target="_recentlike">';
        echo 'Likecode Sales History</td>';
        echo '</tr>';
        echo '</table></fieldset>';
        echo '</div>';
        echo "</div><!-- /#LikeCode -->";
        echo "<br style='clear:both;' /><br />";
        // 5k. Update - Lane Status Fieldset
        echo "<div id='LaneStatus' style='display:" . (array_search('LaneStatus', $Fannie_Item_Modules) !== False ? 'block' : 'none') . ";'>";
        echo '<fieldset id="lanefs">';
        echo '<legend>Lane Status</legend>';
        include 'prodAllLanes_WEFC_Toronto.php';
        echo allLanes($upc);
        echo '</fieldset>';
        echo "</div><!-- /#LaneStatus -->";
    }
    return $num;
    // itemParse
}
Example #2
0
function itemParse($upc, $dupe = 'no', $description = '', $prefix = false)
{
    global $sql;
    /* why am I only checking for being logged in here
     * instead of a specific permission?
     * 
     * The enter and update item pages do that check
     * For new items, permission could be dependent on
     * which subdepartment is selected. For changing an item,
     * changing subdepartment introduces odd scenarios,
     * switching in and out of valid permission. Easier to just
     * check the final changes.
     */
    $logged_in = checkLogin();
    $p_columns = '
        p.upc,
        p.description,
        p.normal_price,
        p.pricemethod,
        p.quantity,
        p.groupprice,
        p.special_price,
        p.end_date,
        p.department,
        p.tax,
        p.foodstamp,
        p.scale,
        p.qttyEnforced,
        p.discount,
        p.modified,
        p.local
    ';
    // last comma omitted on purpose
    $savedUPC = "";
    $queryItem = "";
    $args = array();
    $numType = isset($_REQUEST['ntype']) ? $_REQUEST['ntype'] : 'UPC';
    if (is_numeric($upc)) {
        switch ($numType) {
            case 'UPC':
                $upc = str_pad($upc, 13, 0, STR_PAD_LEFT);
                $savedUPC = $upc;
                $queryItem = "SELECT {$p_columns},x.distributor,x.manufacturer,\n                u.brand,u.description as udesc,u.sizing,u.photo,\n                u.long_text,u.enableOnline,e.expires\n                FROM products as p left join \n                prodExtra as x on p.upc=x.upc \n                LEFT JOIN productUser as u\n                ON p.upc=u.upc LEFT JOIN productExpires\n                AS e ON p.upc=e.upc\n                WHERE p.upc = ? or x.upc = ?";
                $args = array($upc, $upc);
                break;
            case 'SKU':
                $queryItem = "SELECT {$p_columns},x.distributor,x.manufacturer,\n                u.brand,u.description as udesc,u.sizing,u.photo,\n                u.long_text,u.enableOnline,e.expires\n                FROM products as p inner join \n                vendorItems as v ON p.upc=v.upc \n                left join prodExtra as x on p.upc=x.upc \n                LEFT JOIN productUser as u\n                ON p.upc=u.upc LEFT JOIN productExpires\n                AS e ON p.upc=e.upc\n                WHERE v.sku=?";
                $args = array($upc);
                break;
            case 'Brand Prefix':
                $queryItem = "SELECT {$p_columns},x.distributor,x.manufacturer,\n                u.brand,u.description as udesc,u.sizing,u.photo,\n                u.long_text,u.enableOnline,e.expires\n            FROM products as p \n            left join prodExtra as x on p.upc=x.upc \n            LEFT JOIN productUser as u\n            ON p.upc=u.upc LEFT JOIN productExpires\n            AS e ON p.upc=e.upc\n            WHERE p.upc like ? order by p.upc";
                $args = array('%' . $upc . '%');
                break;
        }
    } else {
        $queryItem = "SELECT {$p_columns},x.distributor,x.manufacturer,\n            u.brand,u.description as udesc,u.sizing,u.photo,\n                u.long_text,u.enableOnline,e.expires\n            FROM products as p left join \n            prodExtra as x on p.upc=x.upc \n            LEFT JOIN productUser as u\n            ON p.upc=u.upc LEFT JOIN productExpires\n            AS e ON p.upc=e.upc\n            WHERE p.description LIKE ? OR \n            u.description LIKE ? ORDER BY p.description";
        $args = array('%' . $upc . '%', '%' . $upc . '%');
    }
    //echo $queryItem;
    echo "<script type=\"text/javascript\">";
    echo "function shelftag(u){";
    echo "testwindow= window.open (\"../../item/addShelfTag.php?upc=\"+u, \"New Shelftag\",\"location=0,status=1,scrollbars=1,width=300,height=220\");";
    echo "testwindow.moveTo(50,50);";
    echo "}";
    echo "</script>";
    $barcodeUPC = ltrim($upc, "0");
    echo "<script language=JavaScript>";
    echo "function popup(){";
    echo "testwindow= window.open (\"addLikeCode.php\", \"Add Like Code\",\"location=0,status=1,scrollbars=1,width=200,height=200\");";
    echo "testwindow.moveTo(50,50);";
    echo "}";
    echo "</script>";
    echo "<script language=JavaScript>";
    echo "function newTagCheck(){";
    echo "if (document.getElementById('newTag').checked)";
    //echo "shelftag();";
    echo "}";
    echo "</script>";
    $num = 0;
    $prepItem = $sql->prepare($queryItem);
    $resultItem = $sql->execute($prepItem, $args);
    $num = $sql->num_rows($resultItem);
    $likeCodeQ = $sql->prepare("SELECT u.*,l.likeCodeDesc FROM upcLike as u, likeCodes as l \n        WHERE u.likeCode = l.likeCode and u.upc = ?");
    $likeCodeR = $sql->execute($likeCodeQ, array($upc));
    $likeCodeRow = $sql->fetch_row($likeCodeR);
    $likeCodeNum = $sql->num_rows($likeCodeR);
    $listCodeQ = "SELECT * from likeCodes";
    $listCodeR = $sql->query($listCodeQ);
    $listCodeRow = $sql->fetch_row($likeCodeR);
    if ($num == 0) {
        noItem();
        echo "<head><title>Enter New Item</title></head>";
        echo "<BODY onLoad='putFocus(0,1);'>";
        printMods($savedUPC);
        echo "Item not found, would you like to enter it?";
        echo "<form action=enterTestItem.php method=post onsubmit=\"newTagCheck();\">";
        echo "<table>";
        echo "<tr><td align=right><b>UPC</b></td><td><font color='red'></font>\n            <input type=text value={$upc} name=upc maxlength=13></td>";
        echo "</tr><tr><td><b>Description</b></td><td>\n            <input type=text size=35 name=descript maxlength=30></td>";
        echo "<td><b>Price</b></td><td>\$<input type=text name=price></td></tr>";
        echo "<tr><td><b>Manufacturer</b></td><td><input type=text size=35 value=\"\" name=manufacturer /></td>";
        echo "<td><b>Distributor</b></td><td>&nbsp;<input type=text value=\"\" name=distributor /></td></tr>";
        echo "</table>";
        echo "<table border=0><tr>";
        echo "<th>Dept<th>Tax<th>FS<th>Scale<th>QtyFrc<th>NoDisc<th>Local<th>Like Code<th>Shelf Tag</b>";
        echo "</tr>";
        echo "<tr>";
        $query2 = "SELECT * FROM departments as d,\n                MasterSuperDepts AS s WHERE s.dept_ID=d.dept_no AND dept_no NOT IN (60,225)\n                ORDER BY superID, dept_no";
        echo "<td>";
        $upc_split = substr($upc, 0, 7);
        $guessQ = $sql->prepare("select department from products where upc like ?\n                   group by department\n                   order by count(*) desc");
        $guessR = $sql->execute($guessQ, array($upc_split . '%'));
        $guess = 60;
        if ($sql->num_rows($guessR) > 0) {
            $guessW = $sql->fetch_array($guessR);
        }
        $guess = $guessW['department'];
        echo '<select name="dept">';
        $result2 = $sql->query($query2);
        while ($row2 = $sql->fetch_row($result2)) {
            printf('<option %s value="%d">%d %s</option>', $row2['dept_no'] == $guess ? 'selected' : '', $row2['dept_no'], $row2['dept_no'], $row2['dept_name']);
        }
        echo '</select>';
        echo " </td>";
        echo "<td align=right>Reg";
        echo "<input type=radio name=tax value=1><br>";
        echo "Deli<input type=radio name=tax value=2><br>";
        echo "No Tax<input type=radio name=tax value=0";
        echo "></td><td align=center><input type=checkbox value=1 name=FS";
        echo "></td><td align=center><input type=checkbox value=1 name=Scale";
        echo "></td><td align=center><input type=checkbox value=1 name=ForcQty";
        echo "></td><td align=center><input type=checkbox value=1 name=NoDisc";
        echo "></td><td align=center><select name=local><option value=0>No</option>\n        <option value=1>SC</option><option value=2>300mi</option></select>";
        echo "<input type=hidden value=1 name=inUse";
        echo "><td align=center>";
        //echo "<input type=text align=right size=4 name=likeCode>";
        echo "<select name=likeCode style=\"{width: 175px;}\">";
        echo "<option value=\"\">(none)</option>";
        $likelistQ = "select * from likeCodes order by likecode";
        $likelistR = $sql->query($likelistQ);
        while ($llRow = $sql->fetch_array($likelistR)) {
            echo "<option value={$llRow[0]}";
            if (isset($likecode) && $llRow[0] == $likecode) {
                echo " selected";
            }
            echo ">{$llRow[0]} {$llRow[1]}</option>";
        }
        echo "</select>";
        echo "</td><td align=center><input type=checkbox value=1 id=newTag name=shelftag></td></tr>";
        if ($logged_in) {
            echo "<tr><td><input type='submit' name='submit' value='submit'>";
        } else {
            echo "<tr><td>Please <a href=/auth/ui/loginform.php?redirect=/queries/productTest.php?upc={$upc}>";
            echo "login</a> to add items";
        }
        echo "</td></tr> ";
        echo "</tr></table>";
    } elseif ($num > 1) {
        moreItems($upc);
        $upcs = array();
        $descriptions = array();
        for ($i = 0; $i < $num; $i++) {
            $rowItem = $sql->fetch_array($resultItem);
            $upcs[$i] = $rowItem['upc'];
            $descriptions[$i] = $rowItem['description'];
            $modified[$i] = $rowItem['modified'];
            //echo "<a href='productTest.php?upc=$upc'>" . $upc . " </a>- " . $rowItem['description'] . "<br>";
        }
        for ($i = 0; $i < $num; $i++) {
            $dupe = false;
            for ($j = 0; $j < $num; $j++) {
                if ($i != $j and $upcs[$i] == $upcs[$j]) {
                    $enc = base64_encode($descriptions[$i]);
                    echo "<a href=productTest.php?upc={$upcs[$i]}&duplicate=yes&description={$enc}>{$upcs[$i]}</a>-{$descriptions[$i]} - <b>DUPLICATE</b> - ";
                    echo "<a href=javascript:delete_popup(\"{$upcs[$i]}\",\"{$enc}\")><img src=trash.png border=0/></a><br />";
                    $j = $num;
                    $dupe = true;
                }
            }
            if (!$dupe) {
                echo "<a href=productTest.php?upc={$upcs[$i]}>{$upcs[$i]}</a>-{$descriptions[$i]}<br />";
            }
        }
    } else {
        oneItem($upc);
        $rowItem = $sql->fetch_array($resultItem);
        $upc = $rowItem['upc'];
        $currentDepartment = $rowItem['department'];
        $prev = $next = 0;
        $modified = $rowItem['modified'];
        deptPrevNext($currentDepartment, $upc, $prev, $next);
        $modDate = $modified;
        $likecode = '';
        if (!empty($likeCodeRow[1])) {
            $likecode = $likeCodeRow[1];
        }
        echo "<head><title>Update Item</title></head>";
        echo "<BODY onLoad='putFocus(0,2);'>";
        printMods($savedUPC);
        echo "<form action=updateItemTest.php method=post>";
        echo "<table>";
        echo "<tr><td align=right><b>UPC</b></td><td><font color='red'>" . $rowItem['upc'] . "</font><input type=hidden value='{$rowItem['upc']}' name=upc>";
        if ($prev != -1) {
            echo "&nbsp;&nbsp;<a href=productTest.php?upc={$prev}>Previous</a>";
        }
        if ($next != -1) {
            echo "&nbsp;&nbsp;<a href=productTest.php?upc={$next}>Next</a>";
        }
        echo "</td>";
        echo "</tr><tr><td><b>Description</b></td><td><input type=text size=35 maxlength=30 value=\"{$rowItem['description']}\" name=descript></td>";
        echo "<td><b>Price</b></td><td>\$<input type=text value='{$rowItem['normal_price']}' name=price></td></tr>";
        echo "<tr><td colspan=2 align=right><b>Enable Volume Price</b> <input type=checkbox name=doVolume ";
        echo ($rowItem['pricemethod'] != 0 ? "checked" : "") . " /></td><td colspan=2>";
        echo "<input type=hidden name=pricemethod value=\"{$rowItem['pricemethod']}\">";
        echo "<input type=text size=4 name=vol_qtty value=" . ($rowItem['quantity'] != 0 ? $rowItem['quantity'] : "\"\"") . " />";
        echo " for \$<input type=text size=4 name=vol_price value=" . ($rowItem['groupprice'] != 0 ? $rowItem['groupprice'] : "\"\"") . " /></td></tr>";
        echo "<tr><td><b>Manufacturer</b></td><td><input type=text size=35 value=\"{$rowItem['manufacturer']}\" name=manufacturer /></td>";
        echo "<td><b>Distributor</b></td><td>&nbsp;<input type=text value=\"{$rowItem['distributor']}\" name=distributor /></td></tr>";
        echo "<a href=/git/fannie/reports/PriceHistory/?upc={$rowItem['upc']} target=blank>Click for Price History</a>";
        if ($rowItem['special_price'] != 0) {
            echo "<tr><td><font size=+1 color=green><b>Sale Price:</b></font></td><td><font size=+1 color=green>{$rowItem['special_price']}</font>";
            echo "<td colspan=2><font size=+1 color=green>End Date: {$rowItem['end_date']}</font></td><tr>";
            $findBatchQ = $sql->prepare("select batchName from batches as b, batchList as l\n              where b.batchID = l.batchID and l.upc like ?\n              and " . $sql->curdate() . " BETWEEN b.startDate AND b.endDate");
            $findBatchR = $sql->execute($findBatchQ, array($upc));
            $batchName = $sql->num_rows($findBatchR) == 0 ? "Unknown" : array_pop($sql->fetch_array($findBatchR));
            if ($batchName == "Unknown" && $likecode != "") {
                $findBatchQ = $sql->prepare("select batchName from batches as b, batchList as l\n                where b.batchID=l.batchID and l.upc = ?\n                  and " . $sql->curdate() . " BETWEEN b.startDate AND b.endDate");
                $findBatchR = $sql->execute($findBatchQ, array('LC' . $likecode));
                $batchName = $sql->num_rows($findBatchR) == 0 ? "Unknown" : array_pop($sql->fetch_array($findBatchR));
            }
            echo "<tr><td colspan=4><b>Batch: {$batchName}</b> ";
            if (validateUserQuiet('pricechange') || substr($upc, 0, 3) == "002") {
                echo "(<a href=unsale.php?upc={$upc}><font color=red>Take this item off sale now</font></a>)</td>";
            }
        }
        echo "</table>";
        echo "<table border=0><tr>";
        echo "<th>Dept<th>Tax<th>FS<th>Scale<th>QtyFrc<th>NoDisc<th>Local<th>Like Code<th>&nbsp;</b>";
        echo "</tr>";
        echo "<tr align=top>";
        //$dept=$row1[3];
        $query2 = "SELECT * FROM departments as d,\n                MasterSuperDepts AS s WHERE s.dept_ID=d.dept_no AND dept_no NOT IN (60,225)\n                ORDER BY superID, dept_no";
        echo "<td>";
        $query3 = $sql->prepare("SELECT dept_no,superID FROM departments as d\n                LEFT JOIN MasterSuperDepts AS s ON d.dept_no=s.dept_ID\n                WHERE dept_no = ?");
        $result3 = $sql->execute($query3, $rowItem['department']);
        $row3 = $sql->fetch_array($result3);
        echo '<select name="dept">';
        $result2 = $sql->query($query2);
        while ($row2 = $sql->fetch_row($result2)) {
            printf('<option %s value="%d">%d %s</option>', $row2['dept_no'] == $rowItem['department'] ? 'selected' : '', $row2['dept_no'], $row2['dept_no'], $row2['dept_name']);
        }
        echo '</select>';
        echo " </td>";
        echo "<td align=right>Reg ";
        echo "<input type=radio name=tax value=1";
        if ($rowItem['tax'] == 1) {
            echo " checked";
        }
        echo "><br>Deli <input type=radio name=tax value=2";
        if ($rowItem['tax'] == 2) {
            echo " checked";
        }
        echo "><br>NoTax <input type=radio name=tax value=0";
        if ($rowItem['tax'] == 0) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=1 name=FS";
        if ($rowItem['foodstamp'] == 1) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=1 name=Scale";
        if ($rowItem['scale'] == 1) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=1 name=QtyFrc";
        if ($rowItem['qttyEnforced'] == 1) {
            echo " checked";
        }
        echo "></td><td align=center><input type=checkbox value=0 name=NoDisc";
        if ($rowItem['discount'] == 0) {
            echo " checked";
        }
        echo ">" . "</td><input type=hidden value=1 name=inUse";
        echo "></td><td align=center><select name=local>";
        printf("<option value=0 %s>No</option>", $rowItem['local'] == 0 ? 'selected' : '');
        printf("<option value=1 %s>SC</option>", $rowItem['local'] == 1 ? 'selected' : '');
        printf("<option value=2 %s>300mi</option>", $rowItem['local'] == 2 ? 'selected' : '');
        echo "</select><td align=center>";
        //echo "<input type=text align=right size=4 value='$likecode' name=likeCode>";
        echo "<select name=likeCode style=\"{width: 175px;}\">";
        echo "<option value=-1>(none)</option>";
        $likelistQ = "select * from likeCodes order by likecode";
        $likelistR = $sql->query($likelistQ);
        while ($llRow = $sql->fetch_array($likelistR)) {
            echo "<option value={$llRow[0]}";
            if ($llRow[0] == $likecode) {
                echo " selected";
            }
            echo ">{$llRow[0]} {$llRow[1]}</option>";
        }
        echo "</select>";
        echo "</td><td>";
        echo "<a href=javascript:popup()>Add like code</a>";
        echo "</td>";
        echo "<a href=javascript:shelftag('{$upc}')>New Shelf Tag</a>";
        echo "</tr>";
        echo "</tr>";
        echo "<tr><td align=right><font size=-1 color=purple><i><b>Last Modified: </b></i></font></td>";
        echo "<td colspan=3><font size=-1 color=purple><i>{$modDate}</i></td>";
        echo "<td colspan=5><a href=/git/fannie/reports/RecentSales/index.php?upc={$upc} target=blank>Click for History</a></td></tr>";
        echo "<tr><td colspan=4>";
        // kick out a scale input for upcs starting with 002
        // pass variables with prefix s_
        if (preg_match("/^002/", $rowItem['upc']) && $row3[1] == 3) {
            $scaleQuery = $sql->prepare("select * from scaleItems where plu=?");
            $scaleRes = $sql->execute($scaleQuery, array($upc));
            $scaleRow = $sql->fetch_row($scaleRes);
            echo "<table border=1 cellspacing=0 cellpadding=7><tr>";
            echo "<td bgcolor=\"#FFFFCC\">";
            echo "Scale Information:<br />";
            echo "UPC: <font color=red>{$rowItem['upc']}</font><p />";
            echo "<input type=hidden name=s_plu value={$rowItem['upc']}>";
            // update:  some items might need a longer description
            echo "Longer description:";
            // only show a longer description if the description differs
            echo "&nbsp;&nbsp;<input type=text name=s_longdesc size=40 maxlength=100";
            if ($rowItem['description'] != $scaleRow[2]) {
                echo " value='{$scaleRow[2]}'";
            }
            echo ">";
            echo "<p />";
            // EXCEPTION PRICE?
            //   Unnecessary to users but expected by csv package
            echo "<input type=hidden name=s_exception value=0.00>";
            echo "<table border=1 cellspacing=0 cellpadding=7><tr>";
            echo "<th>Weight</th><th>By Count</th><th>Tare</th><th>Shelf Life</th><th>Net Wt (oz)</th><th>Label</th><th>Safehandling</th>";
            echo "</tr><tr><td>";
            echo "<input type=radio name=s_type value=\"Random Weight\"";
            if ($scaleRow[4] == 0) {
                echo " checked> Random<br />";
            } else {
                echo "> Random<br />";
            }
            echo "<input type=radio name=s_type value=\"Fixed Weight\"";
            if ($scaleRow[4] == 1) {
                echo " checked> Fixed<br />";
            } else {
                echo "> Fixed<br />";
            }
            echo "</td><td align=center>";
            echo "<input type=checkbox name=s_bycount";
            if ($scaleRow['bycount'] == 1) {
                echo " checked>";
            } else {
                echo ">";
            }
            echo "</td><td>";
            echo "<input type=text name=s_tare size=5 value={$scaleRow['tare']}>";
            echo "</td><td>";
            echo "<input type=text name=s_shelflife size=5 value={$scaleRow['shelflife']}>";
            echo "</td><td>";
            echo "<input type=text name=s_netwt size=5 value={$scaleRow['netWeight']}>";
            echo "</td><td>";
            echo "<select name=s_label size=2>";
            if ($scaleRow['label'] == 133 || $scaleRow['label'] == 63) {
                echo "<option value=horizontal selected>Horizontal</option>";
            } else {
                echo "<option value=horizontal>Horizontal</option>";
            }
            if ($scaleRow['label'] == 103 || $scaleRow['label'] == 53 || $scaleRow['label'] == 23) {
                echo "<option value=vertical selected>Vertical</option>";
            } else {
                echo "<option value=vertical>Vertical</option>";
            }
            echo "</select>";
            echo "</td><td align=center>";
            if ($scaleRow['graphics'] == 0) {
                echo "<input type=checkbox name=s_graphics />";
            } else {
                echo "<input type=checkbox name=s_graphics checked />";
            }
            echo "</td>";
            echo "</td></tr></table><br />";
            echo "<p />Expanded text:<br /><textarea name=s_text rows=4\n           cols=40>{$scaleRow['text']}</textarea>";
            echo "<p /></td></tr></table>";
        }
        echo "<br /></td></tr><tr><td>";
        echo "Like Code Linked Items</td><td>&nbsp;</td><td><input type=checkbox name=update value='no'></td><td colspan=4>Check to not update like code items</td></tr><tr><td>";
        if ($likeCodeNum > 0) {
            $selLikeQ = "SELECT p.upc,p.description,p.normal_price FROM products as p, upcLike as u WHERE u.upc = p.upc and u.likeCode = ?";
            likedtotable($selLikeQ, $likeCodeRow[0], 0, 'FFFFCC');
            echo "<td valign=top colspan=3><a href=/git/fannie/reports/PriceHistory/?likecode={$likeCodeRow['1']} target=lc_hist>Click for Like Code History</a></td>";
        }
        if ($logged_in || preg_match("/^002/", $rowItem['upc']) && $row3[1] == 3) {
            echo "</td></tr><tr><td colspan=4><input type='submit' name='submit' value='submit'> ";
            echo " <a href=../../item/DeleteItemPage.php?id={$upc}>Delete this item</a> | ";
        } else {
            echo "</td></tr><tr><td colspan=4>Please <a href=/auth/ui/loginform.php?redirect=/queries/productTest.php?upc={$upc}>";
            echo "login</a> to change prices";
        }
        echo " <a href=javascript:back()>Back</a></td></tr> ";
        echo "<tr><td colspan=5>";
        echo '<a href="" onclick="$(\'#topSecret\').toggle();return false;">Extra</a>';
        echo "<div id=\"topSecret\" style=\"display:none;\">";
        echo "<div style=\"float:left;width:500px;\">";
        echo "<b>Sane Brand &amp; Description</b>: ";
        printf("<input name=\"u_brand\" value=\"%s\" /> \n            <input name=\"u_desc\" value=\"%s\" /><br />", $rowItem["brand"], $rowItem["udesc"]);
        printf("<b>Size</b>: <input name=\"u_size\" value=\"%s\" />", $rowItem["sizing"]);
        printf('&nbsp;&nbsp;<input type="checkbox" name="u_enableOnline" %s />Sell online<br />', $rowItem['enableOnline'] == 1 ? 'checked' : '');
        printf("<b>Expires</b>: <input name=\"u_expires\" value=\"%s\" />", $rowItem["expires"]);
        printf('<p><b>Page Text</b><br /><textarea rows=15 cols=80 name=u_long_text>%s</textarea></p>', str_replace("<br />", "\n", $rowItem['long_text']));
        echo "</div>";
        if (!empty($rowItem["photo"])) {
            echo "<div style=\"float:left;\">";
            printf("<a href=\"/git/fannie/item/images/done/%s\"><img src=\"/git/fannie/item/images/done/%s\" /></a>", $rowItem["photo"], str_replace("png", "thumb.png", $rowItem["photo"]));
            echo "</div>";
        }
        echo "<div style=\"clear:left;\"></div>";
        echo "</div>";
        echo "</tr>";
        echo "<tr><td height=5>&nbsp;</td></tr><tr><td bgcolor=#ddffdd colspan=3>";
        allLanes($upc);
        echo "</td></tr>";
    }
    return $num;
}