Skip to content
Snippets Groups Projects
Commit 4f99051f authored by Jared Hancock's avatar Jared Hancock
Browse files

Merge pull request #305 from protich/issue/collabs


bug : Fix dispatcher

Reviewed-By: default avatarJared Hancock <jared@osticket.com>
parents ca7e005d dd6e5b2c
No related branches found
No related tags found
No related merge requests found
......@@ -450,16 +450,19 @@ class TicketsAjaxAPI extends AjaxController {
}
//Collaborators utils
function addCollaborator($tid) {
function addCollaborator($tid, $uid=0) {
global $thisstaff;
if (!($ticket=Ticket::lookup($tid))
|| !$ticket->checkStaffAccess($thisstaff))
Http::response(404, 'No such ticket');
$user = $uid? User::lookup($uid) : null;
//If not a post then assume new collaborator form
if(!$_POST)
return self::_addcollaborator($ticket);
return self::_addcollaborator($ticket, $user);
$user = $form = null;
if (isset($_POST['id']) && $_POST['id']) { //Existing user/
......@@ -540,9 +543,9 @@ class TicketsAjaxAPI extends AjaxController {
$info += array(
'title' => sprintf('Ticket #%s: Add a collaborator', $ticket->getNumber()),
'action' => sprintf('#tickets/%d/add-collaborator', $ticket->getId())
'action' => sprintf('#tickets/%d/add-collaborator', $ticket->getId()),
'onselect' => sprintf('ajax.php/tickets/%d/add-collaborator/', $ticket->getId()),
);
return self::_userlookup($user, $form, $info);
}
......
......@@ -100,9 +100,11 @@ class UrlMatcher {
}
function dispatch($url, $prev_args=null) {
# Remove named values from the match array
$this->matches = array_flip(array_intersect(
array_flip($this->matches), range(0,31)));
$f = array_filter(array_keys($this->matches), 'is_numeric');
$this->matches = array_intersect_key($this->matches, array_flip($f));
if (@get_class($this->func) == "Dispatcher") {
# Trim the leading match off the $url and call the
# sub-dispatcher. This will be the case for lines in the URL
......@@ -116,29 +118,31 @@ class UrlMatcher {
substr($url, strlen($this->matches[0])),
array_merge(($prev_args) ? $prev_args : array(),
array_slice($this->matches, 1)));
} else {
# Drop the first item of the matches array (which is the whole
# matched url). Then merge in any initial arguments.
unset($this->matches[0]);
# Prepend received arguments (from a parent Dispatcher). This is
# different from the static args, which are postpended
if (is_array($prev_args))
$args = array_merge($prev_args, $this->matches);
else $args = $this->matches;
# Add in static args specified in the constructor
$args = array_merge($args, $this->args);
# Apply the $prefix given
list($class, $func) = $this->apply_prefix();
if ($class) {
# Create instance of the class, which is the first item,
# then call the method which is the second item
$func = array(new $class, $func);
}
if (!is_callable($func))
Http::response(500,
'Dispatcher compile error. Function not callable');
return call_user_func_array($func, $args);
}
# Drop the first item of the matches array (which is the whole
# matched url). Then merge in any initial arguments.
unset($this->matches[0]);
# Prepend received arguments (from a parent Dispatcher). This is
# different from the static args, which are postpended
if (is_array($prev_args))
$args = array_merge($prev_args, $this->matches);
else $args = $this->matches;
# Add in static args specified in the constructor
$args = array_merge($args, $this->args);
# Apply the $prefix given
list($class, $func) = $this->apply_prefix();
if ($class) {
# Create instance of the class, which is the first item,
# then call the method which is the second item
$func = array(new $class, $func);
}
if (!is_callable($func))
Http::response(500, 'Dispatcher compile error. Function not callable');
return call_user_func_array($func, $args);
}
/**
* For the $prefix recieved by the constuctor, prepend it to the
......
......@@ -80,7 +80,7 @@ $(function() {
},
onselect: function (obj) {
$('#the-lookup-form').load(
"ajax.php/users/select/"+obj.id
'<?php echo $info['onselect']? $info['onselect']: "ajax.php/users/select/"; ?>'+obj.id
);
},
property: "/bin/true"
......
......@@ -62,7 +62,7 @@ $dispatcher = patterns('',
url_get('^/(?P<id>\d+)$', 'getUser'),
url_post('^/(?P<id>\d+)$', 'updateUser'),
url_get('^/(?P<id>\d+)/edit$', 'editUser'),
url_get('^/lookup$', 'getUser'),
url('^/lookup$', 'getUser'),
url_get('^/lookup/form$', 'getLookupForm'),
url_post('^/lookup/form$', 'addUser'),
url_get('^/select$', 'selectUser'),
......@@ -80,6 +80,7 @@ $dispatcher = patterns('',
url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/release', 'releaseLock'),
url_get('^(?P<tid>\d+)/collaborators/manage$', 'showCollaborators'),
url_post('^(?P<tid>\d+)/collaborators$', 'updateCollaborators'),
url_get('^(?P<tid>\d+)/add-collaborator/(?P<uid>\d+)$', 'addCollaborator'),
url('^(?P<tid>\d+)/add-collaborator$', 'addCollaborator'),
url_get('^lookup', 'lookup'),
url_get('^search', 'search')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment