vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Add new Users (automatically) (https://vborg.vbsupport.ru/showthread.php?t=82836)

dionsis 01-10-2008 04:43 PM

Ok can anyone including the developers out there suggest a method for solving

PHP Fatal error: Call to a member function query_first_slave() on a non-object in /path/to/my/forum/includes/functions.php on line 1194

from doing a bit of research it seems this error comes up mostly when a file X.php included file Y.PHP and Y.PHP would include the code for adding a user and in turn would include the globals.php, class_dm.php and class_dm_user.php

so it seems nested including is a problem for objects further down the line

has anyone got any idea's of how we can solve this issue as i'd like to make use of the datamanager for inserting users rather than the silly method of SQL inserting which isnt the best method going

Opserty 01-11-2008 01:35 PM

Quote:

Originally Posted by dionsis (Post 1419037)
Ok can anyone including the developers out there suggest a method for solving

PHP Fatal error: Call to a member function query_first_slave() on a non-object in /path/to/my/forum/includes/functions.php on line 1194

from doing a bit of research it seems this error comes up mostly when a file X.php included file Y.PHP and Y.PHP would include the code for adding a user and in turn would include the globals.php, class_dm.php and class_dm_user.php

Make sure you include global.php (not globals.php) at the very top of your script, the advised method of doing so is with a chdir().
PHP Code:

// Start of script
$cwd getcwd();
chdir('path/to/your/forums');
require_once(
'global.php');
// Place any other vBulletin files you need to include here. 
// datamanger_init....possibly?
chdir($cwd);

// Include your extra files here 

Try it out.

dionsis 01-14-2008 12:32 AM

i do include global.php

Quote:

$cwd = getcwd();
chdir('/home/content/d/i/o/dionsis/html/acuffe/test/forum');
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');
chdir($cwd);

$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', $username);
$userdm->set('email', $email);
$userdm->set('password', $password);
$userdm->set('usergroupid',$usergroupid);
//$userdm->set('ipaddress', $ipaddress);
$userdm->set('timezoneoffset', $timezoneoffset);
$userdm->set_bitfield('options', 'adminemail', '1');
$userdm->set_bitfield('options', 'showemail', '1');

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors))
{
for($i=0; $i<count($userdm->errors); $i++)
{
print "ERROR{$i}:{$userdm->errors[$i]}\n";
return(false);
}
}
else
{
# If everything is OK
$newuserid = $userdm->save();
print "vbuserid:$newuserid\n";
return(true);
}

dionsis 01-24-2008 12:08 PM

Nobody have any idea's on this? i might post this to the vbulletin programming forum and see if anyone see's it better there

scoopr 02-01-2008 12:26 PM

I was pleased to find amatulic's class.forumops.php as that was exactly what I needed, excellent work!

However, I found the user login part of it acting a bit weird.

PHP Code:

   function login($vbuser)
   {
      global 
$vbulletin;
      
$vbulletin->userinfo fetch_userinfo_from_username($vbuser['username']);
      
// set cookies
      
vbsetcookie('userid'$vbulletin->userinfo['userid'],
         
PERMANENT_COOKIEtruetrue);
      
vbsetcookie('password',
         
md5($vbulletin->userinfo['password'].COOKIE_SALT),
         
PERMANENT_COOKIEtruetrue);
      
// create session stuff
      
process_new_login(''1'');
   } 


If you look at the function, it does not use the $vbuser['password'] value at any point! This means, if you use this login function in some page, it logs in successfully any user no matter what she supplied as her password!

You might need forcing successful login when you have custom user database you check against yourself and want to ignore vbulletin user database and still be logged in to vbulletin, but in my eyes, the class implied it actually checked against the vb user database (the comments have an example where it supplied the password).

I replaced the login method as follows, now it returns true when the login is successfully, false otherwise. I'm not totally sure if the md5 passwords are totally correct here, but seem to work in my quick test.

PHP Code:

   function login($vbuser)
   {

        return 
verify_authentication($vbuser['username'], 
                                   
$vbuser['password'], 
                                   
md5(htmlentities($vbuser['password'], ENT_NOQUOTES"UTF-8")), 
                                   
md5($vbuser['password']), 
                                   
1true);

   } 


Feel free to comment if I had misunderstood something, but I felt it would be important bring this issue up, if someone else uses this class as a login method assuming the same thing as I did.

Oh, and this skips the userdata conversion part, as I felt it was a bit pointless in this context.

Iron Guard 02-11-2008 08:32 AM

I have found the datamanager_user class (class_dm_user.php) in the includes folder of the vbulletin directory on my server.

Now could anybody please suggest me what files do I need to include in my script before I could instantiate the datamanager object and run the add process successfully?

1. What files do I need to include in my script to create a database connection?
2. Any function files that I need to include to run the process successfully?
3. Any other class file that is related with this class_dm_user.php file and required to be included as well?

Thanks.

WebConnection 02-14-2008 06:10 AM

Is there any tables may be affected when adding a new user except for the 'user' table? If so, what are they?

matzelkoenig 03-25-2008 04:55 PM

