<?php
$LastOrderID=null;
include_once 'init-lite.php';
?>
<div data-role="controlgroup" data-type="horizontal" >
<a href="#" id="catalogo" style="width:85px;"  class="ui-btn   ui-btn-inline ui-mini ui-shadow"  onclick="loadmenu('');">全部分类</a> 
<?php
$sql    = "SELECT CategoryID,CategoryName FROM Categories Order By PrintGroup,CategoryID";
if (is_numeric($LastOrderID)) $sql="SELECT   Categories.CategoryID,  
	CASE WHEN   derivedtbl_1.Quantity IS NOT NULL 
	THEN '(' + CAST(CAST( derivedtbl_1.Quantity  AS int) AS nvarchar(100)) + ')' 
	ELSE '' END + Categories.CategoryName  AS CategoryName
FROM      Categories LEFT OUTER JOIN
                    (SELECT   SUM([Order Details].Quantity) AS Quantity, Products.CategoryID
                     FROM      [Order Details] INNER JOIN
                                     Products ON [Order Details].ProductID = Products.ProductID
                     WHERE   ([Order Details].OrderID = ".$LastOrderID.")
                     GROUP BY Products.CategoryID) AS derivedtbl_1 ON Categories.CategoryID = derivedtbl_1.CategoryID 
					  Order By Categories.PrintGroup,Categories.CategoryID "; 

//die($sql);
//console_log("catalogo select  :	" .  $sql );

$values = $orders->query($sql);
if (is_iterable($values)) {
    foreach ($values as $pCategories) {
		//console_log("catalogo select  :	" . $pCategories['CategoryName']);
		$pCategories['CategoryName'] = loadFromMssql($pCategories['CategoryName']);
?>
<a href="#" id="catalogo" class="ui-btn   ui-btn-inline ui-mini ui-shadow" onclick="loadmenu('<?php
        echo $pCategories['CategoryID'];
?>');"><?php
         echo $pCategories['CategoryName'];
?></a>                                   
  <?php
    }
}
?>
<a href="#" id="catalogo" class="ui-btn   ui-btn-inline ui-mini ui-shadow" onclick="loadmenu('thisorder');">本订单</a> 
</div>