This has been doing my head in for months!!!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

This has been doing my head in for months!!!!!!

Post by JayBird »

Okay here is the senario.

I am creating a calendar for our companys intranet that is going to be used to show what days people have had/going to have off. The calendar is a whole year view as shown below:

Image

I currently have my database set up like this

id
who <-- Persons name
from_date <--Date holiday starts
to_date <--Date holiday ends
fd_hd <--Is it a half day or full day off
fd_hd_when <--If it is a half day, is it AM or PM

If you want to see the code i use to generate the calendar shown in the image above, just ask, but i don't want code help really, i just want to know how you lot would go about inputting the data from the database into the calendar shown above.

I am open to suggestions for the database design or anything really cos i am totally stuck.

I did have a version working, but it didn't allow for 2 people to have the same day off.

Thanks

Mark[/img]
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

Hmmm.... I've been doing similar kind of stuff few months back, It needed to show a chart for some daily operations, for 10 days before and 10 after from current day. I had stucked on kind of same thing you are on, getting data from database in calander days. I quitely don't remember what exact workaround I had done for it, and unfortunately the code files are not with me currently.

But I guess I can get hold of those files, and once I get I'll let you know. Whatever I had done for that project, I'm sure I wasn't satisfied with way I had. Maybe we can get some better way to do it.
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

Bech,


I would probably output a line in the date such as follows


Jason Lewis 1/2 day 8:00am - 12:00pm
Mark Jones Full Day 8:00am - 12:00pm


so on and so forth. Now im curious, any chance you will be realeasing your finished code or even what you have now? I have seen alot of people searching for something along these lines, myself included ;)


Saethyr
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Saethyr wrote:Bech,


I would probably output a line in the date such as follows


Jason Lewis 1/2 day 8:00am - 12:00pm
Mark Jones Full Day 8:00am - 12:00pm


so on and so forth. Now im curious, any chance you will be realeasing your finished code or even what you have now? I have seen alot of people searching for something along these lines, myself included ;)


Saethyr
I know how i wanna display, i just don't really know the way of going about gettting the data from the DB then inputting the info into the correct dated cells.

here is the code to produce the table as show in the image in my first post. There seems to be a problem with March 2004 for some reason.

Code: Select all

<?

$BasePath = str_repeat("../", substr_count(dirname($_SERVER["SCRIPT_NAME"]), "/"));

//require ($BasePath."ocdaintranet/includes/db_connection.php");

// Get todays date
$todaysEpoch = time();
$todaysEpochArray = getdate($todaysEpoch);

if(!isset($_GET['year'])) { // If no year on query string, get this year
	$year = $todaysEpochArray['year'];
} else {
	$year = $_GET['year'];
}

?>

