3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Hook;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Session;
9 use Friendica\Database\DBA;
11 use Friendica\Model\Contact;
12 use Friendica\Model\User;
13 use Friendica\Network\HTTPException\ForbiddenException;
16 * Switches current user between delegates/parent user
18 class Delegation extends BaseModule
20 public static function post(array $parameters = [])
27 $orig_record = DI::app()->user;
29 if (Session::get('submanage')) {
30 $user = User::getById(Session::get('submanage'));
31 if (DBA::isResult($user)) {
32 $uid = intval($user['uid']);
37 $identity = intval($_POST['identity'] ?? 0);
45 $manages = DBA::selectToArray('manage', ['mid'], ['uid' => $uid]);
46 foreach ($manages as $manage) {
47 if ($identity == $manage['mid']) {
48 $limited_id = $manage['mid'];
54 $user = User::getById($limited_id);
56 // Check if the target user is one of our children
57 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
59 // Check if the target user is one of our siblings
60 if (!DBA::isResult($user) && ($orig_record['parent-uid'] != 0)) {
61 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
64 // Check if it's our parent or our own user
65 if (!DBA::isResult($user)
67 $orig_record['parent-uid'] != 0 && $orig_record['parent-uid'] == $identity
69 $orig_record['uid'] != 0 && $orig_record['uid'] == $identity
72 $user = User::getById($identity);
76 if (!DBA::isResult($user)) {
82 DI::auth()->setForUser(DI::app(), $user, true, true);
85 Session::set('submanage', $original_id);
89 Hook::callAll('home_init', $ret);
91 DI::baseUrl()->redirect('profile/' . DI::app()->user['nickname']);
95 public static function content(array $parameters = [])
98 throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
101 $identities = DI::app()->identities;
103 //getting additinal information for each identity
104 foreach ($identities as $key => $identity) {
105 $thumb = Contact::selectFirst(['thumb'], ['uid' => $identity['uid'], 'self' => true]);
106 if (!DBA::isResult($thumb)) {
110 $identities[$key]['thumb'] = $thumb['thumb'];
112 $identities[$key]['selected'] = ($identity['nickname'] === DI::app()->user['nickname']);
114 $condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $identity['uid'], NOTIFY_INTRO, NOTIFY_MAIL];
115 $params = ['distinct' => true, 'expression' => 'parent'];
116 $notifications = DBA::count('notify', $condition, $params);
118 $params = ['distinct' => true, 'expression' => 'convid'];
119 $notifications += DBA::count('mail', ['uid' => $identity['uid'], 'seen' => false], $params);
121 $notifications += DBA::count('intro', ['blocked' => false, 'ignore' => false, 'uid' => $identity['uid']]);
123 $identities[$key]['notifications'] = $notifications;
126 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('delegation.tpl'), [
127 '$title' => DI::l10n()->t('Manage Identities and/or Pages'),
128 '$desc' => DI::l10n()->t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
129 '$choose' => DI::l10n()->t('Select an identity to manage: '),
130 '$identities' => $identities,
131 '$submit' => DI::l10n()->t('Submit'),