<?
session_start();
require '../includes/init.php';
require '../includes/connect.php';

$linkDB = new ConnectDatabase();
$sql = "";
$sqlCondizione1 = "";
$txt_cod_cond1 = "";
$iCat = 0;
$sqlArticoli = "";

$sqlCondizione1 = ($txt_cod_cond1 != "NADA") ? " where codice='" . $txt_cod_cond1 . "'" : " ";
$sqlCondizione1 = "";

$sql = "select id,codice as cod_cat ,ucase(categ_it) as txt_catUPPER,categ_it as txt_cat,qta from codice_articoli  ;";

#echo $sql;
if ($stmt = $linkDB->query($sql)) {

	unset($vettcat);
	unset($vettcatTitle);
	unset($vettidcat);
	unset($vettqta);
	unset($vettcod);
	while ($row = mysqli_fetch_array($stmt)) {
		$vettcat[$iCat] = $row['txt_cat'];
		$vettcatTitle[$iCat] = $row['txt_catUPPER'];
		$vettidcat[$iCat] = $row['id'];
		$vettqta[$iCat] = $row['qta'];
		$vettcod[$iCat] = $row['cod_cat'];

		$iCat++;
	}

	mysqli_free_result($stmt);

}

$txt_cod_cond1 = (isset($_GET['c']) && !empty($_GET['c']) && in_array(substr($_GET['c'], 0, 2), $vettcod)) ? substr($_GET['c'], 0, 2) : "NADA";
#echo $txt_cod_cond1 . "    " . $_GET['c'];
?>
<!DOCTYPE html>
<html lang="<?echo $site_lang; ?>">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>News & noticias | LaBakeca.eu</title>
    <meta content="" name="description">
    <meta content="" name="keywords">
    <?require '../includes/inc_head.php';?>
    <style type="text/css">
    .posts-list>.macroTitle {
        background-color: #d9d5c8;
        padding: 1rem;
    }
    </style>
</head>

