Skip to content

Commit

Permalink
GSoC 2018: Setup Improvements Continue(libreehr) ** New (#1253)
Browse files Browse the repository at this point in the history
* GSOC 2018 Setup improvements #1195

* setup polished and added mysql version for mac-os, ajax cloning database setup

* recursicely scanned all directories in the sites folder for config variable

* separated intalled sites and non installed sites for dropdown

* multisite select login screen

* adjust some ui issues
  • Loading branch information
muarachmann authored and aethelwulffe committed May 9, 2019
1 parent 6708e99 commit ff250a1
Show file tree
Hide file tree
Showing 141 changed files with 36,328 additions and 21 deletions.
48 changes: 27 additions & 21 deletions gacl/setup.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once(dirname(__FILE__).'/admin/gacl_admin.inc.php');
require_once(ADODB_DIR .'/adodb-xmlschema.inc.php');


$db_table_prefix = $gacl->_db_table_prefix;
$db_type = $gacl->_db_type;
$db_name = $gacl->_db_name;
Expand All @@ -13,35 +14,39 @@
$db_password = $gacl->_db_password;

$failed = 0;
echo '<h4 class="librehealth-color">Configuration...</h4>';
echo '
<p>driver = <span class="blueblack">'.$db_type.',</span></p>
<p>host = <span class="blueblack">'.$db_host.',</span></p>
<p>user = <span class="blueblack">'.$db_user.',</span></p>
<p>database = <span class="blueblack">'.$db_name.',</span></p>
<p>table prefix = '.$db_table_prefix.'</p>
';

echo '<b>Configuration:</b><br/>
driver = <b>'.$db_type.'</b>,<br/>
host = <b>'.$db_host.'</b>,<br/>
user = <b>'.$db_user.'</b>,<br/>
database = <b>'.$db_name.'</b>,<br/>
table prefix = <b>'.$db_table_prefix.'</b>';

function echo_success($text) {
echo '<font color="green"><b>Success!</b></font> '.$text."<br/>\n";
echo '<p><span class="green"><b>Success!</b></span> '.$text."</p>";
}

function echo_failed($text) {
global $failed;
echo '<font color="red"><b>Failed!</b></font> '.$text."<br/>\n";
echo '<p><span class="red"><b>Failed!</b></span> '.$text."</p>";
$failed++;
}

function echo_normal($text) {
echo $text."<br/>\n";
echo "<p>".$text."</p>";
}

/*
* Test database connection
*/
echo 'Testing database connection...<br/>'."\n";
echo '<p class="clearfix"></p>';
echo '<h4 class="librehealth-color">Testing database connection...</h4>';

if (is_object($db->_connectionID)) {
echo_success('Connected to &quot;<b>'.$db_type.'</b>&quot; database on &quot;<b>'.$db_host.'</b>&quot;.');
echo_success('<span class="blueblack">'.$db_type.'</span> database on <span class="blueblack">' .$db_host.'</span>');
} else {
echo_failed('<b>ERROR</b> connecting to database,<br/>
are you sure you specified the proper host, user name, password, and database in <b>admin/gacl_admin.inc.php</b>?<br/>
Expand All @@ -52,25 +57,26 @@ function echo_normal($text) {
/*
* Do database specific stuff.
*/
echo 'Testing database type...<br/>'."\n";
echo "<p class='clearfix'></p>";
echo "<h4 class='librehealth-color'>Testing database type...</h4>";

switch ( $db_type ) {
case ($db_type == "mysql" OR $db_type == "mysqlt" OR $db_type == "maxsql" OR $db_type == "mysqli" ):
echo_success("Compatible database type \"<b>$db_type</b>\" detected!");
echo_normal("Making sure database \"<b>$db_name</b>\" exists...");
echo_success("Compatible database type <span class='blueblack'>".$db_type."</span> detected!");
echo_normal("Making sure database <span class='blueblack'>".$db_name."</span> exists...");

$databases = $db->GetCol("show databases");

if (in_array($db_name, $databases) ) {
echo_success("Good, database \"<b>$db_name</b>\" already exists!");
echo_success("Good database <span class='blueblack'>".$db_name."</span> already exists!");
} else {
echo_normal("Database \"<b>$db_name</b>\" does not exist!");
echo_normal("Database <span class='blueblack'>".$db_name."</span> does not exist!");
echo_normal("Lets try to create it...");

if (!$db->Execute("create database $db_name") ) {
echo_failed("Database \"<b>$db_name</b>\" could not be created, please do so manually.");
echo_failed("Database <span class='blueblack'>".$db_name."</span> could not be created, please do so manually.");
} else {
echo_success("Good, database \"<b>$db_name</b>\" has been created!!");
echo_success("Good, database <span class='blueblack'>".$db_name."</span> has been created!!");

//Reconnect. Hrmm, this is kinda weird.
$db->Connect($db_host, $db_user, $db_password, $db_name);
Expand Down Expand Up @@ -182,15 +188,15 @@ function echo_normal($text) {
#ADODB's xmlschema is being lame, continue on error.
$schema->ContinueOnError(TRUE);
$result = $schema->ExecuteSchema();
echo "<p class='clearfix'></p>";

if ($result != 2) {
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.');
}

if ( $failed <= 0 ) {
echo_success('
First Step of Access Control Installation Successful!!!<br>');
echo_success('First Step of Access Control Installation Successful!!!');
} else {
echo_failed('Please fix the above errors and try again.<br><br>');
echo_failed('Please fix the above errors and try again.');
}
?>
63 changes: 63 additions & 0 deletions modules/setup/ajaxprocess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* This file is responsible for grabbing the current status of the setup process in step 4 of the installation.
* It reads from the tmp/ajaxprocess.txt file and returns the state of the setup process.
*
* LICENSE: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0
* See the Mozilla Public License for more details.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* @package Librehealth EHR
* @author Mua Laurent <[email protected]>
* @link http://librehealth.io
*
* Please help the overall project by sending changes you make to the author and to the LibreEHR community.
*
*/
?>

<?php
// Tract down all processes of the ajax call one after another and reads them here
// reads the temp/123213.txt and gets the json format (decodes and encodes it again).
// Then sends the result to our step4.php process.


// The file has JSON type.
header('Content-Type: application/json');

// Prepare the file name from the query string.
// Don't use session_start here. Otherwise this file will be only executed after the process.php execution is done.

// $file = str_replace(".", "", $_GET['file']);
$file = "tmp/ajaxprocess.txt";


// Make sure the file is exist.
if (file_exists($file)) {
// Get the content and echo it.
$text = file_get_contents($file);
echo $text;
// Convert to JSON to read the status.
$obj = json_decode($text);
// If the process is finished, delete the file.
if ($obj->percentage == 100) {
unlink($file);
}
}
else {
echo json_encode(array("percent" => null, "message" => null));
}













?>
Loading

0 comments on commit ff250a1

Please sign in to comment.