3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Authentication;
7 use Friendica\Core\Hook;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Session;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\User;
14 use Friendica\Network\HTTPException\ForbiddenException;
17 * Switches current user between delegates/parent user
19 class Delegation extends BaseModule
21 public static function post(array $parameters = [])
28 $orig_record = self::getApp()->user;
30 if (Session::get('submanage')) {
31 $user = User::getById(Session::get('submanage'));
32 if (DBA::isResult($user)) {
33 $uid = intval($user['uid']);
38 $identity = intval($_POST['identity'] ?? 0);
46 $manages = DBA::selectToArray('manage', ['mid'], ['uid' => $uid]);
47 foreach ($manages as $manage) {
48 if ($identity == $manage['mid']) {
49 $limited_id = $manage['mid'];
55 $user = User::getById($limited_id);
57 // Check if the target user is one of our children
58 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
60 // Check if the target user is one of our siblings
61 if (!DBA::isResult($user) && ($orig_record['parent-uid'] != 0)) {
62 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
65 // Check if it's our parent or our own user
66 if (!DBA::isResult($user)
68 $orig_record['parent-uid'] != 0 && $orig_record['parent-uid'] == $identity
70 $orig_record['uid'] != 0 && $orig_record['uid'] == $identity
73 $user = User::getById($identity);
77 if (!DBA::isResult($user)) {
83 /** @var Authentication $authentication */
84 $authentication = self::getClass(Authentication::class);
85 $authentication->setForUser(self::getApp(), $user, true, true);
88 Session::set('submanage', $original_id);
92 Hook::callAll('home_init', $ret);
94 self::getApp()->internalRedirect('profile/' . self::getApp()->user['nickname']);
98 public static function content(array $parameters = [])
101 throw new ForbiddenException(L10n::t('Permission denied.'));
104 $identities = self::getApp()->identities;
106 //getting additinal information for each identity
107 foreach ($identities as $key => $identity) {
108 $thumb = Contact::selectFirst(['thumb'], ['uid' => $identity['uid'], 'self' => true]);
109 if (!DBA::isResult($thumb)) {
113 $identities[$key]['thumb'] = $thumb['thumb'];
115 $identities[$key]['selected'] = ($identity['nickname'] === self::getApp()->user['nickname']);
117 $condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $identity['uid'], NOTIFY_INTRO, NOTIFY_MAIL];
118 $params = ['distinct' => true, 'expression' => 'parent'];
119 $notifications = DBA::count('notify', $condition, $params);
121 $params = ['distinct' => true, 'expression' => 'convid'];
122 $notifications += DBA::count('mail', ['uid' => $identity['uid'], 'seen' => false], $params);
124 $notifications += DBA::count('intro', ['blocked' => false, 'ignore' => false, 'uid' => $identity['uid']]);
126 $identities[$key]['notifications'] = $notifications;
129 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('delegation.tpl'), [
130 '$title' => L10n::t('Manage Identities and/or Pages'),
131 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
132 '$choose' => L10n::t('Select an identity to manage: '),
133 '$identities' => $identities,
134 '$submit' => L10n::t('Submit'),