Index: /trunk/phpgwapi/inc/class.categories.inc.php
===================================================================
--- /trunk/phpgwapi/inc/class.categories.inc.php	(revision 2)
+++ /trunk/phpgwapi/inc/class.categories.inc.php	(revision 577)
@@ -56,5 +56,5 @@
 			$this->app_name		= $GLOBALS['phpgw']->db->db_addslashes($app_name);
 			$this->db			= $GLOBALS['phpgw']->db;
-			$this->db2			= $this->db;
+			$this->db2			= $this->db;			
 			$this->grants		= $GLOBALS['phpgw']->acl->get_grants($app_name);
 		}
@@ -137,22 +137,43 @@
 		@param $order order by
 		@param $globals True or False, includes the global egroupware categories or not
+		@param $parent_id
+		@param $lastmod integer defaults to -1
+		@param column string default to '' (All), includes the column returned.
 		@result $cats array
 		*/
 		function return_array($type,$start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '', $lastmod = -1, $column = '')
 		{
-			//casting and addslashes for security
-			$start		= (int)$start;
-			$parent_id	= (int)$parent_id;
-			$query		= $this->db->db_addslashes($query);
-			$sort		= $this->db->db_addslashes($sort);
-			$order		= $this->db->db_addslashes($order);
-
-			if ($globals)
-			{
-				$global_cats = " OR cat_appname='phpgw'";
-			}
-
-			$filter = $this->filter($type);
-
+			return $this -> return_sorted_array( $start, $limit, $query, $sort, $order, $globals, $parent_id, NULL, $lastmod, $column);
+		}
+		/*!
+		@function return_sorted_array
+		@abstract return an array populated with categories
+		@param $type string defaults to 'all'
+		@param $start ?
+		@param $limit ?
+		@param $query string defaults to ''
+		@param $sort string sort order, either defaults to 'ASC'
+		@param $order order by
+		@param $globals True or False, includes the global egroupware categories or not
+		@param $parent_id string defaults to '', includes the parent category ID
+		@param $group_id integer defaults to NULL, includes the gidNumber
+		@param $lastmod integer defaults to -1
+		@param column string default to '' (All), includes the column returned.
+		@result $cats array
+		*/			
+		function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '',$group_id = NULL,$lastmod = -1, $column = '')
+		{
+			//casting and slashes for security
+			$start = (int)$start;
+			$query = $this->db->db_addslashes($query);
+			$sort  = $this->db->db_addslashes($sort);
+			$order = $this->db->db_addslashes($order);
+			$parent_id = (int)$parent_id;
+
+			if ($globals && !$group_id)
+			{
+				$global_cats = " cat_appname='phpgw'";
+			}
+			
 			if (!$sort)
 			{
@@ -160,5 +181,5 @@
 			}
 
-			if (!empty($order) && preg_match('/^[a-zA-Z_(), ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort)))
+			if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort)))
 			{
 				$ordermethod = " ORDER BY $order $sort";
@@ -166,37 +187,41 @@
 			else
 			{
-				$ordermethod = ' ORDER BY cat_main, cat_level, cat_name ASC';
-			}
-
-			if ($this->account_id == '-1')
-			{
-				$grant_cats = ' cat_owner=-1 ';
-			}
-			else
-			{
+				$ordermethod = ' ORDER BY cat_name ASC';
+			}
+									
+			if($group_id){
+				$grant_cats .= " cat_owner='".$group_id."' ";
+			}
+			else if ($this->account_id != '-1'){
+				$grants = $this->grants;
+				$groups = $GLOBALS['phpgw']->accounts->membership();
+			
 				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_owner=-1 OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ')) ';
+					
+					foreach($grants as $idx => $user){												
+						$public_user_list[$user] = $user;
+					}
+					if(is_array($groups)){
+						foreach($groups as $idx => $group) {
+							$public_user_list[$group['account_id']] = $group['account_id'];
+						}
+					}
+					@reset($public_user_list);
+					$grant_cats = " (cat_owner='" . $this->account_id . "' ".(is_array($public_user_list) ? "OR (cat_owner in(" . implode(',',$public_user_list) . ")  AND cat_access='public')" : "").") ";
+					
 				}
 				else
 				{
-					$grant_cats = ' cat_owner=' . $this->account_id . ' OR cat_owner=-1 ';
-				}
-			}
-
-			if ($parent_id > 0)
-			{
-				$parent_filter = ' AND cat_parent=' . $parent_id;
-			}
+					$grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' ";
+				}
+			}
+			
+
+			$parent_select = ' AND cat_parent=' . $parent_id;
 
 			if ($query)
 			{
-				$querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%') ";
+				$querymethod = " AND (cat_name ILIKE '%$query%' OR cat_description ILIKE '%$query%') ";
 			}
 
@@ -228,109 +253,9 @@
 			}
 
-			$sql = "SELECT $table_column FROM phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ')'
-				. $parent_filter . $querymethod . $filter;
-
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
-
-			if ($limit)
-			{
-				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
-			}
-			else
-			{
-				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
-			}
-
-			while ($this->db->next_record())
-			{
-				if ($column)
-				{
-					$cats[] = array
-					(
-						$column => $this->db->f(0)
-					);
-				}
-				else
-				{
-					$cats[] = array
-					(
-						'id'			=> $this->db->f('cat_id'),
-						'owner'			=> $this->db->f('cat_owner'),
-						'access'		=> $this->db->f('cat_access'),
-						'app_name'		=> $this->db->f('cat_appname'),
-						'main'			=> $this->db->f('cat_main'),
-						'level'			=> $this->db->f('cat_level'),
-						'parent'		=> $this->db->f('cat_parent'),
-						'name'			=> $this->db->f('cat_name'),
-						'description'	=> $this->db->f('cat_description'),
-						'data'			=> $this->db->f('cat_data'),
-						'last_mod'		=> $this->db->f('last_mod')
-					);
-				}
-			}
-			return $cats;
-		}
-
-		function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '')
-		{
-			//casting and slashes for security
-			$start = (int)$start;
-			$query = $this->db->db_addslashes($query);
-			$sort  = $this->db->db_addslashes($sort);
-			$order = $this->db->db_addslashes($order);
-			$parent_id = (int)$parent_id;
-
-			if ($globals)
-			{
-				$global_cats = " OR cat_appname='phpgw'";
-			}
-
-			if (!$sort)
-			{
-				$sort = 'ASC';
-			}
-
-			if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/')))
-			{
-				$ordermethod = " ORDER BY $order $sort";
-			}
-			else
-			{
-				$ordermethod = ' ORDER BY cat_name ASC';
-			}
-
-			if ($this->account_id == '-1')
-			{
-				$grant_cats = " cat_owner='-1' ";
-			}
-			else
-			{
-				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_owner='-1' OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ")) ";
-				}
-				else
-				{
-					$grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' ";
-				}
-			}
-
-			$parent_select = ' AND cat_parent=' . $parent_id;
-
-			if ($query)
-			{
-				$querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%') ";
-			}
-
-			$sql = "SELECT * FROM phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ")"
-					. $querymethod;
-
+
+			$sql = "SELECT".$table_column."FROM phpgw_categories WHERE (cat_appname='" . $this->app_name. "' ".
+					($grant_cats ? " AND".$grant_cats : "") .($global_cats ? " OR".$global_cats: "").
+					")".$querymethod;						
+			
 			$this->db2->query($sql . $parent_select,__LINE__,__FILE__);
 			$total = $this->db2->num_rows();
@@ -350,4 +275,9 @@
 				$cats[$i]['id']          = (int)$this->db->f('cat_id');
 				$cats[$i]['owner']       = (int)$this->db->f('cat_owner');
+				if($cats[$i]['owner'] > 0){
+				// 	Load Name Group.
+					$group = $this->get_group($cats[$i]['owner']);
+					$cats[$i]['owner'] = $group['name'];
+				}
 				$cats[$i]['access']      = $this->db->f('cat_access');
 				$cats[$i]['app_name']    = $this->db->f('cat_appname');
