Here is my current version of ntozier's very useful script.

I removed his 'agency' lookup parts (since that's another mod, though I may reuse that for my own purposes later) and re-purposed the agency lookup code to do a department name lookup. Its crude, but it works for me:

<?php

/*********************************************************************

display_open_topics.php

Displays a block of the last X number of open tickets.

Neil Tozier <tmib@tmib.net>

Copyright (c) 2010-2013

For use with osTicket version 1.7ST (http://www.osticket.com)

Released under the GNU General Public License WITHOUT ANY WARRANTY.

See osTickets's LICENSE.TXT for details.

**********************************************************************/

# configure this area with your database connection information

$dbhost = 'localhost'; // FQDN server name or IP (or localhost for local machine)

$dbname = 'osticket'; // database name

$dbuser = 'osticket'; // database username

$dbpass = '<your db pass here>'; // database password for username (above)

# make the connection to the MySQL server

mysql_connect($dbhost,$dbuser,$dbpass);

<USERMENTION username="mysql_select_db">@mysql_select_db</USERMENTION>($dbname) or die( "DB Error: Unable to select database");

// The columns that you want to collect data for from the db

$columns = "ticketID, name, subject, created, updated, priority_id, dept_id";

// The maximum amount of open tickets that you want to display.

$limit ='10';

// mysql query. The columns tha

$query = "SELECT $columns

FROM ost_ticket

WHERE status = 'open'

ORDER BY created DESC

LIMIT 0,$limit";

$result=mysql_query($query);

$num = mysql_num_rows($result);

if ($num >> 0) {

// table headers, if you add or remove columns edit this

echo "<table border-color=#BFBFBF border=0 cell-spacing=2><tr style='background-color: #BFBFBF;'>";

echo "<td id='openticks-a'><b>Ticket #</b></td><td id='openticks-a'><b>Name</b></td><td id='openticks-a'><b>Issue</b></td><td id='openticks-a'><b>Opened on</b></td><td id='openticks-b'><b>Last Update</b></td><td id='openticks-b'><b>Department</b></td></tr>";

$i=0;

while ($i < $num) {

// You will need one line below for each column name that you collect and want to display.

// If you are unfamiliar with php its essentially $uniqueVariable = mysql junk ( columnName );

// Just copy one of the lines below and change the $uniqueVariable and columnName

$ticketid = mysql_result($result,$i,"ticketID");

$name = mysql_result($result,$i,"name");

$subject = mysql_result($result,$i,"subject");

$created = mysql_result($result,$i,"created");

$updated = mysql_result($result,$i,"updated");

$priority = mysql_result($result,$i,"priority_id");

$department_id = mysql_result($result,$i,"dept_id");

// if no update say so

if ($updated == '0000-00-00 00') {

$updated = 'no update yet';

}

// look up department and display proper name

// mysql query.

$getdept_names = "SELECT * FROM ost_department WHERE dept_id='$department_id'";

$deptresult = mysql_query($getdept_names);

$dept = mysql_result($deptresult,0,"dept_name");

// change row back ground color to make more readable

if(($i % 2) == 1) //odd

{$bgcolour = '#F6F6F6';}

else //even

{$bgcolour = '#FEFEFE';}

//populate the table with data

echo "<tr align=center><td BGCOLOR=$bgcolour id='openticks-a' nowrap> &nbsp; $ticketid &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a' nowrap> &nbsp; $name &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $subject ($priority) &nbsp; </td>"

."<td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $created &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-b'>"

." &nbsp; $updated &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $dept &nbsp; </td></tr>";

++$i;

}

echo "</table>";

}

else {

echo "<p style='text-align;'><span id='msg_warning'>There are no tickets open at this time.</span></p>";

}

?>

This spits out the table stand-alone, which means you can iFrame it into another website. It also displays the ticket# as well. I see that the dashboard links to the ticket_id (Which is *NOT* the ticket#), so I might even make it a dynamic link that someone can click to go right to the ticket.

OK well thank you both for your replies. I'll give this a go here in a bit and see. Thats why I'm confused though, queries run fine if I do them manually, but not getting any love when trying to in the live site so I'll take a look into it. Thanks for all your help

@[deleted]

I actually purposefully didn't include ticket #, since that's essentially one half of what someone needs to log into the system. I saw it as meaning that with a little bit of knowledge (such as a companies username schema) since it displays users names and with the ticket number anyone could log into the ticket system as that client and update their tickets, and cause general badness. Until osTicket actually has its own user authentication system for clients I felt it was to insecure for us. If you are utilizing osTicket for an closed intranet site its probably okay, but if its at all internet facing...

Sorry off the soap box :)

@[deleted]

Feel free to keep posting and we'll help you the ebst that we can. :)

