Cara Menambah Login Button di Product Service WHMCS

Posted on

Halo sobat hosterbyte, berikut ini adalah hook untuk menambahkan login button pada pages Product Service WHMCS. Untuk contoh tampilannya seperti berikut

 

  • Buat file hook dengan nama AutoLoginToAnyPanelFromMyServices.php dengan lokasi
    folder-whmcs/include/hooks

    Copy kode berikut

    <?php

    /**
    * Auto-Login to cPanel/Plesk from My Services
    *
    * @package WHMCS
    * @copyright Katamaze
    * @link https://katamaze.com
    * @author Davide Mantenuto <[email protected]>
    */

    // IMPORTANT! The hook requires changes to two template files. Read the following for instructions
    // https://github.com/Katamaze/WHMCS-Free-Action-Hooks/blob/master/README.md#cpanel–plesk-login-button-in-my-services

    use WHMCS\Database\Capsule;

    add_hook(‘ClientAreaPage’, 1, function($vars)
    {
    if ($vars[‘filename’] == ‘clientarea’ AND $_GET[‘action’] == ‘services’ AND $_SESSION[‘uid’])
    {
    $productIDs = Capsule::select(Capsule::raw(‘SELECT t1.id, t2.type FROM tblhosting AS t1 LEFT JOIN tblservers AS t2 ON t1.server = t2.id WHERE t1.userid = ‘ . $_SESSION[‘uid’] . ‘ AND t1.server != “0” AND t1.domainstatus IN (“Active”, “Suspended”) AND t1.username != “” AND t1.password != “” AND t2.type != “”‘));

    foreach ($productIDs as $v)
    {
    $output[‘kt_autologin’][$v->id] = $v;
    }

    return $output;
    }
    elseif ($vars[‘filename’] == ‘clientarea’ AND $_GET[‘action’] == ‘productdetails’ AND $_GET[‘id’] AND $_GET[‘autologin’])
    {
    $product = Capsule::select(Capsule::raw(‘SELECT t2.type FROM tblhosting AS t1 LEFT JOIN tblservers AS t2 ON t1.server = t2.id WHERE t1.id = ‘ . $_GET[‘id’] . ‘ AND t1.server != “0” AND t1.domainstatus IN (“Active”, “Suspended”) AND t1.username IS NOT NULL AND t1.password IS NOT NULL AND t2.type IS NOT NULL LIMIT 1’))[0];

    switch ($product->type)
    {
    case ‘cpanel’: header(‘Location: clientarea.php?action=productdetails&id=’ . $_GET[‘id’] . ‘&dosinglesignon=1’); die(); break;
    }
    }
    });

    add_hook(‘ClientAreaHeadOutput’, 1, function($vars)
    {
    if ($vars[‘filename’] == ‘clientarea’ AND $_GET[‘action’] == ‘productdetails’ AND $_GET[‘id’] AND $_GET[‘autologin’])
    {
    return <<<HTML
    <style>
    body {
    visibility:hidden;
    }
    </style>
    <script type=”text/javascript”>
    $(document).ready(function() {
    $(“#domain form”).removeAttr(‘target’);
    $(“#domain form”).submit();
    });
    </script>
    HTML;
    }
    });

  • Cari file clientareaproducts.tpl pada folderwhmcs/templetes/{namafolder-template}/
    Note : jangan lupa backup file asli sebelum dilakukan editing
  • ganti isinya dengan kode berikut

    {include file=”$template/includes/tablelist.tpl” tableName=”ServicesList” filterColumn=”4″ noSortColumns=”0″}

    <script>
    jQuery(document).ready(function() {
    var table = jQuery(‘#tableServicesList’).show().DataTable();

    {if $orderby == ‘product’}
    table.order([1, ‘{$sort}’], [4, ‘asc’]);
    {elseif $orderby == ‘amount’ || $orderby == ‘billingcycle’}
    table.order(2, ‘{$sort}’);
    {elseif $orderby == ‘nextduedate’}
    table.order(3, ‘{$sort}’);
    {elseif $orderby == ‘domainstatus’}
    table.order(4, ‘{$sort}’);
    {/if}
    table.draw();
    jQuery(‘#tableLoading’).hide();
    });
    </script>

    <div class=”table-container clearfix”>
    <table id=”tableServicesList” class=”table table-list w-hidden”>
    <thead>
    <tr>
    <th></th>
    <th>{lang key=’orderproduct’}</th>
    <th>{lang key=’clientareaaddonpricing’}</th>
    <th>{lang key=’clientareahostingnextduedate’}</th>
    <th>{lang key=’clientareastatus’}</th>
    <th> Login Panel </th>
    </tr>
    </thead>
    <tbody>
    {foreach $services as $service}
    <tr onclick=”clickableSafeRedirect(event, ‘clientarea.php?action=productdetails&amp;id={$service.id}’, false)”>
    <td class=”py-0 text-center{if $service.sslStatus} ssl-info{/if}” data-element-id=”{$service.id}” data-type=”service”{if $service.domain} data-domain=”{$service.domain}”{/if}>
    {if $service.sslStatus}
    <img src=”{$service.sslStatus->getImagePath()}” data-toggle=”tooltip” title=”{$service.sslStatus->getTooltipContent()}” class=”{$service.sslStatus->getClass()}” width=”25″>
    {elseif !$service.isActive}
    <img src=”{$BASE_PATH_IMG}/ssl/ssl-inactive-domain.png” data-toggle=”tooltip” title=”{lang key=’sslState.sslInactiveService’}” width=”25″>
    {/if}
    </td>
    <td><strong>{$service.product}</strong>{if $service.domain}<br /><a href=”http://{$service.domain}” target=”_blank”>{$service.domain}</a>{else}<br />-{/if}</td>
    <td class=”text-center” data-order=”{$service.amountnum}”>{$service.amount} <small class=”text-muted”>{$service.billingcycle}</small></td>
    <td class=”text-center”><span class=”w-hidden”>{$service.normalisedNextDueDate}</span>{$service.nextduedate}</td>
    <td class=”text-center”><span class=”label status status-{$service.status|strtolower}”>{$service.statustext}</span></td>
    <td class=”text-center”>
    {if $kt_autologin[$service.id]}
    <div class=”btn-group btn-group-sm plesk-login” style=”width:60px;”>
    <a href=”clientarea.php?action=productdetails&id={$service.id}&autologin=1″ target=”_blank” class=”btn btn-primary btn-xs” alt=”Click to Login Panel” title=”Click to Login Panel” style=”padding: 2px 5px;”><i class=”fa fa-sign-in fa-fw” aria-hidden=”true”></i></a>
    </div>
    {/if}
    </td>
    </tr>

    {/foreach}
    </tbody>
    </table>
    <div class=”text-center” id=”tableLoading”>
    <p><i class=”fas fa-spinner fa-spin”></i> {lang key=’loading’}</p>
    </div>
    </div>

  • Kemudian Save
  • Dan lihat hasilnya

Selamat mencoba

  • Referensi :
    https://github.com/Katamaze/WHMCS-Action-Hook-Factory#cpanel–plesk-login-button-in-my-services

Leave a Reply

Your email address will not be published. Required fields are marked *