<?php

require_once "functions.php";
session_start();
security::redirect_if_not_loggedin();
$Guid = costant::desktop_guid();
if (isset($_GET["DeleteAttach"])) {
    attachments::delete_attachment_by_name($_GET["DeleteAttach"]);
}
if (isset($_FILES['UploadedAttachments']) && isset($_POST["Attachment_TrId"])) {
    $TrNumber = (int) $_POST['Attachment_TrId'];
    $FileName = $_FILES['UploadedAttachments']['name'];
    $FileExtension = substr($FileName, strpos($FileName, ".") + 1, strlen($FileName));
    $NewFileName = "Transaction_" . $TrNumber . "_Attach" . (attachments::get_number_of_attachments($TrNumber) + 1) . "." . $FileExtension;
    move_uploaded_file($_FILES['UploadedAttachments']['tmp_name'], "attachments/" . $NewFileName);
    echo $NewFileName;
}
if (isset($_GET["AttachmentsTable"])) {
    $TrId = $_GET["AttachmentsTable"];
    $Attachments = attachments::get_attachments_filename_array($TrId, true);
    echo "<table class = 'table'>";
    echo "<tbody>";
    for ($i = 0; $i < sizeof($Attachments); $i++) {
        echo "<tr>";
        $File = $Attachments[$i];
        design::table_cell(substr($File, strpos($File, "Attach"), strlen($File)), "");
        design::table_cell("<a href='services.php?guid={$Guid}&download_attachment={$File}'>\n                            <span class='glyphicon glyphicon-download-alt'> </span> Open</a>", "text_align_right");
        design::table_cell("<a href='#' onclick='attachment_delete(\"{$File}\",{$TrId});return false;'>\n                            <span class='glyphicon glyphicon-remove'> </span> Delete</a>", "text_align_right");
        echo "</tr>";
    }
    echo "</tbody>";
Example #2
0
    #Download Attachments by name
    if (isset($_GET["download_attachment"])) {
        $AttachmentFileName = $_GET["download_attachment"];
        if (!empty($AttachmentFileName)) {
            $FullPath = costant::attachments_folder() . "/" . $AttachmentFileName;
            header("Content-Type:");
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-Disposition: attachment; filename= " . $AttachmentFileName);
            header("Content-Transfer-Encoding: binary");
            readfile($FullPath);
        }
    }
    #Delete Attachments
    if (isset($_GET["delete_attachment"])) {
        $AttachmentFileName = $_GET["delete_attachment"];
        if (!empty($AttachmentFileName)) {
            attachments::delete_attachment_by_name($AttachmentFileName);
        }
    }
    #Delete transaction group
    if (isset($_GET["delete_group"])) {
        $deletegroup_string = $_GET["delete_group"];
        $deletegroup_array = explode(",", $deletegroup_string);
        db_function::transaction_delete_group($deletegroup_array);
        attachments::delete_group($deletegroup_array);
        echo $operation_succeded;
    }
} else {
    echo $wrong_guid;
}