<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once('../lib/dbclass.php');



$challenge_startdate = date('Y-m-d');


$data = findQuery("select * from  `tbl_challenge` where '$challenge_startdate'  between `challenge_startdate` and `challenge_enddate` and status=0");











if ($data) {
    for ($i = 0;$i < count($data);$i++) {
        $message = 'true';

        $product_name2   = '';
        $product_image2  = '';
        $product_amount2 = '';
        $delivary_date2  = '';

        if ($data[$i]['product_name2']) {
            $product_name2   = $data[$i]['product_name2'];
            $product_image2  = 'https://iumltuvvur.com//Challenge/upload/' . $data[$i]['product_image2'];
            $product_amount2 = $data[$i]['product_amount2'];
            $delivary_date2  = date('d-m-Y', strtotime($data[$i]['delivary_date2']));
        }
        $product_name3   = '';
        $product_image3  = '';
        $product_amount3 = '';
        $delivary_date3  = '';

        if ($data[$i]['product_name3']) {
            $product_name3   = $data[$i]['product_name3'];
            $product_image3  = 'https://iumltuvvur.com//Challenge/upload/' . $data[$i]['product_image3'];
            $product_amount3 = $data[$i]['product_amount3'];
            $delivary_date3  = date('d-m-Y', strtotime($data[$i]['delivary_date3']));
        }

        $data2[] = [



            'id'          => $data[$i]['id'],
'challenge_name'          => $data[$i]['challenge_name'],
'challenge_image'         => 'https://iumltuvvur.com//Challenge/upload/' . $data[$i]['challenge_image'],
'challenge_startdate'     => date('d-m-Y', strtotime($data[$i]['challenge_startdate'])),
'challenge_enddate'       => date('d-m-Y', strtotime($data[$i]['challenge_enddate'])),
'location'                => $data[$i]['location'],
'description'             => $data[$i]['description'],
'product_name1'           => $data[$i]['product_name1'],
'product_image1'          => 'https://iumltuvvur.com//Challenge/upload/' . $data[$i]['product_image1'],
'product_amount1'         => $data[$i]['product_amount1'],
'delivary_date1'          => date('d-m-Y', strtotime($data[$i]['delivary_date1'])),
'product_name2'           => $product_name2,
'product_image2'          => $product_image2,
'product_amount2'         => $product_amount2,
'delivary_date2'          => $delivary_date2,
'product_name3'           => $product_name3,
'product_image3'          => $product_image3,
'product_amount3'         => $product_amount3,
'delivary_date3'          => $delivary_date3,
'showdistrictandassembly' => $data[$i]['showdistrictandassembly'],









            ];
    }
} else {
    $message = 'false';
    $data2[] = ['error' => 'Not Found'];
}

echo json_encode(['Status' => $message, 'data' => $data2]);

return;

?>

