Skip to content

Commit

Permalink
Added administrative page for editing and uploading site-specific files.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsetsystems committed Nov 2, 2010
1 parent b2f2276 commit 60a7087
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 1 deletion.
2 changes: 1 addition & 1 deletion interface/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function undoMagicQuotes($array, $topLevel=true) {
}
$login_filler_line = ' bgcolor="#f7f0d5" ';
$login_body_line = ' background="'.$rootdir.'/pic/aquabg.gif" ';
$logocode="<img src='$rootdir/pic/logo_sky.gif'>";
$logocode = "<img src='$web_root/sites/" . $_SESSION['site_id'] . "/images/login_logo.gif'>";
$linepic = "$rootdir/pic/repeat_vline9.gif";
$table_bg = ' bgcolor="#cccccc" ';
$GLOBALS['style']['BGCOLOR1'] = "#cccccc";
Expand Down
2 changes: 2 additions & 0 deletions interface/main/left_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ function selpopup(selobj) {
<?php if (acl_check('admin', 'calendar') && !$GLOBALS['disable_calendar']) genMiscLink('RTop','adm','0',xl('Calendar'),'main/calendar/index.php?module=PostCalendar&type=admin&func=modifyconfig'); ?>
<?php if (acl_check('admin', 'users' )) genMiscLink('RTop','adm','0',xl('Logs'),'logview/logview.php'); ?>
<?php if ( (!$GLOBALS['disable_phpmyadmin_link']) && (acl_check('admin', 'database')) ) genMiscLink('RTop','adm','0',xl('Database'),'../phpmyadmin/index.php'); ?>
<?php if (acl_check('admin', 'super' )) genMiscLink('RTop','adm','0',xl('Files'),'super/manage_site_files.php'); ?>
<?php if (acl_check('admin', 'super' )) genMiscLink('RTop','adm','0',xl('Backup'),'main/backup.php'); ?>
<?php if (acl_check('admin', 'users' )) genMiscLink('RTop','adm','0',xl('Certificates'),'usergroup/ssl_certificates_admin.php'); ?>
</ul>
Expand Down Expand Up @@ -984,6 +985,7 @@ function selpopup(selobj) {
<?php if (acl_check('admin', 'super' )) genMiscLink('RTop','adm','0',xl('Layouts'),'super/edit_layout.php'); ?>
<?php if (acl_check('admin', 'super' )) genMiscLink('RTop','adm','0',xl('Lists'),'super/edit_list.php'); ?>
<?php if (acl_check('admin', 'acl' )) genMiscLink('RTop','adm','0',xl('ACL'),'usergroup/adminacl.php'); ?>
<?php if (acl_check('admin', 'super' )) genMiscLink('RTop','adm','0',xl('Files'),'super/manage_site_files.php'); ?>
<?php if (acl_check('admin', 'super' )) genMiscLink('RTop','adm','0',xl('Backup'),'main/backup.php'); ?>
<?php if ( ($GLOBALS['include_de_identification']) && (acl_check('admin', 'super' )) ) genMiscLink('RTop','adm','0',xl('De Identification'),'de_identification_forms/de_identification_screen1.php'); ?>
<?php if ( ($GLOBALS['include_de_identification']) && (acl_check('admin', 'super' )) ) genMiscLink('RTop','adm','0',xl('Re Identification'),'de_identification_forms/re_identification_input_screen.php'); ?>
Expand Down
180 changes: 180 additions & 0 deletions interface/super/manage_site_files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
// Copyright (C) 2010 Rod Roark <[email protected]>
//
// 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("$srcdir/acl.inc");
require_once("$srcdir/formdata.inc.php");

if (!acl_check('admin', 'super')) die(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 = strip_escape_custom($_REQUEST['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",
strip_escape_custom($_POST['form_filedata'])));
$form_filename = '';
}

// Handle uploads.
if (is_uploaded_file($_FILES['form_image']['tmp_name']) && $_FILES['form_image']['size']) {
$form_dest_filename = strip_escape_custom($_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(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(xl('Unable to create') . " '$imagepath'");
}
}
}
?>
<html>

<head>
<title><?php xl('File management','e'); ?></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 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='$filename'";
if ($filename == $form_filename) echo " selected";
echo ">$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 xl('Upload Image to') . " $imagedir"; ?></td>
</tr>

<tr>
<td valign='top' class='detail' nowrap>
<?php xl('Source File','e'); ?>:
<input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
<input type="file" name="form_image" size="40" />&nbsp;
<?php xl('Destination Filename','e') ?>:
<select name='form_dest_filename'>
<option value=''>(<?php xl('Use source filename','e') ?>)</option>
<?php
$dh = opendir($imagedir);
if (!$dh) die(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='$sfname'";
echo ">$sfname</option>\n";
}
?>
</select>
</td>
</tr>

</table>

<p>
<input type='submit' name='bn_save' value='<?php xl('Save','e') ?>' />
</p>

</center>

</form>
</body>
</html>

5 changes: 5 additions & 0 deletions interface/usergroup/usergroup_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
title="Form Layout Management"><?php xl('Layouts','e'); ?></a>&nbsp;
</td>
<td valign="middle" nowrap>
&nbsp;<a class="menu" target=Main href="../super/manage_site_files.php"
onclick="top.restoreSession()"
title="Site Files Management"><?php xl('Files','e'); ?></a>&nbsp;
</td>
<td valign="middle" nowrap>
&nbsp;<a class="menu" target=Main href="../main/backup.php"
onclick="top.restoreSession()"
title="System Backup"><?php xl('Backup','e'); ?></a>&nbsp;
Expand Down
File renamed without changes

0 comments on commit 60a7087

Please sign in to comment.