Import examples/php/applib.php from OpenRico 2.1
[misc/kostenrechnung] / lib / dbase.php
1 <?php
2 //
3 // This is where the database connection settings go.
4 // This is required to get the LiveGrid examples running.
5 // As your application develops, this would also be a logical place to put security checks.
6 // The Northwind database is required to run the examples. 
7 // Samples of this database in various formats are located in the examples/data directory.
8 //
9
10
11 require "../../plugins/php/dbClass2.php";
12 $appName="Northwind";
13 $appDB="northwind";
14
15 function CreateDbClass() {
16   global $oDB;
17   $oDB = new dbClass();  // from dbClass2
18   
19   // What dialect of SQL will we be speaking?
20   
21   //$oDB->Dialect="MySQL"  // this is the default, so you can leave it commented
22   //$oDB->Dialect="Oracle";
23   //$oDB->Dialect="TSQL";
24   //$oDB->Dialect="Access";
25 }
26
27 function OpenDB() {
28   global $oDB;
29   CreateDbClass();
30   
31   // This is where the database connection is made
32   // Uncomment the appropriate line for your database
33   
34   // Using MySQL
35   // $oDB->Provider="MySQLremoveserver"  // required if MySQL is remote
36   return $oDB->MySqlLogon($GLOBALS['appDB'], "userid", "password");
37   
38   // Connect via ODBC to a DSN
39   //return $oDB->OdbcLogon("northwindDSN","Northwind","userid","password");
40   
41   // Connect to Oracle XE
42   // Make sure the Oracle database is loaded with the sample database
43   // $oDB->Provider="MySQLremoveserver"  // required if Oracle is remote
44   //return $oDB->OracleLogon("XE","northwind","password");
45 }
46
47 function OpenApp($title) {
48   $_retval=false;
49   if (!OpenDB()) {
50     return $_retval;
51   }
52   if (!empty($title)) {
53     AppHeader($GLOBALS['appName']."-".$title);
54   }
55   $GLOBALS['accessRights']="rw";
56   // CHECK APPLICATION SECURITY HERE  (in this example, "r" gives read-only access and "rw" gives read/write access)
57   if (empty($GLOBALS['accessRights']) || !isset($GLOBALS['accessRights']) || substr($GLOBALS['accessRights'],0,1) != "r") {
58     echo "<p class='error'>You do not have permission to access this application";
59   }
60   else {
61     $_retval=true;
62   }
63   return $_retval;
64 }
65
66 function OpenTableEdit($tabname) {
67   $obj= new TableEditClass();
68   $obj->SetTableName($tabname);
69   $obj->options["XMLprovider"]="ricoXMLquery.php";
70   $obj->convertCharSet=true;   // because sample database is ISO-8859-1 encoded
71   return $obj;
72 }
73
74 function OpenGridForm($title, $tabname) {
75   $_retval=false;
76   if (!OpenApp($title)) {
77     return $_retval;
78   }
79   $GLOBALS['oForm']= OpenTableEdit($tabname);
80   $CanModify=($GLOBALS['accessRights'] == "rw");
81   $GLOBALS['oForm']->options["canAdd"]=$CanModify;
82   $GLOBALS['oForm']->options["canEdit"]=$CanModify;
83   $GLOBALS['oForm']->options["canDelete"]=$CanModify;
84   session_set_cookie_params(60*60);
85   $GLOBALS['sqltext']='.';
86   return true;
87 }
88
89 function CloseApp() {
90   global $oDB;
91   if (is_object($oDB)) $oDB->dbClose();
92   $oDB=NULL;
93   $GLOBALS['oForm']=NULL;
94 }
95
96 function AppHeader($hdg) {
97   echo "<h2 class='appHeader'>".str_replace("<dialect>",$GLOBALS['oDB']->Dialect,$hdg)."</h2>";
98 }
99 ?>
100