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");
14 /* Fax attributes */
15 var $goFaxDeliveryMode= "";
16 var $facsimileTelephoneNumber= "";
17 var $goFaxIsEnabled= 1;
18 var $goFaxPrinter= "";
19 var $goFaxDivertNumber= "";
20 var $goFaxLanguage= "";
21 var $goFaxFormat= "";
22 var $goFaxRBlocklist = array();
23 var $goFaxRBlockgroups= array();
24 var $goFaxSBlocklist= array();
25 var $goFaxSBlockgroups= array();
26 var $mail= "";
27 var $facsimileAlternateTelephoneNumber= array();
29 /* Internal variables */
30 var $printerList= array();
31 var $has_mailAccount= FALSE;
32 var $locals_dialog= FALSE;
33 var $in_blocklist_dialog= FALSE;
34 var $out_blocklist_dialog= FALSE;
35 var $current_blocklist= array();
37 /* attribute list for save action */
38 var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled",
39 "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail");
40 var $objectclasses= array("goFaxAccount");
42 function gofaxAccount ($config, $dn= NULL)
43 {
44 /* General initialization */
45 plugin::plugin ($config, $dn);
47 if ($dn != "new"){
48 /* Get arrays */
49 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
50 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
52 if (isset($this->attrs["$val"]["count"])){
53 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
54 array_push($this->$val, $this->attrs["$val"][$i]);
55 }
56 }
57 }
59 /* Set up has_mailAccount */
60 if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
61 $this->has_mailAccount= TRUE;
62 }
63 if (isset($this->attrs["facsimileTelephoneNumber"][0])){
64 $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
65 }
66 }
68 /* Load printer list */
69 if (isset($this->config->data['SERVERS']['CUPS'])){
70 $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
71 asort ($this->printerList);
72 }
74 /* Get global filter config */
75 if (!is_global("faxfilter")){
76 $ui= get_userinfo();
77 $base= get_base_from_people($ui->dn);
78 $faxfilter= array( "depselect" => $base,
79 "fuser" => "*",
80 "regex" => "");
81 register_global("faxfilter", $faxfilter);
82 }
83 }
85 function execute()
86 {
87 /* Call parent execute */
88 plugin::execute();
90 /* Load smarty stuff */
91 $smarty= get_smarty();
93 /* Check if mail account is active. We'll display an additional
94 mail address field if this is not the case. Some people may
95 want goFax, but have a mailserver which is not managed with
96 GOsa */
97 if (!@isset($this->parent->by_object['mailAccount'])) {
98 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
99 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
100 $smarty->assign("has_mailaccount", "false");
101 $this->has_mailAccount= false;
102 } else {
103 $smarty->assign("has_mailaccount", "true");
104 }
106 /* Do we need to flip is_account state? */
107 if (isset($_POST['modify_state'])){
108 $this->is_account= !$this->is_account;
109 }
111 /* Do we represent a valid account? */
112 if (!$this->is_account && $this->parent == NULL){
113 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
114 _("This account has no fax extensions.")."</b>";
115 $display.= back_to_main();
116 return ($display);
117 }
119 /* Show tab dialog headers */
120 $display= "";
121 if ($this->parent != NULL){
122 if ($this->is_account){
123 $display= $this->show_header(_("Remove fax account"),
124 _("This account has fax features enabled. You can disable them by clicking below."));
125 } else {
126 $display= $this->show_header(_("Create fax account"),
127 _("This account has fax features disabled. You can enable them by clicking below."));
128 return ($display);
129 }
130 }
132 /* Trigger Add local fax alternatives dialog */
133 if (isset($_POST['add_local_alternate'])){
134 $this->locals_dialog= TRUE;
135 $this->dialog= TRUE;
136 }
138 /* Add alternatives from dialog */
139 if (isset($_POST['add_locals_finish'])){
140 if (isset($_POST['local_list']) &&
141 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
143 foreach ($_POST['local_list'] as $val){
144 $this->addAlternate($val);
145 $this->is_modified= TRUE;
146 }
147 }
148 }
150 /* Add alternatives */
151 if (isset($_POST['add_alternate'])){
152 if ($_POST['forward_address'] != "" &&
153 is_phone_nr($_POST['forward_address']) &&
154 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
156 $this->addAlternate($_POST['forward_address']);
157 }
158 }
160 /* Delete alternate fax number */
161 if (isset($_POST['delete_alternate'])){
162 if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
163 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
165 $this->delAlternate ($_POST['alternate_list']);
166 }
167 }
170 /* Edit incoming blocklists */
171 if (isset($_POST['edit_incoming'])){
172 $this->current_blocklist= array_merge($this->goFaxRBlocklist,
173 $this->goFaxRBlockgroups);
174 sort($this->current_blocklist);
175 reset($this->current_blocklist);
177 $this->in_blocklist_dialog= TRUE;
178 $this->dialog= TRUE;
179 }
181 /* Edit outgoing blocklists */
182 if (isset($_POST['edit_outgoing'])){
183 $this->current_blocklist= array_merge($this->goFaxSBlocklist,
184 $this->goFaxSBlockgroups);
185 sort($this->current_blocklist);
186 reset($this->current_blocklist);
188 $this->out_blocklist_dialog= TRUE;
189 $this->dialog= TRUE;
190 }
192 /* Add number to blocklist (dialog) */
193 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
194 if (!is_phone_nr($_POST['block_number'])){
195 print_red (_("You're trying to add an invalid phone number."));
196 } else {
197 array_push($this->current_blocklist, $_POST['block_number']);
198 $this->current_blocklist= array_unique($this->current_blocklist);
199 sort($this->current_blocklist);
200 reset($this->current_blocklist);
201 }
202 }
204 /* Add list to blocklist */
205 if (isset($_POST['add_blocklist']) && isset($_POST['predefined_list'])){
206 $this->current_blocklist= array_merge($this->current_blocklist,
207 $_POST['predefined_list']);
208 $this->current_blocklist= array_unique($this->current_blocklist);
209 sort($this->current_blocklist);
210 reset($this->current_blocklist);
211 }
213 /* Delete from blocklist */
214 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
215 $tmp= array();
216 foreach($this->current_blocklist as $val){
217 if (!in_array($val, $_POST['block_list'])){
218 $tmp[]= $val;
219 }
220 }
221 $this->current_blocklist= $tmp;
222 }
224 /* Blocklist edit finished */
225 if (isset($_POST['edit_blocklists_finish'])){
227 /* Incoming or outgoing? */
228 if ($this->in_blocklist_dialog){
229 $destlist="goFaxRBlocklist";
230 $destgroup="goFaxRBlockgroups";
231 } else {
232 $destlist="goFaxSBlocklist";
233 $destgroup="goFaxSBlockgroups";
234 }
236 /* Transfer values to ourself */
237 $this->$destlist= array();
238 $this->$destgroup= array();
240 foreach ($this->current_blocklist as $val){
241 if (is_phone_nr($val)){
242 array_push($this->$destlist, $val);
243 } else {
244 array_push($this->$destgroups, $val);
245 }
246 }
248 $this->is_modified= TRUE;
249 }
251 /* Set departments */
252 if ($this->locals_dialog ||
253 $this->in_blocklist_dialog ||
254 $this->out_blocklist_dialog){
256 $list= array ();
257 $ldap= $this->config->get_ldap_link();
258 if (isset ($_POST['department'])){
259 $ldap->cd ($_POST['department']);
260 } else {
261 $ldap->cd ($this->config->current['BASE']);
262 }
263 }
265 /* Cancel dialogs */
266 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
267 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
269 $this->locals_dialog= FALSE;
270 $this->in_blocklist_dialog= FALSE;
271 $this->out_blocklist_dialog= FALSE;
272 $this->dialog= FALSE;
273 }
275 /* Manage locals dialog */
276 if ($this->locals_dialog){
278 /* Save data */
279 $faxfilter= get_global("faxfilter");
280 foreach( array("depselect", "fuser", "regex") as $type){
281 if (isset($_POST[$type])){
282 $faxfilter[$type]= $_POST[$type];
283 }
284 }
285 if (isset($_GET['search'])){
286 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
287 if ($s == "**"){
288 $s= "*";
289 }
290 $faxfilter['fuser']= $s;
291 }
292 register_global("faxfilter", $faxfilter);
294 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
295 $regex= $faxfilter['regex'];
296 $filter= "(facimileTelephoneNumber=$regex)";
297 } else {
298 $filter= "";
299 }
300 if ($faxfilter['fuser'] != ""){
301 $user= $faxfilter['fuser'];
302 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
303 }
305 $base= $faxfilter['depselect'];
306 $acl= array($this->config->current['BASE'] => ":all");
307 $res= get_list($acl, "(&(objectClass=goFaxAccount)$filter)", TRUE, $base, array("sn", "givenName", "facsimileTelephoneNumber"), TRUE);
309 foreach ($res as $attrs){
310 $list[$attrs['facsimileTelephoneNumber'][0]]=
311 $attrs['sn'][0].", ".
312 $attrs['givenName'][0]." [".
313 $attrs['facsimileTelephoneNumber'][0]."]";
314 }
316 /* Show dialog */
317 $smarty->assign("search_image", get_template_path('images/search.png'));
318 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
319 $smarty->assign("tree_image", get_template_path('images/tree.png'));
320 $smarty->assign("infoimage", get_template_path('images/info.png'));
321 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
322 $smarty->assign("departments", $this->config->idepartments);
323 $smarty->assign("list", $list);
324 if (isset($_POST['depselect'])){
325 $smarty->assign("depselect", $_POST['depselect']);
326 }
327 $smarty->assign("deplist", $this->config->idepartments);
328 $smarty->assign("apply", apply_filter());
329 $smarty->assign("alphabet", generate_alphabet());
330 $smarty->assign("hint", print_sizelimit_warning());
331 foreach( array("depselect", "fuser", "regex") as $type){
332 $smarty->assign("$type", $faxfilter[$type]);
333 }
334 $smarty->assign("hint", print_sizelimit_warning());
336 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
337 return ($display);
338 }
340 /* Manage incoming blocklists */
341 if ($this->in_blocklist_dialog){
342 $ldap->search ("(objectClass=goFaxRBlock)");
343 while ($attrs= $ldap->fetch()){
344 $list[$attrs['cn'][0]]=
345 $attrs['description'][0].
346 " [".$attrs['cn'][0]."]";
347 }
349 /* Show dialog */
350 $smarty->assign("cblocklist", $this->current_blocklist);
351 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
352 $smarty->assign("departments", $this->config->idepartments);
353 $smarty->assign("list", $list);
355 if (isset($_POST['department'])){
356 $smarty->assign("department", $_POST['department']);
357 } else {
358 $smarty->assign("department", "");
359 }
363 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
364 return ($display);
365 }
367 /* Manage outgoing blocklists */
368 if ($this->out_blocklist_dialog){
369 $ldap->search ("(objectClass=goFaxSBlock)");
370 while ($attrs= $ldap->fetch()){
371 if (isset($attrs['description'][0])){
372 $list[$attrs['cn'][0]]= $attrs['cn'][0].
373 " [".$attrs['description'][0]."]";
374 } else {
375 $list[$attrs['cn'][0]]= $attrs['cn'][0];
376 }
377 }
379 /* Show dialog */
380 $smarty->assign("cblocklist", $this->current_blocklist);
381 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
382 $smarty->assign("departments", $this->config->idepartments);
383 $smarty->assign("list", $list);
384 if (isset($_POST['department'])){
385 $smarty->assign("department", $_POST['department']);
386 } else {
387 $smarty->assign("department", "");
388 }
391 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
392 return ($display);
393 }
396 /* Show main page */
397 $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
398 $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
399 $smarty->assign("printers", $this->printerList);
401 /* Load attributes */
402 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
403 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
404 "facsimileAlternateTelephoneNumber", "mail") as $val){
406 $smarty->assign("$val", $this->$val);
407 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
408 }
409 $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
410 $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
412 /* Load checkboxes */
413 if ($this->goFaxIsEnabled == "1"){
414 $smarty->assign("goFaxIsEnabled", "");
415 } else {
416 $smarty->assign("goFaxIsEnabled", "checked");
417 }
418 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
419 if ($this->goFaxDeliveryMode & 32) {
420 $smarty->assign("fax_to_mail", "checked");
421 } else {
422 $smarty->assign("fax_to_mail", "");
423 }
424 if ($this->goFaxDeliveryMode & 64) {
425 $smarty->assign("fax_to_printer", "checked");
426 } else {
427 $smarty->assign("fax_to_printer", "");
428 }
431 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
432 return ($display);
433 }
435 function remove_from_parent()
436 {
437 /* Cancel if there's nothing to do here */
438 if (!$this->initially_was_account){
439 return;
440 }
442 plugin::remove_from_parent();
444 /* Zero out arrays */
445 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
446 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
448 $this->attrs[$val]= array();
449 }
451 /* Adapt mail settings if needed */
452 if ($this->parent->by_object['mailAccount']->is_account){
453 unset($this->attrs['mail']);
454 }
456 $ldap= $this->config->get_ldap_link();
457 $ldap->cd($this->dn);
458 $ldap->modify($this->attrs);
459 show_ldap_error($ldap->get_error());
461 /* Optionally execute a command after we're done */
462 $this->handle_post_events('remove');
463 }
466 /* Check formular input */
467 function check()
468 {
469 /* Reset message array */
470 $message= array();
472 /* must: facsimileTelephoneNumber */
473 if ($this->facsimileTelephoneNumber == ""){
474 $message[]= _("The required field 'Fax' is not set.");
475 }
477 if (!is_phone_nr($this->facsimileTelephoneNumber)){
478 $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
479 }
481 /* IF mail is specified (which is only the case if there's no mail account
482 present), check if it's valid.. */
483 if (@isset($this->parent->by_object['mailAccount']) &&
484 $this->goFaxDeliveryMode && 32){
485 if ($this->mail == ""){
486 $message[]= _("Mail delivery is checked, but no address has been specified.");
487 } elseif (!is_email($this->mail)){
488 $message[]= _("The mail address you've entered is invalid.");
489 }
490 }
492 // IE Fix, IE lets you choose disabled option, stupid browser ...
493 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
494 $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
495 }
497 return ($message);
498 }
500 /* Save data to object */
501 function save_object()
502 {
503 if (isset($_POST['faxTab'])){
504 plugin::save_object();
506 /* Adapt combobox values */
507 $tmp= 0;
508 if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
509 $tmp+= 32;
510 }
511 if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
512 $tmp+= 64;
513 }
514 if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
515 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
516 $this->goFaxIsEnabled= "0";
517 } else {
518 $this->goFaxIsEnabled= "1";
519 }
520 }
522 if (isset($_POST['facsimileTelephoneNumber'])){
523 if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
524 $this->is_modified= TRUE;
525 }
526 $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
527 }
529 if (isset($_POST['mail'])){
530 if ($this->mail != $_POST['mail']){
531 $this->is_modified= TRUE;
532 }
533 $this->mail= $_POST['mail'];
534 }
536 /* Write to object */
537 if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
538 if ($tmp != $this->goFaxDeliveryMode){
539 $this->is_modified= TRUE;
540 }
541 $this->goFaxDeliveryMode= "$tmp";
542 }
544 /* Check if mail account is active and correct the internal
545 reference to represent the current status. */
546 if ($this->parent->by_object['mailAccount']->is_account){
547 $this->has_mailAccount= TRUE;
548 }
549 }
551 }
554 /* Save to LDAP */
555 function save()
556 {
557 plugin::save();
559 /* Save arrays */
560 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
561 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
563 $this->attrs[$val]= $this->$val;
564 }
566 /* Adapt mail settings if needed */
567 unset($this->attrs['mail']);
568 if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
569 $this->attrs['mail']= $this->mail;
570 }
572 /* Write back to ldap */
573 $ldap= $this->config->get_ldap_link();
574 $ldap->cd($this->dn);
575 $ldap->modify($this->attrs);
576 show_ldap_error($ldap->get_error());
578 /* Optionally execute a command after we're done */
579 if ($this->initially_was_account == $this->is_account){
580 if ($this->is_modified){
581 $this->handle_post_events("mofify");
582 }
583 } else {
584 $this->handle_post_events("add");
585 }
587 }
590 /* Adapt from template, using 'dn' */
591 function adapt_from_template($dn)
592 {
593 plugin::adapt_from_template($dn);
595 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
596 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
598 if (isset($this->attrs[$val])){
599 $this->$val= $this->attrs[$val];
600 }
601 }
602 }
606 /* Add alternate fax recipient */
607 function addAlternate($number)
608 {
609 $this->facsimileAlternateTelephoneNumber[]= "$number";
610 $this->facsimileAlternateTelephoneNumber=
611 array_unique ($this->facsimileAlternateTelephoneNumber);
613 sort ($this->facsimileAlternateTelephoneNumber);
614 reset ($this->facsimileAlternateTelephoneNumber);
615 }
617 function delAlternate($numbers)
618 {
619 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
620 $this->facsimileAlternateTelephoneNumber);
621 }
624 }
626 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
627 ?>