Code

Readed koabConnectivity Account Free Busy check
[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","goFaxRBlockgroups","facsimileAlternateTelephoneNumber",
43       "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail");
44   var $objectclasses= array("goFaxAccount");
46   var $uid= "";
48   function gofaxAccount ($config, $dn= NULL, $parent)
49   {
50     /* General initialization */
51     plugin::plugin ($config, $dn, $parent);
53     /* Get user id */
54     if(isset($this->attrs['uid'])){
55       $this->uid = $this->attrs['uid'][0];
56     }
58     /* Hickert : 11.11.05
59      * Added to be able to handle department selection in divSelelect
60      */
61     if(!isset($_SESSION["Fax_Filter"])){
62       $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
63     }
65     if ($dn != "new"){
66       /* Get arrays */
67       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
68             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
69         $this->$val =array();
70         if (isset($this->attrs["$val"]["count"])){
71           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
72             array_push($this->$val, $this->attrs["$val"][$i]);
73           }
74         }
75       }
77       /* Set up has_mailAccount */
78       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
79         $this->has_mailAccount= TRUE;
80       }
81       if (isset($this->attrs["facsimileTelephoneNumber"][0])){
82         $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
83       }
84     }
86     /* Load printer list */
87     if (isset($this->config->data['SERVERS']['CUPS'])){
88       $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
89       asort ($this->printerList);
90     }
92     /* Get global filter config */
93     if (!is_global("faxfilter")){
94       $ui= get_userinfo();
95       $base= get_base_from_people($ui->dn);
96       $faxfilter= array( "depselect"       => $base,
97           "fuser"            => "*",
98           "regex"           => "");
99       register_global("faxfilter", $faxfilter);
100     }
101   }
103   function execute()
104   {
105     /* Call parent execute */
106     plugin::execute();
107     /* Hickert : 11.11.05
108      * Added to be able to handle department selection in divSelelect
109      */
110     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
112       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
113         $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
114       }else{
115         $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
116       }
117     }
119     /* Load smarty stuff */
120     $smarty= get_smarty();
122     /* Check if mail account is active. We'll display an additional
123        mail address field if this is not the case. Some people may
124        want goFax, but have a mailserver which is not managed with
125        GOsa */
126     if (!@isset($this->parent->by_object['mailAccount'])) {
127       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
128     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
129       $smarty->assign("has_mailaccount", "false");
130       $this->has_mailAccount= false;
131     } else {
132       $smarty->assign("has_mailaccount", "true");
133     }
135     /* Do we need to flip is_account state? */
136     if (isset($_POST['modify_state'])){
137       $this->is_account= !$this->is_account;
138     }
140     /* Do we represent a valid account? */
141     if (!$this->is_account && $this->parent == NULL){
142       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
143         _("This account has no fax extensions.")."</b>";
144       $display.= back_to_main();
145       return ($display);
146     }
148     /* Show tab dialog headers */
149     $display= "";
150     if ($this->parent != NULL){
151       if ($this->is_account){
152         $display= $this->show_header(_("Remove fax account"),
153             _("This account has fax features enabled. You can disable them by clicking below."));
154       } else {
155         $display= $this->show_header(_("Create fax account"),
156             _("This account has fax features disabled. You can enable them by clicking below."));
157         return ($display);
158       }
159     }
161     /* Trigger Add local fax alternatives dialog */
162     if (isset($_POST['add_local_alternate'])){
163       $this->locals_dialog= TRUE;       
164       $this->dialog= TRUE;      
165     }
167     /* Add alternatives from dialog */
168     if (isset($_POST['add_locals_finish'])){
169       if (isset($_POST['local_list']) &&
170           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
172         foreach ($_POST['local_list'] as $val){
173           $this->addAlternate($val);
174           $this->is_modified= TRUE;
175         }
176       }
177     }
179     /* Add alternatives */
180     if (isset($_POST['add_alternate'])){
181       if ($_POST['forward_address'] != "" &&
182           is_phone_nr($_POST['forward_address']) &&
183           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
185         $this->addAlternate($_POST['forward_address']);
186       }
187     }
189     /* Delete alternate fax number */
190     if (isset($_POST['delete_alternate'])){
191       if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
192           chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
194         $this->delAlternate ($_POST['alternate_list']);
195       }
196     }
199     /* Edit incoming blocklists */
200     if (isset($_POST['edit_incoming'])){
201       $this->current_blocklist= array_merge($this->goFaxRBlocklist,
202           $this->goFaxRBlockgroups);
203       sort($this->current_blocklist);
204       reset($this->current_blocklist);
206       $this->in_blocklist_dialog= TRUE;
207       $this->dialog= TRUE;
208     }
210     /* Edit outgoing blocklists */
211     if (isset($_POST['edit_outgoing'])){
212       $this->current_blocklist= array_merge($this->goFaxSBlocklist,
213           $this->goFaxSBlockgroups);
214       sort($this->current_blocklist);
215       reset($this->current_blocklist);
217       $this->out_blocklist_dialog= TRUE;
218       $this->dialog= TRUE;
219     }
221     /* Add number to blocklist (dialog) */
222     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
223       if (!is_phone_nr($_POST['block_number'])){
224         print_red (_("You're trying to add an invalid phone number."));
225       } else {
226         array_push($this->current_blocklist, $_POST['block_number']);
227         $this->current_blocklist= array_unique($this->current_blocklist);
228         sort($this->current_blocklist);
229         reset($this->current_blocklist);
230       }
231     }
233     /* Hickert : 11.11.05
234      * Add selection from divSelelect to our Blocklist 
235      */
236     /* Add list to blocklist */
237     if (isset($_POST['add_blocklist'])){
238       foreach($_POST as $name => $value){
239         if(preg_match("/ADDLIST_/i",$name)){
240           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
242         }
243       } 
244       $this->current_blocklist= array_unique($this->current_blocklist);
245       sort($this->current_blocklist);
246       reset($this->current_blocklist);
247     }
249     /* Add list to blocklist */
250     if (isset($_GET['add'])){
251       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
252       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
253       $this->current_blocklist= array_unique($this->current_blocklist);
254       sort($this->current_blocklist);
255       reset($this->current_blocklist);
256     }
258     /* Delete from blocklist */
259     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
260       $tmp= array();
261       foreach($this->current_blocklist as $val){
262         if (!in_array($val, $_POST['block_list'])){
263           $tmp[]= $val;
264         }
265       }
266       $this->current_blocklist= $tmp;
267     }
270     /* Blocklist edit finished */
271     if (isset($_POST['edit_blocklists_finish'])){
273       /* Incoming or outgoing? */
274       if ($this->in_blocklist_dialog){
275         $this->goFaxRBlocklist = array();
276         $this->goFaxRBlockgroups = array();
278         foreach ($this->current_blocklist as $val){
279           if (is_phone_nr($val)){
280             $this->goFaxRBlocklist[]=$val;
281           } else {
282             $this->goFaxRBlockgroups[]= $val;
283           }
284         }
285       } else {
286         $this->goFaxSBlocklist = array();
287         $this->goFaxSBlockgroups = array();
289         /* Transfer values to ourself */
290         foreach ($this->current_blocklist as $val){
291           if (is_phone_nr($val)){
292             $this->goFaxSBlocklist[]=$val;
293           } else {
294             $this->goFaxSBlockgroups[]= $val;
295           }
296         }
297       }
298       $this->is_modified= TRUE;
299     }
302     /* Set departments */
303     if ($this->locals_dialog ||
304         $this->in_blocklist_dialog ||
305         $this->out_blocklist_dialog){
307       $list= array ();
308       $ldap= $this->config->get_ldap_link();
309       if (isset ($_POST['department'])){
310         $ldap->cd ($_POST['department']);
311       } else {
312         $ldap->cd ($this->config->current['BASE']);
313       }
314     }
316     /* Cancel  dialogs */
317     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
318         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
320       $this->locals_dialog= FALSE;
321       $this->in_blocklist_dialog= FALSE;
322       $this->out_blocklist_dialog= FALSE;
323       $this->dialog= FALSE;
324     }
326     /* Manage locals dialog */
327     if ($this->locals_dialog){
329       /* Save data */
330       $faxfilter= get_global("faxfilter");
331       foreach( array("depselect", "fuser", "regex") as $type){
332         if (isset($_POST[$type])){
333           $faxfilter[$type]= $_POST[$type];
334         }
335       }
336       if (isset($_GET['search'])){
337         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
338         if ($s == "**"){
339           $s= "*";
340         }
341         $faxfilter['fuser']= $s;
342       }
343       register_global("faxfilter", $faxfilter);
345       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
346         $regex= $faxfilter['regex'];
347         $filter= "(facimileTelephoneNumber=$regex)";
348       } else {
349         $filter= "";
350       }
351       if ($faxfilter['fuser'] != ""){
352         $user= $faxfilter['fuser'];
353         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
354       }
356       $base= $faxfilter['depselect'];
357       $acl= array($this->config->current['BASE'] => ":all");
358       $res= get_list("(&(objectClass=goFaxAccount)$filter)", $acl, $base, 
359                      array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
361       foreach ($res as $attrs){
362         $list[$attrs['facsimileTelephoneNumber'][0]]=
363           $attrs['sn'][0].", ".
364           $attrs['givenName'][0]." [".
365           $attrs['facsimileTelephoneNumber'][0]."]";
366       }
368       /* Show dialog */
369       $smarty->assign("search_image", get_template_path('images/search.png'));
370       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
371       $smarty->assign("tree_image", get_template_path('images/tree.png'));
372       $smarty->assign("infoimage", get_template_path('images/info.png'));
373       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
374       $smarty->assign("departments", $this->config->idepartments);
375       $smarty->assign("list", $list);
376       if (isset($_POST['depselect'])){
377         $smarty->assign("depselect", $_POST['depselect']);
378       }
379       $smarty->assign("deplist", $this->config->idepartments);
380       $smarty->assign("apply", apply_filter());
381       $smarty->assign("alphabet", generate_alphabet());
382       $smarty->assign("hint", print_sizelimit_warning());
383       foreach( array("depselect", "fuser", "regex") as $type){
384         $smarty->assign("$type", $faxfilter[$type]);
385       }
386       $smarty->assign("hint", print_sizelimit_warning());
388       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
389       return ($display);
390     }
393     /* Manage incoming blocklists */
394     if ($this->in_blocklist_dialog){
396       /* This handles the divSelectBox */
398       /* The base specifies the current position in the ldap tree 
399        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
400        */
401       $base = $_SESSION['Fax_Filter']['depselect'];
402       $ldap->cd($base);
404       /* Ge all Blocklists */
405       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
406       while ($attrs= $ldap->fetch()){
408         /* Generate list depending on description */
409         if(isset($attrs['description'][0])){
410           $list[$attrs['cn'][0]]=
411             $attrs['description'][0].
412             " [".$attrs['cn'][0]."]";
413         }else{
414           $list[$attrs['cn'][0]]= $attrs['cn'][0];
415         }
416       }
418       /* Create our divselect box */
419       $divSel = new divSelectBox("divSelectPredefined");
420       $divSel->setHeight(296);
422       /* NEW LIST MANAGMENT
423        * We also need to search for the departments
424        * So we are able to navigate like in konquerer
425        */
426       $this->departments= array();
427    
428       /* Get all departments within the current department */ 
429       $base = $_SESSION['Fax_Filter']['depselect'];
430       $ldap->ls("(objectClass=gosaDepartment)",$base);
432       /* Base back is used to go one department up in our ldap tree */
433       $base_back = preg_replace("/^[^,]+,/","",$base);
435       /* Only show base_back if it is needed */
436       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
437         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
438       }
440       /* Fetch all returned departments an add them to our divlist */
441       while($value = $ldap->fetch()){
442         if($value["description"][0]!=".."){
443           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
444         }else{
445           $this->departments[$value['dn']]=$value["description"][0];
446         }
447       }
448       /* END NEW LIST MANAGMENT
449        */
451       // This links specifies the department open link 
452       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
454       /* Insert departments in divsel */
455       foreach($this->departments as $key=> $val){
456         if(!isset($this->config->departments[trim($key)])){
457           $this->config->departments[trim($key)]="";
458         }
459         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
460         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
461         $divSel->AddEntry(array($field1,$field2));
462       }
464       /* Append predefined Blocklists */
465       foreach($list as $entry => $value){
466         $divSel->AddEntry(array(
467               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
468               array("string"=>$value,"attach"=>"style='border:0px;'")
469               ));
470       }
472       /* Show dialog */
473       $smarty->assign("cblocklist", $this->current_blocklist);
474       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
475       $smarty->assign("departments", $this->config->idepartments);
476       $smarty->assign("divSelectPredefined", $divSel->DrawList());
477       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
478       return ($display);
479     }
481     /* Manage outgoing blocklists */
483     if ($this->out_blocklist_dialog){
485       /* This handles the divSelectBox */
487       /* The base specifies the current position in the ldap tree
488        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
489        */
490       $base = $_SESSION['Fax_Filter']['depselect'];
491       $ldap->cd($base);
493       /* Ge all Blocklists */ 
494       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
495       while ($attrs= $ldap->fetch()){
496         if(isset($attrs['description'][0])){
497           $list[$attrs['cn'][0]]=
498             $attrs['description'][0].
499             " [".$attrs['cn'][0]."]";
500         }else{
501           $list[$attrs['cn'][0]]= $attrs['cn'][0];
502         }
503       }
505       /*Create DivSel*/
506       $divSel = new divSelectBox("divSelectPredefined");
507       $divSel->setHeight(296);
509       /* NEW LIST MANAGMENT
510        * We also need to search for the departments
511        * So we are able to navigate like in konquerer
512        */
513       $this->departments= array();
514       $ldap->ls("(objectClass=gosaDepartment)",$base);
516       /* Generate Back url, and append if it is needed */
517       $base_back = preg_replace("/^[^,]+,/","",$base);
518       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
519         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
520       }
522       /* Get all departments */
523       while($value = $ldap->fetch()){
524         if(isset($value["description"][0])){
525           $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
526         }else{
527           $this->departments[$value['dn']]=$value["description"][0];
528         }
529       }
530       /* END NEW LIST MANAGMENT
531        */
533       // Defining Links
534       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
536       /* Insert departments in divlist*/
537       foreach($this->departments as $key=> $val){
538         if(!isset($this->config->departments[trim($key)])){
539           $this->config->departments[trim($key)]="";
540         }
542         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
543         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
544         $divSel->AddEntry(array($field1,$field2));
545       }
547       /* Append Blocklits */
548       foreach($list as $entry => $value){
549         $divSel->AddEntry(array(
550               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
551               array("string"=>$value,"attach"=>"style='border:0px;'")
552               ));
553       }
555       /* Show dialog */
556       $smarty->assign("cblocklist", $this->current_blocklist);
557       $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
558       $smarty->assign("departments", $this->config->idepartments);
559       $smarty->assign("divSelectPredefined", $divSel->DrawList());
560       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
561       return ($display);
562     }
565     /* Show main page */
566     $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
567     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
568     $smarty->assign("printers", $this->printerList);
570     /* Load attributes */
571     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
572           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
573           "facsimileAlternateTelephoneNumber", "mail") as $val){
575       $smarty->assign("$val", $this->$val);
576       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
577     }
578     $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
579     $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
581     /* Load checkboxes */
582     if ($this->goFaxIsEnabled == "1"){
583       $smarty->assign("goFaxIsEnabled", "");
584     } else {
585       $smarty->assign("goFaxIsEnabled", "checked");
586     }
587     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
588     if ($this->goFaxDeliveryMode & 32) {
589       $smarty->assign("fax_to_mail", "checked");
590     } else {
591       $smarty->assign("fax_to_mail", "");
592     }
593     if ($this->goFaxDeliveryMode & 64) {
594       $smarty->assign("fax_to_printer", "checked");
595     } else {
596       $smarty->assign("fax_to_printer", "");
597     }
600     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
601     return ($display);
602   }
604   function remove_from_parent()
605   {
606     /* Cancel if there's nothing to do here */
607     if (!$this->initially_was_account){
608       return;
609     }
611     plugin::remove_from_parent();
613     /* Zero out arrays */
614     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
615           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
617       $this->attrs[$val]= array();
618     }
620     /* Adapt mail settings if needed */
621     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
622       unset($this->attrs['mail']);
623     }
625     $ldap= $this->config->get_ldap_link();
626     $ldap->cd($this->dn);
627     $this->cleanup();
628     $ldap->modify ($this->attrs); 
630     show_ldap_error($ldap->get_error(), _("Removing FAX account failed"));
632     /* Optionally execute a command after we're done */
633     $this->handle_post_events('remove',array("uid"=> $this->uid));
634   }
637   /* Check formular input */
638   function check()
639   {
640     /* Call common method to give check the hook */
641     $message= plugin::check();
643     /* must: facsimileTelephoneNumber */
644     if ($this->facsimileTelephoneNumber == ""){
645       $message[]= _("The required field 'Fax' is not set.");
646     }
648     if (!is_phone_nr($this->facsimileTelephoneNumber)){
649       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
650     }
652     /* IF mail is specified (which is only the case if there's no mail account
653        present), check if it's valid..  */
654     if (@isset($this->parent->by_object['mailAccount']) &&
655         $this->goFaxDeliveryMode && 32){
656       if ($this->mail == ""){
657         $message[]= _("Mail delivery is checked, but no address has been specified.");
658       } elseif (!is_email($this->mail)){
659         $message[]= _("The mail address you've entered is invalid.");
660       }
661     }
663     // IE Fix, IE lets you choose disabled option, stupid browser ... 
664     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
665       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
666     }
668     return ($message);
669   }
671   /* Save data to object */
672   function save_object()
673   {
674     if (isset($_POST['faxTab'])){
675       plugin::save_object();
677       /* Adapt combobox values */
678       $tmp= 0;
679       if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
680         $tmp+= 32;
681       }
682       if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
683         $tmp+= 64;
684       }
685       if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
686         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
687           $this->goFaxIsEnabled= "0";
688         } else {
689           $this->goFaxIsEnabled= "1";
690         }
691       }
693       if (isset($_POST['facsimileTelephoneNumber'])){
694         if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
695           $this->is_modified= TRUE;
696         }
697         $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
698       }
700       if (isset($_POST['mail'])){
701         if ($this->mail != $_POST['mail']){
702           $this->is_modified= TRUE;
703         }
704         $this->mail= $_POST['mail'];
705       }
707       /* Write to object */
708       if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
709         if ($tmp != $this->goFaxDeliveryMode){
710           $this->is_modified= TRUE;
711         }
712         $this->goFaxDeliveryMode= "$tmp";
713       }
715       /* Check if mail account is active and correct the internal
716          reference to represent the current status. */
717       if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
718         $this->has_mailAccount= TRUE;
719       }
720     }
722   }
725   /* Save to LDAP */
726   function save()
727   {
728     plugin::save();
730     /* Save arrays */
731     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
732           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
734       $this->attrs[$val]= $this->$val;
735     }
737     /* Adapt mail settings if needed */
738     unset($this->attrs['mail']);
739     if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
740       $this->attrs['mail']= $this->mail;
741     }
743     /* Write back to ldap */
744     $ldap= $this->config->get_ldap_link();
745     $ldap->cd($this->dn);
746     $this->cleanup();
747     $ldap->modify ($this->attrs); 
749     show_ldap_error($ldap->get_error(), _("Saving FAX account failed"));
751     /* Optionally execute a command after we're done */
752     if ($this->initially_was_account == $this->is_account){
753       if ($this->is_modified){
754         $this->handle_post_events("modify",array("uid" => $this->uid));
755       }
756     } else {
757       $this->handle_post_events("add",array("uid" => $this->uid));
758     }
760   }
763   /* Adapt from template, using 'dn' */
764   function adapt_from_template($dn)
765   {
766     plugin::adapt_from_template($dn);
768     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
769           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
771       if (isset($this->attrs[$val])){
772         $this->$val= $this->attrs[$val];
773       }
774     }
775   }
779   /* Add alternate fax recipient */
780   function addAlternate($number)
781   {
782     $this->facsimileAlternateTelephoneNumber[]= "$number";
783     $this->facsimileAlternateTelephoneNumber=
784       array_unique ($this->facsimileAlternateTelephoneNumber);
786     sort ($this->facsimileAlternateTelephoneNumber);
787     reset ($this->facsimileAlternateTelephoneNumber);
788   }
790   function delAlternate($numbers)
791   {
792     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
793         $this->facsimileAlternateTelephoneNumber);
794   }
796   function getCopyDialog()
797   {
798     $str    = "";
799     $smarty = get_smarty();
800     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
801     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
802     $str['status'] ="";
803     return($str);
804   }
806   function SaveCopyDialog()
807   {
808     if(isset($_POST['facsimileTelephoneNumber'])){
809       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
810     }
811   }
815 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
816 ?>