/[omni_gantt]/db2gantt.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 /db2gantt.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu Sep 12 12:06:34 2002 UTC (17 years, 1 month ago) by dpavlin
Branch: MAIN
web script

1 #!/usr/bin/perl -w
2
3 use strict;
4 use DBI;
5 use Data::Dumper;
6 use Date::Parse;
7
8 print "Content-type: text/html\n\n";
9
10 my $from="2002-09-11 20:00:00";
11 my $to="2002-09-13 00:00:00";
12
13 # all vars ending in *_t have utime in them.
14 #
15 my $from_t = str2time($from);
16 my $to_t = str2time($to);
17 my $len_t = $to_t - $from_t;
18
19 die "interval must be positive and bigger than 1 sec !" if ($len_t < 1);
20
21 my $debug = 1;
22
23 my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
24
25 #--- no user servicable parts below this line
26
27 print "<table>";
28 print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>$from</td><td align=right>$to</td></tr>";
29
30 my $width = 900;
31
32 sub draw {
33 my $l = shift @_; # lenght of event utime
34 my $type = shift @_; # what to draw
35 my $size = int($l / ($len_t / $width)) || 1; # dump size (min. size=1)
36
37 print STDERR "l[$type]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug);
38
39 print "<img src=$type.png width=$size height=8>";
40 }
41
42 my $sql = "select start,finish,specification,status
43 from gantt
44 where (start < '$from' and finish > '$from') or
45 (start > '$from' and start < '$to')
46 order by specification
47 ";
48
49 my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
50
51 my %spec; # specification hash
52
53 my $curr_spec;
54 my $curr_t = $from_t;
55
56 $sth->execute() || die "sql: $sql ".$dbh->errstr;
57 while(my $row = $sth->fetchrow_hashref) {
58 if ($row->{specification} ne $curr_spec) {
59
60 if ($curr_t < $to_t ) {
61 my $t = $to_t - $curr_t;
62 print STDERR "[filler $curr_t:$t]" if ($debug);
63 draw($t,"gray");
64 }
65
66 print "</td></tr>\n" if ($curr_t != 0);
67 print "<tr><td>", $row->{specification},"</td><td colspan=2>";
68
69 $curr_t = $from_t; # init timeline
70 $curr_spec = $row->{specification};
71
72 }
73
74 my $start_t = str2time($row->{start});
75 my $fin_t = str2time($row->{finish});
76
77 if ($start_t > $curr_t) {
78 my $t = $start_t - $curr_t;
79 print STDERR "[filler $curr_t:$t]" if ($debug);
80 draw($t,"gray");
81 $curr_t = $start_t;
82 }
83
84 my $len = $fin_t - $start_t;
85 # $len = $len_t if ($len > $len_t);
86 my $less = '';
87 my $more = '';
88
89 if ($start_t < $from_t) {
90 # $len += ($from_t - $start_t);
91 $len = ($fin_t - $curr_t);
92 $less = "<<";
93 }
94 if ($fin_t > $to_t) {
95 # $len -= ($fin_t - $to_t);
96 $len = ($to_t - $curr_t);
97 $more = ">>"; # event now shown whole
98 }
99
100 print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
101 draw($len,"red");
102
103 $curr_t += $len;
104
105 # print Dumper($row);
106
107 }
108
109 if ($curr_t < $to_t ) {
110 my $t = $to_t - $curr_t;
111 print STDERR "[filler $curr_t:$t]" if ($debug);
112 draw($t,"white");
113 }
114
115 undef $sth;
116 $dbh->disconnect;
117
118 print "</td></tr></table>";
119

  ViewVC Help
Powered by ViewVC 1.1.26