From 431345ade7855b01099ed932f9f1775df4d72925 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 11 Dec 2013 12:32:01 -0600 Subject: [PATCH] Allow edit of user on ticket-edit page Previously, the user information could only be modified on the ticket-view page. For instance, if creating a new ticket for a user, no new information could be added or modified on the user until after the ticket was created Fixes osTicket/osTicket-1.8#281 --- include/ajax.users.php | 36 +++++++++++++++++++++++++-- include/staff/templates/user.tmpl.php | 3 ++- include/staff/ticket-edit.inc.php | 11 +++++++- include/staff/ticket-open.inc.php | 11 +++++++- include/staff/ticket-view.inc.php | 4 ++- scp/ajax.php | 2 ++ 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/include/ajax.users.php b/include/ajax.users.php index 04b29bec6..f84fbd7d8 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -54,9 +54,41 @@ class UsersAjaxAPI extends AjaxController { } - function getUser() { + function editUser($id) { + global $thisstaff; - if(($user=User::lookup($_REQUEST['id']))) + if(!$thisstaff) + Http::response(403, 'Login Required'); + elseif(!($user = User::lookup($id))) + Http::response(404, 'Unknown user'); + + $info = array( + 'title' => sprintf('Update %s', $user->getName()) + ); + $forms = $user->getForms(); + + include(STAFFINC_DIR . 'templates/user.tmpl.php'); + } + + function updateUser($id) { + global $thisstaff; + + if(!$thisstaff) + Http::response(403, 'Login Required'); + elseif(!($user = User::lookup($id))) + Http::response(404, 'Unknown user'); + + $errors = array(); + if($user->updateInfo($_POST, $errors)) + Http::response(201, $user->to_json()); + + $forms = $user->getForms(); + include(STAFFINC_DIR . 'templates/user.tmpl.php'); + } + + function getUser($id=false) { + + if(($user=User::lookup(($id) ? $id : $_REQUEST['id']))) Http::response(201, $user->to_json()); $info = array('error' =>'Unknown or invalid user'); diff --git a/include/staff/templates/user.tmpl.php b/include/staff/templates/user.tmpl.php index 92bbe3754..43176c796 100644 --- a/include/staff/templates/user.tmpl.php +++ b/include/staff/templates/user.tmpl.php @@ -47,7 +47,8 @@ if ($ticket && $ticket->getOwnerId() == $user->getId()) <p class="full-width"> <span class="buttons" style="float:left"> <input type="reset" value="Reset"> - <input type="button" name="cancel" class="<?php echo $user ? 'cancel' : 'close' ?>" value="Cancel"> + <input type="button" name="cancel" class="<?php + echo ($ticket && $user) ? 'cancel' : 'close' ?>" value="Cancel"> </span> <span class="buttons" style="float:right"> <input type="submit" value="Update User"> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index 6294cda92..0fe5c8ee7 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -25,8 +25,17 @@ if ($_POST) ?> <tr><td>Client:</td><td> <div id="client-info"> + <a href="#" onclick="javascript: + $.userLookup('ajax.php/users/<?php echo $ticket->getOwnerId(); ?>/edit', + function (user) { + $('#client-name').text(user.name); + $('#client-email').text(user.email); + }); + return false; + "><i class="icon-user"></i> <span id="client-name"><?php echo $user->getName(); ?></span> - <span id="client-email"><<?php echo $user->getEmail(); ?>></span> + <<span id="client-email"><?php echo $user->getEmail(); ?></span>> + </a> <a class="action-button" style="float:none;overflow:inherit" href="#" onclick="javascript: $.userLookup('ajax.php/tickets/<?php echo $ticket->getId(); ?>/change-user', diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index f491756f3..1c49b4073 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -32,8 +32,17 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <tr><td>Client:</td><td> <div id="client-info"> <input type="hidden" name="uid" id="uid" value="<?php echo $user->getId(); ?>" /> + <a href="#" onclick="javascript: + $.userLookup('ajax.php/users/<?php echo $user->getId(); ?>/edit', + function (user) { + $('#client-name').text(user.name); + $('#client-email').text(user.email); + }); + return false; + "><i class="icon-user"></i> <span id="client-name"><?php echo $user->getName(); ?></span> - <span id="client-email"><<?php echo $user->getEmail(); ?>></span> + <<span id="client-email"><?php echo $user->getEmail(); ?></span>> + </a> <a class="action-button" style="float:none;overflow:inherit" href="#" onclick="javascript: $.userLookup('ajax.php/users/select/'+$('input#uid').val(), diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 9bc7823ab..1891bc07f 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -893,8 +893,10 @@ $tcount+= $ticket->getNumNotes(); Are you sure want to <b>unassign</b> ticket from <b><?php echo $ticket->getAssigned(); ?></b>? </p> <p class="confirm-action" style="display:none;" id="changeuser-confirm"> + <p id="msg_warning"> + <b><?php echo $ticket->getName(); ?></b> <<?php echo $ticket->getEmail(); ?>> will no longer have access to the ticket. + </p> Are you sure want to <b>change</b> ticket owner to <b><span id="newuser">this guy</span></b>? - <br><br><b><?php echo $ticket->getName(); ?></b> <<?php echo $ticket->getEmail(); ?>> will no longer have access to the ticket. </p> <p class="confirm-action" style="display:none;" id="delete-confirm"> <font color="red"><strong>Are you sure you want to DELETE this ticket?</strong></font> diff --git a/scp/ajax.php b/scp/ajax.php index 106f3366a..b40a6696d 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -60,6 +60,8 @@ $dispatcher = patterns('', url('^/users', patterns('ajax.users.php:UsersAjaxAPI', url_get('^$', 'search'), url_get('^/(?P<id>\d+)$', 'getUser'), + url_post('^/(?P<id>\d+)$', 'updateUser'), + url_get('^/(?P<id>\d+)/edit$', 'editUser'), url_get('^/lookup$', 'getUser'), url_get('^/lookup/form$', 'getLookupForm'), url_post('^/lookup/form$', 'addUser'), -- GitLab