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.

vacation.php 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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$
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: edit-vacation.php
  15. *
  16. * Allows users to update their vacation status and
  17. * admins to update the vacation status for the their users
  18. *
  19. * Template File: vacation.tpl
  20. *
  21. * Template Variables:
  22. *
  23. * tUseremail
  24. * tActiveFrom
  25. * tActiveUntil
  26. * tSubject
  27. * tBody
  28. * tInterval_time
  29. *
  30. * Form POST \ GET Variables:
  31. *
  32. * fUsername
  33. * fDomain
  34. * fCancel
  35. * fChange
  36. * fBack
  37. * fActive
  38. */
  39. require_once('common.php');
  40. // only allow admins to change someone else's 'stuff'
  41. if (authentication_has_role('admin')) {
  42. $Admin_role = 1 ;
  43. $fUsername = safeget('username');
  44. list(/*NULL*/, $fDomain) = explode('@', $fUsername);
  45. $Return_url = "list-virtual.php?domain=" . urlencode($fDomain);
  46. # TODO: better check for valid username (check if mailbox exists)
  47. # TODO: (should be done in VacationHandler)
  48. if ($fDomain == '' || !check_owner(authentication_get_username(), $fDomain)) {
  49. die("Invalid username!"); # TODO: better error message
  50. }
  51. } else {
  52. $Admin_role = 0 ;
  53. $Return_url = "main.php";
  54. authentication_require_role('user');
  55. $fUsername = authentication_get_username();
  56. }
  57. // is vacation support enabled in $CONF ?
  58. if ($CONF['vacation'] == 'NO') {
  59. header("Location: $Return_url");
  60. exit(0);
  61. }
  62. date_default_timezone_set(@date_default_timezone_get()); # Suppress date.timezone warnings
  63. $error = 0;
  64. $vh = new VacationHandler($fUsername);
  65. $choice_of_reply = Config::read('vacation_choice_of_reply');
  66. foreach (array_keys($choice_of_reply) as $key) {
  67. $choice_of_reply[$key] = Config::Lang($choice_of_reply[$key]);
  68. }
  69. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  70. $tSubject = '';
  71. $tBody = '';
  72. $tActiveFrom = '';
  73. $tActiveUntil = '';
  74. $tUseremail = $fUsername;
  75. $tInterval_Time = '';
  76. $details = $vh->get_details();
  77. if ($details != false) {
  78. $tSubject = $details['subject'];
  79. $tBody = $details['body'];
  80. $tInterval_Time = $details['interval_time'];
  81. $tActiveFrom = $details['activeFrom'];
  82. $tActiveUntil = $details['activeUntil'];
  83. }
  84. if ($vh->check_vacation()) {
  85. flash_info(sprintf($PALANG['pUsersVacation_welcome_text'], htmlentities($tUseremail)));
  86. }
  87. //set a default, reset fields for coming back selection
  88. if ($tSubject == '') {
  89. $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8');
  90. }
  91. if ($tBody == '') {
  92. $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8');
  93. }
  94. }
  95. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  96. if (safepost('token') != $_SESSION['PFA_token']) {
  97. die('Invalid token!');
  98. }
  99. if (isset($_POST['fCancel'])) {
  100. header("Location: $Return_url");
  101. exit(0);
  102. }
  103. $tActiveFrom = date("Y-m-d 00:00:00", strtotime(safepost('fActiveFrom')));
  104. $tActiveUntil = date("Y-m-d 23:59:59", strtotime(safepost('fActiveUntil')));
  105. $tSubject = safepost('fSubject');
  106. $fSubject = $tSubject;
  107. $tBody = safepost('fBody');
  108. $fBody = $tBody;
  109. $tInterval_Time = safepost('fInterval_Time');
  110. $fChange = escape_string(safepost('fChange'));
  111. $fBack = escape_string(safepost('fBack'));
  112. $tUseremail = $fUsername;
  113. //set a default, reset fields for coming back selection
  114. if ($tSubject == '') {
  115. $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8');
  116. }
  117. if ($tBody == '') {
  118. $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8');
  119. }
  120. if (isset($choice_of_reply[$tInterval_Time])) {
  121. $fInterval_Time = $tInterval_Time;
  122. } else {
  123. $fInterval_Time = 0;
  124. }
  125. // if they've set themselves change OR back, delete any record of vacation emails.
  126. // the user is going away - set the goto alias and vacation table as necessary.
  127. //Set the vacation data for $fUsername
  128. if (!empty($fChange)) {
  129. ## check if ActiveUnitl is not back in time,
  130. ## because vacation.pl will report SMTP recipient $smtp_recipient which resolves to $email does not have an active vacation (rv: $rv, email: $email)"
  131. ## and will not send message
  132. if (($tActiveUntil >= date("Y-m-d")) and ($tActiveUntil >= $tActiveFrom)) {
  133. if (!$vh->set_away($fSubject, $fBody, $fInterval_Time, $tActiveFrom, $tActiveUntil)) {
  134. $error = 1;
  135. }
  136. } else {
  137. if ($tActiveUntil < date("Y-m-d")) {
  138. flash_error($PALANG['pVacation_until_before_today']);
  139. } else {
  140. flash_error($PALANG['pVacation_until_before_from']);
  141. }
  142. $error = 1;
  143. }
  144. }
  145. //if change, remove old one, then perhaps set new one
  146. if (!empty($fBack)) {
  147. if (!$vh->remove()) {
  148. $error = 1;
  149. }
  150. }
  151. }
  152. // If NO error then diplay flash message and go back to right url where we came from
  153. if ($error == 0) {
  154. if (!empty($fBack)) {
  155. flash_info(sprintf($PALANG['pVacation_result_removed'], htmlentities($tUseremail)));
  156. header("Location: $Return_url");
  157. exit;
  158. }
  159. if (!empty($fChange)) {
  160. flash_info(sprintf($PALANG['pVacation_result_added'], htmlentities($tUseremail)));
  161. header("Location: $Return_url");
  162. exit;
  163. }
  164. } else {
  165. flash_error(sprintf($PALANG['pVacation_result_error'], htmlentities($fUsername)));
  166. }
  167. $today = date("Y-m-d");
  168. if (empty($tActiveFrom)) {
  169. $tActiveFrom = $today;
  170. }
  171. if (empty($tActiveUntil)) {
  172. $tActiveUntil = $today;
  173. }
  174. if (! $details['active']) {
  175. # if vacation is disabled, there's no point in displaying the date of the last vacation ;-)
  176. # (which also means users would have to scroll in the calendar a lot)
  177. # so let's be user-friendly and set today's date (but only if the last vacation is in the past)
  178. if ($tActiveFrom < $today) {
  179. $tActiveFrom = $today;
  180. }
  181. if ($tActiveUntil < $today) {
  182. $tActiveUntil = $today;
  183. }
  184. }
  185. $smarty->assign('tUseremail', $tUseremail);
  186. $smarty->assign('tSubject', $tSubject);
  187. $smarty->assign('tBody', $tBody);
  188. $smarty->assign('tActiveFrom', date("d.m.Y", strtotime($tActiveFrom)));
  189. $smarty->assign('tActiveUntil', date("d.m.Y", strtotime($tActiveUntil)));
  190. $smarty->assign('select_options', $choice_of_reply);
  191. $smarty->assign('tInterval_Time', $tInterval_Time);
  192. $smarty->assign('smarty_template', 'vacation');
  193. $smarty->display('index.tpl');
  194. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */