Code

Created trunk inside of 2.6-lhm
[gosa.git] / trunk / 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= "This does something";
8   var $plIcon = "plugins/gofax/images/plugin.png";
10   /* Department list shown in the divSelectList*/
11   var $departments;
13   /* Fax attributes */
14   var $goFaxDeliveryMode= "";
15   var $facsimileTelephoneNumber= "";
16   var $goFaxIsEnabled= 1;
17   var $goFaxPrinter= "";
18   var $goFaxDivertNumber= "";
19   var $goFaxLanguage= "";
20   var $goFaxFormat= "";
21   var $goFaxRBlocklist = array();
22   var $goFaxRBlockgroups= array();
23   var $goFaxSBlocklist= array();
24   var $goFaxSBlockgroups= array();
25   var $mail= "";
26   var $facsimileAlternateTelephoneNumber= array();
27   var $fax_formats = array("pdf","ps","png","mtiff","tiff");  
29   /* Internal variables */
30   var $printerList= array();
31   var $has_mailAccount= FALSE;
32   var $locals_dialog= FALSE;
33   var $in_blocklist_dialog= FALSE;
34   var $out_blocklist_dialog= FALSE;
35   var $current_blocklist= array();
36   var $view_logged = FALSE;
38   /* Copy & paste variables */
39   var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
41   /* attribute list for save action */
42   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
44   var $uid ="";
46   var $objectclasses= array("goFaxAccount");
48   /* Enable multiple edit support */
49   var $multiple_support = TRUE;
51   function gofaxAccount (&$config, $dn= NULL)
52   {
53     /* General initialization */
54     plugin::plugin ($config, $dn);
56     /* Set uid, it is used in handle_post_events */
57     if(isset($this->attrs['uid'])){
58       $this->uid = $this->attrs['uid'][0];
59     }
61     /* Hickert : 11.11.05
62      * Added to be able to handle department selection in divSelelect
63      */
64     if(!session::is_set("Fax_Filter")){
65       $Fax_Filter = array();
66       $Fax_Filter['depselect'] = $this->config->current['BASE'];
67       session::set('Fax_Filter',$Fax_Filter);
68     }
70     if ($dn != "new"){
71       /* Get arrays */
72       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
73             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
74         $this->$val =array();
75         if (isset($this->attrs["$val"]["count"])){
76           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
77             array_push($this->$val, $this->attrs["$val"][$i]);
78           }
79         }
80       }
82       /* Set up has_mailAccount */
83       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
84         $this->has_mailAccount= TRUE;
85       }
86     }
88     /* Load printer list */
89     $this->printerList=get_printer_list();
91     /* Check if the currently selected printer is still available. 
92        If not, append current printer to list of available.
93        It could be possible, that we are not allowed to view printers and so the list is empty ...  */
94     if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
95       $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
96     }
98     /* Get global filter config */
99     if (!session::is_set("faxfilter")){
100       $ui= get_userinfo();
101       $base= get_base_from_people($ui->dn);
102       $faxfilter= array( "depselect"       => $base,
103           "fuser"            => "*",
104           "regex"           => "");
105       session::set("faxfilter", $faxfilter);
106     }
107   }
109   function execute()
110   {
111     /* Call parent execute */
112     plugin::execute();
114     /* Log view */
115     if($this->is_account && !$this->view_logged){
116       $this->view_logged = TRUE;
117       new log("view","users/".get_class($this),$this->dn);
118     }
120     /* Hickert : 11.11.05
121      * Added to be able to handle department selection in divSelelect
122      */
123     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
125       $Fax_Filter = session::get('Fax_Filter');
126       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
127         $Fax_Filter['depselect']= base64_decode($_GET['dep_id']);
128       }else{
129         $Fax_Filter['depselect']= $this->config->current['BASE'];
130       }
131       session::set('Fax_Filter',$Fax_Filter);
132     }
134     /* Edit mode specifies if we are editing from my accout */
135     $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
137     /* Load smarty stuff */
138     $smarty= get_smarty();
140     /* Check if mail account is active. We'll display an additional
141        mail address field if this is not the case. Some people may
142        want goFax, but have a mailserver which is not managed with
143        GOsa */
144     if (!@isset($this->parent->by_object['mailAccount'])) {
145       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
146     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
147       $smarty->assign("has_mailaccount", "false");
148       $this->has_mailAccount= false;
149     } else {
150       $smarty->assign("has_mailaccount", "true");
151     }
154     $display = "";
155     if(!$this->multiple_support_active){    
157       /* Do we need to flip is_account state? */
158       if (isset($_POST['modify_state'])){
159         $this->is_account= !$this->is_account;
160       }
162       /* Do we represent a valid account? */
163       if (!$this->is_account && $this->parent === NULL){
164         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
165           msgPool::noValidExtension(_("GOfax"))."</b>";
166         $display.= back_to_main();
167         return ($display);
168       }
170       /* Show tab dialog headers */
171       $display= "";
172       if ($this->parent !== NULL){
173         if ($this->is_account){
174           $display= $this->show_disable_header(_("Remove fax account"),
175               msgPool::featuresEnabled(_("GOfax")));
176         } else {
177           $display= $this->show_enable_header(_("Create fax account"),
178               msgPool::featuresDisabled(_("GOfax")));
179           return ($display);
180         }
181       }
182     }
184     /* Trigger Add local fax alternatives dialog */
185     if (isset($_POST['add_local_alternate'])){
186       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
187         $this->locals_dialog= TRUE;     
188         $this->dialog= TRUE;    
189       }
190     }
192     /* Add alternatives from dialog */
193     if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
194       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
195         foreach ($_POST['local_list'] as $val){
196           $this->addAlternate($val);
197           $this->is_modified= TRUE;
198         }
199       }
200     }
202     /* Add alternatives */
203     if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && tests::is_phone_nr($_POST['forward_address'])){ 
204       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
205         $this->addAlternate($_POST['forward_address']);
206       }
207     }
209     /* Delete alternate fax number */
210     if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
211       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
212         $this->delAlternate ($_POST['alternate_list']);
213       }
214     }
217     /* Edit incoming blocklists */
218     if (isset($_POST['edit_incoming'])){
219       if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode))  {
220         $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
221         sort($this->current_blocklist);
222         reset($this->current_blocklist);
224         $this->in_blocklist_dialog= TRUE;
225         $this->dialog= TRUE;
226       }
227     }
229     /* Edit outgoing blocklists */
230     if (isset($_POST['edit_outgoing'])){
231       $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
232       sort($this->current_blocklist);
233       reset($this->current_blocklist);
235       $this->out_blocklist_dialog= TRUE;
236       $this->dialog= TRUE;
237     }
239     /* Add number to blocklist (dialog) */
240     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
241       if (!tests::is_phone_nr($_POST['block_number'])){
242         msg_dialog::display(_("Error"), msgPool::invalid(_("Phone number")), ERROR_DIALOG);
243       } else {
244         array_push($this->current_blocklist, $_POST['block_number']);
245         $this->current_blocklist= array_unique($this->current_blocklist);
246         sort($this->current_blocklist);
247         reset($this->current_blocklist);
248       }
249     }
251     /* Hickert : 11.11.05
252      * Add selection from divSelelect to our Blocklist 
253      */
254     /* Add list to blocklist */
255     if (isset($_POST['add_blocklist'])){
256       foreach($_POST as $name => $value){
257         if(preg_match("/ADDLIST_/i",$name)){
258           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
260         }
261       } 
262       $this->current_blocklist= array_unique($this->current_blocklist);
263       sort($this->current_blocklist);
264       reset($this->current_blocklist);
265     }
267     /* Add list to blocklist */
268     if (isset($_GET['add'])){
269       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
270       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
271       $this->current_blocklist= array_unique($this->current_blocklist);
272       sort($this->current_blocklist);
273       reset($this->current_blocklist);
274     }
276     /* Delete from blocklist */
277     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
278       $tmp= array();
279       foreach($this->current_blocklist as $val){
280         if (!in_array($val, $_POST['block_list'])){
281           $tmp[]= $val;
282         }
283       }
284       $this->current_blocklist= $tmp;
285     }
288     /* Blocklist edit finished */
289     if (isset($_POST['edit_blocklists_finish'])){
291       /* Incoming or outgoing? */
292       if ($this->in_blocklist_dialog){
293         $this->goFaxRBlocklist = array();
294         $this->goFaxRBlockgroups = array();
296         foreach ($this->current_blocklist as $val){
297           if (tests::is_phone_nr($val)){
298             $this->goFaxRBlocklist[]=$val;
299           } else {
300             $this->goFaxRBlockgroups[]= $val;
301           }
302         }
303       } else {
304         $this->goFaxSBlocklist = array();
305         $this->goFaxSBlockgroups = array();
307         /* Transfer values to ourself */
308         foreach ($this->current_blocklist as $val){
309           if (tests::is_phone_nr($val)){
310             $this->goFaxSBlocklist[]=$val;
311           } else {
312             $this->goFaxSBlockgroups[]= $val;
313           }
314         }
315       }
316       $this->is_modified= TRUE;
317     }
320     /* Set departments */
321     if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
322       
323       $list= array ();
324       $ldap= $this->config->get_ldap_link();
325       if (isset ($_POST['department'])){
326         $ldap->cd ($_POST['department']);
327       } else {
328         $ldap->cd ($this->config->current['BASE']);
329       }
330     }
332     /* Cancel  dialogs */
333     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
334         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
336       $this->locals_dialog= FALSE;
337       $this->in_blocklist_dialog= FALSE;
338       $this->out_blocklist_dialog= FALSE;
339       $this->dialog= FALSE;
340     }
342     /* Manage locals dialog */
343     if ($this->locals_dialog){
345       /* Save data */
346       $faxfilter= session::get("faxfilter");
347       foreach( array("depselect", "fuser", "regex") as $type){
348         if (isset($_POST[$type])){
349           $faxfilter[$type]= $_POST[$type];
350         }
351       }
352       if (isset($_GET['search'])){
353         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
354         if ($s == "**"){
355           $s= "*";
356         }
357         $faxfilter['fuser']= $s;
358       }
360       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
361         $regex= $faxfilter['regex'];
362         $filter= "(facimileTelephoneNumber=$regex)";
363       } else {
364         $filter= "";
365       }
366       if ($faxfilter['fuser'] != ""){
367         $user= $faxfilter['fuser'];
368         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
369       }
371       $base= $faxfilter['depselect'];
372       $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base, 
373                      array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
375       foreach ($res as $attrs){
376         $list[$attrs['facsimileTelephoneNumber'][0]]=
377           $attrs['sn'][0].", ".
378           $attrs['givenName'][0]." [".
379           $attrs['facsimileTelephoneNumber'][0]."]";
380       }
382       /* Show dialog */
383       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
384       $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
385       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
386       $smarty->assign("infoimage", get_template_path('images/info.png'));
387       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
388       $smarty->assign("departments", $this->config->idepartments);
389       $smarty->assign("list", $list);
390       if (isset($_POST['depselect'])){
391         $smarty->assign("depselect", $_POST['depselect']);
392       }
393       $smarty->assign("deplist", $this->config->idepartments);
394       $smarty->assign("apply", apply_filter());
395       $smarty->assign("alphabet", generate_alphabet());
396       $smarty->assign("hint", print_sizelimit_warning());
397       foreach( array("depselect", "fuser", "regex") as $type){
398         $smarty->assign("$type", $faxfilter[$type]);
399       }
400       $smarty->assign("hint", print_sizelimit_warning());
402       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
403       return ($display);
404     }
407     /* Manage incoming blocklists */
408     if ($this->in_blocklist_dialog){
410       /* This handles the divSelectBox */
412       /* The base specifies the current position in the ldap tree 
413        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
414        */
415       $Fax_Filter = session::get('Fax_Filter');
416       $base = $Fax_Filter['depselect'];
417       $ldap->cd($base);
419       /* Ge all Blocklists */
420       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
421       while ($attrs= $ldap->fetch()){
423         /* Generate list depending on description */
424         if(isset($attrs['description'][0])){
425           $list[$attrs['cn'][0]]=
426             $attrs['description'][0].
427             " [".$attrs['cn'][0]."]";
428         }else{
429           $list[$attrs['cn'][0]]= $attrs['cn'][0];
430         }
431       }
433       /* Create our divselect box */
434       $divSel = new divSelectBox("divSelectPredefined");
435       $divSel->setHeight(296);
437       /* NEW LIST MANAGMENT
438        * We also need to search for the departments
439        * So we are able to navigate like in konquerer
440        */
441       $this->departments= array();
442    
443       /* Get all departments within the current department */ 
444       $Fax_Filter = session::get('Fax_Filter');
445       $base = $Fax_Filter['depselect'];
446       $ldap->ls("(objectClass=gosaDepartment)",$base);
448       /* Base back is used to go one department up in our ldap tree */
449       $base_back = preg_replace("/^[^,]+,/","",$base);
451       /* Only show base_back if it is needed */
452       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
453         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
454       }
456       /* Fetch all returned departments an add them to our divlist */
457       while($value = $ldap->fetch()){
458         if($value["description"][0]!=".."){
459           $this->departments[$value['dn']]=LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
460         }else{
461           $this->departments[$value['dn']]=$value["description"][0];
462         }
463       }
464       /* END NEW LIST MANAGMENT
465        */
467       // This links specifies the department open link 
468       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
470       /* Insert departments in divsel */
471       foreach($this->departments as $key=> $val){
472         if(!isset($this->config->departments[trim($key)])){
473           $this->config->departments[trim($key)]="";
474         }
475         $field1 = array("string" => "<img src='images/lists/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
476         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
477         $divSel->AddEntry(array($field1,$field2));
478       }
480       /* Append predefined Blocklists */
481       foreach($list as $entry => $value){
482         $divSel->AddEntry(array(
483               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
484               array("string"=>$value,"attach"=>"style='border:0px;'")
485               ));
486       }
488       /* Show dialog */
489       $smarty->assign("cblocklist", $this->current_blocklist);
490       $smarty->assign("departments", $this->config->idepartments);
491       $smarty->assign("divSelectPredefined", $divSel->DrawList());
492       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
493       return ($display);
494     }
496     /* Manage outgoing blocklists */
498     if ($this->out_blocklist_dialog){
500       /* This handles the divSelectBox */
502       /* The base specifies the current position in the ldap tree
503        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
504        */
505       $Fax_Filter = session::get('Fax_Filter');
506       $base = $Fax_Filter['depselect'];
507       $ldap->cd($base);
509       /* Ge all Blocklists */ 
510       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
511       while ($attrs= $ldap->fetch()){
512         if(isset($attrs['description'][0])){
513           $list[$attrs['cn'][0]]=
514             $attrs['description'][0].
515             " [".$attrs['cn'][0]."]";
516         }else{
517           $list[$attrs['cn'][0]]= $attrs['cn'][0];
518         }
519       }
521       /*Create DivSel*/
522       $divSel = new divSelectBox("divSelectPredefined");
523       $divSel->setHeight(296);
525       /* NEW LIST MANAGMENT
526        * We also need to search for the departments
527        * So we are able to navigate like in konquerer
528        */
529       $this->departments= array();
530       $ldap->ls("(objectClass=gosaDepartment)",$base);
532       /* Generate Back url, and append if it is needed */
533       $base_back = preg_replace("/^[^,]+,/","",$base);
534       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
535         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
536       }
538       /* Get all departments */
539       while($value = $ldap->fetch()){
540         if(isset($value["description"][0])){
541           $this->departments[$value['dn']]=LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
542         }else{
543           $this->departments[$value['dn']]=$value["description"][0];
544         }
545       }
546       /* END NEW LIST MANAGMENT
547        */
549       // Defining Links
550       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
552       /* Insert departments in divlist*/
553       foreach($this->departments as $key=> $val){
554         if(!isset($this->config->departments[trim($key)])){
555           $this->config->departments[trim($key)]="";
556         }
558         $field1 = array("string" => "<img src='images/lists/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
559         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
560         $divSel->AddEntry(array($field1,$field2));
561       }
563       /* Append Blocklits */
564       foreach($list as $entry => $value){
565         $divSel->AddEntry(array(
566               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
567               array("string"=>$value,"attach"=>"style='border:0px;'")
568               ));
569       }
571       /* Show dialog */
572       $smarty->assign("cblocklist", $this->current_blocklist);
573       $smarty->assign("departments", $this->config->idepartments);
574       $smarty->assign("divSelectPredefined", $divSel->DrawList());
575       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
576       return ($display);
577     }
580     /* Show main page */
581     $smarty->assign("languages", get_languages(TRUE));
583     $smarty->assign("formats",  $this->fax_formats);
584     $smarty->assign("printers", $this->printerList);
586     /* Load attributes */
587     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
588           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
589           "facsimileAlternateTelephoneNumber", "mail") as $val){
591       $smarty->assign("$val", $this->$val);
592     }
594     $tmp = $this->plInfo();
595     foreach($tmp['plProvidedAcls'] as $acl => $desc){
596       $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
597     }
599     /* Load checkboxes */
600     if ($this->goFaxIsEnabled == "1"){
601       $smarty->assign("goFaxIsEnabled", "");
602     } else {
603       $smarty->assign("goFaxIsEnabled", "checked");
604     }
605     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
606     if ($this->goFaxDeliveryMode & 32) {
607       $smarty->assign("faxtomail", "checked");
608     } else {
609       $smarty->assign("faxtomail", "");
610     }
611     if ($this->goFaxDeliveryMode & 64) {
612       $smarty->assign("faxtoprinter", "checked");
613     } else {
614       $smarty->assign("faxtoprinter", "");
615     }
617     foreach($this->attributes as $attr){
618       if(in_array($attr,$this->multi_boxes)) {
619         $smarty->assign("use_".$attr,TRUE);
620       }else{
621         $smarty->assign("use_".$attr,FALSE);
622       }
623     }
624     foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
625       if(in_array($attr,$this->multi_boxes)) {
626         $smarty->assign("use_".$attr,TRUE);
627       }else{
628         $smarty->assign("use_".$attr,FALSE);
629       }
630     }
631   
632     $smarty->assign("multiple_support",$this->multiple_support_active);
633     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
634     return ($display);
635   }
637   function remove_from_parent()
638   {
639     /* Cancel if there's nothing to do here */
640     if (!$this->initially_was_account){
641       return;
642     }
644     plugin::remove_from_parent();
646     /* Adapt mail settings if needed */
647     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
648       unset($this->attrs['mail']);
649     }
651     $ldap= $this->config->get_ldap_link();
652     $ldap->cd($this->dn);
653     $this->cleanup();
654     $ldap->modify ($this->attrs); 
656     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
658     if (!$ldap->success()){
659       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
660     }
662     /* Optionally execute a command after we're done */
663     $this->handle_post_events('remove',array("uid"=> $this->uid));
664   }
667   /* Check formular input */
668   function check()
669   {
670     /* Call common method to give check the hook */
671     $message= plugin::check();
673     /* must: facsimileTelephoneNumber */
674     if ($this->facsimileTelephoneNumber == ""){
675       $message[]= msgPool::required(_("Fax number"));
676     }
678     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
679       $message[]= msgPool::invalid(_("Fax number"),$this->facsimileTelephoneNumber,"/[0-9]/");
680     }
682     /* IF mail is specified (which is only the case if there's no mail account
683        present), check if it's valid..  */
684     if (@isset($this->parent->by_object['mailAccount']) &&
685         $this->goFaxDeliveryMode & 32){
686       if ($this->mail == ""){
687         $message[]= _("Mail delivery is requested without target address!");
688       } elseif (!tests::is_email($this->mail)){
689         $message[]= msgPool::invalid(_("Mail address"),"","",_("your-name@your-domain.com"));
690       }
691     }
693     // IE Fix, IE lets you choose disabled option, stupid browser ... 
694     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
695       $message[]= _("Printing is requested without a target printer!");
696     }
698     return ($message);
699   }
701   /* Save data to object */
702   function save_object()
703   {
704     $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
705     if (isset($_POST['faxTab'])){
706       plugin::save_object();
709       $tmp = 0+$this->goFaxDeliveryMode;
711       if($this->acl_is_writeable("faxtomail",$edit_mode)){
712         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
713           $tmp |= 32;
714         }elseif($tmp & 32){
715           $tmp &= (!32);
716         }
717       }
718       if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
719         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
720           $tmp |= 64;
721         }elseif($tmp & 64){
722           $tmp &= !64;
723         }
724       }
725       $this->goFaxDeliveryMode = $tmp;
727       if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
728         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
729           $this->goFaxIsEnabled= "0";
730         } else {
731           $this->goFaxIsEnabled= "1";
732         }
733       }
735     
736       if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
737         $this->mail= $_POST['mail'];
738       }
740       /* Check if mail account is active and correct the internal
741          reference to represent the current status. */
742       if(isset($this->parent)){
743         if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
744           $this->has_mailAccount= TRUE;
745         }
746       }
747     }
749   }
752   /* Save to LDAP */
753   function save()
754   {
755     plugin::save();
757     /* Save arrays */
758     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
759           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
761       $this->attrs[$val]= $this->$val;
762     }
764     if(!$this->attrs['goFaxDeliveryMode']){
765       $this->attrs['goFaxDeliveryMode'] = 0;
766     }
767   
768     /* Do not save mail address ... it was possibly changed by mail plugin */
769     /* Adapt mail settings if needed */
770     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
771       unset($this->attrs['mail']);
772     }
774     /* Write back to ldap */
775     $ldap= $this->config->get_ldap_link();
776     $ldap->cd($this->dn);
777     $this->cleanup();
778     $ldap->modify ($this->attrs); 
780     /* Log last action */
781     if($this->initially_was_account){
782       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
783     }else{
784       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
785     }
787     if (!$ldap->success()){
788       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
789     }
791     /* Optionally execute a command after we're done */
792     if ($this->initially_was_account == $this->is_account){
793       if ($this->is_modified){
794         $this->handle_post_events("mofidy",array("uid" => $this->uid));
795       }
796     } else {
797       $this->handle_post_events("add",array("uid" => $this->uid));
798     }
800   }
803   /* Adapt from template, using 'dn' */
804   function adapt_from_template($dn, $skip= array())
805   {
806     plugin::adapt_from_template($dn, $skip);
808     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
809           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
811       if (in_array($val, $skip)){
812         continue;
813       }
815       if (isset($this->attrs[$val])){
816         $this->$val= $this->attrs[$val];
817       }
818     }
819   }
823   /* Add alternate fax recipient */
824   function addAlternate($number)
825   {
826     $this->facsimileAlternateTelephoneNumber[]= "$number";
827     $this->facsimileAlternateTelephoneNumber=
828       array_unique ($this->facsimileAlternateTelephoneNumber);
830     sort ($this->facsimileAlternateTelephoneNumber);
831     reset ($this->facsimileAlternateTelephoneNumber);
832   }
834   function delAlternate($numbers)
835   {
836     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
837         $this->facsimileAlternateTelephoneNumber);
838   }
840   function getCopyDialog()
841   {
842     $str    = "";
843     $smarty = get_smarty();
844     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
845     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
846     $str['status'] ="";
847     return($str);
848   }
850   function SaveCopyDialog()
851   {
852     if(isset($_POST['facsimileTelephoneNumber'])){
853       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
854     }
855   }
858   /* Return plugin informations for acl handling 
859       #FIXME some attributes are still missing in this plugin acls */
860   static function plInfo()
861   {
862     return (array(  
863           "plShortName"     => _("Fax"),
864           "plDescription"   => _("Fax account settings"),
865           "plSelfModify"    => TRUE,
866           "plDepends"       => array("user"),
867           "plPriority"      => 6,             
868           "plSection"       => "personal",  
869           "plCategory"      => array("users"),
870           "plOptions"       => array(),
872           "plProvidedAcls"  => array(
873             "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
874             "goFaxLanguage"                     => _("Language"),
875             "goFaxFormat"                       => _("Delivery format"),
876             "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
877             "goFaxIsEnabled"                    => _("Enable/Disable fax"),
878             "faxtomail"                         => _("Deliver fax as mail"),
879             "faxtoprinter"                      => _("Deliver fax to printer"),
880             "goFaxRBlocklist"                   => _("Receive blocklist"),
881             "goFaxSBlocklist"                   => _("Send blocklist"))
882           ));
883   }
885   /* Multiple edit support 
886    */
887   
888   /* Execute */
889   function multiple_execute()
890   {
891     return($this->execute());
892   }
894   function multiple_save_object()
895   {
896     if (isset($_POST['faxTab'])){
897       plugin::multiple_save_object();
898       foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
899         if(isset($_POST["use_".$attr])){
900           $this->multi_boxes[] = $attr;
901         }
902       }
904       $tmp = 0+$this->goFaxDeliveryMode;
905       if(in_array("faxtomail",$this->multi_boxes)){
906         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
907           $tmp |= 32;
908         }elseif($tmp & 32){
909           $tmp &= (!32);
910         }
911       }
912       if(in_array("faxtoprinter",$this->multi_boxes)){
913         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
914           $tmp |= 64;
915         }elseif($tmp & 64){
916           $tmp &= !64;
917         }
918       }
919       $this->goFaxDeliveryMode = $tmp;
921         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
922           $this->goFaxIsEnabled= "0";
923         } else {
924           $this->goFaxIsEnabled= "1";
925         }
926       if (isset($_POST['mail']) && in_array("mail",$this->multi_boxes)){
927         $this->mail= $_POST['mail'];
928       }
929     }
930   }
932   function get_multi_edit_values()
933   {
934     $ret = plugin::get_multi_edit_values();
935     if(in_array("goFaxIsEnabled",$this->multi_boxes)){
936       $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
937     }
938     if(in_array("faxtoprinter",$this->multi_boxes)){
939       $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
940     }
941     if(in_array("faxtomail",$this->multi_boxes)){
942       $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
943     }
945     if(in_array("edit_incoming",$this->multi_boxes)){
946       $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
947       $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
948     }
949     if(in_array("edit_outgoing",$this->multi_boxes)){
950       $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
951       $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
952     }
953     return($ret);
954   }
956   function multiple_check()
957   {
958     $message = plugin::multiple_check();
959     return($message);
960   }
962   function set_multi_edit_values($values)
963   {
964     plugin::set_multi_edit_values($values);
966     if(isset($values['faxtoprinter'])){
967       if($values['faxtoprinter']){
968         $this->goFaxDeliveryMode |= 64;
969       }else{
970         $this->goFaxDeliveryMode &= !64;
971       }
972     }
973     if(isset($values['faxtomail'])){
974       if($values['faxtomail']){
975         $this->goFaxDeliveryMode |= 32;
976       }else{
977         $this->goFaxDeliveryMode &= !32;
978       }
979     }
980   }
983 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
984 ?>