Code

Updated ACL usage
[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->setEditable(false);
152     $this->memberListing->setWidth("100%");
153     $this->memberListing->setHeight("300px");
154     $this->memberListing->setHeader(array("~",_("Name")));
155     $this->memberListing->setColspecs(array('20px','*','20px'));
156     $this->memberListing->setDefaultSortColumn(1);
158     $this->reload();
159   }
161   function AddDelMembership($NewMember = false){
163     if($NewMember){
165       /* Add member and force reload */
166       $this->member[$NewMember]= $NewMember;
168       $this->memberList[$NewMember]= $this->objcache[$NewMember];
169       unset ($this->objects[$NewMember]);
170       reset ($this->memberList);
171       $this->reload(); 
172     }else{
174         // Act on list modifications 
175         $this->memberListing->save_object();
176         $action = $this->memberListing->getAction();
177         if($action['action'] == 'delete'){
178             foreach($action['targets'] as $id){
179                 $value = $this->memberListing->getKey($id);
180                 $this->objects["$value"]= $this->memberList[$value];                  
181                 unset ($this->memberList["$value"]);                                  
182                 unset ($this->member["$value"]);                                      
183             }
184             $this->reload();
185         }
188       /* Add objects to group */
189       if (isset($_POST['objectSelect_save']) && $this->objectSelect instanceOf objectSelect){
190         $objects = $this->objectSelect->save();
191         $skipped = FALSE;
192         foreach($objects as $object){
194           $tmp = "";
195           foreach($this->memberList as $obj){
196             $tmp .= $obj['type'];
197           }
199           $type  = $this->getObjectType($object);
200           $name= $this->getObjectName($object);
201           $dn = $object['dn'];
203           /* Fill array */
204           if (isset($object["description"][0])){
205             $object= array("text" => "$name [".$object["description"][0]."]", "type" => "$type");
206           } elseif (isset($object["uid"][0])) {
207             $object= array("text" => "$name [".$object["uid"][0]."]", "type" => "$type");
208           } else {
209             $object= array("text" => "$name", "type" => "$type");
210           }
212           if(preg_match("/T/",$tmp) && $type == "W"){
213             $skipped =TRUE;
214           }elseif(preg_match("/W/",$tmp) && $type == "T"){
215             $skipped =TRUE;
216           }else{
218             $this->memberList["$dn"]= $object;
219             $this->member["$dn"]= $dn;
220             reset ($this->memberList);
221           }
222         }
223         if($skipped){
224           msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
225         }
226         $this->objectSelect= FALSE;
227         $this->dialog= FALSE;
228         $this->reload();
229       }
230     }
231   }
233   function execute()
234   {
235     /* Call parent execute */
236     plugin::execute();
238     if(!$this->view_logged){
239       $this->view_logged = TRUE;
240       new log("view","ogroups/".get_class($this),$this->dn);
241     }
244     /* Do we represent a valid group? */
245     if (!$this->is_account){
246       $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
247         msgPool::noValidExtension("object group")."</b>";
248       return ($display);
249     }
252     /* Load templating engine */
253     $smarty= get_smarty();
254     $smarty->assign("usePrototype", "true");
256     $tmp = $this->plInfo();
257     foreach($tmp['plProvidedAcls'] as $name => $translation){
258       $smarty->assign($name."ACL",$this->getacl($name));
259     }
261     /***********
262      * Trusts 
263      ***********/
265     // Handle trust mode dialog
266     $this->dialog = FALSE;
267     $trustModeDialog = $this->trustModeDialog->execute();
268     if($this->trustModeDialog->trustSelect){
269         $this->dialog = TRUE;
270         return($trustModeDialog);
271     }
272     $smarty->assign("trustModeDialog",$trustModeDialog);
274     /***********
275      * Ende - Trusts 
276      ***********/
279     /* Add objects? */
280     if (isset($_POST["edit_membership"])){
281       $this->objectSelect= new objectSelect($this->config, get_userinfo());
282     }
284     /* Add objects finished? */
285     if (isset($_POST["objectSelect_cancel"])){
286       $this->objectSelect= FALSE;
287     }
289     /* Manage object add dialog */
290     if ($this->objectSelect){
291       session::set('filterBlacklist', array('dn'=> $this->member));
292       $this->dialog= TRUE;
293       return($this->objectSelect->execute());
294     }
296     /* Bases / Departments */
297       if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
298         $this->base= $_POST['base'];
299       }
301     /* Assemble combine string */
302     if ($this->gosaGroupObjects == "[]"){
303       $smarty->assign("combinedObjects", _("none"));
304     } elseif (strlen($this->gosaGroupObjects) > 4){
305       $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
306     } else {
307       $conv= array(   "U" => _("users"),
308           "G" => _("groups"),
309           "A" => _("applications"),
310           "D" => _("departments"),
311           "S" => _("servers"),
312           "W" => _("workstations"),
313           "O" => _("winstations"),
314           "T" => _("terminals"),
315           "F" => _("phones"),
316           "P" => _("printers"));
318       $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
319       $p1= $conv[$type[0]];
320       error_reporting(0);
321       if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
322         $p2= $conv[$type[1]];
323         $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
324       } else {
325         $smarty->assign("combinedObjects", "$p1");
326       }
327       error_reporting(E_ALL | E_STRICT);
328     }
330     /* Assign variables */
331     $smarty->assign("base", $this->baseSelector->render());
335     $this->memberListing->setAcl($this->getacl("member"));
336     $data = $lData = array();
337     foreach($this->member as $key => $dn){
338         $image = 'images/lists/element.png';
339         $name = $dn;
340         if(isset($this->memberList[$dn])){
341             $name  = $this->memberList[$dn]['text'];
342             if(isset($this->typeToImage[$this->memberList[$dn]['type']])){
343                 $image = $this->typeToImage[$this->memberList[$dn]['type']];
344             }
345         }
346         $data[$key] = $dn;
347         $lData[$key] = array('data'=> array(image($image),$name));
348     }
349     $this->memberListing->setListData($data,$lData);
350     $this->memberListing->update();
351     $smarty->assign("memberList",$this->memberListing->render());
353     /* Fields */
354     foreach ($this->attributes as $val){
355       $smarty->assign("$val", $this->$val);
356     }
358     return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
359   }
362   function set_acl_base($base)
363   {
364     plugin::set_acl_base($base);
365     $this->trustModeDialog->set_acl_base($base);
366   }
369   /* Save data to object */
370   function save_object()
371   {
372     /* Save additional values for possible next step */
373     if (isset($_POST['ogroupedit'])){
375       $this->trustModeDialog->save_object();
377       /* Create a base backup and reset the
378          base directly after calling plugin::save_object();
379          Base will be set seperatly a few lines below */
380       $base_tmp = $this->base;
381       plugin::save_object();
382       $this->base = $base_tmp;
384       /* Refresh base */
385       if ($this->acl_is_moveable($this->base)){
386         if (!$this->baseSelector->update()) {
387           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
388         }
389         if ($this->base != $this->baseSelector->getBase()) {
390           $this->base= $this->baseSelector->getBase();
391           $this->is_modified= TRUE;
392         }
393       }
395     }
396   }
399   /* (Re-)Load objects */
400   function reload()
401   {
402     /*###########
403       Variable initialisation 
404       ###########*/
406     $this->objects                = array();
407     $this->ui                     = get_userinfo();
408     $filter                       = "";
409     $objectClasses                = array();
410     
411     $ogfilter               = session::get("ogfilter");
412     $regex                  = $ogfilter['regex'];
414     $ldap= $this->config->get_ldap_link();
415     $ldap->cd ($ogfilter['dselect']);
418     /*###########
419       Generate Filter 
420       ###########*/
422     $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount"    ,
423           "DN"=> get_people_ou()           ,"ACL" => "users"), 
424         "groups"          => array("OBJ"=>"group", "CLASS"=>"posixGroup"     ,
425           "DN"=> get_groups_ou('ogroupRDN') ,"ACL" => "groups"), 
426         "departments"     => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
427           "DN"=> ""                        ,"ACL" => "department"), 
428         "servers"         => array("OBJ"=>"servgeneric", "CLASS"=>"goServer"       ,
429           "DN"=> get_ou('serverRDN')        ,"ACL" => "server"),
430         "workstations"    => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
431           "DN"=> get_ou('workstationRDN')   ,"ACL" => "workstation"),
432         "winstations"     => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",        
433           "DN"=> get_ou('SAMBAMACHINEACCOUNTRDN')     ,"ACL" => "winstation"),
434         "terminals"       => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal"   ,
435           "DN"=> get_ou('terminalRDN')      ,"ACL" => "terminal"),
436         "printers"        => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter"    ,
437           "DN"=> get_ou('printerRDN')       ,"ACL" => "printer"),
438         "phones"          => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware"  ,
439           "DN"=> get_ou('phoneRDN')         ,"ACL" => "phone"));
442     /* Allow searching for applications, if we are not using release managed applications 
443       */
444     if(!$this->IsReleaseManagementActivated()){
445       $p_f[      "applications"]    = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
446           "DN"=> get_ou('applicationRDN')   ,"ACL" => "application"); 
447     }
448            
449     /*###########
450       Perform search for selected objectClasses & regex to fill list with objects   
451       ###########*/
453     $Get_list_flags = 0;
454     if($ogfilter['subtrees'] == "checked"){
455       $Get_list_flags |= GL_SUBSEARCH;
456     }    
458     foreach($p_f as $post_name => $data){
460       if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
462         if($ogfilter['subtrees']){
463           $base =  $ogfilter['dselect'];
464         }else{
465           $base =  $data['DN'].$ogfilter['dselect'];
466         }
467    
468          
469         $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
470         $res    = get_list($filter, $data['ACL']  , $base, 
471                     array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
473         /* fetch results and append them to the list */
474         foreach($res as $attrs){
476           /* Skip workstations which are already assigned to an object group.
477            */
478           if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]"){
479             if(in_array($attrs['dn'],$this->used_workstations)){
480               continue;
481             }
482           }
484           $type= $this->getObjectType($attrs);
485           $name= $this->getObjectName($attrs);
487           /* Fill array */
488           if (isset($attrs["description"][0])){
489             $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
490           } elseif (isset($attrs["uid"][0])) {
491             $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
492           } else {
493             $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
494           }
495         }
496       }
497     }
498     reset ($this->objects);
500     
501     /*###########
502       Build member list and try to detect obsolete entries 
503       ###########*/
505     $this->memberList = array();
506   
507     /* Walk through all single member entry */
508     foreach($this->member as $dn){
510       /* The dn for the current member can't be resolved 
511          it seams that this entry was removed 
512        */ 
513       /* Try to resolv the entry again, if it still fails, display error msg */
514       $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
516       /* It has failed, add entry with type flag I (Invalid)*/
517       if (!$ldap->success()){
518         $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".LDAP::fix($dn),"type" => "I");
520       } else {
522         /* Append this entry to our all object list */
524         /* Fetch object */
525         $attrs= $ldap->fetch();
527         $type= $this->getObjectType($attrs);
528         $name= $this->getObjectName($attrs);
530         if (isset($attrs["description"][0])){
531           $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
532         } elseif (isset($attrs["uid"][0])) {
533           $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
534         } else {
535           $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
536         }
537         $this->objcache[$attrs["dn"]]['objectClass']  = $attrs['objectClass'];
539         if(isset($attrs['macAddress'][0])){
540           $this->objcache[$attrs["dn"]]['macAddress']  = $attrs['macAddress'][0];
541         }else{
542           $this->objcache[$attrs["dn"]]['macAddress']  = "";
543         }
545         if(isset($attrs['uid'])){
546           $this->objcache[$attrs["dn"]]['uid']          = $attrs['uid'];
547         }
549         /* Fill array */
550         if (isset($attrs["description"][0])){
551           $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
552         } else {
553           $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
554         }
556         $this->memberList[$dn]= $this->objects[$attrs["dn"]];
557       }
558     }
559     reset ($this->memberList);
561     /* Assemble types of currently combined objects */
562     $objectTypes= "";
563     foreach ($this->memberList as $dn => $desc){
565       /* Invalid object? */
566       if ($desc['type'] == 'I'){
567         continue;
568       }
570       /* Fine. Add to list. */
571       if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
572         $objectTypes.= $desc['type'];
573       }
574     }
575     $this->gosaGroupObjects= "[$objectTypes]";
576   }
579   function getObjectType($attrs)
580   {
581     $type= "I";
583     foreach($this->typeToClass as $index => $class){
584       if (in_array($class, $attrs['objectClass'])){
585         $type= $index;
586         break;
587       }
588     }
589     return ($type);
590   }
593   function getObjectName($attrs)
594   {
595     /* Person? */
596     $name =""; 
597     if (in_array('gosaAccount', $attrs['objectClass'])){
598       if(isset($attrs['sn']) && isset($attrs['givenName'])){
599         $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
600       } else {
601         $name= $attrs['uid'][0];
602       }
603     } else {
604       if(isset($attrs["cn"][0])) {
605         $name= $attrs['cn'][0];
606       } else {
607         $name= $attrs['ou'][0];
608       }
609     }
611     return ($name);
612   }
615   function check()
616   {
617     /* Call common method to give check the hook */
618     $message= plugin::check();
620     /* Permissions for that base? */
621     if ($this->base != ""){
622       $new_dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
623     } else {
624       $new_dn= $this->dn;
625     }
627     /* Check if we have workstations assigned, that are already assigned to
628         another object group.  */
629     if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
630       $test =array_intersect($this->used_workstations,$this->member); 
631       if(count($test)){
632         $str = "";
633         foreach($test as $dn){
634           $str .= "<li>".$dn."</li>";
635         }
636         $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
637       }
638     }
640     $ldap = $this->config->get_ldap_link();
641     if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
642       $ldap->cat ($new_dn, array('dn'));
643     }
644     
645     if($ldap->count() !=0){
646       $message[]= msgPool::duplicated(_("Name"));
647     } 
649     // Check if a wrong base was supplied
650     if(!$this->baseSelector->checkLastBaseUpdate()){
651       $message[]= msgPool::check_base();;
652     } 
654     /* Set new acl base */
655     if($this->dn == "new") {
656       $this->set_acl_base($this->base);
657     }
659     /* must: cn */
660     if ($this->cn == ""){
661       $message[]= msgPool::required(_("Name"));
662     }
664     if (preg_match('/[=,+<>#;]/', $this->cn)) { 
665       $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^=+,<>#;]/"); 
666     } 
668     /* To many different object types? */
669     if (strlen($this->gosaGroupObjects) > 4){
670       $message[]= _("You can combine two different object types at maximum, only!");
671     }
673     /* Check if we are allowed to create or move this object 
674      */
675     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
676       $message[] = msgPool::permCreate();
677     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
678       $message[] = msgPool::permMove();
679     }
681     return ($message);
682   }
685   /* Save to LDAP */
686   function save()
687   {
688     plugin::save();
690     /* Move members to target array */
691     $this->attrs['member'] =array();
692     foreach ($this->member as $key => $desc){
693       $this->attrs['member'][]= LDAP::fix($key);
694     }
696     $ldap= $this->config->get_ldap_link();
698     /* New accounts need proper 'dn', propagate it to remaining objects */
699     if ($this->dn == 'new'){
700       $this->dn= 'cn='.$this->cn.','.get_ou('ogroupRDN').$this->base;
701     }
703     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
704        new entries. So do a check first... */
705     $ldap->cat ($this->dn, array('dn'));
706     if ($ldap->fetch()){
707       /* Modify needs array() to remove values :-( */
708       if (!count ($this->member)){
709         $this->attrs['member']= array();
710       }
711       $mode= "modify";
713     } else {
714       $mode= "add";
715       $ldap->cd($this->config->current['BASE']);
716       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
717     }
720     /* Write back to ldap */
721     $ldap->cd($this->dn);
722     $this->cleanup();
723     $ldap->$mode($this->attrs);
725     if($mode == "add"){
726       new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
727     }else{
728       new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
729     }
731     /* Trigger post signal */
732     $this->handle_post_events($mode);
734     $ret= 0;
735     if (!$ldap->success()){
736       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
737       $ret= 1;
738     }else{
739       $this->trustModeDialog->dn = $this->dn;
740       $this->trustModeDialog->save();
741     }
743     return ($ret);
744   }
746   function remove_from_parent()
747   {
748     plugin::remove_from_parent();
750     $ldap= $this->config->get_ldap_link();
751     $ldap->rmdir($this->dn);
752     if (!$ldap->success()){
753       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
754     }
756     new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
758     /* Trigger remove signal */
759     $this->handle_post_events("remove");
760   }
762   
763   function PrepareForCopyPaste($source)
764   {
765     plugin::PrepareForCopyPaste($source);
767     /* Reload tabs */
768     $this->parent->reload($this->gosaGroupObjects );
769     
770     $this->trustModeDialog->PrepareForCopyPaste($source);
771    
772     /* Reload plugins */ 
773     foreach($this->parent->by_object as $name => $class ){
774       if(get_class($this) != $name) {
775         $this->parent->by_object[$name]->PrepareForCopyPaste($source);
776       }
777     }
779     $source_o = new ogroup ($this->config, $source['dn']);
780     foreach(array("member","gosaGroupObjects")  as $attr){
781       $this->$attr = $source_o->$attr;
782     }
783   }
786   function getCopyDialog()
787   {
788     $smarty = get_smarty();
789     $smarty->assign("cn",     $this->cn);
790     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
791     $ret = array();
792     $ret['string'] = $str;
793     $ret['status'] = "";
794     return($ret);
795   }
797   function saveCopyDialog()
798   {
799     if(isset($_POST['cn'])){
800       $this->cn = $_POST['cn'];
801     }
802   }
805   function IsReleaseManagementActivated()
806   {
807     /* Check if we should enable the release selection */
808     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
809     if(!empty($tmp)){
810       return(true);
811     }
812     return(false);
813   }
816   static function plInfo()
817   {
818     return (array(
819           "plShortName"   => _("Generic"),
820           "plDescription" => _("Object group generic"),
821           "plSelfModify"  => FALSE,
822           "plDepends"     => array(),
823           "plPriority"    => 1,
824           "plSection"     => array("administration"),
825           "plCategory"    => array("ogroups" => array("description"  => _("Object groups"),
826                                                       "objectClass"  => "gosaGroupOfNames")),
827           "plProvidedAcls"=> array(
828             "cn"                => _("Name"),
829             "base"              => _("Base"),
830             "description"       => _("Description"),
831             "accessTo"          => _("Sytem trust"),
832             "member"            => _("Member"))
833           ));
834   }
837 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
838 ?>