<?php

/*
 * TODO :   Refactor
            main () {
                if (areAllEnviromentVaraiblesOKToGeneratePdf) {
                    getVaraiblesNeededToCreatePDF();
                    setupPdfConverter();
                    setupRealsizeVaribales();
                    Generate PDF
                }
            }
*/
require 'pdf/pdfcrowd.php';
require_once 'product-customizer/api/api-requests.php';
$apiRequests = new ApiRequests();
$idCus = $_GET['IDcus'];
$type = $_GET['type'];
//[pdf|pdfwb]
$realSize = isset($_GET['realSize']) ? $_GET['realSize'] : false;
//if ( $_GET['IDcli'] === $apiRequests->getIdCliFromBDPedidosCustom($idCus)[0]['ID_cli']) {
try {
    $client = new Pdfcrowd('dani3rs', '6cb8fce0fa072b77c4655a4da2631cb2');
    $productId = $apiRequests->getCustomization($_GET['IDcus'])[0]['ID_pro'];
    $productWidth = $apiRequests->getProduct($productId)[0][W_anchura];
    $productHeight = $apiRequests->getProduct($productId)[0][H_altura];
    $productUnits = $apiRequests->getProduct($productId)[0][Unidad];
    $productDiameter = $apiRequests->getProduct($productId)[0][D_diametro];
    $numPages = count($apiRequests->getViews($_GET['IDcus']));
    $pageWidth = 450;
    // 600 * 72 / 96
<?php

require_once 'Connections/bd_SELLOS.php';
require_once 'product-customizer/api/api-requests.php';
$apiRequests = new ApiRequests();
$error = '';
$idCustom = 0;
$idProvar = 0;
$idCart = 0;
$idPro = $_GET['IDpro'];
$env = $_GET['env'];
$idClient = isset($row_RecordsetUser['IDcli']) ? $row_RecordsetUser['IDcli'] : 0;
$hideAddToCart = isset($_GET['hideAddToCart']) ? $_GET['hideAddToCart'] : false;
$hideResetBtn = isset($_GET['hideResetBtn']) ? $_GET['hideResetBtn'] : false;
$productName = $apiRequests->getProduct($idPro)[0]['Producto_esp'];
if (!isset($_GET['env']) || $_GET['env'] == '' || !isset($_GET['IDpro']) || $_GET['IDpro'] == '' || is_null($productName)) {
    $error = 'Error Env o IDpro incorrectos';
} else {
    if ($env == 'webmaster') {
        if (isset($_GET['IDcus']) && $_GET['IDcus'] != '') {
            $idCustom = $_GET['IDcus'];
        } else {
            $idCustom = $apiRequests->getTemplateId($idPro)[0]['IDcus'];
            if ($idCustom === NULL) {
                $idCustom = 0;
                $error = 'Producto no tiene Customización template. No es customizable';
            }
        }
    }
    if ($env == 'front') {
        if (!isset($_GET['IDprovar']) || $_GET['IDprovar'] == '') {