edit-alias.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at http://postfixadmin.sf.net
  10. *
  11. * @version $Id: edit-alias.php 1558 2013-11-10 15:57:32Z christian_boltz $
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: edit-alias.php
  15. * Users can use this to set forwards etc for their mailbox.
  16. *
  17. * Template File: users_edit-alias.tpl
  18. *
  19. */
  20. $rel_path = '../';
  21. require_once('../common.php');
  22. $smarty->assign ('smarty_template', 'users_edit-alias');
  23. authentication_require_role('user');
  24. $USERID_USERNAME = authentication_get_username();
  25. $ah = new AliasHandler();
  26. $ah->init($USERID_USERNAME);
  27. $smarty->assign ('USERID_USERNAME', $USERID_USERNAME);
  28. if ( ! $ah->view() ) die("Can't get alias details. Invalid alias?"); # this can only happen if a admin deleted the user since the user logged in
  29. $result = $ah->result();
  30. $tGotoArray = $result['goto'];
  31. $tStoreAndForward = $result['goto_mailbox'];
  32. if ($_SERVER['REQUEST_METHOD'] == "GET")
  33. {
  34. if ($tStoreAndForward) {
  35. $smarty->assign ('forward_and_store', ' checked="checked"');
  36. $smarty->assign ('forward_only', '');
  37. } else {
  38. $smarty->assign ('forward_and_store', '');
  39. $smarty->assign ('forward_only', ' checked="checked"');
  40. }
  41. $smarty->assign ('tGotoArray', $tGotoArray);
  42. $smarty->display ('index.tpl');
  43. }
  44. if ($_SERVER['REQUEST_METHOD'] == "POST")
  45. {
  46. // user clicked on cancel button
  47. if(isset($_POST['fCancel'])) {
  48. header("Location: main.php");
  49. exit(0);
  50. }
  51. $fGoto = trim(safepost('fGoto'));
  52. $fForward_and_store = safepost('fForward_and_store');
  53. # TODO: use edit.php (or create a edit_user.php)
  54. # TODO: this will obsolete lots of the code below (parsing $goto and the error checks)
  55. $goto = strtolower ($fGoto);
  56. $goto = preg_replace ('/\\\r\\\n/', ',', $goto);
  57. $goto = preg_replace ('/\r\n/', ',', $goto);
  58. $goto = preg_replace ('/,[\s]+/i', ',', $goto);
  59. $goto = preg_replace ('/[\s]+,/i', ',', $goto);
  60. $goto = preg_replace ('/\,*$/', '', $goto);
  61. $goto = explode(",",$goto);
  62. $error = 0;
  63. $goto = array_merge(array_unique($goto));
  64. $good_goto = array();
  65. if($fForward_and_store != 1 && sizeof($goto) == 1 && $goto[0] == '') {
  66. flash_error($PALANG['pEdit_alias_goto_text_error1']);
  67. $error += 1;
  68. }
  69. if($error === 0) {
  70. foreach($goto as $address) {
  71. if ($address != "") { # $goto[] may contain a "" element
  72. # TODO - from https://sourceforge.net/tracker/?func=detail&aid=3027375&group_id=191583&atid=937964
  73. # The not-so-good news is that some internals of edit-alias aren't too nice
  74. # - for example, $goto[] can contain an element with empty string. I added a
  75. # check for that in the 2.3 branch, but we should use a better solution
  76. # (avoid empty elements in $goto) in trunk ;-)
  77. $email_check = check_email($address);
  78. if($email_check != '') {
  79. $error += 1;
  80. flash_error("$address: $email_check");
  81. }
  82. else {
  83. $good_goto[] = $address;
  84. }
  85. }
  86. }
  87. }
  88. if ($error == 0) {
  89. $values = array(
  90. 'goto' => $good_goto,
  91. 'goto_mailbox' => $fForward_and_store,
  92. );
  93. if (!$ah->set($values)) {
  94. $errormsg = $ah->errormsg;
  95. flash_error($errormsg[0]);
  96. }
  97. $updated = $ah->store();
  98. if($updated) {
  99. header ("Location: main.php");
  100. exit;
  101. }
  102. flash_error($PALANG['pEdit_alias_result_error']);
  103. }
  104. else {
  105. $tGotoArray = $goto;
  106. }
  107. $smarty->assign ('tGotoArray', $tGotoArray);
  108. if ($fForward_and_store == 1) {
  109. $smarty->assign ('forward_and_store', ' checked="checked"');
  110. $smarty->assign ('forward_only', '');
  111. } else {
  112. $smarty->assign ('forward_and_store', '');
  113. $smarty->assign ('forward_only', ' checked="checked"');
  114. }
  115. $smarty->display ('index.tpl');
  116. }
  117. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  118. ?>