ntozier,

I fully understand your concern. osTicket will be public, but this list will not be. We have an ancient, clunky, must-die-now order processing and ticket system, where the current tickets show up on the dashboard, just above the pending orders. I planned to embed this table there, since everyone in the company has that page up at all times. Its on a magnificently obfuscated url, behind a login page. Our current system doesn't show the TK#, so I might drop it, it was more an exercise for me to become familiar with it. I've tinkered a bit with PHP in the past, but never pulled SQL data using it.

chaosratt,

Ah okay, gotcha. That makes sense. I just want to make sure that people don't implement this sort of thing with out realizing the security implications because they read about it on osticket.com and didn't think about what it actually meant. :)

So since its not defined who does the queries run as? I guess maybe thats my problem is in my script there is no username or password designated for it to run as? Just a thought?

Presuming you didn't change anything from the last cut and paste its running as your osticket database user.

If you made the script stand alone by added the following:

# configure this area with your database connection information

$dbhost = 'localhost'; // FQDN server name or IP (or localhost for local machine)

$dbname = 'database'; // database name

$dbuser = 'dbusername'; // database username

$dbpass = 'dbpassword'; // database password for username (above)

# make the connection to the MySQL server

mysql_connect($dbhost,$dbuser,$dbpass);

<USERMENTION username="mysql_select_db">@mysql_select_db</USERMENTION>($dbname) or die( "DB Error: Unable to select database");

Then whatever user you specified.

Well I even tried chaosratt's script above, modified it with my info and still no dice. I'm not getting any php error logs generated, even though I've turned them all on it php.ini so I'm not sure. Guess I'll chalk it up as a loss and move on. Thanks

Have you made sure that you have the FAQ enabled, have at least 1 category *and* have at least 1 article? The table would not appear on the index until I did that.

With the edits in my version with the SQL info, you should be able to hit the php file directly in you browser.

Have you made sure that you have the FAQ enabled, have at least 1 category *and* have at least 1 article? The table would not appear on the index until I did that.

With the edits in my version with the SQL info, you should be able to hit the php file directly in you browser.

Yes I have a FAQ setup in the knowledgebase with a category and with an article and still no dice....

So its not out putting anything at all after the line that reads:

Be sure to browse both our Frequently Asked Questions (FAQs), and the open tickets below before opening a ticket..

Try this:

open and edit \index.php

scroll down and replace line 48-EOF

with this

<?php

if($cfg && $cfg->isKnowledgebaseEnabled()){

//FIXME: provide ability to feature or select random FAQs ??

?>

<p>Be sure to browse both our <a href="kb/index.php">Frequently Asked Questions (FAQs)</a>.

<?php

} ?>

<p>Please review the open tickets below before opening a ticket. Thank you.

<div id="openticks"><?php include('display_open_topics.php'); ?></div>

</p>

</div>

<?php require(CLIENTINC_DIR.'footer.inc.php'); ?>

This moves the table out of the FAQ section but still after that and inside the closing div. I've attached a zip with an alternate index.php so you can just drop it into place. You will have to rename index-alternate.php to index.php. Make sure that you back up your current index.php in case you want to revert to it.

