modified this mod to use receiving email address and help topics #2
Step 4: Create osticket_path/scp/add_rule.php
<?php
require('staff.inc.php');
$page='';
$answer=null; //clean start.
$nav->setTabActive('rules');
$nav->addSubMenu(array('desc'=>'Rules','href'=>'rules.php','iconclass'=>'premade'));
$nav->addSubMenu(array('desc'=>'New Rule','href'=>'add_rule.php','iconclass'=>'newPremade'));
require_once(STAFFINC_DIR.'header.inc.php');
?>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="POST" action="add_rule.php">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="5">
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Enabled</strong></td>
<td align="center"><strong>Category</strong></td>
<td align="center"><strong>Contains</strong></td>
<td align="center"><strong>Staff</strong></td>
<td align="center"><strong>Department</strong></td>
<td align="center"><strong>Help Topic</strong></td>
</tr>
<tr>
<td width="50" align="center"><select name="isenabled"><option value="on">On</option><option value="off">Off</option></select></td>
<td align="center">
<select name="Category"><option value="subject">Subject</option><option value="email">Email</option>
begin added by lmg
<option value="email_to">Email To</option>
end added by lmg
</select>
</td>
<td align="center"><input name="Criteria" type="text" id="Criteria"></td>
<td id="Staff" align="center">
<select name="Staff" >
<option value="0" selected="selected"> </option>
<?
$sql=' SELECT staff_id,CONCAT_WS(", ",lastname,firstname) as name FROM '.STAFF_TABLE.
' WHERE isactive=1 AND onvacation=0 ';
$depts= db_query($sql.' ORDER BY lastname,firstname ');
while (list($staffId,$staffName) = db_fetch_row($depts)){?>
<option value="<?=$staffId?>" ><?=$staffName?></option>
<?}?>
</select>
</td>
<td id="Department" align="center">
<select name="Department">
<option value=0> </option>
<?
$depts= db_query('SELECT dept_id,dept_name FROM '.DEPT_TABLE.'');
while (list($deptId,$deptName) = db_fetch_row($depts)){?>
<option value="<?=$deptId?>" ><?=$deptName?></option>
<?}?>
</select>
begin added by lmg
<td id="HelpTopic" align="center">
<select name="HelpTopic">
<option value=0> </option>
<?
$topics= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.' WHERE isactive=1');
while (list($topicId,$topicName) = db_fetch_row($topics)){?>
<option value="<?=$topicId?>" ><?=$topicName?></option>
<?}?>
</select>
</td>
end added by lmg
<tr>
<td colspan="7" align="right"><input type="submit" name="Submit" class="button" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
$ISENABLED = $_POST;
$CATEGORY = $_POST;
$CRITERIA = $_POST;
//begin MODIFIED by lmg
if (isset($_POST))
$DEPARTMENT = $_POST;
else
$DEPARTMENT = "0";
if (isset($_POST))
$STAFF = $_POST;
else
$STAFF = "0";
if (isset($_POST))
$HELPTOPIC = $_POST;
else
$HELPTOPIC = "0";
//end MODIFIED by lmg
// Check if button name "Submit" is active, do this
//begin MODIFIED by lmg
if(isset($_POST)){
$sql="INSERT INTO ".RULES_TABLE." (isenabled, Category, Criteria, Department, Staff, HelpTopic, updated, created)
VALUES ('$_POST','$_POST','$_POST','$DEPARTMENT','$STAFF', '$HELPTOPIC', NOW(), NOW())";
//end MODIFIED by lmg
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "Rule added";
}
?>
<SCRIPT language="JavaScript">
<!<!--
window.location="rules.php";
//
</SCRIPT>><?
mysql_close();
require_once(STAFFINC_DIR.'footer.inc.php');
?>
==================================
Step 5: Modify osticket_path/include/class.ticket.php (note my version uses ',helptopic=' instead of ',topic='):
/*AUTOaSSIGN MOD modified by lmg*/
// BEGIN - sudobash.net Auto-Assignment Rules MOD //
//Last minute checks
$priorityId=$priorityId?$priorityId:$cfg->getDefaultPriorityId();
$deptId=$deptId?$deptId:$cfg->getDefaultDeptId();
$ipaddress=$var?$var:$_SERVER;
$subject=(Format:($var));
$email=($var);
$qry = sprintf("SELECT * FROM ".RULES_TABLE.";");
$result=mysql_query($qry);
while ( $row = mysql_fetch_assoc($result)){
$isenabled=$row;
$Category=$row;
$Criteria=$row;
$Department=$row;
$Staff=$row;
//begin added by lmg
$HelpTopic=$row;
//end added by lmg
if( "$isenabled" == "on" )
{
if( ("$Category" == "subject" && preg_match("/$Criteria/i", $subject)) || ("$Category" == "email" && preg_match("/$Criteria/i", $email)) || ("$Category" == "email_to" && preg_match("/$Criteria/i", $email_to)))
{
if ($Department>0)
$deptId=$Department;
if ($Staff>0)
$staffId=$Staff;
if ($Department<=0)
{
$staffId=preg_replace( '/\n/', '', trim($staffId) );
$qry = sprintf("SELECT dept_id FROM ".STAFF_TABLE." WHERE staff_id=$Staff;");
$result=mysql_query($qry);
while ( $row = mysql_fetch_assoc($result)){
$deptId=$row;
}
}
$topic = new Topic($HelpTopic);
$topicDesc = $topic->getName();
if ($Department<=0)
$deptId = $topic->getDeptId();
}
}
} // End while loop
//We are ready son...hold on to the rails.
$extId=Ticket:();
$sql= 'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
',ticketID='.db_input($extId).
',priority_id='.db_input($priorityId).
',email='.db_input($var).
',name='.db_input(Format:($var)).
',subject='.db_input($subject).
',dept_id='.db_input($deptId).
',staff_id='.db_input($staffId).
',helptopic='.db_input(Format:($topicDesc)).
',phone='.db_input($var).
',phone_ext='.db_input($var?$var:'').
',ip_address='.db_input($ipaddress).
',source='.db_input($source);
// END - sudobash.net Auto-Assignment Rules MOD
============================================
Step 6: Modify osticket_path/include/class.nav.php (have not changed at all) to include:
$tabs=array('desc'=>'Rules','href'=>'rules.php','title'=>'Rules');