Quellcode durchsuchen

Msgs fix remove msg

Piotr Labudda vor 10 Jahren
Ursprung
Commit
4451a169e0
3 geänderte Dateien mit 62 neuen und 44 gelöschten Zeilen
  1. 26 0
      SE/se-lib/Route/Msgs.php
  2. 8 20
      SE/se-lib/Route/TableMsgs.php
  3. 28 24
      SE/se-lib/Route/UserMsgs.php

+ 26 - 0
SE/se-lib/Route/Msgs.php

@@ -17,6 +17,12 @@ Lib::loadClass('RouteBase');
 	- `actionNotes` - notes/msgs/dbg for user actions executed from this msg
 
 	Messages created by db triggers must define `app_className` that should parse `msg`. For example to use in FixProjectPath and FixZasobPath to keep correct paths.
+
+	## `A_STATUS`
+	- 'WAITING'  - msg sent by `A_RECORD_CREATE_AUTHOR` at `A_RECORD_CREATE_DATE`
+	- 'NORMAL'   - msg read by `A_RECORD_UPDATE_AUTHOR` at `A_RECORD_UPDATE_DATE`
+	- 'OFF_HARD' - msg deleted by `A_RECORD_DELETE_AUTHOR` if != `A_RECORD_CREATE_AUTHOR` at `A_RECORD_DELETE_DATE`
+	- 'DELETED'  - msg deleted by `A_RECORD_CREATE_AUTHOR` at `A_RECORD_DELETE_DATE`
 */
 class Route_Msgs extends RouteBase {
 
@@ -439,4 +445,24 @@ SQL_QUERY;
 		$db->query($sql);
 	}
 
+	public function removeTableRecordMsg($idMsg) {
+		// IDEA: do kosza - add trigger to insert into `CRM_UI_MSGS__TRASH` after DELETE on `CRM_UI_MSGS`
+		$idMsg = intval($idMsg);
+		if ($idMsg <= 0) throw new Exception("Brak wiadomości!");
+		$usrLogin = User::getLogin();
+		$db = DB::getDB();
+		if (!$db) throw new Exception("Brak dazy danych!");
+		if ($db->has_errors()) throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+		$sqlTODO = "delete `CRM_UI_MSGS` where `ID`='{$idMsg}' ";
+		$sql = "update `CRM_UI_MSGS`
+			set `A_STATUS`=IF('{$usrLogin}'=`A_RECORD_CREATE_AUTHOR`, 'DELETED', 'OFF_SOFT')
+				, `A_RECORD_DELETE_AUTHOR`='{$usrLogin}'
+				, `A_RECORD_DELETE_DATE`=NOW()
+			where `ID`='{$idMsg}'
+		";
+		DBG::_('DBG_MSGS', '>1', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		$res = $db->query($sql);
+		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()));
+	}
+
 }

+ 8 - 20
SE/se-lib/Route/TableMsgs.php

