1 #################################################################################
2 # Xestia Scanner Server - Download Export Module. #
3 # Presents the scanned image after being processed as a download link. #
5 # Copyright (C) 2010-2011 Steve Brokenshire <sbrokenshire@xestia.co.uk> #
7 # This module is licensed under the same license as Xestia Scanner Server which #
8 # is licensed under the GPL version 3. #
10 # This program is free software: you can redistribute it and/or modify #
11 # it under the terms of the GNU General Public License as published by #
12 # the Free Software Foundation, version 3 of the License. #
14 # This program is distributed in the hope that it will be useful, #
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 # GNU General Public License for more details. #
19 # You should have received a copy of the GNU General Public License #
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
21 #################################################################################
23 # Define the package (perl module) name.
25 package Modules::Export::Download;
27 # Enable strict and use warnings.
31 use Encode qw(decode_utf8);
32 use Modules::System::Common;
36 # Set the following values.
38 our $VERSION = "0.1.0";
41 my $error_message = "";
42 my $language_name = "";
46 #################################################################################
47 # new: Create an instance of Modules::Output::Normal #
51 # $dbmodule = Modules::Output::Normal->new(); #
52 #################################################################################
54 # Get the perl module name.
59 return bless($self, $class);
64 #################################################################################
65 # initialise: Initialises the output module. #
69 # $outputmodule->initialise(); #
70 #################################################################################
75 #################################################################################
76 # loadsettings: Loads some settings for the output module. #
80 # $outputmodule->loadsettings(language); #
82 # language Specifies the language to use. #
83 #################################################################################
86 my $passed_lang = shift;
88 $language_name = $passed_lang;
93 #################################################################################
94 # getoptions: Gets the options that will be used. #
98 # %options = $outputmodule->getoptions(); #
99 #################################################################################
101 my (%options, $options);
102 tie(%options, "Tie::IxHash");
104 $options{filenameforexport}{type} = "textbox";
105 $options{filenameforexport}{string} = languagestrings("filenametouse");
106 $options{filenameforexport}{maxlength} = "256";
107 $options{filenameforexport}{size} = "64";
114 #################################################################################
115 # exportimage: Exports the image. #
119 # $exportmodule->exportimage(processedfilename, scansuridirectory, #
120 # scansfsdirectory, exportoptions); #
122 # processedfilename Specifies the processed file to export. #
123 # scansuridirectory Specifies the URI of the scans directory. #
124 # scansfsdirectory Specifies the FS location of the scans directory. #
125 # exportoptions Specifies the options for the export module. #
126 #################################################################################
128 my ($exportoptions, %exportoptions);
131 my $processed_filename = shift;
132 my $scans_uri = shift;
133 my $scans_fs = shift;
136 # Copy the file to the download directory.
140 # Remove everything before the last slash.
142 my $processed_filename_nopath = fileparse($processed_filename);
144 copy($processed_filename, "scans/" . $processed_filename_nopath) or ($error_flag = 1, $error_message = $!, return);
146 # Move the file into the scans folder.
148 if ($exportoptions{filenameforexport}){
150 # Remove everything before the last slash.
152 my $processedexportname = basename($exportoptions{filenameforexport});
154 move("scans/" . $processed_filename_nopath, $scans_fs . "/" . $processedexportname) or ($error_flag = 1, $error_message = $!, return);
155 $processed_filename_nopath = $processedexportname;
160 move("scans/" . $processed_filename_nopath, $scans_fs . "/" . $processed_filename_nopath) or ($error_flag = 1, $error_message = $!, return);
166 $main::xestiascan_presmodule->addlink($scans_uri . "/" . $processed_filename_nopath, { Text => languagestrings("clicklink") });
173 #################################################################################
174 # errorflag: Returns an error flag (if any). #
178 # $errorflag = $outputmodule->errorflag(); #
179 #################################################################################
186 #################################################################################
187 # errormessage: Returns an error message (if any). #
191 # $errormessage = $outputmodule->errormessage(); #
192 #################################################################################
194 return $error_message;
199 #################################################################################
200 # clearflag: Clears the error message flag and the error message itself. #
204 # $outputmodule->clearflag(); #
205 #################################################################################
213 #################################################################################
214 # languagestrings: Language strings that are used in this module. #
218 # $string = $outputmodule->languagestrings("langstring"); #
219 #################################################################################
221 my $langstring = shift;
224 my ($language_strings, %language_strings);
227 if ($language_name eq "en-GB"){
229 # Language strings for English (British) language.
231 $language_strings{clicklink} = "Click on or select this link to download the image.";
232 $language_strings{filenametouse} = "Filename to use (leave blank for default):";
236 # Invalid language so use English (British) as default.
238 $language_strings{clicklink} = "Click on or select this link to download the image.";
239 $language_strings{filenametouse} = "Filename to use (leave blank for default):";
243 $language_string = $language_strings{$langstring};
247 $language_string =~ s/%s/$item/;
251 return $language_string;