Files

87 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2019-03-28 12:18:24 -06:00
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2024-09-05 16:10:04 -07:00
Portions created by the Initial Developer are Copyright (C) 2016-2024
2019-03-28 12:18:24 -06:00
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2022-10-10 16:35:14 -06:00
//includes files
2023-06-15 14:28:23 -03:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
2019-03-28 12:18:24 -06:00
//add multi-lingual support
$language = new text;
$text = $language->get();
//get attachment uuid
2023-06-01 11:50:12 -06:00
$contact_attachment_uuid = $_GET['id'] ?? '';
$action = $_GET['action'] ?? '';
$session_id = $_GET['sid'] ?? '';
2019-03-28 12:18:24 -06:00
//get media
2023-06-01 11:50:12 -06:00
if (!empty($contact_attachment_uuid) && is_uuid($contact_attachment_uuid)) {
2019-03-28 12:18:24 -06:00
$sql = "select attachment_filename, attachment_content from v_contact_attachments ";
$sql .= "where contact_attachment_uuid = :contact_attachment_uuid ";
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['contact_attachment_uuid'] = $contact_attachment_uuid;
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
2023-06-01 11:50:12 -06:00
$attachment = $database->select($sql, $parameters ?? null, 'row');
unset($sql, $parameters);
2019-03-28 12:18:24 -06:00
2023-06-01 11:50:12 -06:00
$attachment_type = strtolower(pathinfo($attachment['attachment_filename'] ?? '', PATHINFO_EXTENSION));
2019-03-28 12:18:24 -06:00
//determine mime type
$content_type = 'application/octet-stream'; //set default
$allowed_attachment_types = json_decode($_SESSION['contact']['allowed_attachment_types']['text'] ?? '', true);
2023-06-01 11:50:12 -06:00
if (!empty($allowed_attachment_types)) {
2019-03-28 12:18:24 -06:00
if ($allowed_attachment_types[$attachment_type] != '') {
$content_type = $allowed_attachment_types[$attachment_type];
}
}
switch ($action) {
case 'download':
header("Content-type: ".$content_type."; charset=utf-8");
header("Content-Disposition: attachment; filename=\"".$attachment['attachment_filename']."\"");
header("Content-Length: ".strlen(base64_decode($attachment['attachment_content'])));
if (!empty($session_id)) {
header("Cache-Control: max-age=86400"); // 24h
header("Expires: ". gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); // 24h
}
2019-03-28 12:18:24 -06:00
echo base64_decode($attachment['attachment_content']);
break;
case 'display':
echo " <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>\n";
echo " <tr>\n";
echo " <td align='center' valign='middle'>\n";
2023-07-12 15:42:40 -06:00
echo " <img src=\"data:".$content_type.";base64,".$attachment['attachment_content']."\" style='width: auto; max-width: 95%; height: auto; max-height: 800px; box-shadow: 0px 1px 20px #888; background-color: #fff; cursor: pointer;' onclick=\"$('#contact_attachment_layer').fadeOut(200);\" oncontextmenu=\"window.open('contact_attachment.php?id=".$contact_attachment_uuid."&action=download'); return false;\" title=\"\">\n";
2019-03-28 12:18:24 -06:00
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
break;
}
}
?>