<?php
header('Content-Type: application/json');

if ($_GET['email']) {

  $NETCAT_FOLDER = join(strstr(__FILE__, "/") ? "/" : "\\", array_slice(preg_split("/[\/\\\]+/", __FILE__), 0, -5)) . (strstr(__FILE__, "/") ? "/" : "\\");
  include_once($NETCAT_FOLDER . "vars.inc.php");
  require($INCLUDE_FOLDER . "index.php");

  $nc_core = nc_core::get_object();

  $MODULE_VARS = $nc_core->modules->get_module_vars()['dashamail'];

  $sql = "SELECT `User_ID` FROM `User` WHERE `" . $MODULE_VARS['USER_FIELD_EMAIL'] . "` = '" . $nc_core->db->escape($_GET['email']) . "' LIMIT 1";
  $user_id = $nc_core->db->get_var($sql);

  $sql = "SELECT `DashaMail_Online_ID` FROM `Module_DashaMail_Online` WHERE `User_ID` = ".$user_id." LIMIT 1";
  $online_user_id = $nc_core->db->get_var($sql);

  $cart = null;

  if ($online_user_id) {
    $dashamail_online = new dashamail_online();
    $dashamail_online->load($online_user_id);
    $cart = unserialize($dashamail_online->get('cart'));
  }
  
  echo json_encode($cart);
}