@@ -358,4 +288,5 @@
 				$cats[$i]['description'] = $this->db->f('cat_description');
 				$cats[$i]['data']        = $this->db->f('cat_data');
+					
 				$i++;
 			}
@@ -365,17 +296,6 @@
 			{
 				$sub_select = ' AND cat_parent=' . $cats[$i]['id'] . ' AND cat_level=' . ($cats[$i]['level']+1);
-
-				/*$this->db2->query($sql . $sub_select,__LINE__,__FILE__);
-				$total_subs += $this->db2->num_rows();
-
-				if ($limit)
-				{
-					$this->db->limit_query($sql . $sub_select . $ordermethod,$start,__LINE__,__FILE__);
-				}
-				else
-				{*/
-					$this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__);
-					$total += $this->db->num_rows();
-				//}
+				$this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__);
+				$total += $this->db->num_rows();
 
 				$subcats = array();
@@ -429,5 +349,4 @@
 		{
 			$this->db->query('SELECT * FROM phpgw_categories WHERE cat_id=' . (int)$id,__LINE__,__FILE__);
-
 			if ($this->db->next_record())
 			{
@@ -442,4 +361,10 @@
 				$cats[0]['description'] = $this->db->f('cat_description');
 				$cats[0]['data']        = $this->db->f('cat_data');
+				if($cats[0]['owner'] > 0){
+				// 	Load Group.
+					$group = $this->get_group($cats[0]['owner']);
+					$cats[0]['id_group']    = $group['id'];
+					$cats[0]['name_group']  = $group['name'];					
+				}				
 			}
 			return $cats;
@@ -459,4 +384,11 @@
 			return $this->formated_list($format,$type,$selected,$globals,$site_link);
 		}
+		function get_group($id)
+		{
+			if (!IsSet($id))
+				return "";
+			return array("id" => $id, "name" => $GLOBALS['phpgw']->accounts->id2name($id));
+		}
+
 		function formated_list($format,$type='',$selected = '',$globals = False,$site_link = 'site')
 		{
@@ -591,7 +523,6 @@
 				$id_val = $values['id'] . ',';
 			}
-
 			$this->db->query('INSERT INTO phpgw_categories (' . $id_col . 'cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,cat_data,'
-				. 'cat_main,cat_level, last_mod) VALUES (' . $id_val . (int)$values['parent'] . ',' . $this->account_id . ",'" . $values['access']
+				. 'cat_main,cat_level, last_mod) VALUES (' . $id_val . (int)$values['parent'] . ',' . ($values['group']!= 0 ? $values['group'] : $this->account_id) . ",'" . $values['access']
 				. "','" . $this->app_name . "','" . $values['name'] . "','" . $values['descr'] . "','" . $values['data']
 				. "'," . (int)$values['main'] . ',' . (int)$values['level'] . ',' . time() . ')',__LINE__,__FILE__);
@@ -687,5 +618,8 @@
 			$values['id']     = (int)$values['id'];
 			$values['parent'] = (int)$values['parent'];
