tiki-friends.php 4.7 KB
Newer Older
lfagundes's avatar
lfagundes committed
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3 4 5 6 7
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

lfagundes's avatar
lfagundes committed
8 9 10
require_once('tiki-setup.php');
include_once('lib/messu/messulib.php');

11
$access->check_user($user);
12
$access->check_feature('feature_friends');
lfagundes's avatar
lfagundes committed
13

14
// TODO: all messages should be translated to receiver language, not sender.
lfagundes's avatar
lfagundes committed
15
if (isset($_REQUEST['request_friendship'])) {
16
    $friend = $_REQUEST['request_friendship'];
17
    
18 19 20
    if ($userlib->user_exists($friend)) {
	if (!$tikilib->verify_friendship($friend,$user)) {
	    $userlib->request_friendship($user,$friend);
21
	    $lg = $tikilib->get_user_preference($friend, "language", $prefs['site_language']);
22
	    $smarty->assign('msg',sprintf(tra("Friendship request sent to %s"), $friend));
23
	    $foo = parse_url($_SERVER["REQUEST_URI"]);
24
	    $machine = $tikilib->httpPrefix( true ). $foo["path"];
25 26 27 28
	    $smarty->assign('server_name',$machine);
	    $messulib->post_message($friend, $user, $friend, '', 
				    $smarty->fetchLang($lg,'mail/new_friend_invitation_subject.tpl'),
				    $smarty->fetchLang($lg,'mail/new_friend_invitation.tpl'),
29 30
				    3);

31 32 33 34 35
	} else {
	    $smarty->assign('msg',sprintf(tra("You're already friend of %s"), $_REQUEST['request_friendship']));
	    $smarty->display("error.tpl");
	    die;
	}
lfagundes's avatar
lfagundes committed
36
    } else {
37 38 39
	$smarty->assign('msg',tra("Invalid username"));
	    $smarty->display("error.tpl");
	    die;
lfagundes's avatar
lfagundes committed
40 41
    }

42
} elseif (isset($_REQUEST['accept'])) {
43 44
    $friend = $_REQUEST['accept'];
    $userlib->accept_friendship($user,$friend);
45
    $lg = $tikilib->get_user_preference($friend, "language", $prefs['site_language']);
46 47 48
    $smarty->assign('msg', sprintf(tra('Accepted friendship request from %s'),$friend));

    $messulib->post_message($friend, $user, $friend, '',
49
			    tra("I have accepted your friendship request!", $lg),
50 51 52
			    '', // Do we need a message?
			    3);

lfagundes's avatar
lfagundes committed
53

54
} elseif (isset($_REQUEST['refuse'])) {
55 56
    $friend = $_REQUEST['refuse'];
    $userlib->refuse_friendship($user, $friend);
57
    $lg = $tikilib->get_user_preference($friend, "language", $prefs['site_language']);
58 59 60 61 62
    $smarty->assign('msg', sprintf(tra('Refused friendship request from %s'),$friend));

    // Should we send a message, or that would intimidate refusing friendships?
    // TODO: make it optional
    $messulib->post_message($friend, $user, $friend, '',
63
			    tra("I have refused your friendship request.", $lg),
64 65 66
			    '',
			    3);

67 68 69 70 71
}elseif (isset($_REQUEST['cancel_waiting_friendship'])) {
    $friend = $_REQUEST['cancel_waiting_friendship'];
    $userlib->refuse_friendship($friend, $user);
    $lg = $tikilib->get_user_preference($friend, "language", $prefs['site_language']);
    $smarty->assign('msg', sprintf(tra('Canceled friendship request with %s'),$friend));
72

73 74 75 76 77 78 79
    // Should we send a message, or that would intimidate refusing friendships?
    // TODO: make it optional
    $messulib->post_message($friend, $user, $friend, '',
			    tra("I have canceled my friendship request.", $lg),
			    '',
			    3);
			    
80 81 82
} elseif (isset($_REQUEST['break'])) { 
    $friend = $_REQUEST['break'];
    $userlib->break_friendship($user, $friend);
83
    $lg = $tikilib->get_user_preference($friend, "language", $prefs['site_language']);
84 85 86 87 88
    $smarty->assign('msg', sprintf(tra('Broke friendship with %s'),$friend));
    
    // Should we send a message, or that would intimidate user?
    // TODO: make it optional
    $messulib->post_message($friend, $user, $friend, '',
89
			    tra('I have broken our friendship!', $lg),
90 91 92
			    '',
			    3);

lfagundes's avatar
lfagundes committed
93 94 95
}

if(!isset($_REQUEST["sort_mode"])) {
96
  $sort_mode = $prefs['user_list_order'];
lfagundes's avatar
lfagundes committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
} else {
  $sort_mode = $_REQUEST["sort_mode"];
} 

$smarty->assign_by_ref('sort_mode',$sort_mode);

// If offset is set use it if not then use offset =0
// use the maxRecords php variable to set the limit
// if sortMode is not set then use lastModif_desc
if(!isset($_REQUEST["offset"])) {
  $offset = 0;
} else {
  $offset = $_REQUEST["offset"]; 
}
$smarty->assign_by_ref('offset',$offset);

if(isset($_REQUEST["find"])) {
  $find = $_REQUEST["find"];  
} else {
  $find = ''; 
}
$smarty->assign('find',$find);

$smarty->assign('pending_requests',$userlib->list_pending_friendship_requests($user));
$smarty->assign('waiting_requests',$userlib->list_waiting_friendship_requests($user));

$listpages = $tikilib->list_user_friends($user,$offset,$maxRecords,$sort_mode,$find);

125
$smarty->assign_by_ref('cant_pages', $listpages["cant"]);
lfagundes's avatar
lfagundes committed
126 127 128 129 130 131 132 133 134

$smarty->assign_by_ref('listpages',$listpages["data"]);

$section='friends';
include_once('tiki-section_options.php');

// Display the template
$smarty->assign('mid','tiki-friends.tpl');
$smarty->display("tiki.tpl");