<?php
session_start();
if ($first_name>=1){
echo "Prego effettuare il login <a href=\"/contenuti.php\"> Qui<br>
&copy;Bloghosteria.com<br>
</a>";
}
 elseif  ( empty( $first_name ) ) {
?> Prego effettuare il login <a href="/contenuti.php"> Qui<br>
&copy;Bloghosteria.com<br>
</a>
<?php
} elseif ($first_name==$_SESSION['first_name']) { 
include ("langselect.php");  
include ("Config2db.php");
echo "Salve, 
". $_SESSION['last_name'] ." <a href=logout.php> Logout</a><style type=\"text/css\">

a:link, a:visited {
	color: #009933; text-decoration: none;
	font-weight: bold;
}

a:hover {
	color: #ff6600;	text-decoration: none;
	font-weight: bold;	
}
.style1 {
    color: #ff0000;
}

</style>  <p><a href=/sample2.php?last_name=$last_name>$lang0073</a> | 
<a href=Nuova_Fattura_Fornitore.php?Ragione_Sociale=$last_name>$lang0074</a> |
<a href=mailto:$emailwebm>$lang0006</a> | 
<a href= gestfattforn.php?Ragione_Sociale=$last_name>$lang0075</a></p>
";

include("dblib.inc");

include("clublib.inc");
$image_dir = "images";
$image_url = "images";
$upload_dir = "uploads/";
$upload_url = "uploads/";
include ("random.php");

  

if ( isset( $fupload ))
	{
	// controllo se ha inserito qualcosa
	if  ( $fupload_name == "" ) 
		{
		$message .= "$lang0104";
		}	

	// controllo se e' un' imago	
	if (!($fupload_type == "image/jpeg" || $fupload_type == "image/pjpeg") )
			{
			$message = "$lang0105 $fupload_type";
			}
	// sovrascrivo il file
	if ($message == "")
		{
	
		copy ( $fupload, "$image_dir/P$random_password.jpg") or die ("Impossibile copiare il file");
	//	$message = "Il file &egrave; stato aggiornato con successo. <br>(Potrebbe essere necessario aggiornare la pagina per vedere la nuova fotografia)";
            
		
		}

	
	}








if (isset ($actionflag))

	{
	//controllo sull'esistenza dei campi obbligatori
	if (
		empty($form["Totale"]) 
		 
		)
		
		$message .= "<span class=style1>$lang0126</span> <br>";
	


	if ($message == "")

		{
		// se tutto ok inserisco la nuova fattura ma prima faccio qualche operazione sulle variabili
		makeSlashes($fornitore); 
		makeSlashes($form);
		// formatto le date
		$form["Data_Fattura"] = strftime ("$anno-$mese-$giorno");
		$form["Data_Scadenza"] = strftime ("$anno_scadenza-$mese_scadenza-$giorno_scadenza");
		
		$result = spl_invoiceInsert($form['N_Fattura'], $form['Data_Fattura'], $form['Ragione_Sociale'], $form['Descrizione'], $form['Totale'], $form['Imposta'], $form['Tipo_Pagamento'], $form['Data_Scadenza'], $form['Note']);
		
		if (! $result )

			die (" Errore di inserimento: ".mysql_error());

		else 
			{

				

			// resetto la variabile session[ID_Fornitore]
			
			
			echo "<p>$lang0127</p>";
			
			
			exit;	
			}
		}

	}

if (! isset($actionflag))

		{


		
		// inizializzo l'array associativo del modulo
		
		$form ["Ragione_Sociale"] = "";

		$form["N_Fattura"] = "";
		
		$form["Tipo_Pagamento"] = "";

		$form["Descrizione"] = "";
		
		$form["Totale"] = "";
		
		$form["Imposta"] = "";
		
		$form["Note"] = "";		
		
		$giorno = "";
		
		$mese = "";
		
		$anno = "";
			
		$giorno_scadenza = "";
		
		$mese_scadenza = "";
	
		$anno_scadenza = "";
		
		}

?>





<form method="post" action="<?php print $PHP_SELF;?>" name="cv_upload" enctype="multipart/form-data" action="post">

<p>
  <input type="Hidden" name="actionflag" value="ins_exp">
    <input type="Hidden" name="Ragione_Sociale" value="<? echo "$Ragione_Sociale"; ?>">
  
</p>
<div align="center"><font class="FacetFormHeaderFont"><? echo "$lang0128"; ?></font></div>
<div align="center"><font class="FacetFieldCaptionTD"></font></div><br>
<table border="0" cellpadding="3" cellspacing="1" class="FacetFormTABLE" align="center">
  <!-- BEGIN Error -->
  <tr>
    <td colspan="2" class="FacetDataTD">
	
	</td>
  </tr>
  <!-- END Error -->
    <tr>
<td class="FacetFieldCaptionTD"><? echo "$lang0129"; ?></td> 
<td class="FacetDataTD"><input type="file" name="fupload"  class="FacetButton" class="FacetDataTD"></td></tr>
<td colspan="3" align="right" nowrap class="FacetFooterTD">
      <!-- BEGIN Button Insert --><input name="Insert" type="submit" value="UPLOAD" class="FacetButton"><!-- END Button Insert -->
</td>
</table>
</form>
<?
echo"<form method=post action= $PHP_SELF name=pws_clienti>

<!-- flag di invio del modulo -->

<input type=Hidden name=actionflag value=insert>

<div align=center><font class=FacetFormHeaderFont>$lang0130</font></div>

<table border=0 cellpadding=3 cellspacing=1 class=FacetFormTABLE align=center>

  <!-- BEGIN Error -->

  <tr>

    <td colspan=2 class=FacetDataTD>";
?>
	<?php

	if (! $message == "")

	{

	print "$message";

	}

	?>
<?php	

	echo"</td>

  </tr>

  <!-- END Error -->
  <tr>

    <td class=FacetFieldCaptionTD>$lang0035 &nbsp;</td>

    <td class=FacetDataTD><input type=hidden name=form[Ragione_Sociale]  value=$Ragione_Sociale maxlength=100 size=30 class=FacetInput>$Ragione_Sociale</td>

  </tr>
  <tr>

    <td class=FacetFieldCaptionTD>$lang0076 * &nbsp;</td>

    <td class=FacetDataTD><input type=text name=form[N_Fattura] value= \"$form[N_Fattura]\"  maxlength=100 size=30 class=FacetInput>&nbsp;</td>

  </tr>
 <tr>

    <td class=FacetFieldCaptionTD>$lang0079 &nbsp;</td>
	 <td class=FacetDataTD>";
	?> 
		 <? 
		 // inserisco il select box per il campo data
		   $select_data = new selectDate("giorno", "mese", "anno");
		   $select_data -> daySelected($giorno); 
		   $select_data -> monthSelected($mese); 
		   $select_data -> yearSelected($anno); 	  
		   $select_data -> output();
		 ?>
		 <?
	 echo"</td>
  </tr>

 <tr>

 	<td class=FacetFieldCaptionTD>$lang0013 * &nbsp;</td>

    <td colspan=2 class=FacetDataTD>";
	?>
		 <? 
		 // inserisco il select box per il campo tipo pagamento
		   $select_pagamento = new selectPagamento();
		   $select_pagamento -> addSelectName("form[Tipo_Pagamento]");
		   $select_pagamento -> addSelected($form["Tipo_Pagamento"]);
		   $select_pagamento -> output();
		 ?>
<?
	echo"</td>

  </tr>
  <tr>

    <td class=FacetFieldCaptionTD>$lang0133 * &nbsp;</td>

    <td class=FacetDataTD><input type=text name=form[Totale] value=\"$form[Totale]\" maxlength=20 size=10 class=FacetInput>&nbsp;</td>

  </tr>
  <tr>

    <td class=FacetFieldCaptionTD>$lang0083 * &nbsp;</td>
    <td class=FacetDataTD><input type=text name=form[Imposta] value=\"$form[Imposta]\" maxlength=20 size=10 class=FacetInput>&nbsp;</td>
  </tr>
  <tr>
    <td class=FacetFieldCaptionTD>$lang0080 *</td>&nbsp;</td>
    <td class=FacetDataTD>";
	?>
	  <? 
	 // inserisco il select box per il campo data
	   $select_scdata = new selectDate("giorno_scadenza", "mese_scadenza", "anno_scadenza");
	   $select_scdata -> daySelected($giorno_scadenza); 
	   $select_scdata -> monthSelected($mese_scadenza); 
	   $select_scdata -> yearSelected($anno_scadenza); 	  
	   $select_scdata -> output();
	 ?>
    <?
	  
	echo"</td>
  </tr>	

	<tr>
		<td class=FacetFieldCaptionTD>$lang0131 &nbsp;</td><td class=FacetDataTD><textarea name=form[Descrizione] cols=40 rows=5 class=FacetInput> $form[Descrizione] </textarea></td>
	</tr>

	<tr>
		<td class=FacetFieldCaptionTD>$lang0132</td><td class=FacetDataTD><input type=hidden name=form[Note]  value=$image_dir/P$random_password.jpg>$image_dir/P$random_password.jpg</td>
	</tr>

 


 <td colspan=2 align=right nowrap class=FacetFooterTD>

      <!-- BEGIN Button Insert --><input name=Insert type=submit value=$lang0056 class=FacetButton><!-- END Button Insert -->



    </td>

</table>

</form>";

} else {
echo "Prego effettuare il login <a href=\"contenuti.php\"> Qui<br>
&copy;Bloghosteria.com<br>
</a>";
}
?>