Example #1
0
function PDFStop($handle)
{
    //global $htmldocPath,$htmldocAssetsPath;
    global $wkhtmltopdfPath, $wkhtmltopdfAssetsPath, $locale;
    $handle['orientation'] = $_SESSION['orientation'];
    unset($_SESSION['orientation']);
    $html_content = ob_get_clean();
    //convert to HTML page with CSS
    $html = '<!DOCTYPE html><HTML lang="' . mb_substr($locale, 0, 2) . '" ' . (mb_substr($locale, 0, 2) == 'he' || mb_substr($locale, 0, 2) == 'ar' ? ' dir="RTL"' : '') . '><HEAD><meta charset="UTF-8" />';
    if ($handle['css']) {
        $html .= '<link rel="stylesheet" type="text/css" href="assets/themes/' . Preferences('THEME') . '/stylesheet.css" />';
    }
    //modif Francois: bugfix wkhtmltopdf screen resolution on linux
    //see: https://code.google.com/p/wkhtmltopdf/issues/detail?id=118
    $html .= '<TITLE>' . str_replace(_('Print') . ' ', '', ProgramTitle()) . '</TITLE></HEAD><BODY><div style="width:' . (!empty($handle['orientation']) && $handle['orientation'] == 'landscape' ? '1448' : '1024') . 'px">' . $html_content . '</div></BODY></HTML>';
    //modif Francois: wkhtmltopdf
    if (!empty($wkhtmltopdfPath)) {
        if (!empty($wkhtmltopdfAssetsPath)) {
            $html = str_replace('assets/', $wkhtmltopdfAssetsPath, $html);
        }
        require 'classes/Wkhtmltopdf.php';
        try {
            //indicate to create PDF in the temporary files system directory
            $wkhtmltopdf = new Wkhtmltopdf(array('path' => sys_get_temp_dir()));
            $wkhtmltopdf->setBinPath($wkhtmltopdfPath);
            if (!empty($handle['orientation']) && $handle['orientation'] == 'landscape') {
                $wkhtmltopdf->setOrientation(Wkhtmltopdf::ORIENTATION_LANDSCAPE);
            }
            if (!empty($handle['margins']) && is_array($handle['margins'])) {
                $wkhtmltopdf->setMargins($handle['margins']);
            }
            $wkhtmltopdf->setTitle(utf8_decode(str_replace(_('Print') . ' ', '', ProgramTitle())));
            //directly pass HTML code
            $wkhtmltopdf->setHtml($html);
            //MODE_EMBEDDED displays PDF in browser, MODE_DOWNLOAD forces PDF download
            $wkhtmltopdf->output(Wkhtmltopdf::MODE_EMBEDDED, str_replace(array(_('Print') . ' ', ' '), array('', '_'), utf8_decode(ProgramTitle())) . '.pdf');
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    } else {
        echo $html;
    }
}
Example #2
0
    $option_keys = array('company_fax');
    $options = get_options($option_keys);
    $quotation = check_quotation_exists($id);
    $quotation_items = unserialize($quotation->items);
    $data = array('breadcrumb_title' => '刪除報價單', 'quotation' => $quotation, 'quotation_items' => $quotation_items);
    $data = array_merge($data, $options);
    $app->render('quotation_delete.html', $data);
});
$app->get('/quotation_download_pdf/:id', function ($id) use($app) {
    require 'lib/Wkhtmltopdf.php';
    $option_keys = array('company_fax');
    $options = get_options($option_keys);
    $quotation = check_quotation_exists($id);
    $url = $app->config('full_doc_root') . '/quotation_view/' . $id;
    try {
        $wkhtmltopdf = new Wkhtmltopdf(array('path' => PROJECT_PATH . '/pdf/', 'binpath' => WKHTMLTOPDF_BIN_PATH));
        $wkhtmltopdf->setTitle($quotation->quotation_name);
        $wkhtmltopdf->setUrl($url);
        $wkhtmltopdf->setCookie(COOKIE_NAME, urlencode($app->getCookie(COOKIE_NAME)));
        $wkhtmltopdf->output(Wkhtmltopdf::MODE_DOWNLOAD, $quotation->quotation_name . '.pdf');
    } catch (Exception $e) {
        $app->notFound();
    }
});
$app->get('/quotation_status_update/:id', function ($id) use($app) {
    $quotation_status_words = array('confirmed' => '訂單確認', 'canceled' => '取消', 'paid' => '已付款', 'wait' => '待回應');
    $quotation = check_quotation_exists($id);
    $quotation_items = unserialize($quotation->items);
    $data = array('breadcrumb_title' => '更新報價單狀態', 'quotation' => $quotation, 'quotation_status_words' => $quotation_status_words);
    $app->render('quotation_status_update.html', $data);
});
<?php

