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