From 24ecfd7ff3d19415e893fb47532c125afdab0d15 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 3 Jul 2009 09:39:47 +0000 Subject: [PATCH] Updated role management -Added member/occupant selection. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13880 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../roleManagement/class_occupantSelect.inc | 124 +++++++++++++++++- .../roleManagement/class_roleGeneric.inc | 89 ++++++++++++- .../admin/roleManagement/occupantSelect.tpl | 48 ++++++- 3 files changed, 249 insertions(+), 12 deletions(-) diff --git a/gosa-plugins/roleManagement/admin/roleManagement/class_occupantSelect.inc b/gosa-plugins/roleManagement/admin/roleManagement/class_occupantSelect.inc index 2d5856e40..7fc690e9f 100644 --- a/gosa-plugins/roleManagement/admin/roleManagement/class_occupantSelect.inc +++ b/gosa-plugins/roleManagement/admin/roleManagement/class_occupantSelect.inc @@ -26,17 +26,137 @@ class occupantSelect extends plugin { $this->config = $config; $this->dn = $dn; $this->parent = $parent; + $this->skipEntries = $parent->getOccupants(); + + /* Get global filter config */ + if (!session::is_set("roleAddOccupantFilter")){ + $ui= get_userinfo(); + $base= get_base_from_people($ui->dn); + $roleAddOccupantFilter= array( + "dselect" => $base, + "subtrees" => FALSE, + "regex" => "*"); + session::set("roleAddOccupantFilter", $roleAddOccupantFilter); + } + } function execute() { + /* Save data */ + $roleAddOccupantFilter= session::get("roleAddOccupantFilter"); + if(isset($_POST['occupantSearched'])){ + + $roleAddOccupantFilter['subtrees'] = false; + if(isset($_POST['subtrees'])){ + $roleAddOccupantFilter['subtrees'] = "checked"; + } + + foreach( array("dselect", "regex") as $type){ + if (isset($_POST[$type])){ + $roleAddOccupantFilter[$type]= $_POST[$type]; + } + } + } + if (isset($_GET['search'])){ + $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; + if ($s == "**"){ + $s= "*"; + } + $roleAddOccupantFilter['regex']= $s; + } + session::set("roleAddOccupantFilter", $roleAddOccupantFilter); + $smarty = get_smarty(); + $smarty->assign("search_image", get_template_path('images/lists/search.png')); + $smarty->assign("launchimage", get_template_path('images/lists/action.png')); + $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png')); + $smarty->assign("deplist", $this->config->idepartments); + $smarty->assign("alphabet", generate_alphabet()); + $smarty->assign("hint", print_sizelimit_warning()); + $smarty->assign("apply", apply_filter()); + $smarty->assign("objects", $this->getObjects()); + foreach( array("dselect", "regex", "subtrees") as $type){ + $smarty->assign("$type", $roleAddOccupantFilter[$type]); + } + return($smarty->fetch(get_template_path("occupantSelect.tpl",TRUE, dirname(__FILE__)))); + } + - + function getObjects() + { + + // Initialize variables + $ldap = $this->config->get_ldap_link(); + $roleAddOccupantFilter= session::get("roleAddOccupantFilter"); + $regex = $roleAddOccupantFilter['regex']; + + // Detect the base to be use for ldap search + if($roleAddOccupantFilter['subtrees']){ + $base = $roleAddOccupantFilter['dselect']; + }else{ + $base = get_people_ou().$roleAddOccupantFilter['dselect']; + } + + // Set search flags flat/subsearch + $Get_list_flags = 0; + if($roleAddOccupantFilter['subtrees'] == "checked"){ + $Get_list_flags |= GL_SUBSEARCH; + } + + // Search for matching user objects. + $filter = "(&(objectClass=gosaAccount)(!(uid=*$))(|(uid=$regex)(cn=$regex)))"; + $res = get_list($filter, "users/user" , $base, + array("description", "objectClass", "sn", "givenName", "uid","cn"),$Get_list_flags); + + // Collect data. + $this->objects = array(); + foreach($res as $attrs){ + + // Skip entries which are already part of our role + if(in_array($attrs['dn'], $this->skipEntries)) continue; + + $name = $attrs['cn'][0]; + $dn = $attrs['dn']; + if (isset($attrs["description"][0])){ + $name .= " [".$attrs["description"][0]."]"; + } - return($smarty->fetch(get_template_path("occupantSelect.tpl",TRUE, dirname(__FILE__)))); + $entry = array(); + $entry['attrs'] = $attrs; + $entry['name'] = $name; + $entry['dn'] = $dn; + $this->objects[] = $entry; + } + uksort ($this->objects, 'strnatcasecmp'); + reset ($this->objects); + + // Create HTML content + $temp = ""; + foreach ($this->objects as $key => $value){ + $temp.= " + \n"; + } + return ($temp); } + + + function save() + { + $ret = array(); + if(isset($_POST['objects'])){ + $objects = $_POST['objects']; + foreach($objects as $id){ + $ret[] = $this->objects[$id]; + } + } + return($ret); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc b/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc index 1892f8115..ee30124ec 100644 --- a/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc +++ b/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc @@ -28,7 +28,6 @@ class roleGeneric extends plugin { var $description =""; var $telephoneNumber = ""; var $facsimileTelephoneNumber = ""; - var $roleOccupant = array(); // The objects base var $base = ""; @@ -41,6 +40,12 @@ class roleGeneric extends plugin { // The object classes written by this plugin var $objectclasses = array("top","organizationalRole"); + // The list of occupants ([dn]) + var $roleOccupant = array(); + + // The roleOccupant cache, dn=>attrs + var $roleOccCache = array(); + // A list of attributes managed by this plugin var $attributes = array("cn","description", "telephoneNumber","facsimileTelephoneNumber","roleOccupant"); @@ -52,6 +57,14 @@ class roleGeneric extends plugin { plugin::plugin($config,$dn); $this->is_account = TRUE; + // Initialize list of occupants + $this->roleOccupant = array(); + if(isset($this->attrs['roleOccupant'])){ + for($i=0;$i<$this->attrs['roleOccupant']['count']; $i++){ + $this->roleOccupant[] = $this->attrs['roleOccupant'][$i]; + } + } + // Detect the objects base if ($this->dn == "new"){ $this->base = session::get('CurrentMainBase'); @@ -63,9 +76,39 @@ class roleGeneric extends plugin { $this->orig_base = $this->base; $this->orig_dn = $dn; $this->orig_cn = $this->cn; + + // Reload the occupant cache. + $this->reload(); } + /* Keep occupant cache up to date. + * Else, we may have entries we can't display. + */ + function reload() + { + // Entries can't be added twice. + $attrs = array("description", "objectClass", "uid","cn"); + $this->roleOccupant = array_unique($this->roleOccupant); + $this->roleOccupant = array_values($this->roleOccupant); + + $ldap = $this->config->get_ldap_link(); + foreach($this->roleOccupant as $dn){ + if(!isset($this->roleOccCache[$dn])){ + if($ldap->dn_exists($dn)){ + $ldap->cat($dn, $attrs); + $this->roleOccCache[$dn] = $ldap->fetch(); + } + } + } + + } + + + function getOccupants(){ + return($this->roleOccupant); + } + /* Generate HTML output of this plugin. */ function execute() @@ -81,6 +124,29 @@ class roleGeneric extends plugin { if(isset($_POST['edit_membership']) && !$this->dialog instanceOf plugin){ $this->dialog = new occupantSelect($this->config,$this->dn,$this); } + if(isset($_POST['delete_membership']) && !$this->dialog instanceOf plugin){ + if(isset($_POST['members'])){ + foreach($_POST['members'] as $id){ + if(isset($this->roleOccupant[$id])){ + unset($this->roleOccupant[$id]); + } + } + $this->reload(); + } + } + + if(isset($_POST['add_object_cancel']) && $this->dialog instanceOf plugin){ + $this->dialog = NULL; + } + if(isset($_POST['add_object_finish']) && $this->dialog instanceOf plugin){ + $ret = $this->dialog->save(); + foreach($ret as $key => $entry){ + $this->roleOccupant[] = $entry['dn']; + $this->roleOccCache[$entry['dn']] = $entry['attrs']; + } + $this->reload(); + $this->dialog = NULL; + } if($this->dialog instanceOf plugin){ $this->dialog->save_object(); @@ -88,6 +154,9 @@ class roleGeneric extends plugin { } + /*************** + * Template handling + ***************/ // Get smarty instance and assign required variables. $smarty = get_smarty(); @@ -144,13 +213,19 @@ class roleGeneric extends plugin { function convert_list() { $temp= ""; - foreach ($this->roleOccupant as $key => $value){ - $temp.= " - \n"; + $icon = " style=\"background-image:url('plugins/generic/images/head.png');\" "; + foreach ($this->roleOccupant as $key => $dn){ + if(isset($this->roleOccCache[$dn])){ + $entry = $this->roleOccCache[$dn]; + $name = $entry['cn']['0']; + if(isset($entry['description'][0])){ + $name .= " [".$entry['description'][0]."]"; + } + }else{ + $name = _("Unknown")." ".$dn; + } + $temp.= "\n"; } - return ($temp); } diff --git a/gosa-plugins/roleManagement/admin/roleManagement/occupantSelect.tpl b/gosa-plugins/roleManagement/admin/roleManagement/occupantSelect.tpl index 0e5ccffbc..c34e29731 100644 --- a/gosa-plugins/roleManagement/admin/roleManagement/occupantSelect.tpl +++ b/gosa-plugins/roleManagement/admin/roleManagement/occupantSelect.tpl @@ -1,7 +1,49 @@ + + + + + +
+
+

+ {t}Select objects to add{/t} {$hint} +

+
+
+

+ + +

+
+
+
+

[F]{t}Filters{/t}

+
+
+ + {$alphabet} +
+

+ {t}Search in subtrees{/t}
+

+ +
  +
+ +
+ {$apply} +
+
+ +

- -   - + +   +

-- 2.30.2