11
xoopdio
Re: user insertion
  • 2011/11/5 4:10

  • xoopdio

  • Just popping in

  • Posts: 29

  • Since: 2011/9/27


Thanks for the link (I just happen to see that it's far more useful with javascript enabled.. )

Quote:
and for the level attribute; level 1 is for people who are activated and level 0 is for those who are not. So everyone should be either a 0 or 1. Sometimes there are some greater than one, but the important thing is that they are greater than 0.

Ok, now it's crystal ! As I was inserting 2 as level value, I could have been waiting and coding a long time..

So now, the module behaves as expected ! I got to test it on a production server as I don't have mail function on my workstation. The next step is to get the process automatized at each registration.

With an Extra thanks to you, I guess it is solved now !

The user_add function code (if it can help someone) :

function user_add($USER_INFOS) 
{
         global 
$xoopsConfig;
        include (
'../../../mainfile.php');
         include_once 
XOOPS_ROOT_PATH . '/kernel/user.php';
         include_once 
XOOPS_ROOT_PATH . '/kernel/object.php';
         include_once 
XOOPS_ROOT_PATH . '/include/functions.php';
          
$table = $this->xoopsDB->prefix('users');
         
$date = time();
         
$user_avatar = 'avatars/blank.gif';
         
$actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
         
$theme = 'zetagenesis';
         
$member_handler =& xoops_gethandler('member');
         
$user =& $member_handler->createUser();
         
$user->setVar('name', $USER_INFOS['NAME'], true);
         
$user->setVar('uname', $USER_INFOS['UNAME'], true);
         
$user->setVar('pass', $USER_INFOS['PASS'], true);
         
$user->setVar('email', $USER_INFOS['EMAIL'], true);
         
$user->setVar('url', $USER_INFOS['URL'], true);
         
$user->setVar('user_avatar', $user_avatar, true);
         
$user->setVar('user_regdate', $date, true);
         
$user->setVar('user_icq', $USER_INFOS['USER_ICQ'], true);
         
$user->setVar('actkey', $actkey, true);
         
$user->setVar('user_aim', $USER_INFOS['USER_AIM'], true);
         
$user->setVar('user_yim', $USER_INFOS['USER_YIM'], true);
         
$user->setVar('user_msnm', $USER_INFOS['USER_MSNM'], true);
         
$user->setVar('theme', $theme, true);
         
$user->setVar('bio', '', true);
         
$user->setVar('uorder', $xoopsConfig['com_order'], true);
         
$user->setVar('umode', $xoopsConfig['com_mode'], true);
         
$user->setVar('level', 0);        // admin activation
         
if($member_handler->insertUser($user))
         {
             
$sql = 'SELECT uid FROM ' . $table . ' WHERE uname = '' . 
                                    $USER_INFOS['
UNAME'] . '';';             
                        
$result = $this->xoopsDB->queryF($sql);
              while(
$row = $this->xoopsDB->fetchRow($result))
             {                 
                                 foreach(
$row as $value)
                 {
                     
$UID = (int)$value;
                 }
             }              
                        
$XoopsMemberShip =& $member_handler->addUserToGroup(2, $UID);                          // admin mail
             
$xoopsMailer =& xoops_getMailer();
             
$xoopsMailer->reset();
             
$xoopsMailer->useMail();
             
$xoopsMailer->setTemplate('adminactivate.tpl');
             
$xoopsMailer->assign('USERNAME', $user->getVar('uname'));
             
$xoopsMailer->assign('USEREMAIL', $user->getVar('email'));
             
$xoopsMailer->assign('USERACTLINK', XOOPS_URL . "/modules/" . 
                                      
$GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/activate.php?id=' .                          $user->getVar('uid') . '&actkey=' . $user->getVar('actkey', 'n'));
             
$xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']);
             
$xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']);
             
$xoopsMailer->assign('SITEURL', XOOPS_URL . "/");             
                        
                  
$xoopsMailer->setToGroups($member_handler->getGroup($GLOBALS['xoopsConfigUser']['activation_group']));
             
$xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
             
$xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
             
$xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $user->getVar('uname')));
             if (!
$xoopsMailer->send())
                        {
                 
$_SESSION['profile_post']['_message_'] = 2;
             } else {
                 
$_SESSION['profile_post']['_message_'] = 3;
             }
         } else {
             
//user not created successfully, you can perhaps get error messages with this:
             
$errors_array = $user->getErrors();
         }     
}
"A tree is made of non-tree elements" Thich Nhat Hanh