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

Annotation of /sap2orgjed.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Jan 25 14:47:43 2002 UTC (22 years, 2 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
sap organizacijske jedinice

1 dpavlin 1.1 #!/usr/local/bin/perl -w
2    
3     #use strict;
4    
5     # unrolls org.jed to text files
6    
7     my $debug=0;
8    
9     my $sap_dir="/data/sap/tkc/telefoni";
10    
11     use DBI;
12     my $dbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die DBI::errstr;
13    
14     # clean tables
15     $sql="delete from sap_osobe";
16     $dbh->do($sql) || die "$sql",$dbh->errstr();
17    
18     $sql="delete from sap_oj";
19     $dbh->do($sql) || die "$sql",$dbh->errstr();
20    
21     my %orgjed_parent;
22     my %orgjed;
23     my %orgjed_sap;
24    
25     my @orgjed_arr;
26    
27    
28     sub initcap {
29     my ($str) = $_[0];
30     $str=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
31     my ($lower,$upper);
32     $str=~s/ +/ /g;
33     $str=~s/^ +//g;
34     $str=~s/ +$//g;
35     $lower=$upper=$str;
36     $lower=~tr/[A-Z]©ÐÈÆ®/[a-z]¹ðèæ¾/;
37     my $new;
38     for (my $i=0; $i<length($lower); $i++) {
39     my $cl=substr($lower,$i,1);
40     my $cu=substr($upper,$i,1);
41     if ($i==0) {
42     $new.=$cu;
43     } elsif ($cl =~ /[ \.-]/) {
44     $i++;
45     $new.=$cl.substr($upper,$i,1);
46     } else {
47     $new.=$cl;
48     }
49     }
50     return($new);
51     }
52    
53     sub unroll_orgjed {
54     my $foo = $_[0];
55     my $oj=$orgjed{$foo};
56     # print $foo,"\t",$orgjed{$foo},"\n";
57     while (defined($orgjed_parent{$foo}) && $orgjed_parent{$foo} != 1) {
58     $foo=$orgjed_parent{$foo};
59     $oj="$orgjed{$foo} >> $oj";
60     }
61     return $oj;
62     }
63    
64    
65     ###----------- organizacijske jedinice
66    
67     open(OJ,"$sap_dir/ZRHRTEL2") || die "ZRHRTEL2: $!";
68     while(<OJ>) {
69     chomp;
70     if (m,^(\d{8})(\d{8})$,) {
71     my($parent,$child) = ($1,$2);
72     $orgjed_parent{$child}=$parent;
73     print "oj: $child -> $parent\n" if ($debug);
74     } else {
75     warn "can't parse ZRHRTEL2 line '$_' if ($debug)";
76     }
77     }
78     close(OJ);
79    
80     open(OJ,"$sap_dir/ZRHRTEL3") || die "ZRHRTEL3: $!";
81     while(<OJ>) {
82     chomp;
83     if (m,^(\d{8})(.{12})(.+)$,) {
84     my ($oj_sif,$sap_sif,$naziv) = ($1,$2,$3);
85     $orgjed{$oj_sif}=$naziv;
86     $orgjed_sap{$oj_sif}=$sap_sif;
87     print "$oj_sif..$sap_sif..$naziv\n" if ($debug);
88     push @orgjed_arr,$oj_sif;
89     } else {
90     warn "can't parse ZRHRTEL3 line '$_'" if ($debug);
91     }
92     }
93     close(OJ);
94    
95     ##------------------------------------
96    
97     sub save_sap_oj {
98     my $sap_oj = $_[0];
99     $sap_name=unroll_orgjed($sap_oj);
100     # $sql="insert into sap_oj values ('$sap_oj','$sap_name')";
101     $sql="insert into sap_oj (sifra_oj,naziv) select '$sap_oj','$sap_name' where not exists (select sifra_oj from sap_oj where sifra_oj='$sap_oj')";
102     $dbh->do("$sql") || die $dbh->errstr();
103     }
104    
105     ###----------- osobe
106    
107     open(IN,"$sap_dir/ZRHRTEL1") || die "ZRHRTEL1";
108     while(<IN>) {
109     chomp;
110     my $bar=$_;
111     my $czs=$bar;
112     $czs=~tr/¹ð¾èæ©Ð®ÈÆ[A-Z]/sdzccsdzcc[a-z]/;
113    
114     if (m,(\d{6})(\d{4})(\d{8})(.{24})(.+),) {
115     my ($sifra,$mt,$orgjed,$ime,$prezime) = ($1,$2,$3,$4,$5);
116     $ime=initcap($ime);
117     $prezime=initcap($prezime);
118     print "$sifra\t$ime $prezime\t$orgjed\n";
119     save_sap_oj($orgjed);
120     $dbh->do("insert into sap_osobe values ('$sifra','$ime','$prezime','$mt','$orgjed')") || $dbh->do("update sap_osobe set ime='$ime',prezime='$prezime',mt='$mt',sap_oj='$orgjed' where sifra='$sifra'") || die $dbh->errstr();
121     } else {
122     print "skipped: $_\n";
123     }
124     }
125     close(IN);
126    

  ViewVC Help
Powered by ViewVC 1.1.26