Location: PHPKode > projects > Opensheet > opensheet/functions/date_day_chk.php
<?php
#ini_set('display_errors',1);
#error_reporting(E_ALL);
#require ('functions/db_connect.php');
#cколько дней в месяце
function get_days_month($year,$month)

{

	$day_in_month = date( 't', mktime(01,01,01,$month,01,$year) );
	return $days_in_month;
	echo $days_in_month;
}




#cколько дней в месяце
function day_in_month($year,$month)

{

	$day_in_month = date( 't', mktime(01,01,01,$month,01,$year) );
	return $day_in_month;
}



#проверяем является ли день выходным
function holyday_chk($day,$month,$year){
    $timestamp = mktime(01,01,01,$month,$day,$year);
	$today_day_name = date( 'l', $timestamp );	
	if ($today_day_name == 'Saturday' ) {
          $holyday = 'Y';
#        return $holyday;    
	} elseif ($today_day_name == 'Sunday' ) {
        $holyday = 'Y';
# return $holyday;
 #  echo $holyday;
} else {
    $holyday = 'N';  
 #  return $holyday;

}
 return $holyday;
}


# добавляем запись о выходных в базу
function add_holyday($date,$holyday)
{
	db_connect();
	$res ="INSERT INTO  `timesheet`.`holydays` (`date` ,`holyday`) VALUES ('$date',  '$holyday') ON DUPLICATE KEY UPDATE holyday = '$holyday';";
	#echo $res;
	$result = mysql_query($res);
}

# Берем список выходных и праздников, если нет в базе то вычисляет субботу и воскресенье

function holyday_get($date){
	db_connect();
	$query = "SELECT holyday FROM  `holydays` WHERE  `date` =  '$date'";
	$res = mysql_query($query);
    $res_row = mysql_fetch_row($res);
    $day = $res_row[0];
    
      if (!isset($day))
	    { 
	 $day = explode("-", $date);	
#	   print_r( $day); 	
	 $year =  $day['0'];
	 $month =  $day['1'];
	 $day = $day['2'];
	 $day =  holyday_chk($day,$month,$year);
   
	 }
	
   return $day;
}


function work_days_sum($year,$month){
		db_connect();
			$query = "SELECT count( date ) FROM `holydays` WHERE holyday = 'n' AND MONTH( DATE ) = '$month' AND YEAR(DATE) = '$year'";
			$res = mysql_query($query);
		    $res_row = mysql_fetch_row($res);
    		$work_days_sum = $res_row[0];
  			return $work_days_sum;
}

function get_holydays($year,$month){
	db_connect();
	$query = "SELECT holyday FROM  `holydays` WHERE YEAR( holydays.date ) =  '$year' AND MONTH( holydays.date ) =  '$month'";
	$res = mysql_query($query);
	$i='1';
	while($row = mysql_fetch_assoc($res)) { $days[$i++]=$row[holyday]; }
	if (!isset($days)){
	    $day_in_month = date( 't', mktime(01,01,01,$month,01,$year) );
		$day_in_month++;
		for ($i=1; $i<$day_in_month;$i++){
			$days[$i]=holyday_chk($i,$month,$year);
		}
	}
   return $days;
}




?>
Return current item: Opensheet