Code

Updated Strings
[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         if (!$ldap->success()){
206           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
207         }
208         new log("remove","addressbook/".get_class($this),$this->dn,array(),"Addressbook object'".$this->dn."' has been removed");
209   
210       } else {
212         /* Normally this shouldn't be reached, send some extra
213            logs to notify the administrator */
214               msg_dialog::permDelete($this->dn);
215         new log("remove","addressbook/".get_class($this),$this->dn,array(),"Warning: '".$this->ui->uid."' tried to trick address book deletion.");
216       }
218       /* Remove lock file after successfull deletion */
219       del_lock ($this->dn);
221       /* Clean up */
222       if (session::is_set('saved_start')){
223         $_GET['start']= session::get('saved_start');
224       }
225       session::un_set('show_info');
226       session::un_set('saved_start');
227     }
230     /* Delete entry? */
231     if (isset($_POST['delete_cancel'])){
232       del_lock ($this->dn);
233     }
236     /* Save address entry? */
237     if (isset($_POST['save'])){
238       $this->save_object();
239       $this->storage_base= $_POST['storage_base'];
241       /* Perform checks */
242       $message= $this->check ();
244       /* No errors, save object */
245       if (count ($message) == 0){
246         $this->save();
248         /* Clean up */
249         if (session::is_set('saved_start')){
250           $_GET['start']= session::get('saved_start');
251         }
252         session::set('show_info',$this->dn);
253         session::un_set('saved_start');
254       } else {
255         /* Errors found, show message */
256         msgDialog::displayChecks($message);
257       }
258     }
261     /* Close info window */
262     if (isset($_GET['close']) || isset($_POST['cancel'])){
263       if (session::is_set('saved_start')){
264         $_GET['start']= session::get('saved_start');
265       }
266       session::un_set('show_info');
267       session::un_set('saved_start');
268     }
271     /* Start address book edit mode? */
272     if (isset($_GET['global'])){
273       if (!session::is_set('saved_start') && isset($_GET['start'])){
274         session::set('saved_start',$_GET['start']);
275       }
276       switch ($_GET['global']){
277         case "add":
278           $this->dn= "new";
279         $this->orig_cn= "";
281         /* Clean values */
282         foreach ($this->attributes as $name){
283           $this->$name= "";
284         }
285         $this->saved_attributes= array();
286         $this->storage_base= $this->config->current["BASE"];
287         break;
289         case "edit":
290           /* Clean values */
291           foreach ($this->attributes as $name){
292             $this->$name= "";
293           }
294         $this->dn= session::get('show_info'); 
295         $this->load();
296         $this->orig_cn= $this->cn;
297         break;
298         case "remove":
299           $this->dn= session::get('show_info'); 
300         $this->load();
302         /* Load permissions for selected 'dn' and check if
303            we're allowed to remove this 'dn' */
304         $acl = $this->get_entry_acls($this->dn);
305         if(preg_match("/d/",$acl)){
307           /* Check locking, save current plugin in 'back_plugin', so
308              the dialog knows where to return. */
309           if (($user= get_lock($this->dn)) != ""){
310             return(gen_locked_message ($user, $this->dn));
311           }
313           /* Lock the current entry, so nobody will edit it during deletion */
314           $ui= get_userinfo();
315           add_lock ($this->dn, $ui->dn);
316           $smarty->assign("info", sprintf(_("You're about to delete the entry %s."), $this->dn));
317           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
318         } else {
320           /* Obviously the user isn't allowed to delete. Show message and
321              clean session. */
322                 msg_dialog::permDelete($this->dn);
323         }
324       }
325       session::set('show_info',"ADD");
326     }
329     /* Open info window */
330     if (isset($_GET['show'])){
331       if (!session::is_set('saved_start')){
332         session::set('saved_start',$_GET['start']);
333       }
334       $this->dn = base64_decode($_GET['show']);
335       $this->view_logged =FALSE;
336       if(!$this->view_logged){
337         $this->view_logged = TRUE;
338         new log("view","addressbook/".get_class($this),$this->dn);
339       }
340       session::set('show_info',base64_decode($_GET['show']));
341     }
344     /* Get ldap link / build filter */
345     $ldap= $this->config->get_ldap_link();
346     $this->telephone_list= array ();
349     /* Assemble bases 
350         (Depending on checkboxes, we search for organisational entries or seperated 
351         adressbook entries within dc=adressbook, ) */
352     $bases= array();
353     $filter= "";
354     if ($phonefilter['global'] == "checked"){
355       $bases[]= preg_replace("/".$this->config->current['BASE']."/", $this->abobjectclass.",".$this->config->current['BASE'], $this->search_base);
356     } else {
357       $filter= '(objectClass=gosaAccount)';
358     }
359     if ($phonefilter['organizational'] == "checked"){
360       $bases[]= $this->search_base;
361     }
364     /* Only display those entries that have at least on of this attributes set */
365     $must_have_this = array("telephoneNumber","facsimileTelephoneNumber","mobile","homePhone","mail");
367     /* Requested attributes in ldap search */
368     $attributes = array("sn", "givenName", "telephoneNumber", "facsimileTelephoneNumber", "mobile", "homePhone", "uid", "mail", "cn");
370     /* Create attribute filter part */
371     $attribute_filter = "";
372     foreach($attributes as $att){
373       $attribute_filter .= "(".$att."=".$s.")";
374     }
376     /* Walk through bases an check for usable entries */
377     foreach ($bases as $base){
379       $ldap->cd ($base);
381       if ($phonefilter['object_type'] == '*'){
382         $ldap->search (
383             "(&(objectClass=person)$filter(!(objectClass=gosaUserTemplate))".   // Skip templates etc ..
384             "(!(uid=*$))".                                                      // Skip entries with ...$ as uid 
385             "(|".$attribute_filter."))"                                         
386           ,$attributes); 
387       } else {
388         $ldap->search ("(&$filter(!(uid=*$))(!(objectClass=gosaUserTemplate))".                     //array
389             "(".$phonefilter['object_type']."=$s))", $attributes);
390       }
392       /* Walk through LDAP results */
393       while ($attrs= $ldap->fetch()){
395         /* prevent empty vaiables */
396         foreach($this->attributes as $atr)          {
397           if(!isset($attrs[$atr][0])) {
398             $attrs[$atr][0] = "";
399           }
400         }
402         /* Check if page number was posted */
403         if(!isset($_GET['start'])) {
404           $_GET['start']="";
405         }
407         /* Check if at least one attribute is specified */
408         $skip = false;
410         foreach($must_have_this as $attr)      {
411           if(isset($attrs[$attr][0]) && !empty($attrs[$attr][0])){
412             $skip =false;
413             break;
414           }
415         }
417         /* Skip all attributes that we are not allowed to read */
418         $any = false;
419         foreach($attributes as $attr){
420     
421           $acls = $this->get_entry_acls($attrs['dn'],$attr);  
422           if(!preg_match("/r/",$acls)){
423             $attrs[$attr][0] = "";
424           }else{
425             $any = true;
426           }
427         }
428  
429         /* Only show lines that have set any mail or phone informations */
430         if(!$skip && $any){      
431   
432           $this->telephone_list[$attrs['sn'][0].$attrs['dn']]=
434             "<td class=\"phonelist\" title=\"".$attrs['sn'][0].", ".$attrs['givenName'][0].
435               "\"onClick='location.href=\"main.php?plug=".validate($_GET['plug']).
436                           "&amp;start=".validate($_GET['start']).
437                           "&amp;show=".urlencode(base64_encode($attrs['dn']))."\"'>
438               <a style='vertical-align:middle;' href=\"main.php?plug=".validate($_GET['plug']).
439                           "&amp;start=".validate($_GET['start']).
440                           "&amp;show=".urlencode(base64_encode($attrs['dn']))."\">".
441                $attrs['sn'][0].", ".$attrs['givenName'][0].
442             "</a>
443             &nbsp;</td>
444             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['telephoneNumber'][0]."\">
445             <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]."
446             </a>
447             &nbsp;</td>
448             <td class=\"phonelist\" title=\"".$attrs['facsimileTelephoneNumber'][0]."\">
449             ".$attrs['facsimileTelephoneNumber'][0]."
450             &nbsp;</td>
451             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['mobile'][0]."\">
452             <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]."
453             </a>
454             &nbsp;</td>
455             <td class=\"phonelist\" title=\""._("Dial")." ".$attrs['homePhone'][0]."\">
456             <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]."
457             </a>
458             &nbsp;</td>
459             <td>
460             <a href=\"getvcard.php?dn=".base64_encode($attrs['dn'])."\">
461             <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])."\">
462             </a>";
465           if(preg_match("/r/",$this->get_entry_acls($attrs['dn'],"mail"))){
466             if (isset($attrs['mail'][0]) && !empty($attrs['mail'][0])){
467               $dest= sprintf(_("Send mail to %s"), $attrs['mail'][0]);
468               $this->telephone_list[$attrs['sn'][0].$attrs['dn']].=
470                 "<a href=\"mailto:".htmlentities($attrs['mail'][0])."\">".
471                 "<img  align=\"top\" border=0 src=\"images/mailto.png\" alt=\"vcf\" title=\"$dest\"></a>";
472             }
473           }
474           $this->telephone_list[$attrs['sn'][0].$attrs['dn']].= "&nbsp;</td>";
475         }
476       }
477       error_reporting(E_ALL | E_STRICT);
478     }
480     /* Sort up list */
481     ksort ($this->telephone_list);
482     reset ($this->telephone_list);
484     /* Fill template variables */
485     $smarty->assign("search_for", $this->search_for);
486     $smarty->assign("object_type", $this->object_type);
488     $this->base = $phonefilter['search_base'];
489     $smarty->assign("deplist", $this->get_allowed_bases());
490     $smarty->assign("depselect", $this->search_base);
491     $smarty->assign("global", $phonefilter['global']);
492     $smarty->assign("organizational", $phonefilter['organizational']);
493     $smarty->assign("search_image", get_template_path('images/search.png'));
494     $smarty->assign("obj_image", get_template_path('images/list_ogroup.png'));
495     $smarty->assign("tree_image", get_template_path('images/tree.png'));
496     $smarty->assign("infoimage", get_template_path('images/info.png'));
497     $smarty->assign("actionimage", get_template_path('images/action.png'));
498     $smarty->assign("launchimage", get_template_path('images/launch.png'));
500     /* Generate alphabet */
501     $alphabet= generate_alphabet();
503     /* Build list output */
504     $output= "";
505     $mod= 0;
508     /* View detailed infos */
509     $smarty->assign("show_info", "");
510     if (session::is_set('show_info')){
512       $range= 4;
513       $smarty->assign("show_info", "1");
514       $smarty->assign("url", "main.php?plug=".validate($_GET['plug'])."&amp;close=1");
516       $tmp = $this->plInfo();
518       if(isset($_POST['storage_base'])){
519         $this->storage_base = $_POST['storage_base'];  
520       }
522       switch (session::get('show_info')){
524         case "ADD":
526           $a_bases = $this->get_allowed_bases();
527   
528           if(!isset($a_bases[$this->storage_base])){
529             $base = key($this->get_allowed_bases());
530             $this->storage_base = $base;
531           } 
533           $smarty->assign ('storage_base', $this->storage_base);
534           $smarty->assign ('address_info', get_template_path('address_edit.tpl', TRUE));
536           foreach($tmp['plProvidedAcls'] as $name => $translated){
537             $smarty->assign($name."ACL",$this->get_entry_acls($this->abobjectclass.",".$base,$name));
538           }
539         break;
541         default:
542           $smarty->assign ('address_info', get_template_path('address_info.tpl', TRUE));
543           foreach($tmp['plProvidedAcls'] as $name => $translated){
544             $smarty->assign($name."ACL",$this->get_entry_acls($this->dn,$name));
545           }
546         break;
547       }
549       /* Fill variables from LDAP */
550       if (session::get('show_info') != "ADD"){
551         $ldap->cat(session::get('show_info'), $this->attributes);
552         $info= $ldap->fetch();
553       }
554       foreach ($this->attributes as $name){
556         /* Skip entries we are not allowed to read */
557         if(!preg_match("/r/",$this->get_entry_acls($this->dn,$name))){
558           $smarty->assign("info_$name", "");
559         }else
561         if (session::get('show_info') != "ADD" && isset($info["$name"][0])){
562           error_reporting(0);
563           /* Special treatment for phone attributes */
564           if ($name == "mobile" ||
565               $name == "homePhone" ||
566               $name == "telephoneNumber"){
567             $smarty->assign("info_$name",
568                 "<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>");
569           } else {
570             $smarty->assign("info_$name", preg_replace("/\n/", "<br>", $info["$name"][0]));
571           }
572           error_reporting(E_ALL | E_STRICT);
573         } elseif (session::get('show_info') == "ADD" && isset($this->$name)) {
574           $smarty->assign("info_$name", $this->$name);
575         } else {
576           $smarty->assign("info_$name", "-");
577         }
578       }
579       if (preg_match("/,".$this->abobjectclass.",/", session::get('show_info'))){
580         $storage= _("global addressbook");
581         $smarty->assign("internal", 0);
582       } else {
583         $storage= _("user database");
584         $smarty->assign("internal", 1);
585       }
586       if (session::get('show_info') != "ADD"){
587         $smarty->assign("storage_info", sprintf(_("Contact stored in '%s'"), $storage));
588       } else {
589         $smarty->assign("storage_info", _("Creating new entry in"));
590       }
591     } else {
594       if(isset($_POST['EntryPerPage'])){
595         $this->range = $_POST['EntryPerPage'];
596       }
597       $range = $this->range;    
598       $smarty->assign("internal", 1);
599     }
600     if (isset($_GET['start'])){
601       $this->start= validate($_GET['start']);
602     }
603     foreach ($this->telephone_list as $val){
604       if ($mod < $this->start) {
605         $mod++;
606         continue;
607       }
608       if ($mod >= ($this->start + $range)){
609         $mod++;
610         break;
611       }
612       if ( ($mod++) & 1){
613         $col= "style=\"background-color: #ECECEC;\"";
614       } else {
615         $col= "style=\"background-color: #F5F5F5;\"";
616       }
617       $output.= "<tr $col>\n$val</tr>\n";
618     }
620     $smarty->assign("search_result", $output);
621     $smarty->assign("apply", apply_filter());
622     $smarty->assign("alphabet", $alphabet);
623     if($range < 20){
624       $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range));
625     }else{
626       $smarty->assign("range_selector", range_selector(count($this->telephone_list), $this->start, $range, "EntryPerPage"));
627     }
628     $tmp= array("*" => _("All"), "sn" => _("Name"), "givenName" => _("Given name"),
629         "telephoneNumber" => _("Work phone"), "mobile" => _("Cell phone"),
630         "homePhone" => _("Home phone"), "uid" => _("User ID"));
631     natsort($tmp);
632     $smarty->assign("objlist", $tmp);
634     /* Show main page */
635     $smarty->assign ('personal_image', get_template_path('images/addr_personal.png'));
636     $smarty->assign ('home_image', get_template_path('images/addr_home.png'));
637     $smarty->assign ('company_image', get_template_path('images/addr_company.png'));
638     $smarty->assign ('add_image', get_template_path('images/editpaste.png'));
639     $smarty->assign ('edit_image', get_template_path('images/edit.png'));
640     $smarty->assign ('delete_image', get_template_path('images/editdelete.png'));
641     return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
642   }
644   function save_object()
645   {
646     plugin::save_object();
647     foreach($this->attributes as $attr){
649       /* save attributes depending on acls */
650       $acl = $this->get_entry_acls($this->dn,$attr);
652       if(preg_match("/w/",$acl)){
653         if(isset($_POST[$attr])){
654           $this->$attr = $_POST[$attr];
655         }
656       }
658     }
659   }
661   function check()
662   {
663     /* Call common method to give check the hook */
664     $message= plugin::check();
666     /* must: sn, givenName */
667     if ($this->sn == ""){
668       $message[] = msgPool::required(_("Name"));
669       return ($message);
670     }
671     if ($this->givenName == ""){
672       $message[] = msgPool::required(_("Given name"));
673       return ($message);
674     }
676     /* Check for valid name definition */
677     if (preg_match ("/[\\\\]/", $this->sn)){
678       $message[] = msgPool::invalid(_("Name"),$this->sn,"/[\\\\]");
679     }
680     if (preg_match ("/[\\\\]/", $this->givenName)){
681       $message[] = msgPool::invalid(_("Given name"),$this->givenName,"/[\\\\]");
682     }
684     /* Check phone numbers */
685     if (!tests::is_phone_nr($this->homePhone)){
686       $message[] = msgPool::invalid(_("Phone"),$this->homePhone);
687     }
688     if (!tests::is_phone_nr($this->telephoneNumber)){
689       $message[] = msgPool::invalid(_("Telephone number"),$this->telephoneNumber);
690     }
691     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
692       $message[] = msgPool::invalid(_("Fax"),$this->facsimileTelephoneNumber);
693     }
694     if (!tests::is_phone_nr($this->mobile)){
695       $message[] = msgPool::invalid(_("Mobile"),$this->mobile);
696     }
697     if (!tests::is_phone_nr($this->pager)){
698       $message[] = msgPool::invalid(_("Pager"),$this->pager);
699     }
700     /* Check for reserved characers */
701     if (preg_match ('/[,+"<>;]/', $this->givenName)){
702       $message[] = msgPool::invalid(_("Given name"),$this->givenName,'/[,+"<>;]/');
703   }
704   if (preg_match ('/[,+"<>;]/', $this->sn)){
705     $message[] = msgPool::invalid(_("Name"),$this->sn,'/[,+"<>;]/');
706   }
708   /* Check mail */
709   if (!tests::is_email($this->mail)){
710     $message[] = msgPool::invalid(_("Email"),"","","example@your-domain.com");
711   }
713   /* Assemble cn/dn */
714   $this->cn= $this->givenName." ".$this->sn;
715   if ($this->orig_cn != $this->cn || $this->storage_base != $this->orig_storage_base){
716     $this->new_dn= $this->create_unique_dn("cn", preg_replace("/,*".$this->config->current['BASE']."$/", "", $this->storage_base).",".$this->abobjectclass.",".$this->config->current['BASE']);
717     if ($this->new_dn == "none"){
718       $message[]= _("Cannot create a unique DN for your entry. Please fill more formular fields.");
719       return ($message);
720     }
721   } else {
722     $this->new_dn= $this->dn;
723   }
725   return ($message);
726   }
729   function load()
730   {
731     /* Load base attributes */
732     plugin::plugin ($this->config, $this->dn);
733     $this->view_logged = FALSE;
734     $this->storage_base= preg_replace('/^[^,]+,/', '', preg_replace('/'.$this->abobjectclass.',/', '', $this->dn));
735   }
738   function save()
739   {
740     /* First use parents methods to do some basic fillup in $this->attrs */
741     plugin::save ();
743     $this->attrs['cn']= $this->cn;
744     $this->attrs['displayName']= $this->givenName." ".$this->sn;
746     /* Move entry if it got another name... */
747     if ($this->dn != "new" && $this->dn != $this->new_dn){
748       $this->move($this->dn, $this->new_dn);
749     }
750     $this->dn= $this->new_dn;
752     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
753        new entries. So do a check first... */
754     $ldap= $this->config->get_ldap_link();
755     $ldap->cat ($this->dn,array('dn'));
756     if ($ldap->fetch()){
757       $mode= "modify";
758     } else {
759       $mode= "add";
760       $ldap->cd($this->config->current['BASE']);
761       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
762     }
764     /* Finally write data with selected 'mode' */
765     $ldap->cd ($this->dn);
766     $this->cleanup();
767     $ldap->$mode ($this->attrs);
768     if (!$ldap->success()){
769       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
770       return (1);
771     }
773     if($mode == "add"){
774       new log("create","addressbook/".get_class($this),$this->dn, array_keys($this->attrs),$ldap->get_error());
775     }else{
776       new log("modify","addressbook/".get_class($this),$this->dn, array_keys($this->attrs),$ldap->get_error());
777     }
778   }
780   
781   /* Return entry acls */
782   function get_entry_acls($dn,$attr = "")
783   {
784     $acls = "";
785   
786     /* Use addressbook acls */
787     if(preg_match("/".normalizePreg($this->abobjectclass)."/",$dn))  {
788       $dn = preg_replace("/".normalizePreg($this->abobjectclass).",/","",$dn);
789       $acls = $this->ui->get_permissions($dn,"addressbook/addressbook",$attr);
790     }
791     
792     /* Use Organizational Person acls */
793     else{
794       $acls = $this->ui->get_permissions($dn,"users/user",$attr);
795     }
797     return($acls);
798   }
801   /* Return plugin informations for acl handling  */
802   static function plInfo()
803   {
804     return (array(
805           "plShortName" => _("Addressbook"),
806           "plDescription" => _("Addressbook entry acls"),
807           "plSelfModify"  => FALSE,
808           "plDepends"     => array(),
809           "plPriority"    => 0,
810           "plSection"     => array("addons" => _("Addons")),
811           "plCategory"    => array("addressbook" => array("objectClass" => "inetOrgPerson", "description" => _("Addressbook"))),
813           "plProvidedAcls"    => array(
814             "sn"                        => _("Surename"),         
815             "givenName"                 => _("Given name"), 
816             "telephoneNumber"           => _("Telefon number"), 
817             "facsimileTelephoneNumber"  => _("Fax number"), 
818             "mobile"                    => _("Mobile number"), 
819             "homePhone"                 => _("Home phone number"), 
820             "uid"                       => _("User identification"), 
821             "mail"                      => _("Mail address"), 
822             "pager"                     => _("Pager"),
823             "o"                         => _("Organization"),
824             "ou"                        => _("Department"),
825             "l"                         => _("Location"),
826             "postalAddress"             => _("Postal address"),
827             "postalCode"                => _("Postal address"),
828             "st"                        => _("State"),
829             "initials"                  => _("Initials"), 
830             "title"                     => _("Title"), 
831             "homePostalAddress"         => _("Home postal address"), 
832             "cn"                        => _("Common name"))
833             ));
834   }
836 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
837 ?>