Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate File Write in letter #1600

Closed
wants to merge 12 commits into from
43 changes: 24 additions & 19 deletions interface/patient_file/letter.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,32 @@
}
}
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);
}
if (! fwrite($fh, $temp_bodytext)) {
echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
die;
// authenticate
$userAuthorized = $_SESSION['userauthorized'];
if ($userAuthorized) {
// 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);
}
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);
// translate from constant to the definition
foreach ($FIELD_TAG as $key => $value) {
$bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
}
}
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);
}
}

// This is the case where we display the form for data entry.
Expand Down
12 changes: 10 additions & 2 deletions patient_portal/import_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@
file_put_contents($_POST['docid'], $_POST['content']);
exit(true);
} else if ($_POST['mode'] == 'delete') {
unlink($_POST['docid']);
exit(true);

// authenticate
$userAuthorized = $_SESSION['userauthorized'];
if ($userAuthorized) {
//allow
unlink($_POST['docid']);
exit(true);
}

}

// so it is an import
if(!isset($_POST['up_dir'])){

Expand Down