"added quoting"

This commit is contained in:
Ralf Becker 2008-04-16 11:37:47 +00:00
parent 0a5be8a725
commit f3181308c5

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* API - Categories * API - Categories
* *
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Joseph Engo <jengo@phpgroupware.org> * @author Joseph Engo <jengo@phpgroupware.org>
* @author Bettina Gille <ceb@phpgroupware.org> * @author Bettina Gille <ceb@phpgroupware.org>
@ -191,15 +191,15 @@ class categories
. $parent_filter . $querymethod . $filter; . $parent_filter . $querymethod . $filter;
$this->total_records = $this->db->select($this->table,'COUNT(*)',$where,__LINE__,__FILE__)->fetchSingle(); $this->total_records = $this->db->select($this->table,'COUNT(*)',$where,__LINE__,__FILE__)->fetchSingle();
if (!$this->total_records) return false; if (!$this->total_records) return false;
foreach($this->db->select($this->table,'*',$where,__LINE__,__FILE__,$limit ? (int) $start : false,$ordermethod) as $cat) foreach($this->db->select($this->table,'*',$where,__LINE__,__FILE__,$limit ? (int) $start : false,$ordermethod) as $cat)
{ {
$cat = egw_db::strip_array_keys($cat,'cat_'); $cat = egw_db::strip_array_keys($cat,'cat_');
$cat['app_name'] = $cat['appname']; $cat['app_name'] = $cat['appname'];
$this->cache_id2cat_data[$cat['id']] = $cat; $this->cache_id2cat_data[$cat['id']] = $cat;
if ($column) if ($column)
{ {
$cats[] = array($column => isset($cat[$column]) ? $cat[$column] : $cat['id']); $cats[] = array($column => isset($cat[$column]) ? $cat[$column] : $cat['id']);
@ -273,7 +273,7 @@ class categories
$cat = egw_db::strip_array_keys($cat,'cat_'); $cat = egw_db::strip_array_keys($cat,'cat_');
$cat['app_name'] = $cat['appname']; $cat['app_name'] = $cat['appname'];
$this->cache_id2cat_data[$cat['id']] = $cat; $this->cache_id2cat_data[$cat['id']] = $cat;
$cats[] = $cat; $cats[] = $cat;
$parents[] = $cat['id']; $parents[] = $cat['id'];
} }
@ -286,7 +286,7 @@ class categories
$cat = egw_db::strip_array_keys($cat,'cat_'); $cat = egw_db::strip_array_keys($cat,'cat_');
$cat['app_name'] = $cat['appname']; $cat['app_name'] = $cat['appname'];
$this->cache_id2cat_data[$cat['id']] = $cat; $this->cache_id2cat_data[$cat['id']] = $cat;
$parents[] = $cat['id']; $parents[] = $cat['id'];
$children[$cat['parent']][] = $cat; $children[$cat['parent']][] = $cat;
} }
@ -309,7 +309,7 @@ class categories
} }
} }
$this->total_records = count($cats); $this->total_records = count($cats);
if ($limit) if ($limit)
{ {
return array_slice($cats,(int)$start,$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']); return array_slice($cats,(int)$start,$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']);
@ -406,7 +406,7 @@ class categories
$s .= '</option>' . "\n"; $s .= '</option>' . "\n";
} }
break; break;
case 'list': case 'list':
$space = '&nbsp;&nbsp;'; $space = '&nbsp;&nbsp;';
@ -469,7 +469,7 @@ class categories
'cat_description' => $values['descr'], 'cat_description' => $values['descr'],
'cat_data' => $values['data'], 'cat_data' => $values['data'],
'cat_main' => $values['main'], 'cat_main' => $values['main'],
'cat_level' => $values['level'], 'cat_level' => $values['level'],
'last_mod' => time(), 'last_mod' => time(),
),(int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(),__LINE__,__FILE__); ),(int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(),__LINE__,__FILE__);
@ -500,8 +500,8 @@ class categories
if ($cat['level'] == 1) if ($cat['level'] == 1)
{ {
$this->db->update($this->table,array( $this->db->update($this->table,array(
'cat_level' => 0, 'cat_level' => 0,
'cat_parent' => 0, 'cat_parent' => 0,
'cat_main' => $cat['id'], 'cat_main' => $cat['id'],
),array( ),array(
'cat_id' => $cat['id'], 'cat_id' => $cat['id'],
@ -513,7 +513,7 @@ class categories
else else
{ {
$update = array('cat_level' => $cat['level']-1); $update = array('cat_level' => $cat['level']-1);
if ($new_main) $update['cat_main'] = $new_main; if ($new_main) $update['cat_main'] = $new_main;
if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent;
@ -578,13 +578,13 @@ class categories
'cat_id' => $values['id'], 'cat_id' => $values['id'],
'cat_appname' => $this->app_name, 'cat_appname' => $this->app_name,
),__LINE__,__FILE__); ),__LINE__,__FILE__);
return (int)$values['id']; return (int)$values['id'];
} }
/** /**
* return category id for a given name * return category id for a given name
* *
* Cat's with the given name are returned in this order: * Cat's with the given name are returned in this order:
* - personal cats first * - personal cats first
* - then application global categories * - then application global categories
@ -598,7 +598,7 @@ class categories
function name2id($cat_name,$strip=false) function name2id($cat_name,$strip=false)
{ {
static $cache = array(); // a litle bit of caching static $cache = array(); // a litle bit of caching
if (isset($cache[$cat_name])) return $cache[$cat_name]; if (isset($cache[$cat_name])) return $cache[$cat_name];
if ($strip === true) if ($strip === true)
@ -617,13 +617,13 @@ class categories
} }
$cats[] = $stripped_cat_name; $cats[] = $stripped_cat_name;
} }
$cat = $this->db->select($this->table,array('cat_name','cat_id'),array( $cat = $this->db->select($this->table,array('cat_name','cat_id'),array(
'cat_name' => $cats, 'cat_name' => $cats,
'cat_appname' => array($this->app_name, 'phpgw'), 'cat_appname' => array($this->app_name, 'phpgw'),
),__LINE__,__FILE__,0, ),__LINE__,__FILE__,0,
"ORDER BY cat_name!='$cat_name',(CASE cat_owner WHEN ".(int)$this->account_id." THEN 1 WHEN -1 THEN 2 ELSE 3 END),cat_appname='phpgw'", 'ORDER BY cat_name<>'.$this->db->quote($cat_name).',(CASE cat_owner WHEN '.(int)$this->account_id." THEN 1 WHEN -1 THEN 2 ELSE 3 END),cat_appname='phpgw'",
false,1)->fetch(); false,1)->fetch();
if (!$cat) return 0; // cat not found, dont cache it, as it might be created in this request if (!$cat) return 0; // cat not found, dont cache it, as it might be created in this request
@ -643,9 +643,9 @@ class categories
function id2name($cat_id=0, $item='name') function id2name($cat_id=0, $item='name')
{ {
if(!$cat_id) return '--'; if(!$cat_id) return '--';
if (!isset($this->cache_id2cat_data[$cat_id])) $this->return_single($cat_id); if (!isset($this->cache_id2cat_data[$cat_id])) $this->return_single($cat_id);
if (!$item) $item = 'parent'; if (!$item) $item = 'parent';
$cat = $this->cache_id2cat_data[$cat_id]; $cat = $this->cache_id2cat_data[$cat_id];
@ -700,7 +700,7 @@ class categories
if ($cat_name) if ($cat_name)
{ {
$where['cat_name'] = $cat_name; $where['cat_name'] = $cat_name;
if ($cat_id) $where[] = 'cat_id != '.(int)$cat_id; if ($cat_id) $where[] = 'cat_id != '.(int)$cat_id;
} }
elseif ($cat_id) elseif ($cat_id)
@ -711,7 +711,7 @@ class categories
return $cache[$type][$cat_name][$cat_id] = $this->db->select($this->table,'cat_id',$where,__LINE__,__FILE__)->fetchSingle(); return $cache[$type][$cat_name][$cat_id] = $this->db->select($this->table,'cat_id',$where,__LINE__,__FILE__)->fetchSingle();
} }
/** /**
* Change the owner of all cats owned by $owner to $to OR deletes them if !$to * Change the owner of all cats owned by $owner to $to OR deletes them if !$to
* *
@ -722,7 +722,7 @@ class categories
function change_owner($owner,$to=0,$app='') function change_owner($owner,$to=0,$app='')
{ {
$where = array('cat_owner' => $owner); $where = array('cat_owner' => $owner);
if ($app) $where['cat_appname'] = $app; if ($app) $where['cat_appname'] = $app;
if ((int)$to) if ((int)$to)