Code

msgPool
[gosa.git] / gosa-plugins / addressbook / 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                    = "";
46   var $view_logged              = FALSE;
48         /* attribute list for save action */
49         var $attributes= array("sn", "givenName", "mail", "title",
50                         "initials", "homePostalAddress", "displayName",
51                         "homePhone", "mobile", "o", "postalAddress", "l",
52                         "postalCode", "st", "ou", "telephoneNumber",
53                         "facsimileTelephoneNumber", "pager");
55         var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson");
57         var $abobjectclass= "dc=addressbook";
59   function addressbook (&$config, $dn= NULL)
60   {
61     /* Include config object */
62     $this->config= &$config;
64     /* Check if there is a special ldap-sub-tree specified, instead of dc=addressbook, */
65     $aoc = $this->config->search("addressbook", "LDAP_OBJECT_CLASS",array('menu'));
66     if ($aoc != ""){
67       $this->abobjectclass  = $aoc;
68     }
70     /* Get global filter config */
71     if (!session::is_set("phonefilter")){
72       $ui         = get_userinfo();
73       $base       = get_base_from_people($ui->dn);
74       $phonefilter= array(
75           "search_base"       => $base,
76           "organizational"    => "checked",
77           "global"            => "checked",
78           "search_for"        => "*",
79           "object_type"       => "*");
80       session::set("phonefilter", $phonefilter);
81     }
82      
83     $this->ui = get_userinfo();
84   }
86   function execute()
87   {
88     /* Call parent execute */
89     plugin::execute();
91     $smarty= get_smarty();
93     /* Prevent empty variables for smarty */
94     foreach($this->attributes as $atr) {
95       $smarty->assign($atr,"");
96     }
98     /* Save formular information */
99     $phonefilter= session::get("phonefilter");
100     foreach( array("search_for", "search_base", "object_type") as $type){
101       if (isset($_POST[$type])){
102         $phonefilter[$type]= $_POST[$type];
103       }
104       $this->$type= $phonefilter[$type];
105     }
106     if (isset($_POST['search_base'])){
107       foreach( array("organizational", "global") as $type){
108         if (isset($_POST[$type])){
109           $phonefilter[$type]= "checked";
110         } else {
111           $phonefilter[$type]= "";
112         }
113       }
114     }
116     /* Search string */
117     $s= $phonefilter['search_for'];
118     if ($s == "") {
119       $s= "*";
120     }
121     if (isset($_GET['search'])){
122       $s= validate(mb_substr($_GET['search'], 0, 1, "UTF8"))."*";
123       if ($s == "**"){
124         $s= "*";
125       }
126       $this->search_for= $s;
127       $phonefilter['search_for']= $s;
128     }
129     session::set("phonefilter", $phonefilter);
131     /* Assign create acl */
132     $acl = $this->get_entry_acls($this->abobjectclass.",".$phonefilter['search_base']);
133     $smarty->assign("internal_createable", preg_match("/c/",$acl));
134     $smarty->assign("internal_removeable", preg_match("/d/",$acl));
135     $smarty->assign("internal_editable",   preg_match("/w/",$acl));
137     /* Perform actions with CTI hook */
138     if (isset($_GET['target'])
139         && isset($_GET['dial'])
140         && isset($this->config->current['CTIHOOK'])){
142       $dialmode= $_GET['dial'];
143       if ($dialmode == "telephoneNumber" ||
144           $dialmode == "mobile" ||
145           $dialmode == "homePhone"){
147         /* Get target */
148         $ldap= $this->config->get_ldap_link();
149         $ldap->cat(base64_decode($_GET['target']), array('telephoneNumber', 'mobile', 'homePhone'));
150         $attrs= $ldap->fetch();
151         if (isset($attrs["$dialmode"])){
152           $target= $attrs[$dialmode][0];
153         } else {
154           $target= "";
155         }
157         /* Get source */
158         $ui= get_userinfo();
159         $ldap->cat($ui->dn, array('telephoneNumber'));
160         $attrs= $ldap->fetch();
161         if (isset($attrs["telephoneNumber"])){
162           $source= $attrs['telephoneNumber'][0];
163         } else {
164           $source= "";
165         }
167         /* Save to session */
168         session::set('source',$source);
169         session::set('target',$target);
171         /* Perform call */
172         if ($target != "" && $source != ""){
173           $smarty->assign("phone_image", get_template_path('images/phone.png'));
174           $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>"));
175           return($smarty->fetch(get_template_path('dial.tpl', TRUE)));
176           return;
177         } else {
178           msg_dialog::display(_("Error"), _("You need to set your personal phone number in order to perform direct dials."), ERROR_DIALOG);
179         }
180       }
182     }
184     /* Finally dial */
185     if (isset($_POST['dial']) && session::is_set('source') && session::is_set('target')){
186       exec ($this->config->current['CTIHOOK']." '".session::get('source')."' '".session::get('target')."'", $dummy, $retval);
187       session::un_set('source');
188       session::un_set('target');
189     }
192     /* Delete entry? */
193     if (isset($_POST['delete_entry_confirm'])){
195       /* Some nice guy may send this as POST, so we've to check
196          for the permissions again. */
197       
198       $acl = $this->get_entry_acls($this->dn);
199       if(preg_match("/d/",$acl)){
201         /* Delete request is permitted, perform LDAP action */
202         $ldap= $this->config->get_ldap_link();
203         $ldap->rmdir ($this->dn);
204         new log("remove","addressbook/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
205         show_ldap_error($ldap->get_error(), sprintf(_("Removing of addressbook entry '%s' failed."),$this->dn));
206         new log("remove","addressbook/".get_class($this),$this->dn,array(),"Address book object'".$this->dn."' has been removed");
207   
208       } else {
210         /* Normally this shouldn't be reached, send some extra
211            logs to notify the administrator */
212         msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
213         new log("remove","addressbook/".get_class($this),$this->dn,array(),"Warning: '".$this->ui->uid."' tried to trick address book deletion.");
214       }
216       /* Remove lock file after successfull deletion */
217       del_lock ($this->dn);
219       /* Clean up */
220       if (session::is_set('saved_start')){
221         $_GET['start']= session::get('saved_start');
222       }
223       session::un_set('show_info');
224       session::un_set('saved_start');
225     }
228     /* Delete entry? */
229     if (isset($_POST['delete_cancel'])){
230       del_lock ($this->dn);
231     }
234     /* Save address entry? */
235     if (isset($_POST['save'])){
236       $this->save_object();
237       $this->storage_base= $_POST['storage_base'];
239       /* Perform checks */
240       $message= $this->check ();
242       /* No errors, save object */
243       if (count ($message) == 0){
244         $this->save();
246         /* Clean up */
247         if (session::is_set('saved_start')){
248           $_GET['start']= session::get('saved_start');
249         }
250         session::set('show_info',$this->dn);
251         session::un_set('saved_start');
252       } else {
253         /* Errors found, show message */
254         show_errors ($message);
255       }
256     }
259     /* Close info window */
260     if (isset($_GET['close']) || isset($_POST['cancel'])){
261       if (session::is_set('saved_start')){
262         $_GET['start']= session::get('saved_start');
263       }
264       session::un_set('show_info');
265       session::un_set('saved_start');
266     }
269     /* Start address book edit mode? */
270     if (isset($_GET['global'])){
271       if (!session::is_set('saved_start') && isset($_GET['start'])){
272         session::set('saved_start',$_GET['start']);
273       }
274       switch ($_GET['global']){
275         case "add":
276           $this->dn= "new";
277         $this->orig_cn= "";
279         /* Clean values */
280         foreach ($this->attributes as $name){
281           $this->$name= "";
282         }
283         $this->saved_attributes= array();
284         $this->storage_base= $this->config->current["BASE"];
285         break;
287         case "edit":
288           /* Clean values */
289           foreach ($this->attributes as $name){
290             $this->$name= "";
291           }
292         $this->dn= session::get('show_info'); 
293         $this->load();
294         $this->orig_cn= $this->cn;
295         break;
296         case "remove":
297           $this->dn= session::get('show_info'); 
298         $this->load();
300         /* Load permissions for selected 'dn' and check if
301            we're allowed to remove this 'dn' */
302         $acl = $this->get_entry_acls($this->dn);
303         if(preg_match("/d/",$acl)){
305           /* Check locking, save current plugin in 'back_plugin', so
306              the dialog knows where to return. */
307           if (($user= get_lock($this->dn)) != ""){
308             return(gen_locked_message ($user, $this->dn));
309           }
311           /* Lock the current entry, so nobody will edit it during deletion */
312           $ui= get_userinfo();
313           add_lock ($this->dn, $ui->dn);
314           $smarty->assign("info", sprintf(_("You're about to delete the entry %s."), $this->dn));
315           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
316         } else {
318           /* Obviously the user isn't allowed to delete. Show message and
319              clean session. */
320           msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
321         }
322       }
323       session::set('show_info',"ADD");
324     }
327     /* Open info window */
328     if (isset($_GET['show'])){
329       if (!session::is_set('saved_start')){
330         session::set('saved_start',$_GET['start']);
331       }
332       $this->dn = base64_decode($_GET['show']);
333       $this->view_logged =FALSE;
334       if(!$this->view_logged){
335         $this->view_logged = TRUE;
336         new log("view","addressbook/".get_class($this),$this->dn);
337       }
338       session::set('show_info',base64_decode($_GET['show']));
339     }
342     /* Get ldap link / build filter */
343     $ldap= $this->config->get_ldap_link();
344     $this->telephone_list= array ();
347     /* Assemble bases 
348         (Depending on checkboxes, we search for organisational entries or seperated 
349         adressbook entries within dc=adressbook, ) */
350     $bases= array();
351     $filter= "";
352     if ($phonefilter['global'] == "checked"){
353       $bases[]= preg_replace("/".$this->config->current['BASE']."/", $this->abobjectclass.",".$this->config->current['BASE'], $this->search_base);
354     } else {
355       $filter= '(objectClass=gosaAccount)';
356     }
357     if ($phonefilter['organizational'] == "checked"){
358       $bases[]= $this->search_base;
359     }
362     /* Only display those entries that have at least on of this attributes set */
363     $must_have_this = array("telephoneNumber","facsimileTelephoneNumber","mobile","homePhone","mail");
365     /* Requested attributes in ldap search */
366     $attributes = array("sn", "givenName", "telephoneNumber", "facsimileTelephoneNumber", "mobile", "homePhone", "uid", "mail", "cn");
368     /* Create attribute filter part */
369     $attribute_filter = "";
370     foreach($attributes as $att){
371       $attribute_filter .= "(".$att."=".$s.")";
372     }
374     /* Walk through bases an check for usable entries */
375     foreach ($bases as $base){
377       $ldap->cd ($base);
379       if ($phonefilter['object_type'] == '*'){
380         $ldap->search (
381             "(&(objectClass=person)$filter(!(objectClass=gosaUserTemplate))".   // Skip templates etc ..
382             "(!(uid=*$))".                                                      // Skip entries with ...$ as uid 
383             "(|".$attribute_filter."))"                                         
384           ,$attributes); 
385       } else {
386         $ldap->search ("(&$filter(!(uid=*$))(!(objectClass=gosaUserTemplate))".                     //array
387             "(".$phonefilter['object_type']."=$s))", $attributes);
388       }
390       /* Walk through LDAP results */
391       while ($attrs= $ldap->fetch()){
393         /* prevent empty vaiables */
394         foreach($this->attributes as $atr)          {
395           if(!isset($attrs[$atr][0])) {
396             $attrs[$atr][0] = "";
397           }
398         }
400         /* Check if page number was posted */
401         if(!isset($_GET['start'])) {
402           $_GET['start']="";
403         }
405         /* Check if at least one attribute is specified */
406         $skip = false;
408         foreach($must_have_this as $attr)      {
409           if(isset($attrs[$attr][0]) && !empty($attrs[$attr][0])){
410             $skip =false;
411             break;
412           }
413         }
415         /* Skip all attributes that we are not allowed to read */
416         $any = false;
417         foreach($attributes as $attr){
418     
419           $acls = $this->get_entry_acls($attrs['dn'],$attr);  
420           if(!preg_match("/r/",$acls)){
421             $attrs[$attr][0] = "";
422           }else{
423             $any = true;
424           }
425         }
426  
427         /* Only show lines that have set any mail or phone informations */
428         if(!$skip && $any){      
429   
430           $this->telephone_list[$attrs['sn'][0].$attrs['dn']]=
432             "<td class=\"phonelist\" title=\"".$attrs['sn'][0].", ".$attrs['givenName'][0].
433               "\"onClick='location.href=\"main.php?plug=".validate($_GET['plug']).
434                           "&amp;start=".validate($_GET['start']).
435                           "&amp;show=".urlencode(base64_encode($attrs['dn']))."\"'>
436               <a style='vertical-align:middle;' href=\"main.php?plug=".validate($_GET['plug']).
437                           "&amp;start=".validate($_GET['start']).
438                           "&amp;show=".urlencode(base64_encode($attrs['dn']))."\">".
439                $attrs['sn'][0].", ".$attrs['givenName'][0].
440             "</a>
441             &nbsp;</td>
442             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['telephoneNumber'][0]."\">
443             <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]."
444             </a>
445             &nbsp;</td>
446             <td class=\"phonelist\" title=\"".$attrs['facsimileTelephoneNumber'][0]."\">
447             ".$attrs['facsimileTelephoneNumber'][0]."
448             &nbsp;</td>
449             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['mobile'][0]."\">
450             <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]."
451             </a>
452             &nbsp;</td>
453             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['homePhone'][0]."\">
454             <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]."
455             </a>
456             &nbsp;</td>
457             <td>
458             <a href=\"getvcard.php?dn=".base64_encode($attrs['dn'])."\">
459             <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])."\">
460             </a>";
463           if(preg_match("/r/",$this->get_entry_acls($attrs['dn'],"mail"))){
464             if (isset($attrs['mail'][0]) && !empty($attrs['mail'][0])){
465               $dest= sprintf(_("Send mail to %s"), $attrs['mail'][0]);
466               $this->telephone_list[$attrs['sn'][0].$attrs['dn']].=
468                 "<a href=\"mailto:".htmlentities($attrs['mail'][0])."\">".
469                 "<img  align=\"top\" border=0 src=\"images/mailto.png\" alt=\"vcf\" title=\"$dest\"></a>";
470             }
471           }
472           $this->telephone_list[$attrs['sn'][0].$attrs['dn']].= "&nbsp;</td>";
473         }
474       }
475       error_reporting(E_ALL | E_STRICT);
476     }
478     /* Sort up list */
479     ksort ($this->telephone_list);
480     reset ($this->telephone_list);
482     /* Fill template variables */
483     $smarty->assign("search_for", $this->search_for);
484     $smarty->assign("object_type", $this->object_type);
486     $this->base = $phonefilter['search_base'];
487     $smarty->assign("deplist", $this->get_allowed_bases());
488     $smarty->assign("depselect", $this->search_base);
489     $smarty->assign("global", $phonefilter['global']);
490     $smarty->assign("organizational", $phonefilter['organizational']);
491     $smarty->assign("search_image", get_template_path('images/search.png'));
492     $smarty->assign("obj_image", get_template_path('images/list_ogroup.png'));
493     $smarty->assign("tree_image", get_template_path('images/tree.png'));
494     $smarty->assign("infoimage", get_template_path('images/info.png'));
495     $smarty->assign("actionimage", get_template_path('images/action.png'));
496     $smarty->assign("launchimage", get_template_path('images/launch.png'));
498     /* Generate alphabet */
499     $alphabet= generate_alphabet();
501     /* Build list output */
502     $output= "";
503     $mod= 0;
506     /* View detailed infos */
507     $smarty->assign("show_info", "");
508     if (session::is_set('show_info')){
510       $range= 4;
511       $smarty->assign("show_info", "1");
512       $smarty->assign("url", "main.php?plug=".validate($_GET['plug'])."&amp;close=1");
514       $tmp = $this->plInfo();
516       if(isset($_POST['storage_base'])){
517         $this->storage_base = $_POST['storage_base'];  
518       }
520       switch (session::get('show_info')){
522         case "ADD":
524           $a_bases = $this->get_allowed_bases();
525   
526           if(!isset($a_bases[$this->storage_base])){
527             $base = key($this->get_allowed_bases());
528             $this->storage_base = $base;
529           } 
531           $smarty->assign ('storage_base', $this->storage_base);
532           $smarty->assign ('address_info', get_template_path('address_edit.tpl', TRUE));
534           foreach($tmp['plProvidedAcls'] as $name => $translated){
535             $smarty->assign($name."ACL",$this->get_entry_acls($this->abobjectclass.",".$base,$name));
536           }
537         break;
539         default:
540           $smarty->assign ('address_info', get_template_path('address_info.tpl', TRUE));
541           foreach($tmp['plProvidedAcls'] as $name => $translated){
542             $smarty->assign($name."ACL",$this->get_entry_acls($this->dn,$name));
543           }
544         break;
545       }
547       /* Fill variables from LDAP */
548       if (session::get('show_info') != "ADD"){
549         $ldap->cat(session::get('show_info'), $this->attributes);
550         $info= $ldap->fetch();
551       }
552       foreach ($this->attributes as $name){
554         /* Skip entries we are not allowed to read */
555         if(!preg_match("/r/",$this->get_entry_acls($this->dn,$name))){
556           $smarty->assign("info_$name", "");
557         }else
559         if (session::get('show_info') != "ADD" && isset($info["$name"][0])){
560           error_reporting(0);
561           /* Special treatment for phone attributes */
562           if ($name == "mobile" ||
563               $name == "homePhone" ||
564               $name == "telephoneNumber"){
565             $smarty->assign("info_$name",
566                 "<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::get('show_info'))."\">".$info["$name"][0]."</a>");
567           } else {
568             $smarty->assign("info_$name", preg_replace("/\n/", "<br>", $info["$name"][0]));
569           }
570           error_reporting(E_ALL | E_STRICT);
571         } elseif (session::get('show_info') == "ADD" && isset($this->$name)) {
572           $smarty->assign("info_$name", $this->$name);
573         } else {
574           $smarty->assign("info_$name", "-");
575         }
576       }
577       if (preg_match("/,".$this->abobjectclass.",/", session::get('show_info'))){
578         $storage= _("global addressbook");
579         $smarty->assign("internal", 0);
580       } else {
581         $storage= _("user database");
582         $smarty->assign("internal", 1);
583       }
584       if (session::get('show_info') != "ADD"){
585         $smarty->assign("storage_info", sprintf(_("Contact stored in '%s'"), $storage));
586       } else {
587         $smarty->assign("storage_info", _("Creating new entry in"));
588       }
589     } else {
592       if(isset($_POST['EntryPerPage'])){
593         $this->range = $_POST['EntryPerPage'];
594       }
595       $range = $this->range;    
596       $smarty->assign("internal", 1);
597     }
598     if (isset($_GET['start'])){
599       $this->start= validate($_GET['start']);
600     }
601     foreach ($this->telephone_list as $val){
602       if ($mod < $this->start) {
603         $mod++;
604         continue;
605       }
606       if ($mod >= ($this->start + $range)){
607         $mod++;
608         break;
609       }
610       if ( ($mod++) & 1){
611         $col= "style=\"background-color: #ECECEC;\"";
612       } else {
613         $col= "style=\"background-color: #F5F5F5;\"";
614       }
615       $output.= "<tr $col>\n$val</tr>\n";
616     }
618     $smarty->assign("search_result", $output);
619     $smarty->assign("apply", apply_filter());
620     $smarty->assign("alphabet", $alphabet);
621     if($range < 20){
622       $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range));
623     }else{
624       $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range, "EntryPerPage"));
625     }
626     $tmp= array("*" => _("All"), "sn" => _("Name"), "givenName" => _("Given name"),
627         "telephoneNumber" => _("Work phone"), "mobile" => _("Cell phone"),
628         "homePhone" => _("Home phone"), "uid" => _("User ID"));
629     natsort($tmp);
630     $smarty->assign("objlist", $tmp);
632     /* Show main page */
633     $smarty->assign ('personal_image', get_template_path('images/addr_personal.png'));
634     $smarty->assign ('home_image', get_template_path('images/addr_home.png'));
635     $smarty->assign ('company_image', get_template_path('images/addr_company.png'));
636     $smarty->assign ('add_image', get_template_path('images/editpaste.png'));
637     $smarty->assign ('edit_image', get_template_path('images/edit.png'));
638     $smarty->assign ('delete_image', get_template_path('images/editdelete.png'));
639     return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
640   }
642   function save_object()
643   {
644     plugin::save_object();
645     foreach($this->attributes as $attr){
647       /* save attributes depending on acls */
648       $acl = $this->get_entry_acls($this->dn,$attr);
650       if(preg_match("/w/",$acl)){
651         if(isset($_POST[$attr])){
652           $this->$attr = $_POST[$attr];
653         }
654       }
656     }
657   }
659   function check()
660   {
661     /* Call common method to give check the hook */
662     $message= plugin::check();
664     /* must: sn, givenName */
665     if ($this->sn == ""){
666       $message[] = msgPool::required(_("Name"));
667       return ($message);
668     }
669     if ($this->givenName == ""){
670       $message[] = msgPool::required(_("Given name"));
671       return ($message);
672     }
674     /* Check for valid name definition */
675     if (preg_match ("/[\\\\]/", $this->sn)){
676       $message[] = msgPool::invalid(_("Name"),$this->sn,"/[\\\\]");
677     }
678     if (preg_match ("/[\\\\]/", $this->givenName)){
679       $message[] = msgPool::invalid(_("Given name"),$this->givenName,"/[\\\\]");
680     }
682     /* Check phone numbers */
683     if (!tests::is_phone_nr($this->homePhone)){
684       $message[] = msgPool::invalid(_("Phone"),$this->homePhone);
685     }
686     if (!tests::is_phone_nr($this->telephoneNumber)){
687       $message[] = msgPool::invalid(_("Telephone number"),$this->telephoneNumber);
688     }
689     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
690       $message[] = msgPool::invalid(_("Fax"),$this->facsimileTelephoneNumber);
691     }
692     if (!tests::is_phone_nr($this->mobile)){
693       $message[] = msgPool::invalid(_("Mobile"),$this->mobile);
694     }
695     if (!tests::is_phone_nr($this->pager)){
696       $message[] = msgPool::invalid(_("Pager"),$this->pager);
697     }
698     /* Check for reserved characers */
699     if (preg_match ('/[,+"<>;]/', $this->givenName)){
700       $message[] = msgPool::invalid(_("Given name"),$this->givenName,'/[,+"<>;]/');
701   }
702   if (preg_match ('/[,+"<>;]/', $this->sn)){
703     $message[] = msgPool::invalid(_("Name"),$this->sn,'/[,+"<>;]/');
704   }
706   /* Check mail */
707   if (!tests::is_email($this->mail)){
708     $message[] = msgPool::invalid(_("Email"),"","","example@your-domain.com");
709   }
711   /* Assemble cn/dn */
712   $this->cn= $this->givenName." ".$this->sn;
713   if ($this->orig_cn != $this->cn || $this->storage_base != $this->orig_storage_base){
714     $this->new_dn= $this->create_unique_dn("cn", preg_replace("/,*".$this->config->current['BASE']."$/", "", $this->storage_base).",".$this->abobjectclass.",".$this->config->current['BASE']);
715     if ($this->new_dn == "none"){
716       $message[]= _("Cannot create a unique DN for your entry. Please fill more formular fields.");
717       return ($message);
718     }
719   } else {
720     $this->new_dn= $this->dn;
721   }
723   return ($message);
724   }
727   function load()
728   {
729     /* Load base attributes */
730     plugin::plugin ($this->config, $this->dn);
731     $this->view_logged = FALSE;
732     $this->storage_base= preg_replace('/^[^,]+,/', '', preg_replace('/'.$this->abobjectclass.',/', '', $this->dn));
733   }
736   function save()
737   {
738     /* First use parents methods to do some basic fillup in $this->attrs */
739     plugin::save ();
741     $this->attrs['cn']= $this->cn;
742     $this->attrs['displayName']= $this->givenName." ".$this->sn;
744     /* Move entry if it got another name... */
745     if ($this->dn != "new" && $this->dn != $this->new_dn){
746       $this->move($this->dn, $this->new_dn);
747     }
748     $this->dn= $this->new_dn;
750     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
751        new entries. So do a check first... */
752     $ldap= $this->config->get_ldap_link();
753     $ldap->cat ($this->dn,array('dn'));
754     if ($ldap->fetch()){
755       $mode= "modify";
756     } else {
757       $mode= "add";
758       $ldap->cd($this->config->current['BASE']);
759       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
760     }
762     /* Finally write data with selected 'mode' */
763     $ldap->cd ($this->dn);
764     $this->cleanup();
765     $ldap->$mode ($this->attrs);
766     if (show_ldap_error($ldap->get_error(), sprintf(_("Removing of addressbook entry '%s' failed."),$this->dn))){
767       return (1);
768     }
770     if($mode == "add"){
771       new log("create","addressbook/".get_class($this),$this->dn, array_keys($this->attrs),$ldap->get_error());
772     }else{
773       new log("modify","addressbook/".get_class($this),$this->dn, array_keys($this->attrs),$ldap->get_error());
774     }
775   }
777   
778   /* Return entry acls */
779   function get_entry_acls($dn,$attr = "")
780   {
781     $acls = "";
782   
783     /* Use addressbook acls */
784     if(preg_match("/".normalizePreg($this->abobjectclass)."/",$dn))  {
785       $dn = preg_replace("/".normalizePreg($this->abobjectclass).",/","",$dn);
786       $acls = $this->ui->get_permissions($dn,"addressbook/addressbook",$attr);
787     }
788     
789     /* Use Organizational Person acls */
790     else{
791       $acls = $this->ui->get_permissions($dn,"users/user",$attr);
792     }
794     return($acls);
795   }
798   /* Return plugin informations for acl handling  */
799   static function plInfo()
800   {
801     return (array(
802           "plShortName" => _("Addressbook"),
803           "plDescription" => _("Addressbook entry acls"),
804           "plSelfModify"  => FALSE,
805           "plDepends"     => array(),
806           "plPriority"    => 0,
807           "plSection"     => array("addons" => _("Addons")),
808           "plCategory"    => array("addressbook" => array("objectClass" => "inetOrgPerson", "description" => _("Addressbook"))),
810           "plProvidedAcls"    => array(
811             "sn"                        => _("Surename"),         
812             "givenName"                 => _("Given name"), 
813             "telephoneNumber"           => _("Telefon number"), 
814             "facsimileTelephoneNumber"  => _("Fax number"), 
815             "mobile"                    => _("Mobile number"), 
816             "homePhone"                 => _("Home phone number"), 
817             "uid"                       => _("User identification"), 
818             "mail"                      => _("Mail address"), 
819             "pager"                     => _("Pager"),
820             "o"                         => _("Organization"),
821             "ou"                        => _("Department"),
822             "l"                         => _("Location"),
823             "postalAddress"             => _("Postal address"),
824             "postalCode"                => _("Postal address"),
825             "st"                        => _("State"),
826             "initials"                  => _("Initials"), 
827             "title"                     => _("Title"), 
828             "homePostalAddress"         => _("Home postal address"), 
829             "cn"                        => _("Common name"))
830             ));
831   }
833 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
834 ?>