Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Forked Xestia Scanner Server!
[xestiascansrv/.git] / cgi-files / Modules / Export / Download.pm
1 #################################################################################
2 # Xestia Scanner Server - Download Export Module.                               #
3 # Presents the scanned image after being processed as a download link.          #
4 #                                                                               #
5 # Copyright (C) 2010-2011 Steve Brokenshire <sbrokenshire@xestia.co.uk>         #
6 #                                                                               #
7 # This module is licensed under the same license as Xestia Scanner Server which #
8 # is licensed under the GPL version 3.                                          #
9 #                                                                               #
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.                       #
13 #                                                                               #
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.                                  #
18 #                                                                               #
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.
29 use strict;
30 use warnings;
31 use Encode qw(decode_utf8);
32 use Modules::System::Common;
33 use File::Copy;
34 use File::Basename;
36 # Set the following values.
38 our $VERSION = "0.1.0";
40 my $error_flag = 0;
41 my $error_message = "";
42 my $language_name = "";
43 my %optionshash = ();
45 sub new{
46 #################################################################################
47 # new: Create an instance of Modules::Output::Normal                            #
48 #                                                                               #
49 # Usage:                                                                        #
50 #                                                                               #
51 # $dbmodule = Modules::Output::Normal->new();                                   #
52 #################################################################################
53         
54         # Get the perl module name.
56         my $class = shift;
57         my $self = {};
59         return bless($self, $class);
61 }
63 sub initialise{
64 #################################################################################
65 # initialise: Initialises the output module.                                    #
66 #                                                                               #
67 # Usage:                                                                        #
68 #                                                                               #
69 # $outputmodule->initialise();                                                  #
70 #################################################################################
72 }
74 sub loadsettings{
75 #################################################################################
76 # loadsettings: Loads some settings for the output module.                      #
77 #                                                                               #
78 # Usage:                                                                        #
79 #                                                                               #
80 # $outputmodule->loadsettings(language);                                        #
81 #                                                                               #
82 # language      Specifies the language to use.                                  #
83 #################################################################################
84         
85         my $class = shift;
86         my $passed_lang = shift;
87         
88         $language_name = $passed_lang;
89         
90 }
92 sub getoptions{
93 #################################################################################
94 # getoptions: Gets the options that will be used.                               #
95 #                                                                               #
96 # Usage:                                                                        #
97 #                                                                               #
98 # %options = $outputmodule->getoptions();                                       #
99 #################################################################################
101         my (%options, $options);
102         tie(%options, "Tie::IxHash");
103         
104         $options{filenameforexport}{type} = "textbox";
105         $options{filenameforexport}{string} = languagestrings("filenametouse");
106         $options{filenameforexport}{maxlength} = "256";
107         $options{filenameforexport}{size} = "64";
108         
109         return %options;
113 sub exportimage{
114 #################################################################################
115 # exportimage: Exports the image.                                               #
116 #                                                                               #
117 # Usage:                                                                        #
118 #                                                                               #
119 # $exportmodule->exportimage(processedfilename, scansuridirectory,              #
120 #                               scansfsdirectory, exportoptions);               #
121 #                                                                               #
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);
129         
130         my $class = shift;
131         my $processed_filename = shift;
132         my $scans_uri = shift;
133         my $scans_fs = shift;
134         %exportoptions = @_;
135         
136         # Copy the file to the download directory.
137         
138         $! = 0;
140         # Remove everything before the last slash.
141         
142         my $processed_filename_nopath = fileparse($processed_filename);
143         
144         copy($processed_filename, "scans/" . $processed_filename_nopath) or ($error_flag = 1, $error_message = $!, return);
145         
146         # Move the file into the scans folder.
147         
148         if ($exportoptions{filenameforexport}){
149                 
150                 # Remove everything before the last slash.
151                 
152                 my $processedexportname = basename($exportoptions{filenameforexport});
153                 
154                 move("scans/" . $processed_filename_nopath, $scans_fs . "/" . $processedexportname) or ($error_flag = 1, $error_message = $!, return);
155                 $processed_filename_nopath = $processedexportname;
157                 
158         } else {
159         
160                 move("scans/" . $processed_filename_nopath, $scans_fs . "/" . $processed_filename_nopath) or ($error_flag = 1, $error_message = $!, return);
161                 
162         }
163         
164         # Print Link.
165         
166         $main::xestiascan_presmodule->addlink($scans_uri . "/" . $processed_filename_nopath, { Text => languagestrings("clicklink") });
167         
168         return;
172 sub errorflag{
173 #################################################################################
174 # errorflag: Returns an error flag (if any).                                    #
175 #                                                                               #
176 # Usage:                                                                        #
177 #                                                                               #
178 # $errorflag    = $outputmodule->errorflag();                                   #
179 #################################################################################
180         
181         return $error_flag;
185 sub errormessage{
186 #################################################################################
187 # errormessage: Returns an error message (if any).                              #
188 #                                                                               #
189 # Usage:                                                                        #
190 #                                                                               #
191 # $errormessage = $outputmodule->errormessage();                                #
192 #################################################################################
194         return $error_message;
198 sub clearflag{
199 #################################################################################
200 # clearflag: Clears the error message flag and the error message itself.        #
201 #                                                                               #
202 # Usage:                                                                        #
203 #                                                                               #
204 # $outputmodule->clearflag();                                                   #
205 #################################################################################
207         $error_flag     = 0;
208         $error_message  = "";
212 sub languagestrings{
213 #################################################################################
214 # languagestrings: Language strings that are used in this module.               #
215 #                                                                               #
216 # Usage:                                                                        #
217 #                                                                               #
218 # $string = $outputmodule->languagestrings("langstring");                       #
219 #################################################################################
221         my $langstring = shift;
223         my $language_string;
224         my ($language_strings, %language_strings);
225         my $item;
226         
227         if ($language_name eq "en-GB"){
229                 # Language strings for English (British) language.
230                 
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):";
234         } else {
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):";
240                 
241         }
243         $language_string = $language_strings{$langstring};
244         
245         foreach $item (@_){
247                 $language_string =~ s/%s/$item/;
249         }
251         return $language_string;
255 1;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy