Code

Replaced in_array calls with in_array_strict
[gosa.git] / gosa-plugins / gofax / gofax / faxaccount / class_gofaxAccount.inc
1 <?php
3 class gofaxAccount extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "FAX";
7   var $plDescription= "Manage personal facsimile settings";
8   var $plIcon = "plugins/gofax/images/plugin.png";
10   var $departments;
12   /* Fax attributes */
13   var $goFaxDeliveryMode= "";
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();
26   var $fax_formats = array("pdf","ps","png","mtiff","tiff");  
28   /* Internal variables */
29   var $printerList= array();
30   var $has_mailAccount= FALSE;
31   var $faxNumberSelect= FALSE;
32   var $in_blocklist_dialog= FALSE;
33   var $out_blocklist_dialog= FALSE;
34   var $current_blocklist= array();
35   var $view_logged = FALSE;
37   /* Copy & paste variables */
38   var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
40   /* attribute list for save action */
41   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
43   var $uid ="";
45   var $objectclasses= array("goFaxAccount");
47   /* Enable multiple edit support */
48   var $multiple_support = TRUE;
50   function gofaxAccount (&$config, $dn= NULL)
51   {
52     /* General initialization */
53     plugin::plugin ($config, $dn);
55     /* Set uid, it is used in handle_post_events */
56     if(isset($this->attrs['uid'])){
57       $this->uid = $this->attrs['uid'][0];
58     }
60     /* Hickert : 11.11.05
61      */
62     if(!session::is_set("Fax_Filter")){
63       $Fax_Filter = array();
64       $Fax_Filter['depselect'] = $this->config->current['BASE'];
65       session::set('Fax_Filter',$Fax_Filter);
66     }
68     if ($dn != "new"){
69       /* Get arrays */
70       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
71             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
72         $this->$val =array();
73         if (isset($this->attrs["$val"]["count"])){
74           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
75             array_push($this->$val, $this->attrs["$val"][$i]);
76           }
77         }
78       }
80       /* Set up has_mailAccount */
81       if (in_array_strict("gosaMailAccount", $this->attrs['objectClass'])){
82         $this->has_mailAccount= TRUE;
83       }
84     }
86     /* Load printer list */
87     $this->printerList=get_printer_list();
89     /* Check if the currently selected printer is still available. 
90        If not, append current printer to list of available.
91        It could be possible, that we are not allowed to view printers and so the list is empty ...  */
92     if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
93       $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
94     }
96     // Prepare lists
97     $this->predefinedList = new sortableListing();
98     $this->predefinedList->setDeleteable(false);
99     $this->predefinedList->setEditable(false);
100     $this->predefinedList->setWidth("100%");
101     $this->predefinedList->setHeight("300px");
102     $this->predefinedList->setColspecs(array('20px','*'));
103     $this->predefinedList->setHeader(array("~",_("Name")));
104     $this->predefinedList->setDefaultSortColumn(1);
105   }
107   function execute()
108   {
109     /* Call parent execute */
110     plugin::execute();
112     /* Log view */
113     if($this->is_account && !$this->view_logged){
114       $this->view_logged = TRUE;
115       new log("view","users/".get_class($this),$this->dn);
116     }
118     /* Department selection handling
119      */
120     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
121       $Fax_Filter = session::get('Fax_Filter');
122       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
123         $Fax_Filter['depselect']= base64_decode($_GET['dep_id']);
124       }else{
125         $Fax_Filter['depselect']= $this->config->current['BASE'];
126       }
127       session::set('Fax_Filter',$Fax_Filter);
128     }
130     /* Edit mode specifies if we are editing from my accout */
131     $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
133     /* Load smarty stuff */
134     $smarty= get_smarty();
136     /* Check if mail account is active. We'll display an additional
137        mail address field if this is not the case. Some people may
138        want goFax, but have a mailserver which is not managed with
139        GOsa */
140     if (!@isset($this->parent->by_object['mailAccount'])) {
141       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
142     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
143       $smarty->assign("has_mailaccount", "false");
144       $this->has_mailAccount= false;
145     } else {
146       $smarty->assign("has_mailaccount", "true");
147     }
150     $display = "";
151     if(!$this->multiple_support_active){    
153       /* Do we need to flip is_account state? */
154       if (isset($_POST['modify_state'])){
155         $this->is_account= !$this->is_account;
156       }
158       /* Do we represent a valid account? */
159       if (!$this->is_account && $this->parent === NULL){
160         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
161           msgPool::noValidExtension(_("GOfax"))."</b>";
162         $display.= back_to_main();
163         return ($display);
164       }
166       /* Show tab dialog headers */
167       $display= "";
168       if ($this->parent !== NULL){
169         if ($this->is_account){
170           $display= $this->show_disable_header(_("Remove FAX account"),
171               msgPool::featuresEnabled(_("GOfax")));
172         } else {
173           $display= $this->show_enable_header(_("Create FAX account"),
174               msgPool::featuresDisabled(_("GOfax")));
175           return ($display);
176         }
177       }
178     }
180     /* Trigger Add local fax alternatives dialog */
181     if (isset($_POST['add_local_alternate'])){
182       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
183         $this->faxNumberSelect = new faxNumberSelect($this->config, get_userinfo());
184         $this->dialog= TRUE;    
185       }
186     }
188     if (isset($_POST['faxNumberSelect_cancel']) && $this->faxNumberSelect instanceOf faxNumberSelect){
189       $this->dialog = $this->faxNumberSelect = FALSE;
190     }
192     /* Add alternatives from dialog */
193     if (isset($_POST['faxNumberSelect_save']) && $this->faxNumberSelect instanceOf faxNumberSelect){
194       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
196         $entries = $this->faxNumberSelect->save();
197         foreach ($entries as $entry){
198           $this->addAlternate($entry['facsimileTelephoneNumber'][0]);
199           $this->is_modified= TRUE;
200         }
201       }
202       $this->dialog = $this->faxNumberSelect = FALSE;
203     }
205     if ($this->faxNumberSelect){
207       // Build up blocklist
208       $list = $this->facsimileAlternateTelephoneNumber;
209       $list[] = $this->facsimileTelephoneNumber;
210       session::set('filterBlacklist', array('facsimileTelephoneNumber' => $list));
211       return($this->faxNumberSelect->execute());
212     }
214     /* Add alternatives */
215     if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && tests::is_phone_nr($_POST['forward_address'])){ 
216       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
217         $this->addAlternate($_POST['forward_address']);
218       }
219     }
221     /* Delete alternate fax number */
222     if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
223       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
224         $this->delAlternate ($_POST['alternate_list']);
225       }
226     }
229     /* Edit incoming blocklists */
230     if (isset($_POST['edit_incoming'])){
231       if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode))  {
232         $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
233         sort($this->current_blocklist);
234         reset($this->current_blocklist);
236         $this->in_blocklist_dialog= TRUE;
237         $this->dialog= TRUE;
238       }
239     }
241     /* Edit outgoing blocklists */
242     if (isset($_POST['edit_outgoing'])){
243       $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
244       sort($this->current_blocklist);
245       reset($this->current_blocklist);
247       $this->out_blocklist_dialog= TRUE;
248       $this->dialog= TRUE;
249     }
251     /* Add number to blocklist (dialog) */
252     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
253       if (!tests::is_phone_nr($_POST['block_number'])){
254         msg_dialog::display(_("Error"), msgPool::invalid(_("Phone number")), ERROR_DIALOG);
255       } else {
256         array_push($this->current_blocklist, $_POST['block_number']);
257         $this->current_blocklist= array_unique($this->current_blocklist);
258         sort($this->current_blocklist);
259         reset($this->current_blocklist);
260       }
261     }
263     /* Add list to blocklist */
264     if (isset($_POST['add_blocklist'])){
265       foreach($_POST as $name => $value){
266         if(preg_match("/ADDLIST_/i",$name)){
267           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
269         }
270       } 
271       $this->current_blocklist= array_unique($this->current_blocklist);
272       sort($this->current_blocklist);
273       reset($this->current_blocklist);
274     }
276     /* Add list to blocklist */
277     if (isset($_GET['add'])){
278       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
279       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
280       $this->current_blocklist= array_unique($this->current_blocklist);
281       sort($this->current_blocklist);
282       reset($this->current_blocklist);
283     }
285     /* Delete from blocklist */
286     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
287       $tmp= array();
288       foreach($this->current_blocklist as $val){
289         if (!in_array_strict($val, $_POST['block_list'])){
290           $tmp[]= $val;
291         }
292       }
293       $this->current_blocklist= $tmp;
294     }
297     /* Blocklist edit finished */
298     if (isset($_POST['edit_blocklists_finish'])){
300       /* Incoming or outgoing? */
301       if ($this->in_blocklist_dialog){
302         $this->goFaxRBlocklist = array();
303         $this->goFaxRBlockgroups = array();
305         foreach ($this->current_blocklist as $val){
306           if (tests::is_phone_nr($val)){
307             $this->goFaxRBlocklist[]=$val;
308           } else {
309             $this->goFaxRBlockgroups[]= $val;
310           }
311         }
312       } else {
313         $this->goFaxSBlocklist = array();
314         $this->goFaxSBlockgroups = array();
316         /* Transfer values to ourself */
317         foreach ($this->current_blocklist as $val){
318           if (tests::is_phone_nr($val)){
319             $this->goFaxSBlocklist[]=$val;
320           } else {
321             $this->goFaxSBlockgroups[]= $val;
322           }
323         }
324       }
325       $this->is_modified= TRUE;
326     }
329     /* Set departments */
330     if ( $this->in_blocklist_dialog || $this->out_blocklist_dialog){
331       
332       $list= array ();
333       $ldap= $this->config->get_ldap_link();
334       if (isset ($_POST['department'])){
335         $ldap->cd ($_POST['department']);
336       } else {
337         $ldap->cd ($this->config->current['BASE']);
338       }
339     }
341     /* Cancel  dialogs */
342     if (isset($_POST['edit_blocklists_finish']) || isset($_POST['edit_blocklists_cancel'])){
343       $this->in_blocklist_dialog= FALSE;
344       $this->out_blocklist_dialog= FALSE;
345       $this->dialog= FALSE;
346     }
348     /* Manage locals dialog */
349     if ($this->faxNumberSelect){
350       return($this->faxNumberSelect->execute());
351     }
354     /* Manage incoming blocklists */
355     if ($this->in_blocklist_dialog){
357       /* The base specifies the current position in the ldap tree 
358        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
359        */
360       $Fax_Filter = session::get('Fax_Filter');
361       $base = $Fax_Filter['depselect'];
362       $ldap->cd($base);
364       /* Ge all Blocklists */
365       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
366       while ($attrs= $ldap->fetch()){
368         /* Generate list depending on description */
369         if(isset($attrs['description'][0])){
370           $list[$attrs['cn'][0]]=
371             $attrs['description'][0].
372             " [".$attrs['cn'][0]."]";
373         }else{
374           $list[$attrs['cn'][0]]= $attrs['cn'][0];
375         }
376       }
378       /* NEW LIST MANAGMENT
379        * We also need to search for the departments
380        * So we are able to navigate like in konquerer
381        */
382       $this->departments= array();
383    
384       /* Get all departments within the current department */ 
385       $Fax_Filter = session::get('Fax_Filter');
386       $base = $Fax_Filter['depselect'];
387       $ldap->ls("(objectClass=gosaDepartment)",$base);
389       /* Base back is used to go one department up in our ldap tree */
390       $base_back = preg_replace("/^[^,]+,/","",$base);
392       /* Only show base_back if it is needed */
393       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
394         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
395       }
397       /* Fetch all returned departments an add them to our listing */
398       while($value = $ldap->fetch()){
399         if($value["description"][0]!=".."){
400           $this->departments[$value['dn']]=LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
401         }else{
402           $this->departments[$value['dn']]=$value["description"][0];
403         }
404       }
405       /* END NEW LIST MANAGMENT
406        */
408       // This links specifies the department open link 
409       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
411       /* Insert departments in divsel */
412         $data = $lData = array();
413       foreach($this->departments as $key=> $val){
414         if(!isset($this->config->departments[trim($key)])){
415           $this->config->departments[trim($key)]="";
416         }
417         $img = image('images/lists/folder.png');
418         $val = sprintf( $linkopen, postEncode($key), $val);
419         $data[] = array('TYPE' => 'DEP', 'ID' => $key);
420         $lData[] = array('data' => array($img,$val));
421       }
424       /* Append predefined Blocklists */
425       foreach($list as $entry => $value){
426           $chk = "<input type='checkbox' value='".base64_encode($entry)."' 
427               name='ADDLIST_".base64_encode($entry)."'>";
428           $data[] = array('TYPE' => 'ENTRY', 'ID' => $key);
429           $lData[] = array('data' => array($chk,$value));
430       }
432       $this->predefinedList->setAcl('rwcdm');
433       $this->predefinedList->setListData($data,$lData);
434       $this->predefinedList->update();
437       /* Show dialog */
438       $smarty->assign("cblocklist", set_post($this->current_blocklist));
439       $smarty->assign("predefinedList", $this->predefinedList->render());
440       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
441       return ($display);
442     }
444     /* Manage outgoing blocklists */
446     if ($this->out_blocklist_dialog){
448       /* The base specifies the current position in the ldap tree
449        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
450        */
451       $Fax_Filter = session::get('Fax_Filter');
452       $base = $Fax_Filter['depselect'];
453       $ldap->cd($base);
455       /* Ge all Blocklists */ 
456       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
457       while ($attrs= $ldap->fetch()){
458         if(isset($attrs['description'][0])){
459           $list[$attrs['cn'][0]]=
460             $attrs['description'][0].
461             " [".$attrs['cn'][0]."]";
462         }else{
463           $list[$attrs['cn'][0]]= $attrs['cn'][0];
464         }
465       }
467       /* NEW LIST MANAGMENT
468        * We also need to search for the departments
469        * So we are able to navigate like in konquerer
470        */
471       $this->departments= array();
472       $ldap->ls("(objectClass=gosaDepartment)",$base);
474       /* Generate Back url, and append if it is needed */
475       $base_back = preg_replace("/^[^,]+,/","",$base);
476       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
477         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
478       }
480       /* Get all departments */
481       while($value = $ldap->fetch()){
482         if(isset($value["description"][0])){
483           $this->departments[$value['dn']]=LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
484         }else{
485           $this->departments[$value['dn']]=$value["description"][0];
486         }
487       }
488       /* END NEW LIST MANAGMENT
489        */
491       /* Insert departments in divsel */
492       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
493       $data = $lData = array();
494       foreach($this->departments as $key=> $val){
495         if(!isset($this->config->departments[trim($key)])){
496           $this->config->departments[trim($key)]="";
497         }
498         $img = image('images/lists/folder.png');
499         $val = sprintf( $linkopen, postEncode($key), $val);
500         $data[] = array('TYPE' => 'DEP', 'ID' => $key);
501         $lData[] = array('data' => array($img,$val));
502       }
505       /* Append predefined Blocklists */
506       foreach($list as $entry => $value){
507           $chk = "<input type='checkbox' value='".base64_encode($entry)."' 
508               name='ADDLIST_".base64_encode($entry)."'>";
509           $data[] = array('TYPE' => 'ENTRY', 'ID' => $key);
510           $lData[] = array('data' => array($chk,$value));
511       }
513       $this->predefinedList->setAcl('rwcdm');
514       $this->predefinedList->setListData($data,$lData);
515       $this->predefinedList->update();
517       /* Show dialog */
518       $smarty->assign("cblocklist", set_post($this->current_blocklist));
519       $smarty->assign("predefinedList", $this->predefinedList->render());
520       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
521       return ($display);
522     }
525     /* Show main page */
526     $smarty->assign("languages", get_languages(TRUE));
527     $smarty->assign("formats",  set_post($this->fax_formats));
528     $smarty->assign("printers", set_post($this->printerList));
530     /* Load attributes */
531     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
532           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
533           "facsimileAlternateTelephoneNumber", "mail") as $val){
535       $smarty->assign("$val", set_post($this->$val));
536     }
538     $tmp = $this->plInfo();
539     foreach($tmp['plProvidedAcls'] as $acl => $desc){
540       $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
541     }
543     /* Load checkboxes */
544     if ($this->goFaxIsEnabled == "1"){
545       $smarty->assign("goFaxIsEnabled", "");
546     } else {
547       $smarty->assign("goFaxIsEnabled", "checked");
548     }
549     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
550     if ($this->goFaxDeliveryMode & 32) {
551       $smarty->assign("faxtomail", "checked");
552     } else {
553       $smarty->assign("faxtomail", "");
554     }
555     if ($this->goFaxDeliveryMode & 64) {
556       $smarty->assign("faxtoprinter", "checked");
557     } else {
558       $smarty->assign("faxtoprinter", "");
559     }
561     foreach($this->attributes as $attr){
562       if(in_array_strict($attr,$this->multi_boxes)) {
563         $smarty->assign("use_".$attr,TRUE);
564       }else{
565         $smarty->assign("use_".$attr,FALSE);
566       }
567     }
568     foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
569       if(in_array_strict($attr,$this->multi_boxes)) {
570         $smarty->assign("use_".$attr,TRUE);
571       }else{
572         $smarty->assign("use_".$attr,FALSE);
573       }
574     }
575   
576     $smarty->assign("multiple_support",$this->multiple_support_active);
577     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
578     return ($display);
579   }
581   function remove_from_parent()
582   {
583     /* Cancel if there's nothing to do here */
584     if (!$this->initially_was_account){
585       return;
586     }
588     plugin::remove_from_parent();
590     /* Adapt mail settings if needed */
591     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
592       unset($this->attrs['mail']);
593     }
595     $ldap= $this->config->get_ldap_link();
596     $ldap->cd($this->dn);
597     $this->cleanup();
598     $ldap->modify ($this->attrs); 
600     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
602     if (!$ldap->success()){
603       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
604     }
606     /* Optionally execute a command after we're done */
607     $this->handle_post_events('remove',array("uid"=> $this->uid));
608   }
611   /* Check formular input */
612   function check()
613   {
614     /* Call common method to give check the hook */
615     $message= plugin::check();
617     /* must: facsimileTelephoneNumber */
618     if ($this->facsimileTelephoneNumber == ""){
619       $message[]= msgPool::required(_("Fax number"));
620     }
622     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
623       $message[]= msgPool::invalid(_("Fax number"),$this->facsimileTelephoneNumber,"/[0-9]/");
624     }
626     // check for a valid Mail-Address in case of 'delivery to mailbox'
627     $mailAccount = (isset($this->parent->by_object['mailAccount']) && $this->parent->by_object['mailAccount']->is_account);
628     if(!$mailAccount && $this->goFaxDeliveryMode & 32){
629       if ($this->mail == ""){
630         $message[]= _("Mail delivery is requested without target address!");
631       } elseif (!tests::is_email($this->mail)){
632         $message[]= msgPool::invalid(_("Mail address"),"","",_("your-name@your-domain.com"));
633       }
634     }
636     // IE Fix, IE lets you choose disabled option, stupid browser ... 
637     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
638       $message[]= _("Printing is requested without a target printer!");
639     }
641     return ($message);
642   }
644   /* Save data to object */
645   function save_object()
646   {
647     $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
648     if (isset($_POST['faxTab'])){
649       plugin::save_object();
652       $tmp = 0+$this->goFaxDeliveryMode;
654       if($this->acl_is_writeable("faxtomail",$edit_mode)){
655         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
656           $tmp |= 32;
657         }elseif($tmp & 32){
658           $tmp &= (!32);
659         }
660       }
661       if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
662         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
663           $tmp |= 64;
664         }elseif($tmp & 64){
665           $tmp &= !64;
666         }
667         if(isset($_POST['goFaxPrinterSelected'])){
668           $this->goFaxPrinter =get_post('goFaxPrinterSelected');
669         }
670       }
671       $this->goFaxDeliveryMode = $tmp;
673       if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
674         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
675           $this->goFaxIsEnabled= "0";
676         } else {
677           $this->goFaxIsEnabled= "1";
678         }
679       }
681     
682       if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
683         $this->mail= get_post('mail');
684       }
686       /* Check if mail account is active and correct the internal
687          reference to represent the current status. */
688       if(isset($this->parent)){
689         if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
690           $this->has_mailAccount= TRUE;
691         }
692       }
693     }
695   }
698   /* Save to LDAP */
699   function save()
700   {
701     plugin::save();
703     /* Save arrays */
704     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
705           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
707       $this->attrs[$val]= $this->$val;
708     }
710     if(!$this->attrs['goFaxDeliveryMode']){
711       $this->attrs['goFaxDeliveryMode'] = 0;
712     }
713   
714     /* Do not save mail address ... it was possibly changed by mail plugin */
715     /* Adapt mail settings if needed */
716     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
717       unset($this->attrs['mail']);
718     }
720     /* Write back to ldap */
721     $ldap= $this->config->get_ldap_link();
722     $ldap->cd($this->dn);
723     $this->cleanup();
724     $ldap->modify ($this->attrs); 
726     /* Log last action */
727     if($this->initially_was_account){
728       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
729     }else{
730       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
731     }
733     if (!$ldap->success()){
734       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
735     }
737     /* Optionally execute a command after we're done */
738     if ($this->initially_was_account == $this->is_account){
739       if ($this->is_modified){
740         $this->handle_post_events("modify",array("uid" => $this->uid));
741       }
742     } else {
743       $this->handle_post_events("add",array("uid" => $this->uid));
744     }
746   }
749   /* Adapt from template, using 'dn' */
750   function adapt_from_template($dn, $skip= array())
751   {
752     plugin::adapt_from_template($dn, $skip);
754     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
755           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
757       if (in_array_strict($val, $skip)){
758         continue;
759       }
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   }
786   function getCopyDialog()
787   {
788     $str    = "";
789     $smarty = get_smarty();
790     $smarty->assign("facsimileTelephoneNumber", set_post($this->facsimileTelephoneNumber));
791     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
792     $str['status'] ="";
793     return($str);
794   }
796   function SaveCopyDialog()
797   {
798     if(isset($_POST['facsimileTelephoneNumber'])){
799       $this->facsimileTelephoneNumber = get_post('facsimileTelephoneNumber');
800     }
801   }
804   /* Return plugin informations for acl handling 
805       #FIXME some attributes are still missing in this plugin acls */
806   static function plInfo()
807   {
808     return (array(  
809           "plShortName"     => _("Fax"),
810           "plDescription"   => _("Fax account settings"),
811           "plSelfModify"    => TRUE,
812           "plDepends"       => array("user"),
813           "plPriority"      => 6,             
814           "plSection"       => "personal",  
815           "plCategory"      => array("users"),
816           "plRequirements"=> array(
817               'ldapSchema' => array('goFaxAccount' => '>=1.0.4'),
818               'onFailureDisablePlugin' => array(get_class(),'gofaxAccount','goFaxServer')
819               ),
820           "plOptions"       => array(),
822           "plProvidedAcls"  => array(
823             "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
824             "goFaxLanguage"                     => _("Language"),
825             "goFaxFormat"                       => _("Delivery format"),
826             "facsimileAlternateTelephoneNumber" => _("Alternate FAX number"), // goFaxDeliveryMode
827             "goFaxIsEnabled"                    => _("Enable/Disable FAX"),
828             "faxtomail"                         => _("Deliver FAX as mail"),
829             "faxtoprinter"                      => _("Deliver FAX to printer"),
830             "goFaxRBlocklist"                   => _("Receive blacklist"),
831             "goFaxSBlocklist"                   => _("Send blacklist"))
832           ));
833   }
835   /* Multiple edit support 
836    */
837   
838   /* Execute */
839   function multiple_execute()
840   {
841     return($this->execute());
842   }
844   function multiple_save_object()
845   {
846     if (isset($_POST['faxTab'])){
847       plugin::multiple_save_object();
848       foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
849         if(isset($_POST["use_".$attr])){
850           $this->multi_boxes[] = $attr;
851         }
852       }
854       $tmp = 0+$this->goFaxDeliveryMode;
855       if(in_array_strict("faxtomail",$this->multi_boxes)){
856         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
857           $tmp |= 32;
858         }elseif($tmp & 32){
859           $tmp &= (!32);
860         }
861       }
862       if(in_array_strict("faxtoprinter",$this->multi_boxes)){
863         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
864           $tmp |= 64;
865         }elseif($tmp & 64){
866           $tmp &= !64;
867         }
868       }
869       $this->goFaxDeliveryMode = $tmp;
871         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
872           $this->goFaxIsEnabled= "0";
873         } else {
874           $this->goFaxIsEnabled= "1";
875         }
876       if (isset($_POST['mail']) && in_array_strict("mail",$this->multi_boxes)){
877         $this->mail= get_post('mail');
878       }
879     }
880   }
882   function get_multi_edit_values()
883   {
884     $ret = plugin::get_multi_edit_values();
885     if(in_array_strict("goFaxIsEnabled",$this->multi_boxes)){
886       $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
887     }
888     if(in_array_strict("faxtoprinter",$this->multi_boxes)){
889       $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
890     }
891     if(in_array_strict("faxtomail",$this->multi_boxes)){
892       $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
893     }
895     if(in_array_strict("edit_incoming",$this->multi_boxes)){
896       $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
897       $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
898     }
899     if(in_array_strict("edit_outgoing",$this->multi_boxes)){
900       $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
901       $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
902     }
903     return($ret);
904   }
906   function multiple_check()
907   {
908     $message = plugin::multiple_check();
909     return($message);
910   }
912   function set_multi_edit_values($values)
913   {
914     plugin::set_multi_edit_values($values);
916     if(isset($values['faxtoprinter'])){
917       if($values['faxtoprinter']){
918         $this->goFaxDeliveryMode |= 64;
919       }else{
920         $this->goFaxDeliveryMode &= !64;
921       }
922     }
923     if(isset($values['faxtomail'])){
924       if($values['faxtomail']){
925         $this->goFaxDeliveryMode |= 32;
926       }else{
927         $this->goFaxDeliveryMode &= !32;
928       }
929     }
930   }
933 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
934 ?>