/[informatika.old]/print/izvjestaj.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

Diff of /print/izvjestaj.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Wed Apr 12 08:10:24 2000 UTC revision 1.9 by dpavlin, Thu Jul 13 08:01:31 2000 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5    my $ic_mail='biljana.gombar@pliva.hr';
6    my $mreze_mail='davorin.koprivnjak@pliva.hr';
7    
8    my $debug=0;
9    
10  use DBI;  use DBI;
11  use POSIX qw(strftime);  use POSIX qw(strftime);
12    
13  my $currdate = strftime "%d.%m.%Y %H:%M:%S", localtime;  $debug++ if ($ARGV[0] eq "-d");
14    
15    print STDERR "Debug mod: output je u /tmp/debug*\n" if ($debug);
16    
17    my $currdate = strftime "%Y-%m-%d %H:%M:%S", localtime;
18    
19  my $html_file=$currdate;  my $html_file=$currdate;
20  $html_file=~s/ /_/g;  $html_file=~s/ /_/g;
21  $html_file="izvjestaji/$html_file.html";  $html_file="izvjestaji/$html_file.html";
22    my $html_date=$currdate;
23    $html_date=~s/ /%20/g;
24    
25    if (! $debug) {
26  open(HTML,"> $html_file") || die "html: $!";  open(HTML,"> $html_file") || die "html: $!";
27  open(MAIL,"|/usr/lib/sendmail biljana.gombar\@pliva.hr,izvjestaji\@support.pliva.hr") || die "sendmail: $!";  open(MAIL,"|/usr/lib/sendmail $ic_mail,$mreze_mail,izvjestaji\@support.pliva.hr") || die "sendmail: $!";
28    } else {
29    open(HTML,"> /tmp/debug.html") || die "html: $!";
30    open(MAIL,"> /tmp/debug.mail") || die "sendmail: $!";
31    }
32    
33  print HTML '  print HTML '
34  <html>  <html>
# Line 26  Subject: otvoreni računi za e-mail Line 42  Subject: otvoreni računi za e-mail
42    
43  ';  ';
44    
45  my $dbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr;  my $host = "host=support.pliva.hr;";
46    
47    open(WHO,"who -m |") || die "who am i? $!";
48    my $db_user=<WHO>;
49    $db_user=~s/[^!]+!//;
50    close(WHO);
51    if (! defined($db_user)) {
52            $db_user="user=dpavlin;"; $host="";     # works on localhost
53    } else {
54            $db_user=~s/\s.+$//g;
55            $db_user="user=$db_user;";
56    }
57    
58    
59    my $dbh = DBI->connect("DBI:Pg:dbname=informatika;${host}${db_user}","","") || die $DBI::errstr;
60  $dbh->do("set datestyle = 'german'") || die $dbh->errstr();  $dbh->do("set datestyle = 'german'") || die $dbh->errstr();
61    
62  my $sth = $dbh->prepare("select id from last_print order by id desc limit 1,1");  my $sth = $dbh->prepare("select id from last_print order by id desc limit 1,1");
# Line 42  $sth->execute() || die $sth->errstr(); Line 72  $sth->execute() || die $sth->errstr();
72  my @osoba_id_za_print;  my @osoba_id_za_print;
73    
74  while (my ($osoba_id,$status_tip_id) = $sth->fetchrow_array() ) {  while (my ($osoba_id,$status_tip_id) = $sth->fetchrow_array() ) {
75          if ($status_tip_id == 5) {      # print          if ($status_tip_id == 5 || $status_tip_id == 8 ) { # print/umrežavanje
76                  push @osoba_id_za_print,$osoba_id;                  push @osoba_id_za_print,$osoba_id;
77          }          }
78  }  }
79    
80  print MAIL "Otvorenih računa: ",$#osoba_id_za_print+1,"  print MAIL "
81  Datum i vrijeme generiranja izvještaja: $currdate  Datum i vrijeme generiranja izvještaja: $currdate
82    
83  Izvještaj se nalazi i na  Izvještaj za štampanje se nalazi na
84  http://support.pliva.hr/$html_file  http://support.pliva.hr/ic.php?datum=$html_date
85  (npr. za ispis na štampaču)  sa potpunim podacima o umrežavanju, lokaciji računala i osobe
86    
87  ";  ";
88  print HTML "Otvorenih računa: ",$#osoba_id_za_print+1,"  print HTML "
89  <br>Datum i vrijeme generiranja izvještaja: $currdate<p>";  <br>Datum i vrijeme generiranja izvještaja: $currdate<p>";
90    
91  $sth = $dbh->prepare("  $sth = $dbh->prepare("
92          select osobe.id,ime,prezime,tel,lokacije.naziv,          select osobe.id,ime,prezime,tel,lokacije.naziv,
93                  org_jed.naziv,org_pod_jed.pod_naziv,                  org_jed.naziv,org_pod_jed.pod_naziv,
94                  lok_racunala,objekt,kat,soba,z_rac                  lok_racunala,objekt,kat,soba,z_rac,umrezavanje,
95                    kontakt_osobe.e_mail,podesavanje
96          from osobe          from osobe
97          where osobe.id in (".join(",",@osoba_id_za_print).")          where osobe.id in (".join(",",@osoba_id_za_print).")
98                  and lokacija_id=lokacije.id and org_jed_id=org_jed.id                  and lokacija_id=lokacije.id and org_jed_id=org_jed.id
99                  and org_pod_jed_id=org_pod_jed.pod_id                  and org_pod_jed_id=org_pod_jed.pod_id
100                    and podesavanje=true
101                    and kontakt_osobe.id=kontakt_osoba_id
102          order by lokacije.naziv,org_jed.naziv          order by lokacije.naziv,org_jed.naziv
103          ") || die $dbh->errstr();          ") || die $dbh->errstr();
104  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
105    
106  my $rbr=1;  my $rbr=1;
107    my $lokacija='';
108    
109  printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n","rbr","id","ime i prezime","tel","lokacija","org.jed");  printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n","rbr","id","ime i prezime","tel","lokacija","org.jed");
110  print HTML '<table border=1>  print HTML '<table border=1>
111  <tr bgcolor="#e0e0f0"><th>rbr</th><th>id</th><th>ime i prezime</th><th>tel</th><th>lokacija</th><th>org.jed</th></tr>  <tr bgcolor="#e0e0f0"><th>rbr</th><th>id</th><th>ime i prezime</th><th>tel</th><th>lokacija</th><th>org.jed</th></tr>
112    <tr bgcolor="#e0e0f0"><th></th><th></th><th>lokacija računala, mreža</th><th>ž</th><th colspan=2>objekat / kat / soba</th></tr>
113  ';  ';
114    
115    my $bgcol='';
116    my $mreza='';
117    my @za_ic;
118    my %mail4ko;
119    
120  while (my @arr = $sth->fetchrow_array() ) {  while (my @arr = $sth->fetchrow_array() ) {
121            push @za_ic,$arr[0];
122            $mail4ko{$arr[13]}.="\t$arr[1] $arr[2]";
123            $mail4ko{$arr[13]}.=" (bez podešavanja)" if ($arr[14] == 0);
124    
125          printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n",$rbr,$arr[0],"$arr[1] $arr[2]",$arr[3],$arr[4],"$arr[5] $arr[6]");          printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n",$rbr,$arr[0],"$arr[1] $arr[2]",$arr[3],$arr[4],"$arr[5] $arr[6]");
126          print HTML "<tr><td>$rbr</td><td>$arr[0]</td><td>$arr[1] $arr[2]</td><td>$arr[3]</td><td>$arr[4]</td><td>$arr[5]<br>$arr[6]</td></tr>\n";          if ($lokacija ne $arr[4]) {
127                    $lokacija=$arr[4];
128                    print HTML "<tr bgcolor=#000000><td colspan=6><font size=+1 color=#ffffff>$lokacija</font></td></tr>";
129            }
130            print HTML "<tr$bgcol><td>$rbr</td><td><a href=\"http://support.pliva.hr/obavijest.php?id=$arr[0]\">$arr[0]</a></td><td>$arr[1] $arr[2]</td><td>tel: $arr[3]</td><td><small>$arr[4]</small></td><td>$arr[5]<br>$arr[6]</td></tr>\n";
131            if ($arr[12] == 0) {
132                    $mreza='umreženo';
133            } else {
134                    my $sth2 = $dbh->prepare("select count(status_tip_id) from status
135                            where osoba_id = $arr[0] and status_tip_id=8") ||
136                                    die $dbh->errstr();
137                    $sth2->execute() || die $sth2->errstr();
138                    my ($nr_of_status8) = $sth2->fetchrow_array();
139                            
140                    if ($nr_of_status8 > 0) {
141                            $mreza='<i>umrežavanje obavljeno</i>';
142                    } else {
143                            $mreza='<b>potrebno umrežavanje</b>';
144                    }
145            }
146            print HTML "<tr$bgcol><td colspan=2>&nbsp;</td><td><small>$arr[7] $mreza</small></a><td><small>ž-$arr[11]</small></td><td colspan=2><small>$arr[8] / $arr[9] / $arr[10]</small></td></tr>\n";
147          $rbr++;          $rbr++;
148            if ($rbr % 2 == 0) {
149                    $bgcol=' bgcolor=#eeeeee';
150            } else {
151                    $bgcol='';
152            }
153  }  }
154    
 $sth->finish;  
155    
156  print HTML '  print HTML '
157  </table>  </table>
# Line 92  print HTML ' Line 160  print HTML '
160    
161  close(HTML);  close(HTML);
162  close(MAIL);  close(MAIL);
163    
164    foreach my $email_ko (keys %mail4ko) {
165            if (! $debug) {
166                    open(MAIL,"|/usr/lib/sendmail $email_ko") || die "sendmail: $!";
167            } else {
168                    open(MAIL,">> /tmp/debug.komail") || die "sendmail: $!";
169            }
170    
171            print MAIL 'From: PlivaNet Core Support Team <pcst@pliva.hr>
172    Subject: otvoreni računi za e-mail
173    
174    Obavještavamo Vas da su otvoreni korisnički računi na intranet poslužitelju
175    za slijedeće osobe:
176    ';
177            foreach my $ime_pr (split(/\t/,$mail4ko{$email_ko})) {
178                    print MAIL "\t$ime_pr\n";
179            }
180            print MAIL '
181    Vaši korisnici dobiti će pristupno ime (login) i lozinku (password) internom
182    poštom, a djelatnici odjela Informatika IC će izvršiti podešavanje korisničkog
183    računala.';
184    
185            close(MAIL);
186    }
187    
188    #print "Printanje zahtjeva za print za IC:\n./print.pl ",join(",",@za_ic),"\n";
189    foreach my $id (@za_ic) {
190            if (! $debug) {
191                    $dbh->do("insert into izvjestaji (datum,osoba_id)
192                            values ('$currdate',$id)") || die $dbh->errstr();
193            }
194    }
195    
196    $sth->finish; undef $sth;
197    $dbh->disconnect;
198    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.26