From 82936fd3c8e42eeb2693747aa76ddd4fc88c424e Mon Sep 17 00:00:00 2001 From: jengo Date: Mon, 12 Mar 2001 12:16:14 +0000 Subject: [PATCH] Added function to return the total categories depending on filter. Also, applied some source formating --- phpgwapi/inc/class.categories.inc.php | 346 ++++++++++++++------------ 1 file changed, 193 insertions(+), 153 deletions(-) diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index 68a5b48b7c..da9bf32a24 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -1,190 +1,230 @@ * - * Category manager * - * Copyright (C) 2000, 2001 Joseph Engo * - * -------------------------------------------------------------------------* - * This library is part of the phpGroupWare API * - * http://www.phpgroupware.org/api * - * ------------------------------------------------------------------------ * - * This library is free software; you can redistribute it and/or modify it * - * under the terms of the GNU Lesser General Public License as published by * - * the Free Software Foundation; either version 2.1 of the License, * - * or any later version. * - * This library 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 Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License * - * along with this library; if not, write to the Free Software Foundation, * - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - \**************************************************************************/ + /**************************************************************************\ + * phpGroupWare API - Categories * + * This file written by Joseph Engo * + * Category manager * + * Copyright (C) 2000, 2001 Joseph Engo * + * -------------------------------------------------------------------------* + * This library is part of the phpGroupWare API * + * http://www.phpgroupware.org/api * + * ------------------------------------------------------------------------ * + * This library is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published by * + * the Free Software Foundation; either version 2.1 of the License, * + * or any later version. * + * This library 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 Lesser General Public License for more details. * + * You should have received a copy of the GNU Lesser General Public License * + * along with this library; if not, write to the Free Software Foundation, * + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + \**************************************************************************/ - /* $Id$ */ + /* $Id$ */ - class categories - { - var $account_id; - var $app_name; - var $cats; - var $db; - var $total_records; + class categories + { + var $account_id; + var $app_name; + var $cats; + var $db; + var $total_records; - function filter($type) - { - switch ($type) - { - case 'subs': $s = " and cat_parent != '0'"; break; - case 'mains': $s = " and cat_parent = '0'"; break; - } - return $s; - } + function filter($type) + { + switch ($type) + { + case 'subs': $s = " and cat_parent != '0'"; break; + case 'mains': $s = " and cat_parent = '0'"; break; + } + return $s; + } - 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 ($order) { $ordermethod = " order by $order $sort"; } - else { $ordermethod = " order by cat_parent asc"; } - - 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 { - $sql = "select * from phpgw_categories where cat_appname='" . $this->app_name . "'" - . "$filter $ordermethod"; - } - - $this->db2->query($sql,__LINE__,__FILE__); - $this->total_records = $this->db2->num_rows(); - $this->db->query($sql. " " . $this->db->limit($start,$limit),__LINE__,__FILE__); - - $i = 0; - 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'); - $cats[$i]['name'] = $this->db->f('cat_name'); - $cats[$i]['description'] = $this->db->f('cat_description'); - $cats[$i]['data'] = $this->db->f('cat_data'); - $i++; - } - return $cats; - } + 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_single($id = '') - { + function return_array($type = 'all',$start,$limit,$query = '',$sort = '',$order = '') + { + global $phpgw, $phpgw_info; - $this->db->query("select * from phpgw_categories where cat_id='$id' and " - . "cat_appname='" . $this->app_name . "'",__LINE__,__FILE__); + $this->db2 = $this->db; + + $filter = $this->filter($type); + if (!$sort) + { + $sort = "ASC"; + } + + if ($order) + { + $ordermethod = " order by $order $sort"; + } + else + { + $ordermethod = " order by cat_parent asc"; + } + + 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 + { + $sql = "select * from phpgw_categories where cat_appname='" . $this->app_name . "'" + . "$filter $ordermethod"; + } + + $this->db2->query($sql,__LINE__,__FILE__); + $this->total_records = $this->db2->num_rows(); + $this->db->query($sql. " " . $this->db->limit($start,$limit),__LINE__,__FILE__); + + $i = 0; + 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'); + $cats[$i]['name'] = $this->db->f('cat_name'); + $cats[$i]['description'] = $this->db->f('cat_description'); + $cats[$i]['data'] = $this->db->f('cat_data'); + $i++; + } + return $cats; + } + + + function return_single($id = '') + { + + $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'); $cats[0]['name'] = $this->db->f('cat_name'); $cats[0]['description'] = $this->db->f('cat_description'); $cats[0]['data'] = $this->db->f('cat_data'); - } - return $cats; - } + } + return $cats; + } - function categories($account_id = '',$app_name = '') - { - global $phpgw, $phpgw_info; + function categories($account_id = '',$app_name = '') + { + global $phpgw, $phpgw_info; - if (! $account_id) { - $account_id = $phpgw_info['user']['account_id']; - } - if (! $app_name) { - $app_name = $phpgw_info['flags']['currentapp']; - } + if (! $account_id) + { + $account_id = $phpgw_info['user']['account_id']; + } - $this->account_id = $account_id; - $this->app_name = $app_name; - $this->db = $phpgw->db; - $this->total_records = $this->db->num_rows(); - $this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order); - } + if (! $app_name) + { + $app_name = $phpgw_info['flags']['currentapp']; + } - // Return into a select box, list or other formats - function formated_list($format,$type,$selected = "") - { - global $phpgw; - $filter = $this->filter($type); + $this->account_id = $account_id; + $this->app_name = $app_name; + $this->db = $phpgw->db; + $this->total_records = $this->db->num_rows(); + $this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order); + } + // Return into a select box, list or other formats + function formated_list($format,$type,$selected = "") + { + global $phpgw; + $filter = $this->filter($type); - if ($format == 'select') { - $this->db->query("select * from phpgw_categories where cat_appname='" . $this->app_name - . "' $filter",__LINE__,__FILE__); - while ($this->db->next_record()) { - $s .= ''; - } - return $s; - } + if ($format == 'select') + { + $this->db->query("select * from phpgw_categories where cat_appname='" . $this->app_name + . "' $filter",__LINE__,__FILE__); + while ($this->db->next_record()) + { + $s .= ''; + } + return $s; + } + } - } - - function add($cat_name,$cat_parent,$cat_description = '', $cat_data = '') - { - $this->db->query('insert into phpgw_categories (cat_parent,cat_owner,cat_appname,cat_name,' + function add($cat_name,$cat_parent,$cat_description = '', $cat_data = '') + { + $this->db->query('insert into phpgw_categories (cat_parent,cat_owner,cat_appname,cat_name,' . "cat_description,cat_data) values ('$cat_parent','" . $this->account_id . "','" . $this->app_name . "','" . addslashes($cat_name) . "','" . addslashes($cat_description) . "','$cat_data')",__LINE__,__FILE__); - } + } - function delete($cat_id) - { - $this->db->query("delete from phpgw_categories where cat_id='$cat_id' and cat_appname='" + function delete($cat_id) + { + $this->db->query("delete from phpgw_categories where cat_id='$cat_id' and cat_appname='" . $this->app_name . "'",__LINE__,__FILE__); - } + } - function edit($cat_id,$cat_parent,$cat_name,$cat_description = '',$cat_data = '') - { - $this->db->query("update phpgw_categories set cat_name='" . addslashes($cat_name) . "', " + function edit($cat_id,$cat_parent,$cat_name,$cat_description = '',$cat_data = '') + { + $this->db->query("update phpgw_categories set cat_name='" . addslashes($cat_name) . "', " . "cat_description='" . addslashes($cat_description) . "', cat_data='" . "$cat_data', cat_parent='$cat_parent' where cat_appname='" . $this->app_name . "' and cat_id='$cat_id'",__LINE__,__FILE__); - } + } - function return_name($cat_id) - { - $this->db->query("select cat_name from phpgw_categories where cat_id='" + function return_name($cat_id) + { + $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')) { - return $this->db->f('cat_name'); - } else { - return '--'; - } - } + $this->db->next_record(); - function exists($type,$cat_name) - { - $filter = $this->filter($type); + if ($this->db->f('cat_name')) + { + return $this->db->f('cat_name'); + } + else + { + return '--'; + } + } - $this->db->query("select count(*) from phpgw_categories where cat_name='" + function exists($type,$cat_name) + { + $filter = $this->filter($type); + + $this->db->query("select count(*) from phpgw_categories where cat_name='" . addslashes($cat_name) . "' and cat_appname='" . $this->app_name . "' $filter",__LINE__,__FILE__); - $this->db->next_record(); - if ($this->db->f(0)) { - return True; - } else { - return False; - } - } - } -?> + $this->db->next_record(); + + if ($this->db->f(0)) + { + return True; + } + else + { + return False; + } + } + } +?> \ No newline at end of file