View Single Post
  #9  
Old 03-31-2006, 01:53 AM
makaiguy's Avatar
makaiguy makaiguy is offline
 
Join Date: May 2004
Location: Aiken, SC, USA
Posts: 150
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks again, Paul. Your latest hint got me a lot further. Finally I just created a separate display page with my routine in it. This allowed me to insert a bunch of print() functions to check variables and progress and really get this thing debugged. Seems to be working like a champ.

Here's the final code, in case it will be of use to anybody else (please see questions and concerns below):
PHP Code:
// Add or remove user from secondary usergroup
// according to Pwd value in user's profile

  
global $vbulletin;

  
// #### SET THESE THREE STRINGS TO THE PROPER VALUES FOR YOUR SYSTEM ####
  
$org_mg '12';                        // membergroup # as string
  
$org_pwfield 'field5';               // custom field# in profile as string
  
$org_pwphrase 'org_member_password'// vbphrase name containing pwd

  // other string variables 
  
$org_mglist = (''.$vbulletin->userinfo['membergroupids']); // current membergroups string
  
$org_userid = ($vbulletin->userinfo['userid']);         // userid of user

  
$org_mg_pos = (strpos($org_mglist$org_mg));         // find target membergroup position
                                                        // in group list - returns false
                                                        // if not found

  // boolean variables 
  
$org_grp    = ($org_mg_pos !== false);                // User is in target group (true/false)
  
  
$org_haspwd = ($vbulletin->userinfo[$org_pwfield] == $vbphrase[$org_pwphrase]); // User 
                                                        // has correct password in profile (T/F)

  
if ($org_haspwd != $org_grp)      // Need to update membergroups?
  
{
     if (!
$org_grp)                 // If not currently in target group
                                    // add to group
     
{
        
        if (
$org_mglist != '')
        {
           
$org_comma ',';
        }      
        
$org_newmg = ($org_mglist $org_comma $org_mg);
     }
     else                            
// else currently in target group
                                     // and must remove  
     
{
        
// ********* potential problem section *************
        
$org_srch = ($org_mg ',');            // search string to remove = mg#,             
        
$org_newmg str_replace($org_srch,'',$org_mglist);  
        
$org_mglist $org_newmg;           
        
        
$org_srch = (',' $org_mg);            // search string to remove = ,mg#             
        
$org_newmg str_replace($org_srch,'',$org_mglist);  

        if ((
strpos($org_newmg$org_mg)) !== false)
        { 
           
$org_newmg '';                    
        }
        
// ******** end potential problem section **********
     
}
     
$updatefields $vbulletin->db->query("
            UPDATE user
            SET membergroupids='
$org_newmg'                             
            WHERE userid=
$org_userid
     "
);
     
  } 
Couple of concerns/questions:

Had to frog around with the str_replace() function quite a bit. Couldn't get it to work recursively on itself as
PHP Code:
$a str_replace($b,$c,$a)); 
Finally had to bring in a temp string to hold results:
PHP Code:
$d str_replace($b,$c,$a));
$a $d
Second concern is the method used to remove target group from the list. (See portion of code labeled as 'potential problem section'. ) Happens to work okay for me because my target group is 2-digit group 12. So nulling out '12,' and ',12' works.

But if my target were a single digit number, say 3, nulling out '3,' and ',3' via str_replace() could mess up some two-digit group numbers:
'3,12,23,31' would become '12,21'

.. or even I could have problems if, heaven forbid, we ended up with three digit membergroup numbers.

So for MY use for now, this will work, but as a generic routine for others, it's still lacking.

Can anybody suggest a way of dealing with removing the target group that would solve this problem? (Maybe by working with the group numbers as an array?)
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01224 seconds
  • Memory Usage 1,820KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete