<commit_before><?php
//**************************************************************************
// This file is part of the BlueberryPHP project.
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Programmer: <NAME> 
// Date: 16 June 2014
// Description: 
// 
//**************************************************************************
?>

<?php
session_start();

require('/var/www/html/public/assets/php/password_compat/lib/password.php');

function getDB() {
	try {
		return new PDO("mysql:host=localhost;dbname=workorder;charset=utf8", 'secureUser', 'BL3FFEE5WUsrJQnx');
	}
	catch (Exception $e) {
		session_unset();
		header('Location: index.php');
	}
}

function dontCache() {
	echo '<meta http-equiv="cache-control" content="no-cache">';
	echo '<meta http-equiv="expires" content="0">';
	echo '<meta http-equiv="pragma" content="no-cache">';
}

function redirectIfNotLoggedIn() {
	if (!isset($_SESSION['user'])) {	
		header('Location: ../');
	}
}

function timestampSession() {
	$_SESSION['lastActivity'] = time();
}

function ifError() {
	if (isset($_SESSION['error'])) {
		return true;
	} else {
		return false;
	}
}

function setErrorVar($str) {
	$_SESSION['error'] = $str;
}

function printSuccess($str) {
	echo "<p class='success'>$str</p>";
}

function printError($str) {
	echo "<p class='error'>$str</p>";
}

function getErrorVar() {
	$error = $_SESSION['error'];
	unset($_SESSION['error']);
	session_unset();
	return $error;
}

// Compares time with last activity; logs out if time expired
function checkLastActivity() {
	$seconds = 1800;	// 30 minutes
	if (isset($_SESSION['lastActivity'])) {	
		if (time() - $_SESSION['lastActivity'] > $seconds) {
			logout();
		}
	} else {
		timestampSession();
	}
	timestampSession();
}

function forbid() {
	$user = getUser();
	if (!isset($_SESSION['user'])) {	
		header('Location: ../forbidden');
	} else {
		if (!isAdmin() || $user = '') {
			header('Location: ../forbidden');
		}
	}

}

function openTicket() {
	header('Location: ../ticket');
}


// Echo a table representing a header for inline queries
function printFilterHeader() {

	echo '	<table>
		<tr>
			<th>Ticket Number</th>
			<th>Date Created</th>
			<th>Problem Description</th>
			<th>Requestor</th>
			<th>Problem Code</th>
			<th>Assigned To</th>
			<th>Date Closed</th>
			<th>Status</th>
		</tr>';

}

function printFilterFooter() {
	echo '</table>';
}

function printRecords($arr) {
	foreach($arr as $a) {
		echo '<td>' . $a . '</td>';
	}
}

// Put function on hold to implement
function appendEditRecordButton($index) {
//	echo '<td><input type="submit" name="btnEdit" value="Edit"></td>';
}

// Setup table displaying outstanding workorders; if regular user, display tickets created by that user; if admin,
// display all outstanding tickets
function generateDashboard() {
	if (isAdmin()) {
		$query = 'SELECT * FROM tickets';
		$result = getDB()->prepare($query);
		$result->bindParam(':requestor', $_SESSION['user']);
		$result->execute();	
	} else {
		$query = 'SELECT * FROM tickets WHERE requestor LIKE :requestor AND STATUS = :open';
		$status = 'OPEN';
		$result = getDB()->prepare($query);
		$result->bindParam(':requestor', $_SESSION['user']);
		$result->bindParam(':open', $status);
		$result->execute();	
	}


	printFilterHeader();
	$numRecords = 0;
	while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
		$records = array();
		echo '<tr>';
//		$ticketNumber = $row['ticketNumber'];
//		$dateCreated = $row['dateCreated'];
//		$problemDescription = $row['problemDescription'];
//		$requestor = $row['requestor'];
//		$problemCode = $row['problemCode'];
//		$assignedTo = $row['assignedTo'];
//		$dateClosed = $row['dateClosed'];
//		$status = $row['status'];
	
		array_push($records, $row['ticketNumber'], $row['dateCreated'], $row['problemDescription'], $row['requestor'], 
		$row['problemCode'], $row['assignedTo'], $row['dateClosed'], $row['status']);
	

		printRecords($records);
		appendEditRecordButton($numRecords);
		$numRecords++;
		echo '</tr>';
		
	}
	printFilterFooter();

}