I am using your functions in my project and it worked very well! But now I want to add also an customavatar picture for new users. How can I do this with your ForumOps Code?

upnorth 04-01-2008 12:04 PM

Can anyone tell me where there might be a complete updated list of what can be set for a new user in vB 3.6.9 Seems the list provided in the initial post (see below) is a little dated.

Quote:

Originally Posted by Andreas (Post 664586)
...
You can also set many other info too:
  • membergroupids = comma-separated string of all additional usergroups (Default=Empty)
  • displaygroupid = ID of the usergroup this user should show up as (Default=0)
    Note that this must be set after usergroupid and membergroupids!
  • styleid = ID of the Style to be used by this user (Default=Board Default)
  • languageid = ID of the language to be used by this user (Default=Board Default)
  • threadedmode = Whether to use Flat (0), Hybrid (1) or Threaded (2) Display Mode
  • maxposts = Integer, how many posts should be shown on one Page (Default=Board Default)
  • ipaddress = String, IP-Adress of the User registering (Default=Empty)
  • refererid = String, Username or UserID of the User this user was refered by
  • parentemail = String. eMail-Address of the users Parents
  • daysprune = Integer, show threads from the last X days
  • startofweek = Integer, When does the week start (1=Sunday, 2=;onday, ...) (Default=Board Default)
  • timezoneoffset = Integer, spexifying the Timezone (-12 .. +12)
  • autosubscribe = Integer, defining default mode for Thread subscription
    -1 = no Subscription, 1 = Instant, 2 = Daily Digest, 3 = Weekly Digest
    (Default=Board Default)
  • homepage = String, URL of the users Homepage (Default=Empty)
  • icq = String, the Users ICQ # (Default=Empty)
  • aim = String, the Users AIM ID (Default=Empty)
  • yahoo = String, the Users Yahoo ID (Default=Empty)
  • MSN = String, the Users MSN ID (Default=Empty)
  • usertitle = String, the Usertitle this user should have
  • customtitle = Integer, defining behaviour of Usertitle. 0=No Custom Title, 1=Custom, Title with HTML, 2=Custom Title without HTML (Default=
  • birthday = array(month, day, year). The users birthdate.
  • avatarid = Integer, ID of the Avatar being used for this user
  • signature = String. The Users Signature
  • subfolders = Array. The Users Subscription Folders
  • pmfolders = Array. The Users Subscription Folders
  • buddylist = String. Space separated List of UserIDs defining the Users buddylist
  • ignorelist = String. Space separated List of UserIDs defining the Users ignorelist
...
  • showsignatures = Show Signatures
  • showavatars = Show Avatars
  • showimages = Show Images, incl. attached Images and [img] BBCode
    If this is not set they will show up as links
  • coppauser = User is COPPA User
  • adminemail = Receive Admin eMails
  • showvcard = Allow vCard Download
  • dstauto = Automatically detect DST setting
  • dstonoff = DST turned On
  • showemail = Receive eMails from other Users
  • invisible = Be invisible
  • showreputation = Show Reputation
  • receivepm = PM turned on
  • emailonpm = eMail notification for new PMs

....


Opserty 04-02-2008 07:14 AM

Quote:

Originally Posted by upnorth (Post 1480002)
Can anyone tell me where there might be a complete updated list of what can be set for a new user in vB 3.6.9 Seems the list provided in the initial post (see below) is a little dated.

I don't think there have be many changes, maybe just ask about a specific field either in this thread of one of the other vBulletin.org forums.

upnorth 04-02-2008 01:49 PM

The ones I seem to be running into problems with are the ones below:

$newuser->set_bitfield('options', 'receivepm', '1');
--this dosn't seem to set the "Receive Private Messages" for the user to "Yes"

$newuser->set_bitfield('options', 'emailonpm', '1');
--this dosn't seem to set the "Send Notification Email When a Private Message is Received" for the user to "Yes"

Pop up a Notification Box When a Private Message is Received
--not sure what the option is to set this one?

Opserty 04-02-2008 02:59 PM

Try:
PHP Code:

 $newuser->set_bitfield('options''receivepm'true); 

Does that work?

upnorth 04-02-2008 03:19 PM

nope, didn't work

JulienT 04-13-2008 05:13 PM

This was a really good code that helped me integrate VB with my existing website.
Any idea if those functions will still work in 6.7?
I will wait for the final release of course of 6.7, but having this code working is a key factor for me to upgrade or not.

So if someone has tried this code on 6.7, please let us know.

Thanks.

binevi 04-13-2008 09:03 PM

Can anyone explain step by step? How and where do we suppose to put these codes ;(

upnorth 04-24-2008 04:28 PM

Still running into problems with these as well as showimages

Anyone? Anyone lol :D

Quote:

Originally Posted by upnorth (Post 1480978)
The ones I seem to be running into problems with are the ones below:

$newuser->set_bitfield('options', 'receivepm', '1');
--this dosn't seem to set the "Receive Private Messages" for the user to "Yes"

$newuser->set_bitfield('options', 'emailonpm', '1');
--this dosn't seem to set the "Send Notification Email When a Private Message is Received" for the user to "Yes"

Pop up a Notification Box When a Private Message is Received
--not sure what the option is to set this one?


coffeesgr 05-25-2008 09:20 AM

Anyone know how to fix error:
Quote:

Fatal error: Registry object is not an object in [path]/includes/class_dm.php on line 177
#0 vb_error_handler(256, Registry object is not an object, /home/gymchat/public_html/messageboards/includes/class_dm.php, 177, Array ([this] => vB_DataManager_User Object ([validfields]

Quote:

Originally Posted by novastar (Post 1105250)
i use a modified version of the code they gave a couple posts back which works great for me.
Code:

<?php
$username="username";
$email="email@address.com";
$password="password";
$usergroupid="2";
$timezoneoffset="-6";
define('THIS_SCRIPT', 'remote_register.php');
chdir('/home/site/public_html/forum');
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');
$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', $username);
$userdm->set('email', $email);
$userdm->set('password', $password);
$userdm->set('usergroupid',$usergroupid);
$userdm->set('ipaddress', $ipaddress);
$userdm->set('timezoneoffset', $timezoneoffset);
$userdm->set_bitfield('options', 'adminemail', '1');
$userdm->set_bitfield('options', 'showemail', '1');

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
} else {
# If everything is OK
$newuserid = $userdm->save();
print "vbuserid:$newuserid\n";
}
chdir('/home/site/public_html/');
?>

I would have taken more time to tinker with it, and possibilly put it in a function, but as there is only 1 place in my scripting but that works fine for me.
Im running it on vBulletin 3.6.2


grenma 05-27-2008 11:02 PM

This is the only auto-login/auto-register/integration information in all of support as far as I can tell. It is 3 years old and, while giving thanks to the author and noting that it is better than nothing, it hardly classifies as much more than a code snippet. I've seen dozens of posts on integration here that could be addressed by expanding and updating this information- surely it is not too much to ask?

--------------- Added [DATE]1211943709[/DATE] at [TIME]1211943709[/TIME] ---------------

Thank You!

--------------- Added [DATE]1211943812[/DATE] at [TIME]1211943812[/TIME] ---------------

Quote:

Originally Posted by coffeesgr (Post 1530799)
Anyone know how to fix error:

This did the trick for me

--------------- Added [DATE]1211943912[/DATE] at [TIME]1211943912[/TIME] ---------------

changing to the vb install directory is the key

coffeesgr 05-28-2008 02:25 AM

What fixed the error for you?

This does change to the vb directory:
chdir('/home/site/public_html/forum');

wassimeh 06-10-2008 01:35 PM

Thanks coffeesgr your code works #1 when executed directly; unfortunately it won't work when i use it inside a $_POST action.. please help.. what am I doing wrong ? here's my code below

Quote:

<?php
//Ajouter l'utilisateur dans la database du forum
if(isset($_POST['btn_update'])){
/*
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['password'];
$usergroupid=$_POST['usergroupid'];
$timezoneoffset="-5";
*/
$username="username";
$email="email@address.com";
$password="password";
$usergroupid="2";
$timezoneoffset="-5";

define('THIS_SCRIPT', 'remote_register.php');
chdir('forum/');
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');
$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', $username);
$userdm->set('email', $email);
$userdm->set('password', $password);
$userdm->set('usergroupid',$usergroupid);
$userdm->set('ipaddress', $ipaddress);
$userdm->set('timezoneoffset', $timezoneoffset);
$userdm->set_bitfield('options', 'adminemail', '1');
$userdm->set_bitfield('options', 'showemail', '1');

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
}
else{
# If everything is OK
$newuserid = $userdm->save();
}
chdir('..');
}


