2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2001-01-13 11:18:50 +01:00
|
|
|
* phpGroupWare API - Categories *
|
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* Category manager *
|
|
|
|
* Copyright (C) 2000, 2001 Joseph Engo *
|
|
|
|
* -------------------------------------------------------------------------*
|
2001-01-16 14:52:32 +01:00
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
2001-01-13 11:18:50 +01:00
|
|
|
* 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 *
|
2001-01-11 10:52:33 +01:00
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class categories
|
|
|
|
{
|
|
|
|
var $account_id;
|
|
|
|
var $app_name;
|
|
|
|
var $cats;
|
|
|
|
var $db;
|
2001-01-20 00:45:37 +01:00
|
|
|
|
|
|
|
function filter($type)
|
|
|
|
{
|
|
|
|
switch ($type)
|
|
|
|
{
|
2001-02-11 21:03:35 +01:00
|
|
|
case 'subs': $s = " and cat_parent != '0'"; break;
|
|
|
|
case 'mains': $s = " and cat_parent = '0'"; break;
|
2001-01-20 00:45:37 +01:00
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
2001-02-21 02:23:23 +01:00
|
|
|
function return_array($type ='all',$start,$limit,$query = '',$sort = '',$order = '') {
|
2001-02-04 09:27:35 +01:00
|
|
|
|
2001-02-21 02:23:23 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
|
|
|
|
|
|
|
$filter = $this->filter($type);
|
|
|
|
|
|
|
|
if (!$sort) { $sort = "ASC"; }
|
|
|
|
|
|
|
|
if ($order) { $ordermethod = " order by $order $sort"; }
|
|
|
|
else { $ordermethod = " order by cat_parent asc"; }
|
|
|
|
|
|
|
|
if ($query) {
|
|
|
|
$phpgw->db->query("select * from phpgw_categories where cat_appname='" . $this->app_name . "' and "
|
|
|
|
. "(cat_name like '%$query%' or cat_description like '%$query%') $filter $ordermethod" . " "
|
|
|
|
. $this->db->limit($start,$limit),__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$phpgw->db->query("select * from phpgw_categories where cat_appname='" . $this->app_name . "'"
|
|
|
|
. "$filter $ordermethod" . " "
|
|
|
|
. $this->db->limit($start,$limit),__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while ($phpgw->db->next_record()) {
|
|
|
|
$cats[$i]['id'] = $phpgw->db->f('cat_id');
|
|
|
|
$cats[$i]['owner'] = $phpgw->db->f('cat_owner');
|
|
|
|
$cats[$i]['parent'] = $phpgw->db->f('cat_parent');
|
|
|
|
$cats[$i]['name'] = $phpgw->db->f('cat_name');
|
|
|
|
$cats[$i]['description'] = $phpgw->db->f('cat_description');
|
|
|
|
$cats[$i]['data'] = $phpgw->db->f('cat_data');
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $cats;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function return_single($id = '')
|
|
|
|
{
|
2001-01-20 00:45:37 +01:00
|
|
|
|
2001-02-21 02:23:23 +01:00
|
|
|
$this->db->query("select * from phpgw_categories where cat_id='$id'",__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$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');
|
2001-01-20 00:45:37 +01:00
|
|
|
}
|
|
|
|
return $cats;
|
|
|
|
}
|
|
|
|
|
2001-02-11 21:03:35 +01:00
|
|
|
function categories($account_id = '',$app_name = '')
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-01-11 16:33:23 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
|
|
|
|
|
|
|
if (! $account_id) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$account_id = $phpgw_info['user']['account_id'];
|
2001-01-11 16:33:23 +01:00
|
|
|
}
|
|
|
|
if (! $app_name) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$app_name = $phpgw_info['flags']['currentapp'];
|
2001-01-11 16:33:23 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 10:52:33 +01:00
|
|
|
$this->account_id = $account_id;
|
|
|
|
$this->app_name = $app_name;
|
|
|
|
$this->db = $phpgw->db;
|
2001-02-21 02:23:23 +01:00
|
|
|
$this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order);
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return into a select box, list or other formats
|
2001-01-20 00:45:37 +01:00
|
|
|
function formated_list($format,$type,$selected = "")
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-01-11 15:53:07 +01:00
|
|
|
global $phpgw;
|
2001-01-20 00:45:37 +01:00
|
|
|
$filter = $this->filter($type);
|
2001-01-11 15:53:07 +01:00
|
|
|
|
2001-02-11 21:03:35 +01:00
|
|
|
if ($format == 'select') {
|
2001-02-19 12:26:08 +01:00
|
|
|
$this->db->query("select * from phpgw_categories where cat_appname='" . $this->app_name
|
2001-01-20 00:45:37 +01:00
|
|
|
. "' $filter",__LINE__,__FILE__);
|
2001-01-11 15:53:07 +01:00
|
|
|
while ($this->db->next_record()) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$s .= '<option value="' . $this->db->f('cat_id') . '"';
|
|
|
|
if ($this->db->f('cat_id') == $selected) {
|
|
|
|
$s .= ' selected';
|
2001-01-20 00:45:37 +01:00
|
|
|
}
|
2001-02-11 21:03:35 +01:00
|
|
|
$s .= '>' . $phpgw->strip_html($this->db->f('cat_name'))
|
2001-01-20 00:45:37 +01:00
|
|
|
. '</option>';
|
2001-01-11 15:53:07 +01:00
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
2001-01-11 14:37:37 +01:00
|
|
|
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
2001-01-11 14:37:37 +01:00
|
|
|
|
2001-02-11 21:03:35 +01:00
|
|
|
function add($cat_name,$cat_parent,$cat_description = '', $cat_data = '')
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-02-11 21:03:35 +01:00
|
|
|
$this->db->query('insert into phpgw_categories (cat_parent,cat_owner,cat_appname,cat_name,'
|
2001-01-11 10:52:33 +01:00
|
|
|
. "cat_description,cat_data) values ('$cat_parent','" . $this->account_id . "','"
|
2001-01-11 14:37:37 +01:00
|
|
|
. $this->app_name . "','" . addslashes($cat_name) . "','" . addslashes($cat_description)
|
|
|
|
. "','$cat_data')",__LINE__,__FILE__);
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete($cat_id)
|
|
|
|
{
|
2001-02-19 12:26:08 +01:00
|
|
|
$this->db->query("delete from phpgw_categories where cat_id='$cat_id' and cat_appname='"
|
|
|
|
. $this->app_name . "'",__LINE__,__FILE__);
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-02-11 21:03:35 +01:00
|
|
|
function edit($cat_id,$cat_parent,$cat_name,$cat_description = '',$cat_data = '')
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-01-11 15:53:07 +01:00
|
|
|
$this->db->query("update phpgw_categories set cat_name='" . addslashes($cat_name) . "', "
|
|
|
|
. "cat_description='" . addslashes($cat_description) . "', cat_data='"
|
2001-02-19 12:26:08 +01:00
|
|
|
. "$cat_data', cat_parent='$cat_parent' where cat_appname='"
|
|
|
|
. $this->app_name . "' and cat_id='$cat_id'",__LINE__,__FILE__);
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-01-20 00:45:37 +01:00
|
|
|
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();
|
2001-02-11 21:03:35 +01:00
|
|
|
if ($this->db->f('cat_name')) {
|
|
|
|
return $this->db->f('cat_name');
|
2001-01-31 08:46:26 +01:00
|
|
|
} else {
|
2001-02-11 21:03:35 +01:00
|
|
|
return '--';
|
2001-01-31 08:46:26 +01:00
|
|
|
}
|
2001-01-20 00:45:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function exists($type,$cat_name)
|
|
|
|
{
|
|
|
|
$filter = $this->filter($type);
|
|
|
|
|
|
|
|
$this->db->query("select count(*) from phpgw_categories where cat_name='"
|
2001-02-19 12:26:08 +01:00
|
|
|
. addslashes($cat_name) . "' and cat_appname='"
|
|
|
|
. $this->app_name . "' $filter",__LINE__,__FILE__);
|
2001-01-20 00:45:37 +01:00
|
|
|
$this->db->next_record();
|
|
|
|
if ($this->db->f(0)) {
|
|
|
|
return True;
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
2001-01-20 00:45:37 +01:00
|
|
|
?>
|