[index-alternate.zip](https://forum.osticket.com/assets/files/migrated/a/d755474c24b2de82fcc4909c22c5982.zip)

Yes sir that worked like a charm! Thanks for all your help! I might modify it to add some different columns, but its showing up now. Thanks again!

last time......is there a way to display LOW, NORMAL, HIGH for priority instead of just a priority_id? I know the actual names for the priorities are stored in the ost_ticket_priority table. I tried making an IF statement, but it didn't work.

You could do something like this

if($priority_id == '1') {

$priority = 'Low';

}

if($priority_id == '2') {

$priority = 'Normal';

}

if($priority_id == '3') {

$priority = 'High';

}

if($priority_id == '4') {

$priority = 'Emergency';

}

echo $priority;

You could even echo that inside an img tag with appropriately named images and have it display small gifs and/or images.

You could do something like this

if($priority_id == '1') {

$priority = 'Low';

}

if($priority_id == '2') {

$priority = 'Normal';

}

if($priority_id == '3') {

$priority = 'High';

}

if($priority_id == '4') {

$priority = 'Emergency';

}

echo $priority;

Where would the IF statement go? I tried putting it in and its not doing anything.

I'd add it the block at about line 55 of the display_open_topics.php.

18 days later

I've made some changes that I'd like to contribute back to the group.

Note: This is embedded into our order processing control panel that only staff see, I would *NOT* recommend showing this to the public.

blank

<?php

/*********************************************************************

display_open_topics.php

Displays a block of the last X number of open tickets.

Neil Tozier <tmib@tmib.net>

Copyright (c) 2010-2013

For use with osTicket version 1.7ST (http://www.osticket.com)

Released under the GNU General Public License WITHOUT ANY WARRANTY.

See osTickets's LICENSE.TXT for details.

**********************************************************************/

# configure this area with your database connection information

$dbhost = 'localhost'; // FQDN server name or IP (or localhost for local machine)

$dbname = 'osticket'; // database name

$dbuser = 'osticket'; // database username

$dbpass = '<DBPASS>'; // database password for username (above)

# make the connection to the MySQL server

mysql_connect($dbhost,$dbuser,$dbpass);

<USERMENTION username="mysql_select_db">@mysql_select_db</USERMENTION>($dbname) or die( "DB Error: Unable to select database");

// The columns that you want to collect data for from the db

$columns = "ticket_id, ticketID, staff_id, name, subject, created, updated, priority_id, dept_id";

// The maximum amount of open tickets that you want to display.

$limit ='10';

// mysql query. The columns tha

$query = "SELECT $columns

FROM ost_ticket

WHERE status='open' AND dept_id != 3

ORDER BY created DESC

LIMIT 0,$limit";

$result=mysql_query($query);

$num = mysql_num_rows($result);

if ($num >> 0) {

// table headers, if you add or remove columns edit this

echo "<table width=890 border-color=#BFBFBF border=0 cell-spacing=2 style='font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: xx-small;'><tr style='background-color: #BFBFBF;' align=center>";

echo "<td id='openticks-a'><b>Priority</b></td><td id='openticks-a'><b>Name</b></td><td id='openticks-a'><b>Issue</b></td><td id='openticks-a'><b>Opened on</b></td><td id='openticks-b'><b>Last Update</b></td><td id='openticks-b'><b>Department</b></td><td id='openticks-b'><b>Assigned To</b></td></tr>";

$i=0;

while ($i < $num) {

// You will need one line below for each column name that you collect and want to display.

// If you are unfamiliar with php its essentially $uniqueVariable = mysql junk ( columnName );

// Just copy one of the lines below and change the $uniqueVariable and columnName

$ticket_id = mysql_result($result,$i,"ticket_ID");

$ticketid = mysql_result($result,$i,"ticketID");

$name = mysql_result($result,$i,"name");

$subject = mysql_result($result,$i,"subject");

$created = mysql_result($result,$i,"created");

$updated = mysql_result($result,$i,"updated");

$priority = mysql_result($result,$i,"priority_id");

$department_id = mysql_result($result,$i,"dept_id");

$staff_id = mysql_result($result,$i,"staff_id");

// if no update say so, and make the date format more human friendly

if ($updated == '0000-00-00 00')

{

$updated_date = 'No update yet';

}

else

{

$updated_date = date("d-m-y g", strtotime($updated));

}

//make the created date format more human friendly

$created_date = date("d-m-y g", strtotime($created));

// look up department and then cross refference to get department's name

$getdept_names = "SELECT * FROM ost_department WHERE dept_id='$department_id'";

$deptresult = mysql_query($getdept_names);

$dept = mysql_result($deptresult,0,"dept_name");

//look up the staff ID# and then cross reference it to get the staff member's name

$getstaff_names = "SELECT * FROM ost_staff WHERE staff_id='$staff_id'";

$staffresult = mysql_query($getstaff_names);

$staff = mysql_result($staffresult,0,"firstname");

// change row back ground color to make more readable

if(($i % 2) == 1) //odd

{$bgcolour = '#F6F6F6';}

else //even

{$bgcolour = '#FEFEFE';}

//populate the table with data

echo "<tr align=center><td BGCOLOR=$bgcolour id='openticks-a' nowrap><img src='priority/pr_$priority.gif'></td>"

."<td BGCOLOR=$bgcolour id='openticks-a' nowrap> &nbsp; $name &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a'>&nbsp;<a href='http://support.coolgear.com/scp/tickets.php?id=$ticket_id' target='_blank'>$subject</a>&nbsp;</td>"

."<td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $created_date &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-b'>"

." &nbsp; $updated_date &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $dept &nbsp; </td>"

."<td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $staff &nbsp; </td></tr>";

++$i;

}

echo "</table>";

}

else {

echo "<p style='text-align;'><span id='msg_warning'>There are no tickets open at this time.</span></p>";

}

?>

a month later

I've made some changes that I'd like to contribute back to the group.

Note: This is embedded into our order processing control panel that only staff see, I would *NOT* recommend showing this to the public.

blank

<?php

/*********************************************************************

display_open_topics.php

Displays a block of the last X number of open tickets.

Neil Tozier <tmib@tmib.net>

Copyright (c) 2010-2013

For use with osTicket version 1.7ST (http://www.osticket.com)

Released under the GNU General Public License WITHOUT ANY WARRANTY.

See osTickets's LICENSE.TXT for details.

**********************************************************************/

# configure this area with your database connection information

$dbhost = 'localhost'; // FQDN server name or IP (or localhost for local machine)

$dbname = 'osticket'; // database name

$dbuser = 'osticket'; // database username

$dbpass = '<DBPASS>'; // database password for username (above)

# make the connection to the MySQL server

mysql_connect($dbhost,$dbuser,$dbpass);

<USERMENTION username="mysql_select_db">@mysql_select_db</USERMENTION>($dbname) or die( "DB Error: Unable to select database");

// The columns that you want to collect data for from the db

$columns = "ticket_id, ticketID, staff_id, name, subject, created, updated, priority_id, dept_id";

// The maximum amount of open tickets that you want to display.

$limit ='10';

// mysql query. The columns tha

$query = "SELECT $columns

FROM ost_ticket

WHERE status='open' AND dept_id != 3

ORDER BY created DESC

LIMIT 0,$limit";

$result=mysql_query($query);

$num = mysql_num_rows($result);

if ($num >> 0) {

// table headers, if you add or remove columns edit this

echo "<table width=890 border-color=#BFBFBF border=0 cell-spacing=2 style='font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: xx-small;'><tr style='background-color: #BFBFBF;' align=center>";

echo "<td id='openticks-a'><b>Priority</b></td><td id='openticks-a'><b>Name</b></td><td id='openticks-a'><b>Issue</b></td><td id='openticks-a'><b>Opened on</b></td><td id='openticks-b'><b>Last Update</b></td><td id='openticks-b'><b>Department</b></td><td id='openticks-b'><b>Assigned To</b></td></tr>";

$i=0;

while ($i < $num) {

// You will need one line below for each column name that you collect and want to display.

// If you are unfamiliar with php its essentially $uniqueVariable = mysql junk ( columnName );

// Just copy one of the lines below and change the $uniqueVariable and columnName

$ticket_id = mysql_result($result,$i,"ticket_ID");

$ticketid = mysql_result($result,$i,"ticketID");

$name = mysql_result($result,$i,"name");

$subject = mysql_result($result,$i,"subject");

$created = mysql_result($result,$i,"created");

$updated = mysql_result($result,$i,"updated");

$priority = mysql_result($result,$i,"priority_id");

$department_id = mysql_result($result,$i,"dept_id");

$staff_id = mysql_result($result,$i,"staff_id");

// if no update say so, and make the date format more human friendly

if ($updated == '0000-00-00 00')

{

$updated_date = 'No update yet';

}

else

{

$updated_date = date("d-m-y g", strtotime($updated));

}

//make the created date format more human friendly

$created_date = date("d-m-y g", strtotime($created));

// look up department and then cross refference to get department's name

$getdept_names = "SELECT * FROM ost_department WHERE dept_id='$department_id'";

$deptresult = mysql_query($getdept_names);

$dept = mysql_result($deptresult,0,"dept_name");

//look up the staff ID# and then cross reference it to get the staff member's name

$getstaff_names = "SELECT * FROM ost_staff WHERE staff_id='$staff_id'";

$staffresult = mysql_query($getstaff_names);

$staff = mysql_result($staffresult,0,"firstname");

// change row back ground color to make more readable

if(($i % 2) == 1) //odd

{$bgcolour = '#F6F6F6';}

else //even

{$bgcolour = '#FEFEFE';}

//populate the table with data

echo "<tr align=center><td BGCOLOR=$bgcolour id='openticks-a' nowrap><img src='priority/pr_$priority.gif'></td>"

."<td BGCOLOR=$bgcolour id='openticks-a' nowrap> &nbsp; $name &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a'>&nbsp;<a href='http://support.coolgear.com/scp/tickets.php?id=$ticket_id' target='_blank'>$subject</a>&nbsp;</td>"

."<td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $created_date &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-b'>"

." &nbsp; $updated_date &nbsp; </td><td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $dept &nbsp; </td>"

."<td BGCOLOR=$bgcolour id='openticks-a'> &nbsp; $staff &nbsp; </td></tr>";

++$i;

}

echo "</table>";

}

else {

echo "<p style='text-align;'><span id='msg_warning'>There are no tickets open at this time.</span></p>";

}

?>

@[deleted] your idea is cool, could you add some html specific like charset to support UTF-8 for international language

a month later

@chaosratt your idea is cool, could you add some html specific like charset to support UTF-8 for international language

I'm afraid my knowledge of HTML is quite limited. I simply took what I knew and modified ntozier's script to fit my needs.