$dnum=date(Ymd)*4;
$dnum2=( date(Y)*3 )+( date(md)*7 );
$from=$_POST['fr'];
if($from!=$dnum and $from!=$dnum2){
echo("Unauthorized.");
exit();
}
$dbcnx = @mysql_connect('mysql.plainhost.com', 'ecosmar_ecosmart', 'ecoman1');
$QID=$_POST['QID'];
$usrn=$_POST['usrn'];
$page=$_POST['page'];
if($page=="ecologged.php"){
$relocate="../ecologged.php?usrn=".$usrn;
}elseif($page=="ecocontact_edit.php"){
$relocate="../contacts/ecocontact_edit.php?usrn=".$usrn."&ID=".$CID."&fr=".$dnum;
}else{
$relocate="../ecologged.php?usrn=".$usrn;
}
$gocount=0;
mysql_select_db('ecosmar_inv', $dbcnx);
$getprods=mysql_query("SELECT ID FROM q_products WHERE QID='$QID'");
if(!$getprods){
echo("Could not verify Quote Products. Error: ".mysql_error()."
");
}else{
while($row=mysql_fetch_array($getprods)){
$pIDs[]=$row['ID'];
}//while fetching product IDs
foreach($pIDs as $value){
$pout=mysql_query("DELETE FROM q_products WHERE ID='$value' LIMIT 1");
if(!$pout){
echo("Could not delete Product ID $value. Error: ".mysql_error()."
");
}
}//4each product ID
$popto=mysql_query("OPTIMIZE TABLE q_products");
if(!$popto){
echo("Could not optimize Quote Products. Error: ".mysql_error()."
");
}else{
$gocount=$gocount+1;
}//table optimized
}//gotproducts
$getnotes=mysql_query("SELECT ID FROM q_notes WHERE QID='$QID'");
if(!$getnotes){
echo("Could not verify Quote Notes. Error: ".mysql_error()."
");
}else{
while($row=mysql_fetch_array($getnotes)){
$nIDs[]= $row[0];
}//while getting notes
foreach($nIDs as $value){
$nout=mysql_query("DELETE FROM q_notes WHERE ID='$value' LIMIT 1");
if(!$nout){
echo("Could not delete Note ID $value. Error: ".mysql_error()."
");
}
}//4each note
$popto=mysql_query("OPTIMIZE TABLE q_notes");
if(!$popto){
echo("Could not optimize Quote Notes. Error: ".mysql_error()."
");
}else{
$gocount=$gocount+1;
}//table optimized
}/////got notes
$outship=mysql_query("DELETE FROM q_ship WHERE QID='$QID' LIMIT 1");
if(!$outship){
echo("Could not delete Ship To Record. Error: ".mysql_error()."
");
}else{
$popto=mysql_query("OPTIMIZE TABLE q_ship");
if(!$popto){
echo("Could not optimize Quote Notes. Error: ".mysql_error()."
");
}else{
$gocount=$gocount+1;
}//table optimized
}//outed ship
$outit=mysql_query("DELETE FROM quotes WHERE ID='$QID' and usrn='$usrn' LIMIT 1");
if(!$outit){
echo("Could not delete quote. Error: ".mysql_error()."
");
}else{
$gocount=$gocount+1;
}
if($gocount>3){
header("Location: $relocate");
}
?>