diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index bee2c7d6cfcd7be03684f1baedb273979b7205a5..1a010c450a2c693a62b2fb360e6a53d76574b77a 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -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); } diff --git a/include/class.dispatcher.php b/include/class.dispatcher.php index 44d710b55b1256bfe5709c0ddc0254a80695031a..0448f5024eb3e9244f1bf1bbe1b8b462d171117a 100644 --- a/include/class.dispatcher.php +++ b/include/class.dispatcher.php @@ -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 diff --git a/include/staff/templates/user-lookup.tmpl.php b/include/staff/templates/user-lookup.tmpl.php index fcc8ec2ca3624364bc1b668aebdf843f00036fbd..617011b2d6eaeeafa59c31fe5e12003b55d40ff0 100644 --- a/include/staff/templates/user-lookup.tmpl.php +++ b/include/staff/templates/user-lookup.tmpl.php @@ -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" diff --git a/scp/ajax.php b/scp/ajax.php index 397d1f44b563cb2d4e8221d7d8dd5f71229330b6..c84b73c2d9328a4c5b39d35e7c460a0d1ece21d3 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -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')