perl files of the serial modul
[wip/koha-chris_n.git] / bull / statecollection.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Interface::CGI::Output;
8 use C4::Context;
9 use C4::Bull;
10 use HTML::Template;
11
12 my $query = new CGI;
13 my $op = $query->param('op');
14 my $dbh = C4::Context->dbh;
15 my $sid = $query->param('subsid');
16 my $ser = $query->param('serial');
17 warn "$ser la valeur du nom du formulaire";
18 if ($op eq 'modsubscriptionhistory')
19 {
20    my $auser = $query->param('user');
21    my $status = $query->param('status');
22    my $waited = $query->param('waited');
23    my $begin = $query->param('begin');
24    my $end = $query->param('end');
25    my $arrived = $query->param('arrived');
26    my $gapped = $query->param('gapped');
27    my $opac = $query->param('opac');
28    my $intra = $query->param('intra');
29
30     my $sth=$dbh->prepare("update subscriptionhistory set startdate=?, enddate=?,missinglist=?, recievedlist=?, opacnote=?, librariannote=? where subscriptionid = ?");
31  $sth->execute($begin, $end, $gapped, $arrived, $opac, $intra, $sid);
32
33    if ($status != 1)
34    {
35        if ($status == 2)
36        {
37            $sth = $dbh->prepare("select recievedlist from subscriptionhistory where subscriptionid = ?");
38            $sth->execute($sid);
39            my $received = $sth->fetchrow;
40            $sth = $dbh->prepare("select * from subscription where subscriptionid = ? ");
41            $sth->execute($sid);
42            my $val = $sth->fetchrow_hashref;
43            $sth = $dbh->prepare("update serial set serialseq = ? where subscriptionid = ? and status = 1");
44            my ($temp, $X, $Y, $Z, $Xpos, $Ypos, $Zpos) = Get_Next_Seq($val->{'numberingmethod'},$val->{'seqnum1'},$val->{'freq1'}, $val->{'step1'}, $val->{'seqtype1'}, $val->{'seqnum2'}, $val->{'freq2'}, $val->{'step2'}, $val->{'seqtype2'}, $val->{'seqnum3'}, $val->{'freq3'}, $val->{'step3'}, $val->{'seqtype3'}, $val->{'pos1'}, $val->{'pos2'}, $val->{'pos3'});
45            $sth->execute($temp, $sid);
46            $sth = $dbh->prepare("update subscription set seqnum1=?, seqnum2=?,seqnum3=?,pos1=?,pos2=?,pos3=? where subscriptionid = ?");
47            $sth->execute($X, $Y, $Z, $Xpos, $Ypos, $Zpos, $sid);
48            $sth = $dbh->prepare("update subscriptionhistory set recievedlist=? where subscriptionid = ?");
49            if (length($received) > 2)
50            {
51                $sth->execute("$received,$waited", $sid);
52            }
53            else
54            {
55                $sth->execute($waited, $sid);
56            }
57            
58        }
59        elsif ($status == 3)
60        {
61            $sth = $dbh->prepare("select missinglist from subscriptionhistory where subscriptionid = ?");
62            $sth->execute($sid);
63            my $missing = $sth->fetchrow;
64            $sth = $dbh->prepare("select * from subscription where subscriptionid = ? ");
65            $sth->execute($sid);
66            my $val = $sth->fetchrow_hashref;
67            $sth = $dbh->prepare("update serial set status = 2 where subscriptionid = ? and status = 1");
68            $sth->execute($sid);
69            $sth = $dbh->prepare("insert into serial (serialseq,subscriptionid,biblionumber,status, planneddate) values (?,?,?,?,?)");
70            my ($temp, $X, $Y, $Z, $Xpos, $Ypos, $Zpos) = Get_Next_Seq($val->{'numberingmethod'},$val->{'seqnum1'},$val->{'freq1'}, $val->{'step1'}, $val->{'seqtype1'}, $val->{'seqnum2'}, $val->{'freq2'}, $val->{'step2'}, $val->{'seqtype2'}, $val->{'seqnum3'}, $val->{'freq3'}, $val->{'step3'}, $val->{'seqtype3'}, $val->{'pos1'}, $val->{'pos2'}, $val->{'pos3'});
71            $sth->execute($temp, $sid, $val->{'biblionumber'}, 1, 0);
72            $sth = $dbh->prepare("update subscription set seqnum1=?, seqnum2=?,seqnum3=?,pos1=?,pos2=?,pos3=? where subscriptionid = ?");
73            $sth->execute($X, $Y, $Z, $Xpos, $Ypos, $Zpos, $sid);
74            $sth = $dbh->prepare("update subscriptionhistory set missinglist=? where subscriptionid = ?");
75            if (length($missing) > 2)
76            {
77                $sth->execute("$missing,$waited", $sid);
78            }
79            else
80            {
81                $sth->execute($waited, $sid);
82            }
83
84        }
85        else
86        {
87            warn ("Error vous avez fait None dans le formulaire receipt\n");
88        }
89    }
90     
91   $sth->finish;
92 }
93 my $sth=$dbh->prepare("select serialseq, status, planneddate from serial where subscriptionid = ? and status = ?");
94 $sth->execute($sid, 1);
95 my $sol = $sth->fetchrow_hashref;
96 my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?");
97 $sth->execute($sid);
98 my $solhistory = $sth->fetchrow_hashref;
99 my ($template, $loggedinuser, $cookie)
100 = get_template_and_user({template_name => "bull/statecollection.tmpl",
101                                 query => $query,
102                                 type => "intranet",
103                                 authnotrequired => 0,
104                                 flagsrequired => {catalogue => 1},
105                                 debug => 1,
106                                 });
107
108         my ($user, $cookie, $sessionID, $flags)
109                 = checkauth($query, 0, {catalogue => 1}, "intranet");
110
111         $template->param(
112                 user             => $user,
113                       serial => $ser,
114                          status  => $sol->{'status'},
115                          waited  => $sol->{'serialseq'},
116                          begin => $solhistory->{'startdate'},
117                          end => $solhistory->{'enddate'},
118                          arrived => $solhistory->{'recievedlist'},
119                          gapped => $solhistory->{'missinglist'},
120                          opac => $solhistory->{'opacnote'},
121                          intra => $solhistory->{'librariannote'},
122                          sid => $sid,
123                 );
124 output_html_with_http_headers $query, $cookie, $template->output;