Code

70cbdf9ba7d83cd07ca92f3a5615cde7bb8d21b3
[gosa.git] / plugins / gofax / faxaccount / class_gofaxAccount.inc
1 <?php
3 class gofaxAccount extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "FAX";
7   var $plDescription= "This does something";
9   /* CLI vars */
10   var $cli_summary= "Manage users fax account";
11   var $cli_description= "Some longer text\nfor help";
12   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
14   var $departments;
16   /* Fax attributes */
17   var $goFaxDeliveryMode= "";
18   var $facsimileTelephoneNumber= "";
19   var $goFaxIsEnabled= 1;
20   var $goFaxPrinter= "";
21   var $goFaxDivertNumber= "";
22   var $goFaxLanguage= "";
23   var $goFaxFormat= "";
24   var $goFaxRBlocklist = array();
25   var $goFaxRBlockgroups= array();
26   var $goFaxSBlocklist= array();
27   var $goFaxSBlockgroups= array();
28   var $mail= "";
29   var $facsimileAlternateTelephoneNumber= array();
31   /* Internal variables */
32   var $printerList= array();
33   var $has_mailAccount= FALSE;
34   var $locals_dialog= FALSE;
35   var $in_blocklist_dialog= FALSE;
36   var $out_blocklist_dialog= FALSE;
37   var $current_blocklist= array();
39   /* attribute list for save action */
40   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled",
41       "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail");
42   var $objectclasses= array("goFaxAccount");
44   function gofaxAccount ($config, $dn= NULL)
45   {
46     /* General initialization */
47     plugin::plugin ($config, $dn);
49     if(!isset($_SESSION["Fax_Filter"])){
50       $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
51     }
53     if ($dn != "new"){
54       /* Get arrays */
55       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
56             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
58         if (isset($this->attrs["$val"]["count"])){
59           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
60             array_push($this->$val, $this->attrs["$val"][$i]);
61           }
62         }
63       }
65       /* Set up has_mailAccount */
66       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
67         $this->has_mailAccount= TRUE;
68       }
69       if (isset($this->attrs["facsimileTelephoneNumber"][0])){
70         $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
71       }
72     }
74     /* Load printer list */
75     if (isset($this->config->data['SERVERS']['CUPS'])){
76       $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
77       asort ($this->printerList);
78     }
80     /* Get global filter config */
81     if (!is_global("faxfilter")){
82       $ui= get_userinfo();
83       $base= get_base_from_people($ui->dn);
84       $faxfilter= array( "depselect"       => $base,
85           "fuser"            => "*",
86           "regex"           => "");
87       register_global("faxfilter", $faxfilter);
88     }
89   }
91   function execute()
92   {
93         /* Call parent execute */
94         plugin::execute();
96       if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
98         if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
99           $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
100         }else{
101           $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
102         }
103       }
105     /* Load smarty stuff */
106     $smarty= get_smarty();
108     /* Check if mail account is active. We'll display an additional
109        mail address field if this is not the case. Some people may
110        want goFax, but have a mailserver which is not managed with
111        GOsa */
112     if (!@isset($this->parent->by_object['mailAccount'])) {
113       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
114     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
115       $smarty->assign("has_mailaccount", "false");
116       $this->has_mailAccount= false;
117     } else {
118       $smarty->assign("has_mailaccount", "true");
119     }
121     /* Do we need to flip is_account state? */
122     if (isset($_POST['modify_state'])){
123       $this->is_account= !$this->is_account;
124     }
126     /* Do we represent a valid account? */
127     if (!$this->is_account && $this->parent == NULL){
128       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
129         _("This account has no fax extensions.")."</b>";
130       $display.= back_to_main();
131       return ($display);
132     }
134     /* Show tab dialog headers */
135     $display= "";
136     if ($this->parent != NULL){
137       if ($this->is_account){
138         $display= $this->show_header(_("Remove fax account"),
139             _("This account has fax features enabled. You can disable them by clicking below."));
140       } else {
141         $display= $this->show_header(_("Create fax account"),
142             _("This account has fax features disabled. You can enable them by clicking below."));
143         return ($display);
144       }
145     }
147     /* Trigger Add local fax alternatives dialog */
148     if (isset($_POST['add_local_alternate'])){
149       $this->locals_dialog= TRUE;       
150       $this->dialog= TRUE;      
151     }
153     /* Add alternatives from dialog */
154     if (isset($_POST['add_locals_finish'])){
155       if (isset($_POST['local_list']) &&
156           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
158         foreach ($_POST['local_list'] as $val){
159           $this->addAlternate($val);
160           $this->is_modified= TRUE;
161         }
162       }
163     }
165     /* Add alternatives */
166     if (isset($_POST['add_alternate'])){
167       if ($_POST['forward_address'] != "" &&
168           is_phone_nr($_POST['forward_address']) &&
169           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
171         $this->addAlternate($_POST['forward_address']);
172       }
173     }
175     /* Delete alternate fax number */
176     if (isset($_POST['delete_alternate'])){
177       if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
178           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
180         $this->delAlternate ($_POST['alternate_list']);
181       }
182     }
185     /* Edit incoming blocklists */
186     if (isset($_POST['edit_incoming'])){
187       $this->current_blocklist= array_merge($this->goFaxRBlocklist,
188           $this->goFaxRBlockgroups);
189       sort($this->current_blocklist);
190       reset($this->current_blocklist);
192       $this->in_blocklist_dialog= TRUE;
193       $this->dialog= TRUE;
194     }
196     /* Edit outgoing blocklists */
197     if (isset($_POST['edit_outgoing'])){
198       $this->current_blocklist= array_merge($this->goFaxSBlocklist,
199           $this->goFaxSBlockgroups);
200       sort($this->current_blocklist);
201       reset($this->current_blocklist);
203       $this->out_blocklist_dialog= TRUE;
204       $this->dialog= TRUE;
205     }
207     /* Add number to blocklist (dialog) */
208     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
209       if (!is_phone_nr($_POST['block_number'])){
210         print_red (_("You're trying to add an invalid phone number."));
211       } else {
212         array_push($this->current_blocklist, $_POST['block_number']);
213         $this->current_blocklist= array_unique($this->current_blocklist);
214         sort($this->current_blocklist);
215         reset($this->current_blocklist);
216       }
217     }
219     /* Add list to blocklist */
220     if (isset($_POST['add_blocklist'])){
221       foreach($_POST as $name => $value){
222         if(preg_match("/ADDLIST_/i",$name)){
223           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
225         }
226       } 
227       $this->current_blocklist= array_unique($this->current_blocklist);
228       sort($this->current_blocklist);
229       reset($this->current_blocklist);
231     }
233     /* Add list to blocklist */
234     if (isset($_GET['add'])){
235       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
236       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
237       $this->current_blocklist= array_unique($this->current_blocklist);
238       sort($this->current_blocklist);
239       reset($this->current_blocklist);
240     }
242     /* Delete from blocklist */
243     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
244       $tmp= array();
245       foreach($this->current_blocklist as $val){
246         if (!in_array($val, $_POST['block_list'])){
247           $tmp[]= $val;
248         }
249       }
250       $this->current_blocklist= $tmp;
251     }
254         /* Blocklist edit finished */
255     if (isset($_POST['edit_blocklists_finish'])){
257       /* Incoming or outgoing? */
258       if ($this->in_blocklist_dialog){
259         $this->goFaxRBlocklist = array();
260         $this->goFaxRBlockgroups = array();
262         foreach ($this->current_blocklist as $val){
263           if (is_phone_nr($val)){
264             $this->goFaxRBlocklist[]=$val;
265           } else {
266             $this->goFaxRBlockgroups[]= $val;
267           }
268         }
269       } else {
270         $this->goFaxSBlocklist = array();
271         $this->goFaxSBlockgroups = array();
273         /* Transfer values to ourself */
274         foreach ($this->current_blocklist as $val){
275           if (is_phone_nr($val)){
276             $this->goFaxSBlocklist[]=$val;
277           } else {
278             $this->goFaxSBlockgroups[]= $val;
279           }
280         }
281       }
282       $this->is_modified= TRUE;
283     }
286     /* Set departments */
287     if ($this->locals_dialog ||
288         $this->in_blocklist_dialog ||
289         $this->out_blocklist_dialog){
291       $list= array ();
292       $ldap= $this->config->get_ldap_link();
293       if (isset ($_POST['department'])){
294         $ldap->cd ($_POST['department']);
295       } else {
296         $ldap->cd ($this->config->current['BASE']);
297       }
298     }
300     /* Cancel  dialogs */
301     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
302         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
304       $this->locals_dialog= FALSE;
305       $this->in_blocklist_dialog= FALSE;
306       $this->out_blocklist_dialog= FALSE;
307       $this->dialog= FALSE;
308     }
310     /* Manage locals dialog */
311     if ($this->locals_dialog){
313       /* Save data */
314       $faxfilter= get_global("faxfilter");
315       foreach( array("depselect", "fuser", "regex") as $type){
316         if (isset($_POST[$type])){
317           $faxfilter[$type]= $_POST[$type];
318         }
319       }
320       if (isset($_GET['search'])){
321         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
322         if ($s == "**"){
323           $s= "*";
324         }
325         $faxfilter['fuser']= $s;
326       }
327       register_global("faxfilter", $faxfilter);
329       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
330         $regex= $faxfilter['regex'];
331         $filter= "(facimileTelephoneNumber=$regex)";
332       } else {
333         $filter= "";
334       }
335       if ($faxfilter['fuser'] != ""){
336         $user= $faxfilter['fuser'];
337         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
338       }
340       $base= $faxfilter['depselect'];
341       $acl= array($this->config->current['BASE'] => ":all");
342       print "(&(objectClass=goFaxAccount)$filter)";
343       $res= get_list($acl, "(&(objectClass=goFaxAccount)$filter)", TRUE, $base, array("sn", "givenName", "facsimileTelephoneNumber"), TRUE);
345       foreach ($res as $attrs){
346         $list[$attrs['facsimileTelephoneNumber'][0]]=
347           $attrs['sn'][0].", ".
348           $attrs['givenName'][0]." [".
349           $attrs['facsimileTelephoneNumber'][0]."]";
350       }
352       /* Show dialog */
353       $smarty->assign("search_image", get_template_path('images/search.png'));
354       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
355       $smarty->assign("tree_image", get_template_path('images/tree.png'));
356       $smarty->assign("infoimage", get_template_path('images/info.png'));
357       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
358       $smarty->assign("departments", $this->config->idepartments);
359       $smarty->assign("list", $list);
360       if (isset($_POST['depselect'])){
361         $smarty->assign("depselect", $_POST['depselect']);
362       }
363       $smarty->assign("deplist", $this->config->idepartments);
364       $smarty->assign("apply", apply_filter());
365       $smarty->assign("alphabet", generate_alphabet());
366       $smarty->assign("hint", print_sizelimit_warning());
367       foreach( array("depselect", "fuser", "regex") as $type){
368         $smarty->assign("$type", $faxfilter[$type]);
369       }
370       $smarty->assign("hint", print_sizelimit_warning());
372       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
373       return ($display);
374     }
375       
376     
377     /* Manage incoming blocklists */
378     if ($this->in_blocklist_dialog){
379     
380       $base = $_SESSION['Fax_Filter']['depselect'];
381       $ldap->cd($base);
383       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
384       while ($attrs= $ldap->fetch()){
385         if(isset($attrs['description'][0])){
386           $list[$attrs['cn'][0]]=
387             $attrs['description'][0].
388             " [".$attrs['cn'][0]."]";
389         }else{
390           $list[$attrs['cn'][0]]= $attrs['cn'][0];
391         }
392       }
394       $divSel = new divSelectBox("divSelectPredefined");
395       $divSel->setHeight(300);
396       $divSel->setWidth(350);
398       /* NEW LIST MANAGMENT
399        * We also need to search for the departments
400        * So we are able to navigate like in konquerer
401        */
403       $tmp = array();
404       $this->departments= array();
405       $base = $_SESSION['Fax_Filter']['depselect'];
406       $ldap->ls("(objectClass=gosaDepartment)",$base);
408       $base_back = preg_replace("/^[^,]+,/","",$base);
409     
410       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
411         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
412       }
413       while($value = $ldap->fetch()){
414         if($value["description"][0]!=".."){
415           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
416         }else{
417           $this->departments[$value['dn']]=$value["description"][0];
418         }
419       }
420       /* END NEW LIST MANAGMENT
421        */
423       // Defining Links
424       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
426       /* Insert departments in divlist*/
427       foreach($this->departments as $key=> $val){
429         if(!isset($this->config->departments[trim($key)])){
430           $this->config->departments[trim($key)]="";
431         }
433         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
434         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
435         $divSel->AddEntry(array($field1,$field2));
436       }
438       foreach($list as $entry => $value){
439         $divSel->AddEntry(array(
440                             array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
441                             array("string"=>$value,"attach"=>"style='border:0px;'")
442                             ));
443       }
445       /* Show dialog */
446       $smarty->assign("cblocklist", $this->current_blocklist);
447       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
448       $smarty->assign("departments", $this->config->idepartments);
449       $smarty->assign("divSelectPredefined", $divSel->DrawList());
450       
451       if (isset($_POST['department'])){
452         $smarty->assign("department", $_POST['department']);
453       } else {
454         $smarty->assign("department", "");
455       }
457       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
458       return ($display);
459     }
461     /* Manage outgoing blocklists */
463     if ($this->out_blocklist_dialog){
465       $base = $_SESSION['Fax_Filter']['depselect'];
466       $ldap->cd($base);
468       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
469       while ($attrs= $ldap->fetch()){
470         if(isset($attrs['description'][0])){
471           $list[$attrs['cn'][0]]=
472             $attrs['description'][0].
473             " [".$attrs['cn'][0]."]";
474         }else{
475           $list[$attrs['cn'][0]]= $attrs['cn'][0];
476         }
477       }
479       $divSel = new divSelectBox("divSelectPredefined");
480       $divSel->setHeight(300);
481       $divSel->setWidth(350);
483       /* NEW LIST MANAGMENT
484        * We also need to search for the departments
485        * So we are able to navigate like in konquerer
486        */
487       $tmp = array();
488       $this->departments= array();
489       $ldap->ls("(objectClass=gosaDepartment)",$base);
491       $base_back = preg_replace("/^[^,]+,/","",$base);
493       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
494         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
495       }
496       while($value = $ldap->fetch()){
497         if(isset($value["description"][0])){
498           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
499         }else{
500           $this->departments[$value['dn']]=$value["description"][0];
501         }
502       }
503       /* END NEW LIST MANAGMENT
504        */
506       // Defining Links
507       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
509       /* Insert departments in divlist*/
510       foreach($this->departments as $key=> $val){
511         if(!isset($this->config->departments[trim($key)])){
512           $this->config->departments[trim($key)]="";
513         }
515         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
516         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
517         $divSel->AddEntry(array($field1,$field2));
518       }
520       foreach($list as $entry => $value){
521         $divSel->AddEntry(array(
522               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
523               array("string"=>$value,"attach"=>"style='border:0px;'")
524               ));
525       }
528       /* Show dialog */
529       $smarty->assign("cblocklist", $this->current_blocklist);
530       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
531       $smarty->assign("departments", $this->config->idepartments);
532       $smarty->assign("divSelectPredefined", $divSel->DrawList());
533       if (isset($_POST['department'])){
534         $smarty->assign("department", $_POST['department']);
535       } else {
536         $smarty->assign("department", "");
537       }
540       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
541       return ($display);
542     }
545     /* Show main page */
546     $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
547     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
548     $smarty->assign("printers", $this->printerList);
550     /* Load attributes */
551     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
552           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
553           "facsimileAlternateTelephoneNumber", "mail") as $val){
555       $smarty->assign("$val", $this->$val);
556       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
557     }
558     $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
559     $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
561     /* Load checkboxes */
562     if ($this->goFaxIsEnabled == "1"){
563       $smarty->assign("goFaxIsEnabled", "");
564     } else {
565       $smarty->assign("goFaxIsEnabled", "checked");
566     }
567     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
568     if ($this->goFaxDeliveryMode & 32) {
569       $smarty->assign("fax_to_mail", "checked");
570     } else {
571       $smarty->assign("fax_to_mail", "");
572     }
573     if ($this->goFaxDeliveryMode & 64) {
574       $smarty->assign("fax_to_printer", "checked");
575     } else {
576       $smarty->assign("fax_to_printer", "");
577     }
580     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
581     return ($display);
582   }
584   function remove_from_parent()
585   {
586     /* Cancel if there's nothing to do here */
587     if (!$this->initially_was_account){
588       return;
589     }
591     plugin::remove_from_parent();
593     /* Zero out arrays */
594     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
595           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
597       $this->attrs[$val]= array();
598     }
600     /* Adapt mail settings if needed */
601     if ($this->parent->by_object['mailAccount']->is_account){
602       unset($this->attrs['mail']);
603     }
605     $ldap= $this->config->get_ldap_link();
606     $ldap->cd($this->dn);
607     $ldap->modify($this->attrs);
608     show_ldap_error($ldap->get_error());
610     /* Optionally execute a command after we're done */
611     $this->handle_post_events('remove');
612   }
615   /* Check formular input */
616   function check()
617   {
618     /* Reset message array */
619     $message= array();
621     /* must: facsimileTelephoneNumber */
622     if ($this->facsimileTelephoneNumber == ""){
623       $message[]= _("The required field 'Fax' is not set.");
624     }
626     if (!is_phone_nr($this->facsimileTelephoneNumber)){
627       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
628     }
630     /* IF mail is specified (which is only the case if there's no mail account
631        present), check if it's valid..  */
632     if (@isset($this->parent->by_object['mailAccount']) &&
633         $this->goFaxDeliveryMode && 32){
634       if ($this->mail == ""){
635         $message[]= _("Mail delivery is checked, but no address has been specified.");
636       } elseif (!is_email($this->mail)){
637         $message[]= _("The mail address you've entered is invalid.");
638       }
639     }
640  
641     // IE Fix, IE lets you choose disabled option, stupid browser ... 
642     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
643       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
644     }
646     return ($message);
647   }
649   /* Save data to object */
650   function save_object()
651   {
652     if (isset($_POST['faxTab'])){
653       plugin::save_object();
655       /* Adapt combobox values */
656       $tmp= 0;
657       if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
658         $tmp+= 32;
659       }
660       if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
661         $tmp+= 64;
662       }
663       if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
664         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
665           $this->goFaxIsEnabled= "0";
666         } else {
667           $this->goFaxIsEnabled= "1";
668         }
669       }
671       if (isset($_POST['facsimileTelephoneNumber'])){
672         if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
673           $this->is_modified= TRUE;
674         }
675         $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
676       }
678       if (isset($_POST['mail'])){
679         if ($this->mail != $_POST['mail']){
680           $this->is_modified= TRUE;
681         }
682         $this->mail= $_POST['mail'];
683       }
685       /* Write to object */
686       if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
687         if ($tmp != $this->goFaxDeliveryMode){
688             $this->is_modified= TRUE;
689         }
690         $this->goFaxDeliveryMode= "$tmp";
691       }
693       /* Check if mail account is active and correct the internal
694          reference to represent the current status. */
695       if ($this->parent->by_object['mailAccount']->is_account){
696         $this->has_mailAccount= TRUE;
697       }
698     }
700   }
703   /* Save to LDAP */
704   function save()
705   {
706     plugin::save();
708     /* Save arrays */
709     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
710           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
712       $this->attrs[$val]= $this->$val;
713     }
715     /* Adapt mail settings if needed */
716     unset($this->attrs['mail']);
717     if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
718       $this->attrs['mail']= $this->mail;
719     }
721     /* Write back to ldap */
722     $ldap= $this->config->get_ldap_link();
723     $ldap->cd($this->dn);
724     $ldap->modify($this->attrs);
725     show_ldap_error($ldap->get_error());
727     /* Optionally execute a command after we're done */
728     if ($this->initially_was_account == $this->is_account){
729       if ($this->is_modified){
730         $this->handle_post_events("mofify");
731       }
732     } else {
733       $this->handle_post_events("add");
734     }
736   }
739   /* Adapt from template, using 'dn' */
740   function adapt_from_template($dn)
741   {
742     plugin::adapt_from_template($dn);
744     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
745           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
747       if (isset($this->attrs[$val])){
748         $this->$val= $this->attrs[$val];
749       }
750     }
751   }
755   /* Add alternate fax recipient */
756   function addAlternate($number)
757   {
758     $this->facsimileAlternateTelephoneNumber[]= "$number";
759     $this->facsimileAlternateTelephoneNumber=
760       array_unique ($this->facsimileAlternateTelephoneNumber);
762     sort ($this->facsimileAlternateTelephoneNumber);
763     reset ($this->facsimileAlternateTelephoneNumber);
764   }
766   function delAlternate($numbers)
767   {
768     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
769         $this->facsimileAlternateTelephoneNumber);
770   }
775 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
776 ?>