Code

Updated translation, fixed some typo/errors
[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   /* Department list shown in the divSelectList*/
10   var $departments;
12   /* Fax attributes */
13   var $goFaxDeliveryMode= "0";
14   var $facsimileTelephoneNumber= "";
15   var $goFaxIsEnabled= 1;
16   var $goFaxPrinter= "";
17   var $goFaxDivertNumber= "";
18   var $goFaxLanguage= "";
19   var $goFaxFormat= "";
20   var $goFaxRBlocklist = array();
21   var $goFaxRBlockgroups= array();
22   var $goFaxSBlocklist= array();
23   var $goFaxSBlockgroups= array();
24   var $mail= "";
25   var $facsimileAlternateTelephoneNumber= array();
27   /* Internal variables */
28   var $printerList= array();
29   var $has_mailAccount= FALSE;
30   var $locals_dialog= FALSE;
31   var $in_blocklist_dialog= FALSE;
32   var $out_blocklist_dialog= FALSE;
33   var $current_blocklist= array();
35   /* Copy & paste variables */
36   var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
38   /* attribute list for save action */
39   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
40   var $objectclasses= array("goFaxAccount");
42   var $uid= "";
44   function gofaxAccount ($config, $dn= NULL, $parent)
45   {
46     /* General initialization */
47     plugin::plugin ($config, $dn, $parent);
49     /* Get user id */
50     if(isset($this->attrs['uid'])){
51       $this->uid = $this->attrs['uid'][0];
52     }
54     /* Hickert : 11.11.05
55      * Added to be able to handle department selection in divSelelect
56      */
57     if(!isset($_SESSION["Fax_Filter"])){
58       $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
59     }
61     if ($dn != "new"){
62       /* Get arrays */
63       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
64             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
65         $this->$val =array();
66         if (isset($this->attrs["$val"]["count"])){
67           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
68             array_push($this->$val, $this->attrs["$val"][$i]);
69           }
70         }
71       }
73       /* Set up has_mailAccount */
74       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
75         $this->has_mailAccount= TRUE;
76       }
77       if (isset($this->attrs["facsimileTelephoneNumber"][0])){
78         $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
79       }
80     }
82     /* Load printer list */
83     if (isset($this->config->data['SERVERS']['CUPS'])){
84       $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
85       asort ($this->printerList);
86     }
88     /* Get global filter config */
89     if (!is_global("faxfilter")){
90       $ui= get_userinfo();
91       $base= get_base_from_people($ui->dn);
92       $faxfilter= array( "depselect"       => $base,
93           "fuser"            => "*",
94           "regex"           => "");
95       register_global("faxfilter", $faxfilter);
96     }
97     $this->ui = get_userinfo();
98   }
100   function execute()
101   {
102     /* Call parent execute */
103     plugin::execute();
106     $acl= get_permissions ($this->ui->dn, $this->ui->subtreeACL);
107     $editacl= get_module_permission($acl, "gofax", $this->dn);
108     $this->acl = $editacl;
110     /* Hickert : 11.11.05
111      * Added to be able to handle department selection in divSelelect
112      */
113     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
115       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
116         $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
117       }else{
118         $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
119       }
120     }
122     /* Load smarty stuff */
123     $smarty= get_smarty();
125     /* Check if mail account is active. We'll display an additional
126        mail address field if this is not the case. Some people may
127        want goFax, but have a mailserver which is not managed with
128        GOsa */
129     if (!@isset($this->parent->by_object['mailAccount'])) {
130       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
131     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
132       $smarty->assign("has_mailaccount", "false");
133       $this->has_mailAccount= false;
134     } else {
135       $smarty->assign("has_mailaccount", "true");
136     }
138     /* Do we need to flip is_account state? */
139     if (isset($_POST['modify_state'])){
141       /* Onyl change account state if allowed */
142       if($this->is_account && $this->acl == "#all#"){
143         $this->is_account= !$this->is_account;
144       }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
145         $this->is_account= !$this->is_account;
146       }
147     }
149     /* Do we represent a valid account? */
150     if (!$this->is_account && $this->parent == NULL){
151       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
152         _("This account has no fax extensions.")."</b>";
153       $display.= back_to_main();
154       return ($display);
155     }
157     /* Show tab dialog headers */
158     $display= "";
159     if ($this->parent != NULL){
160       if ($this->is_account){
161         $display= $this->show_header(_("Remove fax account"),
162             _("This account has fax features enabled. You can disable them by clicking below."));
163       } else {
164         $display= $this->show_header(_("Create fax account"),
165             _("This account has fax features disabled. You can enable them by clicking below."));
166         return ($display);
167       }
168     }
170     /* Trigger Add local fax alternatives dialog */
171     if (isset($_POST['add_local_alternate'])){
172       $this->locals_dialog= TRUE;       
173       $this->dialog= TRUE;      
174     }
176     /* Add alternatives from dialog */
177     if (isset($_POST['add_locals_finish'])){
178       if (isset($_POST['local_list']) &&
179           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
181         foreach ($_POST['local_list'] as $val){
182           $this->addAlternate($val);
183           $this->is_modified= TRUE;
184         }
185       }
186     }
188     /* Add alternatives */
189     if (isset($_POST['add_alternate'])){
190       if ($_POST['forward_address'] != "" &&
191           is_phone_nr($_POST['forward_address']) &&
192           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
194         $this->addAlternate($_POST['forward_address']);
195       }
196     }
198     /* Delete alternate fax number */
199     if (isset($_POST['delete_alternate'])){
200       if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
201           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
203         $this->delAlternate ($_POST['alternate_list']);
204       }
205     }
208     /* Edit incoming blocklists */
209     if (isset($_POST['edit_incoming'])){
210       $this->current_blocklist= array_merge($this->goFaxRBlocklist,
211           $this->goFaxRBlockgroups);
212       sort($this->current_blocklist);
213       reset($this->current_blocklist);
215       $this->in_blocklist_dialog= TRUE;
216       $this->dialog= TRUE;
217     }
219     /* Edit outgoing blocklists */
220     if (isset($_POST['edit_outgoing'])){
221       $this->current_blocklist= array_merge($this->goFaxSBlocklist,
222           $this->goFaxSBlockgroups);
223       sort($this->current_blocklist);
224       reset($this->current_blocklist);
226       $this->out_blocklist_dialog= TRUE;
227       $this->dialog= TRUE;
228     }
230     /* Add number to blocklist (dialog) */
231     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
232       if (!is_phone_nr($_POST['block_number'])){
233         print_red (_("You're trying to add an invalid phone number."));
234       } else {
235         array_push($this->current_blocklist, $_POST['block_number']);
236         $this->current_blocklist= array_unique($this->current_blocklist);
237         sort($this->current_blocklist);
238         reset($this->current_blocklist);
239       }
240     }
242     /* Hickert : 11.11.05
243      * Add selection from divSelelect to our Blocklist 
244      */
245     /* Add list to blocklist */
246     if (isset($_POST['add_blocklist'])){
247       foreach($_POST as $name => $value){
248         if(preg_match("/ADDLIST_/i",$name)){
249           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
251         }
252       } 
253       $this->current_blocklist= array_unique($this->current_blocklist);
254       sort($this->current_blocklist);
255       reset($this->current_blocklist);
256     }
258     /* Add list to blocklist */
259     if (isset($_GET['add'])){
260       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
261       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
262       $this->current_blocklist= array_unique($this->current_blocklist);
263       sort($this->current_blocklist);
264       reset($this->current_blocklist);
265     }
267     /* Delete from blocklist */
268     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
269       $tmp= array();
270       foreach($this->current_blocklist as $val){
271         if (!in_array($val, $_POST['block_list'])){
272           $tmp[]= $val;
273         }
274       }
275       $this->current_blocklist= $tmp;
276     }
279     /* Blocklist edit finished */
280     if (isset($_POST['edit_blocklists_finish'])){
282       /* Incoming or outgoing? */
283       if ($this->in_blocklist_dialog){
284         $this->goFaxRBlocklist = array();
285         $this->goFaxRBlockgroups = array();
287         foreach ($this->current_blocklist as $val){
288           if (is_phone_nr($val)){
289             $this->goFaxRBlocklist[]=$val;
290           } else {
291             $this->goFaxRBlockgroups[]= $val;
292           }
293         }
294       } else {
295         $this->goFaxSBlocklist = array();
296         $this->goFaxSBlockgroups = array();
298         /* Transfer values to ourself */
299         foreach ($this->current_blocklist as $val){
300           if (is_phone_nr($val)){
301             $this->goFaxSBlocklist[]=$val;
302           } else {
303             $this->goFaxSBlockgroups[]= $val;
304           }
305         }
306       }
307       $this->is_modified= TRUE;
308     }
311     /* Set departments */
312     if ($this->locals_dialog ||
313         $this->in_blocklist_dialog ||
314         $this->out_blocklist_dialog){
316       $list= array ();
317       $ldap= $this->config->get_ldap_link();
318       if (isset ($_POST['department'])){
319         $ldap->cd ($_POST['department']);
320       } else {
321         $ldap->cd ($this->config->current['BASE']);
322       }
323     }
325     /* Cancel  dialogs */
326     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
327         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
329       $this->locals_dialog= FALSE;
330       $this->in_blocklist_dialog= FALSE;
331       $this->out_blocklist_dialog= FALSE;
332       $this->dialog= FALSE;
333     }
335     /* Manage locals dialog */
336     if ($this->locals_dialog){
338       /* Save data */
339       $faxfilter= get_global("faxfilter");
340       foreach( array("depselect", "fuser", "regex") as $type){
341         if (isset($_POST[$type])){
342           $faxfilter[$type]= $_POST[$type];
343         }
344       }
345       if (isset($_GET['search'])){
346         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
347         if ($s == "**"){
348           $s= "*";
349         }
350         $faxfilter['fuser']= $s;
351       }
352       register_global("faxfilter", $faxfilter);
354       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
355         $regex= $faxfilter['regex'];
356         $filter= "(facimileTelephoneNumber=$regex)";
357       } else {
358         $filter= "";
359       }
360       if ($faxfilter['fuser'] != ""){
361         $user= $faxfilter['fuser'];
362         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
363       }
365       $base= $faxfilter['depselect'];
366       $acl= array($this->config->current['BASE'] => ":all");
367       $res= get_list("(&(objectClass=goFaxAccount)$filter)", $acl, $base, 
368                      array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
370       foreach ($res as $attrs){
371         $list[$attrs['facsimileTelephoneNumber'][0]]=
372           $attrs['sn'][0].", ".
373           $attrs['givenName'][0]." [".
374           $attrs['facsimileTelephoneNumber'][0]."]";
375       }
377       /* Show dialog */
378       $smarty->assign("search_image", get_template_path('images/search.png'));
379       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
380       $smarty->assign("tree_image", get_template_path('images/tree.png'));
381       $smarty->assign("infoimage", get_template_path('images/info.png'));
382       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
383       $smarty->assign("departments", $this->config->idepartments);
384       $smarty->assign("list", $list);
385       if (isset($_POST['depselect'])){
386         $smarty->assign("depselect", $_POST['depselect']);
387       }
388       $smarty->assign("deplist", $this->config->idepartments);
389       $smarty->assign("apply", apply_filter());
390       $smarty->assign("alphabet", generate_alphabet());
391       $smarty->assign("hint", print_sizelimit_warning());
392       foreach( array("depselect", "fuser", "regex") as $type){
393         $smarty->assign("$type", $faxfilter[$type]);
394       }
395       $smarty->assign("hint", print_sizelimit_warning());
397       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
398       return ($display);
399     }
402     /* Manage incoming blocklists */
403     if ($this->in_blocklist_dialog){
405       /* This handles the divSelectBox */
407       /* The base specifies the current position in the ldap tree 
408        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
409        */
410       $base = $_SESSION['Fax_Filter']['depselect'];
411       $ldap->cd($base);
413       /* Ge all Blocklists */
414       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
415       while ($attrs= $ldap->fetch()){
417         /* Generate list depending on description */
418         if(isset($attrs['description'][0])){
419           $list[$attrs['cn'][0]]=
420             $attrs['description'][0].
421             " [".$attrs['cn'][0]."]";
422         }else{
423           $list[$attrs['cn'][0]]= $attrs['cn'][0];
424         }
425       }
427       /* Create our divselect box */
428       $divSel = new divSelectBox("divSelectPredefined");
429       $divSel->setHeight(296);
431       /* NEW LIST MANAGMENT
432        * We also need to search for the departments
433        * So we are able to navigate like in konquerer
434        */
435       $this->departments= array();
436    
437       /* Get all departments within the current department */ 
438       $base = $_SESSION['Fax_Filter']['depselect'];
439       $ldap->ls("(objectClass=gosaDepartment)",$base);
441       /* Base back is used to go one department up in our ldap tree */
442       $base_back = preg_replace("/^[^,]+,/","",$base);
444       /* Only show base_back if it is needed */
445       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
446         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
447       }
449       /* Fetch all returned departments an add them to our divlist */
450       while($value = $ldap->fetch()){
451         if($value["description"][0]!=".."){
452           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
453         }else{
454           $this->departments[$value['dn']]=$value["description"][0];
455         }
456       }
457       /* END NEW LIST MANAGMENT
458        */
460       // This links specifies the department open link 
461       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
463       /* Insert departments in divsel */
464       foreach($this->departments as $key=> $val){
465         if(!isset($this->config->departments[trim($key)])){
466           $this->config->departments[trim($key)]="";
467         }
468         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
469         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
470         $divSel->AddEntry(array($field1,$field2));
471       }
473       /* Append predefined Blocklists */
474       foreach($list as $entry => $value){
475         $divSel->AddEntry(array(
476               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
477               array("string"=>$value,"attach"=>"style='border:0px;'")
478               ));
479       }
481       /* Show dialog */
482       $smarty->assign("cblocklist", $this->current_blocklist);
483       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
484       $smarty->assign("departments", $this->config->idepartments);
485       $smarty->assign("divSelectPredefined", $divSel->DrawList());
486       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
487       return ($display);
488     }
490     /* Manage outgoing blocklists */
492     if ($this->out_blocklist_dialog){
494       /* This handles the divSelectBox */
496       /* The base specifies the current position in the ldap tree
497        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
498        */
499       $base = $_SESSION['Fax_Filter']['depselect'];
500       $ldap->cd($base);
502       /* Ge all Blocklists */ 
503       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
504       while ($attrs= $ldap->fetch()){
505         if(isset($attrs['description'][0])){
506           $list[$attrs['cn'][0]]=
507             $attrs['description'][0].
508             " [".$attrs['cn'][0]."]";
509         }else{
510           $list[$attrs['cn'][0]]= $attrs['cn'][0];
511         }
512       }
514       /*Create DivSel*/
515       $divSel = new divSelectBox("divSelectPredefined");
516       $divSel->setHeight(296);
518       /* NEW LIST MANAGMENT
519        * We also need to search for the departments
520        * So we are able to navigate like in konquerer
521        */
522       $this->departments= array();
523       $ldap->ls("(objectClass=gosaDepartment)",$base);
525       /* Generate Back url, and append if it is needed */
526       $base_back = preg_replace("/^[^,]+,/","",$base);
527       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
528         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
529       }
531       /* Get all departments */
532       while($value = $ldap->fetch()){
533         if(isset($value["description"][0])){
534           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
535         }else{
536           $this->departments[$value['dn']]=$value["description"][0];
537         }
538       }
539       /* END NEW LIST MANAGMENT
540        */
542       // Defining Links
543       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
545       /* Insert departments in divlist*/
546       foreach($this->departments as $key=> $val){
547         if(!isset($this->config->departments[trim($key)])){
548           $this->config->departments[trim($key)]="";
549         }
551         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
552         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
553         $divSel->AddEntry(array($field1,$field2));
554       }
556       /* Append Blocklits */
557       foreach($list as $entry => $value){
558         $divSel->AddEntry(array(
559               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
560               array("string"=>$value,"attach"=>"style='border:0px;'")
561               ));
562       }
564       /* Show dialog */
565       $smarty->assign("cblocklist", $this->current_blocklist);
566       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
567       $smarty->assign("departments", $this->config->idepartments);
568       $smarty->assign("divSelectPredefined", $divSel->DrawList());
569       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
570       return ($display);
571     }
574     /* Show main page */
575     $smarty->assign("languages", get_languages(TRUE));
577     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
578     $smarty->assign("printers", $this->printerList);
580     /* Load attributes */
581     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
582           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
583           "facsimileAlternateTelephoneNumber", "mail") as $val){
585       $smarty->assign("$val", $this->$val);
586       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
587     }
588     $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
589     $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
591     /* Load checkboxes */
592     if ($this->goFaxIsEnabled == "1"){
593       $smarty->assign("goFaxIsEnabled", "");
594     } else {
595       $smarty->assign("goFaxIsEnabled", "checked");
596     }
597     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
598     if ($this->goFaxDeliveryMode & 32) {
599       $smarty->assign("fax_to_mail", "checked");
600     } else {
601       $smarty->assign("fax_to_mail", "");
602     }
603     if ($this->goFaxDeliveryMode & 64) {
604       $smarty->assign("fax_to_printer", "checked");
605     } else {
606       $smarty->assign("fax_to_printer", "");
607     }
610     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
611     return ($display);
612   }
614   function remove_from_parent()
615   {
616     /* Cancel if there's nothing to do here */
617     if (!$this->initially_was_account){
618       return;
619     }
621     plugin::remove_from_parent();
623     /* Adapt mail settings if needed */
624     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
625       unset($this->attrs['mail']);
626     }
628     $ldap= $this->config->get_ldap_link();
629     $ldap->cd($this->dn);
630     $this->cleanup();
631     $ldap->modify ($this->attrs); 
633     show_ldap_error($ldap->get_error(), _("Removing FAX account failed"));
635     /* Optionally execute a command after we're done */
636     $this->handle_post_events('remove',array("uid"=> $this->uid));
637   }
640   /* Check formular input */
641   function check()
642   {
643     /* Call common method to give check the hook */
644     $message= plugin::check();
646     /* must: facsimileTelephoneNumber */
647     if ($this->facsimileTelephoneNumber == ""){
648       $message[]= _("The required field 'Fax' is not set.");
649     }
651     if (!is_phone_nr($this->facsimileTelephoneNumber)){
652       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
653     }
655     /* IF mail is specified (which is only the case if there's no mail account
656        present), check if it's valid..  */
657     if (@isset($this->parent->by_object['mailAccount']) &&
658         $this->goFaxDeliveryMode & 32){
659       if ($this->mail == ""){
660         $message[]= _("Mail delivery is checked, but no address has been specified.");
661       } elseif (!is_email($this->mail)){
662         $message[]= _("The mail address you've entered is invalid.");
663       }
664     }
666     // IE Fix, IE lets you choose disabled option, stupid browser ... 
667     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
668       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
669     }
671     return ($message);
672   }
674   /* Save data to object */
675   function save_object()
676   {
677     if (isset($_POST['faxTab'])){
678       plugin::save_object();
680       /* Adapt combobox values */
681       $tmp= 0;
682       if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
683         $tmp+= 32;
684       }
685       if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
686         $tmp+= 64;
687       }
688       if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
689         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
690           $this->goFaxIsEnabled= "0";
691         } else {
692           $this->goFaxIsEnabled= "1";
693         }
694       }
696       if (isset($_POST['facsimileTelephoneNumber'])){
697         if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
698           $this->is_modified= TRUE;
699         }
700         $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
701       }
703       if (isset($_POST['mail'])){
704         if ($this->mail != $_POST['mail']){
705           $this->is_modified= TRUE;
706         }
707         $this->mail= $_POST['mail'];
708       }
710       /* Write to object */
711       if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
712         if ($tmp != $this->goFaxDeliveryMode){
713           $this->is_modified= TRUE;
714         }
715         $this->goFaxDeliveryMode= "$tmp";
716       }
718       /* Check if mail account is active and correct the internal
719          reference to represent the current status. */
720       if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
721         $this->has_mailAccount= TRUE;
722       }
723     }
725   }
728   /* Save to LDAP */
729   function save()
730   {
731     plugin::save();
733     /* Save arrays */
734     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
735           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
737       $this->attrs[$val]= $this->$val;
738     }
740     /* Do not save mail address ... it was possibly changed by mail plugin*/
741     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
742       unset($this->attrs['mail']);
743     }
745     /* Write back to ldap */
746     $ldap= $this->config->get_ldap_link();
747     $ldap->cd($this->dn);
748     $this->cleanup();
749     $ldap->modify ($this->attrs); 
751     show_ldap_error($ldap->get_error(), _("Saving FAX account failed"));
753     /* Optionally execute a command after we're done */
754     if ($this->initially_was_account == $this->is_account){
755       if ($this->is_modified){
756         $this->handle_post_events("modify",array("uid" => $this->uid));
757       }
758     } else {
759       $this->handle_post_events("add",array("uid" => $this->uid));
760     }
762   }
765   /* Adapt from template, using 'dn' */
766   function adapt_from_template($dn)
767   {
768     plugin::adapt_from_template($dn);
770     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
771           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
773       if (isset($this->attrs[$val])){
774         $this->$val= $this->attrs[$val];
775       }
776     }
777   }
781   /* Add alternate fax recipient */
782   function addAlternate($number)
783   {
784     $this->facsimileAlternateTelephoneNumber[]= "$number";
785     $this->facsimileAlternateTelephoneNumber=
786       array_unique ($this->facsimileAlternateTelephoneNumber);
788     sort ($this->facsimileAlternateTelephoneNumber);
789     reset ($this->facsimileAlternateTelephoneNumber);
790   }
792   function delAlternate($numbers)
793   {
794     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
795         $this->facsimileAlternateTelephoneNumber);
796   }
798   function getCopyDialog()
799   {
800     $str    = "";
801     $smarty = get_smarty();
802     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
803     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
804     $str['status'] ="";
805     return($str);
806   }
808   function SaveCopyDialog()
809   {
810     if(isset($_POST['facsimileTelephoneNumber'])){
811       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
812     }
813   }
817 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
818 ?>