2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
2008-03-15 15:52:26 +01:00
|
|
|
/**
|
|
|
|
* API - Categories
|
2008-04-16 13:37:47 +02:00
|
|
|
*
|
2008-03-15 15:52:26 +01:00
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Joseph Engo <jengo@phpgroupware.org>
|
|
|
|
* @author Bettina Gille <ceb@phpgroupware.org>
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* Copyright (C) 2000, 2001 Joseph Engo, Bettina Gille
|
|
|
|
* Copyright (C) 2002, 2003 Bettina Gille
|
|
|
|
* Reworked 11/2005 by RalfBecker-AT-outdoor-training.de
|
2008-12-17 21:05:19 +01:00
|
|
|
* Reworked 12/2008 by RalfBecker-AT-outdoor-training.de to operate only on a catergory cache, no longer the db direct
|
2008-03-15 15:52:26 +01:00
|
|
|
* @license http://opensource.org/licenses/lgpl-license.php LGPL - GNU Lesser General Public License
|
|
|
|
* @package api
|
|
|
|
* @subpackage categories
|
|
|
|
* @access public
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-03-20 14:41:33 +01:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2008-03-15 15:52:26 +01:00
|
|
|
/**
|
|
|
|
* class to manage categories in eGroupWare
|
2009-02-25 13:59:28 +01:00
|
|
|
*
|
2016-03-20 14:41:33 +01:00
|
|
|
* @deprecated use Api\Categories
|
2008-03-15 15:52:26 +01:00
|
|
|
*/
|
2016-03-20 14:41:33 +01:00
|
|
|
class categories extends Api\Categories
|
2008-03-15 15:52:26 +01:00
|
|
|
{
|
2009-02-25 15:35:43 +01:00
|
|
|
/**
|
2009-05-14 09:59:51 +02:00
|
|
|
* @deprecated use categories::TABLE
|
2009-02-25 15:35:43 +01:00
|
|
|
* @var string
|
|
|
|
*/
|
2009-05-14 09:59:51 +02:00
|
|
|
public $table = self::TABLE;
|
2010-01-31 00:50:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* read a single category
|
|
|
|
*
|
|
|
|
* We use a shared cache together with id2name
|
|
|
|
*
|
|
|
|
* @deprecated use read($id) returning just the category array not an array with one element
|
|
|
|
* @param int $id id of category
|
|
|
|
* @return array|boolean array with one array of cat-data or false if cat not found
|
|
|
|
*/
|
|
|
|
static function return_single($id)
|
|
|
|
{
|
2012-02-10 21:14:44 +01:00
|
|
|
if (is_null(self::$cache)) self::init_cache();
|
|
|
|
|
2010-01-31 00:50:51 +01:00
|
|
|
return isset(self::$cache[$id]) ? array(self::$cache[$id]) : false;
|
|
|
|
}
|
2011-02-15 14:03:39 +01:00
|
|
|
|
2010-01-31 00:50:51 +01:00
|
|
|
/**
|
|
|
|
* return into a select box, list or other formats
|
|
|
|
*
|
|
|
|
* @param string/array $format string 'select' or 'list', or array with all params
|
|
|
|
* @param string $type='' subs or mains
|
|
|
|
* @param int/array $selected - cat_id or array with cat_id values
|
|
|
|
* @param boolean $globals True or False, includes the global egroupware categories or not
|
|
|
|
* @deprecated use html class to create selectboxes
|
|
|
|
* @return string populated with categories
|
|
|
|
*/
|
|
|
|
function formatted_list($format,$type='',$selected = '',$globals = False,$site_link = 'site')
|
|
|
|
{
|
|
|
|
if(is_array($format))
|
|
|
|
{
|
|
|
|
$type = ($format['type']?$format['type']:'all');
|
|
|
|
$selected = (isset($format['selected'])?$format['selected']:'');
|
|
|
|
$self = (isset($format['self'])?$format['self']:'');
|
|
|
|
$globals = (isset($format['globals'])?$format['globals']:True);
|
|
|
|
$site_link = (isset($format['site_link'])?$format['site_link']:'site');
|
|
|
|
$format = $format['format'] ? $format['format'] : 'select';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_array($selected))
|
|
|
|
{
|
|
|
|
$selected = explode(',',$selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type != 'all')
|
|
|
|
{
|
|
|
|
$cats = $this->return_array($type,0,False,'','','',$globals);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cats = $this->return_sorted_array(0,False,'','','',$globals);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$cats) return '';
|
|
|
|
|
|
|
|
if($self)
|
|
|
|
{
|
|
|
|
foreach($cats as $key => $cat)
|
|
|
|
{
|
|
|
|
if ($cat['id'] == $self)
|
|
|
|
{
|
|
|
|
unset($cats[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($format)
|
|
|
|
{
|
|
|
|
case 'select':
|
|
|
|
foreach($cats as $cat)
|
|
|
|
{
|
|
|
|
$s .= '<option value="' . $cat['id'] . '"';
|
|
|
|
if (in_array($cat['id'],$selected))
|
|
|
|
{
|
|
|
|
$s .= ' selected="selected"';
|
|
|
|
}
|
|
|
|
$s .= '>'.str_repeat(' ',$cat['level']);
|
|
|
|
$s .= $GLOBALS['egw']->strip_html($cat['name']);
|
2010-01-31 04:36:01 +01:00
|
|
|
if (self::is_global($cat))
|
2010-01-31 00:50:51 +01:00
|
|
|
{
|
2013-02-05 12:24:02 +01:00
|
|
|
$s .= self::$global_marker;
|
2010-01-31 00:50:51 +01:00
|
|
|
}
|
|
|
|
$s .= '</option>' . "\n";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'list':
|
|
|
|
$space = ' ';
|
|
|
|
|
|
|
|
$s = '<table border="0" cellpadding="2" cellspacing="2">' . "\n";
|
|
|
|
|
|
|
|
foreach($cats as $cat)
|
|
|
|
{
|
|
|
|
$image_set = ' ';
|
|
|
|
|
|
|
|
if (in_array($cat['id'],$selected))
|
|
|
|
{
|
|
|
|
$image_set = '<img src="' . EGW_IMAGES_DIR . '/roter_pfeil.gif">';
|
|
|
|
}
|
|
|
|
if (($cat['level'] == 0) && !in_array($cat['id'],$selected))
|
|
|
|
{
|
|
|
|
$image_set = '<img src="' . EGW_IMAGES_DIR . '/grauer_pfeil.gif">';
|
|
|
|
}
|
|
|
|
$space_set = str_repeat($space,$cat['level']);
|
|
|
|
|
|
|
|
$s .= '<tr>' . "\n";
|
|
|
|
$s .= '<td width="8">' . $image_set . '</td>' . "\n";
|
|
|
|
$s .= '<td>' . $space_set . '<a href="' . $GLOBALS['egw']->link($site_link,'cat_id=' . $cat['id']) . '">'
|
|
|
|
. $GLOBALS['egw']->strip_html($cat['name'])
|
|
|
|
. '</a></td>' . "\n"
|
|
|
|
. '</tr>' . "\n";
|
|
|
|
}
|
|
|
|
$s .= '</table>' . "\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return category name for a given id
|
|
|
|
*
|
|
|
|
* @deprecated This is only a temp wrapper, use id2name() to keep things matching across the board. (jengo)
|
|
|
|
* @param int $cat_id
|
|
|
|
* @return string cat_name category name
|
|
|
|
*/
|
|
|
|
function return_name($cat_id)
|
|
|
|
{
|
|
|
|
return $this->id2name($cat_id);
|
|
|
|
}
|
2008-03-15 15:52:26 +01:00
|
|
|
}
|