diff --git a/action.php b/action.php
index b19a934..3a34f2e 100644
--- a/action.php
+++ b/action.php
@@ -14,7 +14,7 @@ public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handleStart');
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleAction');
-
+ $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAdminAjax');
}
/**
@@ -83,5 +83,35 @@ public function handleAction(Doku_Event $event, $param)
}
}
-}
+ /**
+ * Check username input against all users with saved LMS data
+ * and return a list of matching names
+ *
+ * @param Doku_Event $event
+ * @return void
+ */
+ public function handleAdminAjax(Doku_Event $event)
+ {
+ if ($event->data !== 'plugin_lms_autocomplete') return;
+ global $INPUT;
+
+ if (!checkSecurityToken()) return;
+ $event->preventDefault();
+ $event->stopPropagation();
+
+ /** @var helper_plugin_lms $hlp */
+ $hlp = $this->loadHelper('lms');
+
+ $knownUsers = $hlp->getKnownUsers();
+
+ $search = $INPUT->str('user');
+ $found = array_filter($knownUsers, function ($user) use ($search) {
+ return (strstr(strtolower($user), strtolower($search))) !== false ? $user : null;
+ });
+
+ header('Content-Type: application/json');
+
+ echo json_encode($found);
+ }
+}
diff --git a/admin.php b/admin.php
index 692af5c..b7b7e8c 100644
--- a/admin.php
+++ b/admin.php
@@ -27,7 +27,7 @@ public function html()
echo '
' . $this->getLang('menu') . '
';
- $form = new dokuwiki\Form\Form(['method' => 'POST']);
+ $form = new dokuwiki\Form\Form(['method' => 'POST', 'id' => 'lms__admin-autocomplete']);
$form->addTextInput('user', $this->getLang('username'));
$form->addButton('submit', '🔍');
echo ''. $form->toHTML() .'
';
@@ -46,15 +46,14 @@ public function html()
echo html_wikilink($id);
echo '';
echo '';
- if($dt){
+ if ($dt){
echo dformat($dt);
+ } else {
+ echo '---';
}
echo ' | ';
echo '';
}
echo '';
-
-
}
}
-
diff --git a/helper.php b/helper.php
index 7884053..6f52fb4 100644
--- a/helper.php
+++ b/helper.php
@@ -173,6 +173,23 @@ protected function getUserFile($user)
return $conf['metadir'] . '_lms/' . $user . '.lms';
}
+ public function getKnownUsers()
+ {
+ global $conf;
+
+ $lmsData = $conf['metadir'] . '_lms/';
+
+ $s = scandir($lmsData);
+
+ $users = array_map(function ($file) {
+ if (!in_array($file, ['.', '..'])) {
+ return str_replace('.lms', '', $file);
+ }
+ }, $s);
+
+ return array_filter($users);
+ }
+
/**
* Get a list of links from the given control page
*
diff --git a/script.js b/script.js
index af6649d..1ab9f29 100644
--- a/script.js
+++ b/script.js
@@ -2,13 +2,15 @@ jQuery(function (){
if(!JSINFO['plugins']) return;
if(!JSINFO.plugins['lms']) return;
- jQuery('a.wikilink1, a.wikilink2').each(function (idx, elem){
+ if (JSINFO.ACT !== 'admin') {
+ jQuery('a.wikilink1, a.wikilink2').each(function (idx, elem){
- if(elem['title'] && JSINFO.plugins.lms.seen.includes(elem.title)) {
- jQuery(elem).addClass('lms-seen');
- }
+ if(elem['title'] && JSINFO.plugins.lms.seen.includes(elem.title)) {
+ jQuery(elem).addClass('lms-seen');
+ }
- });
+ });
+ }
// mark whole sections seen
const navheaders = jQuery('nav div.content h1, nav div.content h2, nav div.content h3, nav div.content h4, nav div.content h5');
@@ -21,4 +23,20 @@ jQuery(function (){
}
});
+ /**
+ * admin interface: autocomplete users
+ */
+ const $form = jQuery('.dokuwiki.mode_admin form#lms__admin-autocomplete');
+ if (!$form.length) return;
+
+ $form.find('input')
+ .autocomplete({
+ source: function (request, response) {
+ jQuery.getJSON(DOKU_BASE + 'lib/exe/ajax.php?call=plugin_lms_autocomplete', {
+ user: request.term,
+ sectok: $form.find('input[name="sectok"]').val()
+ }, response);
+ },
+ minLength: 0
+ });
});