]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/offline/offline-upload.pl
batch of scripts for handling the processing of offline content
[Evergreen.git] / Open-ILS / src / offline / offline-upload.pl
1 #!/usr/bin/perl
2 use strict; use warnings;
3
4 # --------------------------------------------------------------------
5 #  Uploads offline action files
6 #       pending files go into $base_dir/pending/<org>/<ws>.log
7 #       completed transactions go into $base_dir/archive/<org>/YYYMMDDHHMM/<ws>.log
8 # --------------------------------------------------------------------
9
10 our $U;
11 our %config;
12 our $cgi;
13 our $base_dir;
14 our $logger;
15 my $org;
16 require 'offline-lib.pl';
17
18 if( $cgi->param('file') ) { 
19         &load_file(); 
20         &handle_success("File Upload Succeeded<br/><br/>".
21         "<a href='offline-execute.pl?org=$org'>Execute Scripts for org $org</a>");
22 } else {
23         &display_upload(); 
24 }
25
26
27 # --------------------------------------------------------------------
28 # Use this for testing manual uploads
29 # --------------------------------------------------------------------
30 sub display_upload {
31
32         my $ws  = $cgi->param('ws');
33         my $ses = $cgi->param('ses');
34
35         handle_error("Missing data in upload.  We need ws and ses") 
36                 unless ($ws and $ses);
37
38         print "content-type: text/html\n\n";
39         print <<"       HTML";
40         <html>
41                 <head>
42                         <title>Offline Upload Server</title>
43                         <style type='text/css'>
44                                 input { margin: 5px;' }
45                         </style>
46                 </head>
47                 <body>
48                         <div style='margin-top: 50px; text-align: center;'>
49                                 <form action='offline-upload.pl' method='post' enctype='multipart/form-data'>
50                                         <b>Testing</b><br/><br/>
51                                         <b> - Select an offline file to upload - </b><br/><br/>
52                                         <input type='file' name='file'> </input>
53                                         <input type='submit' name='Submit' value='Upload'> </input>
54                                         <input type='hidden' name='ws' value='$ws'> </input>
55                                         <input type='hidden' name='ses' value='$ses'> </input>
56                                 </form>
57                         </div>
58                 </body>
59         </html>
60         HTML
61 }
62
63
64
65 sub load_file() {
66
67         my $wsname      = $cgi->param('ws');
68         my $ses         = $cgi->param('ses');
69         my $filehandle = $cgi->upload('file');
70
71         my $ws = fetch_workstation($wsname);
72         $org = $ws->owning_lib;
73         my $dir = get_pending_dir($org);
74         my $output = "$dir/$wsname.log";
75         my $lock = "$dir/lock";
76
77         handle_error("Offline batch in process for this location.  Please try again later." ) if( -e $lock );
78         handle_error("File $output already exists" ) if( -e $output );
79
80         $logger->debug("offline: Writing log file $output");
81         open(FILE, ">$output");
82         while( <$filehandle> ) { print FILE; }
83 }
84
85
86
87
88