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 /* Load smarty stuff */
88 $smarty= get_smarty();
90 /* Check if mail account is active. We'll display an additional
91 mail address field if this is not the case. Some people may
92 want goFax, but have a mailserver which is not managed with
93 GOsa */
94 if (!@isset($this->parent->by_object['mailAccount'])) {
95 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
96 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
97 $smarty->assign("has_mailaccount", "false");
98 $this->has_mailAccount= false;
99 } else {
100 $smarty->assign("has_mailaccount", "true");
101 }
103 /* Do we need to flip is_account state? */
104 if (isset($_POST['modify_state'])){
105 $this->is_account= !$this->is_account;
106 }
108 /* Do we represent a valid account? */
109 if (!$this->is_account && $this->parent == NULL){
110 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
111 _("This account has no fax extensions.")."</b>";
112 $display.= back_to_main();
113 return ($display);
114 }
116 /* Show tab dialog headers */
117 $display= "";
118 if ($this->parent != NULL){
119 if ($this->is_account){
120 $display= $this->show_header(_("Remove fax account"),
121 _("This account has fax features enabled. You can disable them by clicking below."));
122 } else {
123 $display= $this->show_header(_("Create fax account"),
124 _("This account has fax features disabled. You can enable them by clicking below."));
125 return ($display);
126 }
127 }
129 /* Trigger Add local fax alternatives dialog */
130 if (isset($_POST['add_local_alternate'])){
131 $this->locals_dialog= TRUE;
132 $this->dialog= TRUE;
133 }
135 /* Add alternatives from dialog */
136 if (isset($_POST['add_locals_finish'])){
137 if (isset($_POST['local_list']) &&
138 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
140 foreach ($_POST['local_list'] as $val){
141 $this->addAlternate($val);
142 $this->is_modified= TRUE;
143 }
144 }
145 }
147 /* Add alternatives */
148 if (isset($_POST['add_alternate'])){
149 if ($_POST['forward_address'] != "" &&
150 is_phone_nr($_POST['forward_address']) &&
151 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
153 $this->addAlternate($_POST['forward_address']);
154 }
155 }
157 /* Delete alternate fax number */
158 if (isset($_POST['delete_alternate'])){
159 if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
160 chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
162 $this->delAlternate ($_POST['alternate_list']);
163 }
164 }
167 /* Edit incoming blocklists */
168 if (isset($_POST['edit_incoming'])){
169 $this->current_blocklist= array_merge($this->goFaxRBlocklist,
170 $this->goFaxRBlockgroups);
171 sort($this->current_blocklist);
172 reset($this->current_blocklist);
174 $this->in_blocklist_dialog= TRUE;
175 $this->dialog= TRUE;
176 }
178 /* Edit outgoing blocklists */
179 if (isset($_POST['edit_outgoing'])){
180 $this->current_blocklist= array_merge($this->goFaxSBlocklist,
181 $this->goFaxSBlockgroups);
182 sort($this->current_blocklist);
183 reset($this->current_blocklist);
185 $this->out_blocklist_dialog= TRUE;
186 $this->dialog= TRUE;
187 }
189 /* Add number to blocklist (dialog) */
190 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
191 if (!is_phone_nr($_POST['block_number'])){
192 print_red (_("You're trying to add an invalid phone number."));
193 } else {
194 array_push($this->current_blocklist, $_POST['block_number']);
195 $this->current_blocklist= array_unique($this->current_blocklist);
196 sort($this->current_blocklist);
197 reset($this->current_blocklist);
198 }
199 }
201 /* Add list to blocklist */
202 if (isset($_POST['add_blocklist']) && isset($_POST['predefined_list'])){
203 $this->current_blocklist= array_merge($this->current_blocklist,
204 $_POST['predefined_list']);
205 $this->current_blocklist= array_unique($this->current_blocklist);
206 sort($this->current_blocklist);
207 reset($this->current_blocklist);
208 }
210 /* Delete from blocklist */
211 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
212 $tmp= array();
213 foreach($this->current_blocklist as $val){
214 if (!in_array($val, $_POST['block_list'])){
215 $tmp[]= $val;
216 }
217 }
218 $this->current_blocklist= $tmp;
219 }
221 /* Blocklist edit finished */
222 if (isset($_POST['edit_blocklists_finish'])){
224 /* Incoming or outgoing? */
225 if ($this->in_blocklist_dialog){
226 $destlist="goFaxRBlocklist";
227 $destgroup="goFaxRBlockgroups";
228 } else {
229 $destlist="goFaxSBlocklist";
230 $destgroup="goFaxSBlockgroups";
231 }
233 /* Transfer values to ourself */
234 $this->$destlist= array();
235 $this->$destgroup= array();
237 foreach ($this->current_blocklist as $val){
238 if (is_phone_nr($val)){
239 array_push($this->$destlist, $val);
240 } else {
241 array_push($this->$destgroups, $val);
242 }
243 }
245 $this->is_modified= TRUE;
246 }
248 /* Set departments */
249 if ($this->locals_dialog ||
250 $this->in_blocklist_dialog ||
251 $this->out_blocklist_dialog){
253 $list= array ();
254 $ldap= $this->config->get_ldap_link();
255 if (isset ($_POST['department'])){
256 $ldap->cd ($_POST['department']);
257 } else {
258 $ldap->cd ($this->config->current['BASE']);
259 }
260 }
262 /* Cancel dialogs */
263 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
264 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
266 $this->locals_dialog= FALSE;
267 $this->in_blocklist_dialog= FALSE;
268 $this->out_blocklist_dialog= FALSE;
269 $this->dialog= FALSE;
270 }
272 /* Manage locals dialog */
273 if ($this->locals_dialog){
275 /* Save data */
276 $faxfilter= get_global("faxfilter");
277 foreach( array("depselect", "fuser", "regex") as $type){
278 if (isset($_POST[$type])){
279 $faxfilter[$type]= $_POST[$type];
280 }
281 }
282 if (isset($_GET['search'])){
283 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
284 if ($s == "**"){
285 $s= "*";
286 }
287 $faxfilter['fuser']= $s;
288 }
289 register_global("faxfilter", $faxfilter);
291 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
292 $regex= $faxfilter['regex'];
293 $filter= "(facimileTelephoneNumber=$regex)";
294 } else {
295 $filter= "";
296 }
297 if ($faxfilter['fuser'] != ""){
298 $user= $faxfilter['fuser'];
299 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
300 }
302 $base= $faxfilter['depselect'];
303 $acl= array($this->config->current['BASE'] => ":all");
304 $res= get_list($acl, "(&(objectClass=goFaxAccount)$filter)", TRUE, $base, array("sn", "givenName", "facsimileTelephoneNumber"), TRUE);
306 foreach ($res as $attrs){
307 $list[$attrs['facsimileTelephoneNumber'][0]]=
308 $attrs['sn'][0].", ".
309 $attrs['givenName'][0]." [".
310 $attrs['facsimileTelephoneNumber'][0]."]";
311 }
313 /* Show dialog */
314 $smarty->assign("search_image", get_template_path('images/search.png'));
315 $smarty->assign("tree_image", get_template_path('images/tree.png'));
316 $smarty->assign("infoimage", get_template_path('images/info.png'));
317 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
318 $smarty->assign("departments", $this->config->idepartments);
319 $smarty->assign("list", $list);
320 if (isset($_POST['depselect'])){
321 $smarty->assign("depselect", $_POST['depselect']);
322 }
323 $smarty->assign("deplist", $this->config->idepartments);
324 $smarty->assign("apply", apply_filter());
325 $smarty->assign("alphabet", generate_alphabet());
326 $smarty->assign("hint", print_sizelimit_warning());
327 foreach( array("depselect", "fuser", "regex") as $type){
328 $smarty->assign("$type", $faxfilter[$type]);
329 }
330 $smarty->assign("hint", print_sizelimit_warning());
332 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
333 return ($display);
334 }
336 /* Manage incoming blocklists */
337 if ($this->in_blocklist_dialog){
338 $ldap->search ("(objectClass=goFaxRBlock)");
339 while ($attrs= $ldap->fetch()){
340 $list[$attrs['cn'][0]]=
341 $attrs['description'][0].
342 " [".$attrs['cn'][0]."]";
343 }
345 /* Show dialog */
346 $smarty->assign("cblocklist", $this->current_blocklist);
347 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
348 $smarty->assign("departments", $this->config->idepartments);
349 $smarty->assign("list", $list);
351 if (isset($_POST['department'])){
352 $smarty->assign("department", $_POST['department']);
353 } else {
354 $smarty->assign("department", "");
355 }
359 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
360 return ($display);
361 }
363 /* Manage outgoing blocklists */
364 if ($this->out_blocklist_dialog){
365 $ldap->search ("(objectClass=goFaxSBlock)");
366 while ($attrs= $ldap->fetch()){
367 if (isset($attrs['description'][0])){
368 $list[$attrs['cn'][0]]= $attrs['cn'][0].
369 " [".$attrs['description'][0]."]";
370 } else {
371 $list[$attrs['cn'][0]]= $attrs['cn'][0];
372 }
373 }
375 /* Show dialog */
376 $smarty->assign("cblocklist", $this->current_blocklist);
377 $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
378 $smarty->assign("departments", $this->config->idepartments);
379 $smarty->assign("list", $list);
380 if (isset($_POST['department'])){
381 $smarty->assign("department", $_POST['department']);
382 } else {
383 $smarty->assign("department", "");
384 }
387 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
388 return ($display);
389 }
392 /* Show main page */
393 $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
394 $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
395 $smarty->assign("printers", $this->printerList);
397 /* Load attributes */
398 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
399 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
400 "facsimileAlternateTelephoneNumber", "mail") as $val){
402 $smarty->assign("$val", $this->$val);
403 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
404 }
405 $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
406 $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
408 /* Load checkboxes */
409 if ($this->goFaxIsEnabled == "1"){
410 $smarty->assign("goFaxIsEnabled", "");
411 } else {
412 $smarty->assign("goFaxIsEnabled", "checked");
413 }
414 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
415 if ($this->goFaxDeliveryMode & 32) {
416 $smarty->assign("fax_to_mail", "checked");
417 } else {
418 $smarty->assign("fax_to_mail", "");
419 }
420 if ($this->goFaxDeliveryMode & 64) {
421 $smarty->assign("fax_to_printer", "checked");
422 } else {
423 $smarty->assign("fax_to_printer", "");
424 }
427 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
428 return ($display);
429 }
431 function remove_from_parent()
432 {
433 /* Cancel if there's nothing to do here */
434 if (!$this->initially_was_account){
435 return;
436 }
438 plugin::remove_from_parent();
440 /* Zero out arrays */
441 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
442 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
444 $this->attrs[$val]= array();
445 }
447 /* Adapt mail settings if needed */
448 if ($this->parent->by_object['mailAccount']->is_account){
449 unset($this->attrs['mail']);
450 }
452 $ldap= $this->config->get_ldap_link();
453 $ldap->cd($this->dn);
454 $ldap->modify($this->attrs);
455 show_ldap_error($ldap->get_error());
457 /* Optionally execute a command after we're done */
458 $this->handle_post_events('remove');
459 }
462 /* Check formular input */
463 function check()
464 {
465 /* Reset message array */
466 $message= array();
468 /* must: facsimileTelephoneNumber */
469 if ($this->facsimileTelephoneNumber == ""){
470 $message[]= _("The required field 'Fax' is not set.");
471 }
473 if (!is_phone_nr($this->facsimileTelephoneNumber)){
474 $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
475 }
477 /* IF mail is specified (which is only the case if there's no mail account
478 present), check if it's valid.. */
479 if (@isset($this->parent->by_object['mailAccount']) &&
480 $this->goFaxDeliveryMode && 32){
481 if ($this->mail == ""){
482 $message[]= _("Mail delivery is checked, but no address has been specified.");
483 } elseif (!is_email($this->mail)){
484 $message[]= _("The mail address you've entered is invalid.");
485 }
486 }
488 // IE Fix, IE lets you choose disabled option, stupid browser ...
489 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
490 $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
491 }
493 return ($message);
494 }
496 /* Save data to object */
497 function save_object()
498 {
499 if (isset($_POST['faxTab'])){
500 plugin::save_object();
502 /* Adapt combobox values */
503 $tmp= 0;
504 if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
505 $tmp+= 32;
506 }
507 if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
508 $tmp+= 64;
509 }
510 if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
511 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
512 $this->goFaxIsEnabled= "0";
513 } else {
514 $this->goFaxIsEnabled= "1";
515 }
516 }
518 if (isset($_POST['facsimileTelephoneNumber'])){
519 if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
520 $this->is_modified= TRUE;
521 }
522 $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
523 }
525 if (isset($_POST['mail'])){
526 if ($this->mail != $_POST['mail']){
527 $this->is_modified= TRUE;
528 }
529 $this->mail= $_POST['mail'];
530 }
532 /* Write to object */
533 if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
534 if ($tmp != $this->goFaxDeliveryMode){
535 $this->is_modified= TRUE;
536 }
537 $this->goFaxDeliveryMode= "$tmp";
538 }
540 /* Check if mail account is active and correct the internal
541 reference to represent the current status. */
542 if ($this->parent->by_object['mailAccount']->is_account){
543 $this->has_mailAccount= TRUE;
544 }
545 }
547 }
550 /* Save to LDAP */
551 function save()
552 {
553 plugin::save();
555 /* Save arrays */
556 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
557 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
559 $this->attrs[$val]= $this->$val;
560 }
562 /* Adapt mail settings if needed */
563 unset($this->attrs['mail']);
564 if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
565 $this->attrs['mail']= $this->mail;
566 }
568 /* Write back to ldap */
569 $ldap= $this->config->get_ldap_link();
570 $ldap->cd($this->dn);
571 $ldap->modify($this->attrs);
572 show_ldap_error($ldap->get_error());
574 /* Optionally execute a command after we're done */
575 if ($this->initially_was_account == $this->is_account){
576 if ($this->is_modified){
577 $this->handle_post_events("mofify");
578 }
579 } else {
580 $this->handle_post_events("add");
581 }
583 }
586 /* Adapt from template, using 'dn' */
587 function adapt_from_template($dn)
588 {
589 plugin::adapt_from_template($dn);
591 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
592 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
594 if (isset($this->attrs[$val])){
595 $this->$val= $this->attrs[$val];
596 }
597 }
598 }
602 /* Add alternate fax recipient */
603 function addAlternate($number)
604 {
605 $this->facsimileAlternateTelephoneNumber[]= "$number";
606 $this->facsimileAlternateTelephoneNumber=
607 array_unique ($this->facsimileAlternateTelephoneNumber);
609 sort ($this->facsimileAlternateTelephoneNumber);
610 reset ($this->facsimileAlternateTelephoneNumber);
611 }
613 function delAlternate($numbers)
614 {
615 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
616 $this->facsimileAlternateTelephoneNumber);
617 }
620 }
622 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
623 ?>