Code

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