\n password = \"test!1!me\"\n";
exit( 1 );
}
} else {
echo "ERROR: Config file (" . CONFIG_FILE . ") does not exist or is not readable!\n";
exit( 1 );
}
if ( defined( 'PRODUCTION' ) == false ) {
if ( isset( $config_vars['debug']['production'] ) && $config_vars['debug']['production'] == 1 ) {
define( 'PRODUCTION', true );
} else {
define( 'PRODUCTION', false );
}
}
if ( defined( 'DEMO_MODE' ) == false ) {
if ( isset( $config_vars['other']['demo_mode'] ) && $config_vars['other']['demo_mode'] == 1 ) {
define( 'DEMO_MODE', true );
} else {
define( 'DEMO_MODE', false );
}
}
//**REMOVING OR CHANGING THIS APPLICATION NAME AND ORGANIZATION URL IS IN STRICT VIOLATION OF THE LICENSE AND COPYRIGHT AGREEMENT**//
define( 'APPLICATION_NAME', ( PRODUCTION == false && DEMO_MODE == false ) ? 'TimeTrex-Debug' : 'TimeTrex' );
define( 'ORGANIZATION_NAME', 'TimeTrex' );
define( 'ORGANIZATION_URL', 'www.TimeTrex.com' );
if ( isset( $config_vars['other']['deployment_on_demand'] ) && $config_vars['other']['deployment_on_demand'] == 1 ) {
define( 'DEPLOYMENT_ON_DEMAND', true );
} else {
define( 'DEPLOYMENT_ON_DEMAND', false );
}
if ( isset( $config_vars['other']['primary_company_id'] ) && $config_vars['other']['primary_company_id'] != '' ) {
define( 'PRIMARY_COMPANY_ID', (string)$config_vars['other']['primary_company_id'] );
} else {
define( 'PRIMARY_COMPANY_ID', false );
}
if ( PRODUCTION == true ) {
define( 'APPLICATION_BUILD', APPLICATION_VERSION . '-' . date( 'Ymd', APPLICATION_VERSION_DATE ) . '-' . date( 'His', filemtime( __FILE__ ) ) );
} else {
define( 'APPLICATION_BUILD', APPLICATION_VERSION . '-' . date( 'Ymd' ) ); //Keep as static as possible as if this changes during JS debugging it will wipe out any temporary break points.
}
//Windows doesn't define LC_MESSAGES, so lets do it manually here.
if ( defined( 'LC_MESSAGES' ) == false ) {
define( 'LC_MESSAGES', 6 );
}
if ( PRODUCTION == TRUE ) {
error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT ); //Disable DEPRECATED & STRICT notices when in production.
}
/**
* Converts human readable size to bytes.
* @param int|float|string $size Human readable size, ie: 1K, 1M, 1G
* @return int
*/
function convertHumanSizeToBytes( $size ) {
$retval = (int)str_ireplace( [ 'G', 'M', 'K' ], [ '000000000', '000000', '000' ], $size );
//Debug::text('Input Size: '. $size .' Bytes: '. $retval, __FILE__, __LINE__, __METHOD__, 9);
return $retval;
}
//If memory limit is set below the minimum required, just bump it up to that minimum. If its higher, keep the higher value.
$memory_limit = convertHumanSizeToBytes( ini_get( 'memory_limit' ) );
if ( $memory_limit >= 0 && $memory_limit < 512000000 ) { //Use * 1000 rather than * 1024 for easier parsing of G, M, K -- Make sure we consider -1 as the limit.
ini_set( 'memory_limit', '512000000' );
}
unset( $memory_limit );
//IIS 5 doesn't seem to set REQUEST_URI, so attempt to build one on our own
//This also appears to fix CGI mode.
//Inspired by: http://neosmart.net/blog/2006/100-apache-compliant-request_uri-for-iis-and-windows/
if ( !isset( $_SERVER['REQUEST_URI'] ) ) {
if ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
} else if ( isset( $_SERVER['PHP_SELF'] ) ) {
$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
}
if ( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] != '' ) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
//HTTP Basic authentication doesn't work properly with CGI/FCGI unless we decode it this way.
if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) && $_SERVER['HTTP_AUTHORIZATION'] != '' && stripos( php_sapi_name(), 'cgi' ) !== false ) {
//
//RewriteEngine on
//RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
//
//Or this instead:
//SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
[ $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ] = array_pad( explode( ':', base64_decode( substr( $_SERVER['HTTP_AUTHORIZATION'], 6 ) ) ), 2, null );
}
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'ClassMap.inc.php' );
/**
* @param $name
* @return bool
*/
function TTAutoload( $name ) {
global $global_class_map, $profiler; //$config_vars needs to be here, otherwise TTPDF can't access the cache_dir.
//if ( isset( $profiler ) ) {
// $profiler->startTimer( '__autoload' );
//}
if ( isset( $global_class_map[$name] ) ) {
$file_name = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $global_class_map[$name];
} else {
//If the class name contains "plugin", try to load classes directly from the plugins directory.
if ( $name == 'PEAR' ) {
return false; //Skip trying to load PEAR class as it fails anyways.
} else if ( strpos( $name, 'Plugin' ) === false ) {
$file_name = $name . '.class.php';
} else {
$file_name = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . str_replace( 'Plugin', '', $name ) . '.plugin.php';
}
}
//Use include_once() instead of require_once so the installer doesn't Fatal Error without displaying anything.
//include_once() is redundant in __autoload.
//Debug::Text('Autoloading Class: '. $name .' File: '. $file_name, __FILE__, __LINE__, __METHOD__,10);
//Debug::Arr(Debug::BackTrace(), 'Backtrace: ', __FILE__, __LINE__, __METHOD__,10);
//Remove the following @ symbol to help in debugging parse errors.
if ( file_exists( $file_name ) === true ) {
include( $file_name );
} else {
return false; //File doesn't exist, could be external library or just incorrect name.
}
//if ( isset( $profiler ) ) {
// $profiler->stopTimer( '__autoload' );
//}
return true;
}
spl_autoload_register( 'TTAutoload' ); //Registers the autoloader mainly for use with PHPUnit
/**
* The basis for the plugin system, instantiate all classes through this, allowing the class to be overloaded on the fly by a class in the plugin directory.
* ie: $uf = TTNew( 'UserFactory' ); OR $uf = TTNew( 'UserFactory', $arg1, $arg2, $arg3 );
* @param $class_name
* @return string
*/
function TTgetPluginClassName( $class_name ) {
global $config_vars;
//Check if the plugin system is enabled in the config.
if ( isset( $config_vars['other']['enable_plugins'] ) && $config_vars['other']['enable_plugins'] == 1 ) {
//Classes must be alpha numeric, otherwise exit out early if someone is trying to pass in crazy class names as a potential attack.
// This also must ensure that no class name contains '../../' so an attacker can't attempt to access files outside the plugin directory.
// Some TimeClock classes have underscores in the name, so we need to use the actual PHP regex for class names as stated here: https://www.php.net/manual/en/language.oop5.basic.php
if ( preg_match( '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $class_name ) !== 1 ) { //Was using: ctype_alnum( $class_name ) == false -- But that doesn't allow underscores and is less than 10% faster than a complex regex.
Debug::Text( 'WARNING: Class name contains invalid characters: ' . $class_name, __FILE__, __LINE__, __METHOD__, 1 );
return false;
}
$plugin_class_name = $class_name . 'Plugin';
//This improves performance greatly for classes with no plugins.
//But it may cause problems if the original class was somehow loaded before the plugin.
//However the plugin wouldn't apply to it anyways in that case.
//
//Due to a bug that would cause the plugin to not be properly loaded if both the Factory and ListFactory were loaded in the same script
//we need to always reload the plugin class if the current class relates to it.
$is_class_exists = class_exists( $class_name, false );
if ( $is_class_exists == false || ( $is_class_exists == true && stripos( $plugin_class_name, $class_name ) !== false ) ) {
if ( class_exists( $plugin_class_name, false ) == false ) {
//Class file needs to be loaded.
$plugin_directory = Environment::getBasePath() . 'classes' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'plugins';
$plugin_class_file_name = $plugin_directory . DIRECTORY_SEPARATOR . $class_name . '.plugin.php';
//Debug::Text('Plugin System enabled! Looking for class: '. $class_name .' in file: '. $plugin_class_file_name, __FILE__, __LINE__, __METHOD__,10);
if ( file_exists( $plugin_class_file_name ) ) {
@include_once( $plugin_class_file_name );
$class_name = $plugin_class_name;
Debug::Text( 'Found Plugin: ' . $plugin_class_file_name . ' Class: ' . $class_name, __FILE__, __LINE__, __METHOD__, 10 );
}
} else {
//Class file is already loaded.
$class_name = $plugin_class_name;
}
}
//else {
//Debug::Text('Plugin not found...', __FILE__, __LINE__, __METHOD__, 10);
//}
}
//else {
//Debug::Text('Plugins disabled...', __FILE__, __LINE__, __METHOD__, 10);
//}
return $class_name;
}
/**
* Instantiates a new object using plugins if they exist.
* @template Object
* @param class-string