Add New FMC code from Intesync
[openemr.git] / gacl / setup.php
blob1be81b6d55dec17d557b3ea2f01b28105f70d3fc
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;
14 $db_name = $gacl->_db_name;
16 $failed = 0;
18 echo '<b>Configuration:</b><br/>
19 driver = <b>'.$db_type.'</b>,<br/>
20 host = <b>'.$db_host.'</b>,<br/>
21 user = <b>'.$db_user.'</b>,<br/>
22 database = <b>'.$db_name.'</b>,<br/>
23 table prefix = <b>'.$db_table_prefix.'</b>';
25 function echo_success($text) {
26 echo '<font color="green"><b>Success!</b></font> '.$text."<br/>\n";
29 function echo_failed($text) {
30 global $failed;
31 echo '<font color="red"><b>Failed!</b></font> '.$text."<br/>\n";
32 $failed++;
35 function echo_normal($text) {
36 echo $text."<br/>\n";
40 * Test database connection
42 echo 'Testing database connection...<br/>'."\n";
44 if (is_resource($db->_connectionID)) {
45 echo_success('Connected to &quot;<b>'.$db_type.'</b>&quot; database on &quot;<b>'.$db_host.'</b>&quot;.');
46 } else {
47 echo_failed('<b>ERROR</b> connecting to database,<br/>
48 are you sure you specified the proper host, user name, password, and database in <b>admin/gacl_admin.inc.php</b>?<br/>
49 Did you create the database, and give read/write permissions to &quot;<b>'.$db_user.'</b>&quot; already?');
50 exit;
54 * Do database specific stuff.
56 echo 'Testing database type...<br/>'."\n";
58 switch ( $db_type ) {
59 case ($db_type == "mysql" OR $db_type == "mysqlt" OR $db_type == "maxsql" ):
60 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
61 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
63 $databases = $db->GetCol("show databases");
65 if (in_array($db_name, $databases) ) {
66 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
67 } else {
68 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
69 echo_normal("Lets try to create it...");
71 if (!$db->Execute("create database $db_name") ) {
72 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
73 } else {
74 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
76 //Reconnect. Hrmm, this is kinda weird.
77 $db->Connect($db_host, $db_user, $db_password, $db_name);
81 break;
82 case ( $db_type == "postgres8" OR $db_type == "postgres7" ):
83 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
85 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
87 $databases = $db->GetCol("select datname from pg_database");
89 if (in_array($db_name, $databases) ) {
90 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
91 } else {
92 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
93 echo_normal("Lets try to create it...");
95 if (!$db->Execute("create database $db_name") ) {
96 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
97 } else {
98 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
100 //Reconnect. Hrmm, this is kinda weird.
101 $db->Connect($db_host, $db_user, $db_password, $db_name);
105 break;
107 case "oci8-po":
108 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
110 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
112 $databases = $db->GetCol("select '$db_name' from dual");
114 if (in_array($db_name, $databases) ) {
115 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
116 } else {
117 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
118 echo_normal("Lets try to create it...");
120 if (!$db->Execute("create database $db_name") ) {
121 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
122 } else {
123 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
125 //Reconnect. Hrmm, this is kinda weird.
126 $db->Connect($db_host, $db_user, $db_password, $db_name);
130 break;
132 case "mssql":
133 echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
135 echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
137 $databases = $db->GetCol("select CATALOG_NAME from INFORMATION_SCHEMA.SCHEMATA");
139 if (in_array($db_name, $databases) ) {
140 echo_success("Good, database \"<b>$db_name</b>\" already exists!");
141 } else {
142 echo_normal("Database \"<b>$db_name</b>\" does not exist!");
143 echo_normal("Lets try to create it...");
145 if (!$db->Execute("create database $db_name") ) {
146 echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
147 } else {
148 echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
150 //Reconnect. Hrmm, this is kinda weird.
151 $db->Connect($db_host, $db_user, $db_password, $db_name);
155 break;
157 default:
158 echo_normal("Sorry, <b>setup.php</b> currently does not fully support \"<b>$db_type</b>\" databases.
159 <br>I'm assuming you've already created the database \"$db_name\", attempting to create tables.
160 <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.");
165 * Attempt to create tables
167 // Create the schema object and build the query array.
168 $schema = new adoSchema($db);
169 $schema->SetPrefix($db_table_prefix, FALSE); //set $underscore == FALSE
171 // Build the SQL array
172 $schema->ParseSchema(dirname(__FILE__).'/schema.xml');
174 // maybe display this if $gacl->debug is true?
175 if ($gacl->_debug) {
176 print "Here's the SQL to do the build:<br />\n<code>";
177 print $schema->getSQL('html');
178 print "</code>\n";
179 // exit;
182 // Execute the SQL on the database
183 #ADODB's xmlschema is being lame, continue on error.
184 $schema->ContinueOnError(TRUE);
185 $result = $schema->ExecuteSchema();
187 if ($result != 2) {
188 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.');
191 if ( $failed <= 0 ) {
192 echo_success('
193 First Step of Access Control Installation Successful!!!<br>');
194 } else {
195 echo_failed('Please fix the above errors and try again.<br><br>');