Ask not what osTicket community can do for you - ask what you can do for osTicket community

Go Back   osTicket Forums > osTicket 1.6.x > Mods and Customizations

Reply
 
Thread Tools Search this Thread Display Modes
  #51  
Old 03-28-2012, 12:32 PM
lmg lmg is offline
Junior Member
 
Join Date: Mar 2012
Posts: 3
Default modified this mod to use receiving email address and help topics #2

Step 4: Create osticket_path/scp/add_rule.php

Code:
<?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">&nbsp;</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>&nbsp;</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>&nbsp;</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['isenabled'];
$CATEGORY = $_POST['Category'];
$CRITERIA = $_POST['Criteria']; 

//begin MODIFIED by lmg
if (isset($_POST['Department']))
  $DEPARTMENT = $_POST['Department'];
else
  $DEPARTMENT = "0"; 
if (isset($_POST['Staff']))
  $STAFF = $_POST['Staff'];
else
  $STAFF = "0";
if (isset($_POST['HelpTopic']))
  $HELPTOPIC = $_POST['HelpTopic'];
else
  $HELPTOPIC = "0";
//end MODIFIED by lmg


// Check if button name "Submit" is active, do this
//begin MODIFIED by lmg
if(isset($_POST['Submit'])){
$sql="INSERT INTO ".RULES_TABLE." (isenabled, Category, Criteria, Department, Staff, HelpTopic, updated, created)
VALUES ('$_POST[isenabled]','$_POST[Category]','$_POST[Criteria]','$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='):

Code:
/*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['ip']?$var['ip']:$_SERVER['REMOTE_ADDR'];
 
        $subject=(Format::striptags($var['subject']));
        $email=($var['email']);
 
      $qry = sprintf("SELECT * FROM ".RULES_TABLE.";");
      $result=mysql_query($qry);
      while ( $row = mysql_fetch_assoc($result)){
 
      $isenabled=$row['isenabled'];
      $Category=$row['Category'];
      $Criteria=$row['Criteria'];
      $Department=$row['Department'];
      $Staff=$row['Staff'];
      
      //begin added by lmg
      $HelpTopic=$row['HelpTopic'];
      //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['dept_id'];
                  }
                
                }
                
                $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::genExtRandID();
        $sql=   'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
                ',ticketID='.db_input($extId).
                ',priority_id='.db_input($priorityId).
                ',email='.db_input($var['email']).
                ',name='.db_input(Format::striptags($var['name'])).
                ',subject='.db_input($subject).
                ',dept_id='.db_input($deptId).
                ',staff_id='.db_input($staffId).
                ',helptopic='.db_input(Format::striptags($topicDesc)).
                ',phone='.db_input($var['phone']).
                ',phone_ext='.db_input($var['phone_ext']?$var['phone_ext']:'').
                ',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:

Code:
$tabs['rules']=array('desc'=>'Rules','href'=>'rules.php','title'=>'Rules');
Reply With Quote
  #52  
Old 03-28-2012, 01:35 PM
scottro's Avatar
scottro scottro is offline
Senior Member
 
Join Date: Jul 2009
Posts: 726
Default

Right on, I'm glad you like it and I'm happy to see you were able to modify it for your needs. I haven't spent any time with any of my MODs recently except for the Reports MOD.
__________________
Sudo Bash Creations
Sudo Bash - osTicket MODs
Reply With Quote
  #53  
Old 03-29-2012, 06:58 AM
ZeroEffect ZeroEffect is offline
Member
 
Join Date: Sep 2011
Posts: 43
Default

I have added the auto assign ability to web based tickets and the help topics. I'll share once I am finished testing, so far so good. The only issue I have is only managers of the group/department are sent emails.

If I have a department called "Tier 1" and there are three people in the department.

Bob, John, and Sara

With Bob being the manager if a ticket is assigned to Bob an email gets sent out to Bob. When a ticket is assigned to John or Sara, emails are not sent to them but to the manager Bob. When no manager is selected for the department emails are sent to no one.

I am not sure if this is a MOD issue or just how OSTicket works.

Anyone have thoughts on this?

Thanks

ZeroEffect
Reply With Quote
  #54  
Old 03-29-2012, 02:13 PM
lmg lmg is offline
Junior Member
 
Join Date: Mar 2012
Posts: 3
Default

What are your Alerts & Notices settings in the Admin panel -> Settings tab (scroll all the way to the bottom)?
Reply With Quote
  #55  
Old 03-29-2012, 07:00 PM
ZeroEffect ZeroEffect is offline
Member
 
Join Date: Sep 2011
Posts: 43
Default my settings

These are my settings. enabled/selections are in bold.

Notices sent to user use 'No Reply Email' whereas alerts to staff use 'Alert Email' set above as FROM address respectively.
New Ticket Alert: Enabled
Select recipients
Admin Email Department Manager Department Members (spammy)
New Message Alert: EnableSelect recipients
Last Respondent Assigned Staff Department Manager (spammy)
New Internal Note Alert: Enable
Select recipients
Last Respondent Assigned Staff Department Manager (spammy)
Overdue Ticket Alert: Enable
Admin Email gets an alert by default. Select additional recipients below
Assigned Staff Department Manager Department Members (spammy)
System Errors: Enabled errors are sent to admin email set above
System Errors SQL errors Excessive Login attempts
Reply With Quote
  #56  
Old 04-10-2012, 04:37 PM
ZeroEffect ZeroEffect is offline
Member
 
Join Date: Sep 2011
Posts: 43
Post My additions to this MOD

While this MOD did most of what I wanted it did not auto assign for client web based tickets. After looking at the code and trial and error I have auto assign working for client web based tickets.

Here is everything I did.
  • Modified the rules.php and add_rule.php to use help topics in the system.
  • Modified the code in class.ticket.php to look for web based tickets.

Modifying the rules.php file.

Code:
Original MOD code

<td align="center"><strong>Category</strong></td>
<td align="center"><strong>Contains</strong></td>
<td align="center"><strong>Assign To</strong></td>

My change

<td align="center"><strong>Category</strong></td> 
   <td align="center"><strong>Help Topic</strong></td> 
<td align="center"><strong>Assign To</strong></td>
Code:
Original MOD Code

<select name="Category[]"><option value="subject" <? if($rows['Category'] == "subject"){print "SELECTED";}?>>Subject</option><option value="email" <? if($rows['Category'] == "email"){print "SELECTED";}?>>Email</option></select> 

My Change

<select name="Category[]"><option value="web" <? if($rows['Category'] == "web"){print "SELECTED";}?>>Web</option><option value="subject" <? if($rows['Category'] == "subject"){print "SELECTED";}?>>Subject</option><option value="email" <? if($rows['Category'] == "email"){print "SELECTED";}?>>Email</option></select>
Changes to the add_rule.php file.

Code:
Original MOD code

<td align="center"><strong>Category</strong></td>
<td align="center"><strong>Contains</strong></td>
<td align="center"><strong>Assign To</strong></td> 

My change

<td align="center"><strong>Category</strong></td> 
    <td align="center"><strong>Help Topic</strong></td> 
<td align="center"><strong>Assign To</strong></td>
Code:
Original MOD code

<input name="Criteria" type="text" id="Criteria">

My Change

<select name="Criteria">
<option value=0> </option> 
	<? 
	   $topics= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.''); 
	   while (list($topicId,$topicName) = db_fetch_row($topics)){?> 
	   <option value="<?=$topicName?>" ><?=$topicName?></option>
	<?}?> 
</select>
The changes above renamed my cell titles and populated my criteria with help topics.

Changes to the /include/class.ticket.php file.

Code:
Orignal MOD code
        $subject=(Format::striptags($var['subject'])); 
        $email=($var['email']);

        $qry = sprintf("SELECT * FROM ost_ticket_rules;"); 

My Changes

        $subject=(Format::striptags($var['subject'])); 
        $email=($var['email']);

// add web selection
	$web=(Format::striptags($topicDesc));
// End
  
      $qry = sprintf("SELECT * FROM ost_ticket_rules;");
Code:
Original MOD code

      if( "$isenabled" == "on" ) 
      { 
        if( "$Category" == "subject" ) 
        { 
        if (preg_match("/$Criteria/i", $subject)) 
           { 
             if( "$Action" == "deptId" ) 
              { 
                $deptId=$Department; 
              } 
             elseif( "$Action" == "staffId" ) 
              { 
                $staffId=$Staff; 
                $staffId=preg_replace( '/\n/', '', trim($staffId) ); 
                 $qry = sprintf("SELECT dept_id FROM `ost_staff` WHERE staff_id=$Staff;"); 
                 $result=mysql_query($qry); 
                 while ( $row = mysql_fetch_assoc($result)){ 
                  $deptId=$row['dept_id']; 
                  } 
              } 
           } 
        } 

My Changes

      if( "$isenabled" == "on" ) 
      { 
// Add web check
        if( "$Category" == "web" ) 
         {
        if (preg_match("/$Criteria/i", $web)) 
           { 
             if( "$Action" == "deptId" ) 
              { 
                $deptId=$Department; 
              } 
             elseif( "$Action" == "staffId" ) 
              { 
                $staffId=$Staff; 
                $staffId=preg_replace( '/\n/', '', trim($staffId) ); 
                 $qry = sprintf("SELECT dept_id FROM `ost_staff` WHERE staff_id=$Staff;"); 
                 $result=mysql_query($qry); 
                 while ( $row = mysql_fetch_assoc($result)){ 
                  $deptId=$row['dept_id']; 
                  } 
              } 
           } 
        }
// End
        elseif( "$Category" == "subject" ) //orignal start of the "if" statment.
I also had to change this line because I am running version 1.6ST
Code:
// Pre 1.6ST               ',topic='.db_input(Format::striptags($topicDesc)). 
                ',helptopic='.db_input(Format::striptags($topicDesc)).
Now all client web tickets auto assign. now I have only one more thing to add and that is a priority for each rule. Help topic X get a priority of high while help topic Y gets a priority of normal and so on. I know it can be done, but how.

I don't think I missed any of my changes. I am sure someone will post if I did.

This is a great MOD!

ZeroEffect
Reply With Quote
  #57  
Old 04-11-2012, 04:01 PM
ZeroEffect ZeroEffect is offline
Member
 
Join Date: Sep 2011
Posts: 43
Talking Rules with Priorities!

Took me a bit but I got it working. the rules will now also assign a priority based on the rule.

First I added a column to the ticket_rules table, Priority.

Code:
// I think this was the code I used.

alter table ost_ticket_rules add column Priority text
Changes to the spc/rules.php file

Code:
<!-- add the priority column header -->
<td align="center"><strong>Priority</strong></td>
<td align="center"><strong>Last Updated</strong></td>
Code:
<!-- Added the combo box to the table cell -->
<td>
<select name="Priority[]">
   <option value=""></option> 
   <option value="3" <? if($rows['Priority'] == "3"){print "SELECTED";}?>>High</option>
   <option value="2" <? if($rows['Priority'] == "2"){print "SELECTED";}?>>Normal</option>
   <option value="1" <? if($rows['Priority'] == "1"){print "SELECTED";}?>>Low</option>
</select>  
</td>

<td align="center"><? echo $rows['updated']; ?></td>
Code:
<!-- added the variable and edited the sql statment

$STAFF = $_POST['Staff']; 
$PRIORITY = $_POST['Priority']; //added this line
$DELETE = $_POST['deleteRule']; 

Updated the sql Statment.

  $sql1="UPDATE ost_ticket_rules SET isenabled='$ISENABLED[$i]', Category='$CATEGORY[$i]', Criteria='$CRITERIA[$i]', Action='$ACTION[$i]', 

Department='$DEPARTMENT[$i]', Staff='$STAFF[$i]', Priority='$PRIORITY[$i]', updated=NOW() WHERE id='$id[$i]'"; 
  $result=mysql_query($sql1);
Changes to the spc/add_rules.php file

Code:
<!-- Add Priority column and table cell -->

<td align="center"><strong>Priority</strong></td> 

<td align="center"> 
   <select name="Priority">
      <option value="3">High</option>
      <option value="2">Normal</option>
      <option value="1">Low</option>
   </select> 
</td>
Code:
<!-- add the variable and change the sql statment -->

$PRIORITY = $_POST['Priority']; 

$sql="INSERT INTO ost_ticket_rules (isenabled, Category, Criteria, Action, Department, Staff, Priority, updated, created) 
VALUES ('$_POST[isenabled]','$_POST[Category]','$_POST[Criteria]','$_POST[Action]','$_POST[Department]','$_POST[Staff]', '$_POST[Priority]', NOW(), NOW())";
edited the include/class.ticket.php file

Code:
//Add the priority 
      $Staff=$row['Staff'];
      $Priority=$row['Priority']; // new line

//and assign it the value from the rules in the if statments, all of them.

                $priorityId=$Priority;
                $priorityId=preg_replace( '/\n/', '', trim($priorityId) );
                $staffId=$Staff; 
                $staffId=preg_replace( '/\n/', '', trim($staffId) );
Now when rule criteria are met the default priority is over ruled by the priority set in the rule.

I have one thing left to do to the rules.php file. Ok two things.
  1. Need to load the help topics in a combo box and select the active topic
  2. Rule updates do not work. they did not work before all of my changes. I need to find some logs.

Any help on those two things is welcome.

Thanks

ZeroEffect
Reply With Quote
  #58  
Old 04-12-2012, 04:20 PM
ZeroEffect ZeroEffect is offline
Member
 
Join Date: Sep 2011
Posts: 43
Default

Okay, I got the help topics on the rules page completed.

Code:
<!-- <input name="Criteria[]" type="text" id="Criteria" value="<? echo $rows['Criteria']; ?>"> -->
<select name="Criteria[]">
<option value=0> </option> 
	<? 
	   $topics= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.''); 
	   while (list($topicId,$topicName) = db_fetch_row($topics)){?> 
           <option value="<?=$topicName?>" <? if($topicName == $rows['Criteria']){print SELECTED;}?>>><?=$topicName?></option>
	<?}?> 
</select>
now to get the rules to update.....
Reply With Quote
  #59  
Old 04-13-2012, 12:01 PM
ZeroEffect ZeroEffect is offline
Member
 
Join Date: Sep 2011
Posts: 43
Smile And complete.

Finally I got updating rules to work. I was able to find that the id in the sql statement was not being set or referenced.

in the scp/rules.php file we need to add the ID to each row and assign it. I added this line in the same cell as the check box for deleting the row.

Code:
<input name="id[]" type="hidden" value="<?=$rows['id']; ?>">

here it is in the cell

<td align="center"><input name="id[]" type="hidden" value="<?=$rows['id']; ?>"><input type="checkbox" name="deleteRule[]" value="<?=$rows['id']; ?>"></td>
Doing the above gave me the data without showing the id number.

Now all I had to do was assign it to the variable all ready in the sql statement.

Code:
$id = $_POST['id']; //added line
$ISENABLED = $_POST['isenabled']; 
$CATEGORY = $_POST['Category'];
Now everything works! Great MOD!

ZeroEffect
Reply With Quote
  #60  
Old 04-14-2012, 04:39 AM
dr-reen dr-reen is offline
Junior Member
 
Join Date: Apr 2012
Posts: 1
Default

Is there any possibility to check not only the subject but the whole email text for a certain phrase to create an auto-assignment rule?

This is really something I am desperately looking for :-)
Reply With Quote


Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:28 AM.