Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 1st, 2007, 04:10 AM
Registered User
Join Date: Jun 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sethhilton
Default Aid on CheckIn.php/Checkout.php

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:




    // 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

       // 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);


               echo "Sorry, you cannot login<br><br>";

               echo "There is $numberlock lock on your account :-<br><br>";

               // Printing Employee Lock Alert

               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


                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');

                         // Checking if user has personal messages

                } // 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








    // 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

// chopping off scriptname from path
if ($scriptname!="precheckout.php")

       echo "Error ! This page can only be accesed from precheckout.php";

else if ($scriptname=="precheckout.php")


   // If project is not chosen
   if ($projectid=="-1")

    echo "You have to choose a project. Project box cannot be left blank<br><br>";


   // 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>";


   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

     // 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);



         // 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)

             $checkout=mysql_result($resultlogout,0,"checkout") ;

             // Split Check in time into hours, minutes and seconds
             list($inday,$intime)=explode(' ',$checkin);
             list($inhour, $inminute, $inseconds) = explode(':',$intime);

             // Split Check out time(now) into hours, minutes and seconds
             list($outday,$outtime)=explode(' ',$dt);
             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

             // 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

             // Amount of Time worked in Minutes

             // 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

            $deptid=genericget($empid,'empid','deptid','employ ee');
            $deptname=genericget($deptid,'deptid','deptname',' department');
            $projname=genericget($projectid,'projectid','proje cttitle','project');

            // Printing Employee Check Out Slip

<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>
  <tr bgcolor="#FFFFFF" valign="middle">
    <td height="40"><b><? echo $empname; ?></b></td>
    <td height="40"><b><? echo $deptname; ?></b></td>
  <tr bgcolor="#F4F4F4" valign="middle">
    <td height="40" colspan="2"><b><? echo $checkout2; ?> </b><? echo $projname; ?></td>
    <td valign="top" width="263" height="110" bgcolor="#FFFFFF">
      <p><b><? echo $checkout3; ?></b></p>
        <p><? echo $checkout4; ?><b><? echo $inday; ?></b></p>
        <p><? echo $checkout5; ?><b><? echo $intime; ?></b></p>
    <td rowspan="2" width="237" valign="top" bgcolor="#FFFFFF">
      <p><b><? echo $checkout6; ?></b></p>
      <p><b><i><? echo $checkout7; ?></i></b></p>
        <p><b><? echo $roundedtime; ?> <? echo $checkout8; ?></b></p>
      <p><b><i><? echo $checkout9; ?></i></b></p>
        <p><b><? echo $timeworkminute1; ?> <? echo $checkout10; ?></b></p>
    <td valign="top" width="263" height="110" bgcolor="#FFFFFF"> <b><? echo $checkout11; ?></b>
        <p><? echo $checkout4; ?><b> <? echo $outday; ?></b></p>
        <p><? echo $checkout5; ?><b><? echo $outtime; ?></b></p>
  <tr bgcolor="#F4F4F4">
    <td valign="top" colspan="2" height="110">
      <p><b><? echo $checkout12; ?></b></p>
        <p><i><? echo $workdone; ?></i></p>

                        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





Please HELP!!

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Commit.PHP and Delete.PHP in WROX's book GiFos Beginning PHP 0 January 30th, 2007 10:51 PM
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
PHP Warning: PHP Startup: Unable to load dynamic l surendran Beginning PHP 1 May 29th, 2006 08:49 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM

All times are GMT -4. The time now is 06:41 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.