/
templates.php
647 lines (605 loc) · 26.5 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
<?php
/*
#############################################################
# >>> PHP Surveyor #
#############################################################
# > 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. #
#############################################################
*/
$file_version="PHPSurveyor Template Editor Version 0.98rc9";
require_once("config.php");
$slstyle3=$slstyle2;
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);
function newfolder($name) { //Creates a new template directory
if (mkdir("$publicdir/templates/$name")) {
return true;
} else {
return false;
}
}
function createfiles($folder) { //Places basic files into new template directory
}
//PUBLIC LANGUAGE FILE
$langdir="$publicdir/lang";
$langfilename="$langdir/$defaultlang.lang.php";
if (!is_file($langfilename)) {$langfilename="$langdir/$defaultlang.lang.php";}
require($langfilename);
//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'];
}
}
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)){
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");
$normalfiles=array("DUMMYENTRY", ".", "..");
foreach ($files as $fl) {
$normalfiles[]=$fl["name"];
}
$screens[]=array("name"=>_TP_WELCOMEPAGE);
$screens[]=array("name"=>_TP_QUESTIONPAGE);
$screens[]=array("name"=>_TP_SUBMITPAGE);
$screens[]=array("name"=>_TP_COMPLETEDPAGE);
$screens[]=array("name"=>_TP_CLEARALLPAGE);
$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", "completed.pstpl", "endpage.pstpl");
$Clearall=array("startpage.pstpl", "endpage.pstpl");
//Load this editfile
function filetext($templatefile) {
global $publicdir, $templatename;
$output="";
foreach(file("$publicdir/templates/$templatename/$templatefile") as $line) {
$output .= $line;
}
return $output;
}
function templatereplace($line)
{
global $publicurl, $templatedir, $templatename;
global $question, $questioncode, $answer;
global $screenname;
$surveyname="Template Sample";
$surveydescription="This is a sample survey description. It could be quite long.<br /><br />But this one isn't.";
$surveywelcome="Welcome to this sample survey.<br />\n You should have a great time doing this<br />";
$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 != _TP_WELCOMEPAGE) {$navigator = "<input class='submit' type='submit' value=' << prev ' name='move' />\n".$navigator;}
$help="Help me";
$totalquestions="10";
$surveyformat="Format";
$completed="Survey is completed and saved.";
$surveyurl="http://phpsurveyor.sourceforge.net/";
$surveyurldescrip="A URL Description";
$notanswered="5";
$privacy="";
$sid="1295";
$token=1234567;
if ($templatename) {$templateurl="$publicurl/templates/$templatename/";}
else {$templateurl="$publicurl/templates/default/";}
//echo $templateurl;
//$clearall = "\t\t\t\t\t<div class='clearall'><a href='{$_SERVER['PHP_SELF']}?sid=$sid&move=clearall' onClick='return confirm(\""._CONFIRMCLEAR."\")'>["._EXITCLEAR."]</a></div>\n";
$clearall = "\t\t\t\t\t<div class='clearall'><a href='{$_SERVER['PHP_SELF']}?sid=$sid&move=clearall' onClick='return confirm(\"Are you sure you want to clear?\")'>[Exit and Clear Responses]</a></div>\n";
$line=str_replace("{SURVEYNAME}", $surveyname, $line);
$line=str_replace("{SURVEYDESCRIPTION}", $surveydescription, $line);
$line=str_replace("{WELCOME}", $surveywelcome, $line);
$line=str_replace("{PERCENTCOMPLETE}", $percentcomplete, $line);
$line=str_replace("{GROUPNAME}", $groupname, $line);
$line=str_replace("{GROUPDESCRIPTION}", $groupdescription, $line);
$line=str_replace("{QUESTION}", $question, $line);
$line=str_replace("{QUESTION_CODE}", $questioncode, $line);
$line=str_replace("{ANSWER}", $answer, $line);
$line=str_replace("{THEREAREXQUESTIONS}", _THEREAREXQUESTIONS, $line);
$line=str_replace("{NUMBEROFQUESTIONS}", $totalquestions, $line);
$line=str_replace("{TOKEN}", $token, $line);
$line=str_replace("{SID}", $sid, $line);
if ($help)
{$line=str_replace("{QUESTIONHELP}", "<img src='".$publicurl."/help.gif' align='left'>".$help, $line);}
else
{$line=str_replace("{QUESTIONHELP}", $help, $line);}
$line=str_replace("{NAVIGATOR}", $navigator, $line);
//$submitbutton="<input class='submit' type='submit' value=' "._SUBMIT." ' name='move'>";
$submitbutton="<input class='submit' type='submit' value=' Submit ' name='move'>";
$line=str_replace("{SUBMITBUTTON}", $submitbutton, $line);
$line=str_replace("{COMPLETED}", $completed, $line);
if (!$surveyurldescrip) {$linkreplace="<a href='$surveyurl'>$surveyurl</a>";}
else {$linkreplace="<a href='$surveyurl'>$surveyurldescrip</a>";}
$line=str_replace("{URL}", $linkreplace, $line);
$line=str_replace("{PRIVACY}", $privacy, $line);
$line=str_replace("{PRIVACYMESSAGE}", _PRIVACY_MESSAGE, $line);
$line=str_replace("{CLEARALL}", $clearall, $line);
$line=str_replace("{TEMPLATEURL}", $templateurl, $line);
return $line;
}
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=_TP_WELCOMEPAGE;}
$addbr=false;
switch($screenname) {
case _TP_QUESTIONPAGE:
unset($files);
foreach ($Question as $qs) {
$files[]=array("name"=>$qs);
}
$myoutput[]="<html>\n";
$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 _TP_WELCOMEPAGE:
unset($files);
$myoutput[]="<html>";
foreach ($Welcome as $qs) {
$files[]=array("name"=>$qs);
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/$qs"));
}
break;
case _TP_CLEARALLPAGE:
unset($files);
foreach ($Clearall as $qs) {
$files[]=array("name"=>$qs);
}
$myoutput[]="<html>";
foreach(file("$publicdir/templates/$templatename/startpage.pstpl") as $op)
{
$myoutput[]=templatereplace($op);
}
$myoutput[]= "<table align='center' cellpadding='30'><tr><td align='center' bgcolor='white'>";
$myoutput[]= "<font face='arial' size='2'>";
$myoutput[]= "<b><font color='red'>"._ANSCLEAR."</b></font><br /><br />";
$myoutput[]= "<a href='{$_SERVER['PHP_SELF']}?sid=x'>"._RESTART."</a><br />";
$myoutput[]= "<a href='javascript: window.close()'>"._CLOSEWIN."</a>";
$myoutput[]= "</font>";
$myoutput[]= "</td></tr>";
$myoutput[]= "</table><br />";
foreach(file("$publicdir/templates/$templatename/endpage.pstpl") as $op)
{
$myoutput[]= templatereplace($op);
}
$myoutput[]= "\n";
break;
case _TP_SUBMITPAGE:
unset($files);
$myoutput[]="<html>";
foreach ($Submit as $qs) {
$files[]=array("name"=>$qs);
$myoutput = array_merge($myoutput, doreplacement("$publicdir/templates/$templatename/$qs"));
}
break;
case _TP_COMPLETEDPAGE:
unset($files);
$myoutput[]="<html>";
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
//****************************************************************
echo $htmlheader;
echo "<script type='text/javascript'>\n"
."<!--\nfunction 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'><b>".$file_version."</b>\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.gif' name='HomeButton' alt='"
. _A_HOME_BT."' title='"
. _A_HOME_BT."' border='0' align='left' hspace='0' 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"
."<input type='image' src='$imagefiles/close.gif' title='"._CLOSEWIN."' hspace='0' alt='"._CLOSEWIN."'"
." align='right' onClick='javascript: self.close()'>"
."<img src='$imagefiles/blank.gif' align='right' border='0' hspace='0' width='40' height='10'>"
."<img src='$imagefiles/seperator.gif' alt='|' align='right' alt='minimise' border='0' hspace='0'>"
."<input type='image' src='$imagefiles/add.gif' align='right' hspace='0' title='"._TP_CREATENEW."' "
."onClick=\"javascript: copyprompt('"._TP_NEWTEMPLATECALLED."', '"._TP_DEFAULTNEWTEMPLATE."', 'default', 'copy')\">"
."<font face='verdana' size='2' color='white'><b>"._SL_TEMPLATE."</b> </font>"
."<select $slstyle 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'><b>"._SL_TEMPLATE." <i>$templatename</i></b>\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.gif' alt='"._TP_CANMODIFY."' hspace='0' align='left'>\n";
} else {
echo "\t\t\t\t\t<img src='$imagefiles/trafficred.gif' alt='"._TP_CANNOTMODIFY."' 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.gif' align='left' hspace='0' "
."border='0' title='"._TP_RENAME."'"
." onClick=\"javascript: copyprompt('"._TP_RENAMETO."', '$templatename', '$templatename', 'rename')\"";
if ($templatename == "default") {echo " disabled";}
echo ">";
echo "\t\t\t\t\t<img src='$imagefiles/blank.gif' alt='-' width='40' 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='MakeCopy' src='$imagefiles/copy.gif' align='left' hspace='0' "
."border='0' title='"._TP_COPY."'"
." onClick=\"javascript: copyprompt('"._TP_COPYTO."', '"._TP_COPYOF."$templatename', '$templatename', 'copy')\">"
."</td><td align='right'>\n"
."<img src='./images/blank.gif' align='right' alt='-' border='0' hspace='0' width='60' height='10'>"
."<img src='$imagefiles/seperator.gif' alt='|' align='right' alt='minimise' border='0' hspace='0'>"
."<img src='$imagefiles/blank.gif' alt='-' width='23' align='right' alt='minimise' border='0' hspace='0'>"
."<font face='verdana' size='2' color='white'><b>"._TP_SCREEN."</b> </font>"
. "<select name='screenname' $slstyle 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'><b>"._TP_FILECONTROL."</b>\n"
. "\t\t\t\t</font></font></td>\n"
. "\t\t\t</tr>\n"
. "\t\t\t<tr bgcolor='#999999'><form 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<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='left' valign='top' width='150'>"
."$setfont<b>"._TP_STANDARDFILES."</b><font size='1'><br />\n"
."<select size='12' $slstyle2 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<b>"._TP_NOWEDITING." <i>$editfile</i></b><font size='1'><br />\n"
."<textarea $slstyle3 name='changes' cols='110' rows='12'>";
if ($editfile) {
echo filetext($editfile);
}
echo "</textarea><br />\n";
if (is_writable("$publicdir/templates/$templatename")) {
echo "<input $btstyle align='right' type='submit' value='Save Changes'";
if ($templatename == "default") {
echo " disabled";
}
echo ">";
}
echo "<br />\n"
. "</font></font></td></form>\n"
."\t\t\t\t\t\t<td valign='top' align='right'>"
. "$setfont<b>"._TP_OTHERFILES."</b><br />\n"
//. "<iframe width='100%' height='140' src=\"templates.html\"></iframe>"
. "<select size='12' $slstyle2 name='otherfile' style='width: 120'>\n"
.makeoptions($otherfiles, "name", "name", "")
."</select><br />"
."<input type='submit' value='"._TP_DELETEFILE."' $btstyle";
if ($templatename == "default") {
echo " disabled";
}
echo "><input type='submit' value='"._TP_UPLOADFILE."' $btstyle";
if ($templatename == "default") {
echo " disabled";
}
echo ">"
."\t\t\t\t\t\t</font></font></td>\n"
."\t\t\t\t\t</tr>\n"
."\t\t\t\t</table>\n"
."\t\t\t</td>\n"
."\t</tr>"
."</table>"
."<table><tr><td height='1'></td></tr><table>\n";
//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'><b>"._TP_PREVIEW."</b>\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+");
foreach($myoutput as $line) {
fwrite($fnew, $line);
}
fclose($fnew);
echo "<font face='verdana' size='2'><br />\n"
."<iframe src='$tempurl/template_temp_$time.html' width='95%' height='400' name='sample'></iframe>\n"
."<br /> <br />"
."</td></tr></table>\n"
.htmlfooter("", "");
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;
}
?>