package ONO::FW::Edu::Apps::Modules::Money;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2022-2026 Jos Kirps and The Joopita Project [ASBL]
# Copyright (C) 2011-2022 Jos Kirps and Joopita Research ASBL
# Copyright (C) 2006-2011 Jos Kirps and The Joopita Project
# Copyright (C) 2001-2006 Jos Kirps and The WobbleWolf Project
#
# This file, as well as many other parts of the ONO Software Project or
# related elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
#: This module is a front end application module wrapper that has been
#: created for the Morzino Project (morzino.com) and that has been released
#: as Open Source software.
#:
#: Note that this is NOT a self-contained application, it is only a wrapper
#: that makes heavy use of the ONO Perl Framework application engine.
use strict;
use ONO::FW::Edu::Apps::ToolBox;
use ONO::FW::Edu::Apps::Modules::WorksheetMaker::Input;
use ONO::FW::Apps::ToolBox;
use ONO::FW::Apps::PDF;
use ONO::Lib::PDF::Draw;
use ONO::Lib::PDF::ToolBox;
use ONO::Lib::Code::RandomID;
use ONO::FW::Apps::Core;
use ONO::FW::Apps::Core::Graphics;
use ONO::FW::Apps::Core::Math;
use ONO::Lib::Parser;
use ONO::IO;
sub learn {
my (
$self,
$option,
$vars_ref,
$HTTP,
$BASE,
) = @_;
################################################################
# INIT - BEGIN
################################################################
my (
$db,
$community,
$action_url,
$form,
$format,
$canvas,
$pdfkey,
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$timestamp,
$lang,
$BLK_ref,
$vars_ref,
) = ONO::FW::Apps::Core->init($vars_ref);
my %vars = %$vars_ref;
my %BLK = %$BLK_ref;
my $app = "money";
ONO::FW::Apps::Core->now("",$app,$vars{'app_lang'});
my $currency = ¤cy;
my $currency_def = $currency;
my $symbol_cent = "c";
if ($vars{'app_lang'} =~ /(de|lu)/) {
$symbol_cent = "ct";
}
my $AppName = "Money";
my @txt = (
"count the money",
"give the money",
"pay & return money",
"compare",
"calculate",
"",
"coin",
"coins",
"note",
"notes",
"",
"You give",
"You get",
);
if ($vars{'app_lang'} eq "de") {
$currency = "eur";
$currency_def = "eur";
$AppName = "Geld";
@txt = (
"zähle das Geld",
"lege das Geld",
"zahlen & Geld zurück",
"vergleiche",
"rechne",
"",
"Münze",
"Münzen",
"Schein",
"Scheine",
"",
"Du gibst",
"Du bekommst zurück",
);
}
if ($vars{'app_lang'} eq "lu" || ONO::IO->devstation) {
$currency = "eur";
$currency_def = "eur";
$AppName = "Geld";
@txt = (
"ziel d'Geld",
"lee d'Geld eraus",
"bezuelen & Geld zréck",
"vergläichen",
"rechnen",
"",
"Mënz",
"Mënzen",
"Schäin",
"Schäiner",
"",
"Du gëss",
"Du kriss zréck",
);
}
if ($vars{'app_lang'} eq "fr") {
$currency = "eur";
$currency_def = "eur";
$AppName = "Argent";
@txt = (
"compter l'argent",
"donner l'argent",
"payer & retourner argent",
"comparer",
"calculer",
"",
"piece",
"pieces",
"billet",
"billets",
"",
"Tu donnes",
"Tu reçois",
);
}
if ($vars{'app_input_currency'}) {
$currency = $vars{'app_input_currency'};
}
my @usd = &curr_usd;
my @eur = &curr_eur;
my @gbp = &curr_gbp;
my @chf = &curr_chf;
my $symbol = "$";
my $symbol_code = "\044";
my @money = @usd;
if ($currency eq "eur") {
$symbol = "€";
$symbol_code = "\200";
@money = @eur;
}
if ($currency eq "gbp") {
$symbol = "£";
$symbol_code = "\243";
@money = @gbp;
}
if ($currency eq "chf") {
$symbol = "F";
$symbol_code = "F";
@money = @chf;
}
my ($num_comma,$num_delimiter) = ONO::FW::Apps::Core->local_comma_delimiter(ONO::FW::Apps::Core->detect_local($vars{'app_lang'}),$vars_ref);
my $WEB;
$vars{'app_input_print_options_title_default'} = $AppName;
$WEB .= ONO::FW::Apps::Core->output_paper_save($pdfkey,$BLK_ref,\%vars,$HTTP,$BASE,"$year$mon$mday");
if (ONO::FW::Apps::Core->running(\%vars,$db)) {
$WEB .= ONO::FW::Apps::Core->blockbackbutton($BASE,$vars_ref);
(
$vars{'app_input_range_from'},
$vars{'app_input_range_to'},
) = ONO::FW::Apps::Core->range_check(
100,
1000,
$vars{'app_input_range_from'},
$vars{'app_input_range_to'},
$vars{'app_input_negative'},
$vars{'app_input_numsys_status'},
);
#############################################################
# WORKSHEET MAKER
#############################################################
if ($vars{'output_worksheet_maker'}) {
$vars_ref = ONO::FW::Edu::Apps::Modules::WorksheetMaker::Input->vars(\%vars);
%vars = %$vars_ref;
}
#############################################################
# ONLINE TRAINING
#############################################################
if ($vars{'output_web'} || $vars{'output_paper'}) {
if ($vars{'output_web_continue_key'}) {
foreach my $key (keys %vars) {
if ($key =~ /^output_web_cache_false/) {
$vars{$key} = "";
}
}
}
if ($vars{'output_web'} && ($vars{'app_input_exercise'} eq "compare" || $vars{'output_web_cache_exercise'} eq "compare") && $vars{'output_web_continue_key'}) {
$vars{'output_web_question_number'}++;
if ($vars{'compare_mistake'}) {
$vars{'output_web_mistakes'}++;
}
}
my $question_number = ONO::FW::Apps::Core->question_number($vars{'output_web_question_number'});
my (
$page,$pages,%cache,
$whilecounter,$stats_switches,
$PDF_OPTS,
$stat_correct,$stat_wrong,$stat_todo,
);
my $questions_per_page = 1;
if ($vars{'output_paper'}) {
$questions_per_page = 8;
$PDF_OPTS = ONO::FW::Apps::Core->headers_options($BLK_ref,$vars_ref);
ONO::FW::Apps::PDF->new("$BASE/pdf/pdf-$pdfkey.pdf","",$format);
$vars{'app_input_multiple_questions_per_page'}++;
}
if ($vars{'output_worksheet_maker'}) {
$questions_per_page = 2;
}
foreach my $copy (ONO::FW::Apps::Core->unique_copies($vars{'app_input_print_options_unique_copies'})) {
my (@corr_cache,@corr_cache_add);
if ($vars{'output_paper'}) {
if ($copy > 1) {
ONO::FW::Apps::PDF->page("",$format);
}
ONO::FW::Apps::Core->headers(\%vars,$format);
ONO::FW::Apps::PDF->title($vars{'app_input_print_options_title'},$PDF_OPTS,$vars{'app_input_print_options_code'},$format);
ONO::FW::Apps::Core->unique_copies_info($canvas,$copy,$vars_ref);
ONO::FW::Apps::Core::Graphics->pdf_draw_item_numbers($canvas,-2,0,1,8,"dHV",$vars_ref);
# ONO::Lib::PDF::ToolBox->canvas_test($canvas);
}
if ($vars{'output_web'}) {
$WEB .= qq~<$form>~;
$WEB .= ONO::FW::Apps::Core->question_progress($vars{'app_input_number_of_questions'},$question_number,ONO::FW::Apps::Core->stats("",$BLK_ref,"ctWm$stats_switches"));
}
if ($vars{'output_web_completed'}) {
my $msg_switches;
$vars{'output_progress_done'}++;
$WEB .= ONO::FW::Apps::Core->question_progress_done_msg(
$app,$db,$community,$form,$action_url,
$vars{'app_input_number_of_questions'},$vars{'output_web_mistakes'},
$lang,$BLK_ref,$vars_ref,$msg_switches,
);
} else {
$WEB .= ONO::FW::Apps::Core->timer($vars{'output_web'},$vars{'output_web_timer_start'});
# LOGIC - START
my %used;
# compile the list with elements to use
if (!$vars{'app_input_elements'}) {
foreach my $key (sort %vars) {
if ($key =~ /^app_input_use_element_$vars{'app_input_currency'}_(.*?)$/ && $vars{$key}) {
$vars{'app_input_elements'} .= "$1:";
if ($1 =~ /c/) {
$vars{'app_is_using_cents'}++;
}
}
}
if (!$vars{'app_input_elements'}) {
$vars{'app_input_elements'} = "e001:";
}
}
my @moneys = split(/:/,$vars{'app_input_elements'});
my $moneys_num = @moneys;
my $comma_enable;
if ($vars{'output_web_cache_comma_enable'}) {
$comma_enable = $vars{'output_web_cache_comma_enable'}
} else {
$comma_enable = &comma_enable("",$vars{'app_input_currency_display'});
}
# LOGIC - END
for (my $i = 0; $i < $questions_per_page; $i++) {
# pdf_y
my $pdf_y = &pdf_y_calc($i,$vars{'output_worksheet_maker'});
# exercise type
my $exercise_type = $vars{'output_web_cache_exercise'};
if (!$exercise_type || $vars{'output_web_continue_key'}) {
$exercise_type = $vars{'app_input_exercise'};
}
if ($exercise_type eq "random") {
my @types = ('count','give','return','compare','calculate');
my $types_num = @types;
$exercise_type = $types[int(rand($types_num))];
if ($used{"extype_$exercise_type"}) {
$exercise_type = $types[int(rand($types_num))];
}
$used{"extype_$exercise_type"}++;
}
my $HTML;
# LOGIC - START
if ($vars{'output_web'} || $vars{'output_paper'}) {
my ($pdf_insert,$answer1,$answer2);
if (!$vars{'questions'} || $vars{'output_web_continue_key'} || $vars{'output_paper'}) {
$vars{'questions'} = 1 + int(rand($vars{'app_input_max'}));
}
$WEB .= qq~<input type="hidden" name="questions" value="$vars{'questions'}">~;
# compare or calculate
if ($exercise_type) {
my (@VAL,@NUMS,@CALC,@PDF_LENGTH,$CENTER,@ans1,@ans2,$op);
my $height = 350;
my $blocks = 2;
if ($exercise_type =~ /^(count|give)$/) {
$height = 250;
$blocks = 1;
}
if ($exercise_type =~ /^(return)$/) {
$height = 250;
}
if ($exercise_type =~ /^calc/) {
$op = $vars{'output_web_cache_op'};
if (!$vars{'output_web_cache_op'} || $vars{'output_web_continue_key'}) {
$op = "add";
if (int(rand(100)) > 50) {
$op = "sub";
}
}
if ($exercise_type =~ /^calc_(add|sub)$/) {
$op = $1;
}
}
# number generator - step 1 of 2
my $abs_max = 999;
for (my $v = 1; $v < $blocks+1; $v++) {
if (!$vars{'output_web_continue_key'}) {
$NUMS[$v] = $vars{"output_web_cache_nums_$v"};
$ans1[$v] = $vars{"output_web_cache_answer_${v}_1"};
$ans2[$v] = $vars{"output_web_cache_answer_${v}_2"};
}
if (!$NUMS[$v]) {
my $total_num = 0;
my $total_val = 0;
my $total_max = 1 + int(rand($vars{'app_input_max'}));
if ($exercise_type =~ /^calc/) {
if ($v == 2) {
$abs_max = 1+int(rand($vars{'app_input_range_to'}-$abs_max));
} else {
$abs_max = 1+int(rand($vars{'app_input_range_to'}-1));
}
}
for (my $n = 0; $n < 1024; $n++) {
my $use = $moneys[int(rand($moneys_num))];
my $use_val;
if ($use !~ /c/) {
$use_val = $use;
$use_val =~ s~[^0-9]~~g;
}
if ($total_val + $use_val < $vars{'app_input_range_to'} && $total_num < $total_max && $total_val + $use_val < $abs_max+1) {
$total_val = $total_val + $use_val;
$total_num++;
$NUMS[$v] .= "$use:";
$PDF_LENGTH[$v] = $PDF_LENGTH[$v] + 12;
if ($use_val > 4) {
$PDF_LENGTH[$v] = $PDF_LENGTH[$v] + 8;
}
my $value = $use;
$value =~ s~[^0-9]~~g;
if ($use =~ /c/) {
$ans2[$v] = $ans2[$v] + $value;
} else {
$ans1[$v] = $ans1[$v] + $value;
}
}
}
}
if (!$NUMS[$v]) {
$NUMS[$v] = "e001";
$ans1[$v] = 1;
$ans2[$v] = 0;
}
}
# calc exact values...
my $a1 = &comma_number("",$ans1[1],$ans2[1]);
my $a2 = &comma_number("",$ans1[2],$ans2[2]);
# flip if required
if (($op eq "sub" && $a2 > $a1) || ($exercise_type eq "return" && $a1 > $a2)) {
my @CACHE = ("",$NUMS[1],$NUMS[2],$a1,$a2,$PDF_LENGTH[1],$PDF_LENGTH[2]);
@NUMS = ("",$CACHE[2],$CACHE[1]);
($a1,$a2) = ($CACHE[4],$CACHE[3]);
@PDF_LENGTH = ("",$CACHE[6],$CACHE[5]);
my @CACHE = ($ans1[1],$ans2[1],$ans1[2],$ans2[2]);
($ans1[1],$ans2[1]) = ($CACHE[2],$CACHE[3]);
($ans1[2],$ans2[2]) = ($CACHE[0],$CACHE[1]);
}
$WEB .= qq~<input type="hidden" name="output_web_cache_exercise" value="$exercise_type">
<input type="hidden" name="output_web_cache_nums_1" value="$NUMS[1]">
<input type="hidden" name="output_web_cache_nums_2" value="$NUMS[2]">
<input type="hidden" name="output_web_cache_answer_1_1" value="$ans1[1]">
<input type="hidden" name="output_web_cache_answer_1_2" value="$ans2[1]">
<input type="hidden" name="output_web_cache_answer_2_1" value="$ans1[2]">
<input type="hidden" name="output_web_cache_answer_2_2" value="$ans2[2]">
<input type="hidden" name="output_web_cache_op" value="$op">
~;
if ($exercise_type eq "give") {
$WEB .= qq~<input type="hidden" name="output_web_cache_false_running" value="1">~;
}
# number generator - step 2 of 2
for (my $v = 1; $v < $blocks+1; $v++) {
my ($off_x,$off_y,$use_second_line);
my $start_x = 0;
my $offset_x = 90;
my $limit_x = 70;
if ($exercise_type eq "count" || $exercise_type eq "give") {
$start_x = 2;
$offset_x = 0;
$limit_x = 115;
}
if ($exercise_type =~ /^calc/) {
$start_x = 2;
$offset_x = 63;
$limit_x = 50;
}
my @uses = split(/:/,$NUMS[$v]);
if ($exercise_type eq "give") {
@uses = reverse sort @uses;
}
my $uses_num = @uses;
my $use_count;
foreach my $use (@uses) {
if ($use =~ /[1-9]/) {
$use_count++;
my $value = $use;
$value =~ s~[^0-9]~~g;
my $size = 48;
if ($exercise_type =~ /^(give|compare)/) {
$size = 64;
}
if ($exercise_type =~ /^(count)/) {
$size = 80;
}
my $size2 = $size * 2;
my $DIM;
my $width = 10;
my $width2 = 10;
my $height = 10;
my $border = 0;
if ($use !~ /c/ && &money_large("",$value,$currency)) {
$DIM = qq~ style="width:${size2}px;border:1px solid #999999"~;
if (ONO::IO->devstation) {
$DIM = qq~ style="width:${size2}px;border:1px solid #00cc00"~;
}
$width = 18;
$width2 = 18;
$border = 0.5;
}
if ($vars{'output_web'}) {
if ($exercise_type eq "give") {
$vars{'give_counter'}++;
$VAL[$v] .= &insert_false_items("",$exercise_type,$vars{'give_counter'},\@moneys,$moneys_num,$currency,\%vars);
$vars{'give_counter'}++;
my $ID = ONO::Lib::Code::RandomID->make();
my $TRANS = " trans30";
my $status = 0;
if ($vars{"output_web_cache_false_$vars{'give_counter'}_0_status"}) {
$TRANS = "";
$status = 1;
}
$VAL[$v] .= qq~<div id="answer_false_${ID}_div_id" class="fl mr20 mb10$TRANS" style="height:${size}px" onclick="answer_give_toggle('answer_false_${ID}');">
<img class="block${size} cursorlink" src="/images/money/$vars{'app_input_currency'}/128/$use.png"$DIM alt="">
</div>
<input type="hidden" id="answer_false_${ID}_status_id" name="output_web_cache_false_$vars{'give_counter'}_0_status" value="$status">
<input type="hidden" name="output_web_cache_false_$vars{'give_counter'}_0_value" value="$use">
~;
$vars{'give_counter'}++;
$VAL[$v] .= &insert_false_items("",$exercise_type,$vars{'give_counter'},\@moneys,$moneys_num,$currency,\%vars);
} else {
$VAL[$v] .= qq~<div class="fl mr20 mb10" style="height:${size}px">
<img class="block${size}" src="/images/money/$vars{'app_input_currency'}/128/$use.png"$DIM alt="">
</div>
~;
}
}
if ($vars{'output_paper'}) {
# single line logic
my $ratio = 1;
if ($PDF_LENGTH[$v] > $limit_x) {
$ratio = $limit_x/$PDF_LENGTH[$v];
$width = $width*$ratio;
$height = $height*$ratio;
$off_y = 10-$height;
}
# dual line logic
if ($height < 6.5) {
$height = 6.5;
$width = $width2/10*6.5;
$off_y = 0;
if ($off_x + $width > $limit_x || $off_x - $width < -$limit_x || $use_second_line) {
if (!$use_second_line) {
$off_x = 5;
if ($exercise_type eq "compare" && $v == 1) {
$off_x = -5;
}
}
$off_y = 7;
$use_second_line++;
}
}
if ($exercise_type eq "compare" && $v == 1) {
$start_x = 72;
$off_x = $off_x - $width - (2*$ratio);
}
my $X = int(100*(5 + (($v-1)*$offset_x) + $off_x))/100 + $start_x;
my $Y = int(100*($pdf_y+$height/2))/100+$off_y;
my $IMG = "images/money/$vars{'app_input_currency'}/128/$use.jpg";
if ($exercise_type ne "compare" || $v > 1) {
$off_x = $off_x + $width + (2*$ratio);
}
if ($exercise_type ne "return") {
if ($vars{'output_paper'}) {
if ($exercise_type eq "give") {
if ($width == $height) {
ONO::Lib::PDF::Draw->circle($canvas,$X+$width/2,$Y+$width/2,$width/2,1);
} else {
ONO::Lib::PDF::Draw->rect($canvas,$X,$Y,$X+$width,$Y+$height,1);
}
} else {
ONO::Lib::PDF::Draw->image($canvas,$X,$Y,$width,$height,$IMG,$border);
}
}
$corr_cache_add[$i] .= "IMG;$X;$Y;$width;$height;$IMG;$border:";
}
}
}
}
}
# done...
if ($exercise_type eq "count" || $exercise_type eq "give") {
($answer1,$answer2) = ¢_fix($ans1[1],$ans2[1]);
$corr_cache[$i] = "$exercise_type:$answer1:$answer2:";
if ($vars{'output_paper'}) {
ONO::Lib::PDF::Draw->rect($canvas,5,$pdf_y+2,122,$pdf_y+18,1,"0:155:155:155",0,2);
ONO::Lib::PDF::Draw->font('',20);
ONO::Lib::PDF::Draw->text($canvas,127,$pdf_y+11.75,"=","c");
ONO::Lib::PDF::Draw->font('',12);
}
&pdf_answer_box("",$i,$exercise_type,$canvas,$answer1,$answer2,$symbol_code,$symbol_cent,\%vars);
}
if ($exercise_type eq "compare") {
if ($vars{'output_paper'}) {
ONO::Lib::PDF::Draw->compare_bulb_box($canvas,85,$pdf_y);
}
my ($answer1a,$answer1b) = ¢_fix($ans1[1],$ans2[1]);
my ($answer2a,$answer2b) = ¢_fix($ans1[2],$ans2[2]);
$answer1 = $answer1a;
if ($answer1b) {
$answer1 .= ".$answer1b";
}
$answer2 = $answer2a;
if ($answer2b) {
$answer2 .= ".$answer2b";
}
$corr_cache[$i] = "$exercise_type:$answer1:$answer2:";
if ($vars{'output_web'}) {
my $r1 = 0;
my $r2 = 0;
my $r3 = 0;
if ($a1 < $a2) {
$r1 = 1;
}
if ($a1 == $a2) {
$r2 = 1;
}
if ($a1 > $a2) {
$r3 = 1;
}
$CENTER = qq~<div class="inline mt20">
<a href="javascript:void(0);" onmouseover="compare_over('3');" onmouseout="compare_out('3');" onclick="compare_click('3','$r3');" style="text-decoration:none">
<div id="compare_3" class="box_black radius10 mt20" style="padding:15px 25px 15px 25px">></div>
</a>
<div id="compare_res_3" class="hide" style="padding:15px 25px 15px 25px">></div>
<a href="javascript:void(0);" onmouseover="compare_over('2');" onmouseout="compare_out('2');" onclick="compare_click('2','$r2');" style="text-decoration:none">
<div id="compare_2" class="box_black radius10 mt20" style="padding:15px 25px 15px 25px">=</div>
</a>
<div id="compare_res_2" class="hide" style="padding:15px 25px 15px 25px">=</div>
<a href="javascript:void(0);" onmouseover="compare_over('1');" onmouseout="compare_out('1');" onclick="compare_click('1','$r1');" style="text-decoration:none">
<div id="compare_1" class="box_black radius10 mt20" style="padding:15px 25px 15px 25px"><</div>
</a>
<div id="compare_res_1" class="hide" style="padding:15px 25px 15px 25px"><</div>
<input type="hidden" name="output_web" value="1">
</div>
~;
}
}
if ($exercise_type =~ /^calc/) {
$height = 240;
if ($vars{'output_paper'}) {
&calc_gfx("",$canvas,$pdf_y,$op);
&pdf_answer_box("",$i,$exercise_type,$canvas,0,0,$symbol_code,$symbol_cent,\%vars);
}
my ($answer1a,$answer1b) = ($ans1[1],$ans2[1]);
my ($answer2a,$answer2b) = ($ans1[2],$ans2[2]);
$answer1 = $answer1a + $answer2a;
$answer2 = $answer1b + $answer2b;
if ($op eq "sub") {
$answer1 = $answer1a - $answer2a;
$answer2 = $answer1b - $answer2b;
}
($answer1,$answer2) = ¢_fix($answer1,$answer2);
$corr_cache[$i] = "$exercise_type:$answer1:$answer2:$op:";
}
if ($exercise_type eq "return") {
# strictly limit the price to 999.xx:
my $largest_option = $vars{'largest_option'};
if (!$largest_option) {
foreach my $key (sort %vars) {
if ($key =~ /^app_input_use_element_$vars{'app_input_currency'}_e(.*?)$/ && $vars{$key}) {
if ($1 > $largest_option) {
$largest_option = $1;
}
}
}
$vars{'largest_option'} = $largest_option;
}
my $whilecounter;
while ($whilecounter < 256 && ($ans1[1] > 999 || $ans1[1] > $largest_option)) {
$whilecounter++;
$ans1[1] = int($ans1[1]/2);
}
# limit price to max used value:
# still missing !!!, could be added above ...
# continue...
($answer1,$answer2) = ¢_fix($ans1[1],$ans2[1]);
my $price = $answer1;
if ($answer2) {
$price = "$answer1.$answer2";
}
if (!$answer1) {
$price = "0.$answer2";
}
my $give = $vars{'output_web_cache_give'};
my $give_display = $vars{'output_web_cache_give_display'};
if (!$give || !$give_display || $vars{'output_web_continue_key'}) {
# randomly select a valid give value:
$give = 0;
my $whilecounter;
while ($whilecounter < 256 && (!$give || $used{"$price/$give_display"})) {
$whilecounter++;
my $test = $moneys[int(rand($moneys_num))];
if ($test =~ /^e(.*?)$/) {
my $test_val = $1;
if ($test_val > $price && ($price < 1 || $test_val < $price*2+11)) {
$give = $1;
$give_display = $give;
}
}
}
# try to use two different values, only if price is at least 1
if ($price > 0.99 && int(rand(100)) > 20) {
my $whilecounter;
while ($whilecounter < 128 && ($give_display !~ /\// || $used{"$price/$give_display"})) {
$whilecounter++;
my $test1 = $moneys[int(rand($moneys_num))];
my $test2 = $moneys[int(rand($moneys_num))];
if ($test1 =~ s~e~~ && $test2 =~ s~e~~) {
if ($test1 < $price && $test2 < $price && $test1+$test2 > $price) {
$give_display = "$test1/$test2";
if ($test2 > $test1) {
$give_display = "$test2/$test1";
}
$give = $test1 + $test2;
}
}
}
}
# if nothing found then we'll fall back to default values:
if (!$give) {
$answer1 = 1+int(rand(20));
$give = "020";
$give_display = "020";
}
}
$used{"$price/$give_display"}++;
# calc the return...
my $ret1 = ONO::FW::Apps::Core::Math->fix_fp_rounding($give - $price);
my $ret2;
if ($ret1 =~ /^(.*?)\.(.*?)$/) {
$ret1 = $1;
$ret2 = $2;
if (length $ret2 < 2) {
$ret2 .= 0;
}
}
# display everything...
if ($vars{'output_paper'}) {
&return_gfx("",$canvas,$format,$pdf_y,$price,$symbol_code,$num_comma,$vars_ref);
&return_gfx_money("",$canvas,$pdf_y,$vars{'app_input_currency'},$give_display);
&pdf_answer_box("",$i,$exercise_type,$canvas,$ret1,$ret2,$symbol_code,$symbol_cent,\%vars);
}
if ($vars{'output_web'}) {
my @tag = (int(945/4),int(454/4));
my $GIVE;
foreach my $test (split(/\//,"/$give_display/")) {
if ($test =~ /[1-9]/) {
my $DIM;
if (&money_large("",$test,$currency)) {
$DIM = qq~ style="width:128px;border:1px solid #999999"~;
}
$GIVE .= qq~<div class="inline auto"><div class="p5"><img class="block64" src="/images/money/$vars{'app_input_currency'}/64/e$test.png"$DIM alt=""></div></div>~;
}
}
$VAL[1] = qq~<div class="box_fabric">
<table class="wide_table">
<tr class="vtop">
<td>
<div class="box_paper">
<div class="mt20 mb20">
<div class="rel rot345" style="width:$tag[0]px;height:$tag[1]px">
<img class="block" src="/images/money/price_tag.jpg" style="width:$tag[0]px;height:$tag[1]px" alt="">
<div class="abs" style="top:0px;left:0px;width:$tag[0]px;height:$tag[1]px">
<table class="wide_table" style="height:$tag[1]px">
<tr>
<td><div class="xlarge bold center">$price $symbol</div></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</td>
<td class="w100">
<div class="box_paper ml10">
<div class="inline auto">
<table class="default_table">
<tr>
<td>$GIVE</td>
<td><div class="p10"><img class="block128" src="/images/pix/preview/rgb_low_quality/0378_3.jpg" alt=""></div></td>
<td><div class="p10"><img class="block128" src="/images/pix/preview/rgb_low_quality/0118.jpg" alt=""></div></td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</div>
<input type="hidden" name="output_web_cache_give" value="$give">
<input type="hidden" name="output_web_cache_give_display" value="$give_display">
~;
}
$corr_cache[$i] = "$exercise_type:$price:$give:$give_display:$ret1:$ret2:";
}
if ($vars{'output_web'}) {
if ($exercise_type =~ /^(count|give|return)$/) {
if ($exercise_type =~ /^(return)$/) {
$WEB .= qq~<div class="pad10_0 noselect">
<div>$VAL[1]</div>
<div class="rel center p5 large" style="top:10px">$txt[12]:</div>
</div>
~;
} else {
$WEB .= qq~<div class="pad10_0"><div class="box_paper noselect" style="height:${height}px"><div class="inline w100">$VAL[1]</div></div></div>~;
}
} else {
if ($exercise_type =~ /^(calc)/) {
if ($op eq "add") {
$CENTER = qq~<div class="xlarge bold green rel" style="top:100px">+</div>~;
}
if ($op eq "sub") {
$CENTER = qq~<div class="xlarge bold lightred rel" style="top:100px"">–</div>~;
}
}
$WEB .= qq~<table class="wide_table">
<tr class="vtop">
<td class="w50 pad10_0"><div class="box_paper noselect" style="height:${height}px"><div class="inline">$VAL[1]</div></div></td>
<td class="xlarge center">$CENTER</td>
<td class="w50 pad10_0"><div class="box_paper noselect" style="height:${height}px"><div class="inline">$VAL[2]</div></div></td>
</tr>
</table>
~;
}
if ($exercise_type eq "compare") {
$WEB .= qq~<div id="compare_continue" class="abs w100 hide" style="top:0px">
<div class="w33 auto box_green inline radius10 rel" style="top:330px">
<div class="inline auto"><input type="submit" name="output_web_continue_key" value="$BLK{'continue'}..." class="button_green button_big"></div>
</div>
</div>
<input type="hidden" id="compare_mistake_id" name="compare_mistake" value="0">
<script>
function compare_over(id) {
onojs_class('compare_'+id,'box_yellow radius10 mt20');
}
function compare_out(id) {
onojs_class('compare_'+id,'box_black radius10 mt20 cole');
}
function compare_click(id,res) {
onojs_hide('compare_'+id);
onojs_block('compare_res_'+id);;
if (res > 0) {
onojs_class('compare_res_'+id,'box_green radius10 mt20 cole');
onojs_block('compare_continue');
} else {
onojs_class('compare_res_'+id,'box_red radius10 mt20 cole');
onojs_setvalue('compare_mistake_id','1');
}
}
</script>
~;
}
}
}
}
# LOGIC - END
if ($vars{'output_web'}) {
# default
my @cp = split(/:/,$corr_cache[$i]);
my @chks = ("","<td>$symbol </td>","CnMZ");
# euro + cents
if ($vars{'app_input_elements'} =~ /c/) {
@chks = ("<td>$symbol </td>","<td>$symbol_cent</td>","BCdnMZY");
if ($comma_enable) {
@chks = ("<td>,</td>","<td>$symbol</td>","BCdnMZY");
}
}
# give
if ($exercise_type eq "give") {
# count and check
my ($given1,$given2);
foreach my $key (keys %vars) {
if ($key =~ /^output_web_cache_false_(.*?)_status$/ && $vars{$key} == 1) {
my $id = $1;
if ($vars{"output_web_cache_false_${id}_value"} =~ /^e(.*?)$/) {
$given1 = $given1 + $1;
}
if ($vars{"output_web_cache_false_${id}_value"} =~ /^c(.*?)$/) {
$given2 = $given2 + $1;
}
}
}
if ($given1 || $given2) {
$vars{'output_web_answer_status'} = 2;
if ($cp[1] == $given1 && $cp[2] == $given2) {
$vars{'output_web_answer_status'} = 1;
} else {
$vars{'output_web_mistakes'}++;
}
}
@chks = (qq~<td class="pad10_2">$cp[1] $symbol</td>~,"","CIM");
if ($vars{'app_input_elements'} =~ /c/) {
@chks = (qq~<td class="pad10_2">$cp[1] $symbol</td>~,qq~<td class="pad10_2">$cp[2] $symbol_cent</td>~,"CIM");
if ($comma_enable) {
my $num = &comma_display("",&comma_simplify("",&comma_number("",$cp[1],$cp[2])),$num_comma);
@chks = (qq~<td class="pad10_2">$num $symbol</td>~,"","CIM");
}
}
}
if ($exercise_type eq "return") {
my $price = $cp[1];
my $give = $cp[2];
my $return = ONO::FW::Apps::Core::Math->fix_fp_rounding($give - $price);
$cp[1] = $return;
$cp[2] = 0;
if ($return =~ /^(.*?)\.(.*?)$/) {
$cp[1] = $1;
$cp[2] = $2;
if (length $cp[2] < 2) {
$cp[2] .= "0";
}
}
}
if ($vars{'output_web_answer'} || $vars{'output_web_answer2'}) {
$vars{'output_web_answer_status'} = 2;
if ($cp[1] == $vars{'output_web_answer'} && $cp[2] == $vars{'output_web_answer2'}) {
$vars{'output_web_answer_status'} = 1;
} else {
$vars{'output_web_mistakes'}++;
}
}
if ($exercise_type ne "compare") {
$HTML .= ONO::FW::Apps::Core->check_single(
$chks[0],
$chks[1],
50,
"4:2",
$BLK_ref,
\%vars,
"f$chks[2]",
);
}
$WEB .= qq~<input type="hidden" name="output_web_cache_running" value="1">
<input type="hidden" name="output_web_cache_comma_enable" value="$comma_enable">
<div class="mt20">
$HTML
</div>
~;
if ($exercise_type eq "give") {
$WEB .= qq~<script>
function answer_give_toggle(id) {
if (onojs_getvalue(id+'_status_id') > 0) {
onojs_setvalue(id+'_status_id','0');
onojs_class(id+'_div_id','fl trans30 mr20 mb10');
} else {
onojs_setvalue(id+'_status_id','1');
onojs_class(id+'_div_id','fl mr20 mb10');
}
}
</script>
~;
}
if (ONO::IO->devstation) {
$WEB .= qq~<div class="abs pad10_2 bg_yellow" style="top:500px;left:10px">debug: $cp[1],$cp[2] vs $vars{'output_web_answer'},$vars{'output_web_answer2'}</div>~;
}
}
}
if ($vars{'output_web'}) {
$WEB .= ONO::FW::Apps::Core->input_vars(\%vars);
if ($vars{'app_input_number_of_questions'}-$question_number < 1) {
$WEB .= qq~<input type="hidden" name="output_web_completed" value="1">~;
}
$WEB .= qq~</form>~;
}
}
if (ONO::FW::Apps::Core->print_corrections("$BASE/pdf/pdf-$pdfkey-corr.pdf","",$format,$vars_ref)) {
ONO::FW::Apps::Core->headers(\%vars,$format,"c");
ONO::FW::Apps::PDF->title($BLK{'Corrections'},$PDF_OPTS,$vars{'app_input_print_options_code'},$format);
ONO::FW::Apps::Core->unique_copies_info($canvas,$copy,$vars_ref);
ONO::FW::Apps::Core::Graphics->pdf_draw_item_numbers($canvas,-2,0,1,8,"CdHV",$vars_ref);
# ONO::Lib::PDF::ToolBox->canvas_test($canvas);
for (my $i = 0; $i < $questions_per_page; $i++) {
my $pdf_y = &pdf_y_calc($i,$vars{'output_worksheet_maker'});
my @cp = split(/:/,"$corr_cache[$i]:$corr_cache_add[$i]");
my $exercise_type = $cp[0];
my $xpos = 165;
my $xipos = 0;
# count + give
if ($exercise_type eq "count" || $exercise_type eq "give") {
&pdf_answer_box("",$i,$exercise_type,$canvas,$cp[1],$cp[2],$symbol_code,$symbol_cent,\%vars,1);
for (my $j = 2; $j < 20; $j++) {
my @cp2 = split(/;/,$cp[$j]);
if ($cp2[0] eq "IMG") {
ONO::Lib::PDF::Draw->image($canvas,$cp2[1]+$xipos,$cp2[2],$cp2[3],$cp2[4],$cp2[5],$cp2[6]);
}
}
}
# return
if ($exercise_type eq "return") {
&return_gfx("",$canvas,$format,$pdf_y,$cp[1],$symbol_code,$num_comma,$vars_ref);
&return_gfx_money("",$canvas,$pdf_y,$vars{'app_input_currency'},$cp[3]);
&pdf_answer_box("",$i,$exercise_type,$canvas,$cp[4],$cp[5],$symbol_code,$symbol_cent,\%vars,1);
}
# compare
if ($exercise_type eq "compare") {
for (my $j = 2; $j < 20; $j++) {
my @cp2 = split(/;/,$cp[$j]);
if ($cp2[0] eq "IMG") {
ONO::Lib::PDF::Draw->image($canvas,$cp2[1]+$xipos,$cp2[2],$cp2[3],$cp2[4],$cp2[5],$cp2[6]);
}
}
my $CMP = "=";
if ($cp[1] > $cp[2]) {
$CMP = ">";
}
if ($cp[1] < $cp[2]) {
$CMP = "<";
}
$cp[1] =~ s~^\.~0\.~;
$cp[2] =~ s~^\.~0\.~;
if ($num_comma ne ".") {
$cp[1] =~ s~\.~$num_comma~g;
$cp[2] =~ s~\.~$num_comma~g;
}
ONO::Lib::PDF::Draw->rect($canvas,66,$pdf_y+13.5,104,$pdf_y+18,1,"0:22:22:22","0:244:244:244",1);
ONO::Lib::PDF::Draw->font('H',8);
ONO::Lib::PDF::Draw->text($canvas,74,$pdf_y+16.75,"$cp[1] $symbol_code","c",0,"E");
ONO::Lib::PDF::Draw->text($canvas,97,$pdf_y+16.75,"$cp[2] $symbol_code","c",0,"E");
ONO::Lib::PDF::Draw->compare_bulb_box($canvas,85,$pdf_y,$CMP);
}
# calculate
if ($exercise_type =~ /^calc/) {
for (my $j = 3; $j < 20; $j++) {
my @cp2 = split(/;/,$cp[$j]);
if ($cp2[0] eq "IMG") {
ONO::Lib::PDF::Draw->image($canvas,$cp2[1]+$xipos,$cp2[2],$cp2[3],$cp2[4],$cp2[5],$cp2[6]);
}
}
&calc_gfx("",$canvas,$pdf_y,$cp[3]);
&pdf_answer_box("",$i,$exercise_type,$canvas,$cp[1],$cp[2],$symbol_code,$symbol_cent,\%vars,1);
}
# end
}
}
}
if ($vars{'output_web'}) {
$WEB = ONO::FW::Apps::Core->stats_replace(
$WEB,
$question_number-1,
$stat_wrong,
$vars{'app_input_number_of_questions'}-$question_number+1,
$vars{'output_web_mistakes'},
$page,
$pages,
$vars{'output_web_completed'},
);
}
if ($vars{'output_paper'}) {
ONO::FW::Apps::PDF->end;
$WEB .= ONO::FW::Apps::Core->output_paper($pdfkey,\%BLK,\%vars,$HTTP,$BASE);
}
}
if ($vars{'output_web'}) {
ONO::FW::Apps::Core->varstore($vars{'username'},$vars{'virclass'},$vars{'anonymous'},\%vars);
}
} else {
#############################################################
# EXERCISE SETUP
#############################################################
if (!$vars{'app_input_number_of_questions'}) {
$vars{'app_input_number_of_questions'} = 20;
}
my ($MAX,%chk);
if ($vars{'app_input_exercise'}) {
$chk{$vars{'app_input_exercise'}} = " selected";
}
my $EXERCISE = qq~<div class="select"><select name="app_input_exercise">
<option value="random">$BLK{'all'} ($BLK{'random'})</option>
<option value="random">----</option>
<option value="count"$chk{'count'}>$txt[0]</option>
<option value="give"$chk{'give'}>$BLK{'draw'} ($txt[1])</option>
<option value="compare"$chk{'compare'}>$txt[3] (<=>)</option>
<option value="random">----</option>
<option value="calculate"$chk{'calculate'}>$txt[4] (+ & –)</option>
<option value="calc_add"$chk{'calc_add'}>$txt[4] (+)</option>
<option value="calc_sub"$chk{'calc_sub'}>$txt[4] (–)</option>
<option value="random">----</option>
<option value="return"$chk{'return'}>$txt[2]</option>
</select></div>
~;
# can't be more than 9, as notes would be too big
for (my $i = 1; $i < 9; $i++) {
my $sel;
if ($vars{'app_input_max'} == $i || (!$vars{'app_input_max'} && $i == 5)) {
$sel = " selected";
}
$MAX .= qq~<option value="$i"$sel>$i</option>~;
}
$MAX = qq~<table class="default_table"><tr><td>max.</td><td></td><td class="p0"><div class="select"><select name="app_input_max">$MAX</select></div></td><td></td><td>$txt[7]/$txt[9]</td></tr></table>~;
$chk{$currency} = " selected";
# @uses may contain other currencies...
my @currs = ¤cy_currs("",$currency_def);
my ($CUSTOM,$USE,$SCRIPT,$SelectedSymbol) = ¤cy_select("",$currency,\@currs,\@usd,\@eur,\@gbp,\@chf,\%vars);
$USE .= $SCRIPT;
if ($vars{'app_input_currency'}) {
$CUSTOM .= qq~<div class="select" style="width:60px"><select name="app_input_currency_display">
<option value="">$SelectedSymbol + c</option>
<option value="comma">$SelectedSymbol,c ($BLK{'comma'})</option>
<option value="mixed">$BLK{'mixed'}</option>
</select></div>
~;
}
my $CONF;
$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"","$BLK{'exercise'}",$EXERCISE);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("range", $BLK_ref,\%vars,"",1,100,5000);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"","",$MAX);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"","$BLK{'currency'}",$CUSTOM);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"T","$BLK{'use'}",$USE);
$WEB .= ONO::FW::Apps::Core->conf_box(
$db,
$community,
$app,
$form,
"",
$action_url,
$CONF,
$lang,
$BLK_ref,
\%vars,
"op-ncdi-CDI-lsu-N",
);
my $curr_img = "usd";
if ($vars{'app_input_currency'}) {
$curr_img = $vars{'app_input_currency'};
}
$WEB .= ONO::FW::Apps::Core->infopics(
"screen:320:50:40::money_screenshot_1.jpg",
"sheet:168:190:120:15:money_sheet_1.jpg",
"sheet:168:40:130:-10:money_sheet_2.jpg",
);
$WEB .= qq~<div class="hide720">
<div class="bo abs" style="width:280px;height:128px;top:320px;right:20px">
<img class="block128 abs" src="/images/money/$curr_img/128/e010.png" style="width:280px" alt="">
</div>
<img class="block128 abs" src="/images/money/$curr_img/128/e001.png" style="top:260px;right:40px" alt="">
</div>
~;
if (!$vars{'exercise'}) {
$WEB .= ONO::FW::Apps::Core->info_display(
ONO::FW::Apps::Core->info("info_online_print",$vars{'app_lang'}),
ONO::FW::Apps::Core->info("info_indiv_diff", $vars{'app_lang'}),
);
}
}
my ($status,$WEB) = ONO::Lib::Parser->parse($WEB,$vars_ref);
$WEB .= ONO::FW::Apps::Core->vardump($vars_ref);
$WEB = ONO::FW::Edu::Apps::ToolBox->apps_gate($WEB,$vars_ref);
return $WEB;
}
###################################################################
# SUBS
###################################################################
sub script {
my (
$use,
$class,
) = @_;
return qq~<script>
function ${use}_mouseout(id) {
if (document.getElementById('${use}_element_'+id).value > 0) {
onojs_class('${use}_select_'+id,'fl$class');
} else {
onojs_class('${use}_select_'+id,'fl trans30$class');
}
}
function ${use}_toggle(id) {
if (document.getElementById('${use}_element_'+id).value > 0) {
document.getElementById('${use}_element_'+id).value = '0';
onojs_class('${use}_select_'+id,'fl trans30$class');
} else {
document.getElementById('${use}_element_'+id).value = '1';
onojs_class('${use}_select_'+id,'fl$class');
}
}
</script>
~;
}
sub cent_fix {
my (
$answer1,
$answer2,
) = @_;
my $whilecounter;
while ($answer2 > 99 && $whilecounter < 1024) {
$whilecounter++;
$answer1++;
$answer2 = $answer2 - 100;
}
while ($answer2 < 0 && $whilecounter < 1024) {
$whilecounter++;
$answer1--;
$answer2 = $answer2 + 100;
}
return ($answer1,$answer2);
}
sub comma_cents {
my $cents = $_[1];
if ($cents < 10) {
$cents = "0$cents";
}
if ($cents < 1) {
$cents = "00";
}
return $cents;
}
sub comma_number {
my $money = $_[1];
my $cents = &comma_cents("",$_[2]);
if ($money < 1) {
$money = 0;
}
my $whilecounter;
while ($whilecounter < 1000 && $cents > 99) {
$whilecounter++;
$money++;
$cents = $cents-100;
}
return "$money.$cents";
}
sub comma_enable {
if ($_[1] eq "comma" || ($_[1] eq "mixed" && int(rand(100)) > 50)) {
return 1;
} else {
return 0;
}
}
sub comma_fix {
my $answer = $_[1];
$answer =~ s~\.(0|1|2|3|4|5|6|7|8|9)$~\.${1}0~;
return $answer;
}
sub comma_simplify {
my $num = $_[1];
$num =~ s~\.00$~~;
return $num;
}
sub comma_display {
my $num = $_[1];
if ($_[2] eq ",") {
$num =~ s~\.~\,~;
}
return $num;
}
sub currency {
my $currency = "usd";
if ($ENV{'SERVER_NAME'} =~ /^(lu|de|fr)./ || $ENV{'SERVER_NAME'} =~ /\.(lu|de|fr)$/) {
$currency = "eur";
}
if ($ENV{'SERVER_NAME'} =~ /^(ch)./ || $ENV{'SERVER_NAME'} =~ /\.(ch)$/) {
$currency = "chf";
}
return $currency;
}
sub currency_currs {
my @currs = ('usd','eur','gbp','chf');
if ($_[1] eq "eur") {
@currs = ('eur','gbp','chf','usd');
}
if ($_[1] eq "gbp") {
@currs = ('gbp','eur','chf','usd');
}
if ($_[1] eq "chf") {
@currs = ('eur','chf','gbp','usd');
}
return @currs;
}
sub currency_select {
my (
$self,
$currency,
$currs_ref,
$usd_ref,
$eur_ref,
$gbp_ref,
$chf_ref,
$vars_ref,
$switches,
) = @_;
# -a always show all currencies
my @currs = @$currs_ref;
my @usd = @$usd_ref;
my @eur = @$eur_ref;
my @gbp = @$gbp_ref;
my @chf = @$chf_ref;
my %vars = %$vars_ref;
my ($CUSTOM,$USE,$SCRIPT,$SelectedSymbol);
foreach my $opt (@currs) {
my $OPT = uc $opt;
my $Name = "Dollar";
my $Symbol = "\$";
my @opts = @usd;
my ($color,$hide);
if ($opt eq $currency) {
$color = "_green";
} else {
$hide = " hide";
}
if ($opt eq "eur") {
$Name = "Euro";
$Symbol = "€";
@opts = @eur;
}
if ($opt eq "gbp") {
$Name = "Pound";
$Symbol = "£";
@opts = @gbp;
}
if ($opt eq "chf") {
$Name = "Franken";
$Symbol = "CHf";
@opts = @chf;
}
if (!$vars{'app_input_currency'} || $vars{'app_input_currency'} eq $opt || $switches =~ /a/ || (!$vars{'output_web'} && !$vars{'output_paper'})) {
$CUSTOM .= qq~<a id="use_button_$opt" href="javascript:void(0);" onclick="use_box_select('$opt');" class="button$color">$Symbol</a>~;
}
if ($opt eq $vars{'app_input_currency'}) {
$SelectedSymbol = $Symbol;
}
$USE .= qq~<div id="use_box_$opt" class="inline w100$hide">~;
foreach my $use (@opts) {
my @up = split(/:/,$use);
my ($SHADOW,$STYLE,$TRANS,$SEL);
if ($up[1]) {
$up[1] = int($up[1]/16);
$SHADOW = " bo";
$STYLE = qq~ style="width:$up[1]px"~;
}
if ($up[2] !~ /d/) {
$TRANS = " trans30";
} else {
$SEL = 1;
}
if ($vars{'output_paper'} || $vars{'output_web'}) {
$TRANS = " trans30";
$SEL = 0;
}
if ($vars{"app_input_use_element_${opt}_$up[0]"}) {
$TRANS = "";
$SEL = 1;
}
$USE .= qq~<div id="use_select_${opt}_$up[0]" class="fl$TRANS" onmouseover = "onojs_class('use_select_${opt}_$up[0]','fl trans80');"
onmouseout = "use_mouseout('${opt}_$up[0]')"
onclick = "use_toggle('${opt}_$up[0]');">
<div class="mr10 mb10$SHADOW"><img class="block32" src="/images/money/$opt/32/$up[0].png"$STYLE alt=""></div>
</div>
<input type="hidden" id="use_element_${opt}_$up[0]" name="app_input_use_element_${opt}_$up[0]" value="$SEL">
~;
}
$USE .= qq~</div>~;
}
$SCRIPT .= qq~<input type="hidden" id="app_input_currency_id" name="app_input_currency" value="$currency">
<script>
function use_box_select(opt) {
var opts = ["usd","eur","gbp","chf"];
for (index = 0; index < opts.length; ++index) {
onojs_hide('use_box_'+opts[index]);
onojs_class('use_button_'+opts[index],'button');
}
onojs_block('use_box_'+opt);
onojs_class('use_button_'+opt,'button_green');
onojs_setvalue('app_input_currency_id',opt);
}
</script>
~;
$SCRIPT .= &script("use");
return ($CUSTOM,$USE,$SCRIPT,$SelectedSymbol);
}
sub curr_usd {
return (
'c001::',
'c005::',
'c010::',
'c025::',
'c050::',
'e001:1179:d',
'e002:1234:d',
'e005:1215:d',
'e010:1210:',
'e020:1191:',
'e050:1198:',
'e100:1206:',
);
}
sub curr_eur {
return (
'c001::',
'c002::',
'c005::',
'c010::',
'c020::',
'c050::',
'e001::d',
'e002::d',
'e005:1078:d',
'e010:971:d',
'e020:974:d',
'e050:978:',
'e100:955:',
'e200:986:',
'e500:993:',
);
}
sub curr_gbp {
return (
'c001::',
'c002::',
'c005::',
'c010::',
'c020::',
'c050::',
'e001::d',
'e005:986:d',
'e010:978:d',
'e020:975:',
'e050:941:',
);
}
sub curr_chf {
return (
'c005::',
'c010::',
'c020::',
'c050::',
'e001::d',
'e002::d',
'e010:869:d',
'e020:944:d',
'e100:1126:',
'e200:1203:',
'e1000:1272:',
);
}
sub pdf_answer_box {
my (
$self,
$i,
$exercise_type,
$canvas,
$answer1,
$answer2,
$symbol_code,
$symbol_cent,
$vars_ref,
$corr_mode,
) = @_;
my %vars = %$vars_ref;
if ($vars{'output_paper'}) {
my $pdf_y = &pdf_y_calc($i,$vars{'output_worksheet_maker'});
$answer1 = ONO::FW::Apps::Core::Math->fix_fp_rounding($answer1);
$answer2 = ONO::FW::Apps::Core::Math->fix_fp_rounding($answer2);
ONO::Lib::PDF::Draw->rect($canvas,132,$pdf_y+2,170,$pdf_y+18,1,"0:22:22:22","0:244:244:244",2);
ONO::Lib::PDF::Draw->font('',16);
my $display_cent;
if (!&comma_enable("",$vars{'app_input_currency_display'})) {
$display_cent = 1;
}
if ($exercise_type =~ /^(count|give|return)$/ || $exercise_type =~ /^calc/) { # || ($exercise_type =~ /^calc/ && $corr_mode)) {
$display_cent = 0;
if ($answer2) {
$display_cent = 1;
}
}
if (!$vars{'app_input_currency_display'} && $vars{'app_is_using_cents'}) {
$display_cent = 1;
}
if ($display_cent) {
if ($exercise_type =~ /^(count|return|calc)/) {
ONO::Lib::PDF::Draw->line($canvas,136,$pdf_y+15,149,$pdf_y+15,0.5);
ONO::Lib::PDF::Draw->line($canvas,155,$pdf_y+15,163,$pdf_y+15,0.5);
}
if ($exercise_type eq "give" || $corr_mode) {
my $symbol_cent_off;
if (length $symbol_cent > 1) {
$symbol_cent_off = 1.5;
}
ONO::Lib::PDF::Draw->text($canvas,148,$pdf_y+13,$answer1,"r");
ONO::Lib::PDF::Draw->text($canvas,163-$symbol_cent_off,$pdf_y+13,$answer2,"r");
}
ONO::Lib::PDF::Draw->text($canvas,152,$pdf_y+13,"$symbol_code","r","","E");
ONO::Lib::PDF::Draw->text($canvas,167,$pdf_y+13,"$symbol_cent","r","","E");
} else {
if ($exercise_type =~ /^(count|return|calc)/) {
ONO::Lib::PDF::Draw->line($canvas,138,$pdf_y+15,160,$pdf_y+15,0.5);
}
if ($exercise_type eq "give" || $corr_mode) {
ONO::Lib::PDF::Draw->text($canvas,160,$pdf_y+13,$answer1,"r");
}
ONO::Lib::PDF::Draw->text($canvas,165,$pdf_y+13,"$symbol_code","r","","E");
}
ONO::Lib::PDF::Draw->font('',12);
}
}
sub pdf_y_calc {
if ($_[1]) {
return $_[0] * 21 + 2;
} else {
return $_[0] * 23.75 + 2;
}
}
sub return_gfx {
my (
$self,
$canvas,
$format,
$pdf_y,
$price,
$symbol_code,
$num_comma,
$vars_ref,
) = @_;
my %vars = %$vars_ref;
if ($price =~ /\.(.*?)$/) {
my $cents = $1;
if (length $cents < 2) {
$price .= "0";
}
}
if ($num_comma ne ".") {
$price =~ s~\.~\,~;
}
my $work_y;
if ($vars{'output_worksheet_maker'}) {
$work_y = 8;
}
ONO::Lib::PDF::Draw->place_pdf($canvas,5,$pdf_y-4+$work_y,"images/money/price_tag.pdf",0.09,280,$format);
if (length $price > 5) {
ONO::Lib::PDF::Draw->font('HB',12);
} else {
ONO::Lib::PDF::Draw->font('HB',14);
}
ONO::Lib::PDF::Draw->text($canvas,20,$pdf_y+12,"$price $symbol_code","c",10,"E");
ONO::Lib::PDF::Draw->image($canvas,71.5,$pdf_y+3.5,14,14,"images/pix/preview/rgb_low_quality/0378_3.jpg");
ONO::Lib::PDF::Draw->image($canvas,85,$pdf_y-4,22,22,"images/pix/preview/rgb_low_quality/0118.jpg");
# ONO::Lib::PDF::Draw->image($canvas,87,$pdf_y,18,18,"images/pix/preview/rgb_low_quality/0118.jpg");
ONO::Lib::PDF::Draw->rect($canvas,87.5,$pdf_y+6.5,95,$pdf_y+10,1,"0:125:115:88","0:250:230:175",0.5);
if (length $price > 5) {
ONO::Lib::PDF::Draw->font('',5);
} else {
ONO::Lib::PDF::Draw->font('',6);
}
ONO::Lib::PDF::Draw->text($canvas,91.25,$pdf_y+9,"$price","c");
ONO::Lib::PDF::Draw->font('H',12);
ONO::Lib::PDF::Draw->rect($canvas,40,$pdf_y+2,109,$pdf_y+18,1,"0:155:155:155","",2);
ONO::Lib::PDF::Draw->image($canvas,115,$pdf_y+3.5,14,14,"images/pix/preview/rgb_low_quality/0378_3.jpg");
}
sub return_gfx_money {
my (
$self,
$canvas,
$pdf_y,
$curr,
$give,
) = @_;
my $width = 12;
my $border = 0;
if (&money_large("",$give,$curr)) {
$width = 24;
$border = 0.1;
}
if ($give =~ /^(.*?)\/(.*?)$/) {
my ($give1,$give2) = ($1,$2);
my ($width1,$bor1) = (7.5,0);
my ($width2,$bor2) = (7.5,0);
my $off_x;
if (&money_large("",$give1,$curr)) {
($width1,$bor1) = (15,0.1);
}
if (&money_large("",$give2,$curr)) {
($width2,$bor2) = (15,0.1);
}
if ($width1 == 15 && $width2 == 7.5) {
$off_x = 8;
}
ONO::Lib::PDF::Draw->image($canvas,45,$pdf_y+4,$width1,7.5,"images/money/$curr/128/e$give1.jpg",$bor1);
ONO::Lib::PDF::Draw->image($canvas,53.5+$off_x,$pdf_y+8.5,$width2,7.5,"images/money/$curr/128/e$give2.jpg",$bor2);
} else {
ONO::Lib::PDF::Draw->image($canvas,45,$pdf_y+4,$width,12,"images/money/$curr/128/e$give.jpg",$border);
}
}
sub calc_gfx {
my (
$self,
$canvas,
$pdf_y,
$op,
) = @_;
my $box = 54;
ONO::Lib::PDF::Draw->rect($canvas,5,$pdf_y+2,5+$box,$pdf_y+18,1,"0:155:155:155",0,2);
ONO::Lib::PDF::Draw->rect($canvas,68,$pdf_y+2,68+$box,$pdf_y+18,1,"0:155:155:155",0,2);
if ($op eq "add") {
ONO::Lib::PDF::Draw->line($canvas,61,$pdf_y+10,66,$pdf_y+10,2,"0:55:222:55");
ONO::Lib::PDF::Draw->line($canvas,63.5,$pdf_y+7.5,63.5,$pdf_y+12.5,2,"0:55:222:55");
}
if ($op eq "sub") {
ONO::Lib::PDF::Draw->line($canvas,61,$pdf_y+10,66,$pdf_y+10,2,"0:222:55:55");
}
ONO::Lib::PDF::Draw->font('',20);
ONO::Lib::PDF::Draw->text($canvas,127,$pdf_y+11.75,"=","c");
ONO::Lib::PDF::Draw->font('',12);
}
sub money_large_val {
my $val = $_[1];
if ($val =~ /c/) {
return 0;
} else {
if ($val =~ s/e//gi) {
return (&money_large("",$val,$_[2]));
} else {
return 0;
}
}
}
sub money_large {
if ($_[1] > 5 || ($_[2] ne "chf" && $_[1] > 2)) {
return 1;
} else {
return 0;
}
}
sub insert_false_items {
my (
$self,
$exercise_type,
$give_counter,
$moneys_ref,
$moneys_num,
$currency,
$vars_ref,
) = @_;
my @moneys = @$moneys_ref;
my %vars = %$vars_ref;
my $size = 64;
my $size2 = 128;
my $RET;
if ($exercise_type eq "give") {
for (my $f = 0; $f < 2; $f++) {
my ($run,$false);
if ($vars{'output_web_cache_false_running'}) {
if ($vars{"output_web_cache_false_${give_counter}_${f}_value"}) {
$run = 1;
$false = $vars{"output_web_cache_false_${give_counter}_${f}_value"};
}
} else {
if (int(rand(100)) > 50) {
$run = 1;
}
}
if ($run) {
if (!$false) {
$false = $moneys[int(rand($moneys_num))];
}
my $FDIM;
if (&money_large_val("",$false,$currency)) {
$FDIM = qq~ style="width:${size2}px;border:1px solid #999999"~;
if (ONO::IO->devstation) {
$FDIM = qq~ style="width:${size2}px;border:1px solid #cc0000"~;
}
}
my $ID = ONO::Lib::Code::RandomID->make();
my $TRANS = " trans30";
my $status = 0;
if ($vars{"output_web_cache_false_${give_counter}_${f}_status"}) {
$TRANS = "";
$status = 1;
}
$RET = qq~<div id="answer_false_${ID}_div_id" class="fl mr20 mb10$TRANS" style="height:${size}px" onclick="answer_give_toggle('answer_false_${ID}');">
<img class="block${size} cursorlink" src="/images/money/$vars{'app_input_currency'}/128/$false.png"$FDIM alt="">
</div>
<input type="hidden" id="answer_false_${ID}_status_id" name="output_web_cache_false_${give_counter}_${f}_status" value="$status">
<input type="hidden" name="output_web_cache_false_${give_counter}_${f}_value" value="$false">
~;
}
}
}
return $RET;
}
###################################################################
#### THAT'S IT :-D
###################################################################
1;
__END__