The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
php script to add user to group - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: php script to add user to group (/showthread.php?tid=171)



php script to add user to group - caleb - 06-19-2016

does any one know to add the currently logged in user to a permissions group.


php script to add user to group - mudmin - 06-19-2016

I can't think of a way to do that. It seems like it would be a security vulnerability.

I think the better thing to do would be something along the lines of putting...
Code:
if($user->isLoggedIn()){
Code:
//your code here
Code:
}

somewhere on the page to make something accessible to only logged in users. Maybe I'm missing something.

Can you tell me a little bit more about what you're trying to accomplish?


php script to add user to group - caleb - 06-19-2016

I need to add users to a group with out manually doing it. is there any way of doing that


php script to add user to group - mudmin - 06-19-2016

Sure. Let me think through that.


php script to add user to group - mudmin - 06-19-2016

Ok. So when you're on the admin_permissions.php page and you click on a permission, you'll see that each permission level has an id. By default, User level is id 1, Administrator is id 2. As you add more, they go up. I'm guessing you want to add a third level. Take note of its id. (Let's assume it's 3).

So, the user will have to go to a particular page to trigger the "check" to add them to this permission group. Let's assume it's the default account.php. Somewhere at the top, you'll need to add a php check to see if they already have the proper permission.

Code:
<?php
Code:
$check = $db->query("SELECT * from user_permission_matches WHERE user_id = $user->data()->id AND permission_id = 3");
Code:
$count = $check->count();

Code:
if($count<1) { //meaning that permission was not found for that user
Code:
$fields=array('user_id'=>$user->data()->id, 'permission_id'=>3); //column_name=>entry
Code:
$db->insert('user_permission_matches',$fields);
Code:
}
Code:
?>

This is totally off the top of my head, but should point you in the right direction. If you get stuck, let me know.



php script to add user to group - caleb - 06-19-2016

Yes this helps a ton. Thank you.



php script to add user to group - caleb - 06-19-2016

Works great


php script to add user to group - mudmin - 06-19-2016

Awesome! I was a little rusty in my mind on some of that stuff. I'm glad it worked.


php script to add user to group - caleb - 08-27-2016

For some odd reason this stopped working. I tried everything. I just did a fresh install and it still was not working. I have tried it on 2 different servers with different hoses here is the code i am using.


php script to add user to group - mudmin - 08-28-2016

I'm not seeing your code. Can you paste it on hastebin and give me the link?