<?php

require ('../credentials.php');
$con=mysqli_connect(HOST, USERNAME, PASSWORD, DBNAME)or die("cannot connect"); 

// array for JSON response

if(isset($_REQUEST['month']))
{  
	$title=$_REQUEST['title'];
	 $body=$_REQUEST['body'];
	$category=$_REQUEST['category'];
	  $image=$_REQUEST['image'];
	  $month=$_REQUEST['month'];
	 $day=$_REQUEST['day'];
		$date_inserted=$_REQUEST['date'];
	
	$bday=$day.'_'.$month;
	 $sql ="INSERT INTO news(title,description,image,date,birthday_target,category)";
    $sql .=" VALUES('$title','$body','$image','$date_inserted','$bday','$category')";   
 
 if ($con->query($sql) === TRUE) {
    //echo "New record created successfully";
    //$id = mysqli_insert_id($con);
	//echo $id;
	} else {
    echo "Error: " . $sql . "<br>" . $con->error;
	}

	
}else if(isset($_REQUEST['title']))
{  
     $title=$_REQUEST['title'];
	 $body=$_REQUEST['body'];
	 //$image=$_REQUEST['image'];
         $image='rccg-logo-min.jpg';
	  $category=$_REQUEST['category'];
	   $dept=$_REQUEST['department'];
	  $faculty=$_REQUEST['faculty'];
	  $level=$_REQUEST['level'];
	   $sex=$_REQUEST['sex'];
		$user=$_REQUEST['user'];

	  $target=$faculty."_".$dept."_".$level."_".$sex;

		//$date_inserted=$_REQUEST['date'];
          $date= time();
          $date=date_format($date,"Y/m/d H:i:s");
	 
    $sql ="INSERT INTO push_news(title,description,image,category,date,target_faculty, target_department, target_level, target_sex,target_user)";
    $sql .=" VALUES('$title','$body','$image','$category','$date_inserted','$faculty','$dept','$level','$sex','$user')";   

	//echo $sql;
 
 	
    if ($con->query($sql) === TRUE) {
    //echo "New record created successfully";
    //$id = mysqli_insert_id($con);
	//echo $id;
	} else {
    echo "Error: " . $sql . "<br>" . $con->error;
	}

     
}
mysqli_close($con);
?>
