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 /* Copy & paste variables */
42 var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
44 /* attribute list for save action */
45 var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
47 var $uid ="";
49 var $objectclasses= array("goFaxAccount");
51 function gofaxAccount ($config, $dn= NULL)
52 {
53 /* General initialization */
54 plugin::plugin ($config, $dn);
56 /* Set uid, it is used in handle_post_events */
57 if(isset($this->attrs['uid'])){
58 $this->uid = $this->attrs['uid'][0];
59 }
61 /* Hickert : 11.11.05
62 * Added to be able to handle department selection in divSelelect
63 */
64 if(!isset($_SESSION["Fax_Filter"])){
65 $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
66 }
68 if ($dn != "new"){
69 /* Get arrays */
70 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
71 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
72 $this->$val =array();
73 if (isset($this->attrs["$val"]["count"])){
74 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
75 array_push($this->$val, $this->attrs["$val"][$i]);
76 }
77 }
78 }
80 /* Set up has_mailAccount */
81 if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
82 $this->has_mailAccount= TRUE;
83 }
84 }
86 /* Load printer list */
87 if (isset($this->config->data['SERVERS']['CUPS'])){
88 $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
89 asort ($this->printerList);
90 }
92 /* Check if the currently selected printer is still available.
93 If not, append current printer to list of available.
94 It could be possible, that we are not allowed to view printers and so the list is empty ... */
95 if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
96 $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
97 }
99 /* Get global filter config */
100 if (!is_global("faxfilter")){
101 $ui= get_userinfo();
102 $base= get_base_from_people($ui->dn);
103 $faxfilter= array( "depselect" => $base,
104 "fuser" => "*",
105 "regex" => "");
106 register_global("faxfilter", $faxfilter);
107 }
108 }
110 function execute()
111 {
112 /* Call parent execute */
113 plugin::execute();
114 /* Hickert : 11.11.05
115 * Added to be able to handle department selection in divSelelect
116 */
117 if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
119 if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
120 $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
121 }else{
122 $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
123 }
124 }
126 /* Edit mode specifies if we are editing from my accout */
127 $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
129 /* Load smarty stuff */
130 $smarty= get_smarty();
132 /* Check if mail account is active. We'll display an additional
133 mail address field if this is not the case. Some people may
134 want goFax, but have a mailserver which is not managed with
135 GOsa */
136 if (!@isset($this->parent->by_object['mailAccount'])) {
137 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
138 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
139 $smarty->assign("has_mailaccount", "false");
140 $this->has_mailAccount= false;
141 } else {
142 $smarty->assign("has_mailaccount", "true");
143 }
145 /* Do we need to flip is_account state? */
146 if (isset($_POST['modify_state'])){
147 $this->is_account= !$this->is_account;
148 }
150 /* Do we represent a valid account? */
151 if (!$this->is_account && $this->parent == NULL){
152 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
153 _("This account has no fax extensions.")."</b>";
154 $display.= back_to_main();
155 return ($display);
156 }
158 /* Show tab dialog headers */
159 $display= "";
160 if ($this->parent != NULL){
161 if ($this->is_account){
162 $display= $this->show_disable_header(_("Remove fax account"),
163 _("This account has fax features enabled. You can disable them by clicking below."));
164 } else {
165 $display= $this->show_enable_header(_("Create fax account"),
166 _("This account has fax features disabled. You can enable them by clicking below."));
167 return ($display);
168 }
169 }
171 /* Trigger Add local fax alternatives dialog */
172 if (isset($_POST['add_local_alternate'])){
173 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
174 $this->locals_dialog= TRUE;
175 $this->dialog= TRUE;
176 }
177 }
179 /* Add alternatives from dialog */
180 if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
181 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
182 foreach ($_POST['local_list'] as $val){
183 $this->addAlternate($val);
184 $this->is_modified= TRUE;
185 }
186 }
187 }
189 /* Add alternatives */
190 if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){
191 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
192 $this->addAlternate($_POST['forward_address']);
193 }
194 }
196 /* Delete alternate fax number */
197 if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){
198 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
199 $this->delAlternate ($_POST['alternate_list']);
200 }
201 }
204 /* Edit incoming blocklists */
205 if (isset($_POST['edit_incoming'])){
206 if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode)) {
207 $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
208 sort($this->current_blocklist);
209 reset($this->current_blocklist);
211 $this->in_blocklist_dialog= TRUE;
212 $this->dialog= TRUE;
213 }
214 }
216 /* Edit outgoing blocklists */
217 if (isset($_POST['edit_outgoing'])){
218 $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
219 sort($this->current_blocklist);
220 reset($this->current_blocklist);
222 $this->out_blocklist_dialog= TRUE;
223 $this->dialog= TRUE;
224 }
226 /* Add number to blocklist (dialog) */
227 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
228 if (!is_phone_nr($_POST['block_number'])){
229 print_red (_("You're trying to add an invalid phone number."));
230 } else {
231 array_push($this->current_blocklist, $_POST['block_number']);
232 $this->current_blocklist= array_unique($this->current_blocklist);
233 sort($this->current_blocklist);
234 reset($this->current_blocklist);
235 }
236 }
238 /* Hickert : 11.11.05
239 * Add selection from divSelelect to our Blocklist
240 */
241 /* Add list to blocklist */
242 if (isset($_POST['add_blocklist'])){
243 foreach($_POST as $name => $value){
244 if(preg_match("/ADDLIST_/i",$name)){
245 $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
247 }
248 }
249 $this->current_blocklist= array_unique($this->current_blocklist);
250 sort($this->current_blocklist);
251 reset($this->current_blocklist);
252 }
254 /* Add list to blocklist */
255 if (isset($_GET['add'])){
256 if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
257 $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
258 $this->current_blocklist= array_unique($this->current_blocklist);
259 sort($this->current_blocklist);
260 reset($this->current_blocklist);
261 }
263 /* Delete from blocklist */
264 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
265 $tmp= array();
266 foreach($this->current_blocklist as $val){
267 if (!in_array($val, $_POST['block_list'])){
268 $tmp[]= $val;
269 }
270 }
271 $this->current_blocklist= $tmp;
272 }
275 /* Blocklist edit finished */
276 if (isset($_POST['edit_blocklists_finish'])){
278 /* Incoming or outgoing? */
279 if ($this->in_blocklist_dialog){
280 $this->goFaxRBlocklist = array();
281 $this->goFaxRBlockgroups = array();
283 foreach ($this->current_blocklist as $val){
284 if (is_phone_nr($val)){
285 $this->goFaxRBlocklist[]=$val;
286 } else {
287 $this->goFaxRBlockgroups[]= $val;
288 }
289 }
290 } else {
291 $this->goFaxSBlocklist = array();
292 $this->goFaxSBlockgroups = array();
294 /* Transfer values to ourself */
295 foreach ($this->current_blocklist as $val){
296 if (is_phone_nr($val)){
297 $this->goFaxSBlocklist[]=$val;
298 } else {
299 $this->goFaxSBlockgroups[]= $val;
300 }
301 }
302 }
303 $this->is_modified= TRUE;
304 }
307 /* Set departments */
308 if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
310 $list= array ();
311 $ldap= $this->config->get_ldap_link();
312 if (isset ($_POST['department'])){
313 $ldap->cd ($_POST['department']);
314 } else {
315 $ldap->cd ($this->config->current['BASE']);
316 }
317 }
319 /* Cancel dialogs */
320 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
321 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
323 $this->locals_dialog= FALSE;
324 $this->in_blocklist_dialog= FALSE;
325 $this->out_blocklist_dialog= FALSE;
326 $this->dialog= FALSE;
327 }
329 /* Manage locals dialog */
330 if ($this->locals_dialog){
332 /* Save data */
333 $faxfilter= get_global("faxfilter");
334 foreach( array("depselect", "fuser", "regex") as $type){
335 if (isset($_POST[$type])){
336 $faxfilter[$type]= $_POST[$type];
337 }
338 }
339 if (isset($_GET['search'])){
340 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
341 if ($s == "**"){
342 $s= "*";
343 }
344 $faxfilter['fuser']= $s;
345 }
347 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
348 $regex= $faxfilter['regex'];
349 $filter= "(facimileTelephoneNumber=$regex)";
350 } else {
351 $filter= "";
352 }
353 if ($faxfilter['fuser'] != ""){
354 $user= $faxfilter['fuser'];
355 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
356 }
358 $base= $faxfilter['depselect'];
359 $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base,
360 array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
362 foreach ($res as $attrs){
363 $list[$attrs['facsimileTelephoneNumber'][0]]=
364 $attrs['sn'][0].", ".
365 $attrs['givenName'][0]." [".
366 $attrs['facsimileTelephoneNumber'][0]."]";
367 }
369 /* Show dialog */
370 $smarty->assign("search_image", get_template_path('images/search.png'));
371 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
372 $smarty->assign("tree_image", get_template_path('images/tree.png'));
373 $smarty->assign("infoimage", get_template_path('images/info.png'));
374 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
375 $smarty->assign("departments", $this->config->idepartments);
376 $smarty->assign("list", $list);
377 if (isset($_POST['depselect'])){
378 $smarty->assign("depselect", $_POST['depselect']);
379 }
380 $smarty->assign("deplist", $this->config->idepartments);
381 $smarty->assign("apply", apply_filter());
382 $smarty->assign("alphabet", generate_alphabet());
383 $smarty->assign("hint", print_sizelimit_warning());
384 foreach( array("depselect", "fuser", "regex") as $type){
385 $smarty->assign("$type", $faxfilter[$type]);
386 }
387 $smarty->assign("hint", print_sizelimit_warning());
389 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
390 return ($display);
391 }
394 /* Manage incoming blocklists */
395 if ($this->in_blocklist_dialog){
397 /* This handles the divSelectBox */
399 /* The base specifies the current position in the ldap tree
400 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
401 */
402 $base = $_SESSION['Fax_Filter']['depselect'];
403 $ldap->cd($base);
405 /* Ge all Blocklists */
406 $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
407 while ($attrs= $ldap->fetch()){
409 /* Generate list depending on description */
410 if(isset($attrs['description'][0])){
411 $list[$attrs['cn'][0]]=
412 $attrs['description'][0].
413 " [".$attrs['cn'][0]."]";
414 }else{
415 $list[$attrs['cn'][0]]= $attrs['cn'][0];
416 }
417 }
419 /* Create our divselect box */
420 $divSel = new divSelectBox("divSelectPredefined");
421 $divSel->setHeight(296);
423 /* NEW LIST MANAGMENT
424 * We also need to search for the departments
425 * So we are able to navigate like in konquerer
426 */
427 $this->departments= array();
429 /* Get all departments within the current department */
430 $base = $_SESSION['Fax_Filter']['depselect'];
431 $ldap->ls("(objectClass=gosaDepartment)",$base);
433 /* Base back is used to go one department up in our ldap tree */
434 $base_back = preg_replace("/^[^,]+,/","",$base);
436 /* Only show base_back if it is needed */
437 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
438 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
439 }
441 /* Fetch all returned departments an add them to our divlist */
442 while($value = $ldap->fetch()){
443 if($value["description"][0]!=".."){
444 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
445 }else{
446 $this->departments[$value['dn']]=$value["description"][0];
447 }
448 }
449 /* END NEW LIST MANAGMENT
450 */
452 // This links specifies the department open link
453 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
455 /* Insert departments in divsel */
456 foreach($this->departments as $key=> $val){
457 if(!isset($this->config->departments[trim($key)])){
458 $this->config->departments[trim($key)]="";
459 }
460 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
461 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
462 $divSel->AddEntry(array($field1,$field2));
463 }
465 /* Append predefined Blocklists */
466 foreach($list as $entry => $value){
467 $divSel->AddEntry(array(
468 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
469 array("string"=>$value,"attach"=>"style='border:0px;'")
470 ));
471 }
473 /* Show dialog */
474 $smarty->assign("cblocklist", $this->current_blocklist);
475 $smarty->assign("departments", $this->config->idepartments);
476 $smarty->assign("divSelectPredefined", $divSel->DrawList());
477 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
478 return ($display);
479 }
481 /* Manage outgoing blocklists */
483 if ($this->out_blocklist_dialog){
485 /* This handles the divSelectBox */
487 /* The base specifies the current position in the ldap tree
488 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
489 */
490 $base = $_SESSION['Fax_Filter']['depselect'];
491 $ldap->cd($base);
493 /* Ge all Blocklists */
494 $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
495 while ($attrs= $ldap->fetch()){
496 if(isset($attrs['description'][0])){
497 $list[$attrs['cn'][0]]=
498 $attrs['description'][0].
499 " [".$attrs['cn'][0]."]";
500 }else{
501 $list[$attrs['cn'][0]]= $attrs['cn'][0];
502 }
503 }
505 /*Create DivSel*/
506 $divSel = new divSelectBox("divSelectPredefined");
507 $divSel->setHeight(296);
509 /* NEW LIST MANAGMENT
510 * We also need to search for the departments
511 * So we are able to navigate like in konquerer
512 */
513 $this->departments= array();
514 $ldap->ls("(objectClass=gosaDepartment)",$base);
516 /* Generate Back url, and append if it is needed */
517 $base_back = preg_replace("/^[^,]+,/","",$base);
518 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
519 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
520 }
522 /* Get all departments */
523 while($value = $ldap->fetch()){
524 if(isset($value["description"][0])){
525 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
526 }else{
527 $this->departments[$value['dn']]=$value["description"][0];
528 }
529 }
530 /* END NEW LIST MANAGMENT
531 */
533 // Defining Links
534 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
536 /* Insert departments in divlist*/
537 foreach($this->departments as $key=> $val){
538 if(!isset($this->config->departments[trim($key)])){
539 $this->config->departments[trim($key)]="";
540 }
542 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
543 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
544 $divSel->AddEntry(array($field1,$field2));
545 }
547 /* Append Blocklits */
548 foreach($list as $entry => $value){
549 $divSel->AddEntry(array(
550 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
551 array("string"=>$value,"attach"=>"style='border:0px;'")
552 ));
553 }
555 /* Show dialog */
556 $smarty->assign("cblocklist", $this->current_blocklist);
557 $smarty->assign("departments", $this->config->idepartments);
558 $smarty->assign("divSelectPredefined", $divSel->DrawList());
559 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
560 return ($display);
561 }
564 /* Show main page */
565 $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
566 $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
567 $smarty->assign("printers", $this->printerList);
569 /* Load attributes */
570 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
571 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
572 "facsimileAlternateTelephoneNumber", "mail") as $val){
574 $smarty->assign("$val", $this->$val);
575 }
577 $tmp = $this->plInfo();
578 foreach($tmp['plProvidedAcls'] as $acl => $desc){
579 $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
580 }
582 /* Load checkboxes */
583 if ($this->goFaxIsEnabled == "1"){
584 $smarty->assign("goFaxIsEnabled", "");
585 } else {
586 $smarty->assign("goFaxIsEnabled", "checked");
587 }
588 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
589 if ($this->goFaxDeliveryMode & 32) {
590 $smarty->assign("faxtomail", "checked");
591 } else {
592 $smarty->assign("faxtomail", "");
593 }
594 if ($this->goFaxDeliveryMode & 64) {
595 $smarty->assign("faxtoprinter", "checked");
596 } else {
597 $smarty->assign("faxtoprinter", "");
598 }
601 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
602 return ($display);
603 }
605 function remove_from_parent()
606 {
607 /* Cancel if there's nothing to do here */
608 if (!$this->initially_was_account){
609 return;
610 }
612 plugin::remove_from_parent();
614 /* Adapt mail settings if needed */
615 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($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(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
626 /* Optionally execute a command after we're done */
627 $this->handle_post_events('remove',array("uid"=> $this->uid));
628 }
631 /* Check formular input */
632 function check()
633 {
634 /* Call common method to give check the hook */
635 $message= plugin::check();
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 $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
669 if (isset($_POST['faxTab'])){
670 plugin::save_object();
673 $tmp = 0+$this->goFaxDeliveryMode;
675 if($this->acl_is_writeable("faxtomail",$edit_mode)){
676 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
677 $tmp |= 32;
678 }elseif($tmp & 32){
679 $tmp &= (!32);
680 }
681 }
682 if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
683 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
684 $tmp |= 64;
685 }elseif($tmp & 64){
686 $tmp &= !64;
687 }
688 }
689 $this->goFaxDeliveryMode = $tmp;
691 if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
692 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
693 $this->goFaxIsEnabled= "0";
694 } else {
695 $this->goFaxIsEnabled= "1";
696 }
697 }
700 if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
701 $this->mail= $_POST['mail'];
702 }
704 /* Check if mail account is active and correct the internal
705 reference to represent the current status. */
706 if(isset($this->parent)){
707 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
708 $this->has_mailAccount= TRUE;
709 }
710 }
711 }
713 }
716 /* Save to LDAP */
717 function save()
718 {
719 plugin::save();
721 /* Save arrays */
722 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
723 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
725 $this->attrs[$val]= $this->$val;
726 }
728 if(!$this->attrs['goFaxDeliveryMode']){
729 $this->attrs['goFaxDeliveryMode'] = 0;
730 }
732 /* Do not save mail address ... it was possibly changed by mail plugin */
733 /* Adapt mail settings if needed */
734 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
735 unset($this->attrs['mail']);
736 }
738 /* Write back to ldap */
739 $ldap= $this->config->get_ldap_link();
740 $ldap->cd($this->dn);
741 $this->cleanup();
742 $ldap->modify ($this->attrs);
744 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
746 /* Optionally execute a command after we're done */
747 if ($this->initially_was_account == $this->is_account){
748 if ($this->is_modified){
749 $this->handle_post_events("mofidy",array("uid" => $this->uid));
750 }
751 } else {
752 $this->handle_post_events("add",array("uid" => $this->uid));
753 }
755 }
758 /* Adapt from template, using 'dn' */
759 function adapt_from_template($dn)
760 {
761 plugin::adapt_from_template($dn);
763 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
764 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
766 if (isset($this->attrs[$val])){
767 $this->$val= $this->attrs[$val];
768 }
769 }
770 }
774 /* Add alternate fax recipient */
775 function addAlternate($number)
776 {
777 $this->facsimileAlternateTelephoneNumber[]= "$number";
778 $this->facsimileAlternateTelephoneNumber=
779 array_unique ($this->facsimileAlternateTelephoneNumber);
781 sort ($this->facsimileAlternateTelephoneNumber);
782 reset ($this->facsimileAlternateTelephoneNumber);
783 }
785 function delAlternate($numbers)
786 {
787 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
788 $this->facsimileAlternateTelephoneNumber);
789 }
791 function getCopyDialog()
792 {
793 $str = "";
794 $smarty = get_smarty();
795 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
796 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
797 $str['status'] ="";
798 return($str);
799 }
801 function SaveCopyDialog()
802 {
803 if(isset($_POST['facsimileTelephoneNumber'])){
804 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
805 }
806 }
809 /* Return plugin informations for acl handling
810 #FIXME some attributes are still missing in this plugin acls */
811 function plInfo()
812 {
813 return (array(
814 "plShortName" => _("Fax"),
815 "plDescription" => _("Fax account settings"),
816 "plSelfModify" => TRUE,
817 "plDepends" => array("user"),
818 "plPriority" => 6,
819 "plSection" => "personal",
820 "plCategory" => array("users"),
821 "plOptions" => array(),
823 "plProvidedAcls" => array(
824 "goFaxIsEnabled" => _("Enable/Disable fax"),
825 "goFaxRBlocklist" => _("Receive blocklist"),
826 "goFaxSBlocklist" => _("Send blocklist"),
827 "facsimileTelephoneNumber" => _("Fax number"), // goFaxDeliveryMode
828 "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
829 "faxtomail" => _("Deliver fax as mail"),
830 "faxtoprinter" => _("Deliver fax to printer"),
831 "goFaxFormat" => _("Delivery format"),
832 "goFaxLanguage" => _("Language"))
833 ));
834 }
835 }
837 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
838 ?>