?>
<form name='f_updaccess' method='post' action='test.php'>
username : <input type='textarea' name='username' value='user2'>
email : <input type='textarea' name='email' value='email@haha.ca'>
pass : <input type='textarea' name='password' value='password'>
usergroup : <input type='textarea' name='usergroupid' value='9'>
<input type='submit' name='btn_update'>
</form>

nautiboy 06-14-2008 12:15 AM

I know this question was asked earlier, but it was never answered.

Is there any way to handle the case where the password you have is an md5 hash? I don't like sending passwords in the clear, so my login pages do the md5 hash before sending up to the server, so I don't have access to the actual password.

Any ideas?

--------------- Added [DATE]1213414760[/DATE] at [TIME]1213414760[/TIME] ---------------

OK, I've managed to answer my own question. It turns out that you can use md5's also. If you pass in a plain-text, it will md5 it. But if you pass in an md5, it will use it as-is (basically it just checks to see if the password is 32 characters long - if it is, it assumes it's an md5).

So it "just works". Cool! :up:

scoutz 06-26-2008 06:23 AM

I don't know if this has been covered yet but if you would like to show the username and userid in your activation mail you just have to set $username and $userid to the appropriate values.

ram94401 07-08-2008 02:59 AM

Quote:

Originally Posted by bradsears (Post 1002413)
Hi. I'd like to be able to send the registration email after the user registers. How do I do this. Thanks in advance.

-- edit --

I answered this one myself

$activateid = build_user_activation_id($newuserid, 2, 0);
eval(fetch_email_phrases('activateaccount'));
vbmail($email, $subject, $message, true);


Thanks. But, when you do $userdm->save, won't the user is automatically activated? I assume that you used the code in https://vborg.vbsupport.ru/showpost....&postcount=31;

--------------- Added [DATE]1215493772[/DATE] at [TIME]1215493772[/TIME] ---------------

All right. This entire integration thing works partially for me. After getting frustrated, I wrote the program to get the user data from the form and update the Vbulletin tables directly.

Here is the logical flow:

1. I updated user and useractivation tables with the user information. I set the usergroupid as "3" (users waiting for email activation group) in user table and added the row for the new user in useractivation table. This row will be deleted when the user activates the account.

2. I sent the activation email to the user. This is a nice thing, because I can customize the email format. If a user registers in the main site and the forum sends the activation email, it looks kind of weird. Because some users of our CMS site don't even know what is a forum.

3. User clicks the link in the activation email. Program checks the activation id in the useractivation table. If everything is ok, the usergroupid is changed from 3 to 2 in usertable. Activation record in useractivation table is deleted, because it's no longer needed.

Ok. All works well. The user can do anything he wants just as he would normally do when he registers using forums/register.php.

But..(you know it's coming!) there is a headache for the admin. In the admin control panel, username, email, IP, and all those fields are EMPTY for this user. Options like receive admin email, PM options, etc., are all set ok. Only the username, email, IP fields are empty.

Do I need to update another table? Doesn't admin control panel use the user table to display the user profile?

ArbuZz 07-10-2008 05:38 PM

Personally I got very odd:"Existing data passed is not an array" while using amatulic's class and when doing:

Quote:

$userdata['username'] = $_POST['username'];
$userdata['password'] = $_POST['password'];
$userdata['email'] = $_POST['email'];
$forum->register_newuser($userdata));
What maybe the problem? Anyone?

--------------- Added [DATE]1215718968[/DATE] at [TIME]1215718968[/TIME] ---------------

Quote:

Called set_existing in ..class.forumops.php on line 296
Called login in ..class.forumops.php on line 153
I guess this has something with vBulletin's way to manage database connections :(

--------------- Added [DATE]1215719381[/DATE] at [TIME]1215719381[/TIME] ---------------

This doesn't help:

Quote:

$cwd = getcwd();
chdir('.../forum');
require_once('global.php');
chdir($cwd);
--------------- Added [DATE]1215760256[/DATE] at [TIME]1215760256[/TIME] ---------------

ok. for some unknown reason in the userdata_convert function exist the following line:
Quote:

$vbuser = array( 'username' => $userdata['userid'] );
:confused: but why?! I guess it has to be:

Quote:

$vbuser = array( 'username' => $userdata['username'] );
I've moved amatulic's class in the different place, stored variables in $_SESSION and called header redirect to it. So that now it has totally separated namespace. However I'm not sure if this is secure thing to do.

As I've figured out, there is some problem with login part, cause as soon as I turned it off, I was able to register user in vBulletin. At least it has showed up in the database.

--------------- Added [DATE]1215760677[/DATE] at [TIME]1215760677[/TIME] ---------------

It is "function fetch_userinfo_from_username" that does the trouble. It is not able to retrieve the information from database with its:

Quote:

...
global $vbulletin;
$useridq = $vbulletin->db->query_first_slave("SELECT userid FROM " . TABLE_PREFIX . "user WHERE username='{$username}'");
...
Any ideas how to correct this?

--------------- Added [DATE]1215769463[/DATE] at [TIME]1215769463[/TIME] ---------------

ok. for some reason $login variable is set to true in register_newuser so that it tries to login user by default as soon as he/she is registered. However it seems that user is not inserted in database yet, when the function tries to login him/her. I don't know why, but that's what happens. So I've turned $login to false, like this:

Quote:

function register_newuser(&$userdata, $login = false)
Also I rewrote db connection, but I think It worked without it. Now everything works. Thank you amatulic. I've lost two days figuring out the faults, but thanks god it works and that's the best news :) Here is my working version if anyone's interested:

