ca4a7771597653e3f5dffd2015a4765c18279e87
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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) 
bernd AJAXified

bernd authored 15 years ago

17) require_once('inc/base.php');
Bernd Wurst Suche auch bei unvollständi...

Bernd Wurst authored 11 years ago

18) require_once('class/customer.php');
bernd Su-Login für Admins

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

41)     array_push($ret, $item);
42)   return $ret;
43) }
44) 
45) 
bernd AJAXified

bernd authored 15 years ago

46) function find_customers($string) 
47) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

51)                      "firma LIKE :string OR firma2 LIKE :string OR ".
52)                      "nachname LIKE :string OR vorname LIKE :string OR ".
53)                      "adresse LIKE :string OR adresse2 LIKE :string OR ".
54)                      "ort LIKE :string OR pgp_id LIKE :string OR ".
55)                      "notizen LIKE :string OR email_rechnung LIKE :string OR ".
56)                      "email LIKE :string OR email_extern LIKE :string OR u.name LIKE :string OR ".
57)                      "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

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

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

bernd authored 15 years ago

65) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

67)     $return[] = $entry['kunde'];
68) 
bernd AJAXified

bernd authored 15 years ago

69)   return $return;
70) }
71) 
72) 
73) function find_users_for_customer($id)
74) {
75)   $id = (int) $id;
76)   $return = array();
Bernd Wurst übersichtlichere Auswahllis...

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 15 years ago

81) 
82)   return $return;
83) }
84) 
85) 
86) 
87) 
Bernd Wurst Verschiebe Such-Logik in di...

Bernd Wurst authored 11 years ago

88) function build_results($term) {
89)   global $ret;
90)   $ret = array();
91)   
92)   $add = function($val, $id, $value) {
93)     global $ret;
94)     if (isset($ret[$val]) && is_array($ret[$val])) {
95)       array_push($ret[$val], array("id" => $id, "value" => $value));
96)     } else {
97)       $ret[$val] = array( array("id" => $id, "value" => $value) );
98)     }
99)   };
100) 
101) 
102)   $result = array_unique(find_customers($term));
103)   sort($result);
104)   foreach ($result as $val) {
105)     $c = new Customer((int) $val);
106)     if ($c->id == $term) {
107)       $add(10, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}");
108)     } else {
109)       $add(90, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}");
110)     }
111)     $users = find_users_for_customer($c->id);
112)     foreach ($users as $u) {
113)       $realname = $c->fullname;
114)       if ($u['name']) {
115)         $realname = $u['name'];
116)       }
117)       if ($u['uid'] == $term || $u['username'] == $term) {
118)         $add(15, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
119)       } elseif (strstr($u['username'], $term)) {
120)         $add(20, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
121)       } elseif (stristr($u['name'], $term)) {
122)         $add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
123)       } else {
124)         $add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
125)       }
126)     }
127)   }
128) 
129)   ksort($ret);
130)   
131)   $allentries = array();
132)   foreach ($ret as $group) {
133)     usort($group, function ($a, $b) {
134)       return strnatcmp($a['value'], $b['value']); 
135)     });
136)     foreach ($group as $entry) {
137)       $allentries[] = $entry;
138)     }
139)   }
140)   unset($ret);
141)   return $allentries;
142) }
bernd AJAXified

bernd authored 15 years ago

143) 
144)