5
Ok, I must say that Registration Keys was exactly what I was looking for, except I use 2.2.2... So @ 3 AM I started to incorporate it into 2.2.2 Now, do not curse my crude code - all I can say is it can be cleaned up, but it works...
Sudo Legal Stuff->Disclaimer:
Although this works flawlessly on my install, I do not imply this will for for everyone. Nor is it implied that this will not totally trash your running site - all code must be tested and deemed safe by your own testing and judgement. I will not be held responsible for any damage done using this code.
Here is the "hack":
1. All files except for register.php and registerform.php (in the registration keys download) need to be incorporated as required (do not overwrite, add the commented portions into your own files - they are not the same)
2. After all is included create your registration keys (Misc. Tools->Registration Keys), jot down the one for the default registration type (registered user).
3. I had to add a $_Get[] statement into Modules->System->Admin->Regkeys->main.php in order to get the admin pages working properly (one server required it - one did not, so I figured I would mention it):
if (isset($_GET['op'])) {
$op = trim($_GET['op']);
}
if (isset($_GET['type'])) {
$type = trim($_GET['type']);
}
if (isset($_GET['key_id'])) {
$key_id = trim($_GET['key_id']);
}
4. Create a new field in "Modules->Profile->Fields" called "user_regkey" - with a default set to #2 above and ensure that it is on the registration page and that it is required. (this portion takes care of all the the coding that was in registerform.php).
5. Do the following in {Xoops Root}->Modules->Profile->register.php:
------------- Find This -----------------------
if ($xoopsModuleConfig['display_disclaimer'] != 0 && $xoopsModuleConfig['disclaimer'] != '') {
if (empty($agree_disc)) {
$stop .= _PROFILE_MA_UNEEDAGREE.'
';
}
}
----------- End Find This ---------------------
--------- Add This After Above Code -----------
// Registration Keys Module add-in
// Author: Jean-Philippe Steinmetz
// Modded By: Rodger Cravens
global $xoopsDB;
$xoopsDB =& Database::getInstance();
$str_regkey = $newuser->getVar('user_regkey');
$result = $xoopsDB->query("SELECT status,groups FROM ".$xoopsDB->prefix('regkeys')." WHERE code='".$str_regkey."'");
$rkfound = false;
if(count($result) == 1) { // registration key found
list($rkstatus,$rkgroups) = $xoopsDB->fetchRow($result);
if($rkstatus) { // check to see if key is enabled
$rkfound = true;
}
}
if (!$rkfound) { // check if reg key is required and if not found
if($str_regkey == '') { // Check if any key was entered.
$stop .= _US_UNEEDREGKEY;
} else {
$stop .= _US_BADREGKEY;
}
}
// End Module add-in
------- End Add This After Above Code ---------
------------- Find This -----------------------
if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid)) {
echo _PROFILE_MA_REGISTERNG;
break;
}
----------- End Find This ---------------------
----------- Replace With This Code ------------
------ OR Comment Out For Easy Roll Back ------
// Registration Keys Module alteration
// Author: Jean-Philippe Steinmetz
// Modded By: Rodger Cravens
mysql_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS) or die("Unable to connect to host $server");
mysql_select_db("XOOPS_DB_NAME") or die("Unable to select database $db");
$i = "0";
$query1 = "SELECT * FROM ".$xoopsDB->prefix('user_profile')." WHERE profileid = '".$newid."'";
$result = mysql_query($query1);
$userkey = mysql_result($result,$i,"user_regkey");
$query2 = "SELECT groups FROM ".$xoopsDB->prefix('regkeys')." WHERE code = '$userkey'";
$result = mysql_query($query2);
$usergroup = mysql_result($result,$i,"groups");
$lt = ltrim($usergroup,"[]");
$reg_groups = trim(rtrim($lt,"])"));
// the following adds them to the entered group, or on fail adds them to the XOOPS default group
if(!$member_handler->addUserToGroup($reg_groups,$newid))
{
$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid);
}
// End alteration
--------- End Replace With This Code ----------