示例#1
0
function Soap_generatePDF($userid)
{
    $adb = PearDatabase::getInstance();
    $current_user = vglobal('current_user');
    $_SESSION['type'] = "single";
    $user = new Users();
    $current_user = $user->retrieveCurrentUserInfoFromFile($userid);
    require_once "modules/OSSPdf/Print.php";
    require_once 'modules/OSSPdf/ModulesQueries.php';
    $module = $_REQUEST['usingmodule'];
    $id = $_REQUEST['recordid'];
    if (isset($_REQUEST['fromdetailview']) && $_REQUEST['fromdetailview'] == 'yes') {
        $document_list = array();
        if ($_REQUEST['return_name'] == "yes" || isset($_REQUEST['pdfajax'])) {
            $_REQUEST['template'] = explode(';', trim($_REQUEST['template'], ';'));
        }
        /* ----------------------------- */
        ##############
        ### PRZETWANIA ZMIENNYCH POCZATKOWYCH
        foreach ($_REQUEST['template'] as $templateid) {
            $_SESSION['template_to_perfom'] = $_REQUEST['template_to_perfom'] = $templateid;
            $pobierzdane = $adb->query("select osspdf_pdf_format,osspdf_pdf_orientation, filename, left_margin, right_margin, top_margin, bottom_margin from vtiger_osspdf where osspdfid = '{$templateid}'", true);
            $_REQUEST['pdf_format'] = $adb->query_result($pobierzdane, 0, "osspdf_pdf_format");
            $pdf_orientation_result = $adb->query_result($pobierzdane, 0, "osspdf_pdf_orientation");
            $_REQUEST['file_name'] = $adb->query_result($pobierzdane, 0, "filename");
            $_REQUEST['left'] = $adb->query_result($pobierzdane, 0, "left_margin");
            $_REQUEST['right'] = $adb->query_result($pobierzdane, 0, "right_margin");
            $_REQUEST['top'] = $adb->query_result($pobierzdane, 0, "top_margin");
            $_REQUEST['bottom'] = $adb->query_result($pobierzdane, 0, "bottom_margin");
            $_SESSION['top'] = $_REQUEST['top'];
            if ($pdf_orientation_result == 'Portrait') {
                $pdf_orientation = "P";
            } elseif ($pdf_orientation_result == 'Landscape') {
                $pdf_orientation = "L";
            }
            /* ----------------------------- */
            ##############
            ### INICJOWANIE PDFA, POBIERANIE DANYCH ETC
            $pdf = new Printer();
            $pdf->setPageFormat($_REQUEST['pdf_format'], $pdf_orientation);
            //$pdf->setPrintHeader(false);
            //$pdf->setPrintFooter(false);
            //	$pdf->SetHeaderData( '','','asd','' );
            $pdf->SetCompression(true);
            //$pdf->SetMargins( $left,$top, $right = -1,$keepmargins = false );
            if (isset($_REQUEST['left']) && $_REQUEST['left'] != '' && $_REQUEST['left'] != 0) {
                $pdf->SetLeftMargin($_REQUEST['left']);
            }
            if (isset($_REQUEST['right']) && $_REQUEST['right'] != '' && $_REQUEST['right'] != 0) {
                $pdf->SetRightMargin($_REQUEST['right']);
            }
            /*
                        if (isset($_REQUEST['top']) && $_REQUEST['top'] != '' && $_REQUEST['top'] != 0) {
                            $pdf->SetTopMargin($_REQUEST['top']);
                        }
            
                        if (isset($_REQUEST['bottom']) && $_REQUEST['bottom'] != '' && $_REQUEST['bottom'] != 0) {
                            $pdf->SetAutoPageBreak(true, $_REQUEST['bottom']);
                        }*/
            /* ----------------------------- */
            ################
            $date_var = $adb->formatDate(date('Y-m-d H:i:s'), true);
            $query = "insert into vtiger_audit_trial values(?,?,?,?,?,?)";
            $qparams = array($adb->getUniqueID('vtiger_audit_trial'), $current_user->id, $module, 'Generate PDF', $id, $date_var);
            $adb->pquery($query, $qparams, true);
            TakeContent($pdf, $module, $id, $site_URL);
            $filepath = $_REQUEST['file_name'] . '_' . $id . $templateid . '_' . date("YmdHis") . '.pdf';
            $pdf->Output($filepath, 'F');
            ###
            $pobierz = $adb->query("select * from vtiger_osspdf_config where conf_id = 'GENERALCONFIGURATION'", true);
            ###
            $data = array();
            for ($i = 0; $i < $adb->num_rows($pobierz); $i++) {
                $data[$adb->query_result($pobierz, $i, "name")] = $adb->query_result($pobierz, $i, "value");
            }
            $docid = 0;
            if ($data['ifsave'] == 'yes') {
                $document_id = CreateDocument($filepath, $data['ifattach'], $id, $module, $docid);
                $nr = $document_id + 1;
                $document_list[] = $nr . '_' . $filepath;
                $storage_path = decideFilePath();
                $pelnasciezka = $storage_path . $nr . '_' . $filepath;
            } else {
                $document_list[] = $filepath;
                $storage_path = decideFilePath();
                $pelnasciezka = $storage_path . $filepath;
            }
            chmod('storage', 0777);
            if ($_REQUEST['return_name'] != "yes" || $_REQUEST['return_name'] == "") {
                rename($filepath, $pelnasciezka);
            } else {
                $sciezka = "storage/" . $filepath;
                rename($filepath, $sciezka);
            }
            if ($data['ifattach'] == 'yes') {
                $sql = "INSERT INTO vtiger_senotesrel (`crmid`,`notesid`) VALUES ('{$id}','{$docid}')";
                $wykonaj = $adb->query($sql, true);
            }
        }
        if ($_REQUEST['return_name'] != "yes" || $_REQUEST['return_name'] == "") {
            $storage_path = decideFilePath();
        } else {
            $storage_path = "storage/";
        }
        $zip = getTranslatedString($_REQUEST['usingmodule']) . '_' . date("YmdHis") . '.zip';
        $zipname = 'storage/' . $zip;
        $zipname = file_exist_fn($zipname, 0);
        if (count($document_list) > 1) {
            zipFilesAndDownload($document_list, $zipname, $storage_path, $zip);
        } else {
            if ($_REQUEST['return_name'] != "yes") {
                header("Content-type: application/pdf");
                header("Content-Disposition: attachment; filename=" . $document_list[0]);
                header("Pragma: no-cache");
                header("Expires: 0");
                readfile($storage_path . "/" . $document_list[0]);
                exit;
            } elseif ($_REQUEST['return_name'] == "yes") {
                return $document_list[0];
            }
        }
    }
}
示例#2
0
        // At least write the document to webspace:
        $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
        // buat pathnya di C..jika belum ada, sistem langsung dibikin
        $path = 'C:Surat_Wanprestasi/';
        if (!file_exists($path)) {
            mkdir($path, 0777, true);
        }
        //simpan file di komputer
        $document->save($path . "/" . $nama_file);
        //simpan ke dalam array
        $file_names[] = $nama_file;
    }
    //persiapan file zip dan memanggil fungsi generate zip
    $zip_file_name = "Surat_Wanprestasi_" . date('d F Y') . ".zip";
    $file_path = getcwd() . '/Surat_Wanprestasi/';
    zipFilesAndDownload($file_names, $zip_file_name, $path);
}
//fungsi untuk membuat zip
function zipFilesAndDownload($file_names, $archive_file_name, $file_path)
{
    $zip = new ZipArchive();
    //create the file and throw the error if unsuccessful
    if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE) !== TRUE) {
        exit("cannot open <{$archive_file_name}>\n");
    }
    //add each files of $file_name array to archive
    foreach ((array) $file_names as $files) {
        $zip->addFile($file_path . $files, $files);
    }
    $zip->close();
    $zipped_size = filesize($archive_file_name);
示例#3
0
文件: files.php 项目: vidolch/TitleMe
<?php

if (isset($_POST['titles'])) {
    $file_names = array('/settingsEMptyFile.txt', '/settingsmyfile.txt');
    //Archive name
    $archive_file_name = 'test.zip';
    //Download Files path
    $file_path = $_SERVER['DOCUMENT_ROOT'];
    zipFilesAndDownload($file_names, $archive_file_name, $file_path);
    function zipFilesAndDownload($file_names, $archive_file_name, $file_path)
    {
        //echo $file_path;die;
        $zip = new ZipArchive();
        //create the file and throw the error if unsuccessful
        if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE) !== TRUE) {
            exit("cannot open <{$archive_file_name}>\n");
        }
        //add each files of $file_name array to archive
        foreach ($file_names as $files) {
            $zip->addFile($file_path . $files, $files);
            //echo $file_path.$files,$files."
        }
        $zip->close();
        //then send the headers to foce download the zip file
        header("Content-type: application/zip");
        header("Content-Disposition: attachment; filename={$archive_file_name}");
        header("Content-length: " . filesize($archive_file_name));
        header("Pragma: no-cache");
        header("Expires: 0");
        sleep(5);
        readfile("{$archive_file_name}");