Location: PHPKode > projects > IntraMessenger > common/functions.inc.php
<?php
/*******************************************************
 **                  IntraMessenger - server          **
 **                                                   **
 **  Copyright:      (C) 2006 - 2011 THeUDS           **
 **  Web:            http://www.theuds.com            **
 **                  http://www.intramessenger.net    **
 **  Licence :       GPL (GNU Public License)         **
 **  http://opensource.org/licenses/gpl-license.php   **
 *******************************************************/

/*******************************************************
 **       This file is part of IntraMessenger-server  **
 **                                                   **
 **  IntraMessenger is a free software.               **
 **  IntraMessenger is distributed in the hope that   **
 **  it will be useful, but WITHOUT ANY WARRANTY.     **
 *******************************************************/
//

if ( !defined('INTRAMESSENGER') )
{
  exit;
}


function prevent_error_option_missing()
{
  if (!defined("_LANG"))                                          define("_LANG", "EN");
  if (!defined("_MAINTENANCE_MODE"))                              define("_MAINTENANCE_MODE", "X");
  if (!defined("_MAX_NB_USER"))                                   define("_MAX_NB_USER", "0");
  if (!defined("_MAX_NB_SESSION"))                                define("_MAX_NB_SESSION", "0");
  if (!defined("_MAX_NB_CONTACT_BY_USER"))                        define("_MAX_NB_CONTACT_BY_USER", "0");
  if (!defined("_MAX_NB_IP"))                                     define("_MAX_NB_IP", "0");
  if (!defined("_DISPLAY_USER_FLAG_COUNTRY"))                     define("_DISPLAY_USER_FLAG_COUNTRY", "");
  if (!defined("_OUTOFDATE_AFTER_X_DAYS_NOT_USE"))                define("_OUTOFDATE_AFTER_X_DAYS_NOT_USE", "90");
  if (!defined("_CHECK_NEW_MSG_EVERY"))                           define("_CHECK_NEW_MSG_EVERY", "30");
  if (!defined("_FULL_CHECK"))                                    define("_FULL_CHECK", "");
  if (!defined("_STATISTICS"))                                    define("_STATISTICS", "");
  if (!defined("_PUBLIC_FOLDER"))                                 define("_PUBLIC_FOLDER", "public");
  if (!defined("_PUBLIC_OPTIONS_LIST"))                           define("_PUBLIC_OPTIONS_LIST", "");
  if (!defined("_PUBLIC_USERS_LIST"))                             define("_PUBLIC_USERS_LIST", "");
  if (!defined("_PUBLIC_POST_AVATAR"))                            define("_PUBLIC_POST_AVATAR", "");
  if (!defined("_FORCE_USERNAME_TO_PC_SESSION_NAME"))             define("_FORCE_USERNAME_TO_PC_SESSION_NAME", "");
  if (!defined("_ALLOW_CONFERENCE"))                              define("_ALLOW_CONFERENCE", "");
  if (!defined("_ALLOW_INVISIBLE"))                               define("_ALLOW_INVISIBLE", "");
  if (!defined("_ALLOW_SMILEYS"))                                 define("_ALLOW_SMILEYS", "");
  if (!defined("_ALLOW_CHANGE_CONTACT_NICKNAME"))                 define("_ALLOW_CHANGE_CONTACT_NICKNAME", "");
  if (!defined("_ALLOW_CHANGE_EMAIL_PHONE"))                      define("_ALLOW_CHANGE_EMAIL_PHONE", "");
  if (!defined("_ALLOW_CHANGE_FUNCTION_NAME"))                    define("_ALLOW_CHANGE_FUNCTION_NAME", "");
  if (!defined("_ALLOW_CHANGE_AVATAR"))                           define("_ALLOW_CHANGE_AVATAR", "");
  if (!defined("_ALLOW_SEND_TO_OFFLINE_USER"))                    define("_ALLOW_SEND_TO_OFFLINE_USER", "");
  if (!defined("_ALLOW_USER_TO_HISTORY_MESSAGES"))                define("_ALLOW_USER_TO_HISTORY_MESSAGES", "");
  if (!defined("_ALLOW_USE_PROXY"))                               define("_ALLOW_USE_PROXY", "");
  if (!defined("_ALLOW_USER_RATING"))                             define("_ALLOW_USER_RATING", "");
  if (!defined("_ALLOW_EMAIL_NOTIFIER"))                          define("_ALLOW_EMAIL_NOTIFIER", "");
  if (!defined("_INCOMING_EMAIL_SERVER_ADDRESS"))                 define("_INCOMING_EMAIL_SERVER_ADDRESS", "");
  if (!defined("_FORCE_AWAY_ON_SCREENSAVER"))                     define("_FORCE_AWAY_ON_SCREENSAVER", "");
  if (!defined("_HIDE_COL_FUNCTION_NAME"))                        define("_HIDE_COL_FUNCTION_NAME", "");
  if (!defined("_USER_HIEARCHIC_MANAGEMENT_BY_ADMIN"))            define("_USER_HIEARCHIC_MANAGEMENT_BY_ADMIN", "");
  if (!defined("_LOCK_USER_CONTACT_LIST"))                        define("_LOCK_USER_CONTACT_LIST", "");
  if (!defined("_LOCK_USER_OPTIONS"))                             define("_LOCK_USER_OPTIONS", "");
  if (!defined("_FORCE_STATUS_LIST_FROM_SERVER"))                 define("_FORCE_STATUS_LIST_FROM_SERVER", "");
  if (!defined("_AWAY_REASONS_LIST"))                             define("_AWAY_REASONS_LIST", "");
  if (!defined("_MINIMUM_USERNAME_LENGTH"))                       define("_MINIMUM_USERNAME_LENGTH", "4");
  if (!defined("_USER_NEED_PASSWORD"))                            define("_USER_NEED_PASSWORD", "");
  if (!defined("_MINIMUM_PASSWORD_LENGTH"))                       define("_MINIMUM_PASSWORD_LENGTH", "4");
  if (!defined("_MAX_PASSWORD_ERRORS_BEFORE_LOCK_USER"))          define("_MAX_PASSWORD_ERRORS_BEFORE_LOCK_USER", "5");
  if (!defined("_ALLOW_AUTO_ADD_NEW_USER_ON_SERVER"))             define("_ALLOW_AUTO_ADD_NEW_USER_ON_SERVER", "");
  if (!defined("_PENDING_NEW_AUTO_ADDED_USER"))                   define("_PENDING_NEW_AUTO_ADDED_USER", "");
  if (!defined("_PENDING_USER_ON_COMPUTER_CHANGE"))               define("_PENDING_USER_ON_COMPUTER_CHANGE", "");
  if (!defined("_CRYPT_MESSAGES"))                                define("_CRYPT_MESSAGES", "");
  if (!defined("_LOG_MESSAGES"))                                  define("_LOG_MESSAGES", "");
  if (!defined("_LOG_SESSION_OPEN"))                              define("_LOG_SESSION_OPEN", "");
  if (!defined("_PASSWORD_FOR_PRIVATE_SERVER"))                   define("_PASSWORD_FOR_PRIVATE_SERVER", "");
  if (!defined("_FORCE_UPDATE_BY_SERVER"))                        define("_FORCE_UPDATE_BY_SERVER", "");
  if (!defined("_FORCE_UPDATE_BY_INTERNET"))                      define("_FORCE_UPDATE_BY_INTERNET", "");
  if (!defined("_SEND_ADMIN_ALERT"))                              define("_SEND_ADMIN_ALERT", "");
  if (!defined("_PROXY_ADDRESS"))                                 define("_PROXY_ADDRESS", "");
  if (!defined("_PROXY_PORT_NUMBER"))                             define("_PROXY_PORT_NUMBER", "");
  if (!defined("_SITE_URL_TO_SHOW"))                              define("_SITE_URL_TO_SHOW", "");
  if (!defined("_SITE_TITLE_TO_SHOW"))                            define("_SITE_TITLE_TO_SHOW", "");
  if (!defined("_SCROLL_TEXT"))                                   define("_SCROLL_TEXT", "");
  if (!defined("_ADMIN_EMAIL"))                                   define("_ADMIN_EMAIL", "");
  if (!defined("_ADMIN_PHONE"))                                   define("_ADMIN_PHONE", "");
  if (!defined("_ENTERPRISE_SERVER"))                             define("_ENTERPRISE_SERVER", "");
  if (!defined("_IM_ADDRESS_BOOK_PASSWORD"))                      define("_IM_ADDRESS_BOOK_PASSWORD", "");
  //if (!defined("_GROUP_FOR_ADMIN_MESSAGES"))                      define("_GROUP_FOR_ADMIN_MESSAGES", "");
  if (!defined("_SPECIAL_MODE_OPEN_COMMUNITY"))                   define("_SPECIAL_MODE_OPEN_COMMUNITY", "");
  if (!defined("_SPECIAL_MODE_GROUP_COMMUNITY"))                  define("_SPECIAL_MODE_GROUP_COMMUNITY", "");
  if (!defined("_EXTERN_URL_TO_REGISTER"))                        define("_EXTERN_URL_TO_REGISTER", "");
  if (!defined("_EXTERN_URL_FORGET_PASSWORD"))                    define("_EXTERN_URL_FORGET_PASSWORD", "");
  if (!defined("_EXTERN_URL_CHANGE_PASSWORD"))                    define("_EXTERN_URL_CHANGE_PASSWORD", "");
  if (!defined("_STOP_USE_THIS_SERVER_ADDRESS_NOW_USE_THIS_URL")) define("_STOP_USE_THIS_SERVER_ADDRESS_NOW_USE_THIS_URL", "");
  if (!defined("_EXTERNAL_AUTHENTICATION"))                       define("_EXTERNAL_AUTHENTICATION", "");
  if (!defined("_NEED_QUICK_REGISTER_TO_AUTO_ADD_NEW_USER"))      define("_NEED_QUICK_REGISTER_TO_AUTO_ADD_NEW_USER", "");
  if (!defined("_SITE_TITLE"))                                    define("_SITE_TITLE", "");
  if (!defined("_ALLOW_UPPERCASE_SPACE_USERNAME"))                define("_ALLOW_UPPERCASE_SPACE_USERNAME", "");
  if (!defined("_CENSOR_MESSAGES"))                               define("_CENSOR_MESSAGES", "");
  if (!defined("_PWD_NEED_DIGIT_LETTER"))                         define("_PWD_NEED_DIGIT_LETTER", "");
  if (!defined("_PWD_NEED_UPPER_LOWER"))                          define("_PWD_NEED_UPPER_LOWER", "");
  if (!defined("_PWD_NEED_SPECIAL_CHARACTER"))                    define("_PWD_NEED_SPECIAL_CHARACTER", "");
  if (!defined("_SHOUTBOX"))                                      define("_SHOUTBOX", "");
  if (!defined("_SHOUTBOX_REFRESH_DELAY"))                        define("_SHOUTBOX_REFRESH_DELAY", "60");
  if (!defined("_SHOUTBOX_STORE_DAYS"))                           define("_SHOUTBOX_STORE_DAYS", "30");
  if (!defined("_SHOUTBOX_STORE_MAX"))                            define("_SHOUTBOX_STORE_MAX", "200");
  if (!defined("_SHOUTBOX_QUOTA_USER_DAY"))                       define("_SHOUTBOX_QUOTA_USER_DAY", "50");
  if (!defined("_SHOUTBOX_QUOTA_USER_WEEK"))                      define("_SHOUTBOX_QUOTA_USER_WEEK", "100");
  if (!defined("_SHOUTBOX_NEED_APPROVAL"))                        define("_SHOUTBOX_NEED_APPROVAL", "");
  if (!defined("_SHOUTBOX_APPROVAL_QUEUE_USER"))                  define("_SHOUTBOX_APPROVAL_QUEUE_USER", "3");
  if (!defined("_SHOUTBOX_APPROVAL_QUEUE"))                       define("_SHOUTBOX_APPROVAL_QUEUE", "10");
  if (!defined("_SHOUTBOX_LOCK_USER_APPROVAL"))                   define("_SHOUTBOX_LOCK_USER_APPROVAL", "0");
  if (!defined("_SHOUTBOX_VOTE"))                                 define("_SHOUTBOX_VOTE", "");
  if (!defined("_SHOUTBOX_MAX_NOTES_USER_DAY"))                   define("_SHOUTBOX_MAX_NOTES_USER_DAY", "0");
  if (!defined("_SHOUTBOX_MAX_NOTES_USER_WEEK"))                  define("_SHOUTBOX_MAX_NOTES_USER_WEEK", "0");
  if (!defined("_SHOUTBOX_REMOVE_MESSAGE_VOTES"))                 define("_SHOUTBOX_REMOVE_MESSAGE_VOTES", "0");
  if (!defined("_SHOUTBOX_LOCK_USER_VOTES"))                      define("_SHOUTBOX_LOCK_USER_VOTES", "0");
  if (!defined("_GROUP_USER_CAN_JOIN"))                           define("_GROUP_USER_CAN_JOIN", "");
  if (!defined("_GROUP_FOR_SBX_AND_ADMIN_MSG"))                   define("_GROUP_FOR_SBX_AND_ADMIN_MSG", "");
  if (!defined("_SERVERS_STATUS"))                                define("_SERVERS_STATUS", "");
  if (!defined("_CHECK_VERSION_INTERNET"))                        define("_CHECK_VERSION_INTERNET", "X");
  if (!defined("_TIME_ZONES"))                                    define("_TIME_ZONES", "X");
  if (!defined("_SHOUTBOX_PUBLIC"))                               define("_SHOUTBOX_PUBLIC", "");
  if (!defined("_BOOKMARKS"))                                     define("_BOOKMARKS", "");
  if (!defined("_BOOKMARKS_VOTE"))                                define("_BOOKMARKS_VOTE", "");
  if (!defined("_BOOKMARKS_PUBLIC"))                              define("_BOOKMARKS_PUBLIC", "");
  if (!defined("_BOOKMARKS_NEED_APPROVAL"))                       define("_BOOKMARKS_NEED_APPROVAL", "");
  if (!defined("_LOCK_DURATION"))                                 define("_LOCK_DURATION", "");
  if (!defined("_UNREAD_MESSAGE_VALIDITY"))                       define("_UNREAD_MESSAGE_VALIDITY", "");
  if (!defined("_LOCK_AFTER_NO_CONTACT_DURATION"))                define("_LOCK_AFTER_NO_CONTACT_DURATION", "");
  if (!defined("_LOCK_AFTER_NO_ACTIVITY_DURATION"))               define("_LOCK_AFTER_NO_ACTIVITY_DURATION", "");
  if (!defined("_LOCK_USER_PROFILE"))                             define("_LOCK_USER_PROFILE", "");
  if (!defined("_INVITE_FILL_PROFILE_ON_FIRST_LOGIN"))            define("_INVITE_FILL_PROFILE_ON_FIRST_LOGIN", "");
  if (!defined("_ROLES_TO_OVERRIDE_PERMISSIONS"))                 define("_ROLES_TO_OVERRIDE_PERMISSIONS", "");
  if (!defined("_WAIT_STARTUP_IF_SERVER_UNAVAILABLE"))            define("_WAIT_STARTUP_IF_SERVER_UNAVAILABLE", "");
  if (!defined("_ONLINE_REASONS_LIST"))                           define("_ONLINE_REASONS_LIST", "");
  if (!defined("_BUSY_REASONS_LIST"))                             define("_BUSY_REASONS_LIST", "");
  if (!defined("_DONOTDISTURB_REASONS_LIST"))                     define("_DONOTDISTURB_REASONS_LIST", "");
}


