forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXT_helper.php
154 lines (116 loc) · 3.94 KB
/
EXT_helper.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?
//************************************************************************
// Leonardo XC Server, https://github.com/leonardoxc/leonardoxc
//
// Copyright (c) 2004-2010 by Andreadakis Manolis
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// $Id: EXT_helper.php,v 1.2 2012/06/02 08:40:12 manolis Exp $
//
//************************************************************************
require_once dirname(__FILE__)."/EXT_config_pre.php";
require_once "config.php";
$op=makeSane($_GET['op']);
// $CONF_use_utf=1;
require_once "EXT_config.php";
require_once "CL_flightData.php";
require_once "FN_functions.php";
require_once "FN_UTM.php";
require_once "FN_waypoint.php";
require_once "FN_output.php";
setDEBUGfromGET();
$op=makeSane($_GET['op1']);
if (!in_array($op,array("create_pdf")) ) return;
// $SERVER_URL='';
if ($op=="create_pdf") {
$direct=$_GET['direct']+0;
$remote=$_GET['remote']+0;
if ($userID <=0 || $remote) {
//echo "Not valid user";
// exit;
$userID =makeSane($_GET['userIDnotify']);
$userEmail=makeSane($_GET['userEmailNotify'],2);
unset($_GET['userIDnotify']);
unset($_GET['userEmailNotify']);
} else {
require_once "CL_user.php";
$userEmail=LeoUser::getEmail($userID);
}
unset($_GET['op1']);
unset($_GET['direct']);
unset($_GET['remote']);
$url="http://".urldecode($_GET['url']);
foreach($_GET as $name=>$val ) {
if ( !in_array($name,array('print','url') ) ){
$url.="&$name=$val";
}
}
if ($remote) $url.='&remote=1';
$url.='&print';
if ($direct){
$res=fetchURL($url,300);
echo "<a href='$url' target='_blank'>Printing URL</a><BR>\n";
// echo $res;
$lines=split("\n",$res);
if (!$remote) {
//$lines=$res;
$pdfFile=$SERVER_URL.$moduleRelPath.$lines[count($lines)-1];
$pdfFile=$SERVER_URL.$lines[count($lines)-1];
} else {
require_once dirname(__FILE__)."/CL_pdf.php";
$linesNum=count($lines);
for($k=$linesNum-1;$k>0;$k--) {
if (substr($lines[$k],0,8)=='PDF URL:') {
$pdfUrls[$k]=substr($lines[$k],8);
}
if (substr($lines[$k],0,9)=='START PDF') {
echo "Found start of pdf list, breaking <br>";
break;
}
}
print_r($pdfUrls);
$tmpDir=md5($_SERVER['REQUEST_URI']);
$pdfFile=leoPdf::createPDFmulti($pdfUrls,$tmpDir);
// $pdfFile=$tmpDir.'/logbook.pdf';
$helperUrl=$CONF['pdf']['helperUrl'];
if ($helperUrl) {
$helperUrl=$helperUrl.'/';
}
if ($pdfFile) {
echo "<a href='".$helperUrl.$CONF['pdf']['tmpPathRel'].'/'.$pdfFile."' target='_blank'>PDF is ready</a>";
// echo "\n\n".$moduleRelPath.'/'.$CONF['pdf']['tmpPathRel'].'/'.$pdfFile;
} else {
echo "ERROR: PDF creation failed";
}
return;
}
echo "<BR>PDF File is ready. <a href='$pdfFile' target='_blank'>Download it from here</a><BR>\n";
// echo "PDF FILE: $pdfFile\n";
echo "<BR><BR><a href='javascript:closePdfDiv();'>OK</a><br>";
return;
}
echo "printing $url";
require_once "CL_job.php";
$jobArgs=array('userID'=>$userID,
'jobType'=>'pdf',
'priority'=>(L_auth::isModerator($userID)?1:0),
'timeCreated'=>gmdate('Y-m-d H:i:s'),
'status'=>0,
'param1'=>$url,
'param2'=>$userEmail,
);
$previousJobTime=leoJob::searchJob($jobArgs);
if ($previousJobTime) {
echo "You have ordered the same PDF on GMT $previousJobTime<BR>";
} else {
leoJob::addJob($jobArgs);
echo "PDF order has been send<BR><BR>Will send email to $userEmail when the pdf is created<BR><BR>";
}
// $res=file_get_contents($url);
// echo "#<pre>".$res."</pre>#";
echo "<BR><BR><a href='javascript:closePdfDiv();'>OK</a><br>";
}
?>