eca2228577a9cc7591826a1803e03327489faafd
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();
32 var $fax_formats = array("pdf","ps","png","mtiff","tiff");
34 /* Internal variables */
35 var $printerList= array();
36 var $has_mailAccount= FALSE;
37 var $locals_dialog= FALSE;
38 var $in_blocklist_dialog= FALSE;
39 var $out_blocklist_dialog= FALSE;
40 var $current_blocklist= array();
41 var $view_logged = FALSE;
43 /* Copy & paste variables */
44 var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
46 /* attribute list for save action */
47 var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
49 var $uid ="";
51 var $objectclasses= array("goFaxAccount");
53 function gofaxAccount (&$config, $dn= NULL)
54 {
55 /* General initialization */
56 plugin::plugin ($config, $dn);
58 /* Set uid, it is used in handle_post_events */
59 if(isset($this->attrs['uid'])){
60 $this->uid = $this->attrs['uid'][0];
61 }
63 /* Hickert : 11.11.05
64 * Added to be able to handle department selection in divSelelect
65 */
66 if(!isset($_SESSION["Fax_Filter"])){
67 $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
68 }
70 if ($dn != "new"){
71 /* Get arrays */
72 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
73 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
74 $this->$val =array();
75 if (isset($this->attrs["$val"]["count"])){
76 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
77 array_push($this->$val, $this->attrs["$val"][$i]);
78 }
79 }
80 }
82 /* Set up has_mailAccount */
83 if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
84 $this->has_mailAccount= TRUE;
85 }
86 }
88 /* Load printer list */
89 if (isset($this->config->data['SERVERS']['CUPS'])){
90 $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
91 asort ($this->printerList);
92 }
94 /* Check if the currently selected printer is still available.
95 If not, append current printer to list of available.
96 It could be possible, that we are not allowed to view printers and so the list is empty ... */
97 if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
98 $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
99 }
101 /* Get global filter config */
102 if (!is_global("faxfilter")){
103 $ui= get_userinfo();
104 $base= get_base_from_people($ui->dn);
105 $faxfilter= array( "depselect" => $base,
106 "fuser" => "*",
107 "regex" => "");
108 register_global("faxfilter", $faxfilter);
109 }
110 }
112 function execute()
113 {
114 /* Call parent execute */
115 plugin::execute();
117 /* Log view */
118 if($this->is_account && !$this->view_logged){
119 $this->view_logged = TRUE;
120 new log("view","users/".get_class($this),$this->dn);
121 }
123 /* Hickert : 11.11.05
124 * Added to be able to handle department selection in divSelelect
125 */
126 if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
128 if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
129 $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
130 }else{
131 $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
132 }
133 }
135 /* Edit mode specifies if we are editing from my accout */
136 $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
138 /* Load smarty stuff */
139 $smarty= get_smarty();
141 /* Check if mail account is active. We'll display an additional
142 mail address field if this is not the case. Some people may
143 want goFax, but have a mailserver which is not managed with
144 GOsa */
145 if (!@isset($this->parent->by_object['mailAccount'])) {
146 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
147 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
148 $smarty->assign("has_mailaccount", "false");
149 $this->has_mailAccount= false;
150 } else {
151 $smarty->assign("has_mailaccount", "true");
152 }
154 /* Do we need to flip is_account state? */
155 if (isset($_POST['modify_state'])){
156 $this->is_account= !$this->is_account;
157 }
159 /* Do we represent a valid account? */
160 if (!$this->is_account && $this->parent === NULL){
161 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
162 _("This account has no fax extensions.")."</b>";
163 $display.= back_to_main();
164 return ($display);
165 }
167 /* Show tab dialog headers */
168 $display= "";
169 if ($this->parent !== NULL){
170 if ($this->is_account){
171 $display= $this->show_disable_header(_("Remove fax account"),
172 _("This account has fax features enabled. You can disable them by clicking below."));
173 } else {
174 $display= $this->show_enable_header(_("Create fax account"),
175 _("This account has fax features disabled. You can enable them by clicking below."));
176 return ($display);
177 }
178 }
180 /* Trigger Add local fax alternatives dialog */
181 if (isset($_POST['add_local_alternate'])){
182 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
183 $this->locals_dialog= TRUE;
184 $this->dialog= TRUE;
185 }
186 }
188 /* Add alternatives from dialog */
189 if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
190 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
191 foreach ($_POST['local_list'] as $val){
192 $this->addAlternate($val);
193 $this->is_modified= TRUE;
194 }
195 }
196 }
198 /* Add alternatives */
199 if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){
200 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
201 $this->addAlternate($_POST['forward_address']);
202 }
203 }
205 /* Delete alternate fax number */
206 if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){
207 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
208 $this->delAlternate ($_POST['alternate_list']);
209 }
210 }
213 /* Edit incoming blocklists */
214 if (isset($_POST['edit_incoming'])){
215 if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode)) {
216 $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
217 sort($this->current_blocklist);
218 reset($this->current_blocklist);
220 $this->in_blocklist_dialog= TRUE;
221 $this->dialog= TRUE;
222 }
223 }
225 /* Edit outgoing blocklists */
226 if (isset($_POST['edit_outgoing'])){
227 $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
228 sort($this->current_blocklist);
229 reset($this->current_blocklist);
231 $this->out_blocklist_dialog= TRUE;
232 $this->dialog= TRUE;
233 }
235 /* Add number to blocklist (dialog) */
236 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
237 if (!is_phone_nr($_POST['block_number'])){
238 print_red (_("You're trying to add an invalid phone number."));
239 } else {
240 array_push($this->current_blocklist, $_POST['block_number']);
241 $this->current_blocklist= array_unique($this->current_blocklist);
242 sort($this->current_blocklist);
243 reset($this->current_blocklist);
244 }
245 }
247 /* Hickert : 11.11.05
248 * Add selection from divSelelect to our Blocklist
249 */
250 /* Add list to blocklist */
251 if (isset($_POST['add_blocklist'])){
252 foreach($_POST as $name => $value){
253 if(preg_match("/ADDLIST_/i",$name)){
254 $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
256 }
257 }
258 $this->current_blocklist= array_unique($this->current_blocklist);
259 sort($this->current_blocklist);
260 reset($this->current_blocklist);
261 }
263 /* Add list to blocklist */
264 if (isset($_GET['add'])){
265 if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
266 $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
267 $this->current_blocklist= array_unique($this->current_blocklist);
268 sort($this->current_blocklist);
269 reset($this->current_blocklist);
270 }
272 /* Delete from blocklist */
273 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
274 $tmp= array();
275 foreach($this->current_blocklist as $val){
276 if (!in_array($val, $_POST['block_list'])){
277 $tmp[]= $val;
278 }
279 }
280 $this->current_blocklist= $tmp;
281 }
284 /* Blocklist edit finished */
285 if (isset($_POST['edit_blocklists_finish'])){
287 /* Incoming or outgoing? */
288 if ($this->in_blocklist_dialog){
289 $this->goFaxRBlocklist = array();
290 $this->goFaxRBlockgroups = array();
292 foreach ($this->current_blocklist as $val){
293 if (is_phone_nr($val)){
294 $this->goFaxRBlocklist[]=$val;
295 } else {
296 $this->goFaxRBlockgroups[]= $val;
297 }
298 }
299 } else {
300 $this->goFaxSBlocklist = array();
301 $this->goFaxSBlockgroups = array();
303 /* Transfer values to ourself */
304 foreach ($this->current_blocklist as $val){
305 if (is_phone_nr($val)){
306 $this->goFaxSBlocklist[]=$val;
307 } else {
308 $this->goFaxSBlockgroups[]= $val;
309 }
310 }
311 }
312 $this->is_modified= TRUE;
313 }
316 /* Set departments */
317 if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
319 $list= array ();
320 $ldap= $this->config->get_ldap_link();
321 if (isset ($_POST['department'])){
322 $ldap->cd ($_POST['department']);
323 } else {
324 $ldap->cd ($this->config->current['BASE']);
325 }
326 }
328 /* Cancel dialogs */
329 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
330 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
332 $this->locals_dialog= FALSE;
333 $this->in_blocklist_dialog= FALSE;
334 $this->out_blocklist_dialog= FALSE;
335 $this->dialog= FALSE;
336 }
338 /* Manage locals dialog */
339 if ($this->locals_dialog){
341 /* Save data */
342 $faxfilter= get_global("faxfilter");
343 foreach( array("depselect", "fuser", "regex") as $type){
344 if (isset($_POST[$type])){
345 $faxfilter[$type]= $_POST[$type];
346 }
347 }
348 if (isset($_GET['search'])){
349 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
350 if ($s == "**"){
351 $s= "*";
352 }
353 $faxfilter['fuser']= $s;
354 }
356 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
357 $regex= $faxfilter['regex'];
358 $filter= "(facimileTelephoneNumber=$regex)";
359 } else {
360 $filter= "";
361 }
362 if ($faxfilter['fuser'] != ""){
363 $user= $faxfilter['fuser'];
364 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
365 }
367 $base= $faxfilter['depselect'];
368 $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base,
369 array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
371 foreach ($res as $attrs){
372 $list[$attrs['facsimileTelephoneNumber'][0]]=
373 $attrs['sn'][0].", ".
374 $attrs['givenName'][0]." [".
375 $attrs['facsimileTelephoneNumber'][0]."]";
376 }
378 /* Show dialog */
379 $smarty->assign("search_image", get_template_path('images/search.png'));
380 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
381 $smarty->assign("tree_image", get_template_path('images/tree.png'));
382 $smarty->assign("infoimage", get_template_path('images/info.png'));
383 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
384 $smarty->assign("departments", $this->config->idepartments);
385 $smarty->assign("list", $list);
386 if (isset($_POST['depselect'])){
387 $smarty->assign("depselect", $_POST['depselect']);
388 }
389 $smarty->assign("deplist", $this->config->idepartments);
390 $smarty->assign("apply", apply_filter());
391 $smarty->assign("alphabet", generate_alphabet());
392 $smarty->assign("hint", print_sizelimit_warning());
393 foreach( array("depselect", "fuser", "regex") as $type){
394 $smarty->assign("$type", $faxfilter[$type]);
395 }
396 $smarty->assign("hint", print_sizelimit_warning());
398 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
399 return ($display);
400 }
403 /* Manage incoming blocklists */
404 if ($this->in_blocklist_dialog){
406 /* This handles the divSelectBox */
408 /* The base specifies the current position in the ldap tree
409 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
410 */
411 $base = $_SESSION['Fax_Filter']['depselect'];
412 $ldap->cd($base);
414 /* Ge all Blocklists */
415 $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
416 while ($attrs= $ldap->fetch()){
418 /* Generate list depending on description */
419 if(isset($attrs['description'][0])){
420 $list[$attrs['cn'][0]]=
421 $attrs['description'][0].
422 " [".$attrs['cn'][0]."]";
423 }else{
424 $list[$attrs['cn'][0]]= $attrs['cn'][0];
425 }
426 }
428 /* Create our divselect box */
429 $divSel = new divSelectBox("divSelectPredefined");
430 $divSel->setHeight(296);
432 /* NEW LIST MANAGMENT
433 * We also need to search for the departments
434 * So we are able to navigate like in konquerer
435 */
436 $this->departments= array();
438 /* Get all departments within the current department */
439 $base = $_SESSION['Fax_Filter']['depselect'];
440 $ldap->ls("(objectClass=gosaDepartment)",$base);
442 /* Base back is used to go one department up in our ldap tree */
443 $base_back = preg_replace("/^[^,]+,/","",$base);
445 /* Only show base_back if it is needed */
446 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
447 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
448 }
450 /* Fetch all returned departments an add them to our divlist */
451 while($value = $ldap->fetch()){
452 if($value["description"][0]!=".."){
453 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
454 }else{
455 $this->departments[$value['dn']]=$value["description"][0];
456 }
457 }
458 /* END NEW LIST MANAGMENT
459 */
461 // This links specifies the department open link
462 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
464 /* Insert departments in divsel */
465 foreach($this->departments as $key=> $val){
466 if(!isset($this->config->departments[trim($key)])){
467 $this->config->departments[trim($key)]="";
468 }
469 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
470 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
471 $divSel->AddEntry(array($field1,$field2));
472 }
474 /* Append predefined Blocklists */
475 foreach($list as $entry => $value){
476 $divSel->AddEntry(array(
477 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
478 array("string"=>$value,"attach"=>"style='border:0px;'")
479 ));
480 }
482 /* Show dialog */
483 $smarty->assign("cblocklist", $this->current_blocklist);
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']]=@LDAP::fix(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("departments", $this->config->idepartments);
567 $smarty->assign("divSelectPredefined", $divSel->DrawList());
568 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
569 return ($display);
570 }
573 /* Show main page */
574 $smarty->assign("languages", get_languages(TRUE));
576 $smarty->assign("formats", $this->fax_formats);
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 }
587 $tmp = $this->plInfo();
588 foreach($tmp['plProvidedAcls'] as $acl => $desc){
589 $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
590 }
592 /* Load checkboxes */
593 if ($this->goFaxIsEnabled == "1"){
594 $smarty->assign("goFaxIsEnabled", "");
595 } else {
596 $smarty->assign("goFaxIsEnabled", "checked");
597 }
598 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
599 if ($this->goFaxDeliveryMode & 32) {
600 $smarty->assign("faxtomail", "checked");
601 } else {
602 $smarty->assign("faxtomail", "");
603 }
604 if ($this->goFaxDeliveryMode & 64) {
605 $smarty->assign("faxtoprinter", "checked");
606 } else {
607 $smarty->assign("faxtoprinter", "");
608 }
611 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
612 return ($display);
613 }
615 function remove_from_parent()
616 {
617 /* Cancel if there's nothing to do here */
618 if (!$this->initially_was_account){
619 return;
620 }
622 plugin::remove_from_parent();
624 /* Adapt mail settings if needed */
625 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
626 unset($this->attrs['mail']);
627 }
629 $ldap= $this->config->get_ldap_link();
630 $ldap->cd($this->dn);
631 $this->cleanup();
632 $ldap->modify ($this->attrs);
634 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
636 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
638 /* Optionally execute a command after we're done */
639 $this->handle_post_events('remove',array("uid"=> $this->uid));
640 }
643 /* Check formular input */
644 function check()
645 {
646 /* Call common method to give check the hook */
647 $message= plugin::check();
649 /* must: facsimileTelephoneNumber */
650 if ($this->facsimileTelephoneNumber == ""){
651 $message[]= _("The required field 'Fax' is not set.");
652 }
654 if (!is_phone_nr($this->facsimileTelephoneNumber)){
655 $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
656 }
658 /* IF mail is specified (which is only the case if there's no mail account
659 present), check if it's valid.. */
660 if (@isset($this->parent->by_object['mailAccount']) &&
661 $this->goFaxDeliveryMode & 32){
662 if ($this->mail == ""){
663 $message[]= _("Mail delivery is checked, but no address has been specified.");
664 } elseif (!is_email($this->mail)){
665 $message[]= _("The mail address you've entered is invalid.");
666 }
667 }
669 // IE Fix, IE lets you choose disabled option, stupid browser ...
670 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
671 $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
672 }
674 return ($message);
675 }
677 /* Save data to object */
678 function save_object()
679 {
680 $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
681 if (isset($_POST['faxTab'])){
682 plugin::save_object();
685 $tmp = 0+$this->goFaxDeliveryMode;
687 if($this->acl_is_writeable("faxtomail",$edit_mode)){
688 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
689 $tmp |= 32;
690 }elseif($tmp & 32){
691 $tmp &= (!32);
692 }
693 }
694 if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
695 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
696 $tmp |= 64;
697 }elseif($tmp & 64){
698 $tmp &= !64;
699 }
700 }
701 $this->goFaxDeliveryMode = $tmp;
703 if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
704 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
705 $this->goFaxIsEnabled= "0";
706 } else {
707 $this->goFaxIsEnabled= "1";
708 }
709 }
712 if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
713 $this->mail= $_POST['mail'];
714 }
716 /* Check if mail account is active and correct the internal
717 reference to represent the current status. */
718 if(isset($this->parent)){
719 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
720 $this->has_mailAccount= TRUE;
721 }
722 }
723 }
725 }
728 /* Save to LDAP */
729 function save()
730 {
731 plugin::save();
733 /* Save arrays */
734 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
735 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
737 $this->attrs[$val]= $this->$val;
738 }
740 if(!$this->attrs['goFaxDeliveryMode']){
741 $this->attrs['goFaxDeliveryMode'] = 0;
742 }
744 /* Do not save mail address ... it was possibly changed by mail plugin */
745 /* Adapt mail settings if needed */
746 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
747 unset($this->attrs['mail']);
748 }
750 /* Write back to ldap */
751 $ldap= $this->config->get_ldap_link();
752 $ldap->cd($this->dn);
753 $this->cleanup();
754 $ldap->modify ($this->attrs);
756 /* Log last action */
757 if($this->initially_was_account){
758 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
759 }else{
760 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
761 }
763 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
765 /* Optionally execute a command after we're done */
766 if ($this->initially_was_account == $this->is_account){
767 if ($this->is_modified){
768 $this->handle_post_events("mofidy",array("uid" => $this->uid));
769 }
770 } else {
771 $this->handle_post_events("add",array("uid" => $this->uid));
772 }
774 }
777 /* Adapt from template, using 'dn' */
778 function adapt_from_template($dn)
779 {
780 plugin::adapt_from_template($dn);
782 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
783 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
785 if (isset($this->attrs[$val])){
786 $this->$val= $this->attrs[$val];
787 }
788 }
789 }
793 /* Add alternate fax recipient */
794 function addAlternate($number)
795 {
796 $this->facsimileAlternateTelephoneNumber[]= "$number";
797 $this->facsimileAlternateTelephoneNumber=
798 array_unique ($this->facsimileAlternateTelephoneNumber);
800 sort ($this->facsimileAlternateTelephoneNumber);
801 reset ($this->facsimileAlternateTelephoneNumber);
802 }
804 function delAlternate($numbers)
805 {
806 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
807 $this->facsimileAlternateTelephoneNumber);
808 }
810 function getCopyDialog()
811 {
812 $str = "";
813 $smarty = get_smarty();
814 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
815 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
816 $str['status'] ="";
817 return($str);
818 }
820 function SaveCopyDialog()
821 {
822 if(isset($_POST['facsimileTelephoneNumber'])){
823 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
824 }
825 }
828 /* Return plugin informations for acl handling
829 #FIXME some attributes are still missing in this plugin acls */
830 static function plInfo()
831 {
832 return (array(
833 "plShortName" => _("Fax"),
834 "plDescription" => _("Fax account settings"),
835 "plSelfModify" => TRUE,
836 "plDepends" => array("user"),
837 "plPriority" => 6,
838 "plSection" => "personal",
839 "plCategory" => array("users"),
840 "plOptions" => array(),
842 "plProvidedAcls" => array(
843 "goFaxIsEnabled" => _("Enable/Disable fax"),
844 "goFaxRBlocklist" => _("Receive blocklist"),
845 "goFaxSBlocklist" => _("Send blocklist"),
846 "facsimileTelephoneNumber" => _("Fax number"), // goFaxDeliveryMode
847 "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
848 "faxtomail" => _("Deliver fax as mail"),
849 "faxtoprinter" => _("Deliver fax to printer"),
850 "goFaxFormat" => _("Delivery format"),
851 "goFaxLanguage" => _("Language"))
852 ));
853 }
854 }
856 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
857 ?>