6 use Friendica\Core\Authentication;
7 use Friendica\Core\Addon;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
13 require_once "include/text.php";
15 function manage_post(App $a) {
22 $orig_record = $a->user;
24 if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
25 $r = q("select * from user where uid = %d limit 1",
26 intval($_SESSION['submanage'])
28 if (DBA::isResult($r)) {
29 $uid = intval($r[0]['uid']);
34 $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
40 $identity = (x($_POST['identity']) ? intval($_POST['identity']) : 0);
48 if (DBA::isResult($submanage)) {
49 foreach ($submanage as $m) {
50 if ($identity == $m['mid']) {
51 $limited_id = $m['mid'];
58 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
62 // Check if the target user is one of our children
63 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
65 DBA::escape($orig_record['uid'])
68 // Check if the target user is one of our siblings
69 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0)) {
70 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
72 DBA::escape($orig_record['parent-uid'])
76 // Check if it's our parent
77 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
78 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
83 // Finally check if it's out own user
84 if (!DBA::isResult($r) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
85 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
91 if (!DBA::isResult($r)) {
95 unset($_SESSION['authenticated']);
96 unset($_SESSION['uid']);
97 unset($_SESSION['visitor_id']);
98 unset($_SESSION['administrator']);
99 unset($_SESSION['cid']);
100 unset($_SESSION['theme']);
101 unset($_SESSION['mobile-theme']);
102 unset($_SESSION['page_flags']);
103 unset($_SESSION['return_path']);
104 if (x($_SESSION, 'submanage')) {
105 unset($_SESSION['submanage']);
107 if (x($_SESSION, 'sysmsg')) {
108 unset($_SESSION['sysmsg']);
110 if (x($_SESSION, 'sysmsg_info')) {
111 unset($_SESSION['sysmsg_info']);
114 Authentication::setAuthenticatedSessionForUser($r[0], true, true);
117 $_SESSION['submanage'] = $original_id;
121 Addon::callHooks('home_init',$ret);
123 $a->internalRedirect('profile/' . $a->user['nickname'] );
129 function manage_content(App $a) {
131 if (! local_user()) {
132 notice(L10n::t('Permission denied.') . EOL);
136 if (!empty($_GET['identity'])) {
137 $_POST['identity'] = $_GET['identity'];
142 $identities = $a->identities;
144 //getting additinal information for each identity
145 foreach ($identities as $key=>$id) {
146 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
147 DBA::escape($id['uid'])
150 $identities[$key]['thumb'] = $thumb[0]['thumb'];
152 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
156 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
157 intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
159 if (DBA::isResult($r)) {
160 $notifications = sizeof($r);
163 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
166 if (DBA::isResult($r)) {
167 $notifications = $notifications + sizeof($r);
170 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
173 if (DBA::isResult($r)) {
174 $notifications = $notifications + $r[0]["introductions"];
177 $identities[$key]['notifications'] = $notifications;
180 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('manage.tpl'), [
181 '$title' => L10n::t('Manage Identities and/or Pages'),
182 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
183 '$choose' => L10n::t('Select an identity to manage: '),
184 '$identities' => $identities,
185 '$submit' => L10n::t('Submit'),