function populateListOrderSummary($linkPage, $sort = "OrderedDate", $reverse = false, $all = false)
{
    $charityHeader = standardIcon("charity");
    $toShipHeader = standardIcon("released");
    $paidHeader = standardIcon("paid");
    $expediteHeader = standardIcon("expedite");
    $shippedHeader = standardIcon("shipped");
    $invoiceHeader = standardIcon("invoice");
    $checkedBox = standardIcon("checkedBox");
    $unCheckedBox = standardIcon("box");
    $basepage = "?page_id=" . $_GET["page_id"];
    $rows = getOrdersSummary($sort, $reverse, $all);
    $list = "<h3>Current Orders</h3>";
    $list .= '<script>
               // code taken from http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit
               function post(path, params, method) {
                  method = method || "post"; // Set method to post by default if not specified.

                  var form = document.createElement("form");
                  form.setAttribute("method", method);
                  form.setAttribute("action", path);

                  for(var key in params) {
                     if(params.hasOwnProperty(key)) {
                        var hiddenField = document.createElement("input");
                        hiddenField.setAttribute("type", "hidden");
                        hiddenField.setAttribute("name", key);
                        hiddenField.setAttribute("value", params[key]);
 
                        form.appendChild(hiddenField);
                     }
                  }

                  document.body.appendChild(form);
                  form.submit();
               }';
    $list .= "\n               function rowClick(oid) {\n//                  window.location.href = \"http://orders.thechapr.com/Admin/?page_id=89&oid=\" + oid;\n                  window.location.href = \"{$linkPage}\" + \"&oid=\" + oid;\n//                    post(\"http://orders.thechapr.com/Admin/?page_id=89\",\n//                         { email : \"eric@rothfus.com\",\n//                           fname : \"eric\"},\n//                         \"post\");\n               }\n\n               </script>";
    $list .= "<table class=\"orderList\" frame=\"box\" style=\"width:99%;align:center\">";
    $list .= showAllButton($basepage, $sort, $reverse, $all);
    $list .= "\n   <tr class=\"topline\">\n      <td align=\"center\"><font size=\"-2\">" . sortHeader($basepage, "CID", "CID", $sort, $reverse, $all) . "</td>\n      <td align=\"center\"><font size=\"-2\">" . sortHeader($basepage, "OID", "OID", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, "First Name", "FirstName", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, "Last Name", "LastName", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, "Ordered Date", "OrderedDate", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, "Items", "ItemCount", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, $expediteHeader, "IsExpedited", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, $charityHeader, "Charity", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, $invoiceHeader, "RequestedPay", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, $paidHeader, "PaidDate", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, $toShipHeader, "ReleasedToShipping", $sort, $reverse, $all) . "</td>\n      <td align=\"center\">" . sortHeader($basepage, $shippedHeader, "ShippedDate", $sort, $reverse, $all) . "</td>\n      <td align=\"center\"> Order Notes </td>\n   </tr>\n\n";
    // these are counters for the bottom of page reporting
    // canceled orders are never counted in this list - but shipped are as detailed below
    $totalItemCount = 0;
    // total of all items in the current list
    $totalCharityCount = 0;
    // total of charity items in the current list (non charity = $totalItemCount - $totalCharityCount)
    $totalItemsShipped = 0;
    // total of SHIPPED items in the current list (only shown when shipped shown)
    $totalCharityShipped = 0;
    // total of charity shipped items in the current list (only shown when shipped shown)
    foreach ($rows as $row) {
        $canceled = $row["WasCanceled"];
        $cid = $row["CID"];
        $oid = $row["OID"];
        $firstName = $row["FirstName"];
        $lastName = $row["LastName"];
        $orderDate = date("Y-M-d", $row["OrderedDate"]);
        $itemCount = $row["itemCount"];
        $paidDate = $row["PaidDate"];
        $toShipDate = $row["ReleasedToShipping"];
        $shippedDate = $row["ShippedDate"];
        $isExpedited = $row["IsExpedited"];
        $orderNotes = $row["CustomerONotes"];
        if ($row["AdminONotes"]) {
            $orderNotes .= " <em>(" . $row["AdminONotes"] . ")</em>";
        }
        $isCharity = $row["Charity"];
        $isInvoice = $row["RequestedPay"];
        // do the bottom of page item counts
        if (!$canceled) {
            $totalItemCount += $row["itemCount"];
            if ($isCharity) {
                $totalCharityCount += $row["itemCount"];
            }
            if ($shippedDate) {
                $totalItemsShipped += $row["itemCount"];
            }
            if ($shippedDate && $isCharity) {
                $totalCharityShipped += $row["itemCount"];
            }
        }
        // the old way
        $box = '&#9744;';
        /* Empty Box special Character */
        $checked = '&#9745;';
        /* Check Box Special Character */
        // new pretty way
        $box = $unCheckedBox;
        $checked = $checkedBox;
        if ($isInvoice) {
            $invoice = $checked;
            if ($row["RequestedPayDays"] == 1) {
                $invoiceTitle = $row["RequestedPayDays"] . " day ago";
            } else {
                if ($row["RequestedPayDays"] == 0) {
                    $invoiceTitle = "just today";
                } else {
                    $invoiceTitle = $row["RequestedPayDays"] . " days ago";
                }
            }
        } else {
            $invoice = $box;
            $invoiceTitle = "";
        }
        if ($paidDate == 0) {
            $paid = $box;
        } else {
            $paid = $checked;
        }
        if ($toShipDate == 0) {
            $released = $box;
        } else {
            $released = $checked;
        }
        if ($shippedDate == 0) {
            $shipped = $box;
        } else {
            $shipped = $checked;
        }
        if ($isCharity) {
            $charity = $checked;
        } else {
            $charity = $box;
        }
        if ($isExpedited) {
            $expedited = $checked;
        } else {
            $expedited = $box;
        }
        $list .= "<tr onclick=\"rowClick({$oid});\"";
        if ($canceled) {
            $list .= " class=\"strikeout\"";
        }
        $list .= ">";
        $list .= "\n\n      <td class='centered' align='center'> {$cid} </td>\n      <td align='center'> {$oid} </td>\n      <td> {$firstName} </td>\n      <td> {$lastName} </td>\n      <td align='center'> {$orderDate} </td>\n      <td align='center'> {$itemCount} </td>\n      <td align='center'> {$expedited} </td>\n      <td align='center'> {$charity} </td>\n      <td align='center' title='{$invoiceTitle}'> {$invoice} </td>\n      <td align='center'> {$paid} </td>\n      <td align='center'> {$released} </td>\n      <td align='center'> {$shipped} </td>\n      <td> {$orderNotes} </td>\n   </tr>\n\n";
    }
    // deal with a little link for showing ALL orders, or excluding shipped and canceled
    $list .= showAllButton($basepage, $sort, $reverse, $all);
    $list .= "\n</table>\n<div align=\"center\"><font size=\"-1\"><em>\nClick on a row to view, edit, or ship the order.\n</em></font></div><P>";
    $list .= "<div align=\"center\"><font size=\"-1\"><em>";
    $list .= "<table style=\"border:none;margin:0;padding:0\">";
    $list .= "<tr style=\"border:none;margin:0;padding:0\">";
    $list .= "<td style=\"border:none;text-align:center;margin:0;padding:0\">Total Items: {$totalItemCount}</td>";
    $list .= "<td style=\"border:none;text-align:center;margin:0;padding:0\">Total Charity: {$totalCharityCount}</td>";
    $list .= "<td style=\"border:none;text-align:center;margin:0;padding:0\">Total Non-Charity: " . ($totalItemCount - $totalCharityCount) . "</td>";
    $list .= "</tr>";
    if ($all) {
        $list .= "<tr style=\"border:none\">";
        $list .= "<td style=\"border:none;text-align:center;margin:0;padding:0\">Total Shipped Items: {$totalItemsShipped}</td>";
        $list .= "<td style=\"border:none;text-align:center;margin:0;padding:0\">Total Shipped Charity: {$totalCharityShipped}</td>";
        $list .= "<td style=\"border:none;text-align:center;margin:0;padding:0\">Total Shipped Non-Charity: " . ($totalItemsShipped - $totalCharityShipped) . "</td>";
        $list .= "</tr>";
    }
    $list .= "</table></em></font></div>";
    print $list;
}
function titleArea($pdf, $area, $oid, $order, $customer, $items, $mapping, $pieces)
{
    $orderTitle = "<div align=\"center\">";
    if ($order["IsExpedited"]) {
        $orderTitle .= standardIcon("expedite", "../Admin") . "&nbsp;&nbsp;";
    }
    if ($order["Charity"]) {
        $orderTitle .= standardIcon("charity", "../Admin") . "&nbsp;&nbsp;";
    }
    $orderTitle .= "<strong><em>Order: {$oid}</em></strong>";
    if ($order["Charity"]) {
        $orderTitle .= "&nbsp;&nbsp;" . standardIcon("charity", "../Admin");
    }
    if ($order["IsExpedited"]) {
        $orderTitle .= "&nbsp;&nbsp;" . standardIcon("expedite", "../Admin");
    }
    $orderTitle .= "</div>";
    $pdf->setImageScale(1.5);
    $pdf->SetFillColor(0xcc, 0xcc, 0xcc);
    $pdf->SetTextColor(0, 0, 0);
    areaWriteHTMLCell($pdf, $area, "{$orderTitle}", 0, 0, true);
}
function clickableBox($page_id, $oid, $checked, $request = null, $confirm = false, $active = true)
{
    if ($checked) {
        $image = standardIcon("checkedBox");
    } else {
        $image = standardIcon("box");
    }
    return clickRequest($page_id, $oid, $image, "", $request, $confirm, $active);
}
function main($oid, $pdflink)
{
    // a packing list has all of the standard stuff on it, including
    // the order number, customer, address, but no price information.
    // it combines multiple items into one NUMBERED item along with the
    // stuff that should go into it.  It also includes a field for
    // notes that then need to be transcribed to shipping.
    $order = dbGetOrder($oid);
    $items = getItems($oid);
    $mapping = dbGetPVP();
    $pieces = dbGetPieces();
    if (!$order) {
        echo "Can't find order {$oid}\n";
        return;
    }
    $customer = dbGetCustomer($order["CID"]);
    if (!$customer) {
        echo "Can't find customer for order {$oid}\n";
        return;
    }
    echo "<div align=\"right\"><font size=\"-2\"><a href=\"{$pdflink}?oid={$oid}\">PDF Version</a></font></div>\n";
    // the whole thing is one big table
    echo "<table class=\"packinglist\">\n";
    // first, the header with "Order: XXX"
    echo "<tr><td class=\"ordertitle\" colspan=\"3\">";
    if ($order["IsExpedited"]) {
        echo standardIcon("expedite") . "&nbsp;&nbsp;";
    }
    if ($order["Charity"]) {
        echo standardIcon("charity") . "&nbsp;&nbsp;";
    }
    echo "Order: <strong>{$oid}</strong>";
    if ($order["Charity"]) {
        echo "&nbsp;&nbsp;" . standardIcon("charity");
    }
    if ($order["IsExpedited"]) {
        echo "&nbsp;&nbsp;" . standardIcon("expedite");
    }
    echo "</td></tr>\n";
    // now paint the "To:" and "Status"
    echo "<tr><td width=\"50%\">\n";
    echo "<table><tr><td class=\"title\" colspan=\"2\"><strong>Customer</strong></td></tr>\n";
    echo htmlCustomerAddress($customer);
    echo "</table></td>\n";
    echo "<td width=\"50%\">\n";
    echo "<table><tr><td class=\"title\" colspan=\"3\"><strong>Status</strong></td></tr>\n";
    //     echo("<tr><td>");
    echo htmlOrderStatus($order);
    //     echo("</td></tr>");
    echo "<tr><td class=\"title\" colspan=\"3\"><strong>Order Notes</strong></td></tr>\n";
    echo "<tr><td colspan=\"3\">" . htmlNotesFormat($order["CustomerONotes"]) . "</td></tr>\n";
    echo "<tr><td colspan=\"3\"><em>" . htmlNotesFormat($order["AdminONotes"]) . "</em></td></tr>\n";
    echo "</table></td>\n";
    echo "</tr>\n";
    // the middle part of the packing list is the actual list of items and components
    echo "<tr><td colspan=2>\n";
    echo "<table class=\"packingItems\">\n";
    echo "<tr><td class=\"title\" colspan=\"3\"><strong>Shipment Items</strong></td></tr>\n";
    echo "<tr><td style=\"border-bottom:1px solid; text-align:center;\"><strong>Count</strong></td>";
    echo "<td style=\"border-bottom:1px solid;\" width=\"50%\"><strong>Item</strong></td>";
    echo "<td style=\"border-bottom:1px solid;\" ><strong>Notes</strong> <em><font size=-1>(include ChapR number(s) if applicable)</font></em></td</tr>\n";
    echo "<tr><td>&nbsp;</td></tr>\n";
    foreach ($items as $item) {
        echo "<tr>";
        echo "<td class=\"qty\">" . $item["Quantity"] . " x</td>";
        echo "<td><p class=\"itemtitle\">" . $item["Name"] . "</p>";
        echo "<UL>";
        if ($item["Personality"]) {
            echo "<LI>" . $item["Personality"] . "</LI>";
        }
        // now get all of the pieces in the package
        foreach ($mapping as $map) {
            if ($map["PKID"] == $item["PKID"]) {
                echo "<LI>" . findPieceName($map["PID"], $pieces) . "</LI>\n";
            }
        }
        echo "</UL></td>";
        echo "<td></td>";
        echo "</tr>";
    }
    echo "</table></td></tr>\n";
    // the bottom part of the packing list is the shipment note section
    echo "<tr><td colspan=2>\n";
    echo "<table class=\"packingShipping\">\n";
    echo "<tr><td class=\"title\" colspan=\"6\"><strong>Shipment Details</strong></td></tr>\n";
    echo "<tr>";
    echo "<td class=\"fieldName\">Date Shipped: </td><td class=\"field\"></td>\n";
    echo "<td class=\"fieldName\">Carrier: </td><td class=\"field\"></td>\n";
    echo "<td class=\"fieldName\">Tracking #: </td><td class=\"field\"></td>\n";
    echo "</tr>";
    echo "</table></td></tr>\n";
    echo "</table>\n";
}