Whups::attachmentUrl PHP Method

attachmentUrl() public static method

Returns the links to view, download, and delete an attachment.
public static attachmentUrl ( integer $ticket, string $file, integer $queue ) : array
$ticket integer A ticket ID.
$file string An attachment name.
$queue integer The ticket's queue ID.
return array List of URLs.
    public static function attachmentUrl($ticket, $file, $queue)
    {
        global $injector, $registry;
        $links = array();
        // Can we view the attachment online?
        $mime_part = new Horde_Mime_Part();
        $mime_part->setType(Horde_Mime_Magic::extToMime($file['type']));
        $viewer = $injector->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part);
        if ($viewer && !$viewer instanceof Horde_Mime_Viewer_Default) {
            $links['view'] = Horde::url('view.php')->add(array('actionID' => 'view_file', 'type' => $file['type'], 'file' => $file['name'], 'ticket' => $ticket))->link(array('title' => $file['name'], 'target' => '_blank')) . $file['name'] . '</a>';
        } else {
            $links['view'] = $file['name'];
        }
        // We can always download attachments.
        $url_params = array('actionID' => 'download_file', 'file' => $file['name'], 'ticket' => $ticket);
        $links['download'] = $registry->downloadUrl($file['name'], $url_params)->link(array('title' => $file['name'])) . Horde::img('download.png', _("Download")) . '</a>';
        // Admins can delete attachments.
        if (self::hasPermission($queue, 'queue', Horde_Perms::DELETE)) {
            $links['delete'] = Horde::url('ticket/delete_attachment.php')->add(array('file' => $file['name'], 'id' => $ticket, 'url' => Horde::selfUrl(true, false, true)))->link(array('title' => sprintf(_("Delete %s"), $file['name']), 'onclick' => 'return window.confirm(\'' . addslashes(sprintf(_("Permanently delete %s?"), $file['name'])) . '\');')) . Horde::img('delete.png', sprintf(_("Delete %s"), $file['name'])) . '</a>';
        }
        return $links;
    }

Usage Example

Exemplo n.º 1
0
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @author Jan Schneider <*****@*****.**>
 */
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('whups');
$vars = Horde_Variables::getDefaultVariables();
$ticket = Whups::getCurrentTicket();
$view = $injector->createInstance('Horde_View');
try {
    $files = $ticket->listAllAttachments();
} catch (Whups_Exception $e) {
    $notification->push($e);
}
if ($files) {
    $format = array($prefs->getValue('date_format'), $prefs->getValue('time_format'));
    $attachments = Whups::getAttachments($ticket->getId());
    $view->attachments = array();
    foreach ($files as $file) {
        $view->attachments[] = array_merge(array('timestamp' => $file['timestamp'], 'date' => strftime($format[0], $file['timestamp']) . ' ' . strftime($format[1], $file['timestamp']), 'user' => Whups::formatUser(Whups::getUserAttributes($file['user_id']), true, true, true)), Whups::attachmentUrl($ticket->getId(), $attachments[$file['value']], $ticket->get('queue')));
    }
}
Whups::addTopbarSearch();
Whups::addFeedLink();
$page_output->addLinkTag($ticket->feedLink());
$page_output->addScriptFile('tables.js', 'horde');
$page_output->header(array('title' => sprintf(_("Attachments for %s"), '[#' . $id . '] ' . $ticket->get('summary'))));
$notification->notify(array('listeners' => 'status'));
echo Whups::getTicketTabs($vars, $ticket->getId())->render('attachments');
echo $view->render('ticket/attachments');
$page_output->footer();
All Usage Examples Of Whups::attachmentUrl