Easy New Ticket Creation

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Easy New Ticket Creation

Post by smartersolutions »

Hello All,

I have HESK 2.5.5 version.

I would like to modify the "new ticket" function, in particular the email "required" and the name.

I would like the "required" Name and Email addresses to be drop down lists of Staff users. This info is valid and would come from the database. I modified the code to pull the info from the DB but when user submits the ticket they are confronted with the following error:

Error: Please correct the following errors:

Please enter a valid email address

The following is the code to pull the data from the DB. Can anyone help me. Please?

Code: Select all

<td width="80%"><select name="email" <?php if (in_array('email',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('email',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> <?php if($hesk_settings['detect_typos']) { echo ' onblur="Javascript:hesk_suggestEmail(1)"'; } ?> />

	<?php

	if (!empty($_GET['catid']))

	{

		$_SESSION['as_email'] = intval( hesk_GET('catid') );

	}



	$result = hesk_dbQuery('SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'users` ORDER BY `id` ASC');

	while ($row=hesk_dbFetchAssoc($result))

	{

	    if (isset($_SESSION['as_email']) && $_SESSION['as_email'] == $row['id']) {$selected = ' selected="selected"';}

	    else {$selected = '';}

	    echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['email'].'</option>';

	}



	?>

	</select></td>

	</tr>

	</table>



    <div id="email_suggestions"></div> 



	<hr />
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: Easy New Ticket Creation

Post by Klemen »

We can''t be of much help because we don't know how your script or database is setup (also such modifications are out of the scope of support here).

You will need to make sure a valid email address is sent in the "email" POST variable to file "admin_submit_ticket.php".

From a quick look it seems like you need to replace $row['id'] with $row['email'] in your code (id returns user ID number, not email).

Or modify the first line that starts with $tmpvar['email'] in the admin_submit_ticket.php file to get email from your DB.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

The install is completely standard, performed via Softaculous within the Cpanel.

The ticket system is going to be used purely for staff members ONLY, so tickets will be submitted via the staff from within the admin panel.

Currently the admin ticket feature requires "Name and Email" and would like those details to be pulled from the database.

I found some code that I could change that would pull names and email addresses from the DB, but when I submit ticket, I would get the error that the email address (from database) is incorrect.
The following is the original code:

Code: Select all

<!-- Contact info -->

	<table border="0" width="100%">

	<tr>

	<td style="text-align:right" width="150"><?php echo $hesklang['name']; ?>: <font class="important">*</font></td>

	<td width="80%"><input type="text" name="name" size="40" maxlength="30" value="<?php if (isset($_SESSION['as_name'])) {echo stripslashes(hesk_input($_SESSION['as_name']));} ?>" <?php if (in_array('name',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> /></td>

	</tr>

	<tr>

	<td style="text-align:right" width="150"><?php echo $hesklang['email']; ?>: <font class="important">*</font></td>

	<td width="80%"><input type="text" name="email" size="40" maxlength="255" value="<?php if (isset($_SESSION['as_email'])) {echo stripslashes(hesk_input($_SESSION['as_email']));} ?>" <?php if (in_array('email',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('email',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> <?php if($hesk_settings['detect_typos']) { echo ' onblur="Javascript:hesk_suggestEmail(1)"'; } ?> /></td>

	</tr>

	</table>



    <div id="email_suggestions"></div> 



	<hr />
The next following is code I found that would pull the required info from the DB but I just cant seem to get right:

Code: Select all

<td width="80%"><select name="email" <?php if (in_array('email',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('email',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
Your thoughts?
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: Easy New Ticket Creation

Post by mkoch227 »

Looking at the code snippets, I noticed that you didn't include any code that populates the actual choices ("<option value="...">, etc.). Can you show that code? It's possible that you're properly populating the dropdown, but perhaps sending the wrong value when trying to create the ticket.
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

thanks so much for helping me out with this issue.

I'm sure it can be achieved, I'm just not doing something right. The following code has been copied from another area of the script and modified by myself and I suspect that I have missed a vital piece which is why I'm getting the error.

Code: Select all

if (!empty($_GET['catid']))

	{

		$_SESSION['as_category'] = intval( hesk_GET('catid') );

	}



	$result = hesk_dbQuery('SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'email` ORDER BY `cat_order` ASC');

	while ($row=hesk_dbFetchAssoc($result))

	{

	    if (isset($_SESSION['as_email']) && $_SESSION['as_email'] == $row['id']) {$selected = ' selected="selected"';}

	    else {$selected = '';}

	    echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['email'].'</option>';

	}



	?>

	</select></td>
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: Easy New Ticket Creation

Post by mkoch227 »

Your problem lies within this line:

Code: Select all

echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['email'].'</option>';
When submitting the form, PHP will look at the currently selected option's "value" attribute. Since it's set to the ID, the ID is not a valid e-mail address. Changing it to this should work:

Code: Select all

echo '<option value="'.$row['email'].'"'.$selected.'>'.$row['email'].'</option>';
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

thank you I will do this now and let you know how it works out.

So very much appreciate your time and effort :)
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

unfortunately that didnt work for me or I misunderstood. This gave me a "could not access the SQL database" error. :(

The following is the original (untouched code)

Code: Select all

<td style="text-align:right" width="150"><?php echo $hesklang['name']; ?>: <font class="important">*</font></td>
	<td width="80%"><input type="text" name="name" size="40" maxlength="30" value="<?php if (isset($_SESSION['as_name'])) {echo stripslashes(hesk_input($_SESSION['as_name']));} ?>" <?php if (in_array('name',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> /></td>
I tried to replace the above with the following code:

Code: Select all

<td width="80%"><select name="name" <?php if (in_array('name',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('name',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
	<?php
	if (!empty($_GET['catid']))
	{
		$_SESSION['as_name'] = intval( hesk_GET('catid') );
	}

	$result = hesk_dbQuery('SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'users` ORDER BY `cat_order` ASC');
	while ($row=hesk_dbFetchAssoc($result))
	{
	    if (isset($_SESSION['as_name']) && $_SESSION['as_name'] == $row['id']) {$selected = ' selected="selected"';}
	    else {$selected = '';}
	    echo '<option value="'.$row['name'].'"'.$selected.'>'.$row['name'].'</option>';
	}

	?>
	</select></td>
Of course this screwed up and didnt work. Unfortunately I'm not a PHP guru I simply want to reduce the amount of repetitive typing. (Name and Email Address).
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: Easy New Ticket Creation

Post by Klemen »

Go back to the code you had before and make only the exact changes Mike showed you. Nothing more, nothing less.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

Klemen,

I did use Mike's code, and got the error could not connect to SQL database. Is there another file that should be edited somewhere for it to work or what? The code I'm using and modifying is from within the same file (new_ticket.php) but the code is for pulling categories from database, so is there stuff within the code that maybe too much for it to work? I'm copying and pasting that code in place of the code for Name and Email?

Appreciate your reply. Thank you
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: Easy New Ticket Creation

Post by Klemen »

The database error is not connected to the code posted by Mike.

You can enable Debug mode in HESK settings ("settings" > "Help Desk" tab) and to get more info about the DB error.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

Klemen,

Debug is enabled. Code entered as you stated. Nothing more nothing less.

Results:
Error:

Can't execute SQL: SELECT * FROM `hesk_users` ORDER BY `cat_order` ASC

MySQL said:
Unknown column 'cat_order' in 'order clause'

Any suggestions?
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: Easy New Ticket Creation

Post by mkoch227 »

'cat_order' is not a valid column name in the users table. I'd recommend changing 'cat_order' to 'id' so the names that appear will be consistent with the rest of HESK 2.5.5 (2.6.0 beta 1 sorts them by name, I believe).
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
smartersolutions
Posts: 10
Joined: Wed Jan 14, 2015 11:01 pm

Re: Easy New Ticket Creation

Post by smartersolutions »

hi Mkoch,

this is working fine if I just use this for Name, however I would ideally like to use the code for Email as well.

Something is trying to validate the email, and it seems that if the user doesn't enter manually then it errors out. I wish I knew how to fix this and it would be perfect. :)

Nothing I try seems to work.....
Post Reply