-
+			$values['owner'] = (int)$values['group'];
+			if($values['owner']){
+				$owner = "cat_owner = ".$values['owner'].",";
+			}
 			if (isset($values['old_parent']) && (int)$values['old_parent'] != $values['parent'])
 			{
@@ -710,5 +644,5 @@
 			$values['name'] = $this->db->db_addslashes($values['name']);
 
-			$sql = "UPDATE phpgw_categories SET cat_name='" . $values['name'] . "', cat_description='" . $values['descr']
+			$sql = "UPDATE phpgw_categories SET $owner cat_name='" . $values['name'] . "', cat_description='" . $values['descr']
 				. "', cat_data='" . $values['data'] . "', cat_parent=" . $values['parent'] . ", cat_access='"
 				. $values['access'] . "', cat_main=" . $values['main'] . ', cat_level=' . $values['level'] . ',last_mod=' . time()
Index: /trunk/admin/inc/class.uicategories.inc.php
===================================================================
--- /trunk/admin/inc/class.uicategories.inc.php	(revision 2)
+++ /trunk/admin/inc/class.uicategories.inc.php	(revision 577)
@@ -69,4 +69,5 @@
 
 			$dir = dir(PHPGW_SERVER_ROOT.'/phpgwapi/images');
+
 			while($file = $dir->read())
 			{
@@ -115,4 +116,6 @@
 			$this->template->set_var('lang_save',lang('Save'));
 			$this->template->set_var('lang_search',lang('Search'));
+			$this->template->set_var('lang_group_name',lang('group name'));
+			$this->template->set_var('lang_cat_name',lang('category name'));
 			$this->template->set_var('lang_sub',lang('Add sub'));
 			$this->template->set_var('lang_icon',lang('icon'));
@@ -129,4 +132,17 @@
 			$this->template->set_var('lang_color',lang('Color'));
 			$this->template->set_var('lang_icon',lang('Icon'));
+			$this->template->set_var('lang_Loading',lang("Loading"));
+			$this->template->set_var('lang_Searching', lang("search groups"));				
+			$this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));													
+			$this->template->set_var('lang_Search_for', lang("Search Groups"));									
+			$this->template->set_var('lang_cat_all', lang("All"));
+			$this->template->set_var('lang_permission', lang("Permission"));
+			$this->template->set_var('lang_Loading',lang("Loading"));
+			$this->template->set_var('lang_Searching', lang("Search Groups"));
+			$this->template->set_var('lang_Owner', lang("Owner (User/Group)"));
+			$this->template->set_var('lang_Add', lang("Add"));
+			$this->template->set_var('lang_Remove', lang("Remove"));			
+			$this->template->set_var('lang_Search_for', lang("Search Groups"));
+			$this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));				
 		}
 
@@ -148,5 +164,6 @@
 				$GLOBALS['phpgw']->redirect_link('/admin/index.php');
 			}
-
+	
+			
 			$this->template->set_file(array('cat_list_t' => 'listcats.tpl'));
 			$this->template->set_block('cat_list_t','cat_list','list');
@@ -164,5 +181,26 @@
 			echo parse_navbar();
 			$this->set_langs();
+
 			$this->template->set_var('query',$this->query);
+			
+			// if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX. 
+			if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
+				$this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];							
+				$module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
+				if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){								
+					$ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
+					$_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];				
+					$_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
+					$_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
+					$_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
+					// Carrega todos scripts necessarios				
+					$scripts =	"<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
+								"<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".											
+								"<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";
+					// Fim
+				}
+				$this->template->set_var('scripts',$scripts);			
+			}
+			$this->template->set_var('template_set',$this->template_dir);
 
 			$link_data['menuaction'] = 'admin.uicategories.index';
@@ -173,6 +211,11 @@
 				$start = 0;
 			}
-
-			$cats = $this->bo->get_list();
+			list($idgroup,$namegroup) = explode('.', @$_POST['group']);			 
+			if($this-> query || $namegroup)
+				$result_search = lang("result")." :: ".lang("about")." <b>'".($this-> query ? $this-> query : $namegroup)."'</b> :: ";
+			else
+				$this->template->set_var('type_search_'.($_POST['typesearch'] ? $_POST['typesearch'] : 'a').'_checked', "checked");						
+		 	$cats = $this->bo->get_list($idgroup);
+
 			if (!is_array($cats)) $cats = array();
 
@@ -182,8 +225,8 @@
 			$this->template->set_var('right',$right);
 
-			$this->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));
-
-			$this->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data));
-			$this->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data));
+			$this->template->set_var('lang_showing',$result_search.$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));			
+
+			$this->template->set_var('sort_name', !$_POST['typesearch'] ? $this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data) : lang('Name'));
+			$this->template->set_var('sort_description', !$_POST['typesearch'] ? $this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data) : lang('Description'));
 
 			foreach($cats as $cat)
@@ -268,5 +311,5 @@
 				}
 				else
