Jump to content

How can I show a list of open support tickets on other template pages?


paperweight

Recommended Posts

I am really frustrated trying to figure out how to combine 2 templates in my theme into one. I want to put the list of support tickets found on supportticketslist.tpl at the bottom of the page of supportticketsubmit-stepone.tpl.

 

When I copy the content of supportticketslist.tpl and paste it into supportticketsubmit-stepone.tpl, almost all the code displays fine. However, the list of tickets is not there. Instead it says "No Records Found" even though there are tickets available! So I think the atabase is not being queried correctly when I remove code from supportticketslist.tpl and place it elsewhere, correct?

 

Is there something I am missing that I should wrap around this code to make it work?

Link to comment
Share on other sites

  • 1 year later...

But why there's this then?

 

How to define template variables ($ca->assign)

And how to set the template to use and then output it

 

There's no way to use something like $ca->assign('ticket', $ticket); then output it? (Tried this, didn't work. Maybe something similar?)

 

:/

Link to comment
Share on other sites

Are you trying to add $ca->assign('ticket', $ticket); inside the .tpl file? This piece of code is not Smarty, it's PHP in OOP. You should use {php}{/php} tag but i'm not sure of what you are trying to do with this. Can you please post the code that you are using now?

Link to comment
Share on other sites

open-tickets.php

 

 <?php

define("CLIENTAREA",false);

require("init.php");
include("includes/functions.php");

$ca = new WHMCS_ClientArea();

$ca->setPageTitle($whmcs->get_lang('opentiketstitle'));

$ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname'));
$ca->addToBreadCrumb('support-tickets.php',$whmcs->get_lang('opentiketstitle'));

$ca->initPage();

$ca->requireLogin(); // Uncomment this line to require a login to access this page


$ca->setTemplate('open-tickets');

$ca->output();

?>

 

open-tickets.tpl

<h1>{$LANG.ticketsabertostitle}</h1>



<div class="table_title opentickets" style="margin-top:20px;">
 <span class="icon"></span>
 <a class="btn btn-primary pull-right" href="submitticket.php">{$LANG.opennewticket}</a>
 <h3><strong>{$clientsstats.numactivetickets}</strong>  {$LANG.supportticketsopentickets}</h3>
</div>
<table class="table table-striped table-framed table-centered no-more-tables">
 <thead>
   <tr>
     <th><a href="supporttickets.php?orderby=date">{$LANG.supportticketsdate}</a></th>
     <th><a href="supporttickets.php?orderby=dept">{$LANG.supportticketsdepartment}</a></th>
     <th><a href="supporttickets.php?orderby=subject">{$LANG.supportticketssubject}</a></th>
     <th><a href="supporttickets.php?orderby=subject">{$LANG.supportticketsstatus}</a></th>
     <th class="headerSortdesc"><a href="supporttickets.php?orderby=lastreply">{$LANG.supportticketsticketlastupdated}</a></th>
     <th></th>
   </tr>
 </thead>
 <tbody>
 {foreach from=$tickets item=ticket}
   <tr>
     <td data-title="{$LANG.supportticketsdate}">{$ticket.date}</td>
     <td data-title="{$LANG.supportticketsdepartment}">{$ticket.department}</td>
     <td data-title="{$LANG.supportticketssubject}"><div align="left"><img src="images/article.gif" alt="Ticket" border="0" /> <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></div></td>
     <td data-title="{$LANG.supportticketsstatus}">{$ticket.status}</td>
     <td data-title="{$LANG.supportticketsticketlastupdated}">{$ticket.lastreply}</td>
     <td class="last textcenter"><a href="viewticket.php?tid={$ticket.tid}&c={$ticket.c}" class="btn btn-inverse">{$LANG.supportticketsviewticket}</a></td>
   </tr>  
 {foreachelse}
   <tr>
     <td colspan="6" class="textcenter">{$LANG.supportticketsnoneopen}</td>
   </tr>
 {/foreach}
 </tbody>
</table>  

 

Output:

Untitled-1 (1).jpg

Link to comment
Share on other sites

It doesn't work because you are trying to load a non-existing variable. When you reference to {$ticket.subject} inside your open-tickets.tpl, Smarty will try to get this variable from open-tickets.php. Here i can see that there's just the framework and nothing more. Take a look at this example and read comments.

 

open-tickets.php

<?php

define("CLIENTAREA",false);
require("init.php");
include("includes/functions.php");

$ca = new WHMCS_ClientArea();
$ca->setPageTitle($whmcs->get_lang('opentiketstitle'));
$ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname'));
$ca->addToBreadCrumb('support-tickets.php',$whmcs->get_lang('opentiketstitle'));
$ca->initPage();
$ca->requireLogin();

// I don't know the values that you are trying to get from database so change this query accordingly
$result = mysql_query("SELECT name, lastname FROM clients WHERE clientid='1'");
$row = mysql_fetch_array($result); # Let's say that $row["name"] is equal to "James" and $row["lastname"] is "Bond"

// If the result is not empty i create 'name' and 'lastname' Smarty value
if($row)
{
$ca->assign('name', $row["name"]); # {$name} contains "James"
$ca->assign('lastname', $row["lastname"]); # {$lastname} contains "Bond"
}

$ca->setTemplate('open-tickets');
$ca->output();

?>

 

open-tickets.tpl

 

<p>Hey baby... i'm {$name}, {$name} {$lastname}</p>

 

It prints out "Hey baby... i'm James, James Bond". Now 3 notes about this script:

 

  1. First of all the MySQL API (aka library). In my example i was using MySQL library just because it's faster to write :-P You should use PDO (Prepared Statements) or MySQLi because of this reason. You could also use SQL_Helper_Functions of WHMCS but they're not confortable to use.
  2. About arrays. In the example i assigned two separate values ({$name} and {$lastname}) but you can still use arrays. With $ca->assign('clientdetails', $row) for example you can print "James" with {$clientdetails.name} and "Bond" with {$clientdetails.lastname}. I hope that it's clear enough.
  3. Of course you can use while(); foreach(); (...) loops and $ca->assign(); inside the iteration.

 

I know that this argument could be tricky especially if you are not a developer but if you are it's easy.

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