Page 1 of 1

Notify staff by email on category change

Posted: Tue Aug 21, 2007 1:33 pm
by samal
Version of hesk: 0.94

Hello,
Hesk works nice, I have only one small problem:
- system sends emails to admin and user without problem
- system notify user via email after adding new note to topic

but
- system send no email to staff asigned to new category after change of category
(- system send no email to administrator in case of change of category)

My settings:
- All staff has "Notify" option to 1 in database

How can I simply add notification to staff on category change?

This is only one problem - otherwise Hesk is excellent and simply!

Regards

D.Samal

Solved

Posted: Tue Aug 21, 2007 11:18 pm
by samal
Sorry for my first question. It was easy to add 30 lines to one file... Post topic to forum is maybe easier, but need no brain.

I am finalizing internal user ticket system based on Hesk, I´ll send details about my changes later (how to solve this topic etc.), but I have no time to do that now. I replaced One or Zero system by Hesk - this is nice system, but with un-readable code. Changes in Hesk are simply as 123... Nice system and excellent clear code...

Posted: Mon Aug 27, 2007 10:55 am
by Klemen
Thanks for pointing that out, will add notification of category change to the next version.

Posted: Wed Sep 05, 2007 10:56 pm
by Josh
I'm curious about this fix. I was under the assumption that if you had your profile option set to "Notify me of new tickets and posts within my categories" you would receive an e-mail when the category was changed. After testing I don't think this is the case.

Since tickets will change categories in our configuration I'd like back office users to be e-mailed when a ticket is changed from the main categories that users submit to to their specific category.


Could you post your fix samal?

Posted: Thu Sep 06, 2007 12:10 am
by Klemen
Here's a quick fix before I am able to release any official code. Using the codes from submit_ticket.php and admin_ticket.php you can quickly build this:

Code: Select all