<body>
    <!-- ======= Header ======= -->
    <?require '../includes/inc_topbar.php';?>
    <main id="main">
        <!-- ======= Breadcrumbs ======= -->
        <div class="breadcrumbs">
            <div class="container">
                <div class="d-flex justify-content-between align-items-center">
                    <h2>Sección de noticias</h2>
                    <ol>
                        <li><a href="index">Home</a></li>
                        <li>Noticias</li>
                    </ol>
                </div>
            </div>
        </div><!-- End Breadcrumbs -->
        <?if (1 == 2 and $_SERVER['REMOTE_ADDR'] != "93.32.123.231") {?>
        <!-- ======= Blog Section ======= -->
        <section class="inner-page">
            <div class="container" data-aos="fade-up">
                <div class="section-header">
                    <h2>Novità in arrivo!</h2>
                </div>
                <div class="container-fluid cs img-fluid">
                </div>
                <div class="section-header pt-4 m-4" style="color:black;background-color: #0000000d;">
                    <a href="/signup/registrazione/index" class="">Iscriviti e Torna presto</a> per scoprire cosa bolle in pentola..
                </div>
            </div>
        </section><!-- End Inner Page -->
        <?} else {
	?>
        <!-- ======= Blog Section ======= -->
        <section id="blog" class="blog">
            <div class="container" data-aos="fade-up">
                <div class="row g-5">
                    <div class="col-lg-8">
                        <div class="row gy-4 posts-list">
                            <?
	if ($txt_cod_cond1 != "NADA") {
		$i = array_search($txt_cod_cond1, $vettcod);
		echo "<h2 class='macroTitle' id='" . $vettcod[$i] . "'>" . ($vettcatTitle[$i]) . "</a></h2><br>";
		$sqlArticoli = "select id,titolo,left(Corpo,160)as corpo from articoli_it where codice_categ=" . $vettidcat[$i] . ";";

		#echo $sqlArticoli;
		if ($stmt = $linkDB->query($sqlArticoli)) {

			while ($row = mysqli_fetch_array($stmt)) {
				echo '                            <div class="col-lg-6">
                                        <article class="d-flex flex-column">
                                        <div class="post-img">
                                        <img src="/assets/img/compressed/'.$row["id"]. '.png" alt="" class="img-fluid">
                                        </div>
                                        <h2 class="title">
                                        <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'">
                                        ' . $row['titolo'] . '</a>
                                        </h2>
                                        <div class="meta-top">
                                        <ul>
                                        <li class="d-flex align-items-center"><i class="bi bi-person"></i> <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'">Marco Roberti</a></li>
                                        <li class="d-flex align-items-center"><i class="bi bi-clock"></i> <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'"><time datetime="2022-01-01">' . rand(1, 31) . ' May, 2024</time></a></li>

                                        </ul>
                                        </div>
                                        <div class="content">
                                        <p>
                                        ' . $row['corpo'] . '..
                                        </p>
                                        </div>
                                        <div class="read-more mt-auto align-self-end">
                                        <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'">Leggi di pi&ugrave;</a>
                                        </div>
                                        </article>
                                        </div><!-- End post list item -->';
			}

			mysqli_free_result($stmt);

		}

	} else {

		for ($i = 0; ($i < $iCat); $i++) {
			echo "<h2 class='macroTitle' id='" . $vettcod[$i] . "'>" . ($vettcatTitle[$i]) . "</a></h2><br>";
			$sqlArticoli = "select id,titolo,left(Corpo,160)as corpo from articoli_it where codice_categ=" . $vettidcat[$i] . " limit 4;";

			#echo $sqlArticoli;
			if ($stmt = $linkDB->query($sqlArticoli)) {

				while ($row = mysqli_fetch_array($stmt)) {
					echo '                            <div class="col-lg-6">
                                        <article class="d-flex flex-column">
                                        <div class="post-img">
                                        <img src="/assets/img/compressed/' .$row["id"]. '.png/" alt="" class="img-fluid">
                                        </div>
                                        <h2 class="title">
                                        <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'">
                                        ' . $row['titolo'] . '</a>
                                        </h2>
                                        <div class="meta-top">
                                        <ul>
                                        <li class="d-flex align-items-center"><i class="bi bi-person"></i> <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'">Marco Roberti</a></li>
                                        <li class="d-flex align-items-center"><i class="bi bi-clock"></i> <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'"><time datetime="2022-01-01">' . rand(1, 31) . ' May, 2024</time></a></li>

                                        </ul>
                                        </div>
                                        <div class="content">
                                        <p>
                                        ' . $row['corpo'] . '..
                                        </p>
                                        </div>
                                        <div class="read-more mt-auto align-self-end">
                                        <a href="/'.$site_lang.'/blog-details?post='.$row["id"].'">Leggi di pi&ugrave;</a>
                                        </div>
                                        </article>
                                        </div><!-- End post list item -->';
				}

				mysqli_free_result($stmt);

			}

		}
	}

	?>
                    </div><!-- End blog posts list -->


                        <div class="blog-pagination">
                            <ul class="justify-content-center">
                                <li><a href="#">1</a></li>
                                <li class="active"><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                            </ul>
                        </div><!-- End blog pagination -->


                    </div>
                    <div class="col-lg-4">
                        <div class="sidebar">
                            <div class="sidebar-item search-form">
                                <h3 class="sidebar-title">Search</h3>
                                <form action="" class="mt-3">
                                    <input type="text">
                                    <button type="submit"><i class="bi bi-search"></i></button>
                                </form>
                            </div><!-- End sidebar search formn-->
                            <div class="sidebar-item categories">
                                <h3 class="sidebar-title">
                                    <??>
                                    <?if ($site_lang == "en") {?>
                                    Categories:
                                    <?} elseif ($site_lang == "es") {?>
                                    Categorías:
                                    <?} else {?>
                                    Categorie:
                                    <?}?>
                                </h3>
                                <ul class="mt-3">
                                    <?
	for ($i = 0; $i < $iCat; $i++) {
		echo "<li><a href='/" . $site_lang . "/blog/" . $vettcod[$i] . "'>" . $vettcat[$i] . "<span>(" . $vettqta[$i] . ")</span></a></li>";

	}
	?>
                                </ul>
                            </div><!-- End sidebar categories-->
                            <div class="sidebar-item recent-posts">
                                <h3 class="sidebar-title">Recent Posts</h3>
                                <div class="mt-3">
                                    <?

$sql = "select id,SUBSTRING_INDEX(titolo, ':', 1) as titolo from articoli_it order by rand() limit 4;";
$iArt=0;
#echo $sql;
if ($stmt = $linkDB->query($sql)) {

  unset($vettDd);
  unset($vettTitolo);

  while ($row = mysqli_fetch_array($stmt)) {
    $vettId[$iArt] = $row['id'];
    $vettTitolo[$iArt] = $row['titolo'];
    $iArt++;
  }

  mysqli_free_result($stmt);



  for ($i = 0; $i < $iArt; $i++) {
                 echo '<div class="post-item mt-3">
                    <img src="/assets/img/compressed/blog-recent-'.rand(1,4).'.jpg" alt="" class="flex-shrink-0">
                    <div>
                      <h4><a href="/'.$site_lang.'/blog-details?post='.$vettId[$i].'">'.$vettTitolo[$i].'</a></h4>
                      <time datetime="2024-05-'.rand(1,31).'">May '.rand(1,31).', 2024</time>
                    </div>
                  </div><!-- End recent post item-->';
  }
}
  ?>
                                </div>
                            </div><!-- End sidebar recent posts-->
                            <?if (1 == 2) {?>
                            <div class="sidebar-item tags">
                                <h3 class="sidebar-title">Tags</h3>
                                <ul class="mt-3">
                                    <li><a href="#">App</a></li>
                                    <li><a href="#">IT</a></li>
                                    <li><a href="#">Business</a></li>
                                    <li><a href="#">Mac</a></li>
                                    <li><a href="#">Design</a></li>
                                    <li><a href="#">Office</a></li>
                                    <li><a href="#">Creative</a></li>
                                    <li><a href="#">Studio</a></li>
                                    <li><a href="#">Smart</a></li>
                                    <li><a href="#">Tips</a></li>
                                    <li><a href="#">Marketing</a></li>
                                </ul>
                            </div><!-- End sidebar tags-->
                            <?}?>
                        </div><!-- End Blog Sidebar -->
                    </div>
                </div>
            </div>
        </section><!-- End Blog Section -->
        <?
}?>
    </main><!-- End #main -->
    <!-- ======= Footer ======= -->
    <footer id="footer" class="footer">
        <?require '../includes/inc_footer_' . $site_lang . '.php';?>
        <?require '../includes/inc_footer_copyright.php';?>
    </footer><!-- End Footer -->
    <a href="#" class="scroll-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
    <div id="preloader"></div>
    <!-- Vendor JS Files -->
    <?require '../includes/inc_script.php'?>
</body>

</html>