]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/offline/offline-upload.pl
more work done
[working/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 ($ORG, $META_FILE, $LOCK_FILE, $TIME_DELTA, $MD5_SUM, $PRINT_HTML,
11         $AUTHTOKEN, $REQUESTOR, $U, %config, $cgi, $base_dir, $logger);
12
13 require 'offline-lib.pl';
14
15 if( $cgi->param('file') ) { 
16         &load_file(); 
17         &handle_event(OpenILS::Event->new('SUCCESS'));
18 } else {
19         &display_upload(); 
20 }
21
22 # --------------------------------------------------------------------
23 # Loads the POSTed file and writes the contents to disk
24 # --------------------------------------------------------------------
25 sub load_file() {
26
27         my $wsname      = $cgi->param('ws');
28         my $filehandle = $cgi->upload('file');
29
30         my $ws = fetch_workstation($wsname);
31         $ORG = $ws->owning_lib;
32
33         # make sure we have upload priveleges
34         my $evt = $U->check_perms($REQUESTOR->id, $ORG, 'OFFLINE_UPLOAD');
35         handle_event($evt) if $evt;
36
37         my $dir = get_pending_dir();
38         my $output = "$dir/$wsname.log";
39         my $lock = "$dir/$LOCK_FILE";
40
41         &handle_event(OpenILS::Event->new('OFFLINE_SESSION_ACTIVE')) if( -e $lock );
42         &handle_event(OpenILS::Event->new('OFFLINE_SESSION_FILE_EXISTS')) if( -e $output );
43
44         $logger->debug("offline: Writing log file $output");
45         open(FILE, ">$output");
46         while( <$filehandle> ) { print FILE; }
47         close(FILE);
48
49         # Append the metadata for this workstations upload
50         append_meta( {
51                 requestor       => $REQUESTOR->id, 
52                 timestamp       => time, 
53                 workstation => $wsname,
54                 log                     => $output, 
55                 delta                   => $TIME_DELTA}, 
56                 );
57 }
58
59
60 # --------------------------------------------------------------------
61 # Use this for testing manual uploads
62 # --------------------------------------------------------------------
63 sub display_upload {
64         my $ws  = $cgi->param('ws') || "";
65
66         print_html(
67                 title => "Offline Upload",
68                 body => <<"             HTML");
69                         <center>
70                                 <form action='offline-upload.pl' method='post' enctype='multipart/form-data'>
71                                         <b> - Select an offline file to upload - </b><br/><br/>
72                                         <table>
73                                                 <tbody>
74                                                         <tr>
75                                                                 <td>File to Upload: </td>
76                                                                 <td><input type='file' name='file'> </input></td>
77                                                         </tr>
78                                                         <tr>
79                                                                 <td>Workstation Name: </td>
80                                                                 <td><input type='text' name='ws' value='$ws'> </input></td>
81                                                         </tr>
82                                                         <tr>
83                                                                 <td>Time Delta: </td>
84                                                                 <td><input type='text' name='delta' value='$TIME_DELTA'> </input></td>
85                                                         </tr>
86                                                         <tr>
87                                                                 <td colspan='2' align='center'><input type='submit' name='Submit' value='Upload'> </input></td>
88                                                         </tr>
89                                                 </tbody>
90                                         </table>
91                                         <input type='hidden' name='ses' value='$AUTHTOKEN'> </input>
92                                         <input type='hidden' name='html' value='$PRINT_HTML'> </input>
93                                 </form>
94                         </center>
95                 HTML
96 }
97
98
99
100
101
102
103