Location: PHPKode > projects > PhpRechnung > phpRechnung/position/newf.php
<?php
/*
	newf.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_Active']))
{
	$Pos_Active = $_POST['Pos_Active'];
}
if(isset($_POST['Pos_Name']))
{
	$Pos_Name = strip_tags($_POST['Pos_Name']);
}
if(isset($_POST['Pos_Desc']))
{
	$Pos_Desc = strip_tags($_POST['Pos_Desc']);
}
if(isset($_POST['Pos_Price']))
{
	$Pos_Price = ereg_replace(",", ".", $_POST['Pos_Price']);
}
if(isset($_POST['Pos_Tax']))
{
	$Pos_Tax = $_POST['Pos_Tax'];
}
if(isset($_POST['PosGroupID']))
{
	$PosGroupID = $_POST['PosGroupID'];
}
if(isset($_REQUEST['Note']))
{
	$Note = strip_tags($_REQUEST['Note']);
}
if(isset($_POST['Pos_Name1']))
{
	$Pos_Name1 = strip_tags($_POST['Pos_Name1']);
}
if(isset($_POST['Pos_Desc1']))
{
	$Pos_Desc1 = strip_tags($_POST['Pos_Desc1']);
}
if(isset($_POST['Pos_Price1']))
{
	$Pos_Price1 = ereg_replace(",", ".", $_POST['Pos_Price1']);
}
if(isset($_POST['Note1']))
{
	$Note1 = strip_tags($_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($mark)
{
	global $smarty, $posID, $page, $infoID, $Pos_Active, $Pos_Name, $Pos_Desc, $Pos_Price, $Pos_Tax,
	$Note, $PosGroupID, $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_Active","$Pos_Active");
	$smarty->assign("Pos_Name","$Pos_Name");
	$smarty->assign("Pos_Desc","$Pos_Desc");
	$smarty->assign("Pos_Price","$Pos_Price");
	$smarty->assign("Pos_Tax","$Pos_Tax");
	$smarty->assign("PosGroupID","$PosGroupID");
	$smarty->assign("Note","$Note");
	$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");
	$smarty->assign("Mark",$mark);
}

if (empty($Pos_Name))
{
	$smarty->assign("FieldError","$a[pos_name] - $a[field_error]");
	UserInput("Pos_Name");
	$smarty->display('position/newf.tpl');
}
else if (empty($Pos_Desc))
{
	$smarty->assign("FieldError","$a[pos_text] - $a[field_error]");
	UserInput("Pos_Desc");
	$smarty->display('position/newf.tpl');
}
else if ($Pos_Price == "")
{
	$smarty->assign("FieldError","$a[pos_price] - $a[field_error]");
	UserInput("Pos_Price");
	$smarty->display('position/newf.tpl');
}
else
{
	// Database connection
	//
	DBConnect();

	// Get the Pos_Group from posgroup table
	//
	$query = $db->GetAll("SELECT POSGROUPID, DESCRIPTION FROM {$TBLName}posgroup WHERE POSGROUPID=$PosGroupID");

	// If an error has occurred, display the error message
	//
	if (!$query)
		print($db->ErrorMsg());
	else
		// Save position group in $Pos_Group
		//
		foreach ( $query as $f1 )
		{
			$Pos_Group = $f1['DESCRIPTION'];
		}

	$query1 = $db->Execute("SELECT POS_NAME FROM {$TBLName}article WHERE POS_NAME='$Pos_Name'");
	$numrows1 = $query1->RowCount();

	if ($numrows1)
	{
		$smarty->assign("FieldError","$a[entry_exist] - '$Pos_Name'");
		UserInput("Pos_Name");
		$smarty->display('position/newf.tpl');
	}
	else
	{
		$query2 = "INSERT INTO {$TBLName}article (POSITIONID, POS_ACTIVE, POS_NAME, POS_DESC, POS_PRICE, POS_TAX, POSGROUPID, POS_GROUP, NOTE, CREATEDBY, MODIFIEDBY, USERGROUP1, USERGROUP2, CREATED, MODIFIED)";
		$query2 .= "VALUES(NULL, '$Pos_Active', '$Pos_Name', '$Pos_Desc', '$Pos_Price', '$Pos_Tax', '$PosGroupID', '$Pos_Group', '$Note', '$_SESSION[Username]', '$_SESSION[Username]', '$_SESSION[Usergroup1]', '$_SESSION[Usergroup2]', '$CurrentDateTime', '$CurrentDateTime')";

		if ($db->Execute($query2) === false)
		{
			die($db->ErrorMsg());
		}

		$_SESSION['NewID'] = "1";

		Header("Location: $web/position/new.php?page=$page&infoID=$infoID&Pos_Name1=$Pos_Name1&Pos_Text1=$Pos_Text1&Pos_Price1=$Pos_Price1&Order=$Order&Sort=$Sort&Pos_Active1=$Pos_Active1&$sessname=$sessid");
	}
}

?>
Return current item: PhpRechnung