-				{
+				{					
 					$this->template->set_var('edit','');
 				}
@@ -283,7 +326,9 @@
 
 				$data = unserialize($cat['data']);
-				$icon = $data['icon'];
+				$icon = $data['icon'];				
+				$permission = ($cat['owner'] == '-1' ? lang("all"): $cat['owner']);
+				$this->template->set_var('permission', $permission);
 				$dir_img = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'phpgwapi' . SEP . 'images' . SEP;
-				$this->template->set_var('icon', "<img src='". $dir_img . $icon  ."'>");
+				$this->template->set_var('icon', !$icon ? lang("None") : "<img src='". $dir_img . $icon  ."'>");
 
 				$this->template->fp('list','cat_list',True);
@@ -303,7 +348,8 @@
 			$cat_parent			= (int)$_POST['cat_parent'];
 			$cat_name			= $_POST['cat_name'];
-			$cat_description	= $_POST['cat_description'];
+			$cat_description		= $_POST['cat_description'];
 			$cat_data			= $_POST['cat_data'];
 			$old_parent			= (int)$_POST['old_parent'];
+			$cat_group			= $_POST['idgroup'];
 			
 			if ($new_parent)
@@ -328,4 +374,5 @@
 			}
 
+			
 			if ($_POST['save'])
 			{
@@ -337,4 +384,5 @@
 					'descr'			=> $cat_description,
 					'name'			=> $cat_name,
+					'group'			=> $cat_group,
 					'access'		=> 'public',
 					'data'			=> $data
@@ -360,4 +408,24 @@
 
 			$this->set_langs();
+		// if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX. 
+		if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
+			$this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];							
+			$module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
+			if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){								
+				$ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
+				$_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];				
+				$_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
+				$_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
+				$_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
+				// Carrega todos scripts necessarios				
+				$scripts =	"<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
+							"<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".											
+							"<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";				
+				// Fim								
+				$this->template->set_var('scripts',$scripts);
+				$this->template->set_var('template_set', $this->template_dir);
+			}
+		}
+		// FIM if.
 
 			$this->template->set_file(array('form' => 'category_form.tpl'));
@@ -368,4 +436,5 @@
 				$cat['data'] = unserialize($cat['data']);
 			}
+			
 			else
 			{
@@ -373,4 +442,5 @@
 				$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))
@@ -381,5 +451,6 @@
 
 			$hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n" .
-				'<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">' . "\n";
+				'<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">' . "\n".
+				'<input type="hidden" id="idgroup" name="idgroup" value="' . $cat['id_group'] . '">' . "\n";
 
 			$link_data['menuaction']	= 'admin.uicategories.edit';
@@ -401,5 +472,6 @@
 			$this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description']));
 			$this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id)));
-
+			$this->template->set_var('category_namegroup',$GLOBALS['phpgw']->strip_html($cat['name_group']));
+			$this->template->set_var('bt_rem_id_group_visibility',$cat['name_group'] ? "visible" : "hidden");
 			if (!is_object($GLOBALS['phpgw']->html))
 			{
@@ -407,13 +479,16 @@
 			}
 			$this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color')));
-
-			$options = '<option value=""'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
+			$options = '';
+			//$options = '<option value="aanone.gif"'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
 			foreach ($this->icons as $icon)
 			{
+				if(!$cat['data']['icon']){
+					$cat['data']['icon'] = "aanone.gif";
+				}
 				$options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'.
-					ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon))."</option>\n";
+					ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon == 'aanone.gif' ? lang('none') : $icon))."</option>\n";
 			}
 			$this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n");
-			$this->template->set_var('icon','<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
+			$this->template->set_var('icon',  '<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
 
 			$already_done = array('icon','color');
Index: /trunk/admin/inc/class.bocategories.inc.php
===================================================================
--- /trunk/admin/inc/class.bocategories.inc.php	(revision 2)
+++ /trunk/admin/inc/class.bocategories.inc.php	(revision 577)
@@ -96,8 +96,8 @@
 		}
 
-		function get_list()
+		function get_list($id_group)
 		{
-			if($this->debug) { echo '<br>querying: "' . $this->query . '"'; }
-			return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,True);
+			if($this->debug) { echo '<br>querying: "' . $this->query . '"'; }			
+			return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,True,'',$id_group);
 		}
 
