egroupware_official/admin/inc/class.uicategories.inc.php

464 lines
14 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 $nextmatchs;
var $xslttpl;
2001-10-02 15:35:04 +02:00
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,
'edit' => True,
'delete' => True
);
2002-01-12 19:28:42 +01:00
2001-10-02 15:35:04 +02:00
function uicategories()
{
$GLOBALS['phpgw_info']['flags']['xslt_app'] = True;
2002-10-04 22:59:00 +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(
2002-10-04 22:59:00 +02:00
'start' => $this->start,
'query' => $this->query,
'sort' => $this->sort,
'order' => $this->order,
'cat_id' => $this->cat_id
2001-10-02 15:35:04 +02:00
);
echo '<br>UI:<br>';
_debug_array($data);
}
function save_sessiondata()
{
2002-03-13 05:16:46 +01:00
$data = array
(
2002-10-04 22:59:00 +02:00
'start' => $this->start,
'query' => $this->query,
'sort' => $this->sort,
'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);
}
function index()
{
2002-09-08 22:40:12 +02:00
$global_cats = get_var('global_cats',array('POST','GET'));
$GLOBALS['phpgw']->xslttpl->add_file(array('app_data','cats',
$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'search_field',
$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'nextmatchs'));
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
);
2003-04-28 01:16:15 +02:00
if ($_POST['add'])
{
$link_data['menuaction'] = 'admin.uicategories.edit';
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
}
if ($_POST['done'])
{
2003-04-28 02:31:33 +02:00
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uimainscreen.mainscreen');
2003-04-28 01:16:15 +02:00
}
2002-03-13 05:16:46 +01:00
if ($GLOBALS['appname'])
{
$GLOBALS['phpgw_info']['flags']['app_header'] = lang($GLOBALS['appname']) . '&nbsp;' . lang('global categories') . ': ' . lang('category list');
2002-03-13 05:16:46 +01:00
}
else
{
$GLOBALS['phpgw_info']['flags']['app_header'] = lang('global categories') . ': ' . lang('category list');
2002-03-13 05:16:46 +01:00
}
2001-10-02 15:35:04 +02:00
if (!$global_cats)
{
$global_cats = False;
}
$categories = $this->bo->get_list($global_cats);
2001-10-02 15:35:04 +02:00
$cat_header[] = array
(
'sort_name' => $this->nextmatchs->show_sort_order(array
(
'sort' => $this->sort,
'var' => 'cat_name',
'order' => $this->order,
'extra' => $link_data
)),
'lang_add_sub' => lang('add sub'),
'lang_name' => lang('name'),
'lang_descr' => lang('description'),
'lang_edit' => lang('edit'),
'lang_delete' => lang('delete'),
'lang_sort_statustext' => lang('sort the entries'),
'sort_descr' => $this->nextmatchs->show_sort_order(array
(
'sort' => $this->sort,
'var' => 'cat_description',
'order' => $this->order,
'extra' => $link_data
))
);
2001-10-02 15:35:04 +02:00
while (is_array($categories) && list(,$cat) = each($categories))
2001-10-02 15:35:04 +02:00
{
$level = $cat['level'];
$cat_name = $GLOBALS['phpgw']->strip_html($cat['name']);
2001-10-02 15:35:04 +02:00
$main = 'yes';
2001-10-02 15:35:04 +02:00
if ($level > 0)
{
$space = '&nbsp;.&nbsp;';
2001-10-02 15:35:04 +02:00
$spaceset = str_repeat($space,$level);
2002-03-13 05:16:46 +01:00
$cat_name = $spaceset . $cat_name;
$main = 'no';
2001-10-02 15:35:04 +02:00
}
$descr = $GLOBALS['phpgw']->strip_html($cat['descr']);
2001-10-02 15:35:04 +02:00
if ($GLOBALS['appname'] && $cat['app_name'] == 'phpgw')
2002-03-13 05:16:46 +01:00
{
$appendix = '&nbsp;&lt;' . lang('Global') . '&gt;';
2002-03-13 05:16:46 +01:00
}
else
{
$appendix = '';
}
$link_data['menuaction'] = 'admin.uicategories.edit';
$link_data['parent'] = $cat['cat_id'];
$add_sub_url = $GLOBALS['phpgw']->link('/index.php',$link_data);
2002-03-13 05:16:46 +01:00
if ($GLOBALS['appname'] && $cat['app_name'] == $GLOBALS['appname'])
2002-03-13 18:27:31 +01:00
{
$show_edit_del = True;
}
elseif(!$GLOBALS['appname'] && $cat['app_name'] == 'phpgw')
2002-03-13 18:27:31 +01:00
{
$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'] = $cat['cat_id'];
$link_data['menuaction'] = 'admin.uicategories.edit';
$edit_url = $GLOBALS['phpgw']->link('/index.php',$link_data);
$lang_edit = lang('edit');
$link_data['menuaction'] = 'admin.uicategories.delete';
$delete_url = $GLOBALS['phpgw']->link('/index.php',$link_data);
$lang_delete = lang('delete');
2002-03-13 18:27:31 +01:00
}
else
{
$edit_url = '';
$lang_edit = '';
$delete_url = '';
$lang_delete = '';
2002-03-13 18:27:31 +01:00
}
$content[] = array
(
'name' => $cat_name . $appendix,
'descr' => $descr,
'date' => $note['date'],
'main' => $main,
'add_sub_url' => $add_sub_url,
'edit_url' => $edit_url,
'delete_url' => $delete_url,
'lang_add_sub_statustext' => lang('add a subcategory'),
'lang_edit_statustext' => lang('edit this category'),
'lang_delete_statustext' => lang('delete this category'),
'lang_add_sub' => lang('add sub'),
'lang_edit' => $lang_edit,
'lang_delete' => $lang_delete
);
2001-10-02 15:35:04 +02:00
}
2003-04-28 01:16:15 +02:00
$link_data['menuaction'] = 'admin.uicategories.index';
$link_data['parent'] = '';
2001-10-02 15:35:04 +02:00
$cat_add[] = array
2002-03-13 17:30:51 +01:00
(
'lang_add' => lang('add'),
'lang_add_statustext' => lang('add a category'),
2003-04-28 01:16:15 +02:00
'action_url' => $GLOBALS['phpgw']->link('/index.php',$link_data),
'lang_done' => lang('done'),
2003-04-28 01:16:15 +02:00
'lang_done_statustext' => lang('return to admin mainscreen')
2002-03-13 18:03:49 +01:00
);
2002-03-13 17:30:51 +01:00
$link_data['menuaction'] = 'admin.uicategories.index';
2002-01-12 19:28:42 +01:00
$data = array
(
'start_record' => $this->start,
'record_limit' => $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'],
'num_records' => count($categoris),
'all_records' => $this->bo->cats->total_records,
'nextmatchs_url' => $GLOBALS['phpgw']->link('/index.php',$link_data),
'nextmatchs_img_path' => $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
'select_url' => $GLOBALS['phpgw']->link('/index.php',$link_data),
'lang_searchfield_statustext' => lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
'lang_searchbutton_statustext' => lang('Submit the search string'),
'query' => $this->query,
'lang_search' => lang('search'),
'cat_header' => $cat_header,
'cat_data' => $content,
'cat_add' => $cat_add
);
2001-10-02 15:35:04 +02:00
$this->save_sessiondata();
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('cat_list' => $data));
}
2002-03-13 17:30:51 +01:00
function edit()
{
$global_cats = get_var('global_cats',array('POST','GET'));
$parent = get_var('parent',array('GET'));
$values = get_var('values',array('POST'));
2001-10-02 15:35:04 +02:00
2003-04-28 01:16:15 +02:00
$link_data = array
(
'menuaction' => 'admin.uicategories.index',
'appname' => $GLOBALS['appname'],
'global_cats' => $global_cats
);
if ($values['cancel'])
2001-10-02 15:35:04 +02:00
{
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
}
if ($values['save'] || $values['apply'])
{
$values['cat_id'] = $this->cat_id;
$values['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
{
$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
{
$this->cat_id = $this->bo->save_cat($values);
2003-04-28 01:16:15 +02:00
if ($values['apply'])
{
$message = lang('Category %1 has been saved !',$values['name']);
}
else
{
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
}
2001-10-02 15:35:04 +02:00
}
}
2003-04-28 01:16:15 +02:00
if ($this->cat_id)
{
$cats = $this->bo->cats->return_single($this->cat_id);
$parent = $cats['parent'];
}
if ($GLOBALS['appname'])
{
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw_info']['flags']['app_header'] = lang($GLOBALS['appname']) . '&nbsp;' . lang('global categories') . ': ' . ($this->cat_id?lang('edit category'):lang('add category'));
}
else
{
$GLOBALS['phpgw_info']['flags']['app_header'] = lang('global categories') . ': ' . $function;
}
$GLOBALS['phpgw']->xslttpl->add_file(array('app_data','cats'));
2001-10-02 15:35:04 +02:00
if ($GLOBALS['appname'])
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit global category for %1',lang($GLOBALS['appname'])));
}
else
{
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit global category'));
}
$data = array
(
'lang_name' => lang('name'),
'lang_descr' => lang('description'),
'lang_parent' => lang('parent category'),
'old_parent' => $cats['parent'],
'lang_save' => lang('save'),
2003-04-28 01:16:15 +02:00
'lang_apply' => lang('apply'),
'lang_cancel' => lang('cancel'),
'value_name' => $GLOBALS['phpgw']->strip_html($cats['name']),
'value_descr' => $GLOBALS['phpgw']->strip_html($cats['descr']),
'message' => $message,
2003-04-28 01:16:15 +02:00
'lang_content_statustext' => lang('enter a description for the category'),
'lang_cancel_statustext' => lang('leave the category untouched and return back to the list'),
'lang_save_statustext' => lang('save the category and return back to the list'),
'lang_apply_statustext' => lang('save the category'),
'lang_no_cat' => lang('no category'),
'lang_cat_statustext' => lang('Select the parent category. If this is a main category select NO CATEGORY'),
'select_name' => 'values[parent]',
'cat_list' => $this->bo->cats->formatted_xslt_list(array('format' => 'select','selected' => $parent,'globals' => $global_cats))
);
2001-10-02 15:35:04 +02:00
$link_data['menuaction'] = 'admin.uicategories.edit';
if ($this->cat_id)
2001-10-02 15:35:04 +02:00
{
$link_data['cat_id'] = $this->cat_id;
2001-10-02 15:35:04 +02:00
}
$data['edit_url'] = $GLOBALS['phpgw']->link('/index.php',$link_data);
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('cat_edit' => $data));
}
2001-10-02 15:35:04 +02:00
function delete()
{
$global_cats = get_var('global_cats',array('POST','GET'));
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
);
2003-04-28 02:31:33 +02:00
if ($_POST['done'] || $_POST['cancel'] || !$this->cat_id)
2001-10-02 15:35:04 +02:00
{
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
2001-10-02 15:35:04 +02:00
}
2003-04-28 01:16:15 +02:00
if ($_POST['delete'])
2001-10-02 15:35:04 +02:00
{
2003-04-28 01:16:15 +02:00
if ($_POST['subs'])
{
2003-04-28 01:16:15 +02:00
switch ($_POST['subs'])
2002-10-12 02:48:36 +02:00
{
case 'move':
$this->bo->delete(array('cat_id' => $this->cat_id, 'modify_subs' => True));
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
2002-10-12 02:48:36 +02:00
break;
case 'drop':
$this->bo->delete(array('cat_id' => $this->cat_id, 'drop_subs' => True));
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
2002-10-12 02:48:36 +02:00
break;
default:
2003-04-28 02:31:33 +02:00
$error = array('Please choose one of the methods to handle the subcategories');
$msgbox_error = $GLOBALS['phpgw']->common->error_list($error);
2002-10-12 02:48:36 +02:00
break;
}
}
else
{
$this->bo->delete(array('cat_id' => $this->cat_id));
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
}
2002-09-04 02:30:50 +02:00
}
$GLOBALS['phpgw']->xslttpl->add_file(array($GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'app_delete'));
2002-09-04 02:30:50 +02:00
2003-04-28 01:16:15 +02:00
$GLOBALS['phpgw_info']['flags']['app_header'] = ($GLOBALS['appname']?lang($GLOBALS['appname']) . '&nbsp;':'') . lang('global categories') . ': ' . lang('delete category');
$type = ($GLOBALS['appname']?'noglobalapp':'noglobal');
2002-09-08 22:40:12 +02:00
$apps_cats = $this->bo->exists(array('type' => $type,
'cat_name' => '',
'cat_id' => $this->cat_id));
2002-09-04 02:30:50 +02:00
if ($apps_cats)
{
2003-04-28 02:31:33 +02:00
$error = array('This category is currently being used by applications as a parent category',
'You will need to reassign these subcategories before you can delete this category');
2003-04-28 02:41:55 +02:00
$msgbox_error = $GLOBALS['phpgw']->common->error_list($error);
$show_done = 'yes';
2001-10-02 15:35:04 +02:00
}
else
{
2003-04-28 02:31:33 +02:00
$confirm_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
{
$subs = 'yes';
$lang_sub_select_move = lang('Do you want to move all global subcategories one level down ?');
$lang_sub_select_drop = lang('Do you want to delete all global subcategories ?');
2002-09-04 02:30:50 +02:00
}
}
2001-10-02 15:35:04 +02:00
$data = array
(
2003-04-28 02:31:33 +02:00
'show_done' => $show_done,
'msgbox_data' => $msgbox_error,
2003-04-28 01:16:15 +02:00
'lang_delete' => lang('delete'),
'subs' => $subs,
'lang_sub_select_move' => $lang_sub_select_move,
'lang_sub_select_drop' => $lang_sub_select_drop,
'lang_delete_statustext' => lang('delete the category'),
'lang_cancel_statustext' => lang('do NOT delete the category and return back to the list'),
2003-04-28 02:31:33 +02:00
'lang_done_statustext' => lang('back to the list'),
2003-04-28 01:16:15 +02:00
'lang_cancel' => lang('cancel'),
2003-04-28 02:31:33 +02:00
'lang_done' => lang('done'),
'lang_confirm_msg' => $confirm_msg
);
2002-03-13 05:16:46 +01:00
$link_data['menuaction'] = 'admin.uicategories.delete';
$link_data['cat_id'] = $this->cat_id;
$data['delete_url'] = $GLOBALS['phpgw']->link('/index.php',$link_data);
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('delete' => $data));
2001-10-02 15:35:04 +02:00
}
}
?>