Hi,
I'm trying to modify the os ticket system, to send an email when the ticket's status is changed to close.
i've no problem with the status but the email does not go.
Below my close function.
//Close the ticket
function close($alert=true){
global $cfg;
$sql= 'UPDATE '.TICKET_TABLE.' SET status='.db_input('closed').',staff_id=0,isoverdue=0,duedate=NULL,updated=NOW(),closed=NOW() '.
' WHERE ticket_id='.db_input($this->getId());
if(db_query($sql) && db_affected_rows()){
$dept=$this->getDept();
if(!$dept || !($tplId=$dept->getTemplateId()))
$tplId=$cfg->getDefaultTemplateId();
if($alert && $cfg->alertONClosedTicket()){
$dept=$this->getDept();
if(!$dept || !($tplId=$dept->getTemplateId()))
$tplId=$cfg->getDefaultTemplateId();
$sql='SELECT ticket_closed_subj,ticket_closed_body FROM '.EMAIL_TEMPLATE_TABLE.
' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId);
if(($resp=db_query($sql)) && db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){
$body=$this->replaceTemplateVars($body);
$subj=$this->replaceTemplateVars($subj);
$body = str_replace('%note',"$title\n\n$note",$body);
if(!$email=$cfg->getAlertEmail())
$email =$cfg->getDefaultEmail();
if($email && $email->getId()) {
//Build list of recipients and fire the alerts.
$recipients=array();
//Last respondent.
if($cfg->alertLastRespondentONClosedTicket() || $cfg->alertAssignedONClosedTicket())
$recipients=$this->getLastRespondent();
//Assigned staff if any...could be the last respondent
if($this->isAssigned())
$recipients=$this->getStaff();
//Dept manager
if($cfg->alertDeptManagerONClosedTicket() && $dept)
$recipients=$dept->getManager();
$sentlist=array(); //I know it sucks...but..it works.
foreach( $recipients as $k=>$staff){
//TODO: log error messages.
if(!$staff || !is_object($staff) || !$staff->getEmail() || !$staff->isAvailable()) continue;
if(in_array($staff->getEmail(),$sentlist) || ($thisuser && $thisuser->getId()==$staff->getId())) continue;
$alert = str_replace('%staff',$staff->getFirstName(),$body);
$email->send($staff->getEmail(),$subj,$alert);
$sentlist=$staff->getEmail();
}
}
}else {
Sys:(LOG_WARNING,'Template Fetch Error',"Unable to fetch 'new note' alert template #$tplId");
}
}
return true;
}else{
return false;
}
}
Could anyone help me ?
Thanks