<?php
header('Access-Control-Allow-Origin: *');
header("Content-type: application/json; charset=utf-8");

error_reporting(0);

include '../../utils/database.php';
include '../../utils/helper.php';


$nextPage = "payment";


$ts = time();
$currntMonth = tsToShamsiMonth($ts);
$currntMonthName = monthNumberToMonthName($currntMonth);
$ts5MonthLaterNum = $currntMonth + 5;
$ts4MonthLaterNum = $currntMonth + 4;
$ts3MonthLaterNum = $currntMonth + 3;
$ts2MonthLaterNum = $currntMonth + 2;
if ($ts5MonthLaterNum > 12) {
  $ts5MonthLaterNum = $ts5MonthLaterNum - 12;
}
if ($ts4MonthLaterNum > 12) {
  $ts4MonthLaterNum = $ts4MonthLaterNum - 12;
}
if ($ts3MonthLaterNum > 12) {
  $ts3MonthLaterNum = $ts3MonthLaterNum - 12;
}
if ($ts2MonthLaterNum > 12) {
  $ts2MonthLaterNum = $ts2MonthLaterNum - 12;
}
$ts5MonthLater = monthNumberToMonthName($currntMonth + 5);
$ts4MonthLater = monthNumberToMonthName($currntMonth + 4);
$ts3MonthLater = monthNumberToMonthName($currntMonth + 3);
$ts2MonthLater = monthNumberToMonthName($currntMonth + 2);



$token = null;
$code = null;
$headers = apache_request_headers();

$language = "fa";

$bannerImage = "";

$persona = null;
$type = null;

$guaranteeTitle = "";
$guaranteeDescription = "";

$target = "";
$regimeType = "تقویت قدرت باروری";

$codeFirst = $_POST['code'];
if (sizeof($_POST) == 0) {
  $codeFirst = $_GET['code'];
}

$code = convertPersianToEnglish($codeFirst);

$plans = array();
$faqs = array();
$comments = array();
$horizontalComments = array();

$gender = "null";
$height = "";
$weightCurrent = "";
$weightGoal = "";
$programLength = "";
$diffWeight = "";


$description = "96.5 درصد از کاربران اپلیکیشن مینت، بارداریشون رو در سلامت کامل به پایان رسوندن";
$payCounter = "null";
$headerType = "lottie";

$todayDate = getPlanDate(time());
$zaimanDate = "";

$isLazy = "false";

$fitnessPlans = null;

$discount = "0";

$videoBaseLink = "https://file.mintapp.ir/Persona/";

$withoutProcessCodes = array("prevent");


$allAnswers = array();
$wyg = array();

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname_process);
// Check connection
mysqli_set_charset($conn, "utf8");
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}


$result_horizontal_comment = $conn->query("SELECT * FROM horizontal_comments WHERE `type`='text' ORDER BY id DESC");
$mainURL = "https://api.matchadiet.com/files/v2/comments/horizontal/main/";
$profileURL = "https://api.matchadiet.com/files/v2/comments/horizontal/profile/";
$socialURL = "https://api.matchadiet.com/files/social/";

if ($result_horizontal_comment->num_rows > 0) {
  while ($row_horizontal_comment = $result_horizontal_comment->fetch_assoc()) {
    $res_horizontal_comment["name"] = $row_horizontal_comment["name"];
    $profileImageInDB = $row_horizontal_comment["profile_image"];
    if (strlen($profileImageInDB) < 6) {
      $res_horizontal_comment["profileImage"] = "https://api.matchadiet.com/files/v2/profile/ph.png";
    } else {
      $res_horizontal_comment["profileImage"] = $profileURL . $profileImageInDB;
    }
    $socialLogoInDB = $row_horizontal_comment["social_logo"];
    if (strlen($socialLogoInDB) < 4) {
      $res_horizontal_comment["socialLogo"] = "https://api.matchadiet.com/files/social/telegram.svg";
    } else {
      $res_horizontal_comment["socialLogo"] = $socialURL . $row_horizontal_comment["social_logo"] . ".svg";
    }
    $res_horizontal_comment["mainImage"] = $mainURL . $row_horizontal_comment["main_image"];
    $res_horizontal_comment["comment"] = $row_horizontal_comment["comment"];
    $res_horizontal_comment["date"] = $row_horizontal_comment["date"];

    array_push($horizontalComments, $res_horizontal_comment);
  }
}

$response['success'] = 'true';
$response['message'] = '200';

$response['data'] =
  array(
    "horizontalComments" => array(
      "sectionTitle" => "جدیدترین نظرات کاربران ماچا",
      "items" => $horizontalComments
    ),
  );
$json_response = json_encode($response);
echo $json_response;
die();

$conn->close();
