<?php
/*
deletef.php
phpRechnung - is easy-to-use Web-based multilingual accounting software.
Copyright (C) 2001 - 2008 Edy Corak < phprechnung at ecorak dot net >
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once("../include/phprechnung.inc.php");
require_once("../include/smarty.inc.php");
CheckUser();
CheckAdminGroup1();
CheckSession();
if(isset($_POST['posID']))
{
$posID = $_POST['posID'];
}
if(isset($_POST['page']))
{
$page = $_POST['page'];
}
if(isset($_POST['infoID']))
{
$infoID = $_POST['infoID'];
}
if(isset($_POST['Pos_Name1']))
{
$Pos_Name1 = $_POST['Pos_Name1'];
}
if(isset($_POST['Pos_Desc1']))
{
$Pos_Desc1 = $_POST['Pos_Desc1'];
}
if(isset($_POST['Pos_Price1']))
{
$Pos_Price1 = $_POST['Pos_Price1'];
}
if(isset($_POST['Note1']))
{
$Note1 = $_POST['Note1'];
}
if(isset($_POST['Pos_Active1']))
{
$Pos_Active1 = $_POST['Pos_Active1'];
}
if(isset($_POST['Order']))
{
$Order = $_POST['Order'];
}
if(isset($_POST['Sort']))
{
$Sort = $_POST['Sort'];
}
function UserInput()
{
global $smarty, $posID, $page, $infoid, $Pos_Name1,
$Pos_Desc1, $Pos_Price1, $Note1, $Order, $Sort, $Pos_Active1;
$smarty->assign("posID","$posID");
$smarty->assign("page","$page");
$smarty->assign("InfoID","$infoid");
$smarty->assign("Pos_Name1","$Pos_Name1");
$smarty->assign("Pos_Desc1","$Pos_Desc1");
$smarty->assign("Pos_Price1","$Pos_Price1");
$smarty->assign("Note1","$Note1");
$smarty->assign("Pos_Active1","$Pos_Active1");
$smarty->assign("Order","$Order");
$smarty->assign("Sort","$Sort");
}
if (empty($posID))
{
$smarty->assign("FieldError","$a[position] - $a[field_error]");
UserInput("Pos_Name");
$smarty->display('position/deletef.tpl');
}
else
{
// Database connection
//
DBConnect();
// Check if this position in used in invoices or offers
//
$query1 = $db->Execute("SELECT POSITIONID FROM {$TBLName}invoicepos WHERE POSITIONID=$posID");
$query2 = $db->Execute("SELECT POSITIONID FROM {$TBLName}offerpos WHERE POSITIONID=$posID");
$numrows1 = $query1->RowCount();
$numrows2 = $query2->RowCount();
if ($numrows1 || $numrows2)
{
$smarty->assign("FieldError","$a[position] - $a[entry_not_deleted] - $a[number] $posID - $a[position_used]");
UserInput("");
$smarty->display('position/deletef.tpl');
}
else
{
$query4 = "DELETE FROM {$TBLName}article WHERE POSITIONID=$posID";
if ($db->Execute($query4) === false)
{
die($db->ErrorMsg());
}
$query5 = "INSERT INTO {$TBLName}syslog (SYSLOGID, CREATED, DESCRIPTION, CREATEDBY, USERGROUP1, USERGROUP2)";
$query5 .= "VALUES(NULL, '$CurrentDateTime', 'Position-No.: $posID was DELETED by user $_SESSION[Username] (uid=$_SESSION[UserID]) from $IPAddress', 'admin', '1', '2')";
if ($db->Execute($query5) === false)
{
die($db->ErrorMsg());
}
$_SESSION['DeleteID'] = "1";
if($infoid == '9')
Header("Location: $web/position/searchlist.php?posID=$posID&page=$page&Order=$Order&Sort=$Sort&Pos_Active1=$Pos_Active1&Pos_Name1=$Pos_Name1&Pos_Text1=$Pos_Text1&Pos_Price1=$Pos_Price1&$sessname=$sessid#$posID");
else
Header("Location: $web/position/list.php?posID=$posID&page=$page&Order=$Order&Sort=$Sort&Pos_Active1=$Pos_Active1&$sessname=$sessid#$posID");
}
}
?>