Author |
Message |
jaredg16
New Member


Joined: Jun 27, 2006
Posts: 15
Location: Baton Rouge, LA
|
Posted:
Fri Jun 30, 2006 3:21 pm |
|
Okay, so I have the Approve_Membership module installed with my phpNuke 7.6. When a user registers, I have it set up so I approve all memberships. When I approve a membership, I have a SWITCH statement that also automatically adds the user into a usergroup based off of information they enter in a field named "custom21". Here is the SWITCH statement:
Quote: | //EDIT by boham & jaredg16 to automatically add members to a group for us using their selection of type of membership
//get users id
$SQL = "SELECT user_id FROM ".$user_prefix."_users WHERE username='$username'";
$resultID = $db->sql_query($SQL);
$SQL2 = "SELECT option_name FROM ".$user_prefix."_options1 WHERE option_name='$custom21'";
if(!$resultID) {
echo ""._ERROR."<br>";
echo mysql_error();
}
$therow = $db->sql_fetchrow($resultID);
$resultID = $therow['user_id'];
$bbUSERID = $therow['user_id']; //same user ID from nuke_users table
//make the decision of what school group they are to be in for the home school
// SWITCH statement for custom 21
switch ($custom21) {
case "Adams State College":
$bbGROUPID = 2;
break;
case "Alabama A & M Univ":
$bbGROUPID = 3;
break;
case "Alabama State Univ":
$bbGROUPID = 4;
break;
case "Arkansas State Univ":
$bbGROUPID = 5;
break;
case "Ball State Univ":
$bbGROUPID = 6;
break;
case "Binghamton Univ":
$bbGROUPID = 7;
break;
case "Bishops Univ":
$bbGROUPID = 8;
break;
case "Boise State Univ":
$bbGROUPID = 9;
break;
case "Bowie State Univ":
$bbGROUPID = 10;
break;
}
// end SWITCH statement for custom 21
if ( $noSend == 1){
echo "ERROR cannot add user to group!";
}
else{
//add the user to the phpBB group for the forums
$addToBBGroup = $db->sql_query("INSERT INTO ".$prefix."_bbuser_group (group_id, user_id, user_pending) VALUES ('$bbGROUPID', '$bbUSERID', '0')");
}//End If |
Now what I would like to do is to also make it so that when a user edits his profile and changes the information in the custom21 field drop-down menu, the user is then automatically deleted from the previous usergroup and added to the new one.
Can anyone help me out with this?!
Thanks! |
|
|
|
 |
gregexp
The Mouse Is Extension Of Arm

Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol
|
Posted:
Sat Jul 01, 2006 7:29 pm |
|
Try this, Ive tried to think of everything here but I may have missed something.
This is written to delete the old group first then add to the new group.
Code:<?php
//EDIT by boham & jaredg16 to automatically add members to a group for us using their selection of type of membership
//get users id
$SQL = "SELECT user_id FROM ".$user_prefix."_users WHERE username='$username'";
$resultID = $db->sql_query($SQL);
$SQL2 = "SELECT option_name FROM ".$user_prefix."_options1 WHERE option_name='$custom21'";
if(!$resultID) {
echo ""._ERROR."<br>";
echo mysql_error();
}else{
$therow = $db->sql_fetchrow($resultID);
$resultID = $therow['user_id'];
$bbUSERID = $therow['user_id']; //same user ID from nuke_users table
//make the decision of what school group they are to be in for the home school
// SWITCH statement for custom 21
switch ($custom21) {
case "Adams State College":
$bbGROUPID = 2;
break;
case "Alabama A & M Univ":
$bbGROUPID = 3;
break;
case "Alabama State Univ":
$bbGROUPID = 4;
break;
case "Arkansas State Univ":
$bbGROUPID = 5;
break;
case "Ball State Univ":
$bbGROUPID = 6;
break;
case "Binghamton Univ":
$bbGROUPID = 7;
break;
case "Bishops Univ":
$bbGROUPID = 8;
break;
case "Boise State Univ":
$bbGROUPID = 9;
break;
case "Bowie State Univ":
$bbGROUPID = 10;
break;
}
// end SWITCH statement for custom 21
if ( $noSend == 1){
echo "ERROR cannot add user to group!";
}
else{
//add the user to the phpBB group for the forums
$deleteuserfromoldgroup=$db->sql_query("DELETE FROM `".$prefix."_bbuser_group` WHERE user_id='$SQL");
if ( !$deleteuserfromoldgroup){
echo "Mysql said ".mysql_error()."";
}else{
$addToBBGroup = $db->sql_query("INSERT INTO ".$prefix."_bbuser_group (group_id, user_id, user_pending) VALUES ('$bbGROUPID', '$bbUSERID', '0')");
if ( !$addToBBGroup){
echo "$db-sql said ".$db->sql_error()."";
}else{
}
}
}
}
?>
|
|
_________________ For those who stand shall NEVER fall and those who fall shall RISE once more!! |
|
 |
 |
jaredg16

