1. This sub-forum relates to Kayako 3, which is now end-of-life. Please be aware that a lot of information relating to features, sales and the roadmap in the Kayako 3 forums is now outdated or defunct (no longer applicable).

    If unsure about anything, please create a new thread or contact us.

    You can visit the main forums for the latest Kayako here.

Create Alerts for Other Staff

Discussion in 'Modifications, extensions and addons' started by Matthew, Jul 8, 2009.

  1. Matthew

    Matthew Reputed Member

    How many times have you had to explain to staff how to create an alert? And even then, how many times do you end up doing it for the staff by working under that staff's account? Ack! What a pain! You're an admin... why can't you assign an alert to staff under your own account?

    Well, now you can.

    In /modules/tickets/functions_alertrulesui.php, replace function updateAlertRule with...
    PHP:
    function updateAlertRule($alertruleid$title$alerttype$alertscope$departmentid$priorityid$ticketstatusid$execassign$alertactions$staffid 0)
    {
        
    // Allow admins to assign alerts to staff
        // Mod by Matthew Arciniega, 2009-07-08
        // 1) Added $staffid parameter to function parameters, above
        // 2) Changed the query below to use this parameter instead of intval($_SWIFT["staff"]["staffid"])
        
    global $dbCore$_SWIFT;

        if (!
    _is_array($alertactions))
        {
            return 
    false;
        }

        
    $dbCore->query("UPDATE `"TABLE_PREFIX ."alertrules` SET `alertscope` = '"intval($alertscope) ."', `staffid` = '"intval($staffid) ."', `departmentid` = '"intval($departmentid) ."', `priorityid` = '"intval($priorityid) ."', `ticketstatusid` = '"intval($ticketstatusid) ."', `alerttype` = '"intval($alerttype) ."', `execassign` = '"intval($execassign) ."', `title` = '"$dbCore->escape($title) ."' WHERE `alertruleid` = '"intval($alertruleid) ."';");

        
    deleteAllAlertActions(array($alertruleid));

        
    insertAlertActions($alertruleid$alertactions);

        return 
    true;
    }
    Replace function insertAlertRule with...
    PHP:
    function insertAlertRule($title$alerttype$alertscope$departmentid$priorityid$ticketstatusid$execassign$alertactions$staffid 0)
    {
        
    // Allow admins to assign alerts to staff
        // Mod by Matthew Arciniega, 2009-07-08
        // 1) Added $staffid parameter to function parameters, above
        // 2) Changed the query below to use this parameter instead of intval($_SWIFT["staff"]["staffid"])
        
    global $dbCore$_SWIFT;

        if (!
    _is_array($alertactions))
        {
            return 
    false;
        }

        
    $dbCore->query("INSERT INTO `"TABLE_PREFIX ."alertrules` (`alertscope`, `staffid`, `departmentid`, `priorityid`, `ticketstatusid`, `alerttype`, `execassign`, `title`) VALUES ('"intval($alertscope) ."', '"intval($staffid) ."', '"intval($departmentid) ."', '"intval($priorityid) ."', '"intval($ticketstatusid) ."', '"intval($alerttype) ."', '"intval($execassign) ."', '"$dbCore->escape($title) ."');");
        
    $alertruleid $dbCore->lastInsertId();
        if (!
    $alertruleid)
        {
            return 
    false;
        }

        
    insertAlertActions($alertruleid$alertactions);

        return 
    $alertruleid;
    }
    Now search for this line in the same file:
    PHP:
        printDescRow($_SWIFT["language"]["alertoptions"]);
    Insert below it:
    PHP:
        // Allow admins to assign alerts to staff
        // Mod by Matthew Arciniega, 2009-07-08
        
    $isadmin intval($_SWIFT["staff"]["isadmin"]); 
        if (
    $isadmin) {
            
    $options = array();
            
    $index 0;
            foreach (
    $_SWIFT["staffcache"] as $key=>$val)
            {
                
    $options[$index]["title"] = $val["fullname"];
                
    $options[$index]["value"] = $val["staffid"];
                
    $index++;
            }
            
    printSelectRow("staffid""Assign to Staff""Set the alert for this staff member."$options);
        } else {
            
    addHiddenField("staffid"intval($_SWIFT["staff"]["staffid"]));
        }
        
    // End Mod by Matthew Arciniega
    Now search for this line a bit further down...
    PHP:
        $departmentidlist getAssignedDepartments(MODULE_TICKETS);
    ... and replace the entire foreach loop which follows it with...
    PHP:
        foreach ($_SWIFT["departmentcache"] as $key=>$val)
        {
            
    // Allow admins to assign alerts to staff
            // Mod by Matthew Arciniega, 2009-07-08
            
    if ($isadmin || (!$isadmin && ($val["departmentmodule"] == MODULE_TICKETS && in_array($val["departmentid"], $departmentidlist))))
            {
                
    $options[$index]["title"] = $val["title"];
                
    $options[$index]["value"] = $val["departmentid"];
                
    $index++;
            }
            
    // End Mod by Matthew Arciniega
        
    }
    Updated: Search for this line in function deleteAlertRules:
    PHP:
            if (($dbCore->Record["alertscope"] == && $dbCore->Record["staffid"] == $_SWIFT["staff"]["staffid"]) || ($dbCore->Record["alertscope"] == && ($_SWIFT["staff"]["tdelarule"] != "0")))
    Replace with:
    PHP:
            if (($dbCore->Record["alertscope"] == && $dbCore->Record["staffid"] == $_SWIFT["staff"]["staffid"]) || ($dbCore->Record["alertscope"] == && $_SWIFT["staff"]["tdelarule"] != "0") || $_SWIFT["staff"]["isadmin"] == 1)
    Now let's work with /modules/tickets/staff_alertrules.php.

    First, locate this line...
    PHP:
        $record["title"] = '<table width="100%"  border="0" cellspacing="0" cellpadding="1"><tr><td width="1"><img src="'$_SWIFT["themepath"] .'icon_alertrules.gif" border="0" /></td><td><span class="smalltext">&nbsp;<a href="index.php?_m=tickets&_a=editalert&alertruleid='$record["alertruleid"] .'">'$record["title"] .'</a></span></td></tr></table>';
    Insert above it...
    PHP:
        $record["creator"] = $_SWIFT["staffcache"][$record["staffid"]]["fullname"];
        
    $record["execassign"] = iif($record["execassign"], "Yes""No");
    Further down, locate the Manager Alerts sections and replace the entire thing with this:
    PHP:
    /**
    * ###############################################
    * MANAGE ALERTS
    * ###############################################
    */
    if ($eventaction == "managealerts")
    {
        if (
    $_GET["do"] == "delete" && !empty($_GET["alertruleid"]))
        {
            
    $infomessage $_SWIFT["language"]["ardelconfirm"];

            
    deleteAlertRules(array($_GET["alertruleid"]));
        }

        if (!empty(
    $_GET["insertrule"]))
        {
            
    $infomessage sprintf($_SWIFT["language"]["arinsertconfirm"], htmlspecialchars($_GET["insertrule"]));
        } else if (!empty(
    $_GET["editrule"])) {
            
    $infomessage sprintf($_SWIFT["language"]["areditconfirm"], htmlspecialchars($_GET["editrule"]));
        }
        

        
    $options["recordsperpage"] = "10";
        
    $options["sortby"] = "title";
        
    $options["sortorder"] = "asc";
        
    $options["massaction"][0]["title"] = $_SWIFT["language"]["delete"];
        
    $options["massaction"][0]["callback"] = "_maDeleteAlertRules";

        
    $options["idname"] = "alertruleid";
        
    $options["quicksearch"] = true;
        
        
    // Allow admins to assign alerts to staff
        // Mod by Matthew Arciniega, 2009-07-08
        
    $isadmin intval($_SWIFT["staff"]["isadmin"]); // MA:2009-07-08
        
    if ($isadmin) {
            
    $querystr '';
        } else {
            
    $querystr ' AND `staffid` = 'intval($_SWIFT["staff"]["staffid"]);
        }

        
    $options["advancedsearch"][0]["title"] = $_SWIFT["language"]["title"];
        
    $options["advancedsearch"][0]["query"] = 'SELECT * FROM `'TABLE_PREFIX .'alertrules` WHERE `title` LIKE \'%$_searchstr%\' AND ((`alertscope` = \''ALERT_PUBLIC .'\') OR (`alertscope` = \''ALERT_PRIVATE .'\''$queryStr .')) $_sortjoin;';
        
    // End Mod
        
    $options["callback"] = "_alertRuleFields";

        
    $fields[0]["name"] = "title";
        
    $fields[0]["title"] = $_SWIFT["language"]["ruletitle"];
        
    $fields[0]["width"] = "";

        
    $fields[1]["name"] = "alerttype";
        
    $fields[1]["title"] = $_SWIFT["language"]["alerttype"];
        
    $fields[1]["width"] = "100";
        
    $fields[1]["align"] = "center";

        
    $fields[2]["name"] = "alertscope";
        
    $fields[2]["title"] = $_SWIFT["language"]["alertscope"];
        
    $fields[2]["width"] = "100";
        
    $fields[2]["align"] = "center";

        
    $fields[3]["name"] = "creator";
        
    $fields[3]["title"] = "Assigned Staff";
        
    $fields[3]["width"] = "150";
        
    $fields[3]["align"] = "center";
        
    $fields[3]["type"] = "custom";
        

        
    $fields[4]["type"] = "custom";
        
    $fields[4]["name"] = "execassign";
        
    $fields[4]["title"] = "Assigned Only";
        
    $fields[4]["width"] = "100";
        
    $fields[4]["align"] = "center";

        
    $fields[5]["type"] = "custom";
        
    $fields[5]["name"] = "options";
        
    $fields[5]["title"] = $_SWIFT["language"]["options"];
        
    $fields[5]["width"] = "150";
        
    $fields[5]["align"] = "center";

        
    $grid = new Grid();

        
    renderTicketTree();
        
    $interface->staffHeader($_SWIFT["language"]["tickets"]." &gt; ".$_SWIFT["language"]["managealerts"], 2);

        
    $interface->staffNavBar('<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["tickets"].'">'.$_SWIFT["language"]["tickets"].'</a> &raquo; <a href="index.php?_m=tickets&_a=managealerts" title="'.$_SWIFT["language"]["managealerts"].'">'.$_SWIFT["language"]["managealerts"].'</a>'""2);

        
    // Allow admins to assign alerts to staff
        // Mod by Matthew Arciniega, 2009-07-08
        
    if ($isadmin) {
            
    $querystr '';
        } else {
            
    $querystr ' AND `staffid` = 'intval($_SWIFT["staff"]["staffid"]);
        }

        
    $grid->start("alerts"$_SWIFT["language"]["alertrules"], 
            
    'SELECT * FROM `'TABLE_PREFIX .'alertrules` 
                WHERE (`alertscope` = \''
    "1" .'\') OR (`alertscope` = \''"0" .'\' 
                '
    .$querystr .') $_sortjoin;'
            
    'SELECT COUNT(*) AS totalitems 
                FROM `'
    TABLE_PREFIX .'alertrules` AS alertrules 
                WHERE (`alertscope` = \''
    ALERT_PUBLIC .'\') OR (`alertscope` = \''ALERT_PRIVATE .'\' 
                '
    .$querystr .');'
            
    'SELECT * FROM `'TABLE_PREFIX .'alertrules` 
                WHERE `title` LIKE \'%$_searchstr%\' 
                AND ((`alertscope` = \''
    ALERT_PUBLIC .'\') OR (`alertscope` = \''ALERT_PRIVATE .'\' 
                '
    .$querystr .')) $_sortjoin;'$fields$options);
        
    // End Mod
        
    printInfoBox($infomessage);
        
    printErrorBox($errormessage);

        
    $grid->display("alerts");

        
    $interface->staffFooter();
    Go down further to the Insert Alert Rule section. Locate this...
    PHP:
                insertAlertRule($_POST["title"], $_POST["alerttype"], $_POST["alertscope"], $_POST["departmentid"], $_POST["priorityid"], $_POST["ticketstatusid"], $_POST["execassign"], $_POST["alertactions"]);
    Replace with...
    PHP:
                insertAlertRule($_POST["title"], $_POST["alerttype"], $_POST["alertscope"], $_POST["departmentid"], $_POST["priorityid"], $_POST["ticketstatusid"], $_POST["execassign"], $_POST["alertactions"], $_POST["staffid"]);
                
    // Allow admins to assign alerts to staff
                // Mod by Matthew Arciniega, 2009-07-08
                // Added $_POST["staffid"] to above parameters
    In the Edit Alert Rule section further down, find this..

    PHP:
                updateAlertRule($_alertrule["alertruleid"], $_POST["title"], $_POST["alerttype"], $_POST["alertscope"], $_POST["departmentid"], $_POST["priorityid"], $_POST["ticketstatusid"], $_POST["execassign"], $_POST["alertactions"]);
    Replace with this...
    PHP:
                updateAlertRule($_alertrule["alertruleid"], $_POST["title"], $_POST["alerttype"], $_POST["alertscope"], $_POST["departmentid"], $_POST["priorityid"], $_POST["ticketstatusid"], $_POST["execassign"], $_POST["alertactions"], $_POST["staffid"]);
                
    // Allow admins to assign alerts to staff
                // Mod by Matthew Arciniega, 2009-07-08
                // Added $_POST["staffid"] to above parameters);
    Save, and enjoy the ability to create alerts for any staff.

    [​IMG]

    [​IMG]

    Attached Files:

  2. Casey Rousseau

    Casey Rousseau New Member

    On concept alone (I'm not going to be implementing this, much as I wished it was part of the product when I was setting up eSupport to begin with) Bravo!
  3. joshuah

    joshuah New Member

    Great release, maybe you can release some screenshots of the changes?
  4. dcarrion

    dcarrion New Member

    I added this mod today and it works great. Its pretty self-explanatory. You just get to see all employee alerts under Manage Alerts. And this adds a drop-down to assign an alert to a particular staff member when you are creating one.

    Thanks for the nice addition Matthew!
  5. Matthew

    Matthew Reputed Member

    Thanks guys!

    I was just working with this, and I realized... Oops! :eek: As an admin I wasn't able to delete the rules I created for other people!

    So I've update my original post with the code that should fix it, plus a couple screenshots.
  6. smartcard

    smartcard Member

    Is this working on 3.70.02 version?

Share This Page