Skip to content

Commit

Permalink
Fixes issue LibreHealthIO#1213
Browse files Browse the repository at this point in the history
  • Loading branch information
realJema committed Mar 17, 2020
1 parent 186e2ed commit df337dd
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 55 deletions.
130 changes: 85 additions & 45 deletions interface/patient_file/letter.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,26 @@
$cpstring = $_POST['form_body'];

// attempt to save to the autosaved template
$fh = fopen("$template_dir/autosaved", 'w');
// translate from definition to the constant
$temp_bodytext = $cpstring;
foreach ($FIELD_TAG as $key => $value) {
$temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
// the user must be logged in before file manipulation
if (isset($_SESSION['authUserID'])) {
$fh = fopen("$template_dir/autosaved", 'w');
// translate from definition to the constant
$temp_bodytext = $cpstring;
foreach ($FIELD_TAG as $key => $value) {
$temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while saving to the file','','',' ') . $template_dir."/autosaved" .
xl('Ensure LibreEHR has write privileges to directory','',' . ',' ') . $template_dir . "/ ." ;
die;
}
fclose($fh);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while saving to the file','','',' ') . $template_dir."/autosaved" .
xl('Ensure LibreEHR has write privileges to directory','',' . ',' ') . $template_dir . "/ ." ;
die;
else { // redirects to landing page
$landingpage = "index.php";
header('Location: '.$landingpage);
exit;
}
fclose($fh);

$cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}' , $datestr, $cpstring);
$cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}' , $from_title, $cpstring);
Expand Down Expand Up @@ -231,66 +239,98 @@
else if (isset($_GET['template']) && $_GET['template'] != "") {
// utilized to go back to autosaved template
$bodytext = "";
$fh = fopen("$template_dir/".$_GET['template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
// the user must be logged in before file manipulation
if (isset($_SESSION['authUserID'])) {
$fh = fopen("$template_dir/".$_GET['template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
}
else { // redirects to landing page
$landingpage = "index.php";
header('Location: '.$landingpage);
exit;
}
// translate from constant to the definition
foreach ($FIELD_TAG as $key => $value) {
$bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
}
}
else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
$bodytext = "";
$fh = fopen("$template_dir/".$_POST['form_template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
// the user must be logged in before file manipulation
if (isset($_SESSION['authUserID'])) {
$fh = fopen("$template_dir/".$_POST['form_template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
}
else { // redirects to landing page
$landingpage = "index.php";
header('Location: '.$landingpage);
exit;
}
// translate from constant to the definition
foreach ($FIELD_TAG as $key => $value) {
$bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
}
}
else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
// attempt to save the template
$fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
// translate from definition to the constant
$temp_bodytext = $_POST['form_body'];
foreach ($FIELD_TAG as $key => $value) {
$temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
// the user must be logged in before file manipulation
if (isset($_SESSION['authUserID'])) {
$fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
// translate from definition to the constant
$temp_bodytext = $_POST['form_body'];
foreach ($FIELD_TAG as $key => $value) {
$temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['newtemplatename'];
die;
}
fclose($fh);

// read the saved file back
$_POST['form_template'] = $_POST['newtemplatename'];
$fh = fopen("$template_dir/".$_POST['form_template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['newtemplatename'];
die;
else { // redirects to landing page
$landingpage = "index.php";
header('Location: '.$landingpage);
exit;
}
fclose($fh);

// read the saved file back
$_POST['form_template'] = $_POST['newtemplatename'];
$fh = fopen("$template_dir/".$_POST['form_template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
// translate from constant to the definition
foreach ($FIELD_TAG as $key => $value) {
$bodytext = str_replace("{".$key."}", "{".$value."}" , $bodytext);
}
}
else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
// attempt to save the template
$fh = fopen("$template_dir/".$_POST['form_template'], 'w');
// translate from definition to the constant
$temp_bodytext = $_POST['form_body'];
foreach ($FIELD_TAG as $key => $value) {
$temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
// the user must be logged in before file manipulation
if (isset($_SESSION['authUserID'])) {
$fh = fopen("$template_dir/".$_POST['form_template'], 'w');
// translate from definition to the constant
$temp_bodytext = $_POST['form_body'];
foreach ($FIELD_TAG as $key => $value) {
$temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
die;
}
fclose($fh);

// read the saved file back
$fh = fopen("$template_dir/".$_POST['form_template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
die;
else { // redirects to landing page
$landingpage = "index.php";
header('Location: '.$landingpage);
exit;
}
fclose($fh);

// read the saved file back
$fh = fopen("$template_dir/".$_POST['form_template'], 'r');
while (!feof($fh)) $bodytext.= fread($fh, 8192);
fclose($fh);
// translate from constant to the definition
foreach ($FIELD_TAG as $key => $value) {
$bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
Expand Down
23 changes: 13 additions & 10 deletions sites/default/sqlconf.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<?php
// LibreEHR
// MySQL default Config
// Referenced from /library/sqlconf.php.

global $disable_utf8_flag;
$disable_utf8_flag = false;
// MySQL Config

$host = 'localhost';
$port = '3306';
$login = 'libreehr';
$pass = 'libreehr';
$pass = 'toor';
$dbase = 'libreehr';

global $disable_utf8_flag;
$disable_utf8_flag = false;

$sqlconf = array();
global $sqlconf;
$sqlconf["host"]= $host;
$sqlconf["port"] = $port;
$sqlconf["login"] = $login;
$sqlconf["pass"] = $pass;
$sqlconf["dbase"] = $dbase;

//$config for default site files should never be changed.
$config = 0;

/////////WARNING!/////////
//Setting $config to = 0//
// will break this site //
//and cause SETUP to run//
$config = 1; /////////////
//////////////////////////
//////////////////////////
//////////////////////////
?>

0 comments on commit df337dd

Please sign in to comment.