From: Peter B. <mr_...@us...> - 2005-04-21 13:01:10
|
Update of /cvsroot/stud/stud In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26574 Modified Files: booking Log Message: Partially solved RFE:528049. TAGS added to category description for statistics and newest items. Index: booking =================================================================== RCS file: /cvsroot/stud/stud/booking,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** booking 4 Jan 2005 14:13:36 -0000 1.29 --- booking 21 Apr 2005 13:00:59 -0000 1.30 *************** *** 38,42 **** use ClubDb; ! my $version = "2.3.0"; my $q = new CGI(); --- 38,42 ---- use ClubDb; ! my $version = "2.4.0b"; my $q = new CGI(); *************** *** 396,400 **** -bgcolor => $default_bgcolor, -background => $default_background), ! "<center><h1>$$data{'title'}</h1></center>\n", $$data{description}, ($$data{locked} ? "\n<p>$$data{locked}" : ""), render_toolbox("", "", $club, $club_info, $category, $data, 0, 0), --- 396,400 ---- -bgcolor => $default_bgcolor, -background => $default_background), ! "<center><h1>$$data{'title'}</h1></center>\n", expandTags($club, $category, $$data{description}), ($$data{locked} ? "\n<p>$$data{locked}" : ""), render_toolbox("", "", $club, $club_info, $category, $data, 0, 0), *************** *** 1368,1371 **** --- 1368,1616 ---- #* + # Expand STUD TAGS in description + #@param $club + #@param $category + #@param $description + #@return Description with expanded tags + sub expandTags($$$) { + my ($club, $category, $description) = @_; + my $out = ""; + + #$club =3; + #$category = 5; + + # Expected TAGS + # <STUD TAG=STAT TYPE=BOOKINGS|BOOKERS|DAYSBOOKED [PERIOD=N] [LENGHT=N]> + # <STUD TAG=LATEST [PERIOD=N] [LENGTH=N]> + # <STUD TAG=SQL SELECT="NNN"> + + # SELECT id FROM symbols where club=3 AND category=5 AND symbol="Description"; + # SELECT id FROM symbols where club=3 AND category=5 AND symbol="Purchased date"; + while ( $description =~ s/^(.*?)<STUD ([^>]*)>//s ) + { + $out .= $1; + my %h = map { split("=", $_)} split( " ", $2 ); + if (defined $h{"TAG"}) + { + if ($h{"TAG"} eq "STAT") + { + if ($h{"TYPE"} eq "BOOKINGS") + { + $out .= tag_stat($club, $category, 1, iff($h{"LENGTH"},10), iff($h{"PERIOD"},0)); + } + elsif ($h{"TYPE"} eq "DAYSBOOKED") + { + $out .= tag_stat($club, $category, 2, iff($h{"LENGTH"},10), iff($h{"PERIOD"},0)); + } + elsif ($h{"TYPE"} eq "BOOKERS") + { + $out .= tag_stat($club, $category, 3, iff($h{"LENGTH"},10), iff($h{"PERIOD"},0)); + } + else + { + $out .= "STUD TAG: " . $h{"TAG"} . " Unrecognized TYPE: " . $h{"TYPE"}; + } + } + elsif ($h{"TAG"} eq "LATEST") + { + $out .= tag_latest($club, $category, iff($h{"LENGTH"},10), iff($h{"PERIOD"}, 0)); + } + elsif ($h{"TAG"} eq "SQL") + { + $out .= tag_sql($h{"SELECT"}, $h{"FROM"}, $h{"ORDERBY"}); + } + else + { + $out .= "STUD Unrecognized TAG: " . $h{"TAG"}; + } + } + else + { + $out .= "STUD TAG missing! "; + } + } + $out .= $description; + + return $out; + } + + #* + # Generates a HTML tag from a generic database query. + #@param $select SELECT sql statement + #@param $from FROM sql statement + #@param $orderby ORDER BY sql statement + # + sub tag_sql ( $$$ ) { + my ($select, $from, $orderby) = @_; + my $out = ""; + #my %dbq = $db->generic_sql_query($select, $from, $orderby); + return $out; + } + #* + # Generates a HTML tag with newest items. + #@param $club Name of the club in the database. + #@param $category The id of the category. + #@param $listLength How many items that shall be shown, 0=ALL + #@param $period How many days the period is. 0 = all items, >0 number of days + # + sub tag_latest ( $$$$ ) { + my ($club, $category, $listLength, $period) = @_; + my $items = $db->get_items( $club, $category ); + my ($year, $month, $day) = Today(); + my $date = sprintf("%4d-%02d-%02d", $year, $month, $day); + my $state = $db->get_item_state($club, $category, 0, $date); + my $out = ""; + + $out .= sprintf("<table border=1>\n<tr><td>Item</td><td>Date added</td></tr>\n"); + + my $i = 0; + foreach(sort {$$items{$b}{added_date} cmp $$items{$a}{added_date}} keys %$items) { + # Cue balls + my $ball; + if ($$state{"$club-$category-$_"} == 3) { + $ball = "<img src=".StudIni::getImgPath()."padlock.gif width=12 height=15>"; + } elsif ($$state{"$club-$category-$_"} == 2) { + $ball = "<img src=".StudIni::getImgPath()."ball_booked.gif width=12 height=12>"; + } else { + $ball = "<img src=".StudIni::getImgPath()."ball_unbooked.gif width=12 height=12>"; + } + + $i++; + $out .= "<tr><td>$ball<a href=\"$url?club=$club&category=$category&item=$_\">$$items{$_}{title}</a></td><td>$$items{$_}{added_date}</td></tr>\n"; + if ($listLength == $i) { + last; + } + } + $out .= sprintf("</table>\n"); + + return $out; + } + + #* + # Generates a HTML tag with statistics about a category. + # Both a complete set and a set for $period days. + #@param $club Name of the club in the database. + #@param $category The id of the category. + #@param $statType Statistict type (1=Bookings, 2=Days Booked, 3=Bookers + #@param $listLength How many items that shall be shown, 0=ALL + #@param $period How many days the period is. 0 = all past bookings, >0 past bookings, <0 future bookings + # + sub tag_stat ( $$$$$ ) { + my ($club, $category, $statType, $listLength, $period) = @_; + my $out = ""; + + # Fetch state for all items + my ($year, $month, $day) = Today(); + my $date = sprintf("%4d-%02d-%02d", $year, $month, $day); + + my $state = $db->get_item_state($club, $category, 0, $date); + my $sortOrder = 0; + + my %statistics = $db->get_category_booking_statistics($club, $category, $period); + + $out = sprintf("<table border=1>\n<tr><td>Item</td>\n"); + if ($statType==1) + { + if ($period > 0) + { + $sortOrder = 6; + $out .= sprintf ("<td>Bookings Last %d Days</td>\n", $period); + } + elsif ($period < 0) + { + $sortOrder = 6; + $out .= sprintf ("<td>Bookings Next %d Days</td>\n", -$period); + } + else + { + $sortOrder = 1; + $out .= sprintf ("<td>Bookings (Total)</td>\n"); + } + } + elsif ($statType==2) + { + if ($period > 0) + { + $sortOrder = 3; + $out .= sprintf ("<td>Days Booked Last %d Days</td>\n", $period); + } + elsif ($period < 0) + { + $sortOrder = 3; + $out .= sprintf ("<td>Days Booked Next %d Days</td>\n", -$period); + } + else + { + $sortOrder = 2; + $out .= sprintf ("<td>Days Booked (Total)</td>\n"); + } + } + elsif ($statType==3) + { + if ($period > 0) + { + $sortOrder = 5; + $out .= sprintf ("<td>Bookers Last %d Days</td>\n", $period); + } + elsif ($period < 0) + { + $sortOrder = 5; + $out .= sprintf ("<td>Bookers Next %d Days</td>\n", -$period); + } + else + { + $sortOrder = 4; + $out .= sprintf ("<td>Bookers (Total)</td>\n"); + } + } + $out .= sprintf ("</tr>\n"); + + my $i = 0; + my $key; + my @keys; + @keys = sort {-(iff($statistics{$a}->[$sortOrder], 0) <=> iff($statistics{$b}->[$sortOrder], 0))} keys %statistics; + + foreach $key (@keys){ + $key =~ /(.*)-(.*)-(.*)/; + my $clb = $1; + my $cat = $2; + my $item = $3; + + # Cue balls + my $ball; + if ($$state{"$clb-$cat-$item"} == 3) { + $ball = "<img src=".StudIni::getImgPath()."padlock.gif width=12 height=15>"; + } elsif ($$state{"$clb-$cat-$item"} == 2) { + $ball = "<img src=".StudIni::getImgPath()."ball_booked.gif width=12 height=12>"; + } else { + $ball = "<img src=".StudIni::getImgPath()."ball_unbooked.gif width=12 height=12>"; + } + + if ($sortOrder==1) { + $out .= sprintf ("<tr><td>$ball<a href=\"$url?club=$clb&category=$cat&item=$item\">%s</a></td><td align=center>%d</td></tr>",$statistics{$key}->[0], $statistics{$key}->[1]); + } elsif ($sortOrder==2) { + $out .= sprintf ("<tr><td>$ball<a href=\"$url?club=$clb&category=$cat&item=$item\">%s</a></td><td align=center>%d</td></tr>",$statistics{$key}->[0], $statistics{$key}->[2]); + } elsif ($sortOrder==4) { + $out .= sprintf ("<tr><td>$ball<a href=\"$url?club=$clb&category=$cat&item=$item\">%s</a></td><td align=center>%d</td></tr>",$statistics{$key}->[0], $statistics{$key}->[4]); + } elsif ($sortOrder==6) { + $out .= sprintf ("<tr><td>$ball<a href=\"$url?club=$clb&category=$cat&item=$item\">%s</a></td><td align=center>%d</td></tr>",$statistics{$key}->[0], $statistics{$key}->[6]); + } elsif ($sortOrder==3) { + $out .= sprintf ("<tr><td>$ball<a href=\"$url?club=$clb&category=$cat&item=$item\">%s</a></td><td align=center>%d (%.1f%%)</td></tr>",$statistics{$key}->[0], $statistics{$key}->[3], $statistics{$key}->[3]/abs($period)*100); + } elsif ($sortOrder==5) { + $out .= sprintf ("<tr><td>$ball<a href=\"$url?club=$clb&category=$cat&item=$item\">%s</a></td><td align=center>%d</td></tr>",$statistics{$key}->[0], $statistics{$key}->[5]); + } + + ++$i; + if ($i == $listLength) { + last; # Break loop + } + } + + $out .= sprintf ("</table>\n"); + + return $out; + } + + #* # Renders HTML for accessing the corresponding page in the bookings interface #@param $user |