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 in ($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,umrezavanje |
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 |
|
137 |
if ($arr[17] == 1) { |
138 |
s/--umrezavanje--/\\bf{Potrebno je umre¾avanje}/gi; |
139 |
} else { |
140 |
s/--umrezavanje--/{\\small Raèunalo je umre¾eno}/gi; |
141 |
} |
142 |
|
143 |
print OUT $_; |
144 |
|
145 |
if (/^%--insert_status--/) { |
146 |
my $sth2 = $dbh->prepare("select |
147 |
datum,status_tip.opis, |
148 |
kontakt_osobe.ime||' '||kontakt_osobe.prezime |
149 |
from status,status_tip |
150 |
where status_tip_id=status_tip.id |
151 |
and kontakt_osobe.id=kontakt_osoba_id |
152 |
and status.osoba_id=$arr[0] |
153 |
order by datum |
154 |
") || die $dbh->errstr(); |
155 |
$sth2->execute() || die $sth2->errstr(); |
156 |
while (my @arr2 = $sth2->fetchrow_array() ) { |
157 |
print OUT join(" & ",@arr2)," \\\\ \n"; |
158 |
} |
159 |
} |
160 |
last if (/^%--end_of_page--/); |
161 |
} |
162 |
print OUT "\\newpage\n"; |
163 |
|
164 |
} |
165 |
|
166 |
$dbh->do("insert into last_print values ('now'::datetime,$max_osoba_id)") if (!$print_only_id && !$debug); |
167 |
|
168 |
$sth->finish; |
169 |
|
170 |
while(<IN>) { |
171 |
print OUT $_; |
172 |
} |
173 |
close(OUT); |
174 |
close(IN); |
175 |
|
176 |
my $out_no_ext=$out_tex; |
177 |
$out_no_ext=~s/\.tex//; |
178 |
|
179 |
my $path=$0; |
180 |
$path=~s/\/[^\/]+//g; |
181 |
|
182 |
if (!$debug) { |
183 |
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"; |
184 |
} else { |
185 |
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"; |
186 |
|
187 |
} |