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