- Edited
Sorry, looks like the while loop in the function was missing a {
while ($row = db_fetch_array($res))
needs to be:
while ($row = db_fetch_array($res)) {
Sorry, looks like the while loop in the function was missing a {
while ($row = db_fetch_array($res))
needs to be:
while ($row = db_fetch_array($res)) {
almost!
Everything seems to be working fine until I attempt to update on include/staff/viewticket.inc.php. I get the "You must select an action to perform" message.
Can you right click on that page, select view source, and PM me the source code so I can determine what is causing the issue?
PM sent...............
booyah
Okay, everything is working as expected. I'll update post #8 this evening when I get a chance.
This looks really good. Tried the steps in post 8 only. Something is not quite right though, no tickets display at all if i enable
$status_arr = array("Reviewed",'"Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");
in tickets.inc.php
before i try to figure it out i'll wait for your update and start again :)
There was an errant single quote in that line...Between "Reviewed" and "Responded". Sorry bout' that, fix'd.
$status_arr = array("Reviewed","Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");
Complete Simple Status Mod (page 1)
Here are the compiled COMPLETE instructions on how-to implement the Simple Status Addon.
1. Create a new column on the ost_ticket table. I named my column "work". You'll need access to PhpMyAdmin or a similar database management program.
ALTER TABLE ost_ticket ADD COLUMN work int;
includes/class.ticket.php
2.Find this code
class Ticket{
3.Add this code directly below it
var $work;
4. Find this code
//echo $sql;
if(($res=db_query($sql)) && db_num_rows($res)):
$row=db_fetch_array($res);
5. Add this code directly below it
$this->work =$row;
6. Find this code
//GET
7. Add this code directly below it
function setSimpleStatus($status_val){
$status_val = (int) $status_val; // only allowed to use int
// you can add an error check and message here if you want
$sql = 'UPDATE ' . TICKET_TABLE . ' SET work=' .
db_input($status_val) . ' WHERE ' .
'ticket_id='.db_input($this->getId());
db_query($sql);
}
function getSimpleStatus() {
return $this->work;
}
Done with includes/class.ticket.php.
staff/viewticket.inc.php
1. At the very top of the file, directly beneath <?php add this code
function showOptionsDrop($selected){ // shows all options but selected...
$string = '';
$status_arr = array("Reviewed","Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");
foreach($status_arr as $k=>$v){
if($selected == $k) // don't double display the selected option
$string .= '<option selected value="'.$k.'">'.$v.'</option>'."\n";
else
$string .= '<option value="'.$k.'">'.$v.'</option>'."\n";
}
return $string;
}
2. Find this code
3. Directly beneath it add this code
<tr>
<th>Status:</th>
<td>
<form method="POST" action="" name="update">
<input type="hidden" name="a" value="process">
<input type="hidden" name="do" value="set_simple_status">
<select name="updatework" width="150" style="width: 150px">
<?php echo showOptionsDrop($ticket->getSimpleStatus()); ?>
</select>
<input type="submit" value="update" class="button">
</form>
</td>
</tr>
Done with staff/viewticket.inc.php
scp/tickets.php
1. Find this code
switch(strtolower($_POST)):
2. Directly below it add this code
case 'set_simple_status':
if(!$thisuser->canManageTickets()){
$errors='Perm. Denied. You are not allowed change the RMA status.';
}
if(!$errors)
$ticket->setSimpleStatus($_POST);
break;
Done with scp/tickets.php.
Now, wouldn't it be great if that same status were reflected on the staff/tickets.inc.php?
staff/tickets.inc.php
1. Find this code
$qselect = 'SELECT ticket.ticket_id,ticket.ticketID,ticket.dept_id,isanswered,ispublic,subject,name,email '.
We'll need to add our column to the $qselect, mine is called "work" so I'll add it inbetween name and email, like this....
$qselect = 'SELECT ticket.ticket_id,ticket.ticketID,ticket.dept_id,isanswered,ispublic,subject,name,work,email '.
2. Next we'll add a new header to the table. I called mine "Progress".
Find this code...
FROM
Directly beneath, add this code...
Progress
3. Now we will display the status. At the very top of the page, below the very first <?PHP , add this code...
$status_arr = array("Reviewed","Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");
Then Find this code...
<td nowrap><?=Format:($row,22,strpos($row,'@'))?> </td>
Directly below, add this code...
<td nowrap >
<?=$status_arr[$row;?>
</td>
All done, now we have Simple status displaying in staff/tickets.inc.php, MOD completed in next post.
Simple Status MOD (Page 2)
Now, lets create a way to enter new statuses into the database, then populate our status dropdown with the new statuses that we entered!
First, we add a table to list our status, once again youll need access to PHPMyAdmin or a similar database management software:
mysql> use osticket;
mysql> create table ost_status (status_id int auto_increment, status_name varchar(255), primary key(status_id));
In main.inc.php:
After:
define('GROUP_TABLE',TABLE_PREFIX.'groups');
Add:
define('STATUS_TABLE',TABLE_PREFIX.'status');
In include/class.nav.php:
After:
$tabs=array('desc'=>'Departments','href'=>'admin.php?t=depts','title'=>'Departments');
Add:
$tabs=array('desc'=>'Statuses','href'=>'admin.php?t=status','title'=>'Statuses');
In css/main.css
After:
#container {
Change the next line to this:
width;
In /scp/admin.php:
After:
$errors='No users selected.';
}
break;
default:
$errors='Uknown command!';
}
break;
Add:
case 'status':
$do=strtolower($_POST);
switch($do) {
case 'add_status':
// db field is 255 chars max
$status_name = substr($_POST, 0, 255);
$sql = 'INSERT INTO ' . STATUS_TABLE .
'(status_name) VALUES ('
.db_input($status_name) . ')';
echo $sql;
db_query($sql);
$msg = "Successfully added status.";
break;
case 'mass_process':
foreach($_POST as $id) {
$sql = 'SELECT * FROM ' . TICKET_TABLE .
' WHERE work=' . db_input($id);
$res = db_query($sql);
if(db_num_rows($res) != 0) {
$errors='Could not remove one or more'
. ' statuses because a ticket is currently ' .
'assigned that status.';
} else {
$sql = 'DELETE FROM ' . STATUS_TABLE .
' WHERE status_id='. db_input($id);
db_query($sql);
$msg = 'Status/Statuses Deleted';
}
}
break;
}
break;
After:
$page='syslogs.inc.php';
break;
Add:
// add
case 'status':
$page = 'statuses.inc.php';
$nav->setTabActive('status');
$nav->addSubMenu(
array('desc'=>'Statuses',
'href'=>'admin.php?t=status',
'iconclass'=>'preferences'));
break;
Add the following file:
include/staff/statuses.inc.php
With the contents:
<?php
if(!defined('OSTADMININC') || !$thisuser->isadmin()) die('Access Denied');
//List all statuses
$sql='SELECT status_name, status_id FROM ' . STATUS_TABLE;
$statuses = db_query($sql);
?>
<div class="msg">Statuses</div>
<table width="100%" border="0" cellspacing=0 cellpadding=0>
<form action="admin.php?t=status" method="POST" name="status" onSubmit="return checkbox_checker(document.forms,1,0);">
<input type='hidden' name='t' value='status'>
<input type=hidden name='do' value='mass_process'>
<tr><td>
<table border="0" cellspacing=0 cellpadding=2 class="dtable" align="center" width="100%">
<tr>
<th width="7px"> </th>
<th>Status Name</th>
</tr>
<?
$class = 'row1';
$total=0;
$ids=($errors && is_array($_POST))?$_POST;
if($statuses && db_num_rows($statuses)):
while ($row = db_fetch_array($statuses)) {
$sel=false;
if($ids && in_array($row,$ids)){
$class="$class highlight";
$sel=true;
}
?>
<tr class="<?=$class?>" id="<?=$row?>">
<td width=7px>
<input type="checkbox" name="ids" value="<?=$row?>" <?=$sel?'checked':''?>
<?php echo " onClick=\"highLight(this.value,this.checked);\">";?>
<td><a href="admin.php?t=status&id=<?=$row?>"><?=Format:($row)?></a></td>
</tr>
<?
$class = ($class =='row2') ?'row1':'row2';
} //end of while.
else: ?>
<tr class="<?=$class?>"><td colspan=6><b>Query returned 0 results</b></td></tr>
<?
endif; ?>
</table>
</td></tr>
<?
if(db_num_rows($statuses)>0): //Show options..
?>
<tr>
<td style="padding-left">
Select:
<a href="#" onclick="return select_all(document.forms,true)">All</a>
<a href="#" onclick="return reset_all(document.forms)">None</a>
<a href="#" onclick="return toogle_all(document.forms,true)">Toggle</a>
</td>
</tr>
<tr>
<td align="center">
<input class="button" type="submit" name="delete" value="Delete Selected Statuses?"
onClick=' return confirm("Are you sure you want to DELETE selected statuses?");'>
</td>
</tr>
<?
endif;
?>
</form>
<tr><td> </td></tr><tr>
<td align="center">
<form action="admin.php?t=email" method="POST" name="status">
<input type='hidden' name='t' value='status'>
<input type=hidden name='do' value='add_status'>
<input type=text name='status_name'>
<input class="button" type="submit" name="delete" value="Add Status">
</form>
</td>
</table>
Then you'll have to change the showOptionsDrop in staff/viewticket.php:
Code:
function showOptionsDrop($selected){ // shows all options but selected...
$string = '';
$sql = 'SELECT * FROM ' . STATUS_TABLE;
$res = db_query($sql);
while ($row = db_fetch_array($res)) {
$k = $row;
$v = $row;
if($selected == $k) // don't double display the selected option
$string .= '<option selected value="'.$k.'">'.$v.'</option>'."\n";
else
$string .= '<option value="'.$k.'">'.$v.'</option>'."\n";
}
return $string;
}
To allow editing of statuses, complete the following instructions:
in /scp/admin.php:
After:
case 'status':
$do=strtolower($_POST);
switch($do) {
Add:
case 'rename_status':
$status_name = substr($_POST, 0, 255);
$sql = 'UPDATE ' . STATUS_TABLE .
' SET status_name=' . db_input($status_name) .
' WHERE status_id=' . (int) $_POST;
//echo $sql;
db_query($sql);
$msg = "Successfully edited status.";
break;
>>
Simple Status MOD (Page 3)
************************************************** *******
After:
case 'syslog':
$nav->setTabActive('dashboard');
$nav->addSubMenu(array('desc'=>'System Logs','href'=>'admin.php?t=syslog','iconclass'=>'syslogs'));
$page='syslogs.inc.php';
break;
Change the status case to this:
case 'status':
if(isset($_REQUEST)) {
$page='status.inc.php';
} else {
$page='statuses.inc.php';
}
$nav->setTabActive('status');
$nav->addSubMenu(array('desc'=>'Statuses','href'=>'admin.php?t=status','iconclass'=>'preferences'));
break;
Add the following file:
/include/staff/status.inc.php:
<?php
if(!defined('OSTADMININC') || basename($_SERVER)==basename(__FILE__)) die('Habari/Jambo rafiki? '); //Say hi to our friend..
if(!$thisuser || !$thisuser->isadmin()) die('Access Denied');
$status = db_query('SELECT status_id, status_name FROM '. STATUS_TABLE . ' WHERE status_id = ' . (int)$_REQUEST . ' LIMIT 1');
$info = db_fetch_array($status);
$qstr = '?t=status&id=' . (int)$info;
?>
<div class="msg"><?=$title?></div>
<table width="100%" border="0" cellspacing=0 cellpadding=2 class="tform">
<form action="admin.php<?=$qstr?>" method="post">
<input type="hidden" name="do" value="rename_status">
<input type="hidden" name="t" value="status">
<input type="hidden" name="status_id" value="<?=$info?>">
<tr class="header"><td colspan=2>Status Info</td></tr>
<tr class="subheader">
<td colspan=2 >Rename Status</td>
</tr>
<tr><th>Status Name</th>
<td>
<input type="text" name="status_name" size=30 value="<?=$info?>"> <font class="error">* <?=$errors?></font>
</td>
</tr>
<tr><td colspan=2 style="padding 0 10px 220px;">
<input class="button" type="submit" name="submit" value="Submit">
<input class="button" type="reset" name="reset" value="Reset">
<input class="button" type="button" name="cancel" value="Cancel" onClick='window.location.href="admin.php?t=status"'>
</td>
</tr>
</form>
</table>
</div>
Now lets show it on the client front end...
in include/client/viewticket.inc.php
under the very first <?php tag add this code...
function showOptionsDrop($selected){ // shows all options but selected...
$string = '';
$sql = 'SELECT * FROM ' . STATUS_TABLE;
$res = db_query($sql);
while ($row = db_fetch_array($res)) {
$k = $row;
$v = $row;
if($selected == $k) // don't double display the selected option
$string .= '<option selected value="'.$k.'">'.$v.'</option>'."\n";
else
$string .= '<option value="'.$k.'">'.$v.'</option>'."\n";
}
return $string;
}
Find this code...
<table align="center" class="infotable" cellspacing="1" cellpadding="3" width="100%" border=0>
Directly below add this code...
<tr>
<th width="100" >Simple Status:</th>
<td nowrap >
<form method="" action="" name="update">
<select name="updatework" width="150" style="width: 150px" disabled="disabled">
<?php echo showOptionsDrop($ticket->getSimpleStatus()); ?>
</select>
</form>
</tr>
Also , the home/scp/css/main.css needs to have the #footer section changed to this:
#footer {
width; /* change this! *
Done and Done! Enjoy!
Ok, working fine, status updates update the work field in the db so backend working great. Love your work :)
However, I can't figure out how to display the new status on the tickets.inc.php under progress
I created a new array but was only able to get it to display the first status in my table for every ticket. I figure it has to do with the $qselect It has been ages since i worked in SQL/PHP and have only just started getting back in to it now.
Will try again when i have more time.
Lets take a look at the code to see whats actually happening, that way we can figure out how to get the proper result.
In our function, setSimpleStatus, we have this line....
$status_val = (int) $status_val;
This is basically saying $status_val equals an integer of $status_val. Knowing that an integer is always a number we can infer that each value in the array is being assigned a number, 1 - how ever many statuses you have. I have 13 so 1 = reviewed, 2 = responded and so forth.
To get the status to display on tickets.inc.php, we'll need to add a new column to the table and populate it with code to display the actual status, instead of the integer that's being written to the database.
in include/staff/tickets.inc.php
around line 800 or so, add this code...
<th width="180" >Simple Status</th>
Your width may vary depending on any other mods you may have implemented.
Now the trick to getting the page to report the actual simple status instead of the integer that was written to the database is to use a bunch of if's inside a single . Basically we'll say "IF $ROW WORK EQUALS 1, PRINT REVIEWED. IF $ROW WORK EQUALS 2, PRINT RESPONDED and so on and so forth. There's probably a more efficient way to do this, but it works for me and I am lazy.
Around line 900 or so, add this code....
<td nowrap >
<?if($row == "1")
{?>
<?php echo 'Reviewed'; ?>
<?}?>
<?if($row == "2")
{?>
<?php echo 'Responded'; ?>
<?}?>
<?if($row == "3")
{?>
<?php echo 'Quotation Sent'; ?>
<?}?>
<?if($row == "4")
{?>
<?php echo 'PO Requested'; ?>
<?}?>
<?if($row == "5")
{?>
<?php echo 'PO Recieved'; ?>
<?}?>
<?if($row == "6")
{?>
<span style="color:#F00; text-decoration;"><?php echo 'DFNP'; ?></span>
<?}?>
<?if($row == "7")
{?>
<span style="color:#2A9F00; text-decoration;"><?php echo 'DFP'; ?></span>
<?}?>
<?if($row == "8")
{?>
<?php echo 'Awaiting Payment'; ?>
<?}?>
<?if($row == "9")
{?>
<?php echo 'Payment Recieved'; ?>
<?}?>
<?if($row == "10")
{?>
<?php echo 'In Transit'; ?>
<?}?>
<?if($row == "11")
{?>
<?php echo 'Working'; ?>
<?}?>
<?if($row == "12")
{?>
<?php echo 'Finished'; ?>
<?}?>
<?if($row == "13")
{?>
<?php echo 'In Return Transit'; ?>
<?}?>
</td>
My status 6 and 7 have some extra styling (the only good use I could EVER find for the tag). You can change your statuses to whatever you want just make sure you have enough IF's to match your number of statuses and that the integer matches the actual status.
GOOD LUCK!!
Here's what I would do
The following is untested, but it should put "" in the status field. It will query to get the names from the DB.
in include/staff/viewticket.inc.php:
after:
<tr>
<th>Status:</th>
Change the following lines to this:
<th>Status:</th>
<td><?=$ticket->getStatus()?>/
<?php
$status_val = $ticket->getSimpleStatus();
$res = db_query('SELECT status_name FROM ' . STATUS_TABLE . ' WHERE status_id=' . db_input($status_val));
$row1 = db_fetch_row($res);
echo htmlentities($row1);
?>
</td>
teryakisan, can you edit a line of code for the showOptionsDrop from this:
$string .= '<option value="'.$k.'">'.$v.'</option>'."\n";
To this:
$string .= '<option value="'.$k.'">'.htmlentities($v).'</option>'."\n";
Just in case someone tries to use and html special characters in the status names...
I like the way it displays OSTicket status/Simple status. However, I (personally) cannot switch to your code, as I will lose my formatting, and the staff likes the blinky for paid and not paid. (go figure).
Could not get your code in #33 to work. So instead I implemented the following. It seems to be the best of both worlds, Blink etc for some, and for the rest print out normally.
in include/staff/tickets.inc.php:
replace
$status_arr = array($status);
$status_arr = array("Reviewed","Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");
with
$status_arr = array();
$qry = db_query('SELECT * FROM '. STATUS_TABLE);
while($res = db_fetch_array($qry)) {
$status_arr[$res = $res;
}
Then replace
<td nowrap >
<?=$status_arr[$row;?>
</td>
with
<td nowrap >
<?php
switch($status_arr[$row)
{
case "test5":
echo "<span style=\"color:#FF0000; text-decoration;\">{$status_arr[$row}</span>";
break;
default:
echo "{$status_arr[$row}";
}
?>
</td>
Have tested and it works. Can add/remove statuses willy nilly without having to edit backend (except for adding a text decoration case).
If you get a blank table run the SQL queries below.
Also you will need to run the following queries in myphpadmin or similar.
(change '15' to whatever status_id corresponds with your default status.)
UPDATE `cpcticketsadmin`.`ost_ticket` SET `work` = '15' WHERE `ost_ticket`.`work` IS NULL;
ALTER TABLE `ost_ticket` CHANGE `work` `work` INT( 11 ) NOT NULL DEFAULT '15';
Excellent job, Thanks!
teryakisan, this is a great system!
It's kind of funny that today I was just starting to look for ways to do this and I saw this post.
What I'm trying to do though, it's verrrrry simplified ;) I dont need to be able to add more entries and all that.
I basically want to view and track what ticket as either sold, unsold, working or pending...
Now, I did everything in Post #29 and it works great! I had to modify the code where even staff will be able to update the ticket because they will be the ones updating that.
What I'm trying to do now is to add a little bit of color to our status in the staff view tickets area.
See attachment for a better explanation:
I'm sure it's going to be some kind of "if then" statement but I'm not sure how to word it :
Thanks!
Emil
In that case, let's do a quick primer on IF statements. The general idea is that IF a certain condition does or does not exist, then do or don't do something. It sounds confusing, I know, but learning the syntax of the IF statement will really boost your ability to read the code and understand what it does. So, on to the primer!
IF statements are considered to be conditional. That is, IF checks for a condition, then reacts, based on the outcome of that check.
We're going to write the check like this...
<?IF (condition) {?>
do this HTML stuff
<?}?>
basically, you start your line with a PHP opening tag, <?, then, IF, then put your condition inside of the parentheses, (). Add a curly brace, {, then the PHP close tag, ?>. Now, why would we want to put the PHP close tag in the middle of our statement? Well, we are just using PHP to manipulate an outcome. The outcome itself is HTML, which does not require <? or ?>. So then we'll put our HTML, a new PHP opening tag, <?, the closing curly brace, }, then the closing PHP tag ?>. That last curly brace HAS to be in PHP opening and closing tags because it is a part of the statement structure. Your really just jumping back and forth between PHP and HTML.
Let's define a condition. To do so we'll need to know that == means equal to and != means not equal to. There are other operators such as >= and
For example,
<?if($row == "0") {?>
<td style="background-color:#9C0">Stuff from database</td>
<?} ?>
This says, IF ticket table row staff_id is equal to zero then make a new cell containing the data with a freaky green background color.
These statements can be stacked on on top of the other, to get to a certain result. There are far more efficient ways of achieving these results, but will teach you little to nothing about the actual usage of the IF statement.
This should be enough information for you to git-r-done.
Lets see what ya got!