Example #1
0
 public function downloader()
 {
     $query = "SELECT * FROM app_table";
     if ($stmt = mysqli_prepare(Db_Connection::getInstance()->getConnection(), $query)) {
         $stmt->execute();
         /* bind variables to prepared statement */
         //$stmt->bind_result($id, $name, $url, $html);
         /* fetch values */
         $result = $stmt->get_result();
         $resultArray = $result->fetch_all(MYSQLI_ASSOC);
         foreach ($resultArray as $entry) {
             if ($entry["html"] == '') {
                 $html = $this->downloadHtml($entry["url"]);
                 $html = preg_replace('[\\r\\n]', '', $html);
                 $html = mysqli_real_escape_string(Db_Connection::getInstance()->getConnection(), $html);
                 $id = $entry["id"];
                 $query2 = "UPDATE app_table SET html ='" . $html . "' WHERE id ='" . $id . "'";
                 $stmt2 = mysqli_prepare(Db_Connection::getInstance()->getConnection(), $query2);
                 if (!$stmt2) {
                     die('mysqli error: ' . mysqli_error(Db_Connection::getInstance()->getConnection()));
                 }
                 $stmt2->execute();
             }
             // Db_Connection::getInstance()->executeQuery($stmt2);
             // $files = $this->getFiles($html);
             // echo $url."<br>";
             // print_r($files);
             // $query3 = "INSERT INTO files (appId, filename, path) VALUES (?, ?, ?)";
             // $stmt3 = mysqli_prepare(Db_Connection::getInstance()->getConnection(), $query3);
             // mysqli_stmt_bind_param($stmt3, "sss", $id, $files[1], $files[2]);
             // Db_Connection::getInstance()->executeQuery($stmt3);
         }
     }
 }
 } else {
     if (isset($_GET['question_id'])) {
         $question_ID = $_GET['question_id'];
         $db_con = new Db_Connection();
         $question_data = $db_con->selectEntries(false, 'dynmc_questions', array("where" => "question_ID = " . $question_ID))[0];
         $incorrect_answers = $db_con->selectEntries(true, 'dynmc_incorrect', array("where" => "incorrect_question_ID = " . $question_ID));
         foreach ($incorrect_answers as $incorrect) {
             $question_data['incorrect_answers'][] = $incorrect['incorrect_text'];
         }
         //foreach
         $question_data["db_error"] = $db_con->getErrorMessage();
         print json_encode($question_data);
     } else {
         if (isset($_POST['delete_test'])) {
             $test_id = $_POST['selected_test_id'];
             $db_con = new Db_Connection();
             //delete questions:
             $lookups = $db_con->selectEntries(false, 'dynmc_lookup', array("where" => "lookup_test_ID = " . $test_id));
             for ($i = 0; $i < sizeof($lookups); $i++) {
                 deleteQuestion($lookups[$i]['lookup_question_ID'], $test_id);
             }
             //for
             $db_con->deleteEntries(true, 'tests', array("where" => "test_ID = " . $test_id));
             if ($db_con->getErrorMessage() !== '') {
                 $error = true;
                 $error_msg = 'The following error has occurred while deleting the test: ' . $db_con->getErrorMessage();
             } else {
                 $deleted_successfully = true;
             }
             //else
             include INCLUDE_PATH . 'index.php';
     $db_con = new Db_Connection();
     $db_con->deleteEntries(false, 'tests', array("where" => "test_ID = " . $test_id));
     $db_con->deleteEntries(false, 'dragdrop_items', array("where" => "item_test_ID = " . $test_id));
     $db_con->deleteEntries(true, 'dragdrop_containers', array("where" => "container_test_ID = " . $test_id));
     if ($db_con->getErrorMessage() !== '') {
         $error = true;
         $error_msg = 'The following error has occurred while deleting the test: ' . $db_con->getErrorMessage();
     } else {
         $deleted_successfully = true;
     }
     //else
     include INCLUDE_PATH . 'index.php';
 } else {
     if (isset($_GET['check_test'])) {
         $temp_solution = $_GET['check_test'];
         $db_con = new Db_Connection();
         $test_items = $db_con->selectEntries(false, 'dragdrop_items', array("where" => "item_test_ID = " . $_GET['check_test_id']));
         $checked_items = array("correct" => 0);
         foreach ($test_items as $item) {
             if (isset($temp_solution[$item['item_ID']]) && $item['item_container_ID'] == $temp_solution[$item['item_ID']]) {
                 $checked_items[$item['item_ID']] = 1;
                 $checked_items["correct"]++;
             } else {
                 $checked_items[$item['item_ID']] = 0;
             }
         }
         //foreach
         print json_encode($checked_items);
     } else {
         dieIncorrectAccess();
     }
$title = 'Drag &amp; Drop';
$header_text = 'View Drag &amp; Drop Test';
$section = 'dragdrop';
$action = 'view';
require_once $_SERVER['DOCUMENT_ROOT'] . '/e_tests/php_support/config.php';
if (isset($_GET['test_id'])) {
    $test_id = $_GET['test_id'];
} else {
    if (isset($_POST['selected_test_id'])) {
        $test_id = $_POST['selected_test_id'];
    } else {
        dieIncorrectAccess();
    }
}
//else
$db_con = new Db_Connection();
$test_data = $db_con->selectEntries(false, 'tests', array("where" => "test_ID = " . $test_id))[0];
$test_level = $db_con->selectEntries(true, 'test_levels', array("where" => "level_ID = " . $test_data['test_level_ID']))[0];
require_once INCLUDE_PATH . 'php_page_elements/page_header.php';
if (isset($_GET['test_id'])) {
    ?>
		<div class="notification">
			<header>
				Test Saved Successfully!
				<div class="delete_notification_button font-color-4">X</div>
			</header>
			<section>
				Your test has been saved to the database. You see it displayed below.
			</section>
		</div>
<?php 
Example #5
0
*************************************************************************************************************************/
//Page Variables:
$title = 'Dynamic Multiple-Choice';
$header_text = 'Edit Dynamic Multiple-Choice Test';
$section = 'dynmc';
$action = 'edit';
require_once $_SERVER['DOCUMENT_ROOT'] . '/e_tests/php_support/config.php';
if (isset($_POST['selected_test_id'])) {
    $test_id = $_POST['selected_test_id'];
} else {
    dieIncorrectAccess();
}
//else
$db_con = new Db_Connection();
$test_data = $db_con->selectEntries(true, 'tests', array("where" => "test_ID = " . $test_id))[0];
$db_con = new Db_Connection();
$questions = $db_con->selectEntries(true, 'dynmc_questions', array("order" => "question_text"));
require_once INCLUDE_PATH . 'php_page_elements/page_header.php';
require_once INCLUDE_PATH . 'php_page_elements/general_testinfo_form.php';
?>
	</form>
	<header id="test_container_header">
		"<span id="test_name_container"><?php 
echo $test_data['test_name'];
?>
</span>"
	</header>
	<section id="test_container">
		<div class="instructions">
			If you want to change questions, just click on the text that you want to edit. 
			You can delete questions and incorrect answers by clicking on the 'X' signs that appear when you hover over them.
Example #6
0
<?php

/*************************************************************************************************************************
START PAGE OF APPLICATION
- presents user with possibilities to start creating / editing tests
*************************************************************************************************************************/
//Page Variables:
$title = 'Home';
$header_text = 'E-Test Editor';
$section = 'index';
$action = 'index';
require_once $_SERVER['DOCUMENT_ROOT'] . '/e_tests/php_support/config.php';
$db_con = new Db_Connection();
$test_types = $db_con->selectEntries(false, 'test_types', array("order" => "type_label"));
$tests = $db_con->selectEntries(true, 'tests, test_types', array("where" => "tests.test_type_ID = test_types.type_ID", "order" => "tests.test_name"));
require_once INCLUDE_PATH . 'php_page_elements/page_header.php';
?>

<form name="select_test_form" id="select_test_form" action="<?php 
echo ROOT_PATH;
?>
php_support/manage_tests.php" method="post">
<?php 
if (isset($error) && $error) {
    ?>
	<div class="notification">
		<header>
			Error
			<div class="delete_notification_button font-color-4">X</div>
		</header>
		<section>
     $db_con = new Db_Connection();
     $db_con->deleteEntries(false, 'tests', array("where" => "test_ID = " . $test_id));
     $db_con->deleteEntries(false, 'crossword_questions', array("where" => "question_test_ID = " . $test_id));
     $db_con->deleteEntries(true, 'crossword_grid', array("where" => "grid_test_ID = " . $test_id));
     if ($db_con->getErrorMessage() !== '') {
         $error = true;
         $error_msg = 'The following error has occurred while deleting the test: ' . $db_con->getErrorMessage();
     } else {
         $deleted_successfully = true;
     }
     //else
     include INCLUDE_PATH . 'index.php';
 } else {
     if (isset($_GET['check_test'])) {
         $temp_solution = $_GET['check_test'];
         $db_con = new Db_Connection();
         $questions = $db_con->selectEntries(false, 'crossword_questions', array("where" => "question_test_ID = " . $_GET['check_test_id']));
         $checked_items = array("correct" => 0, "wrong_fields" => array());
         foreach ($questions as $question) {
             $error = false;
             $current_x = $question['question_position_x'];
             $current_y = $question['question_position_y'];
             for ($i = 0; $i < strlen($question['question_correct_answer']); $i++) {
                 if (substr($question['question_correct_answer'], $i, 1) != $temp_solution[$current_y][$current_x]) {
                     $error = true;
                     $checked_items["wrong_fields"][] = $current_y . '_' . $current_x;
                 }
                 //if
                 $question['question_orientation'] == "0" ? $current_x++ : $current_y++;
             }
             //for
<?php

/*************************************************************************************************************************
GENERAL TEST INFO FORM
- provides the general information form fields necessary for all types of tests (info that will go to 'tests' tabel in DB)
*************************************************************************************************************************/
$db_con = new Db_Connection();
$test_levels = $db_con->selectEntries(true, 'test_levels', array("order" => "level_number"));
if (!isset($test_data)) {
    $test_data['test_name'] = '';
    $test_data['test_level_ID'] = '';
}
//if
?>
	<header>
		General Information
	</header>
	<section>
		<form name="general_info_form" id="general_info_form">
		<div class="css_table">
			<div class="css_tr">
				<div class="css_td">
					Test Name : 
				</div>
				<div class="css_td">
					<input type="text" name="test_name" id="test_name" size="50"<?php 
printAttr('value', $test_data['test_name']);
?>
>
				</div>
			</div>
Example #9
0
         //else
         die;
     } else {
         if (isset($_POST['run_test'])) {
             if (isset($_POST['selected_type']) && isset($_POST['selected_test_id'])) {
                 include INCLUDE_PATH . 'php_' . $_POST['selected_type'] . '/' . $_POST['selected_type'] . '_runtest.php';
             } else {
                 $error = true;
                 $error_msg = 'Please select the test you want to run!';
                 include INCLUDE_PATH . 'index.php';
             }
             //else
             die;
         } else {
             if (isset($_GET['get_test_names'])) {
                 $db_con = new Db_Connection();
                 $test_types = array('dynmc' => 1, 'dragdrop' => 2, 'crossword' => 3);
                 //get all names of tests of same type and different ID (so that no two tests of same type with same name will exist)
                 $tests = $db_con->selectEntries(true, 'tests', array("select" => "test_name", "where" => "test_ID <> " . $_GET['test_ID'], "and" => "test_type_ID = " . $test_types[$_GET['test_type']]));
                 foreach ($tests as $test) {
                     $test_names[] = html_entity_decode($test['test_name'], ENT_NOQUOTES | ENT_HTML5, "UTF-8");
                     //decode HTML entities (for making comparison to input in JS possible)
                 }
                 //foreach
                 print json_encode($test_names);
             } else {
                 dieIncorrectAccess();
             }
         }
     }
 }
EDITING A CROSSWORD TEST
- presents user with form for modification of an existing crossword test
*************************************************************************************************************************/
//Page Variables:
$title = 'Crossword';
$header_text = 'Edit Crossword Test';
$section = 'crossword';
$action = 'edit';
require_once $_SERVER['DOCUMENT_ROOT'] . '/e_tests/php_support/config.php';
if (isset($_POST['selected_test_id'])) {
    $test_id = $_POST['selected_test_id'];
} else {
    dieIncorrectAccess();
}
//else
$db_con = new Db_Connection();
$test_data = $db_con->selectEntries(true, 'tests', array("where" => "test_ID = " . $test_id))[0];
require_once INCLUDE_PATH . 'php_page_elements/page_header.php';
require_once INCLUDE_PATH . 'php_page_elements/general_testinfo_form.php';
?>
	<header>
		"<span id="test_name_container"><?php 
echo $test_data['test_name'];
?>
</span>"
	</header>
	<section id="test_container">
		<div class="instructions">
			Click on questions and answers to edit them.<br> 
			When you have entered all questions and answers, press 'Create Crossword'. Then click 'Save Test' to store the changes in the database.
		</div>