Support Forums

Automatically update User Group ID

This is a discussion on Automatically update User Group ID within the Technical Support forums, part of the Technical Support Forums category; I want to automatically put users in a user group when they have confirmed registration, depending on the value of ...


Go Back   68 Classifieds Forums > Technical Support Forums > Technical Support

Reply
 
Thread Tools Display Modes
Old 07-14-2010, 01:38 PM   #1
jw4
Junior Member
 
Join Date: Jun 2010
Posts: 19
Rep Power: 7
jw4 is on a distinguished road
Default Automatically update User Group ID

I want to automatically put users in a user group when they have confirmed registration, depending on the value of an extra user field.

I want to put the code where the user group value gets updated from 'awaiting email confirmation (ID 3) to 'registered' (ID 2) - but I can't find which php file this is in.

I have looked in userjoin.php and login.php but can't see it - can anyone tell me where this happens?

Any help much appreciated!
jw4 is offline   Reply With Quote
Old 07-14-2010, 02:00 PM   #2
Developer & Moderator
 
Mike-N-Tosh's Avatar
 
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 2,427
Rep Power: 75
Mike-N-Tosh is just really nice Mike-N-Tosh is just really nice
Default

Register.php
__________________
Mike-N-Tosh
IndianaPC.org - A community website (v3.1.10 Developer - heavily modified & used as the CMS)
Sandbox [localhost(v3.1.10, v4.0.9, 4.1.10,4.2,5.0)] for development and customization
Visit My blog: reviews, tips, tricks, tutorials and my store with Templates, Mods & Docs
Web Hosting | Web Design & Development | 68 Classifieds Customizations
I am not a 68C employee, just a user and try to help out
Mike-N-Tosh is offline   Reply With Quote
Old 07-15-2010, 06:46 AM   #3
jw4
Junior Member
 
Join Date: Jun 2010
Posts: 19
Rep Power: 7
jw4 is on a distinguished road
Default

Thank you Mike - I have found the section in Register.php where the user group (level) is updated.

I realise though that my php/sql is not yet very good (learning fast I hope), I wonder if anyone can help.

what I want to do is override the setting of level to 2 (registered user), depending on the value in an extra text field.

e.g. if extra2="Chiswick Community School" - level=6
if extra2="Teddington" - level=7
etc

Here is the section from Register.php, yo ucan see I had inserted an if statement which makes no difference.

If anyone can anyone give me the code to do this, I will very grateful!!

/**
* Confirms a signup against the confirmation code. If it
* matches, changes the user level. Sent by email, and is required
* by an optional setting.
*
* @access private
* @param string $confirmCode
* @return boolean
* @internal should we use _getUserData here too? I think we should
*/
function confirm ($confirmCode)
{
$sql = 'SELECT uVerify FROM ' . PREFIX . 'users WHERE uVerify=' . $this->_db->quoteInto($confirmCode) . ' AND level<>"4"';
$result = $this->_db->query($sql);
if ($result->size() != 1 || $this->_db->isError()) {
return false;
}
$result->freeResult();
$sql = 'UPDATE ' . PREFIX . 'users SET level=2 WHERE uVerify=' . $this->_db->quoteInto($confirmCode);
$result = $this->_db->query($sql);
if ($result->affectedRows() != 1 || $this->_db->isError()) {
$result->freeResult();
return false;
}

// update level (user group id) according to extra2 (school)

if ($extra2="Chiswick Community School")
{
$level=6;
}
else
if ($extra2="Teddington")
{
$level=7;
}

$modules = Library::loadLibrary('Modules');
$modules->call_hook('user_confirm', $userDetails); // Call any module functions
$result->freeResult();
return true;
}
jw4 is offline   Reply With Quote
Old 07-15-2010, 09:00 AM   #4
curmudgeon
 
Join Date: Mar 2006
Posts: 5,416
Rep Power: 139
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

before you can perform any logic on the contents of a variable you have to make sure the variable even exists.

Next, your section of code is AFTER the sql query that updates the user level so altering the conents of the variale $level doesnt do anything because the users level was previously written to the database already.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 07-15-2010, 01:45 PM   #5
jw4
Junior Member
 
Join Date: Jun 2010
Posts: 19
Rep Power: 7
jw4 is on a distinguished road
Default

Thank yoy very much Larry - it's working now. I have made the update value conditional on the value of $extra, as below.
I'm sure it's not the most elegant way of coding this but I understood what you meant and have managed to achieve what I wanted, so thanks again!

Code:

// update level (user group id) according to extra2 (school)

if ($extra2="Chiswick Community School")
{
$result->freeResult();
$sql = 'UPDATE ' . PREFIX . 'users SET level=6 WHERE uVerify=' . $this->_db->quoteInto($confirmCode);
$result = $this->_db->query($sql);
if ($result->affectedRows() != 1 || $this->_db->isError()) {
$result->freeResult();
return false;
}
}
else
if ($extra2="Teddington")
{
$result->freeResult();
$sql = 'UPDATE ' . PREFIX . 'users SET level=7 WHERE uVerify=' . $this->_db->quoteInto($confirmCode);
$result = $this->_db->query($sql);
if ($result->affectedRows() != 1 || $this->_db->isError()) {
$result->freeResult();
return false;
}
}
// end of modified update code
jw4 is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moderate ADS from user or group philoo Technical Support 2 12-01-2009 04:40 AM
admin user group settings darkqueen Technical Support 7 08-22-2009 05:45 AM
Define user group on sign up rockabilly Technical Support 1 07-06-2009 10:32 PM
User Group Members Login qamarabbas Technical Support 13 03-02-2009 01:29 PM


All times are GMT -4. The time now is 06:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0