Code

Fixed tab creation on copy & paste
[gosa.git] / plugins / admin / ogroups / tabs_ogroups.inc
1 <?php
3 class ogrouptabs extends tabs
4 {
5   var $base= "";
6   var $acl_category; 
7  
8   function reload($dd){
9     $objects= preg_replace('/[\[\]]/', '', $dd);
10     
11     /* If there is a phonequeue,
12      * but there is no user left with goPhoneAccount ... remove it.
13      */
14     $usePhoneTab = false;
15     foreach($this->by_object['ogroup']->memberList as $dn => $val){
16       if(isset($val['objectClass'])){
17         if(in_array("goFonAccount",$val['objectClass'])){
18           $usePhoneTab = true;
19         }
20       }
21     }
22     if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
23       $this->by_object['phonequeue']->remove_from_parent();
24       unset($this->by_object['phonequeue']);
25       unset($this->by_name['phonequeue']);
26     }
27     /* Remove mail group if there is no user anymore */
28     if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
29       $this->by_object['mailogroup']->remove_from_parent();
30       unset($this->by_object['mailogroup']);
31       unset($this->by_name['mailogroup']);
32     }
33     
34     /* Remove terminal group, if theres no terminal left in the object list */
35     if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
36       $this->by_object['termgroup']->remove_from_parent();
37       unset($this->by_object['termgroup']);
38       unset($this->by_name['termgroup']);
39     }
40     
41     /* Remove ws tabs, if theres no ws left in the object list */
42     if((!preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
43       $this->by_object['workservice']->remove_from_parent();
44       unset($this->by_object['workservice']);
45       unset($this->by_name['workservice']);
46       $this->by_object['workstartup']->remove_from_parent();
47       unset($this->by_object['workstartup']);
48       unset($this->by_name['workstartup']);
49       $this->by_object['faiSummary']->remove_from_parent();
50       unset($this->by_object['faiSummary']);
51       unset($this->by_name['faiSummary']);
52     }
53   
54     /* Create goPhoneAccount if theres an user with goPhoneAccount
55      * but only if there is currently no queue enabled.
56      */
57     if(!isset($this->by_object['phonequeue'])){
58       foreach($this->by_object['ogroup']->memberList as $dn => $val){
59         if(isset($val['objectClass'])){
60           if(in_array("goFonAccount",$val['objectClass'])){
61             require_once("class_phonequeue.inc");
62             $this->by_name['phonequeue']= _("Phone queue");
63             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
64             $this->by_object['phonequeue']->parent= &$this;
65           }
66         }
67       }
68     }
70     /* Add mail group tab , if there is curerntly no mail tab defined */ 
71     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
72       if(isset($this->config->current['MAILMETHOD'])){
73         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
74           require_once("class_mailogroup.inc");
75           $this->by_name['mailogroup']= _("Mail");
76           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
77           $this->by_object['mailogroup']->parent= &$this;
78         }
79       }
80     }
82     /* Add Terminal tab */
83     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
84       require_once("class_termgroup.inc");
85       if(!isset($this->by_object['termgroup'])){
86         $this->by_name['termgroup']= _("System");
87         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
88         $this->by_object['termgroup']->inheritTimeServer = false;
89         $this->by_object['termgroup']->parent= &$this;
90       }
91     }
92     
93     /* Add Workstation tabs */
94     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
95       if(!isset($this->by_object['workstartup'])){
96         $this->by_name['workstartup']= _("Startup");
97         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
98         $this->by_object['workstartup']->parent= &$this;
99         $this->by_name['workservice']= _("Devices");
100         $this->by_object['workservice']= new workservice($this->config, $this->dn);
101         $this->by_object['workservice']->inheritTimeServer = false;
102         $this->by_object['workservice']->parent= &$this;
103         $this->by_name['faiSummary']= _("Summary");
104         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
105         $this->by_object['faiSummary']->parent= &$this;
106       }
107     }
109     /* Move reference tab to second position from right */
110     if(isset($this->by_name['acl'])){
111       $tmp = $this->by_name['acl'];
112       unset($this->by_name['acl']);
113       $this->by_name['acl'] = $tmp;
114     }
115   
116     /* Move reference tab to last position*/
117     if(isset($this->by_name['reference'])){
118       $tmp = $this->by_name['reference'];
119       unset($this->by_name['reference']);
120       $this->by_name['reference'] = $tmp;
121     }
123     /* Reset acls */
124     $this->set_acl_base($this->base);
125     foreach($this->by_object as $name => $obj){
126       $this->by_object[$name]->set_acl_category($this->acl_category);
127     }
128   }
130   function execute(){
131     $str = "";
132     $this->by_object['ogroup']->AddDelMembership();
133     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
134     $str .= tabs::execute();
135     return ( $str);
136   }  
138   function ogrouptabs($config, $data, $dn,$category ="ogroups")
139   {
141     tabs::tabs($config, $data, $dn, $category);
142     $this->base= $this->by_object['ogroup']->base;
143     $this->acl_category = $category;
145     /* Insert extra tabs for several object types - if present */
147     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
148     
149     for ($n= 0; $n<strlen($objects); $n++){
150       switch ($objects[$n]){
151         case "T":
152           /* Add a terminal tab */
153           require_once("class_termgroup.inc");
154           $this->by_name['termgroup']= _("Terminals");
155           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
156           $this->by_object['termgroup']->parent= &$this;
158           break;
160           case "U":
161             /* Append a PhoneQueue, if objectClass = goFonAccount */
162             $use = false;
163           foreach($this->by_object['ogroup']->memberList as $dn => $val){
164             if(isset($val['objectClass'])){
165               if(in_array("goFonAccount",$val['objectClass'])){
166                 $use = true; 
167               }
168             }
169           }
171           /* We found goFonAccount in users objectClasses*/
172           if($use){
173             require_once("class_phonequeue.inc");
174             $this->by_name['phonequeue']= _("Phone queue");
175             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
176             $this->by_object['phonequeue']->parent= &$this;
178           } 
179  
180           /* Add a user tab used for mail distribution lists */
181           if(isset($this->config->current['MAILMETHOD'])){
182             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
183               require_once("class_mailogroup.inc");
184               $this->by_name['mailogroup']= _("Mail");
185               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
186               $this->by_object['mailogroup']->parent= &$this;
187             }
188           }
190           break;
191       }
192     }
194     /* Add references/acls/snapshots */
195     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
196     $this->addSpecialTabs();
197   }
200   function check()
201   {
202     return (tabs::check(FALSE));
203   }
206   function save_object($save_current= FALSE)
207   {
208     tabs::save_object($save_current);
210     /* Update reference, transfer variables */
211     $baseobject= $this->by_object['ogroup'];
212     foreach ($this->by_object as $name => $obj){
214       /* Don't touch base object */
215       if ($name != 'ogroup'){
216         $obj->parent    = &$this;
217         $obj->uid       = $baseobject->uid;
218         $obj->cn        = $baseobject->cn;
219         $obj->sn        = $baseobject->uid;
220         $obj->givenName = $baseobject->uid;
221         $this->by_object[$name]= $obj;
222       }
224       /* Update parent in base object */
225       $this->by_object['ogroup']->parent= &$this;
226     }
227   }
230   function save()
231   {
232     $baseobject= $this->by_object['ogroup'];
234     /* Check for new 'dn', in order to propagate the
235        'dn' to all plugins */
236     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
238     /* Move group? */
239     if ($this->dn != $new_dn){
241       /* Write entry on new 'dn' */
242       if ($this->dn != "new"){
243         $baseobject->move($this->dn, $new_dn);
244         $this->by_object['ogroup']= $baseobject;
245       }
247       /* Happen to use the new one */
248       $this->dn= $new_dn;
249     }
251     if ($this->dn == "new"){
252       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
253     }
255     tabs::save();
257     /* Fix tagging if needed */
258                 $baseobject->dn= $new_dn;
259     $baseobject->handle_object_tagging();
260   }
262   function getCopyDialog()
263   {
264     $this->reload($this->by_object['ogroup']->gosaGroupObjects); 
265     return(tabs::getCopyDialog());
266   }
269 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
270 ?>