]> git.mxchange.org Git - friendica.git/blob - mod/manage.php
Some Bugfixes, and variable checks
[friendica.git] / mod / manage.php
1 <?php
2
3
4 function manage_post(&$a) {
5
6         if(! local_user())
7                 return;
8
9         $uid = local_user();
10         $orig_record = $a->user;
11
12         if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
13                 $r = q("select * from user where uid = %d limit 1",
14                         intval($_SESSION['submanage'])
15                 );
16                 if(count($r)) {
17                         $uid = intval($r[0]['uid']);
18                         $orig_record = $r[0];
19                 }
20         }
21
22         $r = q("select * from manage where uid = %d",
23                 intval($uid)
24         );
25
26         $submanage = $r;
27
28         $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0);
29         if(! $identity)
30                 return;
31
32         $limited_id = 0;
33         $original_id = $uid;
34
35         if(count($submanage)) {
36                 foreach($submanage as $m) {
37                         if($identity == $m['mid']) {
38                                 $limited_id = $m['mid'];
39                                 break;
40                         }
41                 }
42         }
43
44         if($limited_id) {
45                 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
46                         intval($limited_id)
47                 );
48         }
49         else {
50                 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1",
51                         intval($identity),
52                         dbesc($orig_record['email']),
53                         dbesc($orig_record['password'])
54                 );
55         }
56
57         if(! count($r))
58                 return;
59
60         unset($_SESSION['authenticated']);
61         unset($_SESSION['uid']);
62         unset($_SESSION['visitor_id']);
63         unset($_SESSION['administrator']);
64         unset($_SESSION['cid']);
65         unset($_SESSION['theme']);
66         unset($_SESSION['page_flags']);
67         unset($_SESSION['return_url']);
68         if(x($_SESSION,'submanage'))
69                 unset($_SESSION['submanage']);
70
71         require_once('include/security.php');
72         authenticate_success($r[0],true,true);
73
74         if($limited_id)
75                 $_SESSION['submanage'] = $original_id;
76
77         goaway($a->get_baseurl(true) . '/profile/' . $a->user['nickname']);
78         // NOTREACHED
79 }
80
81
82
83 function manage_content(&$a) {
84
85         if(! local_user()) {
86                 notice( t('Permission denied.') . EOL);
87                 return;
88         }
89
90         $o = '<h3>' . t('Manage Identities and/or Pages') . '</h3>';
91
92         
93         $o .= '<div id="identity-manage-desc">' . t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions') . '</div>';
94
95         $o .= '<div id="identity-manage-choose">' . t('Select an identity to manage: ') . '</div>';
96
97         $o .= '<div id="identity-selector-wrapper">' . "\r\n";
98         $o .= '<form action="manage" method="post" >' . "\r\n";
99         $o .= '<select name="identity" size="4">' . "\r\n";
100
101         foreach($a->identities as $rr) {
102                 $selected = (($rr['nickname'] === $a->user['nickname']) ? ' selected="selected" ' : '');
103                 $o .= '<option ' . $selected . 'value="' . $rr['uid'] . '">' . $rr['username'] . ' (' . $rr['nickname'] . ')</option>' . "\r\n";
104         }
105
106         $o .= '</select>' . "\r\n";
107         $o .= '<div id="identity-select-break"></div>' . "\r\n";
108
109         $o .= '<input id="identity-submit" type="submit" name="submit" value="' . t('Submit') . '" /></div></form>' . "\r\n";
110
111         return $o;
112
113 }