menu(); SE_Layout::dol(); } public function menu() { $usrLogin = User::getLogin(); ?> 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); ?>

Wiadomości powiązane z rekordem nr
z tabeli getLabel(); ?>

0) : ?>
_printTableMsgsList('inbox', $msgsList, $idTable, $idRow); ?>
_printTableMsgsList('sent', $sentMsgsList, $idTable, $idRow); ?>
_printTableMsgsList('removed', $removedMsgsList, $idTable, $idRow); ?>
Wyślij nową wiadomość
_printMsgForm($args); ?>
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'; ?> $msg) : $i++; if ($i > $listLimit) break; $lastMsgId = $idMsg; ?> 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 . '"'; } ?> class="tblMsgsListItem "> $listLimit) : ?>
# wiadomość data
Brak wiadomości
ID; ?>
od A_RECORD_CREATE_AUTHOR; ?> do userTargetType) { echo "wszystkich"; } else if ('user' == $msg['_raw']->userTargetType) { echo "{$msg['_raw']->userTargetName}"; } else if ('group' == $msg['_raw']->userTargetType) { echo "grupy {$msg['_raw']->userTargetName}"; } ?>
A_RECORD_CREATE_DATE; ?>
nieodczytana
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"); } $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} "; $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
", $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
", $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 : ''; ?>
showFormItem($tblID = -1, $fldName, $selectedGroupId, $fldParams); ?>
showFormItem($tblID = -1, $fldName, $selectedLogin, $fldParams); ?>
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->tableRowMsg($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->tableRowMsg($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
", $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}' "; $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
", $db->get_errors())); } public function tableRowMsg($msg) { $idTable = $msg['idTable']; $idRow = $msg['idRow']; $usrAcl = User::getAcl(); $tblAcl = $usrAcl->getTableAcl($idTable); $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"; ?>

Wiadomości powiązane z rekordem nr » Wiadomość nr ID; ?>
z tabeli Test permy

Wiadomość wysłana przez A_RECORD_CREATE_AUTHOR; ?> A_RECORD_CREATE_DATE; ?>

_getMsg($idMsg, $idTable, $idRow); $this->_removeRowMsg($msg); } catch (Exception $e) { SE_Layout::alert('danger', $e->getMessage() . ' #' . $e->getLine()); SE_Layout::dol(); exit; } ?>
Wiadomość została usunięta - wróć
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
", $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
", $db->get_errors())); } }