1 <?php
3 class gofaxAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "FAX";
7 var $plDescription= "This does something";
9 /* Department list shown in the divSelectList*/
10 var $departments;
12 /* Fax attributes */
13 var $goFaxDeliveryMode= "";
14 var $facsimileTelephoneNumber= "";
15 var $goFaxIsEnabled= 1;
16 var $goFaxPrinter= "";
17 var $goFaxDivertNumber= "";
18 var $goFaxLanguage= "";
19 var $goFaxFormat= "";
20 var $goFaxRBlocklist = array();
21 var $goFaxRBlockgroups= array();
22 var $goFaxSBlocklist= array();
23 var $goFaxSBlockgroups= array();
24 var $mail= "";
25 var $facsimileAlternateTelephoneNumber= array();
26 var $fax_formats = array("pdf","ps","png","mtiff","tiff");
28 /* Internal variables */
29 var $printerList= array();
30 var $has_mailAccount= FALSE;
31 var $locals_dialog= FALSE;
32 var $in_blocklist_dialog= FALSE;
33 var $out_blocklist_dialog= FALSE;
34 var $current_blocklist= array();
35 var $view_logged = FALSE;
37 /* Copy & paste variables */
38 var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
40 /* attribute list for save action */
41 var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
43 var $uid ="";
45 var $objectclasses= array("goFaxAccount");
47 /* Enable multiple edit support */
48 var $multiple_support = TRUE;
50 function gofaxAccount (&$config, $dn= NULL)
51 {
52 /* General initialization */
53 plugin::plugin ($config, $dn);
55 /* Set uid, it is used in handle_post_events */
56 if(isset($this->attrs['uid'])){
57 $this->uid = $this->attrs['uid'][0];
58 }
60 /* Hickert : 11.11.05
61 * Added to be able to handle department selection in divSelelect
62 */
63 if(!session::is_set("Fax_Filter")){
64 $Fax_Filter = array();
65 $Fax_Filter['depselect'] = $this->config->current['BASE'];
66 session::set('Fax_Filter',$Fax_Filter);
67 }
69 if ($dn != "new"){
70 /* Get arrays */
71 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
72 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
73 $this->$val =array();
74 if (isset($this->attrs["$val"]["count"])){
75 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
76 array_push($this->$val, $this->attrs["$val"][$i]);
77 }
78 }
79 }
81 /* Set up has_mailAccount */
82 if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
83 $this->has_mailAccount= TRUE;
84 }
85 }
87 /* Load printer list */
88 $this->printerList=get_printer_list();
90 /* Check if the currently selected printer is still available.
91 If not, append current printer to list of available.
92 It could be possible, that we are not allowed to view printers and so the list is empty ... */
93 if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
94 $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
95 }
97 /* Get global filter config */
98 if (!session::is_set("faxfilter")){
99 $ui= get_userinfo();
100 $base= get_base_from_people($ui->dn);
101 $faxfilter= array( "depselect" => $base,
102 "fuser" => "*",
103 "regex" => "");
104 session::set("faxfilter", $faxfilter);
105 }
106 }
108 function execute()
109 {
110 /* Call parent execute */
111 plugin::execute();
113 /* Log view */
114 if($this->is_account && !$this->view_logged){
115 $this->view_logged = TRUE;
116 new log("view","users/".get_class($this),$this->dn);
117 }
119 /* Hickert : 11.11.05
120 * Added to be able to handle department selection in divSelelect
121 */
122 if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
124 $Fax_Filter = session::get('Fax_Filter');
125 if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
126 $Fax_Filter['depselect']= base64_decode($_GET['dep_id']);
127 }else{
128 $Fax_Filter['depselect']= $this->config->current['BASE'];
129 }
130 session::set('Fax_Filter',$Fax_Filter);
131 }
133 /* Edit mode specifies if we are editing from my accout */
134 $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
136 /* Load smarty stuff */
137 $smarty= get_smarty();
139 /* Check if mail account is active. We'll display an additional
140 mail address field if this is not the case. Some people may
141 want goFax, but have a mailserver which is not managed with
142 GOsa */
143 if (!@isset($this->parent->by_object['mailAccount'])) {
144 $smarty->assign("has_mailaccount", $this->has_mailAccount?"true":"false");
145 } elseif ( !$this->parent->by_object['mailAccount']->is_account){
146 $smarty->assign("has_mailaccount", "false");
147 $this->has_mailAccount= false;
148 } else {
149 $smarty->assign("has_mailaccount", "true");
150 }
153 $display = "";
154 if(!$this->multiple_support_active){
156 /* Do we need to flip is_account state? */
157 if (isset($_POST['modify_state'])){
158 $this->is_account= !$this->is_account;
159 }
161 /* Do we represent a valid account? */
162 if (!$this->is_account && $this->parent === NULL){
163 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
164 _("This account has no fax extensions.")."</b>";
165 $display.= back_to_main();
166 return ($display);
167 }
169 /* Show tab dialog headers */
170 $display= "";
171 if ($this->parent !== NULL){
172 if ($this->is_account){
173 $display= $this->show_disable_header(_("Remove fax account"),
174 _("This account has fax features enabled. You can disable them by clicking below."));
175 } else {
176 $display= $this->show_enable_header(_("Create fax account"),
177 _("This account has fax features disabled. You can enable them by clicking below."));
178 return ($display);
179 }
180 }
181 }
183 /* Trigger Add local fax alternatives dialog */
184 if (isset($_POST['add_local_alternate'])){
185 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
186 $this->locals_dialog= TRUE;
187 $this->dialog= TRUE;
188 }
189 }
191 /* Add alternatives from dialog */
192 if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
193 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
194 foreach ($_POST['local_list'] as $val){
195 $this->addAlternate($val);
196 $this->is_modified= TRUE;
197 }
198 }
199 }
201 /* Add alternatives */
202 if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && tests::is_phone_nr($_POST['forward_address'])){
203 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
204 $this->addAlternate($_POST['forward_address']);
205 }
206 }
208 /* Delete alternate fax number */
209 if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){
210 if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
211 $this->delAlternate ($_POST['alternate_list']);
212 }
213 }
216 /* Edit incoming blocklists */
217 if (isset($_POST['edit_incoming'])){
218 if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode)) {
219 $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
220 sort($this->current_blocklist);
221 reset($this->current_blocklist);
223 $this->in_blocklist_dialog= TRUE;
224 $this->dialog= TRUE;
225 }
226 }
228 /* Edit outgoing blocklists */
229 if (isset($_POST['edit_outgoing'])){
230 $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
231 sort($this->current_blocklist);
232 reset($this->current_blocklist);
234 $this->out_blocklist_dialog= TRUE;
235 $this->dialog= TRUE;
236 }
238 /* Add number to blocklist (dialog) */
239 if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
240 if (!tests::is_phone_nr($_POST['block_number'])){
241 msg_dialog::display(_("Error"), _("Phone number is not valid!"), ERROR_DIALOG);
242 } else {
243 array_push($this->current_blocklist, $_POST['block_number']);
244 $this->current_blocklist= array_unique($this->current_blocklist);
245 sort($this->current_blocklist);
246 reset($this->current_blocklist);
247 }
248 }
250 /* Hickert : 11.11.05
251 * Add selection from divSelelect to our Blocklist
252 */
253 /* Add list to blocklist */
254 if (isset($_POST['add_blocklist'])){
255 foreach($_POST as $name => $value){
256 if(preg_match("/ADDLIST_/i",$name)){
257 $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
259 }
260 }
261 $this->current_blocklist= array_unique($this->current_blocklist);
262 sort($this->current_blocklist);
263 reset($this->current_blocklist);
264 }
266 /* Add list to blocklist */
267 if (isset($_GET['add'])){
268 if(!is_array($this->current_blocklist)) $this->current_blocklist=array();
269 $this->current_blocklist= array_merge($this->current_blocklist, array( base64_decode($_GET['add'])));
270 $this->current_blocklist= array_unique($this->current_blocklist);
271 sort($this->current_blocklist);
272 reset($this->current_blocklist);
273 }
275 /* Delete from blocklist */
276 if (isset($_POST['delete_blocklist_number']) && isset($_POST['block_list'])){
277 $tmp= array();
278 foreach($this->current_blocklist as $val){
279 if (!in_array($val, $_POST['block_list'])){
280 $tmp[]= $val;
281 }
282 }
283 $this->current_blocklist= $tmp;
284 }
287 /* Blocklist edit finished */
288 if (isset($_POST['edit_blocklists_finish'])){
290 /* Incoming or outgoing? */
291 if ($this->in_blocklist_dialog){
292 $this->goFaxRBlocklist = array();
293 $this->goFaxRBlockgroups = array();
295 foreach ($this->current_blocklist as $val){
296 if (tests::is_phone_nr($val)){
297 $this->goFaxRBlocklist[]=$val;
298 } else {
299 $this->goFaxRBlockgroups[]= $val;
300 }
301 }
302 } else {
303 $this->goFaxSBlocklist = array();
304 $this->goFaxSBlockgroups = array();
306 /* Transfer values to ourself */
307 foreach ($this->current_blocklist as $val){
308 if (tests::is_phone_nr($val)){
309 $this->goFaxSBlocklist[]=$val;
310 } else {
311 $this->goFaxSBlockgroups[]= $val;
312 }
313 }
314 }
315 $this->is_modified= TRUE;
316 }
319 /* Set departments */
320 if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
322 $list= array ();
323 $ldap= $this->config->get_ldap_link();
324 if (isset ($_POST['department'])){
325 $ldap->cd ($_POST['department']);
326 } else {
327 $ldap->cd ($this->config->current['BASE']);
328 }
329 }
331 /* Cancel dialogs */
332 if (isset($_POST['add_locals_cancel']) || isset($_POST['edit_blocklists_finish']) ||
333 isset($_POST['edit_blocklists_cancel']) || isset($_POST['add_locals_finish'])){
335 $this->locals_dialog= FALSE;
336 $this->in_blocklist_dialog= FALSE;
337 $this->out_blocklist_dialog= FALSE;
338 $this->dialog= FALSE;
339 }
341 /* Manage locals dialog */
342 if ($this->locals_dialog){
344 /* Save data */
345 $faxfilter= session::get("faxfilter");
346 foreach( array("depselect", "fuser", "regex") as $type){
347 if (isset($_POST[$type])){
348 $faxfilter[$type]= $_POST[$type];
349 }
350 }
351 if (isset($_GET['search'])){
352 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
353 if ($s == "**"){
354 $s= "*";
355 }
356 $faxfilter['fuser']= $s;
357 }
359 if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
360 $regex= $faxfilter['regex'];
361 $filter= "(facimileTelephoneNumber=$regex)";
362 } else {
363 $filter= "";
364 }
365 if ($faxfilter['fuser'] != ""){
366 $user= $faxfilter['fuser'];
367 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
368 }
370 $base= $faxfilter['depselect'];
371 $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base,
372 array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
374 foreach ($res as $attrs){
375 $list[$attrs['facsimileTelephoneNumber'][0]]=
376 $attrs['sn'][0].", ".
377 $attrs['givenName'][0]." [".
378 $attrs['facsimileTelephoneNumber'][0]."]";
379 }
381 /* Show dialog */
382 $smarty->assign("search_image", get_template_path('images/search.png'));
383 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
384 $smarty->assign("tree_image", get_template_path('images/tree.png'));
385 $smarty->assign("infoimage", get_template_path('images/info.png'));
386 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
387 $smarty->assign("departments", $this->config->idepartments);
388 $smarty->assign("list", $list);
389 if (isset($_POST['depselect'])){
390 $smarty->assign("depselect", $_POST['depselect']);
391 }
392 $smarty->assign("deplist", $this->config->idepartments);
393 $smarty->assign("apply", apply_filter());
394 $smarty->assign("alphabet", generate_alphabet());
395 $smarty->assign("hint", print_sizelimit_warning());
396 foreach( array("depselect", "fuser", "regex") as $type){
397 $smarty->assign("$type", $faxfilter[$type]);
398 }
399 $smarty->assign("hint", print_sizelimit_warning());
401 $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
402 return ($display);
403 }
406 /* Manage incoming blocklists */
407 if ($this->in_blocklist_dialog){
409 /* This handles the divSelectBox */
411 /* The base specifies the current position in the ldap tree
412 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
413 */
414 $Fax_Filter = session::get('Fax_Filter');
415 $base = $Fax_Filter['depselect'];
416 $ldap->cd($base);
418 /* Ge all Blocklists */
419 $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
420 while ($attrs= $ldap->fetch()){
422 /* Generate list depending on description */
423 if(isset($attrs['description'][0])){
424 $list[$attrs['cn'][0]]=
425 $attrs['description'][0].
426 " [".$attrs['cn'][0]."]";
427 }else{
428 $list[$attrs['cn'][0]]= $attrs['cn'][0];
429 }
430 }
432 /* Create our divselect box */
433 $divSel = new divSelectBox("divSelectPredefined");
434 $divSel->setHeight(296);
436 /* NEW LIST MANAGMENT
437 * We also need to search for the departments
438 * So we are able to navigate like in konquerer
439 */
440 $this->departments= array();
442 /* Get all departments within the current department */
443 $Fax_Filter = session::get('Fax_Filter');
444 $base = $Fax_Filter['depselect'];
445 $ldap->ls("(objectClass=gosaDepartment)",$base);
447 /* Base back is used to go one department up in our ldap tree */
448 $base_back = preg_replace("/^[^,]+,/","",$base);
450 /* Only show base_back if it is needed */
451 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
452 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
453 }
455 /* Fetch all returned departments an add them to our divlist */
456 while($value = $ldap->fetch()){
457 if($value["description"][0]!=".."){
458 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
459 }else{
460 $this->departments[$value['dn']]=$value["description"][0];
461 }
462 }
463 /* END NEW LIST MANAGMENT
464 */
466 // This links specifies the department open link
467 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
469 /* Insert departments in divsel */
470 foreach($this->departments as $key=> $val){
471 if(!isset($this->config->departments[trim($key)])){
472 $this->config->departments[trim($key)]="";
473 }
474 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
475 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
476 $divSel->AddEntry(array($field1,$field2));
477 }
479 /* Append predefined Blocklists */
480 foreach($list as $entry => $value){
481 $divSel->AddEntry(array(
482 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
483 array("string"=>$value,"attach"=>"style='border:0px;'")
484 ));
485 }
487 /* Show dialog */
488 $smarty->assign("cblocklist", $this->current_blocklist);
489 $smarty->assign("departments", $this->config->idepartments);
490 $smarty->assign("divSelectPredefined", $divSel->DrawList());
491 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
492 return ($display);
493 }
495 /* Manage outgoing blocklists */
497 if ($this->out_blocklist_dialog){
499 /* This handles the divSelectBox */
501 /* The base specifies the current position in the ldap tree
502 * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
503 */
504 $Fax_Filter = session::get('Fax_Filter');
505 $base = $Fax_Filter['depselect'];
506 $ldap->cd($base);
508 /* Ge all Blocklists */
509 $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
510 while ($attrs= $ldap->fetch()){
511 if(isset($attrs['description'][0])){
512 $list[$attrs['cn'][0]]=
513 $attrs['description'][0].
514 " [".$attrs['cn'][0]."]";
515 }else{
516 $list[$attrs['cn'][0]]= $attrs['cn'][0];
517 }
518 }
520 /*Create DivSel*/
521 $divSel = new divSelectBox("divSelectPredefined");
522 $divSel->setHeight(296);
524 /* NEW LIST MANAGMENT
525 * We also need to search for the departments
526 * So we are able to navigate like in konquerer
527 */
528 $this->departments= array();
529 $ldap->ls("(objectClass=gosaDepartment)",$base);
531 /* Generate Back url, and append if it is needed */
532 $base_back = preg_replace("/^[^,]+,/","",$base);
533 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
534 $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
535 }
537 /* Get all departments */
538 while($value = $ldap->fetch()){
539 if(isset($value["description"][0])){
540 $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
541 }else{
542 $this->departments[$value['dn']]=$value["description"][0];
543 }
544 }
545 /* END NEW LIST MANAGMENT
546 */
548 // Defining Links
549 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
551 /* Insert departments in divlist*/
552 foreach($this->departments as $key=> $val){
553 if(!isset($this->config->departments[trim($key)])){
554 $this->config->departments[trim($key)]="";
555 }
557 $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
558 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
559 $divSel->AddEntry(array($field1,$field2));
560 }
562 /* Append Blocklits */
563 foreach($list as $entry => $value){
564 $divSel->AddEntry(array(
565 array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
566 array("string"=>$value,"attach"=>"style='border:0px;'")
567 ));
568 }
570 /* Show dialog */
571 $smarty->assign("cblocklist", $this->current_blocklist);
572 $smarty->assign("departments", $this->config->idepartments);
573 $smarty->assign("divSelectPredefined", $divSel->DrawList());
574 $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
575 return ($display);
576 }
579 /* Show main page */
580 $smarty->assign("languages", get_languages(TRUE));
582 $smarty->assign("formats", $this->fax_formats);
583 $smarty->assign("printers", $this->printerList);
585 /* Load attributes */
586 foreach(array("goFaxIsEnabled", "goFaxDeliveryMode", "facsimileTelephoneNumber",
587 "goFaxPrinter", "goFaxLanguage", "goFaxFormat",
588 "facsimileAlternateTelephoneNumber", "mail") as $val){
590 $smarty->assign("$val", $this->$val);
591 }
593 $tmp = $this->plInfo();
594 foreach($tmp['plProvidedAcls'] as $acl => $desc){
595 $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
596 }
598 /* Load checkboxes */
599 if ($this->goFaxIsEnabled == "1"){
600 $smarty->assign("goFaxIsEnabled", "");
601 } else {
602 $smarty->assign("goFaxIsEnabled", "checked");
603 }
604 /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
605 if ($this->goFaxDeliveryMode & 32) {
606 $smarty->assign("faxtomail", "checked");
607 } else {
608 $smarty->assign("faxtomail", "");
609 }
610 if ($this->goFaxDeliveryMode & 64) {
611 $smarty->assign("faxtoprinter", "checked");
612 } else {
613 $smarty->assign("faxtoprinter", "");
614 }
616 foreach($this->attributes as $attr){
617 if(in_array($attr,$this->multi_boxes)) {
618 $smarty->assign("use_".$attr,TRUE);
619 }else{
620 $smarty->assign("use_".$attr,FALSE);
621 }
622 }
623 foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
624 if(in_array($attr,$this->multi_boxes)) {
625 $smarty->assign("use_".$attr,TRUE);
626 }else{
627 $smarty->assign("use_".$attr,FALSE);
628 }
629 }
631 $smarty->assign("multiple_support",$this->multiple_support_active);
632 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
633 return ($display);
634 }
636 function remove_from_parent()
637 {
638 /* Cancel if there's nothing to do here */
639 if (!$this->initially_was_account){
640 return;
641 }
643 plugin::remove_from_parent();
645 /* Adapt mail settings if needed */
646 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
647 unset($this->attrs['mail']);
648 }
650 $ldap= $this->config->get_ldap_link();
651 $ldap->cd($this->dn);
652 $this->cleanup();
653 $ldap->modify ($this->attrs);
655 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
657 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
659 /* Optionally execute a command after we're done */
660 $this->handle_post_events('remove',array("uid"=> $this->uid));
661 }
664 /* Check formular input */
665 function check()
666 {
667 /* Call common method to give check the hook */
668 $message= plugin::check();
670 /* must: facsimileTelephoneNumber */
671 if ($this->facsimileTelephoneNumber == ""){
672 $message[]= _("Fax is empty!");
673 }
675 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
676 $message[]= _("Fax number is not valid!");
677 }
679 /* IF mail is specified (which is only the case if there's no mail account
680 present), check if it's valid.. */
681 if (@isset($this->parent->by_object['mailAccount']) &&
682 $this->goFaxDeliveryMode & 32){
683 if ($this->mail == ""){
684 $message[]= _("Mail delivery is requested without target address!");
685 } elseif (!tests::is_email($this->mail)){
686 $message[]= _("Mail address is invalid!");
687 }
688 }
690 // IE Fix, IE lets you choose disabled option, stupid browser ...
691 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
692 $message[]= _("Printing is requested without a target printer!");
693 }
695 return ($message);
696 }
698 /* Save data to object */
699 function save_object()
700 {
701 $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
702 if (isset($_POST['faxTab'])){
703 plugin::save_object();
706 $tmp = 0+$this->goFaxDeliveryMode;
708 if($this->acl_is_writeable("faxtomail",$edit_mode)){
709 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
710 $tmp |= 32;
711 }elseif($tmp & 32){
712 $tmp &= (!32);
713 }
714 }
715 if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
716 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
717 $tmp |= 64;
718 }elseif($tmp & 64){
719 $tmp &= !64;
720 }
721 }
722 $this->goFaxDeliveryMode = $tmp;
724 if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
725 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
726 $this->goFaxIsEnabled= "0";
727 } else {
728 $this->goFaxIsEnabled= "1";
729 }
730 }
733 if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
734 $this->mail= $_POST['mail'];
735 }
737 /* Check if mail account is active and correct the internal
738 reference to represent the current status. */
739 if(isset($this->parent)){
740 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
741 $this->has_mailAccount= TRUE;
742 }
743 }
744 }
746 }
749 /* Save to LDAP */
750 function save()
751 {
752 plugin::save();
754 /* Save arrays */
755 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
756 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
758 $this->attrs[$val]= $this->$val;
759 }
761 if(!$this->attrs['goFaxDeliveryMode']){
762 $this->attrs['goFaxDeliveryMode'] = 0;
763 }
765 /* Do not save mail address ... it was possibly changed by mail plugin */
766 /* Adapt mail settings if needed */
767 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
768 unset($this->attrs['mail']);
769 }
771 /* Write back to ldap */
772 $ldap= $this->config->get_ldap_link();
773 $ldap->cd($this->dn);
774 $this->cleanup();
775 $ldap->modify ($this->attrs);
777 /* Log last action */
778 if($this->initially_was_account){
779 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
780 }else{
781 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
782 }
784 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
786 /* Optionally execute a command after we're done */
787 if ($this->initially_was_account == $this->is_account){
788 if ($this->is_modified){
789 $this->handle_post_events("mofidy",array("uid" => $this->uid));
790 }
791 } else {
792 $this->handle_post_events("add",array("uid" => $this->uid));
793 }
795 }
798 /* Adapt from template, using 'dn' */
799 function adapt_from_template($dn)
800 {
801 plugin::adapt_from_template($dn);
803 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
804 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
806 if (isset($this->attrs[$val])){
807 $this->$val= $this->attrs[$val];
808 }
809 }
810 }
814 /* Add alternate fax recipient */
815 function addAlternate($number)
816 {
817 $this->facsimileAlternateTelephoneNumber[]= "$number";
818 $this->facsimileAlternateTelephoneNumber=
819 array_unique ($this->facsimileAlternateTelephoneNumber);
821 sort ($this->facsimileAlternateTelephoneNumber);
822 reset ($this->facsimileAlternateTelephoneNumber);
823 }
825 function delAlternate($numbers)
826 {
827 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
828 $this->facsimileAlternateTelephoneNumber);
829 }
831 function getCopyDialog()
832 {
833 $str = "";
834 $smarty = get_smarty();
835 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
836 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
837 $str['status'] ="";
838 return($str);
839 }
841 function SaveCopyDialog()
842 {
843 if(isset($_POST['facsimileTelephoneNumber'])){
844 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
845 }
846 }
849 /* Return plugin informations for acl handling
850 #FIXME some attributes are still missing in this plugin acls */
851 static function plInfo()
852 {
853 return (array(
854 "plShortName" => _("Fax"),
855 "plDescription" => _("Fax account settings"),
856 "plSelfModify" => TRUE,
857 "plDepends" => array("user"),
858 "plPriority" => 6,
859 "plSection" => "personal",
860 "plCategory" => array("users"),
861 "plOptions" => array(),
863 "plProvidedAcls" => array(
864 "goFaxIsEnabled" => _("Enable/Disable fax"),
865 "goFaxRBlocklist" => _("Receive blocklist"),
866 "goFaxSBlocklist" => _("Send blocklist"),
867 "facsimileTelephoneNumber" => _("Fax number"), // goFaxDeliveryMode
868 "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
869 "faxtomail" => _("Deliver fax as mail"),
870 "faxtoprinter" => _("Deliver fax to printer"),
871 "goFaxFormat" => _("Delivery format"),
872 "goFaxLanguage" => _("Language"))
873 ));
874 }
876 /* Multiple edit support
877 */
879 /* Execute */
880 function multiple_execute()
881 {
882 return($this->execute());
883 }
885 function multiple_save_object()
886 {
887 if (isset($_POST['faxTab'])){
888 plugin::multiple_save_object();
889 foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
890 if(isset($_POST["use_".$attr])){
891 $this->multi_boxes[] = $attr;
892 }
893 }
895 $tmp = 0+$this->goFaxDeliveryMode;
896 if(in_array("faxtomail",$this->multi_boxes)){
897 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
898 $tmp |= 32;
899 }elseif($tmp & 32){
900 $tmp &= (!32);
901 }
902 }
903 if(in_array("faxtoprinter",$this->multi_boxes)){
904 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
905 $tmp |= 64;
906 }elseif($tmp & 64){
907 $tmp &= !64;
908 }
909 }
910 $this->goFaxDeliveryMode = $tmp;
912 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
913 $this->goFaxIsEnabled= "0";
914 } else {
915 $this->goFaxIsEnabled= "1";
916 }
917 if (isset($_POST['mail']) && in_array("mail",$this->multi_boxes)){
918 $this->mail= $_POST['mail'];
919 }
920 }
921 }
923 function get_multi_edit_values()
924 {
925 $ret = plugin::get_multi_edit_values();
926 if(in_array("goFaxIsEnabled",$this->multi_boxes)){
927 $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
928 }
929 if(in_array("faxtoprinter",$this->multi_boxes)){
930 $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
931 }
932 if(in_array("faxtomail",$this->multi_boxes)){
933 $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
934 }
936 if(in_array("edit_incoming",$this->multi_boxes)){
937 $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
938 $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
939 }
940 if(in_array("edit_outgoing",$this->multi_boxes)){
941 $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
942 $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
943 }
944 return($ret);
945 }
947 function multiple_check()
948 {
949 $message = plugin::multiple_check();
950 return($message);
951 }
953 function set_multi_edit_values($values)
954 {
955 plugin::set_multi_edit_values($values);
957 if(isset($values['faxtoprinter'])){
958 if($values['faxtoprinter']){
959 $this->goFaxDeliveryMode |= 64;
960 }else{
961 $this->goFaxDeliveryMode &= !64;
962 }
963 }
964 if(isset($values['faxtomail'])){
965 if($values['faxtomail']){
966 $this->goFaxDeliveryMode |= 32;
967 }else{
968 $this->goFaxDeliveryMode &= !32;
969 }
970 }
971 }
972 }
974 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
975 ?>