5832d3fc3af2ed0a2d17c003a06f9dded73b72bf
bernd Neues AJAX-su

bernd authored 15 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 Neues AJAX-su

bernd authored 15 years ago

16) 
17) require_once('inc/base.php');
18) require_once('inc/debug.php');
19) 
20) require_once('session/start.php');
21) require_once('su.php');
22) 
23) require_once('class/customer.php');
24) 
25) require_role(ROLE_SYSADMIN);
26) 
Bernd Wurst su-Modul auf jQuery umgeste...

Bernd Wurst authored 11 years ago

27) # Save the timestamp of this request to the session, so we accept only actions performed some seconds after this
28) $_SESSION['su_ajax_timestamp'] = time();
bernd Neues AJAX-su

bernd authored 15 years ago

29) 
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

30) $term = $_GET['term'];
31) $ret = array();
32) 
33) function add($val, $id, $value) {
34)   global $ret;
35)   if (isset($ret[$val]) && is_array($ret[$val])) {
36)     array_push($ret[$val], array("id" => $id, "value" => $value));
37)   } else {
38)     $ret[$val] = array( array("id" => $id, "value" => $value) );
39)   }
40) }
41) 
Bernd Wurst su-Modul auf jQuery umgeste...

Bernd Wurst authored 11 years ago

42) 
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

43) $result = array_unique(find_customers($term));
bernd Neues AJAX-su

bernd authored 15 years ago

44) sort($result);
45) foreach ($result as $val) {
46)   $c = new Customer((int) $val);
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

47)   if ($c->id == $term) {
48)     add(10, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}");
49)   } else {
50)     add(90, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}");
51)   }
bernd Neues AJAX-su

bernd authored 15 years ago

52)   $users = find_users_for_customer($c->id);
53)   foreach ($users as $uid => $username) {
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

54)     if ($uid == $term || $username == $term) {
55)       add(15, "u{$uid}", "User {$uid}: {$username}");
56)     } elseif (strstr($username, $term)) {
57)       add(20, "u{$uid}", "User {$uid}: {$username}");
58)     } else {
59)       add(85, "u{$uid}", "User {$uid}: {$username}");
60)     }
61)   }
62) }
63) 
64) ksort($ret);
65) 
66) $lines = array();
67) foreach ($ret as $group) {
68)   foreach ($group as $entry) {
Bernd Wurst sanitize output

Bernd Wurst authored 11 years ago

69)     $lines[] = "  { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }";
bernd Neues AJAX-su

bernd authored 15 years ago

70)   }
71) }
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

72) 
73) 
74) 
75) header("Content-Type: text/javascript");
76) echo "[\n";
77) echo implode(",\n", $lines);
78) echo '
Bernd Wurst su-Modul auf jQuery umgeste...

Bernd Wurst authored 11 years ago

79) ]';