What would your client do if they forgot their ticket number? Especially when they wanted to check the ticket status after several days ago they received the email contains of that ticket number from your ticket system? In some ticket systems, they strongly recommended to re-open a new ticket immediately in order to get or know all of their ticket numbers (including the one they forgot, indeed), afterwards. In osTicket System version 1.6 RC5 (the last version I used until when I wrote this article), there was no feature about this. osTicket also recommend you to do the same way I mentioned above. So I made a modification by providing a new feature about Forgot Ticket Number? into osTicket System.
This modification will add a new link Forgot Ticket Number? beneath the Check Status button on your index.php file. Thus, when client forgot their ticket number, we assume they will click on this link, and after that, your client need to enter their email address and click the Send My Ticket List button in order to get their ticket number list. This page, actually, is the same page that we use if client want to check their ticket status. You can see upon the Forgot Ticket Number? link, the Ticket Status will be collapsed when the Forgot Ticket Number? section being expanded, and vice versa. Besides that, this modification also will add a new section inside the email templates in admin panel. You can define your own email template that sent to your client.
Screenshot: http://www.osticket.com/forums/showthread.php?t=2729
- First of all, you have to add two new fields to your ost_email_template table in the database used by your osTicket system. Run the following SQL script. You may use phpMyAdmin or your another MySQL tools:
ALTER TABLE ost_email_template ADD COLUMN `forgot_ticket_subj` varchar(255) NOT NULL, ADD COLUMN `forgot_ticket_body` text NOT NULL;
- Open index.php file, and find this code:
56 57
<input type="submit" class="button2" value="Check Status"> </fieldset>
and replace with:
56 57 58 59 60 61
<input type="submit" class="button2" value="Check Status"> </fieldset> <fieldset> <label> </label> <div class="forgotticketnumber"><a href="forgotticket.php">Forgot Ticket Number?</a></div> </fieldset>
- Open \styles\main.css file, and find this code:
1 2 3 4 5 6 7
body { font-family:arial, helvetica, sans-serif; font-size:9pt; margin:0; padding:0; text-align:center; }after the last line of that code, please add this following code:
9 10 11 12 13
.forgotticketnumber { font-size:8pt; padding-right:0.1px; padding-left:140px; } - Create a new file and copy this following code into the file and save it as forgotticket.php in your osTicket root directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
<?php /** * @desc Forgot Ticket Number * @author Masino Sinaga * @copyright July 27, 2009 */ require_once('main.inc.php'); if(!defined('INCLUDE_DIR')) die(LOGIN_FATAL_ERROR); define('CLIENTINC_DIR',INCLUDE_DIR.'client/'); define('OSTCLIENTINC',TRUE); //make includes happy require_once(INCLUDE_DIR.'class.client.php'); require_once(INCLUDE_DIR.'class.ticket.php'); include_once(INCLUDE_DIR.'class.email.php'); global $cfg; $forgotmsg='Email required'; if($_POST && (!empty($_POST['femail']) )): $femail=trim($_POST['femail']); if(!$errors && Validator::is_email($femail)) { //$email= new Client($femail); $sqle='SELECT email, ticketID, name FROM '.TICKET_TABLE. ' WHERE email='.db_input($femail).' AND status = "open"'; $respe=db_query($sqle); $ticketNumber = ''; $countRec = db_num_rows($respe); if ($countRec > 0) { $i = 1; $nameForgot = ''; while (list($email,$ticketID,$name) = db_fetch_row($respe)){ if ($i==1) { $ticketNumber .= $ticketID; } else { $ticketNumber .= ", ". $ticketID; } $nameForgot = $name; $i++; } $tplId=$cfg->getDefaultTemplateId(); $sql='SELECT forgot_ticket_subj,forgot_ticket_body FROM '.EMAIL_TEMPLATE_TABLE. ' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId); $resp=db_query($sql); if(db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){ $body = str_replace("%name", $nameForgot, $body); $body = str_replace("%email", $email, $body); $body = str_replace("%ticketlist", $ticketNumber, $body); if(!$dept || !($email=$dept->getAutoRespEmail())) $email=$cfg->getDefaultEmail(); if($email) $email->send($femail,$subj,$body); } require(CLIENTINC_DIR.'header.inc.php'); echo "We have sent your ticket list. "; echo "Please check your email in a few minutes."; require(CLIENTINC_DIR.'footer.inc.php'); exit; } else { require(CLIENTINC_DIR.'header.inc.php'); echo "<p align='center'>Sorry, but that email does not exist."; echo "<input name='back' type='Button' value='Go Back' onclick='javascript:window.history.back()'>"; require(CLIENTINC_DIR.'footer.inc.php'); exit; } } endif; require(CLIENTINC_DIR.'header.inc.php'); require(CLIENTINC_DIR.'login.inc.php'); require(CLIENTINC_DIR.'footer.inc.php'); ?>
- Open \include\client\login.inc.php, and find this code:
5 6 7
$t=Format::htmlchars($_POST['lticket']?$_POST['lticket']:$_GET['t']); ?> <div>
replace that code with this following code:
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
$t=Format::htmlchars($_POST['lticket']?$_POST['lticket']:$_GET['t']); $f=Format::htmlchars($_POST['femail']?$_POST['femail']:$_GET['f']); ?> <head> <script type="text/javascript" > <!-- function expand_collapse(divid,imgpath,imgname) {if(document.getElementById(divid).style.display=='none') {document.getElementById(divid).style.display='block';eval("document."+imgname+".src = imgpath + '/col-btn.gif'");} else {document.getElementById(divid).style.display='none';eval("document."+imgname+".src = imgpath + '/exp-btn.gif'");}} //--> </script> </head> <div>
Find also this code:
28
<div style="margin:5px 0px 100px 0;text-align:center; width:100%;">
replace with the following code:
28 29 30 31 32 33 34 35
<div style="margin:5px 0px 100px 0;text-align:center; width:100%;"> <?php $img = ($loginmsg=='')?'./images/exp-btn.gif':'./images/col-btn.gif'; $disp = ($loginmsg=='')?'display:none':'display:true'; echo '<a href="javascript:void(0);" class="Button" onClick="javascript:expand_collapse(\'ticket_status\',\'./images\',\'email_ticket\');">Ticket Status <img src="'.$img.'" name="email_ticket"></a>'; echo '<div id="ticket_status" style="'.$disp.'">'; ?>
Find again this code:
41
<form action="login.php" method="post">
replace with this following code:
41
<form name="login" action="login.php" method="post">
Find then this code:
49 50
</form> </div>
replace with this following code:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
</form> </div> <br /><br /> <?php $img = ($forgotmsg=='')?'./images/exp-btn.gif':'./images/col-btn.gif'; $disp = ($forgotmsg=='')?'display:none':'display:true'; echo '<a href="javascript:void(0);" class="Button" onClick="javascript:expand_collapse(\'forgot_ticket\',\'./images\',\'pwd_exp_col\');">Forgot Ticket Number? <img src="'.$img.'" name="pwd_exp_col"></a>'; echo '<div id="forgot_ticket" style="'.$disp.'">'; ?> <span class="error"><?=Format::htmlchars($forgotmsg)?></span> <form name="forgot" action="forgotticket.php" method="post"> <table cellspacing="1" cellpadding="5" border="0" bgcolor="#000000" align="center"> <tr bgcolor="#EEEEEE"> <td>E-Mail:</td><td><input type="text" name="femail" size="25" value="<?=$f?>"></td> <td><input class="button" type="submit" value="Send My Ticket List"></td> </tr> </table> </form> </div> </div> - Open include\class.msgtpl.php file, and find this code:
92
$fields['ticket_reply_body'] = array('type'=>'string', 'required'=>1, 'error'=>'Template message required');
replace with this following code:
92 93 94 95 96
$fields['ticket_reply_body'] = array('type'=>'string', 'required'=>1, 'error'=>'Template message required'); // MOD Forgot Ticket Number, added by Masino Sinaga, July 27, 2009 $fields['forgot_ticket_subj'] = array('type'=>'string', 'required'=>1, 'error'=>'Subject required'); $fields['forgot_ticket_body'] = array('type'=>'string', 'required'=>1, 'error'=>'Template message required');
Find also this code:
143 144
',ticket_reply_body='.db_input(Format::striptags($var['ticket_reply_body'])). ' WHERE tpl_id='.db_input($this->getId());
replace with this following code:
143 144 145 146
',ticket_reply_body='.db_input(Format::striptags($var['ticket_reply_body'])). ',forgot_ticket_subj='.db_input(Format::striptags($var['forgot_ticket_subj'])). ',forgot_ticket_body='.db_input(Format::striptags($var['forgot_ticket_body'])). ' WHERE tpl_id='.db_input($this->getId());
Find again this code:
209
',ticket_reply_body='.db_input(Format::striptags($info['ticket_reply_body']));
replace with this following code:
209 210 211
',ticket_reply_body='.db_input(Format::striptags($info['ticket_reply_body'])). ',forgot_ticket_subj='.db_input(Format::striptags($var['forgot_ticket_subj'])). ',forgot_ticket_body='.db_input(Format::striptags($var['forgot_ticket_body']));
- Open \include\staff\template.inc.php file, and find this code:
88 89 90 91 92
<tr> <th>Message Body:</td> <td><textarea rows="7" cols="75" name="ticket_reply_body"><?=$tpl['ticket_reply_body']?></textarea> <font class="error"> <?=$errors['ticket_reply_body']?></font></td> </tr>replace with this following code:
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
<tr> <th>Message Body:</td> <td><textarea rows="7" cols="75" name="ticket_reply_body"><?=$tpl['ticket_reply_body']?></textarea> <font class="error"> <?=$errors['ticket_reply_body']?></font></td> </tr> <tr class="header"><td colspan=2 > Forgot Ticket Number</td></tr> <tr class="subheader"><td colspan=2 > Message template used when responding the Forgot Ticket Number request from user. </td></tr> <tr> <th>Subject</th> <td> <input type="text" size="65" name="forgot_ticket_subj" value="<?=$tpl['forgot_ticket_subj']?>"> <font class="error"> <?=$errors['forgot_ticket_subj']?></font></td> </tr> <tr> <th>Message Body:</td> <td><textarea rows="7" cols="75" name="forgot_ticket_body"><?=$tpl['forgot_ticket_body']?></textarea> <font class="error"> <?=$errors['forgot_ticket_body']?></font></td> </tr>
Please note that you need two additional files.
They are:
1) col-btn.gif (similar with minus image)
Collaps button
2) exp-btn.gif (similar with plus image)
Expand button
Right-click on that image, and click Save Image As… to save to your computer. Then put those both files to your \images\ of your osTicket sub directory.
Before implementing this modification in your osTicket system, do not forget to define the email template regarding Forgot Ticket Number. Go to your admin panel, click on the Emails -> Templates, then click on the osTicket Default Template link item (the only one record after you install your osTicket System), then fill in the textbox from the Forgot Ticket Number section as follow:
Subject = Forgot Ticket Number
Message Body = %name,
This is the list of your tickets:
%ticketlist
Admin
and click on the Save Changes to save the changes.
Have a nice code!

