]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/offline/offline-status.pl
added basic status cgi - more work here...
[Evergreen.git] / Open-ILS / src / offline / offline-status.pl
1 #!/usr/bin/perl
2 use strict; use warnings;
3
4 # --------------------------------------------------------------------
5 # Loads the offline script files for a given org, sorts and runs the 
6 # scripts, and returns the exception list
7 # --------------------------------------------------------------------
8
9 our $U;
10 our $logger;
11 require 'offline-lib.pl';
12 &execute();
13
14
15 sub execute {
16         my $evt = $U->check_perms(&offline_requestor->id, &offline_org, 'OFFLINE_VIEW');
17
18         handle_event($evt) if $evt;
19         
20         my $html        = &offline_cgi->param('html');
21         my $wslist = &gather_workstations;
22
23         if( $html ) { 
24                 &report_html($wslist); 
25
26         } else { 
27                 &report_json($wslist); 
28         }
29 }
30
31 # XXX Make me search by session key ...
32
33
34 # --------------------------------------------------------------------
35 # Collects a list of workstations that have pending files
36 # --------------------------------------------------------------------
37 sub gather_workstations {
38         my $dir = &offline_pending_dir;
39         my @files =  <$dir/*.log>;
40         $_ =~ s/\.log//og for @files; # remove .log
41         $_ =~ s#/.*/(\w+)#$1#og for @files; # remove leading file path
42         return \@files;
43 }
44
45
46
47 # --------------------------------------------------------------------
48 # Reports the workstations and their results as JSON
49 # --------------------------------------------------------------------
50 sub report_json { 
51         my $wslist = shift;
52         my @data;
53         my $meta = &offline_read_meta;
54         my $results = &offline_read_results;
55         for my $ws (@$wslist) {
56                 my ($m) = grep { $_ and $_->{'log'} and $_->{'log'} =~ m#/.*/$ws.log# } @$meta;
57                 my @res = grep { $_->{command}->{_workstation} eq $ws } @$results;
58                 delete $m->{'log'};
59                 push( @data, { meta => $m, workstation => $ws, results =>  \@res } );
60         }
61         &offline_handle_json(\@data);
62 }
63
64