]> git.mxchange.org Git - friendica.git/blob - mod/manage.php
Merge remote branch 'upstream/master'
[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['mobile-theme']);
67         unset($_SESSION['page_flags']);
68         unset($_SESSION['return_url']);
69         if(x($_SESSION,'submanage'))
70                 unset($_SESSION['submanage']);
71
72         require_once('include/security.php');
73         authenticate_success($r[0],true,true);
74
75         if($limited_id)
76                 $_SESSION['submanage'] = $original_id;
77
78         goaway($a->get_baseurl(true) . '/profile/' . $a->user['nickname']);
79         // NOTREACHED
80 }
81
82
83
84 function manage_content(&$a) {
85
86         if(! local_user()) {
87                 notice( t('Permission denied.') . EOL);
88                 return;
89         }
90
91         $o = '<h3>' . t('Manage Identities and/or Pages') . '</h3>';
92
93         
94         $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>';
95
96         $o .= '<div id="identity-manage-choose">' . t('Select an identity to manage: ') . '</div>';
97
98         $o .= '<div id="identity-selector-wrapper">' . "\r\n";
99         $o .= '<form action="manage" method="post" >' . "\r\n";
100         $o .= '<select name="identity" size="4" onchange="this.form.submit();" >' . "\r\n";
101
102         foreach($a->identities as $rr) {
103                 $selected = (($rr['nickname'] === $a->user['nickname']) ? ' selected="selected" ' : '');
104                 $o .= '<option ' . $selected . 'value="' . $rr['uid'] . '">' . $rr['username'] . ' (' . $rr['nickname'] . ')</option>' . "\r\n";
105         }
106
107         $o .= '</select>' . "\r\n";
108         $o .= '<div id="identity-select-break"></div>' . "\r\n";
109
110 //      $o .= '<input id="identity-submit" type="submit" name="submit" value="' . t('Submit') . '" />';
111         $o .= '</div></form>' . "\r\n";
112
113         return $o;
114
115 }