Code

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