PHP Code:

<?php
//==============================================================
// class ForumOps - intended to be used with vBulletin 3.7.2
// by Alex Matulich, June 2008, Unicorn Research Corporation
//
// Setup:
// ------
//
// 1. First, make sure FORUMPATH is defined properly below.
//
// 2. Next, make sure the function userdata_convert correctly converts
// an array of your own user data to an array of vBulletin user data.
// Minimally, you need to convert your data to an array containing
// the keys 'username', 'password', and 'email'.  If your data array
// already contains these keys, simply have userdata_convert return
// the original array, otherwise translate your array to a vBulletin
// array having those keys.
//
// Usage:
// ------
//
// At the top of your php modules where you need to perform vBulletin
// user operations (creation, deletion, updating, login, and logout),
// put these two lines (where MY_PATH is the path to this file):
//
//     require_once(MY_PATH.'/class.forumops.php');
//     $forum = new ForumOps();
//
// Now get your user data array from $_POST or whatever.  Let's call
// this array $userdata.  Here's what you can do:
//
// CREATE AND REGISTER NEW USER:
//
//    $errmsg = $forum->register_newuser($userdata);
//
// UPDATE EXISTING USER DATA:
//
//    $errmsg = $forum->update_user($userdata);
//
// (In this case, $userdata need contain only the username and anything
// else you wish to update, such as password and/or email address.)
//
// $errmsg contains any error messages separated by <br> codes.
// If no errors occured then NULL is returned.
//
// DELETE USER:
//
//    $forum->delete_user($username); // $username = user name
//
// LOGIN USER TO THE FORUM:
//
//    $forum->login(  // requires array to be passed
//       array('username' => $username, 'password' => $pw);
//
// LOG OFF USER FROM THE FORUM:
//
//    $forum->logout();
//
// WARNING: It is common for you to have TABLE_PREFIX defined for
// your own database.  You must call it something else (for example,
// remove the underscore) or it will conflict with the vBulletin
// definition of the same name.
//===============================================================

