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

Diff of /print/print.pl

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

revision 1.2 by dpavlin, Wed Apr 26 12:21:19 2000 UTC revision 1.9 by dpavlin, Mon Feb 4 15:55:13 2002 UTC
# Line 31  $dbh->do("set datestyle = 'german'") || Line 31  $dbh->do("set datestyle = 'german'") ||
31    
32  my $sth;  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    if ($db_user eq "") {
41            open(ID,"id |") || die "id: $!";
42            my $foo=<ID>; chomp $foo;
43            if ($foo=~/uid=\d+\((\w+)\)/) {
44                    $db_user=$1;
45            } else {
46                    die "can't locate who is local user!";
47            }
48    }
49    
50    open(HOSTNAME,"hostname |") || die "hostname: $!";
51    my $hostname=<HOSTNAME>;
52    chomp $hostname;
53    close(HOSTNAME);
54    
55    $sth = $dbh->prepare("select ko_id from unix2ko where login='$db_user' and host='$hostname'") || die $dbh->errstr();
56    $sth->execute() || die $sth->errstr();
57    my ($ko_id)=$sth->fetchrow_array;
58    die "Ne mogu naći odgovarajuću kontakt osobu u tablici unix2ko!\n\tlogin=$db_user host=$hostname\n" if (!defined($ko_id));
59    
60    print "kontakt_osoba_id (koja je pokrenula skriptu): $ko_id\n" if ($debug);
61    
62  #$sth = $dbh->prepare("select id from kontakt_osobe where e_mail like '%hana%'") || die $dbh->errstr();  #$sth = $dbh->prepare("select id from kontakt_osobe where e_mail like '%hana%'") || die $dbh->errstr();
63  #$sth->execute() || die $sth->errstr();  #$sth->execute() || die $sth->errstr();
64  #($kontakt_osoba_id) = $sth->fetchrow_array();  #($kontakt_osoba_id) = $sth->fetchrow_array();
# Line 44  my $sql; Line 72  my $sql;
72  if (! defined($print_only_id)) {  if (! defined($print_only_id)) {
73          $sql="select osoba_id,max(status_tip_id) from status where osoba_id > $last_print_id group by osoba_id";          $sql="select osoba_id,max(status_tip_id) from status where osoba_id > $last_print_id group by osoba_id";
74  } else {  } else {
75          $sql="select osoba_id,status_tip_id from status where osoba_id=$print_only_id and status_tip_id=3";          $sql="select osoba_id,status_tip_id from status where osoba_id in ($print_only_id) and status_tip_id=3";
76  }  }
77    
78  $sth = $dbh->prepare("$sql") || die "$sql ",$dbh->errstr();  $sth = $dbh->prepare("$sql") || die "$sql ",$dbh->errstr();
79  $sth->execute() || die "$sql ",$sth->errstr();  $sth->execute() || die "$sql ",$sth->errstr();
80    
81  #my $out_tex="out.tex";  #my $out_tex="out.tex";
82  my $out_tex="$0-out-$$.tex";  my $out_tex="out-$$.tex";
83    
84  open(IN,"obavjest.tex") || die "obavjest.tex: $!";  open(IN,"obavjest.tex") || die "obavjest.tex: $!";
85  open(OUT,"> $out_tex") || die "$out_tex: $!";  open(OUT,"> $out_tex") || die "$out_tex: $!";
# Line 73  while (my ($osoba_id,$status_tip_id) = $ Line 101  while (my ($osoba_id,$status_tip_id) = $
101    
102  print "Računa za insprintati: ",$#osoba_id_za_print+1,"\n";  print "Računa za insprintati: ",$#osoba_id_za_print+1,"\n";
103  exit if ($#osoba_id_za_print+1 == 0);  exit if ($#osoba_id_za_print+1 == 0);
104    my $server=3;
105  $sth = $dbh->prepare("  $sth = $dbh->prepare("
106          select osobe.id,ime,prezime,tel,lokacije.naziv,          select osobe.id,ime,prezime,tel,lokacije.naziv,
                 org_jed.naziv,org_pod_jed.pod_naziv,  
107                  lok_racunala,login,passwd,alias,sifra,                  lok_racunala,login,passwd,alias,sifra,
108                  objekt,kat,soba,z_rac,kontakt_osoba_id,umrezavanje                  objekt,kat,soba,z_rac,kontakt_osoba_id,umrezavanje
109          from osobe,racuni,e_mail          from osobe,racuni,e_mail
110          where osobe.id in (".join(",",@osoba_id_za_print).")          where osobe.id in (".join(",",@osoba_id_za_print).")
111                  and lokacija_id=lokacije.id and org_jed_id=org_jed.id                  and lokacija_id=lokacije.id
112                  and org_pod_jed_id=org_pod_jed.pod_id                  and racuni.osoba_id=osobe.id and racuni.server_id=$server
113                  and racuni.osoba_id=osobe.id and e_mail.osoba_id=osobe.id                  and e_mail.osoba_id=osobe.id
114          ") || die $dbh->errstr();          ") || die $dbh->errstr();
115  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
116    
# Line 91  $sth->execute() || die $sth->errstr(); Line 118  $sth->execute() || die $sth->errstr();
118  while (my @arr = $sth->fetchrow_array() ) {  while (my @arr = $sth->fetchrow_array() ) {
119          print join("|",@arr),"\n";          print join("|",@arr),"\n";
120    
121          $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($arr[0],3,'now'::datetime,5)") if (!$debug);          if (!$debug) {
122                    $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();
123            }
124    
125            my $sth2 = $dbh->prepare("select naziv,mt from sap_osobe,sap_oj where sap_oj.sifra_oj = sap_oj and sap_sifra = $arr[11]");
126            $sth2->execute() || die $sth2->errstr();
127            my ($sap_org_jed,$mt) = $sth2->fetchrow_array();
128    
129          seek(IN,$begin_pos,0);          seek(IN,$begin_pos,0);
130          while(<IN>) {          while(<IN>) {
# Line 105  while (my @arr = $sth->fetchrow_array() Line 138  while (my @arr = $sth->fetchrow_array()
138                  s/--prezime--/$arr[2]/g;                  s/--prezime--/$arr[2]/g;
139                  s/--tel--/$arr[3]/g;                  s/--tel--/$arr[3]/g;
140                  s/--lok--/$arr[4]/g;                  s/--lok--/$arr[4]/g;
141                  s/--orgjed--/$arr[5]/g;                  s/--orgjed--/$sap_org_jed/g;
142                  s/--orgpodjed--/$arr[6]/g;                  s/--mt--/$mt/g;
143                  s/--lokrac--/$arr[7]/g;                  s/--lokrac--/$arr[7]/g;
144                  s/--login--/$arr[8]/g;                  s/--login--/$arr[8]/g;
145    

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

  ViewVC Help
Powered by ViewVC 1.1.26