snake Posted November 19, 2021 Share Posted November 19, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
string Posted November 19, 2021 Share Posted November 19, 2021 (edited) 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 November 19, 2021 by string 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 9, 2022 Author Share Posted August 9, 2022 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. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 9, 2022 Share Posted August 9, 2022 You'll likely need two hooks to achieve this, one for viewing the ticket and then another for when a reply is made. I'll try throw some code together later on to see if we can get this to work. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 9, 2022 Share Posted August 9, 2022 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'); 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 9, 2022 Author Share Posted August 9, 2022 Thanks for that. I have tested it and its not working. the 'mod_keepticketstatus' table is being created, and the ticket status is being inserted, but when I reply to the ticket, it is still defaulting to "answered" 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 9, 2022 Author Share Posted August 9, 2022 I do use a custom admn theme called Lara if that would have any impact 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 9, 2022 Share Posted August 9, 2022 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. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 9, 2022 Author Share Posted August 9, 2022 alas no, the dropdown list is still defaulting to answered. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 9, 2022 Share Posted August 9, 2022 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. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 10, 2022 Author Share Posted August 10, 2022 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. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 10, 2022 Share Posted August 10, 2022 I'd be inclined to think the lara theme is causing that, or perhaps another hook or module. If you switch to the default theme and try, does the same behavior occur with the dropdown? 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 15, 2022 Author Share Posted August 15, 2022 yes it doe sthe same in the default BLEND theme. I do not have any other hooks or addons that touch ticket status. the only other tickt related addon I have is "bust rack ticket timer" I tried disabling this, no difference. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 22, 2022 Author Share Posted August 22, 2022 any luck figuring it out? 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 22, 2022 Share Posted August 22, 2022 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? 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 24, 2022 Author Share Posted August 24, 2022 I have tested it on 2 different whmcs installs. on both, the status drop down is still defaulting to answered. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 24, 2022 Share Posted August 24, 2022 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? 20220824_221634.mp4 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 25, 2022 Author Share Posted August 25, 2022 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. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 31, 2022 Author Share Posted August 31, 2022 is it possible to fix? If will pay you somehting for your time if we can get a working hook 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 31, 2022 Share Posted August 31, 2022 Heya snake, Apologies, the community didn't notify me of your reply. Leave this with me, I didn't realize it's that box you wish to update. I'll see if I can put something together by the end of tomorrow. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted September 1, 2022 Share Posted September 1, 2022 (edited) 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 September 1, 2022 by leemahoney3 0 Quote Link to comment Share on other sites More sharing options...
snake Posted September 2, 2022 Author Share Posted September 2, 2022 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. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted September 2, 2022 Author Share Posted September 2, 2022 ok I have just gone ahead and used this mod for now, since it works, thanks. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted September 2, 2022 Share Posted September 2, 2022 (edited) 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 September 2, 2022 by leemahoney3 0 Quote Link to comment Share on other sites More sharing options...
snake Posted December 7, 2022 Author Share Posted December 7, 2022 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) 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.