Code

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