<?php
include("connect.php");

if (isset($_POST['value']) && $_POST['value'] != "") {

	$month = $_POST['value'];
	//$month = 11;
    
	$counter = 0;

if(($month == 1)||($month == 3)||($month == 5)||($month == 7)||($month == 8)||($month == 10)||($month == 12)){
		$monthdays = 31;
}

if($month == 2){
		$year = date("Y");
		if($year % 4 == 0){
		$monthdays = 29;
		}else{
		$monthdays = 28;
}
}
	
if(($month == 4)||($month == 6)||($month == 9)||($month == 11)){
		$monthdays = 30;
}

if($month==12){
	$year = date("Y") - 1;
	}else{
	$year = date("Y");
}

for($i=1;$i<$monthdays+1;$i++){
$date2 = "$year-$month-$i";
$ri2 = date( "w ",strtotime("$date2"));

if($ri2!=0){
$counter++;
}
//echo "$date2 $ri2";
//echo "<br/>";
}

//echo "<br/>";
//echo "$date $ri $counter";

	$arr = array(
    $q =>array(
        'counter'=>$counter,
		'start'=>"$year-$month-1",
		'end'=>"$year-$month-$monthdays",
		//'staff'=>$staffrate,
		//'owner'=>$ownerrate
    ),
	);
	
	
    foreach($arr as $k=>$v) {
        
        if ($k == trim($q)) {
			echo $v['counter'] . '|'. $v['start'] . '|' . $v['end'];
        } 
    }
}
?>