Page 1 of 3
PHP leave tracking webpage
Posted: Fri Aug 22, 2008 12:15 am
by sifar786
Hi,
I m trying to create a Leave tracking webpage which will display a sort of HTML Gantt Table.
On selecting/entering a StartDate & EndDate for Gantt table, it will query an MSSQL database and display unique employees with their corresponding row TD cells colored according to their various Leave Date ranges & according to their AppliedLeave status (0=Pending (Yellow), 1=Approved(Green), 2=Rejected(Red)).
EmpCode | EmpName | 01 | 02 | 03 | 05 |....
0001 | sahil | 0 | 0 | | |....
0002 | mae | | | 1 | |....
0003 | joe | 2 | | 1 | 1 |....
How to achieve this?
'********************* CODE HERE ************************
Code: Select all
<?php
$connection = mssql_connect("localhost","root","") or die ("Couldn't connect to server");
$db = mssql_select_db("leavetracker", $connection) or die ("Couldn't select database");
$deptid = $_POST['DeptID'];
/*$date1=$POST['dateinputex1'];
$date2=$POST['dateinputex2'];*/
?>
<HTML>
<HEAD>
<TITLE>
Leave Gantt
</TITLE>
<link rel="stylesheet" type="text/css" media="all" href="datechooser.css">
<script type="text/javascript" src="datechooser.js"></script>
<script type="text/javascript">
<!-- //
events.add(window, 'load', WindowLoad);
function WindowLoad()
{
var ndExample1 = document.getElementById('datechooserex1');
var ndExample2 = document.getElementById('datechooserex2');
ndExample1.DateChooser = new DateChooser();
ndExample2.DateChooser = new DateChooser();
// Check if the browser has fully loaded the DateChooser object, and supports it.
if (!ndExample1.DateChooser.display || !ndExample2.DateChooser.display)
{
return false;
}
ndExample1.DateChooser.setCloseTime(200);
ndExample1.DateChooser.setXOffset(10);
ndExample1.DateChooser.setYOffset(-10);
ndExample1.DateChooser.setUpdateFunction(FunctionEx1);
document.getElementById('datelinkex1').onclick = ndExample1.DateChooser.display;
ndExample2.DateChooser.setCloseTime(200);
ndExample2.DateChooser.setXOffset(10);
ndExample2.DateChooser.setYOffset(-10);
ndExample2.DateChooser.setUpdateFunction(FunctionEx2);
document.getElementById('datelinkex2').onclick = ndExample2.DateChooser.display;
}
function FunctionEx1(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex1').value= objDate.getPHPDate('n/d/Y');
return true;
}
function FunctionEx2(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex2').value= objDate.getPHPDate('n/d/Y');
return true;
}
// -->
</script>
</HEAD>
<BODY>
<H1>Leave Tracking Gantt</H1>
<form name="MyForm" method="POST">
<select id="DeptID" name="DeptID">
<?
$depQy="select DepartmentID,Name FROM Department";
$res=mssql_query($depQy) or die("Query failed: ".mssql_error());
while ($row=mssql_fetch_array($res))
{
if($deptid==$row['DepartmentID'])
$ins="SELECTED";
else
unset($ins);
echo "<option $ins value='".$row['DepartmentID']."'>".$row['Name']."</option>";
}
?>
</select>
<a id="datechooserex1">
<a id="datelinkex1" href="#">StartDate</a>
<input id="dateinputex1" name="dateinputex1" type="text" value="">
</a>
<a id="datechooserex2">
<a id="datelinkex2" href="#">EndDate</a>
<input id="dateinputex2" name="dateinputex2" type="text" value="">
</a>
<input type="submit" NAME="SUBMIT" value="Submit">
</form>
<?php
if($_POST)
{
$date1=$_POST['dateinputex1'];
$date2=$_POST['dateinputex2'];
$query = "SELECT em.Code, em.FirstName, em.LastName, ela.StartDate, ela.EndDate, ela.status FROM EmpMaster as em INNER JOIN EmpLeaveApplication as ela ON em.EmployeeID = ela.EmployeeId where (ela.StartDate >='".$date1."') AND (ela.EndDate <= '".$date2."') AND (em.DepartmentID =".$_POST['DeptID'].")";
$result = mssql_query($query) or die("Query failed: ".mssql_error());
echo "<TABLE BORDER='1'>";
echo "<TR bgcolor=gray>";
echo "<TH>EmpCode</TH><TH>FirstName</TH><TH>LastName</TH><TH>StartDate</TH><TH>EndDate</TH><TH>Status</TH>";
for ($i=0; $i<=date('d',$date2);$i++)
{
echo "<TH>".date('Y/m/d',mktime(0,0,0,date('m',$date1),date('d',$date1)+$i,date('Y',$date1)))."</TH>";
}
echo "</TR>";
while ($row = mssql_fetch_array($result))
{
echo "<TR bgcolor=#DBC7DA>";
echo "<TD>".$row['Code'];
echo "</TD><TD>".$row['FirstName'];
echo "</TD><TD>".$row['LastName'];
echo "</TD><TD>".$row['StartDate'];
echo "</TD><TD>".$row['EndDate'];
echo "</TD><TD>".$row['Status'];
echo "</TD>";
echo "</TR>";
}
echo "</TABLE>";
}
mssql_close($connection);
?>
</BODY>
</HTML>
Re: PHP leave tracking webpage
Posted: Fri Aug 22, 2008 12:21 am
by it2051229
I do not understand what you are trying to achieve.
Re: PHP leave tracking webpage
Posted: Fri Aug 22, 2008 1:45 am
by sifar786
Hi,
I am attaching an excel file which shud give you an idea.
Regards,
Re: PHP leave tracking webpage
Posted: Fri Aug 22, 2008 7:32 pm
by it2051229
but your question "how to achieve this" it's like you're saying you haven't even started doing the project.
Re: PHP leave tracking webpage
Posted: Sat Aug 23, 2008 5:27 am
by sifar786
I have!
If you see, thats the code i posted earlier. But m stuck after that! dont know how to take the result() in different Arrays and generate the output. I m a Newbie....need some type of custom algorithm....
if you can provide any ideas, i would certainly appreciate it!
Regards,
Re: PHP leave tracking webpage
Posted: Sat Aug 23, 2008 8:36 am
by it2051229
i dont even know what your code does.. it has errors like you have $_POST in line 102(here)..., no program comments, i dont know that this and that and those do.
Re: PHP leave tracking webpage
Posted: Sat Aug 23, 2008 9:22 am
by sifar786
i have made similar tables (3 tables) in mysql as thats what is installed at my home. if you want i can post the same to you.
Ok. Let me ask your advice on this...
Code: Select all
<?php>
$leaves = array(
array("rose", '8/1/2008','8/3/2008', 0),
array("rose", '8/5/2008', '8/7/2008', 1),
array("rose", '8/9/2008', '8/11/2008', 1),
array("daisy", '8/2/2008', '8/4/2008', 2),
array("daisy", '8/6/2008', '8/8/2008', 0),
array("daisy", '8/3/2008', '8/3/2008', 0),
array("orchid", '8/15/2008', '8/20/2008', 1),
array("orchid", '8/11/2008', '8/19/2008', 2),
array("orchid", '8/10/2008', '8/20/2008', 1)
);
?>
If i have the following array, how do i collect the dates & Status_code for each unique employee_name and split them into some type of multidimensional array like this. Please forgive me as i m new to PHP and donot yet know the syntax. Just migrating myself from VB.
;
;
;
;
;
;
;
;
;
regards,
Re: PHP leave tracking webpage
Posted: Sat Aug 23, 2008 8:57 pm
by it2051229
you can do a for loop on that array... although you're using multi dimensional arrays so it's quite complicated.
Code: Select all
for($i=0; $i < count($leaves); $i++)
{
// name
echo $leaves[$i][0];
echo "<br />";
// date
echo $leaves[$i][1];
echo "<br />";
// another date
echo $leaves[$i][2];
echo "<br />";
// some unknown 1's and 0's
echo $leaves[$i][3];
echo "<br />";
}
i'm still confused.. you're going to get data from the database and place it in a multi dimensional array?? or are you trying to say that you're going to extract data from the multidimensional array?
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 1:33 am
by sifar786
Hi,
Thnx for your reply.
Yes, i am trying to get data from database and place it in a multidimensional array so that i can manipulate the array using php and create a table of colors as per the status code.
Here it is what i worked last night...I have commented the code...
Code: Select all
<?php
$connection = mysql_connect("localhost","root","") or die ("Couldn't connect to server");
$db=mysql_select_db("timemate", $connection) or die ("Couldn't select database");
$deptid = $_POST['deptid'];
?>
<HTML>
<HEAD>
<TITLE>Leave Gantt!</TITLE>
<link rel="stylesheet" type="text/css" media="all" href="datechooser.css">
<script type="text/javascript" src="datechooser.js"></script>
<script type="text/javascript">
<!-- //
// DateChooser Code for selecting StartDate and EndDate.
events.add(window, 'load', WindowLoad);
function WindowLoad()
{
var ndExample1 = document.getElementById('datechooserex1');
var ndExample2 = document.getElementById('datechooserex2');
ndExample1.DateChooser = new DateChooser();
ndExample2.DateChooser = new DateChooser();
// Check if the browser has fully loaded the DateChooser object, and supports it.
if (!ndExample1.DateChooser.display || !ndExample2.DateChooser.display)
{
return false;
}
ndExample1.DateChooser.setCloseTime(200);
ndExample1.DateChooser.setXOffset(10);
ndExample1.DateChooser.setYOffset(-10);
ndExample1.DateChooser.setUpdateFunction(FunctionEx1);
document.getElementById('datelinkex1').onclick = ndExample1.DateChooser.display;
ndExample2.DateChooser.setCloseTime(200);
ndExample2.DateChooser.setXOffset(10);
ndExample2.DateChooser.setYOffset(-10);
ndExample2.DateChooser.setUpdateFunction(FunctionEx2);
document.getElementById('datelinkex2').onclick = ndExample2.DateChooser.display;
}
function FunctionEx1(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex1').value= objDate.getPHPDate('Y-n-j');
return true;
}
function FunctionEx2(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex2').value= objDate.getPHPDate('Y-n-j');
return true;
}
// -->
</script>
</HEAD>
<BODY>
<H1>Leave Tracker</H1>
<form name="MyForm" method="POST">
<select id="deptid" name="deptid">
<?
/* Select Department in dropdown list.*/
$depQy="select departmentid, name from department";
$res=mysql_query($depQy) or die("Query failed: ".mysql_error());
while ($row=mysql_fetch_array($res))
{
if($deptid==$row['departmentid'])
$ins="SELECTED";
else
unset($ins);
echo "<option $ins value='".$row['departmentid']."'>".$row['name']."</option>";
}
?>
</select>
<a id="datechooserex1">
<a id="datelinkex1" href="#">StartDate</a>
<input id="dateinputex1" name="dateinputex1" type="text" value="" class="datechooser dc-dateformat='Y-n-j'">
</a>
<a id="datechooserex2">
<a id="datelinkex2" href="#">EndDate</a>
<input id="dateinputex2" name="dateinputex2" type="text" value="" class="datechooser dc-dateformat='Y-n-j'">
</a>
<input type="submit" NAME="SUBMIT" value="Submit">
</form>
<?php
// Main Code starts here......
if($_POST)
{
$date1=$_POST['dateinputex1'];
$date2=$_POST['dateinputex2'];
$query = "select em.code, em.firstname, em.lastname, ela.startdate, ela.enddate, ela.status FROM empmaster as em INNER JOIN empleaveapplication as ela ON em.employeeid = ela.employeeid where (ela.startdate >='".$date1."') AND (ela.enddate <= '".$date2."') AND (em.departmentid =".$_POST['deptid'].") order by em.code ASC, ela.startdate ASC";
$result = mysql_query($query) or die("Query failed:".mysql_error());
echo "<table border='0'>";
// For each Employee, display Status Color for leave days from starttime to endtime.
echo "<th align='center'>Code</th>";
echo "<th align='center'>FirstName</th>";
echo "<th align='center'>LastName</th>";
/*Here Code for generating Table-Headers for days starting from StartDate and EndDate.*/
$dt1=date_parse($date1);
$dt2=date_parse($date2);
for ($i=$dt1['day'];$i<($dt2['day']+1);$i++)
{
echo "<th>".($i)."</th>";
}
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='50'>".$rec['code']."</td>";
echo "<td align='center'>".$rec['firstname']."</td>";
echo "<td align='center'>".$rec['lastname']."</td>";
$sd=date_parse($rec['startdate']);
$ed=date_parse($rec['enddate']);
$diff=($ed['day']-$sd['day'])+1;
$Colo="";
// Choose color for TD cell as per status code...
if($rec['status']=='0') //No Color
{
$Colo="";
}
elseif($rec['status']=='1') // Approved
{
$Colo="Green";
}
elseif($rec['status']=='2') //Pending
{
$Colo="Yellow";
}
elseif($rec['status']=='3') //Rejected
{
$Colo="Red";
}
// Create TD cells starting from startdate till enddate....
echo str_repeat("<td> </td>",$sd).str_repeat("<td bgcolor=$Colo> </td>",$diff);
echo "</tr>";
unset($colo);
}
echo "</table>";
}
mysql_close($connection);
?>
</BODY>
</HTML>
1] If you see, i have commented the code but not getting the colors in the right place (i.e. under the correct dates).
e.g try selecting "Information Services" from the dropdown list and select Startdate='2008-8-01' and Enddate='2008-8-31'.
2] Also, i am not able to build logic to display dates in the same row for unique employees...
e.g. all leave dates(startdate to enddate) for employee "zaki" showing as colored TD cells in the same row for "zaki"....
Would i have to modify the SELECT query inorder to display all dates for unique names? Is it possible?
Regards,
P.S: Attached same php file as shown above.
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 4:07 am
by sifar786
Heres an updated one, which will give you a clearer picture as to what i am trying to achieve....
Code: Select all
<?php
$connection = mysql_connect("localhost","root","") or die ("Couldn't connect to server");
$db=mysql_select_db("timemate", $connection) or die ("Couldn't select database");
$deptid = $_POST['deptid'];
?>
<HTML>
<HEAD>
<TITLE>Leave Gantt!</TITLE>
<link rel="stylesheet" type="text/css" media="all" href="datechooser.css">
<script type="text/javascript" src="datechooser.js"></script>
<script type="text/javascript">
<!-- //
// DateChooser Code for selecting StartDate and EndDate.
events.add(window, 'load', WindowLoad);
function WindowLoad()
{
var ndExample1 = document.getElementById('datechooserex1');
var ndExample2 = document.getElementById('datechooserex2');
ndExample1.DateChooser = new DateChooser();
ndExample2.DateChooser = new DateChooser();
// Check if the browser has fully loaded the DateChooser object, and supports it.
if (!ndExample1.DateChooser.display || !ndExample2.DateChooser.display)
{
return false;
}
ndExample1.DateChooser.setCloseTime(200);
ndExample1.DateChooser.setXOffset(10);
ndExample1.DateChooser.setYOffset(-10);
ndExample1.DateChooser.setUpdateFunction(FunctionEx1);
document.getElementById('datelinkex1').onclick = ndExample1.DateChooser.display;
ndExample2.DateChooser.setCloseTime(200);
ndExample2.DateChooser.setXOffset(10);
ndExample2.DateChooser.setYOffset(-10);
ndExample2.DateChooser.setUpdateFunction(FunctionEx2);
document.getElementById('datelinkex2').onclick = ndExample2.DateChooser.display;
}
function FunctionEx1(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex1').value= objDate.getPHPDate('Y-n-j');
return true;
}
function FunctionEx2(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex2').value= objDate.getPHPDate('Y-n-j');
return true;
}
// -->
</script>
</HEAD>
<BODY>
<H1>Leave Tracker</H1>
<form name="MyForm" method="POST">
<select id="deptid" name="deptid">
<?
/* Select Department in dropdown list.*/
$depQy="select departmentid, name from department";
$res=mysql_query($depQy) or die("Query failed: ".mysql_error());
while ($row=mysql_fetch_array($res))
{
if($deptid==$row['departmentid'])
$ins="SELECTED";
else
unset($ins);
echo "<option $ins value='".$row['departmentid']."'>".$row['name']."</option>";
}
?>
</select>
<a id="datechooserex1">
<a id="datelinkex1" href="#">StartDate</a>
<input id="dateinputex1" name="dateinputex1" type="text" value="" class="datechooser dc-dateformat='Y-n-j'">
</a>
<a id="datechooserex2">
<a id="datelinkex2" href="#">EndDate</a>
<input id="dateinputex2" name="dateinputex2" type="text" value="" class="datechooser dc-dateformat='Y-n-j'">
</a>
<input type="submit" NAME="SUBMIT" value="Submit">
</form>
<?php
// Main Code starts here......
if($_POST)
{
$date1=$_POST['dateinputex1'];
$date2=$_POST['dateinputex2'];
$query = "select em.code, em.firstname, em.lastname, ela.startdate, ela.enddate, ela.status FROM empmaster as em INNER JOIN empleaveapplication as ela ON em.employeeid = ela.employeeid where (ela.startdate >='".$date1."') AND (ela.enddate <= '".$date2."') AND (em.departmentid =".$_POST['deptid'].") order by em.code ASC, ela.startdate ASC";
$result = mysql_query($query) or die("Query failed:".mysql_error());
echo "<table border='1' cellspacing='0'>";
// For each Employee, display Status Color for leave days from starttime to endtime.
echo "<th align='center' bordercolor='Black'>Code</th>";
echo "<th align='center' bordercolor='black'>FirstName</th>";
echo "<th align='center' bordercolor='black'>LastName</th>";
/*Here Code for generating Table-Headers for days starting from StartDate and EndDate.*/
$dt1=date_parse($date1);
$dt2=date_parse($date2);
for ($i=$dt1['day'];$i<($dt2['day']+1);$i++)
{
$i = str_pad($i, 2, 0, STR_PAD_LEFT);
echo "<th align='center' bordercolor='black'>".$i."</th>";
}
// echo "</table>";
echo "<table border='1' cellspacing='0'>";
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>".$rec['code']."</td>";
echo "<td align='center'>".$rec['firstname']."</td>";
echo "<td align='center'>".$rec['lastname']."</td>";
unset($sd);
unset($ed);
$sd=date_parse($rec['startdate']);
$ed=date_parse($rec['enddate']);
unset($diff);
$diff=($ed['day']-$sd['day'])+1;
unset($Colo);
// Choose color for TD cell as per status code...
if($rec['status']=='0') //No Color
{
$Colo='White';
}
elseif($rec['status']=='1') // Leave Approved
{
$Colo='Green';
}
elseif($rec['status']=='2') // Leave Pending
{
$Colo='Yellow';
}
elseif($rec['status']=='3') // Leave Rejected
{
$Colo='Red';
}
// Create TD cells starting from startdate till enddate....
echo str_repeat("<td> </td>",$sd['day']-1);
echo str_repeat("<td bgcolor=$Colo bordercolor=$Colo> </td>",$diff);
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "</tr>";
}
echo "</table>";
echo "</table>";
}
mysql_close($connection);
?>
</BODY>
</HTML>
Still need to align the TD cells & Headers, so that the colored TD cells come exactly under the dates...
Also, if you see Employee "zaki", 3 different colorings in 3 different rows...need to get them on a single row for zaki....
I hope this is clear...
Regards,
P.S: attached updated php file.
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 4:36 am
by onion2k
You do realise that we don't have access to your database so every time you upload any code that has the line "$db=mysql_select_db("timemate", $connection) or die ("Couldn't select database");" we'll just get that error message, right?
Stop asking the question in the context of your specific application; try to rephrase it in more general terms. We understand that you're trying to make an HTML Gantt chart. Is it right to say you want to have 1 table row per person, and the dates represented by the columns, with different colours to represent the status of the leave request? EG
Code: Select all
01/01 02/01 03/01 04/01 05/01 06/01 07/01
Person 1 [color=#40FF00]On holiday[/color]
Person 2 [color=#00FF00]On holiday[/color]
Person 3 [color=#FF0000]On holiday[/color]
Is that correct?
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 5:57 am
by sifar786
Yes. all the leave dates ranges for a person should fall on the same row.
If you look through the previous posts, i have already provided the database in the form of an sql file. Its in a zip folder by the name of timemate.zip. I dont have the database online on any server. I am trying to work it on my own pc using XAMPP.
Regards,
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 7:41 am
by it2051229
try this, i dont know if it works but the logic is correct....
Code: Select all
// do the query...
$query = "SELECT em.Code, em.FirstName, em.LastName, ela.StartDate, ela.EndDate, ela.status FROM EmpMaster as em INNER JOIN EmpLeaveApplication as ela ON em.EmployeeID = ela.EmployeeId where (ela.StartDate >='".$date1."') AND (ela.EndDate <= '".$date2."') AND (em.DepartmentID =".$_POST['DeptID'].")";
$result = mysql_query($query) or die(mysql_error());
// procceed only if there are queried results...
if(mysql_num_rows($result) > 0)
{
// if there are results, then set up the main array where to store another set of arrays
$mainArray = array();
for($i=0; $i < mysql_num_rows($result); $i++)
{
// set the queried attributes
$firstName = mysql_result($query,$i,"em.FirstName");
$startDate = mysql_result($query,$i,"ela.StartDate");
$endDate = mysql_result($query,$i,"ela.EndDate");
$status = mysql_result($query,$i,"ela.status");
// from the queried attributes, we set the sub array
$subArray = array($firstName, $startDate, $endDate, $status);
// then we insert insert into the main array the sub array
push_array($mainArray, $subArray);
}
// at this point you have achieved something like this inside the main array
/*
$leaves = array(
array("rose", '8/1/2008','8/3/2008', 0),
array("rose", '8/5/2008', '8/7/2008', 1),
array("rose", '8/9/2008', '8/11/2008', 1),
array("daisy", '8/2/2008', '8/4/2008', 2),
array("daisy", '8/6/2008', '8/8/2008', 0),
array("daisy", '8/3/2008', '8/3/2008', 0),
array("orchid", '8/15/2008', '8/20/2008', 1),
array("orchid", '8/11/2008', '8/19/2008', 2),
array("orchid", '8/10/2008', '8/20/2008', 1)
);
*/
}
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 8:21 am
by sifar786
Thnx pal,
Will try the same...though will this display all the date ranges for "Rose" in a single row & similarly for "Daisy" and so on..... ??
However, here's what i worked till NOW()...
Please find attached :
1] the Database files in form of a single SQL to be imported.
2] CSS files and the datechooser JS file.
3] PHP file.
As you will see, i cant put Border=1 for the (TH) Headers else the TD cells also get a Border, thereby removing the Blend of cell colors as you usually find in a Gantt.
Secondly, i have not been able to think of some logical loop to display the date ranges for each employee in a single row.
regards,
Code: Select all
<?php
$connection = mysql_connect("localhost","root","") or die ("Couldn't connect to server");
$db=mysql_select_db("timemate", $connection) or die ("Couldn't select database");
$deptid = $_POST['deptid'];
?>
<HTML>
<HEAD>
<TITLE>Leave Gantt!</TITLE>
<link rel="stylesheet" type="text/css" media="all" href="datechooser.css">
<link rel="stylesheet" type="text/css" media="all" href="table.css">
<script type="text/javascript" src="datechooser.js"></script>
<script type="text/javascript">
<!-- //
// DateChooser Code for selecting StartDate and EndDate.
events.add(window, 'load', WindowLoad);
function WindowLoad()
{
var ndExample1 = document.getElementById('datechooserex1');
var ndExample2 = document.getElementById('datechooserex2');
ndExample1.DateChooser = new DateChooser();
ndExample2.DateChooser = new DateChooser();
// Check if the browser has fully loaded the DateChooser object, and supports it.
if (!ndExample1.DateChooser.display || !ndExample2.DateChooser.display)
{
return false;
}
ndExample1.DateChooser.setCloseTime(200);
ndExample1.DateChooser.setXOffset(10);
ndExample1.DateChooser.setYOffset(-10);
ndExample1.DateChooser.setUpdateFunction(FunctionEx1);
document.getElementById('datelinkex1').onclick = ndExample1.DateChooser.display;
ndExample2.DateChooser.setCloseTime(200);
ndExample2.DateChooser.setXOffset(10);
ndExample2.DateChooser.setYOffset(-10);
ndExample2.DateChooser.setUpdateFunction(FunctionEx2);
document.getElementById('datelinkex2').onclick = ndExample2.DateChooser.display;
}
function FunctionEx1(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex1').value= objDate.getPHPDate('Y-n-j');
return true;
}
function FunctionEx2(objDate)
{
// objDate is a plain old Date object, with the getPHPDate() property added on.
document.getElementById('dateinputex2').value= objDate.getPHPDate('Y-n-j');
return true;
}
// -->
</script>
</HEAD>
<BODY>
<H1>Leave Tracker</H1>
<form name="MyForm" method="POST">
<select id="deptid" name="deptid">
<?
/* Select Department in dropdown list.*/
$depQy="select departmentid, name from department";
$res=mysql_query($depQy) or die("Query failed: ".mysql_error());
while ($row=mysql_fetch_array($res))
{
if($deptid==$row['departmentid'])
$ins="SELECTED";
else
unset($ins);
echo "<option $ins value='".$row['departmentid']."'>".$row['name']."</option>";
}
?>
</select>
<a id="datechooserex1">
<a id="datelinkex1" href="#">StartDate</a>
<input id="dateinputex1" name="dateinputex1" type="text" value="" class="datechooser dc-dateformat='Y-n-j'">
</a>
<a id="datechooserex2">
<a id="datelinkex2" href="#">EndDate</a>
<input id="dateinputex2" name="dateinputex2" type="text" value="" class="datechooser dc-dateformat='Y-n-j'">
</a>
<input type="submit" NAME="SUBMIT" value="Submit">
</form>
<?php
// Main Code starts here......
if($_POST)
{
$date1=$_POST['dateinputex1'];
$date2=$_POST['dateinputex2'];
$query = "select em.code, em.firstname, em.lastname, ela.startdate, ela.enddate, ela.status FROM empmaster as em INNER JOIN empleaveapplication as ela ON em.employeeid = ela.employeeid where (ela.startdate >='".$date1."') AND (ela.enddate <= '".$date2."') AND (em.departmentid =".$_POST['deptid'].") order by em.code ASC, ela.startdate ASC";
$result = mysql_query($query) or die("Query failed:".mysql_error());
/*Here Code for generating Table-Headers for days starting from StartDate and EndDate.*/
echo "<table border='1' cellspacing='0'>";
echo "<th bgcolor='#6698FF' align='center'>Code</th>";
echo "<th bgcolor='#6698FF' align='center'>FirstName</th>";
echo "<th bgcolor='#6698FF' align='center'>LastName</th>";
$dt1=date_parse($date1);
$dt2=date_parse($date2);
for ($i=$dt1['day'];$i<($dt2['day']+1);$i++)
{
$i = str_pad($i, 2, 0, STR_PAD_LEFT);
echo "<th bgcolor='#6698FF' align='center'>".$i."</th>";
}
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td class='namz' align='center'>".$rec['code']."</td>";
echo "<td class='namz' align='center'>".$rec['firstname']."</td>";
echo "<td class='namz' align='center'>".$rec['lastname']."</td>";
unset($sd);
unset($ed);
$sd=date_parse($rec['startdate']);
$ed=date_parse($rec['enddate']);
unset($diff);
$diff=($ed['day']-$sd['day'])+1;
unset($Colo);
// Choose color for TD cell as per status code...
if($rec['status']=='0') //No Leave
{
$Colo='White';
}
elseif($rec['status']=='1') // Leave Approved
{
$Colo='LightGreen';
}
elseif($rec['status']=='2') // Leave Pending
{
$Colo='Yellow';
}
elseif($rec['status']=='3') // Leave Rejected
{
$Colo='Red';
}
// Create TD cells starting from startdate till enddate....
// is for padding TD cells for proper alignment...
if ($sd['day']==$dt1['day'])
{
echo str_repeat("<td> </td>",0);
}
else
{
echo str_repeat("<td> </td>",abs(($sd['day']-$dt1['day']+1)-1));
}
echo str_repeat("<td bgcolor=$Colo bordercolor=$Colo> </td>",$diff);
echo "</tr>";
// Create a gap between rows.....
echo "<tr>";
echo "<td></td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($connection);
?>
</BODY>
</HTML>
Re: PHP leave tracking webpage
Posted: Sun Aug 24, 2008 10:04 am
by sifar786
Doesnt work!
Injected your code but gives errors on mysql_result.....
Also, push_array function shows as undefined function....googled and found no reference for it in online manual....though found array_push as a standard function. Is this correct?
However, please read my previous posts and download the database and files (timemate.zip) and see the output...will give you an understanding of where i am getting stuck!
regards,