Step 3: Create 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>Assign To</strong></td>
<td align="center"><strong>Department</strong></td>
<td align="center"><strong>Staff</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></select>
</td>
<td align="center"><input name="Criteria" type="text" id="Criteria"></td>
<td align="center"><select name="Action"><option value=""> </option><option value="deptId">Department</option><option value="staffId" >Staff</option></select></td>
<td 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>
</td>
<td align="center">
<select id="Staff" 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>
<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;
$ACTION = $_POST;
$DEPARTMENT = $_POST;
$STAFF = $_POST;
// Check if button name "Submit" is active, do this
if(isset($_POST)){
$sql="INSERT INTO ost_ticket_rules (isenabled, Category, Criteria, Action, Department, Staff, updated, created)
VALUES ('$_POST','$_POST','$_POST','$_POST','$_POST','$_POST', NOW(), NOW())";
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 4: Modify include/class.ticket.php
Remove the following
//Last minute checks
$priorityId=$priorityId?$priorityId:$cfg->getDefaultPriorityId();
$deptId=$deptId?$deptId:$cfg->getDefaultDeptId();
$ipaddress=$var?$var:$_SERVER;
//We are ready son...hold on to the rails.
$extId=Ticket:();
$sql= 'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
',ticketID='.db_input($extId).
',dept_id='.db_input($deptId).
',priority_id='.db_input($priorityId).
',email='.db_input($var).
',name='.db_input(Format:($var)).
',subject='.db_input(Format:($var)).
',topic='.db_input(Format:($topicDesc)).
',phone='.db_input($var).
',phone_ext='.db_input($var?$var:'').
',ip_address='.db_input($ipaddress).
',source='.db_input($source);
and replace with
// HACKED //
//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 ost_ticket_rules;");
$result=mysql_query($qry);
while ( $row = mysql_fetch_assoc($result)){
$isenabled=$row;
$Category=$row;
$Criteria=$row;
$Action=$row;
$Department=$row;
$Staff=$row;
if( "$isenabled" == "on" )
{
if( "$Category" == "subject" )
{
if (preg_match("/$Criteria/i", $subject))
{
if( "$Action" == "deptId" )
{
$deptId=$Department;
}
elseif( "$Action" == "staffId" )
{
$staffId=$Staff;
$qry = sprintf("SELECT dept_id FROM `ost_staff` WHERE staff_id=$Staff;");
$result=mysql_query($qry);
while ( $row = mysql_fetch_assoc($result)){
$deptId=$row;
}
}
}
}
elseif ( "$Category" == "email" )
{
if (preg_match("/$Criteria/i", $email))
{
if( "$Action" == "deptId" )
{
$deptId=$Department;
}
elseif( "$Action" == "staffId" )
{
$staffId=$Staff;
$qry = sprintf("SELECT dept_id FROM `ost_staff` WHERE staff_id=$Staff;");
$result=mysql_query($qry);
while ( $row = mysql_fetch_assoc($result)){
$deptId=$row;
}
}
}
}
}
} // 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).
',topic='.db_input(Format:($topicDesc)).
',phone='.db_input($var).
',phone_ext='.db_input($var?$var:'').
',ip_address='.db_input($ipaddress).
',source='.db_input($source);
// END HACKED
Step 5: Modify class.nav.php
Add the following line wherever in the $tabs lineup you would like to see it
$tabs=array('desc'=>'Rules','href'=>'rules.php','title'=>'Rules');
Step 6: Create rules and test
I have this working on both my test server and now my production osTicket server. All this code was copy and pasted direct from my ssh session. If you run into any errors please first check to make sure that you've followed the steps in order then make sure that nothing errored out because of copy/paste issues.
I look forward to comments, thank you!