Index: /trunk/admin/templates/default/listcats.tpl
===================================================================
--- /trunk/admin/templates/default/listcats.tpl	(revision 2)
+++ /trunk/admin/templates/default/listcats.tpl	(revision 577)
@@ -1,7 +1,25 @@
-
 	<center>
-		<table border="0" cellspacing="2" cellpadding="2">
+		<table border="0" cellspacing="1" cellpadding="2">
+<!-- BEGIN search -->
 			<tr>
-				<td colspan="5" align="left">
+				<td colspan="5" align="left" valign="top"><form name="form1" method="post" onSubmit="return on_submit()" action="{action_nurl}">&nbsp;					
+					<input type="radio" onclick="javascript:changeElement();" name="typesearch" value="g" {type_search_g_checked}/>{lang_group_name}&nbsp;
+					<input type="radio" onclick="javascript:changeElement();" name="typesearch" value="c" {type_search_c_checked}/>{lang_cat_name}&nbsp;
+					<input type="radio" onclick="javascript:changeElement();" name="typesearch" value="a" {type_search_a_checked}/>{lang_cat_all}<br>
+					<div id="filterByGroup" style="display:none"><br>
+				    	{lang_Search_for}&nbsp;<input type="text" id="search_group" size=30 autocomplete="off" onkeyup="javascript:search_object(this,'cal_span_searching','groupsfound','g')"/><br>
+			            &nbsp;<font color="red"><span id="cal_span_searching">&nbsp;</span></font><br/>
+			            <input type="hidden" id="group" name="group"/>
+			            <select id="groupsfound" style="width: 300px" size="4"></select>&nbsp;<input type="submit" value="{lang_search}">
+					</div>
+					<div id="filterByName" style="display:none"><br>
+					<input id="query" type="text" name="query" value="">&nbsp;<input type="submit" value="{lang_search}">
+					</form>
+				</td>
+			</tr>
+<!-- END search -->
+		
+			<tr>
+				<td colspan="6" align="left">
 					<table border="0" width="100%">
 						<tr>
@@ -13,15 +31,9 @@
 				</td>
 			</tr>
-<!-- BEGIN search -->
-			<tr>
-				<td colspan="5" align="right">
-					<form method="post" action="{action_nurl}">
-					<input type="text" name="query">&nbsp;<input type="submit" name="search" value="{lang_search}"></form></td>
-			</tr>
-<!-- END search -->
 			<tr class="th">
 				<td width="20%">{sort_name}</td>
 				<td width="32%">{sort_description}</td>
-				<td>{lang_icon}</td>
+				<td width="1%" align="center">{lang_icon}</td>
+				<td width="8%" align="center">{lang_permission}</td>
 				<td width="8%" align="center">{lang_sub}</td>
 				<td width="8%" align="center">{lang_edit}</td>
@@ -34,5 +46,6 @@
 				<td>{name}</td>
 				<td>{descr}</td>
-				<td>{icon}</td>
+				<td align="center">{icon}</td>
+				<td align="center">{permission}</td>
 				<td align="center">{add_sub}</a></td>
 				<td align="center">{edit}</a></td>
@@ -53,2 +66,33 @@
 		</table>
 	</center>
+{scripts}
+<input type="hidden" id="txt_loading" value="{lang_Loading}">
+<input type="hidden" id="txt_searching" value="{lang_Searching}">
+<input type="hidden" id="txt_typemoreletters" value="{lang_typemoreletters}">
+<script language="JavaScript" type="text/javascript">
+	function on_submit(){
+		var select_group = document.getElementById("groupsfound");
+		if(document.getElementById("query").value == "" && select_group.value == ""){
+			return false;
+		}
+		else if(select_group.options.length == 0)
+			return true;			
+		for(j in select_group.options){
+			if(select_group.selectedIndex == j)
+				document.getElementById("group").value =  select_group.options[j].value+"."+select_group.options[j].text;
+		}
+		return true;		
+	}
+	function changeElement(){
+		var types =	document.form1.typesearch;
+		for(j in types){
+			if(types[j].checked){
+				if(types[j].value == 'a'){				
+					location.href = location.href.toString();
+				}
+				document.getElementById('filterByGroup').style.display 	= (types[j].value == 'g' ? '' : 'none');
+				document.getElementById('filterByName').style.display	= (types[j].value == 'g' || types[j].value == 'a' ? 'none' : '');
+			}
+		}
+	}
+</script>
Index: /trunk/admin/templates/default/category_form.tpl
===================================================================
--- /trunk/admin/templates/default/category_form.tpl	(revision 2)
+++ /trunk/admin/templates/default/category_form.tpl	(revision 577)
@@ -1,4 +1,7 @@
-
 <!-- BEGIN form -->
