Project

General

Profile

Download (6.59 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	edit.php
5
	Copyright (C) 2004, 2005 Scott Ullrich
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10

    
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13

    
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
31
require("guiconfig.inc");
32

    
33
if($_REQUEST['action']) {
34
	switch($_REQUEST['action']) {
35
		case 'load':
36
			if(strlen($_REQUEST['file']) < 1) {
37
				echo "|5|No file name specified.|";
38
			} elseif(is_dir($_REQUEST['file'])) {
39
				echo "|4|Loading a directory is not supported.|";
40
			} elseif(! is_file($_REQUEST['file'])) {
41
				echo "|3|File does not exist or is not a regular file.|";
42
			} else {
43
				$data = file_get_contents($_REQUEST['file']);
44
				if($data === false) {
45
					echo "|1|Failed to read file.|";
46
				} else {
47
					echo "|0|{$_REQUEST['file']}|{$data}|";	
48
				}
49
			}
50
			exit;
51
		case 'save':
52
			if(strlen($_REQUEST['file']) < 1) {
53
				echo "|No file name specified.|";
54
			} else {
55
				$ret = file_put_contents($_REQUEST['file'], $_REQUEST['data']);
56
				if($ret === false) {
57
					echo "|Failed to write file.|";
58
				} elseif($ret <> strlen($_REQUEST['data'])) {
59
					echo "|Error while writing file.|";
60
				} else {
61
					echo "|File successfully saved.|";
62
				}
63
			}
64
			exit;
65
	}
66
	exit;
67
}
68

    
69
require("head.inc");
70
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
71
outputJavaScriptFileInline("javascript/scriptaculous/prototype.js");
72
outputJavaScriptFileInline("javascript/scriptaculous/scriptaculous.js");
73
outputJavaScriptFileInline("javascript/scriptaculous/effects.js");
74
outputJavaScriptFileInline("filebrowser/browser.js");
75

    
76
?>
77

    
78
<body link="#000000" vlink="#000000" alink="#000000">
79
<?php include("fbegin.inc"); ?>
80

    
81
<script type="text/javascript">	
82
	function loadFile() {
83
		$("fileStatus").innerHTML = "Loading file ...";
84
		Effect.Appear("fileStatusBox", { duration: 0.5 });
85

    
86
		new Ajax.Request(
87
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
88
				method:     "post",
89
				postBody:   "action=load&file=" + $("fbTarget").value,
90
				onComplete: loadComplete
91
			}
92
		);
93
	}
94

    
95
	function loadComplete(req) {
96
		Element.show("fileContent")
97
		var values = req.responseText.split("|");
98
		values.shift(); values.pop();
99

    
100
		if(values.shift() == "0") {
101
			var file = values.shift();
102
			$("fileStatus").innerHTML = "File successfully loaded.";
103
			$("fileContent").value    = values.join("|");
104

    
105
			var lang = "none";
106
				 if(file.indexOf(".php") > 0) lang = "php";
107
			else if(file.indexOf(".inc") > 0) lang = "php";
108
			else if(file.indexOf(".xml") > 0) lang = "xml";
109
			else if(file.indexOf(".js" ) > 0) lang = "js";
110
			else if(file.indexOf(".css") > 0) lang = "css";
111

    
112
			if($("highlight").checked && lang != "none") {
113
				$("fileContent").className = lang + ":showcolumns";
114
				dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
115
			}
116
		}
117
		else {
118
			$("fileStatus").innerHTML = values[0];
119
			$("fileContent").value = "";
120
		}
121
		new Effect.Appear("fileContent");
122
	}
123

    
124
	function saveFile(file) {
125
		$("fileStatus").innerHTML = "Saving file ...";
126
		Effect.Appear("fileStatusBox", { duration: 0.5 });
127

    
128
		new Ajax.Request(
129
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
130
				method:     "post",
131
				postBody:   "action=save&file=" + $("fbTarget").value +
132
							"&data=" + escape($("fileContent").value),
133
				onComplete: function(req) {
134
					var values = req.responseText.split("|");
135
					$("fileStatus").innerHTML = values[1];
136
				}
137
			}
138
		);
139
	}
140
</script>
141

    
142
<!-- file status box -->
143
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
144
	<div class="vexpl" style="padding-left:15px;">
145
		<strong id="fileStatus"></strong>
146
	</div>
147
</div>
148

    
149
<br />
150

    
151
<table width="100%" border="0" cellpadding="0" cellspacing="0">
152
	<tr>
153
		<td class="tabcont" align="center">
154

    
155
<!-- controls -->
156
<table width="100%" cellpadding="9" cellspacing="9">
157
	<tr>
158
		<td align="center" class="list">
159
			Save / Load from path:
160
			<input type="text"   class="formfld file" id="fbTarget"         size="45" />
161
			<input type="button" class="formbtn"      onclick="loadFile();" value="<?=gettext('Load');?>" />
162
			<input type="button" class="formbtn"      id="fbOpen"           value="<?=gettext('Browse');?>" />
163
			<input type="button" class="formbtn"      onclick="saveFile();" value="<?=gettext('Save');?>" />
164
			<br />
165
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");?>
166
		</td>
167
	</tr>
168
</table>
169

    
170
<!-- filebrowser -->
171
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
172

    
173
<!-- file viewer/editor -->
174
<table width="100%">
175
	<tr>
176
		<td valign="top" class="label">
177
			<div style="background:#eeeeee;" id="fileOutput">
178
				<textarea id="fileContent" name="fileContent" style="width:100%;" rows="30" wrap="off"></textarea>
179
			</div>
180
		</td>
181
	</tr>
182
</table>
183

    
184
		</td>
185
	</tr>
186
</table>
187

    
188
<script type="text/javascript" src="/code-syntax-highlighter/shCore.js"></script>
189
<script type="text/javascript" src="/code-syntax-highlighter/shBrushCss.js"></script>
190
<script type="text/javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
191
<script type="text/javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
192
<script type="text/javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
193
<script type="text/javascript">
194
	Event.observe(
195
		window, "load",
196
		function() {
197
			$("fbTarget").focus();
198

    
199
			NiftyCheck();
200
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
201
		}
202
	);
203

    
204
	<?php if($_GET['action'] == "load"): ?>
205
		Event.observe(
206
			window, "load",
207
			function() {
208
				$("fbTarget").value = "<?=$_GET['path'];?>";
209
				loadFile();
210
			}
211
		);
212
	<?php endif; ?>
213
</script>
214

    
215
<?php include("fend.inc"); ?>
216
</body>
217
</html>
(34-34/210)