Browse code

su-Modul auf jQuery umgestellt (ohne weitere Verbesserungen der Usability)

Bernd Wurst authored on 20/01/2013 12:09:29
Showing 2 changed files
... ...
@@ -22,18 +22,22 @@ require_once('su.php');
22 22
 
23 23
 require_role(ROLE_SYSADMIN);
24 24
 
25
-if (isset($_GET['type']))
25
+if (isset($_GET['do']))
26 26
 {
27
-  check_form_token('su_su_ajax', $_GET['formtoken']);
27
+  if ($_SESSION['su_ajax_timestamp'] < time() - 30) {
28
+    system_failure("Die su-Auswahl ist schon abgelaufen!");
29
+  }
30
+  $type = $_GET['do'][0];
31
+  $id = (int) substr($_GET['do'], 1);
28 32
   $role = NULL;
29 33
   $admin_user = $_SESSION['userinfo']['username'];
30 34
   $_SESSION['admin_user'] = $admin_user;
31
-  if ($_GET['type'] == 'customer') {
32
-    $role = find_role($_GET['id'], '', True);
33
-    setup_session($role, $_GET['id']);
34
-  } elseif ($_GET['type'] == 'systemuser') {
35
-    $role = find_role($_GET['uid'], '', True);
36
-    setup_session($role, $_GET['uid']);
35
+  if ($type == 'c') {
36
+    $role = find_role($id, '', True);
37
+    setup_session($role, $id);
38
+  } elseif ($type == 'u') {
39
+    $role = find_role($id, '', True);
40
+    setup_session($role, $id);
37 41
   } else {
38 42
     system_failure('unknown type');
39 43
   }
... ...
@@ -62,32 +66,26 @@ $debug = '';
62 66
 if ($debugmode)
63 67
   $debug = 'debug&amp;';
64 68
 
65
-html_header('<script type="text/javascript" src="'.$prefix.'js/ajax.js" ></script>
66
-<script type="text/javascript">
67
-
68
-function doRequest() {
69
-  ajax_request(\'su_ajax\', \''.$debug.'q=\'+document.getElementById(\'query\').value, got_response)
70
-}
71
-
72
-function keyPressed() {
73
-  if(window.mytimeout) window.clearTimeout(window.mytimeout);
74
-  window.mytimeout = window.setTimeout(doRequest, 500);
75
-  return true;
76
-}
77
-
78
-function got_response() {
79
-  if (xmlHttp.readyState == 4) {
80
-    document.getElementById(\'response\').innerHTML = xmlHttp.responseText;
81
-  }
82
-}
83
-
84
-</script>
69
+html_header('
70
+<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css">
71
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.js" ></script>
72
+<script type="text/javascript" src="http://code.jquery.com/ui/1.10.0/jquery-ui.js" ></script>
85 73
 ');
86 74
 
87
-output(html_form('su_su_ajax', '', '', '<strong>Suchtext:</strong> <input type="text" id="query" onkeyup="keyPressed()" />
88
-'));
89
-output('<div id="response"></div>
90
-<div style="height: 3em;">&#160;</div>');
75
+output('<label for="query"><strong>Suchtext:</strong></label> <input type="text" id="query" />
76
+<input type="hidden" id="query_id" name="query_id" />
77
+');
78
+output('
79
+<script>
80
+$("#query").autocomplete({
81
+    source: "su_ajax",
82
+    select: function( event, ui ) {
83
+      if (ui.item) {
84
+        window.location.href = "?do="+ui.item.id;
85
+      }
86
+}
87
+ });
88
+</script>');
91 89
 
92 90
 /*
93 91
 
... ...
@@ -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