chdir(__DIR__);
require 'config.php';
dol_include_once('/query/class/query.class.php');
dol_include_once('/query/class/dashboard.class.php');
$PDOdb = new TPDOdb();
$dash = new TQDashboard();
if ($dash->loadBy($PDOdb, GETPOST('uid'), 'uid', false)) {
    try {
        if (!class_exists('Wkhtmltopdf')) {
            dol_include_once('/query/lib/Wkhtmltopdf.php');
        }
        $wkhtmltopdf = new Wkhtmltopdf(array('path' => sys_get_temp_dir()));
        $wkhtmltopdf->setTitle($dash->title);
        $wkhtmltopdf->setOrientation('landscape');
        $wkhtmltopdf->setUrl(dol_buildpath('/query/dashboard.php', 2) . '?action=run&uid=' . $dash->uid);
        $wkhtmltopdf->_bin = !empty($conf->global->ABRICOT_WKHTMLTOPDF_CMD) ? $conf->global->ABRICOT_WKHTMLTOPDF_CMD : 'wkhtmltopdf';
        $wkhtmltopdf->output(Wkhtmltopdf::MODE_DOWNLOAD, $dash->uid . '.pdf');
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
Example #4
0
    $options = get_options($option_keys);
    $quotation = check_quotation_exists($id);
    $quotation_items = unserialize($quotation->items);
    $data = array('breadcrumb_title' => '刪除報價單', 'quotation' => $quotation, 'quotation_items' => $quotation_items);
    $data = array_merge($data, $options);
    $app->render('quotation_delete.html', $data);
});
$app->get('/quotation_download_pdf/:id', function ($id) use($app) {
    require 'lib/Wkhtmltopdf.php';
    $option_keys = array('company_fax');
    $options = get_options($option_keys);
    $quotation = check_quotation_exists($id);
    $url = $app->config('full_doc_root') . '/quotation_view/' . $id;
    $html = file_get_contents($url);
    try {
        $wkhtmltopdf = new Wkhtmltopdf(array('path' => PROJECT_PATH . '/pdf/', 'binpath' => WKHTMLTOPDF_BIN_PATH));
        $wkhtmltopdf->setTitle($quotation->quotation_name);
        $wkhtmltopdf->setHtml($html);
        $wkhtmltopdf->output(Wkhtmltopdf::MODE_DOWNLOAD, $quotation->quotation_name . '.pdf');
    } catch (Exception $e) {
        $app->notFound();
    }
});
$app->get('/quotation_status_update/:id', function ($id) use($app) {
    $quotation_status_words = array('confirmed' => '訂單確認', 'canceled' => '取消', 'paid' => '已付款', 'wait' => '待回應');
    $quotation = check_quotation_exists($id);
    $quotation_items = unserialize($quotation->items);
    $data = array('breadcrumb_title' => '更新報價單狀態', 'quotation' => $quotation, 'quotation_status_words' => $quotation_status_words);
    $app->render('quotation_status_update.html', $data);
});
$app->post('/ajax_save_quotations', function () use($app) {