diff --git a/addressbook/addcategory.php b/addressbook/addcategory.php
index 4d388aaf0c..3b23398a5b 100644
--- a/addressbook/addcategory.php
+++ b/addressbook/addcategory.php
@@ -24,8 +24,11 @@
if ($submit) {
$errorcount = 0;
- $exists = $c->exists('main',$cat_name);
- if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); }
+ $exists_main = $c->exists('main',$cat_name);
+ if ($exists_main == True) { $error[$errorcount++] = lang('That main category name has been used already !'); }
+
+ $exists_sub = $c->exists('subs',$cat_name);
+ if ($exists_subs == True) { $error[$errorcount++] = lang('That sub category name has been used already !'); }
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
@@ -53,8 +56,8 @@
$t->set_var('lang_choose',lang('Choose the category'));
$t->set_var('lang_select_parent',lang('Select parent category'));
$t->set_var('lang_access',lang('Private'));
- if ($access) { $t->set_var('access', ''); }
- else { $t->set_var('access', 'set_var('access', ''); }
+ else { $t->set_var('access', 'set_var('lang_name',lang('Category name'));
$t->set_var('lang_descr',lang('Category description'));
$t->set_var('cat_name',$cat_name);
diff --git a/addressbook/editcategory.php b/addressbook/editcategory.php
index 9de831bdd2..183177a131 100644
--- a/addressbook/editcategory.php
+++ b/addressbook/editcategory.php
@@ -30,15 +30,21 @@
$errorcount = 0;
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
$phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='"
- . $phpgw_info["flags"]["currentapp"] ."'");
+ . $phpgw_info["flags"]["currentapp"] ."' AND cat_parent='0'");
$phpgw->db->next_record();
- if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That category name has been used already !'); }
+ if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That main category name has been used already !'); }
+
+ $phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='"
+ . $phpgw_info["flags"]["currentapp"] ."' AND cat_parent != '0'");
+ $phpgw->db->next_record();
+ if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That sub category name has been used already !'); }
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
+ if ($access) { $cat_access = 'private'; }
+ else { $cat_access = 'public'; }
-
- if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data); }
+ if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); }
}
if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }
@@ -47,7 +53,8 @@
$cats = $c->return_single($cat_id);
- $t->set_var('category_list',$c->formated_list('select','all',$cat_parent,'False'));
+ $cat_parent = $cats[0]['parent'];
+ $t->set_var('category_list',$c->formated_list('select','all',$cat_parent,'False'));
$t->set_var('font',$font);
$t->set_var('user_name',$phpgw_info["user"]["fullname"]);
$t->set_var('title_categories',lang('Edit category for'));
@@ -61,8 +68,8 @@
$t->set_var('lang_descr',lang('Category description'));
$t->set_var('lang_select_parent',lang('Select parent category'));
$t->set_var('lang_access',lang('Private'));
- if ($access) { $t->set_var('access', ''); }
- else { $t->set_var('access', 'set_var('access', ''); }
+ else { $t->set_var('access', 'set_var('lang_edit',lang('Edit'));
$t->set_var('lang_delete',lang('Delete'));
- $t->set_var('lang_done',lang('Done'));
+ $t->set_var('lang_done',lang('Done'));
$t->set_var('edithandle','');
$t->set_var('addhandle','');
diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php
index 8e3013ea19..bc96d31077 100644
--- a/phpgwapi/inc/class.categories.inc.php
+++ b/phpgwapi/inc/class.categories.inc.php
@@ -34,6 +34,7 @@
var $cats;
var $db;
var $total_records;
+ var $grants;
/*!
@function filter
@abstract ?
@@ -61,7 +62,7 @@
{
case 'app': $w = " cat_appname='" . $this->app_name . "'"; break;
case 'subs': $w = " cat_parent != '0'"; break;
- case 'mains': $w = " cat_parent = '0'"; break;
+ case 'mains': $w = " cat_parent = '0'"; break;
default: return False;
}
@@ -108,15 +109,30 @@
$ordermethod = " order by cat_parent asc";
}
+ if (is_array($this->grants))
+ {
+ $grants = $this->grants;
+ while(list($user) = each($grants))
+ {
+ $public_user_list[] = $user;
+ }
+ reset($public_user_list);
+ $grant_cats = " (cat_owner='" . $this->account_id . "' OR cat_access='public' OR cat_owner in(" . implode(',',$public_user_list) . ")) ";
+ }
+ else
+ {
+ $grant_cats = " (cat_owner='" . $this->account_id . "' OR cat_access='public') ";
+ }
+
if ($query)
{
- $sql = "select * from phpgw_categories where cat_appname='" . $this->app_name . "' $public_cats and "
- . "(cat_name like '%$query%' or cat_description like '%$query%') $filter $ordermethod";
+ $sql = "SELECT * from phpgw_categories WHERE cat_appname='" . $this->app_name . "' AND "
+ . " $grant_cats $public_cats AND (cat_name like '%$query%' OR cat_description like '%$query%') $filter $ordermethod";
}
else
{
- $sql = "select * from phpgw_categories where cat_appname='" . $this->app_name . "'"
- . "$public_cats $filter $ordermethod";
+ $sql = "SELECT * from phpgw_categories WHERE cat_appname='" . $this->app_name . "' AND "
+ . " $grant_cats $public_cats $filter $ordermethod";
}
$this->db2->query($sql,__LINE__,__FILE__);
@@ -183,6 +199,7 @@
$this->app_name = $app_name;
$this->db = $phpgw->db;
$this->total_records = $this->db->num_rows();
+ $this->grants = $phpgw->acl->get_grants($app_name);
$this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order,$public);
}