+<input type="hidden" id="txt_loading" value="{lang_Loading}">
+<input type="hidden" id="txt_searching" value="{lang_Searching}">
+<input type="hidden" id="txt_multipleGroup" value="{lang_Groups}">
+<input type="hidden" id="txt_typemoreletters" value="{lang_typemoreletters}">
 <br>
 <center>
@@ -6,4 +9,5 @@
 <table border="0" width="80%" cellspacing="2" cellpadding="2"> 
 <form name="edit_cat" action="{actionurl}" method="POST">
+{hidden_vars}
 	<tr class="th">
 		<td colspan="2">{lang_parent}</td>
@@ -18,4 +22,17 @@
 		<td colspan="2"><textarea name="cat_description" rows="4" cols="50" wrap="virtual">{cat_description}</textarea></td>
 	</tr>
+        <tr class="row_on">
+         	<td colspan="2">{lang_Search_for}</td>
+            <td valign="center" colspan="2"><input type="text" id="search_group" size=30 autocomplete="off" onkeyup="javascript:search_object(this,'cal_span_searching','groupsfound','g')"/>
+            &nbsp;<font color="red"><span id="cal_span_searching">&nbsp;</span></font><br/>
+            <select id="groupsfound" style="width: 300px" size="4"></select>
+            <button type="button" onClick="javascript:add('groupsfound','group');"><img src="{template_set}/images/add.png" style="vertical-align: bottom;"/></button></td>
+        </tr>
+	<tr class="row_off">
+		<td colspan="2">{lang_Owner}</td>
+		<td valign="center" colspan="2"><label id="namegroup" style="font-weight:bold">{category_namegroup}</label>
+		<button valign="top" style="visibility:{bt_rem_id_group_visibility}" id="bt_rem_idgroup" type="button" onClick="javascript:remove('group');"><img src="{template_set}/images/delete.png" style="vertical-align: middle;" /></button></td>
+	</tr>
+
 	<tr class="row_on">
 		<td colspan="2">{lang_color}</td>
@@ -32,16 +49,37 @@
 	</tr>
 <!-- END data_row -->
-
 	<tr valign="bottom" height="50">
-		<td>
-			{hidden_vars}
-			<input type="submit" name="save" value="{lang_save}"></form></td>
-		<td>
-			<form method="POST" action="{cancel_url}">
-			<input type="submit" name="cancel" value="{lang_cancel}"></form></td>
+		<td><input type="submit" name="save" value="{lang_save}"></td>
+		<td><form method="POST" action="{cancel_url}"><input type="submit" name="cancel" value="{lang_cancel}"></form></td>
 		<td align="right">{delete}</td>
 	</tr>
 </table>
+</form>
 </center>
 
 <!-- END form -->
+<script language="JavaScript" type="text/javascript">
+function remove(to){
+	document.getElementById("name"+to).innerHTML = '';
+	document.getElementById("id"+to).value = '-1';
+	show_button("id"+to);
+} 
+function show_button(id){
+	document.getElementById("bt_rem_"+id).style.visibility = 
+		(document.getElementById(id).value != '-1'  ? 'visible' : 'hidden');
+}
+function add(from, to){
+	var sel_from = document.getElementById(from);
+	for (i = 0 ; i < sel_from.length; i++){
+		if (sel_from[i].selected) {
+			var name = document.getElementById("name"+to);
+			var id = document.getElementById("id"+to);
+			name.innerHTML = sel_from.options[i].text;
+			id.value  = sel_from[i].value;
+			show_button("id"+to);
+			break;
+		}
+	}
+}
+</script>
+{scripts}
