Code

Added configuration flag flag.
[gosa.git] / plugins / admin / users / tabs_user.inc
1 <?php
3 class usertabs extends tabs
4 {
5   var $base;
7   function usertabs($config, $data, $dn)
8   {
9     tabs::tabs($config, $data, $dn);
10     $this->base= $this->by_object['user']->base;
11   }
13   function save_object($save_current= FALSE)
14   {
15     tabs::save_object($save_current);
17     /* Update reference, transfer variables */
18     $baseobject= $this->by_object['user'];
19     foreach ($this->by_object as $name => $obj){
21       /* Adding uid to sub plugins of connectivity */
22       if($name == "connectivity"){
23         foreach ($obj->plugin_name as $plg_name){
24           if(isset($obj->plugin[$plg_name]->uid)){
25             $obj->plugin[$plg_name]->uid = $baseobject->uid;
26           }
27         }
28       }
30       /* Copy mail if needed */
31       if ($name == "gofaxAccount"){
32         if (isset($this->by_object['mailAccount']) && $this->by_object['mailAccount']->is_account){
33           $obj->mail= $this->by_object['mailAccount']->mail;
34         }
35       }
37       /* Don't touch base object */
38       if ($name != 'user'){
39         $obj->parent= &$this;
40         $obj->uid= $baseobject->uid;
41         $obj->sn= $baseobject->uid;
42         $obj->givenName= $baseobject->uid;
43       }
45       /* Store changes */
46       $this->by_object[$name]= $obj;
48       /* Update parent in base object */
49       $this->by_object['user']->parent= &$this;
50     }
52     /* Move facsimile / phone number if nessecary */
53     if ($this->last == "user" && isset($this->by_object['gofaxAccount'])){
55       /* Move number to fax plugin */
56       $this->by_object['gofaxAccount']->facsimileTelephoneNumber=
57         $this->by_object['user']->facsimileTelephoneNumber;
59       /* Move phone number if plugin exists */
60       if (isset($this->by_object['phoneAccount']) && 
61           !$this->by_object['phoneAccount']->is_account){
62         $this->by_object['phoneAccount']->phoneNumbers= array();
63         if ($this->by_object['user']->telephoneNumber != ""){
64           $this->by_object['phoneAccount']->phoneNumbers[$this->by_object['user']->telephoneNumber]= $this->by_object['user']->telephoneNumber;
65         }
66       }
67     }
68     if ($this->last == "gofaxAccount"){
70       /* Move number from fax plugin */
71       $this->by_object['user']->facsimileTelephoneNumber=
72         $this->by_object['gofaxAccount']->facsimileTelephoneNumber;
73     }
74     if ($this->last == "phoneAccount" && $this->by_object['phoneAccount']->is_account){
75       /* Move number from fax plugin */
76       reset($this->by_object['phoneAccount']->phoneNumbers);
77       $number= key($this->by_object['phoneAccount']->phoneNumbers);
78       $this->by_object['user']->telephoneNumber= $number;
79     }
80   }
82   function save()
83   {
84     /* Check for new 'dn', in order to propagate the
85        'dn' to all plugins */
86     $baseobject= $this->by_object['user'];
88     /* Assemble cn */
89     $pt= "";
90     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
91       if(!empty($baseobject->personalTitle)){
92         $pt = $baseobject->personalTitle." ";
93       }
94     }
96     if ($this->dn == 'new'){
97       $baseobject->cn= $pt.$baseobject->givenName." ".$baseobject->sn;
98       $this->by_object['user']= $baseobject;
99       if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
100         $this->dn= 'uid='.$baseobject->uid.','.get_people_ou().$baseobject->base;
101       } else {
102         $this->dn= 'cn='.$baseobject->cn.','.get_people_ou().$baseobject->base;
103       }
104     } // != 'new' 
105     else 
106     {
107       /* Extract cn and compare with actual cn present in 'dn' */
108       if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
109         $new_dn= 'uid='.$baseobject->uid.','.get_people_ou().$baseobject->base;
110       } else {
111         $new_dn= "cn=".$pt.$baseobject->givenName." ".$baseobject->sn.','.
112           get_people_ou().$baseobject->base;
113       }
114       
115       /* Hickert: 31.08.2005 
116        * fixed error = Trying to overwrite cn=***  which already exists.
117        * If you changed one of the "Name" / "Givenname" attributes to lower or upper case, like "test" to "Test", (in DNMODE=cn)
118        *  the old_dn and new dn were different. cn=test ... cn=Test ...
119        * The following code decided to move the entry from old_dn to new_dn. (Because they differ)
120        * But the ldap attribute cn is not case sensitive and the function plugin::move() quits with 
121        *  an error, because source and destination dn are both the same (for ldap, but not for php).
122        * This fix allow you to change the givenname or name attributes.
123        */
124       if(strtolower($this->dn)==strtolower($new_dn)){
125         $this->dn=$new_dn;
126       }
127   
128       if ($this->dn != $new_dn){
130         /* Write entry on new 'dn' */
131         $baseobject->cn= $pt.$baseobject->givenName." ".$baseobject->sn;
132         $baseobject->move($this->dn, $new_dn);
133         $this->by_object['user']= $baseobject;
135         /* Did we change ourselves? Update ui object. */
136         change_ui_dn($this->dn, $new_dn);
138         /* Happen to use the new one */
139         $this->dn= $new_dn;
140       }
141     }
142     return tabs::save();
143   }
146   function set_template_mode()
147   {
148     foreach ($this->by_object as $key => $obj){
149       $this->by_object[$key]->is_template= TRUE;
150     }
151   }
152   
153   function saveCopyDialog()
154   {
155     tabs::saveCopyDialog();
156     $baseobject= $this->by_object['user'];
157     $uid = $baseobject->uid;
158     foreach($this->by_object as  $name => $obj){
159       $this->by_object[$name]->uid = $uid;
160     }
161   }
165 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
166 ?>