/    Sign up×
Community /Pin to ProfileBookmark

php script employee task assigned

Hi

Sorry if is in the wrong place but was seeing if anyone knows of a script that can do the following

1) login to an admin side using admin login info
2) add tasks and assign them to employees
3) the employee can log in with their own log in info
4) the employee can then view their tasks that are just for them and not view others that are assigned to other employees
5) update the task themselves once completed
6) admin can also see the task and the update of it if it has been completed or working on

Thank you in advance

Ian

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmNov 20.2015 — Sure. There are probably hundreds of such scripts. Very simple to write. Perhaps you have some ideas that you have thought of and just don't know how to do them? Let's start small. Pick the first task in your algorithm and write it. Then ask for help where you have difficulties.

Step 1 - Secure login is a must. Do you have that written?

Step 2 - Create & save a task record retrieve it and read or edit it based upon the employee id or logged in id.

Step 3 - See step 1

Step 4 - See step 2

Step 5 - See step 2

Step 6 - See step 2

POC!
Copy linkTweet thisAlerts:
@NogDogNov 20.2015 — You could see if any of these open-source projects fit your needs: http://www.opensourcecms.com/scripts/show.php?catid=4&category=Groupware
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 20.2015 — Hi

I am trying to build it myself and got so far

I have built the register and login php scripts and that works perfect and now working on the view page but got stuck with it a bit

I got the following code

[CODE]
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
?>

<?php

include("db-connect.php");

