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 $r = q("select * from user where uid = %d limit 1",
24 intval($_SESSION['submanage'])
26 if (DBA::isResult($r)) {
27 $uid = intval($r[0]['uid']);
32 $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
38 $identity = (!empty($_POST['identity']) ? intval($_POST['identity']) : 0);
46 if (DBA::isResult($submanage)) {
47 foreach ($submanage as $m) {
48 if ($identity == $m['mid']) {
49 $limited_id = $m['mid'];
56 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
60 // Check if the target user is one of our children
61 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
63 DBA::escape($orig_record['uid'])
66 // Check if the target user is one of our siblings
67 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0)) {
68 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
70 DBA::escape($orig_record['parent-uid'])
74 // Check if it's our parent
75 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
76 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
81 // Finally check if it's out own user
82 if (!DBA::isResult($r) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
83 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
89 if (!DBA::isResult($r)) {
93 unset($_SESSION['authenticated']);
94 unset($_SESSION['uid']);
95 unset($_SESSION['visitor_id']);
96 unset($_SESSION['administrator']);
97 unset($_SESSION['cid']);
98 unset($_SESSION['theme']);
99 unset($_SESSION['mobile-theme']);
100 unset($_SESSION['page_flags']);
101 unset($_SESSION['return_path']);
102 if (!empty($_SESSION['submanage'])) {
103 unset($_SESSION['submanage']);
105 if (!empty($_SESSION['sysmsg'])) {
106 unset($_SESSION['sysmsg']);
108 if (!empty($_SESSION['sysmsg_info'])) {
109 unset($_SESSION['sysmsg_info']);
112 Session::setAuthenticatedForUser($a, $r[0], true, true);
115 $_SESSION['submanage'] = $original_id;
119 Hook::callAll('home_init',$ret);
121 $a->internalRedirect('profile/' . $a->user['nickname'] );
127 function manage_content(App $a) {
129 if (! local_user()) {
130 notice(L10n::t('Permission denied.') . EOL);
134 if (!empty($_GET['identity'])) {
135 $_POST['identity'] = $_GET['identity'];
140 $identities = $a->identities;
142 //getting additinal information for each identity
143 foreach ($identities as $key=>$id) {
144 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
145 DBA::escape($id['uid'])
148 $identities[$key]['thumb'] = $thumb[0]['thumb'];
150 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
154 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
155 intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
157 if (DBA::isResult($r)) {
158 $notifications = sizeof($r);
161 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
164 if (DBA::isResult($r)) {
165 $notifications = $notifications + sizeof($r);
168 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
171 if (DBA::isResult($r)) {
172 $notifications = $notifications + $r[0]["introductions"];
175 $identities[$key]['notifications'] = $notifications;
178 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('manage.tpl'), [
179 '$title' => L10n::t('Manage Identities and/or Pages'),
180 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
181 '$choose' => L10n::t('Select an identity to manage: '),
182 '$identities' => $identities,
183 '$submit' => L10n::t('Submit'),