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_strict("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\"> <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_strict($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){
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();
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']."&act=dep_open&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']."&act=dep_open&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_strict($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_strict($attr,$this->multi_boxes)) {
580 $smarty->assign("use_".$attr,TRUE);
581 }else{
582 $smarty->assign("use_".$attr,FALSE);
583 }
584 }
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 // check for a valid Mail-Address in case of 'delivery to mailbox'
637 $mailAccount = (isset($this->parent->by_object['mailAccount']) && $this->parent->by_object['mailAccount']->is_account);
638 if(!$mailAccount && $this->goFaxDeliveryMode & 32){
639 if ($this->mail == ""){
640 $message[]= _("Mail delivery is requested without target address!");
641 } elseif (!tests::is_email($this->mail)){
642 $message[]= msgPool::invalid(_("Mail address"),"","",_("your-name@your-domain.com"));
643 }
644 }
646 // IE Fix, IE lets you choose disabled option, stupid browser ...
647 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
648 $message[]= _("Printing is requested without a target printer!");
649 }
651 return ($message);
652 }
654 /* Save data to object */
655 function save_object()
656 {
657 $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
658 if (isset($_POST['faxTab'])){
659 plugin::save_object();
662 $tmp = 0+$this->goFaxDeliveryMode;
664 if($this->acl_is_writeable("faxtomail",$edit_mode)){
665 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
666 $tmp |= 32;
667 }elseif($tmp & 32){
668 $tmp &= (!32);
669 }
670 }
671 if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
672 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
673 $tmp |= 64;
674 }elseif($tmp & 64){
675 $tmp &= !64;
676 }
677 }
678 $this->goFaxDeliveryMode = $tmp;
680 if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
681 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
682 $this->goFaxIsEnabled= "0";
683 } else {
684 $this->goFaxIsEnabled= "1";
685 }
686 }
689 if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
690 $this->mail= $_POST['mail'];
691 }
693 /* Check if mail account is active and correct the internal
694 reference to represent the current status. */
695 if(isset($this->parent)){
696 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
697 $this->has_mailAccount= TRUE;
698 }
699 }
700 }
702 }
705 /* Save to LDAP */
706 function save()
707 {
708 plugin::save();
710 /* Save arrays */
711 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
712 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
714 $this->attrs[$val]= $this->$val;
715 }
717 if(!$this->attrs['goFaxDeliveryMode']){
718 $this->attrs['goFaxDeliveryMode'] = 0;
719 }
721 /* Do not save mail address ... it was possibly changed by mail plugin */
722 /* Adapt mail settings if needed */
723 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
724 unset($this->attrs['mail']);
725 }
727 /* Write back to ldap */
728 $ldap= $this->config->get_ldap_link();
729 $ldap->cd($this->dn);
730 $this->cleanup();
731 $ldap->modify ($this->attrs);
733 /* Log last action */
734 if($this->initially_was_account){
735 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
736 }else{
737 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
738 }
740 if (!$ldap->success()){
741 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
742 }
744 /* Optionally execute a command after we're done */
745 if ($this->initially_was_account == $this->is_account){
746 if ($this->is_modified){
747 $this->handle_post_events("modify",array("uid" => $this->uid));
748 }
749 } else {
750 $this->handle_post_events("add",array("uid" => $this->uid));
751 }
753 }
756 /* Adapt from template, using 'dn' */
757 function adapt_from_template($dn, $skip= array())
758 {
759 plugin::adapt_from_template($dn, $skip);
761 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
762 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
764 if (in_array_strict($val, $skip)){
765 continue;
766 }
768 if (isset($this->attrs[$val])){
769 $this->$val= $this->attrs[$val];
770 }
771 }
772 }
776 /* Add alternate fax recipient */
777 function addAlternate($number)
778 {
779 $this->facsimileAlternateTelephoneNumber[]= "$number";
780 $this->facsimileAlternateTelephoneNumber=
781 array_unique ($this->facsimileAlternateTelephoneNumber);
783 sort ($this->facsimileAlternateTelephoneNumber);
784 reset ($this->facsimileAlternateTelephoneNumber);
785 }
787 function delAlternate($numbers)
788 {
789 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
790 $this->facsimileAlternateTelephoneNumber);
791 }
793 function getCopyDialog()
794 {
795 $str = "";
796 $smarty = get_smarty();
797 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
798 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
799 $str['status'] ="";
800 return($str);
801 }
803 function SaveCopyDialog()
804 {
805 if(isset($_POST['facsimileTelephoneNumber'])){
806 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
807 }
808 }
811 /* Return plugin informations for acl handling
812 #FIXME some attributes are still missing in this plugin acls */
813 static function plInfo()
814 {
815 return (array(
816 "plShortName" => _("Fax"),
817 "plDescription" => _("Fax account settings"),
818 "plSelfModify" => TRUE,
819 "plDepends" => array("user"),
820 "plPriority" => 6,
821 "plSection" => "personal",
822 "plCategory" => array("users"),
823 "plOptions" => array(),
825 "plProvidedAcls" => array(
826 "facsimileTelephoneNumber" => _("Fax number"), // goFaxDeliveryMode
827 "goFaxLanguage" => _("Language"),
828 "goFaxFormat" => _("Delivery format"),
829 "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
830 "goFaxIsEnabled" => _("Enable/Disable fax"),
831 "faxtomail" => _("Deliver fax as mail"),
832 "faxtoprinter" => _("Deliver fax to printer"),
833 "goFaxRBlocklist" => _("Receive blocklist"),
834 "goFaxSBlocklist" => _("Send blocklist"))
835 ));
836 }
838 /* Multiple edit support
839 */
841 /* Execute */
842 function multiple_execute()
843 {
844 return($this->execute());
845 }
847 function multiple_save_object()
848 {
849 if (isset($_POST['faxTab'])){
850 plugin::multiple_save_object();
851 foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
852 if(isset($_POST["use_".$attr])){
853 $this->multi_boxes[] = $attr;
854 }
855 }
857 $tmp = 0+$this->goFaxDeliveryMode;
858 if(in_array_strict("faxtomail",$this->multi_boxes)){
859 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
860 $tmp |= 32;
861 }elseif($tmp & 32){
862 $tmp &= (!32);
863 }
864 }
865 if(in_array_strict("faxtoprinter",$this->multi_boxes)){
866 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
867 $tmp |= 64;
868 }elseif($tmp & 64){
869 $tmp &= !64;
870 }
871 }
872 $this->goFaxDeliveryMode = $tmp;
874 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
875 $this->goFaxIsEnabled= "0";
876 } else {
877 $this->goFaxIsEnabled= "1";
878 }
879 if (isset($_POST['mail']) && in_array_strict("mail",$this->multi_boxes)){
880 $this->mail= $_POST['mail'];
881 }
882 }
883 }
885 function get_multi_edit_values()
886 {
887 $ret = plugin::get_multi_edit_values();
888 if(in_array_strict("goFaxIsEnabled",$this->multi_boxes)){
889 $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
890 }
891 if(in_array_strict("faxtoprinter",$this->multi_boxes)){
892 $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
893 }
894 if(in_array_strict("faxtomail",$this->multi_boxes)){
895 $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
896 }
898 if(in_array_strict("edit_incoming",$this->multi_boxes)){
899 $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
900 $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
901 }
902 if(in_array_strict("edit_outgoing",$this->multi_boxes)){
903 $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
904 $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
905 }
906 return($ret);
907 }
909 function multiple_check()
910 {
911 $message = plugin::multiple_check();
912 return($message);
913 }
915 function set_multi_edit_values($values)
916 {
917 plugin::set_multi_edit_values($values);
919 if(isset($values['faxtoprinter'])){
920 if($values['faxtoprinter']){
921 $this->goFaxDeliveryMode |= 64;
922 }else{
923 $this->goFaxDeliveryMode &= !64;
924 }
925 }
926 if(isset($values['faxtomail'])){
927 if($values['faxtomail']){
928 $this->goFaxDeliveryMode |= 32;
929 }else{
930 $this->goFaxDeliveryMode &= !32;
931 }
932 }
933 }
934 }
936 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
937 ?>