<?php
require_once '../_plugins/medoo.php';
require_once '../settings.php';

$mdb = new medoo( [
  'database_type' => 'mysql',
  'database_name' => $settings['db']['database'],
  'server' => $settings['db']['host'] ,
  'username' => $settings['db']['user'],
  'password' => $settings['db']['password'],
  'charset' => 'utf8'
] );

$product_id = (int)$_GET['product_id'];

if ( $product_id ) {
  $reviews = $mdb -> select( 'pakanaturypl', '*', [ 'product_id' => $product_id ], [ 'ORDER' => [ 'date_add' => 'DESC' ] ] );
} else {
  $reviews = $mdb -> select( 'pakanaturypl', '*', [ 'ORDER' => [ 'date_add' => 'DESC' ] ] );
}

for( $i = 0; $i < count( $reviews ); $i++ )
{
  $reviews[$i]['submitted'] = strtotime( $reviews[$i]['date_add'] );
}
echo json_encode( $reviews );
exit;