<?php 
require 'config_db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['user_type'] == ''  or $data['member_id'] == '')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
    $mode = strip_tags(mysqli_real_escape_string($con,$data['mode']));
    if($mode == 1) {
        $member_id = strip_tags(mysqli_real_escape_string($con,$data['member_id']));
        $user_type = strip_tags(mysqli_real_escape_string($con,$data['user_type']));
        $name = strip_tags(mysqli_real_escape_string($con,$data['activity_name']));
        $total_limit = strip_tags(mysqli_real_escape_string($con,$data['total_limit']));
        
        $sql = "INSERT INTO `activities`(`member_id`,`name`,`total_limit`) 
                VALUES ('$member_id','$name','$total_limit')";
        $result = mysqli_query($con,$sql);
        
        if($result) {
            $returnArr = array(
    		"ResponseCode" => "200",
    		"Result" => "true",
    		"ResponseMsg" => "New Activity Added Successfully",
    		"data" => []);
        } else {
            $returnArr = array(
    		"ResponseCode" => "201",
    		"Result" => "false",
    		"ResponseMsg" => "New Activity Added Failure",
    		"data" => []);
        }
    } else if($mode == 2) {
        $member_id = strip_tags(mysqli_real_escape_string($con,$data['member_id']));
        $user_type = strip_tags(mysqli_real_escape_string($con,$data['user_type']));
        $actid = strip_tags(mysqli_real_escape_string($con,$data['activity_id']));
        $creaetedby = strip_tags(mysqli_real_escape_string($con,$data['created_by']));
        $name = strip_tags(mysqli_real_escape_string($con,$data['name']));
        $mobile = strip_tags(mysqli_real_escape_string($con,$data['mobile']));
        $description = strip_tags(mysqli_real_escape_string($con,$data['description']));
        
        $sql = "INSERT INTO `attendance_activity`(`created_by`,`activity_id`,`member_id`,`name`,`mobile`,`description`) 
                VALUES ('$creaetedby','$actid','$member_id','$name','$mobile','$description')";
        $result = mysqli_query($con,$sql);
        
        if($result) {
            $returnArr = array(
    		"ResponseCode" => "200",
    		"Result" => "true",
    		"ResponseMsg" => "Attendance Activity Added Successfully",
    		"data" => []);
        } else {
            $returnArr = array(
    		"ResponseCode" => "201",
    		"Result" => "false",
    		"ResponseMsg" => "Attendance Activity Added Failure",
    		"data" => []);
        }
    }
    
}
echo json_encode($returnArr);