Project

General

Profile

Download (6.62 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(urldecode($_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($_REQUEST['file'] == "config.xml")
57
					if(file_exists("/tmp/config.cache"))
58
						unlink("/tmp/config.cache");
59
				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
	}
69
	exit;
70
}
71

    
72
require("head.inc");
73
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
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
		var fileContent = escape($("fileContent").value);
129
		fileContent = fileContent.replace(/\+/g,"%2B");
130
		
131
		new Ajax.Request(
132
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
133
				method:     "post",
134
				postBody:   "action=save&file=" + $("fbTarget").value +
135
							"&data=" + fileContent,
136
				onComplete: function(req) {
137
					var values = req.responseText.split("|");
138
					$("fileStatus").innerHTML = values[1];
139
				}
140
			}
141
		);
142
	}
143
</script>
144

    
145
<!-- 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

    
152
<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
			<?php
169
			/*
170
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
171
			*/
172
			?>
173
		</td>
174
	</tr>
175
</table>
176

    
177
<!-- 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

    
191
		</td>
192
	</tr>
193
</table>
194

    
195
<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

    
222
<?php include("fend.inc"); ?>
223
</body>
224
</html>
(38-38/217)