perl files of the serial modul
[koha.git] / bull / subscription-add.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 HTML::Template;
10 use C4::Bull;
11
12 my $query = new CGI;
13 my $op = $query->param('op');
14 my $dbh = C4::Context->dbh;
15 if ($op eq 'addsubscription')
16 {
17    my $auser = $query->param('user');
18   my $supplier = $query->param('supplier');
19    my $cost = $query->param('cost');
20    my $budget = $query->param('budget'); 
21    my $begin = $query->param('begin');
22    my $frequency = $query->param('frequency');
23    my $dow = $query->param('arrival');
24     my $numberlength = $query->param('numberlength');
25     my $weeklength = $query->param('weeklength');
26     my $monthlength = $query->param('monthlength');
27     my $X = $query->param('X');
28     my $Xstate = $query->param('Xstate');
29     my $Xfreq = $query->param('Xfreq');
30     my $Xstep = $query->param('Xstep');
31     my $Y = $query->param('Y');
32     my $Ystate = $query->param('Ystate');
33     my $Yfreq = $query->param('Yfreq');
34     my $Ystep = $query->param('Ystep');
35     my $Z = $query->param('Z');
36     my $Zstate = $query->param('Zstate');
37     my $Zfreq = $query->param('Zfreq');
38     my $Zstep = $query->param('Zstep');
39     my $sequence = $query->param('sequence');
40     my $arrivalplanified = $query->param('arrivalplanified');
41     my $status = 1;
42     my $perioid = $query->param('biblioid');
43     my $notes = $query->param('notes');
44
45     my $sth=$dbh->prepare("insert into subscription (librarian, aqbooksellerid,cost,aqbudgetid,startdate, periodicity,dow,numberlength,weeklength,monthlength,seqnum1,startseqnum1,seqtype1,freq1,step1,seqnum2,startseqnum2,seqtype2,freq2, step2, seqnum3,startseqnum3,seqtype3, freq3, step3,numberingmethod, arrivalplanified, status, perioid, notes, pos1, pos2, pos3) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, 0, 0, 0)");
46  $sth->execute($auser,$supplier,$cost,$budget,$begin,$frequency,$dow,$numberlength,$weeklength,$monthlength,$X,$X,$Xstate,$Xfreq, $Xstep,$Y,$Y,$Ystate,$Yfreq, $Ystep,$Z,$Z,$Zstate,$Zfreq, $Zstep, $sequence, $arrivalplanified, $status, $perioid, $notes);
47    $sth = $dbh->prepare("select subscriptionid from subscription where perioid = ? and numberingmethod = ?");
48    $sth->execute($perioid, $sequence);
49    my $subid = $sth->fetchrow;
50    
51    $sth = $dbh->prepare("insert into subscriptionhistory (biblioid, subscriptionid, startdate, enddate, missinglist, recievedlist, opacnote, librariannote) values (?,?,?,?,?,?,?,?)");
52    $sth->execute($perioid, $subid, $begin, 0, "", "", 0, $notes);
53    $sth = $dbh->prepare("insert into serial (biblionumber, subscriptionid, serialseq, status, planneddate) values (?,?,?,?,?)");
54
55    $sth->execute($perioid, $subid, Initialize_Sequence($sequence, $X, $Xstate, $Xfreq, $Xstep, $Y, $Ystate, $Yfreq, $Ystep, $Z, $Zstate, $Zfreq, $Zstep), $status, C4::Bull::Find_Next_Date());
56 # biblionumber,
57 # subscriptionid,
58 # startdate, enddate,
59 # missinglist,
60 # recievedlist,
61 # opacnote,
62 # librariannote
63   $sth->finish;
64
65     
66     
67 }
68 my ($template, $loggedinuser, $cookie)
69 = get_template_and_user({template_name => "bull/subscription-add.tmpl",
70                                 query => $query,
71                                 type => "intranet",
72                                 authnotrequired => 0,
73                                 flagsrequired => {catalogue => 1},
74                                 debug => 1,
75                                 });
76
77         my ($user, $cookie, $sessionID, $flags)
78                 = checkauth($query, 0, {catalogue => 1}, "intranet");
79         $template->param(
80                 user             => $user,
81                 );
82 output_html_with_http_headers $query, $cookie, $template->output;