payless4domains Posted July 12, 2018 Share Posted July 12, 2018 Hi Guys, I would like to merge the clientareaemails.tpl and the supportticketlist.tpl template together into a new template messages.tpl. I have the fundamentals, but can't work out the email and tickets list hook/s. Messages.php (root directory) <?php use WHMCS\ClientArea; use WHMCS\Database\Capsule; define('CLIENTAREA', true); define("FORCESSL", true); // Uncomment to force the page to use https:// require __DIR__ . '/init.php'; $ca = new ClientArea(); $ca->setPageTitle("Messages"); $ca->addToBreadCrumb('index.php', $whmcs->get_lang('globalsystemname')); $ca->addToBreadCrumb('messages.php'); $ca->initPage(); $ca->requireLogin(); // Uncomment this line to require a login to access this page # To assign variables to the template system use the following syntax. # These can then be referenced using {$variablename} in the template. $ca->assign('variablename', $value); # Check login status if ($ca->isLoggedIn()) { # User is logged in - put any code you like here # Here's an example to get the currently logged in clients first name $result = mysql_query("SELECT firstname FROM tblclients WHERE id=" . $ca->getUserID()); $data = mysql_fetch_array($result); $clientname = $data[0]; $ca->assign('clientname', $clientname); } else { # User is not logged in } # Define the template filename to be used without the .tpl extension $ca->setTemplate('messages'); $ca->output(); messages.tpl (template directory) <div class="header-lined"> <h1 style="text-align:center;">My messages</h1> </div> {include file="$template/includes/tablelist.tpl" tableName="TicketsList" filterColumn="2"} <script type="text/javascript"> jQuery(document).ready( function () { var table = $('#tableTicketsList').DataTable(); {if $orderby == 'did' || $orderby == 'dept'} table.order(0, '{$sort}'); {elseif $orderby == 'subject' || $orderby == 'title'} table.order(1, '{$sort}'); {elseif $orderby == 'status'} table.order(2, '{$sort}'); {elseif $orderby == 'lastreply'} table.order(3, '{$sort}'); {/if} table.draw(); }); </script> <div class="table-container clearfix"> <table id="tableTicketsList" class="table table-list"> <thead> <tr> <th>{$LANG.supportticketsdepartment}</th> <th>{$LANG.supportticketssubject}</th> <th>{$LANG.supportticketsstatus}</th> <th>{$LANG.supportticketsticketlastupdated}</th> </tr> </thead> <tbody> {foreach from=$tickets item=ticket} <tr onclick="window.location='viewticket.php?tid={$ticket.tid}&c={$ticket.c}'"> <td class="text-center">{$ticket.department}</td> <td><a href="viewticket.php?tid={$ticket.tid}&c={$ticket.c}">{if $ticket.unread}<strong>{/if}#{$ticket.tid} - {$ticket.subject}{if $ticket.unread}</strong>{/if}</a></td> <td><span class="label status {if is_null($ticket.statusColor)}status-{$ticket.statusClass}"{else}status-custom" style="border-color: {$ticket.statusColor}; color: {$ticket.statusColor}"{/if}>{$ticket.status|strip_tags}</span></td> <td class="text-center"><span class="hidden">{$ticket.normalisedLastReply}</span>{$ticket.lastreply}</td> </tr> {/foreach} </tbody> </table> </div> <div class="header-lined"> <h1 style="text-align:center;">Email history</h1> </div> {include file="$template/includes/tablelist.tpl" tableName="EmailsList" noSortColumns="-1"} <script type="text/javascript"> jQuery(document).ready( function () { var table = $('#tableEmailsList').DataTable(); {if $orderby == 'date'} table.order(0, '{$sort}'); {elseif $orderby == 'subject'} table.order(1, '{$sort}'); {/if} table.draw(); }); </script> <div class="table-container clearfix"> <table id="tableEmailsList" class="table table-list"> <thead> <tr> <th>Date</th> <th>Subject</th> <th> </th> </tr> </thead> <tbody> {foreach from=$emails item=email} <tr onclick="popupWindow('viewemail.php?id={$email.id}', 'emailWin', '650', '450')"> <td class="text-center"><span class="hidden">{$email.normalisedDate}</span>{$email.date}</td> <td>{$email.subject}</td> <td class="text-center"><input type="button" class="btn btn-primary btn-sm" value="View" onclick="popupWindow('viewemail.php?id={$email.id}', 'emailWin', '650', '450')" /></td> </tr> {/foreach} </tbody> </table> </div> emaillist.php / ticketslist.php (hooks directory) - doesn't work <?php # Credit Logs For Client Area # Written by brian! use Illuminate\Database\Capsule\Manager as Capsule; function hook_client_emails($vars) { $client = Menu::context('client'); $emails = Capsule::table('tblEmailsList') ->where('clientid', $client->id) ->get(); $encodedata = json_encode($emails); $decodedata = json_decode($encodedata, true); return array("emails" => $decodedata); } add_hook("ClientAreaPage", 1, "hook_client_emails"); ?> <?php # Credit Logs For Client Area # Written by brian! use Illuminate\Database\Capsule\Manager as Capsule; function hook_client_tickets($vars) { $client = Menu::context('client'); $tickets = Capsule::table('tbltickets') ->where('clientid', $client->id) ->get(); $encodedata = json_encode($tickets); $decodedata = json_decode($encodedata, true); return array("tickets" => $decodedata); } add_hook("ClientAreaPage", 1, "hook_client_tickets"); ?> Any help would be appreciated. Thanks in advance. Kev 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted July 12, 2018 Share Posted July 12, 2018 (edited) The first hook is strange. What is tblEmailsList? There isn't any table in WHMCS with this name. This should work. function hook_client_emails($vars) { $client = Menu::context('client'); $emails = Capsule::table('tblemails') ->where('userid', $client->id) ->get(); $encodedata = json_encode($emails); $decodedata = json_decode($encodedata, true); return array("emails" => $decodedata); } add_hook("ClientAreaPage", 1, "hook_client_emails"); I replaced your table with tblemails and clientid with userid in where condition. Edited July 12, 2018 by Kian 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 12, 2018 Share Posted July 12, 2018 17 hours ago, Kian said: The first hook is strange. What is tblEmailsList? There isn't any table in WHMCS with this name. i've no idea - I didn't write that hook (despite what it says in the header!) 0 Quote Link to comment Share on other sites More sharing options...
payless4domains Posted July 12, 2018 Author Share Posted July 12, 2018 Thankyou Kian and yes that worked for the emails including all values, can't believe I missed that. Cheers I also changed the 'clientid' to 'userid' and now the tickets hook is working, but the values (under debug) are different to the original supportticketlist.tpl Original values id => "78" tid => "986161" c => "EOoxJKPr" date => "07/07/2016 10:05" normalisedDate => "2016-07-07 10:05:20" department => "Customer Care" subject => "test" status => "<span style="color:#888888">Closed</s..." statusClass => "closed" statusColor => null urgency => "Medium" lastreply => "07/07/2016 10:09" normalisedLastReply => "2016-07-07 10:09:24" unread => "0" new hook values id => 78 tid => "986161" did => 1 userid => 1 contactid => 0 name => "" email => "" cc => "" c => "EOoxJKPr" date => "2016-07-07 10:05:20" title => "test" message => "test ---------------------------- IP..." status => "Closed" urgency => "Medium" admin => "" attachment => "" lastreply => "2016-07-07 10:09:24" flag => 0 clientunread => 0 adminunread => "1" replyingadmin => 0 replyingtime => "0000-00-00 00:00:00" service => "S489" So it is displaying slightly different to the original, how do I get the values to be the same as the original? So the table shows all the info not just parts. <?php # Credit Logs For Client Area # Written by brian! use Illuminate\Database\Capsule\Manager as Capsule; function hook_client_tickets($vars) { $client = Menu::context('client'); $tickets = Capsule::table('tbltickets') ->where('userid', $client->id) ->get(); $encodedata = json_encode($tickets); $decodedata = json_decode($encodedata, true); return array("tickets" => $decodedata); } add_hook("ClientAreaPage", 1, "hook_client_tickets"); ?> I'm guessing that this part of the hook needs to be changed to ?? $encodedata = json_encode($tickets); $decodedata = json_decode($encodedata, true); return array("tickets" => $decodedata); Thanks in advance. 0 Quote Link to comment Share on other sites More sharing options...
payless4domains Posted July 12, 2018 Author Share Posted July 12, 2018 12 minutes ago, brian! said: i've no idea - I didn't write that hook (despite what it says in the header!) Sorry Brian, the original hook was written by you (your credit logs hook) which works great as all of your suggestions are, your brilliant. I'm only learning. The not so good tweaks are my doing. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.