Bernd Wurst commited on 2013-01-21 15:59:01
Zeige 1 geänderte Dateien mit 41 Einfügungen und 6 Löschungen.
| ... | ... |
@@ -27,20 +27,55 @@ require_role(ROLE_SYSADMIN); |
| 27 | 27 |
# Save the timestamp of this request to the session, so we accept only actions performed some seconds after this |
| 28 | 28 |
$_SESSION['su_ajax_timestamp'] = time(); |
| 29 | 29 |
|
| 30 |
-header("Content-Type: text/javascript");
|
|
| 31 |
-echo "[\n"; |
|
| 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 |
+} |
|
| 32 | 41 |
|
| 33 |
-$result = array_unique(find_customers($_GET['term'])); |
|
| 42 |
+ |
|
| 43 |
+$result = array_unique(find_customers($term)); |
|
| 34 | 44 |
sort($result); |
| 35 | 45 |
foreach ($result as $val) {
|
| 36 | 46 |
$c = new Customer((int) $val); |
| 37 |
- echo " {\"id\": \"c{$c->id}\", \"value\": \"Kunde {$c->id}: {$c->fullname}\"},\n";
|
|
| 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 |
+ } |
|
| 38 | 52 |
$users = find_users_for_customer($c->id); |
| 39 | 53 |
foreach ($users as $uid => $username) {
|
| 40 |
- echo " {\"id\": \"u{$uid}\", \"label\": \"User {$uid}: {$username}\"},\n";
|
|
| 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}");
|
|
| 41 | 60 |
} |
| 42 | 61 |
} |
| 43 |
-echo ' {}
|
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+ksort($ret); |
|
| 65 |
+ |
|
| 66 |
+$lines = array(); |
|
| 67 |
+foreach ($ret as $group) {
|
|
| 68 |
+ foreach ($group as $entry) {
|
|
| 69 |
+ $lines[] = " { \"id\": \"{$entry['id']}\", \"value\": \"{$entry['value']}\" }";
|
|
| 70 |
+ } |
|
| 71 |
+} |
|
| 72 |
+ |
|
| 73 |
+ |
|
| 74 |
+ |
|
| 75 |
+header("Content-Type: text/javascript");
|
|
| 76 |
+echo "[\n"; |
|
| 77 |
+echo implode(",\n", $lines);
|
|
| 78 |
+echo ' |
|
| 44 | 79 |
]'; |
| 45 | 80 |
die(); |
| 46 | 81 |
|
| 47 | 82 |