Procházet zdrojové kódy

added user select field and fixed sent msgs to another user in Notify

Piotr Labudda před 10 roky
rodič
revize
339cfa8a1d
2 změnil soubory, kde provedl 51 přidání a 7 odebrání
  1. 46 5
      SE/se-lib/Route/Notify.php
  2. 5 2
      SE/se-lib/Route/UserMsgs.php

+ 46 - 5
SE/se-lib/Route/Notify.php

@@ -4,6 +4,7 @@
 Lib::loadClass('RouteBase');
 Lib::loadClass('Przypomnij');
 Lib::loadClass('Request');
+Lib::loadClass('TypespecialVariable');
 Lib::loadClass('Route_UserMsgs');
 
 /*
@@ -65,7 +66,8 @@ class Route_Notify extends RouteBase {
 		}
 		$previewLink = implode('', $urlParts);
 
-		$lastSentDate = 'brak';
+		$lastSentDate = 'brak';// TODO: getLastSendData($usrLogin);
+		$typeSpecialUserLogin = TypespecialVariable::getInstance(-1, '__USER_LOGIN');
 		?>
 <div class="jumbotron">
 	<div class="container">
@@ -73,7 +75,19 @@ class Route_Notify extends RouteBase {
 			<div class="form-group">
 				<label class="col-sm-2 control-label">User</label>
 				<div class="col-sm-10">
-					<input class="form-control" type="text" name="usrLogin" value="<?php echo $usrLogin; ?>">
+				<?php if ($typeSpecialUserLogin) : ?>
+					<?php
+						$fldName = 'usrLogin';
+						$fldParams = array();
+						$fldParams['allowCreate'] = false;
+						$fldParams['ajaxDataUrlBase'] = "index.php?_route=Notify&_task=typeSpecialUserLogin";
+						$fldParams['placeholder'] = 'Szukaj...';
+						//$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
+						echo $typeSpecialUserLogin->showFormItem($tblID = -1, $fldName, $usrLogin, $fldParams);
+					?>
+				<?php else : ?>
+						<input class="form-control" type="text" name="usrLogin" value="<?php echo $usrLogin; ?>">
+				<?php endif; ?>
 				</div>
 			</div>
 
@@ -134,6 +148,33 @@ function refreshPreview() {
 		SE_Layout::dol();
 	}
 
+	public function typeSpecialUserLoginAction() {
+		header("Content-type: application/json");
+		$typeSpecialUserId = TypespecialVariable::getInstance(-1, '__USER_LOGIN');
+		if (!$typeSpecialUserId) {
+			$jsonData = new stdClass();
+			$jsonData->message = "TypeSpecial '__USER_LOGIN' not exists";
+			echo json_encode($jsonData);
+			exit;
+		}
+
+		$query = V::get('q', '', $_REQUEST);
+		$rawRows = null;
+		$jsonData = array();
+		$queryParams = array();
+		$rows = $typeSpecialUserId->getValuesWithExports($query, $queryParams);
+		foreach ($rows as $kID => $vItem) {
+			$itemJson = new stdClass();
+			$itemJson->id = $vItem->id;
+			$itemJson->name = $vItem->param_out;
+			if (!empty($vItem->exports)) {
+				$itemJson->exports = $vItem->exports;
+			}
+			$jsonData[] = $itemJson;
+		}
+		echo json_encode($jsonData);
+	}
+
 	public function send($usrLogin, $reminders) {
 		DBG::_(true, true, "usrLogin", $usrLogin, __CLASS__, __FUNCTION__, __LINE__);
 		DBG::_(true, true, "reminders", $reminders, __CLASS__, __FUNCTION__, __LINE__);
@@ -162,12 +203,12 @@ function refreshPreview() {
 		$subject = "Powiadomienie - {$_SERVER['SERVER_NAME']}";
 		ob_start();
 		$this->generateUserReminders($usrLogin, $reminders);
+		echo '<br><br>' . "\n";
+		echo "Wiadomość została wygenerowana autoamtycznie.";
+		echo "<br>\n------------------ TEST --------------------";// TODO: TEST
 		$message = ob_get_clean();
 
 		if (!mail($to, $subject, $message, $headers)) throw new Exception("Nie udało się wysłać powiadomienia");
-		echo 'Your message has been sent.';
-		throw new Exception(".EOF TODO");
-		DBG::_(true, true, "user", $user, __CLASS__, __FUNCTION__, __LINE__);
 	}
 
 	public function generateUserRemindersAction() {

+ 5 - 2
SE/se-lib/Route/UserMsgs.php

@@ -4,6 +4,7 @@ Lib::loadClass('Router');
 Lib::loadClass('RouteBase');
 Lib::loadClass('TypespecialVariable');
 Lib::loadClass('ProcesHelper');
+Lib::loadClass('UsersHelper');
 
 class Route_UserMsgs extends RouteBase {
 
@@ -311,9 +312,11 @@ function tblMsgsLoadMoreRows(n) {
 		$msgsList = array();
 		if (empty($usrLogin)) throw new Exception("No user login!");
 		$sqlWhereAddFilter = "";
-		{// TODO: fetch groups ids for another user - $usrLogin
-			$usrLogin = User::getLogin();
+		if ($usrLogin == User::getLogin()) {
 			$userGroupIds = User::getGroupsIds();
+		} else {
+			$userGroup = UsersHelper::getGroupByUserName($usrLogin);
+			$userGroupIds = array_keys($userGroup);
 		}
 		$sqlFilerMsgsForUser = "
 			m.`userTargetType` in('everyone')