echo '<td class="numeric">' . F_formatFloat($columns['wrong']);
            if (in_array($row, $calcpercent)) {
                echo ' ' . F_formatPercentage($columns['wrong'] / $usrtestdata['all']);
            }
            echo '</td>' . K_NEWLINE;
            echo '<td class="numeric">' . F_formatFloat($columns['unanswered']);
            if (in_array($row, $calcpercent)) {
                echo ' ' . F_formatPercentage($columns['unanswered'] / $usrtestdata['all']);
            }
            echo '</td>' . K_NEWLINE;
            echo '<td class="numeric">' . F_formatFloat($columns['undisplayed']);
            if (in_array($row, $calcpercent)) {
                echo ' ' . F_formatPercentage($columns['undisplayed'] / $usrtestdata['all']);
            }
            echo '</td>' . K_NEWLINE;
            echo '<td class="numeric">' . F_formatFloat($columns['unrated']);
            if (in_array($row, $calcpercent)) {
                echo ' ' . F_formatPercentage($columns['unrated'] / $usrtestdata['all']);
            }
            echo '</td>' . K_NEWLINE;
            echo '</tr>';
        }
    }
    echo '</table>' . K_NEWLINE;
    echo '<br />' . K_NEWLINE;
}
echo '</div>' . K_NEWLINE;
echo '<div class="row">' . K_NEWLINE;
// show buttons by case
if (isset($test_id) and $test_id > 0) {
    echo '<a href="tce_csv_result_allusers.php?testid=' . $test_id . '&amp;groupid=' . $group_id . '&amp;order_field=' . urlencode($order_field) . '&amp;orderdir=' . $orderdir . '" class="xmlbutton" title="' . $l['h_csv_export'] . '">CSV</a> ';
             $cstr = F_formatFloat($columns['right']);
             if (in_array($row, $calcpercent)) {
                 $cstr .= ' ' . F_formatPdfPercentage($columns['right'] / $usrtestdata['all']);
             }
             $pdf->Cell($data_cell_width * 7 / 5, $data_cell_height, $cstr, 1, 0, 'R', 0);
             $cstr = F_formatFloat($columns['wrong']);
             if (in_array($row, $calcpercent)) {
                 $cstr .= ' ' . F_formatPdfPercentage($columns['wrong'] / $usrtestdata['all']);
             }
             $pdf->Cell($data_cell_width * 7 / 5, $data_cell_height, $cstr, 1, 0, 'R', 0);
             $cstr = F_formatFloat($columns['unanswered']);
             if (in_array($row, $calcpercent)) {
                 $cstr .= ' ' . F_formatPdfPercentage($columns['unanswered'] / $usrtestdata['all']);
             }
             $pdf->Cell($data_cell_width * 7 / 5, $data_cell_height, $cstr, 1, 0, 'R', 0);
             $cstr = F_formatFloat($columns['undisplayed']);
             if (in_array($row, $calcpercent)) {
                 $cstr .= ' ' . F_formatPdfPercentage($columns['undisplayed'] / $usrtestdata['all']);
             }
             $pdf->Cell($data_cell_width * 7 / 5, $data_cell_height, $cstr, 1, 1, 'R', 0);
         }
     }
     break;
 case 2:
     // questions stats
     // get test data
     $testdata = F_getTestData($test_id);
     // get total number of questions for the selected test
     $num_questions = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER, 'WHERE testlog_testuser_id=testuser_id AND testuser_test_id=' . $test_id . '');
     // print table headings
     $pdf->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
Example #3
0
 /**
  * Print test stats table
  * @param $data (array) Array containing test statistics.
  * @param $pubmode (boolean) If true filter the results for the public interface.
  * @param $stats (int) 2 = full stats; 1 = user stats; 0 = disabled stats;
  */
 public function printTestResultStat($data, $pubmode = false, $stats = 2)
 {
     require_once '../config/tce_config.php';
     global $l;
     // add a bookmark
     $this->Bookmark($l['w_results']);
     if ($l['a_meta_dir'] == 'rtl') {
         $tdalignr = 'L';
         $tdalign = 'R';
     } else {
         $tdalignr = 'R';
         $tdalign = 'L';
     }
     if ($pubmode) {
         $num_column = 11;
     } else {
         $num_column = 14;
     }
     if ($stats < 1) {
         $num_column -= 5;
     }
     $tce_data_cell_width = round($this->tce_page_width / $num_column, 2);
     $tce_data_cell_width_third = round($tce_data_cell_width / 3, 2);
     $tce_data_cell_width_half = round($tce_data_cell_width / 2, 2);
     $numberfont = 'courier';
     $fontdatasize = PDF_FONT_SIZE_DATA - 1;
     $this->SetFillColor(204, 204, 204);
     $this->SetLineWidth(0.1);
     $this->SetDrawColor(0, 0, 0);
     $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
     // print table headings
     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '#', 1, 0, 'C', 1);
     $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_time_begin'], 1, 0, 'C', true, '', 1);
     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_time'], 1, 0, 'C', true, '', 1);
     $this->Cell(4 * $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_test'], 1, 0, 'C', true, '', 1);
     if (!$pubmode) {
         $this->Cell(3 * $tce_data_cell_width, $this->tce_data_cell_height, $l['w_user'] . ' - ' . $l['w_lastname'] . ', ' . $l['w_firstname'], 1, 0, 'C', true, '', 1);
     }
     $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_score'], 1, 0, 'C', true, '', 1);
     if ($stats > 0) {
         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answers_right_th'], 1, 0, 'C', true, '', 1);
         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answers_wrong_th'], 1, 0, 'C', true, '', 1);
         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_unanswered_th'], 1, 0, 'C', true, '', 1);
         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_undisplayed_th'], 1, 0, 'C', true, '', 1);
         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_unrated_th'], 1, 0, 'C', true, '', 1);
     }
     $this->Ln();
     $this->Ln(2);
     $this->SetFont($numberfont, '', $fontdatasize);
     foreach ($data['testuser'] as $tu) {
         $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $tu['num'], 1, 0, 'R', 0);
         $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $tu['testuser_creation_time'], 1, 0, 'R', 0, '', 1);
         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['time_diff'], 1, 0, 'R', 0, '', 1);
         $this->SetFont(PDF_FONT_NAME_DATA, '', $fontdatasize);
         $this->Cell(4 * $tce_data_cell_width_third, $this->tce_data_cell_height, $tu['test']['test_name'], 1, 0, $tdalign, 0, '', 1);
         if (!$pubmode) {
             $this->Cell(3 * $tce_data_cell_width, $this->tce_data_cell_height, $tu['user_name'] . ' - ' . $tu['user_lastname'] . ', ' . $tu['user_firstname'], 1, 0, $tdalign, 0, '', 1);
         }
         $this->SetFont($numberfont, '', $fontdatasize);
         if ($tu['passmsg']) {
             $this->SetFillColor(221, 255, 221);
             $this->SetFont($numberfont, 'B', $fontdatasize);
         } else {
             $this->SetFillColor(255, 238, 238);
         }
         $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $tu['total_score'] . ' ' . F_formatPdfPercentage($tu['total_score_perc'], false), 1, 0, 'R', true, '', 1);
         if ($stats > 0) {
             $this->SetFont($numberfont, '', $fontdatasize);
             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['right'] . ' ' . F_formatPdfPercentage($tu['right_perc'], false), 1, 0, 'R', 0, '', 1);
             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['wrong'] . ' ' . F_formatPdfPercentage($tu['wrong_perc'], false), 1, 0, 'R', 0, '', 1);
             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['unanswered'] . ' ' . F_formatPdfPercentage($tu['unanswered_perc'], false), 1, 0, 'R', 0, '', 1);
             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['undisplayed'] . ' ' . F_formatPdfPercentage($tu['undisplayed_perc'], false), 1, 0, 'R', 0, '', 1);
             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['unrated'] . ' ' . F_formatPdfPercentage($tu['unrated_perc'], false), 1, 0, 'R', 0, '', 1);
         }
         $this->Ln();
     }
     $this->SetFont(PDF_FONT_NAME_DATA, 'B', $fontdatasize);
     if ($data['passed_perc'] > 50) {
         $this->SetFillColor(221, 255, 221);
     } else {
         $this->SetFillColor(255, 238, 238);
     }
     $this->Cell(0, $this->tce_data_cell_height, $l['w_passed'] . ': ' . $data['passed'] . ' ' . F_formatPdfPercentage($data['passed_perc'], false), 1, 1, 'L', true, '', 1);
     // print statistics
     $printstat = array('mean', 'median', 'mode', 'standard_deviation', 'skewness', 'kurtosi');
     $noperc = array('skewness', 'kurtosi');
     foreach ($data['statistics'] as $row => $col) {
         if (in_array($row, $printstat)) {
             $this->SetFont(PDF_FONT_NAME_DATA, 'B', $fontdatasize);
             if ($pubmode) {
                 $this->Cell(4 * $tce_data_cell_width + $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_' . $row], 1, 0, $tdalignr, 0, '', 1);
             } else {
                 $this->Cell(7 * $tce_data_cell_width + $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_' . $row], 1, 0, $tdalignr, 0, '', 1);
             }
             $this->SetFont($numberfont, '', $fontdatasize);
             if (in_array($row, $noperc)) {
                 $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, F_formatFloat($col['score_perc']), 1, 0, 'R', 0, '', 1);
                 if ($stats > 0) {
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['right_perc']), 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['wrong_perc']), 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['unanswered_perc']), 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['undisplayed_perc']), 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['unrated_perc']), 1, 0, 'R', 0, '', 1);
                 }
                 $this->Ln();
             } else {
                 $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, round($col['score_perc']) . '%', 1, 0, 'R', 0, '', 1);
                 if ($stats > 0) {
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['right_perc']) . '%', 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['wrong_perc']) . '%', 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['unanswered_perc']) . '%', 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['undisplayed_perc']) . '%', 1, 0, 'R', 0, '', 1);
                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['unrated_perc']) . '%', 1, 0, 'R', 0, '', 1);
                 }
                 $this->Ln();
             }
         }
     }
 }
/**
* Returns test stats as HTML table
* @param $data (array) Array containing test statistics.
* @param $nextorderdir (int) next order direction.
* @param $order_field (string) order fields.
* @param $filter (string) filter string for URLs.
* @param $pubmode (boolean) If true filter the results for the public interface.
* @param $stats (int) 2 = full stats; 1 = user stats; 0 = disabled stats;
* return HTML table string.
*/
function F_printTestResultStat($data, $nextorderdir, $order_field, $filter, $pubmode = false, $stats = 1)
{
    require_once '../config/tce_config.php';
    global $db, $l;
    if (empty($data['num_records'])) {
        return;
    }
    if ($l['a_meta_dir'] == 'rtl') {
        $tdalignr = 'left';
        $tdalign = 'right';
    } else {
        $tdalignr = 'right';
        $tdalign = 'left';
    }
    $ret = '';
    $ret .= '<table class="userselect">' . K_NEWLINE;
    $ret .= '<tr>' . K_NEWLINE;
    $ret .= '<th>&nbsp;</th>' . K_NEWLINE;
    $ret .= '<th>#</th>' . K_NEWLINE;
    $ret .= F_select_table_header_element('testuser_creation_time', $nextorderdir, $l['h_time_begin'], $l['w_time_begin'], $order_field, $filter);
    //$ret .= F_select_table_header_element('testuser_end_time', $nextorderdir, $l['h_time_end'], $l['w_time_end'], $order_field, $filter);
    $ret .= '<th title="' . $l['h_test_time'] . '">' . $l['w_time'] . '</th>' . K_NEWLINE;
    $ret .= F_select_table_header_element('testuser_test_id', $nextorderdir, $l['h_test'], $l['w_test'], $order_field, $filter);
    if (!$pubmode) {
        $ret .= F_select_table_header_element('user_name', $nextorderdir, $l['h_login_name'], $l['w_user'], $order_field, $filter);
        $ret .= F_select_table_header_element('user_lastname', $nextorderdir, $l['h_lastname'], $l['w_lastname'], $order_field, $filter);
        $ret .= F_select_table_header_element('user_firstname', $nextorderdir, $l['h_firstname'], $l['w_firstname'], $order_field, $filter);
    }
    $ret .= F_select_table_header_element('total_score', $nextorderdir, $l['h_score_total'], $l['w_score'], $order_field, $filter);
    if ($stats > 0) {
        $ret .= '<th title="' . $l['h_answers_right'] . '">' . $l['w_answers_right'] . '</th>' . K_NEWLINE;
        $ret .= '<th title="' . $l['h_answers_wrong'] . '">' . $l['w_answers_wrong'] . '</th>' . K_NEWLINE;
        $ret .= '<th title="' . $l['h_questions_unanswered'] . '">' . $l['w_questions_unanswered'] . '</th>' . K_NEWLINE;
        $ret .= '<th title="' . $l['h_questions_undisplayed'] . '">' . $l['w_questions_undisplayed'] . '</th>' . K_NEWLINE;
        $ret .= '<th title="' . $l['h_questions_unrated'] . '">' . $l['w_questions_unrated'] . '</th>' . K_NEWLINE;
    }
    $ret .= '<th title="' . $l['w_status'] . ' (' . $l['w_time'] . ' [' . $l['w_minutes'] . '])">' . $l['w_status'] . ' (' . $l['w_time'] . ' [' . $l['w_minutes'] . '])</th>' . K_NEWLINE;
    $ret .= '<th title="' . $l['h_testcomment'] . '">' . $l['w_comment'] . '</th>' . K_NEWLINE;
    $ret .= '</tr>' . K_NEWLINE;
    foreach ($data['testuser'] as $tu) {
        $ret .= '<tr>';
        $ret .= '<td>';
        $ret .= '<input type="checkbox" name="testuserid' . $tu['num'] . '" id="testuserid' . $tu['num'] . '" value="' . $tu['id'] . '" title="' . $l['w_select'] . '"';
        if (isset($_REQUEST['checkall']) and $_REQUEST['checkall'] == 1) {
            $ret .= ' checked="checked"';
        }
        $ret .= ' />';
        $ret .= '</td>' . K_NEWLINE;
        if (!$pubmode or F_getBoolean($tu['test']['test_report_to_users'])) {
            $ret .= '<td><a href="tce_show_result_user.php?testuser_id=' . $tu['id'] . '&amp;test_id=' . $tu['test']['test_id'] . '&amp;user_id=' . $tu['user_id'] . '" title="' . $l['h_view_details'] . '">' . $tu['num'] . '</a></td>' . K_NEWLINE;
        } else {
            $ret .= '<td>' . $tu['num'] . '</td>' . K_NEWLINE;
        }
        $ret .= '<td style="text-align:center;">' . $tu['testuser_creation_time'] . '</td>' . K_NEWLINE;
        //$ret .= '<td style="text-align:center;">'.$tu['testuser_end_time'].'</td>'.K_NEWLINE;
        $ret .= '<td style="text-align:center;">' . $tu['time_diff'] . '</td>' . K_NEWLINE;
        $passmsg = '';
        if ($tu['passmsg'] === true) {
            $passmsg = ' title="' . $l['w_passed'] . '" style="background-color:#BBFFBB;"';
        } elseif ($tu['passmsg'] === false) {
            $passmsg = ' title="' . $l['w_not_passed'] . '" style="background-color:#FFBBBB;"';
        }
        if ($pubmode) {
            $ret .= '<td style="text-align:' . $tdalign . ';">' . $tu['test']['test_name'] . '</td>' . K_NEWLINE;
        } else {
            $ret .= '<td style="text-align:' . $tdalign . ';"><a href="tce_edit_test.php?test_id=' . $tu['test']['test_id'] . '">' . $tu['test']['test_name'] . '</a></td>' . K_NEWLINE;
            $ret .= '<td style="text-align:' . $tdalign . ';"><a href="tce_edit_user.php?user_id=' . $tu['user_id'] . '">' . $tu['user_name'] . '</a></td>' . K_NEWLINE;
            $ret .= '<td style="text-align:' . $tdalign . ';">&nbsp;' . $tu['user_lastname'] . '</td>' . K_NEWLINE;
            $ret .= '<td style="text-align:' . $tdalign . ';">&nbsp;' . $tu['user_firstname'] . '</td>' . K_NEWLINE;
        }
        $ret .= '<td' . $passmsg . ' class="numeric">' . F_formatFloat($tu['total_score']) . '&nbsp;' . F_formatPercentage($tu['total_score_perc'], false) . '</td>' . K_NEWLINE;
        if ($stats > 0) {
            $ret .= '<td class="numeric">' . $tu['right'] . '&nbsp;' . F_formatPercentage($tu['right_perc'], false) . '</td>' . K_NEWLINE;
            $ret .= '<td class="numeric">' . $tu['wrong'] . '&nbsp;' . F_formatPercentage($tu['wrong_perc'], false) . '</td>' . K_NEWLINE;
            $ret .= '<td class="numeric">' . $tu['unanswered'] . '&nbsp;' . F_formatPercentage($tu['unanswered_perc'], false) . '</td>' . K_NEWLINE;
            $ret .= '<td class="numeric">' . $tu['undisplayed'] . '&nbsp;' . F_formatPercentage($tu['undisplayed_perc'], false) . '</td>' . K_NEWLINE;
            $ret .= '<td class="numeric">' . $tu['unrated'] . '&nbsp;' . F_formatPercentage($tu['unrated_perc'], false) . '</td>' . K_NEWLINE;
        }
        if ($tu['locked']) {
            $ret .= '<td style="background-color:#FFBBBB;">' . $l['w_locked'];
        } else {
            $ret .= '<td style="background-color:#BBFFBB;">' . $l['w_unlocked'];
        }
        if ($tu['remaining_time'] < 0) {
            $ret .= ' (' . $tu['remaining_time'] . ')';
        }
        $ret .= '</td>' . K_NEWLINE;
        if (!empty($tu['user_comment'])) {
            $ret .= '<td title="' . substr(F_compact_string(htmlspecialchars($tu['user_comment'], ENT_NOQUOTES, $l['a_meta_charset'])), 0, 255) . '">' . $l['w_yes'] . '</td>' . K_NEWLINE;
        } else {
            $ret .= '<td>&nbsp;</td>' . K_NEWLINE;
        }
        $ret .= '</tr>' . K_NEWLINE;
    }
    $ret .= '<tr>';
    $colspan = 16;
    if ($pubmode) {
        $colspan -= 3;
    }
    if ($stats == 0) {
        $colspan -= 5;
    }
    $ret .= '<td colspan="' . $colspan . '" style="text-align:' . $tdalign . ';font-weight:bold;padding-right:10px;padding-left:10px;';
    if ($data['passed_perc'] > 50) {
        $ret .= ' background-color:#BBFFBB;"';
    } else {
        $ret .= ' background-color:#FFBBBB;"';
    }
    $ret .= '>' . $l['w_passed'] . ': ' . $data['passed'] . ' ' . F_formatPercentage($data['passed_perc'], false) . '</td>' . K_NEWLINE;
    $ret .= '</tr>';
    // print statistics
    $printstat = array('mean', 'median', 'mode', 'standard_deviation', 'skewness', 'kurtosi');
    $noperc = array('skewness', 'kurtosi');
    foreach ($data['statistics'] as $row => $col) {
        if (in_array($row, $printstat)) {
            $ret .= '<tr>';
            $scolspan = 8;
            if ($pubmode) {
                $scolspan -= 3;
            }
            $ret .= '<th colspan="' . $scolspan . '" style="text-align:' . $tdalignr . ';">' . $l['w_' . $row] . '</th>' . K_NEWLINE;
            if (in_array($row, $noperc)) {
                $ret .= '<td class="numeric">' . F_formatFloat($col['score_perc']) . '</td>' . K_NEWLINE;
                if ($stats > 0) {
                    $ret .= '<td class="numeric">' . F_formatFloat($col['right_perc']) . '</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . F_formatFloat($col['wrong_perc']) . '</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . F_formatFloat($col['unanswered_perc']) . '</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . F_formatFloat($col['undisplayed_perc']) . '</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . F_formatFloat($col['unrated_perc']) . '</td>' . K_NEWLINE;
                }
            } else {
                $ret .= '<td class="numeric">' . round($col['score_perc']) . '%</td>' . K_NEWLINE;
                if ($stats > 0) {
                    $ret .= '<td class="numeric">' . round($col['right_perc']) . '%</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . round($col['wrong_perc']) . '%</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . round($col['unanswered_perc']) . '%</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . round($col['undisplayed_perc']) . '%</td>' . K_NEWLINE;
                    $ret .= '<td class="numeric">' . round($col['unrated_perc']) . '%</td>' . K_NEWLINE;
                }
            }
            $ret .= '<td colspan="2">&nbsp;</td>' . K_NEWLINE;
            $ret .= '</tr>';
        }
    }
    $ret .= '</table>' . K_NEWLINE;
    return $ret;
}
/**
 * Sends email test reports to users.
 * @author Nicola Asuni
 * @since 2005-02-24
 * @param $test_id (int) TEST ID
 * @param $user_id (int) USER ID (0 means all users)
 * @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
 * @param $group_id (int) GROUP ID (0 means all groups)
 * @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
 * @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
 * @param $mode (int) type of report to send: 0=detailed report; 1=summary report (without questions)
 * @param $display_mode display (int) mode: 0 = disabled; 1 = minimum; 2 = module; 3 = subject; 4 = question; 5 = answer.
 * @param $show_graph (boolean) If true display the score graph.
 */
function F_send_report_emails($test_id, $user_id = 0, $testuser_id = 0, $group_id = 0, $startdate = 0, $enddate = 0, $mode = 0, $display_mode = 1, $show_graph = false)
{
    global $l, $db;
    require_once '../config/tce_config.php';
    require_once '../../shared/code/tce_functions_test.php';
    require_once '../../shared/code/tce_functions_test_stats.php';
    require_once '../../shared/code/tce_class_mailer.php';
    require_once 'tce_functions_user_select.php';
    $mode = intval($mode);
    if ($test_id > 0) {
        $test_id = intval($test_id);
        if (!F_isAuthorizedUser(K_TABLE_TESTS, 'test_id', $test_id, 'test_user_id')) {
            return;
        }
    } else {
        $test_id = 0;
    }
    if ($user_id > 0) {
        $user_id = intval($user_id);
    } else {
        $user_id = 0;
    }
    if ($testuser_id > 0) {
        $testuser_id = intval($testuser_id);
    } else {
        $testuser_id = 0;
    }
    if ($group_id > 0) {
        $group_id = intval($group_id);
    } else {
        $group_id = 0;
    }
    if (!empty($startdate)) {
        $startdate_time = strtotime($startdate);
        $startdate = date(K_TIMESTAMP_FORMAT, $startdate_time);
    } else {
        $startdate = '';
    }
    if (!empty($enddate)) {
        $enddate_time = strtotime($enddate);
        $enddate = date(K_TIMESTAMP_FORMAT, $enddate_time);
    } else {
        $enddate = '';
    }
    // Instantiate C_mailer class
    $mail = new C_mailer();
    //Load default values
    $mail->language = $l;
    $mail->Priority = $emailcfg['Priority'];
    $mail->ContentType = $emailcfg['ContentType'];
    $mail->Encoding = $emailcfg['Encoding'];
    $mail->WordWrap = $emailcfg['WordWrap'];
    $mail->Mailer = $emailcfg['Mailer'];
    $mail->Sendmail = $emailcfg['Sendmail'];
    $mail->UseMSMailHeaders = $emailcfg['UseMSMailHeaders'];
    $mail->Host = $emailcfg['Host'];
    $mail->Port = $emailcfg['Port'];
    $mail->Helo = $emailcfg['Helo'];
    $mail->SMTPAuth = $emailcfg['SMTPAuth'];
    $mail->SMTPSecure = $emailcfg['SMTPSecure'];
    $mail->Username = $emailcfg['Username'];
    $mail->Password = $emailcfg['Password'];
    $mail->Timeout = $emailcfg['Timeout'];
    $mail->SMTPDebug = $emailcfg['SMTPDebug'];
    $mail->PluginDir = $emailcfg['PluginDir'];
    $mail->Sender = $emailcfg['Sender'];
    $mail->From = $emailcfg['From'];
    $mail->FromName = $emailcfg['FromName'];
    if ($emailcfg['Reply']) {
        $mail->AddReplyTo($emailcfg['Reply'], $emailcfg['ReplyName']);
    }
    $mail->CharSet = $l['a_meta_charset'];
    if (!$mail->CharSet) {
        $mail->CharSet = $emailcfg['CharSet'];
    }
    $mail->Subject = $l['t_result_user'];
    $mail->IsHTML(TRUE);
    // Set message type to HTML.
    $email_num = 0;
    // count emails;
    // get all data
    $data = F_getAllUsersTestStat($test_id, $group_id, $user_id, $startdate, $enddate, 'total_score', false, $display_mode);
    foreach ($data['testuser'] as $tu) {
        if (strlen($tu['user_email']) > 3) {
            // set HTML header
            $mail->Body = $emailcfg['MsgHeader'];
            // compose alternate TEXT message
            $mail->AltBody = '' . $l['t_result_user'] . ' [' . $tu['testuser_creation_time'] . ']' . K_NEWLINE;
            $mail->AltBody .= $l['w_test'] . ': ' . $tu['test']['test_name'] . K_NEWLINE;
            $passmsg = '';
            if ($tu['test']['test_score_threshold'] > 0) {
                $mail->AltBody .= $l['w_test_score_threshold'] . ': ' . $tu['test']['test_score_threshold'];
                if ($tu['total_score'] >= $tu['test']['test_score_threshold']) {
                    $passmsg = ' - ' . $l['w_passed'];
                } else {
                    $passmsg = ' - ' . $l['w_not_passed'];
                }
                $mail->AltBody .= K_NEWLINE;
            }
            $mail->AltBody .= $l['w_score'] . ': ' . F_formatFloat($tu['total_score']) . ' ' . F_formatPercentage($tu['total_score_perc'], false) . $passmsg . K_NEWLINE;
            if ($display_mode > 0) {
                $mail->AltBody .= $l['w_answers_right'] . ': ' . $tu['right'] . '&nbsp;' . F_formatPercentage($tu['right_perc'], false) . K_NEWLINE;
                $mail->AltBody .= $l['w_answers_wrong'] . ': ' . $tu['wrong'] . '&nbsp;' . F_formatPercentage($tu['wrong_perc'], false) . K_NEWLINE;
                $mail->AltBody .= $l['w_questions_unanswered'] . ': ' . $tu['unanswered'] . '&nbsp;' . F_formatPercentage($tu['unanswered_perc'], false) . K_NEWLINE;
                $mail->AltBody .= $l['w_questions_undisplayed'] . ': ' . $tu['undisplayed'] . '&nbsp;' . F_formatPercentage($tu['undisplayed_perc'], false) . K_NEWLINE;
            }
            if ($mode == 0) {
                $pdfkey = getPasswordHash(date('Y') . $tu['id'] . K_RANDOM_SECURITY . $tu['test']['test_id'] . date('m') . $tu['user_id']);
                // create PDF doc
                $mode = 3;
                $pdf_content = file_get_contents(K_PATH_HOST . K_PATH_TCEXAM . 'admin/code/tce_pdf_results.php?mode=' . $mode . '&diplay_mode=' . $display_mode . '&show_graph=' . $show_graph . '&test_id=' . $tu['test']['test_id'] . '&user_id=' . $tu['user_id'] . '&testuser_id=' . $tu['id'] . '&email=' . $pdfkey);
                // set PDF document file name
                $doc_name = 'tcexam_report';
                $doc_name .= '_' . $mode;
                $doc_name .= '_0';
                $doc_name .= '_' . $tu['test']['test_id'];
                $doc_name .= '_0';
                $doc_name .= '_' . $tu['user_id'];
                $doc_name .= '_' . $tu['id'];
                $doc_name .= '.pdf';
                // attach document
                $mail->AddStringAttachment($pdf_content, $doc_name, $emailcfg['AttachmentsEncoding'], 'application/octet-stream');
                $mail->AltBody .= K_NEWLINE . $l['w_attachment'] . ': ' . $doc_name . K_NEWLINE;
            }
            // convert alternate text to HTML
            $mail->Body .= str_replace(K_NEWLINE, '<br />' . K_NEWLINE, $mail->AltBody);
            // add HTML footer
            $mail->Body .= $emailcfg['MsgFooter'];
            //--- Elaborate user Templates ---
            $mail->Body = str_replace('#CHARSET#', $l['a_meta_charset'], $mail->Body);
            $mail->Body = str_replace('#LANG#', $l['a_meta_language'], $mail->Body);
            $mail->Body = str_replace('#LANGDIR#', $l['a_meta_dir'], $mail->Body);
            $mail->Body = str_replace('#EMAIL#', $tu['user_email'], $mail->Body);
            $mail->Body = str_replace('#USERNAME#', htmlspecialchars($tu['user_name'], ENT_NOQUOTES, $l['a_meta_charset']), $mail->Body);
            $mail->Body = str_replace('#USERFIRSTNAME#', htmlspecialchars($tu['user_firstname'], ENT_NOQUOTES, $l['a_meta_charset']), $mail->Body);
            $mail->Body = str_replace('#USERLASTNAME#', htmlspecialchars($tu['user_lastname'], ENT_NOQUOTES, $l['a_meta_charset']), $mail->Body);
            // add a "To" address
            $mail->AddAddress($tu['user_email'], $tu['user_name']);
            $email_num++;
            $progresslog = '' . $email_num . '. ' . $tu['user_email'] . ' [' . $tu['user_name'] . ']';
            //output user data
            if (!$mail->Send()) {
                //send email to user
                $progresslog .= ' [' . $l['t_error'] . ']';
                //display error message
            }
            $mail->ClearAddresses();
            // Clear all addresses for next loop
            $mail->ClearAttachments();
            // Clears all previously set filesystem, string, and binary attachments
        } else {
            $progresslog = '[' . $l['t_error'] . '] ' . $tu['user_name'] . ': ' . $l['m_unknown_email'] . '';
            //output user data
        }
        echo $progresslog . '<br />' . K_NEWLINE;
        //output processed emails
        flush();
        // force browser output
    }
    $mail->ClearAddresses();
    // Clear all addresses for next loop
    $mail->ClearCustomHeaders();
    // Clears all custom headers
    $mail->ClearAllRecipients();
    // Clears all recipients assigned in the TO, CC and BCC
    $mail->ClearAttachments();
    // Clears all previously set filesystem, string, and binary attachments
    $mail->ClearReplyTos();
    // Clears all recipients assigned in the ReplyTo array
    return;
}