include_once "includes/dbConnNew.php";
include_once "includes/loggedOn.php";
import_request_variables("gp", "");
//remove a friend from the user's network
if($_REQUEST['remove'] == "y"){
$selfID = $_SESSION["sessionUserID"];
$friend_id = $_REQUEST['fid'];
//SEE if this user was piggy backing on the friend's account. If so, switch $selfID and $friend_id so that the slot will be freed up for the friend instead
$sqlNW = "select * from users where (ID = '$selfID') and (MASTER_ACCOUNT = '$friend_id') ";
$resultNW = MySQL($dbName,$sqlNW) or die(mysql_error());
if($myrowNW=MySQL_fetch_array($resultNW)){
$selfID = $myrowNW['MASTER_ACCOUNT'];
$friend_id = $myrowNW['ID'];
}
//first un-network the 2
$sql = "update privacy set deleted = '1' where (user_id = '$selfID') and (friend_id = '$friend_id') limit 1";
$result = MySQL($dbName,$sql) or die(mysql_error());
$sql = "update privacy set deleted = '1' where (user_id = '$friend_id') and (friend_id = '$selfID') limit 1";
$result = MySQL($dbName,$sql) or die(mysql_error());
//now give the user a slot back if they deserve one
//first remove the friend if they were piggy packing on this user
$sql = "update users set Prem_Ind = 'N' where (ID = '$friend_id') AND (Prem_Date = '0000-00-00' ) and (MASTER_ACCOUNT = '$selfID') LIMIT 1";
$result = MySQL($dbName,$sql) or die(mysql_error());
$sql = "update users set MASTER_ACCOUNT = '0' where (ID = '$friend_id') AND (MASTER_ACCOUNT = '$selfID' ) LIMIT 1";
$result = MySQL($dbName,$sql) or die(mysql_error());
if (mysql_affected_rows() > 0){ //then give a user back their slot
$sql = "update users_purchased_slots set NUMBER_LEFT = NUMBER_LEFT + 1, NUMBER_USED = NUMBER_USED - 1 where USER_ID = '$selfID' limit 1 ";
$result = mysql_query($sql) or die(mysql_error());
//get the user's prem date
$sqlNW = "select * from users where ID = '$selfID' ";
$resultNW = MySQL($dbName,$sqlNW) or die(mysql_error());
if($myrowNW=MySQL_fetch_array($resultNW)){
$self_Prem_Date = $myrowNW['Prem_Date'];
}
//now see if we can add someone else to the available slot
$nbrFriendsSlotted = 0;
$sqlNW = "select * from privacy, users where (privacy.user_id = '$selfID') and (privacy.deleted = '0') and (users.ID = privacy.friend_id) and (MASTER_ACCOUNT <> '$selfID') order by privacy.txn_ts";
$resultNW = MySQL($dbName,$sqlNW) or die(mysql_error());
while($myrowNW=MySQL_fetch_array($resultNW)){
$friend_id = $myrowNW['friend_id'];
$friend_Prem_Ind = $myrowNW['Prem_Ind'];
$friend_Prem_Date = $myrowNW['Prem_Date'];
$MASTER_ACCOUNT = $myrowNW['MASTER_ACCOUNT'];
//if they are under someone else's master account, get that person's premium date
if($MASTER_ACCOUNT > 0){
$sqlNW = "select * from users where ID = '$MASTER_ACCOUNT' ";
$resultNW = MySQL($dbName,$sqlNW) or die(mysql_error());
if($myrowNW=MySQL_fetch_array($resultNW)){
$master_Prem_Date = $myrowNW['Prem_Date'];
if($friend_Prem_Date < $master_Prem_Date){
$friend_Prem_Date = $master_Prem_Date;
}
}
}
//see if this friend should go under the user's account -
//should if friend: is not a premium, is a premium but prem date < this user's prem date, biggybacked w/ someone else but their prem date < this user's prem date
if ( ($friend_Prem_Ind <> 'Y') or ($friend_Prem_Date < $self_Prem_Date) ){
if($nbrFriendsSlotted == 0){
$sql = "update users set Prem_Ind = 'Y', MASTER_ACCOUNT = '$selfID' where ID = '$friend_id' limit 1 ";
$result = mysql_query($sql) or die(mysql_error());
//now decrement the invitees slots
$sql = "update users_purchased_slots set NUMBER_LEFT = NUMBER_LEFT - 1, NUMBER_USED = NUMBER_USED + 1 where USER_ID = '$selfID' limit 1";
$result = mysql_query($sql) or die(mysql_error());
}
$nbrFriendsSlotted++;
}
} //end of look for someone to take the slot
}//end of see if we freed up a slot
} //end of remove someone
?>
YadaHome | Sharing Center
include 'beforeEndHead.php'; ?>