<?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  = siteurl . '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  = siteurl . 'Challenge/upload/' . $data[$i]['product_image3'];
            $product_amount3 = $data[$i]['product_amount3'];
            $delivary_date3  = date('d-m-Y', strtotime($data[$i]['delivary_date3']));
        }

        $data2[] = [



'product_name1'   => $data[$i]['product_name1'],
'product_image1'  => siteurl . 'Challenge/upload/' . $data[$i]['product_image1'],
'product_amount1' => $data[$i]['product_amount1'],
'prodid1'         => 1,
'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,
'prodid2'         => 2,
'product_name3'   => $product_name3,
'product_image3'  => $product_image3,
'product_amount3' => $product_amount3,
'delivary_date3'  => $delivary_date3,
'prodid3'         => 3,









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

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

return;

?>

