<?php
//+-----------------------------------------------------+//
//+ Copyright Floopo.com
//+ functions.php
//+ Functions admin helper
//+-----------------------------------------------------+//



//___________________Delete a member__________________________________

function DeleteMember($username){
global $dbase;

//____delete members images_____
$image_list = $dbase->SelectRecordLoop("SELECT filename
                                        FROM content_images 
                                        WHERE user_name = '$username'");
//delete images physically
$total_images = count($image_list);

for($count =0; $count <= $total_images; $count++){
@unlink (BASEPATH . '/content/images/'.$image_list[$count][0]);
@unlink (BASEPATH . '/content/images/thumbs/'.$image_list[$count][0]);
}

//delete images from dbase
$dbase->DeleteRecord("DELETE FROM content_images 
                      WHERE user_name = '$username'");



//____delete members avatar_____
$image_list = $dbase->SelectRecordLoop("SELECT avatar
                                        FROM member_profile 
                                        WHERE user_name = '$username'");

$avatar = $image_list[0][0];
if($avatar != 'default.png'){
@unlink (BASEPATH . '/content/avatars/'.$avatar);
}


//____delete members following_____
$dbase->DeleteRecord("DELETE FROM following 
                      WHERE user_name = '$username' OR followers_user_name = '$username'");


//____delete members direct messages_____
$dbase->DeleteRecord("DELETE FROM personal_messages 
                      WHERE sender = '$username' OR receiver = '$username'");


//____delete web profiles_____
$dbase->DeleteRecord("DELETE FROM web_profiles 
                      WHERE user_name = '$username'");


//____delete member preferences_____
$dbase->DeleteRecord("DELETE FROM member_preferences 
                      WHERE user_name = '$username'");




//____delete members text updates____
$dbase->DeleteRecord("DELETE FROM content_text 
                      WHERE user_name = '$username'");


//____delete actual member____
$dbase->DeleteRecord("DELETE FROM member_profile 
                      WHERE user_name = '$username'");
                      
//check if any database errors
if($dbase->obj_status){
return true;
}

}


//___________________Change members status(e.e. suspend, activate etc)__________________________________

function MemberStatus($username, $status){ //status = 'active', 'suspended', 'new' etc
global $dbase;

$dbase->UpdateRecord("UPDATE member_profile 
                      SET account_status = '$status'
                      WHERE user_name = '$username'");

//check if any database errors
if($dbase->obj_status){
return true;
}

}


?>