Project

General

Profile

Download (6.53 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
		new Ajax.Request(
129
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
130
				method:     "post",
131
				postBody:   "action=save&file=" + $("fbTarget").value +
132
							"&data=" + $("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
			<?php
166
			/*
167
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
168
			*/
169
			?>
170
		</td>
171
	</tr>
172
</table>
173

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

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

    
188
		</td>
189
	</tr>
190
</table>
191

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

    
203
			NiftyCheck();
204
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
205
		}
206
	);
207

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

    
219
<?php include("fend.inc"); ?>
220
</body>
221
</html>
(32-32/207)