-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassignTrainingTo.php
More file actions
105 lines (70 loc) · 3.3 KB
/
Copy pathassignTrainingTo.php
File metadata and controls
105 lines (70 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/* Date Name Changes
* 11/27/2019 Andrey Coding page
*
*
*
*/
session_start();//session is starting
//checking if loggedin session is set, and role is Manager, if not rederecting to main page
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true || !isset($_SESSION["role"]) || $_SESSION["role"] !== "Manager") {
header("location: index.php");
exit;
}
include_once("./includes/open_conn.inc"); //opening connection to db
function getTrainingName($training_id, $link)
{//this function is returning training title(aka name) from the training id
// include_once("./includes/open_conn.inc"); //opening connection to db
$select_title_query = "SELECT training_title from training where training_id='" . $training_id . "'";
$answr = "UNKNOWN ERROR";
if ($result = mysqli_query($link, $select_title_query)) {
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$answr = $row['training_title'];
}
}
}
//include_once("./includes/close_conn.inc"); //closing connection to db
return $answr;
}
?>
<?php include('wrapper/Header.php'); ?>
<title>Assign Training</title>
</head>
<body>
<?php include('wrapper/Logo.php'); ?>
<div class="page-header">
<h1><b><?php echo htmlspecialchars($_SESSION["username"]); ?>
</b> please select users to assign<span style="color:red;"></h1>
<h1><?php echo htmlspecialchars(getTrainingName($_GET['training_id'], $link)); ?></span>
Training to:</h1>
<br><br>
<div>
<form action="./php_scripts/assignTraining.php" method="post">
<?php
echo '<input type="hidden" name="training_id" value="' . $_GET['training_id'] . '">'; // hidden field for sending training id into form action script
$num_of_columns = 5;
$counter = 0;
$select_query = "SELECT username, id, role, firstName, lastName from users, user_info where users.id = user_info.user_id and enabled=b'1' and role='Trainee'"; // this query is selecting trainee user info from two tables: users and user_info
if ($result = mysqli_query($link, $select_query)) {
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
echo '<input type="checkbox" name="checked_trainiees[]" value="' . $row['id'] . '" title="' . $row['username'] . " is " . $row['role'] . " whose id is " . $row['id'] . ' and name is ' . $row['firstName'] . " " . $row['lastName'] . '" > ' . $row['username'];
echo"<br>";
$counter++;
echo"<br>";
}
}
}
include_once("./includes/close_conn.inc"); //closing connection to db
?>
<br>
<div class="form-group">
<a href="./showAllTrainings.php" type="reset" class="btn btn-default" value="Back">Back</a>
<input type="submit" class="btn btn-primary" value="Assing Trainin To Selected Users">
</div>
</form>
</div>
<?php
include('wrapper/Footer.php');
?>