2001-10-02 15:35:04 +02:00
|
|
|
<?php
|
2002-03-13 05:16:46 +01:00
|
|
|
/**************************************************************************\
|
2004-01-27 00:26:19 +01:00
|
|
|
* eGroupWare - Admin - Global categories *
|
|
|
|
* http://www.egroupware.org *
|
2002-03-13 05:16:46 +01:00
|
|
|
* 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$ */
|
|
|
|
/* $Source$ */
|
2001-10-02 15:35:04 +02:00
|
|
|
|
|
|
|
class bocategories
|
|
|
|
{
|
|
|
|
var $cats;
|
|
|
|
|
|
|
|
var $start;
|
|
|
|
var $query;
|
|
|
|
var $sort;
|
|
|
|
var $order;
|
|
|
|
var $filter;
|
|
|
|
var $cat_id;
|
|
|
|
var $total;
|
|
|
|
|
|
|
|
var $debug = False;
|
|
|
|
|
|
|
|
function bocategories()
|
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($_GET['appname'])
|
2002-03-13 05:16:46 +01:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->cats = CreateObject('phpgwapi.categories',-1,$_GET['appname']);
|
2002-03-13 05:16:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->cats = CreateObject('phpgwapi.categories',$GLOBALS['phpgw_info']['user']['account_id'],'phpgw');
|
|
|
|
}
|
2001-10-02 15:35:04 +02:00
|
|
|
|
|
|
|
$this->read_sessiondata();
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
/* _debug_array($_POST); */
|
|
|
|
/* Might change this to '' at the end---> */
|
|
|
|
$start = get_var('start',array('POST','GET'));
|
2002-09-04 03:58:34 +02:00
|
|
|
$query = get_var('query',array('POST','GET'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$sort = get_var('sort', array('POST','GET'));
|
2002-09-04 03:58:34 +02:00
|
|
|
$order = get_var('order',array('POST','GET'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$cat_id = get_var('cat_id',array('POST','GET'));
|
2002-09-04 03:58:34 +02:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if(!empty($start) || $start == '0' || $start == 0)
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
|
|
|
if($this->debug) { echo '<br>overriding start: "' . $this->start . '" now "' . $start . '"'; }
|
|
|
|
$this->start = $start;
|
|
|
|
}
|
|
|
|
if((empty($query) && !empty($this->query)) || !empty($query))
|
|
|
|
{
|
|
|
|
if($this->debug) { echo '<br>setting query to: "' . $query . '"'; }
|
|
|
|
$this->query = $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($cat_id))
|
|
|
|
{
|
|
|
|
$this->cat_id = $cat_id;
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
if($cat_id == '0' || $cat_id == 0 || $cat_id == '')
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
|
|
|
unset($this->cat_id);
|
|
|
|
}
|
2001-12-22 17:14:31 +01:00
|
|
|
if(isset($sort) && !empty($sort))
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
|
|
|
$this->sort = $sort;
|
|
|
|
}
|
2001-12-22 17:14:31 +01:00
|
|
|
if(isset($order) && !empty($order))
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
|
|
|
$this->order = $order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_sessiondata($data)
|
|
|
|
{
|
|
|
|
if($this->debug) { echo '<br>Save:'; _debug_array($data); }
|
|
|
|
$GLOBALS['phpgw']->session->appsession('session_data','admin_cats',$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_sessiondata()
|
|
|
|
{
|
|
|
|
$data = $GLOBALS['phpgw']->session->appsession('session_data','admin_cats');
|
|
|
|
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
|
|
|
|
|
|
|
|
$this->start = $data['start'];
|
|
|
|
$this->query = $data['query'];
|
|
|
|
$this->sort = $data['sort'];
|
|
|
|
$this->order = $data['order'];
|
|
|
|
if(isset($data['cat_id']))
|
|
|
|
{
|
|
|
|
$this->cat_id = $data['cat_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
function get_list()
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
|
|
|
if($this->debug) { echo '<br>querying: "' . $this->query . '"'; }
|
2003-08-28 16:16:30 +02:00
|
|
|
return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,True);
|
2001-10-02 15:35:04 +02:00
|
|
|
}
|
|
|
|
|
2002-01-12 19:28:42 +01:00
|
|
|
function save_cat($values)
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($values['id'] && $values['id'] != 0)
|
2002-01-12 19:28:42 +01:00
|
|
|
{
|
|
|
|
return $this->cats->edit($values);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->cats->add($values);
|
|
|
|
}
|
2001-10-02 15:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function exists($data)
|
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
$data['type'] = $data['type'] ? $data['type'] : '';
|
|
|
|
$data['cat_id'] = $data['cat_id'] ? $data['cat_id'] : '';
|
|
|
|
return $this->cats->exists($data['type'],$data['cat_name'],$data['cat_id']);
|
2001-10-02 15:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatted_list($data)
|
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
return $this->cats->formated_list($data['select'],$data['all'],$data['cat_parent'],True);
|
2001-10-02 15:35:04 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
function delete($cat_id,$subs=False)
|
2001-10-02 15:35:04 +02:00
|
|
|
{
|
2004-02-26 13:18:44 +01:00
|
|
|
return $this->cats->delete($cat_id,$subs,!$subs); // either delete the subs or modify them
|
2001-10-02 15:35:04 +02:00
|
|
|
}
|
2002-01-12 19:28:42 +01:00
|
|
|
|
|
|
|
function check_values($values)
|
|
|
|
{
|
|
|
|
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:54:46 +01:00
|
|
|
if (!$values['parent'])
|
2002-01-12 19:28:42 +01:00
|
|
|
{
|
|
|
|
$exists = $this->exists(array
|
|
|
|
(
|
|
|
|
'type' => 'appandmains',
|
|
|
|
'cat_name' => $values['name'],
|
2003-08-28 16:16:30 +02:00
|
|
|
'cat_id' => $values['id']
|
2002-01-12 19:28:42 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$exists = $this->exists(array
|
|
|
|
(
|
|
|
|
'type' => 'appandsubs',
|
|
|
|
'cat_name' => $values['name'],
|
2003-08-28 16:16:30 +02:00
|
|
|
'cat_id' => $values['id']
|
2002-01-12 19:28:42 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($exists == True)
|
|
|
|
{
|
|
|
|
$error[] = lang('That name has been used already');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($error))
|
|
|
|
{
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
}
|
2001-10-02 15:35:04 +02:00
|
|
|
}
|