-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
manage_site_files.php
183 lines (158 loc) · 5.7 KB
/
manage_site_files.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
<?php
// Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
//
// 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 module provides for editing site-specific text files and
// for uploading site-specific image files.
// Disable magic quotes and fake register globals.
$sanitize_all_escapes = true;
$fake_register_globals = false;
require_once('../globals.php');
require_once($GLOBALS['srcdir'].'/acl.inc');
require_once($GLOBALS['srcdir'].'/htmlspecialchars.inc.php');
/* for formData() */
require_once($GLOBALS['srcdir'].'/formdata.inc.php');
if (!acl_check('admin', 'super')) die(htmlspecialchars(xl('Not authorized')));
// Prepare array of names of editable files, relative to the site directory.
$my_files = array(
'clickoptions.txt',
'config.php',
'faxcover.txt',
'faxtitle.eps',
'referral_template.html',
'statement.inc.php',
'letter_templates/custom_pdf.php',
);
// Append LBF plugin filenames to the array.
$lres = sqlStatement('SELECT * FROM list_options ' .
"WHERE list_id = 'lbfnames' ORDER BY seq, title");
while ($lrow = sqlFetchArray($lres)) {
$option_id = $lrow['option_id']; // should start with LBF
$title = $lrow['title'];
$my_files[] = "LBF/$option_id.plugin.php";
}
$form_filename = formData('form_filename');
// Sanity check to prevent evildoing.
if (!in_array($form_filename, $my_files)) $form_filename = '';
$filepath = "$OE_SITE_DIR/$form_filename";
$imagedir = "$OE_SITE_DIR/images";
if (!empty($_POST['bn_save'])) {
if ($form_filename) {
// Textareas, at least in Firefox, return a \r\n at the end of each line
// even though only \n was originally there. For consistency with
// normal OpenEMR usage we translate those back.
file_put_contents($filepath, str_replace("\r\n", "\n",
$_POST['form_filedata']));
$form_filename = '';
}
// Handle uploads.
if (is_uploaded_file($_FILES['form_image']['tmp_name']) && $_FILES['form_image']['size']) {
$form_dest_filename = $_POST['form_dest_filename'];
if ($form_dest_filename == '') {
$form_dest_filename = $_FILES['form_image']['name'];
}
$form_dest_filename = basename($form_dest_filename);
if ($form_dest_filename == '') {
die(htmlspecialchars(xl('Cannot find a destination filename')));
}
$imagepath = "$imagedir/$form_dest_filename";
// If the site's image directory does not yet exist, create it.
if (!is_dir($imagedir)) {
mkdir($imagedir);
}
if (is_file($imagepath)) unlink($imagepath);
$tmp_name = $_FILES['form_image']['tmp_name'];
if (!move_uploaded_file($_FILES['form_image']['tmp_name'], $imagepath)) {
die(htmlspecialchars(xl('Unable to create') . " '$imagepath'"));
}
}
}
?>
<html>
<head>
<title><?php echo xlt('File management'); ?></title>
<link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
<style type="text/css">
.dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
.detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
</style>
<script language="JavaScript">
// This is invoked when a filename selection changes in the drop-list.
// In this case anything else entered into the form is discarded.
function msfFileChanged() {
top.restoreSession();
document.forms[0].submit();
}
</script>
</head>
<body class="body_top">
<form method='post' action='manage_site_files.php' enctype='multipart/form-data'
onsubmit='return top.restoreSession()'>
<center>
<p>
<table border='1' width='95%'>
<tr bgcolor='#dddddd' class='dehead'>
<td colspan='2' align='center'><?php echo htmlspecialchars(xl('Edit File in') . " $OE_SITE_DIR"); ?></td>
</tr>
<tr>
<td valign='top' class='detail' nowrap>
<select name='form_filename' onchange='msfFileChanged()'>
<option value=''></option>
<?php
foreach ($my_files as $filename) {
echo " <option value='" . htmlspecialchars($filename, ENT_QUOTES) . "'";
if ($filename == $form_filename) echo " selected";
echo ">" . htmlspecialchars($filename) . "</option>\n";
}
?>
</select>
<br />
<textarea name='form_filedata' rows='30' style='width:100%'><?php
if ($form_filename) {
echo htmlspecialchars(@file_get_contents($filepath));
}
?></textarea>
</td>
</tr>
<tr bgcolor='#dddddd' class='dehead'>
<td colspan='2' align='center'><?php echo htmlspecialchars(xl('Upload Image to') . " $imagedir"); ?></td>
</tr>
<tr>
<td valign='top' class='detail' nowrap>
<?php echo htmlspecialchars(xl('Source File')); ?>:
<input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
<input type="file" name="form_image" size="40" />
<?php echo htmlspecialchars(xl('Destination Filename')) ?>:
<select name='form_dest_filename'>
<option value=''>(<?php echo htmlspecialchars(xl('Use source filename')) ?>)</option>
<?php
// Generate an <option> for each file already in the images directory.
$dh = opendir($imagedir);
if (!$dh) die(htmlspecialchars(xl('Cannot read directory') . " '$imagedir'"));
$imagesslist = array();
while (false !== ($sfname = readdir($dh))) {
if (substr($sfname, 0, 1) == '.') continue;
if ($sfname == 'CVS' ) continue;
$imageslist[$sfname] = $sfname;
}
closedir($dh);
ksort($imageslist);
foreach ($imageslist as $sfname) {
echo " <option value='" . htmlspecialchars($sfname, ENT_QUOTES) . "'";
echo ">" . htmlspecialchars($sfname) . "</option>\n";
}
?>
</select>
</td>
</tr>
</table>
<p>
<input type='submit' name='bn_save' value='<?php echo htmlspecialchars(xl('Save')) ?>' />
</p>
</center>
</form>
</body>
</html>