Jump to content

ticket status on reply


snake

Recommended Posts

Is there anyw ay to stop the ticket status form being automatically changed to "answered" when replying to a ticket?

Often I need to reply to a ticket to let customer know I am working on it, but keep it open.
Yes I know I can manually change the status when replying, but I never remember to do this, which means the tickets get set to answered, and I forget about them.

So I would prefer to have status stay open by default unless I change it.

Link to comment
Share on other sites

Quick and dirty:

<?php

add_hook('AdminAreaViewTicketPage', 1, function ($vars) {
    return <<<HTML
        <script>
            jQuery(document).ready(function() {
                jQuery('*[data-value="Answered"]').click();
                
                setTimeout(function(){
                    jQuery('*[data-value="Open"]').click();
                }, 200);
            });
        </script>
    HTML;
});

Save under /includes/hooks/<any_filename>.php

Edited by string
Link to comment
Share on other sites

  • 8 months later...

hi,

thanks for this, I did not see this reply until now.

 

when I say keep it open, what I actually need is to keep the original status and not change it to "answered".

so if the ticket is "open" when I reply, keep it open.
if the ticket is "in progress" when I reply, keep it this way

The status should only change if I actually choose to changem not change automatically.

Link to comment
Share on other sites

Hi Snake,

So the following hooks should work, can add them all to one hook file in the /includes/hooks/ folder. Bit messy but don't see any other way to do this as sessions don't carry between hooks and theres no way to grab the previous status in the TicketAdminReply hook which is incredibly annoying.

<?php

use WHMCS\Database\Capsule;

# Need to store the current status in the database
function store_current_ticket_status($vars) {

    # Create custom database table if it does not already exist.
    if (!Capsule::schema()->hasTable('mod_keepticketstatus')) {

        try {
          
            Capsule::schema()->create('mod_keepticketstatus', function ($table) {
                $table->increments('id');
                $table->string('ticketid');
                $table->string('status');
            });
        
        } catch(\Exception $e) {
            logActivity("Unable to create table 'mod_keepticketstatus', the following error was returned: {$e->getMessage()}");
        }

    }

    # Grab current ticket details
    $ticket = Capsule::table('tbltickets')->where('id', $vars['ticketid'])->first();
    
    # Insert them into the custom table (or update if the entry is already there)
    Capsule::table('mod_keepticketstatus')->updateOrInsert([
        'ticketid'  => $ticket->id
    ], [
        'status'    => $ticket->status
    ]);

}

# Retrieve the current status from the database
function set_ticket_status_after_reply($vars) {

    # Grab ticket details
    $ticket = Capsule::table('tbltickets')->where('id', $vars['ticketid'])->first();
    
    # Check custom table to see if entry exists
    $custom = Capsule::table('mod_keepticketstatus')->where('ticketid', $ticket->id)->first();

    # If it exists then use the status stored in the database, otherwise revert to the default of 'Answered'
    if ($custom) {
        $status = $custom->status;
    } else {
        $status = 'Answered';
    }
    
    # Update the status of the ticket
    localAPI('UpdateTicket', [
        'ticketid'  => $vars['ticketid'],
        'status'    => $status
    ]);

}

# If the status is manually changed by an admin, ensure it is updated in the custom table also
function set_custom_ticket_status_on_change($vars) {
    
    # Insert them into the custom table (or update if the entry is already there)
    Capsule::table('mod_keepticketstatus')->updateOrInsert([
        'ticketid'  => $vars['ticketid']
    ], [
        'status'    => $vars['status']
    ]);

}

# If the ticket is deleted, ensure the entry is removed from the database to keep the table clean
function remove_custom_ticket_status_on_delete($vars) {

    Capsule::table('mod_keepticketstatus')->where('ticketid', $vars['ticketId'])->delete();

}

add_hook('AdminAreaViewTicketPage', 1, 'store_current_ticket_status');
add_hook('TicketAdminReply', 1, 'set_ticket_status_after_reply');
add_hook('TicketStatusChange', 1, 'set_custom_ticket_status_on_change');
add_hook('TicketDelete', 1, 'remove_custom_ticket_status_on_delete');

 

Link to comment
Share on other sites

Strange, its working for me. Can you change 

# Update the status of the ticket
localAPI('UpdateTicket', [
	'ticketid'  => $vars['ticketid'],
	'status'    => $status
]);

To

# Update the status of the ticket
Capsule::table('tbltickets')->where('id', $vars['ticketid'])->update([
	'status' => $status
]);

And try again? I've not used the Lara theme but can't really see how it would affect it.

Link to comment
Share on other sites

Do you have any other addon modules or hooks that might influence the status? I've just tested the code on another install and can confirm it works.

I'd suggest playing around with the hooks, especially the set_ticket_status_after_reply function to see if you can get it to work for your environment.

Link to comment
Share on other sites

I have noticed that it does actually keep the original status in the database, it just doesn;t change it on the form. 
So the dropdown on the form that doesn;t work and still changes to answered. Changing the value in the dropdown has no effect.

So now if I want to change the status, I have to reply to the ticket and submit

then go back into the ticket, and us ethe status at the top to change it.

 

Link to comment
Share on other sites

4 hours ago, snake said:

any luck figuring it out?

Hey snake,

Sorry, some how this thread slipped away from me. I still find it odd that the code does not work, have you tried it in a fresh environment? (e.g. a dev environment)

I've just tried it again on my dev environment and it works as expected, can you confirm if any errors are output in the console (Dev tools) or php or whmcs logs when you submit a ticket?

Link to comment
Share on other sites

6 hours ago, snake said:

I have tested it on 2 different whmcs installs.

on both, the status drop down is still defaulting to answered.

That's just bizarre, take a look at the video I recorded showing the correct behavior when I enable the addon.

Just to confirm, both the correct ticket id and status are being added to the mod_keepticketstatus table when you submit a reply? When you change the status also, does this change in the table yes?

Link to comment
Share on other sites

yes, as I mentioned before, I checked that the table was created and being updated, and the status in the db is being set.

it seems we are talking about different dropdowns.

I am referring to the one above the reply button, as this is the status that gets applied when you reply to a ticket.

The dropdown you are point to, above the ticket, it just used to change the status without replying.

 

Link to comment
Share on other sites

This application gives me unnecessary migraines... hopefully this is what you're looking for! The simple answer is, there is actually no need for a hook (remind me next time to take a look at the template files first 🙈)

Simply navigate to your admin folder and then open up /templates/blend/viewticket.tpl (or whatever template you use) and find the following lines of code (should be lines 102-104):

{foreach $statuses as $statusitem}
	<option value="{$statusitem.title}" style="color:{$statusitem.color}"{if $statusitem.title eq "Answered"} selected{/if}>{$statusitem.title}</option>
{/foreach}

Change them to (Yeah, it's that simple... 😬):

{foreach $statuses as $statusitem}
	<option value="{$statusitem.title}" style="color:{$statusitem.color}"{if $statusitem.title eq $status} selected{/if}>{$statusitem.title}</option>
{/foreach}

Voilà! Can't guarantee a future update wont revert that, if it does then simply update that template again. Oh, you can delete my old hook and remove the database table now if you wish.

Edited by leemahoney3
Link to comment
Share on other sites

1 hour ago, snake said:

I think I was given this suggestion previously, but I use a custom admin theme, so would lose those changes every time I install an update, and will likley forget to redo them every time.Thus why I was hoping for a hook to avoid that.

I did try it with a hook that returns JavaScript to update the drop down, however because that piece of code is in the smarty template (if $statusitem.title eq "Answered"), it does get a little messed up (you cant set the status to Answered).

If you'd prefer that, let me know. Basically no hook can override this without messing it up because the check for it being answered is hard coded into the Smarty template.

Edited by leemahoney3
Link to comment
Share on other sites

  • 3 months later...

I am not a PHP dev, although I have a background in coding in other languages (cobol, pascal, fortran, basic, assembler, ColdFusion), so can usually figure out basic stuff in PHP.

Since a lot of mods, like this one, require editing templates, I always thought it would be useful to create an addon that would perform automatic search and replace rules in templates.
This could then be execute manually or automatically whenever updates were installed.

e.g.

Rule name:  change status dropdown  behaviour
find this: 

{foreach $statuses as $statusitem}
	<option value="{$statusitem.title}" style="color:{$statusitem.color}"{if $statusitem.title eq "Answered"} selected{/if}>{$statusitem.title}</option>
{/foreach}

in this template: viewticket.tpl
and replace with:

{foreach $statuses as $statusitem}
	<option value="{$statusitem.title}" style="color:{$statusitem.color}"{if $statusitem.title eq $status} selected{/if}>{$statusitem.title}</option>
{/foreach}

replace how many occurances: 1
themes to update : (list of installed themes)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated