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

Contents of /oznaci.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed May 10 07:13:42 2000 UTC (23 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +2 -1 lines
File MIME type: text/plain
who -m zapravo radi ako se spaja telnetom

1 #!/usr/local/bin/perl -w
2
3 # Dobrica Pavlinusic <dpavlin@pliva.hr>
4 # 2000-04-18 DbP oznaèi dupli zahtjev
5 # 2000-04-20 DbP opæe oznaèivanje statusa
6
7 use DBI;
8 use strict;
9
10 $|++;
11
12 my ($osoba_id,$status,$status_tip_id,$sth);
13
14 my $host = "host=support.pliva.hr;";
15
16 open(WHO,"who -m |") || die "who am i? $!"; # osf-ism
17 my $db_user=<WHO>;
18 $db_user=~s/[^!]+!//;
19 close(WHO);
20 if (! defined($db_user)) {
21 $db_user="user=dpavlin;"; $host=""; # works on localhost
22 } else {
23 $db_user=~s/\s.+$//g;
24 $db_user="user=$db_user;";
25 }
26
27
28 my $dbh = DBI->connect("DBI:Pg:dbname=informatika;${host}${db_user}","","") || die $DBI::errstr;
29
30 if (defined($ARGV[0]) && defined($ARGV[1])) {
31 $osoba_id = shift @ARGV;
32 $status = shift @ARGV;
33 $sth = $dbh->prepare("select ime,prezime from osobe where id=$osoba_id");
34 $sth->execute() || die $sth->errstr();
35 if (my ($ime,$prezime) = $sth->fetchrow_array()) {
36 print "Dodajem status korisniku $ime $prezime (id: $osoba_id)\n";
37 } else {
38 die "ne mogu naæi osobu sa id-jem zahtjeva $osoba_id !";
39 }
40 } else {
41 print STDERR "trebam ID osobe i status kao argument!\n\n";
42 print STDERR "Moguæi statusi:\n\n";
43 $sth = $dbh->prepare("select opis from status_tip");
44 $sth->execute() || die $sth->errstr();
45 while (my $status = $sth->fetchrow_array()) { print "$status\n"; }
46 exit 1;
47 }
48
49 $sth = $dbh->prepare("select id from status_tip where opis like '$status'");
50 $sth->execute() || die $sth->errstr();
51 if (! (($status_tip_id) = $sth->fetchrow_array())) {
52 die "ne mogu pronaæi status broj $status...";
53 } else {
54 print "\tdodajem status $status ($status_tip_id)\n";
55 }
56
57 $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($osoba_id,3,'now'::datetime,$status_tip_id)");
58

  ViewVC Help
Powered by ViewVC 1.1.26