Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 11:51 am EST

Geeklog Forums

custom registration form


Status: offline

sornok

Forum User
Newbie
Registered: 03/04/04
Posts: 9
I have managed to make the custom registration form work, but now that it works i would like some help

how do i add more fields ? what do i have to change ?

any help would be appreciated Smile
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
This feature is as noted a set of custom functions that require PHP and mySQL skills. Somewhat similar to creating a plugin. The hooks were added some devlopers could extend the GL registration process without hacking core geeklog files.

All of your custom functions can be placed in lib-custom like the provided examples. This way you can upgrade Geeklog and not effect your customizations.

You will need to create a new table for your additional fields which would be linked by uid. Then add your custom code to each of the templated exampes - replacing the sample code.

There are functions that would be called for:
- New member create: custom_usercreate()
- Member delete : custom_userdelete()
- Member display: custom_userdisplay()
- Member edit: custom_useredit()
- Member records update: custom_usersave()
- New Member registration form: custom_userform()

The custom_userdisplay() will display extra member information on the current user profile page. You would add the template variable {customfields} to the member profile template - noted in the function notes. You would probally edit this template to meet your requirements.




Geeklog components by PortalParts -- www.portalparts.com
 Quote

Status: offline

sornok

Forum User
Newbie
Registered: 03/04/04
Posts: 9
ok i get it, a few questions tho

I am sure i can change the database and the sample functions to suit my needs... problems are :

there are not sample functions for userdisplay and useredit, am I supposed to create from scratch ?

also i would like to know when each function is called, for example when I click on `account information` , which function runs , etc

it seems that custom registration atm works only upon registration and after that i cant change the accounts

thx
 Quote

Status: offline

sornok

Forum User
Newbie
Registered: 03/04/04
Posts: 9
ok, i am using 1.3.8-1sr4

apparently u are talking about 1.3.9.rc2

just downloaded it and realized that the custon registration form on this is a bit different...

I could use this version to create my registration form and upgrade to final l8r if i knew that nothing will change on the custom registration form functions

possible to know ?

thx
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
Yes, I was referring to 1.3.9RC2. Changes were made to address a few bugs and missing functions.

I don't have any planned changes - but it needs to be used by users to flesh out any problems. So only needed changes and enhancments as required.

Geeklog components by PortalParts -- www.portalparts.com
 Quote

jf

Anonymous
See also this feature request
 Quote

sornok

Anonymous
ok , i have finished with all functions and they seem to work ok, needs some php and mysql skills after all Wink

i have one little final problem, the only thing that does not work is to create a new user from the user menu as admin, it gives me an sql error

this is caused because the $uid variable is empty at that moment, I put an if in useredit function to check if uid is empty, if it is empty, I fill it with maxuid + 1

this makes the error disappear and the new user form appears, after that I realized that the next fucntion to be called is usersave (checked user.php for that) and that function does not have the appropriate sql to create a new user in my custom table I (atm what it does is to update my custom table)

I guess ill have to put a check there to see if uid is still empty and then to update or insert data in sql

my usersave function looks at the moment like this but doesnt work
Text Formatted Code

/* Function called when saving the user profile. */
/* This function can now update any extra fields  */
function custom_usersave($uid) {
    global $_TABLES,$_CONF, $HTTP_POST_VARS;
   

/* this if checks if the user is new and then adds a new field in custom_memberinfo */

if (empty($uid)) {
DB_query("INSERT INTO {$_TABLES['custom_memberinfo']} (uid,gender,occupation,organisation,abbreviation,category,country) VALUES ($uid,'{$HTTP_POST_VARS['gender']}','{$HTTP_POST_VARS['occupation']}','{$HTTP_POST_VARS['organisation']}','{$HTTP_POST_VARS['abbreviation']}','{$HTTP_POST_VARS['category']}','{$HTTP_POST_VARS['country']}')");
}

        DB_query("UPDATE {$_TABLES['users']} SET cookietimeout='{$HTTP_POST_VARS["cooktime"]}'");
        DB_query("UPDATE {$_TABLES['custom_memberinfo']} SET
            gender='{$HTTP_POST_VARS['gender']}',
            occupation='{$HTTP_POST_VARS['occupation']}',
            organisation='{$HTTP_POST_VARS['organisation']}',
            abbreviation='{$HTTP_POST_VARS['abbreviation']}',
            category='{$HTTP_POST_VARS['category']}',
            country='{$HTTP_POST_VARS['country']}'
        WHERE uid=$uid");      
}

 


any help would be appreciated, its the only thing that still does not work in my custom form
 Quote

Status: offline

sornok

Forum User
Newbie
Registered: 03/04/04
Posts: 9
ok I hope blaine will see this

I have finished with the custom registration form, everything seems to work nice...


Admin New User
I have fixed the previous problem I had with the usersave function, it now checks if the user is new and updates or makes new tables accordingly. The problem is that I had to make a small change in user.php I will quote my custom_usersave and my changed user.php, this might help because with this change, admin cant create a newuser correctly (he/she can only insert data to core tables). Also very important is the if condition I have at the beginning of custom_usersave, without it when admin clicks to newuser, gets an sql error...

looking forward for an answer to all this Smile

Text Formatted Code
/**
* Saves $uid to the database
*
*/
function saveusers($uid,$username,$fullname,$passwd,$email,$regdate,$homepage,$groups,$delete_photo = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG28, $_USER_VERBOSE;

        $retval = '';

        if ($_USER_VERBOSE) COM_errorLog("**** entering saveusers****",1);     
        if ($_USER_VERBOSE) COM_errorLog("group size at beginning = " . sizeof($groups),1);    

        if (!empty($username) && !empty($email)) {

        $ucount = DB_getItem ($_TABLES['users'], 'count(*)',
                              "username = '$username' AND uid <> $uid");
        if ($ucount > 0) {
            // Admin just changed a user's username to one that already exists
            return edituser ($uid, 51);
        }

        if (!COM_isEmail ($email)) {
            return edituser ($uid, 52);
        }

        $ucount = DB_getItem ($_TABLES['users'], 'count(*)',
                              "email = '$email' AND uid <> $uid");
        if ($ucount > 0) {
            // Admin just changed a user's email to one that already exists
            return edituser ($uid, 56);
        }

        $regdate = strftime('%Y-%m-%d %H:%M:$S',$regdate);
                if (($uid == 1) or !empty($passwd)) {
                        $passwd = md5($passwd);
                } else {
            $passwd = DB_getItem($_TABLES['users'],'passwd',"uid = $uid");
                }

        if (DB_count($_TABLES['users'],'uid',$uid) == 0) {
            if (empty ($passwd)) {
                // no password? create one ...
                srand ((double) microtime () * 1000000);
                $passwd = rand ();
                $passwd = md5 ($passwd);
                $passwd = substr ($passwd, 1, 8);
                $passwd = md5 ($passwd);
            }
            DB_query("INSERT INTO {$_TABLES['users']} (uid,username,fullname,passwd,email,regdate,homepage) VALUES($uid,'$username','$fullname','$passwd', '$email','$regdate','$homepage')");
           
            // change by sornok to make admin able to save a user in custom table
           
            if ($_CONF['custom_registration'] AND (function_exists('custom_usersave'))) {
                custom_usersave($uid);}
               
            // end of change
                           
            DB_query("INSERT INTO {$_TABLES['userprefs']} (uid) VALUES ($uid)");
            if ($_CONF['emailstoriesperdefault'] == 1) {
                DB_query("INSERT INTO {$_TABLES['userindex']} (uid) VALUES ($uid)");
            } else {
                DB_query("INSERT INTO {$_TABLES['userindex']} (uid,etids) VALUES ($uid, '-')");
            }
            DB_query("INSERT INTO {$_TABLES['usercomment']} (uid) VALUES ($uid)");
            DB_query("INSERT INTO {$_TABLES['userinfo']} (uid) VALUES ($uid)");

            PLG_createUser ($uid);
        } else {
            $curphoto = DB_getItem($_TABLES['users'],'photo',"uid = $uid");
            if (!empty($curphoto) AND $delete_photo == 'on') {
                if (!unlink($_CONF['path_html'] . 'images/userphotos/' . $curphoto)) {
                    echo COM_errorLog('Unable to delete photo ' . $curphoto);
                    exit;
                }
                $curphoto = '';
            }
            DB_query("UPDATE {$_TABLES['users']} SET username = '$username', fullname = '$fullname', passwd = '$passwd', email = '$email', homepage = '$homepage', photo = '$curphoto' WHERE uid = $uid");
            if ($_CONF['custom_registration'] AND (function_exists('custom_usersave'))) {
                custom_usersave($uid);
               
            }
        }
               
                // if groups is -1 then this user isn't allowed to change any groups so ignore
        if (is_array ($groups) && SEC_inGroup ('Group Admin')) {
            if (!SEC_inGroup ('Root')) {
                $rootgrp = DB_getItem ($_TABLES['groups'], 'grp_id',
                                       "grp_name = 'Root'");
                if (in_array ($rootgrp, $groups)) {
                    COM_accessLog ("User {$_USER['username']} just tried to give Root permissions to user $username.");
                    echo COM_refresh ($_CONF['site_admin_url'] . '/index.php');
                    exit;
                }
            }
                        if ($_USER_VERBOSE) COM_errorLog("deleting all group_assignments for user $uid/$username",1);
            // remove user from all groups that the User Admin is a member of
            $UserAdminGroups = SEC_getUserGroups ();
            $whereGroup = 'ug_main_grp_id IN ('
                        . implode (',', $UserAdminGroups) . ')';
                        DB_query("DELETE FROM {$_TABLES['group_assignments']} WHERE (ug_uid = $uid) AND " . $whereGroup);
                        if (!empty($groups)) {
                                for ($i = 1; $i <= sizeof($groups); $i++) {
                    if (in_array (current ($groups), $UserAdminGroups)) {
                                            if ($_USER_VERBOSE) COM_errorLog("adding group_assignment " . current($groups) . " for $username",1);
                                            $sql = "INSERT INTO {$_TABLES['group_assignments']} (ug_main_grp_id, ug_uid) VALUES (" . current($groups) . ",$uid)";
                                            DB_query($sql);
                    }
                                        next($groups);         
                                }
                        }
                }
        $errors = DB_error();
                if (empty($errors)) {
                        echo COM_refresh($_CONF['site_admin_url'] . '/user.php?msg=21');
                } else {
                        $retval .= COM_siteHeader('menu');
            $retval .= COM_errorLog('Error in saveusers in ' . $_CONF['site_admin_url'] . '/user.php');
                        $retval .= COM_siteFooter();
            echo $retval;
            exit;
                }
        } else {
                $retval = COM_siteHeader('menu');
                $retval .= COM_errorLog($LANG28[10]);
        if (DB_count($_TABLES['users'],'uid',$uid) > 0) {
            $retval .= edituser($uid);
        } else {
            $retval .= edituser();
        }
                $retval .= COM_siteFooter();
        echo $retval;
        exit;
        }

        if ($_USER_VERBOSE) COM_errorLog("***************leaving saveusers*****************",1);       

    return $retval;
}
 


Text Formatted Code
/* Function called when saving the user profile. */
/* This function can now update any extra fields  */
function custom_usersave($uid) {
    global $_TABLES,$_CONF, $HTTP_POST_VARS;
   
$temp1 = DB_query("SELECT MAX(uid) AS max1 FROM {$_TABLES['users']}");
$TT1 = DB_fetchArray($temp1);
$uid1 = $TT1['max1'];

$temp2 = DB_query("SELECT MAX(uid) AS max2 FROM {$_TABLES['custom_memberinfo']}");
$TT2 = DB_fetchArray($temp2);
$uid2 = $TT2['max2'];

if ($uid1!=$uid2)
{
DB_query("INSERT INTO {$_TABLES['custom_memberinfo']} (uid,gender,occupation,organisation,abbreviation,category,country) VALUES ($uid,'
        {$HTTP_POST_VARS['gender']}','
        {$HTTP_POST_VARS['occupation']}','
        {$HTTP_POST_VARS['organisation']}','
        {$HTTP_POST_VARS['abbreviation']}','
        {$HTTP_POST_VARS['category']}','
        {$HTTP_POST_VARS['country']}')");
}

else

{
        DB_query("UPDATE {$_TABLES['users']} SET cookietimeout='{$HTTP_POST_VARS["cooktime"]}'");
        DB_query("UPDATE {$_TABLES['custom_memberinfo']} SET
            gender='{$HTTP_POST_VARS['gender']}',
            occupation='{$HTTP_POST_VARS['occupation']}',
            organisation='{$HTTP_POST_VARS['organisation']}',
            abbreviation='{$HTTP_POST_VARS['abbreviation']}',
            category='{$HTTP_POST_VARS['category']}',
            country='{$HTTP_POST_VARS['country']}'
        WHERE uid=$uid");
}
       
}
 
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
This new feature needs testing by others and I appreciate that you have been able to do so and for the most part has been very complete.

I am interested in understanding the issues with any changes needed to the Core GL calls to the custom functions. I can see that there needs to be a call to the custom_usersave function in the Admin/user.php when saving a new member record. I missed in adding the call in the first condition - no record exists for member.

Have you discovered any other problems - with missing calls or other needed changes to the API calls?

It needs to be able to provide the hooks for your custom functions and it assume you will add all the logic needed in your custom functions to handle errors. There is also an ehancement request to enable a Custom_validation function.

I will add the missing call to custom_usersave in the admin.php.

Geeklog components by PortalParts -- www.portalparts.com
 Quote

Status: offline

sornok

Forum User
Newbie
Registered: 03/04/04
Posts: 9
except for the missing call to custom_usersave in admin/user.php

I would suggest that u add smth like the following, at the beginning of the useredit function

if (empty ($uid) ) {
$temp = DB_query("SELECT MAX(uid) AS max2 FROM {$_TABLES['users']}");
$TT = DB_fetchArray($temp);
$uid = $TT['max2'] + 1;
}

this is needed because $uid is empty when admin tries to make a new user and without that `if` gets an sql error

with these two changes and of course the custom code to all functions, custom registration works file, at least for me Smile

I could post all my custom functions if anyone is interested

cya
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
Sornok,

I don't see the situation where uid is not already defined. In admin/user.php edituser(), if the uid is not passed in (as when a new user), the uid is generated. The uid is generated from the record count in the users table or the max(uid) is used. The call to our custom is after this logic so uid should be known.
Geeklog components by PortalParts -- www.portalparts.com
 Quote

Status: offline

sornok

Forum User
Newbie
Registered: 03/04/04
Posts: 9
Ok, i didnt check the user.php logic but when I finished all my custom functions and had them work I tried to create a new user from the admin panel. Then I got an sql error, I checked the logs and saw that uid was empty. I didnt want to change anything on core files so I put this logic at the beginning of useredit. I'll check user.php though, sorry I didn't do this earlier...
 Quote

T. Shore

Anonymous
I have emailed Sornok to try take him up on his offer of posting his custom_user functions code. However, I have not received a reply. I'm wondering if this isn't because of his or my SPAM filtering, so I thought I'd give it a shot here.

Sornok - I would love to have your code for these functions.

Thank you.
 Quote

Status: offline

rjrufo

Forum User
Regular Poster
Registered: 06/14/03
Posts: 95
Quote by T. Shore:
Sornok - I would love to have your code for these functions.

Thank you.


Same here
 Quote

Status: offline

usarid

Forum User
Newbie
Registered: 05/11/04
Posts: 3
I would recommend adding
global $_TABLES;
as the first line in custom_userdelete so that the function can refer to the proper table indirectly, as is the case for the other functions you give in the examples. The full function would then be:

Text Formatted Code
// Delete any records from custom tables you may have used
function custom_userdelete($uid) {
    global $_TABLES;
    DB_query("DELETE FROM {$_TABLES['custom_userdata']} WHERE (uid = $uid)");
    return true;

}
 
 Quote

Status: offline

usarid

Forum User
Newbie
Registered: 05/11/04
Posts: 3
I think there are a couple of other problems with the examples which might explain the difficulties Sornok was encountering.

1) In admin/user.php, the saveusers function calls custom_usersave in both cases, if the uid is about to be created (so there is an INSERT into the gl_users table) or if the uid already existed (so there is an UPDATE to the gl_users table). I believe the first one should instead call custom_usercreate.

2) In the same file, the edituser function calls custom_useredit($uid) but in fact $uid may be empty if a new user is being created. I believe it should instead call custom_useredit($A['uid']) so the proper uid is always passed to the custom function.

Hope that helps.
 Quote

All times are EST. The time is now 11:51 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content