Fix wheel scrolling on LiveGrid content
[infodrom/rico3] / examples / php / dbConnect.php
1 <?php\r
2 require "../../plugins/php/dbClass3.php";\r
3 $appName="Northwind";\r
4 $appDB="northwind";\r
5 \r
6 function CreateDbClass() {\r
7   global $oDB;\r
8   $oDB = new dbClass();\r
9 }\r
10 \r
11 function OpenDB() {\r
12   global $oDB,$appDB;\r
13   CreateDbClass();\r
14 \r
15   // MySQL\r
16   return $oDB->MySqlLogon($appDB, "userid", "password");\r
17 \r
18   // MS SQL\r
19   //$oDB->Dialect="TSQL";\r
20   //return $oDB->MSSqlLogon("computer/instance", $appDB, "userid", "password");\r
21 \r
22   // PostgreSQL\r
23   // The connection_string can be empty to use all default parameters, or it can contain one or more parameter settings separated by whitespace. Each parameter setting is in the form keyword = value. Spaces around the equal sign are optional. To write an empty value or a value containing spaces, surround it with single quotes, e.g., keyword = 'a value'. Single quotes and backslashes within the value must be escaped with a backslash, i.e., \' and \\.\r
24   // The currently recognized parameter keywords are: host, hostaddr, port, dbname (defaults to value of user), user, password, connect_timeout, options, tty (ignored), sslmode, requiressl (deprecated in favor of sslmode), and service. Which of these arguments exist depends on your PostgreSQL version. \r
25   //return $oDB->PostgreSqlLogon($connection_string);\r
26   \r
27   // ODBC - MS Access\r
28   //$oDB->Dialect="Access";\r
29   //return $oDB->OdbcLogon("northwindDSN","Northwind","userid","password");\r
30 \r
31   // Oracle\r
32   //$oDB->Dialect="Oracle";\r
33   //return $oDB->OracleLogon("XE","northwind","password");\r
34 }\r
35 \r
36 \r
37 function OpenApp($title) {\r
38   $_retval=false;\r
39   if (!OpenDB()) {\r
40     return $_retval;\r
41   }\r
42   if (!empty($title)) {\r
43     AppHeader($GLOBALS['appName']."-".$title);\r
44   }\r
45   $GLOBALS['accessRights']="rw";\r
46   // CHECK APPLICATION SECURITY HERE  (in this example, "r" gives read-only access and "rw" gives read/write access)\r
47   if (empty($GLOBALS['accessRights']) || !isset($GLOBALS['accessRights']) || substr($GLOBALS['accessRights'],0,1) != "r") {\r
48     echo "<p class='error'>You do not have permission to access this application";\r
49   }\r
50   else {\r
51     $_retval=true;\r
52   }\r
53   return $_retval;\r
54 }\r
55 \r
56 \r
57 function OpenTableEdit($tabname) {\r
58   $obj= new TableEditClass();\r
59   $obj->SetTableName($tabname);\r
60   $obj->options["XMLprovider"]="ricoQuery.php";\r
61   $obj->convertCharSet=true;   // because sample database is ISO-8859-1 encoded\r
62   return $obj;\r
63 }\r
64 \r
65 \r
66 function OpenGridForm($title, $tabname) {\r
67   $_retval=false;\r
68   if (!OpenApp($title)) {\r
69     return $_retval;\r
70   }\r
71   $GLOBALS['oForm']= OpenTableEdit($tabname);\r
72   $CanModify=($GLOBALS['accessRights'] == "rw");\r
73   $GLOBALS['oForm']->options["canAdd"]=$CanModify;\r
74   $GLOBALS['oForm']->options["canEdit"]=$CanModify;\r
75   $GLOBALS['oForm']->options["canDelete"]=$CanModify;\r
76   session_set_cookie_params(60*60);\r
77   $GLOBALS['sqltext']='.';\r
78   return true;\r
79 }\r
80 \r
81 \r
82 function CloseApp() {\r
83   global $oDB;\r
84   if (is_object($oDB)) $oDB->dbClose();\r
85   $oDB=NULL;\r
86   $GLOBALS['oForm']=NULL;\r
87 }\r
88 \r
89 \r
90 function AppHeader($hdg) {\r
91   echo "<h2 class='appHeader'>".str_replace("<dialect>",$GLOBALS['oDB']->Dialect,$hdg)."</h2>";\r
92 }\r
93 \r
94 ?>\r
95 \r