/[ldap]/html/vizitka.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /html/vizitka.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Wed May 24 18:37:26 2000 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +26 -13 lines
Potpuna podrka za UTF-8 (i recoding u/iz iso-8859-2)

1 #!/usr/local/bin/perl -w
2
3 use Net::LDAP;
4 use Net::LDAP::LDIF;
5 use CGI qw/:standard/;
6 use CGI::Carp qw(fatalsToBrowser);
7
8 # ldap server host
9 $host = 'sun.lan';
10 # e-mail address to mail report to:
11 $email = 'dpavlin@sun.lan';
12 # log file
13 $log = '/tmp/vizitke.log';
14
15 $ldap = Net::LDAP->new($host,port=>389) || die "$@";
16
17 $ldap->bind; # anonymous
18
19 %labels = ('givenname'=>'ime',
20 'sn'=>'prezime',
21 'cn'=>'ime i prezime');
22
23 %utf2iso_tab = (
24 0x0161 => '¹', 0x0111 => 'ð', 0x010d => 'è', 0x0107 => 'æ', 0x017e => '¾',
25 0x0160 => '©', 0x0110 => 'Ð', 0x010c => 'È', 0x0106 => 'Æ', 0x017d => '®'
26 );
27
28 %iso2utf_tab = (
29 '¹' => 0x0161, 'ð' => 0x0111, 'è' => 0x010d, 'æ' => 0x0107, '¾' => 0x017e,
30 '©' => 0x0160, 'Ð' => 0x0110, 'È' => 0x010c, 'Æ' => 0x0106, '®' => 0x017d
31 );
32
33 sub utf2iso {
34 local($_)=@_;
35 s/([\xC0-\xDF])([\x80-\xBF])/$utf2iso_tab{unpack("c",$1)<<6&0x07C0|unpack("c",$2)&0x003F}/ge;
36 s/([\xE0-\xEF])([\x80-\xBF])([\x80-\xBF])/$utf2iso_tab{unpack("c",$1)<<12&0xF000|unpack("c",$2)<<6&0x0FC0|unpack("c",$3)&0x003F}/ge;
37 s/([\xF0-\xF7])([\x80-\xBF])([\x80-\xBF])([\x80-\xBF])/$utf2iso_tab{unpack("c",$1)<<18&0x1C0000|unpack("c",$2)<<12&0x3F000|unpack("c",$3)<<6&0x0FC0|unpack("c",$4)&0x003F}/ge;
38 return $_;
39 }
40 sub iso2utf {
41 local($_)=@_;
42
43 sub utf8 {
44 local($_)=@_;
45 return $_ < 0x80 ? chr($_) :
46 $_ < 0x800 ? chr($_>>6&0x3F|0xC0) . chr($_&0x3F|0x80) :
47 chr($_>>12&0x0F|0xE0).chr($_>>6&0x3F|0x80).chr($_&0x3F|0x80);
48 }
49 s/([¹ðè澩ÐÈÆ®])/utf8($iso2utf_tab{$1})/ge;
50 return $_;
51 }
52
53 print
54 header(-type => 'text/html;charset=ISO-8859-2'),
55 start_html('Naruèivanje vizitki'),
56 start_form,
57 "Upi¹ite svoje ",popup_menu(-name=>'what',
58 -values=>['givenname','sn','cn'],
59 -default=>'cn',
60 -labels=>\%labels),
61 textfield(-name=>'search',-default=>'*'),br,
62 "Broj komada koje naruèujete ",
63 textfield(-name=>'kom',-size=>4,-default=>10),br,
64 submit(-value=>"Naruèi"),p
65 end_form;
66
67 if(param()) {
68 $mesg = $ldap->search (
69 base => 'o=agrokor.hr',
70 filter => param('what').'='.iso2utf(param('search'))
71 );
72 my $max = $mesg->count;
73 if ($max > 1) {
74 param('what','cn'); # reset what='cn'
75 print "Broj osoba koje odgovaraju upitu: ",$mesg->count,br,
76 b("Odaberite samo jednu!"),
77 start_form,
78 hidden(-name=>'what',-value=>'cn'),
79 hidden(-name=>'kom'),
80 p;
81 for($i = 0 ; $i < $max ; $i++) {
82 my $entry = $mesg->entry($i);
83 my ($mail) = $entry->get('mail'); # array, take first
84 my ($cn)=utf2iso($entry->get('cn'));
85 push @radio_vals,$cn;
86 $radio_labels{$cn}=$cn;
87 }
88 print radio_group(-name=>'search',
89 -values=>\@radio_vals,
90 -linebreak=>'true',
91 -default=>\$radio_vals[0],
92 -labels=>\%radio_labels),
93 submit(-value=>"Odaberi"),p
94 end_form;
95 } elsif ($max==0) {
96 print b("Nije naðena niti jedna osoba");
97 } else {
98 my $entry = $mesg->entry(0);
99 my @data = ( utf2iso($entry->get('cn')) );
100 sub add_opt {
101 ($label,$data) = @_;
102 if ($data) {
103 push @data,"$label ".utf2iso($data);
104 }
105 }
106 add_opt "",$entry->get('ou');
107 add_opt "",$entry->get('postaladdress');
108 add_opt "soba: ",$entry->get('roomnumber');
109 add_opt "e-mail: ",$entry->get('mail');
110 add_opt "tel: ",$entry->get('telephonenumber');
111 add_opt "fax: ",$entry->get('facsimiletelephonenumber');
112 # add_opt ": ",$entry->get('');
113 push @data,"Narud¾ba za ".param("kom")." komada\n";
114 print join("<br>\n",@data);
115 open(MAIL,"|/usr/lib/sendmail $email");
116 print MAIL join("\n",@data);
117 close(MAIL);
118 open(LOG,">> $log");
119 print LOG "\nVrijeme zahtjeva: ".localtime(time)."\n";
120 print LOG join("\t\n",@data);
121 close(LOG);
122 }
123 }
124

  ViewVC Help
Powered by ViewVC 1.1.26