Code

Part 2 trunk update
[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   /* Copy & paste variables */
42   var $CopyPasteVars=array("facsimileTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
44   /* attribute list for save action */
45   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber",
46       "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
48   var $uid ="";
50   var $objectclasses= array("goFaxAccount");
52   function gofaxAccount ($config, $dn= NULL)
53   {
54     /* General initialization */
55     plugin::plugin ($config, $dn);
57     /* Set uid, it is used in handle_post_events */
58     if(isset($this->attrs['uid'])){
59       $this->uid = $this->attrs['uid'][0];
60     }
62     /* Hickert : 11.11.05
63      * Added to be able to handle department selection in divSelelect
64      */
65     if(!isset($_SESSION["Fax_Filter"])){
66       $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
67     }
69     if ($dn != "new"){
70       /* Get arrays */
71       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
72             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
73         $this->$val =array();
74         if (isset($this->attrs["$val"]["count"])){
75           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
76             array_push($this->$val, $this->attrs["$val"][$i]);
77           }
78         }
79       }
81       /* Set up has_mailAccount */
82       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
83         $this->has_mailAccount= TRUE;
84       }
85     }
87     /* Load printer list */
88     if (isset($this->config->data['SERVERS']['CUPS'])){
89       $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
90       asort ($this->printerList);
91     }
93     /* Get global filter config */
94     if (!is_global("faxfilter")){
95       $ui= get_userinfo();
96       $base= get_base_from_people($ui->dn);
97       $faxfilter= array( "depselect"       => $base,
98           "fuser"            => "*",
99           "regex"           => "");
100       register_global("faxfilter", $faxfilter);
101     }
102   }
104   function execute()
105   {
106     /* Call parent execute */
107     plugin::execute();
108     /* Hickert : 11.11.05
109      * Added to be able to handle department selection in divSelelect
110      */
111     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
113       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
114         $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
115       }else{
116         $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
117       }
118     }
120     /* Edit mode specifies if we are editing from my accout */
121     $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
123     /* Load smarty stuff */
124     $smarty= get_smarty();
126     /* Check if mail account is active. We'll display an additional
127        mail address field if this is not the case. Some people may
128        want goFax, but have a mailserver which is not managed with
129        GOsa */
130     if (!@isset($this->parent->by_object['mailAccount'])) {
131       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
132     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
133       $smarty->assign("has_mailaccount", "false");
134       $this->has_mailAccount= false;
135     } else {
136       $smarty->assign("has_mailaccount", "true");
137     }
139     /* Do we need to flip is_account state? */
140     if (isset($_POST['modify_state'])){
141       $this->is_account= !$this->is_account;
142     }
144     /* Do we represent a valid account? */
145     if (!$this->is_account && $this->parent == NULL){
146       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
147         _("This account has no fax extensions.")."</b>";
148       $display.= back_to_main();
149       return ($display);
150     }
152     /* Show tab dialog headers */
153     $display= "";
154     if ($this->parent != NULL){
155       if ($this->is_account){
156         $display= $this->show_disable_header(_("Remove fax account"),
157             _("This account has fax features enabled. You can disable them by clicking below."));
158       } else {
159         $display= $this->show_enable_header(_("Create fax account"),
160             _("This account has fax features disabled. You can enable them by clicking below."));
161         return ($display);
162       }
163     }
165     /* Trigger Add local fax alternatives dialog */
166     if (isset($_POST['add_local_alternate'])){
167       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
168         $this->locals_dialog= TRUE;     
169         $this->dialog= TRUE;    
170       }
171     }
173     /* Add alternatives from dialog */
174     if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
175       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
176         foreach ($_POST['local_list'] as $val){
177           $this->addAlternate($val);
178           $this->is_modified= TRUE;
179         }
180       }
181     }
183     /* Add alternatives */
184     if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){ 
185       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
186         $this->addAlternate($_POST['forward_address']);
187       }
188     }
190     /* Delete alternate fax number */
191     if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
192       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
193         $this->delAlternate ($_POST['alternate_list']);
194       }
195     }
198     /* Edit incoming blocklists */
199     if (isset($_POST['edit_incoming'])){
200       if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode))  {
201         $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
202         sort($this->current_blocklist);
203         reset($this->current_blocklist);
205         $this->in_blocklist_dialog= TRUE;
206         $this->dialog= TRUE;
207       }
208     }
210     /* Edit outgoing blocklists */
211     if (isset($_POST['edit_outgoing'])){
212       $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
213       sort($this->current_blocklist);
214       reset($this->current_blocklist);
216       $this->out_blocklist_dialog= TRUE;
217       $this->dialog= TRUE;
218     }
220     /* Add number to blocklist (dialog) */
221     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
222       if (!is_phone_nr($_POST['block_number'])){
223         print_red (_("You're trying to add an invalid phone number."));
224       } else {
225         array_push($this->current_blocklist, $_POST['block_number']);
226         $this->current_blocklist= array_unique($this->current_blocklist);
227         sort($this->current_blocklist);
228         reset($this->current_blocklist);
229       }
230     }
232     /* Hickert : 11.11.05
233      * Add selection from divSelelect to our Blocklist 
234      */
235     /* Add list to blocklist */
236     if (isset($_POST['add_blocklist'])){
237       foreach($_POST as $name => $value){
238         if(preg_match("/ADDLIST_/i",$name)){
239           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
241         }
242       } 
243       $this->current_blocklist= array_unique($this->current_blocklist);
244       sort($this->current_blocklist);
245       reset($this->current_blocklist);
246     }
248     /* Add list to blocklist */
249     if (isset($_GET['add'])){
250       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
251       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
252       $this->current_blocklist= array_unique($this->current_blocklist);
253       sort($this->current_blocklist);
254       reset($this->current_blocklist);
255     }
257     /* Delete from blocklist */
258     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
259       $tmp= array();
260       foreach($this->current_blocklist as $val){
261         if (!in_array($val, $_POST['block_list'])){
262           $tmp[]= $val;
263         }
264       }
265       $this->current_blocklist= $tmp;
266     }
269     /* Blocklist edit finished */
270     if (isset($_POST['edit_blocklists_finish'])){
272       /* Incoming or outgoing? */
273       if ($this->in_blocklist_dialog){
274         $this->goFaxRBlocklist = array();
275         $this->goFaxRBlockgroups = array();
277         foreach ($this->current_blocklist as $val){
278           if (is_phone_nr($val)){
279             $this->goFaxRBlocklist[]=$val;
280           } else {
281             $this->goFaxRBlockgroups[]= $val;
282           }
283         }
284       } else {
285         $this->goFaxSBlocklist = array();
286         $this->goFaxSBlockgroups = array();
288         /* Transfer values to ourself */
289         foreach ($this->current_blocklist as $val){
290           if (is_phone_nr($val)){
291             $this->goFaxSBlocklist[]=$val;
292           } else {
293             $this->goFaxSBlockgroups[]= $val;
294           }
295         }
296       }
297       $this->is_modified= TRUE;
298     }
301     /* Set departments */
302     if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
303       
304       $list= array ();
305       $ldap= $this->config->get_ldap_link();
306       if (isset ($_POST['department'])){
307         $ldap->cd ($_POST['department']);
308       } else {
309         $ldap->cd ($this->config->current['BASE']);
310       }
311     }
313     /* Cancel  dialogs */
314     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
315         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
317       $this->locals_dialog= FALSE;
318       $this->in_blocklist_dialog= FALSE;
319       $this->out_blocklist_dialog= FALSE;
320       $this->dialog= FALSE;
321     }
323     /* Manage locals dialog */
324     if ($this->locals_dialog){
326       /* Save data */
327       $faxfilter= get_global("faxfilter");
328       foreach( array("depselect", "fuser", "regex") as $type){
329         if (isset($_POST[$type])){
330           $faxfilter[$type]= $_POST[$type];
331         }
332       }
333       if (isset($_GET['search'])){
334         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
335         if ($s == "**"){
336           $s= "*";
337         }
338         $faxfilter['fuser']= $s;
339       }
341       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
342         $regex= $faxfilter['regex'];
343         $filter= "(facimileTelephoneNumber=$regex)";
344       } else {
345         $filter= "";
346       }
347       if ($faxfilter['fuser'] != ""){
348         $user= $faxfilter['fuser'];
349         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
350       }
352       $base= $faxfilter['depselect'];
353       $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base, 
354                      array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
356       foreach ($res as $attrs){
357         $list[$attrs['facsimileTelephoneNumber'][0]]=
358           $attrs['sn'][0].", ".
359           $attrs['givenName'][0]." [".
360           $attrs['facsimileTelephoneNumber'][0]."]";
361       }
363       /* Show dialog */
364       $smarty->assign("search_image", get_template_path('images/search.png'));
365       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
366       $smarty->assign("tree_image", get_template_path('images/tree.png'));
367       $smarty->assign("infoimage", get_template_path('images/info.png'));
368       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
369       $smarty->assign("departments", $this->config->idepartments);
370       $smarty->assign("list", $list);
371       if (isset($_POST['depselect'])){
372         $smarty->assign("depselect", $_POST['depselect']);
373       }
374       $smarty->assign("deplist", $this->config->idepartments);
375       $smarty->assign("apply", apply_filter());
376       $smarty->assign("alphabet", generate_alphabet());
377       $smarty->assign("hint", print_sizelimit_warning());
378       foreach( array("depselect", "fuser", "regex") as $type){
379         $smarty->assign("$type", $faxfilter[$type]);
380       }
381       $smarty->assign("hint", print_sizelimit_warning());
383       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
384       return ($display);
385     }
388     /* Manage incoming blocklists */
389     if ($this->in_blocklist_dialog){
391       /* This handles the divSelectBox */
393       /* The base specifies the current position in the ldap tree 
394        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
395        */
396       $base = $_SESSION['Fax_Filter']['depselect'];
397       $ldap->cd($base);
399       /* Ge all Blocklists */
400       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
401       while ($attrs= $ldap->fetch()){
403         /* Generate list depending on description */
404         if(isset($attrs['description'][0])){
405           $list[$attrs['cn'][0]]=
406             $attrs['description'][0].
407             " [".$attrs['cn'][0]."]";
408         }else{
409           $list[$attrs['cn'][0]]= $attrs['cn'][0];
410         }
411       }
413       /* Create our divselect box */
414       $divSel = new divSelectBox("divSelectPredefined");
415       $divSel->setHeight(296);
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']]=@LDAP::fix(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("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']]=@LDAP::fix(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("departments", $this->config->idepartments);
552       $smarty->assign("divSelectPredefined", $divSel->DrawList());
553       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
554       return ($display);
555     }
558     /* Show main page */
559     $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
560     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
561     $smarty->assign("printers", $this->printerList);
563     /* Load attributes */
564     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
565           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
566           "facsimileAlternateTelephoneNumber", "mail") as $val){
568       $smarty->assign("$val", $this->$val);
569     }
571     $tmp = $this->plInfo();
572     foreach($tmp['plProvidedAcls'] as $acl => $desc){
573       $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
574     }
576     /* Load checkboxes */
577     if ($this->goFaxIsEnabled == "1"){
578       $smarty->assign("goFaxIsEnabled", "");
579     } else {
580       $smarty->assign("goFaxIsEnabled", "checked");
581     }
582     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
583     if ($this->goFaxDeliveryMode & 32) {
584       $smarty->assign("faxtomail", "checked");
585     } else {
586       $smarty->assign("faxtomail", "");
587     }
588     if ($this->goFaxDeliveryMode & 64) {
589       $smarty->assign("faxtoprinter", "checked");
590     } else {
591       $smarty->assign("faxtoprinter", "");
592     }
595     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
596     return ($display);
597   }
599   function remove_from_parent()
600   {
601     /* Cancel if there's nothing to do here */
602     if (!$this->initially_was_account){
603       return;
604     }
606     plugin::remove_from_parent();
608     /* Zero out arrays */
609     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
610           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
612       $this->attrs[$val]= array();
613     }
615     /* Adapt mail settings if needed */
616     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
617       unset($this->attrs['mail']);
618     }
620     $ldap= $this->config->get_ldap_link();
621     $ldap->cd($this->dn);
622     $this->cleanup();
623     $ldap->modify ($this->attrs); 
625     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
627     /* Optionally execute a command after we're done */
628     $this->handle_post_events('remove',array("uid"=> $this->uid));
629   }
632   /* Check formular input */
633   function check()
634   {
635     /* Call common method to give check the hook */
636     $message= plugin::check();
638     /* must: facsimileTelephoneNumber */
639     if ($this->facsimileTelephoneNumber == ""){
640       $message[]= _("The required field 'Fax' is not set.");
641     }
643     if (!is_phone_nr($this->facsimileTelephoneNumber)){
644       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
645     }
647     /* IF mail is specified (which is only the case if there's no mail account
648        present), check if it's valid..  */
649     if (@isset($this->parent->by_object['mailAccount']) &&
650         $this->goFaxDeliveryMode && 32){
651       if ($this->mail == ""){
652         $message[]= _("Mail delivery is checked, but no address has been specified.");
653       } elseif (!is_email($this->mail)){
654         $message[]= _("The mail address you've entered is invalid.");
655       }
656     }
658     // IE Fix, IE lets you choose disabled option, stupid browser ... 
659     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
660       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
661     }
663     return ($message);
664   }
666   /* Save data to object */
667   function save_object()
668   {
669     $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
670     if (isset($_POST['faxTab'])){
671       plugin::save_object();
674       $tmp = 0+$this->goFaxDeliveryMode;
676       if($this->acl_is_writeable("faxtomail",$edit_mode)){
677         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
678           $tmp |= 32;
679         }elseif($tmp & 32){
680           $tmp &= (!32);
681         }
682       }
683       if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
684         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
685           $tmp |= 64;
686         }elseif($tmp & 64){
687           $tmp &= !64;
688         }
689       }
690       $this->goFaxDeliveryMode = $tmp;
692       if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
693         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
694           $this->goFaxIsEnabled= "0";
695         } else {
696           $this->goFaxIsEnabled= "1";
697         }
698       }
700     
701       if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
702         $this->mail= $_POST['mail'];
703       }
705       /* Check if mail account is active and correct the internal
706          reference to represent the current status. */
707       if(isset($this->parent)){
708         if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
709           $this->has_mailAccount= TRUE;
710         }
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     if(!$this->attrs['goFaxDeliveryMode']){
730       $this->attrs['goFaxDeliveryMode'] = 0;
731     }
732   
733     /* Do not save mail address ... it was possibly changed by mail plugin*/
734     unset($this->attrs['mail']);
736     /* Write back to ldap */
737     $ldap= $this->config->get_ldap_link();
738     $ldap->cd($this->dn);
739     $this->cleanup();
740     $ldap->modify ($this->attrs); 
742     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
744     /* Optionally execute a command after we're done */
745     if ($this->initially_was_account == $this->is_account){
746       if ($this->is_modified){
747         $this->handle_post_events("mofidy",array("uid" => $this->uid));
748       }
749     } else {
750       $this->handle_post_events("add",array("uid" => $this->uid));
751     }
753   }
756   /* Adapt from template, using 'dn' */
757   function adapt_from_template($dn)
758   {
759     plugin::adapt_from_template($dn);
761     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
762           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
764       if (isset($this->attrs[$val])){
765         $this->$val= $this->attrs[$val];
766       }
767     }
768   }
772   /* Add alternate fax recipient */
773   function addAlternate($number)
774   {
775     $this->facsimileAlternateTelephoneNumber[]= "$number";
776     $this->facsimileAlternateTelephoneNumber=
777       array_unique ($this->facsimileAlternateTelephoneNumber);
779     sort ($this->facsimileAlternateTelephoneNumber);
780     reset ($this->facsimileAlternateTelephoneNumber);
781   }
783   function delAlternate($numbers)
784   {
785     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
786         $this->facsimileAlternateTelephoneNumber);
787   }
789   function getCopyDialog()
790   {
791     $str    = "";
792     $smarty = get_smarty();
793     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
794     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
795     $str['status'] ="";
796     return($str);
797   }
799   function SaveCopyDialog()
800   {
801     if(isset($_POST['facsimileTelephoneNumber'])){
802       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
803     }
804   }
807   /* Return plugin informations for acl handling 
808       #FIXME some attributes are still missing in this plugin acls */
809   function plInfo()
810   {
811     return (array(  
812           "plShortName"     => _("Fax"),
813           "plDescription"   => _("Fax account settings"),
814           "plSelfModify"    => TRUE,
815           "plDepends"       => array("user"),
816           "plPriority"      => 6,             
817           "plSection"       => "personal",  
818           "plCategory"      => array("users"),
819           "plOptions"       => array(),
821           "plProvidedAcls"  => array(
822             "goFaxIsEnabled"                    => _("Enable/Disable fax"),
823             "goFaxRBlocklist"                   => _("Receive blocklist"),
824             "goFaxSBlocklist"                   => _("Send blocklist"),
825             "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
826             "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
827             "faxtomail"                         => _("Deliver fax as mail"),
828             "faxtoprinter"                      => _("Deliver fax to printer"),
829             "goFaxFormat"                       => _("Delivery format"),
830             "goFaxLanguage"                     => _("Language"))
831           ));
832   }
835 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
836 ?>