Code

Added a first set of reference changes - nearly untested
[gosa.git] / plugins / gofax / faxaccount / class_gofaxAccount.inc
1 <?php
3 class gofaxAccount extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "FAX";
7   var $plDescription= "This does something";
9   /* CLI vars */
10   var $cli_summary= "Manage users fax account";
11   var $cli_description= "Some longer text\nfor help";
12   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
15   /* Department list shown in the divSelectList*/
16   var $departments;
18   /* Fax attributes */
19   var $goFaxDeliveryMode= "";
20   var $facsimileTelephoneNumber= "";
21   var $goFaxIsEnabled= 1;
22   var $goFaxPrinter= "";
23   var $goFaxDivertNumber= "";
24   var $goFaxLanguage= "";
25   var $goFaxFormat= "";
26   var $goFaxRBlocklist = array();
27   var $goFaxRBlockgroups= array();
28   var $goFaxSBlocklist= array();
29   var $goFaxSBlockgroups= array();
30   var $mail= "";
31   var $facsimileAlternateTelephoneNumber= array();
33   /* Internal variables */
34   var $printerList= array();
35   var $has_mailAccount= FALSE;
36   var $locals_dialog= FALSE;
37   var $in_blocklist_dialog= FALSE;
38   var $out_blocklist_dialog= FALSE;
39   var $current_blocklist= array();
40   var $view_logged = FALSE;
42   /* Copy & paste variables */
43   var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
45   /* attribute list for save action */
46   var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
48   var $uid ="";
50   var $objectclasses= array("goFaxAccount");
52   function gofaxAccount (&$config, $dn= NULL)
53   {
54     /* General initialization */
55     plugin::plugin ($config, $dn);
57     /* Set uid, it is used in handle_post_events */
58     if(isset($this->attrs['uid'])){
59       $this->uid = $this->attrs['uid'][0];
60     }
62     /* Hickert : 11.11.05
63      * Added to be able to handle department selection in divSelelect
64      */
65     if(!isset($_SESSION["Fax_Filter"])){
66       $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
67     }
69     if ($dn != "new"){
70       /* Get arrays */
71       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
72             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
73         $this->$val =array();
74         if (isset($this->attrs["$val"]["count"])){
75           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
76             array_push($this->$val, $this->attrs["$val"][$i]);
77           }
78         }
79       }
81       /* Set up has_mailAccount */
82       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
83         $this->has_mailAccount= TRUE;
84       }
85     }
87     /* Load printer list */
88     if (isset($this->config->data['SERVERS']['CUPS'])){
89       $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
90       asort ($this->printerList);
91     }
93     /* Check if the currently selected printer is still available. 
94        If not, append current printer to list of available.
95        It could be possible, that we are not allowed to view printers and so the list is empty ...  */
96     if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
97       $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
98     }
100     /* Get global filter config */
101     if (!is_global("faxfilter")){
102       $ui= get_userinfo();
103       $base= get_base_from_people($ui->dn);
104       $faxfilter= array( "depselect"       => $base,
105           "fuser"            => "*",
106           "regex"           => "");
107       register_global("faxfilter", $faxfilter);
108     }
109   }
111   function execute()
112   {
113     /* Call parent execute */
114     plugin::execute();
116     /* Log view */
117     if($this->is_account && !$this->view_logged){
118       $this->view_logged = TRUE;
119       new log("view","users/".get_class($this),$this->dn);
120     }
122     /* Hickert : 11.11.05
123      * Added to be able to handle department selection in divSelelect
124      */
125     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
127       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
128         $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
129       }else{
130         $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
131       }
132     }
134     /* Edit mode specifies if we are editing from my accout */
135     $edit_mode = (!is_object($this->parent) && !isset($_SESSION['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     }
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/stop.png\" align=\"middle\">&nbsp;<b>".
161         _("This account has no fax extensions.")."</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             _("This account has fax features enabled. You can disable them by clicking below."));
172       } else {
173         $display= $this->show_enable_header(_("Create fax account"),
174             _("This account has fax features disabled. You can enable them by clicking below."));
175         return ($display);
176       }
177     }
179     /* Trigger Add local fax alternatives dialog */
180     if (isset($_POST['add_local_alternate'])){
181       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
182         $this->locals_dialog= TRUE;     
183         $this->dialog= TRUE;    
184       }
185     }
187     /* Add alternatives from dialog */
188     if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
189       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
190         foreach ($_POST['local_list'] as $val){
191           $this->addAlternate($val);
192           $this->is_modified= TRUE;
193         }
194       }
195     }
197     /* Add alternatives */
198     if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){ 
199       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
200         $this->addAlternate($_POST['forward_address']);
201       }
202     }
204     /* Delete alternate fax number */
205     if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
206       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
207         $this->delAlternate ($_POST['alternate_list']);
208       }
209     }
212     /* Edit incoming blocklists */
213     if (isset($_POST['edit_incoming'])){
214       if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode))  {
215         $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
216         sort($this->current_blocklist);
217         reset($this->current_blocklist);
219         $this->in_blocklist_dialog= TRUE;
220         $this->dialog= TRUE;
221       }
222     }
224     /* Edit outgoing blocklists */
225     if (isset($_POST['edit_outgoing'])){
226       $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
227       sort($this->current_blocklist);
228       reset($this->current_blocklist);
230       $this->out_blocklist_dialog= TRUE;
231       $this->dialog= TRUE;
232     }
234     /* Add number to blocklist (dialog) */
235     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
236       if (!is_phone_nr($_POST['block_number'])){
237         print_red (_("You're trying to add an invalid phone number."));
238       } else {
239         array_push($this->current_blocklist, $_POST['block_number']);
240         $this->current_blocklist= array_unique($this->current_blocklist);
241         sort($this->current_blocklist);
242         reset($this->current_blocklist);
243       }
244     }
246     /* Hickert : 11.11.05
247      * Add selection from divSelelect to our Blocklist 
248      */
249     /* Add list to blocklist */
250     if (isset($_POST['add_blocklist'])){
251       foreach($_POST as $name => $value){
252         if(preg_match("/ADDLIST_/i",$name)){
253           $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
255         }
256       } 
257       $this->current_blocklist= array_unique($this->current_blocklist);
258       sort($this->current_blocklist);
259       reset($this->current_blocklist);
260     }
262     /* Add list to blocklist */
263     if (isset($_GET['add'])){
264       if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
265       $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
266       $this->current_blocklist= array_unique($this->current_blocklist);
267       sort($this->current_blocklist);
268       reset($this->current_blocklist);
269     }
271     /* Delete from blocklist */
272     if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
273       $tmp= array();
274       foreach($this->current_blocklist as $val){
275         if (!in_array($val, $_POST['block_list'])){
276           $tmp[]= $val;
277         }
278       }
279       $this->current_blocklist= $tmp;
280     }
283     /* Blocklist edit finished */
284     if (isset($_POST['edit_blocklists_finish'])){
286       /* Incoming or outgoing? */
287       if ($this->in_blocklist_dialog){
288         $this->goFaxRBlocklist = array();
289         $this->goFaxRBlockgroups = array();
291         foreach ($this->current_blocklist as $val){
292           if (is_phone_nr($val)){
293             $this->goFaxRBlocklist[]=$val;
294           } else {
295             $this->goFaxRBlockgroups[]= $val;
296           }
297         }
298       } else {
299         $this->goFaxSBlocklist = array();
300         $this->goFaxSBlockgroups = array();
302         /* Transfer values to ourself */
303         foreach ($this->current_blocklist as $val){
304           if (is_phone_nr($val)){
305             $this->goFaxSBlocklist[]=$val;
306           } else {
307             $this->goFaxSBlockgroups[]= $val;
308           }
309         }
310       }
311       $this->is_modified= TRUE;
312     }
315     /* Set departments */
316     if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
317       
318       $list= array ();
319       $ldap= $this->config->get_ldap_link();
320       if (isset ($_POST['department'])){
321         $ldap->cd ($_POST['department']);
322       } else {
323         $ldap->cd ($this->config->current['BASE']);
324       }
325     }
327     /* Cancel  dialogs */
328     if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
329         isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
331       $this->locals_dialog= FALSE;
332       $this->in_blocklist_dialog= FALSE;
333       $this->out_blocklist_dialog= FALSE;
334       $this->dialog= FALSE;
335     }
337     /* Manage locals dialog */
338     if ($this->locals_dialog){
340       /* Save data */
341       $faxfilter= get_global("faxfilter");
342       foreach( array("depselect", "fuser", "regex") as $type){
343         if (isset($_POST[$type])){
344           $faxfilter[$type]= $_POST[$type];
345         }
346       }
347       if (isset($_GET['search'])){
348         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
349         if ($s == "**"){
350           $s= "*";
351         }
352         $faxfilter['fuser']= $s;
353       }
355       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
356         $regex= $faxfilter['regex'];
357         $filter= "(facimileTelephoneNumber=$regex)";
358       } else {
359         $filter= "";
360       }
361       if ($faxfilter['fuser'] != ""){
362         $user= $faxfilter['fuser'];
363         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
364       }
366       $base= $faxfilter['depselect'];
367       $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base, 
368                      array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
370       foreach ($res as $attrs){
371         $list[$attrs['facsimileTelephoneNumber'][0]]=
372           $attrs['sn'][0].", ".
373           $attrs['givenName'][0]." [".
374           $attrs['facsimileTelephoneNumber'][0]."]";
375       }
377       /* Show dialog */
378       $smarty->assign("search_image", get_template_path('images/search.png'));
379       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
380       $smarty->assign("tree_image", get_template_path('images/tree.png'));
381       $smarty->assign("infoimage", get_template_path('images/info.png'));
382       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
383       $smarty->assign("departments", $this->config->idepartments);
384       $smarty->assign("list", $list);
385       if (isset($_POST['depselect'])){
386         $smarty->assign("depselect", $_POST['depselect']);
387       }
388       $smarty->assign("deplist", $this->config->idepartments);
389       $smarty->assign("apply", apply_filter());
390       $smarty->assign("alphabet", generate_alphabet());
391       $smarty->assign("hint", print_sizelimit_warning());
392       foreach( array("depselect", "fuser", "regex") as $type){
393         $smarty->assign("$type", $faxfilter[$type]);
394       }
395       $smarty->assign("hint", print_sizelimit_warning());
397       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
398       return ($display);
399     }
402     /* Manage incoming blocklists */
403     if ($this->in_blocklist_dialog){
405       /* This handles the divSelectBox */
407       /* The base specifies the current position in the ldap tree 
408        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
409        */
410       $base = $_SESSION['Fax_Filter']['depselect'];
411       $ldap->cd($base);
413       /* Ge all Blocklists */
414       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
415       while ($attrs= $ldap->fetch()){
417         /* Generate list depending on description */
418         if(isset($attrs['description'][0])){
419           $list[$attrs['cn'][0]]=
420             $attrs['description'][0].
421             " [".$attrs['cn'][0]."]";
422         }else{
423           $list[$attrs['cn'][0]]= $attrs['cn'][0];
424         }
425       }
427       /* Create our divselect box */
428       $divSel = new divSelectBox("divSelectPredefined");
429       $divSel->setHeight(296);
431       /* NEW LIST MANAGMENT
432        * We also need to search for the departments
433        * So we are able to navigate like in konquerer
434        */
435       $this->departments= array();
436    
437       /* Get all departments within the current department */ 
438       $base = $_SESSION['Fax_Filter']['depselect'];
439       $ldap->ls("(objectClass=gosaDepartment)",$base);
441       /* Base back is used to go one department up in our ldap tree */
442       $base_back = preg_replace("/^[^,]+,/","",$base);
444       /* Only show base_back if it is needed */
445       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
446         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
447       }
449       /* Fetch all returned departments an add them to our divlist */
450       while($value = $ldap->fetch()){
451         if($value["description"][0]!=".."){
452           $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
453         }else{
454           $this->departments[$value['dn']]=$value["description"][0];
455         }
456       }
457       /* END NEW LIST MANAGMENT
458        */
460       // This links specifies the department open link 
461       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
463       /* Insert departments in divsel */
464       foreach($this->departments as $key=> $val){
465         if(!isset($this->config->departments[trim($key)])){
466           $this->config->departments[trim($key)]="";
467         }
468         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
469         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
470         $divSel->AddEntry(array($field1,$field2));
471       }
473       /* Append predefined Blocklists */
474       foreach($list as $entry => $value){
475         $divSel->AddEntry(array(
476               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
477               array("string"=>$value,"attach"=>"style='border:0px;'")
478               ));
479       }
481       /* Show dialog */
482       $smarty->assign("cblocklist", $this->current_blocklist);
483       $smarty->assign("departments", $this->config->idepartments);
484       $smarty->assign("divSelectPredefined", $divSel->DrawList());
485       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
486       return ($display);
487     }
489     /* Manage outgoing blocklists */
491     if ($this->out_blocklist_dialog){
493       /* This handles the divSelectBox */
495       /* The base specifies the current position in the ldap tree
496        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
497        */
498       $base = $_SESSION['Fax_Filter']['depselect'];
499       $ldap->cd($base);
501       /* Ge all Blocklists */ 
502       $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
503       while ($attrs= $ldap->fetch()){
504         if(isset($attrs['description'][0])){
505           $list[$attrs['cn'][0]]=
506             $attrs['description'][0].
507             " [".$attrs['cn'][0]."]";
508         }else{
509           $list[$attrs['cn'][0]]= $attrs['cn'][0];
510         }
511       }
513       /*Create DivSel*/
514       $divSel = new divSelectBox("divSelectPredefined");
515       $divSel->setHeight(296);
517       /* NEW LIST MANAGMENT
518        * We also need to search for the departments
519        * So we are able to navigate like in konquerer
520        */
521       $this->departments= array();
522       $ldap->ls("(objectClass=gosaDepartment)",$base);
524       /* Generate Back url, and append if it is needed */
525       $base_back = preg_replace("/^[^,]+,/","",$base);
526       if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
527         $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
528       }
530       /* Get all departments */
531       while($value = $ldap->fetch()){
532         if(isset($value["description"][0])){
533           $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
534         }else{
535           $this->departments[$value['dn']]=$value["description"][0];
536         }
537       }
538       /* END NEW LIST MANAGMENT
539        */
541       // Defining Links
542       $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
544       /* Insert departments in divlist*/
545       foreach($this->departments as $key=> $val){
546         if(!isset($this->config->departments[trim($key)])){
547           $this->config->departments[trim($key)]="";
548         }
550         $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
551         $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
552         $divSel->AddEntry(array($field1,$field2));
553       }
555       /* Append Blocklits */
556       foreach($list as $entry => $value){
557         $divSel->AddEntry(array(
558               array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
559               array("string"=>$value,"attach"=>"style='border:0px;'")
560               ));
561       }
563       /* Show dialog */
564       $smarty->assign("cblocklist", $this->current_blocklist);
565       $smarty->assign("departments", $this->config->idepartments);
566       $smarty->assign("divSelectPredefined", $divSel->DrawList());
567       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
568       return ($display);
569     }
572     /* Show main page */
573     $smarty->assign("languages", get_languages());
574     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
575     $smarty->assign("printers", $this->printerList);
577     /* Load attributes */
578     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
579           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
580           "facsimileAlternateTelephoneNumber", "mail") as $val){
582       $smarty->assign("$val", $this->$val);
583     }
585     $tmp = $this->plInfo();
586     foreach($tmp['plProvidedAcls'] as $acl => $desc){
587       $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
588     }
590     /* Load checkboxes */
591     if ($this->goFaxIsEnabled == "1"){
592       $smarty->assign("goFaxIsEnabled", "");
593     } else {
594       $smarty->assign("goFaxIsEnabled", "checked");
595     }
596     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
597     if ($this->goFaxDeliveryMode & 32) {
598       $smarty->assign("faxtomail", "checked");
599     } else {
600       $smarty->assign("faxtomail", "");
601     }
602     if ($this->goFaxDeliveryMode & 64) {
603       $smarty->assign("faxtoprinter", "checked");
604     } else {
605       $smarty->assign("faxtoprinter", "");
606     }
609     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
610     return ($display);
611   }
613   function remove_from_parent()
614   {
615     /* Cancel if there's nothing to do here */
616     if (!$this->initially_was_account){
617       return;
618     }
620     plugin::remove_from_parent();
622     /* Adapt mail settings if needed */
623     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
624       unset($this->attrs['mail']);
625     }
627     $ldap= $this->config->get_ldap_link();
628     $ldap->cd($this->dn);
629     $this->cleanup();
630     $ldap->modify ($this->attrs); 
632     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
634     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
636     /* Optionally execute a command after we're done */
637     $this->handle_post_events('remove',array("uid"=> $this->uid));
638   }
641   /* Check formular input */
642   function check()
643   {
644     /* Call common method to give check the hook */
645     $message= plugin::check();
647     /* must: facsimileTelephoneNumber */
648     if ($this->facsimileTelephoneNumber == ""){
649       $message[]= _("The required field 'Fax' is not set.");
650     }
652     if (!is_phone_nr($this->facsimileTelephoneNumber)){
653       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
654     }
656     /* IF mail is specified (which is only the case if there's no mail account
657        present), check if it's valid..  */
658     if (@isset($this->parent->by_object['mailAccount']) &&
659         $this->goFaxDeliveryMode & 32){
660       if ($this->mail == ""){
661         $message[]= _("Mail delivery is checked, but no address has been specified.");
662       } elseif (!is_email($this->mail)){
663         $message[]= _("The mail address you've entered is invalid.");
664       }
665     }
667     // IE Fix, IE lets you choose disabled option, stupid browser ... 
668     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
669       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
670     }
672     return ($message);
673   }
675   /* Save data to object */
676   function save_object()
677   {
678     $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
679     if (isset($_POST['faxTab'])){
680       plugin::save_object();
683       $tmp = 0+$this->goFaxDeliveryMode;
685       if($this->acl_is_writeable("faxtomail",$edit_mode)){
686         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
687           $tmp |= 32;
688         }elseif($tmp & 32){
689           $tmp &= (!32);
690         }
691       }
692       if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
693         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
694           $tmp |= 64;
695         }elseif($tmp & 64){
696           $tmp &= !64;
697         }
698       }
699       $this->goFaxDeliveryMode = $tmp;
701       if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
702         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
703           $this->goFaxIsEnabled= "0";
704         } else {
705           $this->goFaxIsEnabled= "1";
706         }
707       }
709     
710       if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
711         $this->mail= $_POST['mail'];
712       }
714       /* Check if mail account is active and correct the internal
715          reference to represent the current status. */
716       if(isset($this->parent)){
717         if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
718           $this->has_mailAccount= TRUE;
719         }
720       }
721     }
723   }
726   /* Save to LDAP */
727   function save()
728   {
729     plugin::save();
731     /* Save arrays */
732     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
733           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
735       $this->attrs[$val]= $this->$val;
736     }
738     if(!$this->attrs['goFaxDeliveryMode']){
739       $this->attrs['goFaxDeliveryMode'] = 0;
740     }
741   
742     /* Do not save mail address ... it was possibly changed by mail plugin */
743     /* Adapt mail settings if needed */
744     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
745       unset($this->attrs['mail']);
746     }
748     /* Write back to ldap */
749     $ldap= $this->config->get_ldap_link();
750     $ldap->cd($this->dn);
751     $this->cleanup();
752     $ldap->modify ($this->attrs); 
754     /* Log last action */
755     if($this->initially_was_account){
756       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
757     }else{
758       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
759     }
761     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
763     /* Optionally execute a command after we're done */
764     if ($this->initially_was_account == $this->is_account){
765       if ($this->is_modified){
766         $this->handle_post_events("mofidy",array("uid" => $this->uid));
767       }
768     } else {
769       $this->handle_post_events("add",array("uid" => $this->uid));
770     }
772   }
775   /* Adapt from template, using 'dn' */
776   function adapt_from_template($dn)
777   {
778     plugin::adapt_from_template($dn);
780     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
781           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
783       if (isset($this->attrs[$val])){
784         $this->$val= $this->attrs[$val];
785       }
786     }
787   }
791   /* Add alternate fax recipient */
792   function addAlternate($number)
793   {
794     $this->facsimileAlternateTelephoneNumber[]= "$number";
795     $this->facsimileAlternateTelephoneNumber=
796       array_unique ($this->facsimileAlternateTelephoneNumber);
798     sort ($this->facsimileAlternateTelephoneNumber);
799     reset ($this->facsimileAlternateTelephoneNumber);
800   }
802   function delAlternate($numbers)
803   {
804     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
805         $this->facsimileAlternateTelephoneNumber);
806   }
808   function getCopyDialog()
809   {
810     $str    = "";
811     $smarty = get_smarty();
812     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
813     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
814     $str['status'] ="";
815     return($str);
816   }
818   function SaveCopyDialog()
819   {
820     if(isset($_POST['facsimileTelephoneNumber'])){
821       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
822     }
823   }
826   /* Return plugin informations for acl handling 
827       #FIXME some attributes are still missing in this plugin acls */
828   function plInfo()
829   {
830     return (array(  
831           "plShortName"     => _("Fax"),
832           "plDescription"   => _("Fax account settings"),
833           "plSelfModify"    => TRUE,
834           "plDepends"       => array("user"),
835           "plPriority"      => 6,             
836           "plSection"       => "personal",  
837           "plCategory"      => array("users"),
838           "plOptions"       => array(),
840           "plProvidedAcls"  => array(
841             "goFaxIsEnabled"                    => _("Enable/Disable fax"),
842             "goFaxRBlocklist"                   => _("Receive blocklist"),
843             "goFaxSBlocklist"                   => _("Send blocklist"),
844             "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
845             "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
846             "faxtomail"                         => _("Deliver fax as mail"),
847             "faxtoprinter"                      => _("Deliver fax to printer"),
848             "goFaxFormat"                       => _("Delivery format"),
849             "goFaxLanguage"                     => _("Language"))
850           ));
851   }
854 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
855 ?>