2002-01-12 05:09:56 +01:00
|
|
|
<?php
|
2005-10-14 16:31:35 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - Preferences - categories *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* Written by Bettina Gille [ceb@phpgroupware.org] *
|
|
|
|
* ----------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
/* $Id$ */
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
class bocategories
|
|
|
|
{
|
|
|
|
var $cats;
|
|
|
|
|
|
|
|
var $start;
|
|
|
|
var $query;
|
|
|
|
var $sort;
|
|
|
|
var $order;
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
function bocategories($cats_app='')
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2005-03-12 17:35:27 +01:00
|
|
|
$this->cats =& CreateObject('phpgwapi.categories','',$cats_app);
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
$this->read_sessiondata($cats_app);
|
|
|
|
|
2005-03-12 17:35:27 +01:00
|
|
|
$start = $_POST['start'] ? $_POST['start'] : $_GET['start'];
|
|
|
|
$query = $_POST['query'] ? $_POST['query'] : $_GET['query'];
|
|
|
|
$sort = $_POST['sort'] ? $_POST['sort'] : $_GET['sort'];
|
|
|
|
$order = $_POST['order'] ? $_POST['order'] : $_GET['order'];
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
if(!empty($start) || $start == '0' || $start == 0)
|
|
|
|
{
|
|
|
|
$this->start = $start;
|
|
|
|
}
|
|
|
|
if((empty($query) && !empty($this->query)) || !empty($query))
|
|
|
|
{
|
|
|
|
$this->query = $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($sort) && !empty($sort))
|
|
|
|
{
|
|
|
|
$this->sort = $sort;
|
|
|
|
}
|
|
|
|
if(isset($order) && !empty($order))
|
|
|
|
{
|
|
|
|
$this->order = $order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_sessiondata($data, $cats_app)
|
|
|
|
{
|
2005-11-08 11:43:49 +01:00
|
|
|
$GLOBALS['egw']->session->appsession($cats_app . '_cats','preferences',$data);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function read_sessiondata($cats_app)
|
|
|
|
{
|
2005-11-08 11:43:49 +01:00
|
|
|
$data = $GLOBALS['egw']->session->appsession($cats_app . '_cats','preferences');
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->start = $data['start'];
|
|
|
|
$this->query = $data['query'];
|
|
|
|
$this->sort = $data['sort'];
|
|
|
|
$this->order = $data['order'];
|
2005-11-08 11:43:49 +01:00
|
|
|
$this->referer = $data['referer'];
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2002-01-13 23:35:54 +01:00
|
|
|
function get_list($global_cats)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2002-01-13 23:35:54 +01:00
|
|
|
return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,$global_cats);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_cat($values)
|
|
|
|
{
|
|
|
|
if ($values['access'])
|
|
|
|
{
|
|
|
|
$values['access'] = 'private';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$values['access'] = 'public';
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($values['id'] && $values['id'] != 0)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
|
|
|
return $this->cats->edit($values);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->cats->add($values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function exists($data)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$data['type'] = $data['type'] ? $data['type'] : '';
|
|
|
|
$data['cat_id'] = $data['cat_id'] ? $data['cat_id'] : '';
|
2006-03-10 10:59:18 +01:00
|
|
|
return $this->cats->exists($data['type'],$data['cat_name'],$data['type'] == 'subs' ? 0 : $data['cat_id'],$data['type'] != 'subs' ? 0 : $data['cat_id']);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
function formatted_list($format,$type,$cat_parent,$global_cats)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2007-11-27 18:14:54 +01:00
|
|
|
return $this->cats->formatted_list($format,$type,$cat_parent,$global_cats);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2004-02-26 13:18:44 +01:00
|
|
|
function delete($cat_id,$subs)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2004-02-26 13:18:44 +01:00
|
|
|
return $this->cats->delete($cat_id,$subs,!$subs); // either delete the subs or modify them
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2002-01-12 19:28:42 +01:00
|
|
|
function check_values($values)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
|
|
|
if (strlen($values['descr']) >= 255)
|
|
|
|
{
|
|
|
|
$error[] = lang('Description can not exceed 255 characters in length !');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$values['name'])
|
|
|
|
{
|
|
|
|
$error[] = lang('Please enter a name');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-01-14 00:31:03 +01:00
|
|
|
if (!$values['parent'])
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
|
|
|
$exists = $this->exists(array
|
|
|
|
(
|
|
|
|
'type' => 'appandmains',
|
|
|
|
'cat_name' => $values['name'],
|
2003-08-28 16:31:11 +02:00
|
|
|
'cat_id' => $values['id']
|
2002-01-12 05:09:56 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$exists = $this->exists(array
|
|
|
|
(
|
|
|
|
'type' => 'appandsubs',
|
|
|
|
'cat_name' => $values['name'],
|
2003-08-28 16:31:11 +02:00
|
|
|
'cat_id' => $values['id']
|
2002-01-12 05:09:56 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($exists == True)
|
|
|
|
{
|
2002-01-14 00:31:03 +01:00
|
|
|
$error[] = lang('This name has been used already');
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($error))
|
|
|
|
{
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|