<?php
$page_title = "Find User| CES Admin";
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/common_functions.php"); //common functions in the course registartion system
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/config.php"); //holds global config variables
check_if_authenticated('admin');//check if user is logged in
include_once($_SERVER['DOCUMENT_ROOT'] . "/admin/php/top-admin.php"); //get the HTML heading common to all pages in the CES admin module
?>
<article class="ces-admin">
<h2>CES Admin - Find User</h2>
<?php
include_once($_SERVER['DOCUMENT_ROOT'] . "/admin/php/nav-admin.php");
?>
<form method='post' action='<?php echo $_SERVER['PHP_SELF'] ?>'>
<?php
//opens connection to database
$db = mysqli_connect($mysql_server, $user, $pass, $database);
$session_id = '';
if(isset($_GET['session_id'])){
$session_id = $_GET['session_id'];
}
elseif(isset($_POST['session_id'])){
$session_id = $_POST['session_id'];
}
$location_id = '';
if(isset($_GET['location_id'])){
$location_id = $_GET['location_id'];
}
elseif(isset($_POST['location_id'])){
$location_id = $_POST['location_id'];
}
$action = '';
if(isset($_GET['action'])){
$action = $_GET['action'];
}
elseif(isset($_POST['action'])){
$action = $_POST['action'];
}
$course_id = "";
if($session_id != ''){
$course_id = get_course_id($session_id);
$course_id = "#".$course_id;
}
echo "<input type='hidden' name='session_id' value=" . $session_id . ">"; //so we can keep track of the session
echo "<input type='hidden' name='location_id' value=" . $location_id . ">"; //so we can keep track of the location
echo "<input type='hidden' name='action' value=" . $action . ">"; //so we can keep track of the action
?>
<div class="form-group">
<select class="form-control ces-form-one-quarter" name='search_column'>
<option value='user.email'>Email Address</option>
<option value='first_name.value'>First Name</option>
<option value='last_name.value'>Last Name</option>
</select>
</div>
<div class="form-group">
<input class="form-control ces-form-half" type='text' name='search_key' autofocus>
</div>
<input type='submit' name='submit' value="Search" class="btn btn-lg btn-block ces-green-btn">
<a href="/admin/courses/<?php echo $course_id ?>" class="btn ces-orange-btn">Back</a>
</form>
<?php
if (isset($_POST['submit'])){ //if form has been submitted show search results
echo "\n<table id='ces-search-table' class='table table-striped'>";
echo "\n<thead>";
echo "\n\t<tr>\n";
echo "\n\t<th>First Name</th>";
echo "\n\t<th>Last Name</th>";
echo "\n\t<th>Email Address</th>";
echo "\n\t</tr>";
echo "\n\t</thead>";
echo "\n\t</tbody>";
$search_sql = mysqli_query($db, "SELECT user.id, user.email, first_name.value as first_name, last_name.value as last_name
FROM phplist_user_user user
LEFT OUTER JOIN phplist_user_user_attribute first_name ON user.id = first_name.userid AND first_name.attributeid = '1'
LEFT OUTER JOIN phplist_user_user_attribute last_name ON user.id = last_name.userid AND last_name.attributeid = '2'
WHERE $_POST[search_column] LIKE '%$_POST[search_key]%'");
//output the query results in html table format
while ($search_query = mysqli_fetch_array($search_sql)) {
//depending on the action, determine which link to output
if ($_POST['action'] == "attendee_search"){
$link = "<a href='index.php?id=" . $search_query["id"] ."'>";
}//elseif
else{
$link = "<a href='registration.php?session_id=" . $_POST["session_id"] . "&id=" . $search_query["id"] . "'>";
}//else
echo "\n\t<tr>";
echo "\n\t<td>" . $link . $search_query["first_name"] . "</a></td>";
echo "\n\t<td>" . $link . $search_query["last_name"] . "</a></td>";
echo "\n\t<td>" . $link . $search_query["email"] . "</a></td>";
echo "\n\t</tr>";
}//while
echo "\n</tbody>";
echo "\n</table>";
}//if
?>
</article>
</section><!-- #middle-->
</div><!-- #wrapper -->
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/require/footer.php';?>
<script type="text/javascript">
$(document).ready(function(){
$('#ces-search-table').DataTable({
paging:false,
searching:false,
info:false
});
});
</script>