Code

skipping . .. when deleting smarty spool dir
[gosa.git] / plugins / addons / addressbook / class_addressbook.inc
1 <?php
3 class addressbook extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "Addressbook";
7   var $plDescription= "This does something";
9   /* Phonelist attributes */
10   var $telephone_list = array();
11   var $start= 0;
12   var $search_for= "*";
13   var $search_base= "";
14   var $search_type= "";
15   var $new_dn= "";
16   var $orig_cn= "";
17   var $storage_base= "";
18   var $orig_storage_base= "";
20   var $sn= "";
21   var $cn= "";
22   var $givenName= "";
23   var $mail= "";
24   var $title= "";
25   var $personalTitle= "";
26   var $initials= "";
27   var $homePostalAddress= "";
28   var $homePhone= "";
29   var $mobile= "";
30   var $o= "";
31   var $postalAddress= "";
32   var $l= "";
33   var $postalCode= "";
34   var $st= "";
35   var $ou= "";
36   var $telephoneNumber= "";
37   var $facsimileTelephoneNumber= "";
38   var $pager= "";
40   /* attribute list for save action */
41   var $attributes= array("sn", "givenName", "mail", "title",
42                          "initials", "homePostalAddress", "displayName",
43                          "homePhone", "mobile", "o", "postalAddress", "l",
44                          "postalCode", "st", "ou", "telephoneNumber",
45                          "facsimileTelephoneNumber", "pager");
46   var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson");
48   function addressbook ($config, $dn= NULL)
49   {
50         /* Include config object */
51         $this->config= $config;
53         print $dn;
55         #FIXME: ACL is set to default for testing
56         $this->acl= "#all#";
58         /* Get global filter config */
59         if (!is_global("phonefilter")){
60                 $ui= get_userinfo();
61                 $base= get_base_from_people($ui->dn);
62                 $phonefilter= array("search_base" => $base,
63                                   "organizational" => "checked",
64                                   "global" => "checked",
65                                   "search_for" => "*",
66                                   "object_type" => "*");
67                 register_global("phonefilter", $phonefilter);
68         }
69   }
71   function execute()
72   {
73         $smarty= get_smarty();
75         #! Hickert
76         /*prevent empty variables for smarty*/
77         foreach($this->attributes as $atr) $smarty->assign($atr,"");
79         /* Save formular information */
80         $phonefilter= get_global("phonefilter");
81         foreach( array("search_for", "search_base", "object_type") as $type){
82                 if (isset($_POST[$type])){
83                         $phonefilter[$type]= $_POST[$type];
84                 }
85                 $this->$type= $phonefilter[$type];
86         }
87         if (isset($_POST['search_base'])){
88                 foreach( array("organizational", "global") as $type){
89                         if (isset($_POST[$type])){
90                                 $phonefilter[$type]= "checked";
91                         } else {
92                                 $phonefilter[$type]= "";
93                         }
94                 }
95         }
97         /* Search string */
98         $s= $phonefilter['search_for'];
99         if ($s == "") {
100                 $s= "*";
101         }
102         if (isset($_GET['search'])){
103                 $s= validate(mb_substr($_GET['search'], 0, 1, "UTF8"))."*";
104                 if ($s == "**"){
105                         $s= "*";
106                 }
107                 $this->search_for= $s;
108                 $phonefilter['search_for']= $s;
109         }
110         register_global("phonefilter", $phonefilter);
112         /* Perform actions with CTI hook */
113         if (isset($_GET['target'])
114                 && isset($_GET['dial'])
115                 && isset($this->config->current['CTIHOOK'])){
116         
117                 $dialmode= $_GET['dial'];
118                 if ($dialmode == "telephoneNumber" ||
119                     $dialmode == "mobile" ||
120                     $dialmode == "homePhone"){
121                         
122                         /* Get target */
123                         $ldap= $this->config->get_ldap_link();
124                         $ldap->cat(base64_decode($_GET['target']));
125                         $attrs= $ldap->fetch();
126                         if (isset($attrs["$dialmode"])){
127                                 $target= $attrs[$dialmode][0];
128                         } else {
129                                 $target= "";
130                         }
132                         /* Get source */
133                         $ui= get_userinfo();
134                         $ldap->cat($ui->dn);
135                         $attrs= $ldap->fetch();
136                         if (isset($attrs["telephoneNumber"])){
137                                 $source= $attrs['telephoneNumber'][0];
138                         } else {
139                                 $source= "";
140                         }
142                         /* Save to session */
143                         $_SESSION['source']= $source;
144                         $_SESSION['target']= $target;
146                         /* Perform call */
147                         if ($target != "" && $source != ""){
148                                 $smarty->assign("phone_image", get_template_path('images/phone.png'));
149                                 $smarty->assign("dial_info", sprintf(_("Dial from %s to %s now?"), "<b style='font-size:22px; color:red'>".$source."</b>", "<b style='font-size:22px;color:red'>".$target."</b>"));
150                                 return($smarty->fetch(get_template_path('dial.tpl', TRUE)));
151                                 return;
152                         } else {
153                                 print_red (_("You have no personal phone number set. Please change that in order to perform direct dials."));
154                         }
155                 }
156                 
157         }
159         /* Finally dial */
160         if (isset($_POST['dial']) && isset($_SESSION['source']) && isset($_SESSION['target'])){
161                 exec ($this->config->current['CTIHOOK']." '".$_SESSION['source']."' '".$_SESSION['target']."'", $dummy, $retval);
162                 unset($_SESSION['source']);
163                 unset($_SESSION['target']);
164         }
165         
166         /* Delete entry? */
167         if (isset($_POST['delete_entry_confirm'])){
169                 /* Some nice guy may send this as POST, so we've to check
170                    for the permissions again. */
171                 if (chkacl($this->acl, "delete") == ""){
173                         /* Delete request is permitted, perform LDAP action */
174                         $ldap= $this->config->get_ldap_link();
175                         $ldap->rmdir ($this->dn);
176                         gosa_log ("Address book object'".$this->dn."' has been removed");
178                 } else {
180                         /* Normally this shouldn't be reached, send some extra
181                            logs to notify the administrator */
182                         print_red (_("You are not allowed to delete this entry!"));
183                         gosa_log ("Warning: '".$this->ui->uid."' tried to trick address book deletion.");
184                 }
186                 /* Remove lock file after successfull deletion */
187                 del_lock ($this->dn);
189                 /* Clean up */
190                 if (isset($_SESSION['saved_start'])){
191                         $_GET['start']= $_SESSION['saved_start'];
192                 }
193                 unset($_SESSION['show_info']);
194                 unset($_SESSION['saved_start']);
195         }
197         /* Delete entry? */
198         if (isset($_POST['delete_cancel'])){
199                 del_lock ($this->dn);
200         }
202         /* Save address entry? */
203         if (isset($_POST['save'])){
204                 $this->save_object();
205                 $this->storage_base= $_POST['storage_base'];
207                 /* Perform checks */
208                 $message= $this->check ();
210                 /* No errors, save object */
211                 if (count ($message) == 0){
212                         $this->save();
213                         gosa_log ("Addressbook object '".$this->dn."' has been saved");
215                         /* Clean up */
216                         if (isset($_SESSION['saved_start'])){
217                                 $_GET['start']= $_SESSION['saved_start'];
218                         }
219                         $_SESSION['show_info']= $this->dn;
220                         unset($_SESSION['saved_start']);
221                 } else {
222                         /* Errors found, show message */
223                         show_errors ($message);
224                 }
225         }
226         
227         /* Close info window */
228         if (isset($_GET['close']) || isset($_POST['cancel'])){
229                 if (isset($_SESSION['saved_start'])){
230                         $_GET['start']= $_SESSION['saved_start'];
231                 }
232                 unset($_SESSION['show_info']);
233                 unset($_SESSION['saved_start']);
234         }
236         /* Start address book edit mode? */
237         if (isset($_GET['global'])){
238                 if (!isset($_SESSION['saved_start']) && isset($_GET['start'])){
239                         $_SESSION['saved_start']= $_GET['start'];
240                 }
241                 switch ($_GET['global']){
242                         case "add":
243                                 $this->dn= "new";
244                                 $this->orig_cn= "";
245                                 
246                                 /* Clean values */
247                                 foreach ($this->attributes as $name){
248                                         $this->$name= "";
249                                 }
250                                 $this->storage_base= $this->config->current["BASE"];
251                                 break;
252                         case "edit":
253                                 /* Clean values */
254                                 foreach ($this->attributes as $name){
255                                         $this->$name= "";
256                                 }
257                                 $this->dn= $_SESSION['show_info']; 
258                                 $this->load();
259                                 $this->orig_cn= $this->cn;
260                                 break;
261                         case "remove":
262                                 $this->dn= $_SESSION['show_info']; 
263                                 $this->load();
264                                 /* Load permissions for selected 'dn' and check if
265                                    we're allowed to remove this 'dn' */
266                                 $ui= get_userinfo();
267                                 $dn= preg_replace("/,dc=addressbook,/", "", $this->dn);
268                                 $acl= get_permissions ($dn, $ui->subtreeACL);
269                                 $this->acl= get_module_permission($acl, "global-addressbook", $dn);
270                                 if (chkacl($this->acl, "delete") == ""){
272                                         /* Check locking, save current plugin in 'back_plugin', so
273                                            the dialog knows where to return. */
274                                         if (($user= get_lock($this->dn)) != ""){
275                                                 return(gen_locked_message ($user, $this->dn));
276                                         }
278                                         /* Lock the current entry, so nobody will edit it during deletion */
279                                         add_lock ($this->dn, $ui->dn);
280                                         $smarty->assign("info", sprintf(_("You're about to delete the entry %s."), $this->dn));
281                                         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
282                                 } else {
283         
284                                         /* Obviously the user isn't allowed to delete. Show message and
285                                            clean session. */
286                                         print_red (_("You are not allowed to delete this entry!"));
287                                 }
288                 }
289                 $_SESSION['show_info']= "ADD";
290         }
292         /* Open info window */
293         if (isset($_GET['show'])){
294                 if (!isset($_SESSION['saved_start'])){
295                         $_SESSION['saved_start']= $_GET['start'];
296                 }
297                 $_SESSION['show_info']= base64_decode($_GET['show']);
298         }
300         /* Get ldap link / build filter */
301         $ldap= $this->config->get_ldap_link();
302         $this->telephone_list= array ();
304         /* Assemble bases */
305         $bases= array();
306         $filter= "";
307         if ($phonefilter['global'] == "checked"){
308                 $bases[]= preg_replace("/".$this->config->current['BASE']."/", "dc=addressbook,".$this->config->current['BASE'], $this->search_base);
309         } else {
310                 $filter= '(objectClass=gosaAccount)';
311         }
312         if ($phonefilter['organizational'] == "checked"){
313                 $bases[]= $this->search_base;
314         }
315         foreach ($bases as $base){
316                 $ldap->cd ($base);
317                 if ($phonefilter['object_type'] == '*'){
318                         $ldap->search ("(&(objectClass=person)$filter(!(objectClass=gosaUserTemplate))".
319                                 "(|(uid=$s)(homePhone=$s)(telephoneNumber=$s)".
320                                 "(facsimileTelephoneNumber=$s)(mobile=$s)(givenName=$s)(sn=$s)))", array("sn", "givenName", "telephoneNumber", "facsimileTelephoneNumber", "mobile", "homePhone", "uid", "mail", "cn"));
321                 } else {
322                         $ldap->search ("(&$filter(!(objectClass=gosaUserTemplate))".
323                                 "(".$phonefilter['object_type']."=$s))", array("sn", "givenName", "telephoneNumber", "facsimileTelephoneNumber", "mobile", "homePhone", "uid", "mail", "cn"));
324                 }
326                 /* Build current list, error reporting is off, because many of the
327                    objects may not be defined after LDAP queries. Asking for presence
328                    first is too much overhead. */
329                 error_reporting(0);
332         
334                 /* Walk through LDAP results */
335                 while ($attrs= $ldap->fetch()){
337                 #! hickert  
338                 /* prevent empty vaiables */
339         foreach($this->attributes as $atr)          {
340             if(!isset($attrs[$atr][0])) {
341                                 $attrs[$atr][0] = "";
342                                 }
343             }
344                         if(!isset($_GET['start'])) $_GET['start']="";
347                         /* Only show lines that have set any mail or phone informations */
348                         if (isset($attrs['telephoneNumber'][0]) ||
349                                 isset($attrs['facsimileTelephoneNumber'][0]) ||
350                                 isset($attrs['mobile'][0]) ||
351                                 isset($attrs['homePhone'][0]) ||
352                                 isset($attrs['mail'][0])){
354 $this->telephone_list[$attrs['sn'][0].$attrs['dn']]=
356 "<td class=\"phonelist\" title=\"".$attrs['sn'][0].", ".$attrs['givenName'][0]."\" onClick='location.href=\"main.php?plug=".validate($_GET['plug'])."&amp;start=".validate($_GET['start'])."&amp;show=".base64_encode($attrs['dn'])."\"'><a href=\"main.php?plug=".validate($_GET['plug'])."&amp;start=".validate($_GET['start'])."&amp;show=".base64_encode($attrs['dn'])."\">".$attrs['sn'][0].", ".$attrs['givenName'][0].
357         "</a>
358 </td>
359 <td title=\""._("Dial")." ".$attrs['telephoneNumber'][0]."\">
360         <a href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=telephoneNumber&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($attrs['dn'])."\">".$attrs['telephoneNumber'][0]."
361         </a>
362 </td>
363 <td title=\"".$attrs['facsimileTelephoneNumber'][0]."\">
364         ".$attrs['facsimileTelephoneNumber'][0]."
365 </td>
366 <td title=\""._("Dial")." ".$attrs['mobile'][0]."\">
367         <a href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=mobile&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($attrs['dn'])."\">".$attrs['mobile'][0]."
368         </a>
369 </td>
370 <td title=\""._("Dial")." ".$attrs['homePhone'][0]."\">
371         <a href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=homePhone&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($attrs['dn'])."\">".$attrs['homePhone'][0]."
372         </a>
373 </td>
374 <td>
375         <a href=\"getvcard.php?dn=".base64_encode($attrs['dn'])."\">
376         <img align=\"top\" border=0 src=\"images/save.png\" alt=\"vcf\" title=\"".sprintf(_("Save contact for %s as vcard"), $attrs['givenName'][0]." ".$attrs['sn'][0])."\">
377         </a>";
379                                 if (isset($attrs['mail'])){
380                                         $dest= sprintf(_("Send mail to %s"), $attrs['mail'][0]);
381                                         $this->telephone_list[$attrs['sn'][0].$attrs['dn']].=
382                                                 
383                                                 "<a href=\"mailto:".$attrs['mail'][0]."\">".
384                                                 "<img  align=\"top\" border=0 src=\"images/mailto.png\" ".
385                                                 "alt=\"vcf\" title=\"$dest\"></a>";
386                                 }
387                                 $this->telephone_list[$attrs['sn'][0].$attrs['dn']].= "</td>";
388                         }
389                 }
390                 error_reporting(E_ALL);
391         }
393         /* Sort up list */
394         ksort ($this->telephone_list);
395         reset ($this->telephone_list);
397         /* Fill template variables */
398         $smarty->assign("search_for", $this->search_for);
399         $smarty->assign("object_type", $this->object_type);
400         $smarty->assign("deplist", $this->config->idepartments);
401         $smarty->assign("depselect", $this->search_base);
402         $smarty->assign("global", $phonefilter['global']);
403         $smarty->assign("organizational", $phonefilter['organizational']);
404         $smarty->assign("search_image", get_template_path('images/search.png'));
405         $smarty->assign("tree_image", get_template_path('images/tree.png'));
406         $smarty->assign("infoimage", get_template_path('images/info.png'));
407         $smarty->assign("actionimage", get_template_path('images/action.png'));
408         $smarty->assign("launchimage", get_template_path('images/launch.png'));
410         /* Generate alphabet */
411         $alphabet= generate_alphabet();
413         /* Build list output */
414         $output= "";
415         $mod= 0;
416         
417         #! hickert
418         if(!isset($_SESSION['show_info']))      $smarty->assign("show_info", "");;
420         if (isset($_SESSION['show_info'])){
421                 $range= 4;
422                 $smarty->assign("show_info", "1");
423                 $smarty->assign("url", "main.php?plug=".validate($_GET['plug'])."&amp;close=1");
425                 switch ($_SESSION['show_info']){
427                         case "ADD":
428                                 $smarty->assign ('storage_base', $this->storage_base);
429                                 $smarty->assign ('address_info',
430                                         get_template_path('address_edit.tpl', TRUE));
431                                 break;
433                         default:
434                                 $smarty->assign ('address_info',
435                                         get_template_path('address_info.tpl', TRUE));
436                                 break;
437                 }
439                 /* Fill variables from LDAP */
440                 # FIXME: Missing ACL support for addressbook yet
441                 if ($_SESSION['show_info'] != "ADD"){
442                         $ldap->cat($_SESSION['show_info']);
443                         $info= $ldap->fetch();
444                 }
445                 foreach ($this->attributes as $name){
446                         if ($_SESSION['show_info'] != "ADD" && isset($info["$name"][0])){
447                                 error_reporting(0);
448                                 /* Special treatment for phone attributes */
449                                 if ($name == "mobile" ||
450                                     $name == "homePhone" ||
451                                     $name == "telephoneNumber"){
452                                         $smarty->assign("info_$name",
453                                                 "<a title=\""._("Dial")." ".$info["$name"][0]."\" href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=$name&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($_SESSION['show_info'])."\">".$info["$name"][0]."</a>");
454                                 } else {
455                                         $smarty->assign("info_$name", preg_replace("/\n/", "<br>", $info["$name"][0]));
456                                 }
457                                 error_reporting(E_ALL);
458                         } elseif ($_SESSION['show_info'] == "ADD" && isset($this->$name)) {
459                                 $smarty->assign("info_$name", $this->$name);
460                         } else {
461                                 $smarty->assign("info_$name", "-");
462                         }
463                 }
464                 if (preg_match("/,dc=addressbook,/", $_SESSION['show_info'])){
465                         $storage= _("global addressbook");
466                         $smarty->assign("internal", 0);
467                 } else {
468                         $storage= _("organizations user database");
469                         $smarty->assign("internal", 1);
470                 }
471                 if ($_SESSION['show_info'] != "ADD"){
472                         $smarty->assign("storage_info", sprintf(_("Contact stored in %s"), $storage));
473                 } else {
474                         $smarty->assign("storage_info", _("Creating new entry in"));
475                 }
476         } else {
477                 $range= 20;
478                 $smarty->assign("internal", 1);
479         }
480         if (isset($_GET['start'])){
481                 $this->start= validate($_GET['start']);
482         }
483         foreach ($this->telephone_list as $val){
484                 if ($mod < $this->start) {
485                         $mod++;
486                         continue;
487                 }
488                 if ($mod >= ($this->start + $range)){
489                         $mod++;
490                         break;
491                 }
492                 if ( ($mod++) & 1){
493                         $col= "style=\"background-color: #ECECEC;\"";
494                 } else {
495                         $col= "style=\"background-color: #F5F5F5;\"";
496                 }
497                 $output.= "<tr $col>\n$val</tr>\n";
498         }
499         $smarty->assign("search_result", $output);
500         $smarty->assign("apply", apply_filter());
501         $smarty->assign("alphabet", $alphabet);
502         $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range));
503         $tmp= array("*" => _("All"), "sn" => _("Name"), "givenName" => _("Given name"),
504                         "telephoneNumber" => _("Work phone"), "mobile" => _("Cell phone"),
505                         "homePhone" => _("Home phone"), "uid" => _("User ID"));
506         natsort($tmp);
507         $smarty->assign("objlist", $tmp);
509         /* Show main page */
510         $smarty->assign ('personal_image', get_template_path('images/addr_personal.png'));
511         $smarty->assign ('home_image', get_template_path('images/addr_home.png'));
512         $smarty->assign ('company_image', get_template_path('images/addr_company.png'));
513         $smarty->assign ('add_image', get_template_path('images/editpaste.png'));
514         $smarty->assign ('edit_image', get_template_path('images/edit.png'));
515         $smarty->assign ('delete_image', get_template_path('images/editdelete.png'));
516         return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
517   }
520   function check()
521   {
522         $message= array();
524         /* must: sn, givenName */
525         if ($this->sn == ""){
526                 $message[]= _("The required field 'Name' is not set.");
527                 return ($message);
528         }
529         if ($this->givenName == ""){
530                 $message[]= _("The required field 'Given name' is not set.");
531                 return ($message);
532         }
534         /* Check for valid name definition */
535         if (preg_match ("/[\\\\]/", $this->sn)){
536                 $message[]= _("The field 'Name' contains invalid characters.");
537         }
538         if (preg_match ("/[\\\\]/", $this->givenName)){
539                 $message[]= _("The field 'Given name' contains invalid characters.");
540         }
542         /* Check phone numbers */
543         if (!is_phone_nr($this->homePhone)){
544                 $message[]= _("The field 'Phone' contains an invalid phone number.");
545         }
546         if (!is_phone_nr($this->telephoneNumber)){
547                 $message[]= _("The field 'Phone' contains an invalid phone number.");
548         }
549         if (!is_phone_nr($this->facsimileTelephoneNumber)){
550                 $message[]= _("The field 'Fax' contains an invalid phone number.");
551         }
552         if (!is_phone_nr($this->mobile)){
553                 $message[]= _("The field 'Mobile' contains an invalid phone number.");
554         }
555         if (!is_phone_nr($this->pager)){
556                 $message[]= _("The field 'Pager' contains an invalid phone number.");
557         }
559         /* Check for reserved characers */
560         if (preg_match ('/[,+"<>;]/', $this->givenName)){
561                 $message[]= _("The field 'Given name' contains invalid characters.");
562         }
563         if (preg_match ('/[,+"<>;]/', $this->sn)){
564                 $message[]= _("The field 'Name' contains invalid characters.");
565         }
567         /* Check mail */
568         if (!is_email($this->mail)){
569                 $message[]= _("Please enter a valid email address in 'Primary address' field.");
570         }
572         /* Assemble cn/dn */
573         $this->cn= $this->givenName." ".$this->sn;
574         if ($this->orig_cn != $this->cn || $this->storage_base != $this->orig_storage_base){
575                 $this->new_dn= $this->create_unique_dn("cn", preg_replace("/,*".$this->config->current['BASE']."$/", "", $this->storage_base).",dc=addressbook,".$this->config->current['BASE']);
576                 if ($this->new_dn == "none"){
577                         $message[]= _("Cannot create a unique DN for your entry. Please fill more formular fields.");
578                         return ($message);
579                 }
580         } else {
581                 $this->new_dn= $this->dn;
582         }
584         $ui= get_userinfo();
585         $dn= preg_replace("/,dc=addressbook,/", "", $this->new_dn);
586         $acl= get_permissions ($dn, $ui->subtreeACL);
587         $acl= get_module_permission($acl, "global-addressbook", $this->dn);
588         if ($_SESSION['show_info'] == "ADD" && chkacl($acl, "create") != ""){
589                 $message[]= _("You have no permissions to create or modify a global address book entry.");
590         }
592         return ($message);
593   }
596   function load()
597   {
598         /* Load base attributes */
599         plugin::plugin ($this->config, $this->dn);
600         $this->storage_base= preg_replace('/^[^,]+,/', '', preg_replace('/dc=addressbook,/', '', $this->dn));
601   }
604   function save()
605   {
606         /* First use parents methods to do some basic fillup in $this->attrs */
607         plugin::save ();
609         $this->attrs['cn']= $this->cn;
610         $this->attrs['displayName']= $this->givenName." ".$this->sn;
612         /* Move entry if it got another name... */
613         if ($this->dn != "new" && $this->dn != $this->new_dn){
614                 $this->move($this->dn, $this->new_dn);
615         }
616         $this->dn= $this->new_dn;
618         /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
619            new entries. So do a check first... */
620         $ldap= $this->config->get_ldap_link();
621         $ldap->cat ($this->dn);
622         if ($ldap->fetch()){
623                 $mode= "modify";
624         } else {
625                 $mode= "add";
626                 $ldap->cd($this->config->current['BASE']);
627                 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
628         }
630         /* Finally write data with selected 'mode' */
631         $ldap->cd ($this->dn);
632         $ldap->$mode ($this->attrs);
633         if (show_ldap_error($ldap->get_error())){
634                 return (1);
635         }
636   }
640 ?>