Welcome to Geeklog, Anonymous Friday, March 21 2025 @ 12:36 pm EDT
Geeklog Forums
Add / removing groups
anonymouse
Anonymous

Please forgive the quailty of the code iIm new to php and geeklog and its a proof of concept prototype plugin. The concept is simple upon installation the plugin creates a new table 'freetrial' with fields uid, trialstart, trialend
plugin_user_create_freetrial($uid) - creates an entry in the table when a new user registers and adds users to freetrial group
function plugin_user_login_freetrial($uid) - updates the start and end time stamps first time user logs in and then check trial end against current timestamp. if trial expired revoke group membership
I have 2 problems -
How do I make user_create return nothing as it seems to break the new user
template.
How do I force a refresh of the users access and group memberships.
Thanks.
functions.inc for plugin ( there isnt any interface html for it )
require_once ($_CONF['path'] . 'plugins/freetrial/config.php');
function plugin_uninstall_freetrial($installCheck='')
{
global $_TABLES, $LANG_GLMENU00;
$pi_name='freetrial';
DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'freetrial'",1);
DB_query("drop table {$_TABLES['freetrial']} ",1);
}
/**
* This function is called when a new user is created.
* Adds user to 'trial group' and sets up trial detail record for user
*/
function plugin_user_create_freetrial($uid) {
// create record with $uid,0,0 Dont set start or end date until user has logged in once.
// put uid in trial group
global $_TABLES;
// Ensure all data is prepared correctly before inserts, quotes may need to be escaped with addslashes()
DB_query("INSERT INTO {$_TABLES['freetrial']} (uid,trialstart,trialend) VALUES ('$uid', '0', '0')");
$targetGrp = GetGroupUID('freetrial') ;
USER_addGroup($targetGrp[0], $uid);
}
/**
* This function is called when a Logs in
* if first time user logged in setups up trial start and end params
* else if current timestamp > trialend timestamp - expire trial
* and remove from group
*/
function plugin_user_login_freetrial($uid)
{
global $_TABLES;
$timestamp = time();
$record = GetTrialData($uid);
// start date isnt set - should be users first login so commence trial.
if ($record['trialstart'] == 0) {
$record['uid'] = $uid;
$record['trialstart'] = $timestamp;
$record['trialend'] = time() + (30 * 24 * 60 * 60); // 30 days;
// update record here
$fields = "uid,trialstart,trialend";
$values = "{$record['uid']},{$record['trialstart']},{$record['trialend']}";
DB_save($_TABLES['freetrial'] ,$fields,$values) ;
// DB_query("UPDATE {$_TABLES['freetrial']} SET uid='$record[0]' WHERE uid='$uid'");
// DB_query("UPDATE {$_TABLES['freetrial']} SET trialstart='$record[1]' WHERE uid='$uid'");
// DB_query("UPDATE {$_TABLES['freetrial']} SET trialend='$record[2]' WHERE uid='$uid'");
}
if ($record['trialend'] < $timestamp) {
$result= SEC_inGroup('freetrial',$uid);
if ($result == true) {
$targetGrp = GetGroupUID('freetrial') ;
// remove user from priviledged group
USER_delGroup($targetGrp['grp_id'], $uid);
// call sec_groups to update
}
}
}
function GetTrialData($uid){
global $_TABLES;
//this is a nice example of a sql call that works flawlessly in SQL server,
//but not so well in mysql 4.x and lower....
$sql="select uid, trialstart,trialend";
$sql.=" ";
$sql.="from ";
$sql.="{$_TABLES['freetrial'] } where uid = '$uid'";
$res=DB_query($sql);
$nrows=DB_numRows($res);
$thisRow= DB_fetchArray($res);
return $thisRow;
}
function GetGroupUID($grp_name) {
global $_TABLES;
$sql="select grp_id, grp_name";
$sql.=" ";
$sql.="from ";
$sql.="{$_TABLES['groups'] } where grp_name = '$grp_name'";
$res=DB_query($sql);
$nrows=DB_numRows($res);
$thisRow= DB_fetchArray($res);
return $thisRow;
}
?>
plugin_user_create_freetrial($uid) - creates an entry in the table when a new user registers and adds users to freetrial group
function plugin_user_login_freetrial($uid) - updates the start and end time stamps first time user logs in and then check trial end against current timestamp. if trial expired revoke group membership
I have 2 problems -
How do I make user_create return nothing as it seems to break the new user
template.
How do I force a refresh of the users access and group memberships.
Thanks.
functions.inc for plugin ( there isnt any interface html for it )
Text Formatted Code
<?phprequire_once ($_CONF['path'] . 'plugins/freetrial/config.php');
function plugin_uninstall_freetrial($installCheck='')
{
global $_TABLES, $LANG_GLMENU00;
$pi_name='freetrial';
DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'freetrial'",1);
DB_query("drop table {$_TABLES['freetrial']} ",1);
}
/**
* This function is called when a new user is created.
* Adds user to 'trial group' and sets up trial detail record for user
*/
function plugin_user_create_freetrial($uid) {
// create record with $uid,0,0 Dont set start or end date until user has logged in once.
// put uid in trial group
global $_TABLES;
// Ensure all data is prepared correctly before inserts, quotes may need to be escaped with addslashes()
DB_query("INSERT INTO {$_TABLES['freetrial']} (uid,trialstart,trialend) VALUES ('$uid', '0', '0')");
$targetGrp = GetGroupUID('freetrial') ;
USER_addGroup($targetGrp[0], $uid);
}
/**
* This function is called when a Logs in
* if first time user logged in setups up trial start and end params
* else if current timestamp > trialend timestamp - expire trial
* and remove from group
*/
function plugin_user_login_freetrial($uid)
{
global $_TABLES;
$timestamp = time();
$record = GetTrialData($uid);
// start date isnt set - should be users first login so commence trial.
if ($record['trialstart'] == 0) {
$record['uid'] = $uid;
$record['trialstart'] = $timestamp;
$record['trialend'] = time() + (30 * 24 * 60 * 60); // 30 days;
// update record here
$fields = "uid,trialstart,trialend";
$values = "{$record['uid']},{$record['trialstart']},{$record['trialend']}";
DB_save($_TABLES['freetrial'] ,$fields,$values) ;
// DB_query("UPDATE {$_TABLES['freetrial']} SET uid='$record[0]' WHERE uid='$uid'");
// DB_query("UPDATE {$_TABLES['freetrial']} SET trialstart='$record[1]' WHERE uid='$uid'");
// DB_query("UPDATE {$_TABLES['freetrial']} SET trialend='$record[2]' WHERE uid='$uid'");
}
if ($record['trialend'] < $timestamp) {
$result= SEC_inGroup('freetrial',$uid);
if ($result == true) {
$targetGrp = GetGroupUID('freetrial') ;
// remove user from priviledged group
USER_delGroup($targetGrp['grp_id'], $uid);
// call sec_groups to update
}
}
}
function GetTrialData($uid){
global $_TABLES;
//this is a nice example of a sql call that works flawlessly in SQL server,
//but not so well in mysql 4.x and lower....
$sql="select uid, trialstart,trialend";
$sql.=" ";
$sql.="from ";
$sql.="{$_TABLES['freetrial'] } where uid = '$uid'";
$res=DB_query($sql);
$nrows=DB_numRows($res);
$thisRow= DB_fetchArray($res);
return $thisRow;
}
function GetGroupUID($grp_name) {
global $_TABLES;
$sql="select grp_id, grp_name";
$sql.=" ";
$sql.="from ";
$sql.="{$_TABLES['groups'] } where grp_name = '$grp_name'";
$res=DB_query($sql);
$nrows=DB_numRows($res);
$thisRow= DB_fetchArray($res);
return $thisRow;
}
?>
10
9
Quote
Anonymouse
Anonymous

