Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Functions to add/remove user_id to/from group?

Asked Modified Viewed 4,189 times
H
honeyy
H
honeyy 10
  • Junior Member, joined since
  • Contributed 40 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
asked
Junior Member

Hi...

Ive been checking maincore.php and it seems that functions to remove and add user_id's to/from group isnt there.. Is there anyone who can help me make such functions?
Like: addGroupUser($userid, $groupid); or something similar. checkgroup shouldn't be used tho since this can work for any user_id.

Honeyy
0 replies

4 posts

J
JoiNNN
J
JoiNNN 10
  • Veteran Member, joined since
  • Contributed 850 posts on the community forums.
  • Started 100 threads in the forums
answered
Veteran Member

There are no functions used for this, unfortunately. But this is the code used to add a user to a group and can be find in profile.php
   if (iADMIN && checkrights("UG") && $_GET['lookup'] != $userdata['user_id']) {
      if ((isset($_POST['add_to_group'])) && (isset($_POST['user_group']) && isnum($_POST['user_group']))) {
         if (!preg_match("(^\.{$_POST['user_group']}$|\.{$_POST['user_group']}\.|\.{$_POST['user_group']}$)", $user_data['user_groups'])) {
            $result = dbquery("UPDATE ".DB_USERS." SET user_groups='".$user_data['user_groups'].".".$_POST['user_group']."' WHERE user_id='".$_GET['lookup']."'");
         }
         redirect(FUSION_SELF."?lookup=".$user_data['user_id']);
      }
   }
0 replies
H
honeyy
H
honeyy 10
  • Junior Member, joined since
  • Contributed 40 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
answered
Junior Member

Cool, thanks JoiNNN :)\
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin



function add_to_group($user_id, $group_id) {
global $userdata; // you.

   if (iADMIN && checkrights("UG") && $user_id != $userdata['user_id']) {
   
  $result = dbquery("SELECT user_id, user_group FROM ".DB_USERS." WHERE user_id='$user_id'");
   $udata = (dbrows($result)>0) ? dbarray($result) : array(); // blank string if the user not exist.
   
   if (!preg_match("(^\.{$group_id}$|\.{$group_id}\.|\.{$group_id}$)", $udata['user_group'])) { // ensure the group had not been added to the user earlier.

$update = dbquery("UPDATE ".DB_USERS." SET user_groups='".$udata['user_groups'].".$group_id' WHERE user_id='$user_id'"); // executable function to update rows.

redirect(FUSION_SELF."?lookup=".$user_id['user_id']); // go to user profile.

}

} else {

 print_r("Sorry, you're not admin. You cannot execute this function."); // a notification.
// die(); // crash your server on null input
// redirect(BASEDIR); // to redirect to index page.
// many more options.

}

}



Not sure what function you want, but I took what Dan posted and reassemble it to an executable one so you can run code. The above is an executable.

So to use it in principle, You need 2 variables. 1 user id, 2 group id.
As such if you're in lets say profile.php?lookup='any_number_of_member', have the below.


<form method='post' action='FUSION_SELF.$aidlink'>
<select name='user_group'>...do the opts here.. </select>
<input type='hidden' name='user_id' value='".$_GET['lookup']."'>
<button type='submit' name='add_to_group' value='submit'>Submit</button>
</form>


Then..


if ($_POST['add_to_group']) {

//sanitize
$user_id = (isset($_POST['user_id']) && isnum($_POST['user_id'])) ? stripinput($_POST['user_id']) : "0"; //0 to null

$group_id = (isset($_POST['user_group']) && isnum($_POST['user_group'])) ? stripinput($_POST['user_group']) : "0"; // 0 to null

if ($user_id !=="0" && $user_group !=="0") {
  add_to_group($user_id,$user_group); // execute executable function.
}

} // end if.


I haven't test the code, but the idea is there.. If you paste the function into maincore.php, you can execute anywhere the function the whole PHPFusion. Anyway, I added comment because this is an interesting function to have. If you like functions, you will like 8. The 8 has about hundreds+ new & improvised functions.
0 replies
H
honeyy
H
honeyy 10
  • Junior Member, joined since
  • Contributed 40 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
answered
Junior Member

Ofc i like functions.. especially dbquery :D
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 4 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
H
H
honeyy 10
  • Junior Member, joined since
  • Contributed 40 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
J
J
JoiNNN 10
  • Veteran Member, joined since
  • Contributed 850 posts on the community forums.
  • Started 100 threads in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet