Page 1 of 2

Can we assign ticket to whoever created it from admin panel?

Posted: Fri May 11, 2012 10:45 pm
by SS113
As the subject reads, I am trying to find a way to automatically assign a ticket to whoever (admin/staff) creates it. The auto-assign feature doesn't really help me since I do not want one staff member to create it and get it assigned to another one.

Any thoughts?

Thank you!

Re: Can we assign ticket to whoever created it from admin pa

Posted: Sat May 12, 2012 9:32 am
by Klemen
Simply select your name from the "Assign ticket to" list.

Or leave "Unassigned" and click the "Assign to me" link when the ticket is created.

Re: Can we assign ticket to whoever created it from admin pa

Posted: Sat May 12, 2012 11:58 am
by SS113
Thank you but that only works if you are an admin. If it's staff they don't have that option when creating the ticket. I'm looking for a way to automatically do this when the user submits the form without asking them

Thank you

Re: Can we assign ticket to whoever created it from admin pa

Posted: Sat May 12, 2012 1:39 pm
by Klemen
It does work for non-admins too, just make sure they have "Can assign tickets to self" feature selected.

Re: Can we assign ticket to whoever created it from admin pa

Posted: Sat May 12, 2012 3:29 pm
by SS113
Got you, thank you!

Re: Can we assign ticket to whoever created it from admin pa

Posted: Tue Jul 03, 2012 8:23 pm
by dr_patso
hey, here's a way to make it so you never have an unassigned ticket or assigned to the wrong user...

to your /admin/new_ticket.php add

Code: Select all

<option value="">-- Please select --</option>
right below

Code: Select all

<?php echo $hesklang['asst2']; ?> <select name="owner" <?php if (in_array('owner',$_SESSION['iserror'])) {echo ' class="isError" ';} ?>>
to /language/en/text.php add

Code: Select all

$hesklang['selectowner']='Please select owner of the ticket';
around line 50-60 under /* ERROR MESSAGES */

to /admin/admin_submit_ticket.php add

Code: Select all

$tmpvar['owner'] = hesk_input($_POST['owner']) or $hesk_error_buffer['owner']=$hesklang['selectowner'];
around like 50-56

Re: Can we assign ticket to whoever created it from admin pa

Posted: Tue Jul 03, 2012 8:26 pm
by dr_patso
would be nice to get some help, but i'm going to start researching a way to atleast have the box already selecting the logged in user i'm sure this can be done with php

if user id ="" or username select option for their username in the owner drop down .. maybe i'd have to do this for every user id or something.... but i wouldn't care...

Re: Can we assign ticket to whoever created it from admin pa

Posted: Thu Jul 05, 2012 6:26 pm
by steve
I don't use ticket assignment at all. So I just set EVERY ticket to Ower = 1, here is how I did it.

open /inc/admin_submit_ticket.php

find

Code: Select all

/* Owner */
$owner = 0;
if (hesk_checkPermission('can_assign_others',0))
{
	$owner = intval($_REQUEST['owner']);

	/* If ID is -1 the ticket will be unassigned */
	if ($owner == -1)
	{
		$owner = 0;
	}
    /* Automatically assign owner? */
    elseif ($owner == -2 && $hesk_settings['autoassign'] == 1)
    {
		$autoassign_owner = hesk_autoAssignTicket($tmpvar['category']);
		if ($autoassign_owner)
		{
			$owner = $autoassign_owner['id'];
			$history .= sprintf($hesklang['thist10'],hesk_date(),$autoassign_owner['name'].' ('.$autoassign_owner['user'].')');
		}
        else
        {
        	$owner = 0;
        }
    }
    /* Check for invalid owner values */
	elseif ($owner < 1)
	{
	    $owner = 0;
	}
    else
    {
	    /* Has the new owner access to the selected category? */
		$sql = "SELECT `name`,`isadmin`,`categories` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`=".hesk_dbEscape($owner)." LIMIT 1";
		$res = hesk_dbQuery($sql);
	    if (hesk_dbNumRows($res) == 1)
	    {
	    	$row = hesk_dbFetchAssoc($res);
	        if (!$row['isadmin'])
	        {
				$row['categories']=explode(',',$row['categories']);
				if (!in_array($tmpvar['category'],$row['categories']))
				{
                	$_SESSION['isnotice'][] = 'category';
					$hesk_error_buffer['owner']=$hesklang['onasc'];
				}
	        }
	    }
	    else
	    {
        	$_SESSION['isnotice'][] = 'category';
	    	$hesk_error_buffer['owner']=$hesklang['onasc'];
	    }
    }
}
elseif (hesk_checkPermission('can_assign_self',0) && hesk_okCategory($tmpvar['category'],0) && !empty($_POST['assing_to_self']))
{
	$owner = intval($_SESSION['id']);
}
Replace with

Code: Select all

/* Owner */
$owner = 1;
You would have to do something similar for submit_ticket.php also.

Re: Can we assign ticket to whoever created it from admin pa

Posted: Thu Jul 05, 2012 11:00 pm
by steve
dr_patso wrote:would be nice to get some help, but i'm going to start researching a way to atleast have the box already selecting the logged in user i'm sure this can be done with php

if user id ="" or username select option for their username in the owner drop down .. maybe i'd have to do this for every user id or something.... but i wouldn't care...
You want the owner drop down box in admin/new_ticket.php to show the name of the currently logged in user?

Re: Can we assign ticket to whoever created it from admin pa

Posted: Fri Jul 06, 2012 12:08 am
by dr_patso
it's not a huge deal really.

But i'd like to modify it so it automatically selects the logged in user in the drop down, that way the user doesn't have to mess with it unless they want to assign it to somebody else.

Re: Can we assign ticket to whoever created it from admin pa

Posted: Fri Jul 06, 2012 12:25 am
by dr_patso
i turned auto assign.. it can't be hard to change the logic in the auto assign function in admin_submit_ticket to just choose to sessions user ID as the value if auto assigned is selected

Re: Can we assign ticket to whoever created it from admin pa

Posted: Fri Jul 06, 2012 12:42 am
by dr_patso
ah here we go.. I think I nailed it, can someone confirm? enable auto assign tickets then

in admin_submit_ticket.php I changed...

Code: Select all


