mirror of
https://github.com/fsr/eseeva
synced 2025-04-28 09:28:31 +02:00
first commit
This commit is contained in:
commit
ca0216c0c6
21 changed files with 7115 additions and 0 deletions
117
libs/chartLib.php
Normal file
117
libs/chartLib.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : chartLib.php
|
||||
// Author : Lucas Woltmann
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Description : Provides functions for creating beautiful and astonishing charts
|
||||
//============================================================================
|
||||
|
||||
function DrawCoords($image, $XLength, $YLength, $values)
|
||||
{
|
||||
$width = ImageSX($image);
|
||||
$height = ImageSY($image);
|
||||
|
||||
//scale offset for each axis, minimize Xoffset for small values of Xlength
|
||||
$Xoffset = 0.8*($width/$XLength);
|
||||
$Yoffset = 0.8*($height/$YLength);
|
||||
|
||||
if($Xoffset>150)
|
||||
{
|
||||
$Xoffset=$Xoffset/10;
|
||||
}
|
||||
|
||||
//lines out of image
|
||||
if($width < ($XLength * $Xoffset) || $height < ($YLength * $Yoffset))
|
||||
{
|
||||
echo "lines out of boundaries";
|
||||
}
|
||||
|
||||
$black = ImageColorAllocate($image, 0, 0, 0);
|
||||
|
||||
|
||||
$left = ($width - $XLength * $Xoffset)/2;
|
||||
$right = $width-$left;
|
||||
$upper = ($YLength * $Yoffset)+$Yoffset;
|
||||
$YSpace = ($upper - $Yoffset)/$YLength;
|
||||
$XSpace = ($right - $left)/$XLength;
|
||||
|
||||
//draws X-Axis
|
||||
ImageLine($image, $left, $upper, $right, $upper, $black);
|
||||
|
||||
//draws y-Axis with Yoffset as upper margin
|
||||
ImageLine($image, $left, $upper,$left, $Yoffset,$black);
|
||||
|
||||
//draws arrows
|
||||
ImageLine($image, $right-5, $upper-5,$right,$upper,$black);
|
||||
ImageLine($image, $right-5, $upper+5,$right,$upper,$black);
|
||||
ImageLine($image, $left, $Yoffset,$left+5,$Yoffset+5,$black);
|
||||
ImageLine($image, $left, $Yoffset,$left-5,$Yoffset+5,$black);
|
||||
|
||||
//draws lines for measurement at the y-Axis
|
||||
for($i=1;$i<$YLength;$i++)
|
||||
{
|
||||
ImageLine($image, $left-4, $upper-$YSpace*$i ,$left+4, $upper-$YSpace*$i,$black);
|
||||
}
|
||||
|
||||
//same for the x-Axis
|
||||
for($j=1;$j<$XLength;$j++)
|
||||
{
|
||||
ImageLine($image, $left+$XSpace*$j, $upper-4 ,$left+$XSpace*$j, $upper+4,$black);
|
||||
}
|
||||
|
||||
//caption for x-Axis
|
||||
$index=0;
|
||||
while($index < $XLength)
|
||||
{
|
||||
if($index % 5 == 0)
|
||||
{
|
||||
ImageString($image, 4, $left+($XSpace*$index)-($Xoffset/4), $upper+($Yoffset/3), $index, $black);
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
//caption for y-Axis
|
||||
$index=0;
|
||||
while($index < count($values))
|
||||
{
|
||||
ImageString($image, 4, $left-(0*$Xoffset+30), $upper-$YSpace*$index-($Yoffset*0.7), $values[$index], $black);
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
function DrawBar($image, $length, $maxOfX ,$position, $maxOfY, $value, $color)
|
||||
{
|
||||
$imgWidth = ImageSX($image);
|
||||
$imgHeight = ImageSY($image);
|
||||
|
||||
//scale offset for each axis and minimize Xoffset for small values of maxOfX
|
||||
$Xoffset = 0.8*($imgWidth/$maxOfX);
|
||||
$Yoffset = 0.8*($imgHeight/$maxOfY);
|
||||
|
||||
if($Xoffset>150)
|
||||
{
|
||||
$Xoffset=$Xoffset/10;
|
||||
}
|
||||
|
||||
$length = $length*$Xoffset;
|
||||
$black = ImageColorAllocate($image, 0, 0, 0);
|
||||
|
||||
$left = ($imgWidth - $maxOfX * $Xoffset)/2;
|
||||
$upper = /*($maxOfY*$Yoffset) +*/ $Yoffset + ($position*$Yoffset);
|
||||
$right = $left+$length;
|
||||
ImageFilledRectangle($image, $left, $upper, $right, $upper-$Yoffset, $color);
|
||||
ImageString($image, 4, $right+($Xoffset/3), $upper-$Yoffset*0.7, $value, $black);
|
||||
}
|
||||
|
||||
function CreateImage($width, $height)
|
||||
{
|
||||
$image = ImageCreate($width, $height);
|
||||
$white = ImageColorAllocateAlpha($image, 255, 255, 255, 127);
|
||||
|
||||
ImageFill($image, 0, 0, $white);
|
||||
ImageSaveAlpha($image, TRUE);
|
||||
|
||||
return $image;
|
||||
}
|
||||
?>
|
263
libs/formLib.php
Normal file
263
libs/formLib.php
Normal file
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : formLib.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Description : Provides several functions for displaying form elements
|
||||
// for the ESE evaluation for students and tutors.
|
||||
//============================================================================
|
||||
|
||||
include ('questionnaireLib.php');
|
||||
// constants for the different types of message boxes
|
||||
define ("MSG_ALERT", 0);
|
||||
define ("MSG_WARNING", 1);
|
||||
define ("MSG_DANGER", 2);
|
||||
define ("MSG_SUCCESS", 3);
|
||||
define ("MSG_INFO", 4);
|
||||
// global variable that get toggled if a new row is created and that
|
||||
// indicates if the next created row is of equal or unequal style
|
||||
$isEqualRow = true;
|
||||
|
||||
/**
|
||||
* Echos a new row division element of equal or unequal style depending
|
||||
* on the last row that has been created.
|
||||
*
|
||||
* @param boolean $toggle Indicates if the style should be switched or if the
|
||||
* new row should have same style as the previous row
|
||||
*/
|
||||
function CreateRowHeader($toggle = true)
|
||||
{
|
||||
global $isEqualRow;
|
||||
|
||||
if ($toggle)
|
||||
$isEqualRow = !$isEqualRow;
|
||||
|
||||
if ($isEqualRow == true)
|
||||
echo "<div class=\"row equalrow\">\n";
|
||||
else
|
||||
echo "<div class=\"row unequalrow\">\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new headline division with the specified text with switching
|
||||
* row styles.
|
||||
*
|
||||
* @param string $text The text that should be displayed in the headline.
|
||||
*/
|
||||
function CreateHeadline($text)
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-12\">\n";
|
||||
echo " <h1>" . $text . "</h1>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new section headline with the specified text and switching
|
||||
* row styles.
|
||||
*
|
||||
* @param string $text The text that should be displayed in the section header.
|
||||
*/
|
||||
function CreateSectionHeader($text)
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-12\">\n";
|
||||
echo " <h2>" . $text . "</h2>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new paragraph with the specified text and switching
|
||||
* row styles.
|
||||
*
|
||||
* @param string $text The text that should be displayed in the paragraph.
|
||||
*/
|
||||
function CreateParagraph($text)
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-12\">\n";
|
||||
echo " <p class=\"lead\">" . $text . "</p>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new paragraph with the specified link and switching
|
||||
* row styles.
|
||||
*
|
||||
* @param string $text The text that should be displayed for the link.
|
||||
* @param string $link The target to which should be linked.
|
||||
*/
|
||||
function CreateLink($text, $link)
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-12\">\n";
|
||||
echo " <p class=\"lead\"><a href=\"" . $link . "\">" . $text . "</a></p>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new division with a labelled text box and switching row styles.
|
||||
*
|
||||
* @param string $label The label that should be displayed for the text box.
|
||||
* @param string $id The unique id that is used to identify the text box.
|
||||
* @param string $value The text that should be displayed within the text box.
|
||||
* The default value is no text.
|
||||
*/
|
||||
function CreateTextBox($label, $id, $value = "")
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-8\">\n";
|
||||
echo " <p class=\"lead\">" . $label . "</p>\n";
|
||||
echo " </div>\n";
|
||||
echo " <div class=\"col-sm-4\">\n";
|
||||
echo " <input class=\"form-control\" type=\"text\" id=\"". $id . "\" name=\"". $id . "\" value=\"" . $value . "\" required/>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new division with the questionnaire answer legend and switching row styles.
|
||||
* Should only be used once at the top of the list of questions.
|
||||
*/
|
||||
function CreateLegend()
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-2 col-offset-6\"><p class=\"lead\">Bewertung:</p></div>\n";
|
||||
echo " <div class=\"col-sm-4\">\n";
|
||||
echo " <div class=\"row\">\n";
|
||||
echo " <div class=\"col-2\"><p class=\"lead center\">++</p></div>\n";
|
||||
echo " <div class=\"col-2\"><p class=\"lead center\">+</p></div>\n";
|
||||
echo " <div class=\"col-2\"><p class=\"lead center\">o</p></div>\n";
|
||||
echo " <div class=\"col-2\"><p class=\"lead center\">-</p></div>\n";
|
||||
echo " <div class=\"col-2\"><p class=\"lead center\">--</p></div>\n";
|
||||
echo " <div class=\"col-2\"><p class=\"lead center\">N/A</p></div>\n";
|
||||
echo " </div>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new division with a question and six radio buttons for the possible answer.
|
||||
*
|
||||
* @param string $id The unique id that is used to identify the question.
|
||||
* @param integer $value Indicates which answer should initially be selected.
|
||||
* The default value is -1, which means no answer is selected.
|
||||
* The other possible values range from 1 to 6.
|
||||
*/
|
||||
function CreateQuestion($question, $id, $value = -1)
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-8\">\n";
|
||||
echo " <p class=\"lead\">" . $question . "</p>\n";
|
||||
echo " </div>\n";
|
||||
echo " <div class=\"col-sm-4\">\n";
|
||||
echo " <div class=\"row\">\n";
|
||||
for ($i = 1; $i < 7; $i++)
|
||||
{
|
||||
echo " <div class=\"col-2\"><input class=\"form-control\" type=\"radio\" id=\"" . $id . $i . "\" name=\"" . $id . "\" value=\"" . $i . "\" required";
|
||||
if ($value == $i)
|
||||
echo " checked";
|
||||
echo "/></div>\n";
|
||||
}
|
||||
echo " </div>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new division with a labelled comment box and switching row styles.
|
||||
*
|
||||
* @param string $label The label that should be displayed for the comment box.
|
||||
* @param string $id The unique id that is used to identify the comment box.
|
||||
* @param string $value The comment that should be displayed within the comment box.
|
||||
* The default value is no text.
|
||||
*/
|
||||
function CreateCommentBox($label, $id, $value = "")
|
||||
{
|
||||
CreateRowHeader();
|
||||
echo " <div class=\"col-sm-8\">\n";
|
||||
echo " <p class=\"lead\">" . $label . "</p>\n";
|
||||
echo " </div>\n";
|
||||
echo " <div class=\"col-sm-4\">\n";
|
||||
echo " <textarea class=\"form-control\" id=\"" . $id . "\" name=\"" . $id . "\">" . $value . "</textarea>\n";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
/**
|
||||
* Echos a new division for the questionnaire element with the specified id.
|
||||
* What kind of division is created id determined by the type of the element.
|
||||
*
|
||||
* @param string $id The unique id of the element that should be created.
|
||||
* @param array $questionnaire The questionnaire data that is used to build the form.
|
||||
* Passed by reference.
|
||||
* @param array $formData The list of all form elements and their values. This should
|
||||
* simply be the $_POST array that was submitted.
|
||||
* Passed by reference.
|
||||
*/
|
||||
function CreateQuestionnaireElement($id, &$questionnaire, &$formData)
|
||||
{
|
||||
if (!isset($questionnaire[$id]))
|
||||
return;
|
||||
$entry = $questionnaire[$id];
|
||||
$type = $entry[0];
|
||||
$value = "";
|
||||
if (isset($formData[$id]))
|
||||
$value = $formData[$id];
|
||||
|
||||
if ($type == Q_HEADLINE)
|
||||
CreateHeadline($entry[1]);
|
||||
if ($type == Q_LEGEND)
|
||||
CreateLegend();
|
||||
else if ($type == Q_TEXTBOX)
|
||||
CreateTextBox($entry[1], $id, $value);
|
||||
else if ($type == Q_QUESTION)
|
||||
CreateQuestion($entry[1], $id, $value);
|
||||
else if ($type == Q_COMMENT)
|
||||
CreateCommentBox($entry[1], $id, $value);
|
||||
}
|
||||
/**
|
||||
* Echos a range of new divisions with switching row styles for all questions that
|
||||
* the specified questionnaire data contains. Only the questions are created, nothing else.
|
||||
*
|
||||
* @param array $questionnaire The questionnaire data that is used to build the form.
|
||||
* Passed by reference.
|
||||
* @param array $formData The list of all form elements and their values. This should
|
||||
* simply be the $_POST array that was submitted.
|
||||
* Passed by reference.
|
||||
*/
|
||||
function CreateAllQuestionElements(&$questionnaire, &$formData)
|
||||
{
|
||||
foreach($questionnaire as $id => $entry)
|
||||
{
|
||||
$type = $entry[0];
|
||||
if ($type != Q_QUESTION)
|
||||
continue;
|
||||
$value = "";
|
||||
if (isset($formData[$id]))
|
||||
$value = $formData[$id];
|
||||
CreateQuestion($entry[1], $id, $value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Echos a new division with switching row styles that represents a message box.
|
||||
*
|
||||
* @param integer $msgType The type of message box that should be created. The MSG constants
|
||||
* defined at the beginning of this file should be used for this parameter.
|
||||
* @param string $header The text that should be displayed in the header of the message box.
|
||||
* @param string $text The text that is displayed within the message box itself.
|
||||
*/
|
||||
function CreateMessageBox($msgType, $header, $text)
|
||||
{
|
||||
CreateRowHeader(false);
|
||||
echo " <div class=\"col-sm-12 col-offset-0\">\n";
|
||||
echo "<div class=\"panel";
|
||||
if ($msgType == MSG_WARNING)
|
||||
echo " panel-warning";
|
||||
else if ($msgType == MSG_DANGER)
|
||||
echo " panel-danger";
|
||||
else if ($msgType == MSG_SUCCESS)
|
||||
echo " panel-success";
|
||||
else if ($msgType == MSG_INFO)
|
||||
echo " panel-info";
|
||||
echo "\"><div class=\"panel-heading\"><h3 class=\"panel-title\">" . $header . "</h3></div>" . $text . "</div>";
|
||||
echo " </div>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
?>
|
166
libs/keyLib.php
Normal file
166
libs/keyLib.php
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : keyLib.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Description : Provides several functions for creating and handling keys
|
||||
// for the ESE evaluation for students and tutors.
|
||||
//============================================================================
|
||||
|
||||
// Constant for the file which contains the keys, should be used by all other scripts so it can easily be changed
|
||||
define ("KEYFILE", "keys/Keys.csv");
|
||||
// Constants for the different key states that are possible, should always be used when altering or checking the state of a key
|
||||
define ("KEYSTATE_NONEXISTENT", "nonexistent");
|
||||
define ("KEYSTATE_UNISSUED", "unissued");
|
||||
define ("KEYSTATE_ISSUED", "issued");
|
||||
define ("KEYSTATE_ACTIVATED", "activated");
|
||||
define ("KEYSTATE_USED", "used");
|
||||
|
||||
/**
|
||||
* Generates a key from the specified hash value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function GenerateKey()
|
||||
{
|
||||
// create a hash using a unique id based on the servers system time and the sha1 hashing algorithm
|
||||
$hash = strtoupper(hash("sha1", uniqid()));
|
||||
// extract the desired number of digits out of the hash to generate the key
|
||||
return substr($hash, 0, 4) . "-" . substr($hash, 4, 4) . "-" . substr($hash, 8, 4) . "-" . substr($hash, 12, 4);
|
||||
//return substr($hash, 0, 2) . "-" . substr($hash, 2, 2) . "-" . substr($hash, 4, 2) . "-" . substr($hash, 6, 2);
|
||||
}
|
||||
/**
|
||||
* Generates the specified amount of keys. Be aware that this function just
|
||||
* creates an array of keys with no state assigned.
|
||||
*
|
||||
* @param integer $amount The amount of keys that should be generated
|
||||
* @return array
|
||||
*/
|
||||
function GenerateKeys($amount)
|
||||
{
|
||||
$keys = array();
|
||||
for ($i = 0; $i < $amount; $i++)
|
||||
{
|
||||
array_push($keys, GenerateKey());
|
||||
usleep(1);
|
||||
}
|
||||
return array_unique($keys);
|
||||
}
|
||||
/**
|
||||
* Generates a new key file with the specified name that contains the specified
|
||||
* amount of newly generated keys.
|
||||
* Returns true if the key file was created successfully, otherwise false.
|
||||
*
|
||||
* @param integer $keyAmount The amount of keys that should be generated.
|
||||
* @param string $fileName The name of the key file that should be created.
|
||||
*/
|
||||
function CreateKeyFile($keyAmount, $fileName)
|
||||
{
|
||||
$handle = fopen($fileName, 'w');
|
||||
if (!$handle)
|
||||
return false;
|
||||
$keys = GenerateKeys($keyAmount);
|
||||
$data = "Nr;Key;Status\n";
|
||||
$count = count($keys) - 1;
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
$data = $data . $i . ";" . $keys[$i] . ";" . KEYSTATE_UNISSUED. "\n";
|
||||
$data = $data . $count . ";" . $keys[$count] . ";". KEYSTATE_UNISSUED;
|
||||
fwrite($handle, $data);
|
||||
fclose($handle);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Opens the file with the specified name and reads all key data that the file contains.
|
||||
* The resulting data type will be an array of arrays consisting of the key and its state.
|
||||
* Returns null if the key file could not be found or read.
|
||||
*
|
||||
* @param string $fileName The file which should be read
|
||||
* @return array
|
||||
*/
|
||||
function ReadKeyFile($fileName)
|
||||
{
|
||||
if (!file_exists($fileName))
|
||||
return null;
|
||||
$handle = fopen($fileName, 'r');
|
||||
if (!$handle)
|
||||
return null;
|
||||
$data = fread($handle, filesize($fileName));
|
||||
$lines = explode("\n", $data);
|
||||
$keyData = array();
|
||||
for ($i = 1; $i < count($lines); $i++)
|
||||
{
|
||||
$tmp = explode(";", $lines[$i]);
|
||||
array_push($keyData, array($tmp[1], $tmp[2]));
|
||||
}
|
||||
return $keyData;
|
||||
}
|
||||
/**
|
||||
* Writes the specified key data to the file with the specified name.
|
||||
* The data type of the $keyData should be an array of arrays consisting of the key and its state.
|
||||
* Returns true if the key file was successfully written, otherwise false.
|
||||
*
|
||||
* @param string $fileName The name of the file to which the key data should be written.
|
||||
* @param array $keyData The key data which should be written to the file. Passed by reference.
|
||||
* @return boolean
|
||||
*/
|
||||
function WriteKeyFile($fileName, &$keyData)
|
||||
{
|
||||
if (!isset($fileName) || !isset($keyData))
|
||||
return false;
|
||||
$handle = fopen($fileName, 'w+');
|
||||
if ($handle == null)
|
||||
return false;
|
||||
// debug code
|
||||
//echo "<script type='text/javascript'>alert('file opened');</script>";
|
||||
$data = "Nr;Key;Status\n";
|
||||
$count = count($keyData) - 1;
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
$data = $data . $i . ";" . $keyData[$i][0] . ";" . $keyData[$i][1] . "\n";
|
||||
$data = $data . $count . ";" . $keyData[$count][0] . ";" . $keyData[$count][1];
|
||||
$res = fwrite($handle, $data);
|
||||
// debug Code
|
||||
//if ($res == false)
|
||||
// echo "<script type='text/javascript'>alert('file not written');</script>";
|
||||
//else
|
||||
// echo "<script type='text/javascript'>alert('file written');</script>";
|
||||
fclose($handle);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Get the current state of the specified key which will be one of the defines
|
||||
* KEYSTATE constants.
|
||||
* The data type of the key data should be an array of arrays consisting of the key and its state.
|
||||
*
|
||||
* @param array $keyData The key data array in which the key should be found. Passed by reference.
|
||||
* @param string $key The key which state should be got. Passed by reference.
|
||||
* @return integer
|
||||
*/
|
||||
function GetKeyState(&$keyData, &$key)
|
||||
{
|
||||
for ($i = 0; $i < count($keyData); $i++)
|
||||
if ($key == $keyData[$i][0])
|
||||
return $keyData[$i][1];
|
||||
return KEYSTATE_NONEXISTENT;
|
||||
}
|
||||
/**
|
||||
* Set the state of the specified key to the specified state.
|
||||
* The data type of the $keyData should be an array of arrays consisting of the key and its state.
|
||||
* Returns true if the key was found within the key data and the state has been changed, otherwise false.
|
||||
*
|
||||
* @param array $keyData The key data array in which the key should be found. Passed by reference.
|
||||
* @param string $key The key which state should be changed.
|
||||
* @param integer $newState The new state of the specified key. Must be on of the KEYSTATE constants.
|
||||
* @return boolean
|
||||
*/
|
||||
function SetKeyState(&$keyData, &$key, $newState)
|
||||
{
|
||||
for ($i = 0; $i < count($keyData); $i++)
|
||||
if ($key == $keyData[$i][0])
|
||||
{
|
||||
$keyData[$i][1] = $newState;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
?>
|
304
libs/loggingLib.php
Normal file
304
libs/loggingLib.php
Normal file
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : loggingLib.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Description : Provides functions for creating, reading and appending
|
||||
// log files and data for the ESE evaluation for students
|
||||
// and tutors.
|
||||
//============================================================================
|
||||
|
||||
define ("STUDENTLOGFILE", "logs/ESE2013_studentLog.txt");
|
||||
define ("TUTORLOGFILE", "logs/ESE2013_tutorLog.txt");
|
||||
|
||||
/**
|
||||
* Reads all question data out of a provided log file array that has been split by new lines.
|
||||
* This function should NOT BE CALLED directly, instead the ReadLogFile function should be
|
||||
* used to read a log file as a whole.
|
||||
* All data is written to the specified question data array and
|
||||
* True is returned if a valid question data block was found, otherwise false.
|
||||
*
|
||||
* @param array $lines An array of string resembling the different lines of the log file. Passed by reference.
|
||||
* @param integer $index The index within the lines array by which the processing should start.
|
||||
* The index is passed by reference and will be incremented by this function.
|
||||
* @param array $questionData An array to which all question data is written to.
|
||||
* @return boolean.
|
||||
*/
|
||||
function ReadLogQuestionData(&$lines, &$index, &$questionData)
|
||||
{
|
||||
// check if the current line is a question block
|
||||
// and return false if that is not the case
|
||||
if (trim($lines[$index]) != "###QuestionData###")
|
||||
return false;
|
||||
// the index must be incremented so the next loop starts at the right line
|
||||
$index++;
|
||||
while($index < count($lines))
|
||||
{
|
||||
// if the character '#' indicates that the question data block has been finished
|
||||
// so the loop is completed
|
||||
if ($lines[$index][0] == "#")
|
||||
break;
|
||||
// split the current line by the character ';' to get the individual data elements
|
||||
$tmp = explode(";", $lines[$index]);
|
||||
// set identifier is the first data element and is used to init the field of the
|
||||
// current question in the questionData array
|
||||
$questionData[$tmp[0]] = array();
|
||||
// push all other data elements in the previously created array
|
||||
for ($i = 1; $i < count($tmp); $i++)
|
||||
array_push($questionData[$tmp[0]], $tmp[$i]);
|
||||
// increment the index to continue with the next line of the file
|
||||
$index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Reads all tutor data out of a provided log file array that has been split by new lines.
|
||||
* This function should NOT BE CALLED directly, instead the ReadLogFile function should be
|
||||
* used to read a log file as a whole.
|
||||
* All data is written to the specified tutor data array.
|
||||
* True is returned if a valid tutor data block was found, otherwise false.
|
||||
*
|
||||
* @param array $lines An array of string resembling the different lines of the log file. Passed by reference.
|
||||
* @param integer $index The index within the lines array by which the processing should start.
|
||||
* The index is passed by reference and will be incremented by this function.
|
||||
* @param array $tutorData An array to which all tutor data is written to.
|
||||
* @return boolean.
|
||||
*/
|
||||
function ReadLogTutorData(&$lines, &$index, &$tutorData)
|
||||
{
|
||||
// check if the current line is a tutor data block
|
||||
// and return false if that is not the case
|
||||
if (trim($lines[$index]) != "###TutorData###")
|
||||
return false;
|
||||
// the index must be incremented so the next loop starts at the right line
|
||||
$index++;
|
||||
// parse the tutor data - its basically the same as the question data
|
||||
while($index < count($lines))
|
||||
{
|
||||
// if the character '#' indicates that the tutor data block has been finished
|
||||
// so the loop is completed
|
||||
if ($lines[$index][0] == "#")
|
||||
break;
|
||||
// split the current line by the character ';' to get the individual data elements
|
||||
$tmp = explode(";", $lines[$index]);
|
||||
// set identifier is the first data element and is used to init the field of the
|
||||
// current tutor in the tutorData array
|
||||
$tutorData[$tmp[0]] = array();
|
||||
// push all other data elements in the previously created array
|
||||
for ($i = 1; $i < count($tmp); $i++)
|
||||
array_push($tutorData[$tmp[0]], $tmp[$i]);
|
||||
// increment the index to continue with the next line of the file
|
||||
$index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Reads all comment data out of a provided log file array that has been split by new lines.
|
||||
* This function should NOT BE CALLED directly, instead the ReadLogFile function should be
|
||||
* used to read a log file as a whole.
|
||||
* All data is written to the specified comment data array.
|
||||
* True is returned if a valid comment data block was found, otherwise false.
|
||||
*
|
||||
* @param array $lines An array of string resembling the different lines of the log file. Passed by reference.
|
||||
* @param integer $index The index within the lines array by which the processing should start.
|
||||
* The index is passed by reference and will be incremented by this function.
|
||||
* @param array $commentData An array to which all comment data is written to.
|
||||
* @return boolean.
|
||||
*/
|
||||
function ReadLogCommentData(&$lines, &$index, &$commentData)
|
||||
{
|
||||
// check if the current line is a comment data block
|
||||
// and return false if that is not the case
|
||||
if (trim($lines[$index]) != "###CommentData###")
|
||||
return false;
|
||||
// the index must be incremented so the next loop starts at the right line
|
||||
$index++;
|
||||
// the current comment that gets pushed to the commentData array
|
||||
// when a comment end sequence has been found
|
||||
$comment = "";
|
||||
// parse the comment data
|
||||
while($index < count($lines))
|
||||
{
|
||||
// if the line start with the character '~' the line is
|
||||
// interpreted as the comment end sequence and the current
|
||||
// comment is pushed at the end of the comment array
|
||||
// and the loop continues with a new comment
|
||||
if (trim($lines[$index]) != "" && $lines[$index][0] == "~")
|
||||
{
|
||||
// the last character of the comment is erased because it's
|
||||
// just an unnecessary new line
|
||||
array_push($commentData, substr($comment, 0, -1));
|
||||
$comment = "";
|
||||
}
|
||||
// otherwise the current comment is simply appended by the
|
||||
// current line
|
||||
else
|
||||
$comment = $comment . $lines[$index] . "\n";
|
||||
// increment the index to continue with the next line of the file
|
||||
$index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Reads the log file with the specified name and writes all log data to the corresponding arrays.
|
||||
* Returns true if the log file has been successfully written, otherwise false.
|
||||
* Is guaranteed to initialize the specified log arrays, even when the log file could not be
|
||||
* read in which case they will simply be empty.
|
||||
*
|
||||
* @param array $questionData Will be created by this function and is passed by reference.
|
||||
* Is an array of arrays that consists of the unique id, the question
|
||||
* and the fields for the possible response options which contain
|
||||
* the number of times that option has been selected.
|
||||
* @param array $tutorData Will be created by this function and is passed by reference.
|
||||
* Is an array of arrays that consists of the tutor name and the
|
||||
* fields for the possible response options which contain the number
|
||||
* of times that option has been selected.
|
||||
* @param array $commentData Will be created by this function and is passed by reference.
|
||||
* Is an array of string that resemble the different comments that
|
||||
* have been made.
|
||||
*/
|
||||
function ReadLogFile($fileName, &$questionData, &$tutorData, &$commentData)
|
||||
{
|
||||
// init arrays regardless of the file not being found or eventual errors
|
||||
$questionData = array();
|
||||
$tutorData = array();
|
||||
$commentData = array();
|
||||
// return if the file does not exist
|
||||
if (file_exists($fileName) == false)
|
||||
return false;
|
||||
// open the file and get its length
|
||||
$handle = fopen($fileName, 'r');
|
||||
if (!$handle)
|
||||
return false;
|
||||
$length = filesize($fileName);
|
||||
// if the length is zero, nothing can be read, so return
|
||||
if ($length == 0)
|
||||
return false;
|
||||
// otherwise read the file and split the string at each new line
|
||||
$fileData = fread($handle, $length);
|
||||
$lines = explode("\n", $fileData);
|
||||
// begin parsing of the file, the beginning is the second line, because the
|
||||
// first should contains the disclaimer
|
||||
$index = 1;
|
||||
ReadLogQuestionData($lines, $index, $questionData);
|
||||
ReadLogTutorData($lines, $index, $tutorData);
|
||||
ReadLogCommentData($lines, $index, $commentData);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Writes the specified log arrays to a log file with the specified name.
|
||||
* Expects data in the same format as provided by the ReadLogFile function.
|
||||
* Returns true if the file was written successfully, otherwise false.
|
||||
*
|
||||
* @param string $fileName The name of the file to which the log data should be written.
|
||||
* @param array $questionData The question data that should be written to the log file.
|
||||
* @param array $tutorData The tutor data that should be written to the log file.
|
||||
* @param array $commentData The list of comments that should be written to the log file. Passed by reference.
|
||||
* @return boolean
|
||||
*/
|
||||
function WriteLogFile($fileName, &$questionData, &$tutorData, &$commentData)
|
||||
{
|
||||
$handle = fopen($fileName, 'w');
|
||||
if (!$handle)
|
||||
return false;
|
||||
// write disclaimer and question data block identifier
|
||||
$fileData = "# Automatically generated file - Do not Change ! #\n###QuestionData###\n";
|
||||
// write all question data to the file
|
||||
foreach($questionData as $id => $entry)
|
||||
{
|
||||
// the order is id, question and the number of times each of the six answers was picked
|
||||
$fileData = $fileData . $id . ";";
|
||||
for ($i = 0; $i < 6; $i++)
|
||||
$fileData = $fileData . $entry[$i] . ";";
|
||||
$fileData = $fileData . $entry[6] . "\n";
|
||||
}
|
||||
// write tutor data block identifier
|
||||
$fileData = $fileData . "###TutorData###\n";
|
||||
// write all tutor data to the file
|
||||
foreach($tutorData as $id => $entry)
|
||||
{
|
||||
// the order is tutor name and the number of times each of the six answers was picked
|
||||
$fileData = $fileData . $id . ";";
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
$fileData = $fileData . $entry[$i] . ";";
|
||||
$fileData = $fileData . $entry[5] . "\n";
|
||||
}
|
||||
// write comment data block identifier
|
||||
$fileData = $fileData . "###CommentData###";
|
||||
// write comment data
|
||||
foreach($commentData as $comment)
|
||||
// each comment is escapd by a new line containing three tilde characters
|
||||
$fileData = $fileData . "\n" . $comment . "\n~~~";
|
||||
// write the generated data to the file and close it
|
||||
fwrite($handle, $fileData);
|
||||
fclose($handle);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Add the question data from the specified questionnaire form data to an existing form data array.
|
||||
*
|
||||
* @param array $formData The list of all form elements which for most cases will simply be the
|
||||
* $_POST array that has been submitted by the questionnaire form.
|
||||
* Passed by reference.
|
||||
* @param array $commentData The list of existing question data that will be appended by the question
|
||||
* Data of the form. Passed by reference.
|
||||
*/
|
||||
function AddQuestionData(&$formData, &$questionData, &$questionnaire)
|
||||
{
|
||||
foreach($formData as $id => $value)
|
||||
{
|
||||
if (!isset($questionnaire[$id]))
|
||||
continue;
|
||||
// get the type of the element with the same id as the form element from the questionnaire
|
||||
$type = $questionnaire[$id][0];
|
||||
// check if the element is a question on continue with the next one if that is not hte case
|
||||
if ($type != "Question")
|
||||
continue;
|
||||
// if there is not field for the current element in the question dsta array, create a new
|
||||
// blank field containing the question and zeros for the number of times each answer was picked
|
||||
if (array_key_exists($id, $questionData) == false)
|
||||
$questionData[$id] = array($questionnaire[$id][1], 0, 0, 0, 0, 0, 0);
|
||||
// increment the answer that was selected in the formular by one
|
||||
$questionData[$id][(int)$value]++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add the tutor data from the specified questionnaire form data to an existing tutor data array.
|
||||
*
|
||||
* @param array $formData The list of all form elements which for most cases will simply be the
|
||||
* $_POST array that has been submitted by the questionnaire form.
|
||||
* Passed by reference.
|
||||
* @param array $commentData The list of existing tutor data that will be appended by the tutor
|
||||
* Data of the form. Passed by reference.
|
||||
*/
|
||||
function AddTutorData(&$formData, &$tutorData)
|
||||
{
|
||||
// get the name of the tutor from the form
|
||||
$tutorName = $formData["tutorName"];
|
||||
// get the selected answer of the tutorRating from the form
|
||||
$tutorValue = $formData["tutorRating"];
|
||||
// if there is no field for the current tutor in the tutor array, create a new
|
||||
// nlank one with zeros for the number of times each answer was picked
|
||||
if (array_key_exists($tutorName, $tutorData) == false)
|
||||
$tutorData[$tutorName] = array(0, 0, 0, 0, 0, 0);
|
||||
// increment the answer that was selected in the form by one
|
||||
$tutorData[$tutorName][$tutorValue - 1]++;
|
||||
}
|
||||
/**
|
||||
* Add the comment data from the specified questionnaire form data to an existing comment data array.
|
||||
*
|
||||
* @param array $formData The list of all form elements which for most cases will simply be the
|
||||
* $_POST array that has been submitted by the questionnaire form.
|
||||
* Passed by reference.
|
||||
* @param array $commentData The list of existing comments that will be appended by the comment
|
||||
* Data of the form. Passed by reference.
|
||||
*/
|
||||
function AddCommentData(&$formData, &$commentData)
|
||||
{
|
||||
// if the comment field was filled, the comment
|
||||
// array is appended by the new comment
|
||||
if (array_key_exists("comment", $formData) && trim($formData["comment"]) != "")
|
||||
array_push($commentData, $formData["comment"]);
|
||||
}
|
||||
?>
|
77
libs/questionnaireLib.php
Normal file
77
libs/questionnaireLib.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : questionnaireLib.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 8-2013
|
||||
// Description : Provides functions for handling questionnaire text files
|
||||
// for the ESE questionnaire for students and tutors.
|
||||
//============================================================================
|
||||
|
||||
define ("STUDENT_QUESTIONNAIRE", "questionnaires/student_questionnaire.txt");
|
||||
define ("TUTOR_QUESTIONNAIRE", "questionnaires/tutor_questionnaire.txt");
|
||||
// Possible Questionnaire Element Types
|
||||
// Should be used by all scripts when referencing them
|
||||
/**
|
||||
* Headline element
|
||||
* Parameter:
|
||||
* - Text for the Headline
|
||||
*/
|
||||
define ("Q_HEADLINE", "Headline");
|
||||
/**
|
||||
* TextBox Element
|
||||
* Parameter:
|
||||
* - Label for the TextBox
|
||||
*/
|
||||
define ("Q_TEXTBOX", "TextBox");
|
||||
/**
|
||||
* Legend Element
|
||||
* no Parameter
|
||||
*/
|
||||
define ("Q_LEGEND", "Legend");
|
||||
/**
|
||||
* Question Element
|
||||
* Parameter:
|
||||
* - Label for the Question
|
||||
*/
|
||||
define ("Q_QUESTION", "Question");
|
||||
/**
|
||||
* Comment Element
|
||||
* Parameter:
|
||||
* - Label for the CommentBox
|
||||
*/
|
||||
define ("Q_COMMENT", "Comment");
|
||||
|
||||
/**
|
||||
* Reads the questionnaire file with the specified name and returns an array
|
||||
* resembling the questionnaire data. The array consists of array indexed by
|
||||
* the unique ids of the elements that was specified within the questionnaire
|
||||
* file. The element arrays itself consist the type of the element, and a list
|
||||
* of parameters depending on the type of element.
|
||||
* If the file could not be opened or read, null is returned.
|
||||
*
|
||||
* @param string $fileName The name of the file that should be read.
|
||||
* @return array
|
||||
*/
|
||||
function ReadQuestionnaireFile($fileName)
|
||||
{
|
||||
if (!file_exists($fileName))
|
||||
return null;
|
||||
$handle = fopen($fileName, 'r');
|
||||
if (!$handle)
|
||||
return null;
|
||||
$rawData = fread($handle, filesize($fileName));
|
||||
$lines = explode("\n", $rawData);
|
||||
$data = array();
|
||||
for ($i = 1; $i < count($lines); $i++)
|
||||
if (trim($lines[$i]) != "" && $lines[$i][0] != "#")
|
||||
{
|
||||
$tmp = explode(";", $lines[$i]);
|
||||
$entry = array();
|
||||
for ($j = 1; $j < count($tmp); $j++)
|
||||
array_push($entry, trim($tmp[$j]));
|
||||
$data[trim($tmp[0])] = $entry;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue