thomascube
2005-11-18 fbf77b4493f1b77c99751d8a86365c712ae3fb1b
program/include/main.inc
@@ -40,12 +40,16 @@
  include_once('config/db.inc.php');
  $CONFIG = array_merge($CONFIG, $rcmail_config);
  if (empty($CONFIG['log_dir']))
    $CONFIG['log_dir'] = $INSTALL_PATH.'logs';
  else
    $CONFIG['log_dir'] = ereg_replace('\/$', '', $CONFIG['log_dir']);
  // set PHP error logging according to config
  if ($CONFIG['debug_level'] & 1)
    {
    ini_set('log_errors', 1);
    ini_set('error_log', $INSTALL_PATH.'logs/errors');
    ini_set('error_log', $CONFIG['log_dir'].'/errors');
    }
  if ($CONFIG['debug_level'] & 4)
    ini_set('display_errors', 1);
@@ -64,7 +68,8 @@
  $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql';
  // we can use the database for storing session data
  if (is_object($DB) && $DB->db_provider!='sqlite')
  // session queries do not work with MDB2
  if ($CONFIG['db_backend']!='mdb2' && is_object($DB) && $DB->db_provider!='sqlite')
    include_once('include/session.inc');
@@ -226,7 +231,7 @@
// init output object for GUI and add common scripts
function load_gui()
  {
  global $CONFIG, $OUTPUT, $COMM_PATH, $IMAP, $JS_OBJECT_NAME;
  global $CONFIG, $OUTPUT, $COMM_PATH, $JS_OBJECT_NAME, $sess_user_lang;
  // init output page
  $OUTPUT = new rcube_html_page();
@@ -237,11 +242,42 @@
  if (!empty($GLOBALS['_framed']))
    $javascript .= "$JS_OBJECT_NAME.set_env('framed', true);\n";
  $OUTPUT->add_script($javascript);
  $OUTPUT->include_script('program/js/common.js');
  $OUTPUT->include_script('program/js/app.js');
  $OUTPUT->include_script('program/js/app.js');
  // set user-selected charset
  if ($CONFIG['charset'])
    $OUTPUT->set_charset($CONFIG['charset']);
  else
    rcmail_set_locale($sess_user_lang);
  // add some basic label to client
  rcube_add_label('loading');
  }  
// set localization charset based on the given language
function rcmail_set_locale($lang)
  {
  global $OUTPUT, $INSTLL_PATH, $CHARSET;
  static $rcube_charsets;
  if (!$rcube_charsets)
    @include($INSTLL_PATH.'program/localization/index.inc');
  if (isset($rcube_charsets[$lang]))
    {
    $OUTPUT->set_charset($rcube_charsets[$lang]);
    $CHARSET = $rcube_charsets[$lang];
    }
  else
    {
    $OUTPUT->set_charset('ISO-8859-1');
    $CHARSET = 'ISO-8859-1';
    }
  }
// perfom login to the IMAP server and to the webmail service
@@ -263,13 +299,12 @@
    }
  // query if user already registered
  $sql_result = $DB->query(sprintf("SELECT user_id, username, language, preferences
                                    FROM   %s
                                    WHERE  mail_host='%s' AND (username='%s' OR alias='%s')",
                                   get_table_name('users'),
                                   addslashes($host),
                                   addslashes($user),
                                   addslashes($user)));
  $sql_result = $DB->query("SELECT user_id, username, language, preferences
                            FROM ".get_table_name('users')."
                            WHERE  mail_host=? AND (username=? OR alias=?)",
                            $host,
                            $user,
                            $user);
  // user already registered -> overwrite username
  if ($sql_arr = $DB->fetch_assoc($sql_result))
@@ -299,11 +334,10 @@
      $sess_user_lang = $_SESSION['user_lang'] = $sql_arr['language'];
      
    // update user's record
    $DB->query(sprintf("UPDATE %s
                        SET    last_login=NOW()
                        WHERE  user_id=%d",
                       get_table_name('users'),
                       $user_id));
    $DB->query("UPDATE ".get_table_name('users')."
                SET    last_login=now()
                WHERE  user_id=?",
                $user_id);
    }
  // create new system user
  else if ($CONFIG['auto_create_user'])
@@ -336,27 +370,25 @@
  {
  global $DB, $CONFIG, $IMAP;
  
  $DB->query(sprintf("INSERT INTO %s
                      (created, last_login, username, mail_host, language)
                      VALUES (NOW(), NOW(), '%s', '%s', '%s')",
                     get_table_name('users'),
                     addslashes($user),
                     addslashes($host),
                   $_SESSION['user_lang']));
  $DB->query("INSERT INTO ".get_table_name('users')."
              (created, last_login, username, mail_host, language)
              VALUES (now(), now(), ?, ?, ?)",
              $user,
              $host,
            $_SESSION['user_lang']);
  if ($user_id = $DB->insert_id())
  if ($user_id = $DB->insert_id('user_ids'))
    {
    $user_email = strstr($user, '@') ? $user : sprintf('%s@%s', $user, $host);
    $user_name = $user!=$user_email ? $user : '';
    
    // also create a new identity record
    $DB->query(sprintf("INSERT INTO %s
                        (user_id, `default`, name, email)
                        VALUES (%d, '1', '%s', '%s')",
                       get_table_name('identities'),
                       $user_id,
                       addslashes($user_name),
                       addslashes($user_email)));
    $DB->query("INSERT INTO ".get_table_name('identities')."
                (user_id, `default`, name, email)
                VALUES (?, '1', ?, ?)",
                $user_id,
                $user_name,
                $user_email);
                       
    // get existing mailboxes
    $a_mailboxes = $IMAP->list_mailboxes();
@@ -379,6 +411,16 @@
    }
    
  return $user_id;
  }
// overwrite action variable
function rcmail_overwrite_action($action)
  {
  global $OUTPUT, $JS_OBJECT_NAME;
  $GLOBALS['_action'] = $action;
  $OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $action));
  }
@@ -451,7 +493,7 @@
  if (!sizeof($sa_languages))
    {
    @include_once($INSTLL_PATH.'program/localization/index.inc');
    @include($INSTLL_PATH.'program/localization/index.inc');
    if ($dh = @opendir($INSTLL_PATH.'program/localization'))
      {
@@ -468,6 +510,20 @@
    }
  return $sa_languages;
  }
// add a localized label to the client environment
function rcube_add_label()
  {
  global $OUTPUT, $JS_OBJECT_NAME;
  $arg_list = func_get_args();
  foreach ($arg_list as $i => $name)
    $OUTPUT->add_script(sprintf("%s.add_label('%s', '%s');",
                                $JS_OBJECT_NAME,
                                $name,
                                rep_specialchars_output(rcube_label($name), 'js')));
  }
@@ -527,6 +583,7 @@
// replace all strings ($varname) with the content of the according global variable
function parse_with_globals($input)
  {
  $GLOBALS['__comm_path'] = $GLOBALS['COMM_PATH'];
  $output = preg_replace('/\$(__[a-z0-9_\-]+)/e', '$GLOBALS["\\1"]', $input);
  return $output;
  }
@@ -951,8 +1008,10 @@
  
  if (is_numeric($date))
    $ts = $date;
  else
  else if (!empty($date))
    $ts = strtotime($date);
  else
    return '';
  // convert time to user's timezone
  $timestamp = $ts - date('Z', $ts) + ($CONFIG['timezone'] * 3600);