Fixed Rico.Corner.round to be compatible with latest browsers/CSS3 - in both Rico2...
[infodrom/rico3] / examples / php / simplegrid.php
1 <?php \r
2 ob_start(); \r
3 header('Content-type: text/html; charset=utf-8');\r
4 ?>\r
5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
6 <html>\r
7 <head>\r
8 <title>Rico SimpleGrid-Example 1</title>\r
9 \r
10 <?php\r
11 require "dbConnect.php";\r
12 require "LoadRicoClient.php";\r
13 require "../../plugins/php/SimpleGrid.php";\r
14 ?>\r
15 <link href="../demo.css" type="text/css" rel="stylesheet" />\r
16 \r
17 <script type='text/javascript'>\r
18 var ex1;\r
19 Rico.onLoad( function() {\r
20   var opts = {  \r
21     columnSpecs   : [{width:200},'specQty','specQty','specQty','specQty']\r
22   };\r
23   ex1=new Rico.SimpleGrid ('ex1', opts);\r
24   if (!Rico.isIE) document.getElementById('owc').disabled=true;\r
25 });\r
26 \r
27 function ExportGridClient(ExportType) {\r
28   ex1.printVisible(ExportType);\r
29 }\r
30 \r
31 function ExportGridServer(ExportType) {\r
32   if (Rico.isIE) {\r
33     location.href+='&fmt='+ExportType;\r
34   } else {\r
35     window.open(location.href+'&fmt='+ExportType);\r
36   }\r
37 }\r
38 </script>\r
39 \r
40 <style type="text/css">\r
41 .CatHead {\r
42   background:blue;\r
43   color:white;\r
44   font-weight:bold !important;\r
45 }\r
46 .Subtotal {\r
47   background:#888;\r
48   color:white;\r
49   font-weight:bold !important;\r
50 }\r
51 .GrandTotal {\r
52   background:black;\r
53   color:white;\r
54   font-weight:bold !important;\r
55 }\r
56 div.ricoLG_cell {\r
57   white-space:nowrap;\r
58 }\r
59 </style>\r
60 \r
61 </head>\r
62 \r
63 \r
64 <body>\r
65 \r
66 <table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>\r
67 Base Library: \r
68 <script type='text/javascript'>\r
69 document.write(Rico.Lib+' '+Rico.LibVersion);\r
70 </script>\r
71 <hr>\r
72 <p><strong>Rico: SimpleGrid</strong></p>\r
73 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.\r
74 It shares many of the same characteristics as Rico's better known LiveGrid.\r
75 SimpleGrids have resizable columns, frozen columns on the left, and can use the\r
76 same CSS styling as LiveGrids. Sorting and filtering can also be enabled\r
77 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid\r
78 can be formatted individually.\r
79 </td>\r
80 <td>\r
81 <?php\r
82 require "info.php";\r
83 ?>\r
84 </td>\r
85 </tr></table>\r
86 \r
87 \r
88 <div>\r
89 <button onclick="ExportGridClient('plain')">Export from client<br>to HTML Table</button>\r
90 <button onclick="ExportGridClient('owc')" id="owc">Export from client<br>to OWC spreadsheet</button>\r
91 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>\r
92 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>\r
93 </div>\r
94 \r
95 <?php\r
96 \r
97 if (!OpenDB()) {\r
98   echo "<p>ERROR opening database!";\r
99 } else {\r
100   $grid=new SimpleGrid();\r
101   FillGrid();\r
102   $fmt=isset($_GET["fmt"]) ? $_GET["fmt"] : "";\r
103   switch (strtolower($fmt)) {\r
104     case "xl": \r
105       $grid->RenderExcel("rico.xls");\r
106       break;\r
107     case "csv":\r
108       $grid->RenderDelimited("rico.csv", ",", "");\r
109       break;\r
110     default:\r
111       $grid->Render("ex1", 0);   // output html\r
112       break;\r
113   }\r
114 }\r
115 \r
116 \r
117 \r
118 function FillGrid() {\r
119   global $oDB,$grid;\r
120   $subtotals=array();\r
121   $grandtotals=array();\r
122   for ($i=0; $i<=1; $i++) {\r
123     $grandtotals[$i]=0;\r
124   }\r
125   // define heading\r
126   $grid->AddHeadingRow(true);\r
127   $grid->AddCell("Product");\r
128   $grid->AddCell("Gross Sales");\r
129   $grid->AddCell("Discounts");\r
130   $grid->AddCell("Net Sales");\r
131   $grid->AddCell("Avg Discount");\r
132   $sqltext="select CategoryName,ProductName, SUM(od.UnitPrice*Quantity) as GrossSales, SUM(od.UnitPrice*Quantity*Discount) as Discounts from (Order_Details od inner join Products p on p.ProductID=od.ProductID) inner join Categories c on p.CategoryID=c.CategoryID group by CategoryName,ProductName order by CategoryName,ProductName";\r
133   $rsMain=$oDB->RunQuery($sqltext);\r
134   while ($oDB->db->FetchRow($rsMain,$row)) {\r
135     $category=$row[0];\r
136     $Gross=$row[2];\r
137     $Discounts=$row[3];\r
138     if ($category != $lastCategory) {\r
139       if (!empty($lastCategory)) {\r
140         AddRow("Subtotal", $subtotals[0], $subtotals[1]);\r
141         $grid->SetRowAttr("class", "Subtotal");\r
142       }\r
143       $grid->AddDataRow();\r
144       $grid->SetRowAttr("class", "CatHead");\r
145       $grid->AddCell($category);\r
146       $grid->AddCell("");\r
147       $grid->AddCell("");\r
148       $grid->AddCell("");\r
149       $grid->AddCell("");\r
150       for ($i=0; $i<=1; $i++) {\r
151         $subtotals[$i]=0;\r
152       }\r
153       $lastCategory=$category;\r
154     }\r
155     $subtotals[0]+=$Gross;\r
156     $grandtotals[0]+=$Gross;\r
157     $subtotals[1]+=$Discounts;\r
158     $grandtotals[1]+=$Discounts;\r
159     AddRow($row[1], $Gross, $Discounts);\r
160   }\r
161   $oDB->rsClose($rsMain);\r
162   if (!empty($lastCategory)) {\r
163     AddRow("Subtotal", $subtotals[0], $subtotals[1]);\r
164     $grid->SetRowAttr("class", "Subtotal");\r
165   }\r
166   AddRow("Grand Total", $grandtotals[0], $grandtotals[1]);\r
167   $grid->SetRowAttr("class", "GrandTotal");\r
168 }\r
169 \r
170 function AddRow($ProductName, $Gross, $Discounts) {\r
171   global $grid;\r
172   $grid->AddDataRow();\r
173   $grid->AddCell(htmlspecialchars(utf8_encode($ProductName), ENT_COMPAT, 'UTF-8'));\r
174   $grid->AddCell("$".number_format($Gross)); \r
175   $grid->AddCell("$".number_format($Discounts));\r
176   $grid->AddCell("$".number_format($Gross-$Discounts));\r
177   $grid->AddCell(round($Discounts / $Gross * 100.0)."%");\r
178 }\r
179 \r
180 \r
181 ?>\r
182 \r
183 </body>\r
184 </html>\r
185 \r