-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexports.php
406 lines (391 loc) · 14.5 KB
/
exports.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
if(empty($userid) || $userid==0) die('unauthorized access');
ini_set('memory_limit','768M'); //
ini_set('max_execution_time', 480); //480 seconds = 8 minutes
$docroot = $_SERVER['DOCUMENT_ROOT'];
require_once $docroot."/includes/functions_phpdocx.php";
require_once $docroot."/phpdocx/classes/CreateDocx.inc";
global $thefont, $expfontsize;
$stitle = 'Exports to MS Word';
$processed = 0;
$oper = (isset($_POST['oper']))?$_POST['oper']:'nada';
if($oper=="export"){
$pagebreak = ((isset($_POST['pagebreak']))?1:0);
$otbkcomm = ((isset($_POST['otbkcomm']))?$_POST['otbkcomm']:0);
$ntbkcomm = ((isset($_POST['ntbkcomm']))?$_POST['ntbkcomm']:0);
$unique = getuserfiletimestamp($timezone, 0);
$workdir = createworkdir();
$thefont='arial';
if($fontfamily=='merriweather' || $fontfamily=='times new roman' || $fontfamily=='caladea' || $fontfamily=='ibm plex serif')
$thefont = 'times new roman';
// export prefs are in their own cookie
$expprefs = explode(';', (isset($_COOKIE['rev_expprefs']))?$_COOKIE['rev_expprefs']:'2;1'); // medium font, no gutter
$expfontsize = $expprefs[0];
$expmargintype = $expprefs[1]; // no need to handle, do it from within MSW
switch($expfontsize){
case 1: // small
$expfontsize = (($thefont=='arial')?20:24);
break;
case 3: // large
$expfontsize = (($thefont=='arial')?28:32);
break;
default: // medium
$expfontsize = (($thefont=='arial')?24:28);
break;
}
foreach($_POST as $key => $value){
$prependidx=1;
if (strstr($key, 'doc') && $value==1){
$doc = str_replace('doc','',$key);
$tmp = explode('_', $doc);
$test = $tmp[0];
$book = $tmp[1];
$docx = new CreateDocx($docroot.'/includes/REV_styles.docx');
$docx->modifyPageLayout('letter',
array('marginTop' => 1080,
'marginBottom' => 1080,
'marginLeft' => 900,
'marginRight' => 900,
'numberCols' => (($test==0 || $test==1)?(($viewcols>1)?2:1):1)
));
$options = array(
'textAlign' => 'center',
'pStyle' => 'rFooter'
);
$numbering = new WordFragment($docx, 'defaultFooter');
//$numbering->addPageNumber('page_Number', $options);
$numbering->addPageNumber('page_NumberOfX', $options);
$docx->addFooter(array('default' => $numbering));
$html = '';
switch ($test) {
case 2: // intro
case 3: // appx
$folder = (($test==2)?'Information':'Appendices');
if($book < 95){
$ftitle = 'REV_'.(($test==2)?getbooktitle($test,$book, 0):getbooktagline($test,$book));
$html = getappxintro();
}else{
switch($book){
case 98:
$ftitle = 'REV_Abbreviations';
$html = getbibcontent(0);
break;
case 99:
$ftitle = 'REV_Bibliography';
$html = getbibcontent(1);
break;
default:
$ftitle = 'UNKNOWN!';
$html = 'No content!';
break;
}
}
loadhtm($docx, tidify($html));
break;
case 8: // word studies
$folder = 'Word Studies';
$test = 4;
$prependidx=0;
$ftitle = getbooktitle($test,$book, 0);
$html = getappxintro();
loadhtm($docx, tidify($html));
break;
case 0: // OT text
$folder = 'Old Testament';
$ftitle = 'REV_'.getbooktitle($test,$book, 1);
$row = rs('select chapters from book where testament = '.$test.' and book = '.$book.' ');
$chaps = $row[0];
for($ni=1;$ni<=$chaps;$ni++){
$chap = $ni;
$html = getbible(0);
loadhtm($docx, tidify($html));
}
break;
case 4: // OT comm
$folder = 'OT Commentary';
$test = 0;
$html = '';
$ftitle = 'REV_Commentary_'.getbooktitle($test,$book, 1);
if($otbkcomm > 0){
$html = getbookcomm();
loadhtm($docx, tidify($html));
if($otbkcomm==1){
if($pagebreak==1){
$docx->addBreak(array('type' => 'page'));
$html='';
}else{
$html = '<br /><br /><br />';
}
}
}
if($otbkcomm < 2){
$html.='<h2>'.getbooktitle($test,$book, 0).' Commentary</h2>';
$row = rs('select chapters from book where testament = '.$test.' and book = '.$book.' ');
$chaps = $row[0];
for($ni=1;$ni<=$chaps;$ni++){
$chap = $ni;
$html .= getcommentary();
loadhtm($docx, tidify($html));
$html = '<p> </p>';
}
}
break;
case 1: // NT text
$folder = 'New Testament';
$ftitle = 'REV_'.getbooktitle($test,$book, 1);
$row = rs('select chapters from book where testament = '.$test.' and book = '.$book.' ');
$chaps = $row[0];
for($ni=1;$ni<=$chaps;$ni++){
$chap = $ni;
$html = getbible(0);
loadhtm($docx, tidify($html));
}
break;
case 5: // NT comm
$folder = 'NT Commentary';
$test = 1;
$html = '';
$ftitle = 'REV_Commentary_'.getbooktitle($test,$book, 1);
if($ntbkcomm > 0){
$html = getbookcomm();
loadhtm($docx, tidify($html));
if($ntbkcomm==1){
if($pagebreak==1){
$docx->addBreak(array('type' => 'page'));
$html='';
}else{
$html = '<br /><br /><br />';
}
}
}
if($ntbkcomm<2){
$html.='<h2>'.getbooktitle($test,$book, 0).' Commentary</h2>';
$row = rs('select chapters from book where testament = '.$test.' and book = '.$book.' ');
$chaps = $row[0];
for($ni=1;$ni<=$chaps;$ni++){
$chap = $ni;
$html .= getcommentary();
loadhtm($docx, tidify($html));
$html = '<p> </p>';
}
}
break;
}
$properties = array(
'title' => fixforword($ftitle),
'creator' => 'John Schoenheit',
'dateCreated' => '12/12/2015',
'date' => '12/12/2015',
'description' => 'Revised English Version',
);
$docx->addProperties($properties);
if($prependidx==1) $ftitle = $book.'_'.$ftitle;
$ftitle = fixtxt($ftitle);
$ftitle = str_replace(': ','_',$ftitle);
$ftitle = str_replace(' ','_',$ftitle);
$ftitle = str_replace(':','',$ftitle);
$ftitle = str_replace('/','_',$ftitle);
$ftitle = str_replace('?','',$ftitle);
$ftitle = str_replace(';','_',$ftitle);
$filenames[] = $ftitle.'.docx';
$folders[] = $folder;
if($pagebreak==1) $docx->addBreak(array('type' => 'page'));
$docx->createDocx($docroot.'/export/'.$workdir.$ftitle);
unset($docx);
}
}
$zipfilename = "REV_MSWord".$unique.".zip";
$zip = new ZipArchive();
$zipfile = $docroot."/export/".$workdir.$zipfilename;
if ($zip->open($zipfile, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$zipfile>\n");
}
$cnt=0;
foreach ($filenames as $filename) {
$zip->addFile('./export/'.$workdir.$filename, $folders[$cnt].'/'.$filename);
$cnt++;
}
$zip->close();
foreach ($filenames as $filename) {
unlink($docroot.'/export/'.$workdir.$filename);
}
$processed = 1;
}
?>
<span class="pageheader"><?=$stitle?></span>
<div style="margin:0 auto;text-align:center"><small><?=usermenu()?></small></div>
<?if($superman==1){?>
<div style="margin:0 auto;text-align:center"><small><?=adminmenu()?></small></div>
<?}?>
<form name="frm" action="/" method="post">
<table class="gridtable" style="font-size:80%">
<?
if($processed==1){
print('<tr><td colspan="6">');
print('<span style="color:red"><b>Click <a href="/export/'.$workdir.$zipfilename.'">here</a> to download the file.</b></span> <small>Please download it now. It will be removed from the server in 7 minutes.</small>');
print('</td></tr>');
?>
<tr>
<td colspan="6">
<h4>Instructions for combining MSWord documents</h4>
<ol>
<li>Download the zip file by clicking the link above.</li>
<li>Extract the downloaded file, locate and open the first document you want to combine in MSWord. For example, if you want to combine the books of the NT, open Matthew.</li>
<li>Position the cursor at the very end of the file. If you checked the box to add a page break, the cursor will be on a blank page. If you did not check the box, hit [ENTER] a time or two.</li>
<li>On the MSWord main menu, click "Insert".</li>
<li>Over towards the right, locate and click the little down-arrow to the right of "Object"<br />
<img src="/i/insertobject.jpg" alt="insert object" border="0" /></li>
<li>Click on "Text from file..."</li>
<li>In the window that opens, navigate to and select the rest of the Word docs you want to combine. For example, if you are combining the books of the NT, select Mark through Revelation.</li>
<li>Click "Insert", and Word will append those docs to the end of the first doc you opened.</li>
<li>Save the combined file with an appropriate file name, such as "REV_NT.docx" (or whatever)</li>
</ol>
</td>
</tr>
<?
}else{
?>
<tr>
<td align="center" colspan="7">
NOTICE: depending on how many things are checked,<br />this may take a few minutes to complete. Please be patient.
</td>
</tr>
<tr>
<td align="center" colspan="7">
Choose what you want to export and click <input type="submit" name="btn" value="here." onclick="return validate(document.frm);">
<small>Add page break at end for combining MSWord docs</small><input type="checkbox" name="pagebreak" value="1" checked="checked">
</td>
</tr>
<tr>
<td style="text-align:right;vertical-align:top;">Information <input type="checkbox" name="larry2" value="1" onclick="chkall(0);"></td>
<td style="text-align:right;vertical-align:top;">Old Test <input type="checkbox" name="larry0" value="1" onclick="chkall(1);"></td>
<td style="text-align:right;vertical-align:top;">OT Comm <input type="checkbox" name="larry4" value="1" onclick="chkall(2);"><br />Book Comtry<br />
<select name="otbkcomm">
<option value="0" selected>exclude</option>
<option value="1">prepend</option>
<option value="2">only</option>
</select></td>
<td style="text-align:right;vertical-align:top;">New Test <input type="checkbox" name="larry1" value="1" onclick="chkall(3);"></td>
<td style="text-align:right;vertical-align:top;">NT Comm <input type="checkbox" name="larry5" value="1" onclick="chkall(4);"><br />Book Comtry<br />
<select name="ntbkcomm">
<option value="0" selected>exclude</option>
<option value="1">prepend</option>
<option value="2">only</option>
</select></td>
<td style="text-align:right;vertical-align:top;">Appendices <input type="checkbox" name="chkall5" id="chkall5" value="1" onclick="chkall(5);"></td>
<?if($revws==1 || $showdevitems==1){?>
<td style="text-align:right;vertical-align:top;">Word Studies <input type="checkbox" name="chkall6" id="chkall6" value="1" onclick="chkall(6);"></td>
<?}?>
</tr>
<tr>
<?
if($revws==1 || $showdevitems==1)
$tests = array(2,0,4,1,5,3,8);
else
$tests = array(2,0,4,1,5,3);
$js = 'var testbooks = [';
for($ni=0;$ni<sizeof($tests);$ni++){
$js.='['.$tests[$ni].',';
$tst = (($tests[$ni]<4)?$tests[$ni]:$tests[$ni]-4);
$sql = 'select book, abbr, tagline, title from book where testament = '.$tst.' and active = 1 order by '.(($tst==4)?'title':'sqn').' ';
$dat = dbquery($sql);
print('<td style="text-align:right;vertical-align:top;white-space:nowrap;">');
while($row = mysqli_fetch_array($dat)){
$nam = fixname($tst, $row[1], $row[2], $row[3]);
print($nam.' <input type="checkbox" name="doc'.$tests[$ni].'_'.$row[0].'" value="1"><br />');
$js.=$row[0].',';
}
if($tests[$ni]==2){
// add abbrevs and bib to Info
print('Abbreviations <input type="checkbox" name="doc'.$tests[$ni].'_98" value="1"><br />');
$js.='98,';
print('Bibliography <input type="checkbox" name="doc'.$tests[$ni].'_99" value="1"><br />');
$js.='99,';
}
$js.='0],';
print('</td>'.crlf);
}
print('</tr>');
}
print('</table>');
?>
<input type="hidden" name="mitm" value="<?=$mitm?>" />
<input type="hidden" name="page" value="<?=$page?>" />
<input type="hidden" name="test" value="<?=$test?>" />
<input type="hidden" name="book" value="<?=$book?>" />
<input type="hidden" name="chap" value="<?=$chap?>" />
<input type="hidden" name="vers" value="<?=$vers?>" />
<input type="hidden" name="oper" value="" />
</form>
<script>
<?if($processed==0) print($js.'0];');?>
function chkall(idx){
var ar = testbooks[idx];
var tst = ar[0];
var chk = document.frm['doc'+tst+'_'+ar[1]].checked;
for(i=1;i<ar.length-1;i++){
document.frm['doc'+tst+'_'+ar[i]].checked=!chk;
}
return !chk;
}
function validate(f){
var havebook = false;
for(i=0;i<testbooks.length;i++){
ar = testbooks[i];
tst = ar[0];
for(j=1;j<ar.length-1;j++){
if(document.frm['doc'+tst+'_'+ar[j]].checked){
havebook = true;
break;
}
}
}
if(havebook==false){
alert('Nothing is checked');
return false;
}
f.btn.value = 'please wait..';
f.oper.value = 'export';
return true;
}
</script>
<?
function fixname($t, $abbr, $tag, $title){
$title = fixtxt($title);
$tag = fixtxt($tag);
switch ($t) {
case 3: //appx
$ret = str_replace('Appendix ', 'Appx ', $tag);
if(strlen($ret) > 22)
$ret = substr($ret, 0, 19).'...';
break;
case 0:
case 1:
$ret = (($abbr=='-')?(($tag==null)?$title:$tag):$abbr);
break;
case 2: // intro
$ret = $title;
if(strlen($ret) > 18)
$ret = substr($ret, 0, 17).'...';
break;
case 4: // word study
$ret = $title;
if(strlen($ret) > 18)
$ret = substr($ret, 0, 17).'...';
break;
}
return $ret;
}
function fixtxt($t){
$t = cleanquotes($t);
//$t = str_replace('','',$t);
//$t = str_replace('','',$t);
$t = replacediacritics($t);
return $t;
}
function fixforword($title){
$title = fixtxt($title);
return $title;
}
?>