X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fgroups%2Fclass_groupGeneric.inc;h=f25a036f113d683530f88d3b50aa3349dc4d83cf;hb=1d1cd0cb530ce119ec3d8c26183da6795dff7ba2;hp=e1286d7e1b1344263e9783e717d637d24904a748;hpb=c3f16e2efd365da0c2ffba6dd1de2208e486d1b1;p=gosa.git diff --git a/plugins/admin/groups/class_groupGeneric.inc b/plugins/admin/groups/class_groupGeneric.inc index e1286d7e1..f25a036f1 100644 --- a/plugins/admin/groups/class_groupGeneric.inc +++ b/plugins/admin/groups/class_groupGeneric.inc @@ -1,4 +1,5 @@ samba3= ($config->current['SAMBAVERSION'] == 3); $this->orig_dn= $dn; + $this->orig_cn= $this->cn; /* Get member list */ if (isset($this->attrs['memberUid'][0])){ @@ -136,20 +142,22 @@ class group extends plugin } $gufilter= get_global('gufilter'); - /* Bases / Departments */ - - if(isset($_SESSION['groupfilter']['depselect'])){ - $this->base = $_SESSION['groupfilter']['depselect']; - }else{ - if ($this->dn == "new"){ + $gufilter['SubSearchGroup'] = false; + $gufilter['dselect'] = $_SESSION['gufilter']['dselect']; + + register_global('gufilter',$gufilter); + + if ($this->dn == "new"){ + if(isset($_SESSION['CurrentMainBase'])){ + $this->base= $_SESSION['CurrentMainBase']; + }else{ $ui= get_userinfo(); $this->base= dn2base($ui->dn); - } else { - $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn); } + } else { + $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn); } - /* This is always an account */ $this->is_account= TRUE; $this->reload(); @@ -256,6 +264,14 @@ class group extends plugin $gufilter[$type]= $_POST[$type]; } } + if(isset($_POST['regex'])){ + if(isset($_POST['SubSearchGroup'])){ + $gufilter['SubSearchGroup'] = true; + }else{ + $gufilter['SubSearchGroup'] = false; + } + } + if (isset($_GET['search'])){ $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; if ($s == "**"){ @@ -263,7 +279,6 @@ class group extends plugin } $gufilter['regex']= $s; } - $regex= preg_replace('/[*]/', ".*", $gufilter['regex']); register_global("gufilter", $gufilter); $this->reload(); @@ -273,20 +288,11 @@ class group extends plugin $smarty->assign("tree_image", get_template_path('images/tree.png')); $smarty->assign("deplist", $this->config->idepartments); $smarty->assign("alphabet", generate_alphabet()); - foreach( array("dselect", "regex") as $type){ + foreach( array("dselect", "regex","SubSearchGroup") as $type){ $smarty->assign("$type", $gufilter[$type]); } $smarty->assign("hint", print_sizelimit_warning()); - - $users= array(); - foreach ($this->allusers as $key => $value){ - if (!array_key_exists($key, $this->members)){ - if (preg_match("/^$regex/i", $key)){ - $users[$key]= $value; - } - } - } - $smarty->assign("users", $users); + $smarty->assign("users", $this->displayUsers); $smarty->assign("apply", apply_filter()); $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__))); return ($display); @@ -394,41 +400,101 @@ class group extends plugin /* Reload data */ function reload() { - /* Generate userlists */ - $this->last_sorting= "invalid"; - $this->users= array(); + /* Fix regex string */ + $gufilter = get_global("gufilter"); + $regex = normalizeLdap($gufilter['regex']); + $MaxUser = $this->OnlyShowFirstEntries; + + /* Prepare ldap link */ $ldap= $this->config->get_ldap_link(); - $gufilter= get_global("gufilter"); + $ldap->cd($gufilter['dselect']); - $ldap->cd ($gufilter['dselect']); - $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName")); - $this->allusers= array(); - while ($attrs= $ldap->fetch()){ - if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){ - $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ". - $attrs["givenName"][0]. - " [".$attrs["uid"][0]."]"; - } else { - $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0]; + + /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes + (Store gathered sn/givenName informations in $this->allusers too, + to be prepared when adding/deleting users) + */ + $filter = ""; + foreach ($this->memberUid as $value){ + if(!isset($this->members[$value])){ + $filter .= "(uid=".normalizeLdap($value).")"; } } - natcasesort ($this->allusers); - reset ($this->allusers); - - /* Fill memberlist */ - $this->members= array(); + if(!empty($filter)){ + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName")); + while($attrs = $ldap->fetch()){ + $this->members[$attrs['uid'][0]] = $this->createResultName($attrs); + $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs); + } + } + + /* check if all uids are resolved */ foreach ($this->memberUid as $value){ - if (isset($this->allusers[$value])){ - $this->members[$value]= $this->allusers[$value]; - } else { - $this->members[$value]= "[$value]"; + if(!isset($this->members[$value])){ + $this->members[$value] = _("! unknown id")." [".$value."]"; } + } + + /* Create display list of users matching regex & filter + */ + $this->displayUsers = array(); + + /* Set tag attribute if we've tagging activated */ + $tag= ""; + $ui= get_userinfo(); + if ($ui->gosaUnitTag != "" && isset($this->config->current['STRICT_UNITS']) && + preg_match('/TRUE/i', $this->config->current['STRICT_UNITS'])){ + $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")"; } - asort($this->members); + + $filter = "(&(objectClass=gosaAccount)$tag(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))"; + + /* Search in current tree or within subtrees depending on the checkbox from filter section */ + if($gufilter['SubSearchGroup']){ + $ldap->search($filter, array("uid", "sn","givenName")); + }else{ + $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName")); + } + $i = 0; + + /* Fetch all users and skip already used users */ + while($attrs = $ldap->fetch()){ + if(in_array($attrs['uid'][0], $this->memberUid)) { + continue; + } + $i ++; + if($i > $MaxUser) { + break; + } + $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs); + $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs); + } + + /* If more than max users are found, display a message to warn the user */ + if(($i == $MaxUser)){ + print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser)); + } + + /* Sort lists */ + natcasesort($this->members); reset($this->members); + natcasesort ($this->displayUsers); + reset ($this->displayUsers); } + /* Create display name, this was used so often that it is excluded into a seperate function */ + function createResultName($attrs) + { + if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){ + $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]"; + } else { + $ret= $attrs['uid'][0]; + } + return($ret); + } + function remove_from_parent() { @@ -436,7 +502,7 @@ class group extends plugin $ldap= $this->config->get_ldap_link(); $ldap->rmdir($this->dn); - show_ldap_error($ldap->get_error()); + show_ldap_error($ldap->get_error(), _("Removing group failed")); /* Delete references to object groups */ $ldap->cd ($this->config->current['BASE']); @@ -457,6 +523,7 @@ class group extends plugin { /* Save additional values for possible next step */ if (isset($_POST['groupedit'])){ + plugin::save_object(); $this->force_gid= 0; @@ -497,6 +564,7 @@ class group extends plugin /* Save to LDAP */ function save() { + /* ID handling */ if ($this->force_gid == 0){ if ($this->saved_gidNumber != ""){ @@ -516,7 +584,7 @@ class group extends plugin $this->gidNumber= $this->get_next_id("gidNumber"); } } - + plugin::save(); /* Remove objectClass for samba/phone support */ @@ -534,8 +602,20 @@ class group extends plugin /* Add samba group functionality */ if ($this->samba3 && $this->smbgroup){ - $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID']; - $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; + + /* Fixed undefined index ... + */ + $this->SID = $this->ridBase = ""; + if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){ + $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID']; + }else{ + print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName)); + } + if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){ + $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; + }else{ + print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName)); + } $this->attrs['objectClass'][]= 'sambaGroupMapping'; $this->attrs['sambaGroupType']= "2"; @@ -594,7 +674,7 @@ class group extends plugin /* Save data. Using 'modify' implies that the entry is already present, use 'add' for new entries. So do a check first... */ - $ldap->cat ($this->dn); + $ldap->cat ($this->dn, array('dn')); if ($ldap->fetch()){ /* Modify needs array() to remove values :-( */ if (!count ($this->memberUid)){ @@ -619,7 +699,7 @@ class group extends plugin $ldap->$mode($this->attrs); $ret= 0; - if (show_ldap_error($ldap->get_error())){ + if (show_ldap_error($ldap->get_error(), _("Saving group failed"))){ $ret= 1; } @@ -634,7 +714,8 @@ class group extends plugin function check() { - $message= array(); + /* Call common method to give check the hook */ + $message= plugin::check(); /* Permissions for that base? */ if ($this->base != ""){ @@ -660,26 +741,42 @@ class group extends plugin $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed."); } - /* Check for used 'cn' */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn")); - if ($ldap->count() != 0){ - - /* New entry? */ - if ($this->dn == 'new'){ - $message[]= _("Value specified as 'Name' is already used."); - } - - /* Moved? */ - elseif ($new_dn != $this->orig_dn){ - $ldap->fetch(); - if ($ldap->getDN() != $this->orig_dn){ + + if($this->allowGroupsWithSameNameInOtherSubtrees == true){ + + /* Check for used 'cn' */ + $ldap= $this->config->get_ldap_link(); + if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){ + $ldap->cd("ou=groups,".$this->base); + $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn")); + if ($ldap->count() != 0){ $message[]= _("Value specified as 'Name' is already used."); } } - } + }else{ + + /* Check for used 'cn' */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn")); + if ($ldap->count() != 0){ + + /* New entry? */ + if ($this->dn == 'new'){ + $message[]= _("Value specified as 'Name' is already used."); + } + + /* Moved? */ + elseif ($new_dn != $this->orig_dn){ + $ldap->fetch(); + if ($ldap->getDN() != $this->orig_dn){ + $message[]= _("Value specified as 'Name' is already used."); + } + } + } + } + /* Check ID */ if ($this->force_gid == "1"){ if (!is_id($this->gidNumber)){ @@ -727,6 +824,43 @@ class group extends plugin } } + function getCopyDialog() + { + $vars = array("cn"); + + if($this ->force_gid){ + $used = " checked "; + $dis = ""; + }else{ + $used = ""; + $dis = " disabled "; + } + + $smarty = get_smarty(); + $smarty->assign("used",$used); + $smarty->assign("dis" ,$dis); + $smarty->assign("cn" ,$this->cn); + $smarty->assign("gidNumber",$this->gidNumber); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } + if(isset($_POST['force_gid'])){ + $this->force_gid = 1; + $this->gidNumber= $_POST['gidNumber']; + }else{ + $this->force_gid = 0; + $this->gidNumber = false; + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: