/[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.4 - (show annotations)
Wed May 31 14:32:39 2000 UTC (23 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.3: +16 -1 lines
File MIME type: text/plain
zapisivanje kontakt osobe koja je pokrenula skriptu u bazu

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

  ViewVC Help
Powered by ViewVC 1.1.26