<?php
include "checklog.php";

$ordid = $HTTP_POST_VARS["ordid"];

if ($ordid > 0) {
	$eliminaordini = $HTTP_POST_VARS["eliminaordini"];
	$sql = "SELECT * FROM ordini WHERE ID = $ordid";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result)) {
		$ordcode = $row["codice"];
		if ($eliminaordini == 2) {
			$status = 4;
			if ($row["status"] != $status) {
				$sql2 = "SELECT codice_articolo, codice_completo, quantita FROM ordini_dettagli WHERE ID_ordine='$ordcode'";
				$result2 = mysql_query($sql2);
				while ($row2 = mysql_fetch_array($result2)) {
					$thecode = $row2["codice_articolo"];
					$codeitem = $row2["codice_completo"];
					$codice = CheckCodice($thecode, $codeitem);
					$valore = $row2["quantita"];
					AumGiacenza($codice, $valore);
				}
			}
		}
		$sql2 = "DELETE FROM ordini_dettagli WHERE ID_ordine = '$ordcode'";
		$result2 = mysql_query($sql2);
	}
	$sql = "DELETE FROM ordini WHERE ID = $ordid";
	$result = mysql_query($sql);
}

Header("Location: boordini.php");

?>