]> git.mxchange.org Git - friendica.git/blob - mod/manage.php
added spaces + some curly braces + some usage of dbm::is_result()
[friendica.git] / mod / manage.php
1 <?php
2
3 require_once("include/text.php");
4
5
6 function manage_post(App $a) {
7
8         if (! local_user()) {
9                 return;
10         }
11
12         $uid = local_user();
13         $orig_record = $a->user;
14
15         if ((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
16                 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
17                         intval($_SESSION['submanage'])
18                 );
19                 if (dbm::is_result($r)) {
20                         $uid = intval($r[0]['uid']);
21                         $orig_record = $r[0];
22                 }
23         }
24
25         $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
26                 intval($uid)
27         );
28
29         $submanage = $r;
30
31         $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0);
32         if (! $identity) {
33                 return;
34         }
35
36         $limited_id = 0;
37         $original_id = $uid;
38
39         if (count($submanage)) {
40                 foreach ($submanage as $m) {
41                         if ($identity == $m['mid']) {
42                                 $limited_id = $m['mid'];
43                                 break;
44                         }
45                 }
46         }
47
48         if ($limited_id) {
49                 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
50                         intval($limited_id)
51                 );
52         } else {
53                 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1",
54                         intval($identity),
55                         dbesc($orig_record['email']),
56                         dbesc($orig_record['password'])
57                 );
58         }
59
60         if (! dbm::is_result($r)) {
61                 return;
62         }
63
64         unset($_SESSION['authenticated']);
65         unset($_SESSION['uid']);
66         unset($_SESSION['visitor_id']);
67         unset($_SESSION['administrator']);
68         unset($_SESSION['cid']);
69         unset($_SESSION['theme']);
70         unset($_SESSION['mobile-theme']);
71         unset($_SESSION['page_flags']);
72         unset($_SESSION['return_url']);
73         if (x($_SESSION,'submanage')) {
74                 unset($_SESSION['submanage']);
75         }
76         if (x($_SESSION,'sysmsg')) {
77                 unset($_SESSION['sysmsg']);
78         }
79         if (x($_SESSION,'sysmsg_info')) {
80                 unset($_SESSION['sysmsg_info']);
81         }
82
83         require_once('include/security.php');
84         authenticate_success($r[0],true,true);
85
86         if ($limited_id) {
87                 $_SESSION['submanage'] = $original_id;
88         }
89
90         $ret = array();
91         call_hooks('home_init',$ret);
92
93         goaway( App::get_baseurl() . "/profile/" . $a->user['nickname'] );
94         // NOTREACHED
95 }
96
97
98
99 function manage_content(App $a) {
100
101         if (! local_user()) {
102                 notice( t('Permission denied.') . EOL);
103                 return;
104         }
105
106         if ($_GET['identity']) {
107                 $_POST['identity'] = $_GET['identity'];
108                 manage_post($a);
109                 return;
110         }
111
112         $identities = $a->identities;
113
114         //getting additinal information for each identity
115         foreach ($identities as $key=>$id) {
116                 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
117                         dbesc($id['uid'])
118                 );
119
120                 $identities[$key][thumb] = $thumb[0][thumb];
121
122                 $identities[$key]['selected'] = (($id['nickname'] === $a->user['nickname']) ? true : false);
123
124                 $notifications = 0;
125
126                 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
127                         intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
128                 if ($r)
129                         $notifications = sizeof($r);
130
131                 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
132                         intval($id['uid']));
133                 if ($r)
134                         $notifications = $notifications + sizeof($r);
135
136                 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
137                         intval($id['uid']));
138                 if ($r)
139                         $notifications = $notifications + $r[0]["introductions"];
140
141                 $identities[$key]['notifications'] = $notifications;
142         }
143
144         $o = replace_macros(get_markup_template('manage.tpl'), array(
145                 '$title' => t('Manage Identities and/or Pages'),
146                 '$desc' => t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
147                 '$choose' => t('Select an identity to manage: '),
148                 '$identities' => $identities,
149                 '$submit' => t('Submit'),
150         ));
151
152         return $o;
153
154 }