egroupware/admin/inc/class.uicategories.inc.php

514 lines
17 KiB
PHP
Raw Normal View History

2001-10-02 15:35:04 +02:00
<?php
2002-03-13 05:16:46 +01:00
/**************************************************************************\
* phpGroupWare - Admin - Global categories *
* http://www.phpgroupware.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$ */
/* $Source$ */
2001-10-02 15:35:04 +02:00
class uicategories
{
var $bo;
var $template;
var $start;
var $query;
var $sort;
var $order;
var $cat_id;
var $debug = False;
2002-01-12 19:28:42 +01:00
var $public_functions = array
(
2001-10-02 15:35:04 +02:00
'index' => True,
'add' => True,
'edit' => True,
'delete' => True
);
2002-01-12 19:28:42 +01:00
2001-10-02 15:35:04 +02:00
function uicategories()
{
2002-06-18 03:13:43 +02:00
$this->bo = CreateObject('admin.bocategories');
$this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
$this->start = $this->bo->start;
$this->query = $this->bo->query;
$this->sort = $this->bo->sort;
$this->order = $this->bo->order;
$this->cat_id = $this->bo->cat_id;
2001-10-02 15:35:04 +02:00
if($this->debug) { $this->_debug_sqsof(); }
}
function _debug_sqsof()
{
$data = array(
'start' => $this->start,
'query' => $this->query,
'sort' => $this->sort,
'order' => $this->order,
'cat_id' => $this->cat_id
);
echo '<br>UI:<br>';
_debug_array($data);
}
function save_sessiondata()
{
2002-03-13 05:16:46 +01:00
$data = array
(
2001-10-02 15:35:04 +02:00
'start' => $this->start,
'query' => $this->query,
'sort' => $this->sort,
2001-10-24 14:53:01 +02:00
'order' => $this->order
2001-10-02 15:35:04 +02:00
);
2002-03-13 05:16:46 +01:00
2001-10-02 15:35:04 +02:00
if(isset($this->cat_id))
{
$data['cat_id'] = $this->cat_id;
}
$this->bo->save_sessiondata($data);
}
2002-01-12 19:28:42 +01:00
function set_langs()
{
$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
$GLOBALS['phpgw']->template->set_var('lang_save',lang('Save'));
$GLOBALS['phpgw']->template->set_var('lang_search',lang('Search'));
$GLOBALS['phpgw']->template->set_var('lang_sub',lang('Add sub'));
$GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit'));
$GLOBALS['phpgw']->template->set_var('lang_delete',lang('Delete'));
$GLOBALS['phpgw']->template->set_var('lang_parent',lang('Parent category'));
$GLOBALS['phpgw']->template->set_var('lang_none',lang('None'));
$GLOBALS['phpgw']->template->set_var('lang_name',lang('Name'));
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description'));
$GLOBALS['phpgw']->template->set_var('lang_add',lang('Add'));
$GLOBALS['phpgw']->template->set_var('lang_reset',lang('Clear Form'));
$GLOBALS['phpgw']->template->set_var('lang_done',lang('Done'));
2002-01-12 19:28:42 +01:00
}
2001-10-02 15:35:04 +02:00
function index()
{
2002-09-08 22:40:12 +02:00
$global_cats = get_var('global_cats',array('POST','GET'));
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->common->phpgw_header();
$GLOBALS['phpgw']->template->set_file(array('cat_list_t' => 'listcats.tpl'));
$GLOBALS['phpgw']->template->set_block('cat_list_t','cat_list');
$GLOBALS['phpgw']->template->set_block('cat_list_t','cat_row');
2001-10-02 15:35:04 +02:00
2002-01-12 19:28:42 +01:00
$this->set_langs();
2001-10-02 15:35:04 +02:00
2002-03-13 05:16:46 +01:00
$link_data = array
(
2002-06-18 03:13:43 +02:00
'menuaction' => 'admin.uicategories.index',
'appname' => $GLOBALS['appname'],
'global_cats' => $global_cats
2002-03-13 05:16:46 +01:00
);
$GLOBALS['phpgw']->template->set_var('lang_action',lang('Category list'));
2002-03-13 05:16:46 +01:00
if ($GLOBALS['appname'])
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang($GLOBALS['appname']) . '&nbsp;' . lang('global categories'));
2002-03-13 05:16:46 +01:00
}
else
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Global categories'));
2002-03-13 05:16:46 +01:00
}
$GLOBALS['phpgw']->template->set_var('query',$this->query);
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
$GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/admin/index.php'));
2001-10-02 15:35:04 +02:00
if(!$start)
{
$start = 0;
}
if (!$global_cats)
{
$global_cats = False;
}
$categories = $this->bo->get_list($global_cats);
2001-10-02 15:35:04 +02:00
2002-03-13 05:16:46 +01:00
$left = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,$link_data);
$right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,$link_data);
$GLOBALS['phpgw']->template->set_var('left',$left);
$GLOBALS['phpgw']->template->set_var('right',$right);
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data));
$GLOBALS['phpgw']->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data));
2001-10-02 15:35:04 +02:00
for ($i=0;$i<count($categories);$i++)
{
$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
$GLOBALS['phpgw']->template->set_var(tr_color,$tr_color);
2001-10-02 15:35:04 +02:00
$id = $categories[$i]['id'];
$level = $categories[$i]['level'];
2002-03-13 05:16:46 +01:00
$cat_name = $GLOBALS['phpgw']->strip_html($categories[$i]['name']);
2001-10-02 15:35:04 +02:00
if ($level > 0)
{
$space = '&nbsp;&nbsp;';
$spaceset = str_repeat($space,$level);
2002-03-13 05:16:46 +01:00
$cat_name = $spaceset . $cat_name;
2001-10-02 15:35:04 +02:00
}
$descr = $GLOBALS['phpgw']->strip_html($categories[$i]['description']);
if (!$descr) { $descr = '&nbsp;'; }
if ($level == 0)
{
2002-03-13 05:16:46 +01:00
$cat_name = '<font color="FF0000"><b>' . $cat_name . '</b></font>';
2001-10-02 15:35:04 +02:00
$descr = '<font color="FF0000"><b>' . $descr . '</b></font>';
}
2002-03-13 17:30:51 +01:00
if ($GLOBALS['appname'] && $categories[$i]['app_name'] == 'phpgw')
2002-03-13 05:16:46 +01:00
{
$appendix = '&lt;' . lang('Global') . '&gt;';
}
else
{
$appendix = '';
}
$GLOBALS['phpgw']->template->set_var(array
2002-03-13 05:16:46 +01:00
(
'name' => $cat_name . $appendix,
'descr' => $descr
));
$link_data['menuaction'] = 'admin.uicategories.add';
$link_data['cat_parent'] = $id;
$GLOBALS['phpgw']->template->set_var('add_sub',$GLOBALS['phpgw']->link('/index.php',$link_data));
$GLOBALS['phpgw']->template->set_var('lang_sub_entry',lang('Add sub'));
2002-03-13 05:16:46 +01:00
2002-03-13 18:27:31 +01:00
if ($GLOBALS['appname'] && $categories[$i]['app_name'] == $GLOBALS['appname'])
{
$show_edit_del = True;
}
elseif(!$GLOBALS['appname'] && $categories[$i]['app_name'] == 'phpgw')
{
$show_edit_del = True;
}
else
{
$show_edit_del = False;
}
2001-10-02 15:35:04 +02:00
2002-03-13 18:27:31 +01:00
if ($show_edit_del)
{
$link_data['cat_id'] = $id;
$link_data['menuaction'] = 'admin.uicategories.edit';
$GLOBALS['phpgw']->template->set_var('edit',$GLOBALS['phpgw']->link('/index.php',$link_data));
$GLOBALS['phpgw']->template->set_var('lang_edit_entry',lang('Edit'));
2002-03-13 18:27:31 +01:00
$link_data['menuaction'] = 'admin.uicategories.delete';
$GLOBALS['phpgw']->template->set_var('delete',$GLOBALS['phpgw']->link('/index.php',$link_data));
$GLOBALS['phpgw']->template->set_var('lang_delete_entry',lang('Delete'));
2002-03-13 18:27:31 +01:00
}
else
{
$GLOBALS['phpgw']->template->set_var('edit','');
$GLOBALS['phpgw']->template->set_var('lang_edit_entry','&nbsp;');
$GLOBALS['phpgw']->template->set_var('delete','');
$GLOBALS['phpgw']->template->set_var('lang_delete_entry','&nbsp;');
2002-03-13 18:27:31 +01:00
}
$GLOBALS['phpgw']->template->fp('rows','cat_row',True);
2001-10-02 15:35:04 +02:00
}
2002-03-13 17:30:51 +01:00
$link_data['menuaction'] = 'admin.uicategories.add';
$link_data['cat_parent'] = '';
$GLOBALS['phpgw']->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
2002-03-13 17:30:51 +01:00
2001-10-02 15:35:04 +02:00
$this->save_sessiondata();
$GLOBALS['phpgw']->template->fp('phpgw_body','cat_list',True);
2001-10-02 15:35:04 +02:00
}
function add()
{
2002-09-08 22:40:12 +02:00
$global_cats = get_var('global_cats',array('POST','GET'));
2002-03-13 17:30:51 +01:00
$link_data = array
(
2002-06-18 03:13:43 +02:00
'menuaction' => 'admin.uicategories.index',
'appname' => $GLOBALS['appname'],
'global_cats' => $global_cats
2002-03-13 18:03:49 +01:00
);
2002-03-13 17:30:51 +01:00
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->common->phpgw_header();
2002-01-12 19:28:42 +01:00
$this->set_langs();
2002-06-18 03:13:43 +02:00
$new_parent = $GLOBALS['HTTP_POST_VARS']['new_parent'];
$submit = $GLOBALS['HTTP_POST_VARS']['submit'];
$cat_parent = $GLOBALS['HTTP_POST_VARS']['cat_parent'] ? $GLOBALS['HTTP_POST_VARS']['cat_parent'] : $GLOBALS['HTTP_GET_VARS']['cat_parent'];
$cat_name = $GLOBALS['HTTP_POST_VARS']['cat_name'];
$cat_description = $GLOBALS['HTTP_POST_VARS']['cat_description'];
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->set_file(array('cat_form' => 'category_form.tpl'));
$GLOBALS['phpgw']->template->set_block('cat_form','add');
$GLOBALS['phpgw']->template->set_block('cat_form','edit');
$GLOBALS['phpgw']->template->set_block('cat_form','form');
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
2002-03-13 17:30:51 +01:00
2002-03-13 05:16:46 +01:00
if ($GLOBALS['appname'])
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Add global category for x',lang($GLOBALS['appname'])));
2002-03-13 05:16:46 +01:00
}
else
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Add global category'));
2002-03-13 05:16:46 +01:00
}
2001-10-02 15:35:04 +02:00
if ($new_parent)
{
$cat_parent = $new_parent;
}
if ($submit)
{
2002-01-12 19:28:42 +01:00
$values = array
(
2002-06-18 03:13:43 +02:00
'parent' => $cat_parent,
'descr' => $cat_description,
'name' => $cat_name,
'access' => 'public'
2002-01-12 19:28:42 +01:00
);
$error = $this->bo->check_values($values);
if (is_array($error))
2001-10-02 15:35:04 +02:00
{
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
2001-10-02 15:35:04 +02:00
}
2002-01-12 19:28:42 +01:00
else
2001-10-02 15:35:04 +02:00
{
2002-01-12 19:28:42 +01:00
$this->bo->save_cat($values);
$GLOBALS['phpgw']->template->set_var('message',lang('Category x has been added !', $cat_name));
2001-10-02 15:35:04 +02:00
}
}
$link_data['menuaction'] = 'admin.uicategories.add';
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
2002-03-13 17:30:51 +01:00
2002-06-18 03:13:43 +02:00
$GLOBALS['phpgw']->template->set_var('category_list',$this->bo->formatted_list(array(
'select' => 'select',
'all' => 'all',
'cat_parent' => $cat_parent,
'global_cats' => $global_cats
)));
$GLOBALS['phpgw']->template->set_var('cat_name',$cat_name);
$GLOBALS['phpgw']->template->set_var('cat_description',$cat_description);
$GLOBALS['phpgw']->template->parse('buttons','add');
$GLOBALS['phpgw']->template->fp('phpgw_body','form');
2001-10-02 15:35:04 +02:00
}
function edit()
{
2002-09-08 22:40:12 +02:00
$global_cats = get_var('global_cats',array('POST','GET'));
2002-03-13 17:30:51 +01:00
$link_data = array
(
2002-06-18 03:13:43 +02:00
'menuaction' => 'admin.uicategories.index',
'appname' => $GLOBALS['appname'],
'global_cats' => $global_cats
2002-03-13 18:03:49 +01:00
);
2002-03-13 17:30:51 +01:00
2001-10-02 15:35:04 +02:00
if (!$this->cat_id)
{
2002-03-13 17:30:51 +01:00
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',$link_data));
2001-10-02 15:35:04 +02:00
}
$GLOBALS['phpgw']->common->phpgw_header();
2002-01-12 19:28:42 +01:00
$this->set_langs();
2002-06-18 03:13:43 +02:00
$new_parent = $GLOBALS['HTTP_POST_VARS']['new_parent'];
$submit = $GLOBALS['HTTP_POST_VARS']['submit'];
$cat_parent = $GLOBALS['HTTP_POST_VARS']['cat_parent'];
$cat_name = $GLOBALS['HTTP_POST_VARS']['cat_name'];
$cat_description = $GLOBALS['HTTP_POST_VARS']['cat_description'];
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->set_file(array('cat_form' => 'category_form.tpl'));
$GLOBALS['phpgw']->template->set_block('cat_form','add');
$GLOBALS['phpgw']->template->set_block('cat_form','edit');
$GLOBALS['phpgw']->template->set_block('cat_form','form');
2001-10-02 15:35:04 +02:00
$hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n";
$GLOBALS['phpgw']->template->set_var('hidden_vars',$hidden_vars);
$GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
2001-10-02 15:35:04 +02:00
if ($new_parent)
{
$cat_parent = $new_parent;
}
if ($submit)
{
2002-01-12 19:28:42 +01:00
$values = array
(
2002-06-18 03:13:43 +02:00
'id' => $this->cat_id,
'parent' => $cat_parent,
'descr' => $cat_description,
'name' => $cat_name,
'access' => 'public'
2002-01-12 19:28:42 +01:00
);
$error = $this->bo->check_values($values);
if (is_array($error))
2001-10-02 15:35:04 +02:00
{
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
2001-10-02 15:35:04 +02:00
}
2002-01-12 19:28:42 +01:00
else
2001-10-02 15:35:04 +02:00
{
2002-01-12 19:28:42 +01:00
$this->bo->save_cat($values);
$GLOBALS['phpgw']->template->set_var('message',lang('Category x has been updated !',$cat_name));
2001-10-02 15:35:04 +02:00
}
}
$cats = $this->bo->cats->return_single($this->cat_id);
2002-03-13 05:16:46 +01:00
if ($GLOBALS['appname'])
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit global category for x',lang($GLOBALS['appname'])));
2002-03-13 05:16:46 +01:00
}
else
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit global category'));
2002-03-13 05:16:46 +01:00
}
2002-06-18 03:13:43 +02:00
$link_data['menuaction'] = 'admin.uicategories.edit';
$link_data['cat_id'] = $this->cat_id;
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
2002-06-18 03:13:43 +02:00
$link_data['menuaction'] = 'admin.uicategories.delete';
$GLOBALS['phpgw']->template->set_var('deleteurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cats[0]['name']));
$GLOBALS['phpgw']->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cats[0]['description']));
2002-06-18 03:13:43 +02:00
$GLOBALS['phpgw']->template->set_var('category_list',$this->bo->formatted_list(array(
'select' => 'select',
'all' => 'all',
'cat_parent' => $cats[0]['parent'],
'global_cats' => $global_cats
)));
2001-10-02 15:35:04 +02:00
$GLOBALS['phpgw']->template->parse('buttons','edit');
$GLOBALS['phpgw']->template->fp('phpgw_body','form');
2001-10-02 15:35:04 +02:00
}
function delete()
{
2002-09-08 22:40:12 +02:00
$global_cats = get_var('global_cats',array('POST','GET'));
2002-03-13 05:16:46 +01:00
$link_data = array
(
2002-06-18 03:13:43 +02:00
'menuaction' => 'admin.uicategories.index',
'appname' => $GLOBALS['appname'],
'global_cats' => $global_cats
2002-03-13 05:16:46 +01:00
);
2001-10-02 15:35:04 +02:00
if (!$this->cat_id)
{
2002-03-13 05:16:46 +01:00
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',$link_data));
2001-10-02 15:35:04 +02:00
}
if ($GLOBALS['HTTP_POST_VARS']['confirm'])
{
2002-09-04 02:30:50 +02:00
switch ($GLOBALS['HTTP_POST_VARS']['subs'])
{
2002-09-04 02:30:50 +02:00
case 'move':
2002-09-25 03:10:26 +02:00
$this->bo->delete(array('cat_id' => $this->cat_id, 'modify_subs' => True));
2002-09-04 02:30:50 +02:00
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',$link_data));
break;
case 'drop':
2002-09-25 03:10:26 +02:00
$this->bo->delete(array('cat_id' => $this->cat_id, 'drop_subs' => True));
2002-09-04 02:30:50 +02:00
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',$link_data));
break;
default:
$error_msg = lang('Please choose one of the methods to handle the subcategories');
break;
}
2002-09-04 02:30:50 +02:00
}
$GLOBALS['phpgw']->template->set_file(array('category_delete' => 'delete_cat.tpl'));
$GLOBALS['phpgw']->template->set_var('error_msg',$error_msg);
$nolink = $GLOBALS['phpgw']->link('/index.php',$link_data);
2002-09-08 22:40:12 +02:00
if ($GLOBALS['appname'])
{
$type = 'noglobalapp';
}
else
{
$type = 'noglobal';
}
2002-09-04 02:30:50 +02:00
$apps_cats = $this->bo->exists(array
(
2002-09-08 22:40:12 +02:00
'type' => $type,
2002-09-04 02:30:50 +02:00
'cat_name' => '',
'cat_id' => $this->cat_id
));
$GLOBALS['phpgw']->common->phpgw_header();
$GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="cat_id" value="' . $this->cat_id . '">');
if ($apps_cats)
{
2002-09-08 22:40:12 +02:00
$GLOBALS['phpgw']->template->set_var('delete_msg',lang('This category is currently being used by applications as a parent category') . '<br>'
. lang('You will need to reassign these subcategories before you can delete this category'));
2002-09-04 02:30:50 +02:00
$GLOBALS['phpgw']->template->set_var('lang_subs','');
$GLOBALS['phpgw']->template->set_var('subs','');
$GLOBALS['phpgw']->template->set_var('nolink',$nolink);
$GLOBALS['phpgw']->template->set_var('deletehandle','');
$GLOBALS['phpgw']->template->set_var('donehandle','');
$GLOBALS['phpgw']->template->pfp('out','category_delete');
$GLOBALS['phpgw']->template->pfp('donehandle','done');
2001-10-02 15:35:04 +02:00
}
else
{
2002-09-08 22:40:12 +02:00
$GLOBALS['phpgw']->template->set_var('delete_msg',lang('Are you sure you want to delete this global category ?'));
2001-10-02 15:35:04 +02:00
2002-09-04 02:30:50 +02:00
$exists = $this->bo->exists(array
2002-03-13 05:16:46 +01:00
(
2001-10-02 15:35:04 +02:00
'type' => 'subs',
'cat_name' => '',
'cat_id' => $this->cat_id
));
2002-09-04 02:30:50 +02:00
if ($exists)
2001-10-02 15:35:04 +02:00
{
2002-09-04 02:30:50 +02:00
$sub_select = '<input type="radio" name="subs" value="move">' . lang('Do you want to move all global subcategories one level down ?') . '<br>';
$sub_select .= '<input type="radio" name="subs" value="drop">' . lang('Do you want to delete all global subcategories ?');
$GLOBALS['phpgw']->template->set_var('sub_select',$sub_select);
}
2001-10-02 15:35:04 +02:00
2002-09-04 02:30:50 +02:00
$GLOBALS['phpgw']->template->set_var('nolink',$nolink);
$GLOBALS['phpgw']->template->set_var('lang_no',lang('No'));
2002-03-13 05:16:46 +01:00
2002-09-04 02:30:50 +02:00
$link_data['menuaction'] = 'admin.uicategories.delete';
$link_data['cat_id'] = $this->cat_id;
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
$GLOBALS['phpgw']->template->set_var('lang_yes',lang('Yes'));
2002-09-04 02:30:50 +02:00
$GLOBALS['phpgw']->template->fp('phpgw_body','category_delete');
2001-10-02 15:35:04 +02:00
}
}
}
?>