... | ... |
@@ -2,14 +2,11 @@ |
2 | 2 |
/* |
3 | 3 |
This file belongs to the Webinterface of schokokeks.org Hosting |
4 | 4 |
|
5 |
-Written 2008-2018 by schokokeks.org Hosting, namely |
|
5 |
+Written by schokokeks.org Hosting, namely |
|
6 | 6 |
Bernd Wurst <bernd@schokokeks.org> |
7 | 7 |
Hanno Böck <hanno@schokokeks.org> |
8 | 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/ |
|
9 |
+This code is published under a 0BSD license. |
|
13 | 10 |
|
14 | 11 |
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 | 12 |
*/ |
... | ... |
@@ -31,10 +31,10 @@ $term = $_GET['term']; |
31 | 31 |
|
32 | 32 |
$allentries = build_results($term); |
33 | 33 |
|
34 |
-$out = array(); |
|
34 |
+$out = []; |
|
35 | 35 |
|
36 | 36 |
foreach ($allentries as $entry) { |
37 |
- $out[] = array('id' => $entry['id'], 'value' => $entry['value']); |
|
37 |
+ $out[] = ['id' => $entry['id'], 'value' => $entry['value']]; |
|
38 | 38 |
} |
39 | 39 |
|
40 | 40 |
|
... | ... |
@@ -8,7 +8,7 @@ Written 2008-2018 by schokokeks.org Hosting, namely |
8 | 8 |
|
9 | 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 | 10 |
|
11 |
-You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see |
|
11 |
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see |
|
12 | 12 |
http://creativecommons.org/publicdomain/zero/1.0/ |
13 | 13 |
|
14 | 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. |
... | ... |
@@ -34,12 +34,10 @@ $allentries = build_results($term); |
34 | 34 |
$out = array(); |
35 | 35 |
|
36 | 36 |
foreach ($allentries as $entry) { |
37 |
- $out[] = array('id' => $entry['id'], 'value' => $entry['value']); |
|
37 |
+ $out[] = array('id' => $entry['id'], 'value' => $entry['value']); |
|
38 | 38 |
} |
39 | 39 |
|
40 | 40 |
|
41 | 41 |
header("Content-Type: application/json"); |
42 | 42 |
echo json_encode($out); |
43 | 43 |
die(); |
44 |
- |
|
45 |
- |
... | ... |
@@ -31,18 +31,15 @@ $term = $_GET['term']; |
31 | 31 |
|
32 | 32 |
$allentries = build_results($term); |
33 | 33 |
|
34 |
-$lines = array(); |
|
34 |
+$out = array(); |
|
35 |
+ |
|
35 | 36 |
foreach ($allentries as $entry) { |
36 |
- $lines[] = " { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }"; |
|
37 |
+ $out[] = array('id' => $entry['id'], 'value' => $entry['value']); |
|
37 | 38 |
} |
38 | 39 |
|
39 | 40 |
|
40 |
- |
|
41 | 41 |
header("Content-Type: application/json"); |
42 |
-echo "[\n"; |
|
43 |
-echo implode(",\n", $lines); |
|
44 |
-echo ' |
|
45 |
-]'; |
|
42 |
+echo json_encode($out); |
|
46 | 43 |
die(); |
47 | 44 |
|
48 | 45 |
|
... | ... |
@@ -15,12 +15,12 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r |
15 | 15 |
*/ |
16 | 16 |
|
17 | 17 |
require_once('inc/base.php'); |
18 |
+require_once('inc/security.php'); |
|
18 | 19 |
require_once('inc/debug.php'); |
19 | 20 |
|
20 | 21 |
require_once('session/start.php'); |
21 | 22 |
require_once('su.php'); |
22 | 23 |
|
23 |
-require_once('class/customer.php'); |
|
24 | 24 |
|
25 | 25 |
require_role(ROLE_SYSADMIN); |
26 | 26 |
|
... | ... |
@@ -28,55 +28,12 @@ require_role(ROLE_SYSADMIN); |
28 | 28 |
$_SESSION['su_ajax_timestamp'] = time(); |
29 | 29 |
|
30 | 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 |
- |
|
42 |
- |
|
43 |
-$result = array_unique(find_customers($term)); |
|
44 |
-sort($result); |
|
45 |
-foreach ($result as $val) { |
|
46 |
- $c = new Customer((int) $val); |
|
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 |
- } |
|
52 |
- $users = find_users_for_customer($c->id); |
|
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 (stristr($u['name'], $term)) { |
|
63 |
- add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
|
64 |
- } else { |
|
65 |
- add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
|
66 |
- } |
|
67 |
- } |
|
68 |
-} |
|
69 | 31 |
|
70 |
-ksort($ret); |
|
32 |
+$allentries = build_results($term); |
|
71 | 33 |
|
72 | 34 |
$lines = array(); |
73 |
-foreach ($ret as $group) { |
|
74 |
- usort($group, function ($a, $b) { |
|
75 |
- return strnatcmp($a['value'], $b['value']); |
|
76 |
- }); |
|
77 |
- foreach ($group as $entry) { |
|
78 |
- $lines[] = " { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }"; |
|
79 |
- } |
|
35 |
+foreach ($allentries as $entry) { |
|
36 |
+ $lines[] = " { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }"; |
|
80 | 37 |
} |
81 | 38 |
|
82 | 39 |
|
... | ... |
@@ -71,6 +71,9 @@ ksort($ret); |
71 | 71 |
|
72 | 72 |
$lines = array(); |
73 | 73 |
foreach ($ret as $group) { |
74 |
+ usort($group, function ($a, $b) { |
|
75 |
+ return strnatcmp($a['value'], $b['value']); |
|
76 |
+ }); |
|
74 | 77 |
foreach ($group as $entry) { |
75 | 78 |
$lines[] = " { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }"; |
76 | 79 |
} |
... | ... |
@@ -59,7 +59,7 @@ foreach ($result as $val) { |
59 | 59 |
add(15, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
60 | 60 |
} elseif (strstr($u['username'], $term)) { |
61 | 61 |
add(20, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
62 |
- } elseif (strstr($u['name'], $term)) { |
|
62 |
+ } elseif (stristr($u['name'], $term)) { |
|
63 | 63 |
add(25, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
64 | 64 |
} else { |
65 | 65 |
add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
... | ... |
@@ -50,13 +50,19 @@ foreach ($result as $val) { |
50 | 50 |
add(90, "c{$c->id}", "Kunde {$c->id}: {$c->fullname}"); |
51 | 51 |
} |
52 | 52 |
$users = find_users_for_customer($c->id); |
53 |
- foreach ($users as $uid => $username) { |
|
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}"); |
|
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})"); |
|
58 | 64 |
} else { |
59 |
- add(85, "u{$uid}", "User {$uid}: {$username}"); |
|
65 |
+ add(85, "u{$u['uid']}", "{$u['username']} (UID {$u['uid']}, {$realname})"); |
|
60 | 66 |
} |
61 | 67 |
} |
62 | 68 |
} |
... | ... |
@@ -66,7 +66,7 @@ ksort($ret); |
66 | 66 |
$lines = array(); |
67 | 67 |
foreach ($ret as $group) { |
68 | 68 |
foreach ($group as $entry) { |
69 |
- $lines[] = " { \"id\": \"{$entry['id']}\", \"value\": \"{$entry['value']}\" }"; |
|
69 |
+ $lines[] = " { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }"; |
|
70 | 70 |
} |
71 | 71 |
} |
72 | 72 |
|
... | ... |
@@ -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 |
+} |
|
41 |
+ |
|
32 | 42 |
|
33 |
-$result = array_unique(find_customers($_GET['term'])); |
|
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}"); |
|
60 |
+ } |
|
61 |
+ } |
|
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']}\" }"; |
|
41 | 70 |
} |
42 | 71 |
} |
43 |
-echo ' {} |
|
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 |
|
... | ... |
@@ -24,19 +24,24 @@ require_once('class/customer.php'); |
24 | 24 |
|
25 | 25 |
require_role(ROLE_SYSADMIN); |
26 | 26 |
|
27 |
-$ajax_formtoken = generate_form_token('su_su_ajax'); |
|
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(); |
|
28 | 29 |
|
29 |
-$result = array_unique(find_customers($_GET['q'])); |
|
30 |
+header("Content-Type: text/javascript"); |
|
31 |
+echo "[\n"; |
|
32 |
+ |
|
33 |
+$result = array_unique(find_customers($_GET['term'])); |
|
30 | 34 |
sort($result); |
31 | 35 |
foreach ($result as $val) { |
32 | 36 |
$c = new Customer((int) $val); |
33 |
- echo '<div style="margin-bottom: 0.5em;">'.internal_link('su.php', 'Kunde '.$c->id.': <strong>'.$c->fullname.'</strong>', 'type=customer&id='.$c->id.'&formtoken='.$ajax_formtoken); |
|
37 |
+ echo " {\"id\": \"c{$c->id}\", \"value\": \"Kunde {$c->id}: {$c->fullname}\"},\n"; |
|
34 | 38 |
$users = find_users_for_customer($c->id); |
35 | 39 |
foreach ($users as $uid => $username) { |
36 |
- echo '<p style="padding:0; margin:0;margin-left: 2em;">'.internal_link('', 'User »'.$username.'« (UID '.$uid.')', 'type=systemuser&uid='.$uid.'&formtoken='.$ajax_formtoken).'</p>'; |
|
40 |
+ echo " {\"id\": \"u{$uid}\", \"label\": \"User {$uid}: {$username}\"},\n"; |
|
37 | 41 |
} |
38 |
- echo '</div>'; |
|
39 | 42 |
} |
43 |
+echo ' {} |
|
44 |
+]'; |
|
40 | 45 |
die(); |
41 | 46 |
|
42 | 47 |
|
... | ... |
@@ -1,4 +1,18 @@ |
1 | 1 |
<?php |
2 |
+/* |
|
3 |
+This file belongs to the Webinterface of schokokeks.org Hosting |
|
4 |
+ |
|
5 |
+Written 2008-2012 by schokokeks.org Hosting, namely |
|
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 |
+*/ |
|
2 | 16 |
|
3 | 17 |
require_once('inc/base.php'); |
4 | 18 |
require_once('inc/debug.php'); |
git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@1183 87cf0b9e-d624-0410-a070-f6ee81989793
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+require_once('inc/base.php'); |
|
4 |
+require_once('inc/debug.php'); |
|
5 |
+ |
|
6 |
+require_once('session/start.php'); |
|
7 |
+require_once('su.php'); |
|
8 |
+ |
|
9 |
+require_once('class/customer.php'); |
|
10 |
+ |
|
11 |
+require_role(ROLE_SYSADMIN); |
|
12 |
+ |
|
13 |
+$ajax_formtoken = generate_form_token('su_su_ajax'); |
|
14 |
+ |
|
15 |
+$result = array_unique(find_customers($_GET['q'])); |
|
16 |
+sort($result); |
|
17 |
+foreach ($result as $val) { |
|
18 |
+ $c = new Customer((int) $val); |
|
19 |
+ echo '<div style="margin-bottom: 0.5em;">'.internal_link('su.php', 'Kunde '.$c->id.': <strong>'.$c->fullname.'</strong>', 'type=customer&id='.$c->id.'&formtoken='.$ajax_formtoken); |
|
20 |
+ $users = find_users_for_customer($c->id); |
|
21 |
+ foreach ($users as $uid => $username) { |
|
22 |
+ echo '<p style="padding:0; margin:0;margin-left: 2em;">'.internal_link('', 'User »'.$username.'« (UID '.$uid.')', 'type=systemuser&uid='.$uid.'&formtoken='.$ajax_formtoken).'</p>'; |
|
23 |
+ } |
|
24 |
+ echo '</div>'; |
|
25 |
+} |
|
26 |
+die(); |
|
27 |
+ |
|
28 |
+ |