You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

edit-alias.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 1842 2016-05-20 20:42:04Z 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. if (safepost('token') != $_SESSION['PFA_token']) die('Invalid token!');
  47. // user clicked on cancel button
  48. if(isset($_POST['fCancel'])) {
  49. header("Location: main.php");
  50. exit(0);
  51. }
  52. $fGoto = trim(safepost('fGoto'));
  53. $fForward_and_store = safepost('fForward_and_store');
  54. # TODO: use edit.php (or create a edit_user.php)
  55. # TODO: this will obsolete lots of the code below (parsing $goto and the error checks)
  56. $goto = strtolower ($fGoto);
  57. $goto = preg_replace ('/\\\r\\\n/', ',', $goto);
  58. $goto = preg_replace ('/\r\n/', ',', $goto);
  59. $goto = preg_replace ('/,[\s]+/i', ',', $goto);
  60. $goto = preg_replace ('/[\s]+,/i', ',', $goto);
  61. $goto = preg_replace ('/\,*$/', '', $goto);
  62. $goto = explode(",",$goto);
  63. $error = 0;
  64. $goto = array_merge(array_unique($goto));
  65. $good_goto = array();
  66. if($fForward_and_store != 1 && sizeof($goto) == 1 && $goto[0] == '') {
  67. flash_error($PALANG['pEdit_alias_goto_text_error1']);
  68. $error += 1;
  69. }
  70. if($error === 0) {
  71. foreach($goto as $address) {
  72. if ($address != "") { # $goto[] may contain a "" element
  73. # TODO - from https://sourceforge.net/tracker/?func=detail&aid=3027375&group_id=191583&atid=937964
  74. # The not-so-good news is that some internals of edit-alias aren't too nice
  75. # - for example, $goto[] can contain an element with empty string. I added a
  76. # check for that in the 2.3 branch, but we should use a better solution
  77. # (avoid empty elements in $goto) in trunk ;-)
  78. $email_check = check_email($address);
  79. if($email_check != '') {
  80. $error += 1;
  81. flash_error("$address: $email_check");
  82. }
  83. else {
  84. $good_goto[] = $address;
  85. }
  86. }
  87. }
  88. }
  89. if ($error == 0) {
  90. $values = array(
  91. 'goto' => $good_goto,
  92. 'goto_mailbox' => $fForward_and_store,
  93. );
  94. if (!$ah->set($values)) {
  95. $errormsg = $ah->errormsg;
  96. flash_error($errormsg[0]);
  97. }
  98. $updated = $ah->store();
  99. if($updated) {
  100. header ("Location: main.php");
  101. exit;
  102. }
  103. flash_error($PALANG['pEdit_alias_result_error']);
  104. }
  105. else {
  106. $tGotoArray = $goto;
  107. }
  108. $smarty->assign ('tGotoArray', $tGotoArray);
  109. if ($fForward_and_store == 1) {
  110. $smarty->assign ('forward_and_store', ' checked="checked"');
  111. $smarty->assign ('forward_only', '');
  112. } else {
  113. $smarty->assign ('forward_and_store', '');
  114. $smarty->assign ('forward_only', ' checked="checked"');
  115. }
  116. $smarty->display ('index.tpl');
  117. }
  118. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  119. ?>