Files
Testing/bwadmin/admin_grandfather.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

144 lines
4.9 KiB
PHP

<?php
$page = "admin_grandfather";
include "admin_header.php";
if ( !empty( $_POST['checkme'] ) ) {
foreach( $_POST as $k=>$v ) {
if ( substr( $k, 0, 4 ) != 'user' ) continue;
list( $trash, $userid ) = explode( '_', $k );
// herpderr. do we have this one in the database table?
$holder = $database->database_query( "select count(*) as exists from cc_grandfathers where se_userid='$userid'" );
$r = $database->database_fetch_assoc( $holder );
if ( $r['exists'] == 0 ) {
$holder = $database->database_query( "insert into cc_grandfathers set se_userid='$userid', skip=0" );
}
if ( $v == 'skip' ) {
set_skip( $userid );
}
else {
$holder = $database->database_query( "select * from cc_bill where `Subscription ID`='$v'" );
$sub = $database->database_fetch_assoc( $holder );
$sub = fix_keys( $sub );
switch( $sub['InitialPeriod'] ) {
case 365:
$planid=3;
break;
case 180:
$planid=2;
break;
case 90:
if ( $sub['Rebills']>0 ) {
$planid=1;
}
else {
$planid=6;
}
break;
default:
$planid=4;
}
// don't run this yet because we can't fix it.
set_expiration( $userid, $sub['SubscriptionID'],$planid, $sub['expiration'] );
}
}
print "Handled those, try some more?<br />";
}
// RUN QUERY
$rawusers = $database->database_query("SELECT * from se_users where user_id not in ( select se_userid from cc_grandfathers ) order by user_username");
// $rawusers = $database->database_query("SELECT * from se_users order by user_username");
$users=array();
while( count( $users) < 10 && $user = $database->database_fetch_assoc($rawusers) ) {
$thisuser=array();
$thisuser['user_id'] = $user['user_id'];
$thisuser['new_email']=$user['user_email'];
$thisuser['new_username']=$user['user_username'];
// check for matching usernames in cc_bill;
// they didn't have a restriction on unique usernames.
$check_username = $database->database_query( "select * from cc_bill where Username like '".$database->database_real_escape_string( substr( $user['user_username'],0,8) )."%'" );
$username = array();
$possibles=array();
if ( $database->database_num_rows( $check_username) > 0 ) {
while($foo = $database->database_fetch_assoc($check_username)) {
// stupid database has spacesi n field names.
$bar = fix_keys( $foo );
$key = $bar['SubscriptionID'];
$possibles[ $key ]=$bar;
$possibles[ $key ]['reasons'][]='username';
}
}
$thisuser['check_username'] = $username;
// check for matching emails in cc_bill;
// do the same array build thing even though the emails should be unique. this'll make the template more routine.
$check_email = $database->database_query( "select * from cc_bill where `Email Address`='".$database->database_real_escape_string( $user['user_email'] )."'" );
$email = array();
if ( $database->database_num_rows( $check_email) > 0 ) {
while($foo = $database->database_fetch_assoc($check_email)) {
// stupid database has spacesi n field names.
$bar = fix_keys( $foo );
$key = $bar['SubscriptionID'];
$possibles[ $key ]=$bar;
$possibles[ $key ]['reasons'][]='email';
}
}
if ( count( $possibles ) > 0 ) {
$thisuser['possibles'] = $possibles;
$thisuser['check_email'] = $email;
$users[]=$thisuser;
}
// assign this to an array element;
}
$smarty->assign( 'users', array_slice( $users, 0, 25, true ));
// ASSIGN VARIABLES AND SHOW STATS PAGE
function fix_keys( $input ) {
$output=array();
foreach( $input as $k=>$v ) {
$key = str_replace( ' ', '', $k );
if ($key != '' ) {
$output[$key] = $v;
}
}
// add an expiration date
$start = $input['Transaction Date'];
$start = strtotime( $start );
$dur = $input['Initial Period'];
$end = $start + ( $dur * 60*60*24 );
$output['expiration'] = $end;
return $output;
}
function set_expiration( $user=0, $subscription=0, $planid=4, $expiration=0 ){
if ( (int) $user == 0 ) return false;
if ( (int) $expiration == 0 ) {
$expiration = strtotime( $expiration );
}
if ( $expiration < time() ) return false;
global $database;
$expire_sql = "UPDATE se_semods_userplans SET userplan_plan_id = '$planid', userplan_expiredate = '$expiration' WHERE userplan_user_id = '$user'";
$database->database_query( $expire_sql );
$sub_sql = "UPDATE se_semods_userplans SET userplan_metadata = 'a:1:{s:5:\"cc_id\";s:19:\"$subscription\";}' WHERE userplan_user_id = '$user'";
$database->database_query( $sub_sql );
$cc_sql = "UPDATE cc_bill set se_userid='$user' where `Subscription ID`='$subscription'";
$database->database_query( $cc_sql );
set_skip( $user, $subscription );
}
function set_skip( $userid, $sub=null ) {
global $database;
if ( empty( $sub ) ) { $s=$database->database_query( "update cc_grandfathers set skip=1 where se_userid='$userid'" ); }
else {
$s=$database->database_query( "update cc_grandfathers set ccbill_subid = '$sub' , skip=1 where se_userid='$userid'" ); }
return $s;
}
include "admin_footer.php";
?>