Example #1
0
 public function testfieldsInDbVsMyArray()
 {
     $log_file = fopen("/var/www/jimfuqua/tutor/logs/CT testfieldsInDbVsMyArray", "w");
     // get a list of fields in the db
     $this->testbuildArray();
     // reset myArray to origninal values.
     $classInstance = new tutor\src\CompletedClass();
     $result = $classInstance->insertRecord($this->myArray);
     $results = $classInstance->getLastDbEntry();
     $this->assertTrue(count($results) === count($this->myArray));
     //  Put all of the column names from the returned row in an array.
     $dbKeys = [];
     $i = 0;
     foreach ($results as $key => $value) {
         $dbKeys[$i] = $key;
         $i++;
     }
     $v = var_export($dbKeys, true);
     $string = "\n" . __LINE__ . ' $dbKeys = ' . $v . "\n";
     fwrite($log_file, $string);
     $i = 0;
     foreach ($this->myArray as $key => $value) {
         $myArrayKeys[$i] = $key;
         $i++;
     }
     $v = var_export($myArrayKeys, true);
     $string = "\n" . __LINE__ . ' $myArrayKeys = ' . $v . "\n";
     fwrite($log_file, $string);
     $num_columns = $i;
     $i = 0;
     //  Compare the two arrays key by key.
     for ($i < $num_columns; $i++;) {
         $this->assertTrue($dbKeys[$i] === $myArrayKeys[$i], "{$i}.' '.{$dbKeys[$i]} === {$myArrayKeys[$i]}");
     }
 }
Example #2
0
$tC_Param_array['tC_tAStartRec'] = $_POST['tA_StartRec'];
$tC_Param_array['tC_tAStopRec'] = $_POST['tA_StopRec'];
$tC_Param_array['tC_CompletedTimestamp'] = 'NOW( )';
$tC_Param_array['tC_ServerTimeStarted'] = $_POST['tC_ServerTimeStarted'];
$tC_Param_array['tC_ClientTimeStarted'] = $_POST['tC_ClientTimeStarted'];
$tC_Param_array['tC_Time_client_processed_answer'] = $_POST['tC_Time_client_processed_answer'];
$tC_Param_array['tC_Correct'] = $_POST['tC_Correct'];
$tC_Param_array['tC_Question_and_Response'] = $_POST['tC_Question_and_Response'];
$tC_Param_array['tC_More_data_about_response'] = $_POST['tC_More_data_about_response'];
$v = var_export($tC_Param_array, TRUE);
$string = __LINE__ . ' $tC_Param_array = ' . $v . "\n\n";
fwrite($log_file, $string);
// Sender is not a field in tA and should not be in the query.
// Sender is a good source of info to detect tampering with input data.;
// $sender = $_POST['sender'];
$classInstance = new tutor\src\CompletedClass();
// To tCompleted using the class method.
// returns count of rows affected.
$returnedValue = $classInstance->recordData($tC_Param_array);
$string = __LINE__ . ' $returnedValue = ' . $returnedValue . "\n\n";
fwrite($log_file, $string);
$string = __LINE__ . ' gettype($returnedValue) = ' . gettype($returnedValue) . "\n\n";
fwrite($log_file, $string);
if ($returnedValue !== 1) {
    $string = "\n" . __LINE__ . " Serious Error. update_tA_TC.php failed to record data in tCompleted." . "\n";
    // Serious Error.
    fwrite($log_file, $string);
}
// NOW ALTER tAssignments.
unset($where_array);
$where_array = array('tA_S_ID' => $_POST['tA_S_ID'], 'tA_id' => $_POST['tA_id']);
Example #3
0
    // Trigger fatal error.
    $msg = "Session must have a tG_AssignmentName ";
    $msg .= "to record data to database.";
    trigger_error($msg, E_USER_ERROR);
} else {
    $tC_gA = $_SESSION["tG_AssignmentName"];
}
if (!isset($_SESSION["tA_StartRec"])) {
    // Trigger fatal error.
    $msg = "Session must have a tA_StartRec to record data to database.";
    trigger_error($msg, E_USER_ERROR);
} else {
    $tA_StartRec = $_SESSION["tA_StartRec"];
}
if (!isset($_POST['tC_ClientTimeStarted'])) {
    // Trigger fatal error.
    $msg = "Session must have a tC_ClientTimeStarted to record data to database.";
    trigger_error($msg, E_USER_ERROR);
} else {
    $tC_ClientTimeStarted = $_POST['tC_ClientTimeStarted'];
}
if (!isset($_POST['tC_Correct'])) {
    // Trigger fatal error.
    trigger_error("Session must have a tC_Correct to record data to database.", E_USER_ERROR);
} else {
    $tC_Correct = $_POST['tC_Correct'];
}
$classInstance = new tutor\src\CompletedClass();
$incoming_data = array("tC_Session" => session_id(), "tC_ServerTimeStarted" => $_SESSION["tC_ServerTimeStarted"], "tA_StudentName" => $_SESSION['tA_StudentName'], "tA_S_ID" => $_SESSION['tA_S_ID'], "tC_gA" => $_SESSION['tG_AssignmentName'], "tC_tGStartRec" => $_SESSION['tA_StartRec'], "tC_ClientTimeStarted" => $_POST['tC_ClientTimeStarted'], "tC_Time_client_processed_answer" => $_POST["tC_Time_client_processed_answer"], "tC_Correct" => $_POST['tC_Correct'], "tC_Question_and_Response" => $_POST["tC_Question_and_Response"], "tC_More_data_about_response" => $_POST["tC_More_data_about_response"]);
$y = $classInstance->recordData($incoming_data);
// to tCompleted using the class method.