327 lines
12 KiB
PHP
327 lines
12 KiB
PHP
<?php
|
|
/** \file scripts\page\report_evaluation.php
|
|
* \brief DI webinterface evaluation report script.
|
|
* \author Rob Schalken, Core|Vision
|
|
* \version $Revision: 26247 $
|
|
* \date $Date: 2016-02-29 10:40:22 +0100 (Mon, 29 Feb 2016) $
|
|
*
|
|
* This file contains the evaluation report scripts.
|
|
*/
|
|
|
|
require_once("report.php");
|
|
|
|
/*
|
|
* Definition(s)
|
|
*/
|
|
define("SUB_STEP", 3);
|
|
|
|
|
|
/**
|
|
* Create the mtinfo evaluation report
|
|
*/
|
|
function report_evaluation($id, $destination = "D", $download_by = NULL) {
|
|
global $_PAGE_INFO;
|
|
|
|
// Retrieve info
|
|
$date = date('Y-m-d');
|
|
$datetime = date('Y-m-d / H:i:s');
|
|
$user = (is_null($download_by)) ? db_fetch_user($_PAGE_INFO['login']['user']['id'], "", 1) : $download_by;
|
|
$customer = db_fetch_customer($_PAGE_INFO['login']['customer']['id'], 1);
|
|
|
|
// Set file info
|
|
$_PAGE_INFO['report_type'] = "pdf";
|
|
$_PAGE_INFO['dest'] = $destination;
|
|
$_PAGE_INFO['file'] = _("MTinfo") . " " . strtolower(_("Project")) . " " . strtolower(_("evaluation")) . "_" . str_replace("-", "", $date) . ".pdf";
|
|
|
|
// Create header info
|
|
report_header(array(subject => _("MTinfo") . " " . strtolower(_("Project")) . " " . strtolower(_("evaluation")),
|
|
header => _("MTinfo") . " " . strtolower(_("Project")) . " " . strtolower(_("evaluation")),
|
|
data => array( array("Date", $datetime) ,
|
|
array("MTinfo", VERSION . (is_ReleaseCandidate() ? " - " . $_SESSION[$_PAGE_INFO['id']]['release_dir'] : "")),
|
|
array("User", getUser($user['id'])))));
|
|
// Default table layout
|
|
$single_report_data = array(border => array("LBT","RBT"),
|
|
bold => array(0,0),
|
|
align => array("L","L"),
|
|
font_size => array(8,8),
|
|
cell_width => array(1,179),
|
|
check_page_end => 1);
|
|
|
|
$double_report_data = array(border => array("LRBT","LRBT"),
|
|
bold => array(1,0),
|
|
align => array("L","L"),
|
|
font_size => array(8,8),
|
|
cell_width => array(70,110),
|
|
check_page_end => 1);
|
|
|
|
// Get the answers
|
|
$answers = db_fetch_questionaire_answers($id, QUESTIONAIRE_SINGLE);
|
|
|
|
if ((is_array($answers)) && (!empty($answers))) {
|
|
// Default value
|
|
$enquete_id = 0;
|
|
|
|
// Get user i18n
|
|
$user_info = db_fetch_user($answers[0]['gebruiker'], "", 1);
|
|
|
|
// Override filename
|
|
$_PAGE_INFO['file'] = _("MTinfo") . " " . strtolower(_("Project")) . " " . strtolower(_("evaluation")) . " - " . getUser($user_info['id']) . " - " .str_replace("-", "", $date) . ".pdf";
|
|
|
|
// Get the questions
|
|
$questions = db_fetch_questionaires($user_info['i18n'], $id);
|
|
|
|
// Determine set of questions used
|
|
if (is_array($questions)) {
|
|
for($i=0; $i<sizeof($questions); $i++) {
|
|
if ($questions[$i]['id'] == $answers[0]['enquete']) {
|
|
$enquete_id = $i;
|
|
}
|
|
}
|
|
}
|
|
|
|
// User
|
|
report_data(array_merge($double_report_data, array(value => array("User",getUser($answers[0]['gebruiker'])))));
|
|
|
|
// Project naam
|
|
$project_info = db_fetch_project($answers[0]['project'], "", 1);
|
|
|
|
if (is_array($project_info)) {
|
|
report_data(array_merge($double_report_data, array(value => array("Project", $project_info['naam']))));
|
|
}
|
|
|
|
// Date
|
|
report_data(array_merge($double_report_data, array(value => array("Date",str_replace(" ", " / ", $answers[0]['datum'])))));
|
|
|
|
// GPS
|
|
$gps = ((is_null($answers[0]['latitude'])) || (is_null($answers[0]['longitude']))) ? "-" : $answers[0]['latitude'] . ", " . $answers[0]['longitude'];
|
|
$gps_link = ((is_null($answers[0]['latitude'])) || (is_null($answers[0]['longitude']))) ? "" : GOOGLE_MAPS . "maps?q=" . $answers[0]['latitude'] . ", " . $answers[0]['longitude'];
|
|
report_data(array_merge($double_report_data, array(value => array("Coordinate", $gps), ishtml => array("", array(type => link, data => $gps_link)))));
|
|
|
|
// Enquete
|
|
if ((isset($questions[$enquete_id]['titel'])) && (strlen($questions[$enquete_id]['titel']))) {
|
|
report_data(array_merge($double_report_data, array(value => array(ucFirst(_("evaluation")), $questions[$enquete_id]['titel']))));
|
|
}
|
|
|
|
// Initial value
|
|
$count = 0;
|
|
$max_chars = 100;
|
|
|
|
// Empty line
|
|
empty_line();
|
|
|
|
foreach($answers[0]['antwoorden'] as $answer) {
|
|
// Initial values
|
|
$valid = TRUE;
|
|
|
|
// Get the dependency questions
|
|
$dependency = db_fetch_dependency_questionaire($answer['vraag'], 0);
|
|
|
|
if ((!is_array($dependency)) || (empty($dependency))) {
|
|
// Empty line
|
|
empty_line();
|
|
|
|
// Increment counter
|
|
$count++;
|
|
|
|
// Clear sub counter
|
|
$count_sub = 0;
|
|
|
|
// No sub item?
|
|
$sub_item = FALSE;
|
|
}
|
|
else {
|
|
// Increment sub counter
|
|
$count_sub++;
|
|
|
|
// Default level
|
|
$sub_item = 1;
|
|
|
|
do {
|
|
$found = FALSE;
|
|
for($i=0; (($i<sizeof($dependency)) && ($found!==TRUE)); $i++) {
|
|
// Get the dependency questions
|
|
$new_dependency = db_fetch_dependency_questionaire($dependency[$i]['dependency'], 0);
|
|
|
|
if ((is_array($new_dependency)) && (!empty($new_dependency))) {
|
|
$found = TRUE;
|
|
}
|
|
}
|
|
|
|
// New dependency?
|
|
if ($found) {
|
|
$dependency = $new_dependency;
|
|
$sub_item++;
|
|
}
|
|
} while($found);
|
|
}
|
|
|
|
if ($valid) {
|
|
// Add question
|
|
multiple_lines($questions[$enquete_id]['vragen'][$answer['vraag']]['vraag'], $max_chars, 1, $single_report_data, NULL, $sub_item, array('cell' => "fillcolor={gray .70}"));
|
|
|
|
// Get type of question
|
|
switch($questions[$enquete_id]['vragen'][$answer['vraag']]['type']) {
|
|
// Type=input
|
|
case "text":
|
|
// Type=textarea
|
|
case "simpletext":
|
|
// Add result
|
|
multiple_lines(html_entity_decode($answer['antwoord'], ENT_QUOTES), $max_chars, 0, $single_report_data, NULL, $sub_item);
|
|
break;
|
|
// Type=checkbox
|
|
case "set":
|
|
// Type=enum
|
|
case "enum":
|
|
if (is_array($questions[$enquete_id]['vragen'][$answer['vraag']]['antwoorden'])) {
|
|
$answer_array = explode(",", html_entity_decode($answer['antwoord'], ENT_QUOTES));
|
|
|
|
foreach ($questions[$enquete_id]['vragen'][$answer['vraag']]['antwoorden'] as $item) {
|
|
// Determine image
|
|
$image = ($questions[$enquete_id]['vragen'][$answer['vraag']]['type'] == "enum") ? "radiobutton" : "checkbox";
|
|
|
|
// Define image
|
|
$found = FALSE;
|
|
foreach($answer_array as $answer_item) {
|
|
if (!$found) {
|
|
if (strpos($answer_item, $item['key']) !== FALSE) {
|
|
$image .= "_checked";
|
|
|
|
// Set flag
|
|
$found = TRUE;
|
|
|
|
// Store answer
|
|
$answer_data = $answer_item;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add extension
|
|
$image .= ".png";
|
|
|
|
// Extra input textfield available?
|
|
$extra_input_data = "";
|
|
$extra_input = explode(':', $item['antwoord']);
|
|
|
|
if (is_array($extra_input)) {
|
|
$item['antwoord'] = $extra_input[0];
|
|
|
|
if ($found) {
|
|
// "Title" added to input textfield?
|
|
if (($item['key'] != "*") && (isset($extra_input[1]))) {
|
|
if (!empty($extra_input[1])) {
|
|
$extra_input_data = $extra_input[1] . ":";
|
|
}
|
|
|
|
// Get input textfield data
|
|
$data = explode(":\"",$answer_data);
|
|
if ((is_array($data)) && (isset($data[1]))) {
|
|
// Remove trailing quote/other
|
|
$pos = strrpos($data[1], '"');
|
|
|
|
if ($pos !== FALSE) {
|
|
$extra_input_data .= " " . substr($data[1], 0, $pos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Others filled in?
|
|
if ($item['key'] == "*") {
|
|
$other_answer = "";
|
|
|
|
$pos = array_search($item['key'], $answer_array);
|
|
|
|
if ($pos !== FALSE) {
|
|
if (isset($answer_array[$pos + 1])) {
|
|
// Find next result
|
|
$other_answer = $answer_array[$pos + 1];
|
|
}
|
|
}
|
|
|
|
$item['antwoord'] .= ": " . $other_answer;
|
|
}
|
|
|
|
// Add extra input textfield data
|
|
$item['antwoord'] .= "\r\n" . $extra_input_data;
|
|
|
|
// Add result
|
|
multiple_lines(" ". $item['antwoord'], $max_chars, 0, $single_report_data, array(array(type => "image", left => 2 + ($sub_item * SUB_STEP), width => 7, filename => $image)), $sub_item);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
// Do nothing
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Generate document
|
|
return report_generate();
|
|
}
|
|
|
|
|
|
/*
|
|
* Split up text
|
|
*/
|
|
function multiple_lines($value, $max_chars = 100, $bold = 1, $report_data, $ishtml = NULL, $sub = FALSE, $styling_options = array()) {
|
|
// Calculate number of lines needed for the question
|
|
$lines = nmr_lines($value, 100);
|
|
|
|
// Sub items?
|
|
$bold = array(0, $bold);
|
|
$text = array("", $value);
|
|
$cell = $report_data['cell_width'];
|
|
$border = $report_data['border'];
|
|
$styling_options = array($styling_options, $styling_options);
|
|
|
|
if ($sub !== FALSE) {
|
|
$cell = array(1 + ($sub * SUB_STEP), 180 - (1 + ($sub * SUB_STEP)));
|
|
if ((isset($styling_options[0]['cell'])) && (stristr($styling_options[0]['cell'], "gray") !== FALSE)) {
|
|
$styling_options = array("",array('cell' => "fillcolor={gray ." . (80+($sub * 5)) . "}"));
|
|
}
|
|
if (stristr($border[0], "L") !== FALSE) {
|
|
$border = array("", $border[1] . "L");
|
|
}
|
|
}
|
|
|
|
for ($j = 0; $j < sizeof($lines); $j++) {
|
|
// Get text
|
|
$text = $lines[$j];
|
|
|
|
// To array
|
|
$text = array("", $text);
|
|
|
|
if (sizeof($lines) > 1) {
|
|
if (!$j) {
|
|
if ($sub !== FALSE) {
|
|
$border = array("","LRT");
|
|
}
|
|
report_data(array_merge($report_data, array(value => $text, bold => $bold, border => $border, cell_width => $cell, nr_lines => sizeof($lines), ishtml => $ishtml, styling_options => $styling_options)));
|
|
}
|
|
else {
|
|
if (($j + 1) == sizeof($lines)) {
|
|
if ($sub !== FALSE) {
|
|
$border = array("","LRB");
|
|
}
|
|
report_data(array_merge($report_data, array(value => $text, bold => $bold, border => $border, cell_width => $cell, styling_options => $styling_options)));
|
|
}
|
|
else {
|
|
if ($sub !== FALSE) {
|
|
$border = array("","LR");
|
|
}
|
|
report_data(array_merge($report_data, array(value => $text, bold => $bold, border => $border, cell_width => $cell, styling_options => $styling_options)));
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
// To array
|
|
$text = array("", $value);
|
|
|
|
report_data(array_merge($report_data, array(bold => $bold, value => $text, border => $border, ishtml => $ishtml, cell_width => $cell, styling_options => $styling_options)));
|
|
}
|
|
}
|
|
}
|
|
?>
|