--- otvori_nove+db 2000/04/12 08:19:17 1.1 +++ otvori_nove+db 2000/04/18 12:09:03 1.3 @@ -8,23 +8,22 @@ # 2000-03-13 DbP podrska za novu support/last_open tablicu # 2000-03-16 DbP cuva stare aliase iz /etc/aliases # 2000-03-20 DbP skida razmake prije/poslje imena/prezimena - + use DBI; use strict; my $debug=0; -$debug++ if (defined($ARGV[0]) && $ARGV[0] eq "-d"); +if (defined($ARGV[0]) && $ARGV[0] eq "-d") { + $debug++; + shift @ARGV; +} +my $open_only_id=shift @ARGV if (defined($ARGV[0])); warn "DEBUG -- me kreira ništa!" if ($debug); $|++; -my @mail_to; # array to main initial message to -open(WHO,"who am i |") || die "who am i? $!"; -my $db_user=; -$db_user=~s/\s.+$//g; -close(WHO); #---- @@ -39,6 +38,15 @@ my $mail_alias; my $mail_login; +my @mail_to; # array to main initial message to +open(WHO,"who am i |") || die "who am i? $!"; +my $db_user=; +$db_user=~s/\s.+$//g; +close(WHO); + +xdebug "koristim korinika $db_user\n"; + + v "/etc/aliases\n"; open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!"; open(NALIAS,">aliases.new") || die "Can't open aliases.new: $!"; @@ -100,10 +108,25 @@ my $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr(); $sth->execute() || die $sth->errstr(); my ($last_open)=$sth->fetchrow_array; -$sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id > $last_open") || die $dbh->errstr(); +if (! defined($open_only_id)) { + $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id > $last_open") || die $dbh->errstr(); +} else { + $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id=$open_only_id") || die $dbh->errstr(); + +} $sth->execute() || die $sth->errstr(); + + +my $sth2; + while (my ($osoba_id,$ime,$prezime,$sifra,$objekt,$kat,$soba,$shell) = $sth->fetchrow_array() ) { + $sth2 = $dbh->prepare("select max(status_tip_id) from status where osoba_id = $osoba_id") || die $dbh->errstr(); + $sth2->execute() || die $sth2->errstr(); + my ($max_status) = $sth2->fetchrow_array(); + xdebug "max status zahtjeva $osoba_id je $max_status\n"; + next if ($max_status > 3); # 3 .. otvoren + next if ($ime eq "ime" || $prezime eq "prezime"); if (!defined($ime) || !defined($prezime) || $ime eq "" || $prezime eq "") { @@ -126,11 +149,11 @@ my $login; do { - $login=substr($ime,0,1).substr($prezime_za_login,0,7-length($add)).$add; - xdebug "$ime, $prezime login: $login\n"; - $add++; + $login=substr($ime,0,1).substr($prezime_za_login,0,7-length($add)).$add; + $login =~ tr [A-Z] [a-z]; + xdebug "$ime, $prezime login: $login\n"; + $add++; } while defined($etc_passwd{$login}); - $login =~ tr [A-Z] [a-z]; my $email_alias; @@ -146,7 +169,7 @@ my $group="users"; if (defined($etc_passwd{$login})) { - xerror "preskocen: $ime $prezime (postoji isti login $login)\n"; + xerror "preskocen: $ime $prezime osoba_id=$osoba_id (postoji isti login $login)\n"; $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($osoba_id,3,'now'::datetime,4)") if (! $debug); next; } @@ -188,7 +211,7 @@ $etc_passwd{$login}=$full_name; if (defined($etc_aliases{$email_alias})) { - xerror "upozorenje: $ime $prezime (postoji e-mail alias) -- $email_alias\n"; + xerror "upozorenje: $ime $prezime osoba_id=$osoba_id (postoji e-mail alias) -- $email_alias\n"; print NALIAS "$email_alias:\t$login,$etc_aliases{$email_alias}\n"; } else { print NALIAS "$email_alias:\t$login\n";