|
Posted:
Tue Jul 04, 2006 11:56 pm |
|
okay... so this is what I was told by the author of the custom field mods:
Quote: | Work in modules/Your_Account/index.php. The value of $custom21 is passed to the saveuser() function separately (no for loops to mess with). There are two update queries (one for if the password is to be changed and the other if it isnt). Before you get to that stage, pull the value of custom21 from the database for this user then if the new value is different, do something, else do nothing.
Your do something will be to delete this user from the existing group and insert into the new group depending on the new value of custom21. Do all the above just before:
Code:
if (!empty($user_password)) {
which is after all validations have been carried out but before the new values are updated for this user. |
What is the way I should write the if statement he's talking about? |
|
|
|
 |
gregexp

|
Posted:
Wed Jul 05, 2006 10:30 am |
|
What hes saying is like this
example:
Just a point of reference for you to see.
//$custom21 options:1,2,3,4.........;
Get the new info from what they selected.
$custom=$_POST['$custom21field']';
Get the old info.
sql1= (get original contents of custom21field where userid=userid);
if ($sql1!=$custom){
Delete from table statement;
Insert in new table field;
If they remain in the same table table field, Its better to use an UPDATE statement instead of deleting then adding it.
}
Does the rest AFTER the aabove} but will not run the above statement if they are equal to eachother. |
|
|
|
 |
jaredg16

|
Posted:
Thu Jul 06, 2006 2:57 pm |
|
this isn't working... where's the problem? It's not saving the custom21 field if it's changed in the edit profile page NOR is it deleting the user from the old custom21 usergroup NOR adding the user to the newly chosen custon21 usergroup.
Quote: | // edit by jaredg16
// Get the new info from what they selected.
$custom21 = $_POST['$custom21'];
// Get the old info
$SQL = "SELECT custom21, user_id FROM ".$user_prefix."_users WHERE username='$username'";
$resultID = $db->sql_query($SQL);
$SQL1 = "SELECT option_name FROM ".$user_prefix."_options1 WHERE option_name='$custom21'";
if(!$resultID) {
echo ""._ERROR."<br>";
echo mysql_error();
}
$therow = $db->sql_fetchrow($resultID);
$custom21 = $therow['custom21'];
$resultID = $therow['user_id'];
$bbUSERID = $therow['user_id']; //same user ID from nuke_users table
if ($SQL != $custom21){
//make the decision of what school group they are to be in for the home school
// SWITCH statement for custom 21
switch ($custom21) {
case "Adams State College":
$bbGROUPID = 2;
break;
case "Alabama A & M Univ":
$bbGROUPID = 3;
break;
case "Alabama State Univ":
$bbGROUPID = 4;
break;
case "Arkansas State Univ":
$bbGROUPID = 5;
break;
case "Ball State Univ":
$bbGROUPID = 6;
break;
case "Binghamton Univ":
$bbGROUPID = 7;
break;
case "Bishops Univ":
$bbGROUPID = 8;
break;
case "Boise State Univ":
$bbGROUPID = 9;
break;
case "Bowie State Univ":
$bbGROUPID = 10;
break;
default:
$noSend = 1;
break;
}
// end SWITCH statement for custom 21
if ( $noSend == 1){
echo "ERROR cannot add user to group!";
} else {
//add the user to the phpBB group for the forums
$deleteuserfromoldgroup=$db->sql_query("DELETE FROM `".$prefix."_bbuser_group` WHERE user_id='$resultID' AND group_id='$bbGROUPID'");
if (!$deleteuserfromoldgroup){
echo "Mysql said ".mysql_error()."";
} else {
$addToBBGroup = $db->sql_query("INSERT INTO ".$prefix."_bbuser_group (group_id, user_id, user_pending) VALUES ('$bbGROUPID', '$bbUSERID', '0')");
}
if (!$addToBBGroup){
echo "$db-sql said ".$db->sql_error()."";
} else {}
}//End If
}
/// end editing to automatically change members' usergroups |
|
|
|
|
 |
jaredg16

|
Posted:
Mon Jul 10, 2006 5:14 pm |
|
okay... got it... this is how to make that switch!
Quote: | // Get the old info for custom21
$SQL = "SELECT custom21, user_id FROM ".$user_prefix."_users WHERE username='$username'";
$resultID = $db->sql_query($SQL);
if(!$resultID) {
echo ""._ERROR."<br>";
echo mysql_error();
}
$therow = $db->sql_fetchrow($resultID);
$oldcustom21 = str_replace("&","&",$therow['custom21']);
$bbUSERID = $therow['user_id']; //same user ID from nuke_users table
if($oldcustom21 == $custom21) {
// if same, do nothing
} else {
// getting the old usergroup to see if it needs to be deleted.
switch ($oldcustom21) {
case "Adams State College":
$oldbbGROUPID = 2;
break;
case "Alabama A & M Univ":
$oldbbGROUPID = 3;
break;
case "Alabama State Univ":
$oldbbGROUPID = 4;
break;
case "Arkansas State Univ":
$oldbbGROUPID = 5;
break;
default:
$noSend = 1;
break;
}
// end SWITCH statement for custom 21
//make the decision of what school group they are to be in for the home school
// SWITCH statement for custom 21
switch ($custom21) {
case "Adams State College":
$bbGROUPID = 2;
break;
case "Alabama A & M Univ":
$bbGROUPID = 3;
break;
case "Alabama State Univ":
$bbGROUPID = 4;
break;
case "Arkansas State Univ":
$bbGROUPID = 5;
break;
default:
$noSend = 1;
break;
}
// end SWITCH statement for custom 21
if ($noSend == 1) {
echo "ERROR cannot add user to group!";
} else {
//add the user to the phpBB group for the forums for custom21
$db->sql_query("DELETE FROM ".$user_prefix."_bbuser_group WHERE user_id='$bbUSERID' AND group_id='$oldbbGROUPID'");
$addToBBGroup = $db->sql_query("INSERT INTO ".$prefix."_bbuser_group (group_id, user_id, user_pending) VALUES ('$bbGROUPID', '$bbUSERID', '0')");
} //End If
}
// end editing to automatically change members' usergroup for custom21 |
|
|
|
|
 |
|