/******************************************************************
* Inizio della sessione. Per consentire ad ogni utente di lavorare
* su un anno diverso, si registra l'anno scelto all'interno della
* sessione client.
*******************************************************************/
// error_reporting(0) ;
session_start() ;
if (!isset($_SESSION['login']) and $from_login != "1")
{
// header("Location: http://localhost/produzione/dali/GestioneAzienda/home/no_session.php") ;
echo "SESSION ID = " . session_id() ;
echo "SONO QUI" ;
exit ;
header("Location: http://localhost/GestioneAzienda_3.0/home/no_session.php") ;
exit ;
}
// else
// echo "SESSION ID = " . session_id() ;
if (! $_SESSION["anno"])
$anno = date("Y") ;
else
{
$anno = $_SESSION["anno"] ;
}
// echo "Anno = $anno" ; PERCHE'?
/***********************************************************
* simulo il parametro register_globals del vecchio php
***********************************************************/
if (!ini_get('register_globals')) {
$superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
extract($superglobal, EXTR_SKIP);
}
}
define ('TITLE', "Gestione Azienda") ;
$pub_inc=1;
$databaseeng = 'mysql';
$dialect = '';
// parametro utilizzato nell'invia ordini
$inviaperpagina = "16" ;
class DBbase_Sql {
var $Host = "";
var $Database = "";
var $User = "";
var $Password = "";
var $Link_ID = 0;
var $Query_ID = 0;
var $Record = array();
var $Row;
var $Errno = 0;
var $Error = "";
var $Auto_free = 0; ## Set this to 1 for automatic mysql_free_result()
var $Auto_commit = 0; ## set this to 1 to automatically commit results
function connect() {
if ( 0 == $this->Link_ID ) {
$this->Link_ID = mysqli_connect($this->Host, $this->User, $this->Password, $this->Database);
if (!$this->Link_ID) {
$this->halt("Link-ID == false, pconnect failed");
}
else
debug (0, "ALLORA") ;
// if (!mysqli_select_db($this->Database,$this->Link_ID)) {
// $this->halt("cannot use database ".$this->Database . " " . $this->Link_ID);
// }
}
}
function query($Query_String) {
debug (0, $Query_String) ;
$this->connect() ;
$this->Query_ID = mysqli_query($this->Link_ID, $Query_String) ;
$this->Row = 0;
$this->Errno = mysqli_errno($this->Link_ID);
$this->Error = mysqli_error($this->Link_ID);
if (!$this->Query_ID) {
$this->halt("Invalid SQL: ".$Query_String);
}
return $this->Query_ID;
}
function eseguiquery($query)
{
return $this->query($query);
}
function RecuperaDati($query)
{
$arr_val = array() ;
$num_rows = 0 ;
$i = 0 ;
$this->connect();
// $this->Query_ID = mysql_query($query, $this->Link_ID);
$this->Query_ID = mysqli_query($this->Link_ID, $query);
$this->Row = 0;
$this->Errno = mysqli_errno($this->Link_ID);
$this->Error = mysqli_error($this->Link_ID);
if (!$this->Query_ID)
{
$this->halt("Invalid SQL: ".$Query_String);
return array(-1, array()) ;
}
while ($i < mysqli_num_fields($this->Query_ID))
{
$meta = mysqli_fetch_field($this->Query_ID);
if ($meta)
$arr_val[$meta->name] = array() ;
$i++;
}
while($row = mysqli_fetch_array($this->Query_ID, MYSQLI_ASSOC) )
{
foreach($row as $key => $value)
$arr_val[$key][] = $value ;
$num_rows ++ ;
}
return array($num_rows, $arr_val) ;
}
function checkTable($table)
{
$query = "select * from $table" ;
$this->connect();
$this->Query_ID = mysql_query($query, $this->Link_ID);
if (!$this->Query_ID)
return 0 ;
else
return 1 ;
}
function next_record() {
$this->Record = mysqli_fetch_array($this->Query_ID);
$this->Row += 1;
$this->Errno = mysqli_errno($this->Link_ID);
$this->Error = mysqli_error($this->Link_ID);
debug (0, "NEXREC ". $this->Row) ;
$stat = is_array($this->Record);
if (!$stat && $this->Auto_free) {
mysql_free_result($this->Query_ID);
$this->Query_ID = 0;
}
return $stat;
}
function seek($pos) {
$status = mysql_data_seek($this->Query_ID, $pos);
if ($status)
$this->Row = $pos;
return;
}
function metadata($table) {
$count = 0;
$id = 0;
$res = array();
$this->connect();
$id = @mysql_list_fields($this->Database, $table);
if ($id < 0) {
$this->Errno = mysql_errno();
$this->Error = mysql_error();
$this->halt("Metadata query failed.");
}
$count = mysql_num_fields($id);
for ($i=0; $i<$count; $i++) {
$res[$i]["table"] = mysql_field_table ($id, $i);
$res[$i]["name"] = mysql_field_name ($id, $i);
$res[$i]["type"] = mysql_field_type ($id, $i);
$res[$i]["len"] = mysql_field_len ($id, $i);
$res[$i]["flags"] = mysql_field_flags ($id, $i);
$res["meta"][$res[$i]["name"]] = $i;
$res["num_fields"]= $count;
}
mysql_free_result($id);
return $res;
}
function affected_rows() {
return mysql_affected_rows($this->Link_ID);
}
function num_rows() {
debug (0, "NR ") ;
return mysqli_num_rows($this->Query_ID) ;
}
function num_fields() {
return mysql_num_fields($this->Query_ID);
}
function nf() {
return $this->num_rows();
}
function np() {
print $this->num_rows();
}
function f($Name) {
return $this->Record[$Name];
}
function p($Name) {
print $this->Record[$Name];
}
function halt($msg) {
printf("Database error: %s
\n", $msg);
printf("MySQL Error: %s (%s)
\n",
$this->Errno,
$this->Error);
die("Session halted.");
}
}
// $db_azienda = "dali" ;
$db_azienda = "dali2022" ;
$idsarzi = 121 ;
$dirordini = "C:\\php_app\\GestioneAzienda\\ordini\\" ;
$dirlistini = "C:\\php_app\\GestioneAzienda\\fornitori\\listini\\" ;
$dirtemplate = "C:\\php_app\\GestioneAzienda\\template\\" ;
/***************************************************************
* Gestione delle tabelle in base all'anno di gestione
****************************************************************/
// $anno="2003" ;
$tagenti = "agenti_$anno" ;
$tclienti = "clienti_$anno" ;
$ttipologie = "tipologie_$anno" ;
$tfornitori = "fornitori_$anno" ;
$taziende = "aziende_$anno" ;
$tordini = "ordini_$anno" ;
$tageforper = "ageforper_$anno" ;
$tdettagli = "dettagli_$anno" ;
$tpagamenti = "pagamenti_$anno" ;
$tprodotti = "prodotti_$anno" ;
$tcategorie = "categorie_$anno" ;
$tprovvigioni = "provvigioni_$anno" ;
$tprovvigioniAgenti = "provvigioniAgenti_$anno" ;
$tsarzi = "sarzi_$anno" ;
$tiva = "iva_$anno" ;
$tprogclienti = "progclienti_$anno" ;
$tprogrammazione = "programmazione_$anno" ;
$tscontomerce = "scontomerce_$anno" ;
$tformato = "formato" ;
$tparametri = "ParametriGenerali_$anno" ;
$ttarget = "Target_$anno" ;
$trelprodottotarget = "relprodottitarget_$anno" ;
$tAmmontareVariOrdini = "AmmontareVariOrdini_$anno" ;
/********************************************************************
* mi creo un array con tutte le tabelle dell'archivio.
* Quest'array mi servir� in fase di inizializzazione del nuovo anno
********************************************************************/
$arAllTable[] = array("tabella" => "ageforper", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "agenti", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "AmmontareVariOrdini", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "aziende", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "categorie", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "clienti", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "dettagli", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "fornitori", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "iva", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "ordini", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "pagamenti", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "ParametriGenerali", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "prodotti", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "progclienti", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "programmazione", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "provvigioniagenti", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "provvigioni", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "relprodottitarget", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "sarzi", "copiadati" => "1") ;
$arAllTable[] = array("tabella" => "scontomerce", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "target", "copiadati" => "0") ;
$arAllTable[] = array("tabella" => "tipologie", "copiadati" => "1") ;
$arrMesi = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre") ;
function Debug($display, $str)
{
if ($display == 1)
echo ("DEBUG: $str
") ;
elseif ($display == 2)
{
echo ("DEBUG: $str
") ;
exit ;
}
}
function DebugPre($display, $str)
{
if ($display == 1)
echo ("
DEBUG: $str") ; elseif ($display == 2) { echo ("
DEBUG: $str") ; exit ; } } function ItaDate($str) { $r = preg_match ("/([0-9]{4})[-\/]([0-9]{2})[-\/]([0-9]{2})/", $str, $reg_str) ; $str = sprintf("%s/%s/%s", $reg_str[3], $reg_str[2], $reg_str[1]) ; if ($str != "00/00/0000" and $str != "//") return $str ; else return "" ; } /* OLD VERSION function ItaDate($str) { preg_match ("/([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})", $str, $reg_str) ; print_r($reg_str) ; $str = sprintf("%s/%s/%s", $reg_str[3], $reg_str[2], $reg_str[1]) ; if ($str != "00/00/0000" and $str != "//") return $str ; else return "" ; } */ function ItaDate_2($str) { preg_match ("/([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})", $str, $reg_str) ; $str = sprintf("%s-%s-%s", $reg_str[3], $reg_str[2], $reg_str[1]) ; if ($str != "00-00-0000" and $str != "--") return $str ; else return "" ; } function MySqlDate($str) { preg_match ("/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/", $str, $res) ; $str = sprintf("%s/%s/%s", $res[3],$res[2],$res[1]) ; if ($str != "0000/00/00" and $str != "//") return $str ; else return '' ; } function MySqlDate_2($str) { preg_match ("/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/", $str, $res) ; $str = sprintf("%s-%s-%s", $res[3],$res[2],$res[1]) ; if ($str != "0000-00-00" and $str != "//") return $str ; else return '' ; } function SiNo($str) { if ($str == "0") return "No" ; else return "Si" ; } function nfl($str) { /******************************************************* * formatta i numeri per le lire * Esempio : 1.456.000 *********************************************************/ return number_format($str, 0, "", ".") ; // return number_format($str, 2) ; } function nfe($str) { /******************************************************* * formatta i numeri per l'euro * Esempio : 1.456.000,32 *********************************************************/ $str = floatval($str) ; // prima return number_format($str, 2, ",", ".") ; // poi return number_format($str, 2, ",", "") ; } function nfeExt($str) { /******************************************************* * formatta i numeri per l'euro fino a 5 cifre decimali * Esempio : 1.456.000,32 *********************************************************/ return number_format($str, 5, ",", ".") ; } function nfp($str) { /******************************************************* * formatta i numeri con le virgole e viene utilizzata * nella visualizzazione delle percentuali * Esempio : 3,75% *********************************************************/ $str = floatval($str) ; return number_format($str, 2, ",", ".") ; } function NumToSql($str) { /************************************************* * Trasforma un numero con la virgola in formato * italiano del tipo 2.000,45 in un numero in formato * Db del tipo 2000.45 ***************************************************/ $str = str_replace("\.", "", $str) ; debug (0, "TMP = $str") ; $str = str_replace(",", ".", $str) ; return $str ; } function nflno($str) { // Visualizza un numero senza decimali e senza simboli delle // migliaia return number_format($str, 0, "", "") ; } function nfeNoDot($str) { /*********************************************** * Formatta un numero da es. 1200.00 a 1200,00 ***********************************************/ return number_format($str, 2, ',', ''); } /** * Converts a date to number of days since a * distant unspecified epoch. * * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * * @access public * * @return integer number of days */ function dateToDays($day,$month,$year) { $century = substr($year,0,2); $year = substr($year,2,2); if($month > 2) $month -= 3; else { $month += 9; if($year) $year--; else { $year = 99; $century --; } } return ( floor((146097 * $century) / 4 ) + floor((1461 * $year) / 4 ) + floor((153 * $month + 2) / 5 ) + $day + 1721119); } // end func dateToDays /** * Returns number of days between two given dates. * * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * * @return int absolute number of days between dates, * -1 if there is an error. */ function dateDiff($day1,$month1,$year1,$day2,$month2,$year2) { // if(!Date_Calc::isValidDate($day1,$month1,$year1)) // return -1; // if(!Date_Calc::isValidDate($day2,$month2,$year2)) // return -1; return (abs((dateToDays($day1,$month1,$year1)) - dateToDays($day2,$month2,$year2))); } // end func dateDiff class FC_SQL extends DBbase_Sql { // var $Host = "localhost"; var $Host = "127.0.0.1"; var $Database = "fabrizio"; var $User = "root"; // var $Password = "root"; var $Password = ""; function free_result() { return @mysql_free_result($this->Query_ID); } function rollback() { return 1; } function commit() { return 1; } function autocommit($onezero) { return 1; } function insert_id($col="",$tbl="",$qual="") { return mysql_insert_id($this->Query_ID); } } function CalcolaScontoProdotto($totale, $sconto) { $val = preg_split("/\+/", $sconto, -1, PREG_SPLIT_NO_EMPTY) ; for($i=0; $i