if (!function_exists('ctype_alnum')) 
{
  function ctype_alnum($text) 
  {
    return !preg_match('/^\w*$/', $text);
  }
}


function f_quote($txt)
{
	$txt = str_replace("'", "&#146;", $txt);
  //
  return $txt;
}


function f_language_of_country($country_code, $default)
{
  GLOBAL $lang;
  //
  if (!isset($l_lng['FR'])) require("lang.inc.php");
  //if ($l_lng[$country_code] != '')
  if (isset($l_lng[$country_code]))
    return $l_lng[$country_code];
  else
    return $default;
}


function f_user_local_time($time_shit)
{
  GLOBAL $l_time_format_display, $l_time_short_format_display;
  //
  if ($l_time_short_format_display == '') $l_time_short_format_display = $l_time_format_display;
  if ($l_time_short_format_display == '') $l_time_short_format_display = 'H:i';
  //
  $time_shit = ($time_shit / 10);
  $tlocal = time() + ($time_shit * 60 * 60);
  //
  return date($l_time_short_format_display, $tlocal);
}


function update_check_user($t_id_user, $t_check)
{
  global $PREFIX_IM_TABLE;
  //
  $t_id_user = intval($t_id_user);
  if ($t_id_user > 0)
  {
    $requete  = " update " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " SET USR_CHECK = '" . $t_check . "' ";
    if ($t_check == "WAIT") $requete .= " , USR_STATUS = 2 "; // locked
    if ($t_check == "") $requete .= " , USR_STATUS = 3 "; // chang conf ok
    if (strlen($t_check) > 10) $requete .= " , USR_STATUS = 1 "; // OK
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $requete .= " LIMIT 1 "; // (to protect)
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1a]", $requete);
  }
}


function update_last_activity_user($t_id_user)
{
  global $PREFIX_IM_TABLE;
  //
  $t_id_user = intval($t_id_user);
  if ($t_id_user > 0)
  {
    $requete  = " update " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " SET USR_DATE_ACTIVITY= CURDATE()  ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $requete .= " LIMIT 1 "; // (to protect)
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1j]", $requete);
  }
}


function f_verif_check_user_only($t_id_user, $t_check)
{
  global $PREFIX_IM_TABLE;
  //
	$retour = 'KO'; // par défaut
  $t_id_user = intval($t_id_user);
  if ($t_id_user > 0)
  {
    $requete  = " select USR_CHECK ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1b]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($usr_check) = mysql_fetch_row ($result);
      if ($usr_check == $t_check) 
        $retour = 'OK';
      else
        write_log("log_reject_check_user", $t_id_user . ";" . $usr_check . ";" . $t_check);
    }
  }
	return $retour;
}
	

function f_get_nom_user($t_user)  # f_get_user_name(
{
  global $PREFIX_IM_TABLE;
  //
	$retour = "";
	$t_user = str_replace("'", "", $t_user);
	if ($t_user != '')
	{
    $requete  = " select USR_NAME ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE USR_USERNAME = '" . $t_user . "' ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1f]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($usr_nom) = mysql_fetch_row ($result);
      $retour = $usr_nom;
    }
  }
	return $retour;
}


function f_get_id_nom_user($t_user)  # f_get_id_of_username
{
  global $PREFIX_IM_TABLE;
  //
	$retour = "";
	$t_user = str_replace("'", "", $t_user);
	if ($t_user != '')
	{
    $requete  = " select ID_USER, USR_USERNAME ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE USR_USERNAME = '" . $t_user . "' ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1g]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($id_usr, $usr_name) = mysql_fetch_row ($result);
      if ($usr_name == $t_user) $retour = $id_usr;
    }
  }
	return $retour;
}


function f_get_username_of_id($t_id_user)
{
  global $PREFIX_IM_TABLE;
  //
	$retour = "";
  $t_id_user = intval($t_id_user);
	if ($t_id_user > 0)
	{
    $requete  = " select USR_USERNAME ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1h]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($usrname) = mysql_fetch_row ($result);
      $retour = $usrname;
    }
  }
	return $retour;
}


function f_get_username_nickname_of_id($t_id_user)
{
  global $PREFIX_IM_TABLE;
  //
	$retour = "";
  $t_id_user = intval($t_id_user);
	if ($t_id_user > 0)
	{
    $requete  = " select USR_NICKNAME, USR_USERNAME ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1h2]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($nickname, $usrname) = mysql_fetch_row ($result);
      $retour = $usrname;
      if ($nickname != "") $retour = $nickname;
    }
  }
	return $retour;
}


function f_get_id_of_renamed_nickname($t_nick) 
{
  global $PREFIX_IM_TABLE;
  //
	$retour = "";
	$t_nick = str_replace("'", "", $t_nick);
	if ($t_nick != '')
	{
    $requete  = " select ID_USER_2 ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "CNT_CONTACT ";
    $requete .= " WHERE CNT_NEW_USERNAME = '" . $t_nick . "' ";
    $requete .= " and CNT_NEW_USERNAME <> '' ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1i]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($id_usr) = mysql_fetch_row ($result);
      $retour = $id_usr;
    }
  }
	return $retour;
}


function f_is_deja_in_contacts_id($t_id_u_1, $t_id_u_2)  # f_is_already_in_contacts_id
{
  global $PREFIX_IM_TABLE;
  //
  $t_id_u_1 = intval($t_id_u_1);
  $t_id_u_2 = intval($t_id_u_2);
  if ( ($t_id_u_1 > 0) and ($t_id_u_2 > 0) )
  {
    $requete  = " select CNT.ID_CONTACT, USR.USR_USERNAME, USR.USR_NAME, CNT.CNT_STATUS ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "CNT_CONTACT CNT, " . $PREFIX_IM_TABLE . "USR_USER USR ";
    $requete .= " WHERE USR.ID_USER = CNT.ID_USER_2 ";
    $requete .= " and CNT.ID_USER_1 = " . $t_id_u_1 . " ";
    $requete .= " and CNT.ID_USER_2 = '" . $t_id_u_2 . "' ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1k]", $requete);
    //
    return mysql_num_rows($result);
  }
  else
    return 0;
}


function f_nb_users()
{
  global $PREFIX_IM_TABLE;
  //
	$requete  = " select count(*) ";
	$requete .= " from " . $PREFIX_IM_TABLE . "USR_USER ";
	$result = mysql_query($requete);
	if (!$result) error_sql_log("[ERR-M1m]", $requete);
	list ($nb_user) = mysql_fetch_row ($result);
	if (intval($nb_user) <= 0) $nb_user = 0;
	//
	return $nb_user;
}


function f_if_already_max_nb_users()
{
	$ret = '0'; // OK
	if (intval(_MAX_NB_USER) > 0)
	{
    $nb_user = f_nb_users();
    if ($nb_user >= intval(_MAX_NB_USER))
      $ret = $nb_user;  // Ko
  }
  return $ret;
}


function f_update_pass_user($t_id_user, $t_new_pass)
{
  global $PREFIX_IM_TABLE;
  //
	$retour = 'KO';
  $t_id_user = intval($t_id_user);
	if ($t_id_user > 0)
	{
    $passcr = "";
    if (_USER_NEED_PASSWORD != '')
    {
      if ($t_new_pass != '')
      {
        require("config/auth.inc.php");
        $passcr = sha1($password_pepper . $t_new_pass . "W$*7B0-c6");
      }	
    }	
    $requete  = " update " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " SET USR_PASSWORD = '" . $passcr . "', ";
    $requete .= " USR_DATE_PASSWORD = CURDATE(), USR_DATE_ACTIVITY= CURDATE() ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $requete .= " LIMIT 1 "; // (to protect)
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1m]", $requete);
    //
    // On vérifie que la maj est correcte
    $requete  = " select USR_PASSWORD ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1n]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($usr_pass) = mysql_fetch_row ($result);
      if ( (_USER_NEED_PASSWORD == '') or ($usr_pass == $passcr) )
        $retour = "OK";
    }
  }
	//
	return $retour;
}


function f_level_of_user($t_id_user)
{
  global $PREFIX_IM_TABLE;
  //
	$retour = "";
  $t_id_user = intval($t_id_user);
	if ($t_id_user > 0)
	{
    $requete  = " select USR_LEVEL ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER ";
    $requete .= " WHERE ID_USER = " . $t_id_user . " ";
    $requete .= " and USR_STATUS = 1 ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1p]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($usr_level) = mysql_fetch_row ($result);
      $retour = $usr_level;
    }
  }
	return $retour;
}


