Code

Updated user plugins
[gosa.git] / gosa-core / plugins / admin / users / tabs_user.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 usertabs extends tabs
24 {
25   var $base;
27   /* Template adaption variables
28    */
29   var $uid  ="";
30   var $givenName = "";
31   var $sn;
33   function usertabs($config, $data, $dn)
34   {
35     tabs::tabs($config, $data, $dn, 'users');
36     $this->base= $this->by_object['user']->base;
38     $this->uid = &$this->by_object['user']->uid;
39     $this->sn = &$this->by_object['user']->sn;
40     $this->givenName = &$this->by_object['user']->givenName;
42     /* Add references/acls/snapshots */
43     $this->addSpecialTabs();
45   }
47   function save_object($save_current= FALSE)
48   {
49     tabs::save_object($save_current);
51     /* Update reference, transfer variables */
52     $baseobject= $this->by_object['user'];
53     foreach ($this->by_object as $name => $obj){
55       /* Adding uid to sub plugins of connectivity */
56       if($name == "connectivity"){
57         foreach ($obj->plugin_name as $plg_name){
58           if(isset($obj->plugin[$plg_name]->uid)){
59             $obj->plugin[$plg_name]->uid = $baseobject->uid;
60           }
61         }
62       }
64       /* Don't touch base object */
65       if ($name != 'user'){
66         $obj->parent= &$this;
67         $obj->uid= $baseobject->uid;
68         $obj->sn= $baseobject->uid;
69         $obj->givenName= $baseobject->uid;
70       }
72       /* Copy mail if needed */
73       if ($name == "gofaxAccount"){
74         if (isset($this->by_object['mailAccount']) && $this->by_object['mailAccount']->is_account){
75           $obj->mail= $this->by_object['mailAccount']->mail;
76         }
77       }
79       $this->by_object[$name]= $obj;
81       /* Update parent in base object */
82       $this->by_object['user']->parent= &$this;
83     }
85     /* Move facsimile / phone number if nessecary */
86     if ($this->last == "user" && isset($this->by_object['gofaxAccount'])){
88       /* Move number to fax plugin */
89       $this->by_object['gofaxAccount']->facsimileTelephoneNumber=
90         $this->by_object['user']->facsimileTelephoneNumber;
92       /* Move phone number if plugin exists */
93       if (isset($this->by_object['phoneAccount']) && 
94           !$this->by_object['phoneAccount']->is_account){
95         $this->by_object['phoneAccount']->phoneNumbers= array();
96         if ($this->by_object['user']->telephoneNumber != ""){
97           $this->by_object['phoneAccount']->phoneNumbers[$this->by_object['user']->telephoneNumber]= $this->by_object['user']->telephoneNumber;
98         }
99       }
100     }
102     /* Move number from fax plugin */
103     if ($this->last == "gofaxAccount"){
105       $this->by_object['user']->facsimileTelephoneNumber=
106         $this->by_object['gofaxAccount']->facsimileTelephoneNumber;
107     }
109     /* Move number from fax plugin */
110     if ($this->last == "phoneAccount" && $this->by_object['phoneAccount']->is_account){
111       reset($this->by_object['phoneAccount']->phoneNumbers);
112       $number= key($this->by_object['phoneAccount']->phoneNumbers);
114       /* Only the first phoneAccount number, if it is not empty */
115       if(!empty($number)){
116         $this->by_object['user']->telephoneNumber= $number;
117       }
118     }
120     /* Possibly change acl base */
121     $this->set_acl_base();
122   }
124   function save($ignore_account= FALSE)
125   {
126     /* Check for new 'dn', in order to propagate the
127        'dn' to all plugins */
128     $baseobject= $this->by_object['user'];
129     $baseobject->update_new_dn();
130     if ($this->dn != 'new'){
132       $new_dn= $baseobject->new_dn;
134       if ($this->dn != $new_dn){
136         /* Udpate acls */
137         $baseobject->update_acls($this->dn,$new_dn);
138         $baseobject->move($this->dn, $new_dn);
139         $this->by_object['user']= $baseobject;
141         /* Did we change ourselves? Update ui object. */
142         change_ui_dn($this->dn, $new_dn);
143       }
144     }
146     $this->dn= $baseobject->new_dn;
148     return tabs::save();
149   }
152   function set_template_mode()
153   {
154     foreach ($this->by_object as $key => $obj){
155       $this->by_object[$key]->is_template= TRUE;
156     }
157   }
158   
159   function saveCopyDialog()
160   {
161     tabs::saveCopyDialog();
162     $baseobject= $this->by_object['user'];
163     $uid = $baseobject->uid;
164     foreach($this->by_object as  $name => $obj){
165       $this->by_object[$name]->uid = $uid;
166     }
167   }
171 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
172 ?>