function doFilter() {
//	$query = 'SELECT * FROM tickets WHERE ticketNumber LIKE :ticketNumber AND status LIKE :status';
	$query = 'SELECT * FROM tickets WHERE status LIKE :status';
	$result = getDB()->prepare($query);
//	$result->bindParam(':ticketNumber', $_POST['ticketNumber']);
	$result->bindParam(':status', $_POST['status']);
	$result->execute();	

	printFilterHeader();
	while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
		$records = array();<commit_msg>Added border for menu dashboard<commit_after><?php
//**************************************************************************
// This file is part of the BlueberryPHP project.
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Programmer: <NAME> 
// Date: 16 June 2014
// Description: 
// 
//**************************************************************************
?>

<?php
session_start();

require('/var/www/html/public/assets/php/password_compat/lib/password.php');

function getDB() {
	try {
		return new PDO("mysql:host=localhost;dbname=workorder;charset=utf8", 'secureUser', 'BL3FFEE5WUsrJQnx');
	}
	catch (Exception $e) {
		session_unset();
		header('Location: index.php');
	}
}

function dontCache() {
	echo '<meta http-equiv="cache-control" content="no-cache">';
	echo '<meta http-equiv="expires" content="0">';
	echo '<meta http-equiv="pragma" content="no-cache">';
}

function redirectIfNotLoggedIn() {
	if (!isset($_SESSION['user'])) {	
		header('Location: ../');
	}
}

function timestampSession() {
	$_SESSION['lastActivity'] = time();
}

function ifError() {
	if (isset($_SESSION['error'])) {
		return true;
	} else {
		return false;
	}
}

function setErrorVar($str) {
	$_SESSION['error'] = $str;
}

function printSuccess($str) {
	echo "<p class='success'>$str</p>";
}

function printError($str) {
	echo "<p class='error'>$str</p>";
}

function getErrorVar() {
	$error = $_SESSION['error'];
	unset($_SESSION['error']);
	session_unset();
	return $error;
}

// Compares time with last activity; logs out if time expired
function checkLastActivity() {
	$seconds = 1800;	// 30 minutes
	if (isset($_SESSION['lastActivity'])) {	
		if (time() - $_SESSION['lastActivity'] > $seconds) {
			logout();
		}
	} else {
		timestampSession();
	}
	timestampSession();
}

function forbid() {
	$user = getUser();
	if (!isset($_SESSION['user'])) {	
		header('Location: ../forbidden');
	} else {
		if (!isAdmin() || $user = '') {
			header('Location: ../forbidden');
		}
	}

}

function openTicket() {
	header('Location: ../ticket');
}


// Echo a table representing a header for inline queries
function printFilterHeader() {

	echo '	<table border=1>
		<tr>
			<th>Ticket Number</th>
			<th>Date Created</th>
			<th>Problem Description</th>
			<th>Requestor</th>
			<th>Problem Code</th>
			<th>Assigned To</th>
			<th>Date Closed</th>
			<th>Status</th>
		</tr>';

}

function printFilterFooter() {
	echo '</table>';
}

function printRecords($arr) {
	foreach($arr as $a) {
		echo '<td>' . $a . '</td>';
	}
}

// Put function on hold to implement
function appendEditRecordButton($index) {
//	echo '<td><input type="submit" name="btnEdit" value="Edit"></td>';
}

// Setup table displaying outstanding workorders; if regular user, display tickets created by that user; if admin,
// display all outstanding tickets
function generateDashboard() {
	if (isAdmin()) {
		$query = 'SELECT * FROM tickets';
		$result = getDB()->prepare($query);
		$result->bindParam(':requestor', $_SESSION['user']);
		$result->execute();	
	} else {
		$query = 'SELECT * FROM tickets WHERE requestor LIKE :requestor AND STATUS = :open';
		$status = 'OPEN';
		$result = getDB()->prepare($query);
		$result->bindParam(':requestor', $_SESSION['user']);
		$result->bindParam(':open', $status);
		$result->execute();	
	}


	printFilterHeader();
	$numRecords = 0;
	while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
		$records = array();
		echo '<tr>';
	
		array_push($records, $row['ticketNumber'], $row['dateCreated'], $row['problemDescription'], $row['requestor'], 
		$row['problemCode'], $row['assignedTo'], $row['dateClosed'], $row['status']);
	

		printRecords($records);
		appendEditRecordButton($numRecords);
		$numRecords++;
		echo '</tr>';
		
	}
	printFilterFooter();

}

function doFilter() {
//	$query = 'SELECT * FROM tickets WHERE ticketNumber LIKE :ticketNumber AND status LIKE :status';
	$query = 'SELECT * FROM tickets WHERE status LIKE :status';
	$result = getDB()->prepare($query);
//	$result->bindParam(':ticketNumber', $_POST['ticketNumber']);
	$result->bindParam(':status', $_POST['status']);
	$result->execute();	

	printFilterHeader();
	while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
		$records = array();
{'fraction_non_alphanumeric': 0.20856479143520856, 'fraction_numerical': 0.003736996263003737, 'mean_word_length': 4.56917885264342, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686727', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3091, 'n_words': 818}