//===============================================================
// Change this definition and the userdata_convert() function
// to suit your needs:

define('FORUMPATH'$_SERVER['DOCUMENT_ROOT'].'/forum'); // path to your forum

function userdata_convert(&$userdata// internal function
{
   
// $userdata is our array that contains user data from our own
   // user database, which we must convert to the vBulletin values.
   // Minimally, it must contain the username, email and/or password.

   // required fields
   
$vbuser = array( 'username' => $userdata['username'] );
   if (isset(
$userdata['email']))
      
$vbuser['email'] = $userdata['email'];
   if (isset(
$userdata['password']))
      
$vbuser['password'] = $userdata['password'];

   
// extra stuff, expand as desired
   
if ($userdata['birthdate'])
      
$vbuser['birthday_search'] = date('Y-m-d'$userdata['birthdate']);
   return 
$vbuser;
}
// end of configuration stuff
//===============================================================

define('REGISTERED_USERGROUP'2); // typical default for registered users
define('PERMANENT_COOKIE'false); // false=session cookies (recommended)

define('THIS_SCRIPT'__FILE__);
$cwd getcwd();
chdir(FORUMPATH);
require_once(
'./global.php');
require_once(
'./includes/init.php'); // includes class_core.php
require_once('./includes/class_dm.php'); // for class_dm_user.php
require_once('./includes/class_dm_user.php'); // for user functions
require_once('./includes/functions.php'); // vbsetcookie etc.
require_once('./includes/functions_login.php'); // process login/logout


//---------------------------------------------------------------------
// This function duplicates the functionality of fetch_userinfo(),
// using the user name instead of numeric ID as the argument.
// See comments in includes/functions.php for documentation.
//---------------------------------------------------------------------
function fetch_userinfo_from_username($username$option=0$languageid=0)
{
   global 
$vbulletin$db;
   
$result $db->query("SELECT * FROM "
      
TABLE_PREFIX "user WHERE username = '".$username."'");
    
$useridq $db->fetch_array($result);  
   if (!
$useridq) return $useridq;
   
$userid $useridq['userid'];
   return 
fetch_userinfo($userid$option$languageid);
}


//---------------------------------------------------------------------
// CLASS ForumOps
//---------------------------------------------------------------------
class ForumOps extends vB_DataManager_User {
   var 
$userdm;

   function 
ForumOps() // constructor
   
{
      global 
$vbulletin;
      
$this->userdm =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
   }


   
//======== USER REGISTRATION / UPDATE / DELETE ========

   
function register_newuser(&$userdata$login false)
   {
      global 
$vbulletin;
      
$vbuser userdata_convert($userdata);
      foreach(
$vbuser as $key => $value)
         
$this->userdm->set($key$value);
      
$this->userdm->set('usergroupid'REGISTERED_USERGROUP);

      
// Bitfields; set to desired defaults.
      // Comment out those you have set as defaults
      // in the vBuleltin admin control panel
      
$this->userdm->set_bitfield('options''adminemail'1);
      
$this->userdm->set_bitfield('options''showsignatures'1);
      
$this->userdm->set_bitfield('options''showavatars'1);
      
$this->userdm->set_bitfield('options''showimages'1);
      
$this->userdm->set_bitfield('options''showemail'0);

      if (
$login$this->login($vbuser);

      
//$this->userdm->errors contains error messages
      
if (empty($this->userdm->errors))
         
$vbulletin->userinfo['userid'] = $this->userdm->save();
      else
         return 
implode('<br>'$this->userdm->errors);
      return 
NULL;
   }


   function 
update_user(&$userdata)
   {
      global 
$vbulletin;
      
$vbuser userdata_convert($userdata);
      if (!(
$existing_user fetch_userinfo_from_username($vbuser['username'])))
         return 
'fetch_userinfo_from_username() failed.';

      
$this->userdm->set_existing($existing_user);
      foreach(
$vbuser as $key => $value)
         
$this->userdm->set($key$value);

      
// reset password cookie in case password changed
      
if (isset($vbuser['password']))
         
vbsetcookie('password',
            
md5($vbulletin->userinfo['password'].COOKIE_SALT),
            
PERMANENT_COOKIEtruetrue);

      if (
count($this->userdm->errors))
         return 
implode('<br>'$this->userdm->errors);
      
$vbulletin->userinfo['userid'] = $this->userdm->save();
      return 
NULL;
   }


   function 
delete_user(&$username)
   {
   
// The vBulletin documentation suggests using userdm->delete()
   // to delete a user, but upon examining the code, this doesn't
   // delete everything associated with the user.  The following
   // is adapted from admincp/user.php instead.
   // NOTE: THIS MAY REQUIRE MAINTENANCE WITH NEW VBULLETIN UPDATES.

      
global $vbulletin;
      
$db = &$vbulletin->db;
      
$userdata $db->query_first_slave("SELECT userid FROM "
         
TABLE_PREFIX "user WHERE username='{$username}'");
      
$userid $userdata['userid'];
      if (
$userid) {

      
// from admincp/user.php 'do prune users (step 1)'

         // delete subscribed forums
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"subscribeforum WHERE userid={$userid}");
         
// delete subscribed threads
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"subscribethread WHERE userid={$userid}");
         
// delete events
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"event WHERE userid={$userid}");
         
// delete event reminders
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"subscribeevent WHERE userid={$userid}");
         
// delete custom avatars
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"customavatar WHERE userid={$userid}");
         
