elements = $this->instanceElements(); } /** * Returns whether general statistics are disabled. * * @return boolean */ public function disableGeneralStatistics():bool { global $config; if (users_is_admin($config['id_user']) === true) { return false; } else { return (bool) $config['disable_general_statistics']; } } /** * Instantiate all the elements that will build the dashboard * * @return array */ public function instanceElements():array { global $config; $dir = $config['homedir'].'/include/lib/TacticalView/elements/'; $handle = opendir($dir); if ($handle === false) { return []; } $ignores = [ '.', '..', ]; $elements = []; $elements['welcome'] = $this->getWelcomeMessage(); while (false !== ($file = readdir($handle))) { try { if (in_array($file, $ignores) === true) { continue; } $filepath = realpath($dir.'/'.$file); if (is_readable($filepath) === false || is_dir($filepath) === true || preg_match('/.*\.php$/', $filepath) === false ) { continue; } $className = preg_replace('/.php/', '', $file); include_once $filepath; if (class_exists($className) === true) { $instance = new $className(); $elements[$className] = $instance; } } catch (Exception $e) { } } return $elements; } /** * Render funcion for print the html. * * @return void */ public function render():void { $data = []; $data['javascript'] = $this->javascript(); $data['disableGeneralStatistics'] = $this->disableGeneralStatistics(); $data = array_merge($data, $this->elements); View::render( 'tacticalView/view', $data ); } /** * Function for print js embedded in html. * * @return string */ public function javascript():string { $js = ''; return $js; } /** * Return the welcome message. * * @return string */ private function getWelcomeMessage():string { global $config; $user = users_get_user_by_id($config['id_user']); if (is_array($user) === true && count($user) > 0) { $name = $user['fullname']; } else { $name = ''; } if (empty($name) === true) { $message = __('Welcome back! 👋'); } else { $message = __('Welcome back %s! 👋', $name); } return html_print_div( [ 'content' => $message, 'class' => 'message-welcome', ], true ); } }