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

Make appending to files transactional #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions incl/scan.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
$lang_error=$lang[$lang_id][32];
$error_input=0;
$append_finalize=array_key_exists('append_finalize', $_POST) && $_POST['append_finalize'] == "true";

function scan_error(&$scan_output, &$error_input, $lang_error) {
$scan_output="!!!!!!!! ".$lang_error." !!!!!!!!";
Expand Down Expand Up @@ -116,8 +117,13 @@ function scan_error(&$scan_output, &$error_input, $lang_error) {
$preview_images = $temp_dir."preview_".$sid.".jpg";
$cmd_device = $SCANIMAGE." -d ".$scanner." --resolution ".$PREVIEW_DPI."dpi -l 0mm -t 0mm -x ".$MAX_SCAN_WIDTH_MM."mm -y ".$MAX_SCAN_HEIGHT_MM."mm".$cmd_mode.$cmd_brightness.$cmd_contrast.$cmd_usr_opt." | ".$PNMTOJPEG." --quality=50 > ".$preview_images;
}
else if ($action_save) {
$file_save = $save_dir.$_POST['file_name'].".".$format;
else if ($action_save && $append_finalize) {
$path_info = pathinfo($append_file);
rename($append_file, $save_dir.$path_info['filename'].".".$path_info['extension']);
}
else if ($action_save && !$append_finalize) {
$path = ($do_append_pdf || $do_append_txt) ? $temp_dir : $save_dir;
$file_save = $path.$_POST['file_name'].".".$format;
if (file_exists($file_save)) {
$file_save=$save_dir.$_POST['file_name']." ".date("Y-m-d H.i.s",time()).".".$format;
}
Expand Down Expand Up @@ -173,7 +179,7 @@ function scan_error(&$scan_output, &$error_input, $lang_error) {
}

//merge files
if ($action_save && $append_file !== '') {
if ($action_save && $append_file !== '' && !$append_finalize) {
$escaped_file_save = str_replace(" ", "\\ ", $file_save);
$escaped_append_file = str_replace(" ", "\\ ", $append_file);

Expand Down
16 changes: 10 additions & 6 deletions phpsane.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,15 @@ function fileSelectEvaluateCheckbox() {

////////////////////////////////////////////////////////
//////extend scanned document with another page
<?php if ($action_save && (($format == "pdf" && $do_append_pdf) || ($format == "txt" && $do_append_txt))) {
<?php if ($action_save && !$append_finalize && (($format == "pdf" && $do_append_pdf) || ($format == "txt" && $do_append_txt))) {
echo "
if(confirm('{$lang[$lang_id][50]}')) {
$('#append_file').val('{$file_save}');
$('#tab_menu_buttons_accept').click();
}";
$('#append_file').val('{$file_save}');

if(!confirm('{$lang[$lang_id][50]}')) {
$('#append_finalize').val('true');
}

$('#tab_menu_buttons_accept').click();";
} ?>

////////////////////////////////////////////////////////
Expand All @@ -325,7 +328,8 @@ function fileSelectEvaluateCheckbox() {
<input type=hidden name='lang_id' id='lang_id' value='$lang_id'>
<input type=hidden name='sid' value='$sid'>
<input type=hidden name='preview_images' value='$preview_images'>
<input type=hidden name='append_file' id='append_file' value=''>\n";
<input type=hidden name='append_file' id='append_file' value=''>
<input type=hidden name='append_finalize' id='append_finalize' value=''>\n";
if(!$do_file_name) {
$filename = ($file_name_prefix !== -1 ? $file_name_prefix : $lang[$lang_id][60]) . date("Y-m-d H.i.s", time());
echo " <input type=hidden name='file_name' id='file_name' value='$filename'>\n";
Expand Down