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