Source for file travel.db.php
Documentation is available at travel.db.php
* database functions for travelling expenses
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: travel.db.php 134 2007-08-24 17:30:36Z m2mtech $
* @link http://www.ea-geier.at/
* standard client db functions
require_once('code/clients.db.php');
require_once('code/numbers.inc.php');
require_once('code/date.inc.php');
$opt['decimal'] = $db->conf['numNumberDecimal'];
$vars = array('txtName', 'txtPeriod', 'txtVouchers', 'numDay', 'numNight', 'txtTax', 'numTax', 'numAmount', 'numDistance', 'numDistRate', 'numDistAmount', 'year', 'month', 'day');
foreach ($vars as $var) if (isset ($data[$var])) switch ($var) {
case 'numDay': case 'numNight': case 'numTax': case 'numAmount':
$what[$var] = makeDot($data[$var], $opt['decimal']);
case 'numDistance': case 'numDistRate':
$what[$var] = makeDotOnly($data[$var], $opt['decimal']);
default: $what[$var] = $data[$var];
$what['lastModified'] = $db->now();
$what['who'] = $db->user['mail'];
$table = $db->table('travels');
if (isset ($data['numID'])) { // old item
if (!$db->update($what, $table, array('id' => $id))) return false;
if (!$db->insert($what, $table)) return false;
if (!$id = $db->lastID()) return false;
return $data['numID'] = $id;
* @param integer clientID
$table = $db->table('travels');
if (!$data = $db->selectOne('*', $table, array('id' => $item))) return false;
* get number of travel items
* @param integer clientID
* @return integer number of items
$table = $db->table('travels');
$what = 'count(id) as c, sum(numAmount) as numAmount, sum(numTax) as numTax, sum(numDistAmount) as numDistAmount';
if (!$where) $where = '';
if (isset ($where['txtName'])) { // we have to prepare it ourselves
$where = "txtName like '%" . $db->escape($where['txtName'], true) . "%'";
unset ($filters['txtName']);
if ($filters) { // other filters available
foreach ($filters as $key => $value)
$where .= ' and ' . $db->escapeKey($key) . ' = ' . $db->escape($value);
if (!$dummy = $db->selectOne($what, $table, $where)) return false;
if (!$dummy['c']) return false;
$data['count'] = $dummy['c'];
$data['numAmount'] = $dummy['numAmount'];
$data['numTax'] = $dummy['numTax'];
$data['numDistAmount'] = $dummy['numDistAmount'];
* load multiple travel items
* @param integer clientID
* @param integer number of items
* @param integer number page
* @param string sorting string
function dbLoadTravelItems(&$db, $client, $num = 10, $page = 1, $sort = false, $where = false) {
$table = $db->table('travels');
if (!$where) $where = '';
if (isset ($where['txtName'])) { // we have to prepare it ourselves
$where = "txtName like '%" . $db->escape($where['txtName'], true) . "%'";
unset ($filters['txtName']);
if ($filters) { // other filters available
foreach ($filters as $key => $value)
$where .= ' and ' . $db->escapeKey($key) . ' = ' . $db->escape($value);
if (!$sort) $sort = 'id asc';
if ($page == - 1) $offset = - 1;
else $offset = $num * ($page - 1);
if (!$data = $db->select('*', $table, $where, $sort, $num, $offset))
* prepare the sql data for output
* @param array configuration data
* @param array travel items
static $separator = false;
if (!$decimal) $decimal = $conf['numNumberDecimal'];
if (!$separator) switch ($conf['txtNumberSeperator']) {
if (!$date) $date = $conf['txtDateFormat'];
$numVars = array('numDay', 'numNight', 'numTax', 'numAmount', 'numDistAmount');
foreach ($numVars as $var) if (isset ($data[$var]))
$data[$var] = makeNum($data[$var], $separator, $decimal);
$numVars = array('numDistance', 'numDistRate');
foreach ($numVars as $var) if (isset ($data[$var]))
* @param integer clientID
* @return array templates
$table = $db->table('travels');
if (!$dummy = $db->select('distinct month, year', $table, '', 'year desc, month desc'))
foreach ($dummy as $val) {
$comb = $val['year'] . '-' . $val['month'];
switch ($db->conf['txtDateFormat']) {
$months[$comb] = $val['month'] . '.' . $val['year'];
|