Code

Added width=100% for divSelect
[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(296);
416       /* NEW LIST MANAGMENT
417        * We also need to search for the departments
418        * So we are able to navigate like in konquerer
419        */
420       $this->departments= array();
421    
422       /* Get all departments within the current department */ 
423       $base = $_SESSION['Fax_Filter']['depselect'];
424       $ldap->ls("(objectClass=gosaDepartment)",$base);
426       /* Base back is used to go one department up in our ldap tree */
427       $base_back = preg_replace("/^[^,]+,/","",$base);
429       /* Only show base_back if it is needed */
430       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
431         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
432       }
434       /* Fetch all returned departments an add them to our divlist */
435       while($value = $ldap->fetch()){
436         if($value["description"][0]!=".."){
437           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
438         }else{
439           $this->departments[$value['dn']]=$value["description"][0];
440         }
441       }
442       /* END NEW LIST MANAGMENT
443        */
445       // This links specifies the department open link 
446       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
448       /* Insert departments in divsel */
449       foreach($this->departments as $key=> $val){
450         if(!isset($this->config->departments[trim($key)])){
451           $this->config->departments[trim($key)]="";
452         }
453         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
454         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
455         $divSel->AddEntry(array($field1,$field2));
456       }
458       /* Append predefined Blocklists */
459       foreach($list as $entry => $value){
460         $divSel->AddEntry(array(
461               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
462               array("string"=>$value,"attach"=>"style='border:0px;'")
463               ));
464       }
466       /* Show dialog */
467       $smarty->assign("cblocklist", $this->current_blocklist);
468       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
469       $smarty->assign("departments", $this->config->idepartments);
470       $smarty->assign("divSelectPredefined", $divSel->DrawList());
471       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
472       return ($display);
473     }
475     /* Manage outgoing blocklists */
477     if ($this->out_blocklist_dialog){
479       /* This handles the divSelectBox */
481       /* The base specifies the current position in the ldap tree
482        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
483        */
484       $base = $_SESSION['Fax_Filter']['depselect'];
485       $ldap->cd($base);
487       /* Ge all Blocklists */ 
488       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
489       while ($attrs= $ldap->fetch()){
490         if(isset($attrs['description'][0])){
491           $list[$attrs['cn'][0]]=
492             $attrs['description'][0].
493             " [".$attrs['cn'][0]."]";
494         }else{
495           $list[$attrs['cn'][0]]= $attrs['cn'][0];
496         }
497       }
499       /*Create DivSel*/
500       $divSel = new divSelectBox("divSelectPredefined");
501       $divSel->setHeight(296);
503       /* NEW LIST MANAGMENT
504        * We also need to search for the departments
505        * So we are able to navigate like in konquerer
506        */
507       $this->departments= array();
508       $ldap->ls("(objectClass=gosaDepartment)",$base);
510       /* Generate Back url, and append if it is needed */
511       $base_back = preg_replace("/^[^,]+,/","",$base);
512       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
513         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
514       }
516       /* Get all departments */
517       while($value = $ldap->fetch()){
518         if(isset($value["description"][0])){
519           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
520         }else{
521           $this->departments[$value['dn']]=$value["description"][0];
522         }
523       }
524       /* END NEW LIST MANAGMENT
525        */
527       // Defining Links
528       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
530       /* Insert departments in divlist*/
531       foreach($this->departments as $key=> $val){
532         if(!isset($this->config->departments[trim($key)])){
533           $this->config->departments[trim($key)]="";
534         }
536         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
537         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
538         $divSel->AddEntry(array($field1,$field2));
539       }
541       /* Append Blocklits */
542       foreach($list as $entry => $value){
543         $divSel->AddEntry(array(
544               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
545               array("string"=>$value,"attach"=>"style='border:0px;'")
546               ));
547       }
549       /* Show dialog */
550       $smarty->assign("cblocklist", $this->current_blocklist);
551       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
552       $smarty->assign("departments", $this->config->idepartments);
553       $smarty->assign("divSelectPredefined", $divSel->DrawList());
554       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
555       return ($display);
556     }
559     /* Show main page */
560     $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
561     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
562     $smarty->assign("printers", $this->printerList);
564     /* Load attributes */
565     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
566           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
567           "facsimileAlternateTelephoneNumber", "mail") as $val){
569       $smarty->assign("$val", $this->$val);
570       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
571     }
572     $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
573     $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
575     /* Load checkboxes */
576     if ($this->goFaxIsEnabled == "1"){
577       $smarty->assign("goFaxIsEnabled", "");
578     } else {
579       $smarty->assign("goFaxIsEnabled", "checked");
580     }
581     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
582     if ($this->goFaxDeliveryMode & 32) {
583       $smarty->assign("fax_to_mail", "checked");
584     } else {
585       $smarty->assign("fax_to_mail", "");
586     }
587     if ($this->goFaxDeliveryMode & 64) {
588       $smarty->assign("fax_to_printer", "checked");
589     } else {
590       $smarty->assign("fax_to_printer", "");
591     }
594     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
595     return ($display);
596   }
598   function remove_from_parent()
599   {
600     /* Cancel if there's nothing to do here */
601     if (!$this->initially_was_account){
602       return;
603     }
605     plugin::remove_from_parent();
607     /* Zero out arrays */
608     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
609           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
611       $this->attrs[$val]= array();
612     }
614     /* Adapt mail settings if needed */
615     if ($this->parent->by_object['mailAccount']->is_account){
616       unset($this->attrs['mail']);
617     }
619     $ldap= $this->config->get_ldap_link();
620     $ldap->cd($this->dn);
621     $ldap->modify($this->attrs);
622     show_ldap_error($ldap->get_error());
624     /* Optionally execute a command after we're done */
625     $this->handle_post_events('remove');
626   }
629   /* Check formular input */
630   function check()
631   {
632     /* Reset message array */
633     $message= array();
635     /* must: facsimileTelephoneNumber */
636     if ($this->facsimileTelephoneNumber == ""){
637       $message[]= _("The required field 'Fax' is not set.");
638     }
640     if (!is_phone_nr($this->facsimileTelephoneNumber)){
641       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
642     }
644     /* IF mail is specified (which is only the case if there's no mail account
645        present), check if it's valid..  */
646     if (@isset($this->parent->by_object['mailAccount']) &&
647         $this->goFaxDeliveryMode && 32){
648       if ($this->mail == ""){
649         $message[]= _("Mail delivery is checked, but no address has been specified.");
650       } elseif (!is_email($this->mail)){
651         $message[]= _("The mail address you've entered is invalid.");
652       }
653     }
655     // IE Fix, IE lets you choose disabled option, stupid browser ... 
656     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
657       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
658     }
660     return ($message);
661   }
663   /* Save data to object */
664   function save_object()
665   {
666     if (isset($_POST['faxTab'])){
667       plugin::save_object();
669       /* Adapt combobox values */
670       $tmp= 0;
671       if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
672         $tmp+= 32;
673       }
674       if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
675         $tmp+= 64;
676       }
677       if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
678         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
679           $this->goFaxIsEnabled= "0";
680         } else {
681           $this->goFaxIsEnabled= "1";
682         }
683       }
685       if (isset($_POST['facsimileTelephoneNumber'])){
686         if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
687           $this->is_modified= TRUE;
688         }
689         $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
690       }
692       if (isset($_POST['mail'])){
693         if ($this->mail != $_POST['mail']){
694           $this->is_modified= TRUE;
695         }
696         $this->mail= $_POST['mail'];
697       }
699       /* Write to object */
700       if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
701         if ($tmp != $this->goFaxDeliveryMode){
702           $this->is_modified= TRUE;
703         }
704         $this->goFaxDeliveryMode= "$tmp";
705       }
707       /* Check if mail account is active and correct the internal
708          reference to represent the current status. */
709       if ($this->parent->by_object['mailAccount']->is_account){
710         $this->has_mailAccount= TRUE;
711       }
712     }
714   }
717   /* Save to LDAP */
718   function save()
719   {
720     plugin::save();
722     /* Save arrays */
723     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
724           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
726       $this->attrs[$val]= $this->$val;
727     }
729     /* Adapt mail settings if needed */
730     unset($this->attrs['mail']);
731     if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
732       $this->attrs['mail']= $this->mail;
733     }
735     /* Write back to ldap */
736     $ldap= $this->config->get_ldap_link();
737     $ldap->cd($this->dn);
738     $ldap->modify($this->attrs);
739     show_ldap_error($ldap->get_error());
741     /* Optionally execute a command after we're done */
742     if ($this->initially_was_account == $this->is_account){
743       if ($this->is_modified){
744         $this->handle_post_events("mofify");
745       }
746     } else {
747       $this->handle_post_events("add");
748     }
750   }
753   /* Adapt from template, using 'dn' */
754   function adapt_from_template($dn)
755   {
756     plugin::adapt_from_template($dn);
758     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
759           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
761       if (isset($this->attrs[$val])){
762         $this->$val= $this->attrs[$val];
763       }
764     }
765   }
769   /* Add alternate fax recipient */
770   function addAlternate($number)
771   {
772     $this->facsimileAlternateTelephoneNumber[]= "$number";
773     $this->facsimileAlternateTelephoneNumber=
774       array_unique ($this->facsimileAlternateTelephoneNumber);
776     sort ($this->facsimileAlternateTelephoneNumber);
777     reset ($this->facsimileAlternateTelephoneNumber);
778   }
780   function delAlternate($numbers)
781   {
782     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
783         $this->facsimileAlternateTelephoneNumber);
784   }
789 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
790 ?>