357 lines
16 KiB
PHP
357 lines
16 KiB
PHP
<?php
|
|
/** \file scripts\page\report_evaluation.php
|
|
* \brief DI webinterface evaluation report script.
|
|
* \author Rob Schalken, Core|Vision
|
|
* \version $Revision: 1.10 $
|
|
* \date $Date: 2013/10/31 15:49:59 $
|
|
*
|
|
* 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", $userId = NULL, $userTable = null)
|
|
{
|
|
global $_PAGE_INFO;
|
|
|
|
// Retrieve info
|
|
$date = date('Y-m-d');
|
|
$datetime = date('Y-m-d / H:i:s');
|
|
if (is_null($userId)) {
|
|
$userId = $_PAGE_INFO['login']['user']['id'];
|
|
$userTable = 'gebruiker';
|
|
}
|
|
|
|
$customer = db_fetch_customer($_PAGE_INFO['login']['customer']['id'], 1);
|
|
|
|
// Set file info
|
|
$_PAGE_INFO['report_type'] = "pdf";
|
|
$_PAGE_INFO['dest'] = $destination;
|
|
$_PAGE_INFO['orientation'] = "portrait";
|
|
$_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("Timezone", ucfirst($customer['tz'])),
|
|
array("MTinfo", VERSION . (is_ReleaseCandidate() ? " - " . $_SESSION[$_PAGE_INFO['id']]['release_dir'] : "")),
|
|
array("User", getUserOrProfileName($userId, $userTable)))));
|
|
// 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;
|
|
|
|
// Determine i18n
|
|
if ($answers[0]['gebruiker_tabel'] === 'gebruiker_profiel') {
|
|
$i18n = 'nl';
|
|
} else {
|
|
// Get user i18n
|
|
$user_info = db_fetch_user($answers[0]['gebruiker'], "", 1);
|
|
$i18n = $user_info['i18n'];
|
|
}
|
|
|
|
$userProfileName = getUserOrProfileName($answers[0]['gebruiker'], $answers[0]['gebruiker_tabel']);
|
|
|
|
// Override filename
|
|
$_PAGE_INFO['file'] = _("MTinfo") . " " . strtolower(_("Project")) . " " . strtolower(_("evaluation")) . " - " . $userProfileName . " - " . str_replace("-", "", $date) . ".pdf";
|
|
|
|
// Get the questions
|
|
$questions = db_fetch_questionaires($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;
|
|
}
|
|
}
|
|
}
|
|
|
|
// General information
|
|
report_data(array_merge($double_report_data, array(value => array("General info"), cell_width => array(180, 0), styling_options => array(array('cell' => "fillcolor={rgb 0.78 0.80 0.78}")))));
|
|
|
|
// User
|
|
report_data(array_merge($double_report_data, array(value => array("User", $userProfileName))));
|
|
|
|
// 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
|
|
$max_chars = 100;
|
|
|
|
// Empty line
|
|
empty_line();
|
|
|
|
if (is_array($answers[0]['antwoorden']) & !empty($answers[0]['antwoorden'])) {
|
|
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))) {
|
|
// No sub item?
|
|
$sub_item = FALSE;
|
|
} else {
|
|
// Default level
|
|
$sub_item = 1;
|
|
$valid = FALSE;
|
|
|
|
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);
|
|
|
|
// Check if question which I depend on is available and not empty
|
|
for ($i = 0; (($i < sizeof($answers[0]['antwoorden'])) && ($valid !== TRUE)); $i++) {
|
|
if ($answers[0]['antwoorden'][$i]['vraag'] == $dependency[0]['dependency']) {
|
|
if (strlen($answers[0]['antwoorden'][$i]['antwoord']) > 0) {
|
|
// Dependency is available and not empty
|
|
$valid = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Skip empty answers
|
|
if (strlen($answer['antwoord']) == 0) {
|
|
$valid = FALSE;
|
|
}
|
|
|
|
if ((!$sub_item) && ($valid)) {
|
|
// Empty line
|
|
empty_line();
|
|
}
|
|
|
|
// Valid?
|
|
if (($valid) && ($questions[$enquete_id]['vragen'][$answer['vraag']]['type'])) {
|
|
// Add question
|
|
multiple_lines($questions[$enquete_id]['vragen'][$answer['vraag']]['vraag'], $max_chars, 1, $single_report_data, NULL, $sub_item, array('cell' => "fillcolor={rgb 0.78 0.80 0.78}"));
|
|
|
|
// Get type of question
|
|
switch ($questions[$enquete_id]['vragen'][$answer['vraag']]['type']) {
|
|
// Type=input
|
|
case "text":
|
|
// Type=datetime
|
|
case "datetime":
|
|
// 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 (strtolower($answer_item) == strtolower($item['key'])) {
|
|
$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'], "rgb 0.78 0.80 0.78") !== 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)));
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|