X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fogroups%2Fclass_ogroup.inc;h=ed44e8ea46b873609ce008b4eac4352f98b23ce1;hb=99b0a430dfa6d1cfad04ccf0302e1fbff0b02e28;hp=136562a6308b0383e877bc82469b7847e8873365;hpb=7bf4dc15c75980577ca704b8ee47c37cebe1c008;p=gosa.git diff --git a/plugins/admin/ogroups/class_ogroup.inc b/plugins/admin/ogroups/class_ogroup.inc index 136562a63..ed44e8ea4 100644 --- a/plugins/admin/ogroups/class_ogroup.inc +++ b/plugins/admin/ogroups/class_ogroup.inc @@ -25,14 +25,14 @@ class ogroup extends plugin var $gosaGroupObjects= ""; var $department= ""; var $objects= array(); - var $allobjects= array(); + var $objcache= array(); var $memberList= array(); var $member= array(); var $orig_dn= ""; var $group_dialog= FALSE; /* attribute list for save action */ - var $attributes= array("cn", "description", "gosaGroupObjects"); + var $attributes= array("cn", "description", "gosaGroupObjects","member"); var $objectclasses= array("top", "gosaGroupOfNames"); function ogroup ($config, $dn= NULL) @@ -40,6 +40,8 @@ class ogroup extends plugin plugin::plugin ($config, $dn); $this->orig_dn= $dn; + $this->member = array(); + /* Load member objects */ if (isset($this->attrs['member'])){ foreach ($this->attrs['member'] as $key => $value){ @@ -69,6 +71,7 @@ class ogroup extends plugin "W" => "workstations", "T" => "terminals", "F" => "phones", + "_" => "subtrees", "P" => "printers") as $key => $val){ if (preg_match("/$key/", $this->gosaGroupObjects)){ @@ -78,25 +81,28 @@ class ogroup extends plugin } } register_global("ogfilter", $ogfilter); - - if(isset($_SESSION['ogroupfilter']['depselect'])){ - $this->base = $_SESSION['ogroupfilter']['depselect']; + + /* Set base */ + if ($this->dn == "new"){ + $this->base= $_SESSION['CurrentMainBase']; + } else { + $this->base= preg_replace("/^[^,]+,".get_groups_ou()."/","",$this->dn); } - /* set permissions */ + /* set permissions */ $ui= get_userinfo(); $acl= get_permissions ($ui->dn, $ui->subtreeACL); $this->acl= get_module_permission($acl, "ogroup", $ui->dn); - /* Load member data */ $this->reload(); } - function AddDelMembership($NewMember = false){ - + function AddDelMembership($NewMember = false) + { if($NewMember){ - $this->memberList[$NewMember]= $this->allobjects[$NewMember]; + $this->importMember($NewMember); + $this->memberList[$NewMember]= $this->objcache[$NewMember]; $this->member[$NewMember]= $NewMember; unset ($this->objects[$NewMember]); uasort ($this->memberList, 'sort_list'); @@ -174,6 +180,31 @@ class ogroup extends plugin /* Load templating engine */ $smarty= get_smarty(); + /* Base select dialog */ + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^chooseBase/",$name) && $once){ + $once = false; + $this->dialog = new baseSelectDialog($this->config); + $this->dialog->setCurrentBase($this->base); + } + } + + /* Dialog handling */ + if(is_object($this->dialog)){ + /* Must be called before save_object */ + $this->dialog->save_object(); + + if($this->dialog->isClosed()){ + $this->dialog = false; + }elseif($this->dialog->isSelected()){ + $this->base = $this->dialog->isSelected(); + $this->dialog= false; + }else{ + return($this->dialog->execute()); + } + } + /* Add objects? */ if (isset($_POST["edit_membership"])){ $this->group_dialog= TRUE; @@ -198,7 +229,7 @@ class ogroup extends plugin } if (isset($_POST['dselect'])){ foreach( array("accounts", "groups", "applications", "departments", - "servers", "workstations", "terminals", "printers", + "servers", "workstations", "terminals", "printers","subtrees", "phones") as $type){ if (isset($_POST[$type])) { @@ -228,7 +259,7 @@ class ogroup extends plugin $smarty->assign("deplist", $this->config->idepartments); $smarty->assign("alphabet", generate_alphabet()); foreach( array("dselect", "regex", "accounts", "groups", "applications", - "departments", "servers", "workstations", "terminals", + "departments", "servers", "workstations", "terminals","subtrees", "printers", "phones") as $type){ $smarty->assign("$type", $ogfilter[$type]); } @@ -382,8 +413,15 @@ class ogroup extends plugin /* Perform search for selected objectClasses */ foreach($objectClasses as $class=> $basedn){ - $ldap->ls("(&(objectClass=".$class.")(|(uid=$regex)(cn=$regex)(ou=$regex)))",$basedn.$ogfilter['dselect'] , - array("dn", "cn", "description", "objectClass", "sn", "givenName", "uid","ou")); + + if($ogfilter['subtrees'] == "checked"){ + $ldap->cd($ogfilter['dselect']); + $ldap->search("(&(objectClass=".$class.")(|(uid=$regex)(cn=$regex)(ou=$regex)))", + array("dn", "cn", "description", "objectClass", "sn", "givenName", "uid","ou")); + }else{ + $ldap->ls("(&(objectClass=".$class.")(|(uid=$regex)(cn=$regex)(ou=$regex)))",$basedn.$ogfilter['dselect'] , + array("dn", "cn", "description", "objectClass", "sn", "givenName", "uid","ou")); + } /* fetch results and append them to the list */ while($attrs = $ldap->fetch()){ @@ -404,46 +442,6 @@ class ogroup extends plugin uasort ($this->objects, 'sort_list'); reset ($this->objects); - /*########### - Get a list with all possible objects, to detect objects which doesn't exists anymore ... - ###########*/ - - /* Only do this, if this wasn't already done */ - if(count($this->allobjects) == 0){ - $ldap->cd ($this->config->current['BASE']); - $filter="(objectClass=gosaAccount)". - "(objectClass=posixGroup)". - "(objectClass=gosaApplication)". - "(objectClass=gosaDepartment)". - "(objectClass=goServer)". - "(objectClass=gotoWorkstation)". - "(objectClass=gotoTerminal)". - "(objectClass=gotoPrinter)". - "(objectClass=goFonHardware)"; - $regex= "*"; - - $ldap->search ("(&(|$filter)(|(uid=$regex)(cn=$regex)(ou=$regex)))", array("dn", "cn", "ou", "description", "objectClass", "sn", "givenName", "uid")); - while ($attrs= $ldap->fetch()){ - - $type= $this->getObjectType($attrs); - $name= $this->getObjectName($attrs); - - if (isset($attrs["description"][0])){ - $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type"); - } elseif (isset($attrs["uid"][0])) { - $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type"); - } else { - $this->allobjects[$attrs["dn"]]= array("text" => "$name", "type" => "$type"); - } - $this->allobjects[$attrs["dn"]]['objectClass'] = $attrs['objectClass']; - if(isset($attrs['uid'])){ - $this->allobjects[$attrs["dn"]]['uid'] = $attrs['uid']; - } - } - uasort ($this->allobjects, 'sort_list'); - reset ($this->allobjects); - } - /*########### Build member list and try to detect obsolete entries @@ -453,63 +451,7 @@ class ogroup extends plugin /* Walk through all single member entry */ foreach($this->member as $dn){ - - /* Object in object list? */ - if (isset($this->allobjects[$dn])){ - - /* Add this entry to member list, its dn is in allobjects - this means it still exists - */ - $this->memberList[$dn]= $this->allobjects[$dn]; - - /* Remove this from selectable entries */ - if (isset ($this->objects[$dn])){ - unset ($this->objects[$dn]); - } - - - } else { - - /* The dn for the current member can't be resolved - it seams that this entry was removed - */ - /* Try to resolv the entry again, if it still fails, display error msg */ - $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass")); - - /* It has failed, add entry with type flag I (Invalid)*/ - if ($ldap->error != "success"){ - $this->memberList[$dn]= array('text' => _("Non existing dn: ")."$dn","type" => "I"); - - } else { - - /* Append this entry to our all object list */ - - /* Fetch object */ - $attrs= $ldap->fetch(); - - $type= $this->getObjectType($attrs); - $name= $this->getObjectName($attrs); - - if (isset($attrs["description"][0])){ - $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type"); - } elseif (isset($attrs["uid"][0])) { - $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type"); - } else { - $this->allobjects[$attrs["dn"]]= array("text" => "$name", "type" => "$type"); - } - $this->allobjects[$attrs["dn"]]['objectClass'] = $attrs['objectClass']; - if(isset($attrs['uid'])){ - $this->allobjects[$attrs["dn"]]['uid'] = $attrs['uid']; - } - - /* Fill array */ - if (isset($attrs["description"][0])){ - $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type"); - } else { - $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type"); - } - } - } + $this->importMember($dn); } uasort ($this->memberList, 'sort_list'); reset ($this->memberList); @@ -532,6 +474,48 @@ class ogroup extends plugin } + function importMember($dn) + { + $ldap= $this->config->get_ldap_link(); + + /* Try to resolv the entry again, if it still fails, display error msg */ + $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass")); + + /* It has failed, add entry with type flag I (Invalid)*/ + if ($ldap->error != "Success"){ + $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I"); + } else { + /* Append this entry to our all object list */ + + /* Fetch object */ + $attrs= $ldap->fetch(); + + $type= $this->getObjectType($attrs); + $name= $this->getObjectName($attrs); + + if (isset($attrs["description"][0])){ + $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type"); + } elseif (isset($attrs["uid"][0])) { + $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type"); + } else { + $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type"); + } + $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass']; + if(isset($attrs['uid'])){ + $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid']; + } + + /* Fill array */ + if (isset($attrs["description"][0])){ + $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type"); + } else { + $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type"); + } + + $this->memberList[$dn]= $this->objects[$attrs["dn"]]; + } + } + function convert_list($input) { $temp= ""; @@ -602,7 +586,8 @@ class ogroup extends plugin function check() { - $message= array(); + /* Call common method to give check the hook */ + $message= plugin::check(); /* Permissions for that base? */ if ($this->base != ""){ @@ -614,7 +599,7 @@ class ogroup extends plugin $ldap = $this->config->get_ldap_link(); if($this->dn != $new_dn){ - $ldap->cat ($new_dn); + $ldap->cat ($new_dn, array('dn')); } if($ldap->count() !=0){ @@ -648,8 +633,9 @@ class ogroup extends plugin plugin::save(); /* Move members to target array */ + $this->attrs['member'] =array(); foreach ($this->member as $key => $desc){ - $this->attrs['member'][]= $key; + $this->attrs['member'][]= @LDAP::fix($key); } $ldap= $this->config->get_ldap_link(); @@ -661,7 +647,7 @@ class ogroup 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->member)){ @@ -676,13 +662,14 @@ class ogroup extends plugin /* Write back to ldap */ $ldap->cd($this->dn); + $this->cleanup(); $ldap->$mode($this->attrs); /* Trigger post signal */ $this->handle_post_events($mode); $ret= 0; - if (show_ldap_error($ldap->get_error())){ + if (show_ldap_error($ldap->get_error(), _("Saving object group failed"))){ $ret= 1; } @@ -695,12 +682,31 @@ class ogroup 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 object group failed")); /* Trigger remove signal */ $this->handle_post_events("remove"); } + function getCopyDialog() + { + $str = ""; + + $smarty = get_smarty(); + $smarty->assign("cn", $this->cn); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__))); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: