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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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: vacation.php 1842 2016-05-20 20:42:04Z christian_boltz $
  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. }
  52. else {
  53. $Admin_role = 0 ;
  54. $Return_url = "main.php";
  55. authentication_require_role('user');
  56. $fUsername = authentication_get_username();
  57. }
  58. // is vacation support enabled in $CONF ?
  59. if($CONF['vacation'] == 'NO') {
  60. header ("Location: $Return_url");
  61. exit(0);
  62. }
  63. date_default_timezone_set(@date_default_timezone_get()); # Suppress date.timezone warnings
  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 == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
  89. if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
  90. }
  91. if ($_SERVER['REQUEST_METHOD'] == "POST")
  92. {
  93. if (safepost('token') != $_SESSION['PFA_token']) die('Invalid token!');
  94. if(isset($_POST['fCancel'])) {
  95. header ("Location: $Return_url");
  96. exit(0);
  97. }
  98. $tActiveFrom = date ("Y-m-d 00:00:00", strtotime (safepost('fActiveFrom')));
  99. $tActiveUntil = date ("Y-m-d 23:59:59", strtotime (safepost('fActiveUntil')));
  100. $tSubject = safepost('fSubject');
  101. $fSubject = $tSubject;
  102. $tBody = safepost('fBody');
  103. $fBody = $tBody;
  104. $tInterval_Time = safepost('fInterval_Time');
  105. $fChange = escape_string (safepost('fChange'));
  106. $fBack = escape_string (safepost('fBack'));
  107. $tUseremail = $fUsername;
  108. //set a default, reset fields for coming back selection
  109. if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
  110. if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
  111. if (isset($choice_of_reply[$tInterval_Time])) {
  112. $fInterval_Time = $tInterval_Time;
  113. } else {
  114. $fInterval_Time = 0;
  115. }
  116. // if they've set themselves change OR back, delete any record of vacation emails.
  117. // the user is going away - set the goto alias and vacation table as necessary.
  118. //Set the vacation data for $fUsername
  119. if (!empty ($fChange))
  120. {
  121. ## check if ActiveUnitl is not back in time,
  122. ## because vacation.pl will report SMTP recipient $smtp_recipient which resolves to $email does not have an active vacation (rv: $rv, email: $email)"
  123. ## and will not send message
  124. if ( ($tActiveUntil >= date ("Y-m-d")) and ($tActiveUntil >= $tActiveFrom) ) {
  125. if (!$vh->set_away($fSubject, $fBody, $fInterval_Time, $tActiveFrom, $tActiveUntil)) {
  126. $error = 1;
  127. }
  128. } else {
  129. if ( $tActiveUntil < date ("Y-m-d") ) {
  130. flash_error($PALANG['pVacation_until_before_today']);
  131. } else {
  132. flash_error($PALANG['pVacation_until_before_from']);
  133. }
  134. $error = 1;
  135. }
  136. }
  137. //if change, remove old one, then perhaps set new one
  138. if (!empty ($fBack))
  139. {
  140. if(!$vh->remove()) {
  141. $error = 1;
  142. }
  143. }
  144. }
  145. // If NO error then diplay flash message and go back to right url where we came from
  146. if($error == 0) {
  147. if(!empty ($fBack)) {
  148. flash_info(sprintf($PALANG['pVacation_result_removed'],htmlentities($tUseremail)));
  149. header ("Location: $Return_url");
  150. exit;
  151. }
  152. if(!empty($fChange)) {
  153. flash_info(sprintf($PALANG['pVacation_result_added'],htmlentities($tUseremail)));
  154. header ("Location: $Return_url");
  155. exit;
  156. }
  157. }
  158. else {
  159. flash_error(sprintf($PALANG['pVacation_result_error'],htmlentities($fUsername)));
  160. }
  161. $today = date ("Y-m-d");
  162. if (empty ($tActiveFrom)) $tActiveFrom = $today;
  163. if (empty ($tActiveUntil)) $tActiveUntil = $today;
  164. if ( ! $details['active']) {
  165. # if vacation is disabled, there's no point in displaying the date of the last vacation ;-)
  166. # (which also means users would have to scroll in the calendar a lot)
  167. # so let's be user-friendly and set today's date (but only if the last vacation is in the past)
  168. if ($tActiveFrom < $today) $tActiveFrom = $today;
  169. if ($tActiveUntil < $today) $tActiveUntil = $today;
  170. }
  171. $smarty->assign ('tUseremail', $tUseremail);
  172. $smarty->assign ('tSubject', $tSubject);
  173. $smarty->assign ('tBody', $tBody);
  174. $smarty->assign ('tActiveFrom', date ("d.m.Y", strtotime ($tActiveFrom)));
  175. $smarty->assign ('tActiveUntil', date ("d.m.Y", strtotime ($tActiveUntil)));
  176. $smarty->assign ('select_options', $choice_of_reply);
  177. $smarty->assign ('tInterval_Time', $tInterval_Time);
  178. $smarty->assign ('smarty_template', 'vacation');
  179. $smarty->display ('index.tpl');
  180. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  181. ?>