@@ -687,9 +687,14 @@ function tblMsgsLoadMoreRows(n) {
 	public function tableRowMsg($msg) {
 		$idTable = $msg['idTable'];
 		$idRow = $msg['idRow'];
+		$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;
+
 		$linkBase = "index.php?_route=TableMsgs";
 		$linkBase .= "&idTable={$msg['idTable']}";
 		$linkBase .= "&idRow={$msg['idRow']}";
@@ -716,7 +721,7 @@ function tblMsgsLoadMoreRows(n) {
 			<?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 ('DELETED' != $msg['_raw']->A_STATUS) : ?>
+			<?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>
@@ -739,7 +744,8 @@ function tblMsgsLoadMoreRows(n) {
 
 		try {
 			$msg = $this->_getMsg($idMsg, $idTable, $idRow);
-			$this->_removeRowMsg($msg);
+			$msgsRoute = Router::getRoute('Msgs');
+			$msgsRoute->removeTableRecordMsg($idMsg);
 		} catch (Exception $e) {
 			SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
 			SE_Layout::dol();
@@ -755,22 +761,4 @@ function tblMsgsLoadMoreRows(n) {
 		SE_Layout::dol();
 	}
 
-	public function _removeRowMsg($msg) {
-		// IDEA: do kosza - add trigger to insert into `CRM_UI_MSGS__TRASH` after DELETE on `CRM_UI_MSGS`
-		if (empty($msg['_raw']) || empty($msg['_raw']->ID)) throw new Exception("Brak wiadomości!");
-		$usrLogin = User::getLogin();
-		$db = DB::getDB();
-		if (!$db) throw new Exception("Brak dazy danych!");
-		if ($db->has_errors()) throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
-		$sqlTODO = "delete `CRM_UI_MSGS` where `ID`='{$msg['_raw']->ID}' ";
-		$sql = "update `CRM_UI_MSGS`
-			set `A_STATUS`='DELETED'
-				, `A_RECORD_DELETE_AUTHOR`='{$usrLogin}'
-				, `A_RECORD_DELETE_DATE`=NOW()
-			where `ID`='{$msg['_raw']->ID}'
-		";
-		$res = $db->query($sql);
-		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()));
-	}
-
 }

+ 28 - 24
SE/se-lib/Route/UserMsgs.php

@@ -324,13 +324,15 @@ function tblMsgsLoadMoreRows(n) {
 			case 'inbox':
 				$sqlWhereAddFilter = "
 					and ({$sqlFilerMsgsForUser})
-					and m.`A_STATUS` not in('DELETED')
+					and m.`A_STATUS` in('WAITING', 'NORMAL')
 				";
 				break;
 			case 'sent':
 				$sqlWhereAddFilter = "
 					and m.`A_RECORD_CREATE_AUTHOR`='{$usrLogin}'
-					and m.`A_STATUS` not in('DELETED')
+					and (m.`A_STATUS` in('WAITING', 'NORMAL')
+						or (m.`A_STATUS`='OFF_HARD' and m.`A_RECORD_DELETE_AUTHOR`!='{$usrLogin}')
+					)
 				";
 				break;
 			case 'removed':
@@ -338,7 +340,7 @@ function tblMsgsLoadMoreRows(n) {
 					and (m.`A_RECORD_CREATE_AUTHOR`='{$usrLogin}'
 						or ({$sqlFilerMsgsForUser})
 					)
-					and m.`A_STATUS` in('DELETED')
+					and m.`A_STATUS` in('OFF_HARD', 'DELETED')
 				";
 				break;
 			default: throw new Exception("Unknown filter type");
@@ -653,6 +655,10 @@ function tblMsgsLoadMoreRows(n) {
 		$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}";
@@ -665,6 +671,22 @@ function tblMsgsLoadMoreRows(n) {
 			z tabeli <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idTable; ?>"><?php echo $tblAcl->getLabel(); ?></a>
 		</small>
 	</h3>
+<!--
+<ul class="media-list">
+  <li class="media">
+    <div class="media-left">
+      <a href="#">
+        <img class="media-object" src="..." alt="...">
+      </a>
+    </div>
+    <div class="media-body">
+      <h4 class="media-heading">Media heading</h4>
+      ...
+			<ul class="media-list">...</ul>
+    </div>
+  </li>
+</ul>
+-->
 	<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; ?>
@@ -680,7 +702,7 @@ function tblMsgsLoadMoreRows(n) {
 			<?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 ('DELETED' != $msg['_raw']->A_STATUS) : ?>
+			<?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>
@@ -691,7 +713,6 @@ function tblMsgsLoadMoreRows(n) {
 	}
 
 	public function removeMsgAction() {
-		$idMsg = V::get('id', 0, $_GET, 'int');
 		$idMsg = V::get('id', 0, $_GET, 'int');
 		$usrLogin = V::get('usrLogin', 0, $_REQUEST, 'word');
 		if ($idMsg <= 0) throw new HttpException("Wiadomość nie istnieje!", 404);
@@ -702,7 +723,8 @@ function tblMsgsLoadMoreRows(n) {
 
 		try {
 			$msg = $this->_getMsg($idMsg, $usrLogin);
-			$this->_removeRowMsg($msg);
+			$msgsRoute = Router::getRoute('Msgs');
+			$msgsRoute->removeTableRecordMsg($idMsg);
 		} catch (Exception $e) {
 			SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
 			SE_Layout::dol();
@@ -718,22 +740,4 @@ function tblMsgsLoadMoreRows(n) {
 		SE_Layout::dol();
 	}
 
-	public function _removeRowMsg($msg) {
-		// IDEA: do kosza - add trigger to insert into `CRM_UI_MSGS__TRASH` after DELETE on `CRM_UI_MSGS`
-		if (empty($msg['_raw']) || empty($msg['_raw']->ID)) throw new Exception("Brak wiadomości!");
-		$usrLogin = User::getLogin();
-		$db = DB::getDB();
-		if (!$db) throw new Exception("Brak dazy danych!");
-		if ($db->has_errors()) throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
-		$sqlTODO = "delete `CRM_UI_MSGS` where `ID`='{$msg['_raw']->ID}' ";
-		$sql = "update `CRM_UI_MSGS`
-			set `A_STATUS`='DELETED'
-				, `A_RECORD_DELETE_AUTHOR`='{$usrLogin}'
-				, `A_RECORD_DELETE_DATE`=NOW()
-			where `ID`='{$msg['_raw']->ID}'
-		";
-		$res = $db->query($sql);
-		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()));
-	}
-
 }