/[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.8 - (hide annotations)
Fri Jan 25 14:47:50 2002 UTC (22 years, 3 months ago) by dpavlin
Branch: MAIN
Changes since 1.7: +9 -4 lines
File MIME type: text/plain
sap organizacijske jedinice

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 dpavlin 1.8 my $server=3;
105 dpavlin 1.1 $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 dpavlin 1.8 and racuni.osoba_id=osobe.id and racuni.server_id=$server
115     and e_mail.osoba_id=osobe.id
116 dpavlin 1.1 ") || die $dbh->errstr();
117     $sth->execute() || die $sth->errstr();
118    
119    
120     while (my @arr = $sth->fetchrow_array() ) {
121     print join("|",@arr),"\n";
122    
123 dpavlin 1.5 if (!$debug) {
124     $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();
125     }
126 dpavlin 1.1
127 dpavlin 1.8 my $sth2 = $dbh->prepare("select naziv,mt from sap_osobe,sap_oj where sap_oj.sifra_oj = sap_oj and sap_sifra = $arr[11]");
128     $sth2->execute() || die $sth2->errstr();
129     my ($sap_org_jed,$mt) = $sth2->fetchrow_array();
130    
131 dpavlin 1.1 seek(IN,$begin_pos,0);
132     while(<IN>) {
133     s/--id--/$arr[0]/g;
134     $arr[0]=~s/^\s+//g;
135     $arr[0]=~s/\s+$//g;
136     s/--ime--/$arr[1]/g;
137    
138     $arr[1]=~s/^\s+//g;
139     $arr[1]=~s/\s+$//g;
140     s/--prezime--/$arr[2]/g;
141     s/--tel--/$arr[3]/g;
142     s/--lok--/$arr[4]/g;
143 dpavlin 1.8 s/--orgjed--/$sap_org_jed/g;
144     s/--mt--/$mt/g;
145 dpavlin 1.1 s/--lokrac--/$arr[7]/g;
146     s/--login--/$arr[8]/g;
147    
148    
149     # ovo mora iæi dva puta da bi pretvorio sve znakove
150     # koji LaTeX-u imaju specijalno znaèenje
151     $arr[9]=~ s/([^\\])([%&\$#])/$1\\$2/g;
152     $arr[9]=~ s/([^\\])([%&\$#])/$1\\$2/g;
153     $arr[9]=~ s/^([%&\$#])/\\$1/g;
154    
155     s/--passwd--/$arr[9]/g;
156    
157     $arr[10]=~s/^\s+//g;
158     $arr[10]=~s/\s+$//g;
159     s/--email--/$arr[10]/g;
160    
161     $arr[11]=~s/^\s+//g;
162     $arr[11]=~s/\s+$//g;
163     s/--sifra--/$arr[11]/g;
164    
165     s/--obj--/$arr[12]/g;
166     s/--kat--/$arr[13]/g;
167     s/--soba--/$arr[14]/g;
168     s/--zrac--/$arr[15]/g;
169     my $ean=sprintf("2%06d%05d",$arr[11],$arr[0]);
170     s/--ean--/$ean/g;
171 dpavlin 1.2
172     if ($arr[17] == 1) {
173     s/--umrezavanje--/\\bf{Potrebno je umre¾avanje}/gi;
174     } else {
175     s/--umrezavanje--/{\\small Raèunalo je umre¾eno}/gi;
176     }
177    
178 dpavlin 1.1 print OUT $_;
179    
180     if (/^%--insert_status--/) {
181     my $sth2 = $dbh->prepare("select
182     datum,status_tip.opis,
183     kontakt_osobe.ime||' '||kontakt_osobe.prezime
184     from status,status_tip
185     where status_tip_id=status_tip.id
186     and kontakt_osobe.id=kontakt_osoba_id
187     and status.osoba_id=$arr[0]
188     order by datum
189     ") || die $dbh->errstr();
190     $sth2->execute() || die $sth2->errstr();
191     while (my @arr2 = $sth2->fetchrow_array() ) {
192     print OUT join(" & ",@arr2)," \\\\ \n";
193     }
194     }
195     last if (/^%--end_of_page--/);
196     }
197     print OUT "\\newpage\n";
198    
199     }
200    
201     $dbh->do("insert into last_print values ('now'::datetime,$max_osoba_id)") if (!$print_only_id && !$debug);
202    
203     $sth->finish;
204    
205     while(<IN>) {
206     print OUT $_;
207     }
208     close(OUT);
209     close(IN);
210    
211     my $out_no_ext=$out_tex;
212     $out_no_ext=~s/\.tex//;
213    
214     my $path=$0;
215     $path=~s/\/[^\/]+//g;
216    
217 dpavlin 1.2 if (!$debug) {
218     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";
219     } else {
220     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";
221    
222     }

  ViewVC Help
Powered by ViewVC 1.1.26