Piotr Labudda 10 lat temu
rodzic
commit
326098a339
1 zmienionych plików z 24 dodań i 17 usunięć
  1. 24 17
      SE/se-lib/Route/Notify.php

+ 24 - 17
SE/se-lib/Route/Notify.php

@@ -32,8 +32,10 @@ class Route_Notify extends RouteBase {
 
 	public function defaultAction() {
 		SE_Layout::gora();
+		SE_Layout::menu();
 		try {
-			$this->formUserTableReminder();
+			$usrLogin = User::getLogin();
+			$this->formUserTableReminder($usrLogin);
 		} catch (Exception $e) {
 			SE_Layout::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
 		}
@@ -184,25 +186,12 @@ function refreshPreview() {
 	public function send($usrLogin, $reminders, $forceMail = null) {
 		DBG::_('DBG_NTF', '>1', "usrLogin", $usrLogin, __CLASS__, __FUNCTION__, __LINE__);
 		DBG::_('DBG_NTF', '>1', "reminders", $reminders, __CLASS__, __FUNCTION__, __LINE__);
-		$user = null;
-		$sth = DB::getPDO()->prepare("
-			select u.ID, u.ADM_ACCOUNT as login, u.EMAIL_LOCAL_ACCOUNT_ADDRESS as aliasy
-			from ADMIN_USERS u
-			where u.ADM_ACCOUNT = :usr_login
-		");
-		$sth->bindValue(':usr_login', $usrLogin, PDO::PARAM_STR);
-		$sth->execute();
-		$user = $sth->fetch();
-		if (!$user) throw new Exception("User not found");
+		$mainMail = $this->getUserMainMail($usrLogin);
 
 		$msgNote = '';
 		if (!empty($forceMail)) {
 			$mainMail = $forceMail;
 			if (empty($user['aliasy'])) $msgNote .= 'ERROR: Brak lokalnego adresu email' . "\n\n";
-		} else {
-			if (empty($user['aliasy'])) throw new Exception("Brak lokalnego adresu email");
-			$aliasy = explode(' ', trim($user['aliasy']));
-			$mainMail = reset($aliasy);
 		}
 
 		$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
@@ -222,6 +211,23 @@ function refreshPreview() {
 		if (!mail($to, $subject, $message, $headers)) throw new Exception("Nie udało się wysłać powiadomienia");
 	}
 
+	public function getUserMainMail($usrLogin) {
+		$user = null;
+		$sth = DB::getPDO()->prepare("
+		select u.ID, u.ADM_ACCOUNT as login, u.EMAIL_LOCAL_ACCOUNT_ADDRESS as aliasy
+		from ADMIN_USERS u
+		where u.ADM_ACCOUNT = :usr_login
+		");
+		$sth->bindValue(':usr_login', $usrLogin, PDO::PARAM_STR);
+		$sth->execute();
+		$user = $sth->fetch();
+		if (!$user) throw new Exception("User not found");
+
+		if (empty($user['aliasy'])) throw new Exception("Brak lokalnego adresu email");
+		$aliasy = explode(' ', trim($user['aliasy']));
+		return reset($aliasy);
+	}
+
 	public function markAsSent($usrLogin, $reminders) {
 		$sqlReminderTypes = "'" . implode("','", $reminders) . "'";
 		$sth = DB::getPDO()->prepare("
@@ -513,8 +519,7 @@ function refreshPreview() {
 		$sth->execute();
 	}
 
-	public function formUserTableReminder() {
-		$usrLogin = User::getLogin();
+	public function formUserTableReminder($usrLogin) {
 		echo '<div class="container">';
 		$subTask = V::get('_subTask', '', $_POST);
 		if ('_add_table_reminder' == $subTask) {
@@ -540,8 +545,10 @@ function refreshPreview() {
 			}
 		}
 		$userReminders = $this->getUserReminders($usrLogin);
+		$userMail = $this->getUserMainMail($usrLogin);
 		?>
 	<h1>Powiadomienia dla <code><?php echo $usrLogin; ?></code></h1>
+	<p><i>Będą wysyłane na adres: <?php echo $userMail; ?></i></p>
 	<?php if (empty($userReminders)) : ?>
 		<?php SE_Layout::alert('warning', "Brak zdefiniowanych powiadomień"); ?>
 	<?php else : ?>