<?php
/*
 --------------------------------------------------------------------------
  GAzie - MODULO 'VACATION RENTAL'
  Copyright (C) 2022-2023 - Antonio Germani, Massignano (AP)
  (https://www.programmisitiweb.lacasettabio.it)

  --------------------------------------------------------------------------
  --------------------------------------------------------------------------
  GAzie - Gestione Azienda
  Copyright (C) 2004-present - Antonio De Vincentiis Montesilvano (PE)
  (https://www.devincentiis.it)
  <https://gazie.sourceforge.net>
  --------------------------------------------------------------------------
  Questo programma e` free software;   e` lecito redistribuirlo  e/o
  modificarlo secondo i  termini della Licenza Pubblica Generica GNU
  come e` pubblicata dalla Free Software Foundation; o la versione 2
  della licenza o (a propria scelta) una versione successiva.

  Questo programma  e` distribuito nella speranza  che sia utile, ma
  SENZA   ALCUNA GARANZIA; senza  neppure  la  garanzia implicita di
  NEGOZIABILITA` o di  APPLICABILITA` PER UN  PARTICOLARE SCOPO.  Si
  veda la Licenza Pubblica Generica GNU per avere maggiori dettagli.

  Ognuno dovrebbe avere   ricevuto una copia  della Licenza Pubblica
  Generica GNU insieme a   questo programma; in caso  contrario,  si
  scriva   alla   Free  Software Foundation, 51 Franklin Street,
  Fifth Floor Boston, MA 02110-1335 USA Stati Uniti.
  --------------------------------------------------------------------------
 */
//require("../../library/include/datlib.inc.php");
include ("../../config/config/gconfig.myconf.php");

include_once("manual_settings.php");
$azTables = constant("table_prefix").$idDB;
$IDaz=preg_replace("/[^1-9]/", "", $azTables );

$servername = constant("Host");
$username = constant("User");
$pass = constant("Password");
$dbname = constant("Database");
$genTables = constant("table_prefix")."_";

// Create connection
$link = mysqli_connect($servername, $username, $pass, $dbname);
// Check connection
if (!$link) {
    die("Connection DB failed: " . mysqli_connect_error());
}
// $img1px è una stringa equivalente ad una immagine jpg di 1 pixel
// e serve per evitare la visualizzazione dell'immagine di dafault del browser
// quando non la trova
$img1px= pack("c*",0xFF,0xD8,0xFF,0xE0,0x00,0x10,0x4A,0x46,0x49,0x46,0x00,0x01,0x02,
              0x00,0x00,0x64,0x00,0x64,0x00,0x00,0xFF,0xEC,0x00,0x11,0x44,0x75,
              0x63,0x6B,0x79,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
              0xFF,0xEE,0x00,0x0E,0x41,0x64,0x6F,0x62,0x65,0x00,0x64,0xC0,0x00,
              0x00,0x00,0x01,0xFF,0xDB,0x00,0x84,0x00,0x1B,0x1A,0x1A,0x29,0x1D,
              0x29,0x41,0x26,0x26,0x41,0x42,0x2F,0x2F,0x2F,0x42,0x47,0x3F,0x3E,
              0x3E,0x3F,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x01,0x1D,0x29,0x29,0x34,0x26,
              0x34,0x3F,0x28,0x28,0x3F,0x47,0x3F,0x35,0x3F,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
              0x47,0x47,0x47,0x47,0x47,0x47,0x47,0xFF,0xC0,0x00,0x11,0x08,0x00,
              0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,0x01,
              0xFF,0xC4,0x00,0x4B,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x01,0x01,0x00,
              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
              0x00,0x00,0x10,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x00,
              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
              0xDA,0x00,0x0C,0x03,0x01,0x00,0x02,0x11,0x03,0x11,0x00,0x3F,0x00,
              0xA6,0x00,0x1F,0xFF,0xD9);
if (isset($_GET['table']) && isset($_GET['value'])){
    if (isset($_GET['field'])){
		if ( defined('FILTER_SANITIZE_ADD_SLASHES') ) {
			$f=filter_var(substr($_GET['field'],0,30),FILTER_SANITIZE_ADD_SLASHES);
		} else {
			$f=addslashes(substr($_GET['field'],0,30));
		}
    } else {
        $f='codice';
    }
	if ( defined('FILTER_SANITIZE_ADD_SLASHES') ) {
		$t=filter_var(substr($_GET['table'],0,30),FILTER_SANITIZE_ADD_SLASHES);
	} else {
		$t=addslashes(substr($_GET['table'],0,30));
	}
  $sql = "SELECT image FROM ".$azTables.$t." WHERE ".$f." = '".substr($_GET['value'],0,30)."' LIMIT 1";
    if ($result = mysqli_query($link, $sql)) {
      $col = mysqli_fetch_assoc($result);
    } else {
      echo "Non trovo immagine";die;
    }
   // $col = gaz_dbi_get_row($gTables[$t], $f, substr($_GET['value'],0,30));
    header ('Content-type: image/pjpeg');
    if (empty($col['image'])) {
        echo $img1px;
    } else {
        echo $col['image'];
    }
}
?>
