2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
2001-03-12 13:16:14 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - Categories *
|
2003-05-22 01:02:25 +02:00
|
|
|
* Written by Joseph Engo <jengo@phpgroupware.org> *
|
2002-01-13 01:39:26 +01:00
|
|
|
* and Bettina Gille [ceb@phpgroupware.org] *
|
2001-03-12 13:16:14 +01:00
|
|
|
* Category manager *
|
2003-05-22 01:02:25 +02:00
|
|
|
* Copyright (C) 2000, 2001 Joseph Engo, Bettina Gille *
|
|
|
|
* Copyright (C) 2002, 2003 Bettina Gille *
|
2002-09-04 02:30:50 +02:00
|
|
|
* ------------------------------------------------------------------------ *
|
2001-03-12 13:16:14 +01:00
|
|
|
* This library is part of the phpGroupWare API *
|
2003-05-22 01:02:25 +02:00
|
|
|
* http://www.phpgroupware.org *
|
2001-03-12 13:16:14 +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 *
|
|
|
|
\**************************************************************************/
|
|
|
|
/* $Id$ */
|
2002-01-01 21:58:22 +01:00
|
|
|
|
2002-01-03 18:16:56 +01:00
|
|
|
/*!
|
|
|
|
@class categories
|
|
|
|
@abstract class adds ability for applications to make use of categories
|
|
|
|
@discussion examples can be found in notes app
|
|
|
|
*/
|
2001-03-12 13:16:14 +01:00
|
|
|
class categories
|
|
|
|
{
|
|
|
|
var $account_id;
|
|
|
|
var $app_name;
|
|
|
|
var $cats;
|
|
|
|
var $db;
|
|
|
|
var $total_records;
|
2001-03-27 09:19:28 +02:00
|
|
|
var $grants;
|
2001-04-25 19:00:31 +02:00
|
|
|
|
2002-01-03 18:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function categories
|
|
|
|
@abstract constructor for categories class
|
|
|
|
@param $accountid account id
|
|
|
|
@param $app_name app name defaults to current app
|
|
|
|
*/
|
|
|
|
function categories($accountid = '',$app_name = '')
|
|
|
|
{
|
|
|
|
$account_id = get_account_id($accountid);
|
|
|
|
|
|
|
|
if (! $app_name)
|
|
|
|
{
|
|
|
|
$app_name = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
|
|
|
}
|
|
|
|
|
2002-10-15 02:12:39 +02:00
|
|
|
$this->account_id = $account_id;
|
2003-05-03 16:17:15 +02:00
|
|
|
$this->app_name = $app_name;
|
2002-10-15 02:12:39 +02:00
|
|
|
$this->db = $GLOBALS['phpgw']->db;
|
|
|
|
$this->db2 = $this->db;
|
|
|
|
$this->grants = $GLOBALS['phpgw']->acl->get_grants($app_name);
|
2002-01-03 18:16:56 +01:00
|
|
|
}
|
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function filter
|
|
|
|
@abstract ?
|
|
|
|
@param $type string
|
|
|
|
@result string either subs or mains
|
|
|
|
*/
|
2001-03-12 13:16:14 +01:00
|
|
|
function filter($type)
|
|
|
|
{
|
|
|
|
switch ($type)
|
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
case 'subs': $s = ' AND cat_parent != 0'; break;
|
|
|
|
case 'mains': $s = ' AND cat_parent = 0'; break;
|
|
|
|
case 'appandmains': $s = " AND cat_appname='" . $this->app_name . "' AND cat_parent =0"; break;
|
|
|
|
case 'appandsubs': $s = " AND cat_appname='" . $this->app_name . "' AND cat_parent !=0"; break;
|
2002-09-08 22:40:12 +02:00
|
|
|
case 'noglobal': $s = " AND cat_appname != '" . $this->app_name . "'"; break;
|
2003-05-02 01:24:09 +02:00
|
|
|
case 'noglobalapp': $s = " AND cat_appname = '" . $this->app_name . "' AND cat_owner != " . $this->account_id; break;
|
2002-10-15 02:12:39 +02:00
|
|
|
default: return False;
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
2002-01-03 18:16:56 +01:00
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function total
|
|
|
|
@abstract returns the total number of categories for app, subs or mains
|
|
|
|
@param $for one of either 'app' 'subs' or 'mains'
|
|
|
|
@result integer count of categories
|
|
|
|
*/
|
2001-03-12 13:16:14 +01:00
|
|
|
function total($for = 'app')
|
|
|
|
{
|
|
|
|
switch($for)
|
|
|
|
{
|
2002-10-15 02:12:39 +02:00
|
|
|
case 'app': $w = " WHERE cat_appname='" . $this->app_name . "'"; break;
|
2003-05-02 01:24:09 +02:00
|
|
|
case 'appandmains': $w = " WHERE cat_appname='" . $this->app_name . "' AND cat_parent =0"; break;
|
|
|
|
case 'appandsubs': $w = " WHERE cat_appname='" . $this->app_name . "' AND cat_parent !=0"; break;
|
|
|
|
case 'subs': $w = " WHERE cat_parent != 0"; break;
|
|
|
|
case 'mains': $w = " WHERE cat_parent = 0"; break;
|
2002-10-15 02:12:39 +02:00
|
|
|
default: return False;
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2002-01-02 00:25:54 +01:00
|
|
|
|
2001-11-18 07:11:05 +01:00
|
|
|
$this->db->query("SELECT COUNT(cat_id) FROM phpgw_categories $w",__LINE__,__FILE__);
|
2001-03-12 13:16:14 +01:00
|
|
|
$this->db->next_record();
|
2001-05-02 01:17:13 +02:00
|
|
|
|
2001-03-12 13:16:14 +01:00
|
|
|
return $this->db->f(0);
|
|
|
|
}
|
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
function db2cats()
|
|
|
|
{
|
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
|
|
|
$cats[] = array
|
|
|
|
(
|
|
|
|
'cat_id' => $this->db->f('cat_id'),
|
|
|
|
'owner' => $this->db->f('cat_owner'),
|
|
|
|
'access' => $this->db->f('cat_access'),
|
|
|
|
'app_name' => $this->db->f('cat_appname'),
|
|
|
|
'main' => $this->db->f('cat_main'),
|
|
|
|
'level' => $this->db->f('cat_level'),
|
|
|
|
'parent' => $this->db->f('cat_parent'),
|
|
|
|
'name' => $this->db->f('cat_name'),
|
|
|
|
'descr' => $this->db->f('cat_description'),
|
2003-05-02 01:24:09 +02:00
|
|
|
'data' => $this->db->f('cat_data'),
|
|
|
|
'last_mod' => $this->db->f('last_mod')
|
2002-10-12 19:23:56 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $cats;
|
|
|
|
}
|
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function return_array
|
|
|
|
@abstract return an array populated with categories
|
|
|
|
@param $type string defaults to 'all'
|
|
|
|
@param $start ?
|
|
|
|
@param $limit ?
|
|
|
|
@param $query string defaults to ''
|
|
|
|
@param $sort string sort order, either defaults to 'ASC'
|
|
|
|
@param $order order by
|
2002-07-03 02:55:47 +02:00
|
|
|
@param $globals True or False, includes the global phpgroupware categories or not
|
2001-03-22 07:10:22 +01:00
|
|
|
@result $cats array
|
|
|
|
*/
|
2003-05-02 01:24:09 +02:00
|
|
|
function return_array($type,$start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '',$lastmod = -1)
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$start = intval($start);
|
|
|
|
$query = $this->db->db_addslashes($query);
|
|
|
|
|
2002-07-03 02:55:47 +02:00
|
|
|
if ($globals)
|
2001-03-25 07:58:28 +02:00
|
|
|
{
|
2002-07-03 02:55:47 +02:00
|
|
|
$global_cats = " OR cat_appname='phpgw'";
|
2001-03-25 07:58:28 +02:00
|
|
|
}
|
2001-03-12 13:16:14 +01:00
|
|
|
|
|
|
|
$filter = $this->filter($type);
|
2002-10-12 23:18:23 +02:00
|
|
|
|
2001-03-12 13:16:14 +01:00
|
|
|
if (!$sort)
|
|
|
|
{
|
2001-11-18 07:11:05 +01:00
|
|
|
$sort = 'ASC';
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($order)
|
|
|
|
{
|
2001-11-18 07:11:05 +01:00
|
|
|
$ordermethod = " ORDER BY $order $sort";
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-18 07:11:05 +01:00
|
|
|
$ordermethod = ' ORDER BY cat_main, cat_level, cat_name ASC';
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
|
2002-03-13 17:30:51 +01:00
|
|
|
if ($this->account_id == '-1')
|
2001-03-27 09:19:28 +02:00
|
|
|
{
|
2002-03-13 17:30:51 +01:00
|
|
|
$grant_cats = " cat_owner='-1' ";
|
2001-03-27 09:19:28 +02:00
|
|
|
}
|
2001-05-02 01:17:13 +02:00
|
|
|
else
|
2001-03-27 09:19:28 +02:00
|
|
|
{
|
2002-03-13 17:30:51 +01:00
|
|
|
if (is_array($this->grants))
|
|
|
|
{
|
|
|
|
$grants = $this->grants;
|
|
|
|
while(list($user) = each($grants))
|
|
|
|
{
|
|
|
|
$public_user_list[] = $user;
|
|
|
|
}
|
|
|
|
reset($public_user_list);
|
|
|
|
$grant_cats = " (cat_owner='" . $this->account_id . "' OR cat_owner='-1' OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ")) ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$grant_cats = " cat_owner='" . $this->account_id . "' OR cat_owner='-1' ";
|
|
|
|
}
|
2001-03-27 09:19:28 +02:00
|
|
|
}
|
|
|
|
|
2003-05-03 16:17:15 +02:00
|
|
|
if (intval($parent_id) > 0)
|
2001-04-25 19:00:31 +02:00
|
|
|
{
|
2003-05-03 16:17:15 +02:00
|
|
|
$parent_id = intval($parent_id);
|
2003-05-02 01:24:09 +02:00
|
|
|
$parent_filter = ' AND cat_parent=' . $parent_id;
|
2001-04-25 19:00:31 +02:00
|
|
|
}
|
|
|
|
|
2001-03-12 13:16:14 +01:00
|
|
|
if ($query)
|
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%')";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($lastmod >= 0)
|
|
|
|
{
|
|
|
|
$querymethod .= ' AND lastmod > ' . $lastmod;
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2001-05-02 01:17:13 +02:00
|
|
|
|
2002-07-03 02:55:47 +02:00
|
|
|
$sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ")"
|
2002-01-03 18:16:56 +01:00
|
|
|
. $parent_filter . $querymethod . $filter;
|
2002-10-12 23:18:23 +02:00
|
|
|
|
2002-10-15 02:12:39 +02:00
|
|
|
$this->db2->query($sql,__LINE__,__FILE__);
|
|
|
|
$this->total_records = $this->db2->num_rows();
|
|
|
|
|
2001-07-02 22:08:57 +02:00
|
|
|
if ($limit)
|
|
|
|
{
|
|
|
|
$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
|
|
|
|
}
|
2001-06-06 05:17:45 +02:00
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
return $this->db2cats();
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
|
2002-09-03 04:21:36 +02:00
|
|
|
function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '')
|
2002-01-12 05:08:35 +01:00
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$start = intval($start);
|
|
|
|
$parent_id = intval($parent_id);
|
2003-05-03 16:17:15 +02:00
|
|
|
$query = $this->db->db_addslashes($query);
|
2003-05-02 01:24:09 +02:00
|
|
|
|
2002-07-03 02:55:47 +02:00
|
|
|
if ($globals)
|
2002-01-12 05:08:35 +01:00
|
|
|
{
|
2002-07-03 02:55:47 +02:00
|
|
|
$global_cats = " OR cat_appname='phpgw'";
|
2002-01-12 05:08:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$sort)
|
|
|
|
{
|
|
|
|
$sort = 'ASC';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($order)
|
|
|
|
{
|
|
|
|
$ordermethod = " ORDER BY $order $sort";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ordermethod = ' ORDER BY cat_name ASC';
|
|
|
|
}
|
|
|
|
|
2002-03-13 17:30:51 +01:00
|
|
|
if ($this->account_id == '-1')
|
2002-01-12 05:08:35 +01:00
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$grant_cats = ' cat_owner=-1 ';
|
2002-01-12 05:08:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-03-13 17:30:51 +01:00
|
|
|
if (is_array($this->grants))
|
|
|
|
{
|
|
|
|
$grants = $this->grants;
|
|
|
|
while(list($user) = each($grants))
|
|
|
|
{
|
|
|
|
$public_user_list[] = $user;
|
|
|
|
}
|
|
|
|
reset($public_user_list);
|
|
|
|
$grant_cats = " (cat_owner='" . $this->account_id . "' OR cat_owner='-1' OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ")) ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' ";
|
|
|
|
}
|
2002-01-12 05:08:35 +01:00
|
|
|
}
|
|
|
|
|
2003-05-02 01:24:09 +02:00
|
|
|
$parent_select = ' AND cat_parent=' . $parent_id;
|
2002-09-03 04:21:36 +02:00
|
|
|
|
2002-01-12 05:08:35 +01:00
|
|
|
if ($query)
|
|
|
|
{
|
|
|
|
$querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%') ";
|
|
|
|
}
|
|
|
|
|
2002-07-03 02:55:47 +02:00
|
|
|
$sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ")"
|
2002-01-12 05:08:35 +01:00
|
|
|
. $querymethod;
|
|
|
|
|
2002-10-15 02:12:39 +02:00
|
|
|
$this->db2->query($sql . $parent_select,__LINE__,__FILE__);
|
2002-10-21 00:01:46 +02:00
|
|
|
//$total_mains = $this->db2->num_rows();
|
|
|
|
$this->total_records = $this->db2->num_rows();
|
2002-10-15 02:12:39 +02:00
|
|
|
|
2002-01-13 01:39:26 +01:00
|
|
|
if ($limit)
|
|
|
|
{
|
2002-09-03 04:21:36 +02:00
|
|
|
$this->db->limit_query($sql . $parent_select . $ordermethod,$start,__LINE__,__FILE__);
|
2002-01-13 01:39:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-09-03 04:21:36 +02:00
|
|
|
$this->db->query($sql . $parent_select . $ordermethod,__LINE__,__FILE__);
|
2002-01-13 01:39:26 +01:00
|
|
|
}
|
2002-01-12 05:08:35 +01:00
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
$cats = $this->db2cats();
|
2002-01-12 05:08:35 +01:00
|
|
|
|
|
|
|
$num_cats = count($cats);
|
|
|
|
for ($i=0;$i < $num_cats;$i++)
|
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$sub_select = ' AND cat_parent=' . $cats[$i]['cat_id'] . ' AND cat_level=' . ($cats[$i]['level']+1);
|
2002-01-12 05:08:35 +01:00
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
/*$this->db2->query($sql . $sub_select,__LINE__,__FILE__);
|
2002-10-15 02:12:39 +02:00
|
|
|
$total_subs += $this->db2->num_rows();
|
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
if ($limit)
|
2002-01-13 01:39:26 +01:00
|
|
|
{
|
2002-09-03 04:21:36 +02:00
|
|
|
$this->db->limit_query($sql . $sub_select . $ordermethod,$start,__LINE__,__FILE__);
|
2002-01-13 01:39:26 +01:00
|
|
|
}
|
|
|
|
else
|
2002-10-15 23:40:58 +02:00
|
|
|
{*/
|
2002-09-03 04:21:36 +02:00
|
|
|
$this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__);
|
2002-10-15 23:40:58 +02:00
|
|
|
//}
|
2002-01-12 05:08:35 +01:00
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
$subcats = $this->db2cats();
|
2002-01-12 05:08:35 +01:00
|
|
|
|
|
|
|
$num_subcats = count($subcats);
|
|
|
|
if ($num_subcats != 0)
|
|
|
|
{
|
|
|
|
$newcats = array();
|
|
|
|
for ($k = 0; $k <= $i; $k++)
|
|
|
|
{
|
|
|
|
$newcats[$k] = $cats[$k];
|
|
|
|
}
|
|
|
|
for ($k = 0; $k < $num_subcats; $k++)
|
|
|
|
{
|
|
|
|
$newcats[$k+$i+1] = $subcats[$k];
|
|
|
|
}
|
|
|
|
for ($k = $i+1; $k < $num_cats; $k++)
|
|
|
|
{
|
|
|
|
$newcats[$k+$num_subcats] = $cats[$k];
|
|
|
|
}
|
|
|
|
$cats = $newcats;
|
|
|
|
$num_cats = count($cats);
|
|
|
|
}
|
|
|
|
}
|
2002-10-15 02:12:39 +02:00
|
|
|
//$this->total_records = count($cats);
|
2002-10-21 00:01:46 +02:00
|
|
|
//$this->total_records = $total_mains + $total_subs;
|
2002-01-12 05:08:35 +01:00
|
|
|
return $cats;
|
|
|
|
}
|
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function return_single
|
|
|
|
@abstract return single
|
2001-05-02 01:17:13 +02:00
|
|
|
@param $id integer id of category
|
|
|
|
@result $cats array populated with
|
2001-03-22 07:10:22 +01:00
|
|
|
*/
|
2002-10-14 00:04:55 +02:00
|
|
|
function return_single($cat_id = '')
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2002-10-14 00:04:55 +02:00
|
|
|
$this->db->query('SELECT * FROM phpgw_categories WHERE cat_id=' . intval($cat_id),__LINE__,__FILE__);
|
2001-05-02 01:17:13 +02:00
|
|
|
|
2002-10-12 23:18:23 +02:00
|
|
|
list($cat) = $this->db2cats();
|
|
|
|
|
|
|
|
return $cat;
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2001-05-23 22:19:23 +02:00
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
2002-10-14 00:04:55 +02:00
|
|
|
@function formatted_list
|
2001-03-22 07:10:22 +01:00
|
|
|
@abstract return into a select box, list or other formats
|
|
|
|
@param $format currently only supports select (select box)
|
|
|
|
@param $type string - subs or mains
|
2001-05-23 22:19:23 +02:00
|
|
|
@param $selected - cat_id or array with cat_id values
|
2002-07-03 02:55:47 +02:00
|
|
|
@param $globals True or False, includes the global phpgroupware categories or not
|
2001-03-22 07:10:22 +01:00
|
|
|
@result $s array - populated with categories
|
|
|
|
*/
|
2002-01-15 03:52:51 +01:00
|
|
|
|
2002-10-14 00:04:55 +02:00
|
|
|
function formatted_list($format,$type = 'all',$selected = '',$globals = False,$site_link = 'site')
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2001-12-29 20:31:52 +01:00
|
|
|
if(is_array($format))
|
|
|
|
{
|
2002-10-12 19:23:56 +02:00
|
|
|
$temp_format = $format['format'];
|
|
|
|
$type = (isset($format['type'])?$format['type']:'all');
|
|
|
|
$selected = (isset($format['selected'])?$format['selected']:'');
|
|
|
|
$globals = (isset($format['globals'])?$format['globals']:False);
|
|
|
|
$site_link = (isset($format['site_link'])?$format['site_link']:'site');
|
2001-12-29 20:31:52 +01:00
|
|
|
settype($format,'string');
|
2002-10-12 19:23:56 +02:00
|
|
|
$format = $temp_format;
|
2001-12-29 20:31:52 +01:00
|
|
|
unset($temp_format);
|
|
|
|
}
|
2002-01-03 18:16:56 +01:00
|
|
|
|
2001-05-23 22:19:23 +02:00
|
|
|
if (!is_array($selected))
|
|
|
|
{
|
|
|
|
$selected = explode(',',$selected);
|
2001-06-06 05:17:45 +02:00
|
|
|
}
|
2001-03-12 13:16:14 +01:00
|
|
|
|
2002-01-12 05:08:35 +01:00
|
|
|
if ($type != 'all')
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2002-07-03 02:55:47 +02:00
|
|
|
$cats = $this->return_array($type,$start,False,$query,$sort,$order,$globals);
|
2002-01-12 05:08:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-07-03 02:55:47 +02:00
|
|
|
$cats = $this->return_sorted_array($start,False,$query,$sort,$order,$globals);
|
2002-01-12 05:08:35 +01:00
|
|
|
}
|
2001-03-27 05:40:18 +02:00
|
|
|
|
2002-01-12 05:08:35 +01:00
|
|
|
if ($format == 'select')
|
|
|
|
{
|
2001-03-27 05:40:18 +02:00
|
|
|
for ($i=0;$i<count($cats);$i++)
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2002-10-12 20:01:39 +02:00
|
|
|
$s .= '<option value="' . $cats[$i]['cat_id'] . '"';
|
|
|
|
if (in_array($cats[$i]['cat_id'],$selected))
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
|
|
|
$s .= ' selected';
|
|
|
|
}
|
2002-01-12 05:08:35 +01:00
|
|
|
$s .= '>';
|
|
|
|
for ($j=0;$j<$cats[$i]['level'];$j++)
|
|
|
|
{
|
2002-10-13 00:33:24 +02:00
|
|
|
$s .= ' . ';
|
2002-01-12 05:08:35 +01:00
|
|
|
}
|
|
|
|
$s .= $GLOBALS['phpgw']->strip_html($cats[$i]['name']);
|
2001-05-01 04:15:13 +02:00
|
|
|
if ($cats[$i]['app_name'] == 'phpgw')
|
2001-03-25 09:21:37 +02:00
|
|
|
{
|
2002-04-04 22:52:04 +02:00
|
|
|
$s .= ' <' . lang('Global') . '>';
|
2001-03-25 09:21:37 +02:00
|
|
|
}
|
2002-03-13 05:16:46 +01:00
|
|
|
if ($cats[$i]['owner'] == '-1')
|
|
|
|
{
|
2002-04-04 22:52:04 +02:00
|
|
|
$s .= ' <' . lang('Global') . ' ' . lang($this->app_name) . '>';
|
2002-03-13 05:16:46 +01:00
|
|
|
}
|
|
|
|
|
2001-05-24 02:51:35 +02:00
|
|
|
$s .= '</option>' . "\n";
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
2001-05-01 04:15:13 +02:00
|
|
|
|
2001-05-15 02:00:49 +02:00
|
|
|
if ($format == 'list')
|
|
|
|
{
|
|
|
|
$space = ' ';
|
2001-05-01 04:15:13 +02:00
|
|
|
|
2001-05-15 02:00:49 +02:00
|
|
|
$s = '<table border="0" cellpadding="2" cellspacing="2">' . "\n";
|
2001-05-02 01:17:13 +02:00
|
|
|
|
2001-06-07 09:44:26 +02:00
|
|
|
if ($this->total_records > 0)
|
2001-05-15 02:00:49 +02:00
|
|
|
{
|
2001-06-07 09:44:26 +02:00
|
|
|
for ($i=0;$i<count($cats);$i++)
|
2001-05-15 02:00:49 +02:00
|
|
|
{
|
2001-06-07 09:44:26 +02:00
|
|
|
$image_set = ' ';
|
2001-05-02 01:17:13 +02:00
|
|
|
|
2002-10-12 20:01:39 +02:00
|
|
|
if (in_array($cats[$i]['cat_id'],$selected))
|
2001-06-07 09:44:26 +02:00
|
|
|
{
|
2002-03-16 04:30:03 +01:00
|
|
|
$image_set = '<img src="' . $GLOBALS['phpgw']->common->image('phpgwapi','roter_pfeil') . '">';
|
2001-06-07 09:44:26 +02:00
|
|
|
}
|
2001-05-01 04:15:13 +02:00
|
|
|
|
2002-10-12 20:01:39 +02:00
|
|
|
if (($cats[$i]['level'] == 0) && !in_array($cats[$i]['cat_id'],$selected))
|
2001-06-07 09:44:26 +02:00
|
|
|
{
|
2002-03-16 04:30:03 +01:00
|
|
|
$image_set = '<img src="' . $GLOBALS['phpgw']->common->image('phpgwapi','grauer_pfeil') . '">';
|
2001-06-07 09:44:26 +02:00
|
|
|
}
|
2001-05-01 04:15:13 +02:00
|
|
|
|
2001-06-07 09:44:26 +02:00
|
|
|
$space_set = str_repeat($space,$cats[$i]['level']);
|
|
|
|
|
|
|
|
$s .= '<tr>' . "\n";
|
|
|
|
$s .= '<td width="8">' . $image_set . '</td>' . "\n";
|
2002-10-12 20:01:39 +02:00
|
|
|
$s .= '<td>' . $space_set . '<a href="' . $GLOBALS['phpgw']->link($site_link,'cat_id=' . $cats[$i]['cat_id']) . '">'
|
2001-12-11 02:20:45 +01:00
|
|
|
. $GLOBALS['phpgw']->strip_html($cats[$i]['name'])
|
|
|
|
. '</a></td>' . "\n"
|
|
|
|
. '</tr>' . "\n";
|
2001-06-07 09:44:26 +02:00
|
|
|
}
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
|
|
|
$s .= '</table>' . "\n";
|
2001-05-23 22:19:23 +02:00
|
|
|
return $s;
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2001-07-19 01:50:38 +02:00
|
|
|
|
2002-09-25 06:02:03 +02:00
|
|
|
function formatted_xslt_list($data)
|
|
|
|
{
|
|
|
|
if(is_array($data))
|
|
|
|
{
|
2002-10-21 00:01:46 +02:00
|
|
|
$format = (isset($data['format'])?$data['format']:'filter');
|
|
|
|
$type = (isset($data['type'])?$data['type']:'all');
|
|
|
|
$selected = (isset($data['selected'])?$data['selected']:'');
|
|
|
|
$globals = (isset($data['globals'])?$data['globals']:False);
|
2002-09-25 06:02:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_array($selected))
|
|
|
|
{
|
|
|
|
$selected = explode(',',$selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type != 'all')
|
|
|
|
{
|
|
|
|
$cats = $this->return_array($type,$start,False,$query,$sort,$order,$globals);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cats = $this->return_sorted_array($start,False,$query,$sort,$order,$globals);
|
|
|
|
}
|
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
switch($format)
|
2002-09-25 06:02:03 +02:00
|
|
|
{
|
2002-10-21 00:01:46 +02:00
|
|
|
case 'select':
|
|
|
|
$GLOBALS['phpgw']->xslttpl->add_file($GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'cat_select');
|
|
|
|
break;
|
|
|
|
case 'filter':
|
|
|
|
$GLOBALS['phpgw']->xslttpl->add_file($GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'cat_filter');
|
|
|
|
break;
|
|
|
|
}
|
2002-09-25 06:02:03 +02:00
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
while (is_array($cats) && list(,$cat) = each($cats))
|
|
|
|
{
|
|
|
|
$sel_cat = '';
|
|
|
|
if (in_array($cat['cat_id'],$selected))
|
|
|
|
{
|
|
|
|
$sel_cat = 'selected';
|
|
|
|
}
|
2002-09-25 06:02:03 +02:00
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
$name = '';
|
|
|
|
for ($i=0;$i<$cat['level'];$i++)
|
|
|
|
{
|
|
|
|
$name .= ' . ';
|
|
|
|
}
|
|
|
|
$name .= $GLOBALS['phpgw']->strip_html($cat['name']);
|
2002-09-25 06:02:03 +02:00
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
if ($cat['app_name'] == 'phpgw')
|
|
|
|
{
|
|
|
|
$name .= ' <' . lang('Global') . '>';
|
|
|
|
}
|
|
|
|
if ($cat['owner'] == '-1')
|
|
|
|
{
|
|
|
|
$name .= ' <' . lang('Global') . ' ' . lang($this->app_name) . '>';
|
2002-09-25 06:02:03 +02:00
|
|
|
}
|
|
|
|
|
2002-10-21 00:01:46 +02:00
|
|
|
$cat_list[] = array
|
|
|
|
(
|
|
|
|
'cat_id' => $cat['cat_id'],
|
|
|
|
'name' => $name,
|
|
|
|
'selected' => $sel_cat
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $cat_list;
|
2002-09-25 06:02:03 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function add
|
|
|
|
@abstract add categories
|
|
|
|
@param $cat_name category name
|
|
|
|
@param $cat_parent category parent
|
|
|
|
@param $cat_description category description defaults to ''
|
|
|
|
@param $cat_data category data defaults to ''
|
|
|
|
*/
|
2002-10-12 19:23:56 +02:00
|
|
|
function add($values)
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2003-06-17 15:23:42 +02:00
|
|
|
$values['cat_id'] = intval($values['cat_id']);
|
|
|
|
$values['parent'] = intval($values['parent']);
|
|
|
|
|
|
|
|
if ($values['parent'] > 0)
|
2001-04-28 00:50:02 +02:00
|
|
|
{
|
2003-06-17 15:23:42 +02:00
|
|
|
$values['main'] = $this->id2item(array('cat_id' => $values['parent'],'item' => 'main'));
|
|
|
|
$values['level'] = $this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1;
|
2001-04-28 00:50:02 +02:00
|
|
|
}
|
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
$values['descr'] = $this->db->db_addslashes($values['descr']);
|
|
|
|
$values['name'] = $this->db->db_addslashes($values['name']);
|
2001-05-15 02:00:49 +02:00
|
|
|
|
2003-06-17 15:23:42 +02:00
|
|
|
if ($values['cat_id'] > 0)
|
2002-10-12 02:50:37 +02:00
|
|
|
{
|
|
|
|
$id_col = 'cat_id,';
|
2002-10-12 19:23:56 +02:00
|
|
|
$id_val = $values['cat_id'].',';
|
2002-10-12 02:50:37 +02:00
|
|
|
}
|
|
|
|
$this->db->query("INSERT INTO phpgw_categories (${id_col}cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,cat_data,"
|
2003-06-17 15:23:42 +02:00
|
|
|
. 'cat_main,cat_level,last_mod) VALUES (' . $id_val . $values['parent'] . ',' . $this->account_id . ",'" . $values['access']
|
2002-10-12 19:23:56 +02:00
|
|
|
. "','" . $this->app_name . "','" . $values['name'] . "','" . $values['descr'] . "','" . $values['data']
|
2003-06-17 15:23:42 +02:00
|
|
|
. "'," . intval($values['main']) . ',' . intval($values['level']) . ',' . time() . ')',__LINE__,__FILE__);
|
2001-04-27 18:06:17 +02:00
|
|
|
|
2002-09-03 00:03:00 +02:00
|
|
|
$max = $this->db->get_last_insert_id('phpgw_categories','cat_id');
|
2003-06-17 15:23:42 +02:00
|
|
|
$max = intval($max);
|
|
|
|
if ($values['parent'] == 0)
|
2001-05-15 02:00:49 +02:00
|
|
|
{
|
2003-06-17 15:23:42 +02:00
|
|
|
$this->db->query('UPDATE phpgw_categories SET cat_main=' . $max . ' WHERE cat_id=' . $max,__LINE__,__FILE__);
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
2002-09-03 00:03:00 +02:00
|
|
|
return $max;
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2001-07-19 01:50:38 +02:00
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function delete
|
|
|
|
@abstract delete category
|
|
|
|
@param $cat_id int - category id
|
|
|
|
*/
|
2002-09-25 06:02:03 +02:00
|
|
|
function delete($data)
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2002-09-25 06:02:03 +02:00
|
|
|
if(is_array($data))
|
2001-05-15 02:00:49 +02:00
|
|
|
{
|
2002-09-25 06:02:03 +02:00
|
|
|
$cat_id = $data['cat_id'];
|
|
|
|
$drop_subs = (isset($data['drop_subs'])?$data['drop_subs']:False);
|
|
|
|
$modify_subs = (isset($data['modify_subs'])?$data['modify_subs']:False);
|
2002-09-03 04:21:36 +02:00
|
|
|
}
|
|
|
|
|
2002-09-25 06:02:03 +02:00
|
|
|
if ($cat_id > 0)
|
2002-09-03 04:21:36 +02:00
|
|
|
{
|
2002-09-25 06:02:03 +02:00
|
|
|
if ($drop_subs)
|
|
|
|
{
|
|
|
|
$subdelete = ' OR cat_parent=' . $cat_id . ' OR cat_main=' . $cat_id;
|
|
|
|
}
|
2002-09-03 04:21:36 +02:00
|
|
|
|
2002-09-25 06:02:03 +02:00
|
|
|
if ($modify_subs)
|
2002-09-03 04:21:36 +02:00
|
|
|
{
|
2002-09-25 06:02:03 +02:00
|
|
|
$cats = $this->return_sorted_array('',False,'','','',False, $cat_id);
|
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
$new_parent = $this->id2item(array('cat_id' => $cat_id,'item' => 'parent'));
|
2002-09-25 06:02:03 +02:00
|
|
|
|
|
|
|
for ($i=0;$i<count($cats);$i++)
|
2002-09-03 04:21:36 +02:00
|
|
|
{
|
2002-09-25 06:02:03 +02:00
|
|
|
if ($cats[$i]['level'] == 1)
|
2002-09-03 04:21:36 +02:00
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$this->db->query('UPDATE phpgw_categories set cat_level=0, cat_parent=0, cat_main=' . intval($cats[$i]['cat_id'])
|
|
|
|
. ' WHERE cat_id=' . intval($cats[$i]['cat_id']) . "' AND cat_appname='" . $this->app_name . "'",__LINE__,__FILE__);
|
2002-10-12 23:18:23 +02:00
|
|
|
$new_main = $cats[$i]['cat_id'];
|
2002-09-03 04:21:36 +02:00
|
|
|
}
|
2002-09-25 06:02:03 +02:00
|
|
|
else
|
2002-09-03 04:21:36 +02:00
|
|
|
{
|
2002-09-25 06:02:03 +02:00
|
|
|
if ($new_main)
|
|
|
|
{
|
|
|
|
$update_main = ',cat_main=' . $new_main;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cats[$i]['parent'] == $cat_id)
|
|
|
|
{
|
|
|
|
$update_parent = ',cat_parent=' . $new_parent;
|
|
|
|
}
|
|
|
|
|
2003-05-02 01:24:09 +02:00
|
|
|
$this->db->query('UPDATE phpgw_categories set cat_level=' . ($cats[$i]['level']-1) . $update_main . $update_parent
|
|
|
|
. ' WHERE cat_id=' . intval($cats[$i]['cat_id']) . "' AND cat_appname='" . $this->app_name . "'",__LINE__,__FILE__);
|
2002-09-03 04:21:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 16:45:27 +02:00
|
|
|
|
2003-05-02 01:24:09 +02:00
|
|
|
$this->db->query('DELETE FROM phpgw_categories WHERE cat_id=' . $cat_id . $subdelete . "' AND cat_appname='"
|
2002-09-25 06:02:03 +02:00
|
|
|
. $this->app_name . "'",__LINE__,__FILE__);
|
|
|
|
}
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2002-01-03 18:16:56 +01:00
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
function subs($parent,&$subs,&$main)
|
|
|
|
{
|
|
|
|
if (!is_array($main))
|
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$this->db->query('SELECT * from phpgw_categories WHERE cat_main=' . $main,__LINE__,__FILE__);
|
2002-10-12 19:23:56 +02:00
|
|
|
$main = $this->db2cats();
|
|
|
|
//echo "main: "; _debug_array($main);
|
|
|
|
}
|
|
|
|
reset($main);
|
|
|
|
for ($n = 0; $n < count($main); $n++)
|
|
|
|
{
|
|
|
|
$cat = $main[$n];
|
|
|
|
if ($cat['parent'] == $parent)
|
|
|
|
{
|
2002-10-12 23:18:23 +02:00
|
|
|
//echo "Adding($cat[cat_id])<br>";
|
|
|
|
$subs[$cat['cat_id']] = $cat;
|
2002-10-12 19:23:56 +02:00
|
|
|
$this->subs($cat['cat_id'],$subs,$main);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reparent($values)
|
|
|
|
{
|
|
|
|
$id = $values['cat_id'];
|
|
|
|
$parent = $values['parent'];
|
|
|
|
$old_parent = $values['old_parent'];
|
2002-10-12 23:18:23 +02:00
|
|
|
$main = $old_parent ? intval($this->id2name($old_parent,'main')) : $id;
|
|
|
|
//echo "<p>reparent: $id/$main: $old_parent --> $parent</p>\n";
|
2002-10-12 19:23:56 +02:00
|
|
|
|
|
|
|
$subs = array();
|
|
|
|
$this->subs($id,$subs,$main);
|
2002-10-12 23:18:23 +02:00
|
|
|
//echo "<p>subs($id) = "; _debug_array($subs);
|
|
|
|
|
|
|
|
if (isset($subs[$parent]))
|
|
|
|
{
|
|
|
|
//echo "<p>new parent $parent is sub of $id</p>\n";
|
|
|
|
$parent = $subs[$parent];
|
|
|
|
$parent['old_parent'] = $parent['parent'];
|
|
|
|
$parent['parent'] = intval($values['old_parent']);
|
|
|
|
$this->reparent($parent);
|
|
|
|
|
|
|
|
unset($parent['old_parent']);
|
|
|
|
unset($parent['main']);
|
|
|
|
|
|
|
|
$this->edit($parent);
|
|
|
|
$this->reparent($values);
|
|
|
|
return;
|
|
|
|
}
|
2002-10-12 19:23:56 +02:00
|
|
|
|
|
|
|
$new_main = $parent ? $this->id2name($parent,'main') : $id;
|
|
|
|
$new_parent_level = $parent ? $this->id2name($parent,'level') : -1;
|
|
|
|
$old_parent_level = $old_parent ? $this->id2name($old_parent,'level') : -1;
|
|
|
|
$level_adj = $old_parent_level - $new_parent_level;
|
|
|
|
reset($subs);
|
|
|
|
//echo "new_main=$new_main,level_adj = $level_adj<br>";
|
|
|
|
while (list($n) = each($subs))
|
|
|
|
{
|
|
|
|
$subs[$n]['main'] = $new_main;
|
|
|
|
$subs[$n]['level'] -= $level_adj;
|
2002-10-12 23:18:23 +02:00
|
|
|
//echo "<p>$n: id=".$subs[$n]['cat_id']." set main to $new_main, subs[$n] = \n"; _debug_array($subs[$n]);
|
2002-10-12 19:23:56 +02:00
|
|
|
$this->edit($subs[$n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function edit
|
|
|
|
@abstract edit a category
|
|
|
|
@param $cat_id int - category id
|
|
|
|
@param $cat_parent category parent
|
|
|
|
@param $cat_description category description defaults to ''
|
|
|
|
@param $cat_data category data defaults to ''
|
|
|
|
*/
|
2002-10-12 19:23:56 +02:00
|
|
|
function edit($values)
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2003-06-17 15:23:42 +02:00
|
|
|
$values['cat_id'] = intval($values['id']);
|
|
|
|
$values['parent'] = intval($values['parent']);
|
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
if (isset($values['old_parent']) && $values['old_parent'] != $values['parent'])
|
2001-05-15 02:00:49 +02:00
|
|
|
{
|
2002-10-12 19:23:56 +02:00
|
|
|
//$this->delete(array('cat_id' => $values['cat_id'],'drop_subs' => False,'modify_subs' => True));
|
|
|
|
//return $this->add($values);
|
|
|
|
|
|
|
|
$this->reparent($values);
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
2002-10-12 23:18:23 +02:00
|
|
|
if (!isset($values['main']) || !isset($values['level']))
|
2001-05-15 02:00:49 +02:00
|
|
|
{
|
2003-06-17 15:23:42 +02:00
|
|
|
if ($values['parent'] > 0)
|
2002-10-04 22:59:00 +02:00
|
|
|
{
|
2002-10-12 23:18:23 +02:00
|
|
|
$values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main')));
|
|
|
|
$values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1);
|
2002-10-04 22:59:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-06-17 15:23:42 +02:00
|
|
|
$values['main'] = $values['cat_id'];
|
|
|
|
$values['level'] = 0;
|
2002-10-04 22:59:00 +02:00
|
|
|
}
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
2001-07-19 01:50:38 +02:00
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
$values['descr'] = $this->db->db_addslashes($values['descr']);
|
|
|
|
$values['name'] = $this->db->db_addslashes($values['name']);
|
2002-01-01 21:58:22 +01:00
|
|
|
|
2002-10-12 19:23:56 +02:00
|
|
|
$sql = "UPDATE phpgw_categories SET cat_name='" . $values['name'] . "', cat_description='" . $values['descr']
|
2003-06-17 15:23:42 +02:00
|
|
|
. "', cat_data='" . $values['data'] . "', cat_parent=" . $values['parent'] . ", cat_access='"
|
|
|
|
. $values['access'] . "', cat_main=" . $values['main'] . ', cat_level=' . $values['level'] . ', last_mod=' . time()
|
|
|
|
. " WHERE cat_appname='" . $this->app_name . "' AND cat_id=" . $values['cat_id'];
|
2001-11-18 07:11:05 +01:00
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
2003-06-17 15:23:42 +02:00
|
|
|
return $values['cat_id'];
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
2001-04-25 20:12:10 +02:00
|
|
|
|
|
|
|
function name2id($cat_name)
|
|
|
|
{
|
2002-03-26 20:25:49 +01:00
|
|
|
$this->db->query("SELECT cat_id FROM phpgw_categories WHERE cat_name='" . $this->db->db_addslashes($cat_name) . "' "
|
2003-03-22 10:37:40 +01:00
|
|
|
."AND cat_appname='" . $this->app_name . "' AND (cat_owner=" . $this->account_id ." OR cat_owner=-1)",__LINE__,__FILE__);
|
2001-12-11 02:20:45 +01:00
|
|
|
|
2001-09-17 04:24:41 +02:00
|
|
|
if(!$this->db->num_rows())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-01-03 18:16:56 +01:00
|
|
|
|
2001-04-25 20:12:10 +02:00
|
|
|
$this->db->next_record();
|
|
|
|
|
|
|
|
return $this->db->f('cat_id');
|
|
|
|
}
|
|
|
|
|
2001-12-05 02:32:32 +01:00
|
|
|
function id2name($cat_id = '', $item = 'name')
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2002-10-12 19:23:56 +02:00
|
|
|
return $this->id2item(array('cat_id' => $cat_id,'item' => $item));
|
|
|
|
}
|
|
|
|
|
|
|
|
function id2item($data)
|
|
|
|
{
|
|
|
|
if(is_array($data))
|
|
|
|
{
|
|
|
|
$cat_id = $data['cat_id'];
|
|
|
|
$item = (isset($data['item'])?$data['item']:'name');
|
|
|
|
}
|
|
|
|
|
2001-12-05 02:32:32 +01:00
|
|
|
if ($cat_id == '')
|
|
|
|
{
|
|
|
|
return '--';
|
|
|
|
}
|
2002-10-12 19:23:56 +02:00
|
|
|
|
2001-07-03 14:38:09 +02:00
|
|
|
switch($item)
|
2001-07-02 04:25:26 +02:00
|
|
|
{
|
2002-01-15 03:52:51 +01:00
|
|
|
case 'name': $value = 'cat_name'; break;
|
|
|
|
case 'owner': $value = 'cat_owner'; break;
|
|
|
|
case 'main': $value = 'cat_main'; break;
|
|
|
|
case 'level': $value = 'cat_level'; break;
|
2002-09-03 04:21:36 +02:00
|
|
|
case 'data': $value = 'cat_data'; break;
|
|
|
|
case 'parent': $value = 'cat_parent'; break;
|
2002-01-03 18:16:56 +01:00
|
|
|
}
|
2001-07-02 04:25:26 +02:00
|
|
|
|
2003-05-02 01:24:09 +02:00
|
|
|
$this->db->query("SELECT $value FROM phpgw_categories WHERE cat_id=" . $cat_id,__LINE__,__FILE__);
|
2001-03-12 13:16:14 +01:00
|
|
|
$this->db->next_record();
|
|
|
|
|
2001-07-02 04:25:26 +02:00
|
|
|
if ($this->db->f($value))
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2001-07-02 04:25:26 +02:00
|
|
|
return $this->db->f($value);
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-03 14:13:13 +02:00
|
|
|
if ($item == 'name')
|
|
|
|
{
|
|
|
|
return '--';
|
|
|
|
}
|
2001-07-02 04:25:26 +02:00
|
|
|
}
|
2001-04-25 20:12:10 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 07:10:22 +01:00
|
|
|
/*!
|
|
|
|
@function exists
|
|
|
|
@abstract used for checking if a category name exists
|
|
|
|
@param $type subs or mains
|
|
|
|
@param $cat_name category name
|
|
|
|
@result boolean true or false
|
|
|
|
*/
|
2001-04-22 01:22:27 +02:00
|
|
|
function exists($type,$cat_name = '',$cat_id = '')
|
2001-03-12 13:16:14 +01:00
|
|
|
{
|
2002-09-04 02:30:50 +02:00
|
|
|
if(is_array($type))
|
|
|
|
{
|
|
|
|
$temp_type = $type['type'];
|
|
|
|
$cat_name = $type['cat_name'] ? $type['cat_name'] : '';
|
|
|
|
$cat_id = $type['cat_id'] ? $type['cat_id'] : '';
|
|
|
|
settype($type,'string');
|
|
|
|
$type = $temp_type;
|
|
|
|
unset($temp_type);
|
|
|
|
}
|
|
|
|
|
2001-05-15 02:00:49 +02:00
|
|
|
$filter = $this->filter($type);
|
|
|
|
|
|
|
|
if ($cat_name)
|
|
|
|
{
|
2001-09-17 04:24:41 +02:00
|
|
|
$cat_exists = " cat_name='" . $this->db->db_addslashes($cat_name) . "' ";
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cat_id)
|
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$cat_exists = ' cat_parent=' . $cat_id;
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cat_name && $cat_id)
|
|
|
|
{
|
2003-05-02 01:24:09 +02:00
|
|
|
$cat_exists = " cat_name='" . $this->db->db_addslashes($cat_name) . "' AND cat_id != " . $cat_id;
|
2001-05-15 02:00:49 +02:00
|
|
|
}
|
|
|
|
|
2001-11-18 07:11:05 +01:00
|
|
|
$this->db->query("SELECT COUNT(cat_id) FROM phpgw_categories WHERE $cat_exists $filter",__LINE__,__FILE__);
|
2001-05-15 02:00:49 +02:00
|
|
|
|
|
|
|
$this->db->next_record();
|
|
|
|
|
|
|
|
if ($this->db->f(0))
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2001-03-12 13:16:14 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
?>
|