소스 검색

added msg with reply feature to TableMsgs route like in UserMsgs route

Piotr Labudda 10 년 전
부모
커밋
04a557400b
2개의 변경된 파일47개의 추가작업 그리고 107개의 파일을 삭제
  1. 30 42
      SE/se-lib/Route/TableMsgs.php
  2. 17 65
      SE/se-lib/Route/UserMsgs.php

+ 30 - 42
SE/se-lib/Route/TableMsgs.php

@@ -618,7 +618,7 @@ function tblMsgsLoadMoreRows(n) {
 		try {
 			$msg = $this->_getMsg($idMsg, $idTable, $idRow);
 			$this->_markAsRead($msg);
-			$this->tableRowMsg($msg);
+			$this->viewMsg($msg);
 		} catch (Exception $e) {
 			SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
 		}
@@ -639,7 +639,7 @@ function tblMsgsLoadMoreRows(n) {
 
 		try {
 			$msg = $this->_getMsg($idMsg, $idTable, $idRow);
-			$this->tableRowMsg($msg);
+			$this->viewMsg($msg);
 		} catch (Exception $e) {
 			SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
 		}
@@ -688,54 +688,42 @@ function tblMsgsLoadMoreRows(n) {
 		if (!$res || $db->has_errors()) throw new Exception("Wystąpiły błędy podczas próby zapisu wiadomości: " . implode("\n<br>", $db->get_errors()));
 	}
 
-	public function tableRowMsg($msg) {
-		$idTable = $msg['idTable'];
-		$idRow = $msg['idRow'];
+	public function viewMsg($msg) {
 		$usrLogin = User::getLogin();
-		$usrAcl = User::getAcl();
-		$tblAcl = $usrAcl->getTableAcl($idTable);
-
-		$showRemoveBtn = true;
-		if ('DELETED' == $msg['_raw']->A_STATUS) $showRemoveBtn = false;
-		if ('OFF_HARD' == $msg['_raw']->A_STATUS && $usrLogin != $msg['_raw']->A_RECORD_CREATE_AUTHOR) $showRemoveBtn = false;
-
+		$idTable = 0;
+		if (!empty($msg['tblName'])) {
+			$tblName = $msg['tblName'];
+			$idTable = (!empty($msg['idTable']))? $msg['idTable'] : ProcesHelper::getZasobTableID($tblName);
+			if (!$idTable) throw new Exception("Nie udało się odnaleźć nr tabeli '{$tblName}'");
+			$idRow = $msg['idRow'];
+			if (!$idRow) throw new Exception("Brak numeru powiązanego rekordu!");
+			$usrAcl = User::getAcl();
+			$tblAcl = $usrAcl->getTableAcl($idTable);
+		}
+		$userMsgsRoute = Router::getRoute('UserMsgs');
 		$linkBase = "index.php?_route=TableMsgs";
-		$linkBase .= "&idTable={$msg['idTable']}";
-		$linkBase .= "&idRow={$msg['idRow']}";
-		$rmMsgLink = "{$linkBase}&_task=removeMsg&id={$msg['_raw']->ID}";
+		$linkBase .= "&idTable={$idTable}&idRow={$idRow}";
+		//$rmMsgLink = "{$linkBase}&_task=removeMsg&id={$msg['_raw']->ID}";
 		$backLink = "{$linkBase}&_task=tableRow";
 		?>
 <div class="container">
-	<h3 style="margin-bottom:20px; border-bottom:1px solid #e5e5e5;"><i class="glyphicon glyphicon-envelope"></i> <a href="<?php echo $backLink; ?>">Wiadomości powiązane z rekordem nr <?php echo $idRow; ?></a>
-		&raquo; Wiadomość nr <code><?php echo $msg['_raw']->ID; ?></code>
-<!--		<br><small>z tabeli <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getRawLabel(); ?></a></small> -->
-		<small style="display:block; text-align:right">
-			<a style="font-size:12px; line-height:15px; vertical-align:text-bottom;" title="Edytuj rekord" href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $idRow; ?></a>
-		</small>
+	<h3><i class="glyphicon glyphicon-envelope"></i> <a href="<?php echo $backLink; ?>">Wiadomości powiązane z rekordem nr <?php echo $idRow; ?></a>
+		&raquo; Wiadomość nr <?php echo $msg['_raw']->ID; ?>
+		<?php if ($idTable > 0) : ?>
+<!--			<br><small>wiadomość powiązana z rekordem <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><?php echo $idRow; ?></a>
+				z tabeli <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getLabel(); ?></a>
+			</small>
+-->
+			<small style="display:block; text-align:right">
+				<a style="font-size:12px; line-height:15px; vertical-align:text-bottom;" title="Edytuj rekord" href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $idRow; ?></a>
+				<span style="font-size:12px; line-height:15px; vertical-align:text-bottom;">z tabeli</span>
+				<a style="font-size:12px; line-height:15px; vertical-align:text-bottom;" href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getRawLabel(); ?></a>
+			</small>
+		<?php endif; ?>
 	</h3>
-	<div class="panel panel-<?php echo $msg['type']; ?>">
-		<div class="panel-heading">
-			<h3 class="panel-title">Wiadomość wysłana przez <?php echo $msg['_raw']->A_RECORD_CREATE_AUTHOR; ?>
-				<span class="pull-right"><?php echo $msg['_raw']->A_RECORD_CREATE_DATE; ?></span></h3>
-		</div>
-		<div class="panel-body">
-			<?php echo htmlspecialchars($msg['message']); ?>
-		</div>
-		<div class="panel-footer" style="overflow:hidden">
-			<?php if (!empty($msg['_raw']->A_RECORD_UPDATE_DATE) && !empty($msg['_raw']->A_RECORD_UPDATE_AUTHOR)) : ?>
-				<em style="margin-left:20px" class="text-muted">odczytana <?php echo $msg['_raw']->A_RECORD_UPDATE_DATE; ?> przez <?php echo $msg['_raw']->A_RECORD_UPDATE_AUTHOR; ?></em>
-			<?php endif; ?>
-			<?php if (!empty($msg['_raw']->A_RECORD_DELETE_DATE) && !empty($msg['_raw']->A_RECORD_DELETE_AUTHOR)) : ?>
-				<em style="margin-left:20px" class="text-muted">usunięta <?php echo $msg['_raw']->A_RECORD_DELETE_DATE; ?> przez <?php echo $msg['_raw']->A_RECORD_DELETE_AUTHOR; ?></em>
-			<?php endif; ?>
-			<?php if ($showRemoveBtn) : ?>
-				<a href="<?php echo $rmMsgLink; ?>" class="btn btn-xs btn-default pull-right" title="usuń wiadomość" onclick="return confirm('Czy jesteś pewien że chcesz usunąć wiadomość?');"><i class="glyphicon glyphicon-remove"></i> Usuń</a>
-			<?php endif; ?>
-		</div>
-	</div>
 </div>
+<?php $userMsgsRoute->printWidgetViewMsg($msg); ?>
 <?php
-		// TODO: odpisz
 	}
 
 	public function removeMsgAction() {

+ 17 - 65
SE/se-lib/Route/UserMsgs.php

@@ -656,66 +656,6 @@ function tblMsgsLoadMoreRows(n) {
 		if (!$res || $db->has_errors()) throw new Exception("Wystąpiły błędy podczas próby zapisu wiadomości: " . implode("\n<br>", $db->get_errors()));
 	}
 
-	public function viewMsg__OLD($msg) {
-		$tblName = $msg['tblName'];
-		$usrLogin = $msg['usrLogin'];
-		$idTable = ProcesHelper::getZasobTableID($tblName);
-		if (!$idTable) throw new Exception("Nie udało się odnaleźć nr tabeli '{$tblName}'");
-		$idRow = $msg['idRow'];
-		$usrAcl = User::getAcl();
-		$tblAcl = $usrAcl->getTableAcl($idTable);
-
-		$showRemoveBtn = true;
-		if ('DELETED' == $msg['_raw']->A_STATUS) $showRemoveBtn = false;
-		if ('OFF_HARD' == $msg['_raw']->A_STATUS && $usrLogin != $msg['_raw']->A_RECORD_CREATE_AUTHOR) $showRemoveBtn = false;
-
-		$linkBase = "index.php?_route=UserMsgs";
-		$linkBase .= "&usrLogin={$usrLogin}";
-		$rmMsgLink = "{$linkBase}&_task=removeMsg&id={$msg['_raw']->ID}";
-		$backLink = "{$linkBase}";
-
-		$msgMetaInfo = "do ";
-		if ('everyone' == $msg['_raw']->userTargetType) {
-			$msgMetaInfo .= 'wszystkich';
-		} else if ('user' == $msg['_raw']->userTargetType) {
-			$msgMetaInfo .= $msg['_raw']->userTargetName;
-		} else if ('group' == $msg['_raw']->userTargetType) {
-			$msgMetaInfo .= "grupy {$msg['_raw']->userTargetName}";
-		}
-?>
-<div class="container">
-	<h3><i class="glyphicon glyphicon-envelope"></i> <a href="<?php echo $backLink; ?>">Wiadomości <?php echo $usrLogin; ?></a>
-		&raquo; Wiadomość nr <?php echo $msg['_raw']->ID; ?>
-		<br><small>wiadomość powiązana z rekordem <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><?php echo $idRow; ?></a>
-			z tabeli <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getLabel(); ?></a>
-		</small>
-	</h3>
-
-	<div class="panel panel-<?php echo $msg['type']; ?>">
-		<div class="panel-heading">
-			<h3 class="panel-title">Wiadomość wysłana przez <?php echo $msg['_raw']->A_RECORD_CREATE_AUTHOR; ?>
-				<span class="pull-right"><?php echo $msg['_raw']->A_RECORD_CREATE_DATE; ?></span></h3>
-		</div>
-		<div class="panel-body">
-			<?php echo htmlspecialchars($msg['message']); ?>
-		</div>
-		<div class="panel-footer" style="overflow:hidden">
-			<?php if (!empty($msg['_raw']->A_RECORD_UPDATE_DATE) && !empty($msg['_raw']->A_RECORD_UPDATE_AUTHOR)) : ?>
-				<em style="margin-left:20px" class="text-muted">odczytana <?php echo $msg['_raw']->A_RECORD_UPDATE_DATE; ?> przez <?php echo $msg['_raw']->A_RECORD_UPDATE_AUTHOR; ?></em>
-			<?php endif; ?>
-			<?php if (!empty($msg['_raw']->A_RECORD_DELETE_DATE) && !empty($msg['_raw']->A_RECORD_DELETE_AUTHOR)) : ?>
-				<em style="margin-left:20px" class="text-muted">usunięta <?php echo $msg['_raw']->A_RECORD_DELETE_DATE; ?> przez <?php echo $msg['_raw']->A_RECORD_DELETE_AUTHOR; ?></em>
-			<?php endif; ?>
-			<?php if ($showRemoveBtn) : ?>
-				<a href="<?php echo $rmMsgLink; ?>" class="btn btn-xs btn-default pull-right" title="usuń wiadomość" onclick="return confirm('Czy jesteś pewien że chcesz usunąć wiadomość?');"><i class="glyphicon glyphicon-remove"></i> Usuń</a>
-			<?php endif; ?>
-		</div>
-	</div>
-</div>
-<?php
-		if (V::get('DBG_VIEW', '', $_GET)) $this->_testViewMsg($msg);
-	}
-
 	public function viewMsg($msg) {
 		$usrLogin = User::getLogin();
 		$idTable = 0;
@@ -724,6 +664,7 @@ function tblMsgsLoadMoreRows(n) {
 			$idTable = ProcesHelper::getZasobTableID($tblName);
 			if (!$idTable) throw new Exception("Nie udało się odnaleźć nr tabeli '{$tblName}'");
 			$idRow = $msg['idRow'];
+			if (!$idRow) throw new Exception("Brak numeru powiązanego rekordu!");
 			$usrAcl = User::getAcl();
 			$tblAcl = $usrAcl->getTableAcl($idTable);
 		}
@@ -736,34 +677,45 @@ function tblMsgsLoadMoreRows(n) {
 	<h3><i class="glyphicon glyphicon-envelope"></i> <a href="<?php echo $backLink; ?>">Wiadomości <?php echo $usrLogin; ?></a>
 		&raquo; Wiadomość nr <?php echo $msg['_raw']->ID; ?>
 		<?php if ($idTable > 0) : ?>
-			<br><small>wiadomość powiązana z rekordem <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><?php echo $idRow; ?></a>
+<!--			<br><small>wiadomość powiązana z rekordem <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><?php echo $idRow; ?></a>
 				z tabeli <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getLabel(); ?></a>
 			</small>
+-->
+			<small style="display:block; text-align:right">
+				<a style="font-size:12px; line-height:15px; vertical-align:text-bottom;" title="Edytuj rekord" href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>#EDIT/<?php echo $idRow; ?>"><i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $idRow; ?></a>
+				<span style="font-size:12px; line-height:15px; vertical-align:text-bottom;">z tabeli</span>
+				<a style="font-size:12px; line-height:15px; vertical-align:text-bottom;" href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getRawLabel(); ?></a>
+			</small>
 		<?php endif; ?>
 	</h3>
 </div>
+<?php $this->printWidgetViewMsg($msg); ?>
 <?php
+	}
+
+	public function printWidgetViewMsg($msg) {
 		$messageList = array();
 		$uiTargetName = $msg['_raw']->uiTargetName;
 		$uiTargetType = $msg['_raw']->uiTargetType;
 		$replyLink = "index.php?_route=UserMsgs&_task=reply&uiTargetName={$uiTargetName}&uiTargetType={$uiTargetType}";
 		$markAsReadLink = "index.php?_route=UserMsgs&_task=markAsRead";
 		$message = $this->_convertMessageToJson($msg['_raw']);
-		if ($message->idThread > 0) {
+		{//if ($message->idThread > 0) {
 			$sqlLimit = 100;
 			$ds = DB::getDataSource();
+			$sqlIdThread = ($message->idThread > 0)? $message->idThread : $message->id;
 			$sql = "
 				select m.*
 					from `CRM_UI_MSGS` m
-					where (m.`idThread` = {$message->idThread} or m.`ID` = {$message->idThread})
-						and m.`ID` < {$message->id}
+					where (m.`idThread` = {$sqlIdThread} or m.`ID` = {$sqlIdThread})
+				--		and m.`ID` < {$message->id}
 					order by m.`ID` asc
 					limit {$sqlLimit}
 			";
 			$moreMsgs = $ds->getListByQuery($sql);
 			foreach ($moreMsgs as $msg) $messageList[] = $this->_convertMessageToJson($msg);
 		}
-		$messageList[] = $message;
+		//$messageList[] = $message;
 		?>
 <link rel="stylesheet" href="./stuff/widget-select.css">
 <style type="text/css">