Di Sistem osTicket, ketika sebuah tiket baru dibuat, maka dia akan menjalankan pernyataan SQL INSERT INTO, dan menampilkan halaman “Terima Kasih” setelahnya. Sayangnya, ketika klien memuat atau menyegarkan ulang halaman tersebut, maka sistem ini akan mengeksekusi ulang pernyataan SQL tadi, karena primary key untuk tabel yang menyimpan data tiket tadi adalah ID dari tiket tersebut yang memiliki tipe field nomor yang bertambah secara otomatis. Hal ini menyebabkan isi tiket yang sama dapat dimasukkan berulang-ulang ke Sistem osTicket Anda sehingga terlihat seperti tiket spam. Oleh karenanya, berikut ini solusi untuk menghindari isi tiket duplikat tersimpan di database pada Sistem osTicket Anda. Anda dapat menerapkan kode ini baik pada osTicket versi 1.6 RC4, 1.6 RC5, maupun 1.6 ST.
Pertama-tama, buka file \include\class.ticket.php, dan cari kode berikut di osTicket versi 1.6 RC4:
//Any error above is fatal. if($errors) { return 0; }
atau cari kode berikut jika versi osTicket Anda adalah 1.6 RC5 atau 1.6 ST:
$ipaddress=$var['ip']?$var['ip']:$_SERVER['REMOTE_ADDR'];
setelah kode di atas tadi, tambahkan kode berikut:
// Added by Masino Sinaga, April 13, 2009 // This code to avoid duplicate ticket-content saved in database // // For example: In existing condition, If user refresh/reload // the page that show thank you message after client // open a new ticket, the new ticket would be created // and that new record will be saved in database, even // the new ticket has same content with the previous ticket. // With this MOD, system will avoid the same ticket-content // saved in database. // // In other words: // Before: Duplicate ticket-content will be saved in database // After : Avoid duplicate ticket-content in database $sql1='SELECT email FROM '.TICKET_TABLE.' WHERE email='.db_input($var['email']).' AND name='.db_input(Format::striptags($var['name'])).' AND subject='.db_input(Format::striptags($var['subject'])).' AND phone="'.db_input(Format::striptags($var['phone'])).'" AND ip_address='.db_input($ipaddress).' AND source='.db_input($source).''; $sql2='SELECT ticket_id FROM '.TICKET_MESSAGE_TABLE.' WHERE message='.db_input(Format::striptags($var['message'])).''; $res1=db_query($sql1); $res2=db_query($sql2); if( ($res1 && db_num_rows($res1)) && ($res2 && db_num_rows($res2)) ) { $errors['err']="Data already exists in database!"; return 0; } // Added by Masino Sinaga, April 13, 2009
Dari kode di atas, diasumsikan bahwa isi tiket dikatakan duplikat jika dicek berdasarkan:
- email
- name
- subject
- phone
- ip_address
- source
Anda bisa saja mengkostumais parameter-parameter tersebut sesuai kebutuhan Anda. Sebagai contoh, jika Anda ingin mengabaikan parameter “ip_address” klik Anda, karena alamat IP dapat berubah setiap kali klien Anda menyegarkan atau memuat ulang halaman terima kasih tadi (dynamic IP), maka Anda bisa saja tidak menggunakan “ip_address” dan menghapusnya dari SQL di atas.

Hello from Russia!
Can I quote a post in your blog with the link to you?
Hello,
I have the following problems in OS Ticket. Can you help?
1. For new message alerts we are unable to reply from email client. If replied it creates a new ticket.
2. No Alerts are received to the admin when the staff replies to it.
3. Attachments are not reaching the client by email but able to access the attachments in the tickets web interface.
Thanks,
Sridhar,India
@Sridhar
Hi,
1. Sorry, I never reply a ticket via email. I always reply a ticket via web.
2. Make sure you have already set regarding this via admin panel -> Settings -> Preferences.
3. This answer also related to my answer number 1 above.
You’re welcome.
this doesn’t work in RC5. i get the data already exists but it still creates the ticket
@john
I have tested it and everything worked fine here.
Hi Masino,
This doesn’t work for me as well in rc 5.
You can reload as much as you want or (thanks) until you hit the limit of your “Limiting Tickets Sent by Same Email Within The Last N Days in osTicket” MOD.
I made a small test and after (your code in your MOD) :
I added :
On my install, the result is (inserting a line break before “– “) :
var sql1 = SELECT email FROM ost_ticket WHERE email=’email@mydomain.fr’ AND name=’Test’ AND subject=’reload5′ AND phone=” AND ip_address=’01.23.45.67′ AND source=’Web’
– var sql2 = SELECT ticket_id FROM ost_ticket_message WHERE message=’v5′
– var res1 = Resource id #30
– var res2 = Resource id #31
– db_num_rows(Resource id #30) = 0
– db_num_rows(Resource id #31) = 4
– Resource id #30 && db_num_rows(Resource id #30) =
– Resource id #31 && db_num_rows(Resource id #31) = 1
– Result of if statement below =
I did the test many times and it reloads the same subject && message into the DB with different ticket numbers.
Hope it helps to find out what’s going on.
Sorry I don’t know much about php.
May be using another approach by having a checksum field in the table, concatenating ip+email+subject+message(255 chars or less) and make a (md5) checksum of it as res1, checking the checksum fields in the DB, if the same checksum is found in the DB then error message, else feed the DB with everything and the new checksum ?
A question : When you test a new MOD, do you start from a fresh OST install or do you test it with all your previous MODs installed ?
Regards
@john
@Francois
For those of you who have not succeeded implement this MOD, please try to change this code:
become:
Probably, it caused by the dynamic IP Address when your customer/client reload or refresh the “thank you” page, then in the last page reload, the generated IP Address is different with the previous ticket submission. And make sure you test it by reload the “thank you” page without change any data on the form. Let me know the result. Thanks.
Hi Masino,
Thank you for your answer.
Still doesn’t work.
I don’t think the pb lies within dynamic IP Address since one need to reset/reboot the modem or ask to renew IP to get a new dynamic IP.
In the reload tests I made, IPs used are all logged in tickets and do not change when reloading the thankyou page.
Ok, I found one problem.
The 1st problem came here because I installed “How to Make Phone Number Starting With ’0′ Saved in osTicket System v1.6 RC5″.
So the phone numbers are enclosed with single quote to allow ’0′s.
That’s why the first SQL ($res1) was always returning 0 rows (… AND phone=” …) instead of : AND phone=”””.
In this case the fix is to change:
To:
Now back to the same pb John faces.
In your if statement don’t we need a “return false” or something like that?
The error message is catched and then the code keeps on and creates a new ticket with the same data and displays the thankyou page with the error message.
Regards
Changing:
To:
Just add the line “return 0;” in your class.ticket.php (keep your error message!).
Works on my install.
Hi Francois,
Thanks so much for your solution and modification. I have updated the original modification code above. Hopefully this will help to someone else.
Cheers!