Location: PHPKode > projects > IntraMessenger > common/roles.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 f_role_of_user($t_id_user)
{
  global $PREFIX_IM_TABLE;
  //
	$retour = 0; // par défaut
  $t_id_user = intval($t_id_user);
  if ( ($t_id_user > 0) and (_ROLES_TO_OVERRIDE_PERMISSIONS != "") )
  {
    $requete  = " select ID_ROLE ";
    $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-G7a]", $requete);
    if ( mysql_num_rows($result) == 1 )
    {
      list ($id_role) = mysql_fetch_row ($result);
      $id_role = intval($id_role);
      if ($id_role > 0) 
        $retour = $id_role;
      else
      {
        // If no role, use the default one :
        $requete  = " select SQL_CACHE ID_ROLE ";
        $requete .= " FROM " . $PREFIX_IM_TABLE . "ROL_ROLE ";
        $requete .= " WHERE ROL_DEFAULT = 'D' ";
        $requete .= " limit 1 "; // only first one
        $result = mysql_query($requete);
        if (!$result) error_sql_log("[ERR-G7b]", $requete);
        if ( mysql_num_rows($result) == 1 )
        {
          list ($id_role) = mysql_fetch_row ($result);
          $id_role = intval($id_role);
          if ($id_role > 0) $retour = $id_role;
        }
      }
    }
  }
  //
	return $retour;
}
	
	
function f_role_permission($id_role, $option, $default)
{
  global $PREFIX_IM_TABLE;
  //
	//if ($default != "") $default = "X";  NON !
	$retour = $default; // par défaut
  $id_role = intval($id_role);
  if ( ($id_role > 0) and (_ROLES_TO_OVERRIDE_PERMISSIONS != "") )
  {
    $requete  = " select SQL_CACHE RLM.RLM_STATE, RLM.RLM_VALUE ";
    $requete .= " FROM " . $PREFIX_IM_TABLE . "RLM_ROLEMODULE RLM, " . $PREFIX_IM_TABLE . "MDL_MODULE MDL ";
    $requete .= " WHERE RLM.ID_MODULE = MDL.ID_MODULE ";
    $requete .= " and RLM.ID_ROLE = " . $id_role . " ";
    $requete .= " and MDL.MDL_NAME = '" . $option . "' ";
    $requete .= " LIMIT 2 "; // on ne sait jamais
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-G7c]", $requete);
    //if ( mysql_num_rows($result) == 1 )
    if ( mysql_num_rows($result) > 0 )
    {
      list ($state, $rlm_value) = mysql_fetch_row ($result);
      $state = intval($state);
      if ($state == 1) $retour = "";
      if ($state == 2) $retour = "X";
      if ($state == 3) $retour = $rlm_value;
    }
  }
  //
	return $retour;
}

function f_option_activated($mdl_name)
{
  $retour = "";
  //
  if ($mdl_name == "ALLOW_CHANGE_CONTACT_NICKNAME") { if (_ALLOW_CHANGE_CONTACT_NICKNAME != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_CHANGE_EMAIL_PHONE") { if (_ALLOW_CHANGE_EMAIL_PHONE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_CHANGE_FUNCTION_NAME") { if (_ALLOW_CHANGE_FUNCTION_NAME != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_CHANGE_AVATAR") { if (_ALLOW_CHANGE_AVATAR != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_CONFERENCE") { if (_ALLOW_CONFERENCE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_EMAIL_NOTIFIER") { if (_ALLOW_EMAIL_NOTIFIER != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_INVISIBLE") { if (_ALLOW_INVISIBLE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_SEND_TO_OFFLINE_USER") { if (_ALLOW_SEND_TO_OFFLINE_USER != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_SMILEYS") { if (_ALLOW_SMILEYS != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_USE_PROXY") { if (_ALLOW_USE_PROXY != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_USER_RATING") { if (_ALLOW_USER_RATING != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "ALLOW_USER_TO_HISTORY_MESSAGES") { if (_ALLOW_USER_TO_HISTORY_MESSAGES != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "CENSOR_MESSAGES") { if (_CENSOR_MESSAGES != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "LOG_MESSAGES") { if (_LOG_MESSAGES != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "LOCK_USER_CONTACT_LIST") { if (_LOCK_USER_CONTACT_LIST != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "LOCK_USER_OPTIONS") { if (_LOCK_USER_OPTIONS != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "LOCK_USER_PROFILE") { if (_LOCK_USER_PROFILE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "GROUP_USER_CAN_JOIN") { if (_GROUP_USER_CAN_JOIN != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "PENDING_USER_ON_COMPUTER_CHANGE") { if (_PENDING_USER_ON_COMPUTER_CHANGE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "USER_HIEARCHIC_MANAGEMENT_BY_ADMIN") { if (_USER_HIEARCHIC_MANAGEMENT_BY_ADMIN != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "SERVERS_STATUS") { if (_SERVERS_STATUS != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "BOOKMARKS") { if (_BOOKMARKS != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "BOOKMARKS_VOTE") { if (_BOOKMARKS_VOTE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "BOOKMARKS_NEED_APPROVAL") { if (_BOOKMARKS_NEED_APPROVAL != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "SHOUTBOX") { if (_SHOUTBOX != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "SHOUTBOX_VOTE") { if (_SHOUTBOX_VOTE != "") $retour = 2;  else  $retour = 1; }
  if ($mdl_name == "SHOUTBOX_NEED_APPROVAL") { if (_SHOUTBOX_NEED_APPROVAL != "") $retour = 2;  else  $retour = 1; }
  //
	return $retour;
}


function f_option_value($mdl_name)
{
  $retour = 0;
  //
  if ($mdl_name == "MAX_NB_IP") $retour = _MAX_NB_IP;
  if ($mdl_name == "MAX_NB_CONTACT_BY_USER") $retour = _MAX_NB_CONTACT_BY_USER;
  if ($mdl_name == "MAX_PASSWORD_ERRORS_BEFORE_LOCK_USER") $retour = _MAX_PASSWORD_ERRORS_BEFORE_LOCK_USER;
  if ($mdl_name == "LOCK_DURATION") $retour = _LOCK_DURATION;
  //if ($mdl_name == "CHECK_NEW_MSG_EVERY") $retour = _CHECK_NEW_MSG_EVERY;
  if ($mdl_name == "SHOUTBOX_REFRESH_DELAY") $retour = _SHOUTBOX_REFRESH_DELAY;
  if ($mdl_name == "SHOUTBOX_QUOTA_USER_DAY") $retour = _SHOUTBOX_QUOTA_USER_DAY;
  if ($mdl_name == "SHOUTBOX_QUOTA_USER_WEEK") $retour = _SHOUTBOX_QUOTA_USER_WEEK;
  if ($mdl_name == "SHOUTBOX_APPROVAL_QUEUE_USER") $retour = _SHOUTBOX_APPROVAL_QUEUE_USER;
  if ($mdl_name == "SHOUTBOX_LOCK_USER_APPROVAL") $retour = _SHOUTBOX_LOCK_USER_APPROVAL;
  if ($mdl_name == "SHOUTBOX_MAX_NOTES_USER_DAY") $retour = _SHOUTBOX_MAX_NOTES_USER_DAY;
  if ($mdl_name == "SHOUTBOX_MAX_NOTES_USER_WEEK") $retour = _SHOUTBOX_MAX_NOTES_USER_WEEK;
  if ($mdl_name == "SHOUTBOX_REMOVE_MESSAGE_VOTES") $retour = _SHOUTBOX_REMOVE_MESSAGE_VOTES;
  if ($mdl_name == "SHOUTBOX_LOCK_USER_VOTES") $retour = _SHOUTBOX_LOCK_USER_VOTES;
  //
	return $retour;
}

	
function fill_table_module()
{
  global $PREFIX_IM_TABLE;
  //
  //
  $nb_rlm = 0;
  $requete  = " select count(*) ";
  $requete .= " FROM " . $PREFIX_IM_TABLE . "RLM_ROLEMODULE ";
  $result = mysql_query($requete);
  if (!$result) error_sql_log("[ERR-G7g]", $requete);
  if ( mysql_num_rows($result) == 1 )
  {
    list ($nb_rlm) = mysql_fetch_row ($result);
  }
  //
  if ($nb_rlm <= 0)
  {
    //$requete = "TRUNCATE TABLE " . $PREFIX_IM_TABLE . "MDL_MODULE ";
    $requete = "DELETE FROM " . $PREFIX_IM_TABLE . "MDL_MODULE ";
    $result = mysql_query($requete);
    if (!$result) error_sql_log("[ERR-G7d]", $requete);
    //
    if (_ROLES_TO_OVERRIDE_PERMISSIONS != '')
    {
      // Options :
      $requete  = " INSERT INTO " . $PREFIX_IM_TABLE . "MDL_MODULE (ID_MODULE, MDL_NAME, MDL_MAX_VALUE, MDL_OTHER) VALUES ";
      $requete .= " (1, 'ALLOW_CHANGE_CONTACT_NICKNAME', 0, ''), (2, 'ALLOW_CHANGE_EMAIL_PHONE', 0, ''), (3, 'ALLOW_CHANGE_FUNCTION_NAME', 0, ''), ";
      $requete .= " (4, 'ALLOW_CHANGE_AVATAR', 0, ''), (5, 'ALLOW_CONFERENCE', 0, ''), (6, 'ALLOW_EMAIL_NOTIFIER', 0, ''), ";
      $requete .= " (7, 'ALLOW_INVISIBLE', 0, ''), (8, 'ALLOW_SEND_TO_OFFLINE_USER', 0, ''), (9, 'ALLOW_SMILEYS', 0, ''), ";
      $requete .= " (10, 'ALLOW_USE_PROXY', 0, ''), (11, 'ALLOW_USER_RATING', 0, ''), (12, 'ALLOW_USER_TO_HISTORY_MESSAGES', 0, ''), ";
      $requete .= " (13, 'CENSOR_MESSAGES', 0, ''), (14, 'LOG_MESSAGES', 0, 'X'), (15, 'MAX_NB_IP', 99, ''), ";
      $requete .= " (16, 'MAX_NB_CONTACT_BY_USER', 999, ''), (17, 'MAX_PASSWORD_ERRORS_BEFORE_LOCK_USER', 20, ''), (18, 'LOCK_DURATION', 9999, ''), ";
      $requete .= " (30, 'LOCK_USER_CONTACT_LIST', 0, ''), (31, 'LOCK_USER_OPTIONS', 0, ''), (32, 'LOCK_USER_PROFILE', 0, ''), ";
      $requete .= " (40, 'GROUP_USER_CAN_JOIN', 0, 'X'), (41, 'PENDING_USER_ON_COMPUTER_CHANGE', 0, ''), ";
      $requete .= " (42, 'USER_HIEARCHIC_MANAGEMENT_BY_ADMIN', 0, 'X'), (43, 'SERVERS_STATUS', 0, 'X'), ";
      $requete .= " (50, 'BOOKMARKS', 0, 'X'), (51, 'BOOKMARKS_VOTE', 0, ''), (52, 'BOOKMARKS_NEED_APPROVAL', 0, ''), ";
      $requete .= " (60, 'SHOUTBOX', 0, 'X'), (61, 'SHOUTBOX_REFRESH_DELAY', 120, ''), (62, 'SHOUTBOX_QUOTA_USER_DAY', 99, ''), ";
      $requete .= " (63, 'SHOUTBOX_QUOTA_USER_WEEK', 999, ''), (64, 'SHOUTBOX_NEED_APPROVAL', 0, ''), (65, 'SHOUTBOX_APPROVAL_QUEUE_USER', 9, ''), ";
      $requete .= " (66, 'SHOUTBOX_LOCK_USER_APPROVAL', 99, ''), (67, 'SHOUTBOX_VOTE', 0, ''), (68, 'SHOUTBOX_MAX_NOTES_USER_DAY', 999, ''), ";
      $requete .= " (69, 'SHOUTBOX_MAX_NOTES_USER_WEEK', 999, ''), (70, 'SHOUTBOX_REMOVE_MESSAGE_VOTES', 99, ''), ";
      $requete .= " (71, 'SHOUTBOX_LOCK_USER_VOTES', 99, ''); ";
      //$requete .= " (, '', 0, ''), (, '', 0, ''), (, '', 0, ''); ";
      $result = mysql_query($requete);
      if (!$result) error_sql_log("[ERR-G7e]", $requete);
      //
      // Roles :
      $requete  = " INSERT INTO " . $PREFIX_IM_TABLE . "MDL_MODULE (ID_MODULE, MDL_NAME, MDL_ROLE) VALUES ";
      $requete .= "  ";
      $requete .= " (100, 'ROLE_GET_ADMIN_ALERT_MESSAGES', 'R'), (101, 'ROLE_SEND_ALERT_TO_ADMIN', 'R'), ";
      $requete .= " (102, 'ROLE_BROADCAST_ALERT_TO_GROUP', 'R'), (103, 'ROLE_BROADCAST_ALERT', 'R'); ";
      //$requete .= " (, '', 'R'), (, '', 'R'), ";
      $result = mysql_query($requete);
      if (!$result) error_sql_log("[ERR-G7f]", $requete);
    }
  }
}
?>
Return current item: IntraMessenger