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/small-error.png\" align=\"middle\"> <b>".
164 msgPool::noValidExtension(_("GOfax"))."</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 msgPool::featuresEnabled(_("GOfax")));
175 } else {
176 $display= $this->show_enable_header(_("Create fax account"),
177 msgPool::featuresDisabled(_("GOfax")));
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"), msgPool::invalid(_("Phone number")), 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/lists/search.png'));
383 $smarty->assign("usearch_image", get_template_path('images/lists/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/lists/action.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/lists/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/lists/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 if (!$ldap->success()){
658 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
659 }
661 /* Optionally execute a command after we're done */
662 $this->handle_post_events('remove',array("uid"=> $this->uid));
663 }
666 /* Check formular input */
667 function check()
668 {
669 /* Call common method to give check the hook */
670 $message= plugin::check();
672 /* must: facsimileTelephoneNumber */
673 if ($this->facsimileTelephoneNumber == ""){
674 $message[]= msgPool::required(_("Fax number"));
675 }
677 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
678 $message[]= msgPool::invalid(_("Fax number"),$this->facsimileTelephoneNumber,"/[0-9]/");
679 }
681 /* IF mail is specified (which is only the case if there's no mail account
682 present), check if it's valid.. */
683 if (@isset($this->parent->by_object['mailAccount']) &&
684 $this->goFaxDeliveryMode & 32){
685 if ($this->mail == ""){
686 $message[]= _("Mail delivery is requested without target address!");
687 } elseif (!tests::is_email($this->mail)){
688 $message[]= msgPool::invalid(_("Mail address"),"","",_("your-name@your-domain.com"));
689 }
690 }
692 // IE Fix, IE lets you choose disabled option, stupid browser ...
693 if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
694 $message[]= _("Printing is requested without a target printer!");
695 }
697 return ($message);
698 }
700 /* Save data to object */
701 function save_object()
702 {
703 $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
704 if (isset($_POST['faxTab'])){
705 plugin::save_object();
708 $tmp = 0+$this->goFaxDeliveryMode;
710 if($this->acl_is_writeable("faxtomail",$edit_mode)){
711 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
712 $tmp |= 32;
713 }elseif($tmp & 32){
714 $tmp &= (!32);
715 }
716 }
717 if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
718 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
719 $tmp |= 64;
720 }elseif($tmp & 64){
721 $tmp &= !64;
722 }
723 }
724 $this->goFaxDeliveryMode = $tmp;
726 if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
727 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
728 $this->goFaxIsEnabled= "0";
729 } else {
730 $this->goFaxIsEnabled= "1";
731 }
732 }
735 if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
736 $this->mail= $_POST['mail'];
737 }
739 /* Check if mail account is active and correct the internal
740 reference to represent the current status. */
741 if(isset($this->parent)){
742 if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
743 $this->has_mailAccount= TRUE;
744 }
745 }
746 }
748 }
751 /* Save to LDAP */
752 function save()
753 {
754 plugin::save();
756 /* Save arrays */
757 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
758 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
760 $this->attrs[$val]= $this->$val;
761 }
763 if(!$this->attrs['goFaxDeliveryMode']){
764 $this->attrs['goFaxDeliveryMode'] = 0;
765 }
767 /* Do not save mail address ... it was possibly changed by mail plugin */
768 /* Adapt mail settings if needed */
769 if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
770 unset($this->attrs['mail']);
771 }
773 /* Write back to ldap */
774 $ldap= $this->config->get_ldap_link();
775 $ldap->cd($this->dn);
776 $this->cleanup();
777 $ldap->modify ($this->attrs);
779 /* Log last action */
780 if($this->initially_was_account){
781 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
782 }else{
783 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
784 }
786 if (!$ldap->success()){
787 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
788 }
790 /* Optionally execute a command after we're done */
791 if ($this->initially_was_account == $this->is_account){
792 if ($this->is_modified){
793 $this->handle_post_events("mofidy",array("uid" => $this->uid));
794 }
795 } else {
796 $this->handle_post_events("add",array("uid" => $this->uid));
797 }
799 }
802 /* Adapt from template, using 'dn' */
803 function adapt_from_template($dn, $skip= array())
804 {
805 plugin::adapt_from_template($dn, $skip);
807 foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
808 "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
810 if (in_array($val, $skip)){
811 continue;
812 }
814 if (isset($this->attrs[$val])){
815 $this->$val= $this->attrs[$val];
816 }
817 }
818 }
822 /* Add alternate fax recipient */
823 function addAlternate($number)
824 {
825 $this->facsimileAlternateTelephoneNumber[]= "$number";
826 $this->facsimileAlternateTelephoneNumber=
827 array_unique ($this->facsimileAlternateTelephoneNumber);
829 sort ($this->facsimileAlternateTelephoneNumber);
830 reset ($this->facsimileAlternateTelephoneNumber);
831 }
833 function delAlternate($numbers)
834 {
835 $this->facsimileAlternateTelephoneNumber= array_remove_entries ($numbers,
836 $this->facsimileAlternateTelephoneNumber);
837 }
839 function getCopyDialog()
840 {
841 $str = "";
842 $smarty = get_smarty();
843 $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
844 $str['string'] = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
845 $str['status'] ="";
846 return($str);
847 }
849 function SaveCopyDialog()
850 {
851 if(isset($_POST['facsimileTelephoneNumber'])){
852 $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
853 }
854 }
857 /* Return plugin informations for acl handling
858 #FIXME some attributes are still missing in this plugin acls */
859 static function plInfo()
860 {
861 return (array(
862 "plShortName" => _("Fax"),
863 "plDescription" => _("Fax account settings"),
864 "plSelfModify" => TRUE,
865 "plDepends" => array("user"),
866 "plPriority" => 6,
867 "plSection" => "personal",
868 "plCategory" => array("users"),
869 "plOptions" => array(),
871 "plProvidedAcls" => array(
872 "goFaxIsEnabled" => _("Enable/Disable fax"),
873 "goFaxRBlocklist" => _("Receive blocklist"),
874 "goFaxSBlocklist" => _("Send blocklist"),
875 "facsimileTelephoneNumber" => _("Fax number"), // goFaxDeliveryMode
876 "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
877 "faxtomail" => _("Deliver fax as mail"),
878 "faxtoprinter" => _("Deliver fax to printer"),
879 "goFaxFormat" => _("Delivery format"),
880 "goFaxLanguage" => _("Language"))
881 ));
882 }
884 /* Multiple edit support
885 */
887 /* Execute */
888 function multiple_execute()
889 {
890 return($this->execute());
891 }
893 function multiple_save_object()
894 {
895 if (isset($_POST['faxTab'])){
896 plugin::multiple_save_object();
897 foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
898 if(isset($_POST["use_".$attr])){
899 $this->multi_boxes[] = $attr;
900 }
901 }
903 $tmp = 0+$this->goFaxDeliveryMode;
904 if(in_array("faxtomail",$this->multi_boxes)){
905 if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
906 $tmp |= 32;
907 }elseif($tmp & 32){
908 $tmp &= (!32);
909 }
910 }
911 if(in_array("faxtoprinter",$this->multi_boxes)){
912 if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
913 $tmp |= 64;
914 }elseif($tmp & 64){
915 $tmp &= !64;
916 }
917 }
918 $this->goFaxDeliveryMode = $tmp;
920 if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
921 $this->goFaxIsEnabled= "0";
922 } else {
923 $this->goFaxIsEnabled= "1";
924 }
925 if (isset($_POST['mail']) && in_array("mail",$this->multi_boxes)){
926 $this->mail= $_POST['mail'];
927 }
928 }
929 }
931 function get_multi_edit_values()
932 {
933 $ret = plugin::get_multi_edit_values();
934 if(in_array("goFaxIsEnabled",$this->multi_boxes)){
935 $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
936 }
937 if(in_array("faxtoprinter",$this->multi_boxes)){
938 $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
939 }
940 if(in_array("faxtomail",$this->multi_boxes)){
941 $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
942 }
944 if(in_array("edit_incoming",$this->multi_boxes)){
945 $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
946 $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
947 }
948 if(in_array("edit_outgoing",$this->multi_boxes)){
949 $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
950 $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
951 }
952 return($ret);
953 }
955 function multiple_check()
956 {
957 $message = plugin::multiple_check();
958 return($message);
959 }
961 function set_multi_edit_values($values)
962 {
963 plugin::set_multi_edit_values($values);
965 if(isset($values['faxtoprinter'])){
966 if($values['faxtoprinter']){
967 $this->goFaxDeliveryMode |= 64;
968 }else{
969 $this->goFaxDeliveryMode &= !64;
970 }
971 }
972 if(isset($values['faxtomail'])){
973 if($values['faxtomail']){
974 $this->goFaxDeliveryMode |= 32;
975 }else{
976 $this->goFaxDeliveryMode &= !32;
977 }
978 }
979 }
980 }
982 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
983 ?>