<?php 
namespace AloVoice; 

$opts = json_decode($_REQUEST['PLACEMENT_OPTIONS'], true);
self::eLog($opts, "------ Events.php :: DocucemntGenerator MENU:");	

$chashe = '';

if (!0) {
    $chashe = '?'.time();
}
?>
<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DiDOX</title>
    <!-- Документ в DIDOX -->

    <script src="//api.bitrix24.com/api/v1/"></script>
    <script src="template/js/didox/e-imzo.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/e-imzo-client.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/libs/moment.js" type="text/javascript"></script> 
    <script src="template/js/didox/libs/ag-grid-community.js" type="text/javascript"></script> 
    <script src="template/js/didox/libs/jQuery.js" type="text/javascript"></script> 
    <script src="template/js/didox/helper.js<?php echo $chashe?>" type="text/javascript"></script> 

    <link rel="stylesheet" href="template/css/tailwind.css">
    <link rel="stylesheet" href="template/css/ag-grid.css">
    <link rel="stylesheet" href="template/css/ag-theme-material.css">
    <script>
        var docs = [], deal = {};
    </script>
</head>
<body>
    <noscript>Для работы прижения необходимо включить JavaScript</noscript>

    <div class="app">
        <?php
            if (!empty($opts["ENTITY_ID"])) {
                $doc = BxRest::call( 'crm.documentgenerator.document.list', array(
                    "filter"=>[
                        "entityId" => $opts["ENTITY_ID"]
                    ]
                ));
                $deal = BxRest::call( 'crm.deal.get', array(
                    "ID" => $opts["ENTITY_ID"]
                ));
                ?>
                <script>
                    // docs = JSON.parse('<?php echo json_encode($doc['result']['documents'])?>');
                    // deal  = JSON.parse('<?php echo json_encode($deal['result'])?>');
                </script>
                <div class="">
                    <h4 class="text-center text-2xl" id="deal_name"></h4>

                    <div class="absolute top-2 right-2" id="auth_container" style="display: none">
                        <div>
                            <span>Авторизация DIDOX:</span>
                            <select class="ml-1" name="" id="auth_select">
                                <!-- <option value="0"></option> -->
                            </select>
                        </div>
                    </div>
                </div>
                <div id="docs_table" class="ag-theme-material" style="height: 60vh; width:100%;"></div>
			<?php } else { ?>
               Нет документов.
			  <script> setTimeout(function(){ BX24.closeApplication() }, 3000); </script>
            <?php }
        ?>
    </div>
	
    <script src="template/js/didox/classes/App.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/classes/storage.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/classes/EAuth.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/classes/DocsTable.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/classes/DocSign.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/classes/Didox.js<?php echo $chashe?>" type="text/javascript"></script> 
    <script src="template/js/didox/main.js<?php echo $chashe?>" type="text/javascript"></script> 
    
    <script src="template/js/didox/libs/swal.js" type="text/javascript"></script>     
</body>
</html>
