fe1b74208906f0d0d13e4a5eed38d64679f507ef
bernd Su-Login für Admins

bernd authored 16 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) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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 16 years ago

16) 
17) function list_system_users()
18) {
19)   require_role(ROLE_SYSADMIN);
20) 
21)   $result = db_query("SELECT uid,username FROM system.v_useraccounts ORDER BY username");
22)   
23)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

24)   while ($item = $result->fetch(PDO::FETCH_OBJ))
bernd Su-Login für Admins

bernd authored 16 years ago

25)     array_push($ret, $item);
26)   return $ret;
27) }
28) 
29) 
30) function list_customers()
31) {
32)   require_role(ROLE_SYSADMIN);
33) 
34)   $result = db_query("SELECT id, IF(firma IS NULL, CONCAT_WS(' ', vorname, nachname), CONCAT(firma, ' (', CONCAT_WS(' ', vorname, nachname), ')')) AS name FROM kundendaten.kunden");
35)   
36)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

37)   while ($item = $result->fetch(PDO::FETCH_OBJ))
bernd Su-Login für Admins

bernd authored 16 years ago

38)     array_push($ret, $item);
39)   return $ret;
40) }
41) 
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

42) function customer_details($id) 
43) {
44)     $id = (int) $id; 
45)     $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=?", array($id));
46)     if ($result->rowCount() < 1) {
47)         return NULL;
48)     }
49)     $kunde = $result->fetch();
50)     return $kunde;
51) }
52) 
bernd Su-Login für Admins

bernd authored 16 years ago

53) 
bernd AJAXified

bernd authored 15 years ago

54) function find_customers($string) 
55) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

56)   $args = array(":string" => '%'.chop($string).'%', ":number" => $string);
bernd AJAXified

bernd authored 15 years ago

57)   $return = array();
bernd Tabelle 'kundenkontakt' kom...

bernd authored 14 years ago

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

59)                      "firma LIKE :string OR firma2 LIKE :string OR ".
60)                      "nachname LIKE :string OR vorname LIKE :string OR ".
61)                      "adresse LIKE :string OR adresse2 LIKE :string OR ".
62)                      "ort LIKE :string OR pgp_id LIKE :string OR ".
63)                      "notizen LIKE :string OR email_rechnung LIKE :string OR ".
64)                      "email LIKE :string OR email_extern LIKE :string OR u.name LIKE :string OR ".
65)                      "u.username LIKE :string OR k.id=:number OR u.uid=:number", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

66)   while ($entry = $result->fetch())
bernd AJAXified

bernd authored 15 years ago

67)     $return[] = $entry['id'];
68) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

69)   unset($args[':number']);
bernd Finde Kunden auch anhand vo...

bernd authored 15 years ago

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) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

74)   while ($entry = $result->fetch())
bernd Finde Kunden auch anhand vo...

bernd authored 15 years ago

75)     $return[] = $entry['kunde'];
76) 
bernd AJAXified

bernd authored 15 years ago

77)   return $return;
78) }
79) 
80) 
81) function find_users_for_customer($id)
82) {
83)   $id = (int) $id;
84)   $return = array();
Bernd Wurst übersichtlichere Auswahllis...

Bernd Wurst authored 11 years ago

85)   $result = db_query("SELECT uid, username, name FROM system.useraccounts WHERE ".
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

86)                      "kunde=?", array($id));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

87)   while ($entry = $result->fetch())
Bernd Wurst übersichtlichere Auswahllis...

Bernd Wurst authored 11 years ago

88)     $return[] = $entry;
bernd AJAXified

bernd authored 15 years ago

89) 
90)   return $return;
91) }
92) 
93) 
94) 
95) 
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

96) function build_results($term) {
97)   global $ret;
98)   $ret = array();
99)   
100)   $add = function($val, $id, $value) {
101)     global $ret;
102)     if (isset($ret[$val]) && is_array($ret[$val])) {
103)       array_push($ret[$val], array("id" => $id, "value" => $value));
104)     } else {
105)       $ret[$val] = array( array("id" => $id, "value" => $value) );
106)     }
107)   };
108) 
109) 
110)   $result = array_unique(find_customers($term));
111)   sort($result);
112)   foreach ($result as $val) {
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

113)     $c = customer_details($val);
114)     if ($c['id'] == $term) {
115)       $add(10, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

116)     } else {
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

117)       $add(90, "c{$c['id']}", "Kunde {$c['id']}: {$c['name']}");
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

118)     }
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

119)     $users = find_users_for_customer($c['id']);
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

120)     foreach ($users as $u) {
Bernd Wurst Alte Klassen entfernt

Bernd Wurst authored 6 years ago

121)       $realname = $c['name'];
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

122)       if ($u['name']) {
123)         $realname = $u['name'];
124)       }
125)       if ($u['uid'] == $term || $u['username'] == $term) {
126)         $add(15, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
127)       } elseif (strstr($u['username'], $term)) {
128)         $add(20, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
129)       } elseif (stristr($u['name'], $term)) {
130)         $add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
131)       } else {
132)         $add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
133)       }
134)     }
135)   }
136) 
137)   ksort($ret);
138)   
139)   $allentries = array();
140)   foreach ($ret as $group) {
141)     usort($group, function ($a, $b) {
142)       return strnatcmp($a['value'], $b['value']); 
143)     });
144)     foreach ($group as $entry) {
145)       $allentries[] = $entry;
146)     }
147)   }
148)   unset($ret);
149)   return $allentries;
150) }
bernd AJAXified

bernd authored 15 years ago

151) 
152)