Code

Converted a couple of == / === NULL references
[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(TRUE));
575     $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
576     $smarty->assign("printers", $this->printerList);
578     /* Load attributes */
579     foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
580           "goFaxPrinter", "goFaxLanguage", "goFaxFormat", 
581           "facsimileAlternateTelephoneNumber", "mail") as $val){
583       $smarty->assign("$val", $this->$val);
584     }
586     $tmp = $this->plInfo();
587     foreach($tmp['plProvidedAcls'] as $acl => $desc){
588       $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
589     }
591     /* Load checkboxes */
592     if ($this->goFaxIsEnabled == "1"){
593       $smarty->assign("goFaxIsEnabled", "");
594     } else {
595       $smarty->assign("goFaxIsEnabled", "checked");
596     }
597     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
598     if ($this->goFaxDeliveryMode & 32) {
599       $smarty->assign("faxtomail", "checked");
600     } else {
601       $smarty->assign("faxtomail", "");
602     }
603     if ($this->goFaxDeliveryMode & 64) {
604       $smarty->assign("faxtoprinter", "checked");
605     } else {
606       $smarty->assign("faxtoprinter", "");
607     }
610     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
611     return ($display);
612   }
614   function remove_from_parent()
615   {
616     /* Cancel if there's nothing to do here */
617     if (!$this->initially_was_account){
618       return;
619     }
621     plugin::remove_from_parent();
623     /* Adapt mail settings if needed */
624     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
625       unset($this->attrs['mail']);
626     }
628     $ldap= $this->config->get_ldap_link();
629     $ldap->cd($this->dn);
630     $this->cleanup();
631     $ldap->modify ($this->attrs); 
633     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
635     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
637     /* Optionally execute a command after we're done */
638     $this->handle_post_events('remove',array("uid"=> $this->uid));
639   }
642   /* Check formular input */
643   function check()
644   {
645     /* Call common method to give check the hook */
646     $message= plugin::check();
648     /* must: facsimileTelephoneNumber */
649     if ($this->facsimileTelephoneNumber == ""){
650       $message[]= _("The required field 'Fax' is not set.");
651     }
653     if (!is_phone_nr($this->facsimileTelephoneNumber)){
654       $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
655     }
657     /* IF mail is specified (which is only the case if there's no mail account
658        present), check if it's valid..  */
659     if (@isset($this->parent->by_object['mailAccount']) &&
660         $this->goFaxDeliveryMode & 32){
661       if ($this->mail == ""){
662         $message[]= _("Mail delivery is checked, but no address has been specified.");
663       } elseif (!is_email($this->mail)){
664         $message[]= _("The mail address you've entered is invalid.");
665       }
666     }
668     // IE Fix, IE lets you choose disabled option, stupid browser ... 
669     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
670       $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
671     }
673     return ($message);
674   }
676   /* Save data to object */
677   function save_object()
678   {
679     $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
680     if (isset($_POST['faxTab'])){
681       plugin::save_object();
684       $tmp = 0+$this->goFaxDeliveryMode;
686       if($this->acl_is_writeable("faxtomail",$edit_mode)){
687         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
688           $tmp |= 32;
689         }elseif($tmp & 32){
690           $tmp &= (!32);
691         }
692       }
693       if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
694         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
695           $tmp |= 64;
696         }elseif($tmp & 64){
697           $tmp &= !64;
698         }
699       }
700       $this->goFaxDeliveryMode = $tmp;
702       if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
703         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
704           $this->goFaxIsEnabled= "0";
705         } else {
706           $this->goFaxIsEnabled= "1";
707         }
708       }
710     
711       if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
712         $this->mail= $_POST['mail'];
713       }
715       /* Check if mail account is active and correct the internal
716          reference to represent the current status. */
717       if(isset($this->parent)){
718         if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
719           $this->has_mailAccount= TRUE;
720         }
721       }
722     }
724   }
727   /* Save to LDAP */
728   function save()
729   {
730     plugin::save();
732     /* Save arrays */
733     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
734           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
736       $this->attrs[$val]= $this->$val;
737     }
739     if(!$this->attrs['goFaxDeliveryMode']){
740       $this->attrs['goFaxDeliveryMode'] = 0;
741     }
742   
743     /* Do not save mail address ... it was possibly changed by mail plugin */
744     /* Adapt mail settings if needed */
745     if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
746       unset($this->attrs['mail']);
747     }
749     /* Write back to ldap */
750     $ldap= $this->config->get_ldap_link();
751     $ldap->cd($this->dn);
752     $this->cleanup();
753     $ldap->modify ($this->attrs); 
755     /* Log last action */
756     if($this->initially_was_account){
757       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
758     }else{
759       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
760     }
762     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
764     /* Optionally execute a command after we're done */
765     if ($this->initially_was_account == $this->is_account){
766       if ($this->is_modified){
767         $this->handle_post_events("mofidy",array("uid" => $this->uid));
768       }
769     } else {
770       $this->handle_post_events("add",array("uid" => $this->uid));
771     }
773   }
776   /* Adapt from template, using 'dn' */
777   function adapt_from_template($dn)
778   {
779     plugin::adapt_from_template($dn);
781     foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
782           "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
784       if (isset($this->attrs[$val])){
785         $this->$val= $this->attrs[$val];
786       }
787     }
788   }
792   /* Add alternate fax recipient */
793   function addAlternate($number)
794   {
795     $this->facsimileAlternateTelephoneNumber[]= "$number";
796     $this->facsimileAlternateTelephoneNumber=
797       array_unique ($this->facsimileAlternateTelephoneNumber);
799     sort ($this->facsimileAlternateTelephoneNumber);
800     reset ($this->facsimileAlternateTelephoneNumber);
801   }
803   function delAlternate($numbers)
804   {
805     $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
806         $this->facsimileAlternateTelephoneNumber);
807   }
809   function getCopyDialog()
810   {
811     $str    = "";
812     $smarty = get_smarty();
813     $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
814     $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
815     $str['status'] ="";
816     return($str);
817   }
819   function SaveCopyDialog()
820   {
821     if(isset($_POST['facsimileTelephoneNumber'])){
822       $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
823     }
824   }
827   /* Return plugin informations for acl handling 
828       #FIXME some attributes are still missing in this plugin acls */
829   function plInfo()
830   {
831     return (array(  
832           "plShortName"     => _("Fax"),
833           "plDescription"   => _("Fax account settings"),
834           "plSelfModify"    => TRUE,
835           "plDepends"       => array("user"),
836           "plPriority"      => 6,             
837           "plSection"       => "personal",  
838           "plCategory"      => array("users"),
839           "plOptions"       => array(),
841           "plProvidedAcls"  => array(
842             "goFaxIsEnabled"                    => _("Enable/Disable fax"),
843             "goFaxRBlocklist"                   => _("Receive blocklist"),
844             "goFaxSBlocklist"                   => _("Send blocklist"),
845             "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
846             "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
847             "faxtomail"                         => _("Deliver fax as mail"),
848             "faxtoprinter"                      => _("Deliver fax to printer"),
849             "goFaxFormat"                       => _("Delivery format"),
850             "goFaxLanguage"                     => _("Language"))
851           ));
852   }
855 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
856 ?>