Jump to content

Display user's tickets using a hook


Dimitra

Recommended Posts

Hello,

I want to display a user's recent support tickets in some client area pages. I have created a hook following the instructions here and changes the variables. The hook works fine and it displays the results I need. However, it displays the recent tickets of all users.

 

here is my code

<?php

function hook_displaysupporttickets($vars){

$output = "";
$query = "SELECT * FROM tbltickets ORDER BY date DESC LIMIT 0,6"; 
$result = mysql_query($query);
while ($data = mysql_fetch_array($result)) {
   $tid = $data["tid"];
   $date = $data["date"];
   $replyid = $data["replyid"];
   $title = $data["title"];
   $department = $data["department"];
   $date = fromMySQLDate($date);
   $output .= '<p class="mytitleannoun"><i class="fa fa-file-text-o" aria-hidden="true" style="margin-right:15px;"></i><a style="margin-right:15px;" href="/viewticket.php?tid='.$tid.'">'.$title.'</a><span>'.$department.'</span><span>'.$tid.'</span><font color="#b3b3b3">'.$date.'</font></p>';
}
return array("displaysupporttickets" => $output);
}
add_hook("ClientAreaPage", 1, "hook_displaysupporttickets");

 

I need to change the code so that it displays only the tickets of the logged in user (each user will see only his own tickets).

Any ideas?

 

Thank you.

Link to comment
Share on other sites

you should just need to add the code to access the clients ID and then add that to your query...

 

<?php

function hook_displaysupporttickets($vars){

   $client = Menu::context('client');

   $output = "";
   $query = "SELECT * FROM tbltickets WHERE userid = $client->id ORDER BY date DESC LIMIT 0,6"; 
   $result = mysql_query($query);
   while ($data = mysql_fetch_array($result)) {
       $tid = $data["tid"];
       $date = $data["date"];
       $replyid = $data["replyid"];
       $title = $data["title"];
       $department = $data["department"];
       $date = fromMySQLDate($date);
       $output .= '<p class="mytitleannoun"><i class="fa fa-file-text-o" aria-hidden="true" style="margin-right:15px;"></i><a style="margin-right:15px;" href="/viewticket.php?tid='.$tid.'">'.$title.'</a><span>'.$department.'</span><span>'.$tid.'</span><font color="#b3b3b3">'.$date.'</font></p>';
   }
   return array("displaysupporttickets" => $output);
}

add_hook("ClientAreaPage", 1, "hook_displaysupporttickets"); 

though bear in mind that mysql_query will be removed from WHMCS at some point - so it will still work for now, but ultimately you'll need to rewrite this using Capsule... untested, but probably along the lines of...

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_displaysupporttickets($vars){

   $client = Menu::context('client');
   $output = "";

   $tickets = Capsule::table('tbltickets')
                   ->where('userid', $client->id)
                   ->orderBy('date', 'desc')
                   ->take(6)
                   ->get();

   foreach ($tickets as $ticket) {    
       $output .= '<p class="mytitleannoun"><i class="fa fa-file-text-o" aria-hidden="true" style="margin-right:15px;"></i><a style="margin-right:15px;" href="/viewticket.php?tid='.$ticket->tid.'">'.$ticket->title.'</a><span>'.$ticket->department.'</span><span>'.$ticket->tid.'</span><font color="#b3b3b3">'.fromMySQLDate($ticket->date).'</font></p>';
   }

   return array("displaysupporttickets" => $output);
}

add_hook("ClientAreaPage", 1, "hook_displaysupporttickets");

your path to viewticket may not be correct, but I guess will likely depend on which pages are going to use this code...

Link to comment
Share on other sites

Both solutions work great. I kept the second one with Capsule.

a wise choice. :)

 

I have another question. Is there a place where i can find the variables that are used? eg the ticketid, userid etc. I am looking for a table similar to this one

when you're querying a database table, these variables are the column headings of the table...

 

ivvHbVr.png

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.

×
×
  • 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