Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Forked Xestia Scanner Server!
[xestiascansrv/.git] / cgi-files / Modules / System / Scan.pm
1 #################################################################################
2 # Xestia Scanner Server - Scan System Module                                    #
3 # Version 0.1.0                                                                 #
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 package Modules::System::Scan;
25 use Modules::System::Common;
26 use strict;
27 use warnings;
28 use Exporter;
29 use Tie::IxHash;
30 use Hash::Search;
31 use Sane;
32 use Image::Magick;
33 use CGI::Lite;
35 our @ISA = qw(Exporter);
36 our @EXPORT = qw(xestiascan_scan_preview xestiascan_scan_final xestiascan_scan_getpreviewimage xestiascan_scan_getoutputmodules xestiascan_scan_getexportmodules);
37 our $scan_device;
39 sub xestiascan_scan_getoutputmodules{
40 #################################################################################
41 # xestiascan_scan_getoutputmodules: Gets the list of available output modules.  #
42 #                                                                               #
43 # Usage:                                                                        #
44 #                                                                               #
45 # @outputmodules = xestiascan_scan_getoutputmodules;                            #
46 #################################################################################
48         my (@outputmoduleslist, @outputmoduleslist_final);
49         my $outputmodulefile;
51         opendir(OUTPUTMODULEDIR, "Modules/Output");
52         @outputmoduleslist = grep /m*\.pm$/, sort(readdir(OUTPUTMODULEDIR));
53         closedir(OUTPUTMODULEDIR);
55         foreach $outputmodulefile (@outputmoduleslist){
56                 next if $outputmodulefile =~ m/^\./;
57                 next if $outputmodulefile !~ m/.pm$/;
58                 $outputmodulefile =~ s/.pm$//;
59                 push(@outputmoduleslist_final, $outputmodulefile);
60         }
62         return @outputmoduleslist_final;
63         
64 }
66 sub xestiascan_scan_getexportmodules{
67 #################################################################################
68 # xestiascan_scan_getexportmodules: Gets the list of available export modules.  #
69 #                                                                               #
70 # Usage:                                                                        #
71 #                                                                               #
72 # @exportmodules = xestiascan_scan_getexportmodules;                            #
73 #################################################################################
75         my (@exportmoduleslist, @exportmoduleslist_final);
76         my $exportmodulefile;
78         opendir(EXPORTMODULEDIR, "Modules/Export");
79         @exportmoduleslist = grep /m*\.pm$/, sort(readdir(EXPORTMODULEDIR));
80         closedir(EXPORTMODULEDIR);
82         foreach $exportmodulefile (@exportmoduleslist){
83                 next if $exportmodulefile =~ m/^\./;
84                 next if $exportmodulefile !~ m/.pm$/;
85                 $exportmodulefile =~ s/.pm$//;
86                 push(@exportmoduleslist_final, $exportmodulefile);
87         }
89         return @exportmoduleslist_final;
90         
91 }
93 sub xestiascan_scan_preview{
94 #################################################################################
95 # xestiascan_scan_preview: Previews a scanning.                                 #
96 #                                                                               #
97 # Usage:                                                                        #
98 #                                                                               #
99 # xestiascan_scan_preview(previewdocument, previewoptions);                     #
100 #                                                                               #
101 # previewdocument       Specifies a preview of the document should be made.     #
102 # previewoptions        Specifies the options for the document preview.         #
103 #################################################################################
105         # Get the values passed to this subroutine.
106         
107         my $previewdocument = shift;
108         
109         if (!$previewdocument){
110         
111                 $previewdocument = "off";
112                 
113         }
114         
115         # Setup some variables for later.
116         
117         my $scan_settings = 0;
118         
119         my $picture_resolution = "75";
120         my $picture_brightness = "100";
121         my $picture_contrast = "100";
122         my $picture_topleftx = 0;
123         my $picture_toplefty = 0;
124         my $picture_bottomrightx = 0;
125         my $picture_bottomrighty = 0;
126         
127         # Check if the preview document checkbox is selected and if it is then
128         # scan the image and preview it.
129         
130         my $randomhex = int(0);
131         my %previewoptions;
132         
133         my $scannerpermission;
134         
135         if ($previewdocument eq "on"){
136                 
137                 (%previewoptions) = @_;
138                 
139                 # Check the parameters passed to the subroutine.
140                 
141                 # Brightness.
142                 
143                 xestiascan_error("brightnessblank") if !$previewoptions{Brightness};
144                 my $brightness_numberscheck = xestiascan_variablecheck($previewoptions{Brightness}, "numbers", 0, 1);
145                 xestiascan_error("brightnessinvalidnumber") if $brightness_numberscheck eq 1;
146                 
147                 # Rotate. (Should be either 0, 90, 180, 270 degrees).
148                 
149                 xestiascan_error("rotateblank") if !$previewoptions{Rotate};
150                 if ($previewoptions{Rotate} eq "0deg" || $previewoptions{Rotate} eq "90deg" || $previewoptions{Rotate} eq "180deg" || $previewoptions{Rotate} eq "270deg"){
151                         
152                 } else {
153                 
154                         xestiascan_error("rotateinvalidoption");
155                 
156                 }
157                 
158                 # Colour.
159                 
160                 xestiascan_error("colourblank") if !$previewoptions{Colour};
161                 if ($previewoptions{Colour} eq "rgb" || $previewoptions{Colour} eq "grey" ){
162                         
163                 } else {
164                 
165                         xestiascan_error("colourinvalidoption");
166                         
167                 }
168                 
169                 # Resolution.
170                 
171                 xestiascan_error("resolutionblank") if !defined($previewoptions{Resolution});
172                 my $resolution_numberscheck = xestiascan_variablecheck($previewoptions{Resolution}, "numbers", 0, 1);
173                 xestiascan_error("resolutioninvalidnumber") if $resolution_numberscheck eq 1;
174                 
175                 # Top Left X (Pointy figure);
176                 
177                 xestiascan_error("topleftxblank") if !defined($previewoptions{TopLeftX});
178                 my $topleftx_decimalcheck = xestiascan_variablecheck($previewoptions{TopLeftX}, "decimal", 0, 1);
179                 xestiascan_error("topleftxinvalidnumber") if $topleftx_decimalcheck eq 1;
180                 
181                 # Top Left Y (Pointy figure).
182                 
183                 xestiascan_error("topleftyblank") if !defined($previewoptions{TopLeftY});
184                 my $toplefty_decimalcheck = xestiascan_variablecheck($previewoptions{TopLeftY}, "decimal", 0, 1);
185                 xestiascan_error("topleftyinvalidnumber") if $toplefty_decimalcheck eq 1;               
186                 
187                 # Bottom Right X (Pointy figure).
188                 
189                 xestiascan_error("bottomrightx") if !defined($previewoptions{BottomRightX});
190                 my $bottomrightx_decimalcheck = xestiascan_variablecheck($previewoptions{BottomRightX}, "decimal", 0, 1);
191                 xestiascan_error("bottomrightxinvalidnumber") if $bottomrightx_decimalcheck eq 1;
192                 
193                 # Bottom Right Y (Pointy figure).
194                 
195                 xestiascan_error("bottomrighty") if !defined($previewoptions{BottomRightY});
196                 my $bottomrighty_decimalcheck = xestiascan_variablecheck($previewoptions{BottomRightY}, "decimal", 0, 1);
197                 xestiascan_error("bottomrightyinvalidnumber") if $bottomrighty_decimalcheck eq 1;
198                 
199                 # Check to see if the user has permission to use the scanner.
200                 
201                 $scannerpermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "Scanner", PermissionName => $previewoptions{ScannerID} });
202                 
203                 xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
204                 xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
205                 xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
206                 
207                 if ($scannerpermission eq 1){
208                         
209                         # User has permission to use the scanner so start scanning.
210                         
211                         # Generate a random hex value and use this to write a temporary file.
212                         
213                         $randomhex = hex(int(rand(16777216)));
214                         
215                         # Set variables for scanner and return an error if they were
216                         # not set correctly.
217                         
218                         $scan_device = Sane::Device->open($previewoptions{ScannerID});
219                         xestiascan_error("scannererror", $Sane::STATUS) if $Sane::STATUS;
220                         
221                         xestiascan_scan_setscannervalue(SANE_NAME_SCAN_RESOLUTION, $previewoptions{Resolution});
222                         xestiascan_error("scannererror", xestiascan_language($main::xestiascan_lang{scan}{causedpictureresolution}, $Sane::STATUS)) if $Sane::STATUS;
223                         
224                         xestiascan_scan_setscannervalue(SANE_NAME_SCAN_TL_X, $previewoptions{TopLeftX});
225                         xestiascan_error("scannererror", xestiascan_language($main::xestiascan_lang{scan}{causedtopleftx}, $Sane::STATUS)) if $Sane::STATUS;
226                         
227                         xestiascan_scan_setscannervalue(SANE_NAME_SCAN_TL_Y, $previewoptions{TopLeftY});
228                         xestiascan_error("scannererror", xestiascan_language($main::xestiascan_lang{scan}{causedtoplefty}, $Sane::STATUS)) if $Sane::STATUS;
229                         
230                         xestiascan_scan_setscannervalue(SANE_NAME_SCAN_BR_X, $previewoptions{BottomRightX});
231                         xestiascan_error("scannererror", xestiascan_language($main::xestiascan_lang{scan}{causedbottomrightx}, $Sane::STATUS)) if $Sane::STATUS;
232                         
233                         xestiascan_scan_setscannervalue(SANE_NAME_SCAN_BR_Y, $previewoptions{BottomRightY});
234                         xestiascan_error("scannererror", xestiascan_language($main::xestiascan_lang{scan}{causedbottomrighty}, $Sane::STATUS)) if $Sane::STATUS;
235                         
236                         # Get Sane to scan based on what has been passed (scanner name).
237                         
238                         if ($Sane::STATUS == SANE_STATUS_GOOD){
239                                 $scan_device->start;
240                         } else {
241                         
242                                 # An error occured whilst trying to use the scanner
243                                 # so return an error.
244                                 
245                                 xestiascan_error("scannererror", $Sane::STATUS);
246                                 
247                         }
248                         
249                         my $param = $scan_device->get_parameters;
250                         my $fh;
251                         open ($fh, '>', "/tmp/xestiascanserver-" . $randomhex . ".pnm") or xestiascan_error("filepermissionerror", $!);
252                         $scan_device->write_pnm_header($fh, $param->{format}, 
253                         $param->{pixels_per_line},
254                         $param->{lines}, $param->{depth});
255                         my ($data, $len);
256                         do{ 
257                                 ($data, $len) = $scan_device->read ($param->{bytes_per_line});
258                                 print $fh $data if $data;
259                         } until ($Sane::STATUS == SANE_STATUS_EOF);
260                         close ($fh);
261                         
262                         # Get the current scanner values.
263                         
264                         $picture_resolution = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_RESOLUTION);
265                         $picture_topleftx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_X);
266                         $picture_toplefty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_Y);
267                         $picture_bottomrightx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_X);
268                         $picture_bottomrighty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_Y);
269                         
270                         $scan_settings = 1;
271                         
272                         $picture_topleftx = int(0) if $picture_topleftx eq 0;
273                         
274                         # Convert the PNM based image into PNG format.
275                         
276                         my $im = new Image::Magick;
277                         $im->Read("/tmp/xestiascanserver-" . $randomhex . ".pnm");
278                         
279                         # Rotate the document if needed.
280                         
281                         my $rotate = $previewoptions{Rotate};
282                         my $numrotate = 0;
283                         my $numrotateseek = 0;
284                         
285                         if ($previewoptions{Rotate} ne "0deg" ){
286                                 $numrotate = 1 if $rotate eq "90deg";
287                                 $numrotate = 2 if $rotate eq "180deg";
288                                 $numrotate = 3 if $rotate eq "270deg";
289                                 #$im->Rotate({ degrees => "180" }) if $rotate eq "180deg";
290                                 #$im->Rotate({ degrees => "270" }) if $rotate eq "270deg";
291                                 
292                                 do {
293                                         $im->Rotate();
294                                         $numrotateseek++;
295                                 } until ($numrotateseek eq $numrotate || $numrotateseek > $numrotate);
296                                 
297                         }
298                         
299                         # Change the colour type of the document if needed.
300                         
301                         if ($previewoptions{Colour} eq "rgb"){
302                                 
303                                 # Set the document to colour.
304                                 
305                                 $im->Quantize(colorspace => 'RGB');
306                                 
307                         } elsif ($previewoptions{Colour} eq "grey"){
308                                 
309                                 # Set the document to greyscale.
310                                 
311                                 $im->Quantize(colorspace =>'gray');
312                                 
313                         }
314                 
315                         # Adjust the brightness.
316                         
317                         xestiascan_error("brightnessblank") if !$previewoptions{Brightness};
318                         
319                         my $brightness_numberscheck = xestiascan_variablecheck($previewoptions{Brightness}, "numbers", 0, 1);
320                         xestiascan_error("brightnessinvalidnumber") if $brightness_numberscheck eq 1;
321                         
322                         $picture_brightness = $previewoptions{Brightness};
323                         $im->Modulate(brightness=> $picture_brightness);
324                         
325                         $im->Minify;            # As it is a preview, Minify it.
326                         
327                         $im->Write("/tmp/xestiascanserver-preview-" . $randomhex . ".png");
328                         
329                         # Delete the PNM file.
330                         
331                         unlink("/tmp/xestiascanserver-preview-" . $randomhex . ".pnm");
332                         
333                 }
334                 
335         }
336         
337         my $selectedscandevice;
338         
339         if (@_){
340                 
341                 (%previewoptions) = @_;
342                 
343                 $selectedscandevice = $previewoptions{ScannerID};
344                 
345         }
346         
347         $selectedscandevice = "" if !$selectedscandevice;
348         
349         # Get the list of available scanners and process the list.
350         
351         my %scanners;
352         tie(%scanners, "Tie::IxHash");
353         %scanners = xestiascan_scan_getscannerlist();
354         
355         # Print out the form.
356         
357         $main::xestiascan_presmodule->startform("xsdss.cgi", "POST");
358         $main::xestiascan_presmodule->addhiddendata("mode", "scan");
359         $main::xestiascan_presmodule->addhiddendata("action", "scan");
360         $main::xestiascan_presmodule->startbox("scannermenu");
361         
362         if (!%scanners){
363                 
364                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{noscanners});
365                 $main::xestiascan_presmodule->endbox();
366                 return $main::xestiascan_presmodule->grab();
367                 
368         }
369         
370         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{scanner});
371         $main::xestiascan_presmodule->addselectbox("scanner");
372         
373         my $scannername;
374         my $scandevice;
375         my $notfirstscanner = 0;
376         
377         foreach $scandevice (keys %scanners){
378         
379                 # Check if scanner matches the name of the selected
380                 # scan device.
381                 
382                 if ($scanners{$scandevice}{name} eq $selectedscandevice){
383                         
384                         $main::xestiascan_presmodule->addoption($scanners{$scandevice}{vendor} . ": ". $scanners{$scandevice}{model}, {Value => $scanners{$scandevice}{name}, Selected => 1});
385                         
386                 } else {
387                 
388                         $main::xestiascan_presmodule->addoption($scanners{$scandevice}{vendor} . ": ". $scanners{$scandevice}{model}, {Value => $scanners{$scandevice}{name}});
389                 
390                 }
391                 
392                 if ($notfirstscanner ne 1){
393                 
394                         $scannername = $scanners{$scandevice}{name};
395                         $notfirstscanner = 1;
396                         
397                 }
398                 
399         }
400         
401         $main::xestiascan_presmodule->endselectbox();
402         
403         # Check to see if the user has permission to use this scanner.
404         # Otherwise return an error message.
405         
406         $scannerpermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "Scanner", PermissionName => $scannername });
408         xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
409         xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
410         xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
411         
412         $scannerpermission = 0 if !$scannerpermission;
413         
414         if ($scannerpermission eq 1){
415         
416                 # The user has permission to use this scanner.
417                 
418                 if (!$previewoptions{ScannerID}){
419                         
420                         $scan_device = Sane::Device->open($scannername);
421                         
422                         xestiascan_error("scannererror", $Sane::STATUS) if $Sane::STATUS;
423                         
424                         $picture_resolution = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_RESOLUTION);
425                         $picture_topleftx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_X);
426                         $picture_toplefty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_Y);
427                         $picture_bottomrightx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_X);
428                         $picture_bottomrighty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_Y);           
430                 } else {
431                         
432                         $scan_device = Sane::Device->open($previewoptions{ScannerID}) if !$scan_device;
433                         
434                         $picture_resolution = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_RESOLUTION);
435                         $picture_topleftx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_X);
436                         $picture_toplefty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_Y);
437                         $picture_bottomrightx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_X);
438                         $picture_bottomrighty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_Y);
439                         
440                 }
441                         
442                 $main::xestiascan_presmodule->addtext(" | ");
443                 $main::xestiascan_presmodule->addbutton("switch", { Value => "switched", Description => $main::xestiascan_lang{scan}{switchscanner} });
444                 
445                 $main::xestiascan_presmodule->addtext(" | ");
446                 
447                 if ($previewdocument eq "on"){
448                         $main::xestiascan_presmodule->addcheckbox("previewdocument", { OptionDescription => $main::xestiascan_lang{scan}{previewdocument}, Checked => 1 });
449                 } else {
450                         $main::xestiascan_presmodule->addcheckbox("previewdocument", { OptionDescription => $main::xestiascan_lang{scan}{previewdocument} });
451                 }
452                 
453                 $main::xestiascan_presmodule->addtext(" | ");
454                 $main::xestiascan_presmodule->addsubmit($main::xestiascan_lang{scan}{startscanning});
455                 $main::xestiascan_presmodule->endbox();
456                 
457                 if ($previewdocument eq "on"){
458                         
459                         $main::xestiascan_presmodule->startbox("sectionbox");
460                         $main::xestiascan_presmodule->startbox("sectiontitle");
461                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{documentpreview});
462                         $main::xestiascan_presmodule->endbox();
463                         $main::xestiascan_presmodule->startbox("secondbox");
464                         $main::xestiascan_presmodule->addimage("xsdss.cgi?mode=scan&action=getpreviewimage&pictureid=" . $randomhex);
465                         $main::xestiascan_presmodule->endbox();
466                         $main::xestiascan_presmodule->endbox();
467                         
468                 }
469                 
470                 $main::xestiascan_presmodule->startbox("sectionbox");
471                 $main::xestiascan_presmodule->startbox("sectiontitle");
472                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{documentsettings});
473                 $main::xestiascan_presmodule->endbox();
474                 $main::xestiascan_presmodule->startbox("secondbox");
475                 
476                 $main::xestiascan_presmodule->addboldtext($main::xestiascan_lang{scan}{picturedimensions});
477                 $main::xestiascan_presmodule->addlinebreak();
478                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{topleftx});
479                 $main::xestiascan_presmodule->addinputbox("topleftx", { MaxLength => "5", Size => "5", ZeroInteger => 1, Value => $picture_topleftx });
480                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{mm});
481                 $main::xestiascan_presmodule->addlinebreak();
482                 
483                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{toplefty});
484                 $main::xestiascan_presmodule->addinputbox("toplefty", { MaxLength => "5", Size => "5", ZeroInteger => 1,  Value => $picture_toplefty });
485                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{mm});
486                 $main::xestiascan_presmodule->addlinebreak();
487                 
488                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{bottomrightx});
489                 $main::xestiascan_presmodule->addinputbox("bottomrightx", { MaxLength => "5", Size => "5", ZeroInteger => 1, Value => $picture_bottomrightx });
490                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{mm});
491                 $main::xestiascan_presmodule->addlinebreak();
492                 
493                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{bottomrighty});
494                 $main::xestiascan_presmodule->addinputbox("bottomrighty", { MaxLength => "5", Size => "5", ZeroInteger => 1, Value => $picture_bottomrighty });
495                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{mm});
496                 $main::xestiascan_presmodule->addlinebreak();
497                 
498                 $main::xestiascan_presmodule->addhorizontalline();
499                 
500                 $main::xestiascan_presmodule->addboldtext($main::xestiascan_lang{scan}{picturesettings});
501                 $main::xestiascan_presmodule->addlinebreak();
502                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{pictureresolution});
503                 $main::xestiascan_presmodule->addinputbox("imagedpi", { MaxLength => "4", Size => "4", Value => $picture_resolution});
504                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{dpi});
505                 $main::xestiascan_presmodule->addlinebreak();
506                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{rotate});
507                 $main::xestiascan_presmodule->addselectbox("rotate");
508                 
509                 if ($previewoptions{Rotate}){
510                         
511                         # If the value matches with one of these in the list then
512                         # set that as the selected value.
513                         
514                         if ($previewoptions{Rotate} eq "0deg"){
515                                 
516                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r0deg}, { Value => "0deg", Selected => 1 });
517                                 
518                         } else {
519                                 
520                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r0deg}, { Value => "0deg" });
521                                 
522                         }
523                         
524                         if ($previewoptions{Rotate} eq "90deg"){
525                                 
526                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r90deg}, { Value => "90deg", Selected => 1 });
527                                 
528                         } else {
529                                 
530                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r90deg}, { Value => "90deg" });
531                                 
532                         }
533                         
534                         if ($previewoptions{Rotate} eq "180deg"){
535                                 
536                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r180deg}, { Value => "180deg", Selected => 1 });
537                                 
538                         } else {
539                                 
540                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r180deg}, { Value => "180deg" });
541                                 
542                         }
543                         
544                         if ($previewoptions{Rotate} eq "270deg"){
545                                 
546                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r270deg}, { Value => "270deg", Selected => 1 });
547                                 
548                         } else {
549                                 
550                                 $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r270deg}, { Value => "270deg" });
551                                 
552                         }
553                         
554                         
555                         
556                 } else {
557                         
558                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r0deg}, { Value => "0deg", Selected => 1 });
559                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r90deg}, { Value => "90deg" });
560                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r180deg}, { Value => "180deg" });
561                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{r270deg}, { Value => "270deg" });
562                         
563                 }
564                 
565                 $main::xestiascan_presmodule->endselectbox();
566                 $main::xestiascan_presmodule->addlinebreak();
567                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{brightness});
568                 $main::xestiascan_presmodule->addinputbox("brightness", { MaxLength => "3", Size => "3", Value => $picture_brightness });
569                 $main::xestiascan_presmodule->addtext("%");
570                 $main::xestiascan_presmodule->addlinebreak();
571                 #$main::xestiascan_presmodule->addtext("Contrast: ");
572                 #$main::xestiascan_presmodule->addinputbox("contrast", { MaxLength => "3", Size => "3", Value => $picture_contrast })#;
573                 #$main::xestiascan_presmodule->addtext("%");
574                 #$main::xestiascan_presmodule->addlinebreak();
575                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{colour});
576                 $main::xestiascan_presmodule->addselectbox("colourtype");
577                 
578                 if (!$previewoptions{Colour} || $previewoptions{Colour} eq "rgb"){
579                         
580                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{colourrgb}, { Value => "rgb", Selected => 1 });
581                         
582                 } else {
583                         
584                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{colourrgb}, { Value => "rgb" });
585                         
586                 }
587                 
588                 if ($previewoptions{Colour} && $previewoptions{Colour} eq "grey"){
589                         
590                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{grey}, { Value => "grey", Selected => 1 });
591                         
592                 } else {
593                         
594                         $main::xestiascan_presmodule->addoption($main::xestiascan_lang{scan}{grey}, { Value => "grey" });
595                         
596                 }
597                 
598                 $main::xestiascan_presmodule->endselectbox();
599                 
600                 
601                 $main::xestiascan_presmodule->addlinebreak();
602                 
603                 $main::xestiascan_presmodule->endbox();
604                 $main::xestiascan_presmodule->endbox();
605                 
606                 $main::xestiascan_presmodule->endform();
607                 
608         } else {
609         
610                 # The user does not have permission to use this scanner.
611                 
612                 $main::xestiascan_presmodule->addtext(" | ");
613                 $main::xestiascan_presmodule->addbutton("switch", { Value => "switched", Description => $main::xestiascan_lang{scan}{switchscanner} });
614                 $main::xestiascan_presmodule->endbox();
615                 
616                 $main::xestiascan_presmodule->startbox("errorsectionbox");
617                 $main::xestiascan_presmodule->startbox("errorboxheader");
618                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error});
619                 $main::xestiascan_presmodule->endbox();
620                 $main::xestiascan_presmodule->startbox("errorbox");
621                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{scannerpermissioninvalid});
622                 $main::xestiascan_presmodule->endbox();
623                 $main::xestiascan_presmodule->endbox();
624                 
625         }
626         
627         return $main::xestiascan_presmodule->grab();
628         
631 sub xestiascan_scan_final{
632 #################################################################################
633 # xestiascan_scan_final: Get the final image and present a list of available    #
634 #                        options.                                               #
635 #                                                                               #
636 # Usage:                                                                        #
637 #                                                                               #
638 # xestiascan_scan_final(confirm, pageoptions);                                  #
639 #                                                                               #
640 # confirm               Specifies to confirm the processing of the page.        #
641 # pageoptions           Specifies the options for the page.                     #
642 #################################################################################
643         
644         # Get the variables passed to the subroutine.
645         
646         my $confirm     = shift;
647         
648         if (!$confirm){
649         
650                 # The confirm value is not set so set it to 0.
651                 
652                 $confirm = 0;
653         
654         }
655         
656         my (%previewoptions) = @_;
657         
658         # Check if the user has permission to use the scanner
659         # and return an error if this is not the case.
660         
661         my $scannerpermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "Scanner", PermissionName => $previewoptions{ScannerID} });
662         
663         xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
664         xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
665         xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
666         
667         $scannerpermission = 0 if !$scannerpermission;
668         
669         if ($scannerpermission ne 1 && !$previewoptions{OutputFormat}){
670         
671                 # The user does not have permission to use this scanner,
672                 # so return an error message.
673                 
674                 $main::xestiascan_presmodule->startbox("errorsectionbox");
675                 $main::xestiascan_presmodule->startbox("errorboxheader");
676                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error});
677                 $main::xestiascan_presmodule->endbox();
678                 $main::xestiascan_presmodule->startbox("errorbox");
679                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{scannerpermissioninvalid});
680                 $main::xestiascan_presmodule->endbox();
681                 $main::xestiascan_presmodule->endbox();
682                 
683                 return $main::xestiascan_presmodule->grab();
684                 
685         }
686         
687         if ($confirm eq 1){
688         
689                 # The action to process the page has been confirmed so process the image.
690                 
691                 # Convert the PNM image into the correct format.
692                 
693                 my $outputmodule = $previewoptions{OutputFormat};
694                 my $hexnumber = int($previewoptions{ImageHex});
695                 
696                 # Check if the output module has a valid name.
697                 
698                 my $outputmodulevalid = xestiascan_variablecheck($previewoptions{OutputFormat}, "module", 0, 1);
699                 
700                 if ($outputmodulevalid eq 1){
701                 
702                         # The output module is missing so write a message saying
703                         # the name is invalid.
704                         
705                         $main::xestiascan_presmodule->startbox("errorsectionbox");
706                         $main::xestiascan_presmodule->startbox("errorboxheader");
707                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error});
708                         $main::xestiascan_presmodule->endbox();
709                         $main::xestiascan_presmodule->startbox("errorbox");
710                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleinvalidname});
711                         $main::xestiascan_presmodule->endbox();
712                         $main::xestiascan_presmodule->endbox();
713                         
714                         return $main::xestiascan_presmodule->grab();
715                         
716                 }
717                 
718                 # Check if the module exists.
719                 
720                 my $outputmoduleexists = xestiascan_fileexists("Modules/Output/" . $previewoptions{OutputFormat} . ".pm");
721                 
722                 if ($outputmoduleexists eq 1){
723                 
724                         # The output module is missing so write a message saying
725                         # it does not exist.
726                         
727                         $main::xestiascan_presmodule->startbox("errorsectionbox");
728                         $main::xestiascan_presmodule->startbox("errorboxheader");
729                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error});
730                         $main::xestiascan_presmodule->endbox();
731                         $main::xestiascan_presmodule->startbox("errorbox");
732                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmodulemissing});
733                         $main::xestiascan_presmodule->endbox();
734                         $main::xestiascan_presmodule->endbox();                 
735                         
736                         return $main::xestiascan_presmodule->grab();
737                         
738                 }
739                 
740                 # Check if the module has valid file permissions.
741                 
742                 my $outputmodulefilepermission = xestiascan_filepermissions("Modules/Output/" . $previewoptions{OutputFormat} . ".pm", 1, 0, 0);
743                 
744                 if ($outputmodulefilepermission eq 1){
745                 
746                         # The output module has invalid file permissions so
747                         # write a message.
748                         
749                         $main::xestiascan_presmodule->startbox("errorsectionbox");
750                         $main::xestiascan_presmodule->startbox("errorboxheader");
751                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error});
752                         $main::xestiascan_presmodule->endbox();
753                         $main::xestiascan_presmodule->startbox("errorbox");
754                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleinvalidfilepermissions});
755                         $main::xestiascan_presmodule->endbox();
756                         $main::xestiascan_presmodule->endbox();                 
757                         
758                         return $main::xestiascan_presmodule->grab();                    
759                         
760                 }
761                 
762                 # Check to see if the user has permission to use the output module and return an error if not.
763                 
764                 my $outputmodulepermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "OutputModule", PermissionName => $outputmodule });
766                 xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
767                 xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
768                 xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
769                 
770                 $outputmodulepermission = 0 if !$outputmodulepermission;
771                 
772                 if ($outputmodulepermission eq 0){
773                 
774                         # The user does not have permission so write an error message
775                         # saying the user does not have permission.
776                         
777                         $main::xestiascan_presmodule->startbox("errorsectionbox");
778                         $main::xestiascan_presmodule->startbox("errorboxheader");
779                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error});
780                         $main::xestiascan_presmodule->endbox();
781                         $main::xestiascan_presmodule->startbox("errorbox");
782                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleinvaliddbpermissions});
783                         $main::xestiascan_presmodule->endbox();
784                         $main::xestiascan_presmodule->endbox();                 
785                         
786                         return $main::xestiascan_presmodule->grab();
787                         
788                 }
789                 
790                 my $outputmodulename = "Modules::Output::" . $outputmodule;
791                 eval "use " . $outputmodulename;
792                 my $xestiascan_outputmodule = $outputmodulename->new();
793                 my ($outputmodule_options, %outputmodule_options);
794                 tie(%outputmodule_options, "Tie::IxHash");
795                 $xestiascan_outputmodule->initialise();
796                 $xestiascan_outputmodule->loadsettings($main::xestiascan_config{"system_language"});
797                 %outputmodule_options = $xestiascan_outputmodule->getoptions();
798                 my $option_name;
799                 my $outputmodule_selected = 0;
800                 my $outputmodule_readonly = 0;
801                 my $combobox_count = 0;
802                 my @outputmodule_comboboxnames;
803                 my @outputmodule_comboboxvalues;
804                 my $outputmodule_comboboxname;
805                 my $outputmodule_comboboxvalue;
806                 
807                 # Setup the original filename.
808                 
809                 my $original_filename = "";
810                 my $processed_filename = "";
811                 
812                 # Get the output module settings.
813                 
814                 my ($outputmodule_passedoptions, %outputmodule_passedoptions);
815                 my %outputmodulesettings;
816                 my %outputmodulesettings_final;
817                 tie(%outputmodule_passedoptions, "Tie::IxHash");
818                 
819                 my $hs = new Hash::Search;
820                 my $cgilite = new CGI::Lite;
821                 my %form_data = $cgilite->parse_form_data;
822                 
823                 $hs->hash_search("^outputmodule_", %form_data);
824                 %outputmodulesettings = $hs->hash_search_resultdata;
825                 
826                 # Strip the outputmodule_ prefix.
827                 
828                 my $outputmodule_settings_unprocessed;
829                 my $outputmodule_settings_regex;
830                 
831                 foreach $outputmodule_settings_unprocessed (keys %outputmodulesettings){
832                 
833                         $outputmodule_settings_regex = "^outputmodule_";
834                         $outputmodule_settings_unprocessed =~ s/^$outputmodule_settings_regex//;
835                         
836                         $outputmodulesettings_final{$outputmodule_settings_unprocessed} = $outputmodulesettings{"outputmodule_" . $outputmodule_settings_unprocessed};
837                         
838                 }
839                 
840                 # Proceed with the output module processing.
841                 
842                 $main::xestiascan_presmodule->startbox("sectionboxnofloat");
843                 $main::xestiascan_presmodule->startbox("sectiontitle");
844                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleresults});
845                 $main::xestiascan_presmodule->endbox();
846                 $main::xestiascan_presmodule->startbox("secondbox");
847                 
848                 $main::xestiascan_presmodule->startbox("outputmoduletitle");
849                 $main::xestiascan_presmodule->addtext(xestiascan_language($main::xestiascan_lang{scan}{resultsuffix}, $outputmodule));
850                 $main::xestiascan_presmodule->endbox();
852                 $processed_filename = $xestiascan_outputmodule->processimage($hexnumber, %outputmodulesettings_final);
853                 
854                 $main::xestiascan_presmodule->startbox("outputmoduleoptions");
856                 if ($xestiascan_outputmodule->errorflag ne 0){
857                         
858                         # An error occurred so stop processing and end the script.
859                         
860                         $main::xestiascan_presmodule->addtext(xestiascan_language($main::xestiascan_lang{scan}{outputmodulefailed}, $xestiascan_outputmodule->errormessage));
861                         $main::xestiascan_presmodule->addlinebreak();
862                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleunable});
863                         $main::xestiascan_presmodule->endbox();
864                         
865                         $main::xestiascan_presmodule->endbox();
866                         $main::xestiascan_presmodule->endbox();
867                         $main::xestiascan_presmodule->endbox();
868                         
869                         return $main::xestiascan_presmodule->grab();
870                         
871                 } else {
872                 
873                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmodulecomplete});
874                         
875                 }
876                 
877                 $main::xestiascan_presmodule->endbox();
878                 
879                 $main::xestiascan_presmodule->endbox();
880                 $main::xestiascan_presmodule->endbox();
881                 
882                 # Process the selected export modules.
883                 
884                 $main::xestiascan_presmodule->startbox("sectionboxnofloat");
885                 $main::xestiascan_presmodule->startbox("sectiontitle");
886                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{exportmoduleresults});
887                 $main::xestiascan_presmodule->endbox();
888                 $main::xestiascan_presmodule->startbox("secondbox");
889                 
890                 # Check the list of selected export modules.
891                 
892                 my (%selectedmodules, $selectedmodules);
893                 
894                 my (%exportmodulesettings, $exportmodulesettings);
895                 my (%exportmodulesettings_final);
896                 
897                 $hs->hash_search("^module_", %form_data);
898                 %selectedmodules = $hs->hash_search_resultdata;
899                 
900                 my $exportmodule_count = 0;
901                 my $exportmodule_name = "";
902                 my $exportmodule_unprocessed = "";
903                 
904                 my $exportmodule_settings_unprocessed = "";
905                 my $exportmodule_settings_regex = "";
906                 
907                 my @activemodules;
908                 
909                 foreach $exportmodule_unprocessed (keys %selectedmodules){
910                 
911                         # Skip if the module wasn't selected in the first place.
912                         
913                         next if $selectedmodules{$exportmodule_unprocessed} ne "on";
914                         
915                         # Add the module to the selected modules list.
916                         
917                         $exportmodule_unprocessed =~ s/^module_//;
918                         push(@activemodules, $exportmodule_unprocessed);
919                         $exportmodule_count++;
920                         
921                 }
922                 
923                 @activemodules = sort(@activemodules);
924                 
925                 # Process the export modules.
926                 
927                 foreach $exportmodule_name (@activemodules){
929                         # Write the beginning part of the box for the results of the module.
930                         
931                         $main::xestiascan_presmodule->startbox("exportmoduletitle");
932                         $main::xestiascan_presmodule->addtext(xestiascan_language($main::xestiascan_lang{scan}{resultsuffix}, $exportmodule_name));
933                         $main::xestiascan_presmodule->endbox();
934                         $main::xestiascan_presmodule->startbox("exportmoduleoptions");
935                         
936                         # Check to see if the export module exists and process the next
937                         # one if this is not the case.
938                         
939                         my $exportmodulecheck = xestiascan_variablecheck($exportmodule_name, "module", 0, 1);
940                         
941                         if ($exportmodulecheck eq 1){
942                         
943                                 # The export module name given is invalid. Skip and
944                                 # process the next one.
945                                 
946                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{exportmoduleinvalidname});
947                                 $main::xestiascan_presmodule->endbox();
948                                 
949                                 next;
950                                 
951                         }
952                         
953                         my $exportmoduleexists = xestiascan_fileexists("Modules/Export/" . $exportmodule_name . ".pm");
954                         
955                         if ($exportmoduleexists eq 1){
956                                 
957                                 # The export moudle with the name given is missing.
958                                 # Skip and process the next one.
959                                 
960                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{exportmodulemissing});
961                                 $main::xestiascan_presmodule->endbox();
962                                 
963                                 next;
964                                 
965                                 
966                         }
967                         
968                         my $exportmodulefilepermission = xestiascan_filepermissions("Modules/Export/" . $exportmodule_name . ".pm");
969                         
970                         if ($exportmodulefilepermission eq 1){
971                         
972                                 # The export module with the name given has invalid
973                                 # file permissions.
974                                 
975                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{exportmodulemissing});
976                                 $main::xestiascan_presmodule->endbox();
977                                 
978                                 next;                           
979                                 
980                         }
981                         
982                         # Check if the user has permission to use this export
983                         # module and write a message if not.
984                         
985                         my $exportmodulepermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "ExportModule", PermissionName => $exportmodule_name });
987                         xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
988                         xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
989                         xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
990                         
991                         $exportmodulepermission = 0 if !$exportmodulepermission;
992                         
993                         if ($exportmodulepermission eq 0){
994                         
995                                 # The user does not have permission to use this export
996                                 # module so write a message.
997                                 
998                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{exportmoduleinvaliddbpermissions});
999                                 $main::xestiascan_presmodule->endbox();
1000                                 
1001                                 next;
1002                                 
1003                         }
1004                         
1005                         # Get the module settings.
1006                         
1007                         my ($exportmodule_options, %exportmodule_options);
1008                         tie(%exportmodule_options, "Tie::IxHash");
1009                         
1010                         $hs->hash_search("^exportmodule_" . $exportmodule_name . "_", %form_data);
1011                         %exportmodulesettings = $hs->hash_search_resultdata;
1012                         
1013                         # Strip the module settings.
1014                         
1015                         foreach $exportmodule_settings_unprocessed (keys %exportmodulesettings){
1016                                 
1017                                 $exportmodule_settings_regex = "^exportmodule_" . $exportmodule_name . "_";
1018                                 $exportmodule_settings_unprocessed =~ s/^$exportmodule_settings_regex//;
1019                                 
1020                                 $exportmodule_options{$exportmodule_settings_unprocessed} = $exportmodulesettings{"exportmodule_" . $exportmodule_name . "_" . $exportmodule_settings_unprocessed};
1021                                 
1022                         }
1023                         
1024                         # Load the export module.
1025                         
1026                         my $exportmodulename = "Modules::Export::" . $exportmodule_name;
1027                         eval "use " . $exportmodulename;
1028                         my $xestiascan_exportmodule = $exportmodulename->new();
1029                         
1030                         $xestiascan_exportmodule->initialise();
1031                         $xestiascan_exportmodule->loadsettings($main::xestiascan_config{"system_language"});
1032                         
1033                         # Process the outputted file.
1034                         
1035                         $xestiascan_exportmodule->exportimage($processed_filename, $main::xestiascan_config{"directory_noncgi_scans"}, $main::xestiascan_config{"directory_fs_scans"}, %exportmodule_options);
1036                         
1037                         # Check if an error occured.
1038                         
1039                         $main::xestiascan_presmodule->addhorizontalline();
1040                         
1041                         if ($xestiascan_exportmodule->errorflag ne 0){
1042                                 
1043                                 $main::xestiascan_presmodule->addtext(xestiascan_language($main::xestiascan_lang{scan}{exportmodulefailed}, $xestiascan_exportmodule->errormessage));
1044                                 
1045                         } else {
1046                 
1047                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{exportmodulecomplete});
1048                                 
1049                         }
1050                         
1051                         # Delete the export module.
1052                         
1053                         undef($xestiascan_exportmodule);
1054                         
1055                         # Finish the results box for this export module.
1056                         
1057                         $main::xestiascan_presmodule->endbox();
1058                 
1059                 }
1060                 
1061                 if (!@activemodules){
1062                 
1063                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{noexportmoduleselected});
1064                         
1065                 }
1066                 
1067                 $main::xestiascan_presmodule->endbox();
1068                 $main::xestiascan_presmodule->endbox();         
1069                 
1070         } else {
1071         
1072                 my $randomhex = 0;
1073                 
1074                 if ($previewoptions{Switched} eq "no"){
1075                 
1076                         # Get the image, generate a random number, write the file as PNM and display
1077                         # some options for the scanned image.
1078                         
1079                         # Brightness.
1080                         
1081                         xestiascan_error("brightnessblank") if !$previewoptions{Brightness};
1082                         my $brightness_numberscheck = xestiascan_variablecheck($previewoptions{Brightness}, "numbers", 0, 1);
1083                         xestiascan_error("brightnessinvalidnumber") if $brightness_numberscheck eq 1;
1084                         
1085                         # Rotate. (Should be either 0, 90, 180, 270 degrees).
1086                         
1087                         xestiascan_error("rotateblank") if !$previewoptions{Rotate};
1088                         if ($previewoptions{Rotate} eq "0deg" || $previewoptions{Rotate} eq "90deg" || $previewoptions{Rotate} eq "180deg" || $previewoptions{Rotate} eq "270deg"){
1089                                 
1090                         } else {
1091                                 
1092                                 xestiascan_error("rotateinvalidoption");
1093                                 
1094                         }
1095                         
1096                         # Colour.
1097                         
1098                         xestiascan_error("colourblank") if !$previewoptions{Colour};
1099                         if ($previewoptions{Colour} eq "rgb" || $previewoptions{Colour} eq "grey" ){
1100                                 
1101                         } else {
1102                                 
1103                                 xestiascan_error("colourinvalidoption");
1104                                 
1105                         }
1106                         
1107                         # Resolution.
1108                         
1109                         xestiascan_error("resolutionblank") if !defined($previewoptions{Resolution});
1110                         my $resolution_numberscheck = xestiascan_variablecheck($previewoptions{Resolution}, "numbers", 0, 1);
1111                         xestiascan_error("resolutioninvalidnumber") if $resolution_numberscheck eq 1;
1112                         
1113                         # Top Left X (Pointy figure);
1114                         
1115                         xestiascan_error("topleftxblank") if !defined($previewoptions{TopLeftX});
1116                         my $topleftx_decimalcheck = xestiascan_variablecheck($previewoptions{TopLeftX}, "decimal", 0, 1);
1117                         xestiascan_error("topleftxinvalidnumber") if $topleftx_decimalcheck eq 1;
1118                         
1119                         # Top Left Y (Pointy figure).
1120                         
1121                         xestiascan_error("topleftyblank") if !defined($previewoptions{TopLeftY});
1122                         my $toplefty_decimalcheck = xestiascan_variablecheck($previewoptions{TopLeftY}, "decimal", 0, 1);
1123                         xestiascan_error("topleftyinvalidnumber") if $toplefty_decimalcheck eq 1;               
1124                         
1125                         # Bottom Right X (Pointy figure).
1126                         
1127                         xestiascan_error("bottomrightx") if !defined($previewoptions{BottomRightX});
1128                         my $bottomrightx_decimalcheck = xestiascan_variablecheck($previewoptions{BottomRightX}, "decimal", 0, 1);
1129                         xestiascan_error("bottomrightxinvalidnumber") if $bottomrightx_decimalcheck eq 1;
1130                         
1131                         # Bottom Right Y (Pointy figure).
1132                         
1133                         xestiascan_error("bottomrighty") if !defined($previewoptions{BottomRightY});
1134                         my $bottomrighty_decimalcheck = xestiascan_variablecheck($previewoptions{BottomRightY}, "decimal", 0, 1);
1135                         xestiascan_error("bottomrightyinvalidnumber") if $bottomrighty_decimalcheck eq 1;
1136                         
1137                         # Generate a random hex value and use this to write a temporary file.
1138                         
1139                         $randomhex = 0;
1140                         
1141                         if (!$previewoptions{ImageHex}){
1142                         
1143                                 $randomhex = hex(int(rand(16777216)));
1144                         
1145                                 # Set variables for scanner.
1146                         
1147                                 $scan_device = Sane::Device->open($previewoptions{ScannerID});
1148                         
1149                                 xestiascan_scan_setscannervalue(SANE_NAME_SCAN_RESOLUTION, $previewoptions{Resolution});
1150                                 xestiascan_scan_setscannervalue(SANE_NAME_SCAN_TL_X, $previewoptions{TopLeftX});
1151                                 xestiascan_scan_setscannervalue(SANE_NAME_SCAN_TL_Y, $previewoptions{TopLeftY});
1152                                 xestiascan_scan_setscannervalue(SANE_NAME_SCAN_BR_X, $previewoptions{BottomRightX});
1153                                 xestiascan_scan_setscannervalue(SANE_NAME_SCAN_BR_Y, $previewoptions{BottomRightY});
1154                         
1155                                 # Get Sane to scan based on what has been passed (scanner name).
1156                         
1157                                 if ($Sane::STATUS == SANE_STATUS_GOOD){
1158                                         $scan_device->start;
1159                                 }
1160                         
1161                                 my $param = $scan_device->get_parameters;
1162                                 my $fh;
1163                                 open ($fh, '>', "/tmp/xestiascanserver-preview-" . $randomhex . ".pnm") or die("error: $!");
1164                                 $scan_device->write_pnm_header($fh, $param->{format}, 
1165                                 $param->{pixels_per_line},
1166                                 $param->{lines}, $param->{depth});
1167                                 my ($data, $len);
1168                                 do{ 
1169                                         ($data, $len) = $scan_device->read ($param->{bytes_per_line});
1170                                         print $fh $data if $data;
1171                                 } until ($Sane::STATUS == SANE_STATUS_EOF);
1172                                 close ($fh);
1173                         
1174                                 # Get the current scanner values.
1175                                 
1176                                 my $picture_resolution = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_RESOLUTION);
1177                                 my $picture_topleftx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_X);
1178                                 my $picture_toplefty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_TL_Y);
1179                                 my $picture_bottomrightx = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_X);
1180                                 my $picture_bottomrighty = xestiascan_scan_getscannervalue(SANE_NAME_SCAN_BR_Y);
1181                                 
1182                                 $picture_topleftx = int(0) if $picture_topleftx eq 0;
1183                                 
1184                                 # Convert the PNM based image into PNG format.
1185                                 
1186                                 my $im = new Image::Magick;
1187                                 $im->Read("/tmp/xestiascanserver-preview-" . $randomhex . ".pnm");
1188                                 
1189                                 # Rotate the document if needed.
1190                                 
1191                                 my $rotate = $previewoptions{Rotate};
1192                                 my $numrotate = 0;
1193                                 my $numrotateseek = 0;
1194                                 
1195                                 if ($previewoptions{Rotate} ne "0deg" ){
1196                                         $numrotate = 1 if $rotate eq "90deg";
1197                                         $numrotate = 2 if $rotate eq "180deg";
1198                                         $numrotate = 3 if $rotate eq "270deg";
1199                                         
1200                                         do {
1201                                                 $im->Rotate();
1202                                                 $numrotateseek++;
1203                                         } until ($numrotateseek eq $numrotate || $numrotateseek > $numrotate);
1204                                         
1205                                 }
1206                                 
1207                                 # Change the colour type of the document if needed.
1208                                 
1209                                 if ($previewoptions{Colour} eq "rgb"){
1210                                         
1211                                         # Set the document to colour.
1212                                         
1213                                         $im->Quantize(colorspace => 'RGB');
1214                                         
1215                                 } elsif ($previewoptions{Colour} eq "grey"){
1216                                         
1217                                         # Set the document to greyscale.
1218                                         
1219                                         $im->Quantize(colorspace =>'gray');
1220                                         
1221                                 }
1222                                 
1223                                 # Adjust the brightness.
1224                                 
1225                                 xestiascan_error("brightnessblank") if !$previewoptions{Brightness};
1226                                 
1227                                 my $brightness_numberscheck = xestiascan_variablecheck($previewoptions{Brightness}, "numbers", 0, 1);
1228                                 xestiascan_error("brightnessinvalidnumber") if $brightness_numberscheck eq 1;
1229                                 
1230                                 my $picture_brightness = $previewoptions{Brightness};
1231                                 $im->Modulate( brightness=> $picture_brightness );
1232                                 
1233                                 $im->Write("/tmp/xestiascanserver-preview-" . $randomhex . ".pnm");
1234                                 
1235                                 $im->Minify;
1236                                 
1237                                 $im->Write("/tmp/xestiascanserver-preview-" . $randomhex . ".png");
1239                         } else {
1240                         
1241                                 $randomhex = $previewoptions{ImageHex};
1242                                 
1243                         }
1244                         
1245                 } else {
1246                         
1247                         $randomhex = $previewoptions{ImageHex};
1248                         
1249                 }
1250                 
1251                 my ($outputmodule, $outputmodulesname, $exportmodule);
1252                 
1253                 # Get the output modules.
1254                 
1255                 my @outputmodules = xestiascan_scan_getoutputmodules;
1256                 $outputmodule = $previewoptions{OutputFormat} if $previewoptions{OutputFormat};
1257                 
1258                 # Get the export modules.
1259                 
1260                 my @exportmodules = xestiascan_scan_getexportmodules;
1261                 
1262                 $main::xestiascan_presmodule->startform("xsdss.cgi", "GET");
1263                 $main::xestiascan_presmodule->addhiddendata("mode", "scan");
1264                 $main::xestiascan_presmodule->addhiddendata("action", "scan");
1265                 $main::xestiascan_presmodule->addhiddendata("confirm", "1");
1266                 $main::xestiascan_presmodule->addhiddendata("imagehex", $randomhex);
1267                 
1268                 $main::xestiascan_presmodule->startbox("sectionboxnofloat");
1269                 $main::xestiascan_presmodule->startbox("sectiontitle");
1270                 
1271                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{imagepreview});
1272                 $main::xestiascan_presmodule->endbox();
1273                 $main::xestiascan_presmodule->startbox("secondbox, previewimage");
1274                 
1275                 # Get a preview of the image.
1276                 
1277                 $main::xestiascan_presmodule->addimage("xsdss.cgi?mode=scan&action=getpreviewimage&dontclear=1&pictureid=" . $randomhex);
1278                 $main::xestiascan_presmodule->endbox();
1279                 $main::xestiascan_presmodule->endbox();
1281                 $main::xestiascan_presmodule->startbox("sectionboxnofloat");
1282                 $main::xestiascan_presmodule->startbox("sectiontitle");
1283                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputformatsettings});
1284                 $main::xestiascan_presmodule->endbox();
1285                 $main::xestiascan_presmodule->startbox("secondbox");
1286                 
1287                 $main::xestiascan_presmodule->startbox("outputmoduletitle");
1288                 
1289                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmodule});
1290                 
1291                 $outputmodule = $main::xestiascan_config{"system_outputmodule"} if !$outputmodule;
1292                 
1293                 if (!@outputmodules){
1294                 
1295                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{noneavailable});
1296                         $main::xestiascan_presmodule->endbox();
1297                         $main::xestiascan_presmodule->startbox("outputmoduleoptions");
1298                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{nooutputmodulesavail});
1299                         $main::xestiascan_presmodule->endbox();
1300                         return $main::xestiascan_presmodule->grab();
1301                         
1302                 } else {
1303                 
1304                         $main::xestiascan_presmodule->addselectbox("outputformat");
1305                         
1306                         foreach $outputmodulesname (@outputmodules){
1307                                 if ($outputmodule eq $outputmodulesname){
1308                                         $main::xestiascan_presmodule->addoption($outputmodulesname, { Value => $outputmodulesname, Selected => 1 });
1309                                 } else {
1310                                         $main::xestiascan_presmodule->addoption($outputmodulesname, { Value => $outputmodulesname });
1311                                 }
1312                         }
1313                         
1314                         $main::xestiascan_presmodule->endselectbox();
1315                         $main::xestiascan_presmodule->addbutton("formatswitch", { Value => "yes", Description => "Switch Module" });
1316                         
1317                 }
1318                         
1319                 $main::xestiascan_presmodule->endbox();
1320                 
1321                 $outputmodule = $outputmodules[0] if !$outputmodule;
1322                 
1323                 # Check to see if the user has permission to use this
1324                 # output module.
1325                 
1326                 my $outputmodulepermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "OutputModule", PermissionName => $outputmodule });
1328                 xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
1329                 xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
1330                 xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
1331                 
1332                 $outputmodulepermission = 0 if !$outputmodulepermission;
1333                 
1334                 # Get the settings for the active output module.
1335                 
1336                 my $option_name;
1337                 my $combobox_count = 0;
1338                 
1339                 my $outputmodulefilepermissions = xestiascan_filepermissions("Modules/Output/" . $outputmodule . ".pm", 1, 0, 0);
1340                 
1341                 if ($outputmodulepermission eq 1 && $outputmodulefilepermissions eq 0){
1342                         
1343                         # Load the output module.
1344                         
1345                         my $outputmodulename = "Modules::Output::" . $outputmodule;
1346                         eval "use " . $outputmodulename;
1347                         my $xestiascan_outputmodule = $outputmodulename->new();
1348                         my ($outputmodule_options, %outputmodule_options);
1349                         tie(%outputmodule_options, "Tie::IxHash");
1350                         $xestiascan_outputmodule->initialise();
1351                         $xestiascan_outputmodule->loadsettings($main::xestiascan_config{"system_language"});
1352                         %outputmodule_options = $xestiascan_outputmodule->getoptions();
1353                         my $outputmodule_selected = 0;
1354                         my $outputmodule_readonly = 0;
1355                         my @outputmodule_comboboxnames;
1356                         my @outputmodule_comboboxvalues;
1357                         my $outputmodule_comboboxname;
1358                         my $outputmodule_comboboxvalue;
1359                         
1360                         $main::xestiascan_presmodule->startbox("outputmoduleoptions");          
1361                         
1362                         foreach $option_name (keys %outputmodule_options){
1363                                 
1364                                 # Check if the option is a checkbox option.
1365                                 
1366                                 if ($outputmodule_options{$option_name}{type} eq "checkbox"){
1367                                         
1368                                         $main::xestiascan_presmodule->addcheckbox("outputmodule_" . $option_name, { Checked => $outputmodule_options{$option_name}{checked}, OptionDescription => $outputmodule_options{$option_name}{string}, ReadOnly => $outputmodule_readonly });
1369                                         
1370                                 }
1371                                 
1372                                 # Check if the option is a string option.
1373                                 
1374                                 if ($outputmodule_options{$option_name}{type} eq "textbox"){
1375                                         
1376                                         if (!$outputmodule_options{$option_name}{password}){
1377                                                 $outputmodule_options{$option_name}{password} = 0;
1378                                         }
1379                                         
1380                                         $main::xestiascan_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1381                                         $main::xestiascan_presmodule->addinputbox("outputmodule_" . $option_name, { Size => $outputmodule_options{$option_name}{size}, MaxLength => $outputmodule_options->{$option_name}{maxlength}, Value => $outputmodule_options{$option_name}{value}, Password => $outputmodule_options{$option_name}{password}, ReadOnly => $outputmodule_readonly });
1382                                         
1383                                 }
1384                                 
1385                                 # Check if the option is a combobox option.
1386                                 
1387                                 if ($outputmodule_options{$option_name}{type} eq "combobox"){
1388                                         
1389                                         $combobox_count         = 0;
1390                                         
1391                                         @outputmodule_comboboxnames = split(/\|/, $outputmodule_options{$option_name}{optionnames});
1392                                         @outputmodule_comboboxvalues = split(/\|/, $outputmodule_options{$option_name}{optionvalues});
1393                                         
1394                                         $main::xestiascan_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1395                                         $main::xestiascan_presmodule->addselectbox("outputmodule_" . $option_name);
1396                                         
1397                                         foreach $outputmodule_comboboxname (@outputmodule_comboboxnames){
1398                                                 
1399                                                 $main::xestiascan_presmodule->addoption($outputmodule_comboboxname, { Value => $outputmodule_comboboxvalues[$combobox_count], ReadOnly => $outputmodule_readonly });
1400                                                 $combobox_count++;
1401                                                 
1402                                         }
1403                                         
1404                                         $main::xestiascan_presmodule->endselectbox;
1405                                         
1406                                 }
1407                                 
1408                                 # Check if the option is a radio option.
1409                                 
1410                                 if ($outputmodule_options{$option_name}{type} eq "radio"){
1411                                         
1412                                         # Check if the selected value is blank and if it is then
1413                                         # set it to 0.
1414                                         
1415                                         if (!$outputmodule_options{$option_name}{selected}){
1416                                                 $outputmodule_selected = 0;
1417                                         } else {
1418                                                 $outputmodule_selected = 1;
1419                                         }
1420                                         
1421                                         $main::xestiascan_presmodule->addradiobox("outputmodule_" . $outputmodule_options{$option_name}{name}, { Description => $outputmodule_options{$option_name}{string}, Value => $outputmodule_options{$option_name}{value}, Selected => $outputmodule_selected, ReadOnly => $outputmodule_readonly });
1422                                         
1423                                 }
1424                                 
1425                                 $main::xestiascan_presmodule->addlinebreak();
1426                                 
1427                         }
1429                         # If there are no options available then write a message
1430                         # to say no options are available for this module.
1431                         
1432                         if (!%outputmodule_options){
1433                         
1434                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{nooutputmoduleopts});
1435                                 
1436                         }
1437                         
1438                 } elsif ($outputmodulefilepermissions eq 1) {
1439                         
1440                         $main::xestiascan_presmodule->startbox("outputmoduleoptions");
1441                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleinvalidfilepermissions});                        
1442                         
1443                 } else {
1444                 
1445                         $main::xestiascan_presmodule->startbox("outputmoduleoptions");
1446                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{outputmoduleinvaliddbpermissions});
1447                         
1448                 }
1449                 
1450                 $main::xestiascan_presmodule->endbox();
1451                 $main::xestiascan_presmodule->endbox();
1452                 $main::xestiascan_presmodule->endbox();
1453                 
1454                 $main::xestiascan_presmodule->startbox("sectionboxnofloat");
1455                 $main::xestiascan_presmodule->startbox("sectiontitle");
1456                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{exportformatsettings});
1457                 $main::xestiascan_presmodule->endbox();
1458                 $main::xestiascan_presmodule->startbox("secondbox");
1459                 
1460                 # Process the list of export modules.
1461                 
1462                 my $exportmodulename;
1463                 my $xestiascan_exportmodule;
1464                 my ($exportmodule_options, %exportmodule_options);
1465                 my $exportmodule_readonly = 0;
1466                 my $exportmodule_selected = 0;
1467                 my @exportmodule_comboboxnames;
1468                 my @exportmodule_comboboxvalues;
1469                 my $exportmodule_comboboxname;
1470                 my $exportmodule_comboboxvalue;
1471                 
1472                 if (!@exportmodules){
1473                 
1474                         $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{noexportmodulesavail});
1475                         $main::xestiascan_presmodule->endbox();
1476                         $main::xestiascan_presmodule->endbox();
1477                         $main::xestiascan_presmodule->endbox();
1478                         return $main::xestiascan_presmodule->grab();
1479                         
1480                 }
1481                 
1482                 my $exportmodulepermission;
1483                 my $exportmodulefilepermission;
1484                 
1485                 foreach $exportmodule (@exportmodules){
1486                         
1487                         # Check to see if the user has permission to use the export
1488                         # module and return an error if this is not the case.
1489                         
1490                         $exportmodulepermission = $main::xestiascan_authmodule->getpermissions({ Username => $main::loggedin_user, PermissionType => "ExportModule", PermissionName => $exportmodule });
1492                         xestiascan_error("usernameblank") if ($main::xestiascan_authmodule->geterror eq "UsernameBlank");
1493                         xestiascan_error("permissiontypeblank") if ($main::xestiascan_authmodule->geterror eq "PermissionTypeBlank");
1494                         xestiascan_error("autherror", $main::xestiascan_authmodule->geterror(1)) if ($main::xestiascan_authmodule->geterror eq "DatabaseError");
1495                         
1496                         $exportmodulepermission = 0 if !$exportmodulepermission;
1497                         
1498                         # Check the file permissions for the export module
1499                         # has been set correctly.
1500                         
1501                         $exportmodulefilepermission = xestiascan_filepermissions("Modules/Export/" . $exportmodule . ".pm", 1, 0, 0);
1502                         
1503                         if ($exportmodulepermission eq 0){
1504                         
1505                                 # We don't have permission so write an error message.
1506                                 
1507                                 $main::xestiascan_presmodule->startbox("exportmoduletitle");
1508                                 $main::xestiascan_presmodule->addtext($exportmodule);
1509                                 $main::xestiascan_presmodule->endbox();
1510                                 
1511                                 $main::xestiascan_presmodule->startbox("exportmoduleoptions");
1512                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{exportmoduleinvalidfilepermissions});
1513                                 $main::xestiascan_presmodule->endbox();
1514                                 
1515                                 next;
1516                                 
1517                         }
1518                         
1519                         if ($exportmodulefilepermission ne 0){
1520                         
1521                                 # The file permissions are invalid so write an error message.
1522                                 
1523                                 $main::xestiascan_presmodule->startbox("exportmoduletitle");
1524                                 $main::xestiascan_presmodule->addtext($exportmodule);
1525                                 $main::xestiascan_presmodule->endbox();
1526                                 
1527                                 $main::xestiascan_presmodule->startbox("exportmoduleoptions");
1528                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{exportmoduleinvaliddbpermissions});
1529                                 $main::xestiascan_presmodule->endbox();
1530                                 
1531                                 next;
1532                                 
1533                         }
1534                         
1535                         # Load the export module.
1536                         
1537                         $exportmodulename = "Modules::Export::" . $exportmodule;
1538                         eval "use " . $exportmodulename;
1539                         $xestiascan_exportmodule = $exportmodulename->new();
1540                         tie(%exportmodule_options, "Tie::IxHash");
1541                         $xestiascan_exportmodule->initialise();
1542                         $xestiascan_exportmodule->loadsettings($main::xestiascan_config{"system_language"});
1543                         %exportmodule_options = $xestiascan_exportmodule->getoptions();
1544                         
1545                         $main::xestiascan_presmodule->startbox("exportmoduletitle");
1546                         $main::xestiascan_presmodule->addcheckbox("module_" . $exportmodule, { OptionDescription => "" });
1547                         $main::xestiascan_presmodule->addtext($exportmodule);
1548                         $main::xestiascan_presmodule->endbox();
1549                         
1550                         $main::xestiascan_presmodule->startbox("exportmoduleoptions");
1551                         foreach $option_name (keys %exportmodule_options){
1552                                 
1553                                 # Check if the option is a checkbox option.
1554                                 
1555                                 if ($exportmodule_options{$option_name}{type} eq "checkbox"){
1556                                          
1557                                         $main::xestiascan_presmodule->addcheckbox("exportmodule_" . $exportmodule . "_" . $option_name, { Checked => $exportmodule_options{$option_name}{checked}, OptionDescription => $exportmodule_options{$option_name}{string}, ReadOnly => $exportmodule_readonly });
1558                                         
1559                                 }
1560                                 
1561                                 # Check if the option is a string option.
1562                                 
1563                                 if ($exportmodule_options{$option_name}{type} eq "textbox"){
1564                                         
1565                                         if (!$exportmodule_options{$option_name}{password}){
1566                                                 $exportmodule_options{$option_name}{password} = 0;
1567                                         }
1568                                         
1569                                         $main::xestiascan_presmodule->addtext($exportmodule_options{$option_name}{string} . " ");
1570                                         $main::xestiascan_presmodule->addinputbox("exportmodule_" . $exportmodule . "_" . $option_name, { Size => $exportmodule_options{$option_name}{size}, MaxLength => $exportmodule_options->{$option_name}{maxlength}, Value => $exportmodule_options{$option_name}{value}, Password => $exportmodule_options{$option_name}{password}, ReadOnly => $exportmodule_readonly });
1571                                         
1572                                 }
1573                                 
1574                                 # Check if the option is a combobox option.
1575                                 
1576                                 if ($exportmodule_options{$option_name}{type} eq "combobox"){
1577                                         
1578                                         $combobox_count         = 0;
1579                                         
1580                                         @exportmodule_comboboxnames = split(/\|/, $exportmodule_options{$option_name}{optionnames});
1581                                         @exportmodule_comboboxvalues = split(/\|/, $exportmodule_options{$option_name}{optionvalues});
1582                                         
1583                                         $main::xestiascan_presmodule->addtext($exportmodule_options{$option_name}{string} . " ");
1584                                         $main::xestiascan_presmodule->addselectbox("exportmodule_" . $exportmodule . "_" . $option_name);
1585                                         
1586                                         foreach $exportmodule_comboboxname (@exportmodule_comboboxnames){
1587                                                 
1588                                                 $main::xestiascan_presmodule->addoption($exportmodule_comboboxname, { Value => $exportmodule_comboboxvalues[$combobox_count], ReadOnly => $exportmodule_readonly });
1589                                                 $combobox_count++;
1590                                                 
1591                                         }
1592                                         
1593                                         $main::xestiascan_presmodule->endselectbox;
1594                                         
1595                                 }
1596                                 
1597                                 # Check if the option is a radio option.
1598                                 
1599                                 if ($exportmodule_options{$option_name}{type} eq "radio"){
1600                                         
1601                                         # Check if the selected value is blank and if it is then
1602                                         # set it to 0.
1603                                         
1604                                         if (!$exportmodule_options{$option_name}{selected}){
1605                                                 $exportmodule_selected = 0;
1606                                         } else {
1607                                                 $exportmodule_selected = 1;
1608                                         }
1609                                         
1610                                         $main::xestiascan_presmodule->addradiobox("exportmodule_" . $exportmodule . "_" . $exportmodule_options{$option_name}{name}, { Description => $exportmodule_options{$option_name}{string}, Value => $exportmodule_options{$option_name}{value}, Selected => $exportmodule_selected, ReadOnly => $exportmodule_readonly });
1611                                         
1612                                 }
1613                                 
1614                                 $main::xestiascan_presmodule->addlinebreak();
1615                                 
1616                         }                       
1617                         $main::xestiascan_presmodule->endbox();
1618                         
1619                         if (!%exportmodule_options){
1620                                 
1621                                 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{scan}{noexportmoduleopts});
1622                                 
1623                         }
1624                         
1625                         # Delete (free) the export module.
1626                         
1627                         undef($xestiascan_exportmodule);
1628                         
1629                 }
1630                 
1631                 $main::xestiascan_presmodule->endbox();
1632                 $main::xestiascan_presmodule->endbox();
1633                 $main::xestiascan_presmodule->endbox();
1634                 
1635                 $main::xestiascan_presmodule->addsubmit($main::xestiascan_lang{scan}{process});
1636                 $main::xestiascan_presmodule->addreset($main::xestiascan_lang{common}{restoredefault});
1637                 
1638                 $main::xestiascan_presmodule->endform();
1639                 
1640         }
1641         
1642         return $main::xestiascan_presmodule->grab();
1643         
1647 sub xestiascan_scan_getpreviewimage{
1648 #################################################################################
1649 # xestiascan_scan_getpreviewimage: Get the preview image.                       #
1650 #                                                                               #
1651 # Usage:                                                                        #
1652 #                                                                               #
1653 # xestiascan_scan_getpreviewimage(previewid);                                   #
1654 #                                                                               #
1655 # previewid             Specifies the picture ID.                               #
1656 #################################################################################
1657         
1658         # Get the values from the subroutine.
1659         
1660         my $pictureid = shift;
1661         my $dontclear = shift;
1662         
1663         if (!$dontclear){
1664         
1665                 $dontclear = 0;
1666                 
1667         }
1668         
1669         # Return an error message if picture ID is blank.
1670         
1671         if (!$pictureid){
1672         
1673                 xestiascan_error("blankpictureid");
1674                 
1675         }
1676         
1677         xestiascan_error("invalidpictureid") if xestiascan_variablecheck($pictureid, "numbers", 0, 1) eq 1;
1678         
1679         print "Content-Type: image/png\r\n\r\n";
1680         
1681         binmode(STDOUT, ":bytes");
1682         
1683         my $imgfh;
1684         open($imgfh, "/tmp/xestiascanserver-preview-" . $pictureid . ".png");
1685         my @lines = <$imgfh>;
1686         print @lines;
1687         close ($imgfh);
1688         
1689         unlink("/tmp/xestiascanserver-preview-" . $pictureid . ".png") if $dontclear < 1;
1690         
1691 }       
1693 sub xestiascan_scan_getscannerlist{
1694 #################################################################################
1695 # xestiascan_scan_getscannerlist: Gets the list of available scanners.          #
1696 #                                                                               #
1697 # Usage:                                                                        #
1698 #                                                                               #
1699 # xestiascan_scan_getscannerlist;                                               #
1700 #################################################################################       
1701         
1702         my %scannerlist;
1703         my $scanner;
1704         
1705         tie(%scannerlist, 'Tie::IxHash');
1706         
1707         foreach $scanner (Sane->get_devices){
1708                 $scannerlist{$scanner->{'name'}}{name}          = $scanner->{'name'};
1709                 $scannerlist{$scanner->{'name'}}{model}         = $scanner->{'model'};
1710                 $scannerlist{$scanner->{'name'}}{vendor}        = $scanner->{'vendor'};
1711                 #       if ($scanner->{'name'} eq $http_scannerdevice){
1712                 #               print "<option value=\"" . $scanner->{'name'}  . "\" 
1713                 #selected=selected>" . $scanner->{'vendor'} . ": " . $scanner->{'model'} . "</option>";
1714                 #       } else {
1715                 #               print "<option value=\"" . $scanner->{'name'}  . "\">" . 
1716                 #$scanner->{'vendor'} . ": " . $scanner->{'model'} . "</option>";
1717                 #       }
1718         }
1719         
1720         return %scannerlist;
1721         
1724 sub xestiascan_scan_getscannervalue{
1725 #################################################################################
1726 # xestiascan_scan_getscannervalue: Gets a specific option value.                #
1727 #                                                                               #
1728 # Usage:                                                                        #
1729 #                                                                               #
1730 # xestiascan_scan_getscannervalue(name);                                        #
1731 #                                                                               #
1732 # name                  Specifies the name of option.                           #
1733 #################################################################################
1734         
1735         my $option_name = shift;
1736         
1737         my $option_value;
1738         my $option_found = 0;
1739         my $value = 0;
1740         
1741         my $option_total = $scan_device->get_option(0);
1742         my $option_seek = 0;
1743         
1744         my $option;
1745         
1746         do {
1747                 
1748                 $option = $scan_device->get_option_descriptor($option_seek);
1749                 
1750                 if (!$option->{name}){
1751                         
1752                 } else {
1753                         
1754                         if ($option_name eq $option->{name}){
1755                                 
1756                                 if ($option->{type} eq SANE_TYPE_FIXED){
1757                                         $value = $scan_device->get_option($option_seek);
1758                                         $value = int(0) if !$value;
1759                                 } else {
1760                                         $value = $scan_device->get_option($option_seek);
1761                                 }
1762                                 $option_found = 1;
1763                                 
1764                         }
1765                         
1766                 }
1767                 
1768                 $option_seek++;
1769                 
1770         } until ($option_seek > $option_total || $option_found eq 1);
1772         return $value;
1773         
1776 sub xestiascan_scan_setscannervalue{
1777 #################################################################################
1778 # xestiascan_scan_setscannervalue: Gets a specific option value.                #
1779 #                                                                               #
1780 # Usage:                                                                        #
1781 #                                                                               #
1782 # xestiascan_scan_setscannervalue(name, value);                                 #
1783 #                                                                               #
1784 # name                  Specifies the name of the option.                       #
1785 # value                 Specifies the value of the option.                      #
1786 #################################################################################
1787         
1788         my $option_name         = shift;
1789         my $option_value        = shift;
1790         
1791         my $option_total = $scan_device->get_option(0);
1792         my $option_seek = 0;
1793         
1794         my $option_found = 0;
1795         
1796         my $option_final_value;
1797         
1798         my $option;
1799         
1800         do {
1801                 
1802                 $option = $scan_device->get_option_descriptor($option_seek);
1803                 
1804                 if ($option_name eq $option->{name}){
1805                         
1806                         if ($option->{type} eq SANE_TYPE_FIXED){
1808                                 $scan_device->set_option($option_seek, $option_value) or return;
1809                                 
1810                         } else {
1811                         
1812                                 $scan_device->set_option($option_seek, $option_value) or return;
1813                                 
1814                         }
1815                         
1816                         $option_found = 1;
1817                         
1818                 }
1819                 
1820                 $option_seek++;
1821                 
1822         } until ($option_seek > $option_total || $option_found eq 1);
1823         
1824         return 1;       # Setting set successfully.
1825         
1828 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