-
Notifications
You must be signed in to change notification settings - Fork 987
/
templates.php
748 lines (702 loc) · 29.2 KB
/
templates.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
<?php
/*
#############################################################
# >>> PHPSurveyor #
#############################################################
# > Author: Jason Cleeland #
# > E-mail: jason@cleeland.org #
# > Mail: Box 99, Trades Hall, 54 Victoria St, #
# > CARLTON SOUTH 3053, AUSTRALIA #
# > Date: 20 February 2003 #
# #
# This set of scripts allows you to develop, publish and #
# perform data-entry on surveys. #
#############################################################
# #
# Copyright (C) 2003 Jason Cleeland #
# #
# 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, or (at your #
# option) any later version. #
# #
# This program is distributed in the hope that it will be #
# useful, but WITHOUT ANY WARRANTY; without even the #
# implied warranty of MERCHANTABILITY or FITNESS FOR A #
# PARTICULAR PURPOSE. See the GNU General Public License #
# for more details. #
# #
# You should have received a copy of the GNU General #
# Public License along with this program; if not, write to #
# the Free Software Foundation, Inc., 59 Temple Place - #
# Suite 330, Boston, MA 02111-1307, USA. #
#############################################################
*/
require_once(dirname(__FILE__).'/../config.php');
$file_version="PHPSurveyor Template Editor ".$versionnumber;
if(get_magic_quotes_gpc())
{
$_GET = array_map("stripslashes", $_GET);
$_POST = array_map("stripslashes", $_POST);
}
if (!isset($templatename)) {$templatename = returnglobal('templatename');}
if (!isset($templatedir)) {$templatedir = returnglobal('templatedir');}
if (!isset($editfile)) {$editfile = returnglobal('editfile');}
if (!isset($screenname)) {$screenname=returnglobal('screenname');}
if (!isset($action)) {$action=returnglobal('action');}
if ($action != "newtemplate" && !$templatename) {$templatename = "default";}
$template_a=gettemplatelist();
foreach ($template_a as $tp) {
$templates[]=array("name"=>$tp, "dir"=>$publicdir."/templates/".$tp);
}
unset($template_a);
//Save Changes if necessary
if ($action=="savechanges" && $_POST['changes']) {
$_POST['changes']=str_replace("\r\n", "\n", $_POST['changes']);
if ($_POST['editfile']) {
$savefilename=$publicdir."/templates/".$_POST['templatename']."/".$_POST['editfile'];
if (is_writable($savefilename)) {
if (!$handle = fopen($savefilename, 'w')) {
echo "Could not open file ($savefilename)";
exit;
}
if (!fwrite($handle, $_POST['changes'])) {
echo "Cannot write to file ($savefilename)";
exit;
}
fclose($handle);
} else {
echo "The file $savefilename is not writable";
}
}
}
if ($action == "copy" && isset($_GET['newname']) && isset($_GET['copydir'])) {
//Copies all the files from one template directory to a new one
//This is a security issue because it is allowing copying from get variables...
$newdirname=$publicdir."/templates/".$_GET['newname'];
$copydirname=$publicdir."/templates/".$_GET['copydir'];
$mkdirresult=mkdir_p($newdirname);
if ($mkdirresult == 1) {
$copyfiles=getListOfFiles($copydirname);
foreach ($copyfiles as $file) {
$copyfile=$copydirname."/".$file;
$newfile=$newdirname."/".$file;
if (!copy($copyfile, $newfile)) {
echo "<script type=\"text/javascript\">\n<!--\nalert('Failed to copy $file to new template directory.');\n//-->\n</script>";
}
}
$templates[]=array("name"=>$_GET['newname'], "dir"=>$newdirname);
$templatename=$_GET['newname'];
} elseif($mkdirresult == 2) {
echo "<script type=\"text/javascript\">\n<!--\nalert('Directory with the name `".$_GET['newname']."` already exists - choose another name');\n//-->\n</script>";
} else {
echo "<script type=\"text/javascript\">\n<!--\nalert('Unable to create directory `".$_GET['newname']."`. Maybe you don't have permission.');\n//-->\n</script>";
}
}
if ($action == "rename" && isset($_GET['newname']) && isset($_GET['copydir'])) {
$newdirname=$publicdir."/templates/".$_GET['newname'];
$olddirname=$publicdir."/templates/".$_GET['copydir'];
if (!rename($olddirname, $newdirname)) {
echo "<script type=\"text/javascript\">\n<!--\nalert('Directory could not be renamed to `".$_GET['newname']."`. Maybe you don't have permission.');\n//-->\n</script>";
} else {
$templates[]=array("name"=>$_GET['newname'], "dir"=>$newdirname);
$templatename=$_GET['newname'];
}
}
if ($action == "upload") {
//Uploads the file into the appropriate directory
$the_full_file_path = $publicdir."/templates/".$templatename . "/" . $_FILES['the_file']['name']; //This is where the temp file is
if (!@move_uploaded_file($_FILES['the_file']['tmp_name'], $the_full_file_path)) {
echo "<strong><font color='red'>"._("Error")."</font></strong><br />\n";
echo _("An error occurred uploading your file. This may be caused by incorrect permissions in your admin folder.")."<br /><br />\n";
echo "<input type='submit' value='"._("Main Admin Screen")."' onClick=\"window.open('$scriptname', '_top')\">\n";
echo "</td></tr></table>\n";
echo "</body>\n</html>\n";
exit;
}
}
if ($action == "delete") {
if ($_POST['otherfile'] != "chart.jpg") {
$the_full_file_path = $publicdir."/templates/".$templatename . "/" . $_POST['otherfile']; //This is where the temp file is
unlink($the_full_file_path);
}
}
if ($action == "zip") {
require("classes/phpzip/phpzip.inc.php");
$z = new PHPZip();
$templatedir="$publicdir/templates/$templatename/";
$zipfile="$tempdir/$templatename.zip";
$z -> Zip($templatedir, $zipfile);
if (is_file($zipfile)) {
//Send the file for download!
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=$templatename.zip" );
header( "Content-Description: File Transfer");
@readfile($zipfile);
//Delete the temporary file
unlink($zipfile);
}
}
function mkdir_p($target){
//creates a new directory
//Returns 1 for success
// 2 for "directory/file by that name exists
// 0 for other errors
if(file_exists($target) || is_dir($target))
return 2;
if(mkdir($target,0777)){
return 1;
}
if(mkdir_p(substr($target, 0, (strrpos($target, '/')))) == 1){
if(mkdir_p($target) == 1)
return 1;
else
return 0;
} else {
return 0;
}
}
function makeoptions($array, $value, $text, $selectedvalue) {
$return="";
foreach ($array as $ar) {
$return .= "<option value='".$ar[$value]."'";
if ($ar[$value] == $selectedvalue) {
$return .= " selected";
}
$return .= ">".$ar[$text]."</option>\n";
}
return $return;
}
//Standard Template Files
$files[]=array("name"=>"startpage.pstpl");
$files[]=array("name"=>"survey.pstpl");
$files[]=array("name"=>"welcome.pstpl");
$files[]=array("name"=>"startgroup.pstpl");
$files[]=array("name"=>"groupdescription.pstpl");
$files[]=array("name"=>"question.pstpl");
$files[]=array("name"=>"submit.pstpl");
$files[]=array("name"=>"privacy.pstpl");
$files[]=array("name"=>"completed.pstpl");
$files[]=array("name"=>"endgroup.pstpl");
$files[]=array("name"=>"navigator.pstpl");
$files[]=array("name"=>"endpage.pstpl");
$files[]=array("name"=>"clearall.pstpl");
$files[]=array("name"=>"register.pstpl");
$files[]=array("name"=>"load.pstpl");
$files[]=array("name"=>"save.pstpl");
$files[]=array("name"=>"assessment.pstpl");
$normalfiles=array("DUMMYENTRY", ".", "..");
foreach ($files as $fl) {
$normalfiles[]=$fl["name"];
}
$screens[]=array("name"=>_("Welcome Page"));
$screens[]=array("name"=>_("Question Page"));
$screens[]=array("name"=>_("Submit Page"));
$screens[]=array("name"=>_("Completed Page"));
$screens[]=array("name"=>_("Clear All Page"));
$screens[]=array("name"=>_("Register Page"));
$screens[]=array("name"=>_("Load Page"));
$screens[]=array("name"=>_("Save Page"));
//Page Display Instructions
$Welcome=array("startpage.pstpl", "welcome.pstpl", "navigator.pstpl", "endpage.pstpl");
$Question=array("startpage.pstpl", "survey.pstpl", "startgroup.pstpl", "groupdescription.pstpl", "question.pstpl", "endgroup.pstpl", "navigator.pstpl", "endpage.pstpl");
$Submit=array("startpage.pstpl", "survey.pstpl", "submit.pstpl", "privacy.pstpl", "navigator.pstpl", "endpage.pstpl");
$Completed=array("startpage.pstpl", "assessment.pstpl", "completed.pstpl", "endpage.pstpl");
$Clearall=array("startpage.pstpl", "clearall.pstpl", "endpage.pstpl");
$Register=array("startpage.pstpl", "survey.pstpl", "register.pstpl", "endpage.pstpl");
$Save=array("startpage.pstpl", "save.pstpl", "endpage.pstpl");
$Load=array("startpage.pstpl", "load.pstpl", "endpage.pstpl");
//CHECK ALL FILES EXIST, AND IF NOT - COPY IT FROM DEFAULT DIRECTORY
foreach ($files as $file) {
$thisfile="$publicdir/templates/$templatename/".$file['name'];
if (!is_file($thisfile)) {
$copyfile="$publicdir/templates/default/".$file['name'];
$newfile=$thisfile;
if (!@copy($copyfile, $newfile)) {
echo "<script type=\"text/javascript\">\n<!--\nalert('Failed to copy ".$file['name']." to new template directory.');\n//-->\n</script>";
}
}
}
//Load this editfile
function filetext($templatefile) {
global $publicdir, $templatename;
$output="";
foreach(file("$publicdir/templates/$templatename/$templatefile") as $line) {
$output .= $line;
}
return $output;
}
function makegraph($thisstep, $total)
{
global $templatedir, $publicurl, $templatename;
$chart="$publicurl/templates/$templatedir/chart.jpg";
if (!is_file($chart)) {$shchart="chart.jpg";}
else {$shchart = "$publicurl/templates/$templatedir/chart.jpg";}
$graph = "<table class='graph' width='100' align='center' cellpadding='2'><tr><td>\n";
$graph .= "<table width='180' align='center' cellpadding='0' cellspacing='0' border='0' class='innergraph'>\n";
$graph .= "<tr><td align='right' width='40'>0%</td>\n";
$size=intval(($thisstep-1)/$total*100);
//$graph .= "<td width='100' align='left'><img src='$shchart' height='12' width='$size' align='left' alt='$size% "._("complete")."'></td>\n";
$graph .= "<td width='100' align='left'><img src='$publicurl/templates/$templatename/$shchart' "
."height='12' width='$size' align='left' alt='$size% complete'></td>\n";
$graph .= "<td align='left' width='40'>100%</td></tr>\n";
$graph .= "</table>\n";
$graph .= "</td></tr>\n</table>\n";
return $graph;
}
if (!$screenname) {$screenname=_("Welcome Page");}
if ($screenname != _("Welcome Page")) {$_SESSION['step']=1;} else {unset($_SESSION['step']);} //This helps handle the load/save buttons
if ($screenname == _("Submit Page")) {$_POST['move'] = " "._("last")." ";}
//FAKE DATA FOR TEMPLATES
$thissurvey['name']="Template Sample";
$thissurvey['description']="This is a sample survey description. It could be quite long.<br /><br />But this one isn't.";
$thissurvey['welcome']="Welcome to this sample survey.<br />\n You should have a great time doing this<br />";
$thissurvey['allowsave']="Y";
$thissurvey['templatedir']=$templatename;
$thissurvey['format']="G";
$thissurvey['url']="http://www.phpsurveyor.org/";
$thissurvey['urldescrip']="A URL Description";
$percentcomplete=makegraph(6, 10);
$groupname="Group 1: The first lot of questions";
$groupdescription="This group description is fairly vacuous, but quite important.";
$navigator="<input class='submit' type='submit' value=' next >> ' name='move' />";
if ($screenname != _("Welcome Page")) {$navigator = "<input class='submit' type='submit' value=' << prev ' name='move' />\n".$navigator;}
$help="This is some help text";
$totalquestions="10";
$surveyformat="Format";
$completed="Survey is completed and saved.";
$notanswered="5";
$privacy="";
$surveyid="1295";
$token=1234567;
$assessments="<table align='center'><tr><th>Assessment Heading</th></tr><tr><td align='center'>Assessment details<br />Note that assessments will only show if assessment rules have been set. Otherwise, this assessment table will not appear</td></tr></table>";
$addbr=false;
switch($screenname) {
case _("Question Page"):
unset($files);
foreach ($Question as $qs) {
$files[]=array("name"=>$qs);
}
$myoutput[]="<meta http-equiv=\"expires\" content=\"Wed, 26 Feb 1997 08:21:57 GMT\">\n";
$myoutput[]="<meta http-equiv=\"Last-Modified\" content=\"".gmdate('D, d M Y H:i:s'). " GMT\">\n";
$myoutput[]="<meta http-equiv=\"Cache-Control\" content=\"no-store, no-cache, must-revalidate\">\n";
$myoutput[]="<meta http-equiv=\"Cache-Control\" content=\"post-check=0, pre-check=0, false\">\n";
$myoutput[]="<meta http-equiv=\"Pragma\" content=\"no-cache\">\n";
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/startpage.pstpl"));
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/survey.pstpl"));
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/startgroup.pstpl"));
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/groupdescription.pstpl"));
$question="How many roads must a man walk down?";
$questioncode="1a";
$answer="<input type='radio' name='1' value='1' id='radio1'><label class='answertext' for='radio1'>One</label><br /><input type='radio' name='1' value='2' id='radio2'><label class='answertext' for='radio2'>Two</label><br /><input type='radio' name='1' value='3' id='radio3'><label class='answertext' for='radio3'>Three</label><br />\n";
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/question.pstpl"));
$question="Please explain your details:";
$questioncode="2";
$answer="<textarea class='textarea'>Some text in this answer</textarea>";
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/question.pstpl"));
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/endgroup.pstpl"));
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/navigator.pstpl"));
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/endpage.pstpl"));
break;
case _("Welcome Page"):
unset($files);
$myoutput[]="";
foreach ($Welcome as $qs) {
$files[]=array("name"=>$qs);
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/$qs"));
}
break;
case _("Register Page"):
unset($files);
foreach($Register as $qs) {
$files[]=array("name"=>$qs);
}
foreach(file("$publicdir/templates/$templatename/startpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/survey.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/register.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/endpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
$myoutput[]= "\n";
break;
case _("Save Page"):
unset($files);
foreach($Save as $qs) {
$files[]=array("name"=>$qs);
}
foreach(file("$publicdir/templates/$templatename/startpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/save.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/endpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
$myoutput[]= "\n";
break;
case _("Load Page"):
unset($files);
foreach($Load as $qs) {
$files[]=array("name"=>$qs);
}
foreach(file("$publicdir/templates/$templatename/startpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/load.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/endpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
$myoutput[]= "\n";
break;
case _("Clear All Page"):
unset($files);
foreach ($Clearall as $qs) {
$files[]=array("name"=>$qs);
}
foreach(file("$publicdir/templates/$templatename/startpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/clearall.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
foreach(file("$publicdir/templates/$templatename/endpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
$myoutput[]= "\n";
break;
case _("Submit Page"):
unset($files);
$myoutput[]="";
foreach ($Submit as $qs) {
$files[]=array("name"=>$qs);
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/$qs"));
}
break;
case _("Completed Page"):
unset($files);
$myoutput[]="";
foreach ($Completed as $qs) {
$files[]=array("name"=>$qs);
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/$qs"));
}
break;
}
$myoutput[]="</html>";
function doreplacement($file) { //Produce sample page from template file
$output=array();
foreach(file($file) as $op) {
$output[]=templatereplace($op);
}
return $output;
}
if (is_array($files)) {
$match=0;
foreach ($files as $f) {
if ($editfile == $f["name"]) {
$match=1;
}
}
if ($match != 1) {
if (count($files) == 1) {
$editfile=$files[0]["name"];
} else {
$editfile="";
}
}
}
//Get list of 'otherfiles'
$dirloc=$publicdir."/templates/".$templatename;
if ($handle = opendir($dirloc)) {
while(false !== ($file = readdir($handle))) {
if (!array_search($file, $normalfiles)) {
if (!is_dir("$dirloc/$file")) {
$otherfiles[]=array("name"=>$file);
}
}
} // while
closedir($handle);
}
//****************************************************************
//** OUTPUT STARTS HERE
//****************************************************************
sendcacheheaders();
echo $htmlheader;
echo "<script type='text/javascript'>\n"
."<!--\n"
."function copyprompt(text, defvalue, copydirectory, action)\n"
."\t{\n"
."\tif (newtemplatename=window.prompt(text, defvalue))\n"
."\t\t{\n"
."\t\tvar url='templates.php?action='+action+'&newname='+newtemplatename+'©dir='+copydirectory;\n"
."\t\twindow.open(url, '_top');\n"
."\t\t}\n"
."\t}\n"
."//-->\n</script>\n";
echo "<table width='100%' border='0' bgcolor='#DDDDDD'>\n"
. "\t<tr>\n"
. "\t\t<td>\n"
. "\t\t\t<table width='100%' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n"
. "\t\t\t<tr bgcolor='#555555'>\n"
. "\t\t\t\t<td colspan='2' height='8'>\n"
. "\t\t\t\t\t$setfont<font size='1' color='white'><strong>".$file_version."</strong>\n"
. "\t\t\t\t</font></font></td>\n"
. "\t\t\t</tr>\n"
. "\t\t\t<tr bgcolor='#999999'>\n"
. "\t\t\t\t<td>\n"
. "\t\t\t\t\t<input type='image' src='$imagefiles/home.png' name='HomeButton' alt='"
. _("Default Administration Page")."' title='"
. _("Default Administration Page")."' align='left' onClick=\"window.open('$scriptname', '_top')\">\n"
. "\t\t\t\t\t<img src='$imagefiles/blank.gif' alt='' width='11' border='0' hspace='0' align='left'>\n"
. "\t\t\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left'>"
. "\t\t\t\t\t<img src='$imagefiles/blank.gif' alt='' width='60' height='10' border='0' hspace='0' align='left'>\n"
. "\t\t\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left'>"
."</td><td align='right'>\n"
."<img src='$imagefiles/blank.gif' align='right' border='0' hspace='0' width='60' height='10' alt=''>"
."<img src='$imagefiles/seperator.gif' align='right' alt='' border='0' hspace='0'>"
."<input type='image' src='$imagefiles/add.png' align='right' title='"._("Create new template")."' "
."onClick=\"javascript: copyprompt('"._("Create new template called:")."', '"._("NewTemplate")."', 'default', 'copy')\">"
."<font face='verdana' size='2' color='white'><strong>"._("Template:")."</strong> </font>"
."<select name='templatedir' onchange='javascript: window.open(\"templates.php?editfile=$editfile&screenname=$screenname&templatename=\"+this.value, \"_top\")'>\n"
.makeoptions($templates, "name", "name", $templatename)
."</select> \n"
."</td></tr></table>\n"
."<table><tr><td height='1'></td></tr></table>\n";
//TEMPLATE DETAILS
echo "\t\t\t<table width='100%' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n"
. "\t\t\t<tr bgcolor='#555555'>\n"
. "\t\t\t\t<td colspan='2' height='8'>\n"
. "\t\t\t\t\t$setfont<font size='1' color='white'><strong>"._("Template:")." <i>$templatename</i></strong>\n"
. "\t\t\t\t</font></font></td>\n"
. "\t\t\t</tr>\n"
. "\t\t\t<tr bgcolor='#999999'>\n"
. "\t\t\t\t<td>\n";
if (is_writable("$publicdir/templates/$templatename")) {
echo "\t\t\t\t\t<img src='$imagefiles/trafficgreen.png' alt='"._("This template can be modified")."' hspace='0' align='left'>\n";
} else {
echo "\t\t\t\t\t<img src='$imagefiles/trafficred.png' alt='"._("This template cannot be modified")."' hspace='0' align='left'>\n";
}
echo "\t\t\t\t\t<img src='$imagefiles/blank.gif' alt='' width='11' border='0' hspace='0' align='left'>\n"
."\t\t\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left'>\n"
."\t\t\t\t\t<img src='$imagefiles/blank.gif' alt='' width='60' height='10' border='0' hspace='0' align='left'>\n"
."\t\t\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left'>\n"
."\t\t\t\t\t<input type='image' name='EditName' src='$imagefiles/edit.png' align='left' title='"._("Rename this template")."'"
." onClick=\"javascript: copyprompt('"._("Rename this template to:")."', '$templatename', '$templatename', 'rename')\"";
if ($templatename == "default") {echo " disabled";}
echo ">";
echo "\t\t\t\t\t<img src='$imagefiles/blank.gif' alt='' width='20' height='10' border='0' hspace='0' align='left'>\n"
."\t\t\t\t\t<input type='image' name='Export' src='$imagefiles/exportsql.png' align='left' title='"._("Export Template")."'"
." onClick='javascript:window.open(\"templates.php?action=zip&editfile=$editfile&screenname=$screenname&templatename=$templatename\", \"_top\")'>\n"
."\t\t\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left'>\n"
."\t\t\t\t\t<input type='image' name='MakeCopy' src='$imagefiles/copy.png' align='left' title='"._("Make a copy of this template")."'"
." onClick=\"javascript: copyprompt('"._("Create a copy of this template called:")."', '"._("copy_of_")."$templatename', '$templatename', 'copy')\">"
."</td><td align='right'>\n"
."<img src='$imagefiles/blank.gif' align='right' alt='' border='0' hspace='0' width='60' height='10'>"
."<img src='$imagefiles/seperator.gif' align='right' alt='minimise' border='0' hspace='0'>"
."<img src='$imagefiles/blank.gif' width='23' align='right' alt='minimise' border='0' hspace='0'>"
."<font face='verdana' size='2' color='white'><strong>"._("Screen:")."</strong> </font>"
. "<select name='screenname' onchange='javascript: window.open(\"templates.php?templatename=$templatename&editfile=$editfile&screenname=\"+this.value, \"_top\")'>\n"
. makeoptions($screens, "name", "name", $screenname)
. "</select> \n"
."</td></tr></table>\n"
."<table><tr><td height='1'></td></tr></table>\n";
//FILE CONTROL DETAILS
echo "\t\t\t<table width='100%' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n"
. "\t\t\t<tr bgcolor='#555555'>\n"
. "\t\t\t\t<td colspan='2' height='8'>\n"
. "\t\t\t\t\t$setfont<font size='1' color='white'><strong>"._("File Control:")."</strong>\n"
. "\t\t\t\t</font></font></td>\n"
. "\t\t\t</tr>\n"
. "\t\t\t<tr bgcolor='#999999'>"
. "\t\t\t\t<td align='center' bgcolor='#DDDDDD'>\n";
echo "\t\t\t\t<table width='100%' border='0'>\n"
."\t\t\t\t\t<tr>\n"
."\t\t\t\t\t\t<td align='center' valign='top' width='80%'>"
. "<form name='editTemplate' method='post' action='templates.php'>\n"
. "\t\t\t<input type='hidden' name='templatename' value='$templatename' />\n"
. "\t\t\t<input type='hidden' name='screenname' value='$screenname' />\n"
. "\t\t\t<input type='hidden' name='editfile' value='$editfile' />\n"
. "\t\t\t<input type='hidden' name='action' value='savechanges' />\n"
. "\t\t\t\t<table width='100%' align='center'><tr><td>"
."$setfont<strong>"._("Standard Files:")."</strong><font size='1'><br />\n"
."<select size='12' name='editfile' onChange='javascript: window.open(\"templates.php?templatename=$templatename&screenname=$screenname&editfile=\"+this.value, \"_top\")'>\n"
.makeoptions($files, "name", "name", $editfile)
."</select><br /><br />\n"
."\t\t\t\t\t\t</font></font></td>\n"
."\t\t\t\t\t\t<td align='center' valign='top'>"
."$setfont<strong>"._("Now editing:");
if (trim($editfile)!='') {echo " <i>$editfile</i>";}
echo "</strong><font size='1'><br />\n"
."<textarea 3 name='changes' id='changes' cols='110' rows='12'>";
if ($editfile) {
echo textarea_encode(filetext($editfile));
}
echo "</textarea><br />\n";
if (is_writable("$publicdir/templates/$templatename")) {
echo "<input align='right' type='submit' value='Save Changes'";
if ($templatename == "default") {
echo " disabled";
}
echo ">";
}
echo "<br />\n"
. "</font></font></td></tr></table></form></td>\n"
."\t\t\t\t\t\t<td valign='top' align='right' width='20%'><form action='templates.php' method='post'>"
."<table width='90' align='right' border='0' cellpadding='0' cellspacing='0'>\n<tr><td align='right'>"
. "$setfont<strong>"._("Other Files:")."</strong></font><br />\n"
//. "<iframe width='100%' height='140' src=\"templates.html\"></iframe>"
. "<select size='9' name='otherfile' id='otherfile'>\n"
.makeoptions($otherfiles, "name", "name", "")
."</select>"
."</td></tr><tr><td align='right'>$setfont"
."<input type='submit' value='"._("Delete")."' onClick=\"javascript:return confirm('Are you sure you want to delete this file?')\"";
if ($templatename == "default") {
echo " disabled";
}
echo "></font>\n"
."<input type='hidden' name='editfile' value='$editfile'>\n"
."<input type='hidden' name='screenname' value='$screenname'>\n"
."<input type='hidden' name='templatename' value='$templatename'>\n"
."<input type='hidden' name='action' value='delete'>\n"
."</td>\n"
."</table></form></td></tr><tr><td></td><td align='right' valign='top'>"
."<form enctype='multipart/form-data' name='importsurvey' action='templates.php' method='post'>\n"
."<table><tr $btstyle> <td align='right' valign='top' style='border: solid 1 #000080'>\n"
."<input name=\"the_file\" type=\"file\" size=\"7\"><br />"
."<input type='submit' value='"._("Upload")."' $btstyle";
if ($templatename == "default") {
echo " disabled";
}
echo ">\n"
."<input type='hidden' name='editfile' value='$editfile'>\n"
."<input type='hidden' name='screenname' value='$screenname'>\n"
."<input type='hidden' name='templatename' value='$templatename'>\n"
."<input type='hidden' name='action' value='upload'>\n"
."</td></table></form>\n"
."\t\t\t\t\t\t</td>\n"
."\t\t\t\t\t</tr>\n"
."\t\t\t\t</table>\n"
."\t\t\t</td>\n"
."\t</tr>"
."</table>"
."</table>";
//SAMPLE ROW
echo "\t\t\t<table width='100%' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n"
. "\t\t\t<tr bgcolor='#555555'>\n"
. "\t\t\t\t<td colspan='2' height='8'>\n"
. "\t\t\t\t\t$setfont<font size='1' color='white'><strong>"._("Preview:")."</strong>\n"
. "\t\t\t\t</font></font></td>\n"
. "\t\t\t</tr>\n"
."\t<tr>\n"
."\t\t<td width='90%' align='center' bgcolor='#555555'>\n";
unlink_wc($tempdir, "template_temp_*.html"); //Delete any older template files
$time=date("ymdHis");
$fnew=fopen("$tempdir/template_temp_$time.html", "w+");
fwrite ($fnew, getHeader());
foreach($myoutput as $line) {
fwrite($fnew, $line);
}
fclose($fnew);
$langdir_template="$homeurl/lang/$currentadminlang";
echo "<br />\n"
."<iframe src='$tempurl/template_temp_$time.html' width='95%' height='400' name='sample' style='background-color: white'>Embedded Frame</iframe>\n"
."<br /> <br />"
."</td></tr></table>\n"
.getAdminFooter("$langdir_template/instructions.html#Templates", "");
function unlink_wc($dir, $pattern){
if ($dh = opendir($dir)) {
//List and put into an array all files
while (false !== ($file = readdir($dh))){
if ($file != "." && $file != "..") {
$files[] = $file;
}
}
closedir($dh);
//Split file name and extenssion
if(strpos($pattern,".")) {
$baseexp=substr($pattern,0,strpos($pattern,"."));
$typeexp=substr($pattern,strpos($pattern,".")+1,strlen($pattern));
}else{
$baseexp=$pattern;
$typeexp="";
}
//Escape all regexp Characters
$baseexp=preg_quote($baseexp);
$typeexp=preg_quote($typeexp);
// Allow ? and *
$baseexp=str_replace(array("\*","\?"), array(".*","."), $baseexp);
$typeexp=str_replace(array("\*","\?"), array(".*","."), $typeexp);
//Search for pattern match
$i=0;
foreach($files as $file) {
$filename=basename($file);
if(strpos($filename,".")) {
$base=substr($filename,0,strpos($filename,"."));
$type=substr($filename,strpos($filename,".")+1,strlen($filename));
}else{
$base=$filename;
$type="";
}
if(preg_match("/^".$baseexp."$/i",$base) && preg_match("/^".$typeexp."$/i",$type)) {
$matches[$i]=$file;
$i++;
}
}
if (isset($matches)) {
while(list($idx,$val) = each($matches)){
if (substr($dir,-1) == "/"){
unlink($dir.$val);
}else{
unlink($dir."/".$val);
}
}
}
}
}
function getListOfFiles($wh){
//Returns an array containing all files in a directory
if ($handle = opendir($wh)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !is_dir($file)) {
if(!isset($files) || !$files) $files="$file";
else $files="$file\n$files";
}
}
closedir($handle);
}
$arr=explode("\n",$files);
return $arr;
}
function textarea_encode($html_code)
{
$from = array('<', '>');
$to = array('<', '>');
$html_code = str_replace($from, $to, $html_code);
return $html_code;
}
?>