Code

Fixed Translation String.
[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   /* Generic */
10   var $ui;  
12         /* Phonelist attributes */
13         var $telephone_list   = array();
14         var $new_dn           = "";
15         var $orig_cn          = "";
16         var $storage_base     = "";
17         var $orig_storage_base= "";
19   /* Filter attributes */
20         var $start            = 0;
21         var $search_for       = "*";
22         var $search_base      = "";
23         var $search_type      = "";
24         var $range            = 20;
26   /* Currently edited/added entry attributes */
27         var $sn                       = "";
28         var $cn                       = "";
29         var $givenName                = "";
30         var $mail                     = "";
31         var $title                    = "";
32         var $personalTitle            = "";
33         var $initials                 = "";
34         var $homePostalAddress        = "";
35         var $homePhone                = "";
36         var $mobile                   = "";
37         var $o                        = "";
38         var $postalAddress            = "";
39         var $l                        = "";
40         var $postalCode               = "";
41         var $st                       = "";
42         var $ou                       = "";
43         var $telephoneNumber          = "";
44         var $facsimileTelephoneNumber = "";
45         var $pager                    = "";
47         /* attribute list for save action */
48         var $attributes= array("sn", "givenName", "mail", "title",
49                         "initials", "homePostalAddress", "displayName",
50                         "homePhone", "mobile", "o", "postalAddress", "l",
51                         "postalCode", "st", "ou", "telephoneNumber",
52                         "facsimileTelephoneNumber", "pager");
54         var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson");
56         var $abobjectclass= "dc=addressbook";
58   function addressbook ($config, $dn= NULL)
59   {
60     /* Include config object */
61     $this->config= $config;
63     /* Check if there is a special ldap-sub-tree specified, instead of dc=addressbook, */
64     $aoc = search_config($this->config->data['MENU'], "addressbook", "LDAP_OBJECT_CLASS");
65     if ($aoc != ""){
66       $this->abobjectclass  = $aoc;
67     }
69     /* Get global filter config */
70     if (!is_global("phonefilter")){
71       $ui         = get_userinfo();
72       $base       = get_base_from_people($ui->dn);
73       $phonefilter= array(
74           "search_base"       => $base,
75           "organizational"    => "checked",
76           "global"            => "checked",
77           "search_for"        => "*",
78           "object_type"       => "*");
79       register_global("phonefilter", $phonefilter);
80     }
81     
82     $this->ui = get_userinfo();
83   }
85   function execute()
86   {
87     /* Call parent execute */
88     plugin::execute();
90     $smarty= get_smarty();
92     /* Prevent empty variables for smarty */
93     foreach($this->attributes as $atr) {
94       $smarty->assign($atr,"");
95     }
97     /* Save formular information */
98     $phonefilter= get_global("phonefilter");
99     foreach( array("search_for", "search_base", "object_type") as $type){
100       if (isset($_POST[$type])){
101         $phonefilter[$type]= $_POST[$type];
102       }
103       $this->$type= $phonefilter[$type];
104     }
105     if (isset($_POST['search_base'])){
106       foreach( array("organizational", "global") as $type){
107         if (isset($_POST[$type])){
108           $phonefilter[$type]= "checked";
109         } else {
110           $phonefilter[$type]= "";
111         }
112       }
113     }
115     /* Search string */
116     $s= $phonefilter['search_for'];
117     if ($s == "") {
118       $s= "*";
119     }
120     if (isset($_GET['search'])){
121       $s= validate(mb_substr($_GET['search'], 0, 1, "UTF8"))."*";
122       if ($s == "**"){
123         $s= "*";
124       }
125       $this->search_for= $s;
126       $phonefilter['search_for']= $s;
127     }
128     register_global("phonefilter", $phonefilter);
130     /* Assign create acl */
131     $acl = $this->get_entry_acls($this->abobjectclass.",".$phonefilter['search_base']);
132     $smarty->assign("internal_createable", preg_match("/c/",$acl));
133     $smarty->assign("internal_removeable", preg_match("/d/",$acl));
135     /* Perform actions with CTI hook */
136     if (isset($_GET['target'])
137         && isset($_GET['dial'])
138         && isset($this->config->current['CTIHOOK'])){
140       $dialmode= $_GET['dial'];
141       if ($dialmode == "telephoneNumber" ||
142           $dialmode == "mobile" ||
143           $dialmode == "homePhone"){
145         /* Get target */
146         $ldap= $this->config->get_ldap_link();
147         $ldap->cat(base64_decode($_GET['target']), array('telephoneNumber', 'mobile', 'homePhone'));
148         $attrs= $ldap->fetch();
149         if (isset($attrs["$dialmode"])){
150           $target= $attrs[$dialmode][0];
151         } else {
152           $target= "";
153         }
155         /* Get source */
156         $ui= get_userinfo();
157         $ldap->cat($ui->dn, array('telephoneNumber'));
158         $attrs= $ldap->fetch();
159         if (isset($attrs["telephoneNumber"])){
160           $source= $attrs['telephoneNumber'][0];
161         } else {
162           $source= "";
163         }
165         /* Save to session */
166         $_SESSION['source']= $source;
167         $_SESSION['target']= $target;
169         /* Perform call */
170         if ($target != "" && $source != ""){
171           $smarty->assign("phone_image", get_template_path('images/phone.png'));
172           $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>"));
173           return($smarty->fetch(get_template_path('dial.tpl', TRUE)));
174           return;
175         } else {
176           print_red (_("You have no personal phone number set. Please change that in order to perform direct dials."));
177         }
178       }
180     }
182     /* Finally dial */
183     if (isset($_POST['dial']) && isset($_SESSION['source']) && isset($_SESSION['target'])){
184       exec ($this->config->current['CTIHOOK']." '".$_SESSION['source']."' '".$_SESSION['target']."'", $dummy, $retval);
185       unset($_SESSION['source']);
186       unset($_SESSION['target']);
187     }
190     /* Delete entry? */
191     if (isset($_POST['delete_entry_confirm'])){
193       /* Some nice guy may send this as POST, so we've to check
194          for the permissions again. */
195       
196       $acl = $this->get_entry_acls($this->dn);
197       if(preg_match("/d/",$acl)){
199         /* Delete request is permitted, perform LDAP action */
200         $ldap= $this->config->get_ldap_link();
201         $ldap->rmdir ($this->dn);
202         show_ldap_error($ldap->get_error(), sprintf(_("Removing of addressbook entry '%s' failed."),$this->dn));
203         gosa_log ("Address book object'".$this->dn."' has been removed");
205       } else {
207         /* Normally this shouldn't be reached, send some extra
208            logs to notify the administrator */
209         print_red (_("You are not allowed to delete this entry!"));
210         gosa_log ("Warning: '".$this->ui->uid."' tried to trick address book deletion.");
211       }
213       /* Remove lock file after successfull deletion */
214       del_lock ($this->dn);
216       /* Clean up */
217       if (isset($_SESSION['saved_start'])){
218         $_GET['start']= $_SESSION['saved_start'];
219       }
220       unset($_SESSION['show_info']);
221       unset($_SESSION['saved_start']);
222     }
225     /* Delete entry? */
226     if (isset($_POST['delete_cancel'])){
227       del_lock ($this->dn);
228     }
231     /* Save address entry? */
232     if (isset($_POST['save'])){
233       $this->save_object();
234       $this->storage_base= $_POST['storage_base'];
236       /* Perform checks */
237       $message= $this->check ();
239       /* No errors, save object */
240       if (count ($message) == 0){
241         $this->save();
242         gosa_log ("Addressbook object '".$this->dn."' has been saved");
244         /* Clean up */
245         if (isset($_SESSION['saved_start'])){
246           $_GET['start']= $_SESSION['saved_start'];
247         }
248         $_SESSION['show_info']= $this->dn;
249         unset($_SESSION['saved_start']);
250       } else {
251         /* Errors found, show message */
252         show_errors ($message);
253       }
254     }
257     /* Close info window */
258     if (isset($_GET['close']) || isset($_POST['cancel'])){
259       if (isset($_SESSION['saved_start'])){
260         $_GET['start']= $_SESSION['saved_start'];
261       }
262       unset($_SESSION['show_info']);
263       unset($_SESSION['saved_start']);
264     }
267     /* Start address book edit mode? */
268     if (isset($_GET['global'])){
269       if (!isset($_SESSION['saved_start']) && isset($_GET['start'])){
270         $_SESSION['saved_start']= $_GET['start'];
271       }
272       switch ($_GET['global']){
273         case "add":
274           $this->dn= "new";
275         $this->orig_cn= "";
277         /* Clean values */
278         foreach ($this->attributes as $name){
279           $this->$name= "";
280         }
281         $this->saved_attributes= array();
282         $this->storage_base= $this->config->current["BASE"];
283         break;
285         case "edit":
286           /* Clean values */
287           foreach ($this->attributes as $name){
288             $this->$name= "";
289           }
290         $this->dn= $_SESSION['show_info']; 
291         $this->load();
292         $this->orig_cn= $this->cn;
293         break;
294         case "remove":
295           $this->dn= $_SESSION['show_info']; 
296         $this->load();
298         /* Load permissions for selected 'dn' and check if
299            we're allowed to remove this 'dn' */
300         $acl = $this->get_entry_acls($this->dn);
301         if(preg_match("/d/",$acl)){
303           /* Check locking, save current plugin in 'back_plugin', so
304              the dialog knows where to return. */
305           if (($user= get_lock($this->dn)) != ""){
306             return(gen_locked_message ($user, $this->dn));
307           }
309           /* Lock the current entry, so nobody will edit it during deletion */
310           $ui= get_userinfo();
311           add_lock ($this->dn, $ui->dn);
312           $smarty->assign("info", sprintf(_("You're about to delete the entry %s."), $this->dn));
313           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
314         } else {
316           /* Obviously the user isn't allowed to delete. Show message and
317              clean session. */
318           print_red (_("You are not allowed to delete this entry!"));
319         }
320       }
321       $_SESSION['show_info']= "ADD";
322     }
325     /* Open info window */
326     if (isset($_GET['show'])){
327       if (!isset($_SESSION['saved_start'])){
328         $_SESSION['saved_start']= $_GET['start'];
329       }
330       $_SESSION['show_info']= base64_decode($_GET['show']);
331     }
334     /* Get ldap link / build filter */
335     $ldap= $this->config->get_ldap_link();
336     $this->telephone_list= array ();
339     /* Assemble bases 
340         (Depending on checkboxes, we search for organisational entries or seperated 
341         adressbook entries within dc=adressbook, ) */
342     $bases= array();
343     $filter= "";
344     if ($phonefilter['global'] == "checked"){
345       $bases[]= preg_replace("/".$this->config->current['BASE']."/", $this->abobjectclass.",".$this->config->current['BASE'], $this->search_base);
346     } else {
347       $filter= '(objectClass=gosaAccount)';
348     }
349     if ($phonefilter['organizational'] == "checked"){
350       $bases[]= $this->search_base;
351     }
354     /* Only display those entries that have at least on of this attributes set */
355     $must_have_this = array("telephoneNumber","facsimileTelephoneNumber","mobile","homePhone","mail");
357     /* Requested attributes in ldap search */
358     $attributes = array("sn", "givenName", "telephoneNumber", "facsimileTelephoneNumber", "mobile", "homePhone", "uid", "mail", "cn");
360     /* Create attribute filter part */
361     $attribute_filter = "";
362     foreach($attributes as $att){
363       $attribute_filter .= "(".$att."=".$s.")";
364     }
366     /* Walk through bases an check for usable entries */
367     foreach ($bases as $base){
369       $ldap->cd ($base);
371       if ($phonefilter['object_type'] == '*'){
372         $ldap->search (
373             "(&(objectClass=person)$filter(!(objectClass=gosaUserTemplate))".   // Skip templates etc ..
374             "(!(uid=*$))".                                                      // Skip entries with ...$ as uid 
375             "(|".$attribute_filter."))"                                         
376           ,$attributes); 
377       } else {
378         $ldap->search ("(&$filter(!(uid=*$))(!(objectClass=gosaUserTemplate))".                     //array
379             "(".$phonefilter['object_type']."=$s))", $attributes);
380       }
382       /* Walk through LDAP results */
383       while ($attrs= $ldap->fetch()){
385         /* prevent empty vaiables */
386         foreach($this->attributes as $atr)          {
387           if(!isset($attrs[$atr][0])) {
388             $attrs[$atr][0] = "";
389           }
390         }
392         /* Check if page number was posted */
393         if(!isset($_GET['start'])) {
394           $_GET['start']="";
395         }
397         /* Check if at least one attribute is specified */
398         $skip = false;
400         foreach($must_have_this as $attr)      {
401           if(isset($attrs[$attr][0]) && !empty($attrs[$attr][0])){
402             $skip =false;
403             break;
404           }
405         }
407         /* Skip all attributes that we are not allowed to read */
408         $any = false;
409         foreach($attributes as $attr){
410     
411           $acls = $this->get_entry_acls($attrs['dn'],$attr);  
412           if(!preg_match("/r/",$acls)){
413             $attrs[$attr][0] = "";
414           }else{
415             $any = true;
416           }
417         }
418  
419         /* Only show lines that have set any mail or phone informations */
420         if(!$skip && $any){      
421   
422           $this->telephone_list[$attrs['sn'][0].$attrs['dn']]=
424             "<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 style='vertical-align:middle;' href=\"main.php?plug=".validate($_GET['plug'])."&amp;start=".validate($_GET['start'])."&amp;show=".base64_encode($attrs['dn'])."\">".$attrs['sn'][0].", ".$attrs['givenName'][0].
425             "</a>
426             </td>
427             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['telephoneNumber'][0]."\">
428             <a style='vertical-align:middle;' href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=telephoneNumber&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($attrs['dn'])."\">".$attrs['telephoneNumber'][0]."
429             </a>
430             </td>
431             <td class=\"phonelist\" title=\"".$attrs['facsimileTelephoneNumber'][0]."\">
432             ".$attrs['facsimileTelephoneNumber'][0]."
433             </td>
434             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['mobile'][0]."\">
435             <a style='vertical-align:middle;' href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=mobile&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($attrs['dn'])."\">".$attrs['mobile'][0]."
436             </a>
437             </td>
438             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['homePhone'][0]."\">
439             <a style='vertical-align:middle;' href=\"main.php?plug=".validate($_GET['plug'])."&amp;dial=homePhone&amp;start=".validate($_GET['start'])."&amp;target=".base64_encode($attrs['dn'])."\">".$attrs['homePhone'][0]."
440             </a>
441             </td>
442             <td>
443             <a href=\"getvcard.php?dn=".base64_encode($attrs['dn'])."\">
444             <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])."\">
445             </a>";
448           if(preg_match("/r/",$this->get_entry_acls($attrs['dn'],"mail"))){
449             if (isset($attrs['mail'][0]) && !empty($attrs['mail'][0])){
450               $dest= sprintf(_("Send mail to %s"), $attrs['mail'][0]);
451               $this->telephone_list[$attrs['sn'][0].$attrs['dn']].=
453                 "<a href=\"mailto:".htmlentities($attrs['mail'][0])."\">".
454                 "<img  align=\"top\" border=0 src=\"images/mailto.png\" alt=\"vcf\" title=\"$dest\"></a>";
455             }
456           }
457           $this->telephone_list[$attrs['sn'][0].$attrs['dn']].= "</td>";
458         }
459       }
460       error_reporting(E_ALL);
461     }
463     /* Sort up list */
464     ksort ($this->telephone_list);
465     reset ($this->telephone_list);
467     /* Fill template variables */
468     $smarty->assign("search_for", $this->search_for);
469     $smarty->assign("object_type", $this->object_type);
471     $this->base = $phonefilter['search_base'];
472     $smarty->assign("deplist", $this->get_allowed_bases());
473     $smarty->assign("depselect", $this->search_base);
474     $smarty->assign("global", $phonefilter['global']);
475     $smarty->assign("organizational", $phonefilter['organizational']);
476     $smarty->assign("search_image", get_template_path('images/search.png'));
477     $smarty->assign("obj_image", get_template_path('images/list_ogroup.png'));
478     $smarty->assign("tree_image", get_template_path('images/tree.png'));
479     $smarty->assign("infoimage", get_template_path('images/info.png'));
480     $smarty->assign("actionimage", get_template_path('images/action.png'));
481     $smarty->assign("launchimage", get_template_path('images/launch.png'));
483     /* Generate alphabet */
484     $alphabet= generate_alphabet();
486     /* Build list output */
487     $output= "";
488     $mod= 0;
491     /* View detailed infos */
492     $smarty->assign("show_info", "");
493     if (isset($_SESSION['show_info'])){
495       $range= 4;
496       $smarty->assign("show_info", "1");
497       $smarty->assign("url", "main.php?plug=".validate($_GET['plug'])."&amp;close=1");
499       $tmp = $this->plInfo();
501       if(isset($_POST['storage_base'])){
502         $this->storage_base = $_POST['storage_base'];  
503       }
505       switch ($_SESSION['show_info']){
507         case "ADD":
509           $a_bases = $this->get_allowed_bases();
510   
511           if(!isset($a_bases[$this->storage_base])){
512             $base = key($this->get_allowed_bases());
513             $this->storage_base = $base;
514           } 
516           $smarty->assign ('storage_base', $this->storage_base);
517           $smarty->assign ('address_info', get_template_path('address_edit.tpl', TRUE));
519           foreach($tmp['plProvidedAcls'] as $name => $translated){
520             $smarty->assign($name."ACL",$this->get_entry_acls($this->abobjectclass.",".$base,$name));
521           }
522         break;
524         default:
525           $smarty->assign ('address_info', get_template_path('address_info.tpl', TRUE));
526           foreach($tmp['plProvidedAcls'] as $name => $translated){
527             $smarty->assign($name."ACL",$this->get_entry_acls($this->dn,$name));
528           }
529         break;
530       }
532       /* Fill variables from LDAP */
533       if ($_SESSION['show_info'] != "ADD"){
534         $ldap->cat($_SESSION['show_info'], $this->attributes);
535         $info= $ldap->fetch();
536       }
537       foreach ($this->attributes as $name){
539         /* Skip entries we are not allowed to read */
540         if(!preg_match("/r/",$this->get_entry_acls($_SESSION['show_info'],$name))){
541           $smarty->assign("info_$name", "");
542         }else
544         if ($_SESSION['show_info'] != "ADD" && isset($info["$name"][0])){
545           error_reporting(0);
546           /* Special treatment for phone attributes */
547           if ($name == "mobile" ||
548               $name == "homePhone" ||
549               $name == "telephoneNumber"){
550             $smarty->assign("info_$name",
551                 "<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>");
552           } else {
553             $smarty->assign("info_$name", preg_replace("/\n/", "<br>", $info["$name"][0]));
554           }
555           error_reporting(E_ALL);
556         } elseif ($_SESSION['show_info'] == "ADD" && isset($this->$name)) {
557           $smarty->assign("info_$name", $this->$name);
558         } else {
559           $smarty->assign("info_$name", "-");
560         }
561       }
562       if (preg_match("/,".$this->abobjectclass.",/", $_SESSION['show_info'])){
563         $storage= _("global addressbook");
564         $smarty->assign("internal", 0);
565       } else {
566         $storage= _("user database");
567         $smarty->assign("internal", 1);
568       }
569       if ($_SESSION['show_info'] != "ADD"){
570         $smarty->assign("storage_info", sprintf(_("Contact stored in '%s'"), $storage));
571       } else {
572         $smarty->assign("storage_info", _("Creating new entry in"));
573       }
574     } else {
577       if(isset($_POST['EntryPerPage'])){
578         $this->range = $_POST['EntryPerPage'];
579       }
580       $range = $this->range;    
581       $smarty->assign("internal", 1);
582     }
583     if (isset($_GET['start'])){
584       $this->start= validate($_GET['start']);
585     }
586     foreach ($this->telephone_list as $val){
587       if ($mod < $this->start) {
588         $mod++;
589         continue;
590       }
591       if ($mod >= ($this->start + $range)){
592         $mod++;
593         break;
594       }
595       if ( ($mod++) & 1){
596         $col= "style=\"background-color: #ECECEC;\"";
597       } else {
598         $col= "style=\"background-color: #F5F5F5;\"";
599       }
600       $output.= "<tr $col>\n$val</tr>\n";
601     }
603     $smarty->assign("search_result", $output);
604     $smarty->assign("apply", apply_filter());
605     $smarty->assign("alphabet", $alphabet);
606     if($range < 20){
607       $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range));
608     }else{
609       $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range, "EntryPerPage"));
610     }
611     $tmp= array("*" => _("All"), "sn" => _("Name"), "givenName" => _("Given name"),
612         "telephoneNumber" => _("Work phone"), "mobile" => _("Cell phone"),
613         "homePhone" => _("Home phone"), "uid" => _("User ID"));
614     natsort($tmp);
615     $smarty->assign("objlist", $tmp);
617     /* Show main page */
618     $smarty->assign ('personal_image', get_template_path('images/addr_personal.png'));
619     $smarty->assign ('home_image', get_template_path('images/addr_home.png'));
620     $smarty->assign ('company_image', get_template_path('images/addr_company.png'));
621     $smarty->assign ('add_image', get_template_path('images/editpaste.png'));
622     $smarty->assign ('edit_image', get_template_path('images/edit.png'));
623     $smarty->assign ('delete_image', get_template_path('images/editdelete.png'));
624     return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
625   }
627   function save_object()
628   {
629     plugin::save_object();
630     foreach($this->attributes as $attr){
632       /* save attributes depending on acls */
633       $acl = $this->get_entry_acls($this->dn,$attr);
635       if(preg_match("/w/",$acl)){
636         if(isset($_POST[$attr])){
637           $this->$attr = $_POST[$attr];
638         }
639       }
641     }
642   }
644   function check()
645   {
646     /* Call common method to give check the hook */
647     $message= plugin::check();
649     /* must: sn, givenName */
650     if ($this->sn == ""){
651       $message[]= _("The required field 'Name' is not set.");
652       return ($message);
653     }
654     if ($this->givenName == ""){
655       $message[]= _("The required field 'Given name' is not set.");
656       return ($message);
657     }
659     /* Check for valid name definition */
660     if (preg_match ("/[\\\\]/", $this->sn)){
661       $message[]= _("The field 'Name' contains invalid characters.");
662     }
663     if (preg_match ("/[\\\\]/", $this->givenName)){
664       $message[]= _("The field 'Given name' contains invalid characters.");
665     }
667     /* Check phone numbers */
668     if (!is_phone_nr($this->homePhone)){
669       $message[]= _("The field 'Phone' contains an invalid phone number.");
670     }
671     if (!is_phone_nr($this->telephoneNumber)){
672       $message[]= _("The field 'Phone' contains an invalid phone number.");
673     }
674     if (!is_phone_nr($this->facsimileTelephoneNumber)){
675       $message[]= _("The field 'Fax' contains an invalid phone number.");
676     }
677     if (!is_phone_nr($this->mobile)){
678       $message[]= _("The field 'Mobile' contains an invalid phone number.");
679     }
680     if (!is_phone_nr($this->pager)){
681       $message[]= _("The field 'Pager' contains an invalid phone number.");
682     }
684     /* Check for reserved characers */
685     if (preg_match ('/[,+"<>;]/', $this->givenName)){
686       $message[]= _("The field 'Given name' contains invalid characters.");
687   }
688   if (preg_match ('/[,+"<>;]/', $this->sn)){
689     $message[]= _("The field 'Name' contains invalid characters.");
690   }
692   /* Check mail */
693   if (!is_email($this->mail)){
694     $message[]= _("Please enter a valid email address in 'Primary address' field.");
695   }
697   /* Assemble cn/dn */
698   $this->cn= $this->givenName." ".$this->sn;
699   if ($this->orig_cn != $this->cn || $this->storage_base != $this->orig_storage_base){
700     $this->new_dn= $this->create_unique_dn("cn", preg_replace("/,*".$this->config->current['BASE']."$/", "", $this->storage_base).",".$this->abobjectclass.",".$this->config->current['BASE']);
701     if ($this->new_dn == "none"){
702       $message[]= _("Cannot create a unique DN for your entry. Please fill more formular fields.");
703       return ($message);
704     }
705   } else {
706     $this->new_dn= $this->dn;
707   }
709   return ($message);
710   }
713   function load()
714   {
715     /* Load base attributes */
716     plugin::plugin ($this->config, $this->dn);
717     $this->storage_base= preg_replace('/^[^,]+,/', '', preg_replace('/'.$this->abobjectclass.',/', '', $this->dn));
718   }
721   function save()
722   {
723     /* First use parents methods to do some basic fillup in $this->attrs */
724     plugin::save ();
726     $this->attrs['cn']= $this->cn;
727     $this->attrs['displayName']= $this->givenName." ".$this->sn;
729     /* Move entry if it got another name... */
730     if ($this->dn != "new" && $this->dn != $this->new_dn){
731       $this->move($this->dn, $this->new_dn);
732     }
733     $this->dn= $this->new_dn;
735     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
736        new entries. So do a check first... */
737     $ldap= $this->config->get_ldap_link();
738     $ldap->cat ($this->dn,array('dn'));
739     if ($ldap->fetch()){
740       $mode= "modify";
741     } else {
742       $mode= "add";
743       $ldap->cd($this->config->current['BASE']);
744       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
745     }
747     /* Finally write data with selected 'mode' */
748     $ldap->cd ($this->dn);
749     $this->cleanup();
750     $ldap->$mode ($this->attrs);
751     if (show_ldap_error($ldap->get_error(), sprintf(_("Removing of addressbook entry '%s' failed."),$this->dn))){
752       return (1);
753     }
754   }
756   
757   /* Return entry acls */
758   function get_entry_acls($dn,$attr = "")
759   {
760     $acls = "";
761   
762     /* Use addressbook acls */
763     if(preg_match("/".normalizePreg($this->abobjectclass)."/",$dn))  {
764       $dn = preg_replace("/".normalizePreg($this->abobjectclass).",/","",$dn);
765       $acls = $this->ui->get_permissions($dn,"addressbook/addressbook",$attr);
766     }
767     
768     /* Use Organizational Person acls */
769     else{
770       $acls = $this->ui->get_permissions($dn,"users/user",$attr);
771     }
773     return($acls);
774   }
777   /* Return plugin informations for acl handling  */
778   function plInfo()
779   {
780     return (array(
781           "plShortName" => _("Addressbook"),
782           "plDescription" => _("Addressbook entry acls"),
783           "plSelfModify"  => FALSE,
784           "plDepends"     => array(),
785           "plPriority"    => 0,
786           "plSection"     => array("addons" => _("Addons")),
787           "plCategory"    => array("addressbook" => array("objectClass" => "inetOrgPerson", "description" => _("Addressbook"))),
789           "plProvidedAcls"    => array(
790             "sn"                        => _("Surename"),         
791             "givenName"                 => _("Given name"), 
792             "telephoneNumber"           => _("Telefon number"), 
793             "facsimileTelephoneNumber"  => _("Fax number"), 
794             "mobile"                    => _("Mobile number"), 
795             "homePhone"                 => _("Home phone number"), 
796             "uid"                       => _("User identification"), 
797             "mail"                      => _("Mail address"), 
798             "pager"                     => _("Pager"),
799             "o"                         => _("Organization"),
800             "ou"                        => _("Department"),
801             "l"                         => _("Location"),
802             "postalAddress"             => _("Postal address"),
803             "postalCode"                => _("Postal address"),
804             "st"                        => _("State"),
805             "initials"                  => _("Initials"), 
806             "title"                     => _("Title"), 
807             "homePostalAddress"         => _("Home postal address"), 
808             "cn"                        => _("Common name"))
809             ));
810   }
812 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
813 ?>