Files
Testing/user_friends_manage_bulk.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

500 lines
20 KiB
PHP

<?php
/* $Id: user_friends_manage.php 136 2009-03-24 00:25:44Z john $ */
$page = "user_friends_manage";
include "header.php";
if($_POST["accept"]=="Accept"){$task="add_do";}
if($_POST["deny"]=="Deny"){$task="reject_do";}
if($_POST["addall"]=="Accept All Requests"){$task="add_all";}
if($_POST["delete"]=="Delete Friends"){$task="delete_all";}
if($_POST["p"]!=""){$p=$_POST["p"];}else{$p=1;}
//$task = ( isset($_POST['task']) ? $_POST['task'] : ( isset($_GET['task']) ? $_GET['task'] : NULL ) );
// INITIALIZE VARS
$result = 0;
$friendship_allowed = 1;
// GET FRIEND TYPES IF AVAILABLE
$connection_types = array_filter(explode("<!>", trim($setting['setting_connection_types'])));
$query=$database->database_query("SELECT DISTINCT(friend_type) FROM se_friends WHERE friend_user_id1='{$user->user_info['user_id']}' AND friend_type!='Buddy' AND friend_type!='Just Curious' AND friend_type!='Hottie' AND friend_type!='Special Buddy' AND friend_type!=''");
while($row = $database->database_fetch_array($query)){
$connection_types[]=$row["friend_type"];
}
// ENSURE CONECTIONS ARE ALLOWED FOR THIS USER
switch( $setting['setting_connection_allow'] )
{
// ANYONE CAN INVITE EACH OTHER TO BE FRIENDS
case "3": break;
// CHECK IF IN SAME SUBNETWORK
case "2": if( $user->user_info['user_subnet_id'] != $owner->user_info['user_subnet_id'] ) { $friendship_allowed = 0; } break;
// CHECK IF FRIEND OF FRIEND
case "1": if( !$user->user_friend_of_friend($owner->user_info['user_id']) ) { $friendship_allowed = 0; } break;
// NO ONE CAN INVITE EACH OTHER TO BE FRIENDS
case "0": $friendship_allowed = 0; break;
}
// Secure action
if(( empty($_POST['friend']) && in_array($task, array('edit_do', 'reject_do', 'cancel_do', 'remove_do', 'add_do', 'add_all', 'delete_all'))) )
{
if($task!="add_all"){
//echo 'Please check a box before proceeding';
//exit();
$task="";
}
}
// NO OWNER, FRIENDSHIP NOT ALLOWED, USER IS TRYING TO FRIEND THEMSELVES, USER IS ON BLOCKLIST
/*if( !$owner->user_exists || !$friendship_allowed || $owner->user_info['user_id'] == $user->user_info['user_id'] || $owner->user_blocked($user->user_info['user_id']) )
exit();
*/
// DECIDE WHICH PAGE TO SHOW
if( $owner->user_friended($user->user_info['user_id'], 0) )
{
if($task == "reject")
{
$subpage = "reject";
}
elseif($setting['setting_connection_framework'] == 1 || $setting['setting_connection_framework'] == 3 || $user->user_friended($owner->user_info['user_id']))
{
$subpage = "confirm";
}
else
{
$subpage = "add";
}
}
elseif($user->user_friended($owner->user_info['user_id']))
{
if($task == "remove")
{
$subpage = "remove";
}
else
{
$subpage = "edit";
$friendship = $database->database_fetch_assoc($database->database_query("SELECT friend_id, friend_type FROM se_friends WHERE friend_user_id2='{$owner->user_info['user_id']}' AND friend_user_id1='{$user->user_info['user_id']}' AND friend_status='1'"));
$friend_explain = $database->database_fetch_assoc($database->database_query("SELECT friendexplain_id, friendexplain_body FROM se_friendexplains WHERE friendexplain_friend_id='{$friendship['friend_id']}'"));
$friend_type = $friendship['friend_type'];
$friend_type_other = $friendship['friend_type'];
$friend_explain = $friend_explain['friendexplain_body'];
if(count($connection_types) == 0) { $friend_type = ""; }
if($setting['setting_connection_other'] == 0) { $friend_type_other = ""; }
if($setting['setting_connection_explain'] == 0) { $friend_explain = ""; }
if(in_array($friend_type, $connection_types)) { $friend_type_other = ""; }
}
}
elseif($user->user_friended($owner->user_info['user_id'], 0))
{
$subpage = "cancel";
}
else
{
$subpage = "add";
}
// EDIT FRIEND DETAILS
if( $task == "edit_do" )
{
$friend_type = $_POST['friend_type'];
$friend_type_other = censor($_POST['friend_type_other']);
$friend_explain = censor($_POST['friend_explain']);
if(count($connection_types) == 0) { $friend_type = ""; }
if($setting['setting_connection_other'] == 0) { $friend_type_other = ""; }
if($setting['setting_connection_explain'] == 0) { $friend_explain = ""; }
if(in_array($friend_type, $connection_types)) { $friend_type_other = ""; }
if($friend_type == "other_friendtype") { $friend_type = ""; }
if(trim($friend_type_other) != "") { $friend_type = $friend_type_other; }
$database->database_query("UPDATE se_friends SET friend_type='{$friend_type}' WHERE friend_id='{$friendship['friend_id']}'");
$database->database_query("UPDATE se_friendexplains SET friendexplain_body='{$friend_explain}' WHERE friendexplain_friend_id='{$friendship['friend_id']}'");
$status = "remove";
$result = 923;
}
// REJECT FRIEND REQUEST
elseif( $task == "reject_do" )
{if(count($_POST["friend"])>1){
foreach($_POST["friend"] as $friend){
$owner = new SEUser(Array("",$friend));
$owner->user_friend_remove($user->user_info['user_id']);
$database->database_query("DELETE FROM se_notifys WHERE notify_user_id='{$user->user_info['user_id']}' AND notify_notifytype_id='1' AND notify_object_id='{$owner->user_info['user_id']}'");
$status = "remove";
$result = 914;
}}
else{
$owner = new SEUser(Array("",$_POST["friend"][0]));
$owner->user_friend_remove($user->user_info['user_id']);
$database->database_query("DELETE FROM se_notifys WHERE notify_user_id='{$user->user_info['user_id']}' AND notify_notifytype_id='1' AND notify_object_id='{$owner->user_info['user_id']}'");
$status = "remove";
$result = 914;
}
}
// CANCEL FRIEND REQUEST
elseif( $task == "cancel_do" )
{
$user->user_friend_remove($owner->user_info['user_id']);
$database->database_query("DELETE FROM se_notifys WHERE notify_user_id='{$owner->user_info['user_id']}' AND notify_notifytype_id='1' AND notify_object_id='{$user->user_info['user_id']}'");
$status = "remove";
$result = 920;
}
// UNFRIEND USER
elseif( $task == "remove_do" )
{
$user->user_friend_remove($owner->user_info['user_id']);
$status = "add";
$result = 890;
}
elseif( $task == "delete_all" )
{
if(isset($_POST['s'])) { $s = $_POST['s']; } elseif(isset($_GET['s'])) { $s = $_GET['s']; } else { $s = "zz"; }
if(isset($_POST['search'])) { $search = $_POST['search']; } elseif(isset($_GET['search'])) { $search = $_GET['search']; } else { $search = ""; }
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = ""; }
if(count($_POST["friend"])>1){
foreach($_POST["friend"] as $friend){
$owner = new SEUser(Array("",$friend));
$user->user_friend_remove($owner->user_info['user_id']);
$status = "add";
$result = 890;
}
}
else{
$owner = new SEUser(Array("",$_POST["friend"][0]));
$user->user_friend_remove($owner->user_info['user_id']);
$status = "add";
$result = 890;
}
header("Location: user_friends.php?p=$p&s=$s&search=$search&task=$task");
exit;
}
elseif($task=="add_all")
{
$query=$database->database_query("SELECT * FROM se_friends WHERE friend_user_id2='".$user->user_info["user_id"]."' AND friend_status='0'");
while($row=$database->database_fetch_array($query)){
$owner = new SEUser(Array($row["friend_user_id1"],""));
$friend_type = $_POST['friend_type'];
$friend_type_other = censor($_POST['friend_type_other']);
$friend_explain = censor($_POST['friend_explain']);
if(count($connection_types) == 0) { $friend_type = ""; }
if($setting['setting_connection_other'] == 0) { $friend_type_other = ""; }
if($setting['setting_connection_explain'] == 0) { $friend_explain = ""; }
if($friend_type == "other_friendtype") { $friend_type = ""; }
if(trim($friend_type_other) != "") { $friend_type = $friend_type_other; }
// DETERMINE FRIENDSHIP FRAMEWORK
switch($setting['setting_connection_framework'])
{
case "0": $direction = 2; $friend_status = 0; $status = "pending"; $result = 878; break;
case "1": $direction = 1; $friend_status = 0; $status = "pending"; $result = 878; break;
case "2": $direction = 2; $friend_status = 1; $status = "remove"; $result = 879; break;
case "3": $direction = 1; $friend_status = 1; $status = "remove"; $result = 879; break;
}
// IF CONFIRMING AN EXISTING FRIEND REQUEST
if($owner->user_friended($user->user_info['user_id'], 0))
{
// CONFIRM FRIENDSHIP
$database->database_query("UPDATE se_friends SET friend_status='1' WHERE friend_user_id1='{$owner->user_info['user_id']}' AND friend_user_id2='{$user->user_info['user_id']}' AND friend_status='0'");
// INSERT ACTION
$actions->actions_add($owner, "addfriend", Array($owner->user_info['user_username'], $owner->user_displayname, $user->user_info['user_username'], $user->user_displayname), Array(), 0, false, "user", $owner->user_info['user_id'], $owner->user_info['user_privacy']);
// DELETE NOTIFICATION
$database->database_query("DELETE FROM se_notifys WHERE notify_user_id='{$user->user_info['user_id']}' AND notify_notifytype_id='1' AND notify_object_id='{$owner->user_info['user_id']}'");
// IF TWO-WAY CONNECTION, INSERT OTHER DIRECTION
if( $direction == 2 && !$user->user_friended($owner->user_info['user_id']) )
{
$user->user_friend_add($owner->user_info['user_id'], 1, $friend_type, $friend_explain);
$actions->actions_add($user, "addfriend", Array($user->user_info['user_username'], $user->user_displayname, $owner->user_info['user_username'], $owner->user_displayname), Array(), 0, false, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
$status = "remove";
$result = 879;
}
elseif( $user->user_friended($owner->user_info['user_id']) )
{
$status = "remove";
$result = 886;
}
else
{
$status = "add";
$result = 886;
}
}
/* // CREATING A NEW FRIENDSHIP
else
{
// CREATE FRIENDSHIP
$user->user_friend_add($owner->user_info['user_id'], $friend_status, $friend_type, $friend_explain);
// INSERT ACTION
if($friend_status == 1)
{
$actions->actions_add($user, "addfriend", Array($user->user_info['user_username'], $user->user_displayname, $owner->user_info['user_username'], $owner->user_displayname), Array(), 0, false, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
}
else
{
$notify->notify_add($owner->user_info['user_id'], 'friendrequest', $user->user_info['user_id']);
}
// IF TWO-WAY CONNECTION AND NON-CONFIRMED, INSERT OTHER DIRECTION AND ACTION
if( $direction == 2 && $friend_status == 1 && !$owner->user_friended($user->user_info['user_id']) )
{
$owner->user_friend_add($user->user_info['user_id'], $friend_status, '', '');
$actions->actions_add($owner, "addfriend", Array($owner->user_info['user_username'], $owner->user_displayname, $user->user_info['user_username'], $user->user_displayname), Array(), 0, false, "user", $owner->user_info['user_id'], $owner->user_info['user_privacy']);
}
// SEND FRIENDSHIP EMAIL
$owner->user_settings();
if( $owner->usersetting_info['usersetting_notify_friendrequest'] )
{
send_systememail('friendrequest', $owner->user_info['user_email'], Array($owner->user_displayname, $user->user_displayname, "<a href=\"".$url->url_base."login.php\">".$url->url_base."login.php</a>"));
}
}*/
// UPDATE STATS
update_stats("friends");
}
}
// CONFIRM OR ADD FRIEND
elseif( $task == "add_do" )
{
if(count($_POST["friend"])>1){
foreach($_POST["friend"] as $friend){
$owner = new SEUser(Array("",$friend));
$friend_type = $_POST['friend_type'];
$friend_type_other = censor($_POST['friend_type_other']);
$friend_explain = censor($_POST['friend_explain']);
if(count($connection_types) == 0) { $friend_type = ""; }
if($setting['setting_connection_other'] == 0) { $friend_type_other = ""; }
if($setting['setting_connection_explain'] == 0) { $friend_explain = ""; }
if($friend_type == "other_friendtype") { $friend_type = ""; }
if(trim($friend_type_other) != "") { $friend_type = $friend_type_other; }
// DETERMINE FRIENDSHIP FRAMEWORK
switch($setting['setting_connection_framework'])
{
case "0": $direction = 2; $friend_status = 0; $status = "pending"; $result = 878; break;
case "1": $direction = 1; $friend_status = 0; $status = "pending"; $result = 878; break;
case "2": $direction = 2; $friend_status = 1; $status = "remove"; $result = 879; break;
case "3": $direction = 1; $friend_status = 1; $status = "remove"; $result = 879; break;
}
// IF CONFIRMING AN EXISTING FRIEND REQUEST
if($owner->user_friended($user->user_info['user_id'], 0))
{
// CONFIRM FRIENDSHIP
$database->database_query("UPDATE se_friends SET friend_status='1' WHERE friend_user_id1='{$owner->user_info['user_id']}' AND friend_user_id2='{$user->user_info['user_id']}' AND friend_status='0'");
// INSERT ACTION
$actions->actions_add($owner, "addfriend", Array($owner->user_info['user_username'], $owner->user_displayname, $user->user_info['user_username'], $user->user_displayname), Array(), 0, false, "user", $owner->user_info['user_id'], $owner->user_info['user_privacy']);
// DELETE NOTIFICATION
$database->database_query("DELETE FROM se_notifys WHERE notify_user_id='{$user->user_info['user_id']}' AND notify_notifytype_id='1' AND notify_object_id='{$owner->user_info['user_id']}'");
// IF TWO-WAY CONNECTION, INSERT OTHER DIRECTION
if( $direction == 2 && !$user->user_friended($owner->user_info['user_id']) )
{
$user->user_friend_add($owner->user_info['user_id'], 1, $friend_type, $friend_explain);
$actions->actions_add($user, "addfriend", Array($user->user_info['user_username'], $user->user_displayname, $owner->user_info['user_username'], $owner->user_displayname), Array(), 0, false, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
$status = "remove";
$result = 879;
}
elseif( $user->user_friended($owner->user_info['user_id']) )
{
$status = "remove";
$result = 886;
}
else
{
$status = "add";
$result = 886;
}
if(SE_DEBUG){
// SEND FRIENDSHIP EMAIL
$owner->user_settings();
if( $owner->usersetting_info['usersetting_notify_friendrequest'] )
{
send_systememail('friendacceptsrequest', $owner->user_info['user_email'], Array($owner->user_displayname, $user->user_displayname, "<a href=\"".$url->url_base."login.php\">".$url->url_base."login.php</a>"));
}
}
}
// CREATING A NEW FRIENDSHIP
else
{
// CREATE FRIENDSHIP
$user->user_friend_add($owner->user_info['user_id'], $friend_status, $friend_type, $friend_explain);
// INSERT ACTION
if($friend_status == 1)
{
$actions->actions_add($user, "addfriend", Array($user->user_info['user_username'], $user->user_displayname, $owner->user_info['user_username'], $owner->user_displayname), Array(), 0, false, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
}
else
{
$notify->notify_add($owner->user_info['user_id'], 'friendrequest', $user->user_info['user_id']);
}
// IF TWO-WAY CONNECTION AND NON-CONFIRMED, INSERT OTHER DIRECTION AND ACTION
if( $direction == 2 && $friend_status == 1 && !$owner->user_friended($user->user_info['user_id']) )
{
$owner->user_friend_add($user->user_info['user_id'], $friend_status, '', '');
$actions->actions_add($owner, "addfriend", Array($owner->user_info['user_username'], $owner->user_displayname, $user->user_info['user_username'], $user->user_displayname), Array(), 0, false, "user", $owner->user_info['user_id'], $owner->user_info['user_privacy']);
}
// SEND FRIENDSHIP EMAIL
$owner->user_settings();
if( $owner->usersetting_info['usersetting_notify_friendrequest'] )
{
send_systememail('friendrequest', $owner->user_info['user_email'], Array($owner->user_displayname, $user->user_displayname, "<a href=\"".$url->url_base."login.php\">".$url->url_base."login.php</a>"));
}
}
// UPDATE STATS
update_stats("friends");
}}
else{
$owner = new SEUser(Array("",$_POST["friend"][0]));
$friend_type = $_POST['friend_type'];
$friend_type_other = censor($_POST['friend_type_other']);
$friend_explain = censor($_POST['friend_explain']);
if(count($connection_types) == 0) { $friend_type = ""; }
if($setting['setting_connection_other'] == 0) { $friend_type_other = ""; }
if($setting['setting_connection_explain'] == 0) { $friend_explain = ""; }
if($friend_type == "other_friendtype") { $friend_type = ""; }
if(trim($friend_type_other) != "") { $friend_type = $friend_type_other; }
// DETERMINE FRIENDSHIP FRAMEWORK
switch($setting['setting_connection_framework'])
{
case "0": $direction = 2; $friend_status = 0; $status = "pending"; $result = 878; break;
case "1": $direction = 1; $friend_status = 0; $status = "pending"; $result = 878; break;
case "2": $direction = 2; $friend_status = 1; $status = "remove"; $result = 879; break;
case "3": $direction = 1; $friend_status = 1; $status = "remove"; $result = 879; break;
}
// IF CONFIRMING AN EXISTING FRIEND REQUEST
if($owner->user_friended($user->user_info['user_id'], 0))
{
// CONFIRM FRIENDSHIP
$database->database_query("UPDATE se_friends SET friend_status='1' WHERE friend_user_id1='{$owner->user_info['user_id']}' AND friend_user_id2='{$user->user_info['user_id']}' AND friend_status='0'");
// INSERT ACTION
$actions->actions_add($owner, "addfriend", Array($owner->user_info['user_username'], $owner->user_displayname, $user->user_info['user_username'], $user->user_displayname), Array(), 0, false, "user", $owner->user_info['user_id'], $owner->user_info['user_privacy']);
// DELETE NOTIFICATION
$database->database_query("DELETE FROM se_notifys WHERE notify_user_id='{$user->user_info['user_id']}' AND notify_notifytype_id='1' AND notify_object_id='{$owner->user_info['user_id']}'");
// IF TWO-WAY CONNECTION, INSERT OTHER DIRECTION
if( $direction == 2 && !$user->user_friended($owner->user_info['user_id']) )
{
$user->user_friend_add($owner->user_info['user_id'], 1, $friend_type, $friend_explain);
$actions->actions_add($user, "addfriend", Array($user->user_info['user_username'], $user->user_displayname, $owner->user_info['user_username'], $owner->user_displayname), Array(), 0, false, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
$status = "remove";
$result = 879;
}
elseif( $user->user_friended($owner->user_info['user_id']) )
{
$status = "remove";
$result = 886;
}
else
{
$status = "add";
$result = 886;
}
}
// CREATING A NEW FRIENDSHIP
else
{
// CREATE FRIENDSHIP
$user->user_friend_add($owner->user_info['user_id'], $friend_status, $friend_type, $friend_explain);
// INSERT ACTION
if($friend_status == 1)
{
$actions->actions_add($user, "addfriend", Array($user->user_info['user_username'], $user->user_displayname, $owner->user_info['user_username'], $owner->user_displayname), Array(), 0, false, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
}
else
{
$notify->notify_add($owner->user_info['user_id'], 'friendrequest', $user->user_info['user_id']);
}
// IF TWO-WAY CONNECTION AND NON-CONFIRMED, INSERT OTHER DIRECTION AND ACTION
if( $direction == 2 && $friend_status == 1 && !$owner->user_friended($user->user_info['user_id']) )
{
$owner->user_friend_add($user->user_info['user_id'], $friend_status, '', '');
$actions->actions_add($owner, "addfriend", Array($owner->user_info['user_username'], $owner->user_displayname, $user->user_info['user_username'], $user->user_displayname), Array(), 0, false, "user", $owner->user_info['user_id'], $owner->user_info['user_privacy']);
}
// SEND FRIENDSHIP EMAIL
$owner->user_settings();
if( $owner->usersetting_info['usersetting_notify_friendrequest'] )
{
send_systememail('friendrequest', $owner->user_info['user_email'], Array($owner->user_displayname, $user->user_displayname, "<a href=\"".$url->url_base."login.php\">".$url->url_base."login.php</a>"));
}
}
// UPDATE STATS
update_stats("friends");
}
}
header("Location: user_friends_requests.php?p=$p");
exit;
// ASSIGN VARIABLES AND INCLUDE FOOTER
$smarty->assign('result', $result);
$smarty->assign('status', $status);
$smarty->assign('subpage', $subpage);
$smarty->assign('connection_types', $connection_types);
$smarty->assign('friend_type', $friend_type);
$smarty->assign('friend_type_other', $friend_type_other);
$smarty->assign('friend_explain', $friend_explain);
include "footer.php";
?>