The instructions for how to apply the "Simple Status" Addon are located in post #28, #29, and #30 in this thread - Enjoy!

****************************************************************************************

I have a select drop-down that should simply inform my team members where we stand on the status of an RMA. The first item on the list is populated from the database table ost_ticket.work. Im trying to figure out how to update ost_ticket.work with the option that is selected from the drop-down, effectively changing the first option, and displaying the RMA status. The dropdown looks like this...

blank

The code I have so far is...

Create the array for the drop down and format it properly...

$status_arr = array('Reviewed'=>"Reviewed",'Responded'=>"Responded",'Quotation Sent'=>"Quotation Sent",'PO Requested'=>"PO Requested",'PO Recieved'=>"PO Recieved",'Awaiting Payment'=>"Awaiting Payment",'Payment Recieved'=>"Payment Recieved",'In Transit'=>"In Transit",'Working'=>"Working",'Finished'=>"Finished",'In Return Transit'=>"In Return Transit");

function showOptionsDrop($array){

$string = '';

foreach($array as $k => $v){

$string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";

}

return $string;

}

Function to update the database...

function updatestatus(){

mysql_query("UPDATE ost_ticket SET work = '$work'");

}

The select....

<form action="" name="update">

<select name="updatework" width="150" style="width: 150px" onchange="updatestatus(this.value)">

<option value="0"><?=Format:($ticket->getwork()); ?></option>

<?php echo showOptionsDrop($status_arr); ?>

</select>&nbsp;&nbsp;

<input type="submit" value="update" class="button">

</form>

Everything works pretty well except the part where it updates the database.

Help!

This should help

This should help give you a little guide to what you need to do. I haven't tested any of this code, I just wrote it now on this post. It looks like you know what you're doing, so hopefully what I have below will help you figure everything out...

First of all, you'll need a function to update the database in the includes/class.ticket.php. Assuming you created the field work on the db table, the following function should work:

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);

}

You'll also want one to grab the current status:

function getSimpleStatus() {

return $this->work;

}

In order for this to work , you'll have to add a variable in the Ticket class:

var $id;

var $extid;

var $email;

// add work variable

var $work;

And you'll have to add to the sql query to set the value when the class initializes:

$this->id =$row;

$this->extid =$row;

$this->email =$row;

$this->fullname =$row;

$this->work = $row; // Add this!!

Then your display/form code is really not correct. It does not call anything. So you'll want to change it out with something like this:

// this needs to go in the global scope of the viewticket code

$status_arr = array("Reviewed",'"Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");

function showOptionsDrop($selected){ // shows all options but selected...

$string = '';

foreach($status_arr as $k=>$v){

if($selected != $k) // don't double display the selected option

$string .= '<option value="'.$k.'">'.$v.'</option>'."\n";

}

return $string;

}

<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">

<option selected value="<?=$ticket->getSimpleStatus();?>"><?=$status_arr;?></option>

<?php echo showOptionsDrop($ticket->getSimpleStatus()); ?>

</select>&nbsp;&nbsp;

<input type="submit" value="update" class="button">

</form>

Then you'll need to add some code in the tickets.php class that actually does call the ticket class functions...

case 'process':

$isdeptmanager=($ticket->getDeptId()==$thisuser->getDeptId())?true;

switch(strtolower($_POST)):

// ADD the following

case 'set_simple_status':

if(!$thisuser->canManageTickets()){

$errors='Perm. Denied. You are not allowed change the RMA status.';

}

if(!$errors)

$ticket->setSimpleStatus($_POST);

break;

Hopefully this well help you...

awesome, I'm about to take a whack at it, back with results in 10 or so.

Everything goes well until the actual form part.

<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">

<option selected value="<?=$ticket->getSimpleStatus();?>"><?=$status_arr;?></option>

<?php echo showOptionsDrop($ticket->getSimpleStatus()); ?>

</select>&nbsp;&nbsp;

<input type="submit" value="update" class="button">

</form>

It's displaying the select, with nothing inside, and an empty page thereafter.

ok...

Ok. Try changing the showOptionsDrop function to this:

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;

}

