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