Code

327b473e75c78e06a7ea677fb048cb1fe7d7ac6b
[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     }
27     /* Remove mail group if there is no user anymore */
28     if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailgroup']))){
29       $this->by_object['mailgroup']->remove_from_parent();
30       unset($this->by_object['mailgroup']);
31       unset($this->by_name['mailgroup']);
32     }
33     
34     /* Remove terminal group, if theres no terminal left in the object list */
35     if((!preg_match("/T/",$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     /* Create goPhoneAccount if theres an user with goPhoneAccount
42      * but only if there is currently no queue enabled.
43      */
44     if(!isset($this->by_object['phonequeue'])){
45       foreach($this->by_object['ogroup']->memberList as $dn => $val){
46         if(isset($val['objectClass'])){
47           if(in_array("goFonAccount",$val['objectClass'])){
48             require_once("class_phonequeue.inc");
49             $this->by_name['phonequeue']= _("Phone queue");
50             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
51             $this->by_object['phonequeue']->acl = "#all#";
52             $this->by_object['phonequeue']->parent= &$this;
53           }
54         }
55       }
56     }
58     /* Add mail group tab , if there is curerntly no mail tab defined */ 
59     if((!preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
60       if(isset($this->config->current['MAILMETHOD'])){
61         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
62           require_once("class_mailogroup.inc");
63           $this->by_name['mailogroup']= _("Mail");
64           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
65           $this->by_object['mailogroup']->parent= &$this;
66         }
67       }
68     }
70     /* Add Terminal tab */
71     if((!preg_match("/T/",$objects))&&(!isset($this->by_object['termgroup']))){
72       require_once("class_termgroup.inc");
73       if(!isset($this->by_object['termgroup'])){
74         $this->by_name['termgroup']= _("Terminals");
75         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
76         $this->by_object['termgroup']->parent= &$this;
77       }
78     }
79   }
81   function execute(){
82     $str = "";
83     $this->by_object['ogroup']->AddDelMembership();
84     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
85     $str .= tabs::execute();
86     return ( $str);
87   }  
89   function ogrouptabs($config, $data, $dn)
90   {
92     tabs::tabs($config, $data, $dn);
93     $this->base= $this->by_object['ogroup']->base;
95     /* Insert extra tabs for several object types - if present */
97     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
98     
99     for ($n= 0; $n<strlen($objects); $n++){
100       switch ($objects[$n]){
101         case "T":
102           /* Add a terminal tab */
103           require_once("class_termgroup.inc");
104           $this->by_name['termgroup']= _("Terminals");
105           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
106           $this->by_object['termgroup']->parent= &$this;
108           break;
110           case "U":
111             /* Append a PhoneQueue, if objectClass = goFonAccount */
112             $use = false;
113           foreach($this->by_object['ogroup']->memberList as $dn => $val){
114             if(isset($val['objectClass'])){
115               if(in_array("goFonAccount",$val['objectClass'])){
116                 $use = true; 
117               }
118             }
119           }
121           /* We found goFonAccount in users objectClasses*/
122           if($use){
123             require_once("class_phonequeue.inc");
124             $this->by_name['phonequeue']= _("Phone queue");
125             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
126             $this->by_object['phonequeue']->parent= &$this;
128           } 
129  
130           /* Add a user tab used for mail distribution lists */
131           if(isset($this->config->current['MAILMETHOD'])){
132             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
133               require_once("class_mailogroup.inc");
134               $this->by_name['mailogroup']= _("Mail");
135               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
136               $this->by_object['mailogroup']->parent= &$this;
137             }
138           }
140           break;
141       }
142     }
143   }
146   function check()
147   {
148     return (tabs::check(TRUE));
149   }
152   function save_object($save_current= FALSE)
153   {
154     tabs::save_object($save_current);
156     /* Update reference, transfer variables */
157     $baseobject= $this->by_object['ogroup'];
158     foreach ($this->by_object as $name => $obj){
160       /* Don't touch base object */
161       if ($name != 'ogroup'){
162         $obj->parent= &$this;
163         $obj->uid= $baseobject->uid;
164         $obj->sn= $baseobject->uid;
165         $obj->givenName= $baseobject->uid;
166         $this->by_object[$name]= $obj;
167       }
169       /* Update parent in base object */
170       $this->by_object['ogroup']->parent= &$this;
171     }
172   }
175   function save()
176   {
177     $baseobject= $this->by_object['ogroup'];
179     /* Check for new 'dn', in order to propagate the
180        'dn' to all plugins */
181     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
183     /* Move group? */
184     if ($this->dn != $new_dn){
186       /* Write entry on new 'dn' */
187       if ($this->dn != "new"){
188         $baseobject->move($this->dn, $new_dn);
189         $this->by_object['ogroup']= $baseobject;
190       }
192       /* Happen to use the new one */
193       $this->dn= $new_dn;
194     }
196     if ($this->dn == "new"){
197       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
198     }
200     tabs::save();
201   }
205 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
206 ?>