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;
13 function manage_post(App $a) {
20 $orig_record = $a->user;
22 if(!empty($_SESSION['submanage'])) {
23 $user = DBA::selectFirst('user', [], ['uid' => $_SESSION['submanage']]);
24 if (DBA::isResult($user)) {
25 $uid = intval($user['uid']);
30 $identity = (!empty($_POST['identity']) ? intval($_POST['identity']) : 0);
38 $manage = DBA::select('manage', ['mid'], ['uid' => $uid]);
39 while ($m = DBA::fetch($manage)) {
40 if ($identity == $m['mid']) {
41 $limited_id = $m['mid'];
48 $user = DBA::selectFirst('user', [], ['uid' => $limited_id]);
50 // Check if the target user is one of our children
51 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
53 // Check if the target user is one of our siblings
54 if (!DBA::isResult($user) && ($orig_record['parent-uid'] != 0)) {
55 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
58 // Check if it's our parent
59 if (!DBA::isResult($user) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
60 $user = DBA::selectFirst('user', [], ['uid' => $identity]);
63 // Finally check if it's out own user
64 if (!DBA::isResult($user) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
65 $user = DBA::selectFirst('user', [], ['uid' => $identity]);
70 if (!DBA::isResult($user)) {
76 Session::setAuthenticatedForUser($a, $user, true, true);
79 $_SESSION['submanage'] = $original_id;
83 Hook::callAll('home_init', $ret);
85 $a->internalRedirect('profile/' . $a->user['nickname']);
89 function manage_content(App $a) {
92 notice(L10n::t('Permission denied.') . EOL);
96 if (!empty($_GET['identity'])) {
97 $_POST['identity'] = $_GET['identity'];
102 $identities = $a->identities;
104 //getting additinal information for each identity
105 foreach ($identities as $key => $id) {
106 $thumb = DBA::selectFirst('contact', ['thumb'], ['uid' => $id['uid'] , 'self' => true]);
107 if (!DBA::isResult($thumb)) {
111 $identities[$key]['thumb'] = $thumb['thumb'];
113 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
115 $condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $id['uid'], NOTIFY_INTRO, NOTIFY_MAIL];
116 $params = ['distinct' => true, 'expression' => 'parent'];
117 $notifications = DBA::count('notify', $condition, $params);
119 $params = ['distinct' => true, 'expression' => 'convid'];
120 $notifications += DBA::count('mail', ['uid' => $id['uid'], 'seen' => false], $params);
122 $notifications += DBA::count('intro', ['blocked' => false, 'ignore' => false, 'uid' => $id['uid']]);
124 $identities[$key]['notifications'] = $notifications;
127 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('manage.tpl'), [
128 '$title' => L10n::t('Manage Identities and/or Pages'),
129 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
130 '$choose' => L10n::t('Select an identity to manage: '),
131 '$identities' => $identities,
132 '$submit' => L10n::t('Submit'),