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