Letters / alert system, continuing...
[wip/koha-chris_n.git] / bull / subscription-detail.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Koha;
7 use C4::Date;
8 use C4::Bull;
9 use C4::Output;
10 use C4::Interface::CGI::Output;
11 use C4::Context;
12 use HTML::Template;
13
14 my $query = new CGI;
15 my $op = $query->param('op');
16 my $dbh = C4::Context->dbh;
17 my $sth;
18 # my $id;
19 my ($template, $loggedinuser, $cookie, $subs);
20 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
21         $dow, $numberlength, $weeklength, $monthlength,
22         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
23         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
24         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
25         $numberingmethod, $status, $biblionumber, $bibliotitle, $notes,$letter);
26
27 $subscriptionid = $query->param('subscriptionid');
28
29 if ($op eq 'modsubscription') {
30         $auser = $query->param('user');
31         $librarian => $query->param('librarian'),
32         $cost = $query->param('cost');
33         $aqbooksellerid = $query->param('aqbooksellerid');
34         $biblionumber = $query->param('biblionumber');
35         $aqbudgetid = $query->param('aqbudgetid');
36         $startdate = format_date_in_iso($query->param('startdate'));
37         $periodicity = $query->param('periodicity');
38         $dow = $query->param('dow');
39         $numberlength = $query->param('numberlength');
40         $weeklength = $query->param('weeklength');
41         $monthlength = $query->param('monthlength');
42         $add1 = $query->param('add1');
43         $every1 = $query->param('every1');
44         $whenmorethan1 = $query->param('whenmorethan1');
45         $setto1 = $query->param('setto1');
46         $lastvalue1 = $query->param('lastvalue1');
47         $innerloop1 = $query->param('innerloop1');
48         $add2 = $query->param('add2');
49         $every2 = $query->param('every2');
50         $whenmorethan2 = $query->param('whenmorethan2');
51         $setto2 = $query->param('setto2');
52         $lastvalue2 = $query->param('lastvalue2');
53         $innerloop2 = $query->param('innerloop2');
54         $add3 = $query->param('add3');
55         $every3 = $query->param('every3');
56         $whenmorethan3 = $query->param('whenmorethan3');
57         $setto3 = $query->param('setto3');
58         $lastvalue3 = $query->param('lastvalue3');
59         $innerloop3 = $query->param('innerloop3');
60         $numberingmethod = $query->param('numberingmethod');
61         $status = 1;
62         $notes = $query->param('notes');
63         $letter = $query->param('letter');
64     
65         &modsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
66                                         $periodicity,$dow,$numberlength,$weeklength,$monthlength,
67                                         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
68                                         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
69                                         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
70                                         $numberingmethod, $status, $biblionumber, $notes, $letter, $subscriptionid);
71 }
72
73 if ($op eq 'del') {
74         &delsubscription($subscriptionid);
75         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=../bull-home.pl\"></html>";
76         exit;
77
78 }
79 my $subs = &getsubscription($subscriptionid);
80 my ($totalissues,@serialslist) = getserials($subscriptionid);
81 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
82
83 ($template, $loggedinuser, $cookie)
84 = get_template_and_user({template_name => "bull/subscription-detail.tmpl",
85                                 query => $query,
86                                 type => "intranet",
87                                 authnotrequired => 0,
88                                 flagsrequired => {catalogue => 1},
89                                 debug => 1,
90                                 });
91
92 my ($user, $cookie, $sessionID, $flags) = checkauth($query, 0, {catalogue => 1}, "intranet");
93
94 $template->param(
95         user => $subs->{auser},
96         librarian => $subs->{librarian},
97         aqbooksellerid => $subs->{aqbooksellerid},
98         aqbooksellername => $subs->{aqbooksellername},
99         cost => $subs->{cost},
100         aqbudgetid => $subs->{aqbudgetid},
101         bookfundid => $subs->{bookfundid},
102         startdate => format_date($subs->{startdate}),
103         periodicity => $subs->{periodicity},
104         dow => $subs->{dow},
105         numberlength => $subs->{numberlength},
106         weeklength => $subs->{weeklength},
107         monthlength => $subs->{monthlength},
108         add1 => $subs->{add1},
109         every1 => $subs->{every1},
110         whenmorethan1 => $subs->{whenmorethan1},
111         innerloop1 => $subs->{innerloop1},
112         setto1 => $subs->{setto1},
113         lastvalue1 => $subs->{lastvalue1},
114         add2 => $subs->{add2},
115         every2 => $subs->{every2},
116         whenmorethan2 => $subs->{whenmorethan2},
117         setto2 => $subs->{setto2},
118         lastvalue2 => $subs->{lastvalue2},
119         innerloop2 => $subs->{innerloop2},
120         add3 => $subs->{add3},
121         every3 => $subs->{every3},
122         whenmorethan3 => $subs->{whenmorethan3},
123         setto3 => $subs->{setto3},
124         lastvalue3 => $subs->{lastvalue3},
125         innerloop3 => $subs->{innerloop3},
126         numberingmethod => $subs->{numberingmethod},
127         status => $subs->{status},
128         biblionumber => $subs->{biblionumber},
129         bibliotitle => $subs->{bibliotitle},
130         notes => $subs->{notes},
131         letter => $subs->{letter},
132         subscriptionid => $subs->{subscriptionid},
133         serialslist => \@serialslist,
134         totalissues => $totalissues,
135         );
136 $template->param(
137                         "periodicity$subs->{periodicity}" => 1,
138                         "arrival$subs->{dow}" => 1,
139                         );
140
141 output_html_with_http_headers $query, $cookie, $template->output;