/[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

Contents of /print/print.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Fri Jun 2 07:07:27 2000 UTC (23 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +9 -3 lines
File MIME type: text/plain
popravljena identifikacija osoba na Linux-u

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

  ViewVC Help
Powered by ViewVC 1.1.26