<?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_table where proj_name='$_POST[proj_name]' ");
$rowsd = mysql_num_rows($resultdsg);

$num_val = mysql_fetch_array(mysql_query("SELECT * FROM project_plan_master "));
$pid = $num_val['id'];


 $data['week_id'] = $_POST['sel_wek'];
 $data['dat_from'] =date("Y-m-d",strtotime($_POST['date_frm']));
 $data['dat_to'] = date("Y-m-d",strtotime($_POST['date_tos']));
$data['project_id'] = $_POST['proj_ids'];
$data['hur_s'] = $_POST['hurs'];
$data['stages_ids'] = $_POST['projstage_id'];
$data['activities'] = $_POST['act_vity'];
$data['hourss'] = $_POST['hurs_task'];
$data['status_proj'] = $_POST['stat_act'];
$emp_id=$_POST['userid'];
$data['p_act_id']=$_POST['p_main_id'];
 $data['d_daily'] = $_POST['daily_wrk_dat'];
 $d_from =date("Y-m-d",strtotime($_POST['date_frm']));
 $d_to = date("Y-m-d",strtotime($_POST['date_tos']));

$data['task_detail'] = $_POST['task_detail'];

$cur_dat =date("Y-m-d");

  $count=count($data['project_id']);
	//$db->Insert($data,'project_activity_done');
	//$pid = $db->LastInsertID();

//print_r($data);

$stges=$_POST['proj_stage'];
$projstage_id=$_POST['projstage_id'];
for($j=0;$j<$count;$j++)
{
if($data['hourss'][$j]!='' && $data['activities'][$j]!='')
{
 $d_dat = date("Y-m-d",strtotime($data['d_daily'][$j]));
  mysql_query("INSERT INTO project_activity_done (week_id, dat_from, dat_to,project_id,stages_ids,activities,hourss,status_proj,emp_id,p_act_id,daily_dat) VALUES('".$_POST['sel_wek']."', '".$d_from."', '".$d_to."','".$data['project_id'][$j]."','".$data['stages_ids'][$j]."','".$data['activities'][$j]."','".$data['hourss'][$j]."','".$data['status_proj'][$j]."','".$emp_id."','".$data['p_act_id'][$j]."','".$d_dat."')");
  
    
      mysql_query("UPDATE project_plan_activity SET flag1 = 1 WHERE id = '".$data['p_act_id'][$j]."'");
   
  }
  
  $result_plan = mysql_fetch_array(mysql_query("SELECT * FROM project_plan_activity where id='".$data['p_act_id'][$j]."' "));
  if($result_plan['id']=='' && $data['project_id'][$j]!='')
  {
    $datas['mast_date_id']=$pid;
	$datas['dates_from'] = $d_from;
	$datas['dates_to'] = $d_to;
	$datas['project_id'] = $data['project_id'][$j];
    $datas['e_id'] = $emp_id;
	//$datas['stage_id'] = $data['stages_ids'][$j];
    $datas['week_no'] = $_POST['sel_wek'];
	if($data['hourss'][$j]!='' && $data['activities'][$j]!='')
	{
	$datas['flag1'] = 1;
	}
	else
	{
	$datas['flag1'] = 0;
	}
	$datas['activities'] = $data['task_detail'][$j];
	
	$datas['hourss'] = $data['hur_s'][$j];
	
	$db->Insert($datas,'project_plan_activity');
  }
}

/* $pjt_id=join(',',$_POST['projs']);
$resultdsg = $db->fetchQuery("SELECT proj_name,id FROM project_table");
foreach($resultdsg as $results){
$data['projects'][$results['id']]=$results['proj_name'];
}

$result_stg = $db->fetchQuery("SELECT stage_id,id FROM project_stage");
$j=1;
foreach($result_stg as $result_st)
{
$data['stags'][$result_st['id']]=$result_st['stage_id'];
}
*/
/*foreach($stges as $pr_stage)
{
	$datas['mproj_id'] = $pid;
	$datas['stage_id'] = $pr_stage;


	$db->Insert($datas,'project_stage');
}*/
echo '{"timing":'.json_encode($data).'}';



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

	
?>