I implemented the Forgot Ticket Number into my OSTicket system and now I can not update my templates. I guess I implemented the changes before defining the email template. Is there any work around to get this to work? Thanks.
@Colin
Have you re-checked all of your changes regarding this modification? Make sure each step has been already done correctly. Typically, that problem caused by a little mistake such as typo or something like that. Also, make sure you have already had two additional new fields in your ost_email_template table.
@Masino Sinaga
I checked all of the updates and they are all correct. The error message I receive is “Error updating the template. Try again” when I go to enter in the Subject “Forgot Ticket Number” and message body. Should I try to rerun the SQL script. Thanks!
Yes, you should. That’s why I put that step on the first one. It has to be done first of all in order to avoid that error. Please try again.
I am getting the same error with not being able to update the template. I did all the steps in order and was careful to do them precisely–except that I accidently made the forgot_ticket_body field a varchar field at first and implemented. I then changed it to text and tried again, but it does not work–I cannot edit my template. Is there anything that can be done?
Everything is working correctly except the mod is sending a blank email.
Thanks so much.
I’ve got the same pb after installing your MOD: “Error updating the template. Try again”.
Checking and analysing the DB with phpMyAdmin reported no pb.
I entered the email auto-response’s text directly in phpMyAdmin and had no pb to ask for lost tickets thru a fake user and received an answer with opened & closed tx.
Yet, I was still unable to modify my template (Error updating…).
I was then thinking the pb could lie in the ./include/staff/.
Looking in my svn I found that I mistakenly made the change on step 7 at line 42 instead of 88. Me stupid!
This created the mess.
What made me discover this was lines 89 and 105 (step 7), where you read :
Message Body:.
Quite an original ending for a start tag (the orig file has the same error).
Line 43 is Message Body: (orig file has correct html there).
Now it works.
Hope this helps,
Regards.
Ha!
The sytem seems to mess up html tags.
Let’s try this way.
… where you read :
Message Body:.
Quite an original ending for a start tag (the orig file has the same error).
Line 43 is Message Body: (orig file has correct html there).
I have updated the code from 88 line but still facing the same prob.
Error: “Error updating the template. Try again”
Or if possible please send me “template.inc.php” for version osticket_1.6.rc5
Please suggest.
@Ramesh Kumar
Have you defined your email template from Admin Panel -> Emails -> Templates -> osTicket Default Template -> Forgot Ticket Number ?
Error updating template usually happened if you have not defined the related template, yet. Make sure you have defined it. See the latest section/instruction in my article above.
Good luck!
@Francois
Glad to hear good news from you.
I am having the same problem with saving the template, I have read all of the above and checked I have everything in the right place but still no joy.
I have noticed in phpmyadmin that the two new tables are empty at present, is this correct?
Can you shed any light on my problem?
Thanks
Yogiman
Very appreciative of this Mod…I did follow all the steps, then noticed at the end that I was suppose to define the e-mail template…When I tried to do this, after I clicked “Add”, I got a blank page and could not define any variables…I tried reruning the MySql Script but I got the message that those fields already exist…I am a little stuck as to what to do…I am running the newest version of OSTicket as I just downloaded it…please help. Thank you so much.
~Chris
Hi,
I’ve just implemented this, but I dont see the EMail setup in the templates section.
Se debe colocar al final, archivo “template.inc.php”
Forgot Ticket Number
Message template used when responding the Forgot Ticket Number request from user.
Subject
<input type="text" size="65" name="forgot_ticket_subj" value="”>
Message Body:
Hi
Thank you for this wonderful mod.
But i am facing problem in implementing it.
I guess i am using 1.6 ST is the main cause .. but still most preferred option will be to ask..
Whether this MOD will work on 1.6ST?
Because in your step # 5
instead of
$t=Format::htmlchars($_POST['lticket']?$_POST['lticket']:$_GET['t']);
in 1.6ST i do have
$t=Format::input($_POST['lticket']?$_POST['lticket']:$_GET['t']);
so not sure about replacing it or not…
so afraid to proceed below that step..
please guide me for 1.6ST