posaune
[timetracker.git] / initialize.php
index ce6acdf..241d723 100644 (file)
@@ -42,6 +42,7 @@ define("LIBRARY_DIR", APP_DIR."/WEB-INF/lib");
 define("TEMPLATE_DIR", APP_DIR."/WEB-INF/templates");
 // Date format for database and URI parameters.
 define('DB_DATEFORMAT', '%Y-%m-%d');
+define('MAX_RANK', 512); // Max user rank.
 
 require_once(LIBRARY_DIR.'/common.lib.php');
 
@@ -67,14 +68,13 @@ check_extension('mbstring');
 // If auth params are not defined (in config.php) - initialize with an empty array.
 if (!isset($GLOBALS['AUTH_MODULE_PARAMS']) || !is_array($GLOBALS['AUTH_MODULE_PARAMS']))
   $GLOBALS['AUTH_MODULE_PARAMS'] = array();
-  
+
 // Smarty initialization.
 import('smarty.Smarty');
 $smarty = new Smarty;
 $smarty->use_sub_dirs = false;
 $smarty->template_dir = TEMPLATE_DIR;
 $smarty->compile_dir  = TEMPLATE_DIR.'_c';
-$GLOBALS['SMARTY'] = &$smarty;
 
 // Note: these 3 settings below used to be in .htaccess file. Moved them here to eliminate "error 500" problems
 // with some shared hostings that do not have AllowOverride Options or AllowOverride All in their apache configurations.
@@ -84,6 +84,12 @@ session_cache_expire(1);
 $phpsessid_ttl = defined('PHPSESSID_TTL') ? PHPSESSID_TTL : 60*60*24;
 // Set lifetime for garbage collection.
 ini_set('session.gc_maxlifetime', $phpsessid_ttl);
+// Set PHP session path, if defined to avoid garbage collection interference from other scripts.
+if (defined('PHP_SESSION_PATH')) {
+  ini_set('session.save_path', PHP_SESSION_PATH);
+  ini_set('session.gc_probability', 1);
+}
+
 // Set session cookie lifetime.
 session_set_cookie_params($phpsessid_ttl);
 if (isset($_COOKIE['tt_PHPSESSID'])) {
@@ -93,7 +99,7 @@ if (isset($_COOKIE['tt_PHPSESSID'])) {
 }
 
 // Start or resume PHP session.
-session_name('tt_PHPSESSID'); // "tt_" prefix is to avoid sharing session with other PHP apps that do not name session.  
+session_name('tt_PHPSESSID'); // "tt_" prefix is to avoid sharing session with other PHP apps that do not name session.
 @session_start();
 
 // Authorization.
@@ -120,25 +126,6 @@ define('TYPE_ALL', 0); // Time record can be specified with either duration or s
 define('TYPE_START_FINISH', 1); // Time record has start and finish times.
 define('TYPE_DURATION', 2); // Time record has only duration, no start and finish times.
 
-// User access rights - bits that collectively define an access mask to the system (a role).
-// We'll have some bits here (1,2, etc...) reserved for future use.
-define('right_data_entry', 4);     // Right to enter work hours and expenses.
-define('right_view_charts', 8);    // Right to view charts.
-define('right_view_reports', 16);  // Right to view reports.
-define('right_view_invoices', 32); // Right to view invoices.
-define('right_manage_team', 64);   // Right to manage team. Note that this is not full access to team.
-define('right_assign_roles', 128); // Right to assign user roles.
-define('right_export_team', 256);  // Right to export team data to a file.
-define('right_administer_site', 1024); // Admin account right to manage the application as a whole. 
-
-// User roles.
-define('ROLE_USER', 4);          // Regular user.
-define('ROLE_CLIENT', 16);       // Client (to view reports and invoices).
-define('ROLE_COMANAGER', 68);    // Team co-manager. Can do many things but not as much as team manager.
-define('ROLE_MANAGER', 324);     // Team manager. Can do everything for a team.
-define('ROLE_SITE_ADMIN', 1024); // Site administrator.
-
-
 define('CHARSET', 'utf-8');
 
 date_default_timezone_set(@date_default_timezone_get());
@@ -152,15 +139,15 @@ import('html.HttpRequest');
 $request = new ttHttpRequest();
 
 import('form.ActionErrors');
-$errors = new ActionErrors();
-$messages = new ActionErrors();
+$err = new ActionErrors(); // Error messages for user.
+$msg = new ActionErrors(); // Notification messages (not errrors) for user.
 
 // Create an instance of ttUser class. This gets us most of user details.
 import('ttUser');
 $user = new ttUser(null, $auth->getUserId());
 if ($user->custom_logo) {
-  $smarty->assign('custom_logo', 'images/'.$user->team_id.'.png');
-  $smarty->assign('mobile_custom_logo', '../images/'.$user->team_id.'.png');
+  $smarty->assign('custom_logo', 'images/'.$user->group_id.'.png');
+  $smarty->assign('mobile_custom_logo', '../images/'.$user->group_id.'.png');
 }
 $smarty->assign('user', $user);
 
@@ -173,11 +160,11 @@ $lang = $user->lang;
 if (!$lang) {
   if (defined('LANG_DEFAULT'))
     $lang = LANG_DEFAULT;
-  
+
   // If we still do not have the language get it from the browser.
   if (!$lang) {
     $lang = $i18n->getBrowserLanguage();
-        
+
     // Finally - English is the default.
     if (!$lang) {
       $lang = 'en';
@@ -187,17 +174,14 @@ if (!$lang) {
 
 // Load i18n file.
 $i18n->load($lang);
-$GLOBALS['I18N'] = &$i18n;
-
-$GLOBALS['USER'] = &$user;
 
 // Assign things for smarty to use in template files.
 $smarty->assign('i18n', $i18n->keys);
-$smarty->assign('errors', $errors);
-$smarty->assign('messages', $messages);
+$smarty->assign('err', $err);
+$smarty->assign('msg', $msg);
+
+// TODO: move this code out of here to the files that use it.
 
-// TODO: move this code out of here to the files that use it. 
-  
 // We use js/strftime.js to print dates in JavaScript (in DateField controls).
 // One of our date formats (%d.%m.%Y %a) prints a localized short weekday name (%a).
 // The init_js_date_locale function iniitializes Date.ext.locales array in js/strftime.js for our language
@@ -248,4 +232,3 @@ function init_js_date_locale()
     };";
   $smarty->assign('js_date_locale', $js);
 }
-?>
\ No newline at end of file