getOffset( $date ); $offset = ( $offset < 0 ? '-' : '+' ) . gmdate( 'H:i', abs( $offset ) ); DBQuery( "SET time_zone='" . $offset . "'" ); } else { // If valid PHP timezone_identifier, should be OK for PostgreSQL. DBQuery( "SET TIMEZONE TO '" . $Timezone . "'" ); } } } else { // Fix PHP error if date.timezone ini setting is an invalid time zone identifier. date_default_timezone_set( date_default_timezone_get() ); } // Send email on PHP fatal error. register_shutdown_function( 'ErrorSendEmail' ); /** * Start Session */ session_name( 'RosarioSIS' ); // @link http://php.net/manual/en/session.security.php $cookie_path = dirname( $_SERVER['SCRIPT_NAME'] ) === DIRECTORY_SEPARATOR ? '/' : dirname( $_SERVER['SCRIPT_NAME'] ) . '/'; // Fix #316 CSRF security issue set cookie samesite to strict. // @link https://www.php.net/manual/en/function.session-set-cookie-params.php#125072 $cookie_samesite = 'Strict'; // Cookie secure flag for https. $cookie_https_only = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) || ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] == 443 ); if ( PHP_VERSION_ID < 70300 ) { // PHP version < 7.3. session_set_cookie_params( 0, $cookie_path . '; samesite=' . $cookie_samesite, '', $cookie_https_only, true ); } else { session_set_cookie_params( [ 'lifetime' => 0, 'path' => $cookie_path, 'domain' => '', 'secure' => $cookie_https_only, 'httponly' => true, 'samesite' => $cookie_samesite, ] ); } session_cache_limiter( 'nocache' ); session_start(); if ( empty( $_SESSION['DefaultSyear'] ) ) { // @since 11.1 Copy $DefaultSyear global var to session (once) to prevent errors when edited $_SESSION['DefaultSyear'] = $DefaultSyear; } if ( empty( $_SESSION['token'] ) ) { /** * Add CSRF token to protect unauthenticated requests * * @since 9.0 * @since 11.0 Fix PHP fatal error if openssl PHP extension is missing * @link https://stackoverflow.com/questions/5207160/what-is-a-csrf-token-what-is-its-importance-and-how-does-it-work */ $_SESSION['token'] = bin2hex( function_exists( 'openssl_random_pseudo_bytes' ) ? openssl_random_pseudo_bytes( 16 ) : ( function_exists( 'random_bytes' ) ? random_bytes( 16 ) : mb_substr( sha1( rand( 999999999, 9999999999 ), true ), 0, 16 ) ) ); } if ( empty( $_SESSION['STAFF_ID'] ) && empty( $_SESSION['STUDENT_ID'] ) && ( basename( $_SERVER['SCRIPT_NAME'] ) === 'Modules.php' || basename( $_SERVER['SCRIPT_NAME'] ) === 'Bottom.php' || basename( $_SERVER['SCRIPT_NAME'] ) === 'Side.php' ) ) { // Logout if no Staff or Student session ID. /** * Redirect to Modules.php URL after login. * * @since 3.8 */ $redirect_to = basename( $_SERVER['SCRIPT_NAME'] ) === 'Modules.php' ? '&redirect_to=' . urlencode( $_SERVER['QUERY_STRING'] ) : ''; // Redirection is done in Javascript in case current request is AJAX. ?> ROSARIO_POST_MAX_SIZE_LIMIT ) { $post_max_size_limit = function( $value ) { if ( strlen( $value ) > ( ROSARIO_POST_MAX_SIZE_LIMIT / 4 ) ) { // Reset value > limit / 4, or else we would send it in the HackingLog email! return 'ROSARIO_POST_MAX_SIZE_LIMIT / 4 reached.'; } return $value; }; array_rwalk( $_POST, $post_max_size_limit ); array_rwalk( $_REQUEST, $post_max_size_limit ); require_once 'ProgramFunctions/HackingLog.fnc.php'; // Do not translate. $error[] = 'You are submitting too much data: over the ' . ( ROSARIO_POST_MAX_SIZE_LIMIT / 1024 / 1024 ) . 'M limit. Try reducing the data you are submitting.'; HackingLog(); } /** * Sanitize $_REQUEST array * ($_POST + $_GET) */ // Escape strings for DB queries. array_rwalk( $_REQUEST, 'DBEscapeString' ); // Remove HTML tags. array_rwalk( $_REQUEST, 'strip_tags' ); /** * Internationalization */ if ( ! empty( $_REQUEST['locale'] ) && in_array( $_REQUEST['locale'], $RosarioLocales ) ) { $_SESSION['locale'] = $_REQUEST['locale']; } elseif ( empty( $_SESSION['locale'] ) ) { $_SESSION['locale'] = $RosarioLocales[0]; // English? } $locale = $_SESSION['locale']; putenv( 'LC_ALL=' . $locale ); function_exists( '_setlocale' ) ? // PHP Compatibility: MoTranslator. _setlocale( LC_ALL, $locale ) : setlocale( LC_ALL, $locale ); // Numeric separator ".". setlocale( LC_NUMERIC, 'C', 'english', 'en_US', 'en_US.utf8', 'en_US.UTF-8' ); if ( $locale === 'tr_TR.utf8' ) { // Bugfix for Turkish characters conversion. setlocale( LC_CTYPE, 'C', 'english', 'en_US', 'en_US.utf8', 'en_US.UTF-8' ); } // Binds the messages domain to the locale folder. bindtextdomain( 'rosariosis', $LocalePath ); // Ensures text returned is utf-8, quite often this is iso-8859-1 by default. bind_textdomain_codeset( 'rosariosis', 'UTF-8' ); // Sets the domain name, this means gettext will be looking for a file called rosariosis.mo. textdomain( 'rosariosis' ); if ( mb_internal_encoding() !== 'UTF-8' ) { // Multibyte strings: check if not UTF-8 first to avoid cost of setting. mb_internal_encoding( 'UTF-8' ); } if ( ROSARIO_DEBUG ) { require_once 'ProgramFunctions/Debug.fnc.php'; // @since 5.0 Load Kint. Kint(); } else { function d() { // Prevent PHP Fatal error if Kint debug d() function not loaded. } } /** * Update RosarioSIS * Automatically runs after manual files update * To apply eventual incremental DB updates * * @see ProgramFunctions/Update.fnc.php * @since 2.9 */ // Check if version in DB < ROSARIO_VERSION. if ( version_compare( Config( 'VERSION' ), ROSARIO_VERSION, '<' ) ) { require_once 'ProgramFunctions/Update.fnc.php'; // Run Update() to apply updates if any. Update(); } /** * Modules * * Core modules (packaged with RosarioSIS): cannot be deleted. */ $RosarioCoreModules = [ 'School_Setup', 'Students', 'Users', 'Scheduling', 'Grades', 'Attendance', 'Eligibility', 'Discipline', 'Accounting', 'Student_Billing', 'Food_Service', 'Resources', 'Custom', ]; $RosarioModules = unserialize( Config( 'MODULES' ) ); $non_core_modules = array_diff_key( $RosarioModules, array_flip( $RosarioCoreModules ) ); _LoadAddons( $non_core_modules, 'modules/' ); /** * Plugins * * Core plugins (packaged with RosarioSIS): cannot be deleted. */ $RosarioCorePlugins = [ 'Moodle', ]; $RosarioPlugins = unserialize( Config( 'PLUGINS' ) ); _LoadAddons( $RosarioPlugins, 'plugins/' ); /** * Load not core modules & plugins * (functions & locale) * Deactivate if does not exist * * Local function * * @param array $addons Non core addons (Plugins or Modules). * @param string $folder Plugin or Module folder. * @return void */ function _LoadAddons( $addons, $folder ) { global $RosarioModules, $RosarioPlugins; /** * Check if non core activated modules exist. * Load locale. * Load functions (optional). */ foreach ( (array) $addons as $addon => $activated ) { if ( ! $activated ) { continue; } if ( $folder === 'modules/' && ! file_exists( $folder . $addon . '/Menu.php' ) ) { // If module does not exist, deactivate it. $RosarioModules[$addon] = false; continue; } $addon_functions = $folder . $addon . '/functions.php'; if ( file_exists( $addon_functions ) ) { require_once $addon_functions; } elseif ( $folder === 'plugins/' ) { // If plugin does not exist, deactivate it. $RosarioPlugins[$addon] = false; continue; } // Load addon locale. $locale_path = $folder . $addon . '/locale'; if ( ! is_dir( $locale_path ) ) { continue; } // Binds the messages domain to the locale folder. bindtextdomain( $addon, $locale_path ); // Ensures text returned is utf-8, quite often this is iso-8859-1 by default. bind_textdomain_codeset( $addon, 'UTF-8' ); } } /** * Output HTML header (including Bottom & Side menus), or footer * * @example Warehouse( 'header' ); * * @since 3.8 Warehouse header head hook * @since 3.8 Warehouse footer hook * @since 4.4 Warehouse header hook * @since 6.0 Warehouse Header Javascripts * * @global $_ROSARIO Uses $_ROSARIO['ProgramLoaded'] & $_ROSARIO['page'] * * @uses isPopup() * @uses isAJAX() * @uses ETagCache() * * @param string $mode 'header' or 'footer'. */ function Warehouse( $mode ) { global $_ROSARIO; if ( isset( $_REQUEST['_ROSARIO_PDF'] ) ) { if ( $mode === 'header' ) { // Start buffer. ob_start(); } // Printing PDF, skip, see PDF.fnc.php. return; } switch ( $mode ) { // Header HTML. case 'header': ETagCache( 'start' ); if ( isAJAX() ) { // If jQuery not available, log out. if ( $_ROSARIO['page'] === 'modules' ): ?> >