<?php
header("Access-Control-Allow-Origin: *");
 session_start();
 include '../config.php';
 $lang = $_GET['l'];
 $y = $_GET['y'];

 //echo $y;
 $fecha = $y."-01-01"; 
 $fecha2 = $y."-12-31";

 if(strlen($_GET['w'])>0){
    //echo "LALAOBA";
    $fecha = urldecode($_GET['w']);
    $fecha = date('Y-m-d', strtotime($fecha. ' - 1 days'));
    $fecha2 =date('Y-m-d', strtotime($fecha. ' + 7 days'));
 }

//echo $fecha;
//echo "<br>";
//echo $fecha2;
//echo urldecode($_GET['w']);
 //echo $lang;

	$curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $endpoint_graph_cms,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{"query":"query MyQuery {\\r\\n  avisosDepositantes(orderBy: fecha_DESC, first: 1500, stage: PUBLISHED,where: {fecha_gt: \\"'.$fecha.'\\", fijo_lt: 1, estatus: \\"publicado\\", fecha_lt: \\"'.$fecha2.'\\"} ) {\\r\\n    archivo\\r\\n    fijo\\r\\n  company\\r\\n    estatus\\r\\n    fecha\\r\\n    id\\r\\n    logo\\r\\n    resumen\\r\\n    slug\\r\\n    stage\\r\\n    titulo\\r\\n    localizations(locales: es_MX) {\\r\\n      archivo\\r\\n     fijo\\r\\n  company\\r\\n      estatus\\r\\n      fecha\\r\\n      id\\r\\n      logo\\r\\n      resumen\\r\\n      slug\\r\\n      stage\\r\\n      titulo\\r\\n    }\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
        CURLOPT_HTTPHEADER => array(
          'Content-Type: application/json',
          'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
        ),
      ));
      
      
   
  $responseavisoslist = curl_exec($curl);
 
  curl_close($curl);

$arraylist = json_decode($responseavisoslist, true);
//echo $responseavisoslist;
?>


<div class="col-lg-12">
                <div class="container" id="listado">

                <?php  include 'avisosfijos.php'; ?>

                <h1><?php echo $y;?></h1>

                <?php

                    foreach ($arraylist['data']['avisosDepositantes'] as $item) {

                      
                            if($lang == 'en'){

                                if(strlen($item['imagen'])<4){
                                    $imagen ="/assets/img/pdf.svg";
                                }
                                if(strlen($item['textoBoton'])<2){
                                    $boton ="Ver Aviso";
                                }
                                else{
                                    $boton = $item['textoBoton'];
                                }

                                if(strlen($item['texto'])>0){
                                    $text = '<p class="text-blue">'.urldecode($item['texto']).'</p>';
                                }

                                $myDateTime = DateTime::createFromFormat('Y-m-d', $item['fecha']);
                                $fecha_es = $myDateTime->format('d/m/Y');
                                echo '
                                <div class="col-md-12 comunicado-bg left">
                                    <div class="overlay"></div>

                                    
                                    <div class="col-md-10">
                                         
                                        <h5 class="text-blue my-3 text-uppercase"><span>'.$fecha_es.'</span><i class="datenum">'.urldecode($item['company']).'</i></h5>
                                        '.$text.'
                                        
                                        
                                    </div>

                                    <div class="col-md-2">
                                        
                                        <a target="_blank" class="btn btn-primary btn-xl text-uppercase js-scroll-trigger" href="'.$cloudfront.$item['archivo'].'"><i class="fas fa-file-download"></i></a>
                                    </div>
                                    
                                </div>';
                            }

                            if($lang == 'es'){

                                foreach ($item['localizations'] as $subitem) {
                                    if(strlen($subitem['imagen'])<4){
                                        $imagen ="/assets/img/pdf.svg";
                                    }
                                    if(strlen($subitem['textoBoton'])<2){
                                        $boton ="Ver Aviso";
                                    }
                                    else{
                                        $boton = $subitem['textoBoton'];
                                    }

                                    if(strlen($subitem['texto'])>0){
                                        $text = '<p class="text-blue">'.urldecode($subitem['texto']).'</p>';
                                    }

                                    $myDateTime = DateTime::createFromFormat('Y-m-d', $subitem['fecha']);
                                    $fecha_es = $myDateTime->format('d/m/Y');
                                
                            
                            echo '
                                <div class="col-md-12 comunicado-bg left">
                                    <div class="overlay"></div>

                                    
                                    <div class="col-md-10">
                                         
                                        <h5 class="text-blue my-3 text-uppercase"><span>'.$fecha_es.'</span><i class="datenum">'.urldecode($subitem['company']).'</i></h5>
                                        '.$text.'
                                        
                                        
                                    </div>

                                    <div class="col-md-2">
                                        
                                        <a target="_blank" class="btn btn-primary btn-xl text-uppercase js-scroll-trigger" href="'.$cloudfront.$subitem['archivo'].'"><i class="fas fa-file-download"></i></a>
                                    </div>
                                    
                                </div>';
                                }
                                
                            }
                    
                    }
                ?>

                
                </div>
				</div>
                
                
                			
        <style>
          
a.btndescarga i {
    padding: 0 10px;
    
}

.comunicado-bg.left {
    background-color: transparent;
    padding: 10px;
    margin-bottom: 0px;
    background-repeat: no-repeat;
    padding-left: 5%;
    background-size: 30% 100%;
    padding-right: 5%;
    box-shadow: 0;
    background-color: #eeeeee;
}
h5.text-blue.my-3.text-uppercase {
    color: #2b4365 !important;
    text-transform: none!important;
    padding: 0;
    margin: 0!important;
    font-size: 15px;
    padding-top: 7.5px;
}
.col-md-12, .col-md-10  , .col-md-2{
    float:left;
}
.rounded {
    border-radius: 50%!important;
    width: 100px;
    height: 100px;
    object-fit: cover;
    border: 8px solid #48aa42;
}
.col-md-12.comunicado-bg.left span {
    float: right;
    letter-spacing: 1.5px;
    font-family: "Montserrat", sans-serif;
    /* padding-right: 30px; */
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    color: #056474;
}
a.btn.btn-primary.btn-xl.text-uppercase.js-scroll-trigger {
    padding: 0;
    border: 0;
    font-size: 20px;
}
.col-md-12.comunicado-bg.left.even {
    background: #fff;
}
.datenum{
    color: #48aa42;
    font-style: normal;
    margin-right: 10px;
    font-weight: 500;
    font-size: 13px;
    text-transform:uppercase;
}
.col-lg-12.avisosfijos {
	padding-bottom: 20px;
	display: inline-block;
}
    </style>

    <script>
        //$('#listado .comunicado-bg:nth-child(even)').addClass('even');
        //$('#listado .comunicado-bg:nth-child(odd)').addClass('odd');
    </script>