Jump to content
  • 0
Patty

Admin widget to show clients who view invoice page

Question

Hi there.

I'm not a coder, but I'd like to change the Client Activity widget to list only clients who actually viewed the invoice page. How do I go about doing that? Can somebody shed a light?

TIA for any help!

Here's the original widget code:

<?php

namespace WHMCS\Module\Widget;

use Carbon\Carbon;
use WHMCS\Module\AbstractWidget;
use WHMCS\User\Client;

/**
 * Client Activity Widget.
 *
 * @copyright Copyright (c) WHMCS Limited 2005-2016
 * @license http://www.whmcs.com/license/ WHMCS Eula
 */
class ClientActivity extends AbstractWidget
{
    protected $title = 'Client Activity';
    protected $description = 'Recent online clients.';
    protected $weight = 70;
    protected $cache = false;
    protected $cacheExpiry = 300;
    protected $requiredPermission = 'List Clients';

    public function getData()
    {
        return array(
            'activeCount' => (int) Client::where('status', '=', 'Active')->count(),
            'onlineCount' => (int) Client::where('lastlogin', '>', Carbon::now()->subHour()->toDateTimeString())->count(),
            'recentActiveClients' => Client::orderBy('lastlogin', 'desc')->limit(5)
                ->get(array('id', 'firstname', 'lastname', 'companyname', 'ip', 'lastlogin'))->toArray(),
        );
    }

    public function generateOutput($data)
    {
        $activeClients = number_format((int) $data['activeCount']);
        $usersOnline = number_format((int) $data['onlineCount']);

        $clients = array();
        foreach ($data['recentActiveClients'] as $client) {
            // If there is no lastlogin setting, or its been set to a timestamp like 0000-00-00, we show N/A
            $clientLastLogin = (empty($client['lastlogin']) || strpos($client['lastlogin'], '0000') === 0) ? "N/A" : Carbon::createFromFormat('Y-m-d H:i:s', $client['lastlogin'])->diffForHumans();
            $clients[] = '<div class="client">
        <div class="last-login">' . $clientLastLogin . '</div>
        <a href="clientssummary.php?userid=' . $client['id'] . '" class="link">'
            . $client['firstname'] . ' ' . $client['lastname'] . ($client['companyname'] ? ' ('
                . $client['companyname'] . ')' : '') . '</a>
        <a href="http://www.geoiptool.com/en/?IP=' . $client['ip'] . '" target="_blank" class="ip-address">' . $client['ip'] . '</a>
    </div>';
        }
        $clientOutput = implode($clients);

        return <<<EOF

<div class="icon-stats">
    <div class="row">
        <div class="col-sm-6">
            <div class="item">
                <div class="icon-holder text-center color-pink">
                    <a href="clients.php?status=Active">
                        <i class="pe-7s-user"></i>
                    </a>
                </div>
                <div class="data">
                    <div class="note">
                        <a href="clients.php?status=Active">Active Clients</a>
                    </div>
                    <div class="number">
                        <a href="clients.php?status=Active">
                            <span class="color-pink">{$activeClients}</span>
                            <span class="unit">Active</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="item">
                <div class="icon-holder text-center color-green">
                    <i class="pe-7s-smile"></i>
                </div>
                <div class="data">
                    <div class="note">
                        Users Online
                    </div>
                    <div class="number">
                        <span class="color-green">{$usersOnline}</span>
                        <span class="unit">Last Hour</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="clients-list">
    {$clientOutput}
</div>
EOF;
    }
}

 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
On 12/23/2017 at 19:37, Patty said:

I'm not a coder, but I'd like to change the Client Activity widget to list only clients who actually viewed the invoice page. How do I go about doing that? Can somebody shed a light?

does WHMCS even log when a client visits a particular page? perhaps if they performed some action on the page, but I doubt it just logs page visitations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines