My boss wanted to be able to BCC other staff members when he replied to tickets.
We've been using it for two weeks now. Looks good.
Please backup
1. osticket_root/scp/tickets.php
and
2. osticket_root/include/staff/viewticket.inc.php
before continuing
This works similar to BCC. I simply tell the software to (optionally)send three extra emails when staff reply to a ticket.
First some background information
osticket_root/include/class.email.php class can send emails via SMTP or php mail (sendmail)
The functions that do the work are named
send
sendmail
The send function can use SMTP rather then the php mail function.
/osticket_root/include/class.ticket.php
class Ticket has a function named create
create inserts a new ticket into the database and sends an email back to the user whom sent in the question.
When a ticket class is created it requires the id of the ticket.
Example new Ticket($id)
The id is from the ticket table and the column named ticket_id
When you open up a ticket from a user the web address bar looks like http://yourwebsite.com/scp/tickets.php?id=116(http://yourwebsite.com/scp/tickets.php?id=116)
But what your actually looking at is the php and html generated from osticket_root/include/staff/viewticket.inc.php.
In your web browser you should see the "Post Reply" tab selected at the bottom of the page.
Here is the POST data from the Post Reply tab on submit.
The important post data from viewticket.inc.php is as follows
$_POST = 'reply'
$_POST = 'text from the textarea'
The post data is sent like tickets.php?id=116
thus it goes to osticket_root/scp/tickets.php
$_POST is used in a switch statement.
Look for
case 'reply':
Look for
if(!$errors && ($respId=$ticket->postResponse($_POST,$_POST,$_POST,$_FILES)))
Inside the if statement an email is sent to the person whom submitted the question with the response.
The ticket object includes the email class in osticket_root/include/class.ticket.php
So in order to email the same stuff that postResponse sends I had to include the email class in scp/tickets.php and create extra select fields in
osticket_root/include/staff/viewticket.inc.php. It will all be revealed below.
Phase1: Modify osticket_root/scp/tickets.php
Note: I've pinched a bit of the "how to send" code from the postResponse function in the Ticket class osticket_root/include/class.ticket.php
vi osticket_root/scp/tickets.php
Look for
require_once(INCLUDE_DIR.'class.banlist.php');
Replace with
require_once(INCLUDE_DIR.'class.banlist.php');
require_once(INCLUDE_DIR.'class.email.php');
Look for
if(!$errors && ($respId=$ticket->postResponse($_POST,$_POST,$_POST,$_FILES))){
Under that line put
$sql='SELECT msg.msg_id,msg.created,msg.message,count(attach_id) as attachments FROM '.TICKET_MESSAGE_TABLE.' msg '.
' LEFT JOIN '.TICKET_ATTACHMENT_TABLE." attach ON msg.ticket_id=attach.ticket_id AND msg.msg_id=attach.ref_id AND ref_type='M' ".
' WHERE msg.ticket_id='.db_input($id).
' GROUP BY msg.msg_id ORDER BY created';
$msgres =db_query($sql);
$clients_messages = 'Messages from the client '.$ticket->getName()."\r\n";
while ($msg_row = db_fetch_array($msgres)) {
$clients_messages .= Format:($msg_row)."\r\n";
$clients_messages .= $msg_row."\r\n";
$clients_messages .= "--------------------------------------------------\r\n";
}
$clients_messages .= 'From Our Company'."\r\n";
$subject = 'BCC Ticket#'.$ticket->getExtId().' from '.$thisuser->getName();
$file = null;
$attachment_array = $_FILES;
$link_to_ticket = "Link to ticket http://yourdomain.com/scp/tickets.php?id=".$id;
$email_list = $_POST;
if(count($email_list)>0){
$new_email = new Email();
$file=array('file'=>$attachment_array, 'name'=>$attachment_array, 'type'=>$attachment_array);
foreach($email_list as $key => $email_value){
if($email_value!='0'){
$new_email->send($email_value, $subject, $clients_messages."\r\n".$_POST."\r\n".$link_to_ticket, $file);
sleep(1);
}
}
}
Phase2: Add a bcc field to the "Post Reply" tab in viewticket.php
osticket_root/include/staff/viewticket.inc.php
Look for
if($canned && db_num_rows($canned)) {
?>
Canned Response:
<select id="canned" name="canned"
onChange="getCannedResponse(this.options.value,this.form,'response');this.selectedIndex='0';" >
<option value="0" selected="selected">Select a premade reply</option>
<?while(list($cannedId,$title)=db_fetch_row($canned)) { ?>
<option value="<?=$cannedId?>" ><?=Format:($title)?></option>
<?}?>
</select> <label><input type='checkbox' value='1' name=append checked="true" />Append</label>
<?}?>
At the bottom of the above add
<br />BCC:
<?
$sql=' SELECT staff_id,email,CONCAT_WS(", ",lastname,firstname) as name FROM '.STAFF_TABLE.' WHERE isactive=1 AND onvacation=0 ';
$depts= db_query($sql.' ORDER BY lastname,firstname ');
$option_list = '<option value="0" selected="selected">-Select Staff Member-</option>';
while (list($staffId,$email_address,$staffName) = db_fetch_row($depts)){
$option_list .='<option value="'.strtolower($email_address).'">'.$staffName.'</option>';
}
?>
<select id="address1" name="cc_address">
<? echo $option_list; ?>
</select>
<select id="address2" name="cc_address">
<? echo $option_list; ?>
</select>
<select id="address3" name="cc_address">
<? echo $option_list; ?>
</select>
Hope that was helpful to someone. Let me know.