Ok I have been investigating further and made the following changes in function plugin_user_login_freetrial($uid)
my freetrial group has a value of "19" and user was in group
$groups = SEC_getUserGroups ($uid); // groups = allusers, logged_in , freetrial
$targetGrp = GetGroupUID('freetrial') ; // targetGrp = 19
$result = in_array($targetGrp['grp_id'],$groups);
if ($result) { // should be true
// remove user from priviledged group
USER_delGroup($targetGrp['grp_id'], $uid);
// call sec_groups to update
}
}
$groups = SEC_getUserGroups () // - still lists group freetrial 19
$result = SEC_inGroup($targetGrp['grp_id'],$uid); // - dosnt
Admin screen still shows user in group.
Help needed :-(
my freetrial group has a value of "19" and user was in group
Text Formatted Code
if ($record['trialend'] < $timestamp) { // true$groups = SEC_getUserGroups ($uid); // groups = allusers, logged_in , freetrial
$targetGrp = GetGroupUID('freetrial') ; // targetGrp = 19
$result = in_array($targetGrp['grp_id'],$groups);
if ($result) { // should be true
// remove user from priviledged group
USER_delGroup($targetGrp['grp_id'], $uid);
// call sec_groups to update
}
}
$groups = SEC_getUserGroups () // - still lists group freetrial 19
$result = SEC_inGroup($targetGrp['grp_id'],$uid); // - dosnt
Admin screen still shows user in group.
Help needed :-(
9
11
Quote
All times are EDT. The time is now 12:36 pm.
- 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