Jump to content

Knowledgebase report


Ragonz

Recommended Posts

1 hour ago, Ragonz said:

Would anyone know if I can run a report showing the number of new Knowledgebase guides created during a specific date range and who created them?

yes... but WHMCS doesn't store those details in any of the kb database tables - I think the only source would be the activity log... that should tell you a) when an article/category was created/modified, b) which admin user did it.

so the quick solution, although you couldn't specify a date range, would be to just view the activity log and filter on knowledgebase, and/or admin.

the longer way if you need a date range to search with, would be a report that queried the activity log tables.

Link to comment
Share on other sites

Activity log is a good shout, however whmcs doesnt seem to record the adding of knowledgebase articles, only the modification/deletion of them?

I have an example KB article created on the 11th and I know who created it but it does not show up within activity logs.

Is there a way to change what WHMCS records?

Link to comment
Share on other sites

You could start with this hook.

It automatically add kt_author column to tblknowledgebase table. The kt_ prefix is important as we don't know if one day in the future WHMCS will add author column so it's better to avoid naming collision. When an administrator adds a new KB article, the hook stores admin ID in the newly added column. This way each of your articles will be assigned to an administrator (the author). The hook also adds author information directly on page with jQuery as follows.

whmcs-author-knowledgebase-article.png.2f07a0121a52e9040fe1b709b8d15d81.png

<?php

/**
 * @writtenby	Kian
 */

use WHMCS\Database\Capsule;

add_hook('AdminAreaHeadOutput', 1, function($vars)
{
    if ($vars['filename'] == 'supportkb' AND $_GET['action'] == 'edit' AND $_GET['id'])
    {
        if (!Capsule::schema()->hasColumn('tblknowledgebase', 'kt_author'))
        {
            Capsule::select(Capsule::raw('ALTER TABLE `tblknowledgebase` ADD `kt_author` INT NULL AFTER `language`'));
        }

        $adminID = Capsule::table('tblknowledgebase')->where('id', $_GET['id'])->pluck('kt_author')[0];

        if (!$adminID)
        {
            $adminID = $_SESSION['adminid'];
            Capsule::table('tblknowledgebase')->where('id', $_GET['id'])->update(['kt_author' => $adminID]);
        }

        $adminUsername = Capsule::table('tbladmins')->where('id', $adminID)->pluck('username')[0];

        return <<<HTML
<script>
$(document).ready(function(){
$('table[class="form"] > tbody tr:first').after(('<tr><td class="fieldlabel" width="15%">Author</td><td class="fieldarea"><a href="configadmins.php?action=manage&id={$adminID}"><i class="fas fa-user"></i> {$adminUsername}</a></td></tr>'));
})
</script>
HTML;
    }
});

 

Link to comment
Share on other sites

1 hour ago, Ragonz said:

Activity log is a good shout, however whmcs doesn't seem to record the adding of knowledgebase articles, only the modification/deletion of them?

it should record both...

Duc7BJf.png

1 hour ago, Ragonz said:

I have an example KB article created on the 11th and I know who created it but it does not show up within activity logs.

it's working for me whether i'm an admin or support operator - kb creation is being logged after creation.

1 hour ago, Ragonz said:

Is there a way to change what WHMCS records?

to change what WHMCS internally records, I doubt - they tend to be hardcoded within encrypted files... you can add custom entries to the log (logactivity), but there aren't any kb hooks, so there's no simple way to trigger adding a log after article creation.

I suppose you could run the logactivity hook to add a custom log entry after kb article creation, but that relies on WHMCS adding a default entry in the first place... actually, you could probably use the hook to modify the default entry if it exists... though i'm not keen on modifying log entries.

is it possible the activity log has been trimmed in some way??

Link to comment
Share on other sites

7 minutes ago, Kian said:

You could start with this hook.

it wouldn't help with solving the OP question of generating reports, or logging authors & times - it's just an unnecessary complication... even if you ran a query on the table, it would just tell you the last person to edit it (or maybe the last person to just go to the edit page whether they made changes or not)...

Link to comment
Share on other sites

That's why I said "you could start with this hook" 😛

He can retreive both created and last edit dates from tblactivitylog and then JOIN everything with author column. With a single query he can get all he wants. Alternatively he could get rid of tblactivitylog entirely replicating the same thing I did for author column (adding created and lastmodified columns). This way it's even easier.

Edited by Kian
Link to comment
Share on other sites

3 minutes ago, Kian said:

That's why I said "you could start with this hook" 😛

and one of these days, you'll learn that users want end points, not starting points. 💡

3 minutes ago, Kian said:

He can retrieve both created and last edit dates from tblactivitylog

assuming they're being logged correctly on his install - that seems debatable at this point... in any event, if it's being logged correctly, he can get who created, modified and date from the logs without the need for the hook.

5 minutes ago, Kian said:

With a single query he can get all he wants. Alternatively he could get rid of tblactivitylog entirely replicating the same thing I did for author column (adding created and lastmodified columns). This way it's even easier.

https://developers.whmcs.com/advanced/db-interaction/

Quote

Note: WHMCS does not recommend changing default table schema as that can affect product functionality.

i'm not suggesting that the hook doesn't have its merits, just not for answering this question.... at least not in my eyes... now if it logged article creation/modification/dates etc in a separate table, referencing the kb article or parent id, then you may have something useful on your hands...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated