Hi,
I made MOD for auto assigned ticket. If client or staff create a new ticket to a certain help topic, then the default staff who has been choosen before from Admin Panel, will be assigned to that ticket automatically.
I also made the MOD in Admin Panel, which will help you to manage which staff you can choose or edit/change/switch as a default staff for a certain auto-assigned help topic. This default staff will automatically be auto-assigned when ticket is being created by client or even by staff.
WARNING!!! Before doing this MOD, please follow my instruction at my #2 post below (scroll your mouse to the #2 post below)


You can also easily delete one or some auto-assigned staff if no longer needed, and this will not remove the staff record from staff table.
Just FYI, you will find in some part of my code there are a lots of constants for language translation, because I implemented multi-languate in my osTicket. You can change that constants to the string based on the constant name or the original version of osTicket. Therefore, please be kind of this. ;)
Before doing this, please BACKUP ALL OF YOUR FILES as I am not responsible for any risk you will get further!
Okay. Let's getting started now.
First: Create new table named "ost_help_topic_auto_assign"
CREATE TABLE `ost_help_topic_auto_assign` (
`auto_assign_id` int(11) NOT NULL auto_increment,
`topic_id` int(11) NOT NULL,
`dept_id` int(11) NOT NULL,
`staff_id` int(10) NOT NULL,
`created` datetime NOT NULL default '0000-00-00 00',
`updated` datetime NOT NULL default '0000-00-00 00',
PRIMARY KEY (`auto_assign_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
Second: Download the attachment file, extract the zip file, and put the .php files to the proper directory: \include\staff\. There are 2 files:
- topicautoassign.inc.php
- helptopicsautoassignlist.inc.php
Third: Time to play with code... :)
Open main.inc.php, FIND:
define('TOPIC_TABLE',TABLE_PREFIX.'help_topic');
AFTER, ADD:
define('TOPIC_AUTO_ASSIGN_TABLE',TABLE_PREFIX.'help_topic_auto_assign');
Open \scp\admin.php, FIND:
case 'groups':
$do=strtolower($_POST);
BEFORE, ADD:
case 'topicautoassign':
if($_POST) {
$staff_id = $_POST;
$cekstaff = db_query('SELECT staff_id FROM '.TOPIC_AUTO_ASSIGN_TABLE.'
WHERE staff_id='.$staff_id.' AND dept_id='.$_POST.'
AND topic_id='.$_POST.'');
$staffcount = db_num_rows($cekstaff);
if ($staffcount) {
$sql='UPDATE '.TOPIC_AUTO_ASSIGN_TABLE.' SET updated=NOW()';
} else {
$sql='INSERT INTO '.TOPIC_AUTO_ASSIGN_TABLE.' SET created=NOW(),'.
'staff_id='.$staff_id.','.
'dept_id='.$_POST.','.
'topic_id='.$_POST;
if(!db_query($sql) or !($autoassignid=db_insert_id())) {
$errors='Unable to insert auto-assign help topic';
}
$sql='DELETE FROM '.TOPIC_AUTO_ASSIGN_TABLE.' WHERE dept_id='.$_POST.'
AND topic_id='.$_POST.' AND staff_id <> '.$staff_id;
if(db_query($sql) && ($num=db_affected_rows())) {
$msg="$num ".S_A_OF." $count auto-assign help topic(s) deleted.";
} else {
$errors='Could not remove auto-assign help topic.';
}
}
header('Location: admin.php?t=helptopicsautoassignlist');
} else {
$errors='No auto-assign help topic selected!';
}
break;
case 'helptopicsautoassignlist':
$do=strtolower($_POST);
switch($do){
case 'mass_process':
if(!$_POST || !is_array($_POST)) {
$errors=S_A_YOU_MUST_SELECT_AT_LEAST_ONE_TOPIC;
}else{
$count=count($_POST);
$ids=implode(',',$_POST);
if($_POST){
$sql='DELETE FROM '.TOPIC_AUTO_ASSIGN_TABLE.' WHERE auto_assign_id IN ('.$ids.')';
if(db_query($sql) && ($num=db_affected_rows()))
$msg="$num ".S_A_OF." $count ".S_A_SELECTED_TOPICS_DELETED;
else
$errors=S_A_UNABLE_TO_DELETE_SELECTED_TOPICS;
}
}
break;
default:
$errors=S_A_UNKNOWN_TOPIC_ACTION;
}
break;
FIND:
case 'topics':
require_once(INCLUDE_DIR.'class.topic.php');
$topic=null;
$nav->setTabActive('topics');
$nav->addSubMenu(array('desc'=>'Help Topics','href'=>'admin.php?t=topics','iconclass'=>'helpTopics'));
$nav->addSubMenu(array('desc'=>'Add New Topic','href'=>'admin.php?t=topics&a=new','iconclass'=>'newHelpTopic'));
if(($id=$_REQUEST?$_REQUEST:$_POST) && is_numeric($id)) {
$topic= new Topic($id);
if(!$topic->load() && $topic->getId()==$id) {
$topic=null;
$errors='Unable to fetch info on topic #'.$id;
}
}
$page=($topic or ($_REQUEST=='new' && !$topicID))?'topic.inc.php':'helptopics.inc.php';
break;
REPLACE WITH:
case 'topics':
case 'topicautoassign':
case 'helptopicsautoassignlist':
require_once(INCLUDE_DIR.'class.topic.php');
$topic=null;
$nav->setTabActive('topics');
$nav->addSubMenu(array('desc'=>S_A_HELP_TOPICS,'href'=>'admin.php?t=topics','iconclass'=>'helpTopics'));
$nav->addSubMenu(array('desc'=>S_A_ADD_NEW_TOPIC,'href'=>'admin.php?t=topics&a=new','iconclass'=>'newHelpTopic'));
$nav->addSubMenu(array('desc'=>I_S_HELP_HELP_TOPIC_AUTO_ASSIGN,'href'=>'admin.php?t=helptopicsautoassignlist','iconclass'=>'helpTopics'));
switch(strtolower($_REQUEST)){
case 'topics':
default:
if(($id=$_REQUEST?$_REQUEST:$_POST) && is_numeric($id)) {
$topic= new Topic($id);
if(!$topic->load() && $topic->getId()==$id) {
$topic=null;
$errors=S_A_UNABLE_TO_FETCH_INFO_ON_TOPICNO.$id;
}
}
$page=($topic or ($_REQUEST=='new' && !$topicID))?'topic.inc.php':'helptopics.inc.php';
break;
case 'helptopicsautoassignlist':
$page='helptopicsautoassignlist.inc.php';
break;
case 'topicautoassign':
default:
if(($id=$_REQUEST?$_REQUEST:$_POST) && is_numeric($id)) {
$topic= new Topic($id);
if(!$topic->load() && $topic->getId()==$id) {
$topic=null;
$errors=S_A_UNABLE_TO_FETCH_INFO_ON_TOPICNO.$id;
}
}
$page=($topic or ($_REQUEST=='newedit' && !$topicID))?'topicautoassign.inc.php':'helptopicsautoassignlist.inc.php';
break;
}
break;
Open \include\staff\helptopics.inc.php, FIND:
<th>Help Topic</th>
<th>Status</th>
REPLACE WITH:
<th><?php echo (I_S_HELP_HELP_TOPIC); ?></th>
<th>Auto Assign</th>
<th><?php echo (I_S_HELP_STATUS); ?></th>
FIND:
<td><a href="admin.php?t=topics&id=<?=$row?>"><?=Format:(Format:($row,30))?></a></td>
REPLACE WITH:
<td><a href="admin.php?t=topics&id=<?php echo $row?>"><?php echo Format:(Format:($row,30))?></a></td>
<td><a href="admin.php?t=topicautoassign&a=newedit&topic_id=<?php echo $row ?>&dept_id=<?php echo $row; ?>">Add/Edit Auto Assign</a></td>
Open \include\class.ticket.php, FIND:
//Any error above is fatal.
if($errors) { return 0; }
AFTER, ADD:
$sqlstaff = db_query('SELECT staff_id FROM '.TOPIC_AUTO_ASSIGN_TABLE.' WHERE dept_id='.$deptId.' AND topic_id='.$topicId);
if (db_num_rows($sqlstaff)) {
while (list($staff_id)=db_fetch_row($sqlstaff)) {
$staffid = $staff_id;
}
}
That's all. I have tested this before, and it works good in mine.
Let me know your feedback. Thanks.
Best regards,
Masino Sinaga
[topicautoassign.inc.zip](https://forum.osticket.com/assets/files/migrated/e/34af52d3e64f65c42caa35f0d7e0925.zip)
[helptopicsautoassignlist.inc.zip](https://forum.osticket.com/assets/files/migrated/8/41789667ae1b76f62c639eeed3663e8.zip)