/* Get ticket info */
$sql = "SELECT * FROM `hesk_tickets` WHERE `trackid`='$trackingID' LIMIT 1";
$result = hesk_dbQuery($sql) or hesk_error("$hesklang[cant_sql]: $sql</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
if (hesk_dbNumRows($result) != 1) {hesk_error($hesklang['ticket_not_found']);}
$ticket = hesk_dbFetchAssoc($result);
$name = $ticket['name'];
$subject = $ticket['subject'];

/* Need to notify any admins? */
$admins=array();
$sql = "SELECT `email`,`isadmin`,`categories` FROM `hesk_users` WHERE `notify`='1'";
$result = hesk_dbQuery($sql) or hesk_error("$hesklang[cant_sql]: $sql</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
while ($myuser=hesk_dbFetchAssoc($result))
{
    /* Is this an administrator? */
    if ($myuser['isadmin']) {$admins[]=$myuser['email']; continue;}
    /* Not admin, is he allowed this category? */
    $cat=substr($myuser['categories'], 0, -1);
    $myuser['categories']=explode(',',$cat);
    if (in_array($category,$myuser['categories']))
    {
        $admins[]=$myuser['email']; continue;
    }
}
if (count($admins)>0)
{
$trackingURL_admin=$hesk_settings['hesk_url'].'/admin_ticket.php?track='.$trackingID;

/* Get e-mail message for customer */
$fp=fopen('emails/new_ticket_staff.txt','r');
$message=fread($fp,filesize('emails/new_ticket_staff.txt'));
fclose($fp);

$message=str_replace('%%NAME%%',$name,$message);
$message=str_replace('%%SUBJECT%%',$subject,$message);
$message=str_replace('%%TRACK_ID%%',$trackingID,$message);
$message=str_replace('%%TRACK_URL%%',$trackingURL_admin,$message);
$message=str_replace('%%SITE_TITLE%%',$hesk_settings['site_title'] ,$message);
$message=str_replace('%%SITE_URL%%',$hesk_settings['site_url'] ,$message);

/* Send e-mail to staff */
$email=implode(',',$admins);
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
@mail($email,$hesklang['new_ticket_submitted'],$message,$headers);
} // End if

You need to paste the code above into admin_move_category.php, just ABOVE line 55:

Code: Select all

$admin_trackingURL=$hesk_settings['hesk_url'].'/admin_ticket.php?track='.$trackingID.'&Refresh='.rand(10000,99999);
NOTE: Now I haven't tested this and I'm not sure if I left out something, but give it a try. I might come up with a better solution for the official release, but for now this is it.

Changes in my Hesk...

Posted: Thu Sep 06, 2007 12:49 pm
by samal
Sorry for delay, I have a lot of work...
So - what I changed?
At first I have to say that I´m using categories for "departments" in my office and each departmets can agree/disagree with investment of our user (I modded it for investment tracking...:-).
Manager can send ticket to another department - and this department (new manager) have to be informed.

To send infomail to new manager:
I had to change admin_move_category.php.
I added lines below (added from line 58 )

Code: Select all

/* Get ticket subject */
$subjectpole=array();
$sql = "SELECT `subject` FROM `hesk_tickets` WHERE `trackid`='$trackingID'";
$result = hesk_dbQuery($sql) or hesk_error("$hesklang[cant_sql]: $sql</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
if (hesk_dbNumRows($result) != 1) {hesk_error($hesklang['ticket_not_found']);}
$subjectpole = hesk_dbFetchAssoc($result);
$subject=$subjectpole['subject'];
/* Get e-mail message for customer */
$fp=fopen('emails/catchange_ticket.txt','r');
$message=fread($fp,filesize('emails/catchange_ticket.txt'));
fclose($fp);

$message=str_replace('%%NAME%%',$name,$message);
$message=str_replace('%%SUBJECT%%',$subject,$message);
$message=str_replace('%%TRACK_ID%%',$trackingID,$message);
$message=str_replace('%%TRACK_URL%%',$trackingURL,$message);
$message=str_replace('%%SITE_TITLE%%',$hesk_settings['site_title'] ,$message);
$message=str_replace('%%SITE_URL%%',$hesk_settings['site_url'] ,$message);

/* Send e-mail */
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
@mail($email,$hesklang['ticket_received'],$message,$headers);

/* Need to notify any admins? */
$admins=array();
$sql = "SELECT `email`,`isadmin`,`categories` FROM `hesk_users` WHERE `notify`='1'";
$result = hesk_dbQuery($sql) or hesk_error("$hesklang[cant_sql]: $sql</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
while ($myuser=hesk_dbFetchAssoc($result))
{
    /* Is this an administrator? */
    if ($myuser['isadmin']) {$admins[]=$myuser['email']; continue;}
    /* Not admin, is he allowed this category? */
    $cat=substr($myuser['categories'], 0, -1);
    $myuser['categories']=explode(',',$cat);
    if (in_array($category,$myuser['categories']))
    {
        $admins[]=$myuser['email']; continue;
    }
}
if (count($admins)>0)
{
$trackingURL_admin=$hesk_settings['hesk_url'].'/admin_ticket.php?track='.$trackingID;

/* Get e-mail message for customer */
$fp=fopen('emails/catchange_ticket_staff.txt','r');
$message=fread($fp,filesize('emails/catchange_ticket_staff.txt'));
fclose($fp);

$message=str_replace('%%NAME%%',$name,$message);
$message=str_replace('%%SUBJECT%%',$subject,$message);
$message=str_replace('%%TRACK_ID%%',$trackingID,$message);
$message=str_replace('%%TRACK_URL%%',$trackingURL_admin,$message);
$message=str_replace('%%SITE_TITLE%%',$hesk_settings['site_title'] ,$message);
$message=str_replace('%%SITE_URL%%',$hesk_settings['site_url'] ,$message);

/* Send e-mail to staff */
$email=implode(',',$admins);
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
@mail($email,'[YOUR SYSTEM NAME] '.$subject,$message,$headers);
} 
// End if
You can see that I changed e-mail message file to catchange_ticket.txt
This file doesn´t exist, so we have to create one with message like:

Code: Select all

Hello,

A category change for request has been submitted. Request details:

Request subject: %%SUBJECT%%
Tracking ID: %%TRACK_ID%%
Similar is catchange_ticket_staff.txt - doesn´t exist, we have to add new file with something like this:

Code: Select all

Hello,

A category change for request has been submitted. Request details:

Request subject: %%SUBJECT%%
Tracking ID: %%TRACK_ID%%

You can manage this request here:
%%TRACK_URL%%

Improved search

Posted: Thu Sep 06, 2007 1:19 pm
by samal
And I continued with more changes - for example searching... You can view tickets assigned to you, but you cannot view ticket redirected from you to another manager (category). That´s a problem, because I lost information about next steps of another admin in this ticket (if any).
I placed a link on admin page (where admin can find only his tickets) to new pages for searching in all tickets. He cannot change these tickets, but he can view state of tickets...
I created new files show_tickets_all.php, find_tickets_all.php and in subfolder inc I created show_search_form_all.php and print_tickets_all.php .
These files allow managers to search and view all tickets. As you can see - these files are only simply modded from original files. Basically I blocked sql_private control - like here in show_search_form_all.php line 93:

Code: Select all

$sql_private = "SELECT * FROM `hesk_categories`";
//$sql_private .= hesk_myCategories('id');
$sql_private .= ' ORDER BY `cat_order` ASC';
in print_tickets_all it is around line 40:

Code: Select all

// $sql .= hesk_myCategories();
etc... You have to find this private control...


I created new files for this - and link from admin page to show_tickets_all.php. You have to change link to new required files like:

Code: Select all

<?php
require_once('inc/print_tickets_all.inc.php');
?>
In find_tickets_all.php you can also remove private control:

Code: Select all

// $sql .= hesk_myCategories();
// $sql .= " AND ";
Warning: These changes change sql queries - if you remove AND or hesk_myCategories or other part of query, it cannot work. You have to change all queries! It´s a simple work - sometimes delete some characters or move AND from one part of query to another (it depands on if-end if...
I can send all files, but it´s more lines than I want to paste here...

Ask me for details...:-)

Posted: Thu Sep 06, 2007 3:15 pm
by Josh
Tested it out and things are working just as I had hoped. You guys are the best.

Thanks for your time.

Re: Notify staff by email on category change

Posted: Mon Jan 09, 2012 7:15 am
by lupolo
Hello,

Where can i find the above " Notify Staff on category change/assign " option in Hesk?

Re: Notify staff by email on category change

Posted: Mon Jan 09, 2012 4:50 pm
by Klemen
It send a notification to anyone with access to the category and "A new ticket is submitted with owner: Unassigned" selected in the Profile page. Version 2.4 will change this by only notifying users that weren't already notified in the previous category.