<?php
error_reporting(0);//Desactiva ver warnings
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);//Activa ver warnings

/*conectar bdd, smtp y librerias*/{
if($_SERVER["HTTP_HOST"] == 'localhost'){
    $host_name = 'localhost';
    $database = 'test';
    $user_name = 'root';
    $password = '';    
}else{
    $host_name = 'db5006133589.hosting-data.io';
    $database = 'dbs5131681';
    $user_name = 'dbu1136964';
    $password = 'Pruebas123...';
}
$link = mysqli_connect($host_name, $user_name, $password, $database);    
if ($link->connect_error) {die("Connection failed: " . $link->connect_error);}else{ /*echo "Connected successfully";/**/}
/*character set to utf8mb4 */$link->set_charset(" utf8mb4");

date_default_timezone_set('America/New_York');//La zona horaria
$ejecutarquery=mysqli_query($link,"SET time_zone='America/New_York'"); 

}
//tienes codigo JQuery en footer.php y los CSS en head.php

/*Site generals*/{
$sql="SELECT * FROM amr_other;"; 
$ejecutarquery=mysqli_query($link,$sql); 
if(mysqli_num_rows($ejecutarquery)>0){
    $other=array();
    while($row=mysqli_fetch_assoc($ejecutarquery)){
        $other[$row["meta"]]=$row["valor"];
        $other["id".$row["meta"]]=$row["id"];
    }    
}
$siteName=$other["sitename"];
$logo=$other["logo"];;
$SiteDescription=$other["sitedesc"];
$favIcon=$other["favicon"];
$rutamultimedia='/multimedia';
$extensionesValidas=array('png','jpg','gif','pdf');
}

/*Urls y variables utiles*/{
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === ' on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$uri = $_SERVER['REQUEST_URI'];
//echo $url.$uri;  if(strpos($uri,'') ){}
//echo $_SERVER[HTTP_HOST];
$pestana = explode("?", $uri);
$ahora=date('d-m-Y H:i:s', time());
$timestamp=date('Y-m-d H:i:s', time());
}
/*Traer datos usuario*/{
if(isset($_SESSION['user']) ){//revisa que estes loggeado    
    $sql="SELECT * FROM amr_users WHERE id='".$_SESSION['user']."' ;"; 
    $ejecutarquery=mysqli_query($link,$sql);
    //no puede fallar, jala datos de usuario
    $row=mysqli_fetch_assoc($ejecutarquery);
    $usuario=array("theme"=>$row["theme"],"name"=>$row["name"],"layout"=>$row["layout"],"email"=>$row["email"],"type"=>$row["type"],"img"=>$row["img"],"pwd"=>$row["pwd"]);    
}
}

/*Traer datos del Proyecto! */{
if(isset($_GET['id']) ){//revisa que estes loggeado    
    $sql="SELECT * FROM amr_projects WHERE id='".$_GET['id']."' ;"; 
    $ejecutarquery=mysqli_query($link,$sql);
    //no puede fallar, jala datos de usuario
    $row=mysqli_fetch_assoc($ejecutarquery);
	$proy=array("descripcion"=>$row["descripcion"],"nombre"=>$row["nombre"],"due"=>$row["due"],"direccion"=>$row["direccion"],"ciudad"=>$row["ciudad"],"estado"=>$row["estado"],"pais"=>$row["pais"],"cp"=>$row["cp"]);    
}else{
	header("location: ../");
}

}
/*Funciones*/{
function ProdProy($id){
	global $link;
	$html="";
	$sql="SELECT p.nombre, SUM(m.cantidad) as cant, p.archivo FROM amr_projects_meta m INNER JOIN amr_products p ON m.valor=p.id WHERE proyecto=".$id." AND meta='producto' GROUP BY p.nombre ASC;"; 
	$ejecutarquery=mysqli_query($link,$sql); 
	if(mysqli_num_rows($ejecutarquery)>0){
		while($row=mysqli_fetch_assoc($ejecutarquery)){
		$html.='<tr style="box-sizing: border-box; border-color: inherit; border-style: solid; border-width: 0; border-bottom: 1px solid #e9ecef; border: 1px solid #e9ecef; text-align: right;" align="right">
	<td class="text-center" style="box-sizing: border-box; border: solid 1px #f3f2f2; border-color: inherit; border-style: solid; border-width: 0; border-bottom-width: 1px; padding: 15px 20px; background-color: var(--bs-table-bg); box-shadow: inset 0 0 0 9999px var(--bs-table-accent-bg); text-align: center;" bgcolor="var(--bs-table-bg)" align="center">'.$row["nombre"].'</td>
	<td class="text-right" style="box-sizing: border-box; border: solid 1px #f3f2f2; border-color: inherit; border-style: solid; border-width: 0; border-bottom-width: 1px; padding: 15px 20px; background-color: var(--bs-table-bg); box-shadow: inset 0 0 0 9999px var(--bs-table-accent-bg);" bgcolor="var(--bs-table-bg)">'.$row["cant"].'</td>
													</tr>';
		}
	}else{
		$html.= "Sin resultados";
	}
	return $html;
}
function ProdPdf($id){
	global $link;
	$html=array();
	$sql="SELECT p.nombre, SUM(m.cantidad) as cant, p.archivo FROM amr_projects_meta m INNER JOIN amr_products p ON m.valor=p.id WHERE proyecto=".$id." AND meta='producto' GROUP BY p.nombre ASC;"; 
	$ejecutarquery=mysqli_query($link,$sql); 
	if(mysqli_num_rows($ejecutarquery)>0){
		while($row=mysqli_fetch_assoc($ejecutarquery)){
		$html[]=$row["archivo"];
		}
	}
	return $html;
}
}
?>