a84e72ba1e38d23bc353f56adf00d5a6778cbc6e
bernd Neues AJAX-su

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 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 16 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 16 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 16 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 16 years ago

52)   $users = find_users_for_customer($c->id);
Bernd Wurst übersichtlichere Auswahllis...

Bernd Wurst authored 11 years ago

53)   foreach ($users as $u) {
54)     $realname = $c->fullname;
55)     if ($u['name']) {
56)       $realname = $u['name'];
57)     }
58)     if ($u['uid'] == $term || $u['username'] == $term) {
59)       add(15, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
60)     } elseif (strstr($u['username'], $term)) {
61)       add(20, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
62)     } elseif (strstr($u['name'], $term)) {
63)       add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

64)     } else {
Bernd Wurst übersichtlichere Auswahllis...

Bernd Wurst authored 11 years ago

65)       add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})");
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

66)     }
67)   }
68) }
69) 
70) ksort($ret);
71) 
72) $lines = array();
73) foreach ($ret as $group) {
74)   foreach ($group as $entry) {
Bernd Wurst sanitize output

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

76)   }
77) }
Bernd Wurst Erzeuge sortierte Ausgabe d...

Bernd Wurst authored 11 years ago

78) 
79) 
80) 
81) header("Content-Type: text/javascript");
82) echo "[\n";
83) echo implode(",\n", $lines);
84) echo '
Bernd Wurst su-Modul auf jQuery umgeste...

Bernd Wurst authored 11 years ago

85) ]';