Code

Fixed Kolab attribute mapping.
[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");
15   /* Department list shown in the divSelectList*/
16   var $departments;
18   /* Fax attributes */
19   var $goFaxDeliveryMode= "";
20   var $facsimileTelephoneNumber= "";
21   var $goFaxIsEnabled= 1;
22   var $goFaxPrinter= "";
23   var $goFaxDivertNumber= "";
24   var $goFaxLanguage= "";
25   var $goFaxFormat= "";
26   var $goFaxRBlocklist = array();
27   var $goFaxRBlockgroups= array();
28   var $goFaxSBlocklist= array();
29   var $goFaxSBlockgroups= array();
30   var $mail= "";
31   var $facsimileAlternateTelephoneNumber= array();
33   /* Internal variables */
34   var $printerList= array();
35   var $has_mailAccount= FALSE;
36   var $locals_dialog= FALSE;
37   var $in_blocklist_dialog= FALSE;
38   var $out_blocklist_dialog= FALSE;
39   var $current_blocklist= array();
41   /* attribute list for save action */
42   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled",
43       "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail");
44   var $objectclasses= array("goFaxAccount");
46   function gofaxAccount ($config, $dn= NULL)
47   {
48     /* General initialization */
49     plugin::plugin ($config, $dn);
52     /* Hickert : 11.11.05
53      * Added to be able to handle department selection in divSelelect
54      */
55     if(!isset($_SESSION["Fax_Filter"])){
56       $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
57     }
59     if ($dn != "new"){
60       /* Get arrays */
61       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
62             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
64         if (isset($this->attrs["$val"]["count"])){
65           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
66             array_push($this->$val, $this->attrs["$val"][$i]);
67           }
68         }
69       }
71       /* Set up has_mailAccount */
72       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
73         $this->has_mailAccount= TRUE;
74       }
75       if (isset($this->attrs["facsimileTelephoneNumber"][0])){
76         $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
77       }
78     }
80     /* Load printer list */
81     if (isset($this->config->data['SERVERS']['CUPS'])){
82       $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
83       asort ($this->printerList);
84     }
86     /* Get global filter config */
87     if (!is_global("faxfilter")){
88       $ui= get_userinfo();
89       $base= get_base_from_people($ui->dn);
90       $faxfilter= array( "depselect"       => $base,
91           "fuser"            => "*",
92           "regex"           => "");
93       register_global("faxfilter", $faxfilter);
94     }
95   }
97   function execute()
98   {
99     /* Call parent execute */
100     plugin::execute();
101     /* Hickert : 11.11.05
102      * Added to be able to handle department selection in divSelelect
103      */
104     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
106       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
107         $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
108       }else{
109         $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
110       }
111     }
113     /* Load smarty stuff */
114     $smarty= get_smarty();
116     /* Check if mail account is active. We'll display an additional
117        mail address field if this is not the case. Some people may
118        want goFax, but have a mailserver which is not managed with
119        GOsa */
120     if (!@isset($this->parent->by_object['mailAccount'])) {
121       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
122     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
123       $smarty->assign("has_mailaccount", "false");
124       $this->has_mailAccount= false;
125     } else {
126       $smarty->assign("has_mailaccount", "true");
127     }
129     /* Do we need to flip is_account state? */
130     if (isset($_POST['modify_state'])){
131       $this->is_account= !$this->is_account;
132     }
134     /* Do we represent a valid account? */
135     if (!$this->is_account && $this->parent == NULL){
136       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
137         _("This account has no fax extensions.")."</b>";
138       $display.= back_to_main();
139       return ($display);
140     }
142     /* Show tab dialog headers */
143     $display= "";
144     if ($this->parent != NULL){
145       if ($this->is_account){
146         $display= $this->show_header(_("Remove fax account"),
147             _("This account has fax features enabled. You can disable them by clicking below."));
148       } else {
149         $display= $this->show_header(_("Create fax account"),
150             _("This account has fax features disabled. You can enable them by clicking below."));
151         return ($display);
152       }
153     }
155     /* Trigger Add local fax alternatives dialog */
156     if (isset($_POST['add_local_alternate'])){
157       $this->locals_dialog= TRUE;       
158       $this->dialog= TRUE;      
159     }
161     /* Add alternatives from dialog */
162     if (isset($_POST['add_locals_finish'])){
163       if (isset($_POST['local_list']) &&
164           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
166         foreach ($_POST['local_list'] as $val){
167           $this->addAlternate($val);
168           $this->is_modified= TRUE;
169         }
170       }
171     }
173     /* Add alternatives */
174     if (isset($_POST['add_alternate'])){
175       if ($_POST['forward_address'] != "" &&
176           is_phone_nr($_POST['forward_address']) &&
177           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
179         $this->addAlternate($_POST['forward_address']);
180       }
181     }
183     /* Delete alternate fax number */
184     if (isset($_POST['delete_alternate'])){
185       if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
186           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
188         $this->delAlternate ($_POST['alternate_list']);
189       }
190     }
193     /* Edit incoming blocklists */
194     if (isset($_POST['edit_incoming'])){
195       $this->current_blocklist= array_merge($this->goFaxRBlocklist,
196           $this->goFaxRBlockgroups);
197       sort($this->current_blocklist);
198       reset($this->current_blocklist);
200       $this->in_blocklist_dialog= TRUE;
201       $this->dialog= TRUE;
202     }
204     /* Edit outgoing blocklists */
205     if (isset($_POST['edit_outgoing'])){
206       $this->current_blocklist= array_merge($this->goFaxSBlocklist,
207           $this->goFaxSBlockgroups);
208       sort($this->current_blocklist);
209       reset($this->current_blocklist);
211       $this->out_blocklist_dialog= TRUE;
212       $this->dialog= TRUE;
213     }
215     /* Add number to blocklist (dialog) */
216     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
217       if (!is_phone_nr($_POST['block_number'])){
218         print_red (_("You're trying to add an invalid phone number."));
219       } else {
220         array_push($this->current_blocklist, $_POST['block_number']);
221         $this->current_blocklist= array_unique($this->current_blocklist);
222         sort($this->current_blocklist);
223         reset($this->current_blocklist);
224       }
225     }
227     /* Hickert : 11.11.05
228      * Add selection from divSelelect to our Blocklist 
229      */
230     /* Add list to blocklist */
231     if (isset($_POST['add_blocklist'])){
232       foreach($_POST as $name => $value){
233         if(preg_match("/ADDLIST_/i",$name)){
234           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
236         }
237       } 
238       $this->current_blocklist= array_unique($this->current_blocklist);
239       sort($this->current_blocklist);
240       reset($this->current_blocklist);
241     }
243     /* Add list to blocklist */
244     if (isset($_GET['add'])){
245       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
246       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
247       $this->current_blocklist= array_unique($this->current_blocklist);
248       sort($this->current_blocklist);
249       reset($this->current_blocklist);
250     }
252     /* Delete from blocklist */
253     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
254       $tmp= array();
255       foreach($this->current_blocklist as $val){
256         if (!in_array($val, $_POST['block_list'])){
257           $tmp[]= $val;
258         }
259       }
260       $this->current_blocklist= $tmp;
261     }
264     /* Blocklist edit finished */
265     if (isset($_POST['edit_blocklists_finish'])){
267       /* Incoming or outgoing? */
268       if ($this->in_blocklist_dialog){
269         $this->goFaxRBlocklist = array();
270         $this->goFaxRBlockgroups = array();
272         foreach ($this->current_blocklist as $val){
273           if (is_phone_nr($val)){
274             $this->goFaxRBlocklist[]=$val;
275           } else {
276             $this->goFaxRBlockgroups[]= $val;
277           }
278         }
279       } else {
280         $this->goFaxSBlocklist = array();
281         $this->goFaxSBlockgroups = array();
283         /* Transfer values to ourself */
284         foreach ($this->current_blocklist as $val){
285           if (is_phone_nr($val)){
286             $this->goFaxSBlocklist[]=$val;
287           } else {
288             $this->goFaxSBlockgroups[]= $val;
289           }
290         }
291       }
292       $this->is_modified= TRUE;
293     }
296     /* Set departments */
297     if ($this->locals_dialog ||
298         $this->in_blocklist_dialog ||
299         $this->out_blocklist_dialog){
301       $list= array ();
302       $ldap= $this->config->get_ldap_link();
303       if (isset ($_POST['department'])){
304         $ldap->cd ($_POST['department']);
305       } else {
306         $ldap->cd ($this->config->current['BASE']);
307       }
308     }
310     /* Cancel  dialogs */
311     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
312         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
314       $this->locals_dialog= FALSE;
315       $this->in_blocklist_dialog= FALSE;
316       $this->out_blocklist_dialog= FALSE;
317       $this->dialog= FALSE;
318     }
320     /* Manage locals dialog */
321     if ($this->locals_dialog){
323       /* Save data */
324       $faxfilter= get_global("faxfilter");
325       foreach( array("depselect", "fuser", "regex") as $type){
326         if (isset($_POST[$type])){
327           $faxfilter[$type]= $_POST[$type];
328         }
329       }
330       if (isset($_GET['search'])){
331         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
332         if ($s == "**"){
333           $s= "*";
334         }
335         $faxfilter['fuser']= $s;
336       }
337       register_global("faxfilter", $faxfilter);
339       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
340         $regex= $faxfilter['regex'];
341         $filter= "(facimileTelephoneNumber=$regex)";
342       } else {
343         $filter= "";
344       }
345       if ($faxfilter['fuser'] != ""){
346         $user= $faxfilter['fuser'];
347         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
348       }
350       $base= $faxfilter['depselect'];
351       $acl= array($this->config->current['BASE'] => ":all");
352       print "(&(objectClass=goFaxAccount)$filter)";
353       $res= get_list($acl, "(&(objectClass=goFaxAccount)$filter)", TRUE, $base, array("sn", "givenName", "facsimileTelephoneNumber"), TRUE);
355       foreach ($res as $attrs){
356         $list[$attrs['facsimileTelephoneNumber'][0]]=
357           $attrs['sn'][0].", ".
358           $attrs['givenName'][0]." [".
359           $attrs['facsimileTelephoneNumber'][0]."]";
360       }
362       /* Show dialog */
363       $smarty->assign("search_image", get_template_path('images/search.png'));
364       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
365       $smarty->assign("tree_image", get_template_path('images/tree.png'));
366       $smarty->assign("infoimage", get_template_path('images/info.png'));
367       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
368       $smarty->assign("departments", $this->config->idepartments);
369       $smarty->assign("list", $list);
370       if (isset($_POST['depselect'])){
371         $smarty->assign("depselect", $_POST['depselect']);
372       }
373       $smarty->assign("deplist", $this->config->idepartments);
374       $smarty->assign("apply", apply_filter());
375       $smarty->assign("alphabet", generate_alphabet());
376       $smarty->assign("hint", print_sizelimit_warning());
377       foreach( array("depselect", "fuser", "regex") as $type){
378         $smarty->assign("$type", $faxfilter[$type]);
379       }
380       $smarty->assign("hint", print_sizelimit_warning());
382       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
383       return ($display);
384     }
387     /* Manage incoming blocklists */
388     if ($this->in_blocklist_dialog){
390       /* This handles the divSelectBox */
392       /* The base specifies the current position in the ldap tree 
393        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
394        */
395       $base = $_SESSION['Fax_Filter']['depselect'];
396       $ldap->cd($base);
398       /* Ge all Blocklists */
399       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
400       while ($attrs= $ldap->fetch()){
402         /* Generate list depending on description */
403         if(isset($attrs['description'][0])){
404           $list[$attrs['cn'][0]]=
405             $attrs['description'][0].
406             " [".$attrs['cn'][0]."]";
407         }else{
408           $list[$attrs['cn'][0]]= $attrs['cn'][0];
409         }
410       }
412       /* Create our divselect box */
413       $divSel = new divSelectBox("divSelectPredefined");
414       $divSel->setHeight(150);
415       $divSel->setWidth(150);
417       /* NEW LIST MANAGMENT
418        * We also need to search for the departments
419        * So we are able to navigate like in konquerer
420        */
421       $this->departments= array();
422    
423       /* Get all departments within the current department */ 
424       $base = $_SESSION['Fax_Filter']['depselect'];
425       $ldap->ls("(objectClass=gosaDepartment)",$base);
427       /* Base back is used to go one department up in our ldap tree */
428       $base_back = preg_replace("/^[^,]+,/","",$base);
430       /* Only show base_back if it is needed */
431       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
432         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
433       }
435       /* Fetch all returned departments an add them to our divlist */
436       while($value = $ldap->fetch()){
437         if($value["description"][0]!=".."){
438           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
439         }else{
440           $this->departments[$value['dn']]=$value["description"][0];
441         }
442       }
443       /* END NEW LIST MANAGMENT
444        */
446       // This links specifies the department open link 
447       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
449       /* Insert departments in divsel */
450       foreach($this->departments as $key=> $val){
451         if(!isset($this->config->departments[trim($key)])){
452           $this->config->departments[trim($key)]="";
453         }
454         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
455         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
456         $divSel->AddEntry(array($field1,$field2));
457       }
459       /* Append predefined Blocklists */
460       foreach($list as $entry => $value){
461         $divSel->AddEntry(array(
462               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
463               array("string"=>$value,"attach"=>"style='border:0px;'")
464               ));
465       }
467       /* Show dialog */
468       $smarty->assign("cblocklist", $this->current_blocklist);
469       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
470       $smarty->assign("departments", $this->config->idepartments);
471       $smarty->assign("divSelectPredefined", $divSel->DrawList());
472       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
473       return ($display);
474     }
476     /* Manage outgoing blocklists */
478     if ($this->out_blocklist_dialog){
480       /* This handles the divSelectBox */
482       /* The base specifies the current position in the ldap tree
483        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
484        */
485       $base = $_SESSION['Fax_Filter']['depselect'];
486       $ldap->cd($base);
488       /* Ge all Blocklists */ 
489       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
490       while ($attrs= $ldap->fetch()){
491         if(isset($attrs['description'][0])){
492           $list[$attrs['cn'][0]]=
493             $attrs['description'][0].
494             " [".$attrs['cn'][0]."]";
495         }else{
496           $list[$attrs['cn'][0]]= $attrs['cn'][0];
497         }
498       }
500       /*Create DivSel*/
501       $divSel = new divSelectBox("divSelectPredefined");
502       $divSel->setHeight(300);
503       $divSel->setWidth(350);
505       /* NEW LIST MANAGMENT
506        * We also need to search for the departments
507        * So we are able to navigate like in konquerer
508        */
509       $this->departments= array();
510       $ldap->ls("(objectClass=gosaDepartment)",$base);
512       /* Generate Back url, and append if it is needed */
513       $base_back = preg_replace("/^[^,]+,/","",$base);
514       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
515         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
516       }
518       /* Get all departments */
519       while($value = $ldap->fetch()){
520         if(isset($value["description"][0])){
521           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
522         }else{
523           $this->departments[$value['dn']]=$value["description"][0];
524         }
525       }
526       /* END NEW LIST MANAGMENT
527        */
529       // Defining Links
530       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
532       /* Insert departments in divlist*/
533       foreach($this->departments as $key=> $val){
534         if(!isset($this->config->departments[trim($key)])){
535           $this->config->departments[trim($key)]="";
536         }
538         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
539         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
540         $divSel->AddEntry(array($field1,$field2));
541       }
543       /* Append Blocklits */
544       foreach($list as $entry => $value){
545         $divSel->AddEntry(array(
546               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
547               array("string"=>$value,"attach"=>"style='border:0px;'")
548               ));
549       }
551       /* Show dialog */
552       $smarty->assign("cblocklist", $this->current_blocklist);
553       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
554       $smarty->assign("departments", $this->config->idepartments);
555       $smarty->assign("divSelectPredefined", $divSel->DrawList());
556       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
557       return ($display);
558     }
561     /* Show main page */
562     $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
563     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
564     $smarty->assign("printers", $this->printerList);
566     /* Load attributes */
567     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
568           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
569           "facsimileAlternateTelephoneNumber", "mail") as $val){
571       $smarty->assign("$val", $this->$val);
572       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
573     }
574     $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
575     $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
577     /* Load checkboxes */
578     if ($this->goFaxIsEnabled == "1"){
579       $smarty->assign("goFaxIsEnabled", "");
580     } else {
581       $smarty->assign("goFaxIsEnabled", "checked");
582     }
583     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
584     if ($this->goFaxDeliveryMode & 32) {
585       $smarty->assign("fax_to_mail", "checked");
586     } else {
587       $smarty->assign("fax_to_mail", "");
588     }
589     if ($this->goFaxDeliveryMode & 64) {
590       $smarty->assign("fax_to_printer", "checked");
591     } else {
592       $smarty->assign("fax_to_printer", "");
593     }
596     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
597     return ($display);
598   }
600   function remove_from_parent()
601   {
602     /* Cancel if there's nothing to do here */
603     if (!$this->initially_was_account){
604       return;
605     }
607     plugin::remove_from_parent();
609     /* Zero out arrays */
610     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
611           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
613       $this->attrs[$val]= array();
614     }
616     /* Adapt mail settings if needed */
617     if ($this->parent->by_object['mailAccount']->is_account){
618       unset($this->attrs['mail']);
619     }
621     $ldap= $this->config->get_ldap_link();
622     $ldap->cd($this->dn);
623     $ldap->modify($this->attrs);
624     show_ldap_error($ldap->get_error());
626     /* Optionally execute a command after we're done */
627     $this->handle_post_events('remove');
628   }
631   /* Check formular input */
632   function check()
633   {
634     /* Reset message array */
635     $message= array();
637     /* must: facsimileTelephoneNumber */
638     if ($this->facsimileTelephoneNumber == ""){
639       $message[]= _("The required field 'Fax' is not set.");
640     }
642     if (!is_phone_nr($this->facsimileTelephoneNumber)){
643       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
644     }
646     /* IF mail is specified (which is only the case if there's no mail account
647        present), check if it's valid..  */
648     if (@isset($this->parent->by_object['mailAccount']) &&
649         $this->goFaxDeliveryMode && 32){
650       if ($this->mail == ""){
651         $message[]= _("Mail delivery is checked, but no address has been specified.");
652       } elseif (!is_email($this->mail)){
653         $message[]= _("The mail address you've entered is invalid.");
654       }
655     }
657     // IE Fix, IE lets you choose disabled option, stupid browser ... 
658     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
659       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
660     }
662     return ($message);
663   }
665   /* Save data to object */
666   function save_object()
667   {
668     if (isset($_POST['faxTab'])){
669       plugin::save_object();
671       /* Adapt combobox values */
672       $tmp= 0;
673       if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
674         $tmp+= 32;
675       }
676       if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
677         $tmp+= 64;
678       }
679       if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
680         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
681           $this->goFaxIsEnabled= "0";
682         } else {
683           $this->goFaxIsEnabled= "1";
684         }
685       }
687       if (isset($_POST['facsimileTelephoneNumber'])){
688         if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
689           $this->is_modified= TRUE;
690         }
691         $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
692       }
694       if (isset($_POST['mail'])){
695         if ($this->mail != $_POST['mail']){
696           $this->is_modified= TRUE;
697         }
698         $this->mail= $_POST['mail'];
699       }
701       /* Write to object */
702       if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
703         if ($tmp != $this->goFaxDeliveryMode){
704           $this->is_modified= TRUE;
705         }
706         $this->goFaxDeliveryMode= "$tmp";
707       }
709       /* Check if mail account is active and correct the internal
710          reference to represent the current status. */
711       if ($this->parent->by_object['mailAccount']->is_account){
712         $this->has_mailAccount= TRUE;
713       }
714     }
716   }
719   /* Save to LDAP */
720   function save()
721   {
722     plugin::save();
724     /* Save arrays */
725     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
726           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
728       $this->attrs[$val]= $this->$val;
729     }
731     /* Adapt mail settings if needed */
732     unset($this->attrs['mail']);
733     if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
734       $this->attrs['mail']= $this->mail;
735     }
737     /* Write back to ldap */
738     $ldap= $this->config->get_ldap_link();
739     $ldap->cd($this->dn);
740     $ldap->modify($this->attrs);
741     show_ldap_error($ldap->get_error());
743     /* Optionally execute a command after we're done */
744     if ($this->initially_was_account == $this->is_account){
745       if ($this->is_modified){
746         $this->handle_post_events("mofify");
747       }
748     } else {
749       $this->handle_post_events("add");
750     }
752   }
755   /* Adapt from template, using 'dn' */
756   function adapt_from_template($dn)
757   {
758     plugin::adapt_from_template($dn);
760     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
761           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
763       if (isset($this->attrs[$val])){
764         $this->$val= $this->attrs[$val];
765       }
766     }
767   }
771   /* Add alternate fax recipient */
772   function addAlternate($number)
773   {
774     $this->facsimileAlternateTelephoneNumber[]= "$number";
775     $this->facsimileAlternateTelephoneNumber=
776       array_unique ($this->facsimileAlternateTelephoneNumber);
778     sort ($this->facsimileAlternateTelephoneNumber);
779     reset ($this->facsimileAlternateTelephoneNumber);
780   }
782   function delAlternate($numbers)
783   {
784     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
785         $this->facsimileAlternateTelephoneNumber);
786   }
791 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
792 ?>