And change the display code to this:

<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>&nbsp;&nbsp;

<input type="submit" value="update" class="button">

</form>

Again, I haven't even checked this code for syntax errors, so check your php error logs and let me know if anything is present...

Thank you!!!

Hella yes it works!! The error was was actually an errant ' in showOptionsDrop. YOU ARE THE MAN and thanks again. One of us should totally write this out as a mod, LOTS of people are looking for something just like this.

Great!

Good deal. Glad I could help.

Working Working

Hey i set it up and it works for me Thank You

db column

Also,

Since we are only storing integers in the DB you don't need to use varchar. Int would probably be more suitable...

ALTER TABLE ost_ticket ADD column work int;

Updated the tutorial to reflect int instead of varchar.

So theres really not much use is having a status if you cant just check it real quick, right?

staff/tickets.inc.php

Make sure you have your database column name added to the $qselect on line 51. Mine is called "work".

$qselect = 'SELECT ticket.ticket_id,ticket.ticketID,ticket.dept_id,isanswered,ispublic,subject,name,work,email '.

At the very top of the page, directly beneath the 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");

at line 103, I added a new table header, to indicate progress. I named it "Progress".

Email

Progress

Find this code

<td>&nbsp;<?=Format:($row,40)?></td>

Directly below it add this code

<td nowrap >

<?=$status_arr[$row;?>

</td>

Now we have Simple status reflected in staff/tickets.inc.php

Hey i set it up and it works for me Thank You

You're welcome! Glad it is working for you.

You need ADD COLUMN, the SQL query you edited in the post just has ADD. Also, for the display code on the tickets page, you could just do:

$status_arr = array("Reviewed","Responded","Quotation Sent","PO Requested","PO Recieved","Awaiting Payment","Payment Recieved","In Transit", "Working", "Finished", "In Return Transit");

<td nowrap >

<?=$status_arr[$row;?>

</td>

Statuses

We probably need to create a separate db table for people to make their own statuses and poll from that... I'll write something that does that and post it a little later.

Right on. Pulling from a database table was actually the original idea, I was just trying to get something working immediately. I look forward to your changes/additions.

A little more elaborate

So here is what I have so far... Since I don't have any of this code implemented on my actual machine, I thought I'd have you test it first before adding more functionality.

This should let you add and remove statuses (update not yet implemented). It will show up in the admin menu. If you try to delete a status that is currently already set in some tickets, the system will not let you.

First, add a table to a list of statuses:

mysql> use osticket;

mysql> create table ost_status (status_id int auto_increment, status_name varchar(255), primary key(status_id));

Here is a list of changes to make:

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">&nbsp;</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:&nbsp;

<a href="#" onclick="return select_all(document.forms,true)">All</a>&nbsp;

<a href="#" onclick="return reset_all(document.forms)">None</a>&nbsp;

<a href="#" onclick="return toogle_all(document.forms,true)">Toggle</a>&nbsp;

</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>&nbsp;</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:

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;

}

teryakisan, if you could test (I have not actually implemented any of this..) and integrate this with the current guide - I'd appreciate it. Thanks!

and FYI, I had an errant single quote in post #13.

Brilliant. I'll try to get it integrated a little later this evening. WORK WORK WORK ya know!

Edits complete...

To allow editing of statuses, complete the following instructions:

/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;

*********************************************************

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?>">&nbsp;<font class="error">*&nbsp;<?=$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>

Also , the home/scp/css/main.css needs to have the #footer section changed to this:

#footer {

width; /* change this! */

teryakisan,

This should do everything you want. If it works for you, I'd appreciate it if you could update post 8 so it reflects all of the changes. Thanks!

Looks like the new showOptionsDrop is breaking includes/staff/viewticket.inc.php. Strange, it wasn't doing that yesterday, although it was the fourth and I may not have been in my complete facilities