--- print/izvjestaj.pl 2000/05/10 08:19:39 1.4 +++ print/izvjestaj.pl 2000/07/13 08:01:31 1.9 @@ -2,6 +2,9 @@ use strict; +my $ic_mail='biljana.gombar@pliva.hr'; +my $mreze_mail='davorin.koprivnjak@pliva.hr'; + my $debug=0; use DBI; @@ -11,15 +14,17 @@ print STDERR "Debug mod: output je u /tmp/debug*\n" if ($debug); -my $currdate = strftime "%d.%m.%Y %H:%M:%S", localtime; +my $currdate = strftime "%Y-%m-%d %H:%M:%S", localtime; my $html_file=$currdate; $html_file=~s/ /_/g; $html_file="izvjestaji/$html_file.html"; +my $html_date=$currdate; +$html_date=~s/ /%20/g; if (! $debug) { open(HTML,"> $html_file") || die "html: $!"; -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: $!"; } else { open(HTML,"> /tmp/debug.html") || die "html: $!"; open(MAIL,"> /tmp/debug.mail") || die "sendmail: $!"; @@ -37,7 +42,21 @@ '; -my $dbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr; +my $host = "host=support.pliva.hr;"; + +open(WHO,"who -m |") || die "who am i? $!"; +my $db_user=; +$db_user=~s/[^!]+!//; +close(WHO); +if (! defined($db_user)) { + $db_user="user=dpavlin;"; $host=""; # works on localhost +} else { + $db_user=~s/\s.+$//g; + $db_user="user=$db_user;"; +} + + +my $dbh = DBI->connect("DBI:Pg:dbname=informatika;${host}${db_user}","","") || die $DBI::errstr; $dbh->do("set datestyle = 'german'") || die $dbh->errstr(); my $sth = $dbh->prepare("select id from last_print order by id desc limit 1,1"); @@ -58,26 +77,28 @@ } } -print MAIL "Otvorenih računa: ",$#osoba_id_za_print+1," +print MAIL " Datum i vrijeme generiranja izvještaja: $currdate Izvještaj za štampanje se nalazi na -http://support.pliva.hr/$html_file +http://support.pliva.hr/ic.php?datum=$html_date sa potpunim podacima o umrežavanju, lokaciji računala i osobe "; -print HTML "Otvorenih računa: ",$#osoba_id_za_print+1," +print HTML "
Datum i vrijeme generiranja izvještaja: $currdate

"; $sth = $dbh->prepare(" select osobe.id,ime,prezime,tel,lokacije.naziv, org_jed.naziv,org_pod_jed.pod_naziv, - lok_racunala,objekt,kat,soba,z_rac,umrezavanje + lok_racunala,objekt,kat,soba,z_rac,umrezavanje, + kontakt_osobe.e_mail,podesavanje from osobe where osobe.id in (".join(",",@osoba_id_za_print).") and lokacija_id=lokacije.id and org_jed_id=org_jed.id and org_pod_jed_id=org_pod_jed.pod_id and podesavanje=true + and kontakt_osobe.id=kontakt_osoba_id order by lokacije.naziv,org_jed.naziv ") || die $dbh->errstr(); $sth->execute() || die $sth->errstr(); @@ -93,20 +114,30 @@ my $bgcol=''; my $mreza=''; +my @za_ic; +my %mail4ko; while (my @arr = $sth->fetchrow_array() ) { + push @za_ic,$arr[0]; + $mail4ko{$arr[13]}.="\t$arr[1] $arr[2]"; + $mail4ko{$arr[13]}.=" (bez podešavanja)" if ($arr[14] == 0); + printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n",$rbr,$arr[0],"$arr[1] $arr[2]",$arr[3],$arr[4],"$arr[5] $arr[6]"); if ($lokacija ne $arr[4]) { $lokacija=$arr[4]; print HTML "$lokacija"; } - print HTML "$rbr$arr[0]$arr[1] $arr[2]tel: $arr[3]$arr[4]$arr[5]
$arr[6]\n"; + print HTML "$rbr$arr[0]$arr[1] $arr[2]tel: $arr[3]$arr[4]$arr[5]
$arr[6]\n"; if ($arr[12] == 0) { $mreza='umreženo'; } else { - my $rows = $dbh->do("select max(status_tip_id) from status - where osoba_id = $arr[0] and status_tip_id=8") || die $dbh->errstr(); - if ($rows > 0) { + my $sth2 = $dbh->prepare("select count(status_tip_id) from status + where osoba_id = $arr[0] and status_tip_id=8") || + die $dbh->errstr(); + $sth2->execute() || die $sth2->errstr(); + my ($nr_of_status8) = $sth2->fetchrow_array(); + + if ($nr_of_status8 > 0) { $mreza='umrežavanje obavljeno'; } else { $mreza='potrebno umrežavanje'; @@ -121,7 +152,6 @@ } } -$sth->finish; print HTML ' @@ -131,3 +161,38 @@ close(HTML); close(MAIL); +foreach my $email_ko (keys %mail4ko) { + if (! $debug) { + open(MAIL,"|/usr/lib/sendmail $email_ko") || die "sendmail: $!"; + } else { + open(MAIL,">> /tmp/debug.komail") || die "sendmail: $!"; + } + + print MAIL 'From: PlivaNet Core Support Team +Subject: otvoreni računi za e-mail + +Obavještavamo Vas da su otvoreni korisnički računi na intranet poslužitelju +za slijedeće osobe: +'; + foreach my $ime_pr (split(/\t/,$mail4ko{$email_ko})) { + print MAIL "\t$ime_pr\n"; + } + print MAIL ' +Vaši korisnici dobiti će pristupno ime (login) i lozinku (password) internom +poštom, a djelatnici odjela Informatika IC će izvršiti podešavanje korisničkog +računala.'; + + close(MAIL); +} + +#print "Printanje zahtjeva za print za IC:\n./print.pl ",join(",",@za_ic),"\n"; +foreach my $id (@za_ic) { + if (! $debug) { + $dbh->do("insert into izvjestaji (datum,osoba_id) + values ('$currdate',$id)") || die $dbh->errstr(); + } +} + +$sth->finish; undef $sth; +$dbh->disconnect; +