8 * @link https://www.open-emr.org
9 * @author Andrew Moore <amoore@cpan.org>
10 * @author Ranganath Pathak <pathak@scrs1.org>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2010 Andrew Moore <amoore@cpan.org>
13 * @copyright Copyright (c) 2019 Ranganath Pathak <pathak@scrs1.org>
14 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 use OpenEMR\Gacl\GaclApi
;
39 public $source_site_id;
40 public $clone_database;
41 public $no_root_db_access;
42 public $development_translations;
44 public $ippf_specific;
47 public $translation_sql;
48 public $devel_translation_sql;
52 public $additional_users;
54 public $error_message;
55 public $debug_message;
58 public function __construct($cgi_variables)
60 // Installation variables
61 // For a good explanation of these variables, see documentation in
62 // the contrib/util/installScripts/InstallerAuto.php file.
63 $this->iuser
= isset($cgi_variables['iuser']) ?
($cgi_variables['iuser']) : '';
64 $this->iuserpass
= isset($cgi_variables['iuserpass']) ?
($cgi_variables['iuserpass']) : '';
65 $this->iuname
= isset($cgi_variables['iuname']) ?
($cgi_variables['iuname']) : '';
66 $this->iufname
= isset($cgi_variables['iufname']) ?
($cgi_variables['iufname']) : '';
67 $this->igroup
= isset($cgi_variables['igroup']) ?
($cgi_variables['igroup']) : '';
68 $this->i2faEnable
= isset($cgi_variables['i2faenable']) ?
($cgi_variables['i2faenable']) : '';
69 $this->i2faSecret
= isset($cgi_variables['i2fasecret']) ?
($cgi_variables['i2fasecret']) : '';
70 $this->server
= isset($cgi_variables['server']) ?
($cgi_variables['server']) : ''; // mysql server (usually localhost)
71 $this->loginhost
= isset($cgi_variables['loginhost']) ?
($cgi_variables['loginhost']) : ''; // php/apache server (usually localhost)
72 $this->port
= isset($cgi_variables['port']) ?
($cgi_variables['port']) : '';
73 $this->root
= isset($cgi_variables['root']) ?
($cgi_variables['root']) : '';
74 $this->rootpass
= isset($cgi_variables['rootpass']) ?
($cgi_variables['rootpass']) : '';
75 $this->login
= isset($cgi_variables['login']) ?
($cgi_variables['login']) : '';
76 $this->pass
= isset($cgi_variables['pass']) ?
($cgi_variables['pass']) : '';
77 $this->dbname
= isset($cgi_variables['dbname']) ?
($cgi_variables['dbname']) : '';
78 $this->collate
= isset($cgi_variables['collate']) ?
($cgi_variables['collate']) : '';
79 $this->site
= isset($cgi_variables['site']) ?
($cgi_variables['site']) : 'default'; // set to default if not set in order for install script to work correctly
80 $this->source_site_id
= isset($cgi_variables['source_site_id']) ?
($cgi_variables['source_site_id']) : '';
81 $this->clone_database
= isset($cgi_variables['clone_database']) ?
($cgi_variables['clone_database']) : '';
82 $this->no_root_db_access
= isset($cgi_variables['no_root_db_access']) ?
($cgi_variables['no_root_db_access']) : ''; // no root access to database. user/privileges pre-configured
83 $this->development_translations
= isset($cgi_variables['development_translations']) ?
($cgi_variables['development_translations']) : '';
84 $this->new_theme
= isset($cgi_variables['new_theme']) ?
($cgi_variables['new_theme']) : '';
85 // Make this true for IPPF.
86 $this->ippf_specific
= false;
88 // Record name of sql access file
89 $GLOBALS['OE_SITES_BASE'] = dirname(__FILE__
) . '/../../sites';
90 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . '/' . $this->site
;
91 $this->conffile
= $GLOBALS['OE_SITE_DIR'] . '/sqlconf.php';
93 // Record names of sql table files
94 $this->main_sql
= dirname(__FILE__
) . '/../../sql/database.sql';
95 $this->translation_sql
= dirname(__FILE__
) . '/../../contrib/util/language_translations/currentLanguage_utf8.sql';
96 $this->devel_translation_sql
= "http://translations.openemr.io/languageTranslations_utf8.sql";
97 $this->ippf_sql
= dirname(__FILE__
) . "/../../sql/ippf_layout.sql";
98 $this->icd9
= dirname(__FILE__
) . "/../../sql/icd9.sql";
99 $this->cvx
= dirname(__FILE__
) . "/../../sql/cvx_codes.sql";
100 $this->additional_users
= dirname(__FILE__
) . "/../../sql/official_additional_users.sql";
102 // Prepare the dumpfile list
103 $this->initialize_dumpfile_list();
105 // Entities to hold error and debug messages
106 $this->error_message
= '';
107 $this->debug_message
= '';
109 // Entity to hold sql connection
113 public function login_is_valid()
115 if (($this->login
== '') ||
(! isset($this->login
))) {
116 $this->error_message
= "login is invalid: '$this->login'";
123 public function char_is_valid($input_text)
125 // to prevent php injection
127 if ($input_text == '') {
131 if (preg_match('@[\\\\;()<>/\'"]@', $input_text)) {
138 public function databaseNameIsValid($name)
140 if (preg_match('/[^A-Za-z0-9_-]/', $name)) {
146 public function collateNameIsValid($name)
148 if (preg_match('/[^A-Za-z0-9_-]/', $name)) {
154 public function iuser_is_valid()
156 if (strpos($this->iuser
, " ")) {
157 $this->error_message
= "Initial user is invalid: '$this->iuser'";
164 public function iuname_is_valid()
166 if ($this->iuname
== "" ||
!isset($this->iuname
)) {
167 $this->error_message
= "Initial user last name is invalid: '$this->iuname'";
174 public function password_is_valid()
176 if ($this->pass
== "" ||
!isset($this->pass
)) {
177 $this->error_message
= "The password for the new database account is invalid: '$this->pass'";
184 public function user_password_is_valid()
186 if ($this->iuserpass
== "" ||
!isset($this->iuserpass
)) {
187 $this->error_message
= "The password for the user is invalid: '$this->iuserpass'";
196 public function root_database_connection()
198 $this->dbh
= $this->connect_to_database($this->server
, $this->root
, $this->rootpass
, $this->port
);
200 if (!$this->set_sql_strict()) {
201 $this->error_message
= 'unable to set strict sql setting';
207 $this->error_message
= 'unable to connect to database as root';
212 public function user_database_connection()
214 $this->dbh
= $this->connect_to_database($this->server
, $this->login
, $this->pass
, $this->port
, $this->dbname
);
216 $this->error_message
= "unable to connect to database as user: '$this->login'";
220 if (! $this->set_sql_strict()) {
221 $this->error_message
= 'unable to set strict sql setting';
225 if (! $this->set_collation()) {
226 $this->error_message
= 'unable to set sql collation';
230 if (! mysqli_select_db($this->dbh
, $this->dbname
)) {
231 $this->error_message
= "unable to select database: '$this->dbname'";
238 public function create_database()
240 $sql = "create database " . $this->escapeDatabaseName($this->dbname
);
241 if (empty($this->collate
) ||
($this->collate
== 'utf8_general_ci')) {
242 $this->collate
= 'utf8mb4_general_ci';
244 $sql .= " character set utf8mb4 collate " . $this->escapeCollateName($this->collate
);
245 $this->set_collation();
247 return $this->execute_sql($sql);
250 public function drop_database()
252 $sql = "drop database if exists " . $this->escapeDatabaseName($this->dbname
);
253 return $this->execute_sql($sql);
256 public function create_database_user()
258 // First, check for database user in the mysql.user table (this works for all except mariadb 10.4+)
259 $checkUser = $this->execute_sql("SELECT user FROM mysql.user WHERE user = '" . $this->escapeSql($this->login
) . "' AND host = '" . $this->escapeSql($this->loginhost
) . "'", false);
260 if ($checkUser === false) {
261 // Above caused error, so is MariaDB 10.4+, and need to do below query instead in the mysql.global_priv table
262 $checkUser = $this->execute_sql("SELECT user FROM mysql.global_priv WHERE user = '" . $this->escapeSql($this->login
) . "' AND host = '" . $this->escapeSql($this->loginhost
) . "'");
265 if ($checkUser === false) {
266 // there was an error in the check database user query, so return false
268 } elseif ($checkUser->num_rows
> 0) {
269 // the mysql user already exists, so do not need to create the user, but need to set the password
270 // Note need to try two different methods, first is for newer mysql versions and second is for older mysql versions (if the first method fails)
271 $returnSql = $this->execute_sql("ALTER USER '" . $this->escapeSql($this->login
) . "'@'" . $this->escapeSql($this->loginhost
) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass
) . "'", false);
272 if ($returnSql === false) {
273 error_log("Using older mysql version method to set password for the mysql user");
274 $returnSql = $this->execute_sql("SET PASSWORD FOR '" . $this->escapeSql($this->login
) . "'@'" . $this->escapeSql($this->loginhost
) . "' = PASSWORD('" . $this->escapeSql($this->pass
) . "')");
278 // the mysql user does not yet exist, so create the user
279 if (getenv('FORCE_DATABASE_X509_CONNECT', true) == 1) {
280 // this use case is to allow enforcement of x509 database connection use in applicable docker and kubernetes auto installations
281 return $this->execute_sql("CREATE USER '" . $this->escapeSql($this->login
) . "'@'" . $this->escapeSql($this->loginhost
) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass
) . "' REQUIRE X509");
282 } elseif (getenv('FORCE_DATABASE_SSL_CONNECT', true) == 1) {
283 // this use case is to allow enforcement of ssl database connection use in applicable docker and kubernetes auto installations
284 return $this->execute_sql("CREATE USER '" . $this->escapeSql($this->login
) . "'@'" . $this->escapeSql($this->loginhost
) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass
) . "' REQUIRE SSL");
286 return $this->execute_sql("CREATE USER '" . $this->escapeSql($this->login
) . "'@'" . $this->escapeSql($this->loginhost
) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass
) . "'");
291 public function grant_privileges()
293 return $this->execute_sql("GRANT ALL PRIVILEGES ON " . $this->escapeDatabaseName($this->dbname
) . ".* TO '" . $this->escapeSql($this->login
) . "'@'" . $this->escapeSql($this->loginhost
) . "'");
296 public function disconnect()
298 return mysqli_close($this->dbh
);
302 * This method creates any dumpfiles necessary.
303 * This is actually only done if we're cloning an existing site
304 * and we need to dump their database into a file.
305 * @return bool indicating success
307 public function create_dumpfiles()
309 return $this->dumpSourceDatabase();
312 public function load_dumpfiles()
314 $sql_results = ''; // information string which is returned
315 foreach ($this->dumpfiles
as $filename => $title) {
316 $sql_results_temp = '';
317 $sql_results_temp = $this->load_file($filename, $title);
318 if ($sql_results_temp == false) {
322 $sql_results .= $sql_results_temp;
328 public function load_file($filename, $title)
330 $sql_results = ''; // information string which is returned
331 $sql_results .= "Creating $title tables...\n";
332 $fd = fopen($filename, 'r');
334 $this->error_message
= "ERROR. Could not open dumpfile '$filename'.\n";
341 // Settings to drastically speed up installation with InnoDB
342 if (! $this->execute_sql("SET autocommit=0;")) {
346 if (! $this->execute_sql("START TRANSACTION;")) {
351 $line = fgets($fd, 1024);
352 $line = rtrim($line);
353 if (substr($line, 0, 2) == "--") { // Kill comments
357 if (substr($line, 0, 1) == "#") { // Kill comments
365 $query = $query . $line; // Check for full query
366 $chr = substr($query, strlen($query) - 1, 1);
367 if ($chr == ";") { // valid query, execute
368 $query = rtrim($query, ";");
369 if (! $this->execute_sql($query)) {
377 // Settings to drastically speed up installation with InnoDB
378 if (! $this->execute_sql("COMMIT;")) {
382 if (! $this->execute_sql("SET autocommit=1;")) {
386 $sql_results .= "<span class='text-success'><b>OK</b></span>.<br>\n";
391 public function add_version_info()
393 include dirname(__FILE__
) . "/../../version.php";
394 if ($this->execute_sql("UPDATE version SET v_major = '" . $this->escapeSql($v_major) . "', v_minor = '" . $this->escapeSql($v_minor) . "', v_patch = '" . $this->escapeSql($v_patch) . "', v_realpatch = '" . $this->escapeSql($v_realpatch) . "', v_tag = '" . $this->escapeSql($v_tag) . "', v_database = '" . $this->escapeSql($v_database) . "', v_acl = '" . $this->escapeSql($v_acl) . "'") == false) {
395 $this->error_message
= "ERROR. Unable insert version information into database\n" .
396 "<p>" . mysqli_error($this->dbh
) . " (#" . mysqli_errno($this->dbh
) . ")\n";
403 public function add_initial_user()
405 if ($this->execute_sql("INSERT INTO `groups` (id, name, user) VALUES (1,'" . $this->escapeSql($this->igroup
) . "','" . $this->escapeSql($this->iuser
) . "')") == false) {
406 $this->error_message
= "ERROR. Unable to add initial user group\n" .
407 "<p>" . mysqli_error($this->dbh
) . " (#" . mysqli_errno($this->dbh
) . ")\n";
411 if ($this->execute_sql("INSERT INTO users (id, username, password, authorized, lname, fname, facility_id, calendar, cal_ui) VALUES (1,'" . $this->escapeSql($this->iuser
) . "','NoLongerUsed',1,'" . $this->escapeSql($this->iuname
) . "','" . $this->escapeSql($this->iufname
) . "',3,1,3)") == false) {
412 $this->error_message
= "ERROR. Unable to add initial user\n" .
413 "<p>" . mysqli_error($this->dbh
) . " (#" . mysqli_errno($this->dbh
) . ")\n";
417 $hash = password_hash($this->iuserpass
, PASSWORD_DEFAULT
);
419 // Something is seriously wrong
420 error_log('OpenEMR Error : OpenEMR is not working because unable to create a hash.');
421 die("OpenEMR Error : OpenEMR is not working because unable to create a hash.");
423 if ($this->execute_sql("INSERT INTO users_secure (id, username, password, last_update_password) VALUES (1,'" . $this->escapeSql($this->iuser
) . "','" . $this->escapeSql($hash) . "',NOW())") == false) {
424 $this->error_message
= "ERROR. Unable to add initial user login credentials\n" .
425 "<p>" . mysqli_error($this->dbh
) . " (#" . mysqli_errno($this->dbh
) . ")\n";
429 // Create new 2fa if enabled
430 if (($this->i2faEnable
) && (!empty($this->i2faSecret
)) && (class_exists('Totp')) && (class_exists('OpenEMR\Common\Crypto\CryptoGen'))) {
431 // Encrypt the new secret with the hashed password
432 $cryptoGen = new OpenEMR\Common\Crypto\
CryptoGen();
433 $secret = $cryptoGen->encryptStandard($this->i2faSecret
, $hash);
434 if ($this->execute_sql("INSERT INTO login_mfa_registrations (user_id, name, method, var1, var2) VALUES (1, 'App Based 2FA', 'TOTP', '" . $this->escapeSql($secret) . "', '')") == false) {
435 $this->error_message
= "ERROR. Unable to add initial user's 2FA credentials\n" .
436 "<p>" . mysqli_error($this->dbh
) . " (#" . mysqli_errno($this->dbh
) . ")\n";
445 * Handle the additional users now that our gacl's have finished installing.
448 public function install_additional_users()
450 // Add the official openemr users (services)
451 if ($this->load_file($this->additional_users
, "Additional Official Users") == false) {
457 public function on_care_coordination()
459 $resource = $this->execute_sql("SELECT `mod_id` FROM `modules` WHERE `mod_name` = 'Carecoordination' LIMIT 1");
460 $resource_array = mysqli_fetch_array($resource, MYSQLI_ASSOC
);
461 $modId = $resource_array['mod_id'];
463 $this->error_message
= "ERROR configuring Care Coordination module. Unable to get mod_id for Carecoordination module\n";
467 $resource = $this->execute_sql("SELECT `section_id` FROM `module_acl_sections` WHERE `section_identifier` = 'carecoordination' LIMIT 1");
468 $resource_array = mysqli_fetch_array($resource, MYSQLI_ASSOC
);
469 $sectionId = $resource_array['section_id'];
470 if (empty($sectionId)) {
471 $this->error_message
= "ERROR configuring Care Coordination module. Unable to get section_id for carecoordination module section\n";
475 $resource = $this->execute_sql("SELECT `id` FROM `gacl_aro_groups` WHERE `value` = 'admin' LIMIT 1");
476 $resource_array = mysqli_fetch_array($resource, MYSQLI_ASSOC
);
477 $groupId = $resource_array['id'];
478 if (empty($groupId)) {
479 $this->error_message
= "ERROR configuring Care Coordination module. Unable to get id for gacl_aro_groups admin section\n";
483 if ($this->execute_sql("INSERT INTO `module_acl_group_settings` (`module_id`, `group_id`, `section_id`, `allowed`) VALUES ('" . $this->escapeSql($modId) . "', '" . $this->escapeSql($groupId) . "', '" . $this->escapeSql($sectionId) . "', 1)") == false) {
484 $this->error_message
= "ERROR configuring Care Coordination module. Unable to add the module_acl_group_settings acl entry\n";
492 * Generates the initial user's 2FA QR Code
493 * @return bool|string|void
495 public function get_initial_user_2fa_qr()
497 if (($this->i2faEnable
) && (!empty($this->i2faSecret
)) && (class_exists('Totp'))) {
498 $adminTotp = new Totp($this->i2faSecret
, $this->iuser
);
499 $qr = $adminTotp->generateQrCode();
506 * Create site directory if it is missing.
507 * @global string $GLOBALS['OE_SITE_DIR'] contains the name of the site directory to create
508 * @return name of the site directory or False
510 public function create_site_directory()
512 if (!file_exists($GLOBALS['OE_SITE_DIR'])) {
513 $source_directory = $GLOBALS['OE_SITES_BASE'] . "/" . $this->source_site_id
;
514 $destination_directory = $GLOBALS['OE_SITE_DIR'];
515 if (! $this->recurse_copy($source_directory, $destination_directory)) {
516 $this->error_message
= "unable to copy directory: '$source_directory' to '$destination_directory'. " . $this->error_message
;
519 // the new site will create it's own keys so okay to delete these copied from the source site
520 if (!$this->clone_database
) {
521 array_map('unlink', glob($destination_directory . "/documents/logs_and_misc/methods/*"));
528 public function write_configuration_file()
530 if (!file_exists($GLOBALS['OE_SITE_DIR'])) {
531 $this->create_site_directory();
533 @touch
($this->conffile
); // php bug
534 $fd = @fopen
($this->conffile
, 'w');
536 $this->error_message
= 'unable to open configuration file for writing: ' . $this->conffile
;
546 $it_died = 0; //fmg: variable keeps running track of any errors
548 fwrite($fd, $string) or $it_died++
;
549 fwrite($fd, "global \$disable_utf8_flag;\n") or $it_died++
;
550 fwrite($fd, "\$disable_utf8_flag = false;\n\n") or $it_died++
;
551 fwrite($fd, "\$host\t= '$this->server';\n") or $it_died++
;
552 fwrite($fd, "\$port\t= '$this->port';\n") or $it_died++
;
553 fwrite($fd, "\$login\t= '$this->login';\n") or $it_died++
;
554 fwrite($fd, "\$pass\t= '$this->pass';\n") or $it_died++
;
555 fwrite($fd, "\$dbase\t= '$this->dbname';\n") or $it_died++
;
556 fwrite($fd, "\$db_encoding\t= 'utf8mb4';\n") or $it_died++
;
561 $sqlconf["host"]= $host;
562 $sqlconf["port"] = $port;
563 $sqlconf["login"] = $login;
564 $sqlconf["pass"] = $pass;
565 $sqlconf["dbase"] = $dbase;
566 $sqlconf["db_encoding"] = $db_encoding;
568 //////////////////////////
569 //////////////////////////
570 //////////////////////////
571 //////DO NOT TOUCH THIS///
572 $config = 1; /////////////
573 //////////////////////////
574 //////////////////////////
575 //////////////////////////
579 fwrite($fd, $string) or $it_died++
;
580 fclose($fd) or $it_died++
;
582 //it's rather irresponsible to not report errors when writing this file.
584 $this->error_message
= "ERROR. Couldn't write $it_died lines to config file '$this->conffile'.\n";
588 // Tell PHP that its cached bytecode version of sqlconf.php is no longer usable.
589 if (function_exists('opcache_invalidate')) {
590 opcache_invalidate($this->conffile
, true);
596 public function insert_globals()
598 if (!(function_exists('xl'))) {
604 $GLOBALS['temp_skip_translations'] = true;
606 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
607 require(dirname(__FILE__
) . '/../globals.inc.php');
608 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
609 foreach ($grparr as $fldid => $fldarr) {
610 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
611 if (is_array($fldtype) ||
substr($fldtype, 0, 2) !== 'm_') {
612 $res = $this->execute_sql("SELECT count(*) AS count FROM globals WHERE gl_name = '" . $this->escapeSql($fldid) . "'");
613 $row = mysqli_fetch_array($res, MYSQLI_ASSOC
);
614 if (empty($row['count'])) {
615 $this->execute_sql("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
616 "VALUES ( '" . $this->escapeSql($fldid) . "', '0', '" . $this->escapeSql($flddef) . "' )");
625 public function install_gacl()
628 $gacl = new GaclApi();
630 // Create the ACO sections. Every ACO must have a section.
632 if ($gacl->add_object_section('Accounting', 'acct', 10, 0, 'ACO') === false) {
633 $this->error_message
= "ERROR, Unable to create the access controls for OpenEMR.";
637 $gacl->add_object_section('Administration', 'admin', 10, 0, 'ACO');
638 // xl('Administration')
639 $gacl->add_object_section('Encounters', 'encounters', 10, 0, 'ACO');
641 $gacl->add_object_section('Lists', 'lists', 10, 0, 'ACO');
643 $gacl->add_object_section('Patients', 'patients', 10, 0, 'ACO');
645 $gacl->add_object_section('Squads', 'squads', 10, 0, 'ACO');
647 $gacl->add_object_section('Sensitivities', 'sensitivities', 10, 0, 'ACO');
648 // xl('Sensitivities')
649 $gacl->add_object_section('Placeholder', 'placeholder', 10, 0, 'ACO');
651 $gacl->add_object_section('Nation Notes', 'nationnotes', 10, 0, 'ACO');
652 // xl('Nation Notes')
653 $gacl->add_object_section('Patient Portal', 'patientportal', 10, 0, 'ACO');
654 // xl('Patient Portal')
655 $gacl->add_object_section('Menus', 'menus', 10, 0, 'ACO');
657 $gacl->add_object_section('Groups', 'groups', 10, 0, 'ACO');
659 $gacl->add_object_section('Inventory', 'inventory', 10, 0, 'ACO');
662 // Create Accounting ACOs.
664 $gacl->add_object('acct', 'Billing (write optional)', 'bill', 10, 0, 'ACO');
665 // xl('Billing (write optional)')
666 $gacl->add_object('acct', 'Price Discounting', 'disc', 10, 0, 'ACO');
667 // xl('Price Discounting')
668 $gacl->add_object('acct', 'EOB Data Entry', 'eob', 10, 0, 'ACO');
669 // xl('EOB Data Entry')
670 $gacl->add_object('acct', 'Financial Reporting - my encounters', 'rep', 10, 0, 'ACO');
671 // xl('Financial Reporting - my encounters')
672 $gacl->add_object('acct', 'Financial Reporting - anything', 'rep_a', 10, 0, 'ACO');
673 // xl('Financial Reporting - anything')
675 // Create Administration ACOs.
677 $gacl->add_object('admin', 'Superuser', 'super', 10, 0, 'ACO');
679 $gacl->add_object('admin', 'Calendar Settings', 'calendar', 10, 0, 'ACO');
680 // xl('Calendar Settings')
681 $gacl->add_object('admin', 'Database Reporting', 'database', 10, 0, 'ACO');
682 // xl('Database Reporting')
683 $gacl->add_object('admin', 'Forms Administration', 'forms', 10, 0, 'ACO');
684 // xl('Forms Administration')
685 $gacl->add_object('admin', 'Practice Settings', 'practice', 10, 0, 'ACO');
686 // xl('Practice Settings')
687 $gacl->add_object('admin', 'Superbill Codes Administration', 'superbill', 10, 0, 'ACO');
688 // xl('Superbill Codes Administration')
689 $gacl->add_object('admin', 'Users/Groups/Logs Administration', 'users', 10, 0, 'ACO');
690 // xl('Users/Groups/Logs Administration')
691 $gacl->add_object('admin', 'Batch Communication Tool', 'batchcom', 10, 0, 'ACO');
692 // xl('Batch Communication Tool')
693 $gacl->add_object('admin', 'Language Interface Tool', 'language', 10, 0, 'ACO');
694 // xl('Language Interface Tool')
695 $gacl->add_object('admin', 'Inventory Administration', 'drugs', 10, 0, 'ACO');
696 // xl('Inventory Administration')
697 $gacl->add_object('admin', 'ACL Administration', 'acl', 10, 0, 'ACO');
698 // xl('ACL Administration')
699 $gacl->add_object('admin', 'Multipledb', 'multipledb', 10, 0, 'ACO');
701 $gacl->add_object('admin', 'Menu', 'menu', 10, 0, 'ACO');
703 $gacl->add_object('admin', 'Manage modules', 'manage_modules', 10, 0, 'ACO');
704 // xl('Manage modules')
707 // Create ACOs for encounters.
709 $gacl->add_object('encounters', 'Authorize - my encounters', 'auth', 10, 0, 'ACO');
710 // xl('Authorize - my encounters')
711 $gacl->add_object('encounters', 'Authorize - any encounters', 'auth_a', 10, 0, 'ACO');
712 // xl('Authorize - any encounters')
713 $gacl->add_object('encounters', 'Coding - my encounters (write,wsome optional)', 'coding', 10, 0, 'ACO');
714 // xl('Coding - my encounters (write,wsome optional)')
715 $gacl->add_object('encounters', 'Coding - any encounters (write,wsome optional)', 'coding_a', 10, 0, 'ACO');
716 // xl('Coding - any encounters (write,wsome optional)')
717 $gacl->add_object('encounters', 'Notes - my encounters (write,addonly optional)', 'notes', 10, 0, 'ACO');
718 // xl('Notes - my encounters (write,addonly optional)')
719 $gacl->add_object('encounters', 'Notes - any encounters (write,addonly optional)', 'notes_a', 10, 0, 'ACO');
720 // xl('Notes - any encounters (write,addonly optional)')
721 $gacl->add_object('encounters', 'Fix encounter dates - any encounters', 'date_a', 10, 0, 'ACO');
722 // xl('Fix encounter dates - any encounters')
723 $gacl->add_object('encounters', 'Less-private information (write,addonly optional)', 'relaxed', 10, 0, 'ACO');
724 // xl('Less-private information (write,addonly optional)')
726 // Create ACOs for lists.
728 $gacl->add_object('lists', 'Default List (write,addonly optional)', 'default', 10, 0, 'ACO');
729 // xl('Default List (write,addonly optional)')
730 $gacl->add_object('lists', 'State List (write,addonly optional)', 'state', 10, 0, 'ACO');
731 // xl('State List (write,addonly optional)')
732 $gacl->add_object('lists', 'Country List (write,addonly optional)', 'country', 10, 0, 'ACO');
733 // xl('Country List (write,addonly optional)')
734 $gacl->add_object('lists', 'Language List (write,addonly optional)', 'language', 10, 0, 'ACO');
735 // xl('Language List (write,addonly optional)')
736 $gacl->add_object('lists', 'Ethnicity-Race List (write,addonly optional)', 'ethrace', 10, 0, 'ACO');
737 // xl('Ethnicity-Race List (write,addonly optional)')
739 // Create ACOs for patientportal.
741 $gacl->add_object('patientportal', 'Patient Portal', 'portal', 10, 0, 'ACO');
742 // xl('Patient Portal')
744 // Create ACOs for modules.
746 $gacl->add_object('menus', 'Modules', 'modle', 10, 0, 'ACO');
749 // Create ACOs for patients.
751 $gacl->add_object('patients', 'Appointments (write,wsome optional)', 'appt', 10, 0, 'ACO');
752 // xl('Appointments (write,wsome optional)')
753 $gacl->add_object('patients', 'Demographics (write,addonly optional)', 'demo', 10, 0, 'ACO');
754 // xl('Demographics (write,addonly optional)')
755 $gacl->add_object('patients', 'Medical/History (write,addonly optional)', 'med', 10, 0, 'ACO');
756 // xl('Medical/History (write,addonly optional)')
757 $gacl->add_object('patients', 'Transactions (write optional)', 'trans', 10, 0, 'ACO');
758 // xl('Transactions (write optional)')
759 $gacl->add_object('patients', 'Documents (write,addonly optional)', 'docs', 10, 0, 'ACO');
760 // xl('Documents (write,addonly optional)')
761 $gacl->add_object('patients', 'Documents Delete', 'docs_rm', 10, 0, 'ACO');
762 // xl('Documents Delete')
763 $gacl->add_object('patients', 'Patient Notes (write,addonly optional)', 'notes', 10, 0, 'ACO');
764 // xl('Patient Notes (write,addonly optional)')
765 $gacl->add_object('patients', 'Sign Lab Results (write,addonly optional)', 'sign', 10, 0, 'ACO');
766 // xl('Sign Lab Results (write,addonly optional)')
767 $gacl->add_object('patients', 'Patient Reminders (write,addonly optional)', 'reminder', 10, 0, 'ACO');
768 // xl('Patient Reminders (write,addonly optional)')
769 $gacl->add_object('patients', 'Clinical Reminders/Alerts (write,addonly optional)', 'alert', 10, 0, 'ACO');
770 // xl('Clinical Reminders/Alerts (write,addonly optional)')
771 $gacl->add_object('patients', 'Disclosures (write,addonly optional)', 'disclosure', 10, 0, 'ACO');
772 // xl('Disclosures (write,addonly optional)')
773 $gacl->add_object('patients', 'Prescriptions (write,addonly optional)', 'rx', 10, 0, 'ACO');
774 // xl('Prescriptions (write,addonly optional)')
775 $gacl->add_object('patients', 'Amendments (write,addonly optional)', 'amendment', 10, 0, 'ACO');
776 // xl('Amendments (write,addonly optional)')
777 $gacl->add_object('patients', 'Lab Results (write,addonly optional)', 'lab', 10, 0, 'ACO');
778 // xl('Lab Results (write,addonly optional)')
779 $gacl->add_object('patients', 'Patient Report', 'pat_rep', 10, 0, 'ACO');
780 // xl('Patient Report')
783 $gacl->add_object('groups', 'View/Add/Update groups', 'gadd', 10, 0, 'ACO');
784 // xl('View/Add/Update groups')
785 $gacl->add_object('groups', 'View/Create/Update groups appointment in calendar', 'gcalendar', 10, 0, 'ACO');
786 // xl('View/Create/Update groups appointment in calendar')
787 $gacl->add_object('groups', 'Group encounter log', 'glog', 10, 0, 'ACO');
788 // xl('Group encounter log')
789 $gacl->add_object('groups', 'Group detailed log of appointment in patient record', 'gdlog', 10, 0, 'ACO');
790 // xl('Group detailed log of appointment in patient record')
791 $gacl->add_object('groups', 'Send message from the permanent group therapist to the personal therapist', 'gm', 10, 0, 'ACO');
792 // xl('Send message from the permanent group therapist to the personal therapist')
794 // Create ACOs for sensitivities.
796 $gacl->add_object('sensitivities', 'Normal', 'normal', 10, 0, 'ACO');
798 $gacl->add_object('sensitivities', 'High', 'high', 20, 0, 'ACO');
801 // Create ACO for placeholder.
803 $gacl->add_object('placeholder', 'Placeholder (Maintains empty ACLs)', 'filler', 10, 0, 'ACO');
804 // xl('Placeholder (Maintains empty ACLs)')
806 // Create ACO for nationnotes.
808 $gacl->add_object('nationnotes', 'Nation Notes Configure', 'nn_configure', 10, 0, 'ACO');
809 // xl('Nation Notes Configure')
811 // Create ACOs for Inventory.
813 $gacl->add_object('inventory', 'Lots', 'lots', 10, 0, 'ACO');
815 $gacl->add_object('inventory', 'Sales', 'sales', 20, 0, 'ACO');
817 $gacl->add_object('inventory', 'Purchases', 'purchases', 30, 0, 'ACO');
819 $gacl->add_object('inventory', 'Transfers', 'transfers', 40, 0, 'ACO');
821 $gacl->add_object('inventory', 'Adjustments', 'adjustments', 50, 0, 'ACO');
823 $gacl->add_object('inventory', 'Consumption', 'consumption', 60, 0, 'ACO');
825 $gacl->add_object('inventory', 'Destruction', 'destruction', 70, 0, 'ACO');
827 $gacl->add_object('inventory', 'Reporting', 'reporting', 80, 0, 'ACO');
830 // Create ARO groups.
832 $users = $gacl->add_group('users', 'OpenEMR Users', 0, 'ARO');
833 // xl('OpenEMR Users')
834 $admin = $gacl->add_group('admin', 'Administrators', $users, 'ARO');
835 // xl('Administrators')
836 $clin = $gacl->add_group('clin', 'Clinicians', $users, 'ARO');
838 $doc = $gacl->add_group('doc', 'Physicians', $users, 'ARO');
840 $front = $gacl->add_group('front', 'Front Office', $users, 'ARO');
841 // xl('Front Office')
842 $back = $gacl->add_group('back', 'Accounting', $users, 'ARO');
844 $breakglass = $gacl->add_group('breakglass', 'Emergency Login', $users, 'ARO');
845 // xl('Emergency Login')
848 // Create a Users section for the AROs (humans).
850 $gacl->add_object_section('Users', 'users', 10, 0, 'ARO');
853 // Create the Administrator in the above-created "users" section
854 // and add him/her to the above-created "admin" group.
855 // If this script is being used by OpenEMR's setup, then will
856 // incorporate the installation values. Otherwise will
857 // hardcode the 'admin' user.
858 if (isset($this) && isset($this->iuser
)) {
859 $gacl->add_object('users', $this->iuname
, $this->iuser
, 10, 0, 'ARO');
860 $gacl->add_group_object($admin, 'users', $this->iuser
, 'ARO');
862 $gacl->add_object('users', 'Administrator', 'admin', 10, 0, 'ARO');
863 $gacl->add_group_object($admin, 'users', 'admin', 'ARO');
866 // Declare return terms for language translations
867 // xl('write') xl('wsome') xl('addonly') xl('view')
869 // Set permissions for administrators.
873 'acct' => array('bill', 'disc', 'eob', 'rep', 'rep_a'),
874 'admin' => array('calendar', 'database', 'forms', 'practice', 'superbill', 'users', 'batchcom', 'language', 'super', 'drugs', 'acl','multipledb','menu','manage_modules'),
875 'encounters' => array('auth_a', 'auth', 'coding_a', 'coding', 'notes_a', 'notes', 'date_a', 'relaxed'),
876 'inventory' => array('lots', 'sales', 'purchases', 'transfers', 'adjustments', 'consumption', 'destruction', 'reporting'),
877 'lists' => array('default','state','country','language','ethrace'),
878 'patients' => array('appt', 'demo', 'med', 'trans', 'docs', 'notes', 'sign', 'reminder', 'alert', 'disclosure', 'rx', 'amendment', 'lab', 'docs_rm','pat_rep'),
879 'sensitivities' => array('normal', 'high'),
880 'nationnotes' => array('nn_configure'),
881 'patientportal' => array('portal'),
882 'menus' => array('modle'),
883 'groups' => array('gadd','gcalendar','glog','gdlog','gm')
892 'Administrators can do anything'
894 // xl('Administrators can do anything')
896 // Set permissions for physicians.
900 'patients' => array('pat_rep')
909 'Things that physicians can only read'
911 // xl('Things that physicians can only read')
914 'placeholder' => array('filler')
923 'Things that physicians can read and enter but not modify'
925 // xl('Things that physicians can read and enter but not modify')
928 'placeholder' => array('filler')
937 'Things that physicians can read and partly modify'
939 // xl('Things that physicians can read and partly modify')
942 'acct' => array('disc', 'rep'),
943 'admin' => array('drugs'),
944 'encounters' => array('auth_a', 'auth', 'coding_a', 'coding', 'notes_a', 'notes', 'date_a', 'relaxed'),
945 'patients' => array('appt', 'demo', 'med', 'trans', 'docs', 'notes', 'sign', 'reminder', 'alert',
946 'disclosure', 'rx', 'amendment', 'lab'),
947 'sensitivities' => array('normal', 'high'),
948 'groups' => array('gcalendar','glog')
957 'Things that physicians can read and modify'
959 // xl('Things that physicians can read and modify')
961 // Set permissions for clinicians.
965 'patients' => array('pat_rep')
974 'Things that clinicians can only read'
976 // xl('Things that clinicians can only read')
979 'encounters' => array('notes', 'relaxed'),
980 'patients' => array('demo', 'med', 'docs', 'notes','trans', 'reminder', 'alert', 'disclosure', 'rx', 'amendment', 'lab'),
981 'sensitivities' => array('normal')
990 'Things that clinicians can read and enter but not modify'
992 // xl('Things that clinicians can read and enter but not modify')
995 'placeholder' => array('filler')
1004 'Things that clinicians can read and partly modify'
1006 // xl('Things that clinicians can read and partly modify')
1009 'admin' => array('drugs'),
1010 'encounters' => array('auth', 'coding', 'notes'),
1011 'patients' => array('appt'),
1012 'groups' => array('gcalendar', 'glog')
1021 'Things that clinicians can read and modify'
1023 // xl('Things that clinicians can read and modify')
1025 // Set permissions for front office staff.
1029 'patients' => array('alert')
1038 'Things that front office can only read'
1040 // xl('Things that front office can only read')
1043 'placeholder' => array('filler')
1052 'Things that front office can read and enter but not modify'
1054 // xl('Things that front office can read and enter but not modify')
1057 'placeholder' => array('filler')
1066 'Things that front office can read and partly modify'
1068 // xl('Things that front office can read and partly modify')
1071 'patients' => array('appt', 'demo'),
1072 'groups' => array('gcalendar')
1081 'Things that front office can read and modify'
1083 // xl('Things that front office can read and modify')
1085 // Set permissions for back office staff.
1089 'patients' => array('alert')
1098 'Things that back office can only read'
1100 // xl('Things that back office can only read')
1103 'placeholder' => array('filler')
1112 'Things that back office can read and enter but not modify'
1114 // xl('Things that back office can read and enter but not modify')
1117 'placeholder' => array('filler')
1126 'Things that back office can read and partly modify'
1128 // xl('Things that back office can read and partly modify')
1131 'acct' => array('bill', 'disc', 'eob', 'rep', 'rep_a'),
1132 'admin' => array('practice', 'superbill'),
1133 'encounters' => array('auth_a', 'coding_a', 'date_a'),
1134 'patients' => array('appt', 'demo')
1143 'Things that back office can read and modify'
1145 // xl('Things that back office can read and modify')
1147 // Set permissions for Emergency Login.
1151 'acct' => array('bill', 'disc', 'eob', 'rep', 'rep_a'),
1152 'admin' => array('calendar', 'database', 'forms', 'practice', 'superbill', 'users', 'batchcom', 'language', 'super', 'drugs', 'acl','multipledb','menu','manage_modules'),
1153 'encounters' => array('auth_a', 'auth', 'coding_a', 'coding', 'notes_a', 'notes', 'date_a', 'relaxed'),
1154 'inventory' => array('lots', 'sales', 'purchases', 'transfers', 'adjustments', 'consumption', 'destruction', 'reporting'),
1155 'lists' => array('default','state','country','language','ethrace'),
1156 'patients' => array('appt', 'demo', 'med', 'trans', 'docs', 'notes', 'sign', 'reminder', 'alert', 'disclosure', 'rx', 'amendment', 'lab', 'docs_rm','pat_rep'),
1157 'sensitivities' => array('normal', 'high'),
1158 'nationnotes' => array('nn_configure'),
1159 'patientportal' => array('portal'),
1160 'menus' => array('modle'),
1161 'groups' => array('gadd','gcalendar','glog','gdlog','gm')
1170 'Emergency Login user can do anything'
1172 // xl('Emergency Login user can do anything')
1177 public function quick_install()
1179 // Validation of OpenEMR user settings
1180 // (applicable if not cloning from another database)
1181 if (empty($this->clone_database
)) {
1182 if (! $this->login_is_valid()) {
1186 if (! $this->iuser_is_valid()) {
1190 if (! $this->user_password_is_valid()) {
1195 // Validation of mysql database password
1196 if (! $this->password_is_valid()) {
1200 if (! $this->no_root_db_access
) {
1201 // Connect to mysql via root user
1202 if (! $this->root_database_connection()) {
1206 // Create the dumpfile
1207 // (applicable if cloning from another database)
1208 if (! empty($this->clone_database
)) {
1209 if (! $this->create_dumpfiles()) {
1214 // Create the site directory
1215 // (applicable if mirroring another local site)
1216 if (! empty($this->source_site_id
)) {
1217 if (! $this->create_site_directory()) {
1222 $this->disconnect();
1223 // Using @ in below call to hide the php warning in cases where the
1224 // below connection does not work, which is expected behavior.
1225 // Using try in below call to catch the mysqli exception when the
1226 // below connection does not work, which is expected behavior (needed to
1227 // add this try/catch clause for PHP 8.1).
1229 $checkUserDatabaseConnection = @$this->user_database_connection();
1230 } catch (Exception
$e) {
1231 $checkUserDatabaseConnection = false;
1233 if (! $checkUserDatabaseConnection) {
1234 // Re-connect to mysql via root user
1235 if (! $this->root_database_connection()) {
1239 // Create the mysql database
1240 if (! $this->create_database()) {
1244 // Create the mysql user
1245 if (! $this->create_database_user()) {
1249 // Grant user privileges to the mysql database
1250 if (! $this->grant_privileges()) {
1255 $this->disconnect();
1258 // Connect to mysql via created user
1259 if (! $this->user_database_connection()) {
1263 // Build the database
1264 if (! $this->load_dumpfiles()) {
1268 // Write the sql configuration file
1269 if (! $this->write_configuration_file()) {
1273 // Load the version information, globals settings,
1274 // initial user, and set up gacl access controls.
1275 // (applicable if not cloning from another database)
1276 if (empty($this->clone_database
)) {
1277 if (! $this->add_version_info()) {
1281 if (! $this->insert_globals()) {
1285 if (! $this->add_initial_user()) {
1289 if (! $this->install_gacl()) {
1293 if (! $this->install_additional_users()) {
1297 if (! $this->on_care_coordination()) {
1305 private function escapeSql($sql)
1307 return mysqli_real_escape_string($this->dbh
, $sql);
1310 private function escapeDatabaseName($name)
1312 if (preg_match('/[^A-Za-z0-9_-]/', $name)) {
1313 error_log("Illegal character(s) in database name");
1314 die("Illegal character(s) in database name");
1319 private function escapeCollateName($name)
1321 if (preg_match('/[^A-Za-z0-9_-]/', $name)) {
1322 error_log("Illegal character(s) in collation name");
1323 die("Illegal character(s) in collation name");
1328 private function execute_sql($sql, $showError = true)
1330 $this->error_message
= '';
1332 $this->user_database_connection();
1335 $results = mysqli_query($this->dbh
, $sql);
1340 $error_mes = mysqli_error($this->dbh
);
1341 $this->error_message
= "unable to execute SQL: '$sql' due to: " . $error_mes;
1342 error_log("ERROR IN OPENEMR INSTALL: Unable to execute SQL: " . htmlspecialchars($sql, ENT_QUOTES
) . " due to: " . htmlspecialchars($error_mes, ENT_QUOTES
));
1348 private function connect_to_database($server, $user, $password, $port, $dbname = '')
1350 $pathToCerts = __DIR__
. "/../../sites/" . $this->site
. "/documents/certificates/";
1352 $mysqli = mysqli_init();
1353 if (defined('MYSQLI_CLIENT_SSL') && file_exists($pathToCerts . "mysql-ca")) {
1356 file_exists($pathToCerts . "mysql-key") &&
1357 file_exists($pathToCerts . "mysql-cert")
1359 // with client side certificate/key
1362 $pathToCerts . "mysql-key",
1363 $pathToCerts . "mysql-cert",
1364 $pathToCerts . "mysql-ca",
1369 // without client side certificate/key
1374 $pathToCerts . "mysql-ca",
1382 $ok = mysqli_real_connect($mysqli, $server, $user, $password, $dbname, (int)$port != 0 ?
(int)$port : 3306, '', MYSQLI_CLIENT_SSL
);
1384 $ok = mysqli_real_connect($mysqli, $server, $user, $password, $dbname, (int)$port != 0 ?
(int)$port : 3306);
1386 } catch (mysqli_sql_exception
$e) {
1387 $this->error_message
= "unable to connect to sql server because of mysql error: " . $e->getMessage();
1391 $this->error_message
= 'unable to connect to sql server because of: (' . mysqli_connect_errno() . ') ' . mysqli_connect_error();
1397 private function set_sql_strict()
1399 // Turn off STRICT SQL
1400 return $this->execute_sql("SET sql_mode = ''");
1403 private function set_collation()
1405 return $this->execute_sql("SET NAMES 'utf8mb4'");
1409 * innitialize $this->dumpfiles, an array of the dumpfiles that will
1410 * be loaded into the database, including the correct translation
1412 * The keys are the paths of the dumpfiles, and the values are the titles
1415 private function initialize_dumpfile_list()
1417 if ($this->clone_database
) {
1418 $this->dumpfiles
= array( $this->get_backup_filename() => 'clone database' );
1420 $dumpfiles = array( $this->main_sql
=> 'Main' );
1421 if (! empty($this->development_translations
)) {
1422 // Use the online development translation set
1423 $dumpfiles[ $this->devel_translation_sql
] = "Online Development Language Translations (utf8)";
1425 // Use the local translation set
1426 $dumpfiles[ $this->translation_sql
] = "Language Translation (utf8)";
1429 if ($this->ippf_specific
) {
1430 $dumpfiles[ $this->ippf_sql
] = "IPPF Layout";
1433 // Load ICD-9 codes if present.
1434 if (file_exists($this->icd9
)) {
1435 $dumpfiles[ $this->icd9
] = "ICD-9";
1438 // Load CVX codes if present
1439 if (file_exists($this->cvx
)) {
1440 $dumpfiles[ $this->cvx
] = "CVX Immunization Codes";
1443 $this->dumpfiles
= $dumpfiles;
1446 return $this->dumpfiles
;
1451 * Directory copy logic borrowed from a user comment at
1452 * http://www.php.net/manual/en/function.copy.php
1453 * @param string $src name of the directory to copy
1454 * @param string $dst name of the destination to copy to
1455 * @return bool indicating success
1457 private function recurse_copy($src, $dst)
1459 $dir = opendir($src);
1460 if (! @mkdir
($dst)) {
1461 $this->error_message
= "unable to create directory: '$dst'";
1465 while (false !== ($file = readdir($dir))) {
1466 if ($file != '.' && $file != '..') {
1467 if (is_dir($src . '/' . $file)) {
1468 $this->recurse_copy($src . '/' . $file, $dst . '/' . $file);
1470 copy($src . '/' . $file, $dst . '/' . $file);
1481 * dump a site's database to a temporary file.
1482 * @param string $source_site_id the site_id of the site to dump
1483 * @return filename of the backup
1485 private function dumpSourceDatabase()
1487 global $OE_SITES_BASE;
1488 $source_site_id = $this->source_site_id
;
1490 include("$OE_SITES_BASE/$source_site_id/sqlconf.php");
1492 if (empty($config)) {
1493 die("Source site $source_site_id has not been set up!");
1496 $backup_file = $this->get_backup_filename();
1497 $cmd = "mysqldump -u " . escapeshellarg($login) .
1499 " -p" . escapeshellarg($pass) .
1500 " --ignore-table=" . escapeshellarg($dbase . ".onsite_activity_view") . " --hex-blob --opt --skip-extended-insert --quote-names -r $backup_file " .
1501 escapeshellarg($dbase);
1504 $tmp0 = exec($cmd, $tmp1, $tmp2);
1506 die("Error $tmp2 running \"$cmd\": $tmp0 " . implode(' ', $tmp1));
1509 return $backup_file;
1513 * @return filename of the source backup database for cloning
1515 private function get_backup_filename()
1517 if (stristr(PHP_OS
, 'WIN')) {
1518 $backup_file = 'C:/windows/temp/setup_dump.sql';
1520 $backup_file = '/tmp/setup_dump.sql';
1523 return $backup_file;
1526 public function getCurrentTheme()
1528 $current_theme = $this->execute_sql("SELECT gl_value FROM globals WHERE gl_name LIKE '%css_header%'");
1529 $current_theme = mysqli_fetch_array($current_theme);
1530 return $current_theme[0];
1533 public function setCurrentTheme()
1535 $current_theme = $this->getCurrentTheme();
1536 // for cloned sites since they're not asked about a new theme
1537 if (!$this->new_theme
) {
1538 $this->new_theme
= $current_theme;
1540 return $this->execute_sql("UPDATE globals SET gl_value='" . $this->escapeSql($this->new_theme
) . "' WHERE gl_name LIKE '%css_header%'");
1543 public function listThemes()
1545 $themes_img_dir = "public/images/stylesheets/";
1546 $arr_themes_img = array_values(array_filter(scandir($themes_img_dir), function ($item) {
1547 return $item[0] !== '.';
1549 return $arr_themes_img;
1552 private function extractFileName($theme_file_name = '')
1554 $this->theme_file_name
= $theme_file_name;
1555 $under_score = strpos($theme_file_name, '_') +
1;
1556 $dot = strpos($theme_file_name, '.');
1557 $theme_value = substr($theme_file_name, $under_score, ($dot - $under_score));
1558 $theme_title = ucwords(str_replace("_", " ", $theme_value));
1559 return array('theme_value' => $theme_value, 'theme_title' => $theme_title);
1562 public function displayThemesDivs()
1564 $themes_number = count($this->listThemes());
1565 for ($i = 0; $i < $themes_number; $i++
) {
1567 $arr_theme_name = $this->listThemes();
1568 $theme_file_name = $arr_theme_name[$i];
1569 $arr_extracted_file_name = $this->extractFileName($theme_file_name);
1570 $theme_value = $arr_extracted_file_name['theme_value'];
1571 $theme_title = $arr_extracted_file_name['theme_title'];
1572 $img_path = "public/images/stylesheets/";
1573 $theme_file_path = $img_path . $theme_file_name;
1574 $div_start = " <div class='row'>";
1575 $div_end = " </div>";
1576 $img_div = " <div class='col-sm-2 checkboxgroup'>
1577 <label for='my_radio_button_id" . attr($id) . "'><img height='160px' src='" . attr($theme_file_path) . "' width='100%'></label>
1578 <p class='m-0'>" . text($theme_title) . "</p><input id='my_radio_button_id" . attr($id) . "' name='stylesheet' type='radio' value='" . attr($theme_value) . "'>
1580 $theme_img_number = $i %
6; //to ensure that last file in array will always generate 5 and will end the row
1581 switch ($theme_img_number) {
1583 echo $div_start . "\r\n";
1584 echo $img_div . "\r\n";
1591 echo $img_div . "\r\n";
1595 echo $img_div . "\r\n";
1596 echo $div_end . "\r\n";
1597 echo "<br />" . "\r\n";
1601 echo $div_start . "\r\n";
1602 echo "<h5>Sorry no stylesheet images in directory</h5>";
1603 echo $div_end . "\r\n";
1610 public function displaySelectedThemeDiv()
1612 $theme_file_name = $this->getCurrentTheme();
1613 $arr_extracted_file_name = $this->extractFileName($theme_file_name);
1614 $theme_value = $arr_extracted_file_name['theme_value'];
1615 $theme_title = $arr_extracted_file_name['theme_title'];
1616 $img_path = "public/images/stylesheets/";
1617 $theme_file_path = $img_path . "style_" . $theme_value . ".png";
1619 $display_selected_theme_div = <<<DSTD
1621 <div class="col-sm-12">
1622 <h4>Current Theme:</h4>
1623 <div class="col-sm-4 offset-sm-4 checkboxgroup">
1624 <label for="nothing"><img id="current_theme" src="{$theme_file_path}" width="100%"></label>
1625 <p id="current_theme_title"style="margin:0">{$theme_title}</p>
1631 echo $display_selected_theme_div . "\r\n";
1635 public function displayNewThemeDiv()
1637 // cloned sites don't get a chance to set a new theme
1638 if (!$this->new_theme
) {
1639 $this->new_theme
= $this->getCurrentTheme();
1641 $theme_file_name = $this->new_theme
;
1642 $arr_extracted_file_name = $this->extractFileName($theme_file_name);
1643 $theme_value = $arr_extracted_file_name['theme_value'];
1644 $theme_title = $arr_extracted_file_name['theme_title'];
1645 $img_path = "public/images/stylesheets/";
1646 $theme_file_path = $img_path . "style_" . $theme_value . ".png";
1648 $display_selected_theme_div = <<<DSTD
1650 <div class="col-sm-12">
1651 <div class="col-sm-4 offset-sm-4 checkboxgroup">
1652 <label for="nothing"><img id="current_theme" src="{$theme_file_path}" width="75%"></label>
1653 <p id="current_theme_title"style="margin:0">{$theme_title}</p>
1659 echo $display_selected_theme_div . "\r\n";
1663 public function setupHelpModal()
1665 $setup_help_modal = <<<SETHLP
1667 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
1668 <div class="modal-dialog modal-lg">
1669 <div class="modal-content oe-modal-content" style="height:700px">
1670 <div class="modal-header clearfix">
1671 <button type="button" class="close" data-dismiss="modal" aria-label=Close>
1672 <span aria-hidden="true" style="color:var(--black); font-size:1.5em;">×</span></button>
1674 <div class="modal-body" style="height:80%;">
1675 <iframe src="" id="targetiframe" style="height:100%; width:100%; overflow-x: hidden; border:none"
1676 allowtransparency="true"></iframe>
1678 <div class="modal-footer" style="margin-top:0px;">
1679 <button class="btn btn-link btn-cancel oe-pull-away" data-dismiss="modal" type="button">Close</button>
1680 <!--<button class="btn btn-secondary btn-print oe-pull-away" data-dismiss="modal" id="print-help-href" type="button">Print</button>-->
1688 $('#help-href').click (function(){
1689 document.getElementById('targetiframe').src = "Documentation/help_files/openemr_installation_help.php";
1693 $('#print-help-href').click (function(){
1694 $("#targetiframe").get(0).contentWindow.print();
1698 $(".modal-dialog").addClass('drag-action');
1699 $(".modal-content").addClass('resize-action');
1702 echo $setup_help_modal . "\r\n";