/[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.7 - (hide annotations)
Thu Feb 15 08:35:22 2001 UTC (23 years, 2 months ago) by dpavlin
Branch: MAIN
Changes since 1.6: +9 -0 lines
File MIME type: text/plain
ispravno nala¾enje osobe

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 dpavlin 1.4 open(WHO,"who am i |") || die "who am i? $!";
35     my $db_user=<WHO>;
36     chomp $db_user;
37 dpavlin 1.5 $db_user=~s/\s.+$//g; # OSF obri¹i sve iza logina
38     $db_user=~s/^[^!]+!//g; # Linux obri¹i hostname
39 dpavlin 1.4 close(WHO);
40 dpavlin 1.7 if ($db_user eq "") {
41     open(ID,"id |") || die "id: $!";
42     my $foo=<ID>; chomp $foo;
43     if ($foo=~/uid=\d+\((\w+)\)/) {
44     $db_user=$1;
45     } else {
46     die "can't locate who is local user!";
47     }
48     }
49 dpavlin 1.4
50     open(HOSTNAME,"hostname |") || die "hostname: $!";
51     my $hostname=<HOSTNAME>;
52     chomp $hostname;
53     close(HOSTNAME);
54    
55 dpavlin 1.5 $sth = $dbh->prepare("select ko_id from unix2ko where login='$db_user' and host='$hostname'") || die $dbh->errstr();
56 dpavlin 1.4 $sth->execute() || die $sth->errstr();
57     my ($ko_id)=$sth->fetchrow_array;
58 dpavlin 1.5 die "Ne mogu naæi odgovarajuæu kontakt osobu u tablici unix2ko!\n\tlogin=$db_user host=$hostname\n" if (!defined($ko_id));
59    
60     print "kontakt_osoba_id (koja je pokrenula skriptu): $ko_id\n" if ($debug);
61 dpavlin 1.4
62 dpavlin 1.1 #$sth = $dbh->prepare("select id from kontakt_osobe where e_mail like '%hana%'") || die $dbh->errstr();
63     #$sth->execute() || die $sth->errstr();
64     #($kontakt_osoba_id) = $sth->fetchrow_array();
65    
66     $sth = $dbh->prepare("select max(id) from last_print") || die $dbh->errstr();
67     $sth->execute() || die $sth->errstr();
68     my ($last_print_id) = $sth->fetchrow_array();
69    
70     my $sql;
71    
72     if (! defined($print_only_id)) {
73     $sql="select osoba_id,max(status_tip_id) from status where osoba_id > $last_print_id group by osoba_id";
74     } else {
75 dpavlin 1.3 $sql="select osoba_id,status_tip_id from status where osoba_id in ($print_only_id) and status_tip_id=3";
76 dpavlin 1.1 }
77    
78     $sth = $dbh->prepare("$sql") || die "$sql ",$dbh->errstr();
79     $sth->execute() || die "$sql ",$sth->errstr();
80    
81     #my $out_tex="out.tex";
82 dpavlin 1.6 my $out_tex="out-$$.tex";
83 dpavlin 1.1
84     open(IN,"obavjest.tex") || die "obavjest.tex: $!";
85     open(OUT,"> $out_tex") || die "$out_tex: $!";
86     while(<IN>) {
87     print OUT $_;
88     last if (/^%--begin_of_page--/);
89     }
90     my $begin_pos=tell(IN);
91    
92     my @osoba_id_za_print;
93     my $max_osoba_id = 0;
94    
95     while (my ($osoba_id,$status_tip_id) = $sth->fetchrow_array() ) {
96     if ($status_tip_id == 3) { # 3==otvoren (zadnji status)
97     push @osoba_id_za_print,$osoba_id;
98     $max_osoba_id = $osoba_id if ($osoba_id > $max_osoba_id);
99     }
100     }
101    
102     print "Raèuna za insprintati: ",$#osoba_id_za_print+1,"\n";
103     exit if ($#osoba_id_za_print+1 == 0);
104    
105     $sth = $dbh->prepare("
106     select osobe.id,ime,prezime,tel,lokacije.naziv,
107     org_jed.naziv,org_pod_jed.pod_naziv,
108     lok_racunala,login,passwd,alias,sifra,
109 dpavlin 1.2 objekt,kat,soba,z_rac,kontakt_osoba_id,umrezavanje
110 dpavlin 1.1 from osobe,racuni,e_mail
111     where osobe.id in (".join(",",@osoba_id_za_print).")
112     and lokacija_id=lokacije.id and org_jed_id=org_jed.id
113     and org_pod_jed_id=org_pod_jed.pod_id
114     and racuni.osoba_id=osobe.id and e_mail.osoba_id=osobe.id
115     ") || die $dbh->errstr();
116     $sth->execute() || die $sth->errstr();
117    
118    
119     while (my @arr = $sth->fetchrow_array() ) {
120     print join("|",@arr),"\n";
121    
122 dpavlin 1.5 if (!$debug) {
123     $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($arr[0],$ko_id,'now'::datetime,5)") || die $dbh->errstr();
124     }
125 dpavlin 1.1
126     seek(IN,$begin_pos,0);
127     while(<IN>) {
128     s/--id--/$arr[0]/g;
129     $arr[0]=~s/^\s+//g;
130     $arr[0]=~s/\s+$//g;
131     s/--ime--/$arr[1]/g;
132    
133     $arr[1]=~s/^\s+//g;
134     $arr[1]=~s/\s+$//g;
135     s/--prezime--/$arr[2]/g;
136     s/--tel--/$arr[3]/g;
137     s/--lok--/$arr[4]/g;
138     s/--orgjed--/$arr[5]/g;
139     s/--orgpodjed--/$arr[6]/g;
140     s/--lokrac--/$arr[7]/g;
141     s/--login--/$arr[8]/g;
142    
143    
144     # ovo mora iæi dva puta da bi pretvorio sve znakove
145     # koji LaTeX-u imaju specijalno znaèenje
146     $arr[9]=~ s/([^\\])([%&\$#])/$1\\$2/g;
147     $arr[9]=~ s/([^\\])([%&\$#])/$1\\$2/g;
148     $arr[9]=~ s/^([%&\$#])/\\$1/g;
149    
150     s/--passwd--/$arr[9]/g;
151    
152     $arr[10]=~s/^\s+//g;
153     $arr[10]=~s/\s+$//g;
154     s/--email--/$arr[10]/g;
155    
156     $arr[11]=~s/^\s+//g;
157     $arr[11]=~s/\s+$//g;
158     s/--sifra--/$arr[11]/g;
159    
160     s/--obj--/$arr[12]/g;
161     s/--kat--/$arr[13]/g;
162     s/--soba--/$arr[14]/g;
163     s/--zrac--/$arr[15]/g;
164     my $ean=sprintf("2%06d%05d",$arr[11],$arr[0]);
165     s/--ean--/$ean/g;
166 dpavlin 1.2
167     if ($arr[17] == 1) {
168     s/--umrezavanje--/\\bf{Potrebno je umre¾avanje}/gi;
169     } else {
170     s/--umrezavanje--/{\\small Raèunalo je umre¾eno}/gi;
171     }
172    
173 dpavlin 1.1 print OUT $_;
174    
175     if (/^%--insert_status--/) {
176     my $sth2 = $dbh->prepare("select
177     datum,status_tip.opis,
178     kontakt_osobe.ime||' '||kontakt_osobe.prezime
179     from status,status_tip
180     where status_tip_id=status_tip.id
181     and kontakt_osobe.id=kontakt_osoba_id
182     and status.osoba_id=$arr[0]
183     order by datum
184     ") || die $dbh->errstr();
185     $sth2->execute() || die $sth2->errstr();
186     while (my @arr2 = $sth2->fetchrow_array() ) {
187     print OUT join(" & ",@arr2)," \\\\ \n";
188     }
189     }
190     last if (/^%--end_of_page--/);
191     }
192     print OUT "\\newpage\n";
193    
194     }
195    
196     $dbh->do("insert into last_print values ('now'::datetime,$max_osoba_id)") if (!$print_only_id && !$debug);
197    
198     $sth->finish;
199    
200     while(<IN>) {
201     print OUT $_;
202     }
203     close(OUT);
204     close(IN);
205    
206     my $out_no_ext=$out_tex;
207     $out_no_ext=~s/\.tex//;
208    
209     my $path=$0;
210     $path=~s/\/[^\/]+//g;
211    
212 dpavlin 1.2 if (!$debug) {
213     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";
214     } else {
215     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";
216    
217     }

  ViewVC Help
Powered by ViewVC 1.1.26