|
|
@@ -3,7 +3,6 @@
|
|
|
Lib::loadClass('Router');
|
|
|
Lib::loadClass('RouteBase');
|
|
|
Lib::loadClass('TypespecialVariable');
|
|
|
-Lib::loadClass('ProcesHelper');
|
|
|
|
|
|
class Route_TableMsgs extends RouteBase {
|
|
|
|
|
|
@@ -67,7 +66,7 @@ class Route_TableMsgs extends RouteBase {
|
|
|
$arrorsList[] = $e->getMessage();
|
|
|
}
|
|
|
}
|
|
|
- $msgsList = $this->_getMsgs($tableName, $idRow);
|
|
|
+ $msgsList = $this->_getMsgs('inbox', $tableName, $idRow);
|
|
|
$totalReadMsgs = 0;
|
|
|
$totalUnreadMsgs = 0;
|
|
|
foreach ($msgsList as $ind => $msg) {
|
|
|
@@ -77,7 +76,8 @@ class Route_TableMsgs extends RouteBase {
|
|
|
$totalUnreadMsgs++;
|
|
|
}
|
|
|
}
|
|
|
- $sentMsgsList = $this->_getSentMsgs($tableName, $idRow);
|
|
|
+ $sentMsgsList = $this->_getMsgs('sent', $tableName, $idRow);
|
|
|
+ $removedMsgsList = $this->_getMsgs('removed', $tableName, $idRow);
|
|
|
?>
|
|
|
<style type="text/css">
|
|
|
.tblMsgsListItem { cursor:pointer; }
|
|
|
@@ -97,13 +97,17 @@ class Route_TableMsgs extends RouteBase {
|
|
|
</li>
|
|
|
<li role="presentation" class="active"><a href="#odebrane" aria-controls="odebrane" role="tab" data-toggle="tab">Odebrane <em>(<?php echo $totalUnreadMsgs; ?>)</em></a></li>
|
|
|
<li role="presentation"><a href="#wyslane" aria-controls="wyslane" role="tab" data-toggle="tab">Wysłane</em></a></li>
|
|
|
+ <li role="presentation"><a href="#kosz" aria-controls="kosz" role="tab" data-toggle="tab">Kosz</em></a></li>
|
|
|
</ul>
|
|
|
<div class="tab-content" style="margin-bottom:15px">
|
|
|
<div role="tabpanel" class="tab-pane active" id="odebrane" style="border-style:none solid solid solid; border-width:1px; border-color:#ddd;">
|
|
|
- <?php $this->_printTableMsgsList($msgsList, 'read'); ?>
|
|
|
+ <?php $this->_printTableMsgsList($msgsList, $idTable, $idRow, 'read'); ?>
|
|
|
</div>
|
|
|
<div role="tabpanel" class="tab-pane" id="wyslane" style="border-style:none solid solid solid; border-width:1px; border-color:#ddd;">
|
|
|
- <?php $this->_printTableMsgsList($sentMsgsList, 'view'); ?>
|
|
|
+ <?php $this->_printTableMsgsList($sentMsgsList, $idTable, $idRow, 'view'); ?>
|
|
|
+ </div>
|
|
|
+ <div role="tabpanel" class="tab-pane" id="kosz" style="border-style:none solid solid solid; border-width:1px; border-color:#ddd;">
|
|
|
+ <?php $this->_printTableMsgsList($removedMsgsList, $idTable, $idRow, 'view'); ?>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -128,7 +132,7 @@ class Route_TableMsgs extends RouteBase {
|
|
|
//throw new Exception("TODO: ...");
|
|
|
}
|
|
|
|
|
|
- public function _printTableMsgsList($msgsList, $actionTask = null) {
|
|
|
+ public function _printTableMsgsList($msgsList, $idTable, $idRow, $actionTask = null) {
|
|
|
$msgsTotal = count($msgsList);
|
|
|
?>
|
|
|
<table class="tblMsgsList table table-hovered" style="margin-bottom:0; table-layout:fixed;">
|
|
|
@@ -139,6 +143,13 @@ class Route_TableMsgs extends RouteBase {
|
|
|
<th style="width:130px">data</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
+ <tfoot>
|
|
|
+ <?php if ($msgsTotal > 20) : ?>
|
|
|
+ <tr>
|
|
|
+ <td colspan="3"><em class="text-muted" style="padding-left:60px;">...</em></td>
|
|
|
+ </tr>
|
|
|
+ <?php endif; ?>
|
|
|
+ </tfoot>
|
|
|
<tbody>
|
|
|
<?php if ($msgsTotal <= 0) : ?>
|
|
|
<tr>
|
|
|
@@ -149,6 +160,7 @@ class Route_TableMsgs extends RouteBase {
|
|
|
<?php
|
|
|
$onClick = '';
|
|
|
$msgLink = Request::getPathUri() . 'index.php?_route=TableMsgs&id=' . $msg['_raw']->ID;
|
|
|
+ $msgLink .= "&idTable={$idTable}&idRow={$idRow}";
|
|
|
if ('read' == $actionTask || 'view' == $actionTask) {
|
|
|
$msgLink .= '&_task=' . $actionTask;
|
|
|
} else {
|
|
|
@@ -176,7 +188,12 @@ class Route_TableMsgs extends RouteBase {
|
|
|
?>
|
|
|
</div>
|
|
|
</td>
|
|
|
- <td style="white-space:nowrap;"><?php echo $msg['_raw']->A_RECORD_CREATE_DATE; ?></td>
|
|
|
+ <td style="white-space:nowrap;">
|
|
|
+ <?php echo $msg['_raw']->A_RECORD_CREATE_DATE; ?>
|
|
|
+ <?php if ($msg['_readDate']) : ?>
|
|
|
+ <div class="text-muted" style="font-style:italic" title="Przeczytano <?php echo $msg['_readDate']; ?>"><?php echo $msg['_readDate']; ?></div>
|
|
|
+ <?php endif; ?>
|
|
|
+ </td>
|
|
|
</tr>
|
|
|
<?php endforeach; ?>
|
|
|
<?php endif; ?>
|
|
|
@@ -185,20 +202,62 @@ class Route_TableMsgs extends RouteBase {
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
- public function _getMsgs($tableName, $idRow) {
|
|
|
+ public function _getMsgs($filterType, $tableName, $idRow) {
|
|
|
$msgsRoute = Router::getRoute('Msgs');
|
|
|
- $msgsList = $msgsRoute->getMessagesForTableRecord($tableName, $idRow);
|
|
|
- foreach ($msgsList as $ind => $msg) {
|
|
|
- $msgsList[$ind]['_read'] = ('WAITING' != $msg['_raw']->A_STATUS);
|
|
|
+ //$msgsList = $msgsRoute->getMessagesForTableRecord($tableName, $idRow);
|
|
|
+ $msgsList = array();
|
|
|
+ if (empty($tableName)) throw new Exception("No table name!");
|
|
|
+ $sqlWhereAddFilter = "";
|
|
|
+ $usrLogin = User::getLogin();
|
|
|
+ switch ($filterType) {
|
|
|
+ case 'inbox':
|
|
|
+ $sqlWhereAddFilter = "
|
|
|
+ and (m.`userTargetType` in('everyone')
|
|
|
+ or (m.`userTargetType`='user' and m.`userTargetName`='{$usrLogin}')
|
|
|
+ -- TODO: use group id
|
|
|
+ )
|
|
|
+ and m.`A_STATUS` not in('DELETED')
|
|
|
+ ";
|
|
|
+ break;
|
|
|
+ case 'sent':
|
|
|
+ $sqlWhereAddFilter = "
|
|
|
+ and m.`A_RECORD_CREATE_AUTHOR`='{$usrLogin}'
|
|
|
+ and m.`A_STATUS` not in('DELETED')
|
|
|
+ ";
|
|
|
+ break;
|
|
|
+ case 'removed':
|
|
|
+ $sqlWhereAddFilter = "
|
|
|
+ and (m.`A_RECORD_CREATE_AUTHOR`='{$usrLogin}'
|
|
|
+ or (m.`userTargetType` in('everyone')
|
|
|
+ or (m.`userTargetType`='user' and m.`userTargetName`='{$usrLogin}')
|
|
|
+ -- TODO: use group id
|
|
|
+ )
|
|
|
+ )
|
|
|
+ and m.`A_STATUS` in('DELETED')
|
|
|
+ ";
|
|
|
+ break;
|
|
|
+ default: throw new Exception("Unknown filter type");
|
|
|
}
|
|
|
- return $msgsList;
|
|
|
- }
|
|
|
-
|
|
|
- public function _getSentMsgs($tableName, $idRow) {
|
|
|
- $msgsRoute = Router::getRoute('Msgs');
|
|
|
- $msgsList = $msgsRoute->getSentMessagesForTableRecord($tableName, $idRow);
|
|
|
- foreach ($msgsList as $ind => $msg) {
|
|
|
- $msgsList[$ind]['_read'] = ('WAITING' != $msg['_raw']->A_STATUS);
|
|
|
+ $db = DB::getDB();
|
|
|
+ $tableName = $db->_($tableName);
|
|
|
+
|
|
|
+ $sql = "select m.*
|
|
|
+ from `CRM_UI_MSGS` m
|
|
|
+ where m.`uiTargetType`='default_db_table_record'
|
|
|
+ and m.`uiTargetName`='{$tableName}.{$idRow}'
|
|
|
+ {$sqlWhereAddFilter}
|
|
|
+ order by m.`ID` DESC
|
|
|
+ limit 21
|
|
|
+ ";
|
|
|
+ $db = DB::getDB();
|
|
|
+ $res = $db->query($sql);
|
|
|
+ while ($r = $db->fetch($res)) {
|
|
|
+ $msg['message'] = $r->msg;
|
|
|
+ $msg['type'] = $r->msgType;
|
|
|
+ $msg['_raw'] = $r;
|
|
|
+ $msg['_read'] = ('WAITING' != $r->A_STATUS);
|
|
|
+ $msg['_readDate'] = $r->actionExecutedTime;
|
|
|
+ $msgsList[$r->ID] = $msg;
|
|
|
}
|
|
|
return $msgsList;
|
|
|
}
|
|
|
@@ -397,14 +456,18 @@ class Route_TableMsgs extends RouteBase {
|
|
|
}
|
|
|
|
|
|
public function readAction() {
|
|
|
- $msgId = V::get('id', 0, $_GET, 'int');
|
|
|
- if ($msgId <= 0) throw new HttpException("Wiadomość nie istnieje!", 404);
|
|
|
+ $idMsg = V::get('id', 0, $_GET, 'int');
|
|
|
+ $idTable = V::get('idTable', 0, $_REQUEST, 'int');
|
|
|
+ $idRow = V::get('idRow', 0, $_REQUEST, 'int');
|
|
|
+ if ($idMsg <= 0) throw new HttpException("Wiadomość nie istnieje!", 404);
|
|
|
+ if ($idTable <= 0) throw new HttpException("Błęny numer tabeli", 400);
|
|
|
+ if ($idRow <= 0) throw new HttpException("Błęny numer tabeli", 400);
|
|
|
|
|
|
SE_Layout::gora();
|
|
|
SE_Layout::menu();
|
|
|
|
|
|
try {
|
|
|
- $msg = $this->_getMsg($msgId);
|
|
|
+ $msg = $this->_getMsg($idMsg, $idTable, $idRow);
|
|
|
$this->_markAsRead($msg);
|
|
|
$this->tableRowMsg($msg);
|
|
|
} catch (Exception $e) {
|
|
|
@@ -415,14 +478,18 @@ class Route_TableMsgs extends RouteBase {
|
|
|
}
|
|
|
|
|
|
public function viewAction() {
|
|
|
- $msgId = V::get('id', 0, $_GET, 'int');
|
|
|
- if ($msgId <= 0) throw new HttpException("Wiadomość nie istnieje!", 404);
|
|
|
+ $idMsg = V::get('id', 0, $_GET, 'int');
|
|
|
+ $idTable = V::get('idTable', 0, $_REQUEST, 'int');
|
|
|
+ $idRow = V::get('idRow', 0, $_REQUEST, 'int');
|
|
|
+ if ($idMsg <= 0) throw new HttpException("Wiadomość nie istnieje!", 404);
|
|
|
+ if ($idTable <= 0) throw new HttpException("Błęny numer tabeli", 400);
|
|
|
+ if ($idRow <= 0) throw new HttpException("Błęny numer tabeli", 400);
|
|
|
|
|
|
SE_Layout::gora();
|
|
|
SE_Layout::menu();
|
|
|
|
|
|
try {
|
|
|
- $msg = $this->_getMsg($msgId);
|
|
|
+ $msg = $this->_getMsg($idMsg, $idTable, $idRow);
|
|
|
$this->tableRowMsg($msg);
|
|
|
} catch (Exception $e) {
|
|
|
SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
|
|
|
@@ -431,9 +498,12 @@ class Route_TableMsgs extends RouteBase {
|
|
|
SE_Layout::dol();
|
|
|
}
|
|
|
|
|
|
- public function _getMsg($msgId) {
|
|
|
+ public function _getMsg($idMsg, $idTable, $idRow) {
|
|
|
$msgsRoute = Router::getRoute('Msgs');
|
|
|
- $msg['_raw'] = $msgsRoute->getMessage($msgId);
|
|
|
+ $msg['_raw'] = $msgsRoute->getMessage($idMsg);
|
|
|
+ if (!$msg['_raw']) throw new HttpException("Wiadomość nie istnieje!", 404);
|
|
|
+ $msg['idTable'] = $idTable;
|
|
|
+ $msg['idRow'] = $idRow;
|
|
|
$msg['message'] = $msg['_raw']->msg;
|
|
|
$msg['type'] = $msg['_raw']->msgType;
|
|
|
$msg['_read'] = ('WAITING' != $msg['_raw']->A_STATUS);
|
|
|
@@ -446,8 +516,8 @@ class Route_TableMsgs extends RouteBase {
|
|
|
$parts = explode('.', $msg['_raw']->uiTargetName);
|
|
|
if (2 !== count($parts)) throw new Exception("Parse message target type error!");
|
|
|
$msg['tblName'] = $parts[0];
|
|
|
- $msg['idRow'] = $parts[1];
|
|
|
- if (!is_numeric($msg['idRow'])) throw new Exception("Parse message target type - id row error!");
|
|
|
+ if (!is_numeric($msg['idRow'])) throw new Exception("Parse message target type - id row type error!");
|
|
|
+ if ($msg['idRow'] != $parts[1]) throw new Exception("Parse message target type - id row value error!");
|
|
|
return $msg;
|
|
|
}
|
|
|
|
|
|
@@ -462,6 +532,7 @@ class Route_TableMsgs extends RouteBase {
|
|
|
set `A_STATUS`='NORMAL'
|
|
|
, `A_RECORD_UPDATE_AUTHOR`='{$usrLogin}'
|
|
|
, `A_RECORD_UPDATE_DATE`=NOW()
|
|
|
+ , `actionExecutedTime`=NOW()
|
|
|
where `ID`='{$msg['_raw']->ID}'
|
|
|
";
|
|
|
$res = $db->query($sql);
|
|
|
@@ -469,14 +540,19 @@ class Route_TableMsgs extends RouteBase {
|
|
|
}
|
|
|
|
|
|
public function tableRowMsg($msg) {
|
|
|
- $idTable = ProcesHelper::getZasobTableID($msg['tblName']);
|
|
|
+ $idTable = $msg['idTable'];
|
|
|
+ $idRow = $msg['idRow'];
|
|
|
$usrAcl = User::getAcl();
|
|
|
$tblAcl = $usrAcl->getTableAcl($idTable);
|
|
|
- $idRow = $msg['idRow'];
|
|
|
|
|
|
+ $linkBase = "index.php?_route=TableMsgs";
|
|
|
+ $linkBase .= "&idTable={$msg['idTable']}";
|
|
|
+ $linkBase .= "&idRow={$msg['idRow']}";
|
|
|
+ $rmMsgLink = "{$linkBase}&_task=removeMsg&id={$msg['_raw']->ID}";
|
|
|
+ $backLink = "{$linkBase}&_task=tableRow";
|
|
|
?>
|
|
|
<div class="container">
|
|
|
- <h3><i class="glyphicon glyphicon-envelope"></i> <a href="index.php?_route=TableMsgs&_task=tableRow&idTable=<?php echo $idTable; ?>&idRow=<?php echo $idRow; ?>">Wiadomości powiązane z rekordem nr <?php echo $idRow; ?></a>
|
|
|
+ <h3><i class="glyphicon glyphicon-envelope"></i> <a href="<?php echo $backLink; ?>">Wiadomości powiązane z rekordem nr <?php echo $idRow; ?></a>
|
|
|
» Wiadomość nr <code><?php echo $msg['_raw']->ID; ?></code>
|
|
|
<br><small>z tabeli <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=13051">Test permy</a></small>
|
|
|
</h3>
|
|
|
@@ -488,11 +564,68 @@ class Route_TableMsgs extends RouteBase {
|
|
|
<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 ('DELETED' != $msg['_raw']->A_STATUS) : ?>
|
|
|
+ <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
|
|
|
// TODO: odpisz
|
|
|
- // TODO: do kosza - add trigger to insert into `CRM_UI_MSGS__TRASH` after DELETE on `CRM_UI_MSGS`
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removeMsgAction() {
|
|
|
+ $idMsg = V::get('id', 0, $_GET, 'int');
|
|
|
+ $idTable = V::get('idTable', 0, $_REQUEST, 'int');
|
|
|
+ $idRow = V::get('idRow', 0, $_REQUEST, 'int');
|
|
|
+ if ($idMsg <= 0) throw new HttpException("Wiadomość nie istnieje!", 404);
|
|
|
+ if ($idTable <= 0) throw new HttpException("Błęny numer tabeli", 400);
|
|
|
+ if ($idRow <= 0) throw new HttpException("Błęny numer tabeli", 400);
|
|
|
+
|
|
|
+ SE_Layout::gora();
|
|
|
+ SE_Layout::menu();
|
|
|
+
|
|
|
+ try {
|
|
|
+ $msg = $this->_getMsg($idMsg, $idTable, $idRow);
|
|
|
+ $this->_removeRowMsg($msg);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
|
|
|
+ SE_Layout::dol();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+<div class="container">
|
|
|
+ <div class="alert alert-success">
|
|
|
+ Wiadomość została usunięta - <a href="index.php?_route=TableMsgs&_task=tableRow&idTable=<?php echo $idTable; ?>&idRow=<?php echo $idRow; ?>">wróć</a>
|
|
|
+ </div>
|
|
|
+</div>
|
|
|
+<?php
|
|
|
+ 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()));
|
|
|
}
|
|
|
|
|
|
}
|