Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

PHP Timeline Application
Welcome, Guest. Please login or register.
December 03, 2008, 11:30:36 PM
11306 Posts in 1249 Topics by 499 Members
Latest Member: haulaslemycle
Experts Round Table Network  |  Serverside Technology  |  PHP  |  PHP Timeline Application « previous next »
Pages: [1]
Author Topic: PHP Timeline Application  (Read 224 times)
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« on: February 02, 2007, 06:20:00 AM »

Has anyone every came across a PHP Timeline Application?

Logged

seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #1 on: February 05, 2007, 01:44:06 AM »

Still no luck in finding an application that I can refer to.

What im doing is building my own one.  On our company Intranet, we have a holiday request form where the employees can submit dates that they will be on holiday. 

What im trying to do is give the director of the company a nice timeline application of all the holiday requests so he can browse each month and see very quickly what dates people have holidays booked on.

Now i can display the month horizontally across the screen, dates split up evenly, but im not sure how to manage the vertical side of things.

My plan is to have each new request its own row in the table, but i only want to display the current months holiday requests with each new request having its own rows in the display table.

What do you think?  Any other ideas?
Logged

COBOLdinosaur
ERT.com Admin

Offline Offline

Posts: 481



WWW
« Reply #2 on: February 05, 2007, 07:41:59 PM »

Sean, I'm not sure if I correctly understand what you want so if this is off the mark feel free to dump it in the trash.

It sounds like a vacation planner.  If that is what it is then for the db you you need:

TABLE_requests:

employee_id int(5)   // or what ever format you have now for IDs
year_month  int(4)
request_mask char(31) default "1111111111111111111111111111111"
/* any other columns you want to associate with the request.

The primary key is employee_id, year_month and an index on year month is handy

For a request for a given month the sql is simple:
Code:
select * from TABLE_requests
  where year_month = $yearmonth
   order by employee_id;
   
The request mask is a string where each byte is one or two. One they are in the office or two they are on holiday.  For the output you just create two CSS class to present a differnt look for the two states. You can then generate the cells for the month by looping for the number of days in the given month:
Code:
$dayArray = str_split($request_mask);
for ($i=1 $i<=$daysinmonth;$i++)
{
   $cls=($dayArray[$i-1]%2) ? 'inOffice' : 'holiday';
   print '<td class="'.$cellclass.'">&nbsp;</td>';
   
}
str_split() is PHP5, so if you are on < PHP5 you can add this code to create a function that returns the same array.

Code:

if (!function_exists("str_split")) {
  function str_split($str,$length = 1) {
   if ($length < 1) return false;
   $strlen = strlen($str);
   $ret = array();
   for ($i = 0; $i < $strlen; $i += $length) {
     $ret[] = substr($str,$i,$length);
   }
   return $ret;
  }
}
However if you are looking for something different let me know.

:^)

Cd&
« Last Edit: February 05, 2007, 07:44:19 PM by COBOLdinosaur » Logged
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #3 on: February 06, 2007, 12:43:34 AM »

Hi Roy,

I managed to get somewhere last night.  I already have my DB structure set up.  I can get the current month and the number of days in that month.  I then create a table with $number_of_days_in_month columns.  Depending on the number of events for that month, depends on the number of rows in the table - Basically i have a grid.

Now that point im having trouble at is filling in the days where the user is out of office.  i have managed to fill in the days if all the days are in same month, but when the days are spread over 2 different months : take 27/02/2007 - 11/03/2007 for example, its not so easy and i cant manage to get this working.

let me have another play about and if im still having trouble, i'll post some code.
Logged

seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #4 on: February 06, 2007, 01:36:40 AM »

Code:
$from_parts = explode('/',$zev_from);
$firstDate = $from_parts[2].'-'.$from_parts[1].'-'.$from_parts[0];

$to_parts = explode('/',$zev_to);
$lastDate = $to_parts[2].'-'.$to_parts[1].'-'.$to_parts[0];

$firstTimeStamp = strtotime($firstDate);
$lastTimeStamp = strtotime($lastDate);

for ($i = $firstTimeStamp; $i <= $lastTimeStamp; $i=$i+(24*60*60))
{
    $dates[] = date('Y-n-j',$i);
}

The above code gets all the dates from the "from date" to the "to date":

from date: 27-02-2007 & to date: 04-03-2007 and the dates inbetween using the above code are:

2007-2-27, 2007-2-28, 2007-3-1 ... 2007-3-4.

so next i loop through my days in the month, checking if current day/month/year is in the above list of dates ($dates) ...

Code:
$current_date = $out_of_office = '';

for($y = 1; $y < $days_in_month+1; $y++)
{
$current_date = $year.'-'.$current_month.'-'.$y;

for($idx = 0; $idx < count($dates); $idx++)
{
$out_of_office = '&nbsp;';

if($current_date == $dates[$idx])
{
$out_of_office = 'Y';
}
               
                $html .= ' <td>'.$out_of_office.'</td>'."\n";
}
}

But no days are filled in with Y.

please advice?
Logged

seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #5 on: February 06, 2007, 03:32:33 AM »

i got it working using the following:

Code:
for($y = 1; $y < $days_in_month+1; $y++)
{
$current_date = $year.'-'.$current_month.'-'.$y;

        $out_of_office = '&nbsp;';

for($idx = 0; $idx < count($dates); $idx++)
{
if($current_date == $dates[$idx])
{
$out_of_office = 'Y';
}
               
                $html .= ' <td>'.$out_of_office.'</td>'."\n";
}
}
Logged

Pages: [1]
« previous next »
    Jump to: