#!/usr/bin/perl use lib qw(/usr/home/web/users/a0017451/html/cgi-bin); use CGI qw(:standard escapeHTML); use AklaatDB; use AklaatUser; use AklaatDB::Session; &parseForm; my $basedir = '/usr/home/web/users/a0017451/html/'; my $dbh = AklaatDB::connect (); $dbh->do ('SET NAMES CP1256'); $dbh->do ('SET COLLATION_CONNECTION=CP1256_GENERAL_CI'); my $fileName = $FORM{'fileName'}; my $query = "SELECT rd_title, rd_submitted_by, rd_prep_time, rd_cook_time, rd_servings, "; $query .= "rd_ingredients, rd_directions, rd_comments, rd_footnote "; $query .= "FROM recipes_detail WHERE rd_filename='$fileName'"; #$query .= "FROM recipes_detail WHERE rd_type not in ('articles','diet')"; #$query .= "FROM recipes_detail WHERE rd_type in ('appetizers')"; my $sth = $dbh->prepare ($query); $sth->execute (); print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "$title"; print "\n"; print "\n"; print "\n"; print "\n"; my ($title, $submitted_by, $prep_time, $cook_time, $servings, $ingredients, $directions, $comments, $footnote); while (my $ref = $sth->fetchrow_hashref ()) { $title = $ref->{rd_title}; $submitted_by = $ref->{rd_submitted_by}; $prep_time = $ref->{rd_prep_time}; $cook_time = $ref->{rd_cook_time}; $servings = $ref->{rd_servings}; $ingredients = $ref->{rd_ingredients}; $directions = $ref->{rd_directions}; $comments = $ref->{rd_comments}; $footnote = $ref->{rd_footnote}; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; PrintHeader($title); PrintDetailBox($submitted_by, $prep_time, $cook_time, $servings); PrintComments($comments); PrintIngredient($ingredients); PrintDirection($directions); PrintFootnote($footnote); PrintFooter(); print "
\n"; } print "\n"; print "\n"; $dbh->disconnect(); ######################################################## sub PrintArticles { my $data_file = "$basedir$FORM{fileName}"; open(FILE,"$data_file") ; my @FILE = ; close(FILE); my $print = 0 ; foreach $line(@FILE) { print $line; if ($line =~ /begincontent/) { print $line ; $print = 1; next ; } if ($line =~ /endcontent/) { $print = 0 ; } if ($print eq "1") { print $line; } } } ######################################################## sub PrintHeader { my ($title) = @_; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
 $title
\n"; print "
\n"; print "\n"; print "
\n"; print "
"; print "www.aklaat.com
\n"; } ######################################################## sub PrintDetailBox { my ($submitted_by, $prep_time, $cook_time, $servings) = @_; print "\n"; print "\n"; print "\n"; print "\n"; #print "\n"; my $count = 0; if ($prep_time ne "") { ++$count; } if ($cook_time ne "") { ++$count; } if ($servings ne "") { ++$count; } if ($count > 0) { #print "\n"; #print "
\n"; #print "
\n"; print "\n"; print "\n"; print "\n"; if ($submitted_by ne "") { print "\n"; print "\n"; } print "\n"; if ($submitted_by ne "") { print "\n"; #print "
\n"; print "مقدمة من: $submitted_by\n"; print ""; print "التقيم: "; } else { print " "; } PrintRecipeRate(); print "
\n"; #print "
\n"; #print "\n"; #print "\n"; print "\n"; if ($count == 1) { print "\n"; print "\n"; } if ($cook_time ne "") { print "مدة الطهي:\n"; print "\n"; } if ($servings ne "") { print "الكمية تكفي:\n"; print "\n"; } print "\n"; } elsif ($count == 2) { my $col = 0; print "\n"; print "\n"; } if ($cook_time ne "") { if ($col == 1) { print "\n"; print "\n"; print "\n"; print "\n"; } if ($servings ne "") { print "\n"; print "\n"; print "\n"; print "\n"; } } elsif ($count == 3) { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "
\n"; if ($prep_time ne "") { print "مدة التحضير: $prep_time $cook_time $servings\n"; if ($prep_time ne "") { $col = 1; print "مدة التحضير: $prep_time
\n"; } print "مدة الطهي: $cook_time
\n"; print "الكمية تكفي: $servings\n"; print "مدة التحضير: $prep_time\n"; print "مدة الطهي: $cook_time
\n"; print "الكمية تكفي: $servings
\n"; print "
\n"; } else { print "\n"; print "\n"; } } ######################################################## sub PrintComments { my ($comments) = @_; if ($comments ne "") { print "
\n"; print "\n"; print "\"$comments\""; print "
\n"; } } ######################################################## sub PrintIngredient { my ($ingredients) = @_; if ($ingredients eq '') { return; } print "
\n"; print "المقادير:
\n"; print "\n"; print "\n"; print "\n"; my @ing = split(/\n/, $ingredients); my $count = scalar(@ing); if (($count % 2) > 0) { $ing{$count} = ""; ++$count; } my $row = 0; print "\n"; print "\n"; print "
\n"; for ($row=0; $row < ($count / 2); $row++) { print "
\n"; print "\n"; print " $ing[$row]
\n"; } print "
\n"; for ($row=($count / 2); $row < $count; $row++) { print "
\n"; print "\n"; print "$ing[$row]
\n"; } print "
\n"; } ######################################################## sub PrintDirection { my ($directions) = @_; if ($directions eq '') { return; } print "
\n"; print "الطريقة:
\n"; print "\n"; print "\n"; my @dir = split(/\n/, $directions); my $count = scalar(@dir); if (($count % 2) > 0) { $dir{$count -1} = ""; } my $dirRow = 0; my $row = 0; my $inc = 1; for ($row=0; $row < $count; $row++) { print "\n"; if (substr ($dir[$row],0,5) eq "\n"; print "$dir[$row]\n"; $inc = 0; } else { $dirRow = $row + $inc; print "\n"; print "\n"; } } print "
$dirRow. \n"; print "\n"; print "$dir[$row]
\n"; } ######################################################## sub PrintFootnote { my ($footnote) = @_; if ($footnote ne "") { print "
\n"; print "\n"; print "$footnote"; print "
\n"; } } ######################################################## sub PrintFooter { ($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $day = (localtime)[3]; $month = ((localtime)[4]) + 1; $year = (localtime)[5] + 1900; $date = "$day/$month/$year"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
© 2010 aklaat.comطبعة من موقع أكلات شهية $date
\n"; } ######################################################## sub PrintRecipeRate { 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; if ($red == 0) { print ""; } elsif ($red == 1) { print ""; } elsif ($red == 2) { print ""; } elsif ($red == 3) { print ""; } elsif ($red == 4) { print ""; } elsif ($red == 5) { print ""; } } ######################################################## sub parseForm { if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } } ########################################################