From 8dc7cd7fa1e01bcfab1d824fcc2d47c63b51000e Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 13 Jun 2008 08:59:36 +0000 Subject: [PATCH 1/1] Updated department dialog. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11318 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../class_departmentManagement.inc | 111 ++++++----- .../departments/class_divListDepartment.inc | 172 ++++++++++++------ .../admin/departments/tabs_department.inc | 1 - 3 files changed, 179 insertions(+), 105 deletions(-) diff --git a/gosa-core/plugins/admin/departments/class_departmentManagement.inc b/gosa-core/plugins/admin/departments/class_departmentManagement.inc index 26ed101aa..2d84632ef 100644 --- a/gosa-core/plugins/admin/departments/class_departmentManagement.inc +++ b/gosa-core/plugins/admin/departments/class_departmentManagement.inc @@ -426,67 +426,80 @@ class departmentManagement extends plugin $config = session::get('config'); $tmp = $config->idepartments; - // In case of a valid back button create entry - if(isset($tmp[$base_back])){ - $tmp2 ['dn'] = convert_department_dn($base_back); - - // If empty always go to top - if(empty($tmp2['dn'])){ - $tmp2['dn']="/"; - } - $tmp2 ['description'][0] = ".. ".msgPool::backButton(); - $result[$tmp[$base_back]]=$tmp2; - } - - - + /* Possible department types + */ + $types['country'] = array("ACL" => "country", "ATTR" => "c", + "CLS" => "(objectClass=country)", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "c"); + $types['locality'] = array("ACL" => "locality", "ATTR" => "l", + "CLS" => "(objectClass=locality)", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "l"); + $types['organizationalUnit'] = array("ACL" => "department", "ATTR" => "ou", + "CLS" => "(&(objectClass=gosaDepartment)(objectClass=organizationalUnit))", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "ou"); + $types['organization'] = array("ACL" => "organization", "ATTR" => "o", + "CLS" => "(objectClass=organization)", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "o"); + $types['Alias??'] = array("ACL" => "alias" , "ATTR" => "alias?", + "CLS" => "(objectClass=alias??)", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "alias"); + $types['Referal??'] = array("ACL" => "referal", "ATTR" => "referal?", + "CLS" => "(objectClass=referal??)", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "referal"); + + /* Create search filter for each department type + */ + $res = array(); if($this->DivListDepartment->SubSearch){ - $res= get_list("(&(|(ou=$Regex)(description=$Regex))(objectClass=gosaDepartment))", - "department", $base, array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH); + foreach($types as $oc => $data){ + $res= array_merge($res,get_list("(&(|(".$data['ATTR']."=$Regex)(description=$Regex))".$data['CLS'].")", + "department", $base, array($data['ATTR'],"objectClass", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + } }else{ - $res= get_list("(&(|(ou=$Regex)(description=$Regex))(objectClass=gosaDepartment))", - "department", $base, array("ou", "description"), GL_SIZELIMIT ); - } - - - /**/ - $non_ou = get_list("(&(|(c=$Regex)(description=$Regex))(objectClass=country))", - "department", $base, array("c", "description"), GL_SIZELIMIT ); - $non_ou = array_merge($non_ou,get_list("(&(|(l=$Regex)(description=$Regex))(objectClass=locality))", - "department", $base, array("l", "description"), GL_SIZELIMIT )); - $non_ou = array_merge($non_ou,get_list("(&(|(o=$Regex)(description=$Regex))(objectClass=organization))", - "department", $base, array("o", "description"), GL_SIZELIMIT )); - - $this->departments= array(); - foreach($non_ou as $obj){ - $this->departments[] = $obj['dn']; - } - - - /* Add current base to the list of available departments, but only if its naming attribute is 'ou' */ - if(preg_match("/^ou=/",$base)){ - $this->departments [ convert_department_dn($base) ] = "."; + foreach($types as $oc => $data){ + $res= array_merge($res,get_list("(&(|(".$data['ATTR']."=$Regex)(description=$Regex))".$data['CLS'].")", + "department", $base, array($data['ATTR'], "objectClass","description"), GL_SIZELIMIT )); + } } - foreach ($res as $key => $value){ + /* Prepare list (sortable index) + */ + $deps = array(); + $this->departments = array(); + foreach($res as $attr){ /* Don't display base as entry on subsearch */ - if(($value['dn'] == $base) && ($this->DivListDepartment->SubSearch)){ + if(($attr['dn'] == $base) && ($this->DivListDepartment->SubSearch)){ continue; } - $cdn= convert_department_dn($value['dn']); - - /* Append to dep list */ - if(isset($value["description"][0])){ - $this->departments[$cdn]= get_sub_department($cdn)." - [".$value["description"][0]."]"; - }else{ - $this->departments[$cdn]= get_sub_department($cdn);//$value["description"][0]; + /* Detect type and create sortable index + */ + $found =FALSE; + foreach($types as $oc => $data){ + if(in_array($oc,$attr['objectClass'])){ + $name = $attr[$data['ATTR']][0]."-".$attr['dn']; + $deps[$name] = $attr; + $found =TRUE; + break; + } } + if(!$found ) trigger_error("Not found!"); + } + uksort($deps, 'strnatcasecmp'); + + /* In case of a valid back button create entry + */ + if(isset($tmp[$base_back])){ + $tmp = array(); + $tmp['dn'] = $base_back; + $tmp['ou'][0] = ".."; + $tmp['objectClass'] = array("organizationalUnit","gosaDepartment"); + $tmp['description'][0] = msgPool::backButton(); + $deps= array_merge(array($tmp),$deps); } - natcasesort ($this->departments); - reset ($this->departments); + $this->departments = array_values($deps); } function remove_from_parent() diff --git a/gosa-core/plugins/admin/departments/class_divListDepartment.inc b/gosa-core/plugins/admin/departments/class_divListDepartment.inc index 6fa3f8d07..469b0163b 100644 --- a/gosa-core/plugins/admin/departments/class_divListDepartment.inc +++ b/gosa-core/plugins/admin/departments/class_divListDepartment.inc @@ -135,7 +135,6 @@ class divListDepartment extends MultiSelectWindow /* Generate list head */ $ui = get_userinfo(); - $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/department"); /* Add default header */ $listhead = MultiSelectWindow::get_default_header(); @@ -149,29 +148,41 @@ class divListDepartment extends MultiSelectWindow $s = ".|"._("Actions")."|\n"; /* Append create options */ - if(preg_match("/c/",$acl)) { - $s .= "..|". - " "._("Create")."|\n"; + $s .= "..|". + " "._("Create")."|\n"; + + if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/department"))) { $s.= "...|". " "._("Department")." (ou)|dep_new_ou|\n"; - $s.= "...|". + } + + if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/organization"))) { + $s.= "...|". " "._("Organization")." (o)|dep_new_o|\n"; + } - $s.= "...|". + if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/country"))) { + $s.= "...|". " "._("Country")." (c)"."|dep_new_c|\n"; + } - $s.= "...|". + if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/locality"))) { + $s.= "...|". " "._("Locality")." (l)|dep_new_l|\n"; + } - $s.= "...|". + if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/alias"))) { + $s.= "...|". " "._("Alias")."|dep_new_alias|\n"; + } - $s.= "...|". + if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/referal"))) { + $s.= "...|". " "._("Referal")."|dep_new_referal|\n"; - - $s.= "..|---|\n"; } + + $s.= "..|---|\n"; $s.= "..|". " "._("Remove")."|"."remove_multiple|\n"; @@ -190,64 +201,115 @@ class divListDepartment extends MultiSelectWindow { $linkopen = "%s"; + + /* Possible department types + */ + $types['country'] = array("ACL" => "country", "ATTR" => "c", + "TITLE" => _("Department"), + "IMG_FULL" => "plugins/departments/images/country.png", + "IMG" => "plugins/departments/images/country.png", "ABBR" => "c"); + $types['locality'] = array("ACL" => "locality", "ATTR" => "l", + "TITLE" => _("Department"), + "IMG" => "plugins/departments/images/locality.png", "ABBR" => "l"); + $types['organizationalUnit'] = array("ACL" => "department", "ATTR" => "ou", + "TITLE" => _("Department"), + "IMG_FULL" => "images/lists/folder-full.png", + "IMG" => "images/lists/folder.png", "ABBR" => "ou"); + $types['organization'] = array("ACL" => "organization", "ATTR" => "o", + "TITLE" => _("Department"), + "IMG" => "plugins/departments/images/organization.png", "ABBR" => "o"); + $types['Alias??'] = array("ACL" => "alias" , "ATTR" => "alias?", + "TITLE" => _("Department"), + "IMG" => "plugins/departments/images/department_alias.png", "ABBR" => "alias"); + $types['Referal??'] = array("ACL" => "referal", "ATTR" => "referal?", + "TITLE" => _("Department"), + "IMG" => "plugins/departments/images/department_referal.png", "ABBR" => "referal"); + + $this->departments = $list; + $ui = get_userinfo(); foreach($list as $key => $val) { $actions= ""; - if(!isset($this->config->departments[$key])){ - - $field01 = array("string" => " ", "attach" => "style='width:20px;'"); - $field0 = array("string" => "department", - "attach" => "style='text-align:center;width:20px;'"); - $field1 = array("string" => $val, "attach" => "style='' title='".$val."'"); - $field2 = array("string" => "", "attach" => "style='border-right: 0px;'"); - - }else{ - $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department"); - $acl_all = $ui->has_complete_category_acls($this->config->departments[$key] ,"department"); - - $actions.= ""; - - if(preg_match("/d/",$acl)){ - $actions.= ""; + /* Detect department type + */ + $dep_data = array(); + foreach($types as $type => $data){ + if(in_array($type,$val['objectClass'])){ + $dep_data = $data; + break; } + } + + /* Warn if there was an unknown department type found + */ + if(!count($dep_data)) { + trigger_error("Unknown department type given. Skipped '".$val['dn']."'."); + continue; + } - if(!isset($this->config->departments[trim($key)])){ - $this->config->departments[trim($key)]=""; - } + /* Get permissions + */ + $acl = $ui->get_permissions($val['dn'],"department/".$dep_data['ACL']); + $acl_all = $ui->has_complete_category_acls($val['dn'],"department"); + + /* Create actions + */ + $actions.= ""; + if(preg_match("/d/",$acl)){ + $actions.= ""; + } - /* check if this department contains sub-departments - Display different image in this case - */ - $non_empty=""; - $nkey= normalizePreg($key); - foreach($this->config->departments as $keyd=>$vald ){ - if(preg_match('/$nkey\/.*/',$keyd)){ - $non_empty="full"; - } + /* Check if this department contains sub-departments + Display different image in this case + */ + $sub_folders= FALSE; + foreach($this->config->departments as $keyd){ + if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){ + $sub_folders = TRUE; } + } - $title = preg_replace('/ /', ' ', @LDAP::fix($this->config->departments[$key])); + /* Create entry name + */ + $name = $val[$dep_data['ATTR']][0]; + if(isset($val['description'])){ + $name .= " - [".$val["description"][0]."]"; + } - if($val == "."){ - $field01 = array("string" => " ", - "attach" => "style='width:20px;'"); - }else{ - $field01 = array("string" => "" , - "attach" => "style='width:20px;'"); - } + /* Create title + */ + $title = preg_replace('/ /', ' ', @LDAP::fix($val['dn'])); - $field0 = array("string" => "department", "attach" => "style='text-align:center;width:20px;'"); - $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'"); - $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align: - right;'"); + /* Create checkboxes infront of the entry + */ + if($name == "."){ + $field01 = array("string" => " ", + "attach" => "style='width:20px;'"); + }else{ + $field01 = array("string" => "" , + "attach" => "style='width:20px;'"); + } + /* Create image + */ + if($sub_folders){ + $img = ""; + }else{ + $img = ""; } + + /* Append data to the listing + */ + $field0 = array("string" => $img, "attach" => "style='text-align:center;width:20px;'"); + $field1 = array("string" => sprintf($linkopen,$key,$name), + "attach" => "style='' title='".$title."'"); + $field2 = array("string" => preg_replace("/%KEY%/", $key, $actions), + "attach" => "style='width:60px;border-right:0px;text-align:right;'"); + $this->AddElement( array($field01,$field0,$field1,$field2)); } diff --git a/gosa-core/plugins/admin/departments/tabs_department.inc b/gosa-core/plugins/admin/departments/tabs_department.inc index e8a784248..86f0acd65 100644 --- a/gosa-core/plugins/admin/departments/tabs_department.inc +++ b/gosa-core/plugins/admin/departments/tabs_department.inc @@ -32,7 +32,6 @@ class deptabs extends tabs /* Detect the base class (The classs which extends from department) */ - $class = "department"; foreach($this->by_object as $name => $object){ if($object instanceOf department){ $this->base_name = get_class($object); -- 2.30.2