2 // Copyright (C) 2010-2016 Rod Roark <rod@sunsetsystems.com>
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');
20 if (!acl_check('admin', 'super')) die(htmlspecialchars(xl('Not authorized')));
22 // Prepare array of names of editable files, relative to the site directory.
27 'referral_template.html',
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' AND activity = 1 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 = strip_escape_custom($_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";
46 $educationdir = "$OE_SITE_DIR/documents/education";
48 if (!empty($_POST['bn_save'])) {
50 // Textareas, at least in Firefox, return a \r\n at the end of each line
51 // even though only \n was originally there. For consistency with
52 // normal OpenEMR usage we translate those back.
53 file_put_contents($filepath, str_replace("\r\n", "\n",
54 $_POST['form_filedata']));
58 // Handle image uploads.
59 if (is_uploaded_file($_FILES['form_image']['tmp_name']) && $_FILES['form_image']['size']) {
60 $form_dest_filename = $_POST['form_dest_filename'];
61 if ($form_dest_filename == '') {
62 $form_dest_filename = $_FILES['form_image']['name'];
64 $form_dest_filename = basename($form_dest_filename);
65 if ($form_dest_filename == '') {
66 die(htmlspecialchars(xl('Cannot find a destination filename')));
68 $imagepath = "$imagedir/$form_dest_filename";
69 // If the site's image directory does not yet exist, create it.
70 if (!is_dir($imagedir)) {
73 if (is_file($imagepath)) unlink($imagepath);
74 $tmp_name = $_FILES['form_image']['tmp_name'];
75 if (!move_uploaded_file($_FILES['form_image']['tmp_name'], $imagepath)) {
76 die(htmlspecialchars(xl('Unable to create') . " '$imagepath'"));
80 // Handle PDF uploads for patient education.
81 if (is_uploaded_file($_FILES['form_education']['tmp_name']) && $_FILES['form_education']['size']) {
82 $form_dest_filename = $_FILES['form_education']['name'];
83 $form_dest_filename = strtolower(basename($form_dest_filename));
84 if (substr($form_dest_filename, -4) != '.pdf') {
85 die(xlt('Filename must end with ".pdf"'));
87 $educationpath = "$educationdir/$form_dest_filename";
88 // If the site's education directory does not yet exist, create it.
89 if (!is_dir($educationdir)) {
92 if (is_file($educationpath)) unlink($educationpath);
93 $tmp_name = $_FILES['form_education']['tmp_name'];
94 if (!move_uploaded_file($tmp_name, $educationpath)) {
95 die(text(xl('Unable to create') . " '$educationpath'"));
102 * Thumbnails generator
103 * generating thumbnail image to all images files from documents table
106 if(isset($_POST['generate_thumbnails'])) {
108 $thumb_generator = new ThumbnailGenerator();
109 $results = $thumb_generator->generate_all();
111 $thumbnail_msg = "<p style='color: green'>" . xlt('Generated thumbnail(s)') . " : " . text($results['sum_success']) . "</p>";
112 $thumbnail_msg .= "<p style='color: red'>" . xlt('Failed to generate') . " : " . text($results['sum_failed']) . "</p>";
113 foreach($results['failed'] as $key => $file){
115 $thumbnail_msg .= "<p style='color: red; font-size: 11px'> " .text($num) . ". " . text($file) . "</p>";
119 $count_not_generated = ThumbnailGenerator
::count_not_generated();
121 $thumbnail_msg = "<p>" . xlt('Files with empty thumbnail') . ": " . text($count_not_generated) . " </p>";
131 <title
><?php
echo xlt('File management'); ?
></title
>
132 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
134 <style type
="text/css">
135 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
136 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
140 border
: 2px solid dimgrey
;
142 #generate_thumb table{
146 #generate_thumb table td{
147 border
-right
: 1px solid dimgrey
;
152 <script language
="JavaScript">
153 // This is invoked when a filename selection changes in the drop-list.
154 // In this case anything else entered into the form is discarded.
155 function msfFileChanged() {
156 top
.restoreSession();
157 document
.forms
[0].submit();
163 <body
class="body_top">
164 <form method
='post' action
='manage_site_files.php' enctype
='multipart/form-data'
165 onsubmit
='return top.restoreSession()'>
170 <table border
='1' width
='95%'>
172 <tr bgcolor
='#dddddd' class='dehead'>
173 <td colspan
='2' align
='center'><?php
echo htmlspecialchars(xl('Edit File in') . " $OE_SITE_DIR"); ?
></td
>
177 <td valign
='top' class='detail' nowrap
>
178 <select name
='form_filename' onchange
='msfFileChanged()'>
179 <option value
=''></option
>
181 foreach ($my_files as $filename) {
182 echo " <option value='" . htmlspecialchars($filename, ENT_QUOTES
) . "'";
183 if ($filename == $form_filename) echo " selected";
184 echo ">" . htmlspecialchars($filename) . "</option>\n";
189 <textarea name
='form_filedata' rows
='25' style
='width:100%'><?php
190 if ($form_filename) {
191 echo htmlspecialchars(@file_get_contents
($filepath));
197 <tr bgcolor
='#dddddd' class='dehead'>
198 <td colspan
='2' align
='center'><?php
echo htmlspecialchars(xl('Upload Image to') . " $imagedir"); ?
></td
>
202 <td valign
='top' class='detail' nowrap
>
203 <?php
echo htmlspecialchars(xl('Source File')); ?
>:
204 <input type
="hidden" name
="MAX_FILE_SIZE" value
="12000000" />
205 <input type
="file" name
="form_image" size
="40" /> 
;
206 <?php
echo htmlspecialchars(xl('Destination Filename')) ?
>:
207 <select name
='form_dest_filename'>
208 <option value
=''>(<?php
echo htmlspecialchars(xl('Use source filename')) ?
>)</option
>
210 // Generate an <option> for each file already in the images directory.
211 $dh = opendir($imagedir);
212 if (!$dh) die(htmlspecialchars(xl('Cannot read directory') . " '$imagedir'"));
213 $imagesslist = array();
214 while (false !== ($sfname = readdir($dh))) {
215 if (substr($sfname, 0, 1) == '.') continue;
216 if ($sfname == 'CVS' ) continue;
217 $imageslist[$sfname] = $sfname;
221 foreach ($imageslist as $sfname) {
222 echo " <option value='" . htmlspecialchars($sfname, ENT_QUOTES
) . "'";
223 echo ">" . htmlspecialchars($sfname) . "</option>\n";
230 <tr bgcolor
='#dddddd' class='dehead'>
231 <td colspan
='2' align
='center'><?php
echo text(xl('Upload Patient Education PDF to') . " $educationdir"); ?
></td
>
234 <td valign
='top' class='detail' nowrap
>
235 <?php
echo xlt('Source File'); ?
>:
236 <input type
="file" name
="form_education" size
="40" /> 
;
237 <?php
echo xlt('Name must be like codetype_code_language.pdf, for example icd9_274.11_en.pdf'); ?
>
244 <input type
='submit' name
='bn_save' value
='<?php echo htmlspecialchars(xl('Save
')) ?>' />
251 <div id
="generate_thumb">
252 <table style
="width: 100%">
254 <td
class="thumb_title" style
="width: 33%">
255 <b
><?php
echo xlt('Generate Thumbnails')?
></b
>
257 <td
class="thumb_msg" style
="width: 50%">
258 <span
><?php
echo $thumbnail_msg ?
></span
>
260 <td
class="thumb_form" style
="width:17%;border-right:none">
261 <form method
='post' action
='manage_site_files.php#generate_thumb'>
262 <input style
="margin-top: 10px" type
="submit" name
="generate_thumbnails" value
="<?php echo xla('Generate') ?>">