I'm currently working on a payroll system. An open source payroll system.
Everytime I log in, it's sucessful but then, when checking out, I've this error message saying that you're not logged in therefore you cannot check out.
Here's the php. codes for the checkin followed by checkout:
Checkin.php:
<?
include("header.php");
include("functions.php");
?>
<?
// FILE DOCUMENTATION
// Filename : checkin.php
// Description : This file accepts the arguments formlogin and formpassword
// from the script startwork.php and then processes it. It checks
// for validity of the data and then if everything is ok, it checks
// in employee in the payroll system
//
// License : GPL
// Date : 11/04/2001
// Related Files : startwork.php
?>
<?
// Using Function Checklogin to get properties of the login and password entered
// The function checklogin takes $formlogin and $formpassword as variables
// and return a string of integers separated by the character '>'
//
// e.g of the string would be 'exists>lock>firstname>lastname>empid>passwordok>a ctive'
//
// Exists : if the formlogin exists {0|1}
// Lock : checks whether user has any lock {0|1} (0 = no lock , 1 = lock)
// Firstname, Lastname : Self Explanatory
// Empid : Employee ID
// Passwordok : If password matches {0|1} (0 = no match , 1 = match)
// Active : If user account is active {0|1} (0 = not active , 1 = active)
$loginproperties=checklogin($formlogin,$formpasswo rd);
// Breaking the string into its respective items
list($exists,$lock,$firstname,$lastname,$empid,$pa sswordok,$active)=explode('>',$loginproperties);
// If login does not exists in the database
// Print Error Message
if ($exists==0)
{
echo "This login does not exist in our database. Please go $back and try again<br>";
}
// If Login Exists in databsae, proceed
else if ($exists==1)
{
// If password entered does not match database password
// associated with the login, print error message
if ($passwordok==0)
{
echo "Wrong Password ! Please try again. $back<br>";
}
// Password match
else if ($passwordok==1)
{
// Checking if User is allowed to check in from this IP ADDRESS
// Function checkipaddress returns 1 if address is valid
// else it returns 0
$goodip=checkipaddress($ipaddress,$empid);
// If IP Addres is not good, print error message
if ($goodip==0)
{
echo "You cannot checkin from this location ($ipaddress). You can only checkin from valid locations. Ask your Manager which locations are valid.";
}
// If ip address is good, proceed
else if ($goodip==1)
{
// if account status is not active
// print error message
if ($active==0)
{
echo "Your account is not active. Please contact your manager about it. $back<br>";
} // end if active==0
// Account is active
else if ($active==1)
{
// Check whether user has got any lock
// If user has got any locks, retreive lock message from locks table
// and display and do not proceed forward
if ($lock==1)
{
// Query to check if this person has got any lock on his/her record
$querylock = "select * from locks where empid='$empid'";
$resultlock = MYSQL_QUERY($querylock) or die("SQL Error Occured : ".mysql_error().':'.$querylock);
// Getting number of rows from Querylock
$numberlock = MYSQL_NUMROWS($resultlock);
$lockno=0;
echo "Sorry, you cannot login<br><br>";
echo "There is $numberlock lock on your account :-<br><br>";
// Printing Employee Lock Alert
printlocks($empid);
echo "You have to clear these locks with the person who placed them before you can login.";
echo "<br><br>";
echo "Thanks";
} // end of if ($lock==1)
// If there is no lock on the account
else if ($lock==0)
{
// Checking if user is already logged in
// Function checkifloggedin takes argument employee id
// and returns a string of properties separated by the '>' Character
// string e.g loggedin>loggedindate>loggedintime
//
// loggedin : Whether user is already logged in or not {0|1} (0=not logged in, 1=logged in)
// loggeddate : date that user had last checked in
// loggedtime : time that user had last checked in
$isloggedin=checkifloggedin($empid);
list($loggedin,$loggedindate,$loggedintime)=explod e('>',$isloggedin);
if ($loggedin==1)
{
echo "You are already logged in to the system. You cannot log in again. Please log off before you can log in again.<br>";
echo "Login Date : ".$loggedindate."<br><br>";
echo "Login Time : ".$loggedintime."<br><br>";
echo $back;
}
// User is not already checked in and not checked out
// So can proceed
else if ($loggedin==0)
{
$querystart = "INSERT INTO timesheet (timeid, empid, projectid, checkin, checkout, rawtime, roundedtime, workdesc, ipcheckin, ipcheckout, checked) VALUES (null,'$empid', '', '$dt', '', '0', '0', '', '$ipaddress', '', 'n')";
$resultstart = MYSQL_QUERY($querystart) or die("SQL Error Occured : ".mysql_error().':'.$querystart);
echo "<br>Thanks $firstname $lastname<br><br>";
echo "You have successfully checked in.<br><br>";
echo "<b>Checkin Information</b><br>";
echo "[list]<table><tr><td>Date :</td><td><b>$today</b></td></tr><tr><td>Time : </td><td><b>$timenow</b></td></tr></table></ul>";
echo "Work Hard and do not forget to check out when u finish working.<br><br>";
echo "<a href=\"javascript
:window.close();\">Close this Window</a><br>";
echo "<a href=\"login.php\">Log in to my Account Manager</a><br>";
echo "";
// Checking if user has any departmental events
$deptid=genericget($empid,'empid','deptid','employ ee');
checkdeptmessages($deptid);
// Checking if user has personal messages
checkmessages($empid);
} // end of else if loggedin==0
} // end of else if lock==0
} // end else if active==1
} // end else if goodip==1
} // end of if password==1
} // end if exists==1
?>
<?
include("footer.php");
?>
Checkout.php:
<?
include("header.php");
include("functions.php");
?>
<?
// FILE DOCUMENTATION
// Filename : checkout.php
// Description : After user check out authenticates, and user selects
// project worked, and work description
// this script actually checks out user from the timesheet
// and calculate time worked
// License : GPL
// Date : 11/11/2001
// Related Files : precheckout.php,stopwork.php
?>
<?
// PRE CONDITION = REFERING SCRIPT = precheckout.php
// Checking Precondition that this page is being
// accesed only from precheckout.php
// getting refering script path and name
$r=$HTTP_REFERER;
// chopping off scriptname from path
$scriptname=substr($referer,-15,15);
if ($scriptname!="precheckout.php")
{
echo "Error ! This page can only be accesed from precheckout.php";
}
else if ($scriptname=="precheckout.php")
{
$error=0;
// If project is not chosen
if ($projectid=="-1")
{
echo "You have to choose a project. Project box cannot be left blank<br><br>";
$error=1;
}
// If workdone field is left blank
if ($workdone=="")
{
echo "Work done field cannot be left blank. You have to put a short word description of what you have done today.<br><br>";
$error=1;
}
if ($error==1)
{
echo $back;
}
else if ($error==0)
{
// Checking if User is allowed to check in from this IP ADDRESS
// Function checkipaddress returns 1 if address is valid
// else it returns 0
$goodip=checkipaddress($ipaddress,$empid);
// If IP Addres is not good, print error message
if ($goodip==0)
{
echo "You cannot checkin from this location ($ipaddress). You can only checkin from valid locations. Ask your Manager which locations are valid.";
}
// If ip address is good, proceed
else if ($goodip==1)
{
// Select the user with the login and who had a checkin record but no checkout
$querylogout = "Select * from timesheet where empid='$employeeid' and checkout='';";
// Execute the Query
$resultlogout = MYSQL_QUERY($querylogout);
$numberlogout=MYSQL_NUMROWS($resultlogout);
$i=0;
// Cant find record... So use had not logged in before
if ($numberlogout == 0)
{
echo "Sorry you are not checked in. So you cannot checkout.<br>";
}
elseif ($numberlogout > 0)
{
$timeid=mysql_result($resultlogout,0,"timeid");
$empid=mysql_result($resultlogout,0,"empid");
$checkin=mysql_result($resultlogout,0,"checkin");
$checkout=mysql_result($resultlogout,0,"checkout") ;
// Split Check in time into hours, minutes and seconds
list($inday,$intime)=explode(' ',$checkin);
list($inyear,$inmonth,$indate)=explode('-',$inday);
list($inhour, $inminute, $inseconds) = explode(':',$intime);
// Split Check out time(now) into hours, minutes and seconds
list($outday,$outtime)=explode(' ',$dt);
list($outyear,$outmonth,$outdate)=explode('-',$outday);
list($outhour, $outminute, $outseconds) = explode(':',$outtime);
// use Mktime to find difference in start and end times
$starttime=mktime($inhour,$inminute,$inseconds,$in month,$indate,$inyear);
$endtime=mktime($outhour,$outminute,$outseconds,$o utmonth,$outdate,$outyear);
// Amount of Time worked
// From checkin time to checkout time
// in seconds
$timeworksec=$endtime- $starttime;
// Amount of time worked in hours
$timeworkhour=$timeworksec/3600;
// Getting First 4 digits for hours eliminating
// Additional decimals
$timeworkhour1 = substr($timeworkhour,0,4);
// Rounding the time worked
// The variable rounding is set in the constants.php file
// If $rounding is 0, time remains same
// 25, then it rounds to nearest quarter hour
// 50, then it rounds to nearest half hour
$roundedtime=roundtime($timeworkhour,$rounding);
// Amount of Time worked in Minutes
$timeworkminute=$roundedtime*60;
// Getting the first 5 digits
$timeworkminute1 = substr($timeworkminute,0,5);
// Update Employee record and save checkin time and worked done
$queryupdateout="update timesheet set checkout='$dt',workdesc='$workdone',projectid='$
pr ojectid',rawtime='$timeworkhour1',roundedtime='$ro undedtime',ipcheckout='$ipaddress',checked='n' where timeid='$timeid';";
// Execute Update Query
$resultupdateout = MYSQL_QUERY($queryupdateout);
// Update time for project
// Add this time to project worked on
updateprojecttime($projectid,$timeworkhour1);
updatelastproject($empid,$projectid);
$deptid=genericget($empid,'empid','deptid','employ ee');
$deptname=genericget($deptid,'deptid','deptname',' department');
$empname=getempname($empid);
$projname=genericget($projectid,'projectid','proje cttitle','project');
// Printing Employee Check Out Slip
?>
<center>
<table width="550" border="1" cellspacing="0" cellpadding="0" bordercolordark="#CCCCCC" bordercolorlight="#000000">
<tr bgcolor="#CCCCCC" valign="middle">
<td height="40" colspan="2">
<div align="center"><b><? echo $checkout1; ?></b></div>
</td>
</tr>
<tr bgcolor="#FFFFFF" valign="middle">
<td height="40"><b><? echo $empname; ?></b></td>
<td height="40"><b><? echo $deptname; ?></b></td>
</tr>
<tr bgcolor="#F4F4F4" valign="middle">
<td height="40" colspan="2"><b><? echo $checkout2; ?> </b><? echo $projname; ?></td>
</tr>
<tr>
<td valign="top" width="263" height="110" bgcolor="#FFFFFF">
<p><b><? echo $checkout3; ?></b></p>
<blockquote>
<p><? echo $checkout4; ?><b><? echo $inday; ?></b></p>
<p><? echo $checkout5; ?><b><? echo $intime; ?></b></p>
</blockquote>
</td>
<td rowspan="2" width="237" valign="top" bgcolor="#FFFFFF">
<p><b><? echo $checkout6; ?></b></p>
<p><b><i><? echo $checkout7; ?></i></b></p>
<blockquote>
<p><b><? echo $roundedtime; ?> <? echo $checkout8; ?></b></p>
</blockquote>
<p><b><i><? echo $checkout9; ?></i></b></p>
<blockquote>
<p><b><? echo $timeworkminute1; ?> <? echo $checkout10; ?></b></p>
</blockquote>
</td>
</tr>
<tr>
<td valign="top" width="263" height="110" bgcolor="#FFFFFF"> <b><? echo $checkout11; ?></b>
<blockquote>
<p><? echo $checkout4; ?><b> <? echo $outday; ?></b></p>
<p><? echo $checkout5; ?><b><? echo $outtime; ?></b></p>
</blockquote>
</td>
</tr>
<tr bgcolor="#F4F4F4">
<td valign="top" colspan="2" height="110">
<p><b><? echo $checkout12; ?></b></p>
<blockquote>
<p><i><? echo $workdone; ?></i></p>
</blockquote>
</td>
</tr>
</table>
</center>
<?
echo "<center>";
echo "<a href=\"javascript
:window.close();\">$checkout13</a><br>";
echo "<a href=\"$siteaddress/startwork.php\">$checkout14</a><br>";
echo "<a href=\"login.php\">$checkout15</a><br>";
echo "</center>";
} // end of else if numberlogout>0
} // end of else if goodip=1
} // else if error == 0
} // else if scriptname==precheckout.php
?>
<?
include("footer.php");
?>
Please HELP!!