Added function to return the total categories depending on filter. Also, applied some source formating

This commit is contained in:
jengo 2001-03-12 12:16:14 +00:00
parent d879bf8c96
commit 82936fd3c8

View File

@ -41,23 +41,51 @@
return $s;
}
function return_array($type = 'all',$start,$limit,$query = '',$sort = '',$order = '') {
function total($for = 'app')
{
switch($for)
{
case 'app': $w = " cat_appname='" . $this->app_name . "'"; break;
case 'subs': $w = " cat_parent != '0'"; break;
case 'mains': $w = " cat_parent = '0'"; break;
default: return False;
}
$this->db->query("select count(*) from phpgw_categories $w");
$this->db->next_record();
return $this->db->f(0);
}
function return_array($type = 'all',$start,$limit,$query = '',$sort = '',$order = '')
{
global $phpgw, $phpgw_info;
$this->db2 = $this->db;
$filter = $this->filter($type);
if (!$sort) { $sort = "ASC"; }
if (!$sort)
{
$sort = "ASC";
}
if ($order) { $ordermethod = " order by $order $sort"; }
else { $ordermethod = " order by cat_parent asc"; }
if ($order)
{
$ordermethod = " order by $order $sort";
}
else
{
$ordermethod = " order by cat_parent asc";
}
if ($query) {
if ($query)
{
$sql = "select * from phpgw_categories where cat_appname='" . $this->app_name . "' and "
. "(cat_name like '%$query%' or cat_description like '%$query%') $filter $ordermethod";
}
else {
else
{
$sql = "select * from phpgw_categories where cat_appname='" . $this->app_name . "'"
. "$filter $ordermethod";
}
@ -67,7 +95,8 @@
$this->db->query($sql. " " . $this->db->limit($start,$limit),__LINE__,__FILE__);
$i = 0;
while ($this->db->next_record()) {
while ($this->db->next_record())
{
$cats[$i]['id'] = $this->db->f('cat_id');
$cats[$i]['owner'] = $this->db->f('cat_owner');
$cats[$i]['parent'] = $this->db->f('cat_parent');
@ -86,7 +115,7 @@
$this->db->query("select * from phpgw_categories where cat_id='$id' and "
. "cat_appname='" . $this->app_name . "'",__LINE__,__FILE__);
$this->db->next_record(); {
while ($this->db->next_record()) {
$cats[0]['id'] = $this->db->f('cat_id');
$cats[0]['owner'] = $this->db->f('cat_owner');
$cats[0]['parent'] = $this->db->f('cat_parent');
@ -101,10 +130,13 @@
{
global $phpgw, $phpgw_info;
if (! $account_id) {
if (! $account_id)
{
$account_id = $phpgw_info['user']['account_id'];
}
if (! $app_name) {
if (! $app_name)
{
$app_name = $phpgw_info['flags']['currentapp'];
}
@ -121,21 +153,21 @@
global $phpgw;
$filter = $this->filter($type);
if ($format == 'select') {
if ($format == 'select')
{
$this->db->query("select * from phpgw_categories where cat_appname='" . $this->app_name
. "' $filter",__LINE__,__FILE__);
while ($this->db->next_record()) {
while ($this->db->next_record())
{
$s .= '<option value="' . $this->db->f('cat_id') . '"';
if ($this->db->f('cat_id') == $selected) {
if ($this->db->f('cat_id') == $selected)
{
$s .= ' selected';
}
$s .= '>' . $phpgw->strip_html($this->db->f('cat_name'))
. '</option>';
$s .= '>' . $phpgw->strip_html($this->db->f('cat_name')) . '</option>';
}
return $s;
}
}
function add($cat_name,$cat_parent,$cat_description = '', $cat_data = '')
@ -165,9 +197,13 @@
$this->db->query("select cat_name from phpgw_categories where cat_id='"
. "$cat_id'",__LINE__,__FILE__);
$this->db->next_record();
if ($this->db->f('cat_name')) {
if ($this->db->f('cat_name'))
{
return $this->db->f('cat_name');
} else {
}
else
{
return '--';
}
}
@ -180,9 +216,13 @@
. addslashes($cat_name) . "' and cat_appname='"
. $this->app_name . "' $filter",__LINE__,__FILE__);
$this->db->next_record();
if ($this->db->f(0)) {
if ($this->db->f(0))
{
return True;
} else {
}
else
{
return False;
}
}