<html>
<head>
<title>Holiday Chart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="/ocdaintranet/styles/stylesheet.css" rel="stylesheet" type="text/css">
<link href="/ocdaintranet/styles/calendar.css" rel="stylesheet" type="text/css">
<style type="text/css"> 
<!-- 
.button { cursor:hand; background-color: #DBEDFF } 
.buttonover { cursor:hand; background-color: #CEE7FF } 
.buttonweekend { background-color: #FFD5D5 } 
.buttonoverweekend { cursor:hand; background-color: #FFC5C5 }
.nodate { background-color: #DDDEDF } 
--> 
</style> 
<script language="JavaScript">
<!-- Change the row colour on mouseOver/Out
 
function BGNew(obj, new_style) { 
obj.className = new_style; 
} 

//-->
</script>
</head>
<body onLoad="MM_preloadImages('/ocdaintranet/images/winxp/btn_add_over.gif')">

<? //require ($BasePath."ocdaintranet/menu/menu.php"); ?>

<h1 class="heading">Holiday Chart - <? echo $year; ?></h1>
<table width="604" border="0" cellpadding="0" cellspacing="0" class="icons">
  <tr>
    <td class="commandBtn"><table width="52" border="0" cellspacing="0" cellpadding="1">
      <tr align="center">
        <td width="50"><a href="add_date.php" onMouseOver="MM_swapImage('calendList011','','/ocdaintranet/images/winxp/btn_add_over.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="/ocdaintranet/images/winxp/btn_add_norm.gif" alt='Add' name="calendList011" width="23" height="23" border="0" id="calendList01"></a></td>
        </tr>
      <tr align="center">
        <td width="50">Add</td>
        </tr>
    </table>      
    <div id="calendListtt" class="rel"></div>
    </td>
    <td class="commandDesc" align="right" width="99%"><?
	// Output the number of days left for each person
	if (is_array($count)) {
		echo "<strong>Days left</strong> ::"; 
		foreach ($count as $key=>$val) {
			echo $key."//<strong>".(21-$val)."</strong> :: ";
		}
	}
	?></td>
  </tr>
</table>

<?php

echo "<table width="100%">";
echo "\t<tr>\n";

$dayArray = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");

$dayMonths = 1;
$day = 0;

// Month dates that start incrementing when the first day is reached
$january = 1;
$february = 1;
$march = 1;
$april = 1;
$may = 1;
$june = 1;
$july = 1;
$august = 1;
$september = 1;
$october = 1;
$november = 1;
$december = 1;

$month = 1;

// Output column headings (Months)
echo "\t\t<td width="4%">&nbsp;</td>\n";
while ($month <= 12) {
	echo "\t\t<td width="8%" align="center" class="odd">";
	echo date("M", mktime(0,0,0,$month,1,$year));
	echo "</td>\n";
	$month++;
}
echo "\t</tr>\n";

while ($dayMonths <= 37) { // The maximum number of cells any month will need is 37

	if ($day == 0 || $day > 6) { // If day = sunday, start back at monday
		$day = 0;
		$checkDay = $dayArray[$day];
	} else {
		$checkDay = $dayArray[$day];
	}
	
	// If saturday or Sunday change cell color
	if ($checkDay == "Sun" || $checkDay == "Sat") {
			$td_colour_weekend = "buttonweekend";
			$tr_out = "buttonweekend";
		} else {
			$td_colour_weekend = "even";
			$tr_out = "even";
	}
	echo "\t<tr>\n";
	echo "\t\t<td width="4%" class="odd" align="right">$checkDay</td>\n";

	// January check
			
	// If the current day number is equal to the name of the day and we are still in the same month, output the date
	if (date("D", mktime(0,0,0,1,$january,$year)) == $checkDay && date("M", mktime(0,0,0,1,$january,$year)) == "Jan") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,1,$january,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}
				
		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$tr_out."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,1,$january,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$january++;

	} else { // Otherwise, print a blank cell
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// February check
	if (date("D", mktime(0,0,0,2,$february,$year)) == $checkDay && date("M", mktime(0,0,0,2,$february,$year)) == "Feb") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,2,$february,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,2,$february,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$february++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// March check
	if (date("D", mktime(0,0,0,3,$march,$year)) == $checkDay && date("M", mktime(0,0,0,3,$march,$year)) == "Mar") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,3,$march,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,3,$march,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$march++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// April check
	if (date("D", mktime(0,0,0,4,$april,$year)) == $checkDay && date("M", mktime(0,0,0,4,$april,$year)) == "Apr") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,4,$april,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,4,$april,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$april++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// May check
	if (date("D", mktime(0,0,0,5,$may,$year)) == $checkDay && date("M", mktime(0,0,0,5,$may,$year)) == "May") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,5,$may,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,5,$may,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$may++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// June check
	if (date("D", mktime(0,0,0,6,$june,$year)) == $checkDay && date("M", mktime(0,0,0,6,$june,$year)) == "Jun") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,6,$june,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}
		
		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,6,$june,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$june++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// July check
	if (date("D", mktime(0,0,0,7,$july,$year)) == $checkDay && date("M", mktime(0,0,0,7,$july,$year)) == "Jul") {
	
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,7,$july,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,7,$july,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$july++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
		}			
			
	// August check
	if (date("D", mktime(0,0,0,8,$august,$year)) == $checkDay && date("M", mktime(0,0,0,8,$august,$year)) == "Aug") {

		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,8,$august,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,8,$august,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$august++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// September check
	if (date("D", mktime(0,0,0,9,$september,$year)) == $checkDay && date("M", mktime(0,0,0,9,$september,$year)) == "Sep") {
		
		
		// Check to see if a holiday occurs on this day
		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,9,$september,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}
		
		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,9,$september,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
		
		
		$september++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// October check
	if (date("D", mktime(0,0,0,10,$october,$year)) == $checkDay && date("M", mktime(0,0,0,10,$october,$year)) == "Oct") {

		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,10,$october,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}
		
		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,10,$october,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$october++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// November check
	if (date("D", mktime(0,0,0,11,$november,$year)) == $checkDay && date("M", mktime(0,0,0,11,$november,$year)) == "Nov") {

		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,11,$november,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,11,$november,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$november++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
	// December check
	if (date("D", mktime(0,0,0,12,$december,$year)) == $checkDay && date("M", mktime(0,0,0,12,$december,$year)) == "Dec") {

		if (is_array($days_off)) {
			$currentDay=date("z", mktime(0,0,0,12,$december,$year)); 
			if (in_array($currentDay,$days_off)){ 
				$key=array_search($currentDay,$days_off); 
				$name = $who_sorted[$key];
				$td_colour_weekend_old = $td_colour_weekend;
				$td_colour_weekend = "buttonover";
				$tr_out = "buttonover";
			}
		}

		echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
		echo "<div align="right">".$name."&nbsp;&nbsp;".date("d", mktime(0,0,0,12,$december,$year))."</div>";
		echo "</td>\n";
		
		if (!empty($name)) {
			$td_colour_weekend = $td_colour_weekend_old;
		}
		
		$name = "";
			
		$december++;

	} else {
		echo "\t\t<td width="8%" class="nodate">&nbsp;</td>\n";
	}
			
echo "\t</tr>\n";
			
$day++;
$dayMonths++;
}

echo "</table>";

?>
<table cellspacing="0" width="100%" border="0" cellpadding="0">
  <tr>
    <td nowrap align="right" class="footerCell"><a href="holiday_chart.php?year=<? echo ($year-1); ?>"><< Previous year</a> | <a href="holiday_chart.php?year=<? echo $todaysEpochArray['year']; ?>">This Year</a> | <a href="holiday_chart.php?year=<? echo ($year+1); ?>">Next year >></a></td>
  </tr>
  <tr>
    <td height="5" colspan="2"><img width="1" height="5" border="0" src="../themes/winxp/spacer.gif" alt=""></td>
  </tr>
</table>

</body>
</html>
It's quite long and i am not sure if there is a way i can shorten it.

Mark
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Re: This has been doing my head in for months!!!!!!

Post by scorphus »

Bech100 wrote:(...) I am open to suggestions for the database design (...)
About db design, I suggest you change the way you control half-day/full-day. Take a look:

Code: Select all

mysql&gt; desc holyday;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned |      | PRI | NULL    | auto_increment |
| fd_hd | char(2)          | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

mysql&gt; select fd_hd from holyday;
+-------+
| fd_hd |
+-------+
| AM    |
| PM    |
| FD    |
+-------+
3 rows in set (0.00 sec)

mysql&gt; select fd_hd, case fd_hd when 'AM' then 'Half day / AM' when 'PM' then 'Half day / PM' when 'FD' then 'Full day' end as fd_hd_ext from holyday;
+-------+---------------+
| fd_hd | fd_hd_ext     |
+-------+---------------+
| AM    | Half day / AM |
| PM    | Half day / PM |
| FD    | Full day      |
+-------+---------------+
3 rows in set (0.01 sec)
Bech100 wrote:(...) how you lot would go about inputting the data from the database into the calendar (...)
I think you are talking about design and data positioning issues. You can set three span classes in CSS (i.e. full_half_AM, full_half_PM and full_half_FU) to define color and font settings for distinguish each holyday 'type' and echo the name of each employee inside the cells, something like:

Code: Select all

<span class="full_half_<?php echo $someArray['fd_hd']; ?>"><?php echo $someArray['who']; ?></span>
Then with a legend cell i.e.

Code: Select all

<?php
foreach (...)
	echo "<span class="full_half_${someArray['fd_hd']}">${someArray['fd_hd_ext']}</span><br />\n";
?>
on the table footer, it is one less information to be inserted as text.

I imagine something like this:

Image

This reply took some time to implement/edit, fella, so I really hope it helps. And please excuse my English (I hope it is clear enough).

Cheers,
Scorphus.

[edit]Some corrections.[/edit]
Last edited by scorphus on Fri Jan 09, 2004 9:00 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Thanks for the in-depth reply buddy, some good ideas i will implement there.

Still. the main problem is, in what way should i grab all the days that people are having off and input them into the calenday. Not how they will look.

For example, i wouldn't want to do a query for every single day to see if someone was having that day off. I would like to do just one query at the start and read the data into an array.

I think using day numbers would be the best way. So i might have an array with all the day numbers (1-365), then each day, check to see if that number is in the array.

As i said before i had this working (not including full days and half days) but couldn't get it to work if two people were off on the same day.

So basically, what i need to know now is, how should i grab the data from the DB, and how should i check on each day whether someone is on holiday.

Mark
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Hmmm, got what you mean, Mark. I'll put my brain to work, try somethings here and get back to soon.
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

Bech,
I am an idiot and read your post completely wrong ;)

Saethyr
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Nothing that actually would share light to your questions, but;

Code: Select all

/*
Got this error in the top of the March column. And based on your earlier post "There seems to be a problem with March 2004 for some reason." this might be something to look into. Error levels bumped up?
As the error is not shown in any other column, it's might be where it's set that have issues.

Notice: Undefined variable: name in test.php on line 212

212 being this line:
*/
      echo "<div align="right">".$name."  ".date("d", mktime(0,0,0,3,$march,$year))."</div>";
So it's intranet and yo likely know what you are doing, but just to mention it for others testing the code (and for future reference if shot tags are removed completely):

Code: Select all

// often bad
<?
// usually better
<?php
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Thanks for the info JAM, this code is still very much in the early stages, once i have got it working, then i need to go back over it and neaten and shorten it.

mark
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Mark, while alternating into my school project and your code I came into a working code, take a look.

The db disign and data:

Code: Select all

CREATE TABLE holyday (
  idholyday INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  who VARCHAR(32) NULL,
  from_date DATE NULL,
  to_date DATE NULL,
  fd_hd CHAR(2) NULL,
  PRIMARY KEY(idholyday)
);

insert into holyday values(null, 'William', '20041230', '20041230', 'PM');
insert into holyday values(null, 'William', '20041231', '20041231', 'AM');
insert into holyday values(null, 'Patricia', '20041231', '20041231', 'AM');
insert into holyday values(null, 'Caroline', '20041231', '20041231', 'FD');
insert into holyday values(null, 'John', '20041231', '20041231', 'FD');
The code:

Code: Select all

<?
function getYearData () {
	mysql_connect('localhost', 'root');
	mysql_select_db('test');
	$sql = "select who, from_date, to_date, fd_hd,
		case fd_hd
			when 'AM' then 'Half day / AM'
			when 'PM' then 'Half day / PM'
			when 'FD' then 'Full day'
		end as fd_hd_ext
	from holyday order by to_date";
	$result = mysql_query($sql) or die(mysql_error());
	$table = array();
	while ($table[] = mysql_fetch_assoc($result));
	array_pop($table);
	$year = array_fill(0, 365, array());
	foreach ($table as $value) {
		$yearDayFrom = date('z', strtotime($value['from_date']));
		$yearDayTo = date('z', strtotime($value['to_date']));
		for ($day = $yearDayFrom; $day <= $yearDayTo; $day++)
			$year[$day][] = $value;
	}
	return $year;
}

$yearData = getYearData();

/* ...
... */

   // December check
   if (date("D", mktime(0,0,0,12,$december,$year)) == $checkDay && date("M", mktime(0,0,0,12,$december,$year)) == "Dec") {

      if (is_array($days_off)) {
         $currentDay=date("z", mktime(0,0,0,12,$december,$year));
         if (in_array($currentDay,$days_off)){
            $key=array_search($currentDay,$days_off);
            $name = $who_sorted[$key];
            $td_colour_weekend_old = $td_colour_weekend;
            $td_colour_weekend = "buttonover";
            $tr_out = "buttonover";
         }
      }

      echo "\t\t<td width="8%" align="top" class="".$td_colour_weekend."" onMouseOver="BGNew(this,'buttonover')" onMouseOut="BGNew(this,'".$td_colour_weekend."')" onclick="location='view_contact.php?id=".$line['id']."'">";
      echo "<div align="right">".$name."  ".date("d", mktime(0,0,0,12,$december,$year))."</div>";
      $yearDay = date('z', mktime(0,0,0,12,$december,$year));
      foreach ($yearData[$yearDay] as $value)
      	echo "\t\t<span class="full_half_" . $value['fd_hd'] . "">" . $value['who'] . "</span><br />\n";
      echo "\t\t</div>\n</td>\n";

/* ...
... */

?>
Sorry for not adding comments :P. See if it fits your needs.

Regards,
Scorphus.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Thanks buddy, cant try it until i go to work on monday now, but ill let you know how it goes

Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

will that code allow for 2 people to have the same day off?

Mark
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

I think it does, since 5 employees have holyday on December 31 and I get this printed:

Image

Have no CSS here, so things didn't get in color.

Cheers,
Scorphus.

[edit]corrections...[/edit]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

That code seems to be working really well, thank you very much.

Just one more slight problem, any idea how i can make the code you gave me exclude saturdays and sundays!?

Also code you explain what some of the code does.

I don't fully undertand this Query, especially the "case", "when" and "end as" parts.

Code: Select all

$sql = "select who, from_date, to_date, fd_hd, 
      case fd_hd 
         when 'AM' then 'Half day / AM' 
         when 'PM' then 'Half day / PM' 
         when 'FD' then 'Full day' 
      end as fd_hd_ext 
   from holyday order by to_date";
Also, i cant figure out why you need to do

Code: Select all

array_pop($table);
Mark
Post Reply