mirror of
https://github.com/fsr/eseeva
synced 2024-11-15 00:43:12 +01:00
upgrades to sqlite, first step towards #2
This commit is contained in:
parent
134775b2d7
commit
fe8a426334
18
analysis.php
18
analysis.php
|
@ -2,30 +2,28 @@
|
|||
//============================================================================
|
||||
// Name : analysis.php
|
||||
// Author : Patrick Reipschläger, Lucas Woltmann
|
||||
// Version : 0.5
|
||||
// Date : 08-2013
|
||||
// Version : 1.0
|
||||
// Date : 01-2017
|
||||
// Description : Analysis a ESE Evaluation log file. The file that is analysed
|
||||
// may be passed as parameter with the URL.
|
||||
//============================================================================
|
||||
include_once 'libs/formLib.php';
|
||||
include_once 'libs/questionnaireLib.php';
|
||||
include_once 'libs/loggingLib.php';
|
||||
include_once 'libs/dbLib.php';
|
||||
include_once 'libs/chartLib.php';
|
||||
|
||||
// variables for the log data
|
||||
$questionData;
|
||||
$tutorData;
|
||||
$commentData;
|
||||
// Default log file is the student log file defined in 'loggingLib.php'
|
||||
$logFile = STUDENTLOGFILE;
|
||||
// Default log file is the student log file defined in 'dbLib.php'
|
||||
$logFile = LOGDB;
|
||||
// if a logFile parameter has been passed in the URL, than that value will
|
||||
// be used instead of the default value (with the added folder name)
|
||||
if (isset($_GET["logFile"]))
|
||||
$logFile = "logs/" . $_GET["logFile"];
|
||||
// read the existing log file, if there is no existing log file, the RadLogFile
|
||||
// function guarantees the initialization of the log variables, which will
|
||||
// result in the same outcome as if an empty log file is read
|
||||
ReadLogFile($logFile, $questionData, $tutorData, $commentData);
|
||||
$logFile = "db/" . $_GET["logFile"];
|
||||
// read the database
|
||||
ReadLogDatabase($logFile, 1, $questionData, $tutorData, $commentData);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
|
|
@ -2,30 +2,28 @@
|
|||
//============================================================================
|
||||
// Name : analysisTut.php
|
||||
// Author : Patrick Reipschläger, Lucas Woltmann
|
||||
// Version : 0.5
|
||||
// Date : 08-2013
|
||||
// Version : 1.0
|
||||
// Date : 01-2017
|
||||
// Description : Analysis a ESE Evaluation tutor log file. The file that is analysed
|
||||
// may be passed as parameter with the URL.
|
||||
//============================================================================
|
||||
include_once 'libs/formLib.php';
|
||||
include_once 'libs/questionnaireLib.php';
|
||||
include_once 'libs/loggingLib.php';
|
||||
include_once 'libs/dbLib.php';
|
||||
include_once 'libs/chartLib.php';
|
||||
|
||||
// variables for the log data
|
||||
$questionData;
|
||||
$tutorData;
|
||||
$commentData;
|
||||
// Default log file is the student log file defined in 'loggingLib.php'
|
||||
$logFile = TUTORLOGFILE;
|
||||
// Default log file is the student log file defined in 'dbLib.php'
|
||||
$logFile = LOGDB;
|
||||
// if a logFile parameter has been passed in the URL, than that value will
|
||||
// be used instead of the default value (with the added folder name)
|
||||
if (isset($_GET["logFile"]))
|
||||
$logFile = "logs/" . $_GET["logFile"];
|
||||
// read the existing log file, if there is no existing log file, the RadLogFile
|
||||
// function guarantees the initialization of the log variables, which will
|
||||
// result in the same outcome as if an empty log file is read
|
||||
ReadLogFile($logFile, $questionData, $tutorData, $commentData);
|
||||
$logFile = "db/" . $_GET["logFile"];
|
||||
// read the database
|
||||
ReadLogDatabase($logFile, 0, $questionData, $tutorData, $commentData);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
|
7
db/schema.sql
Normal file
7
db/schema.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE 'answers'
|
||||
(
|
||||
KeyId text primary key,
|
||||
Status text,
|
||||
Student int,
|
||||
Answer
|
||||
);
|
65
keyTable.php
65
keyTable.php
|
@ -1,22 +1,22 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : keyTable.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Author : Patrick Reipschläger, Lucas Woltmann
|
||||
// Version : 2.0
|
||||
// Date : 01-2017
|
||||
// Description : For managing all keys and their states.
|
||||
//============================================================================
|
||||
include_once 'libs/keyLib.php';
|
||||
include_once 'libs/formLib.php';
|
||||
// start a session prevent sending the same post twice
|
||||
// if the user refreshes the page, it will default to the
|
||||
// access code screen
|
||||
session_start();
|
||||
// the key file which should be edited, either the default key file or the one that was specified
|
||||
|
||||
$keyFile = KEYFILE;
|
||||
if (isset($_GET["keyFile"]))
|
||||
$keyFile = $_GET["keyFile"];
|
||||
// holds the key data, either be generated from the form or by from the key file
|
||||
else
|
||||
|
||||
// holds the key data, either be generated from the form or by from the database
|
||||
$keyData;
|
||||
|
||||
|
||||
|
@ -25,53 +25,42 @@
|
|||
|
||||
if (isset($_SESSION["submissionId"]) && ($_SESSION["submissionId"] == $_POST["submissionId"]))
|
||||
{
|
||||
//user changes the states of some keys or deletes keys
|
||||
if (isset($_POST["changesConfirm"]))
|
||||
{
|
||||
$keyData = array();
|
||||
$i = 0;
|
||||
while(isset($_POST["keyIndex" . $i]))
|
||||
{
|
||||
if (!isset($_POST["keyDelete" . $i]) || $_POST["keyDelete" . $i] == false)
|
||||
array_push($keyData, array($_POST["keyCode" . $i], $_POST["keyState" . $i]));
|
||||
if (isset($_POST["keyDelete" . $i]))
|
||||
DeleteKey($keyFile, $_POST["keyCode" . $i]);
|
||||
else
|
||||
SetKeyState($keyFile, $_POST["keyCode" . $i], $_POST["keyState" . $i]);
|
||||
$i++;
|
||||
}
|
||||
WriteKeyFile($keyFile, $keyData);
|
||||
$keyData = ReadKeys($keyFile);
|
||||
}
|
||||
//user generates new keys
|
||||
else if (isset($_POST["keyGenNew"]))
|
||||
{
|
||||
$amount = $_POST["keyAmount"];
|
||||
$keyFile = $_POST["keyFile"];
|
||||
CreateKeyFile($amount, $keyFile);
|
||||
$keyData = ReadKeyFile($keyFile);
|
||||
CreateKeys($amount, $keyFile);
|
||||
$keyData = ReadKeys($keyFile);
|
||||
}
|
||||
//user appends new keys
|
||||
else if (isset($_POST["keyGenAppend"]))
|
||||
{
|
||||
$amount = (int)$_POST["keyAmount"];
|
||||
$amount = $_POST["keyAmount"];
|
||||
$keyFile = $_POST["keyFile"];
|
||||
$keyData = ReadKeyFile($keyFile);
|
||||
while($amount > 0)
|
||||
{
|
||||
$key = GenerateKey();
|
||||
$duplicate = false;
|
||||
foreach($keyData as $entry)
|
||||
if ($entry[0] == $key)
|
||||
{
|
||||
$duplicate = true;
|
||||
break;
|
||||
}
|
||||
if ($duplicate)
|
||||
continue;
|
||||
array_push($keyData, array($key, KEYSTATE_UNISSUED));
|
||||
$amount--;
|
||||
}
|
||||
WriteKeyFile($keyFile, $keyData);
|
||||
CreateKeys($amount, $keyFile);
|
||||
$keyData = ReadKeys($keyFile);
|
||||
}
|
||||
else
|
||||
$keyData = ReadKeyFile($keyFile);
|
||||
$keyData = ReadKeys($keyFile);
|
||||
}
|
||||
// if the page was refreshed by the user, just load the key file
|
||||
else
|
||||
$keyData = ReadKeyFile($keyFile);
|
||||
$keyData = ReadKeys($keyFile);
|
||||
// generate a new submission id that is used within the form to prevent double posts
|
||||
$_SESSION["submissionId"] = rand();
|
||||
?>
|
||||
|
@ -109,15 +98,15 @@
|
|||
echo " </div>\n";
|
||||
|
||||
echo " <div class=\"col-6\">\n";
|
||||
echo " <input type=\"textbox\" class=\"form-control\" name=\"keyCode" . $i . "\" value=\"" . $keyData[$i][0] . "\" readonly/>\n";
|
||||
echo " <input type=\"textbox\" class=\"form-control\" name=\"keyCode" . $i . "\" value=\"" . $keyData[$i]["KeyId"] . "\" readonly/>\n";
|
||||
echo " </div>\n";
|
||||
|
||||
echo " <div class=\"col-2\">\n";
|
||||
echo " <select class=\"form-control lead\" name=\"keyState" . $i . "\">";
|
||||
echo " <option value=\"" . KEYSTATE_UNISSUED . "\""; if ($keyData[$i][1] == KEYSTATE_UNISSUED) echo " selected"; echo">" . KEYSTATE_UNISSUED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_ISSUED . "\""; if ($keyData[$i][1] == KEYSTATE_ISSUED) echo " selected"; echo">" . KEYSTATE_ISSUED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_ACTIVATED . "\""; if ($keyData[$i][1] == KEYSTATE_ACTIVATED) echo " selected"; echo">" . KEYSTATE_ACTIVATED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_USED . "\""; if ($keyData[$i][1] == KEYSTATE_USED) echo " selected"; echo">" . KEYSTATE_USED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_UNISSUED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_UNISSUED) echo " selected"; echo">" . KEYSTATE_UNISSUED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_ISSUED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_ISSUED) echo " selected"; echo">" . KEYSTATE_ISSUED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_ACTIVATED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_ACTIVATED) echo " selected"; echo">" . KEYSTATE_ACTIVATED . "</option>";
|
||||
echo " <option value=\"" . KEYSTATE_USED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_USED) echo " selected"; echo">" . KEYSTATE_USED . "</option>";
|
||||
echo " </select>";
|
||||
echo " </div>\n";
|
||||
|
||||
|
|
302
libs/dbLib.php
Normal file
302
libs/dbLib.php
Normal file
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : dbLib.php
|
||||
// Author : Lucas Woltmann
|
||||
// Version : 1.0
|
||||
// Date : 01-2017
|
||||
// Description : Provides functions for managing the answers of the evaluation
|
||||
// for students and tutors.
|
||||
//============================================================================
|
||||
|
||||
define ("LOGDB", "db/eseeva.db");
|
||||
|
||||
/**
|
||||
* Reads the database with the specified name and writes all log data to the corresponding arrays.
|
||||
* Returns true if the log file has been successfully read, otherwise false.
|
||||
* Is guaranteed to initialize the specified log arrays, even when the database file could not be
|
||||
* read in which case they will simply be empty.
|
||||
*
|
||||
* @param string $fileName The database from which to read.
|
||||
* @param int $student Whether the user is a student(1) or a tutor(0).
|
||||
* @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.
|
||||
* @return boolean
|
||||
*/
|
||||
function ReadLogDatabase($fileName, $student, &$questionData, &$tutorData, &$commentData)
|
||||
{
|
||||
// init arrays regardless of the file not being found or eventual errors
|
||||
$questionData = array();
|
||||
$tutorData = array();
|
||||
$commentData = array();
|
||||
|
||||
$questions = array();
|
||||
$tutors = array();
|
||||
$comments = array();
|
||||
// return if the file does not exist
|
||||
if (file_exists($fileName) == false)
|
||||
return false;
|
||||
// open the db
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READONLY);
|
||||
if (!$handle)
|
||||
return false;
|
||||
|
||||
$stmt = $handle->prepare("SELECT Answer FROM answers WHERE student=:student;");
|
||||
if ($stmt)
|
||||
{
|
||||
$stmt->bindValue(':student', $student, SQLITE3_INTEGER);
|
||||
|
||||
$result = $stmt->execute();
|
||||
//read to ararys, commentData does not need any further attention
|
||||
PrepareAnswer($result, $questions, $tutors, $commentData);
|
||||
}
|
||||
else
|
||||
{
|
||||
$handle->close();
|
||||
return false;
|
||||
}
|
||||
|
||||
$handle->close();
|
||||
|
||||
//convert data into legacy data structure
|
||||
ReadLogQuestionData($questions, $questionData);
|
||||
ReadLogTutorData($tutors, $tutorData);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Writes the specified log arrays to a database with the specified name.
|
||||
* Expects data in the same format as in the legacy version, but combines them to a single array
|
||||
* which is going to be saved in the database.
|
||||
* Returns true if the file was written successfully, otherwise false.
|
||||
*
|
||||
* @param string $fileName The name of the database to which the log data should be written.
|
||||
* @param int $student Whether the user is a student(1) or a tutor(0).
|
||||
* @param array $questionData The question data that should be written to the log file. Passed by reference.
|
||||
* @param array $tutorData The tutor data that should be written to the log file. Passed by reference.
|
||||
* @param array $commentData The list of comments that should be written to the log file. Passed by reference.
|
||||
* @param string $key The key the user used.
|
||||
* @return boolean
|
||||
*/
|
||||
function WriteLogDatabase($fileName, $student, &$questionData, &$tutorData, &$commentData, $key)
|
||||
{
|
||||
$answer = array($questionData, $tutorData, $commentData);
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READWRITE);
|
||||
if (!$handle)
|
||||
return false;
|
||||
|
||||
$stmt = $handle->prepare("UPDATE answers SET Status='activated', Student=:student, Answer=:answer WHERE KeyId=:keyid;");
|
||||
if ($stmt)
|
||||
{
|
||||
$stmt->bindValue(':student', $student, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':answer', serialize($answer), SQLITE3_BLOB);
|
||||
$stmt->bindValue(':keyid', $key, SQLITE3_TEXT);
|
||||
|
||||
$result = $stmt->execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
$handle->close();
|
||||
return false;
|
||||
}
|
||||
|
||||
$handle->close();
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Legacy data management for the question data.
|
||||
* Generates an array of arrays with all the questions.
|
||||
* The first index of each subarray is the full title and the remaining indices are the votes (answers).
|
||||
*
|
||||
* @param array $formData $_POST reference. Passed by reference.
|
||||
* @param array $questionData The array data that should be written to. Passed by reference.
|
||||
* @param array $questionnaire The general structure (questions) of the questionnaire. 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 the 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]++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Legacy data management for the tutor data.
|
||||
* Generates an array of arrays with the tutor.
|
||||
* The first index of each subarray is the full name and the remaining indices are the votes (answers).
|
||||
*
|
||||
* @param array $formData $_POST reference. Passed by reference.
|
||||
* @param array $tutorData The array data that should be written to. 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]++;
|
||||
}
|
||||
/**
|
||||
* Legacy data management for the comment data.
|
||||
* Checks if a comment was left and writes it into the passed reference.
|
||||
*
|
||||
* @param array $formData $_POST reference. Passed by reference.
|
||||
* @param string $commentData The array data that should be written to. Passed by reference.
|
||||
*/
|
||||
function AddCommentData(&$formData, &$commentData)
|
||||
{
|
||||
// if the comment field was filled, the comment
|
||||
// array is appended by the new comment
|
||||
if (trim($formData["comment"]) != "")
|
||||
{
|
||||
$commentData = $formData["comment"];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads all question data out of a provided log file array from the database.
|
||||
* This function should NOT BE CALLED directly, instead the ReadLogDatabase 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 $questions An array from the database. Passed by reference.
|
||||
* @param array $questionData An array to which all question data is written to. Passed by reference.
|
||||
* @return boolean.
|
||||
*/
|
||||
function ReadLogQuestionData(&$questions, &$questionData)
|
||||
{
|
||||
foreach ((array)$questions as $user) {
|
||||
foreach ($user as $id => $values) {
|
||||
if (isset($questionData[$id]))
|
||||
{
|
||||
$questionData[$id] = SumArrays($values, $questionData[$id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$questionData[$id] = $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Reads all tutor data out of a provided log file array from the database.
|
||||
* This function should NOT BE CALLED directly, instead the ReadLogDatabase 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 tutor data block was found, otherwise false.
|
||||
*
|
||||
* @param array $tutors An array from the database. Passed by reference.
|
||||
* @param array $tutorData An array to which all question data is written to. Passed by reference.
|
||||
* @return boolean.
|
||||
*/
|
||||
function ReadLogTutorData(&$tutors, &$tutorData)
|
||||
{
|
||||
foreach ((array)$tutors as $user) {
|
||||
foreach ($user as $id => $values) {
|
||||
if (isset($tutorData[$id]))
|
||||
{
|
||||
$tutorData[$id] = SumArrays($values, $tutorData[$id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tutorData[$id] = $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Reads all comment data out of a provided log file array from the database.
|
||||
* This function should NOT BE CALLED directly, instead the ReadLogDatabase 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 comment data block was found, otherwise false.
|
||||
*
|
||||
* @param array $comments An array from the database. Passed by reference.
|
||||
* @param array $commentData An array to which all question data is written to. Passed by reference.
|
||||
* @return boolean.
|
||||
*/
|
||||
function ReadLogCommentData(&$comments, &$commentData)
|
||||
{
|
||||
foreach ((array)$comments as $user) {
|
||||
foreach ($user as $id => $values) {
|
||||
if (isset($commentData[$id]))
|
||||
{
|
||||
$commentData[$id] = SumArrays($values, $commentData[$id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$commentData[$id] = $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Splits the three arrays from the 'Answer' column in the database into the legacy ararys.
|
||||
*
|
||||
* @param array $resultSet An array from the database. Passed by reference.
|
||||
* @param array $questionsa An array to which all question data is written to. Passed by reference.
|
||||
* @param array $tutors An array to which all tutor data is written to. Passed by reference.
|
||||
* @param array $comments An array to which all comments data is written to. Passed by reference.
|
||||
*/
|
||||
function PrepareAnswer(&$resultSet, &$questions, &$tutors, &$comments)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
while($res = $resultSet->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
$res = unserialize($res["Answer"]);
|
||||
$questions[$i] = $res[0];
|
||||
$tutors[$i] = $res[1];
|
||||
$comments[$i] = $res[2];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Little helper function for adding up single user answers to a global statistic.
|
||||
* Could be compared with a group by.
|
||||
*
|
||||
* @param array $array1 First array to merge/sum.
|
||||
* @param array $array2 Second array to merge/sum.
|
||||
* @return array Summed array by index.
|
||||
*/
|
||||
function SumArrays(&$array1, &$array2)
|
||||
{
|
||||
$result = array();
|
||||
//the name
|
||||
$result[0] = $array2[0];
|
||||
$count = count($array2);
|
||||
|
||||
//start one index into counting, because index 0 is the name
|
||||
for ($i=1; $i < $count; $i++) {
|
||||
$result[$i] = $array1[$i] + $array2[$i];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
?>
|
233
libs/keyLib.php
233
libs/keyLib.php
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : keyLib.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Author : Patrick Reipschläger, Lucas Woltmann
|
||||
// Version : 2.0
|
||||
// Date : 01-2017
|
||||
// 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");
|
||||
define ("KEYFILE", "db/eseeva.db");
|
||||
// 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");
|
||||
|
@ -48,133 +48,176 @@
|
|||
return array_unique($keys);
|
||||
}
|
||||
/**
|
||||
* Generates a new key file with the specified name that contains the specified
|
||||
* amount of newly generated keys.
|
||||
* Generates a new keys in the database.
|
||||
* 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.
|
||||
* @param string $fileName The name of the key database that should be created.
|
||||
*/
|
||||
function CreateKeyFile($keyAmount, $fileName)
|
||||
function CreateKeys($keyAmount, $fileName)
|
||||
{
|
||||
$handle = fopen($fileName, 'w');
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READWRITE);
|
||||
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);
|
||||
fclose($handle);
|
||||
$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, 'c');
|
||||
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];
|
||||
$count = count($keys);
|
||||
|
||||
//use exclusive lock for writing
|
||||
flock($handle, LOCK_EX);
|
||||
ftruncate($handle, 0);
|
||||
$res = fwrite($handle, $data);
|
||||
fflush($handle);
|
||||
flock($handle, LOCK_UN);
|
||||
// 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);
|
||||
if ($res)
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
return true;
|
||||
$stmt = $handle->prepare("INSERT INTO answers (KeyId, Status) VALUES (:key,:status);");
|
||||
if ($stmt)
|
||||
{
|
||||
$stmt->bindValue(':key', $keys[$i], SQLITE3_TEXT);
|
||||
$stmt->bindValue(':status', KEYSTATE_UNISSUED, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
$handle->close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$handle->close();
|
||||
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.
|
||||
* Opens the database with the specified name and reads all key data that the database 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 array $keyData The key data array in which the key should be found. Passed by reference.
|
||||
* @param string $fileName The database which should be read.
|
||||
* @return array
|
||||
*/
|
||||
function ReadKeys($fileName)
|
||||
{
|
||||
if (!file_exists($fileName))
|
||||
return null;
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READONLY);
|
||||
if (!$handle)
|
||||
return null;
|
||||
$data = $handle->query("SELECT KeyId, Status FROM answers;");
|
||||
$data = PrepareResult($data);
|
||||
$handle->close();
|
||||
|
||||
if ($data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* Get the current state of the specified key from the database, which will be one of the defines
|
||||
* KEYSTATE constants.
|
||||
*
|
||||
* @param array $fileName The database with the keys.
|
||||
* @param string $key The key which state should be got. Passed by reference.
|
||||
* @return integer
|
||||
*/
|
||||
function GetKeyState(&$keyData, &$key)
|
||||
function GetKeyState($fileName, &$key)
|
||||
{
|
||||
for ($i = 0; $i < count($keyData); $i++)
|
||||
if ($key == $keyData[$i][0])
|
||||
return $keyData[$i][1];
|
||||
if (!file_exists($fileName))
|
||||
return null;
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READONLY);
|
||||
if (!$handle)
|
||||
return null;
|
||||
|
||||
$stmt = $handle->prepare("SELECT Status FROM answers WHERE KeyId=:keyid;");
|
||||
if ($stmt)
|
||||
{
|
||||
$stmt->bindValue(':keyid', $key, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$result = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$handle->close();
|
||||
return $result["Status"];
|
||||
}
|
||||
|
||||
$handle->close();
|
||||
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 array $fileName The database in which the key should be found.
|
||||
* @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)
|
||||
function SetKeyState($fileName, &$key, $newState)
|
||||
{
|
||||
for ($i = 0; $i < count($keyData); $i++)
|
||||
if ($key == $keyData[$i][0])
|
||||
if (!file_exists($fileName))
|
||||
return false;
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READWRITE);
|
||||
if (!$handle)
|
||||
return false;
|
||||
|
||||
//secure override by checking if key has been uesed already
|
||||
$stmt = $handle->prepare("UPDATE answers SET Status=:status WHERE KeyId=:keyid AND Status!=:status;");
|
||||
if ($stmt)
|
||||
{
|
||||
$keyData[$i][1] = $newState;
|
||||
$stmt->bindValue(':keyid', $key, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':status', $newState, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$handle->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
$handle->close();
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Deletes a single key in the database if it has not been used yet.
|
||||
* Returns true if the key was deleted, otherwise false.
|
||||
*
|
||||
* @param array $fileName The database in which the key should be found.
|
||||
* @param string $key The key which should be deleted.
|
||||
* @return boolean
|
||||
*/
|
||||
function DeleteKey($fileName, &$key)
|
||||
{
|
||||
if (!file_exists($fileName))
|
||||
return false;
|
||||
$handle = new SQLite3($fileName, SQLITE3_OPEN_READWRITE);
|
||||
if (!$handle)
|
||||
return false;
|
||||
|
||||
//secure deleting by checking if key has been uesed already
|
||||
$stmt = $handle->prepare("DELETE FROM answers WHERE KeyId=:keyid AND Answer!=NULL;");
|
||||
if ($stmt)
|
||||
{
|
||||
$stmt->bindValue(':keyid', $key, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$handle->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
$handle->close();
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Prepares the results from the database to an array of keys with their state.
|
||||
*
|
||||
* @param array $resultSet Cursor from the sqlite database. Passed by reference.
|
||||
* @return array
|
||||
*/
|
||||
function PrepareResult(&$resultSet)
|
||||
{
|
||||
$result = array();
|
||||
$i = 0;
|
||||
|
||||
while($res = $resultSet->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
foreach ($res as $key => $value) {
|
||||
$result[$i][$key] = $value;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,310 +0,0 @@
|
|||
<?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/ESE_studentLog.txt");
|
||||
define ("TUTORLOGFILE", "logs/ESE_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);
|
||||
fclose($handle);
|
||||
// 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, 'c');
|
||||
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
|
||||
// use exclusive lock
|
||||
flock($handle, LOCK_EX);
|
||||
ftruncate($handle, 0);
|
||||
fwrite($handle, $fileData);
|
||||
fflush($handle);
|
||||
flock($handle, LOCK_UN);
|
||||
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 the 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"]);
|
||||
}
|
||||
?>
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : student_questionnaire.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Author : Patrick Reipschläger, Lucas Woltmann
|
||||
// Version : 2.0
|
||||
// Date : 01-2017
|
||||
// Description : The form that students have to fill in
|
||||
// for the ESE evaluation.
|
||||
//============================================================================
|
||||
|
@ -11,7 +11,7 @@
|
|||
include_once 'libs/formLib.php';
|
||||
include_once 'libs/questionnaireLib.php';
|
||||
include_once 'libs/keyLib.php';
|
||||
include_once 'libs/loggingLib.php';
|
||||
include_once 'libs/dbLib.php';
|
||||
|
||||
// indicates if an error occurred and what error
|
||||
$error = 0;
|
||||
|
@ -23,34 +23,29 @@
|
|||
// if the variable is set, the form has been posted to itself and can be validated
|
||||
if (isset($_POST["submit"]))
|
||||
{
|
||||
// read the key
|
||||
$keyData = ReadKeyFile(KEYFILE);
|
||||
$keyState = GetKeyState($keyData, $_POST["code"]);
|
||||
// read the key state
|
||||
$keyState = GetKeyState(KEYFILE, $_POST["code"]);
|
||||
if ($keyState == KEYSTATE_ISSUED)
|
||||
{
|
||||
// variables for the log data
|
||||
$questionData;
|
||||
$tutorData;
|
||||
$questionData = array();
|
||||
$tutorData = array();
|
||||
$commentData;
|
||||
// read the existing log file, if there is no existing log file, the RadLogFile
|
||||
// function guarantees the initialization of the log variables, which will
|
||||
// result in the same outcome as if an empty log file is read
|
||||
ReadLogFile(STUDENTLOGFILE, $questionData, $tutorData, $commentData);
|
||||
|
||||
// add the data of the form to the existing log data
|
||||
// add the data of the form to the legacy data structure
|
||||
AddQuestionData($_POST, $questionData, $questionnaire);
|
||||
AddTutorData($_POST, $tutorData);
|
||||
AddCommentData($_POST, $commentData);
|
||||
|
||||
// quick ~~fix~~ hack
|
||||
mail("eseeva@ifsr.de", "ESEEVA2016POST", serialize($_POST));
|
||||
// mail("eseeva@ifsr.de", "ESEEVA2016POST", serialize($_POST));
|
||||
|
||||
// write the altered data back to the log file, only change the state of the key,
|
||||
// write the new data back to the database, only change the state of the key,
|
||||
// if that action was successful
|
||||
if (WriteLogFile(STUDENTLOGFILE, $questionData, $tutorData, $commentData))
|
||||
// Uses $student=1 to imply that a student answered the questionnaire.
|
||||
if (WriteLogDatabase(LOGDB, 1, $questionData, $tutorData, $commentData, $_POST["code"]))
|
||||
{
|
||||
SetKeyState($keyData, $_POST["code"], KEYSTATE_ACTIVATED);
|
||||
if (!WriteKeyFile(KEYFILE, $keyData))
|
||||
if (!SetKeyState(KEYFILE, $_POST["code"], KEYSTATE_ACTIVATED))
|
||||
{
|
||||
$error = 1;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
//============================================================================
|
||||
// Name : tutor_questionnaire.php
|
||||
// Author : Patrick Reipschläger
|
||||
// Version : 1.0
|
||||
// Date : 08-2013
|
||||
// Author : Patrick Reipschläger, Lucas Woltmann
|
||||
// Version : 2.0
|
||||
// Date : 01-2017
|
||||
// Description : The form that tutors have to fill in
|
||||
// for the ESE evaluation.
|
||||
//============================================================================
|
||||
|
@ -11,7 +11,7 @@
|
|||
include_once 'libs/formLib.php';
|
||||
include_once 'libs/questionnaireLib.php';
|
||||
include_once 'libs/keyLib.php';
|
||||
include_once 'libs/loggingLib.php';
|
||||
include_once 'libs/dbLib.php';
|
||||
|
||||
// indicates if an error occurred and what error
|
||||
$error = 0;
|
||||
|
@ -22,30 +22,28 @@
|
|||
// if the variable is set, the form has been posted to itself and can be validated
|
||||
if (isset($_POST["submit"]))
|
||||
{
|
||||
// read the key
|
||||
$keyData = ReadKeyFile(KEYFILE);
|
||||
$keyState = GetKeyState($keyData, $_POST["code"]);
|
||||
// read the key state
|
||||
$keyState = GetKeyState(KEYFILE, $_POST["code"]);
|
||||
if ($keyState == KEYSTATE_ISSUED)
|
||||
{
|
||||
// variables for the log data, tutor data is not needed but must be present
|
||||
$questionData;
|
||||
$tutorData;
|
||||
$questionData = array();
|
||||
$tutorData = array();
|
||||
$commentData;
|
||||
// read the existing log file, if there is no existing log file, the RadLogFile
|
||||
// function guarantees the initialization of the log variables, which will
|
||||
// result in the same outcome as if an empty log file is read
|
||||
ReadLogFile(TUTORLOGFILE, $questionData, $tutorData, $commentData);
|
||||
|
||||
// add the data of the form to the existing log data
|
||||
// add the data of the form to the legacy data structure
|
||||
AddQuestionData($_POST, $questionData, $questionnaire);
|
||||
AddCommentData($_POST, $commentData);
|
||||
|
||||
// write the altered data back to the log file, only change the state of the key,
|
||||
// write the new data back to the database, only change the state of the key,
|
||||
// if that action was successful
|
||||
if (WriteLogFile(TUTORLOGFILE, $questionData, $tutorData, $commentData))
|
||||
// Uses $student=0 to imply that a tutor answered the questionnaire.
|
||||
if (WriteLogDatabase(LOGDB, 0, $questionData, $tutorData, $commentData, $_POST["code"]))
|
||||
{
|
||||
SetKeyState($keyData, $_POST["code"], KEYSTATE_ACTIVATED);
|
||||
WriteKeyFile(KEYFILE, $keyData);
|
||||
if (!SetKeyState(KEYFILE, $_POST["code"], KEYSTATE_ACTIVATED))
|
||||
{
|
||||
$error = 1;
|
||||
}
|
||||
}
|
||||
// otherwise set the error flag
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue