Update edih_x12file_class.php (#295)
[openemr.git] / interface / super / manage_site_files.php
blobf873a8c51e6ccf68f8b3d67ff681370b0c22f7af
1 <?php
2 // Copyright (C) 2010-2016 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($GLOBALS['srcdir'].'/acl.inc');
18 require_once($GLOBALS['srcdir'].'/htmlspecialchars.inc.php');
19 require_once($GLOBALS['srcdir'].'/classes/thumbnail/ThumbnailGenerator.php');
20 /* for formData() */
21 require_once($GLOBALS['srcdir'].'/formdata.inc.php');
23 if (!acl_check('admin', 'super')) die(htmlspecialchars(xl('Not authorized')));
25 // Prepare array of names of editable files, relative to the site directory.
26 $my_files = array(
27 'config.php',
28 'faxcover.txt',
29 'faxtitle.eps',
30 'referral_template.html',
31 'statement.inc.php',
32 'letter_templates/custom_pdf.php',
34 // Append LBF plugin filenames to the array.
35 $lres = sqlStatement('SELECT * FROM list_options ' .
36 "WHERE list_id = 'lbfnames' AND activity = 1 ORDER BY seq, title");
37 while ($lrow = sqlFetchArray($lres)) {
38 $option_id = $lrow['option_id']; // should start with LBF
39 $title = $lrow['title'];
40 $my_files[] = "LBF/$option_id.plugin.php";
43 $form_filename = strip_escape_custom($_REQUEST['form_filename']);
44 // Sanity check to prevent evildoing.
45 if (!in_array($form_filename, $my_files)) $form_filename = '';
46 $filepath = "$OE_SITE_DIR/$form_filename";
48 $imagedir = "$OE_SITE_DIR/images";
49 $educationdir = "$OE_SITE_DIR/documents/education";
51 if (!empty($_POST['bn_save'])) {
52 if ($form_filename) {
53 // Textareas, at least in Firefox, return a \r\n at the end of each line
54 // even though only \n was originally there. For consistency with
55 // normal OpenEMR usage we translate those back.
56 file_put_contents($filepath, str_replace("\r\n", "\n",
57 $_POST['form_filedata']));
58 $form_filename = '';
61 // Handle image uploads.
62 if (is_uploaded_file($_FILES['form_image']['tmp_name']) && $_FILES['form_image']['size']) {
63 $form_dest_filename = $_POST['form_dest_filename'];
64 if ($form_dest_filename == '') {
65 $form_dest_filename = $_FILES['form_image']['name'];
67 $form_dest_filename = basename($form_dest_filename);
68 if ($form_dest_filename == '') {
69 die(htmlspecialchars(xl('Cannot find a destination filename')));
71 $imagepath = "$imagedir/$form_dest_filename";
72 // If the site's image directory does not yet exist, create it.
73 if (!is_dir($imagedir)) {
74 mkdir($imagedir);
76 if (is_file($imagepath)) unlink($imagepath);
77 $tmp_name = $_FILES['form_image']['tmp_name'];
78 if (!move_uploaded_file($_FILES['form_image']['tmp_name'], $imagepath)) {
79 die(htmlspecialchars(xl('Unable to create') . " '$imagepath'"));
83 // Handle PDF uploads for patient education.
84 if (is_uploaded_file($_FILES['form_education']['tmp_name']) && $_FILES['form_education']['size']) {
85 $form_dest_filename = $_FILES['form_education']['name'];
86 $form_dest_filename = strtolower(basename($form_dest_filename));
87 if (substr($form_dest_filename, -4) != '.pdf') {
88 die(xlt('Filename must end with ".pdf"'));
90 $educationpath = "$educationdir/$form_dest_filename";
91 // If the site's education directory does not yet exist, create it.
92 if (!is_dir($educationdir)) {
93 mkdir($educationdir);
95 if (is_file($educationpath)) unlink($educationpath);
96 $tmp_name = $_FILES['form_education']['tmp_name'];
97 if (!move_uploaded_file($tmp_name, $educationpath)) {
98 die(text(xl('Unable to create') . " '$educationpath'"));
105 * Thumbnails generator
106 * generating thumbnail image to all images files from documents table
109 if(isset($_POST['generate_thumbnails'])) {
111 $thumb_generator = new ThumbnailGenerator();
112 $results = $thumb_generator->generate_all();
114 $thumbnail_msg = "<p style='color: green'>" . xlt('Generated thumbnail(s)') . " : " . text($results['sum_success']) . "</p>";
115 $thumbnail_msg .= "<p style='color: red'>" . xlt('Failed to generate') . " : " . text($results['sum_failed']) . "</p>";
116 foreach($results['failed'] as $key => $file){
117 $num = $key +1;
118 $thumbnail_msg .= "<p style='color: red; font-size: 11px'> " .text($num) . ". " . text($file) . "</p>";
120 } else {
122 $count_not_generated = ThumbnailGenerator::count_not_generated();
124 $thumbnail_msg = "<p>" . xlt('Files with empty thumbnail') . ": " . text($count_not_generated) . " </p>";
131 <html>
133 <head>
134 <title><?php echo xlt('File management'); ?></title>
135 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
137 <style type="text/css">
138 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
139 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
140 #generate_thumb{
141 width: 95%;
142 margin: 50px auto;
143 border: 2px solid dimgrey;
145 #generate_thumb table{
146 font-size: 14px;
147 text-align: center;
149 #generate_thumb table td{
150 border-right: 1px solid dimgrey;
151 padding: 0 15px;
153 </style>
155 <script language="JavaScript">
156 // This is invoked when a filename selection changes in the drop-list.
157 // In this case anything else entered into the form is discarded.
158 function msfFileChanged() {
159 top.restoreSession();
160 document.forms[0].submit();
162 </script>
164 </head>
166 <body class="body_top">
167 <form method='post' action='manage_site_files.php' enctype='multipart/form-data'
168 onsubmit='return top.restoreSession()'>
170 <center>
173 <table border='1' width='95%'>
175 <tr bgcolor='#dddddd' class='dehead'>
176 <td colspan='2' align='center'><?php echo htmlspecialchars(xl('Edit File in') . " $OE_SITE_DIR"); ?></td>
177 </tr>
179 <tr>
180 <td valign='top' class='detail' nowrap>
181 <select name='form_filename' onchange='msfFileChanged()'>
182 <option value=''></option>
183 <?php
184 foreach ($my_files as $filename) {
185 echo " <option value='" . htmlspecialchars($filename, ENT_QUOTES) . "'";
186 if ($filename == $form_filename) echo " selected";
187 echo ">" . htmlspecialchars($filename) . "</option>\n";
190 </select>
191 <br />
192 <textarea name='form_filedata' rows='25' style='width:100%'><?php
193 if ($form_filename) {
194 echo htmlspecialchars(@file_get_contents($filepath));
196 ?></textarea>
197 </td>
198 </tr>
200 <tr bgcolor='#dddddd' class='dehead'>
201 <td colspan='2' align='center'><?php echo htmlspecialchars(xl('Upload Image to') . " $imagedir"); ?></td>
202 </tr>
204 <tr>
205 <td valign='top' class='detail' nowrap>
206 <?php echo htmlspecialchars(xl('Source File')); ?>:
207 <input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
208 <input type="file" name="form_image" size="40" />&nbsp;
209 <?php echo htmlspecialchars(xl('Destination Filename')) ?>:
210 <select name='form_dest_filename'>
211 <option value=''>(<?php echo htmlspecialchars(xl('Use source filename')) ?>)</option>
212 <?php
213 // Generate an <option> for each file already in the images directory.
214 $dh = opendir($imagedir);
215 if (!$dh) die(htmlspecialchars(xl('Cannot read directory') . " '$imagedir'"));
216 $imagesslist = array();
217 while (false !== ($sfname = readdir($dh))) {
218 if (substr($sfname, 0, 1) == '.') continue;
219 if ($sfname == 'CVS' ) continue;
220 $imageslist[$sfname] = $sfname;
222 closedir($dh);
223 ksort($imageslist);
224 foreach ($imageslist as $sfname) {
225 echo " <option value='" . htmlspecialchars($sfname, ENT_QUOTES) . "'";
226 echo ">" . htmlspecialchars($sfname) . "</option>\n";
229 </select>
230 </td>
231 </tr>
233 <tr bgcolor='#dddddd' class='dehead'>
234 <td colspan='2' align='center'><?php echo text(xl('Upload Patient Education PDF to') . " $educationdir"); ?></td>
235 </tr>
236 <tr>
237 <td valign='top' class='detail' nowrap>
238 <?php echo xlt('Source File'); ?>:
239 <input type="file" name="form_education" size="40" />&nbsp;
240 <?php echo xlt('Name must be like codetype_code_language.pdf, for example icd9_274.11_en.pdf'); ?>
241 </td>
242 </tr>
244 </table>
247 <input type='submit' name='bn_save' value='<?php echo htmlspecialchars(xl('Save')) ?>' />
248 </p>
250 </center>
252 </form>
254 <div id="generate_thumb">
255 <table style="width: 100%">
256 <tr>
257 <td class="thumb_title" style="width: 33%">
258 <b><?php echo xlt('Generate Thumbnails')?></b>
259 </td>
260 <td class="thumb_msg" style="width: 50%">
261 <span><?php echo $thumbnail_msg ?></span>
262 </td>
263 <td class="thumb_form" style="width:17%;border-right:none">
264 <form method='post' action='manage_site_files.php#generate_thumb'>
265 <input style="margin-top: 10px" type="submit" name="generate_thumbnails" value="<?php echo xla('Generate') ?>">
266 </form>
267 </td>
268 </tr>
269 </table>
270 </div>
272 </body>
273 </html>