/* Automatically assign owner? */
    elseif ($owner == -2 && $hesk_settings['autoassign'] == 1)
    {
		$autoassign_owner = hesk_autoAssignTicket($tmpvar['category']);
		if ($autoassign_owner)
		{
			$owner = $autoassign_owner['id'];
to

Code: Select all

    /* Automatically assign owner? */
    elseif ($owner == -2 && $hesk_settings['autoassign'] == 1)
    {
		$autoassign_owner = hesk_autoAssignTicket($tmpvar['category']);
		if ($autoassign_owner)
		{
			$owner = $_SESSION['id'];
change the line 115 for me

Code: Select all

$owner = $autoassign_owner['id'];
to

Code: Select all

$owner = $autoassign_owner['id'];

Re: Can we assign ticket to whoever created it from admin pa

Posted: Fri Jul 06, 2012 12:50 am
by dr_patso
this has been working for me for about 10 tickets on 3 different users.... I'm scared some other conditional logic will cause it not to work in the future... Klemen if you have time could you approve this as a way for auto assign to always assign to the logged in user??

i don't use the customer interface, if i did i would modify it to not use the auto assign function.

Re: Can we assign ticket to whoever created it from admin pa

Posted: Fri Jul 06, 2012 3:07 am
by steve
Here is how I would do it.

Change

Code: Select all

/* Owner */
$owner = 0;
if (hesk_checkPermission('can_assign_others',0))
{
	$owner = intval($_REQUEST['owner']);

	/* If ID is -1 the ticket will be unassigned */
	if ($owner == -1)
	{
		$owner = 0;
	}
    /* Automatically assign owner? */
    elseif ($owner == -2 && $hesk_settings['autoassign'] == 1)
    {
		$autoassign_owner = hesk_autoAssignTicket($tmpvar['category']);
		if ($autoassign_owner)
		{
			$owner = $autoassign_owner['id'];
			$history .= sprintf($hesklang['thist10'],hesk_date(),$autoassign_owner['name'].' ('.$autoassign_owner['user'].')');
		}
        else
        {
        	$owner = 0;
        }
    }
    /* Check for invalid owner values */
	elseif ($owner < 1)
	{
	    $owner = 0;
	}
    else
    {
	    /* Has the new owner access to the selected category? */
		$sql = "SELECT `name`,`isadmin`,`categories` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`=".hesk_dbEscape($owner)." LIMIT 1";
		$res = hesk_dbQuery($sql);
	    if (hesk_dbNumRows($res) == 1)
	    {
	    	$row = hesk_dbFetchAssoc($res);
	        if (!$row['isadmin'])
	        {
				$row['categories']=explode(',',$row['categories']);
				if (!in_array($tmpvar['category'],$row['categories']))
				{
                	$_SESSION['isnotice'][] = 'category';
					$hesk_error_buffer['owner']=$hesklang['onasc'];
				}
	        }
	    }
	    else
	    {
        	$_SESSION['isnotice'][] = 'category';
	    	$hesk_error_buffer['owner']=$hesklang['onasc'];
	    }
    }
}
elseif (hesk_checkPermission('can_assign_self',0) && hesk_okCategory($tmpvar['category'],0) && !empty($_POST['assing_to_self']))
{
	$owner = intval($_SESSION['id']);
}
To

Code: Select all

$owner = $_SESSION['id'];
That way I don't have to worry about any other variables.

Re: Can we assign ticket to whoever created it from admin pa

Posted: Fri Jul 06, 2012 4:43 am
by dr_patso
hm that breaks the ability to assign to others if needed...

what about this ? The /* Automatically assign owner? */ is the only section that addresses the -2 (auto assign) value... so it should be okay no??

Code: Select all

/* Owner */
$owner = 0;
if (hesk_checkPermission('can_assign_others',0))
{
	$owner = intval($_REQUEST['owner']);

	/* If ID is -1 the ticket will be unassigned */
	if ($owner == -1)
	{
		$owner = 0;
	}
    /* Automatically assign owner? */
    elseif ($owner == -2 && $hesk_settings['autoassign'] == 1)
    {
		$autoassign_owner = hesk_autoAssignTicket($tmpvar['category']);
		if ($autoassign_owner)
		{
			$owner = $_SESSION['id'];
		}
        else
        {
        	$owner = 0;
        }
    }
    /* Check for invalid owner values */
	elseif ($owner < 1)
	{
	    $owner = 0;
	}
    else
    {
	    /* Has the new owner access to the selected category? */
		$sql = "SELECT `name`,`isadmin`,`categories` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`=".hesk_dbEscape($owner)." LIMIT 1";
		$res = hesk_dbQuery($sql);
	    if (hesk_dbNumRows($res) == 1)
	    {
	    	$row = hesk_dbFetchAssoc($res);
	        if (!$row['isadmin'])
	        {
				$row['categories']=explode(',',$row['categories']);
				if (!in_array($tmpvar['category'],$row['categories']))
				{
                	$_SESSION['isnotice'][] = 'category';
					$hesk_error_buffer['owner']=$hesklang['onasc'];
				}
	        }
	    }
	    else
	    {
        	$_SESSION['isnotice'][] = 'category';
	    	$hesk_error_buffer['owner']=$hesklang['onasc'];
	    }
    }
}
elseif (hesk_checkPermission('can_assign_self',0) && hesk_okCategory($tmpvar['category'],0) && !empty($_POST['assing_to_self']))
{
	$owner = intval($_SESSION['id']);
}