Welcome to Geeklog, Anonymous Wednesday, January 15 2025 @ 07:44 am EST
Geeklog Forums
Custom Registration Problem
Eddy
Anonymous
Hi all. I've posted this in the Custom Registration Example thread above, but it's a thread that hasn't been used since 2006 so for fear of my question being overlooked, thought I'd post it here, too.
I've followed the instructions to a T and made a few changes to add a few other custom fields.
When viewing ANY page in the site, I get the following message :
I've looked for line 554 and it doesn't exist. I've also done a search for '$end' and it also doesn't seem to exist. I am, therefore, at a complete loss!
Here is my lib-custom.php file :
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.4 |
// +---------------------------------------------------------------------------+
// | lib-custom.php |
// | |
// | Your very own custom Geeklog library. |
// | |
// | This is the file where you should put all of your custom code. When |
// | possible you should not alter lib-common.php but, instead, put code here. |
// | This will make upgrading to future versions of Geeklog easier for you |
// | because you will always be guaranteed that the Geeklog developers will |
// | NOT add required code to this file. |
// | |
// | NOTE: we have already gone through the trouble of making sure that we |
// | always include this file when lib-common.php is included some place so |
// | you will have access to lib-common.php. It follows then that you should |
// | not include lib-common.php in this file. |
// | |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2006 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Blaine Lang - blaine AT portalparts DOT com |
// | Dirk Haun - dirk AT haun-online DOT de |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
// $Id: lib-custom.php,v 1.36 2006/12/14 05:19:58 blaine Exp $
if (strpos ($_SERVER['PHP_SELF'], 'lib-custom.php') !== false) {
die ('This file can not be used on its own!');
}
// You can use this global variable to print useful messages to the errorlog
// using COM_errorLog(). To see an example of how to do this, look in
// lib-common.php and see how $_COM_VERBOSE was used throughout the code
$_CST_VERBOSE = false;
/**
* Sample PHP Block function
*
* this is a sample function used by a PHP block. This will show the rights that
* a user has in the "What you have access to" block.
*
*/
function phpblock_showrights()
{
global $_RIGHTS, $_CST_VERBOSE;
if ($_CST_VERBOSE) {
COM_errorLog('**** Inside phpblock_showrights in lib-custom.php ****', 1);
}
$retval .= ' ';
for ($i = 0; $i < count($_RIGHTS); $i++) {
$retval .= '<li>' . $_RIGHTS[$i] . '</li>' . LB;
}
if ($_CST_VERBOSE) {
COM_errorLog('**** Leaving phpblock_showrights in lib-custom.php ****', 1);
}
return $retval;
}
/**
* Include any code in this function that will be called by the internal CRON API
* The interval between runs is determined by $_CONF['cron_schedule_interval']
*/
function CUSTOM_runScheduledTask() {
}
/**
* Example of custom function that can be used to handle a login error.
* Only active with custom registration mode enabled
* Used if you have a custom front page and need to trap and reformat any error messages
* This example redirects to the front page with a extra passed variable plus the message
* Note: Message could be a string but in this case maps to $MESSAGE[81] as a default - edit in language file
*/
function CUSTOM_loginErrorHandler($msg='') {
global $_CONF,$MESSAGE;
if ($msg > 0) {
$msg = $msg;
} elseif ($msg == '') {
$msg = 81;
}
$retval = COM_refresh($_CONF['site_url'] .'/index.php?mode=loginfail&msg='.$msg);
echo $retval;
exit;
}
/**
* Include any code in this function to add custom template variables.
* Initially, this function is only called in the COM_siteHeader function to set
* header.thtml variables
*/
function CUSTOM_templateSetVars ($templatename, &$template)
{
if ($templatename == 'header') {
// define a {hello_world} variable which displays "Hello, world!"
$template->set_var ('hello_world', 'Hello, world!');
}
}
/* Sample Custom Member Functions to create and update Custom Membership registration and profile
Note1: Enable CustomRegistration Feature in config.php
$_CONF['custom_registration'] = true; // Set to true if you have custom code
Note2: This example requires a template file called memberdetail.thtml to be
located under the theme_dir/custom directory.
Sample is provided under /system with the distribution.
Functions have been provided that are called from the Core Geeklog user and admin functions
- This works with User Moderation as well
- Admin will see the new registration info when checking a member's profile only
- All other users will see the standard User profile with the optional extended custom information
- Customization requires changes to a few of the core template files to add {customfields} variables
- See notes below in the custom function about the template changes
*/
/* Create any new records in additional tables you may have added */
/* Update any fields in the core GL tables for this user as needed */
/* Called when user is first created */
function CUSTOM_userCreate ($uid)
{
global $_TABLES;
$fleet = COM_applyFilter($_POST['cust_fleet'],true);
$base = COM_applyFilter($_POST['cust_base'],true);
$staffnumber = COM_applyFilter($_POST['cust_staffnumber'],true);
$fullname = COM_applyFilter($_POST['cust_fullname']);
// Ensure all data is prepared correctly before inserts, quotes may need to
// be escaped with addslashes()
DB_query("INSERT INTO {$_TABLES['localuserinfo']} (uid,fleet,base,staffnumber) VALUES ('$uid', '$fleet', '$base', '$staffnumber')");
DB_query("UPDATE {$_TABLES['users']} SET fullname = '$fullname' WHERE uid='$uid'");
return true;
}
$email = '';
if (isset ($_POST['email'])) {
$email = COM_applyFilter ($_POST['email']);
$email = addslashes ($email);
}
$homepage = '';
if (isset ($_POST['homepage'])) {
$homepage = COM_applyFilter ($_POST['homepage']);
$homepage = addslashes ($homepage);
}
$fullname = '';
if (isset ($_POST['fullname'])) {
// COM_applyFilter would strip special characters, e.g. quotes, so
// we only strip HTML
$fullname = strip_tags ($_POST['fullname']);
$fullname = addslashes ($fullname);
}
// Note: In this case, we can trust the $uid variable to contain the new
// account's uid.
DB_query("UPDATE {$_TABLES['users']} SET email = '$email', homepage = '$homepage', fullname = '$fullname' WHERE uid = $uid");
return true;
// Delete any records from custom tables you may have used
function custom_userdelete($uid) {
global $_TABLES;
DB_query("DELETE FROM {$_TABLES['localuserinfo']} WHERE uid='$uid'");
return true;
}
/* Called from users.php - when user is displaying a member profile.
* This function can now return any extra fields that need to be shown.
* Output is then replaced in {customfields} -- This variable needs to be added
* to your templates
* Template: path_layout/users/profile/profile.thtml
*/
function custom_userdisplay($uid) {
global $_CONF,$_TABLES;
$fleet = DB_getItem($_TABLES['localuserinfo'], "fleet", "uid='$uid'");
$base = DB_getItem($_TABLES['localuserinfo'], "base", "uid='$uid'");
$staffnumber = DB_getItem($_TABLES['localuserinfo'], "staffnumber", "uid='$uid'");
$fullname = DB_getItem($_TABLES['users'], "fullname", "uid='$uid'");
$retval .= '<tr>
<td align="right"><b>Full Name:</b></td>
<td>' . $fullname .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Fleet:</b></td>
<td>' . $fleet .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Base:</b></td>
<td>' . $base .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Staff Number:</b></td>
<td>' . $staffnumber .'</td>
</tr>';
return $retval;
}
/* Function called when editing user profile. */
/* Called from usersettings.php - when user is eding their own profile */
/* and from admin/user.php when admin is editing a member profile */
/* This function can now return any extra fields that need to be shown for editing */
/* Output is then replaced in {customfields} -- This variable needs to be added to your templates */
/* User: path_layout/preferences/profile.thtml and Admin: path_layout/admin/user/edituser.thtml */
/* This example shows adding the Cookie Timeout setting and extra text field */
/* As noted: You need to add the {customfields} template variable. */
/* For the edituser.thtml - maybe it would be added about the {group_edit} variable. */
function CUSTOM_userEdit($uid)
{
global $_TABLES,$_CONF;
$fleet = DB_getItem($_TABLES['localuserinfo'], "fleet", "uid='$uid'");
$base = DB_getItem($_TABLES['localuserinfo'], "base", "uid='$uid'");
$staffnumber = DB_getItem($_TABLES['localuserinfo'], "staffnumber", "uid='$uid'");
$fullname = DB_getItem($_TABLES['users'], "fullname", "uid='$uid'");
$retval .= '<tr>
<td align="right"><b>Full Name:</b></td>
<td><input type="text" name="cust_fullname" size="50" value="' . $fullname .'"></td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Fleet:</b></td>
<td><input type="text" name="cust_fleet" size="30" maxlength="50" value="' . $fleet .'"></td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Base:</b></td>
<td><input type="text" name="cust_base" size="30" maxlength="50" value="' . $base .'"></td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Staff Number:</b></td>
<td><input type="text" name="cust_staffnumber" size="30" maxlength="50" value="' . $staffnumber .'"></td>
</tr>';
$retval .= '<tr><td colspan="2"><hr></td></tr>';
return $retval;
}
$var = "Value from custom table";
$cookietimeout = DB_getitem($_TABLES['users'], 'cookietimeout', $uid);
$selection = '<select name="cooktime">' . LB;
$selection .= COM_optionList ($_TABLES['cookiecodes'], 'cc_value,cc_descr', $cookietimeout, 0);
$selection .= '</select>';
$retval .= '<tr>
<td align="right">Remember user for:</td>
<td>' . $selection .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Custom Fields:</b></td>
<td><input type="text" name="custom1" size="50" value="' . $var .'"></td>
</tr>';
$retval .= '<tr><td colspan="2"><hr></td></tr>';
return $retval;
/* Function called when saving the user profile. */
/* This function can now update any extra fields */
function custom_usersave($uid) {
global $_TABLES;
$fleet = COM_applyFilter($_POST['cust_fleet'],true);
$staffnumber = COM_applyFilter($_POST['cust_staffnumber'],true);
$base = COM_applyFilter($_POST['cust_base'],true);
$fullname = COM_applyFilter($_POST['fullname']);
DB_query("UPDATE {$_TABLES['users']} SET fullname='$fullname' WHERE uid='$uid'");
if ($fleet > 0) {
DB_query("UPDATE {$_TABLES['localuserinfo']} SET fleet='$fleet' WHERE uid='$uid'");
if ($base > 0) {
DB_query("UPDATE {$_TABLES['localuserinfo']} SET base='$base' WHERE uid='$uid'");
if ($staffnumber > 0) {
DB_query("UPDATE {$_TABLES['localuserinfo']} SET staffnumber='$staffnumber' WHERE uid='$uid'");
}
$cooktime = 0;
if (isset ($_POST['cooktime'])) {
$cooktime = COM_applyFilter ($_POST['cooktime'], true);
if ($cooktime < 0) {
$cooktime = 0;
}
DB_query("UPDATE {$_TABLES['users']} SET cookietimeout = $cooktime WHERE uid = $uid");
}
}
/**
* Main Form used for Custom membership when member is registering
*
* Note: Requires a file custom/memberdetail.thtml in every theme that is
* installed on the site!
*
* @param string $msg an error message to display or the word 'new'
* @return string HTML for the registration form
*
*/
function custom_userform($uid="",$msg="") {
global $_CONF,$_TABLES, $LANG04;
if (!empty($msg)) {
$retval .= COM_startBlock($LANG04[21]) . $msg . COM_endBlock();
}
$post_url = $_CONF['site_url'] . '/users.php';
$postmode = 'create';
$submitbutton = '<input type="submit" value="Register Now!">';
$message = "<blockquote style=\"padding-top:10px;\"><b>Please complete the application below. Once you have completed the application, click the Register Now! button and the application will be processed immediately.</b></blockquote>";
$user_templates = new Template ($_CONF['path_layout'] . 'custom');
$user_templates->set_file('memberdetail', 'memberdetail.thtml');
$user_templates->set_var('site_url', $_CONF['site_url']);
$user_templates->set_var('layout_url', $_CONF['layout_url']);
$user_templates->set_var('post_url', $post_url);
$user_templates->set_var('startblock', COM_startBlock("Custom Registration Example"));
$user_templates->set_var('message', $message);
$user_templates->set_var('USERNAME', $LANG04[2]);
$user_templates->set_var('USERNAME_HELP', "Name to be used when accessing this site");
$username = '';
if (isset ($_POST['username'])) {
$username = COM_applyFilter ($_POST['username']);
}
$user_templates->set_var('username', $username);
$user_templates->set_var('EMAIL', $LANG04[5]);
$user_templates->set_var('EMAIL_HELP', $LANG04[33]);
$email = '';
if (isset ($_POST['email'])) {
$email = COM_applyFilter ($_POST['email']);
}
$user_templates->set_var('email', $email);
$user_templates->set_var('EMAIL_CONF', $LANG04[124]);
$user_templates->set_var('EMAIL_CONF_HELP', $LANG04[126]);
$email_conf = '';
if (isset ($_POST['email_conf'])) {
$email_conf = COM_applyFilter ($_POST['email_conf']);
}
$user_templates->set_var('email_conf', $email_conf);
$user_templates->set_var('FULLNAME', $LANG04[3]);
$user_templates->set_var('FULLNAME_HELP', $LANG04[34]);
$fullname = '';
if (isset ($_POST['fullname'])) {
$fullname = strip_tags ($_POST['fullname']);
}
$user_templates->set_var('fullname', $fullname);
$user_templates->set_var('FULLNAME', "Full Name");
$user_templates->set_var('FULLNAME_HELP', "First and Last Name");
$user_templates->set_var('fullname', $A['fullname']);
$user_templates->set_var('FLEET_ONE', "Fleet");
$user_templates->set_var('FLEET_HELP', "Fleet");
$user_templates->set_var('fleet', "");
$user_templates->set_var('BASE_ONE', "Base");
$user_templates->set_var('BASE_HELP', "Base");
$user_templates->set_var('base', "");
$user_templates->set_var('STAFFNUMBER_ONE', "Staff Number");
$user_templates->set_var('STAFFNUMBER_HELP', "Staff Number");
$user_templates->set_var('staffnumber', "");
$user_templates->set_var('user_id', $user);
$user_templates->set_var('postmode', $postmode);
$user_templates->set_var('submitbutton', $submitbutton);
$user_templates->set_var('endblock', COM_endBlock());
$user_templates->parse('output', 'memberdetail');
$retval .= $user_templates->finish($user_templates->get_var('output'));
return $retval;
}
/**
* Check if it's okay to create a new user.
*
* Geeklog is about to create a new user with the given username and email
* address. This is the custom code's last chance to prevent that,
* e.g. to check if all required data has been entered.
*
* @param string $username username that Geeklog would use for the new user* @param string $email email address of that user
* @return string an error message or an empty string for "OK"
*
*/
function CUSTOM_userCheck ($username, $email)
{
$msg = '';
// Example, check that the full name has been entered
// and complain if it's missing
if (empty ($_POST['fullname'])) {
$msg = 'Please enter your full name!';
}
return $msg;
}
/**
* Custom function to retrieve and return a formatted list of blocks
* Can be used when calling COM_siteHeader or COM_siteFooter
*
* Example:
* 1: Setup an array of blocks to display
* 2: Call COM_siteHeader or COM_siteFooter
*
* $myblocks = array( 'site_menu', 'site_news', 'poll_block' );
*
* COM_siteHeader( array( 'CUSTOM_showBlocks', $myblocks )) ;
* COM_siteFooter( true, array( 'CUSTOM_showBlocks', $myblocks ));
*
* @param array $showblocks An array of block names to retrieve and format
* @return string Formated HTML containing site footer and optionally right blocks
*/
function CUSTOM_showBlocks($showblocks)
{
global $_CONF, $_USER, $_TABLES;
$retval = '';
if( !isset( $_USER['noboxes'] )) {
if( !empty( $_USER['uid'] )) {
$noboxes = DB_getItem( $_TABLES['userindex'], 'noboxes', "uid = {$_USER['uid']}" );
} else {
$noboxes = 0;
}
} else {
$noboxes = $_USER['noboxes'];
}
foreach($showblocks as $block) {
$sql = "SELECT bid, name,type,title,content,rdfurl,phpblockfn,help,allow_autotags FROM {$_TABLES['blocks']} WHERE name='$block'";
$result = DB_query($sql);
if (DB_numRows($result) == 1) {
$A = DB_fetchArray($result);
$retval .= COM_formatBlock($A,$noboxes);
}
}
return $retval;
}
/**
* This is an example of a custom email function. When this function is NOT
* commented out, Geeklog would send all emails through this function
* instead of sending them through COM_mail in lib-common.php.
*
* This is basically a re-implementation of the way emails were sent
* prior to Geeklog 1.3.9 (Geeklog uses PEAR::Mail as of version 1.3.9).
*
*/
/*
function CUSTOM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0)
{
global $_CONF, $LANG_CHARSET;
if (empty ($LANG_CHARSET)) {
$charset = $_CONF['default_charset'];
if (empty ($charset)) {
$charset = 'iso-8859-1';
}
} else {
$charset = $LANG_CHARSET;
}
if (empty ($from)) {
$from = $_CONF['site_name'] . ' <' . $_CONF['site_mail'] . '>';
}
$headers = 'From: ' . $from . "\r\n"
. 'X-Mailer: Geeklog ' . VERSION . "\r\n";
if ($priority > 0) {
$headers .= 'X-Priority: ' . $priority . "\r\n";
}
if ($html) {
$headers .= "Content-Type: text/html; charset={$charset}\r\n"
. 'Content-Transfer-Encoding: 8bit';
} else {
$headers .= "Content-Type: text/plain; charset={$charset}";
}
return mail ($to, $subject, $message, $headers);
}
*/
/**
* This is an example of a function that returns menu entries to be used for
* the 'custom' entry in $_CONF['menu_elements'] (see config.php).
*
*/
/*
function CUSTOM_menuEntries ()
{
global $_CONF, $_USER;
$myentries = array ();
// Sample link #1: Link to Gallery
$myentries[] = array ('url' => $_CONF['site_url'] . '/gallery/',
'label' => 'Gallery');
// Sample link #2: Link to the Personal Calendar - only visible for
// logged-in users
if (!empty ($_USER['uid']) && ($_USER['uid'] > 1)) {
$myentries[] = array ('url' => $_CONF['site_url']
. '/calendar/index.php?mode=personal',
'label' => 'My Calendar');
}
return $myentries;
}
*/
/**
* This is an example of an error handler override. This will be used in
* place of COM_handleError if the user is not in the Root group. Really,
* this should only be used to display some nice pretty "site error" html.
* Though you could try and notify the sysadmin, and log the error, as this
* example will show. The function is commented out for saftey.
*/
/*
function CUSTOM_handleError($errno, $errstr, $errfile, $errline, $errcontext)
{
global $_CONF;
if( is_array($_CONF) && function_exists('COM_mail'))
{
COM_mail($_CONF['site_mail'], $_CONF['site_name'].' Error Handler',
"An error has occurred: $errno $errstr @ $errline of $errfile");
COM_errorLog("Error Handler: $errno $errstr @ $errline of $errfile");
}
echo("
<html>
<head>
<title>{$_CONF['site_name']} - An error occurred.</title>
<style type=\"text/css\">
body,html {height: 100%; width: 100%;}
body{ border: 0px; padding: 0px;
background-color: white;
color: black;
}
div { margin-left: auto; margin-right: auto;
margin-top: auto; margin-bottom: auto;
border: solid thin blue; width: 400px;
padding: 5px; text-align: center;
}
h1 { color: blue;}
</style>
</head>
<body>
<div>
<h1>An Error Has Occurred.</h1>
<p>Unfortunatley, the action you performed has caused an
error. The site administrator has been informed. If you
try again later, the issue may have been fixed.</p>
</div>
</body>
</html>
");
exit;
}
?>
Any help would be greatly appreciated.
I've followed the instructions to a T and made a few changes to add a few other custom fields.
When viewing ANY page in the site, I get the following message :
Parse error: syntax error, unexpected $end in /home/crewlink/system/lib-custom.php on line 554
I've looked for line 554 and it doesn't exist. I've also done a search for '$end' and it also doesn't seem to exist. I am, therefore, at a complete loss!
Here is my lib-custom.php file :
Text Formatted Code
<?php/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.4 |
// +---------------------------------------------------------------------------+
// | lib-custom.php |
// | |
// | Your very own custom Geeklog library. |
// | |
// | This is the file where you should put all of your custom code. When |
// | possible you should not alter lib-common.php but, instead, put code here. |
// | This will make upgrading to future versions of Geeklog easier for you |
// | because you will always be guaranteed that the Geeklog developers will |
// | NOT add required code to this file. |
// | |
// | NOTE: we have already gone through the trouble of making sure that we |
// | always include this file when lib-common.php is included some place so |
// | you will have access to lib-common.php. It follows then that you should |
// | not include lib-common.php in this file. |
// | |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2006 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Blaine Lang - blaine AT portalparts DOT com |
// | Dirk Haun - dirk AT haun-online DOT de |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
// $Id: lib-custom.php,v 1.36 2006/12/14 05:19:58 blaine Exp $
if (strpos ($_SERVER['PHP_SELF'], 'lib-custom.php') !== false) {
die ('This file can not be used on its own!');
}
// You can use this global variable to print useful messages to the errorlog
// using COM_errorLog(). To see an example of how to do this, look in
// lib-common.php and see how $_COM_VERBOSE was used throughout the code
$_CST_VERBOSE = false;
/**
* Sample PHP Block function
*
* this is a sample function used by a PHP block. This will show the rights that
* a user has in the "What you have access to" block.
*
*/
function phpblock_showrights()
{
global $_RIGHTS, $_CST_VERBOSE;
if ($_CST_VERBOSE) {
COM_errorLog('**** Inside phpblock_showrights in lib-custom.php ****', 1);
}
$retval .= ' ';
for ($i = 0; $i < count($_RIGHTS); $i++) {
$retval .= '<li>' . $_RIGHTS[$i] . '</li>' . LB;
}
if ($_CST_VERBOSE) {
COM_errorLog('**** Leaving phpblock_showrights in lib-custom.php ****', 1);
}
return $retval;
}
/**
* Include any code in this function that will be called by the internal CRON API
* The interval between runs is determined by $_CONF['cron_schedule_interval']
*/
function CUSTOM_runScheduledTask() {
}
/**
* Example of custom function that can be used to handle a login error.
* Only active with custom registration mode enabled
* Used if you have a custom front page and need to trap and reformat any error messages
* This example redirects to the front page with a extra passed variable plus the message
* Note: Message could be a string but in this case maps to $MESSAGE[81] as a default - edit in language file
*/
function CUSTOM_loginErrorHandler($msg='') {
global $_CONF,$MESSAGE;
if ($msg > 0) {
$msg = $msg;
} elseif ($msg == '') {
$msg = 81;
}
$retval = COM_refresh($_CONF['site_url'] .'/index.php?mode=loginfail&msg='.$msg);
echo $retval;
exit;
}
/**
* Include any code in this function to add custom template variables.
* Initially, this function is only called in the COM_siteHeader function to set
* header.thtml variables
*/
function CUSTOM_templateSetVars ($templatename, &$template)
{
if ($templatename == 'header') {
// define a {hello_world} variable which displays "Hello, world!"
$template->set_var ('hello_world', 'Hello, world!');
}
}
/* Sample Custom Member Functions to create and update Custom Membership registration and profile
Note1: Enable CustomRegistration Feature in config.php
$_CONF['custom_registration'] = true; // Set to true if you have custom code
Note2: This example requires a template file called memberdetail.thtml to be
located under the theme_dir/custom directory.
Sample is provided under /system with the distribution.
Functions have been provided that are called from the Core Geeklog user and admin functions
- This works with User Moderation as well
- Admin will see the new registration info when checking a member's profile only
- All other users will see the standard User profile with the optional extended custom information
- Customization requires changes to a few of the core template files to add {customfields} variables
- See notes below in the custom function about the template changes
*/
/* Create any new records in additional tables you may have added */
/* Update any fields in the core GL tables for this user as needed */
/* Called when user is first created */
function CUSTOM_userCreate ($uid)
{
global $_TABLES;
$fleet = COM_applyFilter($_POST['cust_fleet'],true);
$base = COM_applyFilter($_POST['cust_base'],true);
$staffnumber = COM_applyFilter($_POST['cust_staffnumber'],true);
$fullname = COM_applyFilter($_POST['cust_fullname']);
// Ensure all data is prepared correctly before inserts, quotes may need to
// be escaped with addslashes()
DB_query("INSERT INTO {$_TABLES['localuserinfo']} (uid,fleet,base,staffnumber) VALUES ('$uid', '$fleet', '$base', '$staffnumber')");
DB_query("UPDATE {$_TABLES['users']} SET fullname = '$fullname' WHERE uid='$uid'");
return true;
}
$email = '';
if (isset ($_POST['email'])) {
$email = COM_applyFilter ($_POST['email']);
$email = addslashes ($email);
}
$homepage = '';
if (isset ($_POST['homepage'])) {
$homepage = COM_applyFilter ($_POST['homepage']);
$homepage = addslashes ($homepage);
}
$fullname = '';
if (isset ($_POST['fullname'])) {
// COM_applyFilter would strip special characters, e.g. quotes, so
// we only strip HTML
$fullname = strip_tags ($_POST['fullname']);
$fullname = addslashes ($fullname);
}
// Note: In this case, we can trust the $uid variable to contain the new
// account's uid.
DB_query("UPDATE {$_TABLES['users']} SET email = '$email', homepage = '$homepage', fullname = '$fullname' WHERE uid = $uid");
return true;
// Delete any records from custom tables you may have used
function custom_userdelete($uid) {
global $_TABLES;
DB_query("DELETE FROM {$_TABLES['localuserinfo']} WHERE uid='$uid'");
return true;
}
/* Called from users.php - when user is displaying a member profile.
* This function can now return any extra fields that need to be shown.
* Output is then replaced in {customfields} -- This variable needs to be added
* to your templates
* Template: path_layout/users/profile/profile.thtml
*/
function custom_userdisplay($uid) {
global $_CONF,$_TABLES;
$fleet = DB_getItem($_TABLES['localuserinfo'], "fleet", "uid='$uid'");
$base = DB_getItem($_TABLES['localuserinfo'], "base", "uid='$uid'");
$staffnumber = DB_getItem($_TABLES['localuserinfo'], "staffnumber", "uid='$uid'");
$fullname = DB_getItem($_TABLES['users'], "fullname", "uid='$uid'");
$retval .= '<tr>
<td align="right"><b>Full Name:</b></td>
<td>' . $fullname .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Fleet:</b></td>
<td>' . $fleet .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Base:</b></td>
<td>' . $base .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Staff Number:</b></td>
<td>' . $staffnumber .'</td>
</tr>';
return $retval;
}
/* Function called when editing user profile. */
/* Called from usersettings.php - when user is eding their own profile */
/* and from admin/user.php when admin is editing a member profile */
/* This function can now return any extra fields that need to be shown for editing */
/* Output is then replaced in {customfields} -- This variable needs to be added to your templates */
/* User: path_layout/preferences/profile.thtml and Admin: path_layout/admin/user/edituser.thtml */
/* This example shows adding the Cookie Timeout setting and extra text field */
/* As noted: You need to add the {customfields} template variable. */
/* For the edituser.thtml - maybe it would be added about the {group_edit} variable. */
function CUSTOM_userEdit($uid)
{
global $_TABLES,$_CONF;
$fleet = DB_getItem($_TABLES['localuserinfo'], "fleet", "uid='$uid'");
$base = DB_getItem($_TABLES['localuserinfo'], "base", "uid='$uid'");
$staffnumber = DB_getItem($_TABLES['localuserinfo'], "staffnumber", "uid='$uid'");
$fullname = DB_getItem($_TABLES['users'], "fullname", "uid='$uid'");
$retval .= '<tr>
<td align="right"><b>Full Name:</b></td>
<td><input type="text" name="cust_fullname" size="50" value="' . $fullname .'"></td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Fleet:</b></td>
<td><input type="text" name="cust_fleet" size="30" maxlength="50" value="' . $fleet .'"></td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Base:</b></td>
<td><input type="text" name="cust_base" size="30" maxlength="50" value="' . $base .'"></td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Staff Number:</b></td>
<td><input type="text" name="cust_staffnumber" size="30" maxlength="50" value="' . $staffnumber .'"></td>
</tr>';
$retval .= '<tr><td colspan="2"><hr></td></tr>';
return $retval;
}
$var = "Value from custom table";
$cookietimeout = DB_getitem($_TABLES['users'], 'cookietimeout', $uid);
$selection = '<select name="cooktime">' . LB;
$selection .= COM_optionList ($_TABLES['cookiecodes'], 'cc_value,cc_descr', $cookietimeout, 0);
$selection .= '</select>';
$retval .= '<tr>
<td align="right">Remember user for:</td>
<td>' . $selection .'</td>
</tr>';
$retval .= '<tr>
<td align="right"><b>Custom Fields:</b></td>
<td><input type="text" name="custom1" size="50" value="' . $var .'"></td>
</tr>';
$retval .= '<tr><td colspan="2"><hr></td></tr>';
return $retval;
/* Function called when saving the user profile. */
/* This function can now update any extra fields */
function custom_usersave($uid) {
global $_TABLES;
$fleet = COM_applyFilter($_POST['cust_fleet'],true);
$staffnumber = COM_applyFilter($_POST['cust_staffnumber'],true);
$base = COM_applyFilter($_POST['cust_base'],true);
$fullname = COM_applyFilter($_POST['fullname']);
DB_query("UPDATE {$_TABLES['users']} SET fullname='$fullname' WHERE uid='$uid'");
if ($fleet > 0) {
DB_query("UPDATE {$_TABLES['localuserinfo']} SET fleet='$fleet' WHERE uid='$uid'");
if ($base > 0) {
DB_query("UPDATE {$_TABLES['localuserinfo']} SET base='$base' WHERE uid='$uid'");
if ($staffnumber > 0) {
DB_query("UPDATE {$_TABLES['localuserinfo']} SET staffnumber='$staffnumber' WHERE uid='$uid'");
}
$cooktime = 0;
if (isset ($_POST['cooktime'])) {
$cooktime = COM_applyFilter ($_POST['cooktime'], true);
if ($cooktime < 0) {
$cooktime = 0;
}
DB_query("UPDATE {$_TABLES['users']} SET cookietimeout = $cooktime WHERE uid = $uid");
}
}
/**
* Main Form used for Custom membership when member is registering
*
* Note: Requires a file custom/memberdetail.thtml in every theme that is
* installed on the site!
*
* @param string $msg an error message to display or the word 'new'
* @return string HTML for the registration form
*
*/
function custom_userform($uid="",$msg="") {
global $_CONF,$_TABLES, $LANG04;
if (!empty($msg)) {
$retval .= COM_startBlock($LANG04[21]) . $msg . COM_endBlock();
}
$post_url = $_CONF['site_url'] . '/users.php';
$postmode = 'create';
$submitbutton = '<input type="submit" value="Register Now!">';
$message = "<blockquote style=\"padding-top:10px;\"><b>Please complete the application below. Once you have completed the application, click the Register Now! button and the application will be processed immediately.</b></blockquote>";
$user_templates = new Template ($_CONF['path_layout'] . 'custom');
$user_templates->set_file('memberdetail', 'memberdetail.thtml');
$user_templates->set_var('site_url', $_CONF['site_url']);
$user_templates->set_var('layout_url', $_CONF['layout_url']);
$user_templates->set_var('post_url', $post_url);
$user_templates->set_var('startblock', COM_startBlock("Custom Registration Example"));
$user_templates->set_var('message', $message);
$user_templates->set_var('USERNAME', $LANG04[2]);
$user_templates->set_var('USERNAME_HELP', "Name to be used when accessing this site");
$username = '';
if (isset ($_POST['username'])) {
$username = COM_applyFilter ($_POST['username']);
}
$user_templates->set_var('username', $username);
$user_templates->set_var('EMAIL', $LANG04[5]);
$user_templates->set_var('EMAIL_HELP', $LANG04[33]);
$email = '';
if (isset ($_POST['email'])) {
$email = COM_applyFilter ($_POST['email']);
}
$user_templates->set_var('email', $email);
$user_templates->set_var('EMAIL_CONF', $LANG04[124]);
$user_templates->set_var('EMAIL_CONF_HELP', $LANG04[126]);
$email_conf = '';
if (isset ($_POST['email_conf'])) {
$email_conf = COM_applyFilter ($_POST['email_conf']);
}
$user_templates->set_var('email_conf', $email_conf);
$user_templates->set_var('FULLNAME', $LANG04[3]);
$user_templates->set_var('FULLNAME_HELP', $LANG04[34]);
$fullname = '';
if (isset ($_POST['fullname'])) {
$fullname = strip_tags ($_POST['fullname']);
}
$user_templates->set_var('fullname', $fullname);
$user_templates->set_var('FULLNAME', "Full Name");
$user_templates->set_var('FULLNAME_HELP', "First and Last Name");
$user_templates->set_var('fullname', $A['fullname']);
$user_templates->set_var('FLEET_ONE', "Fleet");
$user_templates->set_var('FLEET_HELP', "Fleet");
$user_templates->set_var('fleet', "");
$user_templates->set_var('BASE_ONE', "Base");
$user_templates->set_var('BASE_HELP', "Base");
$user_templates->set_var('base', "");
$user_templates->set_var('STAFFNUMBER_ONE', "Staff Number");
$user_templates->set_var('STAFFNUMBER_HELP', "Staff Number");
$user_templates->set_var('staffnumber', "");
$user_templates->set_var('user_id', $user);
$user_templates->set_var('postmode', $postmode);
$user_templates->set_var('submitbutton', $submitbutton);
$user_templates->set_var('endblock', COM_endBlock());
$user_templates->parse('output', 'memberdetail');
$retval .= $user_templates->finish($user_templates->get_var('output'));
return $retval;
}
/**
* Check if it's okay to create a new user.
*
* Geeklog is about to create a new user with the given username and email
* address. This is the custom code's last chance to prevent that,
* e.g. to check if all required data has been entered.
*
* @param string $username username that Geeklog would use for the new user* @param string $email email address of that user
* @return string an error message or an empty string for "OK"
*
*/
function CUSTOM_userCheck ($username, $email)
{
$msg = '';
// Example, check that the full name has been entered
// and complain if it's missing
if (empty ($_POST['fullname'])) {
$msg = 'Please enter your full name!';
}
return $msg;
}
/**
* Custom function to retrieve and return a formatted list of blocks
* Can be used when calling COM_siteHeader or COM_siteFooter
*
* Example:
* 1: Setup an array of blocks to display
* 2: Call COM_siteHeader or COM_siteFooter
*
* $myblocks = array( 'site_menu', 'site_news', 'poll_block' );
*
* COM_siteHeader( array( 'CUSTOM_showBlocks', $myblocks )) ;
* COM_siteFooter( true, array( 'CUSTOM_showBlocks', $myblocks ));
*
* @param array $showblocks An array of block names to retrieve and format
* @return string Formated HTML containing site footer and optionally right blocks
*/
function CUSTOM_showBlocks($showblocks)
{
global $_CONF, $_USER, $_TABLES;
$retval = '';
if( !isset( $_USER['noboxes'] )) {
if( !empty( $_USER['uid'] )) {
$noboxes = DB_getItem( $_TABLES['userindex'], 'noboxes', "uid = {$_USER['uid']}" );
} else {
$noboxes = 0;
}
} else {
$noboxes = $_USER['noboxes'];
}
foreach($showblocks as $block) {
$sql = "SELECT bid, name,type,title,content,rdfurl,phpblockfn,help,allow_autotags FROM {$_TABLES['blocks']} WHERE name='$block'";
$result = DB_query($sql);
if (DB_numRows($result) == 1) {
$A = DB_fetchArray($result);
$retval .= COM_formatBlock($A,$noboxes);
}
}
return $retval;
}
/**
* This is an example of a custom email function. When this function is NOT
* commented out, Geeklog would send all emails through this function
* instead of sending them through COM_mail in lib-common.php.
*
* This is basically a re-implementation of the way emails were sent
* prior to Geeklog 1.3.9 (Geeklog uses PEAR::Mail as of version 1.3.9).
*
*/
/*
function CUSTOM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0)
{
global $_CONF, $LANG_CHARSET;
if (empty ($LANG_CHARSET)) {
$charset = $_CONF['default_charset'];
if (empty ($charset)) {
$charset = 'iso-8859-1';
}
} else {
$charset = $LANG_CHARSET;
}
if (empty ($from)) {
$from = $_CONF['site_name'] . ' <' . $_CONF['site_mail'] . '>';
}
$headers = 'From: ' . $from . "\r\n"
. 'X-Mailer: Geeklog ' . VERSION . "\r\n";
if ($priority > 0) {
$headers .= 'X-Priority: ' . $priority . "\r\n";
}
if ($html) {
$headers .= "Content-Type: text/html; charset={$charset}\r\n"
. 'Content-Transfer-Encoding: 8bit';
} else {
$headers .= "Content-Type: text/plain; charset={$charset}";
}
return mail ($to, $subject, $message, $headers);
}
*/
/**
* This is an example of a function that returns menu entries to be used for
* the 'custom' entry in $_CONF['menu_elements'] (see config.php).
*
*/
/*
function CUSTOM_menuEntries ()
{
global $_CONF, $_USER;
$myentries = array ();
// Sample link #1: Link to Gallery
$myentries[] = array ('url' => $_CONF['site_url'] . '/gallery/',
'label' => 'Gallery');
// Sample link #2: Link to the Personal Calendar - only visible for
// logged-in users
if (!empty ($_USER['uid']) && ($_USER['uid'] > 1)) {
$myentries[] = array ('url' => $_CONF['site_url']
. '/calendar/index.php?mode=personal',
'label' => 'My Calendar');
}
return $myentries;
}
*/
/**
* This is an example of an error handler override. This will be used in
* place of COM_handleError if the user is not in the Root group. Really,
* this should only be used to display some nice pretty "site error" html.
* Though you could try and notify the sysadmin, and log the error, as this
* example will show. The function is commented out for saftey.
*/
/*
function CUSTOM_handleError($errno, $errstr, $errfile, $errline, $errcontext)
{
global $_CONF;
if( is_array($_CONF) && function_exists('COM_mail'))
{
COM_mail($_CONF['site_mail'], $_CONF['site_name'].' Error Handler',
"An error has occurred: $errno $errstr @ $errline of $errfile");
COM_errorLog("Error Handler: $errno $errstr @ $errline of $errfile");
}
echo("
<html>
<head>
<title>{$_CONF['site_name']} - An error occurred.</title>
<style type=\"text/css\">
body,html {height: 100%; width: 100%;}
body{ border: 0px; padding: 0px;
background-color: white;
color: black;
}
div { margin-left: auto; margin-right: auto;
margin-top: auto; margin-bottom: auto;
border: solid thin blue; width: 400px;
padding: 5px; text-align: center;
}
h1 { color: blue;}
</style>
</head>
<body>
<div>
<h1>An Error Has Occurred.</h1>
<p>Unfortunatley, the action you performed has caused an
error. The site administrator has been informed. If you
try again later, the issue may have been fixed.</p>
</div>
</body>
</html>
");
exit;
}
?>
Any help would be greatly appreciated.
10
9
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
You have some weird code outside of any function after CUSTOM_userCreate. That is probably your problem.
9
8
Quote
Eddy
Anonymous
Quote by: jmucchiello
You have some weird code outside of any function after CUSTOM_userCreate. That is probably your problem.
Thanks for the time, but would you mind providing an example!?
Can't see anything out of the ordinary...
Many thanks
10
12
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
Text Formatted Code
function CUSTOM_userCreate ($uid){
global $_TABLES;
$fleet = COM_applyFilter($_POST['cust_fleet'],true);
$base = COM_applyFilter($_POST['cust_base'],true);
$staffnumber = COM_applyFilter($_POST['cust_staffnumber'],true);
$fullname = COM_applyFilter($_POST['cust_fullname']);
// Ensure all data is prepared correctly before inserts, quotes may need to
// be escaped with addslashes()
DB_query("INSERT INTO {$_TABLES['localuserinfo']} (uid,fleet,base,staffnumber) VALUES ('$uid', '$fleet', '$base', '$staffnumber')");
DB_query("UPDATE {$_TABLES['users']} SET fullname = '$fullname' WHERE uid='$uid'");
return true;
}
// WHAT IS THIS STUFF????????????????????????????????????????????????????
// WHAT IS THIS STUFF????????????????????????????????????????????????????
$email = '';
if (isset ($_POST['email'])) {
$email = COM_applyFilter ($_POST['email']);
$email = addslashes ($email);
}
$homepage = '';
if (isset ($_POST['homepage'])) {
$homepage = COM_applyFilter ($_POST['homepage']);
$homepage = addslashes ($homepage);
}
$fullname = '';
if (isset ($_POST['fullname'])) {
// COM_applyFilter would strip special characters, e.g. quotes, so
// we only strip HTML
$fullname = strip_tags ($_POST['fullname']);
$fullname = addslashes ($fullname);
}
// Note: In this case, we can trust the $uid variable to contain the new
// account's uid.
DB_query("UPDATE {$_TABLES['users']} SET email = '$email', homepage = '$homepage', fullname = '$fullname' WHERE uid = $uid");
return true;
// WHAT IS THIS STUFF????????????????????????????????????????????????????
// WHAT IS THIS STUFF????????????????????????????????????????????????????
// Delete any records from custom tables you may have used
function custom_userdelete($uid) {
global $_TABLES;
DB_query("DELETE FROM {$_TABLES['localuserinfo']} WHERE uid='$uid'");
return true;
}
8
11
Quote
Eddy
Anonymous
Hi there, again, thanks for the time.
Sadly, I'm stil lost. I removed everything between your (humorous!) WHAT IS THIS STUFF???????? tags and I'm still getting the same error message. I really can't work out where the problem lies with this one.
I wonder if I'm doing something wrong when adding more custom fields? Instead of just adding the one grad_year (which I re-named), I've added three new fields and perhaps I've screwed something up in the code I've added for them?
Any other ideas matey?!
Again, huge thanks.
Sadly, I'm stil lost. I removed everything between your (humorous!) WHAT IS THIS STUFF???????? tags and I'm still getting the same error message. I really can't work out where the problem lies with this one.
I wonder if I'm doing something wrong when adding more custom fields? Instead of just adding the one grad_year (which I re-named), I've added three new fields and perhaps I've screwed something up in the code I've added for them?
Any other ideas matey?!
Again, huge thanks.
8
9
Quote
Eddy
Anonymous
Hello again, all!
Can anyone help me with this? I've tried and tried in vain for the past few days, adding things, taking thing away etc. Can't find the solution.
Anyone!? Cheers a million.
Can anyone help me with this? I've tried and tried in vain for the past few days, adding things, taking thing away etc. Can't find the solution.
Anyone!? Cheers a million.
8
10
Quote
Eddy
Anonymous
< BUMP >
Sorry to bump this up but I'm still struggling and getting desperate. Where am I going wrong?!
Thanks a million
Sorry to bump this up but I'm still struggling and getting desperate. Where am I going wrong?!
Thanks a million
12
10
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
Add
*/
before the ?> at the end. There is an open comment with no close comment.
*/
before the ?> at the end. There is an open comment with no close comment.
10
7
Quote
Eddy
Anonymous
Hi there,
Thanks for that. The new fields are being displayed now so in terms of appearance, all seems fine. Only problem is that nothing happens when someone tries to register. The registration form just re-displays, empty, and no registration is processed.
I've followed the 'solutions' in the above sticky thread but to no avail.
Any ideas?!
Cheers
Thanks for that. The new fields are being displayed now so in terms of appearance, all seems fine. Only problem is that nothing happens when someone tries to register. The registration form just re-displays, empty, and no registration is processed.
I've followed the 'solutions' in the above sticky thread but to no avail.
Any ideas?!
Cheers
9
11
Quote
All times are EST. The time is now 07:44 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