// get the records from the database
if ($result = $mysqli->query("SELECT
e.emp_id
, t.description
FROM employee e
JOIN assignment a ON e.emp_id = a.emp_id
JOIN task t ON a.task_id = t.task_id"))

{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table>";

// set table headers
echo "<tr>
<th>Task ID</th>
<th>Description</th>
<th>Status</th>
<th>Emp ID</th>
<th>Status</th>
<th colspan='2'>Actions</th>
</tr>";

while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->task_id . "</td>";
echo "<td>" . $row->description . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td>" . $row->emp_id . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>";
echo "</tr>";
}

echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}

// close database connection
$mysqli->close();

?>
[/CODE]


I get the following errors

Notice: Undefined property: stdClass::$task_id in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 40

Notice: Undefined property: stdClass::$status in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 42

Notice: Undefined property: stdClass::$status in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 44

Notice: Undefined property: stdClass::$task_id in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 45

It is pulling the following info from the database

Description and the emp_id but not the task_id or the status
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 20.2015 — Think I sussed it

I added the following to the select query

[CODE]
, t.status
, t.task_id
[/CODE]
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 20.2015 — How do I make it so that the employee logged in sees just their tasks and not everyones tasks?
Copy linkTweet thisAlerts:
@NogDogNov 20.2015 — I think you could just add it to that join:
<i>
</i>JOIN task t ON a.task_id = t.task_id AND t.emp_id = e.emp_id
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 20.2015 — I tried that and got the following error

Warning: mysqli::query() [mysqli.query]: (42S22/1054): Unknown column 't.emp_id' in 'on clause' in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 47

Error: Unknown column 't.emp_id' in 'on clause'

Would it need to be e.emp_id instead of t.emp_id
Copy linkTweet thisAlerts:
@NogDogNov 20.2015 — oh, wait, I thought it was something specific to task. Looks like you need to instead add a where clause to check the e.emp_id equals the logged in user's ID. Do you already have that ID in $_SESSION?
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 20.2015 — Yeah I am storing the id in a session, I have the following code

[CODE]
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
?>

<!DOCTYPE html>
<html>
<head>
<title>View Tasks</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/login-styles.css" />
</head>
<body>

<h2>View Tasks</h2>

<?
session_start();

if($_SESSION['user']==''){
header("Location:login.php");
}else{
include("config.php");
$sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?");
$sql->execute(array($_SESSION['user']));
while($r=$sql->fetch()){
echo "<div class='home-content'>";
echo "<center><h2>Hello, ".$r['username']."</h2>";
echo "<a href='logout.php'>Log Out</a></center>";
echo "</div>";
}
}
?>

<?php

include("db-connect.php");

// get the records from the database
if ($result = $mysqli->prepare("SELECT
e.emp_id
, t.task_id
, t.description
, t.status
FROM employee e
JOIN assignment a ON e.emp_id = a.emp_id
JOIN task t ON a.task_id = t.task_id
WHERE e.emp_id = ?"));
$sql->execute(array($_SESSION['user']));

{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table>";

// set table headers
echo "<tr>
<th>Task ID</th>
<th>Description</th>
<th>Status</th>
<th>Emp ID</th>
<th>Status</th>
<th colspan='1'>Actions</th>
</tr>";

while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->task_id . "</td>";
echo "<td>" . $row->description . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td>" . $row->emp_id . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>";
echo "</tr>";
}

echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}

// show an error if there is an issue with the database query
/*else {
echo "Error: " . $mysqli->error;
}*/

// close database connection
$mysqli->close();

?>

</body>
</html>
[/CODE]


But it is returning 0 results where as it should be returning 1 result as I have assigned task_id 1 in the task table and in the assignment table is a id of 1 and is assigned to emp_id 2
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 20.2015 — Hi

I have altered the coding slightly and got no errors now but no results still?

[CODE]
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
?>

<!DOCTYPE html>
<html>
<head>
<title>View Tasks</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/login-styles.css" />
</head>
<body>

<h2>View Tasks</h2>

<?
session_start();

if($_SESSION['user']==''){
header("Location:login.php");
}else{
include("config.php");
$sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?");
$sql->execute(array($_SESSION['user']));
while($r=$sql->fetch()){
echo "<div class='home-content'>";
echo "<center><h2>Hello, ".$r['username']."</h2>";
echo "<a href='logout.php'>Log Out</a></center>";
echo "</div>";
}
}
?>

<?php

include("config.php");

$sql=$dbh->prepare("SELECT
e.emp_id
, t.task_id
, t.description
, t.status
FROM employee e
JOIN assignment a ON e.emp_id = a.emp_id
JOIN task t ON a.task_id = t.task_id
WHERE e.emp_id = ?");
$sql->execute(array($_SESSION['user']));

{
// display records if there are records to display
//if ($sql->num_rows > 0)
if ($sql->fetchColumn() > 0)
{
// display records in a table
echo "<table>";

// set table headers
echo "<tr>
<th>Task ID</th>
<th>Description</th>
<th>Status</th>
<th>Emp ID</th>
<th>Status</th>
<th colspan='1'>Actions</th>
</tr>";

while ($row = $sql->fetchColumn())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->task_id . "</td>";
echo "<td>" . $row->description . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td>" . $row->emp_id . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>";
echo "</tr>";
}

echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}

// show an error if there is an issue with the database query
/*else {
echo "Error: " . $mysqli->error;
}*/

// close database connection
$dbh = null;

?>

</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@NogDogNov 21.2015 — Is $_SESSION['user'] the actual user id, or the user name (or email, or whatever)? If the latter, then you'll need to compare to that column, not to emp_id (I'm assuming emp_id is an integer primary key?).
Copy linkTweet thisAlerts:
@ianhaneyauthorNov 21.2015 — Hi

Sorry, I managed to get it working with the following code

[code=php]
$sql=$dbh->prepare("SELECT
e.emp_id
, t.task_id
, t.description
, t.status
FROM employee e
JOIN assignment a ON e.emp_id = a.emp_id
JOIN task t ON a.task_id = t.task_id
WHERE e.emp_id = ?");
$sql->execute(array($_SESSION['user']));

// were any rows found?

if ($row = $sql->fetchObject())
{
// display records in a table
echo "<table>";

// set table headers
echo "<tr>
<th>Task ID</th>
<th>Description</th>
<th>Status</th>
<th>Emp ID</th>
<th>Status</th>
<th colspan='1'>Actions</th>
</tr>";


do {
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->task_id . "</td>";
echo "<td>" . $row->description . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td>" . $row->emp_id . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>";
echo "</tr>";
} while ($row = $sql->fetchObject());

echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
[/code]
×

Success!

Help @ianhaney spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...