diff --git a/include/client/edit.inc.php b/include/client/edit.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..21f2ca726b1863bfe1b5f5eaf0f946606b0830b4 --- /dev/null +++ b/include/client/edit.inc.php @@ -0,0 +1,30 @@ +<?php + +if(!defined('OSTCLIENTINC') || !$thisclient || !$ticket || !$ticket->checkUserAccess($thisclient)) die('Access Denied!'); + +?> + +<h1> + Editing Ticket #<?php echo $ticket->getNumber(); ?> +</h1> + +<form action="tickets.php" method="post"> + <?php echo csrf_token(); ?> + <input type="hidden" name="a" value="edit"/> + <input type="hidden" name="id" value="<?php echo $_REQUEST['id']; ?>"/> +<table width="800"> + <tbody id="dynamic-form"> + <?php if ($forms) + foreach ($forms as $form) { + $form->render(false); + } ?> + </tbody> +</table> +<hr> +<p style="text-align: center;"> + <input type="submit" value="Update"/> + <input type="reset" value="Reset"/> + <input type="button" value="Cancel" onclick="javascript: + window.location.href='index.php';"/> +</p> +</form> diff --git a/include/client/view.inc.php b/include/client/view.inc.php index c36eaec96dd81d06804a5cd44d26fc986a6d2737..55caf9b6e073ea11d23fe916c8a1c2c986117160 100644 --- a/include/client/view.inc.php +++ b/include/client/view.inc.php @@ -15,6 +15,8 @@ if(!$dept || !$dept->isPublic()) <h1> Ticket #<?php echo $ticket->getNumber(); ?> <a href="view.php?id=<?php echo $ticket->getId(); ?>" title="Reload"><span class="Icon refresh"> </span></a> + <a class="action-button" href="tickets.php?a=edit&id=<?php + echo $ticket->getId(); ?>"><i class="icon-edit"></i> Edit</a> </h1> </td> </tr> diff --git a/tickets.php b/tickets.php index 7c49a74d34611ff7f7f4b6fd0aeda80c31fcce0f..a98401ed38416c65eff4b48a299009605f2589e3 100644 --- a/tickets.php +++ b/tickets.php @@ -32,6 +32,23 @@ if($_REQUEST['id']) { if($_POST && is_object($ticket) && $ticket->getId()): $errors=array(); switch(strtolower($_POST['a'])){ + case 'edit': + if(!$ticket->checkUserAccess($thisclient)) //double check perm again! + $errors['err']='Access Denied. Possibly invalid ticket ID'; + else { + $forms=DynamicFormEntry::forTicket($ticket->getId()); + foreach ($forms as $form) + if (!$form->isValid()) + $errors = array_merge($errors, $form->errors()); + } + if (!$errors) { + foreach ($forms as $f) $f->save(); + $_REQUEST['a'] = null; //Clear edit action - going back to view. + $ticket->logNote('Ticket details updated', sprintf( + 'Ticket details were updated by client %s <%s>', + $thisclient->getName(), $thisclient->getEmail())); + } + break; case 'reply': if(!$ticket->checkUserAccess($thisclient)) //double check perm again! $errors['err']='Access Denied. Possibly invalid ticket ID'; @@ -70,7 +87,14 @@ if($_POST && is_object($ticket) && $ticket->getId()): endif; $nav->setActiveNav('tickets'); if($ticket && $ticket->checkUserAccess($thisclient)) { - $inc='view.inc.php'; + if (isset($_REQUEST['a']) && $_REQUEST['a'] == 'edit') { + $inc = 'edit.inc.php'; + if (!$forms) $forms=DynamicFormEntry::forTicket($ticket->getId()); + // Auto add new fields to the entries + foreach ($forms as $f) $f->addMissingFields(); + } + else + $inc='view.inc.php'; } elseif($cfg->showRelatedTickets() && $thisclient->getNumTickets()) { $inc='tickets.inc.php'; } else {