need to specify use of onsetDate as member function rather than global
[openemr.git] / gacl / setup.php
blobb62c18aac017b96d670f75db27c5ff15a1a45c58
1 <?php
3 $config_file = dirname(__FILE__).'/gacl.ini.php';
5 require_once(dirname(__FILE__).'/admin/gacl_admin.inc.php');
6 require_once(ADODB_DIR .'/adodb-xmlschema.inc.php');
8 $db_table_prefix = $gacl->_db_table_prefix;
9 $db_type = $gacl->_db_type;
10 $db_name = $gacl->_db_name;
11 $db_host = $gacl->_db_host;
12 $db_user = $gacl->_db_user;
13 $db_password = $gacl->_db_password;
15 $failed = 0;
17 echo '<b>Configuration:</b><br/>
18 driver = <b>'.$db_type.'</b>,<br/>
19 host = <b>'.$db_host.'</b>,<br/>
20 user = <b>'.$db_user.'</b>,<br/>
21 database = <b>'.$db_name.'</b>,<br/>
22 table prefix = <b>'.$db_table_prefix.'</b>';
24 function echo_success($text) {
25 echo '<font color="green"><b>Success!</b></font> '.$text."<br/>\n";
28 function echo_failed($text) {
29 global $failed;
30 echo '<font color="red"><b>Failed!</b></font> '.$text."<br/>\n";
31 $failed++;
34 function echo_normal($text) {
35 echo $text."<br/>\n";
39 * Test database connection
41 echo 'Testing database connection...<br/>'."\n";
43 if (is_resource($db->_connectionID)) {
44 echo_success('Connected to &quot;<b>'.$db_type.'</b>&quot; database on &quot;<b>'.$db_host.'</b>&quot;.');
45 } else {
46 echo_failed('<b>ERROR</b> connecting to database,<br/>
47 are you sure you specified the proper host, user name, password, and database in <b>admin/gacl_admin.inc.php</b>?<br/>
48 Did you create the database, and give read/write permissions to &quot;<b>'.$db_user.'</b>&quot; already?');
49 exit;
53 * Do database specific stuff.
55 echo 'Testing database type...<br/>'."\n";
57 switch ( $db_type ) {
58 case ($db_type == "mysql" OR $db_type == "mysqlt" OR $db_type == "maxsql" ):
59 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
60 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
62 $databases = $db->GetCol("show databases");
64 if (in_array($db_name, $databases) ) {
65 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
66 } else {
67 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
68 echo_normal("Lets try to create it...");
70 if (!$db->Execute("create database $db_name") ) {
71 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
72 } else {
73 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
75 //Reconnect. Hrmm, this is kinda weird.
76 $db->Connect($db_host, $db_user, $db_password, $db_name);
80 break;
81 case ( $db_type == "postgres8" OR $db_type == "postgres7" ):
82 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
84 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
86 $databases = $db->GetCol("select datname from pg_database");
88 if (in_array($db_name, $databases) ) {
89 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
90 } else {
91 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
92 echo_normal("Lets try to create it...");
94 if (!$db->Execute("create database $db_name") ) {
95 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
96 } else {
97 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
99 //Reconnect. Hrmm, this is kinda weird.
100 $db->Connect($db_host, $db_user, $db_password, $db_name);
104 break;
106 case "oci8-po":
107 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
109 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
111 $databases = $db->GetCol("select '$db_name' from dual");
113 if (in_array($db_name, $databases) ) {
114 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
115 } else {
116 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
117 echo_normal("Lets try to create it...");
119 if (!$db->Execute("create database $db_name") ) {
120 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
121 } else {
122 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
124 //Reconnect. Hrmm, this is kinda weird.
125 $db->Connect($db_host, $db_user, $db_password, $db_name);
129 break;
131 case "mssql":
132 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
134 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
136 $databases = $db->GetCol("select CATALOG_NAME from INFORMATION_SCHEMA.SCHEMATA");
138 if (in_array($db_name, $databases) ) {
139 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
140 } else {
141 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
142 echo_normal("Lets try to create it...");
144 if (!$db->Execute("create database $db_name") ) {
145 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
146 } else {
147 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
149 //Reconnect. Hrmm, this is kinda weird.
150 $db->Connect($db_host, $db_user, $db_password, $db_name);
154 break;
156 default:
157 echo_normal("Sorry, <b>setup.php</b> currently does not fully support \"<b>$db_type</b>\" databases.
158 <br>I'm assuming you've already created the database \"$db_name\", attempting to create tables.
159 <br> Please email <b>$author_email</b> code to detect if a database is created or not so full support for \"<b>$db_type</b>\" can be added.");
164 * Attempt to create tables
166 // Create the schema object and build the query array.
167 $schema = new adoSchema($db);
168 $schema->SetPrefix($db_table_prefix, FALSE); //set $underscore == FALSE
170 // Build the SQL array
171 $schema->ParseSchema(dirname(__FILE__).'/schema.xml');
173 // maybe display this if $gacl->debug is true?
174 if ($gacl->_debug) {
175 print "Here's the SQL to do the build:<br />\n<code>";
176 print $schema->getSQL('html');
177 print "</code>\n";
178 // exit;
181 // Execute the SQL on the database
182 #ADODB's xmlschema is being lame, continue on error.
183 $schema->ContinueOnError(TRUE);
184 $result = $schema->ExecuteSchema();
186 if ($result != 2) {
187 echo_failed('Failed creating tables. Please enable DEBUG mode (set it to TRUE in $gacl_options near top of admin/gacl_admin.inc.php) to see the error and try again. You will most likely need to delete any tables already created.');
190 if ( $failed <= 0 ) {
191 echo_success('
192 First Step of Access Control Installation Successful!!!<br>');
193 } else {
194 echo_failed('Please fix the above errors and try again.<br><br>');