ee1bca3e6ef6a9bd8acf8e5362430a4b95ddaba8
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",
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 if (isset($this->attrs["facsimileTelephoneNumber"][0])){
76 $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
77 }
78 }
80 /* Load printer list */
81 if (isset($this->config->data['SERVERS']['CUPS'])){
82 $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
83 asort ($this->printerList);
84 }
86 /* Get global filter config */
87 if (!is_global("faxfilter")){
88 $ui= get_userinfo();
89 $base= get_base_from_people($ui->dn);
90 $faxfilter= array( "depselect" => $base,
91 "fuser" => "*",
92 "regex" => "");
93 register_global("faxfilter", $faxfilter);
94 }
95 }
97 function execute()
98 {
99 /* Call parent execute */
100 plugin::execute();
101 /* Hickert : 11.11.05
102 * Added to be able to handle department selection in divSelelect
103 */
104 if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
106 if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
107 $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
108 }else{
109 $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
110 }
111 }
113 /* Load smarty stuff */
114 $smarty= get_smarty();
116 /* Check if mail account is active. We'll display an additional
117 mail address field if this is not the case. Some people may
118 want goFax, but have a mailserver which is not managed with
119 GOsa */
120 if (!@isset($this->parent->by_object['mailAccount'])) {
121 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
122 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
123 $smarty->assign("has_mailaccount", "false");
124 $this->has_mailAccount= false;
125 } else {
126 $smarty->assign("has_mailaccount", "true");
127 }
129 /* Do we need to flip is_account state? */
130 if (isset($_POST['modify_state'])){
131 $this->is_account= !$this->is_account;
132 }
134 /* Do we represent a valid account? */
135 if (!$this->is_account && $this->parent == NULL){
136 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
137 _("This account has no fax extensions.")."</b>";
138 $display.= back_to_main();
139 return ($display);
140 }
142 /* Show tab dialog headers */
143 $display= "";
144 if ($this->parent != NULL){
145 if ($this->is_account){
146 $display= $this->show_header(_("Remove fax account"),
147 _("This account has fax features enabled. You can disable them by clicking below."));
148 } else {
149 $display= $this->show_header(_("Create fax account"),
150 _("This account has fax features disabled. You can enable them by clicking below."));
151 return ($display);
152 }
153 }
155 /* Trigger Add local fax alternatives dialog */
156 if (isset($_POST['add_local_alternate'])){
157 $this->locals_dialog= TRUE;
158 $this->dialog= TRUE;
159 }
161 /* Add alternatives from dialog */
162 if (isset($_POST['add_locals_finish'])){
163 if (isset($_POST['local_list']) &&
164 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
166 foreach ($_POST['local_list'] as $val){
167 $this->addAlternate($val);
168 $this->is_modified= TRUE;
169 }
170 }
171 }
173 /* Add alternatives */
174 if (isset($_POST['add_alternate'])){
175 if ($_POST['forward_address'] != "" &&
176 is_phone_nr($_POST['forward_address']) &&
177 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
179 $this->addAlternate($_POST['forward_address']);
180 }
181 }
183 /* Delete alternate fax number */
184 if (isset($_POST['delete_alternate'])){
185 if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
186 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
188 $this->delAlternate ($_POST['alternate_list']);
189 }
190 }
193 /* Edit incoming blocklists */
194 if (isset($_POST['edit_incoming'])){
195 $this->current_blocklist= array_merge($this->goFaxRBlocklist,
196 $this->goFaxRBlockgroups);
197 sort($this->current_blocklist);
198 reset($this->current_blocklist);
200 $this->in_blocklist_dialog= TRUE;
201 $this->dialog= TRUE;
202 }
204 /* Edit outgoing blocklists */
205 if (isset($_POST['edit_outgoing'])){
206 $this->current_blocklist= array_merge($this->goFaxSBlocklist,
207 $this->goFaxSBlockgroups);
208 sort($this->current_blocklist);
209 reset($this->current_blocklist);
211 $this->out_blocklist_dialog= TRUE;
212 $this->dialog= TRUE;
213 }
215 /* Add number to blocklist (dialog) */
216 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
217 if (!is_phone_nr($_POST['block_number'])){
218 print_red (_("You're trying to add an invalid phone number."));
219 } else {
220 array_push($this->current_blocklist, $_POST['block_number']);
221 $this->current_blocklist= array_unique($this->current_blocklist);
222 sort($this->current_blocklist);
223 reset($this->current_blocklist);
224 }
225 }
227 /* Hickert : 11.11.05
228 * Add selection from divSelelect to our Blocklist
229 */
230 /* Add list to blocklist */
231 if (isset($_POST['add_blocklist'])){
232 foreach($_POST as $name => $value){
233 if(preg_match("/ADDLIST_/i",$name)){
234 $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
236 }
237 }
238 $this->current_blocklist= array_unique($this->current_blocklist);
239 sort($this->current_blocklist);
240 reset($this->current_blocklist);
241 }
243 /* Add list to blocklist */
244 if (isset($_GET['add'])){
245 if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
246 $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
247 $this->current_blocklist= array_unique($this->current_blocklist);
248 sort($this->current_blocklist);
249 reset($this->current_blocklist);
250 }
252 /* Delete from blocklist */
253 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
254 $tmp= array();
255 foreach($this->current_blocklist as $val){
256 if (!in_array($val, $_POST['block_list'])){
257 $tmp[]= $val;
258 }
259 }
260 $this->current_blocklist= $tmp;
261 }
264 /* Blocklist edit finished */
265 if (isset($_POST['edit_blocklists_finish'])){
267 /* Incoming or outgoing? */
268 if ($this->in_blocklist_dialog){
269 $this->goFaxRBlocklist = array();
270 $this->goFaxRBlockgroups = array();
272 foreach ($this->current_blocklist as $val){
273 if (is_phone_nr($val)){
274 $this->goFaxRBlocklist[]=$val;
275 } else {
276 $this->goFaxRBlockgroups[]= $val;
277 }
278 }
279 } else {
280 $this->goFaxSBlocklist = array();
281 $this->goFaxSBlockgroups = array();
283 /* Transfer values to ourself */
284 foreach ($this->current_blocklist as $val){
285 if (is_phone_nr($val)){
286 $this->goFaxSBlocklist[]=$val;
287 } else {
288 $this->goFaxSBlockgroups[]= $val;
289 }
290 }
291 }
292 $this->is_modified= TRUE;
293 }
296 /* Set departments */
297 if ($this->locals_dialog ||
298 $this->in_blocklist_dialog ||
299 $this->out_blocklist_dialog){
301 $list= array ();
302 $ldap= $this->config->get_ldap_link();
303 if (isset ($_POST['department'])){
304 $ldap->cd ($_POST['department']);
305 } else {
306 $ldap->cd ($this->config->current['BASE']);
307 }
308 }
310 /* Cancel dialogs */
311 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
312 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
314 $this->locals_dialog= FALSE;
315 $this->in_blocklist_dialog= FALSE;
316 $this->out_blocklist_dialog= FALSE;
317 $this->dialog= FALSE;
318 }
320 /* Manage locals dialog */
321 if ($this->locals_dialog){
323 /* Save data */
324 $faxfilter= get_global("faxfilter");
325 foreach( array("depselect", "fuser", "regex") as $type){
326 if (isset($_POST[$type])){
327 $faxfilter[$type]= $_POST[$type];
328 }
329 }
330 if (isset($_GET['search'])){
331 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
332 if ($s == "**"){
333 $s= "*";
334 }
335 $faxfilter['fuser']= $s;
336 }
337 register_global("faxfilter", $faxfilter);
339 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
340 $regex= $faxfilter['regex'];
341 $filter= "(facimileTelephoneNumber=$regex)";
342 } else {
343 $filter= "";
344 }
345 if ($faxfilter['fuser'] != ""){
346 $user= $faxfilter['fuser'];
347 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
348 }
350 $base= $faxfilter['depselect'];
351 $acl= array($this->config->current['BASE'] => ":all");
352 print "(&(objectClass=goFaxAccount)$filter)";
353 $res= get_list($acl, "(&(objectClass=goFaxAccount)$filter)", TRUE, $base, array("sn", "givenName", "facsimileTelephoneNumber"), TRUE);
355 foreach ($res as $attrs){
356 $list[$attrs['facsimileTelephoneNumber'][0]]=
357 $attrs['sn'][0].", ".
358 $attrs['givenName'][0]." [".
359 $attrs['facsimileTelephoneNumber'][0]."]";
360 }
362 /* Show dialog */
363 $smarty->assign("search_image", get_template_path('images/search.png'));
364 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
365 $smarty->assign("tree_image", get_template_path('images/tree.png'));
366 $smarty->assign("infoimage", get_template_path('images/info.png'));
367 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
368 $smarty->assign("departments", $this->config->idepartments);
369 $smarty->assign("list", $list);
370 if (isset($_POST['depselect'])){
371 $smarty->assign("depselect", $_POST['depselect']);
372 }
373 $smarty->assign("deplist", $this->config->idepartments);
374 $smarty->assign("apply", apply_filter());
375 $smarty->assign("alphabet", generate_alphabet());
376 $smarty->assign("hint", print_sizelimit_warning());
377 foreach( array("depselect", "fuser", "regex") as $type){
378 $smarty->assign("$type", $faxfilter[$type]);
379 }
380 $smarty->assign("hint", print_sizelimit_warning());
382 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
383 return ($display);
384 }
387 /* Manage incoming blocklists */
388 if ($this->in_blocklist_dialog){
390 /* This handles the divSelectBox */
392 /* The base specifies the current position in the ldap tree
393 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
394 */
395 $base = $_SESSION['Fax_Filter']['depselect'];
396 $ldap->cd($base);
398 /* Ge all Blocklists */
399 $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
400 while ($attrs= $ldap->fetch()){
402 /* Generate list depending on description */
403 if(isset($attrs['description'][0])){
404 $list[$attrs['cn'][0]]=
405 $attrs['description'][0].
406 " [".$attrs['cn'][0]."]";
407 }else{
408 $list[$attrs['cn'][0]]= $attrs['cn'][0];
409 }
410 }
412 /* Create our divselect box */
413 $divSel = new divSelectBox("divSelectPredefined");
414 $divSel->setHeight(296);
416 /* NEW LIST MANAGMENT
417 * We also need to search for the departments
418 * So we are able to navigate like in konquerer
419 */
420 $this->departments= array();
422 /* Get all departments within the current department */
423 $base = $_SESSION['Fax_Filter']['depselect'];
424 $ldap->ls("(objectClass=gosaDepartment)",$base);
426 /* Base back is used to go one department up in our ldap tree */
427 $base_back = preg_replace("/^[^,]+,/","",$base);
429 /* Only show base_back if it is needed */
430 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
431 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
432 }
434 /* Fetch all returned departments an add them to our divlist */
435 while($value = $ldap->fetch()){
436 if($value["description"][0]!=".."){
437 $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
438 }else{
439 $this->departments[$value['dn']]=$value["description"][0];
440 }
441 }
442 /* END NEW LIST MANAGMENT
443 */
445 // This links specifies the department open link
446 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
448 /* Insert departments in divsel */
449 foreach($this->departments as $key=> $val){
450 if(!isset($this->config->departments[trim($key)])){
451 $this->config->departments[trim($key)]="";
452 }
453 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
454 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
455 $divSel->AddEntry(array($field1,$field2));
456 }
458 /* Append predefined Blocklists */
459 foreach($list as $entry => $value){
460 $divSel->AddEntry(array(
461 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
462 array("string"=>$value,"attach"=>"style='border:0px;'")
463 ));
464 }
466 /* Show dialog */
467 $smarty->assign("cblocklist", $this->current_blocklist);
468 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
469 $smarty->assign("departments", $this->config->idepartments);
470 $smarty->assign("divSelectPredefined", $divSel->DrawList());
471 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
472 return ($display);
473 }
475 /* Manage outgoing blocklists */
477 if ($this->out_blocklist_dialog){
479 /* This handles the divSelectBox */
481 /* The base specifies the current position in the ldap tree
482 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
483 */
484 $base = $_SESSION['Fax_Filter']['depselect'];
485 $ldap->cd($base);
487 /* Ge all Blocklists */
488 $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
489 while ($attrs= $ldap->fetch()){
490 if(isset($attrs['description'][0])){
491 $list[$attrs['cn'][0]]=
492 $attrs['description'][0].
493 " [".$attrs['cn'][0]."]";
494 }else{
495 $list[$attrs['cn'][0]]= $attrs['cn'][0];
496 }
497 }
499 /*Create DivSel*/
500 $divSel = new divSelectBox("divSelectPredefined");
501 $divSel->setHeight(296);
503 /* NEW LIST MANAGMENT
504 * We also need to search for the departments
505 * So we are able to navigate like in konquerer
506 */
507 $this->departments= array();
508 $ldap->ls("(objectClass=gosaDepartment)",$base);
510 /* Generate Back url, and append if it is needed */
511 $base_back = preg_replace("/^[^,]+,/","",$base);
512 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
513 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
514 }
516 /* Get all departments */
517 while($value = $ldap->fetch()){
518 if(isset($value["description"][0])){
519 $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
520 }else{
521 $this->departments[$value['dn']]=$value["description"][0];
522 }
523 }
524 /* END NEW LIST MANAGMENT
525 */
527 // Defining Links
528 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
530 /* Insert departments in divlist*/
531 foreach($this->departments as $key=> $val){
532 if(!isset($this->config->departments[trim($key)])){
533 $this->config->departments[trim($key)]="";
534 }
536 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
537 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
538 $divSel->AddEntry(array($field1,$field2));
539 }
541 /* Append Blocklits */
542 foreach($list as $entry => $value){
543 $divSel->AddEntry(array(
544 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
545 array("string"=>$value,"attach"=>"style='border:0px;'")
546 ));
547 }
549 /* Show dialog */
550 $smarty->assign("cblocklist", $this->current_blocklist);
551 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
552 $smarty->assign("departments", $this->config->idepartments);
553 $smarty->assign("divSelectPredefined", $divSel->DrawList());
554 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
555 return ($display);
556 }
559 /* Show main page */
560 $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
561 $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
562 $smarty->assign("printers", $this->printerList);
564 /* Load attributes */
565 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
566 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
567 "facsimileAlternateTelephoneNumber", "mail") as $val){
569 $smarty->assign("$val", $this->$val);
570 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
571 }
572 $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
573 $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
575 /* Load checkboxes */
576 if ($this->goFaxIsEnabled == "1"){
577 $smarty->assign("goFaxIsEnabled", "");
578 } else {
579 $smarty->assign("goFaxIsEnabled", "checked");
580 }
581 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
582 if ($this->goFaxDeliveryMode & 32) {
583 $smarty->assign("fax_to_mail", "checked");
584 } else {
585 $smarty->assign("fax_to_mail", "");
586 }
587 if ($this->goFaxDeliveryMode & 64) {
588 $smarty->assign("fax_to_printer", "checked");
589 } else {
590 $smarty->assign("fax_to_printer", "");
591 }
594 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
595 return ($display);
596 }
598 function remove_from_parent()
599 {
600 /* Cancel if there's nothing to do here */
601 if (!$this->initially_was_account){
602 return;
603 }
605 plugin::remove_from_parent();
607 /* Zero out arrays */
608 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
609 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
611 $this->attrs[$val]= array();
612 }
614 /* Adapt mail settings if needed */
615 if ($this->parent->by_object['mailAccount']->is_account){
616 unset($this->attrs['mail']);
617 }
619 $ldap= $this->config->get_ldap_link();
620 $ldap->cd($this->dn);
621 $this->cleanup();
622 $ldap->modify ($this->attrs);
624 show_ldap_error($ldap->get_error());
626 /* Optionally execute a command after we're done */
627 $this->handle_post_events('remove');
628 }
631 /* Check formular input */
632 function check()
633 {
634 /* Reset message array */
635 $message= array();
637 /* must: facsimileTelephoneNumber */
638 if ($this->facsimileTelephoneNumber == ""){
639 $message[]= _("The required field 'Fax' is not set.");
640 }
642 if (!is_phone_nr($this->facsimileTelephoneNumber)){
643 $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
644 }
646 /* IF mail is specified (which is only the case if there's no mail account
647 present), check if it's valid.. */
648 if (@isset($this->parent->by_object['mailAccount']) &&
649 $this->goFaxDeliveryMode && 32){
650 if ($this->mail == ""){
651 $message[]= _("Mail delivery is checked, but no address has been specified.");
652 } elseif (!is_email($this->mail)){
653 $message[]= _("The mail address you've entered is invalid.");
654 }
655 }
657 // IE Fix, IE lets you choose disabled option, stupid browser ...
658 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
659 $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
660 }
662 return ($message);
663 }
665 /* Save data to object */
666 function save_object()
667 {
668 if (isset($_POST['faxTab'])){
669 plugin::save_object();
671 /* Adapt combobox values */
672 $tmp= 0;
673 if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
674 $tmp+= 32;
675 }
676 if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
677 $tmp+= 64;
678 }
679 if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
680 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
681 $this->goFaxIsEnabled= "0";
682 } else {
683 $this->goFaxIsEnabled= "1";
684 }
685 }
687 if (isset($_POST['facsimileTelephoneNumber'])){
688 if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
689 $this->is_modified= TRUE;
690 }
691 $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
692 }
694 if (isset($_POST['mail'])){
695 if ($this->mail != $_POST['mail']){
696 $this->is_modified= TRUE;
697 }
698 $this->mail= $_POST['mail'];
699 }
701 /* Write to object */
702 if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
703 if ($tmp != $this->goFaxDeliveryMode){
704 $this->is_modified= TRUE;
705 }
706 $this->goFaxDeliveryMode= "$tmp";
707 }
709 /* Check if mail account is active and correct the internal
710 reference to represent the current status. */
711 if (isset($this->parent)&&($this->parent->by_object['mailAccount']->is_account)){
712 $this->has_mailAccount= TRUE;
713 }
714 }
716 }
719 /* Save to LDAP */
720 function save()
721 {
722 plugin::save();
724 /* Save arrays */
725 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
726 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
728 $this->attrs[$val]= $this->$val;
729 }
731 /* Adapt mail settings if needed */
732 unset($this->attrs['mail']);
733 if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
734 $this->attrs['mail']= $this->mail;
735 }
737 /* Write back to ldap */
738 $ldap= $this->config->get_ldap_link();
739 $ldap->cd($this->dn);
740 $this->cleanup();
741 $ldap->modify ($this->attrs);
743 show_ldap_error($ldap->get_error());
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("mofify");
749 }
750 } else {
751 $this->handle_post_events("add");
752 }
754 }
757 /* Adapt from template, using 'dn' */
758 function adapt_from_template($dn)
759 {
760 plugin::adapt_from_template($dn);
762 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
763 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
765 if (isset($this->attrs[$val])){
766 $this->$val= $this->attrs[$val];
767 }
768 }
769 }
773 /* Add alternate fax recipient */
774 function addAlternate($number)
775 {
776 $this->facsimileAlternateTelephoneNumber[]= "$number";
777 $this->facsimileAlternateTelephoneNumber=
778 array_unique ($this->facsimileAlternateTelephoneNumber);
780 sort ($this->facsimileAlternateTelephoneNumber);
781 reset ($this->facsimileAlternateTelephoneNumber);
782 }
784 function delAlternate($numbers)
785 {
786 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
787 $this->facsimileAlternateTelephoneNumber);
788 }
791 }
793 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
794 ?>