howto enable whups with a print button in the menu bar.
Joseph Malone <[email protected]>
| Newsgroups | gmane.comp.horde.whups |
|---|---|
| Message-ID | <[email protected]> |
I've attached a copy of details.php and templates/menu/menu.inc that will enable whups to have a print button that will print the ticket your looking at. -Joseph Malone -- Joseph Malone J.E. Higgins Lumber Co. MIS Department (925)245-4359 6999 Southfront Rd, Livermore, CA 94551 -- Whups mailing list - Join the hunt: http://horde.org/bounties/#whups Frequently Asked Questions: http://horde.org/faq/ To unsubscribe, mail: [email protected]
menu.inc
(application/octet-stream, 2 KB) - not displayed
details.php
(application/x-php, 20.6 KB)
<?php /** * $Horde: whups/details.php,v 1.96 2004/05/25 17:36:05 chuck Exp $ * * Copyright 2001-2004 Robert E. Coyle <[email protected]> * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. */ @define('WHUPS_BASE', dirname(__FILE__)); require_once WHUPS_BASE . '/lib/base.php'; require_once WHUPS_BASE . '/lib/Search.php'; require_once WHUPS_BASE . '/lib/Edit.php'; require_once 'Horde/Links.php'; require_once 'Horde/Variables.php'; require_once WHUPS_TEMPLATES . '/comment.inc'; $vars = &Variables::getDefaultVariables(); $ticket = $vars->get('id'); $ticket = preg_replace('|\D|', '', $ticket); $ticket2 = $ticket; if (!$ticket) { $notification->push(_("No such ticket."), 'horde.error'); header('Location: ' . Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true)); exit; } $vars->set('ticket', $ticket); $action = $vars->get('action'); $form = $vars->get('formname'); $links = &Horde_Links::singleton($registry->getApp()); $RENDERER = &new Horde_Form_Renderer(); $COMMENT = &new Comment(); $showticketdetails = true; // Ticket actions. $ACTIONS = &new Horde_UI_Tabs('action', $vars); $ACTIONS->addTab(_("History"), 'details.php', ''); if (Auth::getAuth()) { $ACTIONS->addTab(_("Update"), 'details.php', 'u'); } $ACTIONS->addTab(_("Comment"), 'details.php', 'ac'); $ACTIONS->addTab(_("Attachment"), 'details.php', 'ua'); if (Auth::getAuth()) { $ACTIONS->addTab(_("People"), 'details.php', 'at'); $ACTIONS->addTab(_("Set Queue"), 'details.php', 'sm'); } if (Auth::isAdmin('whups:admin')) { $ACTIONS->addTab(_("Set Type"), 'details.php', 'st'); $ACTIONS->addTab(_("Delete"), 'details.php', 'dt'); } $ACTIONS->preserve('id', $ticket); // Get the ticket details first. $details = $whups->getTicketDetails($ticket); if (is_a($details, 'PEAR_Error')) { if ($details->code === 0) { // No permissions to this ticket. $notification->push($details->getMessage(), 'horde.warning'); $url = Horde::url($registry->getParam('webroot', 'horde') . '/login.php', true); $url = Util::addParameter($url, 'url', Horde::selfUrl(true)); } else { $notification->push($details->getMessage(), 'horde.error'); $url = Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true); } header('Location: ' . $url); exit; } // Check permissions on this ticket. if (!count(Whups::permissionsFilter(array($details['queue'] => ''), 'queue', PERMS_READ))) { $notification->push(_("You are not allowed to view this ticket."), 'horde.error'); header('Location: ' . Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true)); exit; } // Get the attributes of this ticket TODO: Prefences to display all // attributes or just the ones that this ticket has defined. // // $attributes = $whups->getTicketAttributesWithNames($ticket); $attributes = $whups->getAllTicketAttributesWithNames($ticket); // TODO: Perhaps do permission checks on attributes. // We use info about the ticket in the forms below. foreach ($details as $varname => $value) { $vars->add($varname, $value); } /////// Add Comment action if ($form == 'addcommentform') { $addform = &Horde_Form::singleton('AddCommentForm', $vars); $addform->validate($vars); if ($addform->isValid()) { $addform->getInfo($vars, $info); // Add comment. if (!isset($info['newcommentid']) && !empty($info['newcomment'])) { $comment_id = $whups->addComment($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // Add attachment if one was uploaded. if (!empty($info['newattachment'])) { $comment_id = $whups->addAttachment($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // If there was a new comment and permissions were specified // on it, set them. if (!empty($info['newcommentid']) && isset($info['group'])) { Whups::addCommentPerms($info['newcommentid'], $info['group']); } $notification->push(_("Comment added"), 'horde.success'); $action = ''; } else { $action = 'ac'; } } /////// Upload Attachment action if ($form == 'attachmentform') { $attachmentform = &Horde_Form::singleton('AttachmentForm', $vars); $attachmentform->validate($vars); if ($attachmentform->isValid()) { $attachmentform->getInfo($vars, $info); $comment_id = $whups->addAttachment($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); $action = 'ua'; } else { if (isset($info['group'])) { Whups::addCommentPerms($comment_id, $info['group']); } $details = $whups->getTicketDetails($ticket); $notification->push(_("Attachment successfully uploaded"), 'horde.success'); $action = ''; } } else { $action = 'ua'; } } //////// Assign Ticket action if (Auth::getAuth() && $form == 'assignticketform') { $assignform = &Horde_Form::singleton('AssignTicketForm', $vars); $assignform->validate($vars); if ($assignform->isValid()) { $assignform->getInfo($vars, $info); $comment_id = $whups->assignTicket($info); if (isset($info['group'])) { Whups::addCommentPerms($comment_id, $info['group']); } $details = $whups->getTicketDetails($ticket); $notification->push(_("Assign Ticket Succeeded"), 'horde.success'); $action = ''; } else { $action = 'at'; } } //////// Edit action. if ($form == 'editform') { $editform = &Horde_Form::singleton('EditForm', $vars); $editform->validate($vars); if ($editform->isValid()) { $editform->getInfo($vars, $info); // Set the summary if it changed. if ($details['summary'] != $info['summary']) { $comment_id = $whups->setTicketSummary($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // Set the state if it changed. if ($details['state'] != $info['state']) { $comment_id = $whups->setTicketState($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // Set the priority if it changed. if ($details['priority'] != $info['priority']) { $comment_id = $whups->setTicketPriority($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // Update attributes. $comment_id = $whups->setAttributeValues($info); $info['newcommentid'] = $comment_id; $attributes = $whups->getAllTicketAttributesWithNames($ticket); // Add attachment if one was uploaded. if (!empty($info['newattachment'])) { $comment_id = $whups->addAttachment($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // If nothing else changed, make sure we add the comment if we // have one. if (!isset($info['newcommentid']) && !empty($info['newcomment'])) { $comment_id = $whups->addComment($info); if (is_a($comment_id, 'PEAR_Error')) { $notification->push($comment_id, 'horde.error'); header('Location: ' . Horde::applicationUrl(Util::addParameter('details.php', array('id' => $details['id'], 'action' => 'u')), true)); exit; } $info['newcommentid'] = $comment_id; } // If there was a new comment and permissions were specified // on it, set them. if (!empty($info['newcommentid']) && isset($info['group'])) { Whups::addCommentPerms($info['newcommentid'], $info['group']); } // Refetch details and report success. $details = $whups->getTicketDetails($ticket); $notification->push(_("Ticket Updated"), 'horde.success'); $action = ''; } else { $action = 'u'; } } //////// Set Type action if (Auth::isAdmin('whups:admin') && $form == 'settypestep1form') { $settypeform = &Horde_Form::singleton('SetTypeStep1Form', $vars); $settypeform->validate($vars); if ($settypeform->isValid()) { if (Auth::isAdmin('whups:admin')) { $action = 'st2'; } else { $action = ''; } } else { $action = 'st'; } } if (Auth::isAdmin('whups:admin') && $form == 'settypestep2form') { $settypeform = &Horde_Form::singleton('SetTypeStep2Form', $vars); $settypeform->validate($vars); if ($settypeform->isValid()) { $settypeform->getInfo($vars, $info); $comment_id = $whups->setTicketType($info); if (isset($info['group'])) { Whups::addCommentPerms($comment_id, $info['group']); } $details = $whups->getTicketDetails($ticket); $notification->push(_("Set Ticket Type"), 'horde.success'); $action = ''; } else { $notification->push(var_export($settypeform->_errors), 'horder.error'); $action = 'st2'; } } //////// Set Queue action if (Auth::isAdmin('whups:admin') && $form == 'setqueuestep1form') { $setqueueform = &Horde_Form::singleton('SetQueueStep1Form', $vars); $setqueueform->validate($vars); if ($setqueueform->isValid()) { if (Auth::isAdmin('whups:admin')) { $action = 'sm2'; } else { $action = ''; } } else { $action = 'sm'; } } if (Auth::isAdmin('whups:admin') && $form == 'setqueuestep2form') { $setqueueform = &Horde_Form::singleton('SetQueueStep2Form', $vars); $setqueueform->validate($vars); if ($setqueueform->isValid()) { if (Auth::isAdmin('whups:admin')) { $action = 'sm3'; } else { $action = ''; } } else { $action = 'sm2'; } } if (Auth::isAdmin('whups:admin') && $form == 'setqueuestep3form') { $smform1 = &Horde_Form::singleton('SetQueueStep1Form', $vars); $smform2 = &Horde_Form::singleton('SetQueueStep2Form', $vars); $smform3 = &Horde_Form::singleton('SetQueueStep3Form', $vars); $valid1 = $smform1->validate($vars); $valid2 = $smform2->validate($vars); $valid3 = $smform3->validate($vars); if ($valid1 && $valid2 && $valid3) { $smform1->getInfo($vars, $info); $smform2->getInfo($vars, $info); $smform3->getInfo($vars, $info); $comment_id = $whups->setTicketQueue($info); // Update any client links (if necessary). $clients = $vars->get('clients'); $clientstatus = $whups->updateClients($vars->get('ticket'), 'ticket', $clients); if (isset($info['group'])) { Whups::addCommentPerms($comment_id, $info['group']); } $details = $whups->getTicketDetails($ticket); $vars = &Variables::getDefaultVariables(); $vars->set('ticket', $ticket); foreach ($details as $varname => $value) { $vars->add($varname, $value); } $notification->push(sprintf(_("Moved ticket %d to '%s'"), $ticket, $details['_queue_name']), 'horde.success'); $action = ''; } else { $action = 'sm3'; } } //////// Delete Ticket action if (Auth::isAdmin('whups:admin') && $form == 'deleteticketform') { $deleteform = &Horde_Form::singleton('DeleteTicketForm', $vars); $deleteform->validate($vars); if ($deleteform->isValid()) { if ($vars->get('yesno') == 1) { $deleteform->getInfo($vars, $info); $result = $whups->deleteTicket($info); if (!is_a($result, 'PEAR_Error')) { $msg = sprintf(_("Ticket %d has been deleted."), $info['id']); $notification->push($msg, 'horde.success'); $uri = $prefs->getValue('whups_default_view') . '.php'; header('Location: ' . Horde::applicationUrl($uri, true)); exit; } else { $notification->push(sprintf(_("There was an error deleting the ticket: %s"), $result->getMessage()), 'horde.error'); $action = 'dt'; } } else { $notification->push(_("The ticket was not deleted."), 'horde.message'); } } else { $action = 'dt'; } } //////// Main ticket details page $title = '[#' . $ticket . '] ' . $details['summary']; require WHUPS_TEMPLATES . '/common-header.inc'; $print_view = (Util::getFormData('print') == 'true'); if ($print_view) { include_once $registry->getParam('templates', 'horde') . '/javascript/print.js'; } else { $print_link = Util::addParameter('details.php', 'id', $ticket2); $print_link = Util::addParameter($print_link, 'print', 'true'); $print_link = Horde::url($print_link); if ($browser->hasFeature('javascript')) { include_once $registry->getParam('templates', 'horde') . '/javascript/open_print_win.js'; } Whups::menu();} require WHUPS_TEMPLATES . '/prevnext.inc'; echo $ACTIONS->render(); $form = null; switch ($action) { case 'dt': if (Auth::isAdmin('whups:admin')) { $form = &Horde_Form::singleton('DeleteTicketForm', $vars); } else { $action = ''; } break; case 'st': if (Auth::isAdmin('whups:admin')) { $form = &Horde_Form::singleton('SetTypeStep1Form', $vars); } else { $action = ''; } break; case 'st2': if (Auth::isAdmin('whups:admin')) { $form1 = &Horde_Form::singleton('SetTypeStep1Form', $vars); $form2 = &Horde_Form::singleton('SetTypeStep2Form', $vars); $showticketdetails = false; $form1->preserve($vars); $RENDERER->beginInactive('Set Type'); $RENDERER->renderFormInactive($form1, $vars); $RENDERER->end(); $form2->open($RENDERER, $vars, 'details.php', 'post'); $RENDERER->beginActive('Set Type Step 2'); $RENDERER->renderFormActive($form2, $vars); $RENDERER->submit(); $RENDERER->end(); $form2->close($RENDERER); } break; case 'sm': if (Auth::isAdmin('whups:admin')) { $form = &Horde_Form::singleton('SetQueueStep1Form', $vars); } else { $action = ''; } break; case 'sm2': if (Auth::isAdmin('whups:admin')) { $form1 = &Horde_Form::singleton('SetQueueStep1Form', $vars); $form2 = &Horde_Form::singleton('SetQueueStep2Form', $vars); $showticketdetails = false; $form2->open($RENDERER, $vars, 'details.php', 'post'); $form1->preserve($vars); $RENDERER->beginInactive(_("Set Queue Step 1")); $RENDERER->renderFormInactive($form1, $vars); $RENDERER->end(); $RENDERER->beginActive(_("Set Queue Step 2")); $RENDERER->renderFormActive($form2, $vars); $RENDERER->submit(); $RENDERER->end(); $form2->close($RENDERER); } else { $action = ''; } break; case 'sm3': if (Auth::isAdmin('whups:admin')) { $form1 = &Horde_Form::singleton('SetQueueStep1Form', $vars); $form2 = &Horde_Form::singleton('SetQueueStep2Form', $vars); $form3 = &Horde_Form::singleton('SetQueueStep3Form', $vars); $showticketdetails = false; $form3->open($RENDERER, $vars, 'details.php', 'post'); $form1->preserve($vars); $RENDERER->beginInactive(_("Set Queue Step 1")); $RENDERER->renderFormInactive($form1, $vars); $RENDERER->end(); $form2->preserve($vars); $RENDERER->beginInactive(_("Set Queue Step 2")); $RENDERER->renderFormInactive($form2, $vars); $RENDERER->end(); $RENDERER->beginActive(_("Set Queue Step 3")); $RENDERER->renderFormActive($form3, $vars); $RENDERER->submit(); $RENDERER->end(); $form3->close($RENDERER); } break; case 'at': if (Auth::getAuth()) { $form = &Horde_Form::singleton('AssignTicketForm', $vars); } else { $action = ''; } break; case 'u': if (Auth::getAuth()) { $form = &Horde_Form::singleton('EditForm', $vars, $attributes); } else { $action = ''; } break; case 'ac': $form = &Horde_Form::singleton('AddCommentForm', $vars); break; case 'ua': $form = &Horde_Form::singleton('AttachmentForm', $vars); break; } if ($form != null) { $form->open($RENDERER, $vars, 'details.php', 'post'); $RENDERER->beginActive($ACTIONS->getTitleFromAction($action)); $RENDERER->renderFormActive($form, $vars); $RENDERER->submit(); $RENDERER->end(); $form->close($RENDERER); echo '<br />'; } if ($showticketdetails) { $form = &Horde_Form::singleton('TicketDetailsForm', $vars); $form->addAttributes($attributes); $details['user_id_requester'] = Whups::formatUser($details['user_id_requester']); $details['user_id_owner'] = Whups::getOwners($ticket); $clients = Whups::getClients(null, $ticket, true); if (is_a($clients, 'PEAR_Error')) { $details['client_name'] = $clients->getMessage(); } elseif (!empty($clients)) { $details['client_name'] = join("\n", $clients); } $attachments = array(); $files = Whups::getAttachments($ticket); if ($files) { if (is_a($files, 'PEAR_Error')) { $notification->push($files); } else { foreach ($files as $file) { $attachments[] = Whups::attachmentUrl($ticket, $file); } } $details['attachments'] = implode("<br />\n", $attachments); } $RENDERER->beginInactive($title); $RENDERER->renderFormInactive($form, new Variables($details)); $RENDERER->end(); if (empty($action)) { $history = Whups::permissionsFilter($whups->getHistory($ticket), 'comment', PERMS_READ); echo '<br />'; $COMMENT->begin(_("History")); $chtml = array(); foreach ($history as $comment_values) { $chtml[] = $COMMENT->render(new Variables($comment_values)); } if ($prefs->getValue('comment_sort_dir')) { $chtml = array_reverse($chtml); } echo implode(' ',$chtml); $COMMENT->end(); } if ($links->listLinkTypes()) { $link_data = array('from_params' => array('from_key' => 'ticket_id', 'from_value' => $ticket)); $links->viewLinks($link_data); } } require $registry->getParam('templates', 'horde') . '/common-footer.inc';