The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / super / manage_site_files.php
blob7a5975556a71ff817d1533e039e3c91ca7c20b8e
1 <?php
2 // Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This module provides for editing site-specific text files and
10 // for uploading site-specific image files.
12 // Disable magic quotes and fake register globals.
13 $sanitize_all_escapes = true;
14 $fake_register_globals = false;
16 require_once("../globals.php");
17 require_once("$srcdir/acl.inc");
19 if (!acl_check('admin', 'super')) die(htmlspecialchars(xl('Not authorized')));
21 // Prepare array of names of editable files, relative to the site directory.
22 $my_files = array(
23 "clickoptions.txt",
24 "config.php",
25 "faxcover.txt",
26 "faxtitle.eps",
27 "referral_template.html",
28 "statement.inc.php",
29 "letter_templates/custom_pdf.php",
31 // Append LBF plugin filenames to the array.
32 $lres = sqlStatement("SELECT * FROM list_options " .
33 "WHERE list_id = 'lbfnames' ORDER BY seq, title");
34 while ($lrow = sqlFetchArray($lres)) {
35 $option_id = $lrow['option_id']; // should start with LBF
36 $title = $lrow['title'];
37 $my_files[] = "LBF/$option_id.plugin.php";
40 $form_filename = $_REQUEST['form_filename'];
41 // Sanity check to prevent evildoing.
42 if (!in_array($form_filename, $my_files)) $form_filename = '';
43 $filepath = "$OE_SITE_DIR/$form_filename";
45 $imagedir = "$OE_SITE_DIR/images";
47 if (!empty($_POST['bn_save'])) {
48 if ($form_filename) {
49 // Textareas, at least in Firefox, return a \r\n at the end of each line
50 // even though only \n was originally there. For consistency with
51 // normal OpenEMR usage we translate those back.
52 file_put_contents($filepath, str_replace("\r\n", "\n",
53 $_POST['form_filedata']));
54 $form_filename = '';
57 // Handle uploads.
58 if (is_uploaded_file($_FILES['form_image']['tmp_name']) && $_FILES['form_image']['size']) {
59 $form_dest_filename = $_POST['form_dest_filename'];
60 if ($form_dest_filename == '') {
61 $form_dest_filename = $_FILES['form_image']['name'];
63 $form_dest_filename = basename($form_dest_filename);
64 if ($form_dest_filename == '') {
65 die(htmlspecialchars(xl('Cannot find a destination filename')));
67 $imagepath = "$imagedir/$form_dest_filename";
68 // If the site's image directory does not yet exist, create it.
69 if (!is_dir($imagedir)) {
70 mkdir($imagedir);
72 if (is_file($imagepath)) unlink($imagepath);
73 $tmp_name = $_FILES['form_image']['tmp_name'];
74 if (!move_uploaded_file($_FILES['form_image']['tmp_name'], $imagepath)) {
75 die(htmlspecialchars(xl('Unable to create') . " '$imagepath'"));
80 <html>
82 <head>
83 <title><?php echo htmlspecialchars(xl('File management')); ?></title>
84 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
86 <style type="text/css">
87 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
88 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
89 </style>
91 <script language="JavaScript">
92 // This is invoked when a filename selection changes in the drop-list.
93 // In this case anything else entered into the form is discarded.
94 function msfFileChanged() {
95 top.restoreSession();
96 document.forms[0].submit();
98 </script>
100 </head>
102 <body class="body_top">
103 <form method='post' action='manage_site_files.php' enctype='multipart/form-data'
104 onsubmit='return top.restoreSession()'>
106 <center>
109 <table border='1' width='95%'>
111 <tr bgcolor='#dddddd' class='dehead'>
112 <td colspan='2' align='center'><?php echo htmlspecialchars(xl('Edit File in') . " $OE_SITE_DIR"); ?></td>
113 </tr>
115 <tr>
116 <td valign='top' class='detail' nowrap>
117 <select name='form_filename' onchange='msfFileChanged()'>
118 <option value=''></option>
119 <?php
120 foreach ($my_files as $filename) {
121 echo " <option value='" . htmlspecialchars($filename, ENT_QUOTES) . "'";
122 if ($filename == $form_filename) echo " selected";
123 echo ">" . htmlspecialchars($filename) . "</option>\n";
126 </select>
127 <br />
128 <textarea name='form_filedata' rows='30' style='width:100%'><?php
129 if ($form_filename) {
130 echo htmlspecialchars(@file_get_contents($filepath));
132 ?></textarea>
133 </td>
134 </tr>
136 <tr bgcolor='#dddddd' class='dehead'>
137 <td colspan='2' align='center'><?php echo htmlspecialchars(xl('Upload Image to') . " $imagedir"); ?></td>
138 </tr>
140 <tr>
141 <td valign='top' class='detail' nowrap>
142 <?php echo htmlspecialchars(xl('Source File')); ?>:
143 <input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
144 <input type="file" name="form_image" size="40" />&nbsp;
145 <?php echo htmlspecialchars(xl('Destination Filename')) ?>:
146 <select name='form_dest_filename'>
147 <option value=''>(<?php echo htmlspecialchars(xl('Use source filename')) ?>)</option>
148 <?php
149 // Generate an <option> for each file already in the images directory.
150 $dh = opendir($imagedir);
151 if (!$dh) die(htmlspecialchars(xl('Cannot read directory') . " '$imagedir'"));
152 $imagesslist = array();
153 while (false !== ($sfname = readdir($dh))) {
154 if (substr($sfname, 0, 1) == '.') continue;
155 if ($sfname == 'CVS' ) continue;
156 $imageslist[$sfname] = $sfname;
158 closedir($dh);
159 ksort($imageslist);
160 foreach ($imageslist as $sfname) {
161 echo " <option value='" . htmlspecialchars($sfname, ENT_QUOTES) . "'";
162 echo ">" . htmlspecialchars($sfname) . "</option>\n";
165 </select>
166 </td>
167 </tr>
169 </table>
172 <input type='submit' name='bn_save' value='<?php echo htmlspecialchars(xl('Save')) ?>' />
173 </p>
175 </center>
177 </form>
178 </body>
179 </html>