<?php
include_once("class/class.MySQL.php");
include_once("class/class.Message.php");
$db	=new MySQL();
$msg = new messaging();
//test 
//$action = $_GET['action'];


/*$resultdsg = mysql_query("SELECT * FROM project_plan_activity where proj_name='$_POST[proj_name]' ");
$rowsd = mysql_num_rows($resultdsg);

if($rowsd > 0)
{

$vars['proj_name']='Already Saved Data';
echo '{"timing":'.json_encode($vars).'}';
}
else
{
*/

$record_count = mysql_num_rows(mysql_query("SELECT * FROM project_plan_activity "));

$num_count = mysql_num_rows(mysql_query("SELECT * FROM project_plan_master "));
if($num_count==0)
{
	$data['date_from'] = date("Y-m-d",strtotime($_POST['resi_dats']));
	$data['date_to'] = date("Y-m-d",strtotime($_POST['wek_end']));
	$data['weeks'] = $_POST['wek_set'];

	$db->Insert($data,'project_plan_master');
	$pid = $db->LastInsertID();
}
else
{
$num_val = mysql_fetch_array(mysql_query("SELECT * FROM project_plan_master "));
$pid = $num_val['id'];
}


/*foreach($stges as $pr_stage)
{*/
 /*   $datas['mast_date_id']=$pid;
	$datas['dates_from'] = date("Y-m-d",strtotime($_POST['wek_from']));
	$datas['dates_to'] = date("Y-m-d",strtotime($_POST['wek_to']));
	$datas['project_id'] = $_POST['proj_ids'];
    $datas['e_id'] = $_POST['hid'];
	$datas['stage_id'] = $_POST['stage_id'];
    $datas['week_no'] = $_POST['wek_usr'];
	$datas['date_plan'] = date("Y-m-d",strtotime($_POST['asing_dat']));
	
	$db->Insert($datas,'project_plan_activity');*/
/*}*/


	 $datas['mast_date_id']=$pid;
	$datas['dates_from'] = date("Y-m-d",strtotime($_POST['wek_from']));
	$datas['dates_to'] = date("Y-m-d",strtotime($_POST['wek_to']));
	$datas['project_id'] = $_POST['proj_ids'];
    //$datas['e_id'] = $_POST['hid'];
	$datas['activities'] = $_POST['act_vity'];
    $datas['hurs'] = $_POST['hurs'];
	$datas['daily_wrk_dat'] = $_POST['daily_wrk_dat'];

 $count=count($datas['hurs']);
 $d_from =date("Y-m-d",strtotime($_POST['wek_from']));
 $d_to = date("Y-m-d",strtotime($_POST['wek_to']));
 
 $emp_id=$_POST['useridss'];
 

for($j=0;$j<$count;$j++)
{
	
	if($datas['activities'][$j]!='' && $datas['hurs'][$j]!='')
{
	 $d_dat = date("Y-m-d",strtotime($datas['daily_wrk_dat'][$j]));
	
	 mysql_query("INSERT INTO project_plan_activity (mast_date_id, dates_from, dates_to,project_id,e_id,week_no,date_plan,activities,hourss) VALUES('".$pid."','".$d_from."', '".$d_to."','".$datas['project_id'][$j]."','".$emp_id."','".$_POST['wek_usr']."','".$d_dat."','".$datas['activities'][$j]."','".$datas['hurs'][$j]."')");
}	 
	
}
	/*$datas['date_from'] = date("Y-m-d",strtotime($_POST['resi_dats']));
	$datas['date_to'] = date("Y-m-d",strtotime($_POST['wek_end']));
	$datas['weeks'] = $_POST['wek_set'];
	
	$datas['date_fromss'] = date("d-m-Y",strtotime($_POST['resi_dats']));
	$datas['date_toss'] = date("d-m-Y",strtotime($_POST['wek_end']));
	
$resultdsg = mysql_fetch_array(mysql_query("SELECT * FROM employee where e_id='$_POST[hid]' "));
$datas['emps'] = $resultdsg['e_fname'];

$resultproj = mysql_fetch_array(mysql_query("SELECT * FROM project_table where id='$_POST[proj_ids]' "));
$datas['projects'] = $resultproj['proj_name'];
$resultproj_stg = mysql_fetch_array(mysql_query("SELECT * FROM project_stage where id='$_POST[stage_id]' "));
$datas['projects_stage'] = $resultproj_stg['stage_id'];

$datas['r_counts']=$record_count;
	*/
echo '{"timing":'.json_encode($datas).'}';



//header('Location: add_project.php');
	

	
?>