bd22f03937341179a1beaf87aafcde8e61882589
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 Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 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 17 years ago

16) 
bernd AJAXified

bernd authored 16 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 17 years ago

19) 
20) function list_system_users()
21) {
22)   require_role(ROLE_SYSADMIN);
23) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

24)   $result = db_query("SELECT uid,username FROM system.v_useraccounts ORDER BY username");
bernd Su-Login für Admins

bernd authored 17 years ago

25)   
26)   $ret = array();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

27)   while ($item = mysql_fetch_object($result))
bernd Su-Login für Admins

bernd authored 17 years ago

28)     array_push($ret, $item);
29)   return $ret;
30) }
31) 
32) 
33) function list_customers()
34) {
35)   require_role(ROLE_SYSADMIN);
36) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

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");
bernd Su-Login für Admins

bernd authored 17 years ago

38)   
39)   $ret = array();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

40)   while ($item = mysql_fetch_object($result))
bernd Su-Login für Admins

bernd authored 17 years ago

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

bernd authored 16 years ago

46) function find_customers($string) 
47) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

48)   $string = mysql_real_escape_string(chop($string));
bernd AJAXified

bernd authored 16 years ago

49)   $return = array();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 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 AJAXified

bernd authored 16 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 ".
bernd Tabelle 'kundenkontakt' kom...

bernd authored 14 years ago

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 ".
bernd AJAXified

bernd authored 16 years ago

57)                      "u.username LIKE '%{$string}%' OR k.id='{$string}' OR u.uid='{$string}';");
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

58)   while ($entry = mysql_fetch_assoc($result))
bernd AJAXified

bernd authored 16 years ago

59)     $return[] = $entry['id'];
60) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

61)   $result = db_query("SELECT kunde FROM kundendaten.domains WHERE kunde IS NOT NULL AND (
bernd Finde Kunden auch anhand vo...

bernd authored 15 years ago

62)                       domainname LIKE '%{$string}%' OR CONCAT_WS('.', domainname, tld) LIKE '%{$string}%'
63)                       )");
64) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

65)   while ($entry = mysql_fetch_assoc($result))
bernd Finde Kunden auch anhand vo...

bernd authored 15 years ago

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

bernd authored 16 years ago

68)   return $return;
69) }
70) 
71) 
72) function find_users_for_customer($id)
73) {
74)   $id = (int) $id;
75)   $return = array();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

76)   $result = db_query("SELECT uid, username, name FROM system.useraccounts WHERE ".
bernd AJAXified

bernd authored 16 years ago

77)                      "kunde='{$id}';");
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 11 years ago

78)   while ($entry = mysql_fetch_assoc($result))
Bernd Wurst übersichtlichere Auswahllis...

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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