diff --git a/interface/modules/custom_modules/oe-module-faxsms/ModuleManagerActionListener.php b/interface/modules/custom_modules/oe-module-faxsms/ModuleManagerActionListener.php new file mode 100644 index 00000000000..1f63efbf7d2 --- /dev/null +++ b/interface/modules/custom_modules/oe-module-faxsms/ModuleManagerActionListener.php @@ -0,0 +1,106 @@ + + * @copyright Copyright (c) 2024 Jerry Padgett + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +/* + * Currently register isn't supported and support should be a part of install. + * If an error needs to be reported to user, return description of error. + * However, whatever action trapped here has already occurred in Manager. + * Catch any exceptions because chances are they will be overlooked in Laminas module. + * Report them in return value. +*/ + +class ModuleManagerActionListener +{ + // Prevent instantiation + private function __construct() + { + } + + + /** + * @param $methodName + * @param $modId + * @param string $currentActionStatus + * @return string On method success a $currentAction status should be returned or error string. + */ + public static function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string + { + // Check if the action method exists + if (method_exists(self::class, $methodName)) { + return self::$methodName($modId, $currentActionStatus); + } else { + // TODO Perhaps this should be an exception! + return "Module cleanup method $methodName does not exist."; + } + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private static function install($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private static function enable($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private static function disable($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private static function unregister($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private static function install_sql($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private static function upgrade_sql($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } +} diff --git a/interface/modules/custom_modules/oe-module-faxsms/ModuleManagerAfterActionListener.php b/interface/modules/custom_modules/oe-module-faxsms/ModuleManagerAfterActionListener.php new file mode 100644 index 00000000000..364b08299f4 --- /dev/null +++ b/interface/modules/custom_modules/oe-module-faxsms/ModuleManagerAfterActionListener.php @@ -0,0 +1,168 @@ + + * @copyright Copyright (c) 2024 Jerry Padgett + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ +/* + * Do not declare a namespace + * If you want Laminas manager to set namespace set it in getModuleNamespace + * otherwise uncomment below and set path. + * + * */ + +/* + $classLoader = new \OpenEMR\Core\ModulesClassLoader($GLOBALS['fileroot']); + $classLoader->registerNamespaceIfNotExists("OpenEMR\\Modules\\FaxSMS\\", __DIR__ . DIRECTORY_SEPARATOR . 'src'); +*/ + +class ModuleManagerAfterActionListener extends AbstractModuleActionListener +{ + public $service; + private $authUser; + + public function __construct() + { + parent::__construct(); + $this->authUser = (int)$this->getSession('authUserID'); + $this->service = new BootstrapService(); + } + + /** + * @param $methodName + * @param $modId + * @param string $currentActionStatus + * @return string On method success a $currentAction status should be returned or error string. + */ + public function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string + { + if (method_exists(self::class, $methodName)) { + return self::$methodName($modId, $currentActionStatus); + } else { + return "Module cleanup method $methodName does not exist."; + } + } + + /** + * Required method to return namespace + * If namespace isn't provided return an empty + * and register namespace using example at top of this script. + * + * @return string + */ + public static function getModuleNamespace(): string + { + return 'OpenEMR\\Modules\\FaxSMS\\'; + } + + /** + * Required method to return this class object, + * so it is instantiated in Laminas Manager. + * + * @return ModuleManagerAfterActionListener + */ + public static function initListenerSelf(): ModuleManagerAfterActionListener + { + return new self(); + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function install($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function enable($modId, $currentActionStatus): mixed + { + if (empty($this->service)) { + $this->service = new BootstrapService(); + } + $globals = $this->service->fetchPersistedSetupSettings() ?? ''; + if (empty($globals)) { + $globals = $this->service->getVendorGlobals(); + } + $this->service->saveModuleListenerGlobals($globals); + + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function disable($modId, $currentActionStatus) + { + if (empty($this->service)) { + $this->service = new BootstrapService(); + } + // fetch current. + $globals = $this->service->getVendorGlobals(); + // persist current for enable action. + $rid = $this->service->persistSetupSettings($globals); + foreach ($globals as $k => $v) { + if ($k == 'oefax_enable_sms' || $k == 'oefax_enable_fax') { + // force disable of services + $globals[$k] = 0; + } + } + // save new disabled settings. + $this->service->saveModuleListenerGlobals($globals); + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function unregister($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function install_sql($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function upgrade_sql($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } +} diff --git a/interface/modules/custom_modules/oe-module-faxsms/library/rc_sms_notification.php b/interface/modules/custom_modules/oe-module-faxsms/library/rc_sms_notification.php index b3b3f65f55d..4f0658cd1ae 100644 --- a/interface/modules/custom_modules/oe-module-faxsms/library/rc_sms_notification.php +++ b/interface/modules/custom_modules/oe-module-faxsms/library/rc_sms_notification.php @@ -12,7 +12,7 @@ * @author Robert Down * @copyright Unknown * @copyright Copyright (c) 2008 Larry Lart - * @copyright Copyright (c) 2018-2023 Jerry Padgett + * @copyright Copyright (c) 2018-2024 Jerry Padgett * @copyright Copyright (c) 2021 Robert Down */ @@ -24,16 +24,25 @@ $backpic = ""; $clientApp = null; // for cron -if (($argc ?? null) > 1 && empty($_SESSION['site_id']) && empty($_GET['site'])) { - $c = stripos($argv[1], 'site='); - if ($c === false) { - echo xlt("Missing Site Id using default") . "\n"; - $argv[1] = "site=default"; +$error = ''; +$runtime = []; + +// Check for other arguments and perform your script logic + +if (($argc ?? null) > 1) { + foreach ($argv as $k => $v) { + if ($k == 0) { + continue; + } + $args = explode('=', $v); + if ((count($args ?? [])) > 1) { + $runtime[trim($args[0])] = trim($args[1]); + } } - $args = explode('=', $argv[1]); - $_GET['site'] = $args[1] ?? 'default'; } +$isCli = 0; if (php_sapi_name() === 'cli') { + $isCli = 1; $_SERVER["HTTP_HOST"] = "localhost"; $ignoreAuth = true; } @@ -43,13 +52,32 @@ require_once(__DIR__ . "/../../../../globals.php"); require_once("$srcdir/appointments.inc.php"); -$TYPE = "SMS"; +// Check for help argument +if ($argc > 1 && (in_array('--help', $argv) || in_array('-h', $argv))) { + displayHelp(); + exit(0); +} + +if (empty($runtime['site']) && empty($_SESSION['site_id']) && empty($_GET['site'])) { + echo xlt("Missing Site Id using default") . "\n"; + $_GET['site'] = $runtime['site'] = 'default'; +} else { + $_GET['site'] = $runtime['site']; +} + +$TYPE = ''; +if (!empty($runtime['type'])) { + $TYPE = strtoupper($runtime['type']); +} else { + $TYPE = $runtime['type'] = "SMS"; // default +} $CRON_TIME = 150; // use service if needed if ($TYPE === "SMS") { + $_SESSION['authUser'] = $runtime['user'] ?? ''; $clientApp = AppDispatch::getApiService('sms'); $cred = $clientApp->getCredentials(); - if (!$clientApp->verifyAcl()) { + if (!$clientApp->verifyAcl('admin', 'docs', $runtime['user'] ?? '')) { die("

" . xlt("Not Authorised!") . "

"); } } @@ -62,7 +90,7 @@ // check command line for quite option $bTestRun = isset($_REQUEST['dryrun']) ? 1 : 0; -if ($argc > 1 && $argv[2] == 'test') { +if (!empty($runtime['testrun'])) { $bTestRun = 1; } @@ -311,3 +339,22 @@ function cron_GetNotificationSettings(): bool|array return ($vectNotificationSettings); } +function displayHelp(): void +{ + //echo text($helpt); + $help = + << $vendor) { sqlQuery( - "INSERT INTO `globals` (`gl_name`,`gl_value`) VALUES (?, ?) - ON DUPLICATE KEY UPDATE `gl_name` = ?, `gl_value` = ?", + "INSERT INTO `globals` (`gl_name`,`gl_value`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `gl_name` = ?, `gl_value` = ?", array($key, $vendor, $key, $vendor) ); } } + + /** + * Grab all Laminas Module setup or columns values. + * + * @param $modId + * @param string $col + * @return array + */ + function getModuleRegistry($modId, $col = '*'): array + { + $registry = []; + $sql = "SELECT $col FROM modules WHERE mod_id = ?"; + $results = sqlQuery($sql, array($modId)); + foreach ($results as $k => $v) { + $registry[$k] = trim((preg_replace('/\R/', '', $v))); + } + + return $registry; + } + + /** + * @param $items + * @return void + */ + public function saveModuleListenerGlobals($items): void + { + foreach ($items as $key => $vendor) { + $id = sqlQuery( + "INSERT INTO `globals` (`gl_name`,`gl_value`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `gl_name` = ?, `gl_value` = ?", + array($key, $vendor, $key, $vendor) + ); + } + } + + /** + * @param $settings + * @return mixed + */ + public function persistSetupSettings($settings): mixed + { + // vendor for backup of setup globals. + $vendor = '_persisted'; + $authId = 0; + $content = json_encode($settings); + $sql = "INSERT INTO `module_faxsms_credentials` (`id`, `auth_user`, `vendor`, `credentials`) + VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `auth_user`= ?, `vendor` = ?, `credentials`= ?, `updated` = NOW()"; + + return sqlQuery($sql, array('', $authId, $vendor, $content, $authId, $vendor, $content)); + } + + /** + * @return array + */ + public function fetchPersistedSetupSettings(): array + { + $vendor = '_persisted'; + $authUserId = 0; + $globals = sqlQuery("SELECT `credentials` FROM `module_faxsms_credentials` WHERE `auth_user` = ? AND `vendor` = ?", array($authUserId, $vendor)) ?? []; + if (is_string($globals['credentials'])) { + return json_decode($globals['credentials'], true) ?? []; + } + return []; + } } diff --git a/interface/modules/custom_modules/oe-module-faxsms/table.sql b/interface/modules/custom_modules/oe-module-faxsms/table.sql index f2a2b8172ed..f9933b140ad 100644 --- a/interface/modules/custom_modules/oe-module-faxsms/table.sql +++ b/interface/modules/custom_modules/oe-module-faxsms/table.sql @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS `module_faxsms_credentials` ( `vendor` varchar(63) DEFAULT NULL, `credentials` mediumblob NOT NULL, `updated` datetime DEFAULT current_timestamp(), +`setup_persist` tinytext, PRIMARY KEY (`id`), UNIQUE KEY `vendor` (`auth_user`,`vendor`) ) ENGINE=InnoDB COMMENT='Vendor credentials for Fax/SMS'; diff --git a/interface/modules/custom_modules/oe-module-faxsms/version.php b/interface/modules/custom_modules/oe-module-faxsms/version.php index 352526f2571..2171691395e 100644 --- a/interface/modules/custom_modules/oe-module-faxsms/version.php +++ b/interface/modules/custom_modules/oe-module-faxsms/version.php @@ -1,5 +1,11 @@ getRequest(); $status = $this->listenerObject->z_xlt("Failure"); if ($request->isPost()) { + $modId = $request->getPost('modId') ?? null; + $registryEntry = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory"); + $dirModule = $registryEntry->modDirectory; + $modType = $registryEntry->type; if ($request->getPost('modAction') == "enable") { $status = $this->EnableModule($request->getPost('modId')); } elseif ($request->getPost('modAction') == "disable") { @@ -168,6 +173,10 @@ public function manageAction() } elseif ($request->getPost('modAction') == "unregister") { $status = $this->UnregisterModule($request->getPost('modId')); } + // cleanup action. + if ($modType == InstModuleTable::MODULE_TYPE_CUSTOM) { + $status = $this->callModuleAfterAction($request->getPost('modAction'), $modId, $dirModule, $status); + } } $output = ""; if (!empty($div) && is_array($div)) { @@ -177,11 +186,47 @@ public function manageAction() exit(0); } + /** + * @param $action + * @param $modId + * @param $dirModule + * @param $currentStatus + * @return mixed + */ + private function callModuleAfterAction($action, $modId, $dirModule, $currentStatus): mixed + { + $modPath = $GLOBALS['fileroot'] . "/" . $GLOBALS['baseModDir'] . "custom_modules/" . $dirModule; + $moduleClassPath = $modPath . '/ModuleManagerAfterActionListener.php'; + $className = 'ModuleManagerAfterActionListener'; + $action = trim($action); + if (!file_exists($moduleClassPath)) { + return $currentStatus; + } + $t = get_declared_classes(); + require_once($moduleClassPath); + $namespace = attr($className::getModuleNamespace()); + if (!empty($namespace)) { + $classLoader = new ModulesClassLoader($GLOBALS['fileroot']); + $classLoader->registerNamespaceIfNotExists($namespace, $modPath . DIRECTORY_SEPARATOR . 'src'); + } + $methodName = trim($action); + $instance = $className::initListenerSelf(); + if (class_exists($instance::class)) { + if (method_exists($instance, 'moduleManagerAction')) { + return call_user_func([$instance, 'moduleManagerAction'], $methodName, $modId); + } else { + return $currentStatus; + } + } else { + return $currentStatus; + } + } + /** * @param $version * @return int|string */ - function upgradeAclFromVersion($ACL_UPGRADE, $version) + private function upgradeAclFromVersion($ACL_UPGRADE, $version) { $toVersion = ''; foreach ($ACL_UPGRADE as $toVersion => $function) { @@ -506,7 +551,11 @@ public function InstallModuleSQL($modId = '') $registryEntry = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory"); $dirModule = $registryEntry->modDirectory; $modType = $registryEntry->type; - if ($this->getInstallerTable()->installSQL($modId, $modType, $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $dirModule)) { + $modUri = "zend_modules/module/"; + if ($modType == InstModuleTable::MODULE_TYPE_CUSTOM) { + $modUri = "custom_modules/"; + } + if ($this->getInstallerTable()->installSQL($modId, $modType, $GLOBALS['fileroot'] . "/" . $GLOBALS['baseModDir'] . $modUri . $dirModule)) { $values = array($registryEntry->mod_nick_name,$registryEntry->mod_enc_menu); $values[2] = $this->getModuleVersionFromFile($modId); $values[3] = $registryEntry->acl_version; @@ -524,7 +573,12 @@ public function InstallModuleSQL($modId = '') public function UpgradeModuleSQL($modId = '') { $Module = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory"); - $modDir = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $Module->modDirectory; + $modType = $Module->type; + $modUri = "zend_modules/module/"; + if ($modType == InstModuleTable::MODULE_TYPE_CUSTOM) { + $modUri = "custom_modules/"; + } + $modDir = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . $modUri . $Module->modDirectory; $sqlInstallLocation = $modDir . '/sql'; // if this is a custom module that for some reason doesn't have the SQL in a sql folder... if (!file_exists($sqlInstallLocation)) { @@ -542,7 +596,7 @@ public function UpgradeModuleSQL($modId = '') } ob_start(); $sqlUpgradeService = new SQLUpgradeService(); - $sqlUpgradeService->setRenderOutputToScreen(true); + $sqlUpgradeService->setRenderOutputToScreen(false); $sqlUpgradeService->upgradeFromSqlFile($filename, $sqlInstallLocation); $outputToBrowser .= ob_get_contents(); ob_end_clean(); @@ -615,7 +669,7 @@ public function InstallModuleACL($modId = '') */ public function EnableModule($modId = '') { - $resp = $this->getInstallerTable()->updateRegistered($modId, "mod_active=0"); + $resp = $this->getInstallerTable()->updateRegistered($modId, "mod_active=1"); if ($resp['status'] == 'failure' && $resp['code'] == '200') { $status = $resp['value']; } else { @@ -632,7 +686,7 @@ public function EnableModule($modId = '') */ public function DisableModule($modId = '') { - $resp = $this->getInstallerTable()->updateRegistered($modId, "mod_active=1"); + $resp = $this->getInstallerTable()->updateRegistered($modId, "mod_active=0"); if ($resp['status'] == 'failure' && $resp['code'] == '200') { $plural = "Module"; if (count($resp['value'] ?? []) > 1) { @@ -690,7 +744,7 @@ public function InstallModule($modId = '', $mod_enc_menu = '', $mod_nick_name = /** * Function to Unregister Module * - * @param string $dir Location of the php file which calling functions to add sections,aco etc. + * @param string $modId * @return boolean */ public function UnregisterModule($modId = '') @@ -772,9 +826,9 @@ public function commandInstallModuleAction($moduleName, $moduleAction) } elseif ($moduleAction === "upgrade_acl") { $div = $this->UpgradeModuleACL($moduleId); } elseif ($moduleAction === "enable") { - $div = $this->DisableModule($moduleId); - } elseif ($moduleAction === "disable") { $div = $this->EnableModule($moduleId); + } elseif ($moduleAction === "disable") { + $div = $this->DisableModule($moduleId); } elseif ($moduleAction === "install") { $div = $this->InstallModule($moduleId); } elseif ($moduleAction === "unregister") { diff --git a/interface/modules/zend_modules/module/Installer/src/Installer/Model/InstModuleTable.php b/interface/modules/zend_modules/module/Installer/src/Installer/Model/InstModuleTable.php index 7cb86bb4c78..6cb593bc300 100644 --- a/interface/modules/zend_modules/module/Installer/src/Installer/Model/InstModuleTable.php +++ b/interface/modules/zend_modules/module/Installer/src/Installer/Model/InstModuleTable.php @@ -899,7 +899,7 @@ public function getModuleHooks($moduleDirectory) if ($objHooks) { $hooksArr = $objHooks->getHookConfig(); } else { - error_log(errorLogEscape($moduleDirectory) . "does not have a controller object"); + error_log(errorLogEscape($moduleDirectory) . " " . "does not have a controller object"); } return $hooksArr; diff --git a/interface/modules/zend_modules/module/Installer/view/installer/installer/index.phtml b/interface/modules/zend_modules/module/Installer/view/installer/installer/index.phtml index 6345fbd7fd2..4c5facdc96c 100644 --- a/interface/modules/zend_modules/module/Installer/view/installer/installer/index.phtml +++ b/interface/modules/zend_modules/module/Installer/view/installer/installer/index.phtml @@ -31,44 +31,42 @@ $depObj = $this->dependencyObject; $coreModules = $this->coreModules ?? []; ?> -

escapeHtml($title ?? ''); ?>

- -
+
-
+
- +
- - - - - - - - - - - - - - + + + + + + + + + + + + + + coreModules ?? []; modActive == 1) { ?> - + modName != 'Acl') { ?> - + coreModules ?? []; -
- z_xlt('Registered Modules'); ?> -
z_xlt('ID'); ?>z_xlt('Module'); ?> z_xlt('Status'); ?> z_xlt('Menu Text'); ?> z_xlt('Nick Name'); ?> z_xlt('Type'); ?> z_xlt('Dependency Modules'); ?> z_xlt('Action'); ?> z_xlt('Config'); ?>
+ z_xlt('Registered Modules'); ?> +
z_xlt('ID'); ?>z_xlt('Module'); ?> z_xlt('Status'); ?> z_xlt('Menu Text'); ?> z_xlt('Nick Name'); ?> z_xlt('Type'); ?> z_xlt('Dependency Modules'); ?> z_xlt('Action'); ?> z_xlt('Config'); ?>
- - - - - - - - +
- z_xlt('Unregistered Modules'); ?> -
z_xlt('ID'); ?>z_xlt('Module Name'); ?>z_xlt('Type'); ?>z_xlt('Action'); ?>
+ + + + + + + + + + + prependFile($this->basePath() . '/js/lib/jquery-1.8.0.min.js') ?> - -
+ +
content; ?>
diff --git a/src/Core/AbstractModuleActionListener.php b/src/Core/AbstractModuleActionListener.php new file mode 100644 index 00000000000..df9d52fe35d --- /dev/null +++ b/src/Core/AbstractModuleActionListener.php @@ -0,0 +1,158 @@ + + * @copyright Copyright (c) 2024 Jerry Padgett + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +/* + * Do not declare a namespace in class extending this abstract class. + * If you want Laminas manager to set namespace, set it in getModuleNamespace + * otherwise use below at top of class to register namespace. + * $classLoader = new \OpenEMR\Core\ModulesClassLoader($GLOBALS['fileroot']); + * $classLoader->registerNamespaceIfNotExists("OpenEMR\\Modules\\PortalPlugins\\", __DIR__ . DIRECTORY_SEPARATOR . 'src'); + * */ + +namespace OpenEMR\Core; + +/** + * + */ +abstract class AbstractModuleActionListener +{ + use AbstractModuleActionTrait; + + private $_request; + private $_query; + private $_post; + private $_server; + private $_cookies; + private $_session; + + public function __construct() + { + $this->_request = &$_REQUEST; + $this->_query = &$_GET; + $this->_post = &$_POST; + $this->_server = &$_SERVER; + $this->_cookies = &$_COOKIE; + $this->_session = &$_SESSION; + } + + /** + * @param string $methodName Action name e.g. enable, disable etc.. + * @param string $modId Module id + * @param string $currentActionStatus Current action status from Laminas event. + * @return string On method success a $currentAction status should be returned or error string. + */ + abstract public function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string; + + /** + * Required method to return namespace + * If namespace isn't provided return an empty + * and register namespace using example at top of this script. + * + * @return string + */ + abstract protected static function getModuleNamespace(): string; + + /** + * Required method to return this class object, + * so it is instantiated in Laminas Manager. + * + * @return + */ + abstract protected static function initListenerSelf(); + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function install($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function enable($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function disable($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function unregister($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function install_sql($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * @param $modId + * @param $currentActionStatus + * @return mixed + */ + private function upgrade_sql($modId, $currentActionStatus): mixed + { + return $currentActionStatus; + } + + /** + * Grab all Module setup or columns values. + * + * @param $modId + * @param string $col + * @return array + */ + function getModuleRegistry($modId, $col = '*'): array + { + $registry = []; + $sql = "SELECT $col FROM modules WHERE mod_id = ?"; + $results = sqlQuery($sql, array($modId)); + foreach ($results as $k => $v) { + $registry[$k] = trim((preg_replace('/\R/', '', $v))); + } + + return $registry; + } +} diff --git a/src/Core/AbstractModuleActionTrait.php b/src/Core/AbstractModuleActionTrait.php new file mode 100644 index 00000000000..f4b0cbf9b8c --- /dev/null +++ b/src/Core/AbstractModuleActionTrait.php @@ -0,0 +1,132 @@ + + * @copyright Copyright (c) 2024 Jerry Padgett + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +namespace OpenEMR\Core; + +use OpenEMR\Common\Session\SessionUtil; + +/** + * Some useful functions. + */ +trait AbstractModuleActionTrait +{ + /** + * @return array + */ + public static function getLoggedInUser(): array + { + $id = $_SESSION['authUserID'] ?? 1; + $query = "SELECT fname, lname, fax, facility, username FROM users WHERE id = ?"; + $result = sqlQuery($query, array($id)); + + return $result; + } + + /** + * @param $param + * @param $default + * @return mixed|null + */ + public function getPost($param = null, $default = null): mixed + { + if ($param) { + return $this->_post[$param] ?? $default; + } + + return $this->_post; + } + + /** + * @param $param + * @param $default + * @return mixed|null + */ + public function getQuery($param = null, $default = null): mixed + { + if ($param) { + return $this->_query[$param] ?? $default; + } + + return $this->_query; + } + + /** + * @param $param + * @param $default + * @return mixed|null + */ + public function getRequest($param = null, $default = null): mixed + { + if ($param) { + return $this->_request[$param] ?? $default; + } + + return $this->_request; + } + + /** + * @param $param + * @param $default + * @return mixed|null + */ + public function getSession($param = null, $default = null): mixed + { + if ($param) { + return $_SESSION[$param] ?? $default; + } + + return $this->_session; + } + + /** + * @param $param + * @param $default + * @return mixed|null + */ + public function getServer($param = null, $default = null): mixed + { + if ($param) { + return $this->_server[$param] ?? $default; + } + + return $this->_server; + } + + /** + * @param $params + * @return $this + */ + public function setHeader($params): static + { + if (!headers_sent()) { + if (is_scalar($params)) { + header($params); + } else { + foreach ($params as $key => $value) { + header(sprintf('%s: %s', $key, $value)); + } + } + } + + return $this; + } + + /** + * @param $key + * @param $value + * @return $this + */ + public function setSession($key, $value): static + { + // ensure write is allowed by using utility. + SessionUtil::setSession($key, $value); + return $this; + } +} diff --git a/src/Core/ModulesClassLoader.php b/src/Core/ModulesClassLoader.php index 12c216e9886..c1661203d2a 100644 --- a/src/Core/ModulesClassLoader.php +++ b/src/Core/ModulesClassLoader.php @@ -54,9 +54,9 @@ public function __construct($webRootPath) * @param string $prefix The prefix/namespace, with trailing '\\' * @param string[]|string $paths The PSR-4 base directories to * + * @return boolean * @throws \InvalidArgumentException * - * @return void */ public function registerNamespaceIfNotExists($namespace, $paths) {
+ z_xlt('Unregistered Modules'); ?> +
z_xlt('ID'); ?>z_xlt('Module Name'); ?>z_xlt('Type'); ?>z_xlt('Action'); ?>