4654f51193819b767940777a7e6890b2d1b8a22c
[infodrom/rico3] / examples / php / ex2editfilter.php
1 <?php
2 if (!isset ($_SESSION)) session_start();
3 header("Cache-Control: no-cache");
4 header("Pragma: no-cache");
5 header("Expires: ".gmdate("D, d M Y H:i:s",time()+(-1*60))." GMT");
6 header('Content-type: text/html; charset=utf-8');
7 ?>
8
9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
10 <html>
11 <head>
12 <title>Rico LiveGrid-Example 2 (editable)</title>
13 <?php
14 require "dbConnect.php";
15 require "LoadRicoClient.php";
16 require "../../plugins/php/ricoLiveGridForms.php";
17 ?>
18
19 <script type='text/javascript'>
20 Rico.loadModule('LiveGridForms','Calendar','Tree');
21
22 // ricoLiveGridForms will call orders_FormInit right before grid & form initialization.
23
24 function orders_FormInit() {
25   var cal=new Rico.CalendarControl("Cal");
26   Rico.EditControls.register(cal, Rico.imgDir+'calarrow.png');
27   
28   var CustTree=new Rico.TreeControl("CustomerTree","CustTree.php");
29   Rico.EditControls.register(CustTree, Rico.imgDir+'dotbutton.gif');
30 }
31 </script>
32
33 <link href="../demo.css" type="text/css" rel="stylesheet" />
34 <style type="text/css">
35 div.ricoLG_outerDiv thead .ricoLG_cell, div.ricoLG_outerDiv thead td, div.ricoLG_outerDiv thead th {
36         height:1.5em;
37 }
38 div.ricoLG_cell {
39   white-space:nowrap;
40 }
41 </style>
42 </head>
43 <body>
44
45 <?php
46 //************************************************************************************************************
47 //  LiveGrid Plus-Edit Example
48 //************************************************************************************************************
49 //  Matt Brown
50 //************************************************************************************************************
51 if (OpenGridForm("", "orders")) {
52   if ($oForm->action == "table") {
53     DisplayTable();
54   }
55   else {
56     DefineFields();
57   }
58 } else {
59   echo 'open failed';
60 }
61 CloseApp();
62
63 function DisplayTable() {
64   global $oForm,$oDB;
65   echo "<table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>";
66   echo "Base Library: <script type='text/javascript'>document.write(Rico.Lib+' '+Rico.LibVersion);</script>";
67   echo "<hr>The data on this grid can be edited using pop-up forms. ";
68   echo "Just click on a grid cell and then select Edit, Delete, or Add from the pop-up menu. ";
69   echo "The Add and Edit forms are automatically generated by LiveGrid. ";
70   echo "Notice on the Add form how you use the Rico Tree control to select the customer. ";
71   echo "Notice on the Edit form how the Rico Calendar is used to change dates. ";
72   echo "Updates are disabled on the database, so you will get an error message if you try to save.";
73   echo "</td><td>";
74   require "info.php";
75   echo "</td></tr></table>";
76   echo "<p><strong>Orders Table</strong></p>";
77
78   $oForm->options["panelWidth"]=500;
79   $oForm->options["frozenColumns"]=1;
80   $oForm->options["menuEvent"]='click';
81   $oForm->options["highlightElem"]='cursorRow';
82   //$GLOBALS['oForm']->options["DebugFlag"]=true;
83   //$GLOBALS['oDB']->debug=true;
84   DefineFields();
85   //echo "<p><textarea id='orders_debugmsgs' rows='5' cols='80' style='font-size:smaller;'></textarea>";
86 }
87
88 function DefineFields() {
89   global $oForm,$oDB;
90   $oForm->options["FilterLocation"]=-1;
91
92   $oForm->AddPanel("Basic Info");
93   $oForm->AddEntryFieldW("OrderID", "Order ID", "B", "<auto>", 50);
94   $oForm->ConfirmDeleteColumn();
95   $oForm->SortAsc();
96
97   $LookupSQL="select CustomerID,CompanyName from customers order by CompanyName";
98   $oForm->AddLookupField("CustomerID",null,"CustID","Customer","CL","",$LookupSQL);
99   $oForm->LookupField["SelectCtl"]="CustomerTree";
100   $oForm->LookupField["InsertOnly"]=true;   // do not allow customer to be changed once an order is entered
101   $oForm->CurrentField["width"]=160;
102   $oForm->CurrentField["filterUI"]="t";
103
104   $LookupSQL="select EmployeeID,".$oDB->concat(array("LastName", "', '", "FirstName"), false)." from employees order by LastName,FirstName";
105   $oForm->AddLookupField("EmployeeID",null,"EmployeeID","Sales Person","SL","",$LookupSQL);
106   $oForm->CurrentField["width"]=140;
107   $oForm->CurrentField["filterUI"]="m";
108
109   $oForm->AddEntryField("OrderDate", "Order Date", "D", strftime('%Y-%m-%d'));
110   $oForm->CurrentField["SelectCtl"]="Cal";
111   $oForm->CurrentField["width"]=90;
112   $oForm->AddEntryField("RequiredDate", "Required Date", "D", strftime('%Y-%m-%d'));
113   $oForm->CurrentField["SelectCtl"]="Cal";
114   $oForm->CurrentField["width"]=90;
115   $oForm->AddCalculatedField("select sum(UnitPrice*Quantity*(1.0-Discount)) from order_details d where d.OrderID=t.OrderID","Net Sale");
116   $oForm->CurrentField["format"]="DOLLAR";
117   $oForm->CurrentField["width"]=80;
118
119   $oForm->AddPanel("Ship To");
120   $oForm->AddEntryFieldW("ShipName", "Name", "B", "",140);
121   $oForm->AddEntryFieldW("ShipAddress", "Address", "B", "",140);
122   $oForm->AddEntryFieldW("ShipCity", "City", "B", "",120);
123   $oForm->CurrentField["filterUI"]="s";
124   $oForm->AddEntryFieldW("ShipRegion", "Region", "T", "",60);
125   $oForm->AddEntryFieldW("ShipPostalCode", "Postal Code", "T", "",100);
126   
127   // display ShipCountry with a link to wikipedia
128   $colnum=$oForm->AddEntryFieldW("ShipCountry", "Country", "N", "",100);
129   $oForm->CurrentField["control"]="new Rico.TableColumn.link('http://en.wikipedia.org/wiki/{".$colnum."}','_blank')";
130   $oForm->CurrentField["filterUI"]="s";
131
132   $oForm->DisplayPage();
133 }
134 ?>
135
136
137 </body>
138 </html>