/[informatika.old]/print/print.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /print/print.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Wed Apr 12 08:10:24 2000 UTC (24 years ago) by dpavlin
Branch: MAIN
File MIME type: text/plain
alati za ispis izvje¹taja

1 dpavlin 1.1 #!/usr/local/bin/perl -w
2    
3     # ispisuje korisnièke obavijesti iz baze
4     #
5     # upotreba: print.pl [osoba_id]
6     #
7     # ako se ne navede osoba_id onda se printaju *SVI* zahtjevi koji jo¹
8     # nisu isprintani
9    
10     # 2000-03-16 Dobrica Pavlinusic <dpavlin@pliva.hr>
11     # 2000-03-17 DbP dodatak printanja samo jedne osobe
12     # 2000-03-20 DbP last_print tablica
13    
14     use strict;
15    
16     use DBI;
17    
18     my $debug=0;
19    
20     my $print_only_id;
21    
22     if (defined($ARGV[0])) {
23     $print_only_id = $ARGV[0];
24     print "Ispisujem samo podatke za osobu id: $print_only_id\n";
25     } else {
26     undef $print_only_id;
27     }
28    
29     my $dbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr;
30     $dbh->do("set datestyle = 'german'") || die $dbh->errstr();
31    
32     my $sth;
33    
34     #$sth = $dbh->prepare("select id from kontakt_osobe where e_mail like '%hana%'") || die $dbh->errstr();
35     #$sth->execute() || die $sth->errstr();
36     #($kontakt_osoba_id) = $sth->fetchrow_array();
37    
38     $sth = $dbh->prepare("select max(id) from last_print") || die $dbh->errstr();
39     $sth->execute() || die $sth->errstr();
40     my ($last_print_id) = $sth->fetchrow_array();
41    
42     my $sql;
43    
44     if (! defined($print_only_id)) {
45     $sql="select osoba_id,max(status_tip_id) from status where osoba_id > $last_print_id group by osoba_id";
46     } else {
47     $sql="select osoba_id,status_tip_id from status where osoba_id=$print_only_id and status_tip_id=3";
48     }
49    
50     $sth = $dbh->prepare("$sql") || die "$sql ",$dbh->errstr();
51     $sth->execute() || die "$sql ",$sth->errstr();
52    
53     #my $out_tex="out.tex";
54     my $out_tex="$0-out-$$.tex";
55    
56     open(IN,"obavjest.tex") || die "obavjest.tex: $!";
57     open(OUT,"> $out_tex") || die "$out_tex: $!";
58     while(<IN>) {
59     print OUT $_;
60     last if (/^%--begin_of_page--/);
61     }
62     my $begin_pos=tell(IN);
63    
64     my @osoba_id_za_print;
65     my $max_osoba_id = 0;
66    
67     while (my ($osoba_id,$status_tip_id) = $sth->fetchrow_array() ) {
68     if ($status_tip_id == 3) { # 3==otvoren (zadnji status)
69     push @osoba_id_za_print,$osoba_id;
70     $max_osoba_id = $osoba_id if ($osoba_id > $max_osoba_id);
71     }
72     }
73    
74     print "Raèuna za insprintati: ",$#osoba_id_za_print+1,"\n";
75     exit if ($#osoba_id_za_print+1 == 0);
76    
77     $sth = $dbh->prepare("
78     select osobe.id,ime,prezime,tel,lokacije.naziv,
79     org_jed.naziv,org_pod_jed.pod_naziv,
80     lok_racunala,login,passwd,alias,sifra,
81     objekt,kat,soba,z_rac,kontakt_osoba_id
82     from osobe,racuni,e_mail
83     where osobe.id in (".join(",",@osoba_id_za_print).")
84     and lokacija_id=lokacije.id and org_jed_id=org_jed.id
85     and org_pod_jed_id=org_pod_jed.pod_id
86     and racuni.osoba_id=osobe.id and e_mail.osoba_id=osobe.id
87     ") || die $dbh->errstr();
88     $sth->execute() || die $sth->errstr();
89    
90    
91     while (my @arr = $sth->fetchrow_array() ) {
92     print join("|",@arr),"\n";
93    
94     $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($arr[0],3,'now'::datetime,5)") if (!$debug);
95    
96     seek(IN,$begin_pos,0);
97     while(<IN>) {
98     s/--id--/$arr[0]/g;
99     $arr[0]=~s/^\s+//g;
100     $arr[0]=~s/\s+$//g;
101     s/--ime--/$arr[1]/g;
102    
103     $arr[1]=~s/^\s+//g;
104     $arr[1]=~s/\s+$//g;
105     s/--prezime--/$arr[2]/g;
106     s/--tel--/$arr[3]/g;
107     s/--lok--/$arr[4]/g;
108     s/--orgjed--/$arr[5]/g;
109     s/--orgpodjed--/$arr[6]/g;
110     s/--lokrac--/$arr[7]/g;
111     s/--login--/$arr[8]/g;
112    
113    
114     # ovo mora iæi dva puta da bi pretvorio sve znakove
115     # koji LaTeX-u imaju specijalno znaèenje
116     $arr[9]=~ s/([^\\])([%&\$#])/$1\\$2/g;
117     $arr[9]=~ s/([^\\])([%&\$#])/$1\\$2/g;
118     $arr[9]=~ s/^([%&\$#])/\\$1/g;
119    
120     s/--passwd--/$arr[9]/g;
121    
122     $arr[10]=~s/^\s+//g;
123     $arr[10]=~s/\s+$//g;
124     s/--email--/$arr[10]/g;
125    
126     $arr[11]=~s/^\s+//g;
127     $arr[11]=~s/\s+$//g;
128     s/--sifra--/$arr[11]/g;
129    
130     s/--obj--/$arr[12]/g;
131     s/--kat--/$arr[13]/g;
132     s/--soba--/$arr[14]/g;
133     s/--zrac--/$arr[15]/g;
134     my $ean=sprintf("2%06d%05d",$arr[11],$arr[0]);
135     s/--ean--/$ean/g;
136     print OUT $_;
137    
138     if (/^%--insert_status--/) {
139     my $sth2 = $dbh->prepare("select
140     datum,status_tip.opis,
141     kontakt_osobe.ime||' '||kontakt_osobe.prezime
142     from status,status_tip
143     where status_tip_id=status_tip.id
144     and kontakt_osobe.id=kontakt_osoba_id
145     and status.osoba_id=$arr[0]
146     order by datum
147     ") || die $dbh->errstr();
148     $sth2->execute() || die $sth2->errstr();
149     while (my @arr2 = $sth2->fetchrow_array() ) {
150     print OUT join(" & ",@arr2)," \\\\ \n";
151     }
152     }
153     last if (/^%--end_of_page--/);
154     }
155     print OUT "\\newpage\n";
156    
157     }
158    
159     $dbh->do("insert into last_print values ('now'::datetime,$max_osoba_id)") if (!$print_only_id && !$debug);
160    
161     $sth->finish;
162    
163     while(<IN>) {
164     print OUT $_;
165     }
166     close(OUT);
167     close(IN);
168    
169     my $out_no_ext=$out_tex;
170     $out_no_ext=~s/\.tex//;
171    
172     my $path=$0;
173     $path=~s/\/[^\/]+//g;
174    
175     system "$path/codean.pl $out_no_ext.tex $out_no_ext.tex2 && mv $out_no_ext.tex2 $out_no_ext.tex && latex $out_no_ext.tex && dvips $out_no_ext.dvi && lpr $out_no_ext.ps";

  ViewVC Help
Powered by ViewVC 1.1.26