2002-01-12 05:09:56 +01:00
|
|
|
<?php
|
2002-10-04 22:59:00 +02:00
|
|
|
/**************************************************************************\
|
2004-08-09 16:30:59 +02:00
|
|
|
* eGroupWare - Preferences - categories *
|
|
|
|
* http://www.egroupware.org *
|
2002-10-04 22:59:00 +02:00
|
|
|
* Written by Bettina Gille [ceb@phpgroupware.org] *
|
2004-05-26 09:25:29 +02:00
|
|
|
* Simplified ;-) and icon & color added by RalfBecker@outdoor-training.de *
|
2002-10-04 22:59:00 +02:00
|
|
|
* ----------------------------------------------- *
|
2003-08-28 16:31:11 +02:00
|
|
|
* Copyright 2000 - 2003 Free Software Foundation, Inc *
|
|
|
|
* *
|
|
|
|
* 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. *
|
2002-10-04 22:59:00 +02:00
|
|
|
\**************************************************************************/
|
|
|
|
/* $Id$ */
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
class uicategories
|
|
|
|
{
|
|
|
|
var $bo;
|
|
|
|
|
|
|
|
var $start;
|
|
|
|
var $query;
|
|
|
|
var $sort;
|
|
|
|
var $order;
|
|
|
|
var $cat_id;
|
2005-11-08 11:43:49 +01:00
|
|
|
var $referer;
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
var $cats_app;
|
|
|
|
|
2002-01-12 05:09:56 +01:00
|
|
|
var $public_functions = array
|
|
|
|
(
|
2003-08-28 16:31:11 +02:00
|
|
|
'index' => True,
|
|
|
|
'edit' => True,
|
|
|
|
'delete' => True
|
2002-01-12 05:09:56 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
function uicategories()
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$cats_app = get_var('cats_app',array('GET','POST'));
|
2002-10-04 22:59:00 +02:00
|
|
|
|
2005-10-14 16:31:35 +02:00
|
|
|
$this->bo =& CreateObject('preferences.bocategories',$cats_app);
|
|
|
|
$this->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->account = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
$this->user = $GLOBALS['egw_info']['user']['fullname'];
|
2002-10-04 22:59:00 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->start = $this->bo->start;
|
|
|
|
$this->query = $this->bo->query;
|
|
|
|
$this->sort = $this->bo->sort;
|
|
|
|
$this->order = $this->bo->order;
|
2005-11-08 11:43:49 +01:00
|
|
|
$this->referer = $this->bo->referer;
|
2004-05-26 09:25:29 +02:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$dir = dir(EGW_SERVER_ROOT.'/phpgwapi/images');
|
2004-05-26 09:25:29 +02:00
|
|
|
while($file = $dir->read())
|
|
|
|
{
|
|
|
|
if (preg_match('/\\.(png|gif|jpe?g)$/i',$file))
|
|
|
|
{
|
|
|
|
$this->icons[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$dir->close();
|
|
|
|
sort($this->icons);
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->img_url = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/images/';
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_sessiondata($cats_app)
|
|
|
|
{
|
|
|
|
$data = array
|
|
|
|
(
|
2003-08-28 16:31:11 +02:00
|
|
|
'start' => $this->start,
|
|
|
|
'query' => $this->query,
|
|
|
|
'sort' => $this->sort,
|
2005-11-08 11:43:49 +01:00
|
|
|
'order' => $this->order,
|
|
|
|
'referer' => $this->referer,
|
2002-01-12 05:09:56 +01:00
|
|
|
);
|
|
|
|
$this->bo->save_sessiondata($data,$cats_app);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_langs()
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_access',lang('Private'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_save',lang('Save'));
|
|
|
|
$GLOBALS['egw']->template->set_var('user_name',$this->user);
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_search',lang('Search'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_cancel',lang('Cancel'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_sub',lang('Add sub'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_edit',lang('Edit'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_delete',lang('Delete'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_parent',lang('Parent category'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_none',lang('None'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_name',lang('Name'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_descr',lang('Description'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_add',lang('Add'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_reset',lang('Clear Form'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_color',lang('Color'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_icon',lang('Icon'));
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2002-01-14 00:31:03 +01:00
|
|
|
function cat_data($edata,$data)
|
|
|
|
{
|
2004-05-26 09:25:29 +02:00
|
|
|
foreach ($edata as $name)
|
2002-01-14 00:31:03 +01:00
|
|
|
{
|
2004-05-26 09:25:29 +02:00
|
|
|
$td_data .= '<td>' . ($name == 'icon' && $data['icon'] ? '<img src="'.$this->img_url.$data['icon'].'">' : $data[$name]) . '</td>' . "\n";
|
2002-01-14 00:31:03 +01:00
|
|
|
}
|
|
|
|
return $td_data;
|
|
|
|
}
|
|
|
|
|
2002-01-12 05:09:56 +01:00
|
|
|
function index()
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$cats_app = get_var('cats_app',array('GET','POST'));
|
|
|
|
$extra = get_var('extra',array('GET','POST'));
|
|
|
|
$global_cats = get_var('global_cats',array('GET','POST'));
|
|
|
|
$cats_level = get_var('cats_level',array('GET','POST'));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-11-08 11:43:49 +01:00
|
|
|
// make categories called via sidebox menu of an app, to behave like a part of that app
|
2005-11-09 13:46:52 +01:00
|
|
|
$referer = $GLOBALS['egw']->common->get_referer('/preferences/index.php');
|
2007-04-29 17:07:11 +02:00
|
|
|
if (strpos($referer,'menuaction=preferences.uicategories') === false)
|
2005-11-08 11:43:49 +01:00
|
|
|
{
|
|
|
|
$this->referer = $referer;
|
|
|
|
}
|
|
|
|
if ($this->referer != '/preferences/index.php')
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = $cats_app;
|
|
|
|
}
|
|
|
|
|
2002-01-12 05:09:56 +01:00
|
|
|
$link_data = array
|
|
|
|
(
|
2003-08-28 16:31:11 +02:00
|
|
|
'menuaction' => 'preferences.uicategories.index',
|
|
|
|
'cats_app' => $cats_app,
|
|
|
|
'extra' => $extra,
|
|
|
|
'global_cats' => $global_cats,
|
|
|
|
'cats_level' => $cats_level
|
2002-01-12 05:09:56 +01:00
|
|
|
);
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if($extra)
|
2002-01-13 23:35:54 +01:00
|
|
|
{
|
|
|
|
$edata = explode(',',$extra);
|
|
|
|
}
|
2004-05-26 09:25:29 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$edata = array('icon');
|
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$cats_app]['title'].
|
2003-04-20 22:47:50 +02:00
|
|
|
' '.lang('categories for').': '.$this->user;
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->common->egw_header();
|
2003-08-28 16:31:11 +02:00
|
|
|
echo parse_navbar();
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_file(array(
|
2003-10-18 12:30:02 +02:00
|
|
|
'cat_list_t' => 'listcats.tpl',
|
|
|
|
));
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_block('cat_list_t','cat_list','list');
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
$this->set_langs();
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('title_categories',lang('categories for'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_app',lang($cats_app));
|
|
|
|
$GLOBALS['egw']->template->set_var('actionurl',$GLOBALS['egw']->link('/index.php',$link_data));
|
2005-11-08 11:43:49 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('doneurl',$GLOBALS['egw']->link($this->referer));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if(!$this->start)
|
|
|
|
{
|
|
|
|
$this->start = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$global_cats)
|
2002-01-13 23:35:54 +01:00
|
|
|
{
|
|
|
|
$global_cats = False;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cats = $this->bo->get_list($global_cats);
|
2004-05-26 09:25:29 +02:00
|
|
|
if (!is_array($cats)) $cats = array();
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
//--------------------------------- nextmatch --------------------------------------------
|
|
|
|
|
|
|
|
$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);
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('left',$left);
|
|
|
|
$GLOBALS['egw']->template->set_var('right',$right);
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
// ------------------------------ end nextmatch ------------------------------------------
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
//------------------- list header variable template-declarations -------------------------
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2002-01-13 23:35:54 +01:00
|
|
|
if (is_array($edata))
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2002-01-13 23:35:54 +01:00
|
|
|
for($i=0;$i<count($edata);$i++)
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('sort_data','<td class="th">' . lang($edata[$i]) . '</td>');
|
2002-01-13 23:35:54 +01:00
|
|
|
}
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('th_data','');
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
// -------------------------- end header declaration --------------------------------------
|
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
foreach($cats as $cat)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2004-05-26 09:25:29 +02:00
|
|
|
$data = unserialize($cat['data']);
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
if ($data['color'])
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('tr_color',$data['color']);
|
2004-05-26 09:25:29 +02:00
|
|
|
$gray = (hexdec(substr($data['color'],1,2))+hexdec(substr($data['color'],3,2))+hexdec(substr($data['color'],5,2)))/3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->nextmatchs->template_alternate_row_color($GLOBALS['egw']->template);
|
2004-05-26 09:25:29 +02:00
|
|
|
$gray = 255;
|
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('color',$gray < 128 ? 'style="color: white;"' : '');
|
2004-05-26 09:25:29 +02:00
|
|
|
|
|
|
|
if ($cat['app_name'] == 'phpgw')
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$appendix = '<' . lang('Global') . '>';
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2004-05-26 09:25:29 +02:00
|
|
|
elseif ($cat['owner'] == '-1')
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$appendix = '<' . lang('Global') . ' ' . $GLOBALS['egw_info']['apps'][$cats_app]['title'] . '>';
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2002-03-13 17:30:51 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$appendix = '';
|
|
|
|
}
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
$level = $cat['level'];
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
if ($level > 0)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$space = ' ';
|
2002-01-12 05:09:56 +01:00
|
|
|
$spaceset = str_repeat($space,$level);
|
2005-07-09 21:07:16 +02:00
|
|
|
$name = $spaceset . $GLOBALS['egw']->strip_html($cat['name']) . $appendix;
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$descr = $GLOBALS['egw']->strip_html($cat['description']);
|
2002-01-12 05:09:56 +01:00
|
|
|
if (!$descr) { $descr = ' '; }
|
|
|
|
|
2002-01-13 23:35:54 +01:00
|
|
|
if (is_array($edata))
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2004-05-26 09:25:29 +02:00
|
|
|
if (!is_array($data))
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2002-01-13 23:35:54 +01:00
|
|
|
$holder = '<td> </td>' . "\n";
|
|
|
|
$placeholder = str_repeat($holder,count($edata));
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('td_data',$placeholder);
|
2002-01-13 23:35:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('td_data',$this->cat_data($edata,$data));
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($level == 0)
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$name = '<font color="FF0000"><b>' . $GLOBALS['egw']->strip_html($cat['name']) . '</b></font>' . $appendix;
|
2002-01-12 05:09:56 +01:00
|
|
|
$descr = '<font color="FF0000"><b>' . $descr . '</b></font>';
|
|
|
|
}
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2003-08-28 16:31:11 +02:00
|
|
|
'name' => $name,
|
2002-06-18 03:13:43 +02:00
|
|
|
'descr' => $descr
|
|
|
|
));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('app_url',$GLOBALS['egw']->link('/' . $cats_app . '/index.php','cat_id=' . $cat['id']));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
if ($cats_level || ($level == 0))
|
|
|
|
{
|
2004-05-26 09:25:29 +02:00
|
|
|
if ($cat['owner'] == $this->account || $cat['app_name'] == 'phpgw')
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2004-05-26 09:25:29 +02:00
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.edit';
|
|
|
|
$link_data['cat_parent'] = $cat['id'];
|
|
|
|
unset($link_data['cat_id']);
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('add_sub',$GLOBALS['egw']->link('/index.php',$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_sub_entry',lang('Add sub'));
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('add_sub','');
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_sub_entry',' ');
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
$link_data['cat_id'] = $cat['id'];
|
|
|
|
if ($cat['owner'] == $this->account && $cat['app_name'] != 'phpgw')
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.edit';
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('edit',$GLOBALS['egw']->link('/index.php',$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_edit_entry',lang('Edit'));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.delete';
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('delete',$GLOBALS['egw']->link('/index.php',$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_delete_entry',lang('Delete'));
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('edit','');
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_edit_entry',' ');
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('delete','');
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_delete_entry',' ');
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->fp('list','cat_list',True);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2004-05-26 09:25:29 +02:00
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.edit';
|
|
|
|
unset($link_data['cat_id']);
|
|
|
|
unset($link_data['cat_parent']);
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('add_action',$GLOBALS['egw']->link('/index.php',$link_data));
|
2002-01-12 05:09:56 +01:00
|
|
|
$this->save_sessiondata($cats_app);
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->pfp('out','cat_list_t',True);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function edit()
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$cats_app = get_var('cats_app',array('GET','POST'));
|
|
|
|
$extra = get_var('extra',array('GET','POST'));
|
|
|
|
$global_cats = get_var('global_cats',array('GET','POST'));
|
|
|
|
$cats_level = get_var('cats_level',array('GET','POST'));
|
|
|
|
$cat_id = get_var('cat_id',array('GET','POST'));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
$link_data = array
|
|
|
|
(
|
2003-08-28 16:31:11 +02:00
|
|
|
'menuaction' => 'preferences.uicategories.index',
|
|
|
|
'cats_app' => $cats_app,
|
|
|
|
'extra' => $extra,
|
|
|
|
'global_cats' => $global_cats,
|
|
|
|
'cats_level' => $cats_level,
|
|
|
|
'cat_id' => $cat_id
|
2002-01-12 05:09:56 +01:00
|
|
|
);
|
2007-09-16 08:51:13 +02:00
|
|
|
if (!preg_match('/^(#[0-9a-f]+|[a-z]+)?$/i',$_POST['cat_data']['color'])) unset($_POST['cat_data']['color']);
|
|
|
|
if (!preg_match('/^[-_\.a-z0-9]+\.(png|gif|jpe?g)$/i',$_POST['cat_data']['icon'])) unset($_POST['cat_data']['icon']);
|
2003-08-28 16:31:11 +02:00
|
|
|
$new_parent = $_POST['new_parent'];
|
|
|
|
$cat_parent = $_POST['cat_parent'];
|
|
|
|
$cat_name = $_POST['cat_name'];
|
|
|
|
$cat_description = $_POST['cat_description'];
|
|
|
|
$cat_data = $_POST['cat_data'];
|
|
|
|
$cat_access = $_POST['cat_access'];
|
|
|
|
$old_parent = $_POST['old_parent'];
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_file(array('form' => 'category_form.tpl'));
|
|
|
|
$GLOBALS['egw']->template->set_block('form','data_row','row');
|
|
|
|
$GLOBALS['egw']->template->set_block('form','add','addhandle');
|
|
|
|
$GLOBALS['egw']->template->set_block('form','edit','edithandle');
|
2003-08-28 16:31:11 +02:00
|
|
|
|
|
|
|
$this->set_langs();
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('cancel_url',$GLOBALS['egw']->link('/index.php',$link_data));
|
2003-08-28 16:31:11 +02:00
|
|
|
|
|
|
|
if ($new_parent)
|
|
|
|
{
|
|
|
|
$cat_parent = $new_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$global_cats)
|
|
|
|
{
|
|
|
|
$global_cats = False;
|
|
|
|
}
|
2003-04-20 22:47:50 +02:00
|
|
|
|
2003-06-25 00:33:40 +02:00
|
|
|
if ($_POST['save'])
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$values = array
|
|
|
|
(
|
2004-05-26 09:25:29 +02:00
|
|
|
'id' => (int)$cat_id,
|
2003-08-28 16:31:11 +02:00
|
|
|
'parent' => $cat_parent,
|
|
|
|
'descr' => $cat_description,
|
|
|
|
'name' => $cat_name,
|
|
|
|
'access' => $cat_access,
|
2004-05-26 09:25:29 +02:00
|
|
|
'data' => serialize($cat_data),
|
2003-08-28 16:31:11 +02:00
|
|
|
);
|
2004-05-26 09:25:29 +02:00
|
|
|
if ((int)$cat_id)
|
|
|
|
{
|
|
|
|
$values['id'] = (int)$cat_id;
|
|
|
|
$values['old_parent'] = $old_parent;
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
|
|
|
$error = $this->bo->check_values($values);
|
|
|
|
if (is_array($error))
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('message',$GLOBALS['egw']->common->error_list($error));
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
else
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$cat_id = $this->bo->save_cat($values);
|
2003-08-30 12:26:20 +02:00
|
|
|
return $this->index();
|
2005-07-09 21:07:16 +02:00
|
|
|
//$GLOBALS['egw']->template->set_var('message',lang('Category %1 has been updated !',$cat_name));
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
if ($cat_id)
|
|
|
|
{
|
|
|
|
list($cat) = $this->bo->cats->return_single($cat_id);
|
|
|
|
$cat['data'] = unserialize($cat['data']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cat = array();
|
|
|
|
$cat['parent'] = $_GET['cat_parent'];
|
|
|
|
}
|
|
|
|
// update the old calendar color format, color was added to the description
|
|
|
|
if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches))
|
|
|
|
{
|
|
|
|
$cat['data']['color'] = $matches[1];
|
|
|
|
$cat['description'] = str_replace($matches[1],'',$cat['description']);
|
|
|
|
}
|
2002-09-08 22:40:12 +02:00
|
|
|
|
2002-06-18 03:13:43 +02:00
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.edit';
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('actionurl',$GLOBALS['egw']->link('/index.php',$link_data));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('cat_name',$GLOBALS['egw']->strip_html($cat['name']));
|
|
|
|
$GLOBALS['egw']->template->set_var('cat_description',$GLOBALS['egw']->strip_html($cat['description']));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
$hidden_vars = '<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">';
|
2002-09-08 22:40:12 +02:00
|
|
|
|
2002-01-14 00:54:46 +01:00
|
|
|
if ($cats_level)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2002-01-14 00:54:46 +01:00
|
|
|
$type = 'all';
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-01-14 00:54:46 +01:00
|
|
|
$type = 'mains';
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2007-11-27 18:14:54 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('category_list',$this->bo->cats->formatted_list(array(
|
2004-05-26 09:25:29 +02:00
|
|
|
'type' => $type,'selected' => $cat['parent'],
|
2003-10-18 12:30:02 +02:00
|
|
|
'globals' => $global_cats, 'self' => $cat_id
|
|
|
|
)));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('access','<input type="checkbox" name="cat_access" value="True"'
|
2004-05-26 09:25:29 +02:00
|
|
|
. ($cat['access'] == 'private' ? ' checked' : '') . '>');
|
2002-01-13 23:35:54 +01:00
|
|
|
|
2008-03-25 17:43:57 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('color',html::inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color')));
|
2002-01-13 23:35:54 +01:00
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
$options = '<option value=""'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
|
|
|
|
foreach ($this->icons as $icon)
|
|
|
|
{
|
|
|
|
$options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'.
|
|
|
|
ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon))."</option>\n";
|
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n");
|
|
|
|
$GLOBALS['egw']->template->set_var('icon','<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
|
2004-05-26 09:25:29 +02:00
|
|
|
|
|
|
|
$already_done = array('icon','color');
|
|
|
|
|
|
|
|
if ($extra)
|
|
|
|
{
|
|
|
|
foreach(explode(',',$extra) as $i => $name)
|
2002-01-13 23:35:54 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('class',($i & 1) ? 'row_on' : 'row_off');
|
|
|
|
$GLOBALS['egw']->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">');
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_data',lang($name));
|
|
|
|
$GLOBALS['egw']->template->fp('row','data_row',True);
|
2004-05-26 09:25:29 +02:00
|
|
|
$already_done[] = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// preserv everything in the data array, not already shown via extra
|
|
|
|
if (is_array($cat['data']))
|
|
|
|
{
|
|
|
|
foreach($cat['data'] as $name => $value)
|
|
|
|
{
|
|
|
|
if (!in_array($name,$already_done))
|
|
|
|
{
|
|
|
|
$hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">';
|
|
|
|
}
|
2002-01-13 23:35:54 +01:00
|
|
|
}
|
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('hidden_vars',$hidden_vars);
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2004-05-26 09:25:29 +02:00
|
|
|
if ($cat['owner'] == $this->account)
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2002-06-18 03:13:43 +02:00
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.delete';
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('delete','<form method="POST" action="' . $GLOBALS['egw']->link('/index.php',$link_data)
|
2003-08-28 16:31:11 +02:00
|
|
|
. '"><input type="submit" value="' . lang('Delete') .'"></form>');
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('delete',' ');
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang($cat_id ? 'Edit %1 category for' : 'Add %1 category for',
|
|
|
|
$GLOBALS['egw_info']['apps'][$cats_app]['title']).': '.$this->user;
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->common->egw_header();
|
2004-05-26 09:25:29 +02:00
|
|
|
echo parse_navbar();
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('edithandle','');
|
|
|
|
$GLOBALS['egw']->template->set_var('addhandle','');
|
|
|
|
$GLOBALS['egw']->template->pfp('out','form');
|
|
|
|
$GLOBALS['egw']->template->pfp('edithandle','edit');
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete()
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$cats_app = get_var('cats_app',array('GET','POST'));
|
|
|
|
$extra = get_var('extra',array('GET','POST'));
|
|
|
|
$global_cats = get_var('global_cats',array('GET','POST'));
|
|
|
|
$cats_level = get_var('cats_level',array('GET','POST'));
|
|
|
|
$cat_id = get_var('cat_id',array('GET','POST'));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
|
|
|
$link_data = array
|
|
|
|
(
|
2002-06-18 03:13:43 +02:00
|
|
|
'menuaction' => 'preferences.uicategories.index',
|
|
|
|
'cats_app' => $cats_app,
|
|
|
|
'extra' => $extra,
|
|
|
|
'global_cats' => $global_cats,
|
2003-08-28 16:31:11 +02:00
|
|
|
'cats_level' => $cats_level,
|
|
|
|
'cat_id' => $cat_id
|
2002-01-12 05:09:56 +01:00
|
|
|
);
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!$cat_id || $_POST['cancel'])
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->redirect_link('/index.php',$link_data);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:33:40 +02:00
|
|
|
if ($_POST['confirm'])
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2003-06-25 00:33:40 +02:00
|
|
|
if ($_POST['subs'])
|
2002-01-12 05:09:56 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->bo->delete($cat_id,True);
|
2002-10-12 02:48:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-25 07:33:21 +01:00
|
|
|
$this->bo->delete($cat_id,False);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->redirect_link('/index.php',$link_data);
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_file(array('category_delete' => 'delete.tpl'));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Delete Categories');
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->common->egw_header();
|
2003-08-28 16:31:11 +02:00
|
|
|
echo parse_navbar();
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('deleteheader',lang('Are you sure you want to delete this category ?'));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$exists = $this->bo->exists(array
|
|
|
|
(
|
|
|
|
'type' => 'subs',
|
|
|
|
'cat_name' => '',
|
|
|
|
'cat_id' => $cat_id
|
|
|
|
));
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($exists)
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_subs',lang('Do you also want to delete all subcategories ?'));
|
|
|
|
$GLOBALS['egw']->template->set_var('subs','<input type="checkbox" name="subs" value="True">');
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_subs','');
|
|
|
|
$GLOBALS['egw']->template->set_var('subs', '');
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2002-01-12 05:09:56 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_no',lang('No'));
|
2003-08-28 16:31:11 +02:00
|
|
|
$link_data['menuaction'] = 'preferences.uicategories.delete';
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('action_url',$GLOBALS['egw']->link('/index.php',$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_yes',lang('Yes'));
|
|
|
|
$GLOBALS['egw']->template->pfp('out','category_delete');
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2002-01-12 05:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|