function send_alert_message_to_admins($txt)
{
  global $PREFIX_IM_TABLE;
  //
  $txt = str_replace("'", "`", $txt);
  if (_SEND_ADMIN_ALERT != "")
  {
    $requete  = " select distinct(USR.ID_USER) ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER USR, " . $PREFIX_IM_TABLE . "SES_SESSION SES";
    $requete .= " WHERE SES.ID_USER = USR.ID_USER ";
    $requete .= " AND USR_GET_ADMIN_ALERT = 1 ";
    $requete .= " and USR.USR_STATUS = 1 ";
    $requete .= " AND SES.SES_STATUS > 0 ";
    //$requete .= " AND SES.SES_STATUS < 5 ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1q]", $requete);
    if ( mysql_num_rows($result) > 0 )
    {
      while( list ($id_u_dest) = mysql_fetch_row ($result) )
      {
        send_alert_message_to_admins_2($id_u_dest, $txt);
      }
    }
    //
    if (_ROLES_TO_OVERRIDE_PERMISSIONS != "")
    {
      $requete  = " select distinct(USR.ID_USER) ";
      $requete .= " FROM " . $PREFIX_IM_TABLE . "USR_USER USR, " . $PREFIX_IM_TABLE . "RLM_ROLEMODULE RLM, " . $PREFIX_IM_TABLE . "SES_SESSION SES";
      $requete .= " WHERE SES.ID_USER = USR.ID_USER ";
      $requete .= " AND USR.ID_ROLE = RLM.ID_ROLE ";
      $requete .= " and USR.USR_STATUS = 1 ";
      $requete .= " AND RLM.ID_MODULE = 70 "; // 70 : ROLE_GET_ADMIN_ALERT_MESSAGES
      $requete .= " AND RLM.RLM_STATE = 2 ";  // 2 : role actif
      $requete .= " AND SES.SES_STATUS > 0 ";
      //$requete .= " AND SES.SES_STATUS < 5 ";
      $result = mysql_query($requete);
      if (!$result) error_sql_log("[ERR-M1t]", $requete);
      if ( mysql_num_rows($result) > 0 )
      {
        while( list ($id_u_dest) = mysql_fetch_row ($result) )
        {
          send_alert_message_to_admins_2($id_u_dest, $txt);
        }
      }
    }
  }
}


function send_alert_message_to_admins_2($id_u_dest, $txt)
{
  global $PREFIX_IM_TABLE;
  //
  // Pour éviter les doublons :
  $send_already = "";
  $requete  = " select ID_USER_DEST ";
  $requete .= " FROM " . $PREFIX_IM_TABLE . "MSG_MESSAGE ";
  $requete .= " WHERE ID_USER_AUT = -99 ";
  $requete .= " and ID_USER_DEST = " . $id_u_dest;
  $requete .= " and MSG_TEXT = '" . f_encode64($txt) . "' ";
  $requete .= " limit 2 ";
  $result2 = mysql_query($requete);
  if (!$result2) error_sql_log("[ERR-M1u]", $requete);
  if ( mysql_num_rows($result2) > 0 ) $send_already = "X";
  if ($send_already == "")
  {
    $requete  = " INSERT INTO " . $PREFIX_IM_TABLE . "MSG_MESSAGE ( ID_USER_AUT, ID_USER_DEST, MSG_TEXT, MSG_CR, MSG_TIME, MSG_DATE) ";
    $requete .= " VALUES (-99, " . $id_u_dest . ", '" . f_encode64($txt) . "', '64', CURTIME(), CURDATE() ) ";
    $result3 = mysql_query($requete);
    if (!$result3) error_sql_log("[ERR-M1r]", $requete);
  }
}


function f_is_banned_user_ip_pc($tvalue, $type) // $type : 'U' or 'I' or 'P' (Username IP PC)
{
  global $PREFIX_IM_TABLE;
  //
  if ( (strlen($type) == 1) and (strlen($tvalue) > 2) )
  {
    $requete  = " select BAN_VALUE ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "BAN_BANNED ";
    $requete .= " WHERE BAN_TYPE = '" . $type . "' ";
    $requete .= " and '" . $tvalue . "' like LOWER(BAN_VALUE) ";
    $requete .= " limit 2 ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-M1s]", $requete);
    if ( mysql_num_rows($result) > 0 )
      return true;
    else
      return false;
   }
   else
     return false;
}



function f_nb_days_usage_max()
{
  global $PREFIX_IM_TABLE;
  //
	$requete  = " select max(USR_NB_CONNECT) ";
	$requete .= " from " . $PREFIX_IM_TABLE . "USR_USER ";
	$result = mysql_query($requete);
	if (!$result) error_sql_log("[ERR-M1T]", $requete);
	list ($nb_days) = mysql_fetch_row ($result);
	if (intval($nb_days) < 10) $nb_days = 0;
	//
	return $nb_days;
}


function f_servers_status()
{
  global $PREFIX_IM_TABLE;
  //
  $lst = "";
  $requete  = " SELECT SRV_STATE, SRV_NAME ";
  $requete .= " FROM " . $PREFIX_IM_TABLE . "SRV_SERVERSTATE ";
  $requete .= " ORDER BY UPPER(SRV_NAME) ";
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-M1Tzzzzz]", $requete);
  $nb_lig = mysql_num_rows($result);
  if ( $nb_lig > 0 )
  {
    $lst = $nb_lig . "%";
    while( list ($status, $srv_name) = mysql_fetch_row ($result) )
    {
      $lst .= $status . "%";
    }
  }
	//
	return $lst;
}


function delete_user($id_user)
{
  global $PREFIX_IM_TABLE;
  //
  // lock :
  $requete  = " update " . $PREFIX_IM_TABLE . "USR_USER ";
  $requete .= " set USR_STATUS = 2, USR_TIME_LOCK = '00:00:00' "; // locked
  $requete .= " WHERE ID_USER = " . $id_user;
  $requete .= " limit 1 "; // (to protect)
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4k]", $requete);
  //
  // Suppression sessions
  $requete  = " delete FROM " . $PREFIX_IM_TABLE . "SES_SESSION ";
  $requete .= " WHERE ID_USER = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4a]", $requete);
  //
  $requete  = " delete FROM " . $PREFIX_IM_TABLE . "CNF_CONFERENCE ";
  $requete .= " WHERE ID_USER = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4j]", $requete);
  //
  // contacts
  $requete  = " delete FROM " . $PREFIX_IM_TABLE . "CNT_CONTACT ";
  $requete .= " WHERE ID_USER_1 = " . $id_user . " ";
  $requete .= " or ID_USER_2 = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4b]", $requete);
  //
  // sa présence dans les groupes
  $requete  = " delete FROM " . $PREFIX_IM_TABLE . "USG_USERGRP ";
  $requete .= " WHERE ID_USER = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4c]", $requete);
  //
  // Suppression des messages
  $requete  = " delete FROM " . $PREFIX_IM_TABLE . "MSG_MESSAGE ";
  $requete .= " WHERE ID_USER_AUT = " . $id_user;
  $requete .= " or ID_USER_DEST = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4d]", $requete);
  //
  // ShoutBox
  $requete  = " delete from " . $PREFIX_IM_TABLE . "SBV_SHOUTVOTE ";
  $requete .= " where ID_USER_AUT = " . $id_user;
  $requete .= " or ID_USER_VOTE = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4f]", $requete);
  //
  $requete  = " delete from " . $PREFIX_IM_TABLE . "SBS_SHOUTSTATS ";
  $requete .= " where ID_USER_AUT = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4g]", $requete);
  //
  $requete  = " delete from " . $PREFIX_IM_TABLE . "SBX_SHOUTBOX ";
  $requete .= " where ID_USER_AUT = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4h]", $requete);
  //
  // Bookmarks
  $requete  = " delete from " . $PREFIX_IM_TABLE . "BMV_BOOKMVOTE ";
  $requete .= " where ID_USER_VOTE = " . $id_user;
  $requete .= " or ID_USER_AUT = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4m]", $requete);
  //
  $requete  = " delete from " . $PREFIX_IM_TABLE . "BMK_BOOKMARK ";
  $requete .= " where ID_USER_AUT = " . $id_user;
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4n]", $requete);
  //
  //
  // Suppression du compte
  $requete  = " delete FROM " . $PREFIX_IM_TABLE . "USR_USER ";
  $requete .= " WHERE ID_USER = " . $id_user;
  $requete .= " LIMIT 1 "; // (to protect)
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-B4e]", $requete);  
}


function display_image_percent($num, $comment)
{
  $txt = $num;
  if ($comment != "") $txt = $comment . " : " . $num;
  if (intval($num) < 21) echo "<img src='" . _FOLDER_IMAGES . "z1.png' WIDTH='22' HEIGHT='18' alt='" . $txt . "%' title='" . $txt . "%'>";
  if ( (intval($num) >= 21) and (intval($num) < 41 ) ) echo "<img src='" . _FOLDER_IMAGES . "z2.png' WIDTH='22' HEIGHT='18' alt='" . $txt . "%' title='" . $txt . "%'>";
  if ( (intval($num) >= 41) and (intval($num) < 61 ) ) echo "<img src='" . _FOLDER_IMAGES . "z3.png' WIDTH='22' HEIGHT='18' alt='" . $txt . "%' title='" . $txt . "%'>";
  if ( (intval($num) >= 61) and (intval($num) < 81 ) ) echo "<img src='" . _FOLDER_IMAGES . "z4.png' WIDTH='22' HEIGHT='18' alt='" . $txt . "%' title='" . $txt . "%'>";
  if (intval($num) >= 81 ) echo "<img src='" . _FOLDER_IMAGES . "z5.png' WIDTH='22' HEIGHT='18' alt='" . $txt . "%' title='" . $txt . "%'>";
}


function display_image_rating($num)
{
  if (intval($num) == 1) echo "<img src='" . _FOLDER_IMAGES . "vote_1.png' WIDTH='70' HEIGHT='14' alt='1/5' title='1/5'>"; // <font color='red'> 
  if (intval($num) == 2) echo "<img src='" . _FOLDER_IMAGES . "vote_2.png' WIDTH='70' HEIGHT='14' alt='2/5' title='2/5'>"; // <font color='orange'> 
  if (intval($num) == 3) echo "<img src='" . _FOLDER_IMAGES . "vote_3.png' WIDTH='70' HEIGHT='14' alt='3/5' title='3/5'>"; // yellow // <font color='#DDDD00'> 
  if (intval($num) == 4) echo "<img src='" . _FOLDER_IMAGES . "vote_4.png' WIDTH='70' HEIGHT='14' alt='4/5' title='4/5'>"; // <font color='#00DD00'> 
  if (intval($num) == 5) echo "<img src='" . _FOLDER_IMAGES . "vote_5.png' WIDTH='70' HEIGHT='14' alt='5/5' title='5/5'>"; // <font color='green'> 
}


function f_os_name($win_os)
{
  $ret = "?";
  switch ($win_os)
  {
    case "6.1" :
      $ret = 'Windows Seven';
      break;
    case "6.0" :
      $ret = 'Windows Vista';
      break;
    case "XP" :
      $ret = 'Windows XP';
      break;
    case "2000" :
    case "NT 5" :
    case "NT5" :
    case "NT" :
      $ret = 'Windows 2000';
      break;
    case "NT 4" :
      $ret = 'Windows NT 4';
      break;
    case "2003S" :
      $ret = 'Windows 2003';
      break;
    case "98" :
      $ret = 'Windows 98';
      break;
    case "95" :
      $ret = 'Windows 95';
      break;
    case "ME" :
      $ret = 'Windows Me';
      break;
    default :
      $ret = "?";
      break;
  }
  return $ret;
}


function display_os_picture($win_os)
{
  switch ($win_os)
  {
    case "6.1" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "winseven.gif' WIDTH='24' HEIGHT='13' ALT='Windows Seven' TITLE='Windows Seven'>";
      break;
    case "6.0" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "winvista.gif' WIDTH='36' HEIGHT='13' ALT='Windows Vista' TITLE='Windows Vista'>";
      break;
    case "XP" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "winxp.gif' WIDTH='26' HEIGHT='13' ALT='Windows XP' TITLE='Windows XP'>";
      break;
    case "2000" :
    case "NT 5" :
    case "NT5" :
    case "NT" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "win2000.gif' WIDTH='35' HEIGHT='13' ALT='Windows 2000' TITLE='Windows 2000'>";
      break;
    case "NT 4" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "winnt4.gif' WIDTH='35' HEIGHT='13' ALT='Windows NT 4' TITLE='Windows NT 4'>";
      break;
    case "2003S" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "win2003.gif' WIDTH='35' HEIGHT='13' ALT='Windows 2003' TITLE='Windows 2003'>";
      break;
    case "98" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "win98.gif' WIDTH='27' HEIGHT='13' ALT='Windows 98' TITLE='Windows 98'>";
      break;
    case "95" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "win95.gif' WIDTH='27' HEIGHT='13' ALT='Windows 95' TITLE='Windows 95'>";
      break;
    case "ME" :
      echo "<IMG SRC='" . _FOLDER_IMAGES . "winme.gif' WIDTH='29' HEIGHT='13' ALT='Windows Me' TITLE='Windows Me'>";
      break;
    default :
      echo "&nbsp;";
      break;
  }
}


function display_browser_picture($browser)
{
  if (strstr($browser, "Firefox"))            echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_firefox.gif' WIDTH='16' HEIGHT='16' ALT='Mozilla Firefox' TITLE='Mozilla Firefox'>";
  if (strstr($browser, "Internet Explorer"))  echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_ie.gif' WIDTH='16' HEIGHT='16' ALT='Internet Explorer' TITLE='Internet Explorer'>";
  if (strstr($browser, "I.E."))               echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_ie.gif' WIDTH='16' HEIGHT='16' ALT='Internet Explorer' TITLE='Internet Explorer'>";
  if (strstr($browser, "Opera"))              echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_opera.gif' WIDTH='16' HEIGHT='16' ALT='Opera' TITLE='Opera'>";
  if (strstr($browser, "Chrome"))             echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_chrome.gif' WIDTH='16' HEIGHT='16' ALT='Google Chrome' TITLE='Google Chrome'>";
  if (strstr($browser, "Safari"))             echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_safari.gif' WIDTH='16' HEIGHT='16' ALT='Safari' TITLE='Safari'>";
  if (strstr($browser, "Netscape"))           echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_netscape.gif' WIDTH='16' HEIGHT='16' ALT='Netscape' TITLE='Netscape'>";
  if (strstr($browser, "K-Meleon"))           echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_kmeleon.png' WIDTH='16' HEIGHT='16' ALT='K-Meleon' TITLE='K-Meleon'>";
  if (strstr($browser, "MSN Explorer"))       echo "&nbsp;<IMG SRC='" . _FOLDER_IMAGES . "browser_msn.png' WIDTH='16' HEIGHT='16' ALT='MSN Explorer' TITLE='MSN Explorer'>";
}


function f_reduce_browser_name($browser)
{
  $browser = str_replace("Mozilla", "", $browser);
  //
  return trim($browser);
}


function f_reduce_emailclient_name($emailclient)
{
  $emailclient = str_replace("Mozilla", "", $emailclient);
  $emailclient = str_replace("Microsoft", "", $emailclient);
  //
  return trim($emailclient);
}


function write_file($file, $text)
{
  if (is_writeable($file))
  {
    $fp = fopen($file, "w");
    fputs($fp, $text);
    fclose($fp);
  }
} 


function f_DelSpecialChar($string)
{
	$start = array("/À/","/Á/","/Â/","/Ã/","/Ä/","/Å/","/Æ/","/à/","/á/","/â/","/ã/",
	"/ä/","/å/","/æ/","/È/","/É/","/Ê/","/Ë/","/è/","/é/","/ê/","/ë/","/Ì/","/Í/","/Î/",
	"/Ï/","/ì/","/í/","/î/","/ï/","/Ò/","/Ó/","/Ô/","/Õ/","/Ö/","/Ø/","/ò/","/ó/","/ô/",
	"/õ/","/ö/","/ø/","/Ù/","/Ú/","/Û/","/Ü/","/ù/","/ú/","/û/","/ü/","/ß/","/Ç/","/ç/",
	"/Ð/","/ð/","/Ñ/","/ñ/","/Þ/","/þ/","/Ý/");
	$end = array("A","A","A","A","A","A","A","a","a","a","a","a","a","a","E","E",
	"E","E","e","e","e","e","I","I","I","I","i","i","i","i","O","O","O","O","O","O",
	"o","o","o","o","o","o","U","U","U","U","u","u","u","u","B","C","c","D","d","N",
	"n","P","p","Y");
	//
	$newString = preg_replace($start, $end, $string);
	//
	return strtolower($newString);
}


function f_clean_username($username)
{
  $username = 	trim($username);
  $username = 	strtolower($username);
  $username =   str_replace("'", "", $username);
  $username =   str_replace('"', '', $username);
  $username =   str_replace(" ", "_", $username);
  $username =   str_replace("--", "", $username); // pour éviter failles.
  $username =   str_replace("=", "", $username);
  $username =   str_replace("<", "", $username);
  $username =   str_replace(">", "", $username);
  $username =   str_replace("{", "", $username);
  $username =   str_replace("}", "", $username);
  $username =   str_replace(";", "", $username);
  $username =   str_replace("\\", "", $username);
  $username =   str_replace("/", "", $username);
  $username =   str_replace("%20", "", $username);
  $username =   str_replace("%", "", $username);
  $username =   str_replace("|", "", $username);
  //
	return $username;
}


function f_clean_name($name)
{
  $name = 	trim($name);
  //  $name = 	strtolower($name); NON !!!
  $name =   str_replace("'", "", $name);
  $name =   str_replace('"', '', $name);
  //$name =   str_replace(" ", "_", $name);
  $name =   str_replace("--", "", $name); // pour éviter failles.
  $name =   str_replace("=", "", $name);
  $name =   str_replace("<", "", $name);
  $name =   str_replace(">", "", $name);
  $name =   str_replace("{", "", $name);
  $name =   str_replace("}", "", $name);
  $name =   str_replace(";", "", $name);
  $name =   str_replace("\\", "", $name);
  $name =   str_replace("/", "", $name);
  $name =   str_replace("%20", "", $name);
  $name =   str_replace("%", "", $name);
  $name =   str_replace("|", "", $name);
  //
	return $name;
}


function f_decode64_wd($txt)
{
  $txt = str_replace("|", "+", $txt);
  $txt = base64_decode($txt);
  //
	return $txt;
}


// enlever les signes égal en fin de codage
function f_encode64($txt)
{
  $txt = trim($txt);
  $txt = base64_encode($txt);
  if (substr($txt, -1, 1) == "=") $txt = substr($txt, 0, -1);
  if (substr($txt, -1, 1) == "=") $txt = substr($txt, 0, -1);
  //
	return $txt;
}


// JMA vers AMJ (DMY to YMD)
function convertdate_MDY_to_YMD($date) 
{
	$jour = 	substr($date, 0, 2);
	$mois = 	substr($date, 3, 2);
	$annee = 	substr($date, 6, 4);
	$dateretour = 	$annee . "-" . $mois . "-" . $jour;
	//
 	return $dateretour;
}


// AMJ vers JMA (YMD to DMY)
function convertdate_YMD_to_DMY($date) 
{
	if ($date != '0000-00-00')
	{
		$jour = 	substr($date, 8, 2);
		$mois = 	substr($date, 5, 2);
		$annee = 	substr($date, 0, 4);
		$dateretour = 	$jour  . "/" . $mois . "/" . $annee;
	}
	//
 	return $dateretour;
}


if ( ! function_exists( 'exif_imagetype' ) ) 
{
  function exif_imagetype ( $filename ) 
  {
    if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) 
    {
      return $type;
    }
    return false;
  }
}


if (!function_exists('mime_content_type')) 
{
    function mime_content_type($filename) 
    {
        $mime_types = array(

            'txt' => 'text/plain',
            'htm' => 'text/html',
            'html' => 'text/html',
            'php' => 'text/html',
            'css' => 'text/css',
            'js' => 'application/javascript',
            'json' => 'application/json',
            'xml' => 'application/xml',
            'swf' => 'application/x-shockwave-flash',
            'flv' => 'video/x-flv',

            // images
            'png' => 'image/png',
            'jpe' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif',
            'bmp' => 'image/bmp',
            'ico' => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif' => 'image/tiff',
            'svg' => 'image/svg+xml',
            'svgz' => 'image/svg+xml',

            // archives
            'zip' => 'application/zip',
            'rar' => 'application/x-rar-compressed',
            'exe' => 'application/x-msdownload',
            'msi' => 'application/x-msdownload',
            'cab' => 'application/vnd.ms-cab-compressed',

            // audio/video
            'mp3' => 'audio/mpeg',
            'qt' => 'video/quicktime',
            'mov' => 'video/quicktime',

            // adobe
            'pdf' => 'application/pdf',
            'psd' => 'image/vnd.adobe.photoshop',
            'ai' => 'application/postscript',
            'eps' => 'application/postscript',
            'ps' => 'application/postscript',

            // ms office
            'doc' => 'application/msword',
            'rtf' => 'application/rtf',
            'xls' => 'application/vnd.ms-excel',
            'ppt' => 'application/vnd.ms-powerpoint',

            // open office
            'odt' => 'application/vnd.oasis.opendocument.text',
            'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        );

        $ext = strtolower(array_pop(explode('.',$filename)));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[$ext];
        }
        elseif (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);
            return $mimetype;
        }
        else {
            return 'application/octet-stream';
        }
    }
}


function f_old_distant_files()
{
  $f = array();
  $f[] = "avatar_list.php";
  $f[] = "avatar_update.php";
  $f[] = "chang_pass_user.php";
  $f[] = "chang_pseudo_user.php";
  $f[] = "conference_accept.php";
  $f[] = "conference_invite.php";
  $f[] = "conference_list_user.php";
  $f[] = "conference_msg_send.php";
  $f[] = "conference_quit.php";
  $f[] = "contact_user_ask_add.php";
  $f[] = "contact_user_confirme.php";
  $f[] = "contact_user_delete.php";
  $f[] = "contact_user_delete_wait.php";
  $f[] = "contact_user_group.php";
  $f[] = "contact_user_infos.php";
  $f[] = "contact_user_mask.php";
  $f[] = "contact_user_privilege.php";
  $f[] = "contact_user_pseudo.php";
  $f[] = "contact_user_reject.php";
  $f[] = "leave_server.php";
  $f[] = "list_contact_of_user.php";
  $f[] = "list_contact_online_offline.php";
  $f[] = "list_contact_online_only.php";
  $f[] = "list_contact_user_to_confirm.php";
  $f[] = "list_users.php";
  $f[] = "msg_get.php";
  $f[] = "msg_list_contact.php";
  $f[] = "msg_nb.php";
  $f[] = "msg_send.php";
  $f[] = "phenix_today.php";
  $f[] = "phenix_triade_today.php";
  $f[] = "stop.php";
  $f[] = "user_infos_list.php";
  $f[] = "user_infos_update.php";
  $f[] = "im_annu.php";
  $f[] = "status.php";
  #$f[] = "get_options.php";
  $f[] = "get_options_2.php";
  $f[] = "sql_test.php";
  $f[] = "start.php";
  //
  return $f;
}


function f_option_label($option)
{
  GLOBAL $l_admin_options_maintenance_mode, $l_admin_options_nb_max_user, $l_admin_options_nb_max_session, $l_admin_options_nb_max_contact_by_user,
  $l_admin_options_max_simultaneous_ip_addresses, $l_admin_options_del_user_after_x_days_not_use, $l_admin_options_check_new_msg_every,
  $l_admin_options_full_check, $l_admin_options_allow_use_proxy, $l_admin_options_proxy_port_number, $l_admin_options_proxy_address,
  $l_admin_options_admin_email, $l_admin_options_admin_phone, $l_admin_options_scroll_text, $l_admin_options_pass_register_book,
  $l_admin_options_info_book, $l_admin_option_allow_conference, $l_admin_options_allow_invisible, $l_admin_options_allow_smiley,
  $l_admin_options_can_change_contact_nickname, $l_admin_options_allow_change_email_phone, $l_admin_options_allow_change_function_name,
  $l_admin_options_allow_change_avatar, $l_admin_option_send_offline, $l_admin_options_user_history_messages, $l_admin_options_allow_rating,
  $l_admin_options_uppercase_space_nickname, $l_admin_options_allow_email_notifier, $l_admin_options_force_email_server,
  $l_admin_options_force_away, $l_admin_options_col_name_hide, $l_admin_options_lock_contact_list, $l_admin_options_lock_options,
  $l_admin_options_lock_profile, $l_admin_options_public_folder, $l_admin_options_minimum_length_of_username, $l_admin_options_password_user,
  $l_admin_options_minimum_length_of_password, $l_admin_options_max_pwd_error_lock, $l_admin_options_lock_duration,
  $l_admin_options_pass_need_digit_and_letter, $l_admin_options_pass_need_upper_and_lower, $l_admin_options_pass_need_special_character,
  $l_admin_options_crypt_msg, $l_admin_options_censor_messages, $l_admin_options_log_messages, $l_admin_options_password_for_private_server,
  $l_admin_options_is_usernamePC, $l_admin_options_auto_add_user, $l_admin_options_quick_register, $l_admin_options_need_admin_after_add,
  $l_admin_options_need_admin_if_chang_check, $l_admin_options_shoutbox_title_long, $l_admin_options_shoutbox_title_short, $l_admin_options_shoutbox_refresh_delay,
  $l_admin_options_shoutbox_store_max, $l_admin_options_shoutbox_store_days, $l_admin_options_shoutbox_day_user_quota,
  $l_admin_options_shoutbox_week_user_quota, $l_admin_options_shoutbox_need_approval, $l_admin_options_shoutbox_approval_queue,
  $l_admin_options_shoutbox_approval_queue_user, $l_admin_options_shoutbox_lock_user_approval, $l_admin_options_shoutbox_can_vote,
  $l_admin_options_shoutbox_day_votes_quota, $l_admin_options_shoutbox_week_votes_quota, $l_admin_options_shoutbox_remove_msg_votes,
  $l_admin_options_shoutbox_lock_user_votes, $l_admin_options_shoutbox_public, $l_admin_options_bookmarks, $l_admin_options_bookmarks_can_vote,
  $l_admin_options_bookmarks_public, $l_admin_options_bookmarks_need_approval, $l_admin_options_site_url, $l_admin_options_site_title,
  $l_admin_options_groupcommunity, $l_admin_options_opencommunity, $l_admin_authentication_extern, $l_admin_extern_url_to_register,
  $l_admin_extern_url_password_forget, $l_admin_extern_url_change_password, $l_admin_options_site_title, $l_admin_options_group_for_sbx_and_admin_messages,
  $l_admin_options_group_user_can_join, $l_admin_options_enterprise_server, $l_admin_options_hierachic_management, $l_admin_options_servers_status,
  $l_admin_options_force_update_by_server, $l_admin_options_force_update_by_internet, $l_admin_options_public_see_users,
  $l_admin_options_public_upload_avatar, $l_admin_options_public_see_options, $l_admin_options_flag_country, $l_admin_options_profile_first_register,
  $l_admin_options_time_zones, $l_admin_options_log_session_open, $l_admin_options_statistics, $l_admin_options_check_version_internet,
  $l_admin_options_unread_message_validity, $l_admin_options_roles_to_override_permissions, $l_admin_role_get_admin_alert,
  $l_admin_role_send_alert_to_admin, $l_admin_role_broadcast_alert_to_group, $l_admin_role_broadcast_alert;
  //
  $label = "";
  if (substr($option,0 , 1) <> "_") $option = "_" . $option;
  //
  if ($option == "_MAINTENANCE_MODE") $label = $l_admin_options_maintenance_mode;
  if ($option == "_MAX_NB_USER") $label = $l_admin_options_nb_max_user;
  if ($option == "_MAX_NB_SESSION") $label = $l_admin_options_nb_max_session;
  if ($option == "_MAX_NB_CONTACT_BY_USER") $label = $l_admin_options_nb_max_contact_by_user;
  if ($option == "_MAX_NB_IP") $label = $l_admin_options_max_simultaneous_ip_addresses;
  if ($option == "_OUTOFDATE_AFTER_X_DAYS_NOT_USE") $label = $l_admin_options_del_user_after_x_days_not_use;
  if ($option == "_CHECK_NEW_MSG_EVERY") $label = $l_admin_options_check_new_msg_every;
  if ($option == "_FULL_CHECK") $label = $l_admin_options_full_check;
  if ($option == "_ALLOW_USE_PROXY") $label = $l_admin_options_allow_use_proxy;
  if ($option == "_PROXY_PORT_NUMBER") $label = $l_admin_options_proxy_port_number;
  if ($option == "_PROXY_ADDRESS") $label = $l_admin_options_proxy_address;
  if ($option == "_ADMIN_EMAIL") $label = $l_admin_options_admin_email;
  if ($option == "_ADMIN_PHONE") $label = $l_admin_options_admin_phone;
  if ($option == "_SCROLL_TEXT") $label = $l_admin_options_scroll_text;
  if ($option == "_IM_ADDRESS_BOOK_PASSWORD") $label = $l_admin_options_pass_register_book . " " . $l_admin_options_info_book;
  if ($option == "_ALLOW_CONFERENCE") $label = $l_admin_option_allow_conference;
  if ($option == "_ALLOW_INVISIBLE") $label = $l_admin_options_allow_invisible;
  if ($option == "_ALLOW_SMILEYS") $label = $l_admin_options_allow_smiley;
  if ($option == "_ALLOW_CHANGE_CONTACT_NICKNAME") $label = $l_admin_options_can_change_contact_nickname;
  if ($option == "_ALLOW_CHANGE_EMAIL_PHONE") $label = $l_admin_options_allow_change_email_phone;
  if ($option == "_ALLOW_CHANGE_FUNCTION_NAME") $label = $l_admin_options_allow_change_function_name;
  if ($option == "_ALLOW_CHANGE_AVATAR") $label = $l_admin_options_allow_change_avatar;
  if ($option == "_ALLOW_SEND_TO_OFFLINE_USER") $label = $l_admin_option_send_offline;
  if ($option == "_ALLOW_USER_TO_HISTORY_MESSAGES") $label = $l_admin_options_user_history_messages;
  if ($option == "_ALLOW_USER_RATING") $label = $l_admin_options_allow_rating;
  if ($option == "_ALLOW_UPPERCASE_SPACE_USERNAME") $label = $l_admin_options_uppercase_space_nickname;
  if ($option == "_ALLOW_EMAIL_NOTIFIER") $label = $l_admin_options_allow_email_notifier;
  if ($option == "_INCOMING_EMAIL_SERVER_ADDRESS") $label = $l_admin_options_force_email_server;
  if ($option == "_FORCE_AWAY_ON_SCREENSAVER") $label = $l_admin_options_force_away;
  if ($option == "_HIDE_COL_FUNCTION_NAME") $label = $l_admin_options_col_name_hide;
  if ($option == "_LOCK_USER_CONTACT_LIST") $label = $l_admin_options_lock_contact_list;
  if ($option == "_LOCK_USER_OPTIONS") $label = $l_admin_options_lock_options;
  if ($option == "_LOCK_USER_PROFILE") $label = $l_admin_options_lock_profile;
  if ($option == "_PUBLIC_FOLDER") $label = $l_admin_options_public_folder;
  if ($option == "_MINIMUM_USERNAME_LENGTH") $label = $l_admin_options_minimum_length_of_username;
  if ($option == "_USER_NEED_PASSWORD") $label = $l_admin_options_password_user;
  if ($option == "_MINIMUM_PASSWORD_LENGTH") $label = $l_admin_options_minimum_length_of_password;
  if ($option == "_MAX_PASSWORD_ERRORS_BEFORE_LOCK_USER") $label = $l_admin_options_max_pwd_error_lock;
  if ($option == "_LOCK_DURATION") $label = $l_admin_options_lock_duration;
  if ($option == "_PWD_NEED_DIGIT_LETTER") $label = $l_admin_options_pass_need_digit_and_letter;
  if ($option == "_PWD_NEED_UPPER_LOWER") $label = $l_admin_options_pass_need_upper_and_lower;
  if ($option == "_PWD_NEED_SPECIAL_CHARACTER") $label = $l_admin_options_pass_need_special_character;
  if ($option == "_CRYPT_MESSAGES") $label = $l_admin_options_crypt_msg;
  if ($option == "_CENSOR_MESSAGES") $label = $l_admin_options_censor_messages;
  if ($option == "_LOG_MESSAGES") $label = $l_admin_options_log_messages;
  if ($option == "_PASSWORD_FOR_PRIVATE_SERVER") $label = $l_admin_options_password_for_private_server;
  if ($option == "_FORCE_USERNAME_TO_PC_SESSION_NAME") $label = $l_admin_options_is_usernamePC;
  if ($option == "_ALLOW_AUTO_ADD_NEW_USER_ON_SERVER") $label = $l_admin_options_auto_add_user;
  if ($option == "_NEED_QUICK_REGISTER_TO_AUTO_ADD_NEW_USER") $label = $l_admin_options_quick_register;
  if ($option == "_PENDING_NEW_AUTO_ADDED_USER") $label = $l_admin_options_need_admin_after_add;
  if ($option == "_PENDING_USER_ON_COMPUTER_CHANGE") $label = $l_admin_options_need_admin_if_chang_check;
  if ($option == "_SHOUTBOX") $label = $l_admin_options_shoutbox_title_long;
  if ($option == "_SHOUTBOX_REFRESH_DELAY") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_refresh_delay;
  if ($option == "_SHOUTBOX_STORE_MAX") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_store_max;
  if ($option == "_SHOUTBOX_STORE_DAYS") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_store_days;
  if ($option == "_SHOUTBOX_QUOTA_USER_DAY") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_day_user_quota;
  if ($option == "_SHOUTBOX_QUOTA_USER_WEEK") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_week_user_quota;
  if ($option == "_SHOUTBOX_NEED_APPROVAL") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_need_approval;
  if ($option == "_SHOUTBOX_APPROVAL_QUEUE") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_approval_queue;
  if ($option == "_SHOUTBOX_APPROVAL_QUEUE_USER") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_approval_queue_user;
  if ($option == "_SHOUTBOX_LOCK_USER_APPROVAL") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_lock_user_approval;
  if ($option == "_SHOUTBOX_VOTE") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_can_vote;
  if ($option == "_SHOUTBOX_MAX_NOTES_USER_DAY") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_day_votes_quota;
  if ($option == "_SHOUTBOX_MAX_NOTES_USER_WEEK") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_week_votes_quota;
  if ($option == "_SHOUTBOX_REMOVE_MESSAGE_VOTES") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_remove_msg_votes;
  if ($option == "_SHOUTBOX_LOCK_USER_VOTES") $label = $l_admin_options_shoutbox_title_short . " : " . $l_admin_options_shoutbox_lock_user_votes;
  if ($option == "_SHOUTBOX_PUBLIC") $label = $l_admin_options_shoutbox_public;
  if ($option == "_BOOKMARKS") $label = $l_admin_options_bookmarks;
  if ($option == "_BOOKMARKS_VOTE") $label = $l_admin_options_bookmarks_can_vote;
  if ($option == "_BOOKMARKS_PUBLIC") $label = $l_admin_options_bookmarks_public . " + RSS";
  if ($option == "_BOOKMARKS_NEED_APPROVAL") $label = $l_admin_options_bookmarks_need_approval;
  if ($option == "_SITE_URL_TO_SHOW") $label = $l_admin_options_site_url;
  if ($option == "_SITE_TITLE_TO_SHOW") $label = $l_admin_options_site_title;
  if ($option == "_SPECIAL_MODE_GROUP_COMMUNITY") $label = $l_admin_options_groupcommunity;
  if ($option == "_SPECIAL_MODE_OPEN_COMMUNITY") $label = $l_admin_options_opencommunity;
  if ($option == "_EXTERNAL_AUTHENTICATION") $label = $l_admin_authentication_extern;
  if ($option == "_EXTERN_URL_TO_REGISTER") $label = $l_admin_extern_url_to_register;
  if ($option == "_EXTERN_URL_FORGET_PASSWORD") $label = $l_admin_extern_url_password_forget;
  if ($option == "_EXTERN_URL_CHANGE_PASSWORD") $label = $l_admin_extern_url_change_password;
  if ($option == "_SITE_TITLE") $label = $l_admin_options_site_title;
  if ($option == "_GROUP_FOR_SBX_AND_ADMIN_MSG") $label = $l_admin_options_group_for_sbx_and_admin_messages;
  if ($option == "_GROUP_USER_CAN_JOIN") $label = $l_admin_options_group_user_can_join;
  if ($option == "_ENTERPRISE_SERVER") $label = $l_admin_options_enterprise_server;
  if ($option == "_USER_HIEARCHIC_MANAGEMENT_BY_ADMIN") $label = $l_admin_options_hierachic_management;
  if ($option == "_SERVERS_STATUS") $label = $l_admin_options_servers_status;
  if ($option == "_FORCE_UPDATE_BY_SERVER") $label = $l_admin_options_force_update_by_server;
  if ($option == "_FORCE_UPDATE_BY_INTERNET") $label = $l_admin_options_force_update_by_internet;
  if ($option == "_PUBLIC_USERS_LIST") $label = $l_admin_options_public_see_users;
  if ($option == "_PUBLIC_POST_AVATAR") $label = $l_admin_options_public_upload_avatar;
  if ($option == "_PUBLIC_OPTIONS_LIST") $label = $l_admin_options_public_see_options;
  if ($option == "_DISPLAY_USER_FLAG_COUNTRY") $label = $l_admin_options_flag_country;
  if ($option == "_INVITE_FILL_PROFILE_ON_FIRST_LOGIN") $label = $l_admin_options_profile_first_register;
  if ($option == "_TIME_ZONES") $label = $l_admin_options_time_zones;
  if ($option == "_LOG_SESSION_OPEN") $label = $l_admin_options_log_session_open;
  if ($option == "_STATISTICS") $label = $l_admin_options_statistics;
  if ($option == "_CHECK_VERSION_INTERNET") $label = $l_admin_options_check_version_internet;
  if ($option == "_UNREAD_MESSAGE_VALIDITY") $label = $l_admin_options_unread_message_validity;
  if ($option == "_ROLES_TO_OVERRIDE_PERMISSIONS") $label = $l_admin_options_roles_to_override_permissions;
  //if ($option == "") $label = $xxxxxxx;
  //
  // Roles (pas des options !) :
  if ($option == "_ROLE_GET_ADMIN_ALERT_MESSAGES") $label = $l_admin_role_get_admin_alert;
  if ($option == "_ROLE_SEND_ALERT_TO_ADMIN") $label = $l_admin_role_send_alert_to_admin;
  if ($option == "_ROLE_BROADCAST_ALERT_TO_GROUP") $label = $l_admin_role_broadcast_alert_to_group;
  if ($option == "_ROLE_BROADCAST_ALERT") $label = $l_admin_role_broadcast_alert;
  //if ($option == "") $label = $xxxxxxx;
  //
  return $label;
}
?>
Return current item: IntraMessenger