$customavatars $db->query_read("SELECT userid, avatarrevision FROM "
          
TABLE_PREFIX "user WHERE userid={$userid}");
         while (
$customavatar $db->fetch_array($customavatars)) {
            @
unlink($vbulletin->options['avatarpath'] . "/avatar{$customavatar['userid']}_{$customavatar['avatarrevision']}.gif");
         }
         
// delete custom profile pics
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"customprofilepic WHERE userid={$userid}");
         
$customprofilepics $db->query_read(
            
"SELECT userid, profilepicrevision FROM "
            
TABLE_PREFIX "user WHERE userid={$userid}");
         while (
$customprofilepic $db->fetch_array($customprofilepics)) {
            @
unlink($vbulletin->options['profilepicpath'] . "/profilepic$customprofilepic[userid]_$customprofilepic[profilepicrevision].gif");
         }
         
// delete user forum access
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"access WHERE userid={$userid}");
         
// delete moderator
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"moderator WHERE userid={$userid}");
         
// delete private messages
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"pm WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"pmreceipt WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"session WHERE userid={$userid}");
         
// delete user group join requests
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"usergrouprequest WHERE userid={$userid}");
         
// delete bans
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"userban WHERE userid={$userid}");
         
// delete user notes
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"usernote WHERE userid={$userid}");

      
// from admincp/users.php 'do prune users (step 2)'

         // update deleted user's posts with userid=0
         
$db->query_write("UPDATE " TABLE_PREFIX
            
"thread SET postuserid = 0, postusername = '"
            
$db->escape_string($username)
            . 
"' WHERE postuserid = $userid");
         
$db->query_write("UPDATE " TABLE_PREFIX
            
"post SET userid = 0, username = '"
            
$db->escape_string($username)
            . 
"' WHERE userid = $userid");

         
// finally, delete the user
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"usertextfield WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"userfield WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"user WHERE userid={$userid}");
      }
   
/*
      the following is suggested in the documentation but doesn't work:

      $existing_user = fetch_userinfo_from_username($username);
      $this->userdm->set_existing($existing_user);
      return $this->userdm->delete();
   */
   
}


   
// ======== USER LOGIN / LOGOUT ========

   
function login($vbuser)
   {
      global 
$vbulletin;
      
$vbulletin->userinfo fetch_userinfo_from_username($vbuser['username']);
      
      
// update password expire time to
      // to prevent vBulletin from expiring the password
           
      
$this->userdm->set_existing($vbulletin->userinfo);
      
$this->userdm->set('passworddate''FROM_UNIXTIME('.TIMENOW.')'false);
      
$this->userdm->save();

      
// set cookies
      
vbsetcookie('userid'$vbulletin->userinfo['userid'],
         
PERMANENT_COOKIEtruetrue);
      
vbsetcookie('password',
         
md5($vbulletin->userinfo['password'].COOKIE_SALT),
         
PERMANENT_COOKIEtruetrue);

      
// create session stuff
      
process_new_login(''1'');
   }


   function 
logout()
   {
      
process_logout(); // unsets all cookies and session data
   
}

// end class ForumOps
chdir($cwd);
?>

One additional note. I don't use update and delete functions of this class, so I didn't test them. Have that in mind when using.

Jonaid 07-12-2008 11:22 PM

Is there any chance that this'll work, cross site? I'd added a forum on a different server to my main site and I wanted to sync the signups so when someone signs up on my main site it signs them up on the forum.

Any advice??

Regards,

Jonaid

ArbuZz 07-14-2008 08:55 AM

You can use cURL php extension, however I do not know whether it is active by default. With cURL you can call any remote php script and pass parameters to it through the ordinary POST, just like you do it from HTML form.

Peter Bowen 07-20-2008 04:11 PM

Hi,

I'm using amatulic's code in an attempt to create a new user but I keep on getting this error even when using the example test code for making a new user. Any ideas?

Fatal error: Existing data passed is not an array
Called set_existing in /var/www/vhosts/carrington-club-international.co.uk/httpdocs/include/class.forumops.php on line 296
Called login in /var/www/vhosts/carrington-club-international.co.uk/httpdocs/include/class.forumops.php on line 153
Called register_newuser in /var/www/vhosts/carrington-club-international.co.uk/httpdocs/testforumreg.php on line 14
in [path]/includes/class_dm.php on line 235

Thanks

Pete

Selter 09-18-2008 10:50 AM

Hi threre,

I've got some trouble running the PHP code from the first post. To be honest - I'm not so familiar with PHP :(

It would be great if anybody could have a look into this ...
(I already posted this issue in the german board http://www.vbulletin-germany.com/for...ad.php?t=38534 and was advised to ask the author of the code ;) )

Below you'll find the (entire) code which I use in a PHP file (called createuser.php).

I started the code by entering http://www.xyz.de/_forum/createuser.php in the URL-field of my browser.


Code:



<?php
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_USERINFO', 1);
define('CWD', '.');
require_once(CWD . '/includes/init.php');

$newuser =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$newuser->set('username', 'selter');
$newuser->set('email', 'selter@xyz.de');
$newuser->set('password', 'geheim');
$newuser->set('usergroupid', 2); 
$newuserid = $newuser->save(); 

?>


Unfortunately I got this error message:

Quote:


Fatal error: vb_error_handler() [function.require]: Failed opening required 'DIR/includes/functions_log_error.php' (include_path='.:/usr/lib/php') in /xxxxxxx/htdocs/_forum/includes/class_core.php on line 3247


Where is the bug???

Thanks
Selter

Andreas 10-13-2008 05:52 AM

Quote:

Originally Posted by Selter (Post 1624740)
Where is the bug???

init.php
PHP Code:

if (CWD == '.')
{
    
// getcwd() failed and so we need to be told the full forum path in config.php
    
if (!empty($vbulletin->config['Misc']['forumpath']))
    {
        
define('DIR'$vbulletin->config['Misc']['forumpath']);
    }
    else
    {
        
trigger_error('<strong>Konfigurationsfehler</strong>: Sie muessen in der Datei config.php bei <strong>forumpath</strong> einen Eintrag vornehmen.'E_USER_ERROR);
    }
}
else
{
    
define('DIR'CWD);


=> Set CWD properly, eg. full path

mariusvr 10-28-2008 10:38 AM

Quote:

--------------- Added 11 Jul 2008 at 16:17 ---------------

It is "function fetch_userinfo_from_username" that does the trouble. It is not able to retrieve the information from database with its:

...
global $vbulletin;
$useridq = $vbulletin->db->query_first_slave("SELECT userid FROM " . TABLE_PREFIX . "user WHERE username='{$username}'");
...

Any ideas how to correct this?
I am having the same error coming up when using the following code. The db object seems to empty when updating the user stats. The strange thing is that the user was created succesfully, before vbulletin crashes with this error:

Code:

Fatal error: Call to a member function query_first() on a non-object in /home/jfusiono/public_html/demo/vbulletin/includes/functions_databuild.php on line 1684
I am using the following code:

Code:

//load the vbulletin framework
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_USERINFO', 1);
define('CWD', $params->get('source_path'));
global $vbulletin;
require_once(CWD . '/includes/init.php');

//setup the new user
$newuser =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$newuser->set('username', $userinfo->username);
$newuser->set('email', $userinfo->email);
$newuser->set('password', $userinfo->password_clear);
$newuser->set('usergroupid', $usergroup);
$newuser->set('password', $userinfo->password_clear);
$newuserid = $newuser->save();


This is the final hurdle before releasing a Beta version of JFusion, a revolutionary Joomla universal bridge. Any help would be greatly appreciated.

Thanks, Marius

harty83 10-30-2008 02:52 PM

Quote:

Originally Posted by mariusvr (Post 1654415)
This is the final hurdle before releasing a Beta version of JFusion, a revolutionary Joomla universal bridge. Any help would be greatly appreciated.

Thanks, Marius

Very unlikely the problem, but you are setting the password twice?
Code:

$newuser->set('password', $userinfo->password_clear);
$newuser->set('usergroupid', $usergroup);
$newuser->set('password', $userinfo->password_clear);
$newuserid = $newuser->save();


thewitt 11-13-2008 01:47 AM

This "Call to a member function" problem occurs when you try to use the Data Manager from within another program.

I have a stand alone php script that works great to set the usergroups using the Data Manager, however when I try to integrate it into my CMS, I get these errors.

I don't know if there is a workaround or not - short of removing the vB includes from the CMS application - but I suspect there is.

It's simply beyond my understanding.

I hat to go with the CURL and remote approach, but I might be forced into it if no one has any other ideas...

-t

mariusvr 11-30-2008 10:13 PM

The problem was that the scope of the global variable is not available to all vbulletin code when called from a more complex script (standalone php file seems to work fine). Our newest addition to the JFusion programmers team has found a solution on how to make it work even from inside another program:

Code:

               
global $vbulletin;
require_once(CWD . './includes/init.php');

 //work around to make global vbulletin stick
$registry = $vbulletin;
unset($vbulletin);
$vbDb = $registry->db;
//declare as global vbulletin's registry and db objects
global $vbulletin,$db;
$vbulletin = $registry;
//vbulletin db object which is needed for vbulletin's project tools addon
$db = $vbDb;

This resets the global objects in the main script and allows it to be available for the next set of calls to the vb datamanager.

Thanks, Marius

harty83 11-30-2008 10:37 PM

Quote:

Originally Posted by mariusvr (Post 1676051)
Code:

               
global $vbulletin;
require_once(CWD . './includes/init.php');

 //work around to make global vbulletin stick
$registry = $vbulletin;
unset($vbulletin);
$vbDb = $registry->db;
//declare as global vbulletin's registry and db objects
global $vbulletin,$db;
$vbulletin = $registry;
//vbulletin db object which is needed for vbulletin's project tools addon
$db = $vbDb;


Just as a FYI, the first line (global $vbulletin) is not necessary. That was overlooked on my part. The full code that got it working is

Code:

               
//load the vbulletin framework
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_USERINFO', 1);
define('CWD', 'path/to/vbulletin/forum'));

require_once(CWD . './includes/init.php');

 //work around to make global vbulletin stick
$registry = $vbulletin;
unset($vbulletin);
$vbDb = $registry->db;
//declare as global vbulletin's registry and db objects
global $vbulletin,$db;
$vbulletin = $registry;
//vbulletin db object which is needed for vbulletin's project tools addon
$db = $vbDb;

Thanks!
Alan

mariusvr 11-30-2008 10:43 PM

No thank you Alan. Great piece of troubleshooting on the issue and you have raised the level of functionality for the vbulletin JFusion plugin by a lot! Its a pleasure to have you involved with JFusion.

Thanks, Marius

jdelator 12-18-2008 07:13 PM

Has this tutorial changed muched for 3.7 since it was original written for 3.5?

Sagi22 12-29-2008 02:44 PM

It seems for me that after including vBulletin's classes that the connection link to the DB is still open, and I can't access my previous DB link.
The problem is that my forum tables are in different datebase.
How I can disconnect from VB link?

Thanks.

apollothethird 01-20-2009 03:13 AM

Quote:

Originally Posted by Andreas (Post 664586)
As this is a common request for integration purposes, I thought I should write up another HowTo :)

If you want to add a new user to the vBulletin database, you can use Class vB_Datamanager_User.
This Calss does make sure that everything is OK, it will also take care of the default registration options.

Andreas, great code!

I have a userfield included in my registration process for Full Name. You can find it in the User Manager under the User Profile Fields section called ?Full Name?. Its writing ?field5? in the mysql database file.

Can you tell me how to include this in the new users? creation?

Thanks in advance for any suggestions or comments.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames

positiverep 01-23-2009 05:07 PM

Quote:

Originally Posted by jdelator (Post 1688191)
Has this tutorial changed muched for 3.7 since it was original written for 3.5?

I'm running 3.7 and had no problem installing the script.:D

smooth-c 01-29-2009 09:52 AM

I'm using the integration plugin between Interspire's Email Markerter and i'm now, out of the blue experiencing these problems.

This seems to be working flawlessly except lately i've noticed that it's missed out a few members and not added them to my mailing list.

Any ideas why this would happen? Here's my plugin code;

Code:

$username = $userinfo['username'];
$email= $userinfo['email'];
$userid= $userinfo['userid'];


$xml = "<xmlrequest>
    <username>admin</username>
    <usertoken>XX8410b36f01de9fe7df722ab2864677afddfaXX</usertoken>
    <requesttype>subscribers</requesttype>
    <requestmethod>AddSubscriberToList</requestmethod>
    <details>
        <emailaddress>$email</emailaddress>
        <mailinglist>1</mailinglist>
        <format>html</format>
        <confirmed>yes</confirmed>
        <customfields>
            <item>
                <fieldid>12</fieldid>
                <value>$username</value>
            </item>
            <item>
                <fieldid>13</fieldid>
                <value>$userid</value>
            </item>
        </customfields>
    </details>
</xmlrequest>
"
;

$ch = curl_init('http://www.maximum-jackson.com/interspire/xml.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$result = @curl_exec($ch);
if(
$result === false) {
    echo
"Error performing request";
}
else {
   
$xml_doc = simplexml_load_string($result);
   
//echo 'Status is ', $xml_doc->status, '<br/>';
   
if ($xml_doc->status == 'SUCCESS') {
       
//echo 'Data is ', $xml_doc->data, '<br/>';
   
} else {
       
//echo 'Error is ', $xml_doc->errormessage, '<br/>';
   
}

Any help would be greatly appreciated!


All times are GMT. The time now is 06:50 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03070 seconds
  • Memory Usage 2,108KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (9)bbcode_code_printable
  • (6)bbcode_php_printable
  • (24)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete