6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
11 require_once "include/text.php";
13 function manage_post(App $a) {
20 $orig_record = $a->user;
22 if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
23 $r = q("select * from user where uid = %d limit 1",
24 intval($_SESSION['submanage'])
26 if (DBM::is_result($r)) {
27 $uid = intval($r[0]['uid']);
32 $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
38 $identity = (x($_POST['identity']) ? intval($_POST['identity']) : 0);
46 if (DBM::is_result($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 dbesc($orig_record['uid'])
66 // Check if the target user is one of our siblings
67 if (!DBM::is_result($r) && ($orig_record['parent-uid'] != 0)) {
68 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
70 dbesc($orig_record['parent-uid'])
74 // Check if it's our parent
75 if (!DBM::is_result($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 (!DBM::is_result($r) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
83 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
89 if (!DBM::is_result($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_url']);
102 if (x($_SESSION, 'submanage')) {
103 unset($_SESSION['submanage']);
105 if (x($_SESSION, 'sysmsg')) {
106 unset($_SESSION['sysmsg']);
108 if (x($_SESSION, 'sysmsg_info')) {
109 unset($_SESSION['sysmsg_info']);
112 require_once('include/security.php');
113 authenticate_success($r[0], true, true);
116 $_SESSION['submanage'] = $original_id;
120 Addon::callHooks('home_init',$ret);
122 goaway( System::baseUrl() . "/profile/" . $a->user['nickname'] );
128 function manage_content(App $a) {
130 if (! local_user()) {
131 notice(L10n::t('Permission denied.') . EOL);
135 if ($_GET['identity']) {
136 $_POST['identity'] = $_GET['identity'];
141 $identities = $a->identities;
143 //getting additinal information for each identity
144 foreach ($identities as $key=>$id) {
145 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
149 $identities[$key]['thumb'] = $thumb[0]['thumb'];
151 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
155 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
156 intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
158 if (DBM::is_result($r)) {
159 $notifications = sizeof($r);
162 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
165 if (DBM::is_result($r)) {
166 $notifications = $notifications + sizeof($r);
169 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
172 if (DBM::is_result($r)) {
173 $notifications = $notifications + $r[0]["introductions"];
176 $identities[$key]['notifications'] = $notifications;
179 $o = replace_macros(get_markup_template('manage.tpl'), [
180 '$title' => L10n::t('Manage Identities and/or Pages'),
181 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
182 '$choose' => L10n::t('Select an identity to manage: '),
183 '$identities' => $identities,
184 '$submit' => L10n::t('Submit'),