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();
41 /* attribute list for save action */
42 var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","goFaxRBlockgroups","facsimileAlternateTelephoneNumber","facsimileTelephoneNumber",
43 "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail");
44 var $objectclasses= array("goFaxAccount");
46 function gofaxAccount ($config, $dn= NULL)
47 {
48 /* General initialization */
49 plugin::plugin ($config, $dn);
52 /* Hickert : 11.11.05
53 * Added to be able to handle department selection in divSelelect
54 */
55 if(!isset($_SESSION["Fax_Filter"])){
56 $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
57 }
59 if ($dn != "new"){
60 /* Get arrays */
61 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
62 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
63 $this->$val =array();
64 if (isset($this->attrs["$val"]["count"])){
65 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
66 array_push($this->$val, $this->attrs["$val"][$i]);
67 }
68 }
69 }
71 /* Set up has_mailAccount */
72 if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
73 $this->has_mailAccount= TRUE;
74 }
75 }
77 /* Load printer list */
78 if (isset($this->config->data['SERVERS']['CUPS'])){
79 $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
80 asort ($this->printerList);
81 }
83 /* Get global filter config */
84 if (!is_global("faxfilter")){
85 $ui= get_userinfo();
86 $base= get_base_from_people($ui->dn);
87 $faxfilter= array( "depselect" => $base,
88 "fuser" => "*",
89 "regex" => "");
90 register_global("faxfilter", $faxfilter);
91 }
92 }
94 function execute()
95 {
96 /* Call parent execute */
97 plugin::execute();
98 /* Hickert : 11.11.05
99 * Added to be able to handle department selection in divSelelect
100 */
101 if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
103 if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
104 $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
105 }else{
106 $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
107 }
108 }
110 /* Load smarty stuff */
111 $smarty= get_smarty();
113 /* Check if mail account is active. We'll display an additional
114 mail address field if this is not the case. Some people may
115 want goFax, but have a mailserver which is not managed with
116 GOsa */
117 if (!@isset($this->parent->by_object['mailAccount'])) {
118 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
119 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
120 $smarty->assign("has_mailaccount", "false");
121 $this->has_mailAccount= false;
122 } else {
123 $smarty->assign("has_mailaccount", "true");
124 }
126 /* Do we need to flip is_account state? */
127 if (isset($_POST['modify_state'])){
128 $this->is_account= !$this->is_account;
129 }
131 /* Do we represent a valid account? */
132 if (!$this->is_account && $this->parent == NULL){
133 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
134 _("This account has no fax extensions.")."</b>";
135 $display.= back_to_main();
136 return ($display);
137 }
139 /* Show tab dialog headers */
140 $display= "";
141 if ($this->parent != NULL){
142 if ($this->is_account){
143 $display= $this->show_disable_header(_("Remove fax account"),
144 _("This account has fax features enabled. You can disable them by clicking below."));
145 } else {
146 $display= $this->show_enable_header(_("Create fax account"),
147 _("This account has fax features disabled. You can enable them by clicking below."));
148 return ($display);
149 }
150 }
152 /* Trigger Add local fax alternatives dialog */
153 if (isset($_POST['add_local_alternate'])){
154 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
155 $this->locals_dialog= TRUE;
156 $this->dialog= TRUE;
157 }
158 }
160 /* Add alternatives from dialog */
161 if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
162 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
163 foreach ($_POST['local_list'] as $val){
164 $this->addAlternate($val);
165 $this->is_modified= TRUE;
166 }
167 }
168 }
170 /* Add alternatives */
171 if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){
172 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
173 $this->addAlternate($_POST['forward_address']);
174 }
175 }
177 /* Delete alternate fax number */
178 if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){
179 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
180 $this->delAlternate ($_POST['alternate_list']);
181 }
182 }
185 /* Edit incoming blocklists */
186 if (isset($_POST['edit_incoming'])){
187 if($this->acl_is_writeable("goFaxRBlocklist")) {
188 $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
189 sort($this->current_blocklist);
190 reset($this->current_blocklist);
192 $this->in_blocklist_dialog= TRUE;
193 $this->dialog= TRUE;
194 }
195 }
197 /* Edit outgoing blocklists */
198 if (isset($_POST['edit_outgoing'])){
199 $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
200 sort($this->current_blocklist);
201 reset($this->current_blocklist);
203 $this->out_blocklist_dialog= TRUE;
204 $this->dialog= TRUE;
205 }
207 /* Add number to blocklist (dialog) */
208 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
209 if (!is_phone_nr($_POST['block_number'])){
210 print_red (_("You're trying to add an invalid phone number."));
211 } else {
212 array_push($this->current_blocklist, $_POST['block_number']);
213 $this->current_blocklist= array_unique($this->current_blocklist);
214 sort($this->current_blocklist);
215 reset($this->current_blocklist);
216 }
217 }
219 /* Hickert : 11.11.05
220 * Add selection from divSelelect to our Blocklist
221 */
222 /* Add list to blocklist */
223 if (isset($_POST['add_blocklist'])){
224 foreach($_POST as $name => $value){
225 if(preg_match("/ADDLIST_/i",$name)){
226 $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
228 }
229 }
230 $this->current_blocklist= array_unique($this->current_blocklist);
231 sort($this->current_blocklist);
232 reset($this->current_blocklist);
233 }
235 /* Add list to blocklist */
236 if (isset($_GET['add'])){
237 if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
238 $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
239 $this->current_blocklist= array_unique($this->current_blocklist);
240 sort($this->current_blocklist);
241 reset($this->current_blocklist);
242 }
244 /* Delete from blocklist */
245 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
246 $tmp= array();
247 foreach($this->current_blocklist as $val){
248 if (!in_array($val, $_POST['block_list'])){
249 $tmp[]= $val;
250 }
251 }
252 $this->current_blocklist= $tmp;
253 }
256 /* Blocklist edit finished */
257 if (isset($_POST['edit_blocklists_finish'])){
259 /* Incoming or outgoing? */
260 if ($this->in_blocklist_dialog){
261 $this->goFaxRBlocklist = array();
262 $this->goFaxRBlockgroups = array();
264 foreach ($this->current_blocklist as $val){
265 if (is_phone_nr($val)){
266 $this->goFaxRBlocklist[]=$val;
267 } else {
268 $this->goFaxRBlockgroups[]= $val;
269 }
270 }
271 } else {
272 $this->goFaxSBlocklist = array();
273 $this->goFaxSBlockgroups = array();
275 /* Transfer values to ourself */
276 foreach ($this->current_blocklist as $val){
277 if (is_phone_nr($val)){
278 $this->goFaxSBlocklist[]=$val;
279 } else {
280 $this->goFaxSBlockgroups[]= $val;
281 }
282 }
283 }
284 $this->is_modified= TRUE;
285 }
288 /* Set departments */
289 if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
291 $list= array ();
292 $ldap= $this->config->get_ldap_link();
293 if (isset ($_POST['department'])){
294 $ldap->cd ($_POST['department']);
295 } else {
296 $ldap->cd ($this->config->current['BASE']);
297 }
298 }
300 /* Cancel dialogs */
301 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
302 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
304 $this->locals_dialog= FALSE;
305 $this->in_blocklist_dialog= FALSE;
306 $this->out_blocklist_dialog= FALSE;
307 $this->dialog= FALSE;
308 }
310 /* Manage locals dialog */
311 if ($this->locals_dialog){
313 /* Save data */
314 $faxfilter= get_global("faxfilter");
315 foreach( array("depselect", "fuser", "regex") as $type){
316 if (isset($_POST[$type])){
317 $faxfilter[$type]= $_POST[$type];
318 }
319 }
320 if (isset($_GET['search'])){
321 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
322 if ($s == "**"){
323 $s= "*";
324 }
325 $faxfilter['fuser']= $s;
326 }
328 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
329 $regex= $faxfilter['regex'];
330 $filter= "(facimileTelephoneNumber=$regex)";
331 } else {
332 $filter= "";
333 }
334 if ($faxfilter['fuser'] != ""){
335 $user= $faxfilter['fuser'];
336 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
337 }
339 $base= $faxfilter['depselect'];
340 $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base,
341 array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
343 foreach ($res as $attrs){
344 $list[$attrs['facsimileTelephoneNumber'][0]]=
345 $attrs['sn'][0].", ".
346 $attrs['givenName'][0]." [".
347 $attrs['facsimileTelephoneNumber'][0]."]";
348 }
350 /* Show dialog */
351 $smarty->assign("search_image", get_template_path('images/search.png'));
352 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
353 $smarty->assign("tree_image", get_template_path('images/tree.png'));
354 $smarty->assign("infoimage", get_template_path('images/info.png'));
355 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
356 $smarty->assign("departments", $this->config->idepartments);
357 $smarty->assign("list", $list);
358 if (isset($_POST['depselect'])){
359 $smarty->assign("depselect", $_POST['depselect']);
360 }
361 $smarty->assign("deplist", $this->config->idepartments);
362 $smarty->assign("apply", apply_filter());
363 $smarty->assign("alphabet", generate_alphabet());
364 $smarty->assign("hint", print_sizelimit_warning());
365 foreach( array("depselect", "fuser", "regex") as $type){
366 $smarty->assign("$type", $faxfilter[$type]);
367 }
368 $smarty->assign("hint", print_sizelimit_warning());
370 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
371 return ($display);
372 }
375 /* Manage incoming blocklists */
376 if ($this->in_blocklist_dialog){
378 /* This handles the divSelectBox */
380 /* The base specifies the current position in the ldap tree
381 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
382 */
383 $base = $_SESSION['Fax_Filter']['depselect'];
384 $ldap->cd($base);
386 /* Ge all Blocklists */
387 $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
388 while ($attrs= $ldap->fetch()){
390 /* Generate list depending on description */
391 if(isset($attrs['description'][0])){
392 $list[$attrs['cn'][0]]=
393 $attrs['description'][0].
394 " [".$attrs['cn'][0]."]";
395 }else{
396 $list[$attrs['cn'][0]]= $attrs['cn'][0];
397 }
398 }
400 /* Create our divselect box */
401 $divSel = new divSelectBox("divSelectPredefined");
402 $divSel->setHeight(296);
404 /* NEW LIST MANAGMENT
405 * We also need to search for the departments
406 * So we are able to navigate like in konquerer
407 */
408 $this->departments= array();
410 /* Get all departments within the current department */
411 $base = $_SESSION['Fax_Filter']['depselect'];
412 $ldap->ls("(objectClass=gosaDepartment)",$base);
414 /* Base back is used to go one department up in our ldap tree */
415 $base_back = preg_replace("/^[^,]+,/","",$base);
417 /* Only show base_back if it is needed */
418 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
419 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
420 }
422 /* Fetch all returned departments an add them to our divlist */
423 while($value = $ldap->fetch()){
424 if($value["description"][0]!=".."){
425 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
426 }else{
427 $this->departments[$value['dn']]=$value["description"][0];
428 }
429 }
430 /* END NEW LIST MANAGMENT
431 */
433 // This links specifies the department open link
434 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
436 /* Insert departments in divsel */
437 foreach($this->departments as $key=> $val){
438 if(!isset($this->config->departments[trim($key)])){
439 $this->config->departments[trim($key)]="";
440 }
441 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
442 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
443 $divSel->AddEntry(array($field1,$field2));
444 }
446 /* Append predefined Blocklists */
447 foreach($list as $entry => $value){
448 $divSel->AddEntry(array(
449 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
450 array("string"=>$value,"attach"=>"style='border:0px;'")
451 ));
452 }
454 /* Show dialog */
455 $smarty->assign("cblocklist", $this->current_blocklist);
456 $smarty->assign("departments", $this->config->idepartments);
457 $smarty->assign("divSelectPredefined", $divSel->DrawList());
458 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
459 return ($display);
460 }
462 /* Manage outgoing blocklists */
464 if ($this->out_blocklist_dialog){
466 /* This handles the divSelectBox */
468 /* The base specifies the current position in the ldap tree
469 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
470 */
471 $base = $_SESSION['Fax_Filter']['depselect'];
472 $ldap->cd($base);
474 /* Ge all Blocklists */
475 $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
476 while ($attrs= $ldap->fetch()){
477 if(isset($attrs['description'][0])){
478 $list[$attrs['cn'][0]]=
479 $attrs['description'][0].
480 " [".$attrs['cn'][0]."]";
481 }else{
482 $list[$attrs['cn'][0]]= $attrs['cn'][0];
483 }
484 }
486 /*Create DivSel*/
487 $divSel = new divSelectBox("divSelectPredefined");
488 $divSel->setHeight(296);
490 /* NEW LIST MANAGMENT
491 * We also need to search for the departments
492 * So we are able to navigate like in konquerer
493 */
494 $this->departments= array();
495 $ldap->ls("(objectClass=gosaDepartment)",$base);
497 /* Generate Back url, and append if it is needed */
498 $base_back = preg_replace("/^[^,]+,/","",$base);
499 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
500 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
501 }
503 /* Get all departments */
504 while($value = $ldap->fetch()){
505 if(isset($value["description"][0])){
506 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
507 }else{
508 $this->departments[$value['dn']]=$value["description"][0];
509 }
510 }
511 /* END NEW LIST MANAGMENT
512 */
514 // Defining Links
515 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
517 /* Insert departments in divlist*/
518 foreach($this->departments as $key=> $val){
519 if(!isset($this->config->departments[trim($key)])){
520 $this->config->departments[trim($key)]="";
521 }
523 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
524 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
525 $divSel->AddEntry(array($field1,$field2));
526 }
528 /* Append Blocklits */
529 foreach($list as $entry => $value){
530 $divSel->AddEntry(array(
531 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
532 array("string"=>$value,"attach"=>"style='border:0px;'")
533 ));
534 }
536 /* Show dialog */
537 $smarty->assign("cblocklist", $this->current_blocklist);
538 $smarty->assign("departments", $this->config->idepartments);
539 $smarty->assign("divSelectPredefined", $divSel->DrawList());
540 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
541 return ($display);
542 }
545 /* Show main page */
546 $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
547 $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
548 $smarty->assign("printers", $this->printerList);
550 /* Load attributes */
551 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
552 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
553 "facsimileAlternateTelephoneNumber", "mail") as $val){
555 $smarty->assign("$val", $this->$val);
556 }
558 $tmp = $this->plInfo();
559 foreach($tmp['plProvidedAcls'] as $acl => $desc){
560 $smarty->assign($acl."ACL",$this->getacl($acl));
561 }
563 /* Load checkboxes */
564 if ($this->goFaxIsEnabled == "1"){
565 $smarty->assign("goFaxIsEnabled", "");
566 } else {
567 $smarty->assign("goFaxIsEnabled", "checked");
568 }
569 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
570 if ($this->goFaxDeliveryMode & 32) {
571 $smarty->assign("faxtomail", "checked");
572 } else {
573 $smarty->assign("faxtomail", "");
574 }
575 if ($this->goFaxDeliveryMode & 64) {
576 $smarty->assign("faxtoprinter", "checked");
577 } else {
578 $smarty->assign("faxtoprinter", "");
579 }
582 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
583 return ($display);
584 }
586 function remove_from_parent()
587 {
588 /* Cancel if there's nothing to do here */
589 if (!$this->initially_was_account){
590 return;
591 }
593 plugin::remove_from_parent();
595 /* Zero out arrays */
596 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
597 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
599 $this->attrs[$val]= array();
600 }
602 /* Adapt mail settings if needed */
603 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
604 unset($this->attrs['mail']);
605 }
607 $ldap= $this->config->get_ldap_link();
608 $ldap->cd($this->dn);
609 $this->cleanup();
610 $ldap->modify ($this->attrs);
612 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
614 /* Optionally execute a command after we're done */
615 $this->handle_post_events('remove');
616 }
619 /* Check formular input */
620 function check()
621 {
622 /* Call common method to give check the hook */
623 $message= plugin::check();
625 /* must: facsimileTelephoneNumber */
626 if ($this->facsimileTelephoneNumber == ""){
627 $message[]= _("The required field 'Fax' is not set.");
628 }
630 if (!is_phone_nr($this->facsimileTelephoneNumber)){
631 $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
632 }
634 /* IF mail is specified (which is only the case if there's no mail account
635 present), check if it's valid.. */
636 if (@isset($this->parent->by_object['mailAccount']) &&
637 $this->goFaxDeliveryMode && 32){
638 if ($this->mail == ""){
639 $message[]= _("Mail delivery is checked, but no address has been specified.");
640 } elseif (!is_email($this->mail)){
641 $message[]= _("The mail address you've entered is invalid.");
642 }
643 }
645 // IE Fix, IE lets you choose disabled option, stupid browser ...
646 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
647 $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
648 }
650 return ($message);
651 }
653 /* Save data to object */
654 function save_object()
655 {
656 if (isset($_POST['faxTab'])){
657 plugin::save_object();
660 $tmp = 0+$this->goFaxDeliveryMode;
662 if($this->acl_is_writeable("faxtomail")){
663 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
664 $tmp |= 32;
665 }elseif($tmp & 32){
666 $tmp &= (!32);
667 }
668 }
669 if($this->acl_is_writeable("faxtoprinter")){
670 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
671 $tmp |= 64;
672 }elseif($tmp & 64){
673 $tmp &= !64;
674 }
675 }
676 $this->goFaxDeliveryMode = $tmp;
678 if($this->acl_is_writeable("goFaxIsEnabled")){
679 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
680 $this->goFaxIsEnabled= "0";
681 } else {
682 $this->goFaxIsEnabled= "1";
683 }
684 }
687 if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail")){
688 $this->mail= $_POST['mail'];
689 }
691 /* Check if mail account is active and correct the internal
692 reference to represent the current status. */
693 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
694 $this->has_mailAccount= TRUE;
695 }
696 }
698 }
701 /* Save to LDAP */
702 function save()
703 {
704 plugin::save();
706 /* Save arrays */
707 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
708 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
710 $this->attrs[$val]= $this->$val;
711 }
713 if(!$this->attrs['goFaxDeliveryMode']){
714 $this->attrs['goFaxDeliveryMode'] = 0;
715 }
717 /* Adapt mail settings if needed */
718 unset($this->attrs['mail']);
719 if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
720 $this->attrs['mail']= $this->mail;
721 }
723 /* Write back to ldap */
724 $ldap= $this->config->get_ldap_link();
725 $ldap->cd($this->dn);
726 $this->cleanup();
727 $ldap->modify ($this->attrs);
729 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
731 /* Optionally execute a command after we're done */
732 if ($this->initially_was_account == $this->is_account){
733 if ($this->is_modified){
734 $this->handle_post_events("mofify");
735 }
736 } else {
737 $this->handle_post_events("add");
738 }
740 }
743 /* Adapt from template, using 'dn' */
744 function adapt_from_template($dn)
745 {
746 plugin::adapt_from_template($dn);
748 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
749 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
751 if (isset($this->attrs[$val])){
752 $this->$val= $this->attrs[$val];
753 }
754 }
755 }
759 /* Add alternate fax recipient */
760 function addAlternate($number)
761 {
762 $this->facsimileAlternateTelephoneNumber[]= "$number";
763 $this->facsimileAlternateTelephoneNumber=
764 array_unique ($this->facsimileAlternateTelephoneNumber);
766 sort ($this->facsimileAlternateTelephoneNumber);
767 reset ($this->facsimileAlternateTelephoneNumber);
768 }
770 function delAlternate($numbers)
771 {
772 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
773 $this->facsimileAlternateTelephoneNumber);
774 }
776 function getCopyDialog()
777 {
778 $str = "";
779 $smarty = get_smarty();
780 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
781 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
782 $str['status'] ="";
783 return($str);
784 }
786 function SaveCopyDialog()
787 {
788 if(isset($_POST['facsimileTelephoneNumber'])){
789 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
790 }
791 }
794 /* Return plugin informations for acl handling
795 #FIXME some attributes are still missing in this plugin acls */
796 function plInfo()
797 {
798 return (array(
799 "plShortName" => _("Fax"),
800 "plDescription" => _("Fax account settings"),
801 "plSelfModify" => TRUE,
802 "plDepends" => array("user"),
803 "plPriority" => 6,
804 "plSection" => "personal",
805 "plCategory" => array("users"),
806 "plOptions" => array(),
808 "plProvidedAcls" => array(
809 "goFaxIsEnabled" => "!!! FIXME "._("Enable/Disable fax"),
810 "goFaxRBlocklist" => _("Receive blocklist"),
811 "goFaxSBlocklist" => _("Send blocklist"),
812 "facsimileTelephoneNumber" => _("Fax number"), // goFaxDeliveryMode
813 "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
814 "faxtomail" => _("Deliver fax as mail"),
815 "faxtoprinter" => _("Deliver fax to printer"),
816 "goFaxFormat" => _("Delivery format"),
817 "goFaxLanguage" => _("Language"))
818 ));
819 }
820 }
822 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
823 ?>