Code

Moved fax plugins
[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= "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();
32   var $fax_formats = array("pdf","ps","png","mtiff","tiff");  
34   /* Internal variables */
35   var $printerList= array();
36   var $has_mailAccount= FALSE;
37   var $locals_dialog= FALSE;
38   var $in_blocklist_dialog= FALSE;
39   var $out_blocklist_dialog= FALSE;
40   var $current_blocklist= array();
41   var $view_logged = FALSE;
43   /* Copy & paste variables */
44   var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
46   /* attribute list for save action */
47   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
49   var $uid ="";
51   var $objectclasses= array("goFaxAccount");
53   /* Enable multiple edit support */
54   var $multiple_support = TRUE;
56   function gofaxAccount (&$config, $dn= NULL)
57   {
58     /* General initialization */
59     plugin::plugin ($config, $dn);
61     /* Set uid, it is used in handle_post_events */
62     if(isset($this->attrs['uid'])){
63       $this->uid = $this->attrs['uid'][0];
64     }
66     /* Hickert : 11.11.05
67      * Added to be able to handle department selection in divSelelect
68      */
69     if(!session::is_set("Fax_Filter")){
70       $Fax_Filter = array();
71       $Fax_Filter['depselect'] = $this->config->current['BASE'];
72       session::set('Fax_Filter',$Fax_Filter);
73     }
75     if ($dn != "new"){
76       /* Get arrays */
77       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
78             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
79         $this->$val =array();
80         if (isset($this->attrs["$val"]["count"])){
81           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
82             array_push($this->$val, $this->attrs["$val"][$i]);
83           }
84         }
85       }
87       /* Set up has_mailAccount */
88       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
89         $this->has_mailAccount= TRUE;
90       }
91     }
93     /* Load printer list */
94     $this->printerList=get_printer_list();
96     /* Check if the currently selected printer is still available. 
97        If not, append current printer to list of available.
98        It could be possible, that we are not allowed to view printers and so the list is empty ...  */
99     if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
100       $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
101     }
103     /* Get global filter config */
104     if (!session::is_set("faxfilter")){
105       $ui= get_userinfo();
106       $base= get_base_from_people($ui->dn);
107       $faxfilter= array( "depselect"       => $base,
108           "fuser"            => "*",
109           "regex"           => "");
110       session::set("faxfilter", $faxfilter);
111     }
112   }
114   function execute()
115   {
116     /* Call parent execute */
117     plugin::execute();
119     /* Log view */
120     if($this->is_account && !$this->view_logged){
121       $this->view_logged = TRUE;
122       new log("view","users/".get_class($this),$this->dn);
123     }
125     /* Hickert : 11.11.05
126      * Added to be able to handle department selection in divSelelect
127      */
128     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
130       $Fax_Filter = session::get('Fax_Filter');
131       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
132         $Fax_Filter['depselect']= base64_decode($_GET['dep_id']);
133       }else{
134         $Fax_Filter['depselect']= $this->config->current['BASE'];
135       }
136       session::set('Fax_Filter',$Fax_Filter);
137     }
139     /* Edit mode specifies if we are editing from my accout */
140     $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
142     /* Load smarty stuff */
143     $smarty= get_smarty();
145     /* Check if mail account is active. We'll display an additional
146        mail address field if this is not the case. Some people may
147        want goFax, but have a mailserver which is not managed with
148        GOsa */
149     if (!@isset($this->parent->by_object['mailAccount'])) {
150       $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
151     } elseif ( !$this->parent->by_object['mailAccount']->is_account){
152       $smarty->assign("has_mailaccount", "false");
153       $this->has_mailAccount= false;
154     } else {
155       $smarty->assign("has_mailaccount", "true");
156     }
159     $display = "";
160     if(!$this->multiple_support_active){    
162       /* Do we need to flip is_account state? */
163       if (isset($_POST['modify_state'])){
164         $this->is_account= !$this->is_account;
165       }
167       /* Do we represent a valid account? */
168       if (!$this->is_account && $this->parent === NULL){
169         $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
170           _("This account has no fax extensions.")."</b>";
171         $display.= back_to_main();
172         return ($display);
173       }
175       /* Show tab dialog headers */
176       $display= "";
177       if ($this->parent !== NULL){
178         if ($this->is_account){
179           $display= $this->show_disable_header(_("Remove fax account"),
180               _("This account has fax features enabled. You can disable them by clicking below."));
181         } else {
182           $display= $this->show_enable_header(_("Create fax account"),
183               _("This account has fax features disabled. You can enable them by clicking below."));
184           return ($display);
185         }
186       }
187     }
189     /* Trigger Add local fax alternatives dialog */
190     if (isset($_POST['add_local_alternate'])){
191       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
192         $this->locals_dialog= TRUE;     
193         $this->dialog= TRUE;    
194       }
195     }
197     /* Add alternatives from dialog */
198     if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
199       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
200         foreach ($_POST['local_list'] as $val){
201           $this->addAlternate($val);
202           $this->is_modified= TRUE;
203         }
204       }
205     }
207     /* Add alternatives */
208     if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && tests::is_phone_nr($_POST['forward_address'])){ 
209       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
210         $this->addAlternate($_POST['forward_address']);
211       }
212     }
214     /* Delete alternate fax number */
215     if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
216       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
217         $this->delAlternate ($_POST['alternate_list']);
218       }
219     }
222     /* Edit incoming blocklists */
223     if (isset($_POST['edit_incoming'])){
224       if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode))  {
225         $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
226         sort($this->current_blocklist);
227         reset($this->current_blocklist);
229         $this->in_blocklist_dialog= TRUE;
230         $this->dialog= TRUE;
231       }
232     }
234     /* Edit outgoing blocklists */
235     if (isset($_POST['edit_outgoing'])){
236       $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
237       sort($this->current_blocklist);
238       reset($this->current_blocklist);
240       $this->out_blocklist_dialog= TRUE;
241       $this->dialog= TRUE;
242     }
244     /* Add number to blocklist (dialog) */
245     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
246       if (!tests::is_phone_nr($_POST['block_number'])){
247         print_red (_("You're trying to add an invalid phone number."));
248       } else {
249         array_push($this->current_blocklist, $_POST['block_number']);
250         $this->current_blocklist= array_unique($this->current_blocklist);
251         sort($this->current_blocklist);
252         reset($this->current_blocklist);
253       }
254     }
256     /* Hickert : 11.11.05
257      * Add selection from divSelelect to our Blocklist 
258      */
259     /* Add list to blocklist */
260     if (isset($_POST['add_blocklist'])){
261       foreach($_POST as $name => $value){
262         if(preg_match("/ADDLIST_/i",$name)){
263           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
265         }
266       } 
267       $this->current_blocklist= array_unique($this->current_blocklist);
268       sort($this->current_blocklist);
269       reset($this->current_blocklist);
270     }
272     /* Add list to blocklist */
273     if (isset($_GET['add'])){
274       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
275       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
276       $this->current_blocklist= array_unique($this->current_blocklist);
277       sort($this->current_blocklist);
278       reset($this->current_blocklist);
279     }
281     /* Delete from blocklist */
282     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
283       $tmp= array();
284       foreach($this->current_blocklist as $val){
285         if (!in_array($val, $_POST['block_list'])){
286           $tmp[]= $val;
287         }
288       }
289       $this->current_blocklist= $tmp;
290     }
293     /* Blocklist edit finished */
294     if (isset($_POST['edit_blocklists_finish'])){
296       /* Incoming or outgoing? */
297       if ($this->in_blocklist_dialog){
298         $this->goFaxRBlocklist = array();
299         $this->goFaxRBlockgroups = array();
301         foreach ($this->current_blocklist as $val){
302           if (tests::is_phone_nr($val)){
303             $this->goFaxRBlocklist[]=$val;
304           } else {
305             $this->goFaxRBlockgroups[]= $val;
306           }
307         }
308       } else {
309         $this->goFaxSBlocklist = array();
310         $this->goFaxSBlockgroups = array();
312         /* Transfer values to ourself */
313         foreach ($this->current_blocklist as $val){
314           if (tests::is_phone_nr($val)){
315             $this->goFaxSBlocklist[]=$val;
316           } else {
317             $this->goFaxSBlockgroups[]= $val;
318           }
319         }
320       }
321       $this->is_modified= TRUE;
322     }
325     /* Set departments */
326     if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
327       
328       $list= array ();
329       $ldap= $this->config->get_ldap_link();
330       if (isset ($_POST['department'])){
331         $ldap->cd ($_POST['department']);
332       } else {
333         $ldap->cd ($this->config->current['BASE']);
334       }
335     }
337     /* Cancel  dialogs */
338     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
339         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
341       $this->locals_dialog= FALSE;
342       $this->in_blocklist_dialog= FALSE;
343       $this->out_blocklist_dialog= FALSE;
344       $this->dialog= FALSE;
345     }
347     /* Manage locals dialog */
348     if ($this->locals_dialog){
350       /* Save data */
351       $faxfilter= session::get("faxfilter");
352       foreach( array("depselect", "fuser", "regex") as $type){
353         if (isset($_POST[$type])){
354           $faxfilter[$type]= $_POST[$type];
355         }
356       }
357       if (isset($_GET['search'])){
358         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
359         if ($s == "**"){
360           $s= "*";
361         }
362         $faxfilter['fuser']= $s;
363       }
365       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
366         $regex= $faxfilter['regex'];
367         $filter= "(facimileTelephoneNumber=$regex)";
368       } else {
369         $filter= "";
370       }
371       if ($faxfilter['fuser'] != ""){
372         $user= $faxfilter['fuser'];
373         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
374       }
376       $base= $faxfilter['depselect'];
377       $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base, 
378                      array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
380       foreach ($res as $attrs){
381         $list[$attrs['facsimileTelephoneNumber'][0]]=
382           $attrs['sn'][0].", ".
383           $attrs['givenName'][0]." [".
384           $attrs['facsimileTelephoneNumber'][0]."]";
385       }
387       /* Show dialog */
388       $smarty->assign("search_image", get_template_path('images/search.png'));
389       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
390       $smarty->assign("tree_image", get_template_path('images/tree.png'));
391       $smarty->assign("infoimage", get_template_path('images/info.png'));
392       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
393       $smarty->assign("departments", $this->config->idepartments);
394       $smarty->assign("list", $list);
395       if (isset($_POST['depselect'])){
396         $smarty->assign("depselect", $_POST['depselect']);
397       }
398       $smarty->assign("deplist", $this->config->idepartments);
399       $smarty->assign("apply", apply_filter());
400       $smarty->assign("alphabet", generate_alphabet());
401       $smarty->assign("hint", print_sizelimit_warning());
402       foreach( array("depselect", "fuser", "regex") as $type){
403         $smarty->assign("$type", $faxfilter[$type]);
404       }
405       $smarty->assign("hint", print_sizelimit_warning());
407       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
408       return ($display);
409     }
412     /* Manage incoming blocklists */
413     if ($this->in_blocklist_dialog){
415       /* This handles the divSelectBox */
417       /* The base specifies the current position in the ldap tree 
418        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
419        */
420       $Fax_Filter = session::get('Fax_Filter');
421       $base = $Fax_Filter['depselect'];
422       $ldap->cd($base);
424       /* Ge all Blocklists */
425       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
426       while ($attrs= $ldap->fetch()){
428         /* Generate list depending on description */
429         if(isset($attrs['description'][0])){
430           $list[$attrs['cn'][0]]=
431             $attrs['description'][0].
432             " [".$attrs['cn'][0]."]";
433         }else{
434           $list[$attrs['cn'][0]]= $attrs['cn'][0];
435         }
436       }
438       /* Create our divselect box */
439       $divSel = new divSelectBox("divSelectPredefined");
440       $divSel->setHeight(296);
442       /* NEW LIST MANAGMENT
443        * We also need to search for the departments
444        * So we are able to navigate like in konquerer
445        */
446       $this->departments= array();
447    
448       /* Get all departments within the current department */ 
449       $Fax_Filter = session::get('Fax_Filter');
450       $base = $Fax_Filter['depselect'];
451       $ldap->ls("(objectClass=gosaDepartment)",$base);
453       /* Base back is used to go one department up in our ldap tree */
454       $base_back = preg_replace("/^[^,]+,/","",$base);
456       /* Only show base_back if it is needed */
457       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
458         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
459       }
461       /* Fetch all returned departments an add them to our divlist */
462       while($value = $ldap->fetch()){
463         if($value["description"][0]!=".."){
464           $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
465         }else{
466           $this->departments[$value['dn']]=$value["description"][0];
467         }
468       }
469       /* END NEW LIST MANAGMENT
470        */
472       // This links specifies the department open link 
473       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
475       /* Insert departments in divsel */
476       foreach($this->departments as $key=> $val){
477         if(!isset($this->config->departments[trim($key)])){
478           $this->config->departments[trim($key)]="";
479         }
480         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
481         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
482         $divSel->AddEntry(array($field1,$field2));
483       }
485       /* Append predefined Blocklists */
486       foreach($list as $entry => $value){
487         $divSel->AddEntry(array(
488               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
489               array("string"=>$value,"attach"=>"style='border:0px;'")
490               ));
491       }
493       /* Show dialog */
494       $smarty->assign("cblocklist", $this->current_blocklist);
495       $smarty->assign("departments", $this->config->idepartments);
496       $smarty->assign("divSelectPredefined", $divSel->DrawList());
497       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
498       return ($display);
499     }
501     /* Manage outgoing blocklists */
503     if ($this->out_blocklist_dialog){
505       /* This handles the divSelectBox */
507       /* The base specifies the current position in the ldap tree
508        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
509        */
510       $Fax_Filter = session::get('Fax_Filter');
511       $base = $Fax_Filter['depselect'];
512       $ldap->cd($base);
514       /* Ge all Blocklists */ 
515       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
516       while ($attrs= $ldap->fetch()){
517         if(isset($attrs['description'][0])){
518           $list[$attrs['cn'][0]]=
519             $attrs['description'][0].
520             " [".$attrs['cn'][0]."]";
521         }else{
522           $list[$attrs['cn'][0]]= $attrs['cn'][0];
523         }
524       }
526       /*Create DivSel*/
527       $divSel = new divSelectBox("divSelectPredefined");
528       $divSel->setHeight(296);
530       /* NEW LIST MANAGMENT
531        * We also need to search for the departments
532        * So we are able to navigate like in konquerer
533        */
534       $this->departments= array();
535       $ldap->ls("(objectClass=gosaDepartment)",$base);
537       /* Generate Back url, and append if it is needed */
538       $base_back = preg_replace("/^[^,]+,/","",$base);
539       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
540         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
541       }
543       /* Get all departments */
544       while($value = $ldap->fetch()){
545         if(isset($value["description"][0])){
546           $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
547         }else{
548           $this->departments[$value['dn']]=$value["description"][0];
549         }
550       }
551       /* END NEW LIST MANAGMENT
552        */
554       // Defining Links
555       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
557       /* Insert departments in divlist*/
558       foreach($this->departments as $key=> $val){
559         if(!isset($this->config->departments[trim($key)])){
560           $this->config->departments[trim($key)]="";
561         }
563         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
564         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
565         $divSel->AddEntry(array($field1,$field2));
566       }
568       /* Append Blocklits */
569       foreach($list as $entry => $value){
570         $divSel->AddEntry(array(
571               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
572               array("string"=>$value,"attach"=>"style='border:0px;'")
573               ));
574       }
576       /* Show dialog */
577       $smarty->assign("cblocklist", $this->current_blocklist);
578       $smarty->assign("departments", $this->config->idepartments);
579       $smarty->assign("divSelectPredefined", $divSel->DrawList());
580       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
581       return ($display);
582     }
585     /* Show main page */
586     $smarty->assign("languages", get_languages(TRUE));
588     $smarty->assign("formats",  $this->fax_formats);
589     $smarty->assign("printers", $this->printerList);
591     /* Load attributes */
592     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
593           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
594           "facsimileAlternateTelephoneNumber", "mail") as $val){
596       $smarty->assign("$val", $this->$val);
597     }
599     $tmp = $this->plInfo();
600     foreach($tmp['plProvidedAcls'] as $acl => $desc){
601       $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
602     }
604     /* Load checkboxes */
605     if ($this->goFaxIsEnabled == "1"){
606       $smarty->assign("goFaxIsEnabled", "");
607     } else {
608       $smarty->assign("goFaxIsEnabled", "checked");
609     }
610     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
611     if ($this->goFaxDeliveryMode & 32) {
612       $smarty->assign("faxtomail", "checked");
613     } else {
614       $smarty->assign("faxtomail", "");
615     }
616     if ($this->goFaxDeliveryMode & 64) {
617       $smarty->assign("faxtoprinter", "checked");
618     } else {
619       $smarty->assign("faxtoprinter", "");
620     }
622     foreach($this->attributes as $attr){
623       if(in_array($attr,$this->multi_boxes)) {
624         $smarty->assign("use_".$attr,TRUE);
625       }else{
626         $smarty->assign("use_".$attr,FALSE);
627       }
628     }
629     foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
630       if(in_array($attr,$this->multi_boxes)) {
631         $smarty->assign("use_".$attr,TRUE);
632       }else{
633         $smarty->assign("use_".$attr,FALSE);
634       }
635     }
636   
637     $smarty->assign("multiple_support",$this->multiple_support_active);
638     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
639     return ($display);
640   }
642   function remove_from_parent()
643   {
644     /* Cancel if there's nothing to do here */
645     if (!$this->initially_was_account){
646       return;
647     }
649     plugin::remove_from_parent();
651     /* Adapt mail settings if needed */
652     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
653       unset($this->attrs['mail']);
654     }
656     $ldap= $this->config->get_ldap_link();
657     $ldap->cd($this->dn);
658     $this->cleanup();
659     $ldap->modify ($this->attrs); 
661     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
663     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
665     /* Optionally execute a command after we're done */
666     $this->handle_post_events('remove',array("uid"=> $this->uid));
667   }
670   /* Check formular input */
671   function check()
672   {
673     /* Call common method to give check the hook */
674     $message= plugin::check();
676     /* must: facsimileTelephoneNumber */
677     if ($this->facsimileTelephoneNumber == ""){
678       $message[]= _("The required field 'Fax' is not set.");
679     }
681     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
682       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
683     }
685     /* IF mail is specified (which is only the case if there's no mail account
686        present), check if it's valid..  */
687     if (@isset($this->parent->by_object['mailAccount']) &&
688         $this->goFaxDeliveryMode & 32){
689       if ($this->mail == ""){
690         $message[]= _("Mail delivery is checked, but no address has been specified.");
691       } elseif (!tests::is_email($this->mail)){
692         $message[]= _("The mail address you've entered is invalid.");
693       }
694     }
696     // IE Fix, IE lets you choose disabled option, stupid browser ... 
697     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
698       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
699     }
701     return ($message);
702   }
704   /* Save data to object */
705   function save_object()
706   {
707     $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
708     if (isset($_POST['faxTab'])){
709       plugin::save_object();
712       $tmp = 0+$this->goFaxDeliveryMode;
714       if($this->acl_is_writeable("faxtomail",$edit_mode)){
715         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
716           $tmp |= 32;
717         }elseif($tmp & 32){
718           $tmp &= (!32);
719         }
720       }
721       if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
722         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
723           $tmp |= 64;
724         }elseif($tmp & 64){
725           $tmp &= !64;
726         }
727       }
728       $this->goFaxDeliveryMode = $tmp;
730       if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
731         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
732           $this->goFaxIsEnabled= "0";
733         } else {
734           $this->goFaxIsEnabled= "1";
735         }
736       }
738     
739       if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
740         $this->mail= $_POST['mail'];
741       }
743       /* Check if mail account is active and correct the internal
744          reference to represent the current status. */
745       if(isset($this->parent)){
746         if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
747           $this->has_mailAccount= TRUE;
748         }
749       }
750     }
752   }
755   /* Save to LDAP */
756   function save()
757   {
758     plugin::save();
760     /* Save arrays */
761     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
762           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
764       $this->attrs[$val]= $this->$val;
765     }
767     if(!$this->attrs['goFaxDeliveryMode']){
768       $this->attrs['goFaxDeliveryMode'] = 0;
769     }
770   
771     /* Do not save mail address ... it was possibly changed by mail plugin */
772     /* Adapt mail settings if needed */
773     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
774       unset($this->attrs['mail']);
775     }
777     /* Write back to ldap */
778     $ldap= $this->config->get_ldap_link();
779     $ldap->cd($this->dn);
780     $this->cleanup();
781     $ldap->modify ($this->attrs); 
783     /* Log last action */
784     if($this->initially_was_account){
785       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
786     }else{
787       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
788     }
790     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
792     /* Optionally execute a command after we're done */
793     if ($this->initially_was_account == $this->is_account){
794       if ($this->is_modified){
795         $this->handle_post_events("mofidy",array("uid" => $this->uid));
796       }
797     } else {
798       $this->handle_post_events("add",array("uid" => $this->uid));
799     }
801   }
804   /* Adapt from template, using 'dn' */
805   function adapt_from_template($dn)
806   {
807     plugin::adapt_from_template($dn);
809     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
810           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
812       if (isset($this->attrs[$val])){
813         $this->$val= $this->attrs[$val];
814       }
815     }
816   }
820   /* Add alternate fax recipient */
821   function addAlternate($number)
822   {
823     $this->facsimileAlternateTelephoneNumber[]= "$number";
824     $this->facsimileAlternateTelephoneNumber=
825       array_unique ($this->facsimileAlternateTelephoneNumber);
827     sort ($this->facsimileAlternateTelephoneNumber);
828     reset ($this->facsimileAlternateTelephoneNumber);
829   }
831   function delAlternate($numbers)
832   {
833     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
834         $this->facsimileAlternateTelephoneNumber);
835   }
837   function getCopyDialog()
838   {
839     $str    = "";
840     $smarty = get_smarty();
841     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
842     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
843     $str['status'] ="";
844     return($str);
845   }
847   function SaveCopyDialog()
848   {
849     if(isset($_POST['facsimileTelephoneNumber'])){
850       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
851     }
852   }
855   /* Return plugin informations for acl handling 
856       #FIXME some attributes are still missing in this plugin acls */
857   static function plInfo()
858   {
859     return (array(  
860           "plShortName"     => _("Fax"),
861           "plDescription"   => _("Fax account settings"),
862           "plSelfModify"    => TRUE,
863           "plDepends"       => array("user"),
864           "plPriority"      => 6,             
865           "plSection"       => "personal",  
866           "plCategory"      => array("users"),
867           "plOptions"       => array(),
869           "plProvidedAcls"  => array(
870             "goFaxIsEnabled"                    => _("Enable/Disable fax"),
871             "goFaxRBlocklist"                   => _("Receive blocklist"),
872             "goFaxSBlocklist"                   => _("Send blocklist"),
873             "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
874             "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
875             "faxtomail"                         => _("Deliver fax as mail"),
876             "faxtoprinter"                      => _("Deliver fax to printer"),
877             "goFaxFormat"                       => _("Delivery format"),
878             "goFaxLanguage"                     => _("Language"))
879           ));
880   }
882   /* Multiple edit support 
883    */
884   
885   /* Execute */
886   function multiple_execute()
887   {
888     return($this->execute());
889   }
891   function multiple_save_object()
892   {
893     if (isset($_POST['faxTab'])){
894       plugin::multiple_save_object();
895       foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
896         if(isset($_POST["use_".$attr])){
897           $this->multi_boxes[] = $attr;
898         }
899       }
901       $tmp = 0+$this->goFaxDeliveryMode;
902       if(in_array("faxtomail",$this->multi_boxes)){
903         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
904           $tmp |= 32;
905         }elseif($tmp & 32){
906           $tmp &= (!32);
907         }
908       }
909       if(in_array("faxtoprinter",$this->multi_boxes)){
910         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
911           $tmp |= 64;
912         }elseif($tmp & 64){
913           $tmp &= !64;
914         }
915       }
916       $this->goFaxDeliveryMode = $tmp;
918         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
919           $this->goFaxIsEnabled= "0";
920         } else {
921           $this->goFaxIsEnabled= "1";
922         }
923       if (isset($_POST['mail']) && in_array("mail",$this->multi_boxes)){
924         $this->mail= $_POST['mail'];
925       }
926     }
927   }
929   function get_multi_edit_values()
930   {
931     $ret = plugin::get_multi_edit_values();
932     if(in_array("goFaxIsEnabled",$this->multi_boxes)){
933       $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
934     }
935     if(in_array("faxtoprinter",$this->multi_boxes)){
936       $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
937     }
938     if(in_array("faxtomail",$this->multi_boxes)){
939       $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
940     }
942     if(in_array("edit_incoming",$this->multi_boxes)){
943       $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
944       $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
945     }
946     if(in_array("edit_outgoing",$this->multi_boxes)){
947       $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
948       $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
949     }
950     return($ret);
951   }
953   function multiple_check()
954   {
955     $message = plugin::multiple_check();
956     return($message);
957   }
959   function set_multi_edit_values($values)
960   {
961     plugin::set_multi_edit_values($values);
963     if(isset($values['faxtoprinter'])){
964       if($values['faxtoprinter']){
965         $this->goFaxDeliveryMode |= 64;
966       }else{
967         $this->goFaxDeliveryMode &= !64;
968       }
969     }
970     if(isset($values['faxtomail'])){
971       if($values['faxtomail']){
972         $this->goFaxDeliveryMode |= 32;
973       }else{
974         $this->goFaxDeliveryMode &= !32;
975       }
976     }
977   }
980 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
981 ?>