Esempio n. 1
0
 * @internal revisions
 * @since 1.9.13
 *
 */
@ob_end_clean();
require_once '../../config.inc.php';
require_once '../functions/common.php';
require_once '../functions/attachments.inc.php';
// This way can be called without _SESSION, this is useful for reports
testlinkInitPage($db, false, true);
$args = init_args();
if ($args->id) {
    $attachmentRepository = tlAttachmentRepository::create($db);
    $attachmentInfo = $attachmentRepository->getAttachmentInfo($args->id);
    // if ($attachmentInfo)
    if ($attachmentInfo && ($args->skipCheck || checkAttachmentID($db, $args->id, $attachmentInfo))) {
        $content = $attachmentRepository->getAttachmentContent($args->id, $attachmentInfo);
        if ($content != "") {
            @ob_end_clean();
            header('Pragma: public');
            header("Cache-Control: ");
            if (!(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" && preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"]))) {
                header('Pragma: no-cache');
            }
            header('Content-Type: ' . $attachmentInfo['file_type']);
            header('Content-Length: ' . $attachmentInfo['file_size']);
            header("Content-Disposition: inline; filename=\"{$attachmentInfo['file_name']}\"");
            header("Content-Description: Download Data");
            echo $content;
            exit;
        }
/**
 *
 */
function deleteAttachment(&$dbHandler, $fileID, $checkOnSession = true)
{
    $repo = tlAttachmentRepository::create($dbHandler);
    $info = $repo->getAttachmentInfo($fileID);
    if ($info) {
        $doIt = true;
        if ($checkOnSession) {
            $doIt = checkAttachmentID($dbHandler, $fileID, $info);
        }
        if ($doIt) {
            if ($repo->deleteAttachment($fileID, $info)) {
                logAuditEvent(TLS("audit_attachment_deleted", $info['title']), "DELETE", $fileID, "attachments");
            }
        }
    }
}
 * TestLink Open Source Project - http://testlink.sourceforge.net/ 
 * This script is distributed under the GNU General Public License 2 or later. 
 *
 * @filesource  attachmentdelete.php
 * Deletes an attachment by a given id
 */
require_once '../../config.inc.php';
require_once '../functions/common.php';
require_once '../functions/attachments.inc.php';
testlinkInitPage($db, false, false, "checkRights");
$args = init_args();
$deleteDone = false;
if ($args->id) {
    $attachmentRepository = tlAttachmentRepository::create($db);
    $attachmentInfo = $attachmentRepository->getAttachmentInfo($args->id);
    if ($attachmentInfo && checkAttachmentID($db, $args->id, $attachmentInfo)) {
        $deleteDone = $attachmentRepository->deleteAttachment($args->id, $attachmentInfo);
        if ($deleteDone) {
            logAuditEvent(TLS("audit_attachment_deleted", $attachmentInfo['title']), "DELETE", $args->id, "attachments");
        }
    }
}
$smarty = new TLSmarty();
$smarty->assign('bDeleted', $deleteDone);
$smarty->display('attachmentdelete.tpl');
/**
 * @return object returns the arguments for the page
 */
function init_args()
{
    //the id (attachments.id) of the attachment to be deleted