示例#1
0
        // the reply.
        foreach ($history[$tid]['changes'] as $change) {
            if (!empty($change['private'])) {
                $permission = $GLOBALS['injector']->getInstance('Horde_Perms')->getPermission('whups:comments:' . $change['value']);
                $group_id = array_shift(array_keys($permission->getGroupPermissions()));
                $vars->set('group', $group_id);
                break;
            }
        }
        $flowed = new Horde_Text_Flowed(preg_replace("/\\s*\n/U", "\n", $history[$tid]['comment']), 'UTF-8');
        $vars->set('newcomment', $flowed->toFlowed(true));
    }
}
// Edit action.
$title = '[#' . $id . '] ' . $ticket->get('summary');
$editform = new Whups_Form_Ticket_Edit($vars, $ticket, sprintf(_("Update %s"), $title));
if ($vars->get('formname') == 'whups_form_ticket_edit') {
    if ($editform->validate($vars)) {
        $editform->getInfo($vars, $info);
        $ticket->change('summary', $info['summary']);
        $ticket->change('state', $info['state']);
        $ticket->change('priority', $info['priority']);
        $ticket->change('due', $info['due']);
        if (!empty($info['version'])) {
            $ticket->change('version', $info['version']);
        }
        if (!empty($info['newcomment'])) {
            $ticket->change('comment', $info['newcomment']);
        }
        // Update user and group assignments.
        if (Whups::hasPermission($vars->get('queue'), 'queue', 'assign')) {
示例#2
0
文件: Api.php 项目: raz0rsdge/horde
 /**
  * Update a ticket's properties.
  *
  * @param integer $ticket_id  The id of the id to changes.
  * @param array $ticket_info  The attributes to set, from
  *                            Whups_Form_Ticket_Edit.
  *
  * @return boolean  True
  */
 public function updateTicket($ticket_id, $ticket_info)
 {
     global $whups_driver;
     // Cast as an int for safety.
     $ticket = Whups_Ticket::makeTicket((int) $ticket_id);
     // Check that we have permission to update the ticket
     if (!$GLOBALS['registry']->getAuth() || !Whups::hasPermission($ticket->get('queue'), 'queue', 'update')) {
         throw new Whups_Exception_PermissionDenied(_('You do not have permission to update this ticket.'));
     }
     // Populate $vars with existing ticket details.
     $vars = new Horde_Variables();
     $ticket->setDetails($vars);
     // Copy new ticket details in.
     foreach ($ticket_info as $detail => $newval) {
         $vars->set($detail, $newval);
     }
     // Create and populate the EditTicketForm for validation. API calls can't
     // use form tokens and aren't the result of the EditTicketForm being
     // submitted.
     $editform = new Whups_Form_Ticket_Edit($vars, $ticket);
     $editform->useToken(false);
     $editform->setSubmitted(true);
     // Attempt to validate and update the ticket.
     if (!$editform->validate($vars)) {
         $form_errors = var_export($editform->getErrors(), true);
         throw new Whups_Exception(sprintf(_("Invalid ticket data supplied: %s"), $form_errors));
     }
     $editform->getInfo($vars, $info);
     $ticket->change('summary', $info['summary']);
     $ticket->change('state', $info['state']);
     $ticket->change('due', $info['due']);
     $ticket->change('priority', $info['priority']);
     if (!empty($info['newcomment'])) {
         $ticket->change('comment', $info['newcomment']);
     }
     if (!empty($info['due'])) {
         $ticket->change('due', $info['due']);
     }
     // Update attributes.
     $whups_driver->setAttributes($info, $ticket);
     // Add attachment if one was uploaded.
     if (!empty($info['newattachment']['name'])) {
         $ticket->change('attachment', array('name' => $info['newattachment']['name'], 'tmp_name' => $info['newattachment']['tmp_name']));
     }
     // If there was a new comment and permissions were specified on
     // it, set them.
     if (!empty($info['group'])) {
         $ticket->change('comment-perms', $info['group']);
     }
     $ticket->commit();
     // Ticket updated successfully
     return true;
 }