Changeset 1052 for trunk/common


Ignore:
Timestamp:
09/18/09 12:27:26 (3 years ago)
Author:
savin.tiberiu@…
Message:

Fixed moderator rights loss after rating update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/smf.php

    r852 r1052  
    5959// Updates SMF user information from a regular infoarena user. 
    6060function smf_update_user($ia_user) { 
     61 
    6162    $fields = array( 
    6263        'memberName' => $ia_user['username'], 
     
    9697        //'buddy_list' => '', 
    9798        //'memberIP2' => '', 
     99    ); 
    98100 
    99         // ID_GROUP 1 is forum administrator 
    100         'ID_GROUP' => ('admin' == $ia_user['security_level'] ? 1 : null), 
    101     ); 
     101    $smf_user = smf_get_member_by_name($ia_user['username']); 
     102 
     103    $additional_groups = array(); 
     104    if (strlen($smf_user['additional_groups']) > 0) { 
     105        $additional_groups = explode(',', $smf_user['additional_groups']); 
     106    } 
     107 
     108    // Check if user is a smf admin 
     109    // SMF holds the ID of the first group in id_group 
     110    // and the others in additional_groups separated by , (comma) 
     111    $is_smf_admin = false; 
     112    if ($smf_user['id_group'] == 1) { 
     113        $is_smf_admin = true; 
     114    } 
     115 
     116    if (in_array(1, $additional_groups)) { 
     117        $is_smf_admin = true; 
     118    } 
     119 
     120    // If user is admin on IA but not on SMF he is promoted 
     121    if ($ia_user['security_level'] == 'admin' && !$is_smf_admin) { 
     122        $fields['ID_GROUP'] = 1; 
     123 
     124        if ($smf_user['id_group'] != 0) { 
     125            $additional_groups[] = $smf_user['id_group']; 
     126        } 
     127        $fields['additionalGroups'] = implode(',', $additional_groups); 
     128    } 
     129 
     130    // If user is admin on smf but not on IA he is demoted 
     131    if ($ia_user['security_level'] != 'admin' && $is_smf_admin) { 
     132        if ($smf_user['id_group'] == '1') { 
     133            $fields['ID_GROUP'] = 0; 
     134        } else { 
     135            $groups = ''; 
     136            foreach ($additional_groups as $group) { 
     137                // Strip group 1 from additionalGroups 
     138                if ($group == 1) { 
     139                    continue; 
     140                } 
     141 
     142                if (strlen($groups) > 0) { 
     143                    $groups .= ','; 
     144                } 
     145                $groups .= $group; 
     146            } 
     147 
     148            $fields['additionalGroups'] = $groups; 
     149        } 
     150    } 
    102151 
    103152    $where = sprintf("memberName='%s'", db_escape($ia_user['username'])); 
     
    116165        WHERE memberName = '%s' 
    117166    "; 
    118     return db_query_value(sprintf($query, $username)); 
     167    return db_query_value(sprintf($query, db_escape($username))); 
     168} 
     169 
     170function smf_get_member_by_name($username) { 
     171    $prefix = IA_SMF_DB_PREFIX; 
     172    $query = " 
     173        SELECT ID_MEMBER AS id, memberName AS user_name, 
     174        ID_GROUP AS id_group, additionalGroups AS additional_groups 
     175        FROM {$prefix}members 
     176        WHERE memberName = '".db_escape($username)."' 
     177    "; 
     178 
     179    return db_fetch($query); 
    119180} 
    120181 
Note: See TracChangeset for help on using the changeset viewer.