96649f21ba18d07757afa9d98998f7a22c0d86a3
bernd Su-Login für Admins

bernd authored 17 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd Su-Login für Admins

bernd authored 17 years ago

16) 
17) function list_system_users()
18) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

19)     require_role(ROLE_SYSADMIN);
bernd Su-Login für Admins

bernd authored 17 years ago

20) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

21)     $result = db_query("SELECT uid,username FROM system.v_useraccounts ORDER BY username");
Hanno remove whitespace in empty...

Hanno authored 6 years ago

22) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

23)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

24)     while ($item = $result->fetch(PDO::FETCH_OBJ)) {
25)         array_push($ret, $item);
26)     }
27)     return $ret;
bernd Su-Login für Admins

bernd authored 17 years ago

28) }
29) 
30) 
31) function list_customers()
32) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

33)     require_role(ROLE_SYSADMIN);
bernd Su-Login für Admins

bernd authored 17 years ago

34) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

35)     $result = db_query("SELECT id, IF(firma IS NULL, CONCAT_WS(' ', vorname, nachname), CONCAT(firma, ' (', CONCAT_WS(' ', vorname, nachname), ')')) AS name FROM kundendaten.kunden");
Hanno remove whitespace in empty...

Hanno authored 6 years ago

36) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

37)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

38)     while ($item = $result->fetch(PDO::FETCH_OBJ)) {
39)         array_push($ret, $item);
40)     }
41)     return $ret;
bernd Su-Login für Admins

bernd authored 17 years ago

42) }
43) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

44) function customer_details($id)
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

45) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

46)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

47)     $result = db_query("SELECT id, IF(firma IS NULL, CONCAT_WS(' ', vorname, nachname), CONCAT(firma, ' (', CONCAT_WS(' ', vorname, nachname), ')')) AS name FROM kundendaten.kunden WHERE id=?", [$id]);
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

48)     if ($result->rowCount() < 1) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

49)         return null;
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

50)     }
51)     $kunde = $result->fetch();
52)     return $kunde;
53) }
54) 
bernd Su-Login für Admins

bernd authored 17 years ago

55) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

56) function find_customers($string)
bernd AJAXified

bernd authored 16 years ago

57) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

58)     $args = [":string" => '%'.chop($string).'%', ":number" => $string];
59)     $return = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

60)     $result = db_query("SELECT k.id FROM kundendaten.kunden AS k LEFT JOIN system.useraccounts AS u ON (k.id=u.kunde) WHERE ".
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

61)                      "firma LIKE :string OR firma2 LIKE :string OR ".
62)                      "nachname LIKE :string OR vorname LIKE :string OR ".
63)                      "adresse LIKE :string OR adresse2 LIKE :string OR ".
64)                      "ort LIKE :string OR pgp_id LIKE :string OR ".
65)                      "notizen LIKE :string OR email_rechnung LIKE :string OR ".
66)                      "email LIKE :string OR email_extern LIKE :string OR u.name LIKE :string OR ".
67)                      "u.username LIKE :string OR k.id=:number OR u.uid=:number", $args);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

68)     while ($entry = $result->fetch()) {
69)         $return[] = $entry['id'];
70)     }
bernd AJAXified

bernd authored 16 years ago

71) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

72)     unset($args[':number']);
73)     $result = db_query("SELECT kunde FROM kundendaten.domains WHERE kunde IS NOT NULL AND (
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

74)                       domainname LIKE :string OR CONCAT_WS('.', domainname, tld) LIKE :string
75)                       )", $args);
bernd Finde Kunden auch anhand vo...

bernd authored 15 years ago

76) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

77)     while ($entry = $result->fetch()) {
78)         $return[] = $entry['kunde'];
79)     }
bernd Finde Kunden auch anhand vo...

bernd authored 15 years ago

80) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

81)     return $return;
bernd AJAXified

bernd authored 16 years ago

82) }
83) 
84) 
85) function find_users_for_customer($id)
86) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

87)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

88)     $return = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

89)     $result = db_query("SELECT uid, username, name FROM system.useraccounts WHERE ".
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

90)                      "kunde=?", [$id]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

91)     while ($entry = $result->fetch()) {
92)         $return[] = $entry;
93)     }
bernd AJAXified

bernd authored 16 years ago

94) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

95)     return $return;
bernd AJAXified

bernd authored 16 years ago

96) }
97) 
98) 
99) 
100) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

101) function build_results($term)
102) {
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

103)     global $ret;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

104)     $ret = [];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

105) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

106)     $add = function ($val, $id, $value) {
107)         global $ret;
108)         if (isset($ret[$val]) && is_array($ret[$val])) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

109)             array_push($ret[$val], ["id" => $id, "value" => $value]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

110)         } else {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

111)             $ret[$val] = [ ["id" => $id, "value" => $value] ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

112)         }
113)     };
114) 
115) 
116)     $result = array_unique(find_customers($term));
117)     sort($result);
118)     foreach ($result as $val) {
119)         $c = customer_details($val);
120)         if ($c['id'] == $term) {
121)             $add(10, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
122)         } else {
123)             $add(90, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
124)         }
125)         $users = find_users_for_customer($c['id']);
126)         foreach ($users as $u) {
127)             $realname = $c['name'];
128)             if ($u['name']) {
129)                 $realname = $u['name'];
130)             }
131)             if ($u['uid'] == $term || $u['username'] == $term) {
132)                 $add(15, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
133)             } elseif (strstr($u['username'], $term)) {
134)                 $add(20, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
135)             } elseif (stristr($u['name'], $term)) {
136)                 $add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
137)             } else {
138)                 $add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
139)             }
140)         }
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

141)     }
142) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

143)     ksort($ret);
Hanno remove whitespace in empty...

Hanno authored 6 years ago

144) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

145)     $allentries = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

146)     foreach ($ret as $group) {
147)         usort($group, function ($a, $b) {
148)             return strnatcmp($a['value'], $b['value']);
149)         });
150)         foreach ($group as $entry) {
151)             $allentries[] = $entry;
152)         }
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

153)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

154)     unset($ret);
155)     return $allentries;
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

156) }
bernd AJAXified

bernd authored 16 years ago

157) 
158) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

159) function su($type, $id)
160) {
161)     $role = null;
162)     $admin_user = $_SESSION['userinfo']['username'];
163)     $_SESSION['admin_user'] = $admin_user;
164)     $role = find_role($id, '', true);
165)     if (!$role) {
166)         unset($_SESSION['admin_user']);
167)         return false;
Bernd Wurst Generelle Su-Möglichkeit fü...

Bernd Wurst authored 9 years ago

168)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

169)     setup_session($role, $id);
170)     if ($type == 'c') {
171)         if (! (ROLE_CUSTOMER & $_SESSION['role'])) {
172)             session_destroy();
173)             system_failure('Es wurde ein "su" zu einem Kundenaccount angefordert, das war aber kein Kundenaccount!');
174)         }
175)     } elseif ($type == 'u') {
176)         if (! (ROLE_SYSTEMUSER & $_SESSION['role'])) {
177)             session_destroy();
178)             system_failure('Es wurde ein "su" zu einem Benutzeraccount angefordert, das war aber kein Benutzeraccount!');
179)         }
180)     } elseif ($type) {
181)         // wenn type leer ist, dann ist es auch egal
182)         system_failure('unknown type');
Bernd Wurst Generelle Su-Möglichkeit fü...

Bernd Wurst authored 9 years ago

183)     }
184) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

185)     redirect('../../go/index/index');
186)     die();