forked from inxilpro/WP-Survey-And-Quiz-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.php
83 lines (63 loc) · 2.67 KB
/
pdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Handles the fetching and downloading of PDFs
* from DocRaptor.
*
* @author Iain Cambridge
* @copyright Fubra Limited 2010-2011 (c), all rights reserved.
* @license GPL v2
* @package WPSQT
*/
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/wp-load.php';
require_once WPSQT_DIR.'lib/Wpsqt/Tokens.php';
require_once WPSQT_DIR.'lib/docraptor.php';
$resultId = filter_input(INPUT_GET, 'id');
$quizId = filter_input(INPUT_GET,'quizid');
if ( !$_GET['quizid'] || !$_GET['id'] ){
wp_die('No result id given');
}
global $wpdb;
if ( filter_input(INPUT_GET, 'html') ){
echo $pdfTemplate;
exit;
} else {
$quizDetails = $wpdb->get_row(
$wpdb->prepare("SELECT * FROM `".WPSQT_TABLE_QUIZ_SURVEYS."` WHERE id = %d", array($_GET['quizid'])),
ARRAY_A);
$quizDetails['settings'] = unserialize($quizDetails['settings']);
$resultDetails = $wpdb->get_row(
$wpdb->prepare("SELECT * FROM `".WPSQT_TABLE_RESULTS."` WHERE id = %d", array($_GET['id'])),
ARRAY_A );
$resultDetails['person'] = unserialize($resultDetails['person']);
$resultDetails['sections'] = unserialize($resultDetails['sections']);
$personName = ( isset($resultDetails['person']['name']) && !empty($resultDetails['person']['name']) ) ? $resultDetails['person']['name'] : 'Anonymous';
$timestamp = strtotime($resultDetails['timestamp']);
$pdfTemplate = (empty($quizDetails['settings']['pdf_template'])) ? get_option('wpsqt_pdf_template'):$quizDetails['settings']['pdf_template'];
if ( empty($pdfTemplate) ){
// default pdf template here.
$pdfTemplate = "<html>";
$pdfTemplate .= "<body>";
$pdfTemplate .= "<center>You %USER_NAME% passed the %QUIZ_NAME% quiz!</center>";
$pdfTemplate .= "</body>";
$pdfTemplate .= "</html>";
}
$objTokens = Wpsqt_Tokens::getTokenObject();
$objTokens->setDefaultValues();
$pdfTemplate = $objTokens->doReplacement($pdfTemplate);
$resultUrl = esc_html(get_bloginfo('url').'/wp-admin/admin.php?page=wpsqt-menu&type=quiz&action=results&id='.$quizId
.'&subaction=mark&subid='.$resultDetails['id']);
$pdfTemplate = str_ireplace('%RESULT_URL%', $resultUrl, $pdfTemplate);
$url = plugins_url('pdf.php?html=true&id='.$_GET['id'].'&quizid='.$_GET['quizid'],__FILE__);
$apiKey = get_option('wpsqt_docraptor_api');
if ( !$apiKey ){
print "No DocRaptor API key! Please alert the site owner to fix this!";
exit;
}
$objDocraptor = new DocRaptor($apiKey);
$objDocraptor->setDocumentType('pdf')
->setName('PDF')
->setDocumentContent($pdfTemplate);
header('Content-disposition: attachment; filename=document.pdf');
header('Content-type: application/pdf');
print $objDocraptor->fetchDocument();
}