Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
jaredg16
New Member
New Member



Joined: Jun 27, 2006
Posts: 15
Location: Baton Rouge, LA

PostPosted: Fri Jun 30, 2006 3:21 pm Reply with quote

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!
 
View user's profile Send private message AIM Address Yahoo Messenger
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Sat Jul 01, 2006 7:29 pm Reply with quote

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!! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
jaredg16







PostPosted: Tue Jul 04, 2006 11:56 pm Reply with quote

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







PostPosted: Wed Jul 05, 2006 10:30 am Reply with quote

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







PostPosted: Thu Jul 06, 2006 2:57 pm Reply with quote

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







PostPosted: Mon Jul 10, 2006 5:14 pm Reply with quote

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("&amp;","&",$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
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©