1cffedcc836878ebae00a96e3e9ede26deb781df
[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 Rico.loadModule('LiveGridForms','Calendar','Tree');
51
52 // ricoLiveGridForms will call orders_FormInit right before grid & form initialization.
53
54 function orders_FormInit() {
55   var cal=new Rico.CalendarControl("Cal");
56   Rico.EditControls.register(cal, Rico.imgDir+'calarrow.png');
57   
58   var CustTree=new Rico.TreeControl("CustomerTree","CustTree.php");
59   Rico.EditControls.register(CustTree, Rico.imgDir+'dotbutton.gif');
60 }
61 </script>
62
63 <link href="../demo.css" type="text/css" rel="stylesheet" />
64 <style type="text/css">
65 div.ricoLG_outerDiv thead .ricoLG_cell, div.ricoLG_outerDiv thead td, div.ricoLG_outerDiv thead th {
66         height:1.5em;
67 }
68 div.ricoLG_cell {
69   white-space:nowrap;
70 }
71 </style>
72 </head>
73 <body>
74
75
76 <table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>
77 Base Library: <script type='text/javascript'>document.write(Rico.Lib+' '+Rico.LibVersion);</script>
78 <hr>The data on this grid can be edited using pop-up forms. 
79 Just click on a grid cell and then select Edit, Delete, or Add from the pop-up menu. 
80 The Add and Edit forms are automatically generated by LiveGrid. 
81 Notice on the Add form how you use the Rico Tree control to select the customer. 
82 Notice on the Edit form how the Rico Calendar is used to change dates. 
83 Updates are disabled on the database, so you will get an error message if you try to save.
84 </td><td>
85 <script type='text/javascript'><!--
86 google_ad_client = 'pub-7218597156507462';
87 /* 125x125, created 5/11/09 */
88 google_ad_slot = '9298106441';
89 google_ad_width = 125;
90 google_ad_height = 125;
91 //-->
92 </script>
93 <script type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'></script>
94 </td></tr></table>
95
96 <p><strong>Orders Table</strong></p>
97
98 <?php
99 DefineFields();
100 $oForm->DisplayPage();
101 //echo "<p><textarea id='orders_debugmsgs' rows='5' cols='80' style='font-size:smaller;'></textarea>";
102 CloseApp();
103
104
105 function DefineFields() {
106   global $oForm,$oDB;
107   $oForm->options["FilterLocation"]=-1;
108   $oForm->options["panelWidth"]=500;
109   $oForm->options["frozenColumns"]=1;
110   $oForm->options["menuEvent"]='click';
111   $oForm->options["highlightElem"]='cursorRow';
112   $oForm->options["XMLprovider"]=$_SERVER['SCRIPT_NAME'];
113   $oForm->sessions=false;
114   //$GLOBALS['oForm']->options["DebugFlag"]=true;
115   //$GLOBALS['oDB']->debug=true;
116
117   $oForm->AddPanel("Basic Info");
118   $oForm->AddEntryFieldW("OrderID", "Order ID", "B", "<auto>", 50);
119   $oForm->ConfirmDeleteColumn();
120   $oForm->SortAsc();
121
122   $LookupSQL="select CustomerID,CompanyName from customers order by CompanyName";
123   $oForm->AddLookupField("CustomerID",null,"CustID","Customer","CL","",$LookupSQL);
124   $oForm->LookupField["SelectCtl"]="CustomerTree";
125   $oForm->LookupField["InsertOnly"]=true;   // do not allow customer to be changed once an order is entered
126   $oForm->CurrentField["width"]=160;
127   $oForm->CurrentField["filterUI"]="t";
128
129   $LookupSQL="select EmployeeID,".$oDB->concat(array("LastName", "', '", "FirstName"), false)." from employees order by LastName,FirstName";
130   $oForm->AddLookupField("EmployeeID",null,"EmployeeID","Sales Person","SL","",$LookupSQL);
131   $oForm->CurrentField["width"]=140;
132   $oForm->CurrentField["filterUI"]="s";
133
134   $oForm->AddEntryField("OrderDate", "Order Date", "D", strftime('%Y-%m-%d'));
135   $oForm->CurrentField["SelectCtl"]="Cal";
136   $oForm->CurrentField["width"]=90;
137   $oForm->AddEntryField("RequiredDate", "Required Date", "D", strftime('%Y-%m-%d'));
138   $oForm->CurrentField["SelectCtl"]="Cal";
139   $oForm->CurrentField["width"]=90;
140   $oForm->AddCalculatedField("select sum(UnitPrice*Quantity*(1.0-Discount)) from order_details d where d.OrderID=t.OrderID","Net Sale");
141   $oForm->CurrentField["format"]="DOLLAR";
142   $oForm->CurrentField["width"]=80;
143
144   $oForm->AddPanel("Ship To");
145   $oForm->AddEntryFieldW("ShipName", "Name", "B", "",140);
146   $oForm->AddEntryFieldW("ShipAddress", "Address", "B", "",140);
147   $oForm->AddEntryFieldW("ShipCity", "City", "B", "",120);
148   $oForm->CurrentField["filterUI"]="s";
149   $oForm->AddEntryFieldW("ShipRegion", "Region", "T", "",60);
150   $oForm->AddEntryFieldW("ShipPostalCode", "Postal Code", "T", "",100);
151   
152   // display ShipCountry with a link to wikipedia
153   $colnum=$oForm->AddEntryFieldW("ShipCountry", "Country", "N", "",100);
154   $oForm->CurrentField["control"]="new Rico.TableColumn.link('http://en.wikipedia.org/wiki/{".$colnum."}','_blank')";
155   $oForm->CurrentField["filterUI"]="s";
156 }
157 ?>
158
159
160 </body>
161 </html>