1 <?php
3 class gofaxAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "FAX";
7 var $plDescription= "This does something";
9 /* Department list shown in the divSelectList*/
10 var $departments;
12 /* Fax attributes */
13 var $goFaxDeliveryMode= "0";
14 var $facsimileTelephoneNumber= "";
15 var $goFaxIsEnabled= 1;
16 var $goFaxPrinter= "";
17 var $goFaxDivertNumber= "";
18 var $goFaxLanguage= "";
19 var $goFaxFormat= "";
20 var $goFaxRBlocklist = array();
21 var $goFaxRBlockgroups= array();
22 var $goFaxSBlocklist= array();
23 var $goFaxSBlockgroups= array();
24 var $mail= "";
25 var $facsimileAlternateTelephoneNumber= array();
27 /* Internal variables */
28 var $printerList= array();
29 var $has_mailAccount= FALSE;
30 var $locals_dialog= FALSE;
31 var $in_blocklist_dialog= FALSE;
32 var $out_blocklist_dialog= FALSE;
33 var $current_blocklist= array();
35 /* Copy & paste variables */
36 var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
38 /* attribute list for save action */
39 var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
40 var $objectclasses= array("goFaxAccount");
42 var $uid= "";
44 function gofaxAccount ($config, $dn= NULL, $parent)
45 {
46 /* General initialization */
47 plugin::plugin ($config, $dn, $parent);
49 /* Get user id */
50 if(isset($this->attrs['uid'])){
51 $this->uid = $this->attrs['uid'][0];
52 }
54 /* Hickert : 11.11.05
55 * Added to be able to handle department selection in divSelelect
56 */
57 if(!isset($_SESSION["Fax_Filter"])){
58 $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
59 }
61 if ($dn != "new"){
62 /* Get arrays */
63 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
64 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
65 $this->$val =array();
66 if (isset($this->attrs["$val"]["count"])){
67 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
68 array_push($this->$val, $this->attrs["$val"][$i]);
69 }
70 }
71 }
73 /* Set up has_mailAccount */
74 if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
75 $this->has_mailAccount= TRUE;
76 }
77 if (isset($this->attrs["facsimileTelephoneNumber"][0])){
78 $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
79 }
80 }
82 /* Load printer list */
83 if (isset($this->config->data['SERVERS']['CUPS'])){
84 $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
85 asort ($this->printerList);
86 }
88 /* Get global filter config */
89 if (!is_global("faxfilter")){
90 $ui= get_userinfo();
91 $base= get_base_from_people($ui->dn);
92 $faxfilter= array( "depselect" => $base,
93 "fuser" => "*",
94 "regex" => "");
95 register_global("faxfilter", $faxfilter);
96 }
97 $this->ui = get_userinfo();
98 }
100 function execute()
101 {
102 /* Call parent execute */
103 plugin::execute();
106 $acl= get_permissions ($this->ui->dn, $this->ui->subtreeACL);
107 $editacl= get_module_permission($acl, "gofax", $this->dn);
108 $this->acl = $editacl;
110 /* Hickert : 11.11.05
111 * Added to be able to handle department selection in divSelelect
112 */
113 if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
115 if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
116 $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
117 }else{
118 $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
119 }
120 }
122 /* Load smarty stuff */
123 $smarty= get_smarty();
125 /* Check if mail account is active. We'll display an additional
126 mail address field if this is not the case. Some people may
127 want goFax, but have a mailserver which is not managed with
128 GOsa */
129 if (!@isset($this->parent->by_object['mailAccount'])) {
130 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
131 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
132 $smarty->assign("has_mailaccount", "false");
133 $this->has_mailAccount= false;
134 } else {
135 $smarty->assign("has_mailaccount", "true");
136 }
138 /* Do we need to flip is_account state? */
139 if (isset($_POST['modify_state'])){
141 /* Onyl change account state if allowed */
142 if($this->is_account && $this->acl == "#all#"){
143 $this->is_account= !$this->is_account;
144 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
145 $this->is_account= !$this->is_account;
146 }
147 }
149 /* Do we represent a valid account? */
150 if (!$this->is_account && $this->parent == NULL){
151 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
152 _("This account has no fax extensions.")."</b>";
153 $display.= back_to_main();
154 return ($display);
155 }
157 /* Show tab dialog headers */
158 $display= "";
159 if ($this->parent != NULL){
160 if ($this->is_account){
161 $display= $this->show_header(_("Remove fax account"),
162 _("This account has fax features enabled. You can disable them by clicking below."));
163 } else {
164 $display= $this->show_header(_("Create fax account"),
165 _("This account has fax features disabled. You can enable them by clicking below."));
166 return ($display);
167 }
168 }
170 /* Trigger Add local fax alternatives dialog */
171 if (isset($_POST['add_local_alternate'])){
172 $this->locals_dialog= TRUE;
173 $this->dialog= TRUE;
174 }
176 /* Add alternatives from dialog */
177 if (isset($_POST['add_locals_finish'])){
178 if (isset($_POST['local_list']) &&
179 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
181 foreach ($_POST['local_list'] as $val){
182 $this->addAlternate($val);
183 $this->is_modified= TRUE;
184 }
185 }
186 }
188 /* Add alternatives */
189 if (isset($_POST['add_alternate'])){
190 if ($_POST['forward_address'] != "" &&
191 is_phone_nr($_POST['forward_address']) &&
192 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
194 $this->addAlternate($_POST['forward_address']);
195 }
196 }
198 /* Delete alternate fax number */
199 if (isset($_POST['delete_alternate'])){
200 if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
201 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
203 $this->delAlternate ($_POST['alternate_list']);
204 }
205 }
208 /* Edit incoming blocklists */
209 if (isset($_POST['edit_incoming'])){
210 $this->current_blocklist= array_merge($this->goFaxRBlocklist,
211 $this->goFaxRBlockgroups);
212 sort($this->current_blocklist);
213 reset($this->current_blocklist);
215 $this->in_blocklist_dialog= TRUE;
216 $this->dialog= TRUE;
217 }
219 /* Edit outgoing blocklists */
220 if (isset($_POST['edit_outgoing'])){
221 $this->current_blocklist= array_merge($this->goFaxSBlocklist,
222 $this->goFaxSBlockgroups);
223 sort($this->current_blocklist);
224 reset($this->current_blocklist);
226 $this->out_blocklist_dialog= TRUE;
227 $this->dialog= TRUE;
228 }
230 /* Add number to blocklist (dialog) */
231 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
232 if (!is_phone_nr($_POST['block_number'])){
233 print_red (_("You're trying to add an invalid phone number."));
234 } else {
235 array_push($this->current_blocklist, $_POST['block_number']);
236 $this->current_blocklist= array_unique($this->current_blocklist);
237 sort($this->current_blocklist);
238 reset($this->current_blocklist);
239 }
240 }
242 /* Hickert : 11.11.05
243 * Add selection from divSelelect to our Blocklist
244 */
245 /* Add list to blocklist */
246 if (isset($_POST['add_blocklist'])){
247 foreach($_POST as $name => $value){
248 if(preg_match("/ADDLIST_/i",$name)){
249 $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
251 }
252 }
253 $this->current_blocklist= array_unique($this->current_blocklist);
254 sort($this->current_blocklist);
255 reset($this->current_blocklist);
256 }
258 /* Add list to blocklist */
259 if (isset($_GET['add'])){
260 if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
261 $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
262 $this->current_blocklist= array_unique($this->current_blocklist);
263 sort($this->current_blocklist);
264 reset($this->current_blocklist);
265 }
267 /* Delete from blocklist */
268 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
269 $tmp= array();
270 foreach($this->current_blocklist as $val){
271 if (!in_array($val, $_POST['block_list'])){
272 $tmp[]= $val;
273 }
274 }
275 $this->current_blocklist= $tmp;
276 }
279 /* Blocklist edit finished */
280 if (isset($_POST['edit_blocklists_finish'])){
282 /* Incoming or outgoing? */
283 if ($this->in_blocklist_dialog){
284 $this->goFaxRBlocklist = array();
285 $this->goFaxRBlockgroups = array();
287 foreach ($this->current_blocklist as $val){
288 if (is_phone_nr($val)){
289 $this->goFaxRBlocklist[]=$val;
290 } else {
291 $this->goFaxRBlockgroups[]= $val;
292 }
293 }
294 } else {
295 $this->goFaxSBlocklist = array();
296 $this->goFaxSBlockgroups = array();
298 /* Transfer values to ourself */
299 foreach ($this->current_blocklist as $val){
300 if (is_phone_nr($val)){
301 $this->goFaxSBlocklist[]=$val;
302 } else {
303 $this->goFaxSBlockgroups[]= $val;
304 }
305 }
306 }
307 $this->is_modified= TRUE;
308 }
311 /* Set departments */
312 if ($this->locals_dialog ||
313 $this->in_blocklist_dialog ||
314 $this->out_blocklist_dialog){
316 $list= array ();
317 $ldap= $this->config->get_ldap_link();
318 if (isset ($_POST['department'])){
319 $ldap->cd ($_POST['department']);
320 } else {
321 $ldap->cd ($this->config->current['BASE']);
322 }
323 }
325 /* Cancel dialogs */
326 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
327 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
329 $this->locals_dialog= FALSE;
330 $this->in_blocklist_dialog= FALSE;
331 $this->out_blocklist_dialog= FALSE;
332 $this->dialog= FALSE;
333 }
335 /* Manage locals dialog */
336 if ($this->locals_dialog){
338 /* Save data */
339 $faxfilter= get_global("faxfilter");
340 foreach( array("depselect", "fuser", "regex") as $type){
341 if (isset($_POST[$type])){
342 $faxfilter[$type]= $_POST[$type];
343 }
344 }
345 if (isset($_GET['search'])){
346 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
347 if ($s == "**"){
348 $s= "*";
349 }
350 $faxfilter['fuser']= $s;
351 }
352 register_global("faxfilter", $faxfilter);
354 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
355 $regex= $faxfilter['regex'];
356 $filter= "(facimileTelephoneNumber=$regex)";
357 } else {
358 $filter= "";
359 }
360 if ($faxfilter['fuser'] != ""){
361 $user= $faxfilter['fuser'];
362 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
363 }
365 $base= $faxfilter['depselect'];
366 $acl= array($this->config->current['BASE'] => ":all");
367 $res= get_list("(&(objectClass=goFaxAccount)$filter)", $acl, $base,
368 array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
370 foreach ($res as $attrs){
371 $list[$attrs['facsimileTelephoneNumber'][0]]=
372 $attrs['sn'][0].", ".
373 $attrs['givenName'][0]." [".
374 $attrs['facsimileTelephoneNumber'][0]."]";
375 }
377 /* Show dialog */
378 $smarty->assign("search_image", get_template_path('images/search.png'));
379 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
380 $smarty->assign("tree_image", get_template_path('images/tree.png'));
381 $smarty->assign("infoimage", get_template_path('images/info.png'));
382 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
383 $smarty->assign("departments", $this->config->idepartments);
384 $smarty->assign("list", $list);
385 if (isset($_POST['depselect'])){
386 $smarty->assign("depselect", $_POST['depselect']);
387 }
388 $smarty->assign("deplist", $this->config->idepartments);
389 $smarty->assign("apply", apply_filter());
390 $smarty->assign("alphabet", generate_alphabet());
391 $smarty->assign("hint", print_sizelimit_warning());
392 foreach( array("depselect", "fuser", "regex") as $type){
393 $smarty->assign("$type", $faxfilter[$type]);
394 }
395 $smarty->assign("hint", print_sizelimit_warning());
397 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
398 return ($display);
399 }
402 /* Manage incoming blocklists */
403 if ($this->in_blocklist_dialog){
405 /* This handles the divSelectBox */
407 /* The base specifies the current position in the ldap tree
408 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
409 */
410 $base = $_SESSION['Fax_Filter']['depselect'];
411 $ldap->cd($base);
413 /* Ge all Blocklists */
414 $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
415 while ($attrs= $ldap->fetch()){
417 /* Generate list depending on description */
418 if(isset($attrs['description'][0])){
419 $list[$attrs['cn'][0]]=
420 $attrs['description'][0].
421 " [".$attrs['cn'][0]."]";
422 }else{
423 $list[$attrs['cn'][0]]= $attrs['cn'][0];
424 }
425 }
427 /* Create our divselect box */
428 $divSel = new divSelectBox("divSelectPredefined");
429 $divSel->setHeight(296);
431 /* NEW LIST MANAGMENT
432 * We also need to search for the departments
433 * So we are able to navigate like in konquerer
434 */
435 $this->departments= array();
437 /* Get all departments within the current department */
438 $base = $_SESSION['Fax_Filter']['depselect'];
439 $ldap->ls("(objectClass=gosaDepartment)",$base);
441 /* Base back is used to go one department up in our ldap tree */
442 $base_back = preg_replace("/^[^,]+,/","",$base);
444 /* Only show base_back if it is needed */
445 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
446 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
447 }
449 /* Fetch all returned departments an add them to our divlist */
450 while($value = $ldap->fetch()){
451 if($value["description"][0]!=".."){
452 $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
453 }else{
454 $this->departments[$value['dn']]=$value["description"][0];
455 }
456 }
457 /* END NEW LIST MANAGMENT
458 */
460 // This links specifies the department open link
461 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
463 /* Insert departments in divsel */
464 foreach($this->departments as $key=> $val){
465 if(!isset($this->config->departments[trim($key)])){
466 $this->config->departments[trim($key)]="";
467 }
468 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
469 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
470 $divSel->AddEntry(array($field1,$field2));
471 }
473 /* Append predefined Blocklists */
474 foreach($list as $entry => $value){
475 $divSel->AddEntry(array(
476 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
477 array("string"=>$value,"attach"=>"style='border:0px;'")
478 ));
479 }
481 /* Show dialog */
482 $smarty->assign("cblocklist", $this->current_blocklist);
483 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
484 $smarty->assign("departments", $this->config->idepartments);
485 $smarty->assign("divSelectPredefined", $divSel->DrawList());
486 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
487 return ($display);
488 }
490 /* Manage outgoing blocklists */
492 if ($this->out_blocklist_dialog){
494 /* This handles the divSelectBox */
496 /* The base specifies the current position in the ldap tree
497 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
498 */
499 $base = $_SESSION['Fax_Filter']['depselect'];
500 $ldap->cd($base);
502 /* Ge all Blocklists */
503 $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
504 while ($attrs= $ldap->fetch()){
505 if(isset($attrs['description'][0])){
506 $list[$attrs['cn'][0]]=
507 $attrs['description'][0].
508 " [".$attrs['cn'][0]."]";
509 }else{
510 $list[$attrs['cn'][0]]= $attrs['cn'][0];
511 }
512 }
514 /*Create DivSel*/
515 $divSel = new divSelectBox("divSelectPredefined");
516 $divSel->setHeight(296);
518 /* NEW LIST MANAGMENT
519 * We also need to search for the departments
520 * So we are able to navigate like in konquerer
521 */
522 $this->departments= array();
523 $ldap->ls("(objectClass=gosaDepartment)",$base);
525 /* Generate Back url, and append if it is needed */
526 $base_back = preg_replace("/^[^,]+,/","",$base);
527 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
528 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
529 }
531 /* Get all departments */
532 while($value = $ldap->fetch()){
533 if(isset($value["description"][0])){
534 $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
535 }else{
536 $this->departments[$value['dn']]=$value["description"][0];
537 }
538 }
539 /* END NEW LIST MANAGMENT
540 */
542 // Defining Links
543 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
545 /* Insert departments in divlist*/
546 foreach($this->departments as $key=> $val){
547 if(!isset($this->config->departments[trim($key)])){
548 $this->config->departments[trim($key)]="";
549 }
551 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
552 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
553 $divSel->AddEntry(array($field1,$field2));
554 }
556 /* Append Blocklits */
557 foreach($list as $entry => $value){
558 $divSel->AddEntry(array(
559 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
560 array("string"=>$value,"attach"=>"style='border:0px;'")
561 ));
562 }
564 /* Show dialog */
565 $smarty->assign("cblocklist", $this->current_blocklist);
566 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
567 $smarty->assign("departments", $this->config->idepartments);
568 $smarty->assign("divSelectPredefined", $divSel->DrawList());
569 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
570 return ($display);
571 }
574 /* Show main page */
575 $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
576 $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
577 $smarty->assign("printers", $this->printerList);
579 /* Load attributes */
580 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
581 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
582 "facsimileAlternateTelephoneNumber", "mail") as $val){
584 $smarty->assign("$val", $this->$val);
585 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
586 }
587 $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
588 $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
590 /* Load checkboxes */
591 if ($this->goFaxIsEnabled == "1"){
592 $smarty->assign("goFaxIsEnabled", "");
593 } else {
594 $smarty->assign("goFaxIsEnabled", "checked");
595 }
596 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
597 if ($this->goFaxDeliveryMode & 32) {
598 $smarty->assign("fax_to_mail", "checked");
599 } else {
600 $smarty->assign("fax_to_mail", "");
601 }
602 if ($this->goFaxDeliveryMode & 64) {
603 $smarty->assign("fax_to_printer", "checked");
604 } else {
605 $smarty->assign("fax_to_printer", "");
606 }
609 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
610 return ($display);
611 }
613 function remove_from_parent()
614 {
615 /* Cancel if there's nothing to do here */
616 if (!$this->initially_was_account){
617 return;
618 }
620 plugin::remove_from_parent();
622 /* Adapt mail settings if needed */
623 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
624 unset($this->attrs['mail']);
625 }
627 $ldap= $this->config->get_ldap_link();
628 $ldap->cd($this->dn);
629 $this->cleanup();
630 $ldap->modify ($this->attrs);
632 show_ldap_error($ldap->get_error(), _("Removing FAX account failed"));
634 /* Optionally execute a command after we're done */
635 $this->handle_post_events('remove',array("uid"=> $this->uid));
636 }
639 /* Check formular input */
640 function check()
641 {
642 /* Call common method to give check the hook */
643 $message= plugin::check();
645 /* must: facsimileTelephoneNumber */
646 if ($this->facsimileTelephoneNumber == ""){
647 $message[]= _("The required field 'Fax' is not set.");
648 }
650 if (!is_phone_nr($this->facsimileTelephoneNumber)){
651 $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
652 }
654 /* IF mail is specified (which is only the case if there's no mail account
655 present), check if it's valid.. */
656 if (@isset($this->parent->by_object['mailAccount']) &&
657 $this->goFaxDeliveryMode & 32){
658 if ($this->mail == ""){
659 $message[]= _("Mail delivery is checked, but no address has been specified.");
660 } elseif (!is_email($this->mail)){
661 $message[]= _("The mail address you've entered is invalid.");
662 }
663 }
665 // IE Fix, IE lets you choose disabled option, stupid browser ...
666 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
667 $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
668 }
670 return ($message);
671 }
673 /* Save data to object */
674 function save_object()
675 {
676 if (isset($_POST['faxTab'])){
677 plugin::save_object();
679 /* Adapt combobox values */
680 $tmp= 0;
681 if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
682 $tmp+= 32;
683 }
684 if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
685 $tmp+= 64;
686 }
687 if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
688 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
689 $this->goFaxIsEnabled= "0";
690 } else {
691 $this->goFaxIsEnabled= "1";
692 }
693 }
695 if (isset($_POST['facsimileTelephoneNumber'])){
696 if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
697 $this->is_modified= TRUE;
698 }
699 $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
700 }
702 if (isset($_POST['mail'])){
703 if ($this->mail != $_POST['mail']){
704 $this->is_modified= TRUE;
705 }
706 $this->mail= $_POST['mail'];
707 }
709 /* Write to object */
710 if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
711 if ($tmp != $this->goFaxDeliveryMode){
712 $this->is_modified= TRUE;
713 }
714 $this->goFaxDeliveryMode= "$tmp";
715 }
717 /* Check if mail account is active and correct the internal
718 reference to represent the current status. */
719 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
720 $this->has_mailAccount= TRUE;
721 }
722 }
724 }
727 /* Save to LDAP */
728 function save()
729 {
730 plugin::save();
732 /* Save arrays */
733 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
734 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
736 $this->attrs[$val]= $this->$val;
737 }
739 /* Do not save mail address ... it was possibly changed by mail plugin*/
740 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
741 unset($this->attrs['mail']);
742 }
744 /* Write back to ldap */
745 $ldap= $this->config->get_ldap_link();
746 $ldap->cd($this->dn);
747 $this->cleanup();
748 $ldap->modify ($this->attrs);
750 show_ldap_error($ldap->get_error(), _("Saving FAX account failed"));
752 /* Optionally execute a command after we're done */
753 if ($this->initially_was_account == $this->is_account){
754 if ($this->is_modified){
755 $this->handle_post_events("modify",array("uid" => $this->uid));
756 }
757 } else {
758 $this->handle_post_events("add",array("uid" => $this->uid));
759 }
761 }
764 /* Adapt from template, using 'dn' */
765 function adapt_from_template($dn)
766 {
767 plugin::adapt_from_template($dn);
769 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
770 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
772 if (isset($this->attrs[$val])){
773 $this->$val= $this->attrs[$val];
774 }
775 }
776 }
780 /* Add alternate fax recipient */
781 function addAlternate($number)
782 {
783 $this->facsimileAlternateTelephoneNumber[]= "$number";
784 $this->facsimileAlternateTelephoneNumber=
785 array_unique ($this->facsimileAlternateTelephoneNumber);
787 sort ($this->facsimileAlternateTelephoneNumber);
788 reset ($this->facsimileAlternateTelephoneNumber);
789 }
791 function delAlternate($numbers)
792 {
793 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
794 $this->facsimileAlternateTelephoneNumber);
795 }
797 function getCopyDialog()
798 {
799 $str = "";
800 $smarty = get_smarty();
801 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
802 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
803 $str['status'] ="";
804 return($str);
805 }
807 function SaveCopyDialog()
808 {
809 if(isset($_POST['facsimileTelephoneNumber'])){
810 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
811 }
812 }
814 }
816 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
817 ?>