Location: PHPKode > projects > PhpRechnung > phpRechnung/addressbook/newf.php
<?php
/*	newf.php

	phpInvoice - 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();
CheckSession();

if(isset($_POST['page']))
{
	$page = $_POST['page'];
}
if(isset($_POST['infoID']))
{
	$infoID = $_POST['infoID'];
}
if(isset($_POST['Customer']))
{
	$Customer = $_POST['Customer'];
}

if(isset($_POST['PrintName']))
{
	$PrintName = $_POST['PrintName'];
}
if(isset($_POST['Prefix']))
{
	$Prefix = $_POST['Prefix'];
}
if(isset($_POST['Firstname']))
{
	$Firstname = $_POST['Firstname'];
}
if(isset($_POST['Lastname']))
{
	$Lastname = $_POST['Lastname'];
}
if(isset($_POST['Title1']))
{
	$Title1 = $_POST['Title1'];
}
if(isset($_POST['Company']))
{
	$Company = $_POST['Company'];
}
if(isset($_POST['Department']))
{
	$Department = $_POST['Department'];
}
if(isset($_POST['Address']))
{
	$Address = $_POST['Address'];
}
if(isset($_POST['Country']))
{
	$Country = $_POST['Country'];
}
if(isset($_POST['Postalcode']))
{
	$Postalcode = $_POST['Postalcode'];
}
if(isset($_POST['City']))
{
	$City = $_POST['City'];
}
if(isset($_POST['Stateprov']))
{
	$Stateprov = $_POST['Stateprov'];
}
if(isset($_POST['Position1']))
{
	$Position1 = $_POST['Position1'];
}
if(isset($_POST['Initials']))
{
	$Initials = $_POST['Initials'];
}
if(isset($_POST['Salutation']))
{
	$Salutation = $_POST['Salutation'];
}
if(isset($_POST['Phonehome']))
{
	$Phonehome = $_POST['Phonehome'];
}
if(isset($_POST['Phoneoffi']))
{
	$Phoneoffi = $_POST['Phoneoffi'];
}
if(isset($_POST['Phoneothe']))
{
	$Phoneothe = $_POST['Phoneothe'];
}
if(isset($_POST['Phonework']))
{
	$Phonework = $_POST['Phonework'];
}
if(isset($_POST['Mobile']))
{
	$Mobile = $_POST['Mobile'];
}
if(isset($_POST['Pager']))
{
	$Pager = $_POST['Pager'];
}
if(isset($_POST['Fax']))
{
	$Fax = $_POST['Fax'];
}
if(isset($_POST['Email']))
{
	$Email = $_POST['Email'];
}
if(isset($_POST['Url']))
{
	$Url = $_POST['Url'];
}
if(isset($_POST['Note']))
{
	$Note = $_POST['Note'];
}
if(isset($_POST['ChangeLog']))
{
	$ChangeLog = $_POST['ChangeLog'];
}
if(isset($_POST['AltField1']))
{
	$AltField1 = $_POST['AltField1'];
}
if(isset($_POST['AltField2']))
{
	$AltField2 = $_POST['AltField2'];
}
if(isset($_POST['Url2']))
{
	$Url2 = $_POST['Url2'];
}
if(isset($_POST['Email2']))
{
	$Email2 = $_POST['Email2'];
}
if(isset($_POST['Category']))
{
	$Category = $_POST['Category'];
}
if(isset($_POST['MethodOfPayment']))
{
	$MethodOfPayment = $_POST['MethodOfPayment'];
}
if(isset($_POST['Message']))
{
	$Message = $_POST['Message'];
}
if(isset($_POST['Birthday']))
{
	$Birthday = $_POST['Birthday'];
}

if(isset($_POST['PrintName1']))
{
	$PrintName1 = $_POST['PrintName1'];
}
if(isset($_POST['Date_From1']))
{
	$Date_From1 = $_POST['Date_From1'];
}
if(isset($_POST['Date_Till1']))
{
	$Date_Till1 = $_POST['Date_Till1'];
}
if(isset($_POST['CustomerID']))
{
	$CustomerID = $_POST['CustomerID'];
}
if(isset($_POST['Prefix1']))
{
	$Prefix1 = $_POST['Prefix1'];
}
if(isset($_POST['Firstname1']))
{
	$Firstname1 = $_POST['Firstname1'];
}
if(isset($_POST['Lastname1']))
{
	$Lastname1 = $_POST['Lastname1'];
}
if(isset($_POST['Title11']))
{
	$Title11 = $_POST['Title11'];
}
if(isset($_POST['Company1']))
{
	$Company1 = $_POST['Company1'];
}
if(isset($_POST['Department1']))
{
	$Department1 = $_POST['Department1'];
}
if(isset($_POST['Address1']))
{
	$Address1 = $_POST['Address1'];
}
if(isset($_POST['Country1']))
{
	$Country1 = $_POST['Country1'];
}
if(isset($_POST['Postalcode1']))
{
	$Postalcode1 = $_POST['Postalcode1'];
}
if(isset($_POST['City1']))
{
	$City1 = $_POST['City1'];
}
if(isset($_POST['Stateprov1']))
{
	$Stateprov1 = $_POST['Stateprov1'];
}
if(isset($_POST['Position11']))
{
	$Position11 = $_POST['Position11'];
}
if(isset($_POST['Initials1']))
{
	$Initials1 = $_POST['Initials1'];
}
if(isset($_POST['Salutation1']))
{
	$Salutation1 = $_POST['Salutation1'];
}
if(isset($_POST['Phonehome1']))
{
	$Phonehome1 = $_POST['Phonehome1'];
}
if(isset($_POST['Phoneoffi1']))
{
	$Phoneoffi1 = $_POST['Phoneoffi1'];
}
if(isset($_POST['Phoneothe1']))
{
	$Phoneothe1 = $_POST['Phoneothe1'];
}
if(isset($_POST['Phonework1']))
{
	$Phonework1 = $_POST['Phonework1'];
}
if(isset($_POST['Mobile1']))
{
	$Mobile1 = $_POST['Mobile1'];
}
if(isset($_POST['Pager1']))
{
	$Pager1 = $_POST['Pager1'];
}
if(isset($_POST['Fax1']))
{
	$Fax1 = $_POST['Fax1'];
}
if(isset($_POST['Email1']))
{
	$Email1 = $_POST['Email1'];
}
if(isset($_POST['Url1']))
{
	$Url1 = $_POST['Url1'];
}
if(isset($_POST['Note1']))
{
	$Note1 = $_POST['Note1'];
}
if(isset($_POST['AltField11']))
{
	$AltField11 = $_POST['AltField11'];
}
if(isset($_POST['AltField21']))
{
	$AltField21 = $_POST['AltField21'];
}
if(isset($_POST['AltField31']))
{
	$AltField31 = $_POST['AltField31'];
}
if(isset($_POST['AltField41']))
{
	$AltField41 = $_POST['AltField41'];
}
if(isset($_POST['Category1']))
{
	$Category1 = $_POST['Category1'];
}
if(isset($_POST['MethodOfPayment1']))
{
	$MethodOfPayment1 = $_POST['MethodOfPayment1'];
}
if(isset($_POST['Birthday1']))
{
	$Birthday1 = $_POST['Birthday1'];
}
if(isset($_POST['Order']))
{
	$Order = $_POST['Order'];
}
if(isset($_POST['Sort']))
{
	$Sort = $_POST['Sort'];
}
if(isset($_POST['BankName']))
{
	$BankName = $_POST['BankName'];
}
if(isset($_POST['BankAccount']))
{
	$BankAccount = $_POST['BankAccount'];
}
if(isset($_POST['BankNumber']))
{
	$BankNumber = $_POST['BankNumber'];
}
if(isset($_POST['BankIban']))
{
	$BankIban = $_POST['BankIban'];
}
if(isset($_POST['BankBic']))
{
	$BankBic = $_POST['BankBic'];
}
if(isset($_POST['UserActive']))
{
	$UserActive = $_POST['UserActive'];
}
if(isset($_POST['UserName']))
{
	$UserName = $_POST['UserName'];
}
if(isset($_POST['UserLanguage']))
{
	$UserLanguage = $_POST['UserLanguage'];
}
if(isset($_POST['Password1']))
{
	$Password1 = $_POST['Password1'];
}
if(isset($_POST['Password2']))
{
	$Password2 = $_POST['Password2'];
}
if(isset($_POST['TaxFree']))
{
	$TaxFree = $_POST['TaxFree'];
}
if(isset($_POST['Taxnr']))
{
	$Taxnr = $_POST['Taxnr'];
}
if(isset($_POST['BusinessTaxnr']))
{
	$BusinessTaxnr = $_POST['BusinessTaxnr'];
}

$Searchstring = "CustomerID=$CustomerID&amp;Prefix1=$Prefix1&amp;Title11=$Title11&amp;Firstname1=$Firstname1&amp;Initials1=$Initials1&amp;Lastname1=$Lastname1&amp;Phonehome1=$Phonehome1&amp;Salutation1=$Salutation1&amp;Mobile1=$Mobile1&amp;Address1=$Address1&amp;Fax1=$Fax1&amp;Stateprov1=$Stateprov1&amp;Email1=$Email1&amp;Postalcode1=$Postalcode1&amp;City1=$City1&amp;Url1=$Url1&amp;Company1=$Company1&amp;Phonework1=$Phonework1&amp;Department1=$Department1&amp;Phoneoffi1=$Phoneoffi1&amp;Position11=$Position11&amp;Phoneothe1=$Phoneothe1&amp;Pager1=$Pager1&amp;Note1=$Note1&amp;Altfield11=$AltField11&amp;Altfield21=$AltField21&amp;Altfield31=$AltField31&amp;Altfield41=$AltField41&amp;Country1=$Country1&amp;Date_From1=$Date_From1&amp;Date_Till1=$Date_Till1&amp;Birthday1=$Birthday1&amp;Category1=$Category1";

function UserInput($mark)
{
	global $smarty, $page, $infoID, $Prefix, $Title1, $Firstname, $Initials, $Lastname,
	$Phonehome, $Salutation, $Mobile, $Address, $Fax, $Stateprov, $Email, $Postalcode,
	$City, $Url, $Company, $Phonework, $Department, $Phoneoffi, $Position1, $Phoneothe,
	$Pager, $Note, $ChangeLog, $AltField1, $AltField2, $Url2, $Email2, $Country, $Date,
	$Birthday, $Category, $MethodOfPayment, $Message, $PrintName, $Date_From1, $Date_Till1, $CustomerID, $Prefix1,
	$Title11, $Firstname1, $Initials1, $Lastname1, $Phonehome1, $Salutation1, $Mobile1, $Address1,
	$Fax1, $Stateprov1, $Email1, $Postalcode1, $City1, $Url1, $Company1, $Phonework1, $Department1,
	$Phoneoffi1, $Position11, $Phoneothe1, $Pager1, $Note1, $AltField11, $AltField21, $AltField31,
	$AltField41, $Country1, $Birthday1, $Category1, $MethodOfPayment1, $PrintName1, $Customer, $Order, $Sort,
	$BankName, $BankAccount, $BankNumber, $BankIban, $BankBic, $UserActive, $UserName, $UserLanguage,
	$TaxFree, $Taxnr, $BusinessTaxnr;
	$smarty->assign("page",$page);
	$smarty->assign("infoID","$infoID");
	$smarty->assign("Customer","$Customer");
	$smarty->assign("PrintName","$PrintName");
	$smarty->assign("Date","$Date");
	$smarty->assign("Prefix","$Prefix");
	$smarty->assign("Firstname","$Firstname");
	$smarty->assign("Lastname","$Lastname");
	$smarty->assign("Title1","$Title1");
	$smarty->assign("Company","$Company");
	$smarty->assign("Department","$Department");
	$smarty->assign("Address","$Address");
	$smarty->assign("Country","$Country");
	$smarty->assign("Postalcode","$Postalcode");
	$smarty->assign("City","$City");
	$smarty->assign("Stateprov","$Stateprov");
	$smarty->assign("Position1","$Position1");
	$smarty->assign("Initials","$Initials");
	$smarty->assign("Salutation","$Salutation");
	$smarty->assign("Phonehome","$Phonehome");
	$smarty->assign("Phoneoffi","$Phoneoffi");
	$smarty->assign("Phoneothe","$Phoneothe");
	$smarty->assign("Phonework","$Phonework");
	$smarty->assign("Mobile","$Mobile");
	$smarty->assign("Pager","$Pager");
	$smarty->assign("Fax","$Fax");
	$smarty->assign("Email","$Email");
	$smarty->assign("Url","$Url");
	$smarty->assign("Note","$Note");
	$smarty->assign("ChangeLog","$ChangeLog");
	$smarty->assign("AltField1","$AltField1");
	$smarty->assign("AltField2","$AltField2");
	$smarty->assign("Url2","$Url2");
	$smarty->assign("Email2","$Email2");
	$smarty->assign("Category","$Category");
	$smarty->assign("MethodOfPayment","$MethodOfPayment");
	$smarty->assign("Message","$Message");
	$smarty->assign("Birthday","$Birthday");
	$smarty->assign("Date_From1","$Date_From1");
	$smarty->assign("Date_Till1","$Date_Till1");
	$smarty->assign("CustomerID","$CustomerID");
	$smarty->assign("Prefix1","$Prefix1");
	$smarty->assign("Firstname1","$Firstname1");
	$smarty->assign("Lastname1","$Lastname1");
	$smarty->assign("Title11","$Title11");
	$smarty->assign("Company1","$Company1");
	$smarty->assign("Department1","$Department1");
	$smarty->assign("Address1","$Address1");
	$smarty->assign("Country1","$Country1");
	$smarty->assign("Postalcode1","$Postalcode1");
	$smarty->assign("City1","$City1");
	$smarty->assign("Stateprov1","$Stateprov1");
	$smarty->assign("Position11","$Position11");
	$smarty->assign("Initials1","$Initials1");
	$smarty->assign("Salutation1","$Salutation1");
	$smarty->assign("Phonehome1","$Phonehome1");
	$smarty->assign("Phoneoffi1","$Phoneoffi1");
	$smarty->assign("Phoneothe1","$Phoneothe1");
	$smarty->assign("Phonework1","$Phonework1");
	$smarty->assign("Mobile1","$Mobile1");
	$smarty->assign("Pager1","$Pager1");
	$smarty->assign("Fax1","$Fax1");
	$smarty->assign("Email1","$Email1");
	$smarty->assign("Url1","$Url1");
	$smarty->assign("Note1","$Note1");
	$smarty->assign("Category1","$Category1");
	$smarty->assign("MathodOfPayment1","$MethodOfPayment1");
	$smarty->assign("PrintName1","$PrintName1");
	$smarty->assign("Birthday1","$Birthday1");
	$smarty->assign("Order",$Order);
	$smarty->assign("Sort",$Sort);
	$smarty->assign("Mark",$mark);
	$smarty->assign("BankName","$BankName");
	$smarty->assign("BankAccount","$BankAccount");
	$smarty->assign("BankNumber","$BankNumber");
	$smarty->assign("BankIban","$BankIban");
	$smarty->assign("BankBic","$BankBic");
	$smarty->assign("UserActive","$UserActive");
	$smarty->assign("UserName","$UserName");
	$smarty->assign("UserLanguage","$UserLanguage");
	$smarty->assign("TaxFree","$TaxFree");
	$smarty->assign("Taxnr","$Taxnr");
	$smarty->assign("BusinessTaxnr","$BusinessTaxnr");
}

if (empty($Prefix))
{
	$smarty->assign("FieldError","$a[prefix] - $a[field_error]");
	UserInput("Prefix");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($Firstname) && (empty($Company)))
{
	$smarty->assign("FieldError","$a[firstname] - $a[field_error]");
	UserInput("Firstname");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($Lastname) && (empty($Company)))
{
	$smarty->assign("FieldError","$a[lastname] - $a[field_error]");
	UserInput("Lastname");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($Address))
{
	$smarty->assign("FieldError","$a[address] - $a[field_error]");
	UserInput("Address");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($Country))
{
	$smarty->assign("FieldError","$a[country] - $a[field_error]");
	UserInput("Country");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($Postalcode))
{
	$smarty->assign("FieldError","$a[postalcode] - $a[field_error]");
	UserInput("Postalcode");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($City))
{
	$smarty->assign("FieldError","$a[city] - $a[field_error]");
	UserInput("City");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($Category))
{
	$smarty->assign("FieldError","$a[category] - $a[field_error]");
	UserInput("Category");
	$smarty->display('addressbook/newf.tpl');
}
else if (empty($MethodOfPayment))
{
	$smarty->assign("FieldError","$a[cust_method_of_payment] - $a[field_error]");
	UserInput("MethodOfPayment");
	$smarty->display('addressbook/newf.tpl');
}
else if ($UserActive == 1 && empty($UserName))
{
	$smarty->assign("FieldError","$a[username] - $a[field_error]");
	UserInput("UserName");
	$smarty->display('addressbook/newf.tpl');
}
else if ($UserActive == 1 && empty($Password1))
{
	$smarty->assign("FieldError","$a[password] - $a[field_error]");
	UserInput("Password1");
	$smarty->display('addressbook/newf.tpl');
}
else if ($UserActive == 1 && empty($Password2))
{
	$smarty->assign("FieldError","$a[password] - $a[field_error]");
	UserInput("Password1");
	$smarty->display('addressbook/newf.tpl');
}
else if ($UserActive == 1 && $Password1 != $Password2)
{
	$smarty->assign("FieldError","$a[password_error]");
	UserInput("Password1");
	$smarty->display('addressbook/newf.tpl');
}
else
{
	// Database connection
	//
	DBConnect();

	$query1 = $db->Execute("SELECT FIRSTNAME, LASTNAME, ADDRESS, POSTALCODE, CITY FROM {$TBLName}addressbook WHERE FIRSTNAME='$Firstname' AND LASTNAME='$Lastname' AND ADDRESS='$Address' AND POSTALCODE='$Postalcode' AND CITY='$City'");
	$numrows1 = $query1->RowCount();
	$query2 = $db->Execute("SELECT DECODE(USERNAME,'$pkey') AS USERNAME FROM {$TBLName}addressbook WHERE DECODE(USERNAME,'$pkey')='$UserName'");
	$numrows2 = $query2->RowCount();

	if ($numrows1)
	{
		$smarty->assign("FieldError","$a[entry_exist]");
		UserInput("");
		$smarty->display('addressbook/newf.tpl');
	}
	else if (!empty($UserName) && $numrows2)
	{
		$smarty->assign("FieldError","$a[entry_exist] -> $a[username]");
		UserInput("UserName");
		$smarty->display('addressbook/newf.tpl');
	}
	else
	{

		list($day, $month, $year) = explode(".", $Birthday);
		$Birthday = German_Mysql_Date($Birthday);

		$query3 = "INSERT INTO {$TBLName}addressbook (MYID, PRINT_NAME, PREFIX, FIRSTNAME, LASTNAME, TITLE, COMPANY, DEPARTMENT, ADDRESS, CITY, STATEPROV, POSTALCODE, COUNTRY, POSITION, INITIALS, SALUTATION, PHONEHOME, PHONEOFFI, PHONEOTHE, PHONEWORK, MOBILE, PAGER, FAX, EMAIL, URL, NOTE, CHANGELOG, ALTFIELD1, ALTFIELD2, URL2, EMAIL2, CATEGORY, METHODOFPAY, MESSAGE, BIRTHDAY, BANKNAME, BANKACCOUNT, BANKNUMBER, BANKIBAN, BANKBIC, TAX_FREE, TAXNR, BUSINESS_TAXNR, USERNAME, PASSWORD, USERLANGUAGE, USER_ACTIVE, CREATEDBY, MODIFIEDBY, USERGROUP1, USERGROUP2, CREATED, MODIFIED)";
		$query3 .= "VALUES (NULL, '$PrintName', '$Prefix', '$Firstname', '$Lastname', '$Title1', '$Company', '$Department', '$Address', '$City', '$Stateprov', '$Postalcode', '$Country', '$Position1', '$Initials', '$Salutation', '$Phonehome', '$Phoneoffi', '$Phoneothe', '$Phonework', '$Mobile', '$Pager', '$Fax', '$Email', '$Url', '$Note', '$ChangeLog', '$AltField1', '$AltField2', '$Url2', '$Email2', '$Category', '$MethodOfPayment', '$Message', '$Birthday', '$BankName', '$BankAccount', '$BankNumber', '$BankIban', '$BankBic', '2', '$Taxnr', '$BusinessTaxnr', ENCODE('$UserName','$pkey'), ENCODE('$Password1','$pkey'), '$UserLanguage', '$UserActive', '$_SESSION[Username]', '$_SESSION[Username]', '$_SESSION[Usergroup1]', '$_SESSION[Usergroup2]', '$CurrentDateTime', '$CurrentDateTime')";

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

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

		Header("Location: $web/addressbook/new.php?page=$page&infoID=$infoID&$Searchstring&Order=$Order&Sort=$Sort&$sessname=$sessid");
	}
}

?>
Return current item: PhpRechnung