];
# $footer is the HTML code that will go at the bottom of pages
# generated by the program. The same rules apply as to $header
# above. You may also leave this as it is, and it will work fine.
# Again, ONLY change between the lines that say
# and
$footer = qq[
|
|
|
|
|
|
Fitness Cardio © tous droits réservés - reproduction interdite
|
];
# Now, would you like the default to be Kilograms, or Pounds for the
# person entering his or her weight? If you would like it to be
# Kilograms, please set this to $default_weight = "k"; Otherwise,
# set this to $default_weight = "p";
$default_weight = "k";
# And, would you like the default to be Centimeters, or Inches for the
# person entering his or her height? If you would like it to be
# Centimeters, please set this to $default_height = "c"; Otherwise,
# set this to $default_height = "i";
$default_height = "c";
# Okay, one last thing: there are various little question marks that,
# when clicked on, pop up a window with explanations about things.
# The text in these popup windows can be modified by changing the $notes,
# $bmi_notes, $lifestyle_notes, and $bmr_notes variables below. For
# each of these, you may change the explanation using pretty much any
# HTML code you choose, but please, only change in between the
# and tags,
# where by "something" I mean "HB", "BMI," "BMR", or "Lifestyle" as
# appropriate. You should also know that the $ and @ signs are interpreted
# in a special way by the Perl programming language, so if you use them,
# they will not show up unless you put a backslash in front of them, like
# \$ or \@. In some versions of Perl, using @ without a backslash will
# break the program so you'll get "Internal Server Error." Just a word
# to the wise. :-)
$notes = qq[
A propos de ce calculateur
Ce calculateur utilise la méthode Harris-Benedict pour determiner vos besoins caloriques quotidiens.
Comme tout les calculateurs internet, celui-ci comporte une marge d'erreur, et ne se substitue en aucun cas à un spécialiste, qui analysera avec précision vos habitudes alimentaires, votre poids, votre taille et donc l'ensemble de vos besoins caloriques.
];
# Here is the explanation for BMR
$bmr_notes = qq[
Métabolisme Basal
On parle ici des besoins de base de votre corps, sans tenir compte de votre activité physique.
Cette information est un outil supplémentaire, pouvant vous aidez a comprendre le principe des calories et de vos besoins en calorie.
];
# Here is the explanation for the "lifestyle" part of the calculator
$lifestyle_notes = qq[
Activités physiques
Votre activité physique va augmenter vos besoins quotidien en calorie. De façon ponctuelle (Cardio-training) ou régulière (Activité professionnelle ou musculation)
Aucune activité physique : Vous ne pratiquez aucun sport, aucune activité physique...
Normal, sédentaire : Vous avez quelques activités physiques, ne pratiquez aucun sport, et aucune activité professionnelle.
Professionnelle : Vous travaillez dans un bureau, aucun travail de force, vous ne pratiquez aucun sport.
Pratique de la musculation : Vous pratiquez régulièrement la musculation, mais aucun autre sport.
Activité de Cardio-training : Vous pratiquez régulièrement un sport comme le vélo, le tennis, la natation ou le jogging.
Cardio-training + Musculation : Vous pratiquez régulièrement la musculation et un autre sport comme le vélo, le tennis, la natation ou le jogging.
]; # <-- Do not touch this. :-)
# And finally, here is the explanation for the "BMI" part of the
# calculator.
$bmi_notes = qq[
Activités physiques : A propos de l'IMC
L'IMC (indice de masse corporelle) détermine le taux de gras.
Ce taux est un indicateur de votre surchage pondérale.
Formule de calcul de Masse corporelle:
| ( |
Poids en livres |
) |
* 703 |
| ______________ |
| Taille en pouce 2 |
Attention : Si vous êtes particulièrement musclé (Masse musculaire importante) l'indice IMC peut vous classer dans "obèse"
];
# $about_hb_height is for the height (in pixels) of the popup explanation
# window. You may **CHANGE** this to get a taller window. Note: it's
# probably a bad idea to make this bigger than 600.
$about_hb_height = "400";
# $about_hb_width is for the width (in pixels) of the popup explanation
# window. You may **CHANGE** this to get a wider window. It's probably
# a bad idea to make this bigger than 400.
$about_hb_width = "300";
#########################################################################
##### #
##### This is the end of the part where you must **CHANGE** #
##### things. Feel free to look through the code if you are #
##### interested in checking out such things, but don't change #
##### anything beyond this point unless you know what you're doing. #
##### Since this is a free script, there is no warranty, but if there #
##### were a warranty, you'd definitely void it if you modified stuff #
##### below this line. :-) #
##### #
#########################################################################
# First, we get the data submitted on the form into variables we can
# use.
# This line just makes it so everything printed by the script is printed
# immediately instead of being "buffered."
$| = 1;
# This line calles the parse_form_data subroutine, which grabs all the
# input from the form into an associative array so we can use the
# variables.
%data = &parse_form_data();
# And this line must be in any CGI script: it tells your web browser
# that HTML stuff is coming out. If you had a CGI script that showed
# an image, you might use "Content-type: image/gif", but you have to
# have a content-type (or MIME header) of some kind. If you were using
# the Perl CGI module with "use CGI;" then you could probably do something
# like "print header;" but oddly enough, a lot of servers don't have the
# CGI module, so we're taking no chances.
print "Content-type: text/html\n\n";
# If you remove this link, without replacing it with a similar
# HTML comment (as above in the License section) you are in violation
# of the license for this program. No, I don't have the resources to
# enforce this, and I know that some people will remove it anyway.
# But honestly, since you didn't have to pay for this, is the link
# really too much to ask? :)
$footer = "$footer";
#################################################################
# If it's one of the popup window links that people are clicking on,
# we're just going to print out whatever explanation there is, and exit.
if($data{'FA'} eq "AboutHB"){ &print_explanation($notes); }
if($data{'FA'} eq "AboutBMR"){ &print_explanation($bmr_notes); }
if($data{'FA'} eq "AboutBMI"){ &print_explanation($bmi_notes); }
if($data{'FA'} eq "AboutLifestyle"){ &print_explanation($lifestyle_notes); }
# If not, then we're going to print the whole form and so forth. First,
# print our HTML for the top of the page.
print $header;
# Now, figure out whether they chose kilos/centimeters or pounds/inches.
# They could also choose pounds/centimeters, or kilos/inches. We will
# convert if necessary. :-)
$kilos_or_pounds = $data{'wt'};
$centimeters_or_inches = $data{'ht'};
# This next set of things is just checking so that if they enter
# strange values (weight less than 0 or gender that is not "m" or "f",
# age over 120, etc) we just show a little red * next to the form
# field, and don't bother trying to calculate anything. :-)
# If weight is not a number at all, or if it is blank, or if it
# is less than or equal to zero, do the error.
$weight = $data{'weight'};
if($weight * 1 ne $weight || $weight eq "" || $weight <= 0){
$errweight = "*";
$no_calc = 1;
}
# Same for height.
$height = $data{'height'};
if($height * 1 ne $height || $height eq "" || $height <=0 ){
$errheight = "*";
$no_calc = 1;
}
# Same for age, except we also don't allow ages over 120.
# My apologies in advance to anyone over the age of 120
# attempting to use this calculator.
$age = $data{'age'};
if($age == 0 || $age eq "" || $age > 120 | $age < 0){
$errage = "*";
$no_calc = 1;
}
# If gender is not "m" or "f", do an error.
$gender = $data{'gender'};
if($gender ne "m" && $gender ne "f"){
$errgender = "*";
$no_calc = 1;
}
# If their lifestyle is "bed bound," or anything but the general
# lifestyle multiples, we just call it the same as the BMR.
# I don't think you're really supposed to do this with Harris-Benedict
# calculations, but I have, in the past, wanted to do the base calculation
# so therefore everyone gets to.
$lifestyle = $data{'lifestyle'};
if($lifestyle != 1.2 &&
$lifestyle != 1.375 &&
$lifestyle != 1.55 &&
$lifestyle != 1.725 &&
$lifestyle != 1.9){
$lifestyle = 1;
}
# Set a variable to tell us it's okay to do the calculations if we
# didn't hit one of our errors above.
if($no_calc != 1){ $do_calc = 1; }
# We're just going to do the formula in pounds and inches, regardless.
# So, if they entered it in kilos or centimeters, we need to convert.
# Since the answers are ratios, the numbers will be the same whichever
# we use.
if($kilos_or_pounds eq "k"){
$weight = &convert_to_pounds($weight);
}
else {
$weight = $weight;
}
if($centimeters_or_inches eq "c"){
$height = &convert_to_inches($height);
}
else {
$height = $height;
}
# There are two formulae for BMR: one for men and one for women. If they
# entered female, do the one for women. The sprintf() thing tells it
# to display as a number with no decimal places.
if($gender eq "f" && $do_calc == 1){
# This is the female version of the formula
$BMR = sprintf("%d", 655 + (4.35 * $weight) + (4.7 * $height) - (4.7 * $age));
}
# Otherwise, do the one for men.
elsif($gender eq "m" && $do_calc == 1){
# This is the male version of the formula
$BMR = sprintf("%d", 66 + (6.23 * $weight) + (12.7 * $height) - (6.8 * $age));
}
# If they're not male or female, or there was another error above,
# then it's No BMR for You!
else {
$BMR = 0;
}
# We're also going to do some little calcs for plus and minus 5 and 20% so
# people can see a range. sprintf("%d", some number) makes it chop off any
# decimal places and just show a whole number.
$HB_main = sprintf("%d",$BMR * $lifestyle);
$BMR_plus_20 = sprintf("%d", $BMR + ($BMR * 0.2));
$HB_plus_20 = sprintf("%d",$BMR_plus_20 * $lifestyle);
$BMR_plus_5 = sprintf("%d",$BMR + ($BMR * 0.05));
$HB_plus_5 = sprintf("%d",$BMR_plus_5 * $lifestyle);
$BMR_minus_20 = sprintf("%d",$BMR - ($BMR * 0.2));
$HB_minus_20 = sprintf("%d",$BMR_minus_20 * $lifestyle);
$BMR_minus_5 = sprintf("%d",$BMR - ($BMR * 0.05));
$HB_minus_5 = sprintf("%d",$BMR_minus_5 * $lifestyle);
$HB = qq[| Métabolisme basal ] .
qq[(?)] .
qq[ | Besoins en calories ] .
qq[(?)] .
qq[ |
| - 20% = | $BMR_minus_20 |
- 20% = | $HB_minus_20 |
| - 5% = | $BMR_minus_5 |
- 5% = | $HB_minus_5 |
| Besoins par jour : | $BMR |
Besoins par jour : | $HB_main |
| + 5% = | $BMR_plus_5 |
+ 5%: | $HB_plus_5 |
| +20% = | $BMR_plus_20 |
+ 20% = | $HB_plus_20 |
];
# Now everything is in pounds and inches, since HB is relative anyway.
# Calculate BMI because the code was already stolen from SFEBMIcalc and
# what the heck -- give people more info!
if($weight > 0 && $height > 0){
$BMI = sprintf("%.02f", ( $weight / ($height * $height)) * 703);
}
else {
$BMI = "?";
}
# The get_form subroutine pretty much prints out the form, saves whatever
# they entered, etc.
print &get_form;
$about_hb_link = qq[] .
qq[infos calculateur];
print qq[
|
];
print "$HB" if $HB;
print "Vos besoins en calories sont inconnus: calculez les!" if !$HB;
print qq[
|
];
print $about_hb_link;
print qq[
|
];
print $footer;
exit();
sub get_form {
$form = "
Calcul des besoins quotidiens en calories
(Basé sur la formule Harris-Benedict)
|
| Masse corporelle (IMC) |
Résultats |
| + de 29.9 |
Obésité |
| Entre 25.0 et 29.9 |
Surcharge pondérale |
| Entre 18.5 et 24.9 |
Poids normal |
| Moins de 18.5 |
Poids insuffisant |
| Votre IMC : |
$BMI |
| A propos de l'IMC |
|
| |
";
$form;
}
sub parse_form_data {
my($string,%data,@data);
# get data
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$_ = $string = $ENV{'QUERY_STRING'};
tr/\"~;/_/;
$string = $_;
}
else { read(STDIN, $string, $ENV{'CONTENT_LENGTH'});
$_ = $string;
$OK_CHARS='a-zA-Z0-9=&%\n\/_\-\.@';
tr/\"~;/_/;
$string = $_;
}
# split data into name=value pairs
@data = split(/&/, $string);
# split into name=value pairs in associative array
foreach (@data) {
split(/=/, $_);
$_[0] =~ s/\+/ /g; # plus to space
$_[0] =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric
$data{"$_[0]"} = $_[1];
}
# translate special characters
foreach (keys %data) {
$data{"$_"} =~ s/\+/ /g; # plus to space
$data{"$_"} =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric
}
%data; # return associative array of name=value
}
sub convert_to_pounds {
my($kilos) = $_[0];
my($pounds) = $kilos * 2.20462262;
$pounds;
}
sub convert_to_inches {
my($centimeters) = $_[0];
my($inches) = $centimeters * 0.393700787;
$inches;
}
sub print_explanation {
print "$_[0]";
exit();
}
|
| |