Code

Updated object group member handling
[gosa.git] / gosa-core / plugins / admin / ogroups / class_ogroup.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class ogroup extends plugin
24 {
25     var $typeToClass = array(  
26             "Y" => "gosaUserTemplate",
27             "U" => "gosaAccount",
28             "G" => "posixGroup",
29             "A" => "gosaApplication",
30             "D" => "gosaDepartment",
31             "S" => "goServer",
32             "W" => "gotoWorkstation",
33             "O" => "opsiClient",
34             "T" => "gotoTerminal",
35             "F" => "goFonHardware",
36             "P" => "gotoPrinter");
38     var  $typeToImage = array(
39             "Y" => "plugins/users/images/select_template.png",
40             "U" => "plugins/users/images/select_user.png",
41             "G" => "plugins/groups/images/select_group.png",
42             "A" => "plugins/ogroups/images/application.png",
43             "D" => "plugins/departments/images/department.png",
44             "S" => "plugins/ogroups/images/server.png",
45             "W" => "plugins/ogroups/images/workstation.png",
46             "O" => "plugins/ogroups/images/winstation.png",
47             "T" => "plugins/ogroups/images/terminal.png",
48             "F" => "plugins/ogroups/images/phone.png",
49             "P" => "plugins/ogroups/images/printer.png",
50             "I" => "images/false.png");
53     /* Variables */
54     var $cn= "";
55     var $description= "";
56     var $base= "";
57     var $gosaGroupObjects= "";
58     var $objects= array();
59     var $objcache= array();
60     var $memberList= array();
61     var $member= array();
62     var $orig_dn= "";
63     var $orig_cn= "";
64     var $orig_base= "";
65     var $objectSelect= FALSE;
66     var $view_logged = FALSE;
68     var $baseSelector;
70     /* Already assigned Workstations. Will be hidden in selection. 
71      */
72     var $used_workstations = array();
74     /* attribute list for save action */
75     var $attributes= array("cn", "description", "gosaGroupObjects","member");
76     var $objectclasses= array("top", "gosaGroupOfNames");
78   function ogroup (&$config, $dn= NULL)
79   {
80     plugin::plugin ($config, $dn);
82     $this->trustModeDialog = new trustModeDialog($this->config, $this->dn,NULL);
83     $this->trustModeDialog->setAcl('ogroups/ogroup');
85     $this->orig_dn= $dn;
87     $this->member = array();
89     /* Load member objects */
90     if (isset($this->attrs['member'])){
91       foreach ($this->attrs['member'] as $key => $value){
92         if ("$key" != "count"){
93           $value= @LDAP::convert($value);
94           $this->member["$value"]= "$value";
95         }
96       }
97     }
98     $this->is_account= TRUE;
100     /* Set base */
101     if ($this->dn == "new"){
102       $ui = get_userinfo();
103       $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
104     } else {
105       $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("ogroupRDN"), '/')."/i","",$this->dn);
106     }
108     /* Detect all workstations, which are already assigned to an object group  
109         - Those objects will be hidden in the add object dialog.
110         - Check() will complain if such a system is assigned to this object group.
111      */ 
112     $base = $this->config->current['BASE'];
113     $res    = get_list("(|(objectClass=gotoWorkstation)(objectClass=gotoTerminal))","none" , 
114         $base, array("dn"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
115     $ws_dns = array();
116     foreach($res as $data){
117       $ws_dns[] = $data['dn'];
118     }
119     $res=get_list("(&(member=*)(objectClass=gosaGroupOfNames))","none",
120         $base, array("dn","member", "gosaGroupObjects"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
121     $this->used_workstations = array();
122     foreach($res as $og){
123       if($og['dn'] == $this->dn) continue;
124       $test = array_intersect($ws_dns,$og['member']);
125       if(($og['gosaGroupObjects'] == "[W]" || $og['gosaGroupObjects'] == "[T]") && count($test)){
126         $this->used_workstations = array_merge($this->used_workstations,$test);
127       }
128     }
130     $this->orig_cn = $this->cn;
131     $this->orig_base = $this->base;
133     /* Get global filter config */
134     if (!session::is_set("sysfilter")){
135       $ui= get_userinfo();
136       $base= get_base_from_people($ui->dn);
137       $sysfilter= array( "depselect"       => $base,
138           "regex"           => "*");
139       session::set("sysfilter", $sysfilter);
140     }
142     /* Instanciate base selector */
143     $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
144     $this->baseSelector->setSubmitButton(false);
145     $this->baseSelector->setHeight(300);
146     $this->baseSelector->update(true);
147     
148     // Prepare lists
149     $this->memberListing = new sortableListing();
150     $this->memberListing->setDeleteable(true);
151     $this->memberListing->setInstantDelete(true);
152     $this->memberListing->setEditable(false);
153     $this->memberListing->setWidth("100%");
154     $this->memberListing->setHeight("300px");
155     $this->memberListing->setHeader(array("~",_("Name")));
156     $this->memberListing->setColspecs(array('20px','*','20px'));
157     $this->memberListing->setDefaultSortColumn(1);
159     $this->reload();
160   }
162   function AddDelMembership($NewMember = false){
164     if($NewMember){
166       /* Add member and force reload */
167       $this->member[$NewMember]= $NewMember;
169       $this->memberList[$NewMember]= $this->objcache[$NewMember];
170       unset ($this->objects[$NewMember]);
171       reset ($this->memberList);
172       $this->reload(); 
173     }else{
175         // Act on list modifications 
176         $this->memberListing->save_object();
177         $action = $this->memberListing->getAction();
178         if($action['action'] == 'delete'){
179             foreach($action['targets'] as $id){
180                 $value = $this->memberListing->getKey($id);
181                 $this->objects["$value"]= $this->memberList[$value];                  
182                 unset ($this->memberList["$value"]);                                  
183                 unset ($this->member["$value"]);                                      
184             }
185             $this->reload();
186         }
189       /* Add objects to group */
190       if (isset($_POST['objectSelect_save']) && $this->objectSelect instanceOf objectSelect){
191         $objects = $this->objectSelect->save();
192         $skipped = FALSE;
193         foreach($objects as $object){
194           $dn = $object['dn'];
196           // Do not add existing members twice!
197           if(isset($this->member["$dn"])){
198               continue;
199           }
201           $tmp = "";
202           foreach($this->memberList as $obj){
203             $tmp .= $obj['type'];
204           }
206           $type  = $this->getObjectType($object);
207           $name= $this->getObjectName($object);
209           /* Fill array */
210           if (isset($object["description"][0])){
211             $object= array("text" => "$name [".$object["description"][0]."]", "type" => "$type");
212           } elseif (isset($object["uid"][0])) {
213             $object= array("text" => "$name [".$object["uid"][0]."]", "type" => "$type");
214           } else {
215             $object= array("text" => "$name", "type" => "$type");
216           }
218           if(preg_match("/T/",$tmp) && $type == "W"){
219             $skipped =TRUE;
220           }elseif(preg_match("/W/",$tmp) && $type == "T"){
221             $skipped =TRUE;
222           }else{
224             $this->memberList["$dn"]= $object;
225             $this->member["$dn"]= $dn;
226             reset ($this->memberList);
227           }
228         }
229         if($skipped){
230           msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
231         }
232         $this->objectSelect= FALSE;
233         $this->dialog= FALSE;
234         $this->reload();
235       }
236     }
237   }
239   function execute()
240   {
241     /* Call parent execute */
242     plugin::execute();
244     if(!$this->view_logged){
245       $this->view_logged = TRUE;
246       new log("view","ogroups/".get_class($this),$this->dn);
247     }
250     /* Do we represent a valid group? */
251     if (!$this->is_account){
252       $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
253         msgPool::noValidExtension("object group")."</b>";
254       return ($display);
255     }
258     /* Load templating engine */
259     $smarty= get_smarty();
260     $smarty->assign("usePrototype", "true");
262     $tmp = $this->plInfo();
263     foreach($tmp['plProvidedAcls'] as $name => $translation){
264       $smarty->assign($name."ACL",$this->getacl($name));
265     }
267     /***********
268      * Trusts 
269      ***********/
271     // Handle trust mode dialog
272     $this->dialog = FALSE;
273     $trustModeDialog = $this->trustModeDialog->execute();
274     if($this->trustModeDialog->trustSelect){
275         $this->dialog = TRUE;
276         return($trustModeDialog);
277     }
278     $smarty->assign("trustModeDialog",$trustModeDialog);
280     /***********
281      * Ende - Trusts 
282      ***********/
285     /* Add objects? */
286     if (isset($_POST["edit_membership"])){
287       $this->objectSelect= new objectSelect($this->config, get_userinfo());
288     }
290     /* Add objects finished? */
291     if (isset($_POST["objectSelect_cancel"])){
292       $this->objectSelect= FALSE;
293     }
295     /* Manage object add dialog */
296     if ($this->objectSelect){
297       session::set('filterBlacklist', array('dn'=> $this->member));
298       $this->dialog= TRUE;
299       return($this->objectSelect->execute());
300     }
302     /* Bases / Departments */
303       if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
304         $this->base= $_POST['base'];
305       }
307     /* Assemble combine string */
308     if ($this->gosaGroupObjects == "[]"){
309       $smarty->assign("combinedObjects", _("none"));
310     } elseif (strlen($this->gosaGroupObjects) > 4){
311       $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
312     } else {
313       $conv= array(   "U" => _("users"),
314           "G" => _("groups"),
315           "A" => _("applications"),
316           "D" => _("departments"),
317           "S" => _("servers"),
318           "W" => _("workstations"),
319           "O" => _("winstations"),
320           "T" => _("terminals"),
321           "F" => _("phones"),
322           "P" => _("printers"));
324       $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
325       $p1= $conv[$type[0]];
326       error_reporting(0);
327       if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
328         $p2= $conv[$type[1]];
329         $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
330       } else {
331         $smarty->assign("combinedObjects", "$p1");
332       }
333       error_reporting(E_ALL | E_STRICT);
334     }
336     /* Assign variables */
337     $smarty->assign("base", $this->baseSelector->render());
341     $this->memberListing->setAcl($this->getacl("member"));
342     $data = $lData = array();
343     foreach($this->member as $key => $dn){
344         $image = 'images/lists/element.png';
345         $name = $dn;
346         if(isset($this->memberList[$dn])){
347             $name  = $this->memberList[$dn]['text'];
348             if(isset($this->typeToImage[$this->memberList[$dn]['type']])){
349                 $image = $this->typeToImage[$this->memberList[$dn]['type']];
350             }
351         }
352         $data[$key] = $dn;
353         $lData[$key] = array('data'=> array(image($image),$name));
354     }
355     $this->memberListing->setListData($data,$lData);
356     $this->memberListing->update();
357     $smarty->assign("memberList",$this->memberListing->render());
359     /* Fields */
360     foreach ($this->attributes as $val){
361       $smarty->assign("$val", $this->$val);
362     }
364     return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
365   }
368   function set_acl_base($base)
369   {
370     plugin::set_acl_base($base);
371     $this->trustModeDialog->set_acl_base($base);
372   }
375   /* Save data to object */
376   function save_object()
377   {
378     /* Save additional values for possible next step */
379     if (isset($_POST['ogroupedit'])){
381       $this->trustModeDialog->save_object();
383       /* Create a base backup and reset the
384          base directly after calling plugin::save_object();
385          Base will be set seperatly a few lines below */
386       $base_tmp = $this->base;
387       plugin::save_object();
388       $this->base = $base_tmp;
390       /* Refresh base */
391       if ($this->acl_is_moveable($this->base)){
392         if (!$this->baseSelector->update()) {
393           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
394         }
395         if ($this->base != $this->baseSelector->getBase()) {
396           $this->base= $this->baseSelector->getBase();
397           $this->is_modified= TRUE;
398         }
399       }
401     }
402   }
405   /* (Re-)Load objects */
406   function reload()
407   {
408     /*###########
409       Variable initialisation 
410       ###########*/
412     $this->objects                = array();
413     $this->ui                     = get_userinfo();
414     $filter                       = "";
415     $objectClasses                = array();
416     
417     $ogfilter               = session::get("ogfilter");
418     $regex                  = $ogfilter['regex'];
420     $ldap= $this->config->get_ldap_link();
421     $ldap->cd ($ogfilter['dselect']);
424     /*###########
425       Generate Filter 
426       ###########*/
428     $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount"    ,
429           "DN"=> get_people_ou()           ,"ACL" => "users"), 
430         "groups"          => array("OBJ"=>"group", "CLASS"=>"posixGroup"     ,
431           "DN"=> get_groups_ou('ogroupRDN') ,"ACL" => "groups"), 
432         "departments"     => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
433           "DN"=> ""                        ,"ACL" => "department"), 
434         "servers"         => array("OBJ"=>"servgeneric", "CLASS"=>"goServer"       ,
435           "DN"=> get_ou('serverRDN')        ,"ACL" => "server"),
436         "workstations"    => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
437           "DN"=> get_ou('workstationRDN')   ,"ACL" => "workstation"),
438         "winstations"     => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",        
439           "DN"=> get_ou('SAMBAMACHINEACCOUNTRDN')     ,"ACL" => "winstation"),
440         "terminals"       => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal"   ,
441           "DN"=> get_ou('terminalRDN')      ,"ACL" => "terminal"),
442         "printers"        => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter"    ,
443           "DN"=> get_ou('printerRDN')       ,"ACL" => "printer"),
444         "phones"          => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware"  ,
445           "DN"=> get_ou('phoneRDN')         ,"ACL" => "phone"));
448     /* Allow searching for applications, if we are not using release managed applications 
449       */
450     if(!$this->IsReleaseManagementActivated()){
451       $p_f[      "applications"]    = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
452           "DN"=> get_ou('applicationRDN')   ,"ACL" => "application"); 
453     }
454            
455     /*###########
456       Perform search for selected objectClasses & regex to fill list with objects   
457       ###########*/
459     $Get_list_flags = 0;
460     if($ogfilter['subtrees'] == "checked"){
461       $Get_list_flags |= GL_SUBSEARCH;
462     }    
464     foreach($p_f as $post_name => $data){
466       if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
468         if($ogfilter['subtrees']){
469           $base =  $ogfilter['dselect'];
470         }else{
471           $base =  $data['DN'].$ogfilter['dselect'];
472         }
473    
474          
475         $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
476         $res    = get_list($filter, $data['ACL']  , $base, 
477                     array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
479         /* fetch results and append them to the list */
480         foreach($res as $attrs){
482           /* Skip workstations which are already assigned to an object group.
483            */
484           if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]"){
485             if(in_array($attrs['dn'],$this->used_workstations)){
486               continue;
487             }
488           }
490           $type= $this->getObjectType($attrs);
491           $name= $this->getObjectName($attrs);
493           /* Fill array */
494           if (isset($attrs["description"][0])){
495             $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
496           } elseif (isset($attrs["uid"][0])) {
497             $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
498           } else {
499             $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
500           }
501         }
502       }
503     }
504     reset ($this->objects);
506     
507     /*###########
508       Build member list and try to detect obsolete entries 
509       ###########*/
511     $this->memberList = array();
512   
513     /* Walk through all single member entry */
514     foreach($this->member as $dn){
516       /* The dn for the current member can't be resolved 
517          it seams that this entry was removed 
518        */ 
519       /* Try to resolv the entry again, if it still fails, display error msg */
520       $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
522       /* It has failed, add entry with type flag I (Invalid)*/
523       if (!$ldap->success()){
524         $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".LDAP::fix($dn),"type" => "I");
526       } else {
528         /* Append this entry to our all object list */
530         /* Fetch object */
531         $attrs= $ldap->fetch();
533         $type= $this->getObjectType($attrs);
534         $name= $this->getObjectName($attrs);
536         if (isset($attrs["description"][0])){
537           $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
538         } elseif (isset($attrs["uid"][0])) {
539           $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
540         } else {
541           $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
542         }
543         $this->objcache[$attrs["dn"]]['objectClass']  = $attrs['objectClass'];
545         if(isset($attrs['macAddress'][0])){
546           $this->objcache[$attrs["dn"]]['macAddress']  = $attrs['macAddress'][0];
547         }else{
548           $this->objcache[$attrs["dn"]]['macAddress']  = "";
549         }
551         if(isset($attrs['uid'])){
552           $this->objcache[$attrs["dn"]]['uid']          = $attrs['uid'];
553         }
555         /* Fill array */
556         if (isset($attrs["description"][0])){
557           $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
558         } else {
559           $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
560         }
562         $this->memberList[$dn]= $this->objects[$attrs["dn"]];
563       }
564     }
565     reset ($this->memberList);
567     /* Assemble types of currently combined objects */
568     $objectTypes= "";
569     foreach ($this->memberList as $dn => $desc){
571       /* Invalid object? */
572       if ($desc['type'] == 'I'){
573         continue;
574       }
576       /* Fine. Add to list. */
577       if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
578         $objectTypes.= $desc['type'];
579       }
580     }
581     $this->gosaGroupObjects= "[$objectTypes]";
582   }
585   function getObjectType($attrs)
586   {
587     $type= "I";
589     foreach($this->typeToClass as $index => $class){
590       if (in_array($class, $attrs['objectClass'])){
591         $type= $index;
592         break;
593       }
594     }
595     return ($type);
596   }
599   function getObjectName($attrs)
600   {
601     /* Person? */
602     $name =""; 
603     if (in_array('gosaAccount', $attrs['objectClass'])){
604       if(isset($attrs['sn']) && isset($attrs['givenName'])){
605         $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
606       } else {
607         $name= $attrs['uid'][0];
608       }
609     } else {
610       if(isset($attrs["cn"][0])) {
611         $name= $attrs['cn'][0];
612       } else {
613         $name= $attrs['ou'][0];
614       }
615     }
617     return ($name);
618   }
621   function check()
622   {
623     /* Call common method to give check the hook */
624     $message= plugin::check();
626     /* Permissions for that base? */
627     if ($this->base != ""){
628       $new_dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
629     } else {
630       $new_dn= $this->dn;
631     }
633     /* Check if we have workstations assigned, that are already assigned to
634         another object group.  */
635     if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
636       $test =array_intersect($this->used_workstations,$this->member); 
637       if(count($test)){
638         $str = "";
639         foreach($test as $dn){
640           $str .= "<li>".$dn."</li>";
641         }
642         $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
643       }
644     }
646     $ldap = $this->config->get_ldap_link();
647     if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
648       $ldap->cat ($new_dn, array('dn'));
649     }
650     
651     if($ldap->count() !=0){
652       $message[]= msgPool::duplicated(_("Name"));
653     } 
655     // Check if a wrong base was supplied
656     if(!$this->baseSelector->checkLastBaseUpdate()){
657       $message[]= msgPool::check_base();;
658     } 
660     /* Set new acl base */
661     if($this->dn == "new") {
662       $this->set_acl_base($this->base);
663     }
665     /* must: cn */
666     if ($this->cn == ""){
667       $message[]= msgPool::required(_("Name"));
668     }
670     if (preg_match('/[=,+<>#;]/', $this->cn)) { 
671       $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^=+,<>#;]/"); 
672     } 
674     /* To many different object types? */
675     if (strlen($this->gosaGroupObjects) > 4){
676       $message[]= _("You can combine two different object types at maximum, only!");
677     }
679     /* Check if we are allowed to create or move this object 
680      */
681     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
682       $message[] = msgPool::permCreate();
683     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
684       $message[] = msgPool::permMove();
685     }
687     return ($message);
688   }
691   /* Save to LDAP */
692   function save()
693   {
694     plugin::save();
696     /* Move members to target array */
697     $this->attrs['member'] =array();
698     foreach ($this->member as $key => $desc){
699       $this->attrs['member'][]= LDAP::fix($key);
700     }
702     $ldap= $this->config->get_ldap_link();
704     /* New accounts need proper 'dn', propagate it to remaining objects */
705     if ($this->dn == 'new'){
706       $this->dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
707     }
709     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
710        new entries. So do a check first... */
711     $ldap->cat ($this->dn, array('dn'));
712     if ($ldap->fetch()){
713       /* Modify needs array() to remove values :-( */
714       if (!count ($this->member)){
715         $this->attrs['member']= array();
716       }
717       $mode= "modify";
719     } else {
720       $mode= "add";
721       $ldap->cd($this->config->current['BASE']);
722       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
723     }
726     /* Write back to ldap */
727     $ldap->cd($this->dn);
728     $this->cleanup();
729     $ldap->$mode($this->attrs);
731     if($mode == "add"){
732       new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
733     }else{
734       new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
735     }
737     /* Trigger post signal */
738     $this->handle_post_events($mode);
740     $ret= 0;
741     if (!$ldap->success()){
742       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
743       $ret= 1;
744     }else{
745       $this->trustModeDialog->dn = $this->dn;
746       $this->trustModeDialog->save();
747     }
749     return ($ret);
750   }
752   function remove_from_parent()
753   {
754     plugin::remove_from_parent();
756     $ldap= $this->config->get_ldap_link();
757     $ldap->rmdir($this->dn);
758     if (!$ldap->success()){
759       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
760     }
762     new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
764     /* Trigger remove signal */
765     $this->handle_post_events("remove");
766   }
768   
769   function PrepareForCopyPaste($source)
770   {
771     plugin::PrepareForCopyPaste($source);
773     /* Reload tabs */
774     $this->parent->reload($this->gosaGroupObjects );
775     
776     $this->trustModeDialog->PrepareForCopyPaste($source);
777    
778     /* Reload plugins */ 
779     foreach($this->parent->by_object as $name => $class ){
780       if(get_class($this) != $name) {
781         $this->parent->by_object[$name]->PrepareForCopyPaste($source);
782       }
783     }
785     $source_o = new ogroup ($this->config, $source['dn']);
786     foreach(array("member","gosaGroupObjects")  as $attr){
787       $this->$attr = $source_o->$attr;
788     }
789   }
792   function getCopyDialog()
793   {
794     $smarty = get_smarty();
795     $smarty->assign("cn",     $this->cn);
796     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
797     $ret = array();
798     $ret['string'] = $str;
799     $ret['status'] = "";
800     return($ret);
801   }
803   function saveCopyDialog()
804   {
805     if(isset($_POST['cn'])){
806       $this->cn = $_POST['cn'];
807     }
808   }
811   function IsReleaseManagementActivated()
812   {
813     /* Check if we should enable the release selection */
814     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
815     if(!empty($tmp)){
816       return(true);
817     }
818     return(false);
819   }
822   static function plInfo()
823   {
824     return (array(
825           "plShortName"   => _("Generic"),
826           "plDescription" => _("Object group generic"),
827           "plSelfModify"  => FALSE,
828           "plDepends"     => array(),
829           "plPriority"    => 1,
830           "plSection"     => array("administration"),
831           "plCategory"    => array("ogroups" => array("description"  => _("Object groups"),
832                                                       "objectClass"  => "gosaGroupOfNames")),
833           "plProvidedAcls"=> array(
834             "cn"                => _("Name"),
835             "base"              => _("Base"),
836             "description"       => _("Description"),
837             "accessTo"          => _("Sytem trust"),
838             "member"            => _("Member"))
839           ));
840   }
843 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
844 ?>