| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- <?php
- Lib::loadClass('Router');
- Lib::loadClass('RouteBase');
- Lib::loadClass('TypespecialVariable');
- class Route_TableMsgs extends RouteBase {
- var $_listLimit = 20;
- public function handleAuth() {
- if (!User::logged()) {
- User::authByRequest();
- }
- }
- public function defaultAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- $this->menu();
- SE_Layout::dol();
- }
- public function menu() {
- $usrLogin = User::getLogin();
- ?>
- <ul>
- <li>TODO: ...</li>
- </ul>
- <?php
- }
- public function tableRowAction() {
- $idTable = V::get('idTable', 0, $_REQUEST, 'int');
- $idRow = V::get('idRow', 0, $_REQUEST, 'int');
- 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 {
- $this->tableRowMsgs($idTable, $idRow);
- } catch (Exception $e) {
- SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
- }
- SE_Layout::dol();
- }
- public function tableRowMsgs($idTable, $idRow) {
- $tblAcl = User::getAcl()->getTableAcl($idTable);
- $tableName = $tblAcl->getName();
- $record = $tblAcl->getItem($idRow);
- $args = array();
- $args['to_type'] = V::get('to_type', '', $_POST);
- $args['to'] = V::get("to-{$args['to_type']}", '', $_POST);
- $args['msg'] = V::get('msg', '', $_POST);
- $arrorsList = array();
- $createdId = 0;
- if (!empty($_POST)) {
- try {
- $this->_validate($args);
- $createdId = $this->_create($args, $tableName, $idRow);
- if ($createdId > 0) {
- $args['to'] = '';
- $args['msg'] = '';
- }
- } catch(Exception $e) {
- $arrorsList[] = $e->getMessage();
- }
- }
- $msgsList = $this->getMsgs('inbox', $tableName, $idRow);
- $totalReadMsgs = 0;
- $totalUnreadMsgs = 0;
- foreach ($msgsList as $ind => $msg) {
- if ($msg['_read']) {
- $totalReadMsgs++;
- } else {
- $totalUnreadMsgs++;
- }
- }
- $sentMsgsList = $this->getMsgs('sent', $tableName, $idRow);
- $removedMsgsList = $this->getMsgs('removed', $tableName, $idRow);
- ?>
- <style type="text/css">
- .tblMsgsListItem { cursor:pointer; }
- </style>
- <div class="container">
- <h3 style="margin-bottom:20px; border-bottom:1px solid #e5e5e5;"><i class="glyphicon glyphicon-envelope"></i> Wiadomości powiązane z rekordem nr <code><?php echo $idRow; ?></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>
- <?php if ($createdId > 0) : ?>
- <?php echo SE_Layout::alert('info', "Wysłano wiadomość nr '{$createdId}'"); ?>
- <?php endif; ?>
- <div>
- <ul class="nav nav-tabs" role="tablist">
- <li>
- <a href="#tbl-msgs-compose"><i class="glyphicon glyphicon-plus"></i> Nowa wiadomość</a>
- </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('inbox', $msgsList, $idTable, $idRow); ?>
- </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('sent', $sentMsgsList, $idTable, $idRow); ?>
- </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('removed', $removedMsgsList, $idTable, $idRow); ?>
- </div>
- </div>
- </div>
- <div class="panel panel-default" id="tbl-msgs-compose">
- <div class="panel-heading">Wyślij nową wiadomość</div>
- <div class="panel-body">
- <?php if (!empty($arrorsList)) : ?>
- <?php foreach ($arrorsList as $errMsg) : ?>
- <div class="alert alert-danger"><?php echo $errMsg; ?></div>
- <?php endforeach; ?>
- <?php endif; ?>
- <?php $this->_printMsgForm($args); ?>
- </div>
- </div>
- </div>
- <script>
- function tblMsgsLoadMoreRows(n) {
- var nNode = jQuery(n),
- lastMsgId = nNode.data('last_msg_id'),
- listType = nNode.data('list_type')
- ;
- nNode.blur();
- function tblMsgsSetNoMoreRows(btnLoadMoreNode) {
- btnLoadMoreNode.closest('td').css({color:'silver'}).html('Brak starszych wiadomości');
- }
- if (lastMsgId <= 0) {
- tblMsgsSetNoMoreRows(nNode);
- }
- function tblMsgsAddMsgToList(msg, btnLoadMoreNode, listType) {
- var tbodyNode = btnLoadMoreNode.closest('tfoot').prev('tbody'),
- trNode = jQuery('<tr></tr>'),
- tdIdNode = jQuery('<td></td>'),
- tdMsgNode = jQuery('<td></td>'),
- tdDateNode = jQuery('<td style="white-space:nowrap;"></td>'),
- actionTask = (listType == 'inbox')? 'read' : 'view',
- msgLink = ''
- ;
- trNode.addClass('tblMsgsListItem');
- if (msg['_read']) trNode.addClass('active');
- if ('read' === actionTask || 'view' === actionTask) {
- msgLink = '<?php echo Request::getPathUri() . 'index.php?_route=TableMsgs'; ?>';
- msgLink += '&idTable=<?php echo $idTable; ?>&idRow=<?php echo $idRow; ?>';
- msgLink += '&id=' + msg['_raw']['ID'];
- msgLink += '&_task=' + actionTask;
- trNode.attr('onclick', "window.location.href='" + msgLink + "'");
- }
- tdIdNode.append(msg['_raw']['ID']);
- tdIdNode.appendTo(trNode);
- tdMsgNode.append('<div style="overflow:hidden; white-space:nowrap; text-overflow:ellipsis;">' + msg['message'] + '</div>');
- msgMetaInfo = 'od ' + msg['_raw']['A_RECORD_CREATE_AUTHOR'] + ' 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'];
- }
- tdMsgNode.append('<div class="text-muted" style="font-style:italic;">' + msgMetaInfo + '</div>');
- tdMsgNode.appendTo(trNode);
- tdDateNode.append(msg['_raw']['A_RECORD_CREATE_DATE']);
- if (msg['_readDate']) {
- tdDateNode.append('<div class="text-muted" style="font-style:italic" title="Przeczytano ' + msg['_readDate'] + '">' + msg['_readDate'] + '</div>');
- } else {
- tdDateNode.append('<div class="text-muted" style="font-style:italic" title="Wiadomość nie została jeszcze odczytana">nieodczytana</div>');
- }
- tdDateNode.appendTo(trNode);
- trNode.hide();
- trNode.appendTo(tbodyNode);
- trNode.show('slow');
- };
- jQuery.ajax({
- data: {},
- dataType: 'json',
- type: "POST",
- url: 'index.php?_route=TableMsgs&_task=loadMoreRows&listType=' + listType + '&lastMsgId=' + lastMsgId + '&tableName=<?php echo $tableName; ?>' + '&idRow=<?php echo $idRow; ?>'
- })
- .done(function(data, textStatus, jqXHR) {
- var listLimit = <?php echo $this->_listLimit; ?>,
- i = 0,
- lastMsgId = 0,
- hasMore = false
- ;
- if (!data || !data.msgs || !data.keysOrder) {
- jQuery.notify('Wystąpiły błędy podczas pobierania listy wiadomości', 'error');
- return false;
- }
- data.keysOrder.forEach(function(key) {
- if (i < listLimit) {
- lastMsgId = key;
- tblMsgsAddMsgToList(data.msgs[key], nNode, listType);
- } else {
- hasMore = true;
- }
- i++;
- });
- if (!hasMore) {
- tblMsgsSetNoMoreRows(nNode);
- }
- nNode.data('last_msg_id', lastMsgId);
- })
- .fail(function(jqXHR) {
- if (jqXHR.responseJSON) {
- jQuery.notify('Nie udało się pobrać listy wiadomości', 'error');
- }
- else {
- var txt = jqXHR.responseText || 'Nie udało się pobrać listy wiadomości';
- if (jqXHR.status == 404) {
- jQuery.notify(jqXHR.responseText, 'error');
- } else {
- jQuery.notify(jqXHR.responseText, 'warn');
- }
- }
- });
- }
- </script>
- <?php
- //DBG::_(true, true, "_POST", $_POST, __CLASS__, __FUNCTION__, __LINE__);
- //DBG::_(true, true, "tblAcl", $tblAcl, __CLASS__, __FUNCTION__, __LINE__);
- //DBG::_(true, true, "record", $record, __CLASS__, __FUNCTION__, __LINE__);
- //DBG::_(true, true, "msgsList", $msgsList, __CLASS__, __FUNCTION__, __LINE__);
- //throw new Exception("TODO: ...");
- }
- public function loadMoreRowsAction() {
- $tableName = V::get('tableName', '', $_GET, 'word');
- $idRow = V::get('idRow', 0, $_GET, 'int');
- $lastMsgId = V::get('lastMsgId', 0, $_GET, 'int');
- $listType = V::get('listType', '', $_GET, 'word');
- if ($idRow <= 0) throw new HttpException("Wrong param id row", 404);
- if (!$tableName) throw new HttpException("Wrong param table name", 404);
- if ($lastMsgId <= 0) throw new HttpException("Wrong param lastMsgId", 404);
- if (!in_array($listType, array('inbox','sent','removed'))) throw new HttpException("Wrong param listType", 404);
- $resultData = new stdClass();
- $resultData->msgs = $this->getMsgs($listType, $tableName, $idRow, $lastMsgId);
- $resultData->keysOrder = array_keys($resultData->msgs);
- echo json_encode($resultData);
- }
- public function _printTableMsgsList($listType, $msgsList, $idTable, $idRow) {
- $msgsTotal = count($msgsList);
- $listLimit = $this->_listLimit;
- $lastMsgId = 0;
- $actionTask = ($listType == 'inbox')? 'read' : 'view';
- ?>
- <table class="tblMsgsList table table-hovered" style="margin-bottom:0; table-layout:fixed;">
- <thead>
- <tr>
- <th style="width:60px">#</th>
- <th>wiadomość</th>
- <th style="width:130px">data</th>
- </tr>
- </thead>
- <tbody>
- <?php if ($msgsTotal <= 0) : ?>
- <tr>
- <td colspan="3"><em class="text-muted" style="padding-left:60px;">Brak wiadomości</em></td>
- </tr>
- <?php else : ?>
- <?php $i = 0; foreach ($msgsList as $idMsg => $msg) : $i++; if ($i > $listLimit) break; $lastMsgId = $idMsg; ?>
- <?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 {
- $msgLink = null;
- }
- if ($msgLink) {
- $jsOnClick = "window.location.href='{$msgLink}'";
- $onClick = 'onclick="' . $jsOnClick . '"';
- }
- ?>
- <tr <?php echo $onClick; ?>
- class="tblMsgsListItem <?php echo ($msg['_read'])? 'active' : ''; ?>">
- <td><?php echo $msg['_raw']->ID; ?></td>
- <td>
- <div style="overflow:hidden; white-space:nowrap; text-overflow:ellipsis;"><?php echo htmlspecialchars($msg['message']); ?></div>
- <div class="text-muted" style="font-style:italic;">
- od <?php echo $msg['_raw']->A_RECORD_CREATE_AUTHOR; ?> do <?php
- if ('everyone' == $msg['_raw']->userTargetType) {
- echo "wszystkich";
- } else if ('user' == $msg['_raw']->userTargetType) {
- echo "{$msg['_raw']->userTargetName}";
- } else if ('group' == $msg['_raw']->userTargetType) {
- echo "grupy {$msg['_raw']->userTargetName}";
- }
- ?>
- </div>
- </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 else : ?>
- <div class="text-muted" style="font-style:italic" title="Wiadomość nie została jeszcze odczytana">nieodczytana</div>
- <?php endif; ?>
- </td>
- </tr>
- <?php endforeach; ?>
- <?php endif; ?>
- </tbody>
- <tfoot>
- <?php if ($msgsTotal > $listLimit) : ?>
- <tr class="active">
- <td colspan="3" style="text-align:center">
- <button class="btn btn-link"
- data-last_msg_id="<?php echo $lastMsgId; ?>"
- data-list_type="<?php echo $listType; ?>"
- onclick="return tblMsgsLoadMoreRows(this);">pobierz starsze wiadomości ...</button>
- </td>
- </tr>
- <?php endif; ?>
- </tfoot>
- </table>
- <?php
- }
- public function getMsgs($filterType, $tableName, $idRow, $lastMsgId = null) {
- $lastMsgId = (int)$lastMsgId;
- $msgsRoute = Router::getRoute('Msgs');
- $msgsList = array();
- if (empty($tableName)) throw new Exception("No table name!");
- $sqlWhereAddFilter = "";
- $usrLogin = User::getLogin();
- $userGroupIds = User::getGroupsIds();
- $sqlFilerMsgsForUser = "
- m.`userTargetType` in('everyone')
- or (m.`userTargetType`='user' and m.`userTargetName`='{$usrLogin}')
- or (m.`userTargetType`='group' and m.`userTargetName` in(" . implode(",", $userGroupIds) . "))
- ";
- switch ($filterType) {
- case 'inbox':
- $sqlWhereAddFilter = "
- and ({$sqlFilerMsgsForUser})
- 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 ({$sqlFilerMsgsForUser})
- )
- and m.`A_STATUS` in('DELETED')
- ";
- break;
- default: throw new Exception("Unknown filter type");
- }
- $db = DB::getDB();
- $tableName = $db->_($tableName);
- if ($lastMsgId > 0) {
- $sqlWhereAddFilter .= "\n and m.`ID`<{$lastMsgId}";
- }
- $sqlLimit = $this->_listLimit + 1;
- $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 {$sqlLimit}
- ";
- //DBG::_('DBG_MSGS', '>1', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
- $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;
- }
- public function _validate($args) {
- $toType = V::get('to_type', '', $args);
- $to = V::get('to', '', $args);
- $msg = V::get('msg', '', $args);
- if (!in_array($toType, array('everyone', 'user', 'group'))) {
- throw new Exception("Niedozwolony typ odbiorcy");
- }
- if (empty($to) && 'everyone' != $toType) {
- throw new Exception("Proszę podać odbiorcę wiadomości");
- }
- if (empty($msg)) {
- throw new Exception("Proszę podać treść wiadomości");
- }
- }
- public function _create($args, $tableName, $idRow) {
- $toType = V::get('to_type', '', $args);
- $to = V::get('to', '', $args);
- $msg = V::get('msg', '', $args);
- $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()));
- $item = array();
- $item['`uiTargetType`'] = "'default_db_table_record'";
- $item['`uiTargetName`'] = "'{$tableName}.{$idRow}'";
- $item['`userTargetType`'] = "'{$toType}'";
- $item['`userTargetName`'] = "'{$to}'";
- $item['`msg`'] = "'" . $db->_($msg) . "'";
- $item['`A_RECORD_CREATE_DATE`'] = "NOW()";
- $item['`A_RECORD_CREATE_AUTHOR`'] = "'{$usrLogin}'";
- $item['`A_STATUS`'] = "'WAITING'";
- $item['`app_className`'] = "'TableMsgs'";
- $sql = "insert into `CRM_UI_MSGS` (" . implode(",", array_keys($item)) . ")
- values (" . implode(",", array_values($item)) . ")
- ";
- $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()));
- $createdId = $db->insert_id();
- if ($createdId <= 0) throw new Exception("Nie udało się zapisać wiadomości.");
- return $createdId;
- }
- public function _printMsgForm($args) {
- $toType = V::get('to_type', '', $args);
- $to = V::get('to', '', $args);
- $msg = V::get('msg', '', $args);
- $listTo = array();
- $listTo['everyone'] = 'Wszyscy';
- $listTo['user'] = 'Użytkownik';
- $listTo['group'] = 'Grupa';
- $toType = (array_key_exists($toType, $listTo))? $toType : 'everyone';
- $typeSpecialGroupId = TypespecialVariable::getInstance(-1, '__ZASOB');
- $typeSpecialUserLogin = TypespecialVariable::getInstance(-1, '__USER_LOGIN');
- $selectedLogin = ('user' == $toType)? $to : '';
- $selectedGroupId = ('group' == $toType)? $to : '';
- ?>
- <form class="form-horizontal" action="" method="post">
- <div class="form-group">
- <label class="col-sm-2 control-label" for="to">Do:</label>
- <div class="col-sm-3">
- <select name="to_type" class="form-control" onChange="return selectTblMsgsToType(this);">
- <?php foreach ($listTo as $type => $typeLabel) : ?>
- <option <?php echo ($type == $toType)? 'selected' : ''; ?>
- value="<?php echo $type; ?>"><?php echo $typeLabel; ?></option>
- <?php endforeach; ?>
- </select>
- </div>
- <div class="col-sm-7">
- <div id="tblMsgsTo-everyone" style="<?php echo ('everyone' == $toType)? '' : 'display:none'; ?>">
- <input name="to-everyone" type="text" class="form-control" disabled>
- </div>
- <div id="tblMsgsTo-group" style="<?php echo ('group' == $toType)? '' : 'display:none'; ?>">
- <?php if ($typeSpecialGroupId) : ?>
- <?php
- $fldName = 'to-group';
- $fldParams = array();
- $fldParams['allowCreate'] = false;
- $fldParams['ajaxDataUrlBase'] = "index.php?_route=TableMsgs&_task=typeSpecialGroupId";
- $fldParams['placeholder'] = 'Grupa...';
- //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
- echo $typeSpecialUserLogin->showFormItem($tblID = -1, $fldName, $selectedGroupId, $fldParams);
- ?>
- <?php else : ?>
- <input name="to-group" type="text" class="form-control" placeholder="Grupa">
- <?php endif; ?>
- </div>
- <div id="tblMsgsTo-user" style="<?php echo ('user' == $toType)? '' : 'display:none'; ?>">
- <?php if ($typeSpecialUserLogin) : ?>
- <?php
- $fldName = 'to-user';
- $fldParams = array();
- $fldParams['allowCreate'] = false;
- $fldParams['ajaxDataUrlBase'] = "index.php?_route=TableMsgs&_task=typeSpecialUserLogin";
- $fldParams['placeholder'] = 'Użytkownik...';
- //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
- echo $typeSpecialUserLogin->showFormItem($tblID = -1, $fldName, $selectedLogin, $fldParams);
- ?>
- <?php else : ?>
- <input name="to-user" type="text" class="form-control" placeholder="Użytkownik">
- <?php endif; ?>
- </div>
- </div>
- </div>
- <div class="form-group">
- <label for="to" class="col-sm-2 control-label">Wiadomość:</label>
- <div class="col-sm-10">
- <textarea name="msg" class="form-control"><?php echo htmlspecialchars($msg); ?></textarea>
- </div>
- </div>
- <div class="form-group">
- <div class="col-sm-10 col-sm-offset-2">
- <input class="btn btn-primary" type="submit" value="Wyślij">
- </div>
- </div>
- </form>
- <script>
- function selectTblMsgsToType(n) {
- var toTypes = <?php echo json_encode(array_keys($listTo)); ?>,
- selectedType = n.value
- ;
- if (-1 !== toTypes.indexOf(n.value)) {
- toTypes.forEach(function(type) {
- if (type == selectedType) {
- document.getElementById('tblMsgsTo-' + type).style.display = 'block';
- } else {
- document.getElementById('tblMsgsTo-' + type).style.display = 'none';
- }
- });
- }
- }
- </script>
- <?php
- }
- 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 typeSpecialGroupIdAction() {
- header("Content-type: application/json");
- Lib::loadClass('TypespecialVariable');
- $typeSpecialZasob = TypespecialVariable::getInstance(-1, '__ZASOB');
- if (!$typeSpecialZasob) {
- $jsonData = new stdClass();
- $jsonData->message = "TypeSpecial '__ZASOB' not exists";
- echo json_encode($jsonData);
- exit;
- }
- $query = V::get('q', '', $_REQUEST);
- $rawRows = null;
- $jsonData = array();
- $queryParams = array();
- $queryParams['zasob_type_in'] = array('STANOWISKO', 'PODMIOT', 'DZIAL');
- $rows = $typeSpecialZasob->getValuesWithExports($query, $queryParams);
- DBG::_('DBG_TS', '>1', "rows({$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
- 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 readAction() {
- $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->_markAsRead($msg);
- $this->viewMsg($msg);
- } catch (Exception $e) {
- SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
- }
- SE_Layout::dol();
- }
- public function viewAction() {
- $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->viewMsg($msg);
- } catch (Exception $e) {
- SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine());
- }
- SE_Layout::dol();
- }
- public function _getMsg($idMsg, $idTable, $idRow) {
- $msgsRoute = Router::getRoute('Msgs');
- $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);
- // $msg['_raw']->uiTargetType => default_db_table_record
- // $msg['_raw']->uiTargetName => TEST_PERMS.31
- if ('default_db_table_record' !== $msg['_raw']->uiTargetType) {
- throw new Exception("Parse message target type error!");
- }
- $parts = explode('.', $msg['_raw']->uiTargetName);
- if (2 !== count($parts)) throw new Exception("Parse message target type error!");
- $msg['tblName'] = $parts[0];
- 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;
- }
- public function _markAsRead($msg) {
- if ($msg['_read']) return;
- $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()));
- $sql = "update `CRM_UI_MSGS`
- set `A_STATUS`='NORMAL'
- , `A_RECORD_UPDATE_AUTHOR`='{$usrLogin}'
- , `A_RECORD_UPDATE_DATE`=NOW()
- , `actionExecutedTime`=NOW()
- where `ID`='{$msg['_raw']->ID}'
- and `A_STATUS`='WAITING'
- and `A_RECORD_UPDATE_AUTHOR`=''
- and `A_RECORD_UPDATE_DATE` is null
- and (
- ('{$usrLogin}'!=`A_RECORD_CREATE_AUTHOR`)
- or ('{$usrLogin}'=`A_RECORD_CREATE_AUTHOR`
- and 'user'=`userTargetType`
- and '{$usrLogin}'=`userTargetName`
- )
- )
- ";
- $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()));
- }
- public function viewMsg($msg) {
- $usrLogin = User::getLogin();
- $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={$idTable}&idRow={$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="<?php echo $backLink; ?>">Wiadomości powiązane z rekordem nr <?php echo $idRow; ?></a>
- » 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>
- <?php $userMsgsRoute->printWidgetViewMsg($msg); ?>
- <?php
- }
- 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);
- $msgsRoute = Router::getRoute('Msgs');
- $msgsRoute->removeTableRecordMsg($idMsg);
- } 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 class="btn btn-xs btn-default" href="index.php?_route=TableMsgs&_task=tableRow&idTable=<?php echo $idTable; ?>&idRow=<?php echo $idRow; ?>">wróć</a>
- </div>
- </div>
- <?php
- SE_Layout::dol();
- }
- }
|