<?php
/*
searchlist.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/company_settings.inc.php");
require_once("../include/smarty.inc.php");
CheckUser();
CheckSession();
if(isset($_REQUEST['posID']))
{
$posID = $_REQUEST['posID'];
$smarty->assign("posID","$posID");
}
if(!empty($_REQUEST['page']))
{
$intCurrentPage = $_REQUEST['page'];
} else {
$intCurrentPage = 1;
}
if(isset($_REQUEST['Pos_Name1']))
{
$Pos_Name1 = $_REQUEST['Pos_Name1'];
$smarty->assign("Pos_Name1","$Pos_Name1");
}
if(isset($_REQUEST['Pos_Desc1']))
{
$Pos_Desc1 = $_REQUEST['Pos_Desc1'];
$smarty->assign("Pos_Desc1","$Pos_Desc1");
}
if(isset($_REQUEST['Pos_Price1']))
{
$Pos_Price1 = ereg_replace(",", ".", $_POST['Pos_Price1']);
$smarty->assign("Pos_Price1","$Pos_Price1");
}
if(isset($_REQUEST['Pos_Active1']))
{
$Pos_Active1 = $_REQUEST['Pos_Active1'];
$smarty->assign("Pos_Active1","$Pos_Active1");
}
if(!empty($_REQUEST['Order']))
{
$Order = $_REQUEST['Order'];
$smarty->assign("Order","$Order");
}
else
{
$Order = "POS_GROUP ASC,POS_DESC ASC";
$smarty->assign("Order","$Order");
}
if(isset($_REQUEST['Sort']))
{
$Sort = $_REQUEST['Sort'];
$smarty->assign("Sort","$Sort");
}
$smarty->assign("Title","$a[position] - $a[searchresult]");
$smarty->assign("PositionName","$a[pos_name]");
$smarty->assign("PositionText","$a[pos_text]");
$smarty->assign("PositionGroup","$a[pos_group]");
$smarty->assign("PositionPrice","$a[pos_price]");
$smarty->assign("PositionActive","$a[pos_active]");
$smarty->assign("PositionInactive","$a[pos_inactive]");
$smarty->assign("ShowAllPositions","$a[pos_all]");
$smarty->assign("EntryChanged","$a[entry_changed]");
$smarty->assign("EntryDeleted","$a[entry_deleted]");
// Database connection
//
DBConnect();
// Get lines per page and currency from settings table
//
$smarty->assign("Currency","$CompanyCurrency");
$intCursor = ($intCurrentPage - 1) * $EntrysPerPage;
// Display active, inactive or all positions
// Default is to display only active positions
//
if($Pos_Active1 == '1')
{
$query = $db->GetAll("SELECT POSITIONID, POS_NAME, POS_DESC, POS_GROUP, POS_PRICE, POS_ACTIVE FROM {$TBLName}article WHERE POS_ACTIVE='1' AND POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%' ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
$query1 = $db->Execute("SELECT POS_ACTIVE FROM {$TBLName}article WHERE POS_ACTIVE='1' AND POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%'");
}
else if($Pos_Active1 == '2')
{
$query = $db->GetAll("SELECT POSITIONID, POS_NAME, POS_DESC, POS_GROUP, POS_PRICE, POS_ACTIVE FROM {$TBLName}article WHERE POS_ACTIVE='2' AND POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%' ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
$query1 = $db->Execute("SELECT POS_ACTIVE FROM {$TBLName}article WHERE POS_ACTIVE='2' AND POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%'");
}
else if($Pos_Active1 == '3')
{
$query = $db->GetAll("SELECT POSITIONID, POS_NAME, POS_DESC, POS_GROUP, POS_PRICE, POS_ACTIVE FROM {$TBLName}article WHERE POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%' ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
$query1 = $db->Execute("SELECT POSITIONID FROM {$TBLName}article WHERE POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%'");
}
else
{
$query = $db->GetAll("SELECT POSITIONID, POS_NAME, POS_DESC, POS_GROUP, POS_PRICE, POS_ACTIVE FROM {$TBLName}article WHERE POS_ACTIVE='1' AND POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%' ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
$query1 = $db->Execute("SELECT POS_ACTIVE FROM {$TBLName}article WHERE POS_ACTIVE='1' AND POS_NAME LIKE '$Pos_Name1%' AND POS_DESC LIKE '$Pos_Desc1%' AND POS_PRICE LIKE '%$Pos_Price1%'");
}
// If an error has occurred, display the error message
//
if (!$query)
print($db->ErrorMsg());
else
// Count only PageRows depend on active positions
//
$pagenumrows = count($query);
// Count MaxRows depend on active positions
//
foreach($query1 as $result1)
{
$numrows += count($query1);
}
// Save MaxPages
//
$intPages = ceil($numrows/$EntrysPerPage);
// Save all entrys in $Position
//
foreach($query as $result)
{
$Position[] = $result;
}
$smarty->assign('Positions', $Position);
$smarty->assign("PageRows","$pagenumrows");
$smarty->assign("MaxRows","$numrows");
// Display pager only if $numrows > $EntrysPerPage ( lines per page )
// from settings menu
//
if ($numrows > $EntrysPerPage)
{
$smarty->assign('CurrentPage', "$intCurrentPage");
$smarty->assign('MaxPages', "$intPages");
$smarty->assign('AddCurrentPage', "page=$intCurrentPage&");
// If we are not on first page then display
// first page, previous page link
//
if ($intCurrentPage > 1)
{
$Page = $intCurrentPage - 1;
$smarty->assign('PrevPage', "$Page");
}
// If we are not on the last page then display
// next page, last page link
//
if ($intCurrentPage < $intPages)
{
$Page = $intCurrentPage + 1;
$smarty->assign('NextPage', "$Page");
}
}
$smarty->display('position/searchlist.tpl');
unset($_SESSION['EditID']);
unset($_SESSION['DeleteID']);
?>