#!/usr/bin/perl use strict; use lib qw(/usr/home/web/users/a0017451/html/cgi-bin); use CGI qw(:standard escapeHTML); use AklaatDB; use AklaatDB::Session; my $basedir = '/usr/home/web/users/a0017451/html/'; my $rate_base_url = 'http://www.aklaat.com/cgi-bin/rates/ShowRecipeRate.pl'; my $baseurl = '../'; my $link_url = '../index.htm'; my ($name, $value, $page_title, $nav_file, $image_file, $list_file, $pair, @pairs, $title, $rec_to_display, $total_rec, %FORM, $page); $title = 'title'; $total_rec = 0; $page = 0; $rec_to_display = 25; my $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/,$buffer); @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name,$value) = split(/=/,$pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } if ($FORM{'action'} eq 'appetizers') { $page_title = 'شاشة المقبلات والمازات'; $nav_file = 'includes/menu_app.htm'; $image_file = '../images/appt.gif'; } elsif ($FORM{'action'} eq 'articles') { $page_title = 'شاشة المقالات'; $nav_file = 'includes/menu.htm'; $image_file = '../images/news.gif'; } elsif ($FORM{'action'} eq 'deserts') { $page_title = 'شاشة الحلويات'; $nav_file = 'includes/menu_desert.htm'; $image_file = '../images/desert.gif'; } elsif ($FORM{'action'} eq 'diet') { $page_title = 'شاشة تخفيف الوزن والحميات'; $nav_file = 'includes/menu_diet.htm'; $image_file = '../images/diet.gif'; } elsif ($FORM{'action'} eq 'drinks') { $page_title = 'شاشة العصائر والمشروبات'; $nav_file = 'includes/menu_drink.htm'; $image_file = '../images/drink.gif'; } elsif ($FORM{'action'} eq 'maindishes') { $page_title = 'شاشة الأطباق الرئيسية'; $nav_file = 'includes/menu_dish.htm'; $image_file = '../images/maindish.gif'; } elsif ($FORM{'action'} eq 'salads') { $page_title = 'شاشة السلطات'; $nav_file = 'includes/menu_salad.htm'; $image_file = '../images/salad.gif'; } elsif ($FORM{'action'} eq 'soups') { $page_title = 'شاشة الشوربات'; $nav_file = 'includes/menu_soup.htm'; $image_file = '../images/soup.gif'; } elsif ($FORM{'action'} eq 'pastry') { $page_title = 'شاشة المعجنات'; $nav_file = 'includes/menu_pastry.htm'; $image_file = '../images/pastry1.gif'; } elsif ($FORM{'action'} eq 'indomie') { $page_title = 'إندومي - تفنني بوصفاتك'; $nav_file = 'includes/menu.htm'; $image_file = '../images/indomie/indomie-logo.gif'; } elsif ($FORM{'action'} eq 'braun') { $page_title = 'هديّة ومعها عيديّة من بروان'; $nav_file = 'includes/menu.htm'; $image_file = '../images/braun/braun-logo.gif'; } &read_list_file; &return_html; ############################################################# sub read_list_file { my $dbh = AklaatDB::connect (); $dbh->do ('SET NAMES CP1256'); $dbh->do ('SET COLLATION_CONNECTION=CP1256_GENERAL_CI'); $total_rec = $dbh->selectrow_array ("SELECT COUNT(*) FROM recipes WHERE re_type = '$FORM{'action'}'"); $dbh->disconnect (); } ############################################################# sub return_html { print "Content-type: text/html\n\n"; print < $page_title EOM my $data_file="includes/style.htm"; my @raw_data = OpenFile("$basedir$data_file","read"); my $line; foreach $line (@raw_data) { print "$line"; } $data_file="includes/script.htm"; @raw_data = OpenFile("$basedir$data_file","read"); foreach $line (@raw_data) { print "$line"; } print < function callRateScreen(fileName, title) { document.frmPageDetail.title.value = title; document.frmPageDetail.fileName.value = fileName; document.frmPageDetail.submit(); } EOM require "ui/top.pl"; print <     EOM my $bgColor = 0; if ($FORM{'page'} == 0) { $page = 1; } else { $page = $FORM{'page'}; } print ""; my $row_from = (($page * $rec_to_display) - $rec_to_display) + 1; my $row_to = $page * $rec_to_display; my $dbh = AklaatDB::connect (); $dbh->do ('SET NAMES CP1256'); $dbh->do ('SET COLLATION_CONNECTION=CP1256_GENERAL_CI'); #my $sth = $dbh->prepare ("SELECT * FROM recipes WHERE re_type = '$FORM{'action'}' ORDER BY re_sort_title LIMIT $row_from , $row_to"); my $sth = $dbh->prepare ("SELECT * FROM recipes WHERE re_type = '$FORM{'action'}' ORDER BY re_sort_title"); $sth->execute (); my $ref; my $row = 0; while ($ref = $sth->fetchrow_hashref ()) { $row = $row + 1; if (($row < $row_from) || ($row > $row_to)) { next; } if ($bgColor == 0) { print " EOM if (($FORM{'action'} ne 'indomie') && ($FORM{'action'} ne 'braun')) { print ""; } print "
"; &DisplayPageInfo; print "
\n"; $bgColor = 1; } else { print "
\n"; $bgColor = 0; } #print "
"; if ($FORM{'action'} ne 'articles') { print <
"; &show_recipe_rate($ref->{re_filename}); print ""; print ""; print "{re_filename}\">$ref->{re_title}
"; if ($ref->{re_submitted_by} ne '') { print "
"; } print < $ref->{re_description}
EOM } else { print "

"; print "{re_filename}\">$ref->{re_title}"; if ($ref->{re_description} ne '') { print "
 $ref->{re_description}

"; } print "\n"; } #print "
 
"; } print ""; &DisplayPageInfo; print ""; print ""; require "ui/nav.pl"; print ""; $data_file="includes/key_press.htm"; @raw_data = OpenFile("$basedir$data_file","read"); foreach $line (@raw_data) { print "$line"; } print ""; $sth->finish (); $dbh->disconnect (); exit(0); } ############################################################# sub DisplayPageInfo { my ($next_page, $Prev_page, $rec_from, $rec_to, $j, $lastPage); $next_page = $page + 1; $Prev_page = $page - 1; $rec_from = (($page * $rec_to_display) - $rec_to_display) + 1; $rec_to = $page * $rec_to_display; if ($rec_to > $total_rec) { $rec_to = $total_rec; } print ""; print ""; print ""; print ""; print "
  "; print ""; if ($rec_from == 1) { print "  "; } else { print "<<"; print "  "; print "<"; } $lastPage = ceil($total_rec / $rec_to_display); print "  "; print ""; print ""; print " من $lastPage   "; if ($rec_to == $total_rec) { print "  "; } else { print ">"; print "  "; print ">>"; } print "    "; print ""; print "($rec_from - $rec_to من $total_rec)"; print "  
"; } ############################################################# sub OpenFile { my (@temp, $filename, $action, @data); ($filename, $action, @data) = @_; if(lc $action eq "read") # Read File specified by $filename { open DATA,"<$filename" or dienice("Error Opening File, $filename","$!"); @temp = ; close DATA; return @temp; } if(lc $action eq "write") # Write array @data over $filename { open DATA,">$filename" or dienice("Error Opening File, $filename","$!"); print DATA @data; close DATA; } if(lc $action eq "append") # Append array @data on end of $filename { open DATA,">>$filename" or dienice("Error Opening File, $filename","$!"); print DATA @data; close DATA; } } ############################################################# sub ceil { my($number) = shift; return int($number + .99); } ############################################################# sub show_recipe_rate { my($filename) = shift; my $dbh = AklaatDB::connect (); $dbh->do ('SET NAMES CP1256'); $dbh->do ('SET COLLATION_CONNECTION=CP1256_GENERAL_CI'); my $total = $dbh->selectrow_array ("SELECT COUNT(*) FROM rates WHERE recipe = '$filename' GROUP BY recipe"); my $reviews = $dbh->selectrow_array ("SELECT COUNT(*) FROM rates WHERE recipe = '$filename' AND comments != '' GROUP BY recipe"); if ($reviews eq '') { $reviews = 0; } if ($total eq '') { $total = 0; } print < EOM my $red = 0; my $gray = 0; my $count = 0; my $sum = 0; my $sth = $dbh->prepare ("SELECT SUM( genrating ) AS sum, COUNT( recipe ) AS count FROM rates WHERE genrating > 0 AND recipe = '$filename' GROUP BY recipe"); $sth->execute (); my $ref; while ($ref = $sth->fetchrow_hashref ()) { $sum = $ref->{sum}; $count = $ref->{count}; } if ($count != 0) { $red = AklaatDB::round($sum / $count); } $gray = 5 - $red; print ""; for($count=0; $count<$gray; $count++) { print "*"; } print ""; print ""; for($count=0; $count<$red; $count++) { print "*"; } print < تقيمات: $total
تعليقات: $reviews
EOM } #############################################################