Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

2505 Posts in 648 Topics- by 1314 Members - Latest Member: Saudi Arabia

eTicket CommunitySupportTips & Tricks (Moderators: jason, Hummdis)Topic: HOWTO: Custom Fields, Required Fields, Apply Entries to the database and View
Pages: [1]   Go Down
Print
Author Topic: HOWTO: Custom Fields, Required Fields, Apply Entries to the database and View  (Read 3072 times)
0 Members and 1 Guest are viewing this topic.
ScottW
New Member
*

Karma: +3/-0
Offline Offline

Posts: 11



« on: February 23, 2009, 12:06:14 PM »

HOWTO:
eTicket insert custom fields into both the Initial form, the ticket view and the MySQL Database.

Reason: Customise the system to suit your own needs and make it scalable and as “forward compatible” as possible.

(Apologies for advance for the amount of fields I am inserting. I felt showing you EXACTLY what I had done was the best way to proceed.)

Pre-requisites:
A full install of eTicket
An FTP client (if using an off site server)
A Text Editor. .
PhpMyAdmin

REMEMBER - THIS IS IMPORTANT:
Work on a back up. If things go wrong, you aren't going to lose anything.

Files we'll be editing (It may be worthwhile moving these into a separate folder for ease of editing).....

inc/class.ticket.php
inc/open_inc.php
lang.php
themes/eticket/viewticket.html.php
themes/eticket/open_form.html.php
/inc/main.php

 
STEP 1:

I will show you some of the fields I am inserting. These will include address fields, cell-phone number and Invoice Number.  You will likely want different ones to me, to suit the task you are doing.

Work out which fields you wish to insert and the order
For me, it's the following
   mobile_phone
     dop
   address
   city    
   county
   postcode
   invoice_number
   make    
   model

DOP is date of purchase. The rest should be self explanatory.

You will then need to open up your database using phpMyAdmin. It is possible to do it using sql commands, but to be honest, that's a little beyond my current ability (especially when phpMyAdmin does the trick in it's glorious graphical style). If anyone else wants to add the commands, please feel  free.

OK. Open the “tickets” table.
Then add a field to “the end” of the table
On the resulting page, enter
Field          Type         Collation
mobile_phone      Varchar(XX)      utf8_general_ci(**)

XX being the length of field you wish to accept.
** It's best to replicate the collation field with the entry you already have in your table. Yours may vary, depending on your installation language.

Repeat the above step for each new field you wish to create.

OK. That's the phpMyAdmin part done. Onto the next phase.

STEP 2: Edit inc/class.ticket.php

We'll need to introduce our field to a number of sections here....
Search for 
   
Code:
var $phone

Here's what I paste in directly afterwards.....
Code:
    var $mobile_phone;
    var $dop;
    var $address;
    var $city;
    var $county;
    var $postcode;
    var $invoice_number;
    var $make;
    var $model;

Just further down search for
Code:
$this->mobile = $row['mobile'];

Again, directly after this, I will insert the following....

Code:
$this->mobile_phone = $row['mobile_phone'];
$this->dop = $row['dop'];
$this->address = $row['address'];
$this->city = $row['city'];
$this->county = $row['county'];
$this->postcode = $row['postcode'];
$this->invoice_number = $row['invoice_number'];
$this->make = $row['make'];
$this->model = $row['model'];

Now search for....
Code:
function CreateTicket($subject, $name, $email, $cat, $phone, $pri = 2, $ip = '', $message = '', $sendmail = TRUE) {

Then edit to To include our new fields...(in my case)

Code:
function CreateTicket($subject, $name, $email, $cat, $phone, $mobile_phone, $dop, $address, $city, $county, $postcode, $invoice_number, $make, $model, $pri = 2, $ip = '', $message = '',
$sendmail = TRUE) {

Now search for
Code:
$sql_phone = escape_string($phone);

Just below it, we'll insert the following.....
Code:
$sql_mobile_phone = escape_string($mobile_phone);
$sql_dop = escape_string($dop);
$sql_address = escape_string($address);
$sql_city = escape_string($city);
$sql_county = escape_string($county);
$sql_postcode = escape_string($postcode);
$sql_invoice_number = escape_string($invoice_number);
$sql_make = escape_string($make);
$sql_model = escape_string($model);

Now search for
Code:
    $sql = "INSERT INTO " . $db_table['tickets'] . " (subject, name, email, cat, phone, status, ID, priority, ip, timestamp) ";
    $sql.= "VALUES ($sql_subject, $sql_name, $sql_email, '$cat[ID]', $sql_phone, 'new', '$id', '$pri', $sql_ip, UTC_TIMESTAMP())";

So we need to change it to....
Code:
    $sql = "INSERT INTO " . $db_table['tickets'] . " (subject, name, email, cat, phone, mobile_phone, dop, address, city, county, postcode, invoice_number, make, model, status, ID, priority, ip, timestamp) ";
    $sql.= "VALUES ($sql_subject, $sql_name, $sql_email, '$cat[ID]', $sql_phone, $sql_mobile_phone, $sql_dop, $sql_address, $sql_city, $sql_county, $sql_postcode, $sql_invoice_number, $sql_make, $sql_model, 'new', '$id', '$pri', $sql_ip, UTC_TIMESTAMP())";

That will do for that file. Save and move on

STEP 3: Edit lang.php

Here we are going to tell eticket how to refer to the fields we want to create.

Search for
Code:
define('LANG_PHONE', 'Phone');

After this, we want to insert the language definitions we want to insert for our customer fields.

In my case, I'm going to put the following in directly afterwards

Code:
define('LANG_MOBILE_PHONE', 'Mobile');
define('LANG_DOP', 'Date of Purchase');
define('LANG_ADDRESS', 'Address');
define('LANG_CITY', 'Town/City');
define('LANG_COUNTY', 'County');
define('LANG_POSTCODE', 'Postcode');
define('LANG_INVOICE_NUMBER', 'Invoice/Item Number');
define('LANG_MAKE', 'Make of Item');
define('LANG_MODEL', 'Model Number');

Hopefully this is self explanatory. The reason we've done it will become apparent in the next step.

One more thing to edit here.....
Search for
Code:
define('LANG_ERROR_NO_MSG', 'Please specify a message.');

In the line below, we are going to add a custom error message. You'll see why in step 4.

Code:
define('LANG_ERROR_NO_INV', 'Please enter your invoice or item number.');

We've finished with lang.php now. So save it and move to the next step

STEP 4: Edit inc/open_inc.php

Here we are going to set our “Required Fields”. In other words, fields that cannot be left empty.

In my case, I only need one. This is the “invoice_number” field. I can get all the other customer information from my invoicing system.

Search for
Code:
    if (!$_POST['message']) {
        $err[] = LANG_ERROR_NO_MSG;
    }

We are now going to add directly after the above entry

Code:
    if (!$_POST['invoice_number']) {
        $err[] = LANG_ERROR_NO_INV;
    }

Do you see why we added the custom error field in Step 3 now?

We also need to add the entries for our new fields.
Search for
Code:
        $ticket = CreateTicket($_POST['subject'], $client_name, $_POST['email'], $_POST['cat'], $_POST['phone'], $_POST['pri'], $_SERVER['REMOTE_ADDR'], $message, !$answer);
        if (!is_numeric($ticket)) {
            $err[] = LANG_FAILED . ': ' . LANG_OPEN_TICKET . ' ' . $ticket;
        }

And change it to.....
Code:
        $ticket = CreateTicket($_POST['subject'], $client_name, $_POST['email'], $_POST['cat'], $_POST['phone'], $_POST['mobile_phone'], $_POST['dop'], $_POST['address'], $_POST['city'], $_POST['county'], $_POST['postcode'], $_POST['invoice_number'], $_POST['make'], $_POST['model'], $_POST['pri'], $_SERVER['REMOTE_ADDR'], $message, !$answer);
        if (!is_numeric($ticket)) {
            $err[] = LANG_FAILED . ': ' . LANG_OPEN_TICKET . ' ' . $ticket;
        }

OK. Save open_inc.php and move to step 5

STEP 5: Edit themes/eticket/open_form.html.php

Here we are going to set up the first page the customer sees prior to entering their information. It looks complex, but it isn't really. We've done most of the hard work already.

Search for
Code:
<tr>
<td align="left"><?php echo LANG_PHONE?>:</td>
<td><input type="text" name="phone" id="phone" size="25" value="<?php echo $vars['phone']; ?>"></td>
</tr>

We then need to add our custom fields. I'm going to show you all of mine here, so it will be fairly long....

Code:
<tr>
<td align="left"><?php echo LANG_MOBILE_PHONE?>:</td>
<td><input type="text" name="mobile_phone" id="phone" size="25" value="<?php echo $vars['mobile_phone']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_DOP?>:</td>
<td><input type="text" name="dop" id="dop" size="25" value="<?php echo $vars['dop']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_ADDRESS?>:</td>
<td><input type="text" name="address" id="address" size="50" value="<?php echo $vars['address']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_CITY?>:</td>
<td><input type="text" name="city" id="city" size="35" value="<?php echo $vars['city']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_COUNTY?>:</td>
<td><input type="text" name="county" id="county" size="25" value="<?php echo $vars['county']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_POSTCODE?>:</td>
<td><input type="text" name="postcode" id="postcode" size="10" value="<?php echo $vars['postcode']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_INVOICE_NUMBER?>:</td>
<td><input type="text" name="invoice_number" id="invoice_number" size="15" value="<?php echo $vars['invoice_number']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_MAKE?>:</td>
<td><input type="text" name="make" id="make" size="25" value="<?php echo $vars['make']; ?>"></td>
</tr>
<tr>
<td align="left"><?php echo LANG_MODEL_NUMBER?>:</td>
<td><input type="text" name="model" id="model" size="15" value="<?php echo $vars['model']; ?>"></td>
</tr>
You can change the maximum size of the entry by using the size label. This will vary for you.

IMPORTANT: Go back to phpmyadmin and ensure the values in the type relate EXACTLY to the size you've mentioned above. Obviously, if you allow a larger entry than your field in the ticket table will accept, you WILL see errors.

OK. We've finished with open_form.html.php. Save the file and move to Step 6

STEP 6: Edit themes/eticket/viewticket.html.php

Search for
Code:
<?php if ($ticket->phone): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_PHONE?>:</b></td>
<td class="mainTable"><?php echo $ticket->phone?></td>
</tr>
<?php
endif; ?>

We then need to add our extra fields so that they appear when we view the ticket. Again, it looks a lot more complex than it is. I'll add all my fields in one go.......

Code:
<?php if ($ticket->mobile_phone): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_MOBILE_PHONE?>:</b></td>
<td class="mainTable"><?php echo $ticket->mobile_phone?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->dop): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_DOP?>:</b></td>
<td class="mainTable"><?php echo $ticket->dop?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->address): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_ADDRESS?>:</b></td>
<td class="mainTable"><?php echo $ticket->address?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->city): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_CITY?>:</b></td>
<td class="mainTable"><?php echo $ticket->city?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->county): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_COUNTY?>:</b></td>
<td class="mainTable"><?php echo $ticket->county?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->postcode): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_POSTCODE?>:</b></td>
<td class="mainTable"><?php echo $ticket->postcode?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->invoice_number): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_INVOICE_NUMBER?>:</b></td>
<td class="mainTable"><?php echo $ticket->invoice_number?></td>
</tr>
<?php
endif; ?>

<?php if ($ticket->make): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_MAKE?>:</b></td>
<td class="mainTable"><?php echo $ticket->make?></td>
</tr>
<?php
endif; ?>


<?php if ($ticket->model): ?>
<tr>
<td class="mainTable"><b><?php echo LANG_MODEL?>:</b></td>
<td class="mainTable"><?php echo $ticket->model?></td>
</tr>
<?php
endif; ?>

Hopefully you can see what is happening here. It's basically pulling our fields out from the database and displaying them.

That's it for viewticket.html.php. Save the file and move on...

STEP 7: Edit main.php

Find this bit
Code:
    " . $db_table['tickets'] . ".phone LIKE '%$text%' OR

Again we need to add our fields... directly AFTERWARDS -

Code:
    " . $db_table['tickets'] . ".mobile_phone LIKE '%$text%' OR
    " . $db_table['tickets'] . ".dop LIKE '%$text%' OR
    " . $db_table['tickets'] . ".address LIKE '%$text%' OR
    " . $db_table['tickets'] . ".city LIKE '%$text%' OR
    " . $db_table['tickets'] . ".county LIKE '%$text%' OR
    " . $db_table['tickets'] . ".postcode LIKE '%$text%' OR
    " . $db_table['tickets'] . ".invoice_number LIKE '%$text%' OR
    " . $db_table['tickets'] . ".make LIKE '%$text%' OR
    " . $db_table['tickets'] . ".model LIKE '%$text%' OR

We're now done. Save main.php. Hurrah. That's it.

All it takes now is to test.

If you've edited the files locally, upload them to the correct location and test. If you've edited “in situ”, then just test.

Good luck.

FOOTNOTE:

I hope this tutorial is of some use to eticket users. If anyone knows of a quicker and less dirty method, then please feel free to add to this post. If you spot any errors, I'd be grateful for your help in correcting them.

If anyone needs any explanation of what is going on, or help in applying the changes, I'll try to help when available.

Cheers
Scott.
Logged
Hummdis
Moderator
Super Member
*****

Karma: +13/-0
Offline Offline

Posts: 558



WWW
« Reply #1 on: March 10, 2009, 06:13:47 AM »

Very cool!  Thank you for sharing!
Logged

Don't PM me directly for help.  Post to the forums, that's what they are for after all.  PM's to me that request help will be ignored.

Hummdis Communications - Freelance Website Design & IT Consulting
newtech
New Member
*

Karma: +0/-0
Offline Offline

Posts: 16


« Reply #2 on: May 19, 2009, 11:38:31 PM »

Is there anyway to get one of these custom fields inserted into e-mails that are sent out.  Thus, if I have a custom field for the customer to enter their domain name, their domain name would be inserted into the e-mails sent out.

Logged
newtech
New Member
*

Karma: +0/-0
Offline Offline

Posts: 16


« Reply #3 on: May 22, 2009, 02:22:01 AM »

Any answer to my question regarding adding custom fields into e-mail?
Logged
Hummdis
Moderator
Super Member
*****

Karma: +13/-0
Offline Offline

Posts: 558



WWW
« Reply #4 on: June 09, 2009, 07:44:34 AM »

Without a custom mod yourself, there is no way to do this.
Logged

Don't PM me directly for help.  Post to the forums, that's what they are for after all.  PM's to me that request help will be ignored.

Hummdis Communications - Freelance Website Design & IT Consulting
splatt
New Member
*

Karma: +0/-0
Offline Offline

Posts: 6


« Reply #5 on: January 31, 2010, 01:04:32 PM »

Anyone know how to include the added custom fields in hxxp: yourwebsite/helpdesk/open. php ? Which file needs to be edited?
Logged
eTicket Community
   

 Logged
Pages: [1]   Go Up
Print
eTicket CommunitySupportTips & Tricks (Moderators: jason, Hummdis)Topic: HOWTO: Custom Fields, Required Fields, Apply Entries to the database and View
Jump to: