package ONO::FW::Edu::Apps::Modules::ArithmeticWritten;
################################################################################
# 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::Lib::Basic;
use ONO::FW::Apps::ToolBox;
use ONO::Lib::PDF::Draw;
use ONO::Lib::PDF::ToolBox;
use ONO::FW::Apps::Core;
use ONO::FW::Apps::Core::Graphics;
use ONO::Lib::Parser;
use ONO::FW::Apps::PDF;
use ONO::IO;
use ONO::Lib::UI::Check;
use ONO::Lib::UI::Select;
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 = "written_calc";
ONO::FW::Apps::Core->now("",$app,$vars{'app_lang'});
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;
$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);
# max needs to be 999.998, NOT 999.999 as this would cause serious problems when using 3 operands...
(
$vars{'app_input_range_from'},
$vars{'app_input_range_to'},
) = ONO::FW::Apps::Core->range_check(
899999,
999998,
$vars{'app_input_range_from'},
$vars{'app_input_range_to'},
$vars{'app_input_negative'},
);
# limit max when using comma numbers...
if ($vars{'app_input_comma_status'} > 1 && $vars{'app_input_range_to'} > 99999) {
$vars{'app_input_range_to'} = 99999;
}
#############################################################
# 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'}) {
my $question_number = ONO::FW::Apps::Core->question_number($vars{'output_web_question_number'});
my (
$op_symbol_opts,$focus_on,
$page,$pages,%cache,
$whilecounter,$stats_switches,
$PDF_OPTS,
$stat_correct,$stat_wrong,$stat_todo,$stat_todo_total,
$PROGRESS_BAR,
);
my $questions_per_page = 1;
if ($vars{'output_paper'}) {
$PDF_OPTS = ONO::FW::Apps::Core->headers_options($BLK_ref,$vars_ref);
ONO::FW::Apps::PDF->new("$BASE/pdf/pdf-$pdfkey.pdf","",$format);
$questions_per_page = 12;
if ($vars{'app_input_op_div'}) {
$questions_per_page = 6;
}
$op_symbol_opts = "p";
}
foreach my $copy (ONO::FW::Apps::Core->unique_copies($vars{'app_input_print_options_unique_copies'})) {
my (@op,@op_symbol,@num1,@num2,@num3,@res);
my $pdf_y = 3;
my @corr_cache;
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);
if ($questions_per_page == 6) {
ONO::FW::Apps::Core::Graphics->pdf_draw_item_numbers($canvas,-2,0,1,3,"V",$vars_ref);
} else {
ONO::FW::Apps::Core::Graphics->pdf_draw_item_numbers($canvas,-2,0,1,4,"V",$vars_ref);
}
# ONO::Lib::PDF::ToolBox->canvas_test($canvas);
}
if ($vars{'output_web'}) {
$WEB .= qq~<$form>~;
$op_symbol_opts = "c";
$PROGRESS_BAR .= ONO::FW::Apps::Core->question_progress($vars{'app_input_number_of_questions'},$question_number,"","P");
}
my (@qtext,@qtext2);
if (ONO::FW::Apps::Core->question_progress_done($vars{'app_input_number_of_questions'},$question_number) || $vars{'output_web_finish'}) {
$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);
} else {
$WEB .= ONO::FW::Apps::Core->timer($vars{'output_web'},$vars{'output_web_timer_start'});
my $licount;
if ($vars{'output_worksheet_maker'}) {
$questions_per_page = 3;
$pdf_y = 5;
}
for (my $i = 0; $i < $questions_per_page; $i++) {
if ($vars{'output_web'}) {
$stat_todo++;
$vars{"output_web_answer_$i"} = ONO::FW::Apps::Core->clean_answer_math($vars{"output_web_answer_$i"});
# we need to eliminate commas in this app:
my $expected_result = $vars{"output_web_cache_res_$i"};
$expected_result =~ s~[^0-9]~~g;
# build the answer
if ($vars{"output_web_cache_op_0"} eq "div") {
for (my $x = 0; $x < 20; $x++) {
if ($vars{"flush_all_answers"}) {
$vars{"output_web_answer_$x"} = "";
} else {
$vars{"output_web_answer_$x"} = substr($vars{"output_web_answer_$x"},0,1);
$vars{"output_web_answer"} .= $vars{"output_web_answer_$x"};
}
}
} else {
for (my $y = 0; $y < 20; $y++) {
for (my $x = 0; $x < 20; $x++) {
if ($vars{"flush_all_answers"}) {
$vars{"output_web_answer_${x}_${y}"} = "";
$vars{"output_web_answer_inter_${x}_${y}"} = "";
} else {
$vars{"output_web_answer_${x}_${y}"} = substr($vars{"output_web_answer_${x}_${y}"},0,1);
$vars{"output_web_answer_inter_${x}_${y}"} = substr($vars{"output_web_answer_inter_${x}_${y}"},0,1);
$vars{"output_web_answer"} .= $vars{"output_web_answer_${x}_${y}"};
}
}
}
}
# flush everything (required for divisions to work correctly)
if ($vars{"flush_all_answers"}) {
for (my $y = 0; $y < 20; $y++) {
for (my $x = 0; $x < 20; $x++) {
$vars{"output_web_answer_${x}_${y}"} = "";
$vars{"output_web_answer_inter_${x}_${y}"} = "";
}
}
$vars{"output_web_cache_op_$i"} = "";
$vars{"output_web_cache_num1_$i"} = "";
$vars{"output_web_cache_num2_$i"} = "";
$vars{"output_web_cache_num3_$i"} = "";
$vars{"output_web_cache_res_$i"} = "";
}
# check answer
if (!$vars{"output_web_answer"} || ($vars{"output_web_answer"} != $expected_result)) {
$vars{'output_web_answer_status'} = 2;
$op[$i] = $vars{"output_web_cache_op_$i"};
$num1[$i] = $vars{"output_web_cache_num1_$i"};
$num2[$i] = $vars{"output_web_cache_num2_$i"};
$num3[$i] = $vars{"output_web_cache_num3_$i"};
$res[$i] = $vars{"output_web_cache_res_$i"};
} else {
$question_number++;
$vars{'output_web_answer_status'} = 1;
$vars{'output_web_answer'} = "";
}
}
if (!$op[$i]) {
$op[$i] = ONO::FW::Apps::Core->random_operation(ONO::FW::Apps::Core->get_operations($vars_ref));
}
$op_symbol[$i] = ONO::FW::Apps::Core->operation_symbol($op[$i],$op_symbol_opts);
$vars{'app_input_tens_barrier_long'}++;
my $DEBUG;
if ($op[$i] eq "add") {
($num1[$i],$num2[$i],$res[$i],$cache{'num1'},$cache{'num2'},$DEBUG) = ONO::FW::Apps::Core->generate_add($i,$num1[$i],$num2[$i],$op[$i],$res[$i],$cache{'num1'},$cache{'num2'},\%vars);
# $WEB .= ONO::IO->devprint($DEBUG,0);
}
if ($op[$i] eq "sub") {
($num1[$i],$num2[$i],$res[$i],$cache{'num1'},$cache{'num2'},$DEBUG) = ONO::FW::Apps::Core->generate_sub($i,$num1[$i],$num2[$i],$op[$i],$res[$i],$cache{'num1'},$cache{'num2'},\%vars);
# $WEB .= ONO::IO->devprint($DEBUG,0);
# if (ONO::IO->devstation) {
# ($num1[$i],$num2[$i],$res[$i]) = (348,249,99);
# }
}
if ($vars{'app_input_comma_status'} > 0 && ($op[$i] eq "add" || $op[$i] eq "sub")) {
my ($comma1,$comma2,$comma3);
if ($num1[$i] =~ /\.(.*)$/) {
$comma1 = $1;
}
if ($num2[$i] =~ /\.(.*)$/) {
$comma2 = $1;
}
if ($comma1 || $comma2) {
if ($res[$i] =~ /\.(.*)$/) {
$comma3 = $1;
} else {
$res[$i] .= ".";
}
my $whilecounter;
while ($whilecounter < 255 && (length $comma3 < length $comma1 || length $comma3 < length $comma2)) {
$whilecounter++;
$res[$i] .= "0";
$comma3 .= "0";
}
}
}
if ($op[$i] eq "mul" || $op[$i] eq "div") {
($num1[$i],$num2[$i],$res[$i],$cache{'num1'},$cache{'num2'},$DEBUG) = ONO::FW::Apps::Core->generate_muldiv($i,$num1[$i],$num2[$i],$op[$i],$res[$i],$cache{'num1'},$cache{'num2'},\%vars);
# $WEB .= ONO::IO->devprint($DEBUG,0);
# fix numbers that are too big
my $whilecounter;
while ($whilecounter < 255 && (
(length $num2[$i] > 4 || ($num2[$i] !~ /(\.|\,)/) && length $num2[$i] > 3) ||
($op[$i] eq "mul" && length "$num1[$i]$num2[$i]" > 9) ||
($op[$i] eq "div" && length "$num1[$i]$num2[$i]$res[$i]" > 11)
)
) {
$whilecounter++;
($num1[$i],$num2[$i],$res[$i],$cache{'num1'},$cache{'num2'},$DEBUG) = ONO::FW::Apps::Core->generate_muldiv($i,"","",$op[$i],"","","",\%vars);
}
# $WEB .= ONO::IO->devprint("-$DEBUG",0);
}
# if (ONO::IO->devstation) {
# $WEB .= qq~$vars{'app_input_comma_status'} -> $num1[$i] -- $num2[$i] -- $res[$i]<br>~;
# }
# special mode vars
my $class = "tar";
my $width = 75;
my $qanswer = $res[$i];
# special mode: tri
if ($vars{'app_input_extype_status'} eq "tri" && ($op[$i] eq "add" || $op[$i] eq "sub")) {
if ($num3[$i] eq "") {
$res[$i] = 999999;
my ($whilecounter,$exclude,$debug);
while (($res[$i] < $vars{'app_input_range_from'} || $res[$i] > $vars{'app_input_range_to'} || length $res[$i] > 12 || $exclude) && $whilecounter < 512) {
$whilecounter++;
$exclude = "";
$num3[$i] = ONO::FW::Apps::Core->random_number(1,$vars{'app_input_range_to'},1,999999,\%vars);
if ($whilecounter > 200 && $whilecounter < 300) {
$op[$i] = ONO::FW::Apps::Core->random_operation(ONO::FW::Apps::Core->get_operations($vars_ref));
if ($op[$i] eq "mul" || $op[$i] eq "div") {
$op[$i] = "add";
}
}
if ($whilecounter > 300) {
$op[$i] = "add";
}
# exclude negative numbers
# ? missing?
if (!$exclude) {
$res[$i] = $num1[$i] + $num2[$i] + $num3[$i];
if ($op[$i] eq "add" && $res[$i] > $vars{'app_input_range_to'}) {
my $whilecounter2;
while ($res[$i] > $vars{'app_input_range_to'} && $whilecounter2 < 4096) {
$whilecounter2++;
$num1[$i] = int($num1[$i]/1.5);
$num2[$i] = int($num2[$i]/1.5);
$num3[$i] = int($num3[$i]/1.5);
$res[$i] = $num1[$i] + $num2[$i] + $num3[$i];
}
}
if ($op[$i] eq "sub") {
my $whilecounter2;
while ($num2[$i] > $num1[$i] && $whilecounter2 < 512) {
$whilecounter2++;
$num2[$i] = int($num2[$i]/1.5);
}
while ($num3[$i] > ($num1[$i]-$num2[$i]) && $whilecounter2 < 512) {
$whilecounter2++;
$num3[$i] = int($num3[$i]/1.5);
}
$res[$i] = $num1[$i] - $num2[$i] - $num3[$i];
}
}
if ($vars{'app_input_comma_status'} < 1 && $res[$i] =~ /\./) {
$res[$i] = 999999;
}
}
if (!$res[$i]) {
$num1[$i] = 1;
$num2[$i] = 1;
$num3[$i] = 1;
$op[$i] = "add";
}
}
$op_symbol[$i] = ONO::FW::Apps::Core->operation_symbol($op[$i],$op_symbol_opts);
}
# output paper
if ($vars{'output_paper'}) {
my $max_number_length = ONO::FW::Apps::Core->number_length($vars{'app_input_range_to'},$vars{'app_input_comma_status'});
my @pos = (14,17,26,28,12, 15,26);
if ($vars{'app_input_extype_status'} ne "tri" || $op[$i] eq "mul" || $op[$i] eq "div") {
if ($max_number_length > 3) {
@pos = (12,15,27,28,12, 13,26,"...");
}
if ($max_number_length > 4) {
@pos = (13,16,29,30,11, 13,28,"...");
if ($max_number_length > 5) {
@pos = (13,15,29,30,10, 13,28,".....");
}
if ($max_number_length > 6) {
@pos = (13,15,29,30,8, 13,28,".....");
}
ONO::Lib::PDF::Draw->font('',$pos[4]);
}
}
my $pdf_x = 0;
if ($i && ($i-1)%3 == 0) {
$pdf_x = 60;
}
if ($i && ($i-2)%3 == 0) {
$pdf_x = 120;
}
if ($vars{'app_input_op_div'}) {
$pdf_x = 0;
if ($i && ($i-1)%2 == 0) {
$pdf_x = 90;
}
$pdf_y = 3;
if ($i > 1) {
$pdf_y = 66.5;
}
if ($i > 3) {
$pdf_y = 130;
}
}
$num1[$i] = ONO::FW::Apps::Core->make_human_readable($num1[$i],$num_comma,$num_delimiter);
$num2[$i] = ONO::FW::Apps::Core->make_human_readable($num2[$i],$num_comma,$num_delimiter);
$num3[$i] = ONO::FW::Apps::Core->make_human_readable($num3[$i],$num_comma,$num_delimiter);
$res[$i] = ONO::FW::Apps::Core->make_human_readable($res[$i],$num_comma,$num_delimiter);
$corr_cache[$i] = "$op[$i]\^$op_symbol[$i]\^$num1[$i]\^$num2[$i]\^$num3[$i]\^$res[$i]\^$pdf_x\^$pdf_y\^";
$corr_cache[$i] .= "$pos[0]\^$pos[1]\^$pos[2]\^$pos[3]\^$pos[4]\^$pos[5]\^$pos[6]\^$pos[7]\^";
if ($vars{'app_input_extype_status'} eq "tri" && ($op[$i] eq "add" || $op[$i] eq "sub")) {
# tri mode uses a more static display
if ($max_number_length > 5) {
ONO::Lib::PDF::Draw->font('',9);
}
if ($max_number_length > 6) {
ONO::Lib::PDF::Draw->font('',7.5);
}
if ($max_number_length > 7) {
ONO::Lib::PDF::Draw->font('',6);
}
$qtext[$i] = "$num1[$i] $op_symbol[$i] $num2[$i] $op_symbol[$i] $num3[$i]";
} else {
# normal modes (non-tri)
$qtext[$i] = "$num1[$i] $op_symbol[$i] $num2[$i] =";
}
if ($i && ($i-2)%3 == 0) {
$pdf_y = $pdf_y + 47.5;
}
}
if ($vars{'output_web'}) {
$WEB .= qq~<input type="hidden" name="output_web_cache_op_$i" value="$op[$i]">
<input type="hidden" name="output_web_cache_num1_$i" value="$num1[$i]">
<input type="hidden" name="output_web_cache_num2_$i" value="$num2[$i]">
<input type="hidden" name="output_web_cache_num3_$i" value="$num3[$i]">
<input type="hidden" name="output_web_cache_res_$i" value="$res[$i]">
~;
# special for this app: we need to transfer the initial data to vars
if (!$vars{'output_web_cache_op_0'}) {
$vars{"output_web_cache_op_0"} = $op[$i];
$vars{"output_web_cache_num1_0"} = $num1[$i];
$vars{"output_web_cache_num2_0"} = $num2[$i];
$vars{"output_web_cache_num3_0"} = $num3[$i];
$vars{"output_web_cache_res_0"} = $res[$i];
}
}
}
if ($vars{'output_web'}) {
$WEB .= ONO::FW::Apps::Core->multi_frame_end($vars{'output_web_finish'},$vars{'app_input_multiple_questions_per_page'});
$WEB .= ONO::FW::Apps::Core->input_vars(\%vars);
# we can't use ONO::FW::Apps::Core->check_single here...
if ($vars{'app_input_extype_status'} eq "tri") {
}
my $boxcolor = "fabric";
if ($vars{'output_web_answer_status'} == 1) {
$boxcolor = "green";
}
if ($vars{'output_web_answer'} && $vars{'output_web_answer_status'} == 2) {
$boxcolor = "red";
}
my ($max_x,$max_y) = (9,8);
if ($vars{"output_web_cache_op_0"} eq "div") {
($max_x,$max_y) = (15,11);
}
my (%GRID,@LINE,@COMMA);
for (my $y = 0; $y < $max_y; $y++) {
for (my $x = 0; $x < $max_x; $x++) {
$GRID{"$x,$y"} = qq~<div class="block32"></div>~;
}
}
my $op = "+";
my $num1 = $vars{"output_web_cache_num1_0"};
my $num2 = $vars{"output_web_cache_num2_0"};
my $num3 = $vars{"output_web_cache_num3_0"};
my $res = $vars{"output_web_cache_res_0"};
# add / sub
if ($vars{"output_web_cache_op_0"} eq "add" || $vars{"output_web_cache_op_0"} eq "sub") {
if ($vars{"output_web_cache_op_0"} eq "sub") {
$op = "-";
}
my $maxlength = &maxlength("",$num1,$num2,$num3);
my $xfields = 9;
my $maxtail = &maxtail("",$num1,$num2,$num3);
my $qmark = &res2qmark("",$res);
if ($maxtail) {
$xfields = 10;
$COMMA[7-$maxtail] = qq~<td class="bg_darkred"></td>~;
}
my @opts = ($num1,"$op$num2","",$qmark);
my $liline = 3;
my $limax = 1;
if ($num3 ne "") {
@opts = ($num1,"$op$num2","$op$num3","",$qmark);
$LINE[4] = &inter("",$xfields,$maxlength);
$liline = 4;
$limax = 2;
} else {
$LINE[3] = &inter("",$xfields,$maxlength);
}
# render
my ($GRID_ref) = &number_line("","web",$canvas,\@opts,7,1,\%vars);
%GRID = %$GRID_ref;
# little
for (my $li = 9-$maxlength-2; $li < 7; $li++) {
$GRID{"$li,$liline"} = &little("",$limax,$licount,$vars{"little_${licount}_value"});
$licount++;
}
}
# mul + div fix tailing zeroes
my ($num1,$num1b,$num2,$num2b) = &fix_tailing_zeroes("",$op,$num1,$num2);
# mul
if ($vars{"output_web_cache_op_0"} eq "mul") {
$op = "•";
my (@subs,$spos,$thick_y);
for (my $s = 0; $s < length $num2b; $s++) {
my $spacer;
for (my $sp; $sp < (length $num2b)-$spos-1; $sp++) {
$spacer .= " ";
}
@subs = (@subs,&res2qsub("",$num1b*substr($num2b,$spos,1)).$spacer);
$thick_y++;
$spos++;
}
# fix result position
if ($res =~ /(\.|\,)/) {
my $whilecounter;
while (&tail("",$res) < (&tail("",$num1) + &tail("",$num2)) && $whilecounter < 256) {
$whilecounter++;
$res .= "0";
}
} else {
if (&tail("",$num1) || &tail("",$num2)) {
my $whilecounter;
$res .= ",";
while (&tail("",$res) < (&tail("",$num1) + &tail("",$num2)) && $whilecounter < 256) {
$whilecounter++;
$res .= "0";
}
}
}
# thick lines
$LINE[1] = &inter("",9,6);
$LINE[2+$thick_y] = &inter("",9,6);
# render
my $qmark = &res2qmark("",$res);
my @opts = ("${num1}x${num2}",@subs,"",$qmark);
my ($GRID_ref) = &number_line("","web",$canvas,\@opts,7,1,\%vars);
%GRID = %$GRID_ref;
if ($res =~ /(\.|\,)/) {
my $x = 7-&tail("",$res);
my $y = $thick_y+3;
$GRID{"$x,$y"} .= &comma_web("",$1);
}
# little
my $liline = $thick_y + 2;
my $maxlength = &maxlength("",$res);
for (my $li = 9-$maxlength-2; $li < 7; $li++) {
$GRID{"$li,$liline"} = &little("",$maxlength,$licount,$vars{"little_${licount}_value"});
$licount++;
}
}
# div
if ($vars{"output_web_cache_op_0"} eq "div") {
$op = ":";
my $main = "$num1b:$num2b=";
my $main_length = length $main;
for (my $c = 1; $c < $main_length+1; $c++) {
$GRID{"$c,1"} = substr($main,$c-1,1);
}
my $res2 = $res;
$res2 =~ s~[^0-9]~~g;
for (my $r = 0; $r < length $res2; $r++) {
my $pos = $r + $main_length + 1;
my $color;
if ($vars{"output_web_answer_$r"} ne "") {
$color = " bg_red";
}
$GRID{"$pos,1"} = qq~<div class="block32$color">
<input type="text" name="output_web_answer_$r" value="$vars{"output_web_answer_$r"}" class="w20px center" placeholder="?">
</div>
~;
if ($vars{"output_web_answer_$r"} ne "" && $vars{"output_web_answer_$r"} eq substr($vars{'output_web_cache_res_0'},$r,1)) {
$GRID{"$pos,1"} = qq~<span class="bold lightgreen">$vars{"output_web_answer_$r"}</span>
<input type="hidden" name="output_web_answer_$r" value="$vars{"output_web_answer_$r"}">
~;
}
my $sx = 1;
for (my $s = 2; $s < 10; $s++) {
my $alt;
if ($s > 2) {
$alt = 1;
}
for (my $s2 = $sx-$alt; $s2 < $sx+(length $num1); $s2++) {
$vars{"output_web_answer_${s2}_$s"} = substr($vars{"output_web_answer_${s2}_$s"},0,1);
$GRID{"$s2,$s"} = qq~<div class="block32 trans50">
<input type="text" name="output_web_answer_${s2}_$s" value="$vars{"output_web_answer_${s2}_$s"}" class="w20px center" placeholder="?">
</div>
~;
}
if ($s%2 == 0 && $s < 9) {
$sx++;
$LINE[$s] = qq~<tr>~;
for (my $s2 = 0; $s2 < $sx-1; $s2++) {
$LINE[$s] .= qq~ <td class="bl br"></td>~;
}
for (my $s2 = 0; $s2 < (length $num1)+1; $s2++) {
$LINE[$s] .= qq~ <td style="background-color:#333333"></td>~;
}
for (my $s2 = 0; $s2 < 15 - (length $num1) - $sx; $s2++) {
$LINE[$s] .= qq~ <td class="bl br"></td>~;
}
$LINE[$s] .= qq~</tr>~;
}
}
}
# setting the commas in the top row
if ($num1 =~ /(\.|\,)/) {
my $x = (length $num1)-&tail("",$num1)-1;
$GRID{"$x,1"} .= &comma_web("",$1);
}
if ($num2 =~ /(\.|\,)/) {
my $x = (length "$num1b:$num2")-&tail("",$num2)-1;
$GRID{"$x,1"} .= &comma_web("",$1);
}
if ($res =~ /(\.|\,)/) {
my $x = (length "$num1b:$num2b=$res2")-&tail("",$res);
$GRID{"$x,1"} .= &comma_web("",$1);
}
}
my ($NUM3,$DEVRES);
if ($vars{"output_web_cache_num3_0"}) {
$NUM3 = qq~ $op $vars{"output_web_cache_num3_0"}~;
}
if (ONO::IO->devstation) {
$DEVRES = qq~ ($vars{"output_web_cache_res_0"})~;
}
$WEB .= qq~<div class="box_$boxcolor p0 inline auto">
<div class="fr w33 mt5 mr10">$PROGRESS_BAR</div>
<div class="large mt5 mb5 ml10">$vars{"output_web_cache_num1_0"} $op $vars{"output_web_cache_num2_0"}$NUM3 = ?$DEVRES</div>
<div class="box_paper p0 ml10 mr10">
<table class="default_table bo auto">
~;
for (my $y = 0; $y < $max_y; $y++) {
$WEB .= qq~ <tr class="bt bb">~;
for (my $x = 0; $x < $max_x; $x++) {
$WEB .= qq~ <td class="p0 bl br center">$GRID{"$x,$y"}</td>$COMMA[$x]~;
}
$WEB .= qq~ </tr>$LINE[$y]~;
}
my $BUTTON = qq~<input type="submit" name="do_correct" value="$BLK{'do_correct'}" class="button_green mt5 mb5">~;
if ($vars{'output_web_answer_status'} == 1) {
$BUTTON = qq~<input type="submit" name="continue" value="$BLK{'continue'}..." class="button_green mt5 mb5">
<input type="hidden" name="flush_all_answers" value="1">~;
}
$WEB .= qq~ </table>
</div>
<div class="inline auto">
$BUTTON
</div>
</div>
</form>
<script>
function little(max,id) {
var val = onojs_getvalue('little_'+id+'_id');val++;if (val > max) {val=0};onojs_setvalue('little_'+id+'_id',val);
onojs_hide('little_'+id+'_0');onojs_hide('little_'+id+'_1');onojs_hide('little_'+id+'_2');onojs_block('little_'+id+'_'+val);
}
</script>
~;
}
}
# the grids can only be drawn AFTER we know the questions
if ($vars{'output_paper'}) {
&grids("",$canvas,$vars{'app_input_op_div'},$vars{'output_worksheet_maker'},$vars{'app_input_result_hints'},@qtext);
if ($vars{'app_input_result_hints'}) {
if ($vars{'app_input_op_div'}) {
my @block = (
$res[0], $res[1],
$res[2], $res[3],
$res[4],
);
ONO::FW::Apps::Core::Graphics->pdf_draw_result_hints($canvas,100,127,56,61,1,5,\@block,"",$num_comma);
} else {
my @block = (
$res[0], $res[1], $res[2],
$res[3], $res[5],
$res[6], $res[8],
$res[9], $res[10],$res[11],
);
ONO::FW::Apps::Core::Graphics->pdf_draw_result_hints($canvas,60,50,55,88,1,10,\@block,"",$num_comma);
}
}
}
# corrections
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);
if ($questions_per_page == 6) {
ONO::FW::Apps::Core::Graphics->pdf_draw_item_numbers($canvas,-2,0,1,3,"CV",$vars_ref);
} else {
ONO::FW::Apps::Core::Graphics->pdf_draw_item_numbers($canvas,-2,0,1,4,"CV",$vars_ref);
}
# ONO::Lib::PDF::ToolBox->canvas_test($canvas);
for (my $c = 0; $c < $questions_per_page; $c++) {
my ($op,$op_symbol,$num1,$num2,$num3,$res,$pdf_x,$pdf_y,@pos) = split(/\^/,$corr_cache[$c]);
if ($c == 0) {
ONO::Lib::PDF::Draw->font('',$pos[4]);
}
# if ($vars{'app_input_extype_status'} eq "tri" && ($op eq "add" || $op eq "sub")) {
@qtext2[$c] = $res;
# } else {
#
# @qtext2[$c] = $res;
#
# }
my $init_x = $pdf_x+42.5;
my $init_y = $pdf_y+11;
my $exclude;
if ($vars{'app_input_result_hints'}) {
if ($c == 4 || $c == 7) {
$exclude++;
}
}
if (!$exclude) {
# add / sub
if ($op eq "add" || $op eq "sub") {
my $thick_y = 0;
# 2 or 3 operands
my @opts = ($num1,"$op_symbol$num2","",$res);
if ($num3 ne "") {
@opts = ($num1,"$op_symbol$num2","$op_symbol$num3","",$res);
$thick_y = 5;
}
# render
my ($max_length,$report_init,$report_ref) = &number_line("","pdf",$canvas,\@opts,$init_x,$init_y,\%vars);
# reports (-1-)
$WEB .= &reports("",$canvas,$op,$num3,$report_init,$report_ref);
# thick line
if ($max_length > 7) {
$max_length = 7;
}
ONO::Lib::PDF::Draw->line($canvas,$init_x+2.5-($max_length*5),$init_y+11+$thick_y,$init_x+2.5,$init_y+11+$thick_y,1);
}
# mul + div fix tailing zeroes
my ($num1,$num1b,$num2,$num2b) = &fix_tailing_zeroes("",$op,$num1,$num2);
# mul
if ($op eq "mul") {
my (@subs,$spos,$thick_y);
for (my $s = 0; $s < length $num2b; $s++) {
if (substr($num2b,$spos,1) ne "0") {
my $spacer;
for (my $sp; $sp < (length $num2b)-$spos-1; $sp++) {
$spacer .= " ";
}
@subs = (@subs,$num1b*substr($num2b,$spos,1).$spacer);
$thick_y = $thick_y + 5;
}
$spos++;
}
# fix result position
if ($res =~ /(\.|\,)/) {
my $whilecounter;
while (&tail("",$res) < (&tail("",$num1) + &tail("",$num2)) && $whilecounter < 256) {
$whilecounter++;
$res .= "0";
}
} else {
if (&tail("",$num1) || &tail("",$num2)) {
$res .= ",";
my $whilecounter;
while (&tail("",$res) < (&tail("",$num1) + &tail("",$num2)) && $whilecounter < 256) {
$whilecounter++;
$res .= "0";
}
}
}
my @opts = ("${num1}x${num2}",@subs,"",$res);
# render
my ($max_length,$report_init,$report_ref) = &number_line("","pdf",$canvas,\@opts,$init_x,$init_y,\%vars);
# reports (-1-), only if subs > 1, else buggy
my $num = @subs;
if ($num > 1) {
$WEB .= &reports("",$canvas,$op,$thick_y,$report_init,$report_ref,$num);
}
# thick line
if ($max_length > 7) {
$max_length = 7;
}
ONO::Lib::PDF::Draw->line($canvas,$init_x+2.5-($max_length*5),$init_y+1,$init_x+2.5,$init_y+1,1);
ONO::Lib::PDF::Draw->line($canvas,$init_x+2.5-($max_length*5),$init_y+6+$thick_y,$init_x+2.5,$init_y+6+$thick_y,1);
}
# div
if ($op eq "div") {
my $main = "${num1b}:${num2b}=$res";
for (my $m = 0; $m < length $main; $m++) {
ONO::Lib::PDF::Draw->text($canvas,$pdf_x+12.5+($m*5),$init_y,substr($main,$m,1),"center");
}
my $div_y = -5;
my $cache = $num1b;
my ($spos);
my $shift = ((length ($num2b*substr($res,0,1)))-1)*5;
if (substr($num1b,0,1) < substr(($num2b*(substr($res,0,1))),0,1)) {
$shift = $shift + 5;
}
for (my $s = 0; $s < length $res; $s++) {
if ($s < 5) {
$div_y = $div_y + 10;
my $sub = $num2b*substr($res,$spos,1);
my $inter = (substr($cache,0,length $sub) - $sub).substr($num1b,$s+2,1);
for (my $d = 0; $d < length $inter; $d++) {
# ONO::Lib::PDF::Draw->text($canvas,$pdf_x+12.5+($s*5)+($d*5)+$shift-(((length $inter)-1)*5),$init_y+$div_y+5,substr($inter,$d,1),"center");
}
$cache = $sub;
for (my $d = 0; $d < length $sub; $d++) {
ONO::Lib::PDF::Draw->text($canvas,$pdf_x+12.5+($s*5)+($d*5)+$shift-(((length $sub)-1)*5),$init_y+$div_y,substr($sub,$d,1),"center");
}
ONO::Lib::PDF::Draw->line($canvas,$pdf_x+10+($s*5),$init_y+$div_y+1,$pdf_x+10+($s*5)+5+((length $num2)*5),$init_y+$div_y+1,1);
$spos++;
}
}
}
}
}
&grids("",$canvas,$vars{'app_input_op_div'},$vars{'output_worksheet_maker'},$vars{'app_input_result_hints'},@qtext2);
}
}
if ($vars{'output_web'}) {
($stat_correct,$stat_todo_total) = ONO::FW::Apps::Core->stats_multi_pages($vars{'app_input_number_of_questions'},$stat_correct,$stat_wrong,$page,$pages);
$WEB = ONO::FW::Apps::Core->stats_replace($WEB,$stat_correct,$stat_wrong,$stat_todo_total,$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;
}
$WEB .= ONO::FW::Apps::Core->infopics(
"screen:320:50:50::arithmetic_screenshot_1.jpg",
"sheet:168:180:110:15:arithmetic_sheet_2.jpg",
"sheet:168:40:140:-10:arithmetic_sheet_2.jpg",
);
my @tabs = ("std:green:a + b = ?","tri:green:a + b + c = ?");
my $CUSTOM = qq~<div class="inline">~;
$CUSTOM .= ONO::Lib::UI::Select->buttons(
"app_input_extype",
$vars{'app_input_extype_status'},
\@tabs,
"",
"f",
$BLK_ref,
);
$vars{'app_input_range_defaults'} = "1:20;1:100;100:1000;1000:10000;5000:50000";
my $CONF .= ONO::FW::Apps::ToolBox->conf_input("range", $BLK_ref,\%vars,"",1,100,999999);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("ops", $BLK_ref,\%vars,"","asmd-AS-tT");
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("moreopts", $BLK_ref,\%vars,"","bm");
$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"h","",$CUSTOM);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("digits", $BLK_ref,\%vars,"h",3);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("comma", $BLK_ref,\%vars,"h",3);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("roundup", $BLK_ref,\%vars,"h");
$CONF .= ONO::FW::Apps::ToolBox->conf_input("tensbarrier", $BLK_ref,\%vars,"h","S");
$CONF .= ONO::FW::Apps::ToolBox->conf_input("resulthints", $BLK_ref,\%vars,"","S");
# $CONF .= ONO::FW::Apps::ToolBox->conf_input("negative", $BLK_ref,\%vars,"h");
$WEB .= ONO::FW::Apps::Core->conf_box(
$db,
$community,
$app,
$form,
"",
$action_url,
$CONF,
$lang,
$BLK_ref,
\%vars,
"op-ncdi-CDI-lsu-N",
);
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'}),
);
}
}
$WEB .= ONO::FW::Apps::Core->vardump($vars_ref);
my ($status,$WEB) = ONO::Lib::Parser->parse($WEB,$vars_ref);
$WEB = ONO::FW::Edu::Apps::ToolBox->apps_gate($WEB,$vars_ref);
return $WEB;
}
###################################################################
# SUBS
###################################################################
sub grids {
my (
$self,
$canvas,
$div,
$maker,
$hints,
@qtext,
) = @_;
my ($maker_y,$counter);
ONO::Lib::PDF::Draw->font('',10);
if ($div) {
# div
my $max_h = 12;
if ($maker) {
$max_h = 8;
$maker_y = 2;
}
for (my $y = 0; $y < 3; $y++) {
for (my $x = 0; $x < 2; $x++) {
if (!$hints || $x == 0 || $y == 0 || $y == 1) {
my $spacer_x = 5 + $x * 50;
my $spacer_y = 5 + $y * 28.5 + $maker_y;
for (my $h = 0; $h < $max_h; $h++) {
ONO::Lib::PDF::Draw->line($canvas,$x*40+$spacer_x,$y*35+$spacer_y+$h*5,$x*40+75+$spacer_x,$y*35+$spacer_y+$h*5,0.1);
}
for (my $v = 0; $v < 16; $v++) {
ONO::Lib::PDF::Draw->line($canvas,$x*40+$spacer_x+$v*5,$y*35+$spacer_y,$x*40+$spacer_x+$v*5,$y*35+(($max_h-1)*5)+$spacer_y,0.1);
}
ONO::Lib::PDF::Draw->rect($canvas,$x*40+$spacer_x,$y*35+$spacer_y-4,$x*40+75+$spacer_x,$y*35+$spacer_y+2,1,"0:25:25:25","0:240:240:240",1);
ONO::Lib::PDF::Draw->text($canvas,$x*40+$spacer_x+2,$y*35+$spacer_y,$qtext[$counter]);
}
$counter++;
}
}
} else {
# add sub mul
my $max_h = 9;
if ($maker) {
$max_h = 8;
$maker_y = 2;
}
for (my $y = 0; $y < 4; $y++) {
for (my $x = 0; $x < 3; $x++) {
if (!$hints || $x == 0 || $x == 2 || $y == 0 || $y == 3) {
my $spacer_x = 5 + $x * 20;
my $spacer_y = 5 + $y * 12.5 + $maker_y;
for (my $h = 0; $h < $max_h; $h++) {
ONO::Lib::PDF::Draw->line($canvas,$x*40+$spacer_x,$y*35+$spacer_y+$h*5,$x*40+45+$spacer_x,$y*35+$spacer_y+$h*5,0.1);
}
for (my $v = 0; $v < 10; $v++) {
ONO::Lib::PDF::Draw->line($canvas,$x*40+$spacer_x+$v*5,$y*35+$spacer_y,$x*40+$spacer_x+$v*5,$y*35+(($max_h-1)*5)+$spacer_y,0.1);
}
ONO::Lib::PDF::Draw->rect($canvas,$x*40+$spacer_x,$y*35+$spacer_y-4,$x*40+45+$spacer_x,$y*35+$spacer_y+2,1,"0:25:25:25","0:240:240:240",1);
ONO::Lib::PDF::Draw->text($canvas,$x*40+$spacer_x+2,$y*35+$spacer_y,$qtext[$counter]);
}
$counter++;
}
}
}
ONO::Lib::PDF::Draw->font('',12);
}
sub tail {
$_[1] =~ /^(.*?)(\.|\,)(.*?)$/;
return length $3;
}
sub maxtail {
my $tail;
for (my $i = 1; $i < 4; $i++) {
my $test = &tail("",$_[$i]);
if ($test > $tail) {
$tail = $test;
}
}
return $tail;
}
sub number_line {
my (
$self,
$mode,
$canvas,
$opts_ref,
$init_x,
$init_y,
$vars_ref,
) = @_;
my @opts = @$opts_ref;
my ($report_init,%report,%GRID,%COMMA,%vars);
if ($mode eq "web") {
%vars = %$vars_ref;
$vars{'output_web_cache_res_0'} =~ s~[^0-9]~~g;
for (my $y = 0; $y < 8; $y++) {
for (my $x = 0; $x < 9; $x++) {
$GRID{"$x,$y"} = qq~<div class="block32"></div>~;
}
}
}
my $max_length = 0;
my $off_y = 0;
my $tail = 0;
foreach my $opt (@opts) {
$opt =~ /^(.*?)(\.|\,)(.*?)$/;
if (length $3 > $tail) {
$tail = length $3;
}
}
foreach my $opt (@opts) {
my $off_x = 0;
if (length $opt > $max_length) {
$max_length = length $opt;
}
for (my $l = 0; $l <= length $opt; $l++) {
my $comma_offset = 0;
if ($tail && $opts[0] !~ /x/) {
if ($opt =~ /^(.*?)(\.|\,)(.*?)$/) {
$comma_offset = -($tail - length $3);
} else {
$comma_offset = -$tail;
}
}
if ($mode eq "pdf") {
$comma_offset = $comma_offset * 5;
}
my $char = substr($opt,(length $opt)-$l,1);
if ($char =~ /[0-9]/ || $char =~ /( |\+|\-|x|\:|\=|\?|\!)/) {
my $char_x = $init_x-$off_x+$comma_offset;
my $char_y = $init_y+$off_y;
if ($vars{'output_worksheet_maker'}) {
$char_y = $char_y + 2;
}
if ($report_init < 1) {
$report_init = $char_y;
}
if ($mode eq "web") {
if ($char =~ /\?/) {
$char_x = $init_x-$off_x;
}
$char =~ s~x~•~g;
$GRID{"$char_x,$char_y"} = $char;
my $xy = "${char_x}_${char_y}";
$vars{"output_web_answer_$xy"} =~ s~[^0-9]~~g;
if ($vars{"output_web_answer_$xy"} < 0 || $vars{"output_web_answer_$xy"} > 9) {
$vars{"output_web_answer_$xy"} = "";
}
if ($char eq "?") {
my $color;
if ($vars{"output_web_answer_$xy"} ne "") {
$color = " bg_red";
}
my $correct_answer = substr($vars{'output_web_cache_res_0'},(length $opt)-$l,1);
my $PLA = "?";
if (ONO::IO->devstation) {
$PLA = $correct_answer;
}
$GRID{"$char_x,$char_y"} = qq~<div class="block32$color">
<input type="text" name="output_web_answer_$xy" value="$vars{"output_web_answer_$xy"}" class="w20px center" style="padding:4px" placeholder="$PLA" maxlength="1">
</div>
~;
if ($vars{"output_web_answer_$xy"} ne "" && $vars{"output_web_answer_$xy"} eq $correct_answer) {
$GRID{"$char_x,$char_y"} = qq~<span class="bold lightgreen">$vars{"output_web_answer_$xy"}</span>
<input type="hidden" name="output_web_answer_$xy" value="$vars{"output_web_answer_$xy"}">
~;
}
}
if ($char eq "!") {
$GRID{"$char_x,$char_y"} = qq~<div class="block32 trans50">
<input type="text" name="output_web_answer_inter_$xy" value="$vars{"output_web_answer_inter_$xy"}" class="w20px center" style="padding:4px" placeholder="?" maxlength="1">
</div>
~;
}
$off_x++;
}
if ($mode eq "pdf") {
if ($char =~ s~x~ ~g) {
ONO::Lib::PDF::Draw->circle($canvas,$char_x,$char_y-1,0.5,1,1);
}
ONO::Lib::PDF::Draw->text($canvas,$char_x,$char_y,$char,"center");
$off_x = $off_x + 5;
}
my $char_x_aligned = ONO::Lib::Basic->add_leading_zeroes($char_x,5);
$report{"$char_x_aligned,$char_y"} = $char;
}
if ($mode eq "web" && $char =~ /(\.|\,)/) {
my $char_x = $init_x-$off_x;
my $char_y = $init_y+$off_y;
$COMMA{"$char_x,$char_y"} = $char;
}
if ($mode eq "pdf" && $char =~ /(\.|\,)/) {
ONO::Lib::PDF::Draw->text($canvas,$init_x-$off_x+($comma_offset*5)+2,$init_y+$off_y,$char,"center");
}
}
if ($mode eq "web") {
$off_y++;
}
if ($mode eq "pdf") {
$off_y = $off_y + 5;
}
}
if ($mode eq "web") {
foreach my $key (keys %COMMA) {
# $GRID{$key} .= &comma_web("",$COMMA{$key});
}
return (\%GRID);
}
if ($mode eq "pdf") {
return ($max_length,$report_init,\%report);
}
}
sub comma_web {
return qq~<div class="rel"><div class="abs large bold lightred" style="top:-20px;left:24px">$_[1]</div></div>~;
}
sub reports {
my (
$self,
$canvas,
$op,
$num3,
$report_init,
$report_ref,
$max,
) = @_;
# in case of MUL, num3 is thick_y!
my %report = %$report_ref;
if ($max < 1) {
$max = 3;
}
$max++;
my $report_found;
my $DEBUG;
ONO::Lib::PDF::Draw->font('',9);
foreach my $key (reverse sort keys %report) {
if ($key =~ /^(.*?)\,$report_init$/) {
# $DEBUG.="--$key--";
my $report_x = $1;
my @report_y;
for (my $i = 5; $i < $max*5; $i = $i + 5) {
$report_y[$i] = $report_init + $i;
}
# res line for add and sub:
my $report_res = $report_init + 10;
if ($num3 ne "") {
$report_res = $report_init + 15;
}
if ($op eq "add") {
my $total = $report{"$report_x,$report_init"} + $report{"$report_x,$report_y[5]"} + $report{"$report_x,$report_y[10]"} + $report_found;
$report_found = 0;
if ($total > 9) {
ONO::Lib::PDF::Draw->text($canvas,$report_x-5,$report_res,1,"center");
$report_found++;
}
}
if ($op eq "sub") {
my $total = $report{"$report_x,$report_init"} - $report{"$report_x,$report_y[5]"} - $report{"$report_x,$report_y[10]"} - $report_found;
$report_found = 0;
if ($total < 0) {
ONO::Lib::PDF::Draw->text($canvas,$report_x-5,$report_res,1,"center");
$report_found++;
}
# $DEBUG.= qq~$report{"$report_x,$report_init"} - $report{"$report_x,$report_y[5]"} - $report{"$report_x,$report_y[10]"} // ~;
}
if ($op eq "mul") {
my $total = 0;
for (my $i = 5; $i < $max*5; $i = $i + 5) {
$total = $total + $report{"$report_x,$report_y[$i]"};
}
$report_res = $report_init + $num3 + 5;
if ($total > 9) {
ONO::Lib::PDF::Draw->text($canvas,$report_x-5,$report_res,1,"center");
}
}
}
}
ONO::Lib::PDF::Draw->font('',12);
if (ONO::IO->devstation) {
# return "$DEBUG<br>";
return "";
} else {
return "";
}
}
sub fix_tailing_zeroes {
my (
$self,
$op,
$num1,
$num2,
) = @_;
if ($op eq "mul" || $op eq "div") {
my $whilecounter;
while ($num1 =~ /\./ && $num1 =~ s~0$~~ && $whilecounter < 256) {
$whilecounter++;
$num1 =~ s~0$~~;
}
while ($num2 =~ /\./ && $num2 =~ s~0$~~ && $whilecounter < 512) {
$whilecounter++;
$num2 =~ s~0$~~;
}
}
my $num1b = $num1;
$num1b =~ s~[^0-9]~~g;
my $num2b = $num2;
$num2b =~ s~[^0-9]~~g;
return ($num1,$num1b,$num2,$num2b);
}
sub little {
my @hide = ('',' hide',' hide');
if ($_[3] == 1) {
@hide = (' hide','',' hide');
}
if ($_[3] == 2) {
@hide = (' hide',' hide','');
}
return qq~<a href="javascript:void(0);" onclick="little('$_[1]','$_[2]');" style="text-decoration:none">
<div class="rel" style="top:6px">
<div id="little_$_[2]_0" class="small bold cold$hide[0]">1</div>
<div id="little_$_[2]_1" class="small bold lightgreen$hide[1]">1</div>
<div id="little_$_[2]_2" class="small bold lightgreen$hide[2]">2</div>
</div>
</a>
<input type="hidden" id="little_$_[2]_id" name="little_$_[2]_value" value="$_[3]">
~;
}
sub maxlength {
my $max;
for (my $i = 1; $i < 4; $i++) {
if (length $_[$i] > $max) {
$max = length $_[$i];
}
}
return $max;
}
sub inter {
my $INTER;
for (my $j = 0; $j < $_[1]; $j++) {
if ($j > $_[1]-$_[2]-3 && $j < $_[1]-1) {
$INTER .= qq~<td style="background-color:#333333"></td>~;
} else {
$INTER .= qq~<td class="bl br"></td>~;
}
}
return qq~<tr>$INTER</tr>~;
}
sub res2qmark {
my $res = $_[1];
$res =~ s~[^0-9]~~g;
my $qmark;
for (my $q = 0; $q < length $res; $q++) {
$qmark .= "?";
}
return $qmark;
}
sub res2qsub {
my $qmark;
for (my $q = 0; $q < length $_[1]; $q++) {
$qmark .= "!";
}
return $qmark;
}
###################################################################
#### THAT'S IT :-D
###################################################################
1;
__END__