Project

General

Profile

Download (6.62 KB) Statistics
| Branch: | Tag: | Revision:
1 447611c4 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 a7f908db Scott Ullrich
/*
4 0d6a185a Scott Ullrich
	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 a7f908db Scott Ullrich
*/
29
30 fdb38c10 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
31 859329c8 Scott Ullrich
require("guiconfig.inc");
32
33 0d6a185a Scott Ullrich
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 bd125eb2 Scott Ullrich
				$data = file_get_contents(urldecode($_REQUEST['file']));
44 0d6a185a Scott Ullrich
				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 5f05c1e8 Scott Ullrich
				if($_REQUEST['file'] == "config.xml")
57
					if(file_exists("/tmp/config.cache"))
58
						unlink("/tmp/config.cache");
59 0d6a185a Scott Ullrich
				if($ret === false) {
60
					echo "|Failed to write file.|";
61
				} elseif($ret <> strlen($_REQUEST['data'])) {
62
					echo "|Error while writing file.|";
63
				} else {
64
					echo "|File successfully saved.|";
65
				}
66
			}
67
			exit;
68 5124d619 Scott Ullrich
	}
69 0d6a185a Scott Ullrich
	exit;
70 5124d619 Scott Ullrich
}
71
72 0d6a185a Scott Ullrich
require("head.inc");
73
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
74
outputJavaScriptFileInline("filebrowser/browser.js");
75 5b237745 Scott Ullrich
76
?>
77
78 0d6a185a Scott Ullrich
<body link="#000000" vlink="#000000" alink="#000000">
79
<?php include("fbegin.inc"); ?>
80 5b237745 Scott Ullrich
81 0d6a185a Scott Ullrich
<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 5b237745 Scott Ullrich
95 0d6a185a Scott Ullrich
	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 ccce75df Scott Ullrich
		new Effect.Appear("fileContent");
122 0d6a185a Scott Ullrich
	}
123 5b237745 Scott Ullrich
124 0d6a185a Scott Ullrich
	function saveFile(file) {
125
		$("fileStatus").innerHTML = "Saving file ...";
126
		Effect.Appear("fileStatusBox", { duration: 0.5 });
127 df61b7b4 mcrane
		
128
		var fileContent = escape($("fileContent").value);
129
		fileContent = fileContent.replace(/\+/g,"%2B");
130
		
131 0d6a185a Scott Ullrich
		new Ajax.Request(
132
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
133
				method:     "post",
134
				postBody:   "action=save&file=" + $("fbTarget").value +
135 df61b7b4 mcrane
							"&data=" + fileContent,
136 0d6a185a Scott Ullrich
				onComplete: function(req) {
137
					var values = req.responseText.split("|");
138
					$("fileStatus").innerHTML = values[1];
139
				}
140
			}
141
		);
142
	}
143
</script>
144 5b237745 Scott Ullrich
145 0d6a185a Scott Ullrich
<!-- file status box -->
146
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
147
	<div class="vexpl" style="padding-left:15px;">
148
		<strong id="fileStatus"></strong>
149
	</div>
150
</div>
151 48581bb7 Scott Ullrich
152 0d6a185a Scott Ullrich
<br />
153
154
<table width="100%" border="0" cellpadding="0" cellspacing="0">
155
	<tr>
156
		<td class="tabcont" align="center">
157
158
<!-- controls -->
159
<table width="100%" cellpadding="9" cellspacing="9">
160
	<tr>
161
		<td align="center" class="list">
162
			Save / Load from path:
163
			<input type="text"   class="formfld file" id="fbTarget"         size="45" />
164
			<input type="button" class="formbtn"      onclick="loadFile();" value="<?=gettext('Load');?>" />
165
			<input type="button" class="formbtn"      id="fbOpen"           value="<?=gettext('Browse');?>" />
166
			<input type="button" class="formbtn"      onclick="saveFile();" value="<?=gettext('Save');?>" />
167
			<br />
168 fae0b511 Scott Ullrich
			<?php
169
			/*
170
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
171
			*/
172
			?>
173 0d6a185a Scott Ullrich
		</td>
174
	</tr>
175
</table>
176 2e8eada0 Scott Ullrich
177 0d6a185a Scott Ullrich
<!-- filebrowser -->
178
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
179
180
<!-- file viewer/editor -->
181
<table width="100%">
182
	<tr>
183
		<td valign="top" class="label">
184
			<div style="background:#eeeeee;" id="fileOutput">
185
				<textarea id="fileContent" name="fileContent" style="width:100%;" rows="30" wrap="off"></textarea>
186
			</div>
187
		</td>
188
	</tr>
189
</table>
190 2e8eada0 Scott Ullrich
191 0d6a185a Scott Ullrich
		</td>
192
	</tr>
193 5124d619 Scott Ullrich
</table>
194
195 0d6a185a Scott Ullrich
<script type="text/javascript" src="/code-syntax-highlighter/shCore.js"></script>
196
<script type="text/javascript" src="/code-syntax-highlighter/shBrushCss.js"></script>
197
<script type="text/javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
198
<script type="text/javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
199
<script type="text/javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
200
<script type="text/javascript">
201
	Event.observe(
202
		window, "load",
203
		function() {
204
			$("fbTarget").focus();
205
206
			NiftyCheck();
207
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
208
		}
209
	);
210
211
	<?php if($_GET['action'] == "load"): ?>
212
		Event.observe(
213
			window, "load",
214
			function() {
215
				$("fbTarget").value = "<?=$_GET['path'];?>";
216
				loadFile();
217
			}
218
		);
219
	<?php endif; ?>
220
</script>
221 ab541dbb Scott Ullrich
222 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
223 5b237745 Scott Ullrich
</body>
224
</html>