Code

Initial scalix plugin
[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     $o_cache = $this->by_object['ogroup']->objcache;
15     foreach($this->by_object['ogroup']->memberList as $dn => $val){
16       if(isset($o_cache[$dn]['objectClass'])){
17         if(in_array("goFonAccount",$o_cache[$dn]['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     $o_cache = $this->by_object['ogroup']->objcache;
58     if(!isset($this->by_object['phonequeue'])){
59       foreach($this->by_object['ogroup']->memberList as $dn => $val){
60         if(isset($o_cache[$dn]['objectClass'])){
61           if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
62             require_once("class_phonequeue.inc");
63             $this->by_name['phonequeue']= _("Phone queue");
64             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
65             $this->by_object['phonequeue']->acl = "#all#";
66             $this->by_object['phonequeue']->parent= &$this;
67           }
68         }
69       }
70     }
72     /* Add mail group tab , if there is curerntly no mail tab defined */ 
73     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
74       if(isset($this->config->current['MAILMETHOD'])){
75         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
76           require_once("class_mailogroup.inc");
77           $this->by_name['mailogroup']= _("Mail");
78           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
79           $this->by_object['mailogroup']->acl = "#all#";
80           $this->by_object['mailogroup']->parent= &$this;
81         }
82       }
83     }
85     /* Add Terminal tab */
86     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
87       require_once("class_termgroup.inc");
88       if(!isset($this->by_object['termgroup'])){
89         $this->by_name['termgroup']= _("System");
90         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
91         $this->by_object['termgroup']->acl = "#all#";
92         $this->by_object['termgroup']->inheritTimeServer = false;
93         $this->by_object['termgroup']->parent= &$this;
94       }
95     }
96     
97     /* Add Workstation tabs */
98     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
99       if(!isset($this->by_object['workstartup'])){
100         $this->by_name['workstartup']= _("Startup");
101         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
102         $this->by_object['workstartup']->acl = "#all#";
103         $this->by_object['workstartup']->parent= &$this;
104         $this->by_name['workservice']= _("Devices");
105         $this->by_object['workservice']= new workservice($this->config, $this->dn);
106         $this->by_object['workservice']->acl = "#all#";
107         $this->by_object['workservice']->inheritTimeServer = false;
108         $this->by_object['workservice']->parent= &$this;
109         $this->by_name['faiSummary']= _("Summary");
110         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
111         $this->by_object['faiSummary']->acl = "#all#";
112         $this->by_object['faiSummary']->parent= &$this;
113       }
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     }
122   }
124   function execute(){
125     $str = "";
126     $this->by_object['ogroup']->AddDelMembership();
127     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
128     $str .= tabs::execute();
129     return ( $str);
130   }  
132   function ogrouptabs($config, $data, $dn)
133   {
135     tabs::tabs($config, $data, $dn);
136     $this->base= $this->by_object['ogroup']->base;
138     /* Insert extra tabs for several object types - if present */
140     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
141     
142     for ($n= 0; $n<strlen($objects); $n++){
143       switch ($objects[$n]){
144         case "T":
145           /* Add a terminal tab */
146           require_once("class_termgroup.inc");
147           $this->by_name['termgroup']= _("Terminals");
148           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
149           $this->by_object['termgroup']->parent= &$this;
151           break;
153           case "U":
154             /* Append a PhoneQueue, if objectClass = goFonAccount */
155             $use = false;
156           $o_cache = $this->by_object['ogroup']->objcache;
157           foreach($this->by_object['ogroup']->memberList as $dn => $val){
158             if(isset($o_cache[$dn]['objectClass'])){
159               if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
160                 $use = true; 
161               }
162             }
163           }
165           /* We found goFonAccount in users objectClasses*/
166           if($use){
167             require_once("class_phonequeue.inc");
168             $this->by_name['phonequeue']= _("Phone queue");
169             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
170             $this->by_object['phonequeue']->parent= &$this;
172           } 
173  
174           /* Add a user tab used for mail distribution lists */
175           if(isset($this->config->current['MAILMETHOD'])){
176             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
177               require_once("class_mailogroup.inc");
178               $this->by_name['mailogroup']= _("Mail");
179               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
180               $this->by_object['mailogroup']->parent= &$this;
181             }
182           }
184           break;
185       }
186     }
187     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
188   }
191   function check()
192   {
193     return (tabs::check(FALSE));
194   }
197   function save_object($save_current= FALSE)
198   {
199     tabs::save_object($save_current);
201     /* Update reference, transfer variables */
202     $baseobject= $this->by_object['ogroup'];
203     foreach ($this->by_object as $name => $obj){
205       /* Don't touch base object */
206       if ($name != 'ogroup'){
207         $obj->parent    = &$this;
208         $obj->uid       = $baseobject->uid;
209         $obj->cn        = $baseobject->cn;
210         $obj->sn        = $baseobject->uid;
211         $obj->givenName = $baseobject->uid;
212         $this->by_object[$name]= $obj;
213       }
215       /* Update parent in base object */
216       $this->by_object['ogroup']->parent= &$this;
217     }
218   }
221   function save()
222   {
223     $baseobject= $this->by_object['ogroup'];
225     /* Check for new 'dn', in order to propagate the
226        'dn' to all plugins */
227     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
229     /* Move group? */
230     if ($this->dn != $new_dn){
232       /* Write entry on new 'dn' */
233       if ($this->dn != "new"){
234         $baseobject->move($this->dn, $new_dn);
235         $this->by_object['ogroup']= $baseobject;
236       }
238       /* Happen to use the new one */
239       $this->dn= $new_dn;
240     }
242     if ($this->dn == "new"){
243       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
244     }
246     tabs::save();
248     /* Fix tagging if needed */
249                 $baseobject->dn= $new_dn;
250     $baseobject->handle_object_tagging();
251   }
253   function saveCopyDialog()
254   {
255     tabs::saveCopyDialog();
256     $baseobject= $this->by_object['ogroup'];
257     $cn = $baseobject->cn;
258     foreach($this->by_object as  $name => $obj){
259       $this->by_object[$name]->cn = $cn;
260     }
261   }
265 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
266 ?>