6 use Friendica\Core\Authentication;
7 use Friendica\Core\Hook;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Database\DBA;
12 function manage_post(App $a) {
19 $orig_record = $a->user;
21 if(!empty($_SESSION['submanage'])) {
22 $r = q("select * from user where uid = %d limit 1",
23 intval($_SESSION['submanage'])
25 if (DBA::isResult($r)) {
26 $uid = intval($r[0]['uid']);
31 $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
37 $identity = (!empty($_POST['identity']) ? intval($_POST['identity']) : 0);
45 if (DBA::isResult($submanage)) {
46 foreach ($submanage as $m) {
47 if ($identity == $m['mid']) {
48 $limited_id = $m['mid'];
55 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
59 // Check if the target user is one of our children
60 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
62 DBA::escape($orig_record['uid'])
65 // Check if the target user is one of our siblings
66 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0)) {
67 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
69 DBA::escape($orig_record['parent-uid'])
73 // Check if it's our parent
74 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
75 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
80 // Finally check if it's out own user
81 if (!DBA::isResult($r) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
82 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
88 if (!DBA::isResult($r)) {
92 unset($_SESSION['authenticated']);
93 unset($_SESSION['uid']);
94 unset($_SESSION['visitor_id']);
95 unset($_SESSION['administrator']);
96 unset($_SESSION['cid']);
97 unset($_SESSION['theme']);
98 unset($_SESSION['mobile-theme']);
99 unset($_SESSION['page_flags']);
100 unset($_SESSION['return_path']);
101 if (!empty($_SESSION['submanage'])) {
102 unset($_SESSION['submanage']);
104 if (!empty($_SESSION['sysmsg'])) {
105 unset($_SESSION['sysmsg']);
107 if (!empty($_SESSION['sysmsg_info'])) {
108 unset($_SESSION['sysmsg_info']);
111 Authentication::setAuthenticatedSessionForUser($r[0], true, true);
114 $_SESSION['submanage'] = $original_id;
118 Hook::callAll('home_init',$ret);
120 $a->internalRedirect('profile/' . $a->user['nickname'] );
126 function manage_content(App $a) {
128 if (! local_user()) {
129 notice(L10n::t('Permission denied.') . EOL);
133 if (!empty($_GET['identity'])) {
134 $_POST['identity'] = $_GET['identity'];
139 $identities = $a->identities;
141 //getting additinal information for each identity
142 foreach ($identities as $key=>$id) {
143 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
144 DBA::escape($id['uid'])
147 $identities[$key]['thumb'] = $thumb[0]['thumb'];
149 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
153 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
154 intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
156 if (DBA::isResult($r)) {
157 $notifications = sizeof($r);
160 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
163 if (DBA::isResult($r)) {
164 $notifications = $notifications + sizeof($r);
167 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
170 if (DBA::isResult($r)) {
171 $notifications = $notifications + $r[0]["introductions"];
174 $identities[$key]['notifications'] = $notifications;
177 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('manage.tpl'), [
178 '$title' => L10n::t('Manage Identities and/or Pages'),
179 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
180 '$choose' => L10n::t('Select an identity to manage: '),
181 '$identities' => $identities,
182 '$submit' => L10n::t('Submit'),