Code

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