News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How do I assign a user group when creating a new user via SSI.php?

Started by Johnsen Design, September 07, 2008, 04:38:02 PM

Previous topic - Next topic

Johnsen Design

I need to find a way to assign the user group for a new user when I create one using SSI.php.

Here is all the code used
As you will see I am also adding a user to something else called SITELOK.
I am integrating SITELOK with SMF so when people pay for a membership and the payment is accepted us administrators will use this form to add the user into both sitelok and smf with the right user group.
So its important that I can set the user group for the user in SMF to :
<?PHP

if ($_POST['group'] == "WEB")
{ $smfgroup = "WebMember"; };

if ($_POST['group'] == "MINI")
{ $smfgroup = "MiniMember"; };

if ($_POST['group'] == "MEDI")
{ $smfgroup = "MediMember"; };

if ($_POST['group'] == "MAXI")
{ $smfgroup = "MaxiMember"; };

if ($_POST['submit'] == "Registrer bruker")
{

require_once ("/home/norskdat/www/slpw/sitelokapi.php");

$result=slapi_addorupdate($_POST['username'],$_POST['password'],$_POST['email'],$_POST['username'],$_POST['group'],356,"","","","",0);

require_once ("/home/norskdat/www/forums/SSI.php");
function createUser(){
global $db_name, $db_prefix, $sourcedir, $boarddir; };

// Let's get this user into SMF...

mysql_select_db($db_name);  //switch to SMF's database, in case these softwares are in different databases.

          $possible_strings = array(
'websiteUrl', 'websiteTitle',
'AIM', 'YIM',
'location', 'birthdate',
'timeFormat',
'buddy_list',
'pm_ignore_list',
'smileySet',
'signature', 'personalText', 'avatar',
'lngfile',
'secretQuestion', 'secretAnswer',
);
$possible_ints = array(
'pm_email_notify',
'notifyTypes',
'ICQ',
'gender',
'ID_THEME',
);
$possible_floats = array(
'timeOffset',
);
$possible_bools = array(
'notifyAnnouncements', 'notifyOnce', 'notifySendBody',
'hideEmail', 'showOnline',
);

// Set the options needed for registration.
$regOptions = array(
'interface' => 'guest',
'username' => $_POST['username'],  //the variable from the form for the inputted username
'email' => $_POST['email'],  //likewise, the email address that was inputted in the form
'password' => $_POST['password'],  //the password that the user inputted
'password_check' => $_POST['password'],  //the second confirmation password inputted
'check_reserved_name' => true,  //this will make sure that SMF first checks for a reserved name before writing the user to the database
'check_password_strength' => true,
'check_email_ban' => true,  //checks for ban on the email address that was inputted
'send_welcome_email' => false,  //true if you want SMF to send an email, false if you want your other software to handle it.  I'd recommend false.
'require' => 'nothing',
'extra_register_vars' => array(),
'theme_vars' => array(),
);



// Include the additional options that might have been filled in.
foreach ($possible_strings as $var)
if (isset($_POST[$var]))
$regOptions['extra_register_vars'][$var] = '\'' . $_POST[$var] . '\'';
foreach ($possible_ints as $var)
if (isset($_POST[$var]))
$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
foreach ($possible_floats as $var)
if (isset($_POST[$var]))
$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
foreach ($possible_bools as $var)
if (isset($_POST[$var]))
$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;

// Registration options are always default options...
if (isset($_POST['default_options']))
$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();

require_once($sourcedir . '/Subs-Members.php');  //require the file, so that we can call the function
$memberID = registerMember($regOptions);  //call the function.  $memberID should return a value.


mysql_select_db($config["db_database"]); //back to the parent software's database...
}

$content="<p>Legg til all medlem info og velg medlemstype!</p><br />
<form id='form' name='form' action='index.php?pid=22' method='post'>
Brukernavn: <input type='text' name='username'/>
Epost: <input type='text' name='email'/>
Passord: <input type='password' name='password'/> (8+ bokstaver!) <br />
Medlemstype:<br />
<input type='radio' name='group' value='MINI'/> Minimember<br />
<input type='radio' name='group' value='MEDI'/> Medimember<br />
<input type='radio' name='group' value='MAXI'/> Maximember<br />
<input type='radio' name='group' value='WEB'/> Webmember<br />
<input type='submit' name='submit' value='Registrer bruker'/>
</form>"; ?>

Nathaniel

$regOptions['memberGroup'] = $id_group;

Replace $id_group with the ID of the group that you want them to be.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

CND Bacon


Nathaniel

CND Bacon,
The code below should do what you want:
<?php
// Change this so that it points to the SSI.php file in your smf directory.
require_once('SSI.php');

require_once(
$sourcedir.'/Subs-Members.php');

$member = 4;
$group = 2;
removeMembersFromGroups(array($member), $group);
?>


Just remember to change the SSI.php path, as well as the $member and $group variables. :)

SSI.php Documentation:
[README] SSI FAQ\'s
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.


Advertisement: