b65024dba6ac9b5adc7d30824b9ae8419209008a
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) 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.
12) */
bernd Su-Login für Admins

bernd authored 17 years ago

13) 
14) function list_system_users()
15) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

25) }
26) 
27) 
28) function list_customers()
29) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 17 years ago

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

Hanno authored 6 years ago

32)     $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

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

39) }
40) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

44)     $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

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

Hanno authored 6 years ago

46)         return null;
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

47)     }
48)     $kunde = $result->fetch();
49)     return $kunde;
50) }
51) 
bernd Su-Login für Admins

bernd authored 17 years ago

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

Hanno authored 6 years ago

53) function find_customers($string)
bernd AJAXified

bernd authored 16 years ago

54) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

55)     $args = [":string" => '%' . chop($string) . '%', ":number" => $string];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

56)     $return = [];
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

57)     $result = db_query("SELECT k.id FROM kundendaten.kunden AS k LEFT JOIN system.useraccounts AS u ON (k.id=u.kunde) WHERE " .
58)                      "firma LIKE :string OR firma2 LIKE :string OR " .
59)                      "nachname LIKE :string OR vorname LIKE :string OR " .
60)                      "adresse LIKE :string OR adresse2 LIKE :string OR " .
61)                      "ort LIKE :string OR pgp_id LIKE :string OR " .
62)                      "notizen LIKE :string OR email_rechnung LIKE :string OR " .
63)                      "email LIKE :string OR email_extern LIKE :string OR u.name LIKE :string OR " .
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

64)                      "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

65)     while ($entry = $result->fetch()) {
66)         $return[] = $entry['id'];
67)     }
bernd AJAXified

bernd authored 16 years ago

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

Hanno authored 6 years ago

69)     unset($args[':number']);
70)     $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

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

78)     return $return;
bernd AJAXified

bernd authored 16 years ago

79) }
80) 
81) 
82) function find_users_for_customer($id)
83) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

85)     $return = [];
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

86)     $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

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

Hanno authored 6 years ago

88)     while ($entry = $result->fetch()) {
89)         $return[] = $entry;
90)     }
bernd AJAXified

bernd authored 16 years ago

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

Hanno authored 6 years ago

92)     return $return;
bernd AJAXified

bernd authored 16 years ago

93) }
94) 
95) 
96) 
97) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

109)         }
110)     };
111) 
112) 
113)     $result = array_unique(find_customers($term));
114)     sort($result);
115)     foreach ($result as $val) {
116)         $c = customer_details($val);
117)         if ($c['id'] == $term) {
118)             $add(10, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
119)         } else {
120)             $add(90, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
121)         }
122)         $users = find_users_for_customer($c['id']);
123)         foreach ($users as $u) {
124)             $realname = $c['name'];
125)             if ($u['name']) {
126)                 $realname = $u['name'];
127)             }
128)             if ($u['uid'] == $term || $u['username'] == $term) {
129)                 $add(15, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
130)             } elseif (strstr($u['username'], $term)) {
131)                 $add(20, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
Bernd Wurst illegal variable access

Bernd Wurst authored 1 year ago

132)             } elseif (isset($u['name']) && stristr($u['name'], $term)) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

133)                 $add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
134)             } else {
135)                 $add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
136)             }
137)         }
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

138)     }
139) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 11 years ago

153) }
bernd AJAXified

bernd authored 16 years ago

154) 
155) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Bernd Wurst authored 9 years ago

165)     }
Bernd Wurst Speichere Login-Methode in...

Bernd Wurst authored 1 year ago

166)     setup_session($role, $id, 'su');
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

167)     if ($type == 'c') {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

168)         if (!(ROLE_CUSTOMER & $_SESSION['role'])) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

169)             session_destroy();
170)             system_failure('Es wurde ein "su" zu einem Kundenaccount angefordert, das war aber kein Kundenaccount!');
171)         }
172)     } elseif ($type == 'u') {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

173)         if (!(ROLE_SYSTEMUSER & $_SESSION['role'])) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

174)             session_destroy();
175)             system_failure('Es wurde ein "su" zu einem Benutzeraccount angefordert, das war aber kein Benutzeraccount!');
176)         }
177)     } elseif ($type) {
178)         // wenn type leer ist, dann ist es auch egal
179)         system_failure('unknown type');
Bernd Wurst Generelle Su-Möglichkeit fü...

Bernd Wurst authored 9 years ago

180)     }
181) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

182)     redirect('../../go/index/index');
183)     die();