_tbl = $tblAcl->getName();
$this->_acl = $tblAcl;
$this->_zasobID = $tblAcl->getID();
$this->_pageSize = 10;
{
UserProfile::load();
$tableAjaxSettings = UserProfile::getTableAjaxSettings();
$this->_pageSize = V::get('pageSize', 10, $tableAjaxSettings, 'int');
}
$this->_pageSizes = array(10, 20, 50, 100);// default page sizes
$this->_filterInit = new stdClass();
$hash = V::get('_hash', '', $_GET);
if ($hash) {
$this->_htmlID = $hash;
$this->_readState();
} else {
$this->_htmlID = $this->generateHtmlID();
$this->_readState();
}
}
public function showProcesInit($bool = true) {
$this->_showProcesInit = $bool;
}
private function _hasStateFilterInit() {
return array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache']) && array_key_exists('_filterInit', $_SESSION['TableAjax_Cache'][$this->_htmlID]);
}
// TODO: read state from cache by key $this->_htmlID
// TODO: load filters and state: table, edit, add, etc.
// TODO: save this data in Workspace 1, 2, 3, etc.
// TODO: default filters in VIEWTABLE_AJAX
// $tbl->setLabel($zasobObj->OPIS);
// $tbl->setFilterInit($filterInit);
// $tbl->addRowFunction('edit');
// $tbl->addRowFunction('hist');
// $tbl->addRowFunction('files');
// $tbl->addRowFunction('cp');
private function _readState() {
if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
$_SESSION['TableAjax_Cache'] = array();
}
//trigger_error("F." . __FUNCTION__ . " (" . (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) . ")", E_USER_NOTICE);
//trigger_error("F." . __FUNCTION__ . " (".basename($_SERVER['SCRIPT_FILENAME'])."::_filterInit: " . json_encode($_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit']) . ")", E_USER_NOTICE);
if (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
foreach ($_SESSION['TableAjax_Cache'][$this->_htmlID] as $k => $v) {
//trigger_error("F." . __FUNCTION__ . " key: ({$k})", E_USER_NOTICE);
switch ($k) {
case '_label':
$this->_label = $v;
break;
case '_filterInit':
$this->_filterInit = $v;
break;
case '_rowFunctions':
$this->_rowFunctions = $v;
break;
default:
}
}
}
}
protected function _saveState($key = null) {
if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
$_SESSION['TableAjax_Cache'] = array();
}
if (!array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
$_SESSION['TableAjax_Cache'][$this->_htmlID] = array();
}
if (!$key) {
$_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
$_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
$_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
} else if ($key == '_label') {
$_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
} else if ($key == '_filterInit') {
$_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
} else if ($key == '_rowFunctions') {
$_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
}
}
public function setPageSizes($pageSizes) {
$this->_pageSizes = $pageSizes;
}
public function setFilterInit($filterInit) {
if ($this->_hasStateFilterInit()) {
return;
}
$this->_filterInit = (object)$filterInit;
$this->_saveState();
}
/**
* @param array $forceFilterInit
*/
public function setForceFilterInit($forceFilterInit) {
$this->_forceFilterInit = (object)$forceFilterInit;
}
private function setFilters($filterInit) {
$this->_filterInit = (object)$filterInit;
$this->_saveState();
}
public function addRowFunction($funName, $funParams = array()) {
$defaultRowFunction = array();
//$defaultRowFunction['edit'] = '';
//$defaultRowFunction['hist'] = '';
//$defaultRowFunction['files'] = '';
//$defaultRowFunction['cp'] = '';
$defaultRowFunction['edit'] = array('href'=>'#EDIT/{0}', 'ico'=>'glyphicon glyphicon-pencil', 'title'=>'Edytuj rekord');
$defaultRowFunction['hist'] = array('href'=>'#HIST/{0}', 'ico'=>'glyphicon glyphicon-book', 'title'=>'Historia');
$defaultRowFunction['files'] = array('href'=>'#FILES/{0}', 'ico'=>'glyphicon glyphicon-folder-open', 'title'=>'Pliki');
$defaultRowFunction['cp'] = array('href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
$defaultRowFunction['msgs'] = array('href'=>"index.php?_route=TableMsgs&_task=tableRow&idTable={$this->_zasobID}&idRow={0}", 'ico'=>'glyphicon glyphicon-envelope', 'title'=>'Wiadomości');
if (array_key_exists($funName, $defaultRowFunction)) {
$this->_rowFunctions[$funName] = $defaultRowFunction[$funName];
}
else {
$this->_rowFunctions[$funName] = $funParams;
}
$this->_saveState('_rowFunctions');
}
private function _parseRowFunctions($recordID = null, $pomin = array(), $showLabel = false) {
$rowFunctions = array();
foreach ($this->_rowFunctions as $kFunName => $vParams) {
if (in_array($kFunName, $pomin)) continue;
//$rowFunctionsOut .= str_replace('{0}', $recordID, $vUrl);
$attrs = array();
// $defaultRowFunction['cp'] = (object)array('href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
$label = '';
$ico = '';
foreach ($vParams as $kParamName => $v) {
if ($kParamName == 'ico') {
$ico = '';
continue;
}
$attr = $v;
if ($recordID > 0) {
$attr = str_replace('{0}', $recordID, $attr);
}
if ($showLabel && $kParamName == 'title') {
$label = $attr;
}
$attr = $kParamName . '="' . $attr . '"';
$attrs[] = $attr;
}
$rowFunctions[$kFunName] = '' . "{$ico} {$label} " . '';
}
return $rowFunctions;
}
private function _showRowFunctions($recordID = null, $pomin = array(), $showLabel = false) {
$rowFunctionsOut = $this->_parseRowFunctions($recordID, $pomin, $showLabel);
$rowFunctionsOut = implode('', $rowFunctionsOut);
return $rowFunctionsOut;
}
private function _showRowFunctionsJson($recordID = null, $pomin = array(), $showLabel = false) {
$rowFunctions = $this->_parseRowFunctions($recordID, $pomin, $showLabel);
$rowFunctions = (object)$rowFunctions;
return $rowFunctions;
}
private function _showExportFieldsJson() {
$exportFields = $this->_acl->getExportFieldList();
return $exportFields;
}
private function getProcesInitSelected() {
$userAcl = User::getAcl();
return $userAcl->getPermsFiltrProcesId();
}
public function allowTreeView() {
if ($this->_tbl == 'CRM_LISTA_ZASOBOW') return true;
if ($this->_tbl == 'CRM_PROCES') return true;
return false;
}
public function hasGeomFields() {
$hasGeomFields = false;
$fieldsList = $this->_acl->getFields();
foreach ($fieldsList as $kID => $vCol) {
if ($this->_acl->isGeomField($vCol['name'])) {
if ($this->_acl->hasFieldPerm($kID, 'R')) {
$hasGeomFields = true;
break;
}
}
}
return $hasGeomFields;
}
public function render() {
$hasGeomFlds = $this->hasGeomFields();
$tblAjaxMap = null;
if ($hasGeomFlds) {
$tblAjaxMap = new TableAjaxMap($this->_acl, 512, 400);
}
$hasPermCreate = $this->_acl->hasCreatePerms();
$jsToogleFiltrProcesuFunctionName = 'tableAjaxToggleFiltrProcesInit';
ob_start();
?>
_tbl); ?>
printCSS(); ?>
printJS(); ?>
_filterInit;
$forceFilterInit = $this->_forceFilterInit;
$pageSizes = $this->_pageSizes;
$pageSize = $this->_pageSize;
$rowFunctions = $this->_rowFunctions;//$this->_showRowFunctionsJson();
$exportFields = $this->_showExportFieldsJson();
?>
">
">
">
_zasobID);
return !empty($layers);
}
public function ajaxTask($task) {
switch ($task) {
case 'EDIT': {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxEdit($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'EDIT_SAVE': {
$this->sendAjaxResponseJson('ajaxEditSave', $_REQUEST);
break;
}
case 'EDIT_INLINE': {
$this->sendAjaxResponseJson('ajaxInlineEdit', $_REQUEST);
break;
}
case 'EDIT_INLINE_SAVE': {
$this->sendAjaxResponseJson('ajaxEditInlineSave', $_REQUEST);
break;
}
case 'COPY': {
$this->sendAjaxResponseJson('ajaxCopy', $_REQUEST);
break;
}
case 'CREATE': {
$this->sendAjaxCreate($_REQUEST);
break;
}
case 'CREATE_SAVE': {
$this->sendAjaxResponseJson('ajaxCreateSave', $_REQUEST);
break;
}
case 'HIST': {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxHistory($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'FILES': {
try {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id <= 0) throw new HttpException("404", 404);
$this->sendAjaxFiles($id, $_REQUEST);
} catch (HttpException $e) {
Http::sendHeaderByCode($e->getCode());
echo $e->getMessage();
//SE_Layout::alert('danger', $e->getMessage());
} catch (Exception $e) {
echo '';
SE_Layout::alert('danger', $e->getMessage());
echo '
';
}
break;
}
case 'FILES_UPLOAD': {
$this->sendAjaxResponseJson('ajaxFileUpload', $_REQUEST);
break;
}
case 'FILES_LIST': {
$this->sendAjaxResponseJson('ajaxFileList', $_REQUEST);
break;
}
case 'FILE_REMOVE': {
$args = array();
$args['ID'] = V::get('ID', '', $_REQUEST);
$args['filename'] = V::get('filename', '', $_POST);
$this->sendAjaxResponseJson('ajaxFileRemove', $args);
break;
}
case 'filePermsRefresh': {
$this->sendAjaxResponseJson('ajaxFilePermsRefresh', $_REQUEST);
break;
}
case 'FILES_CONN_TBL_LIST': {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxFilesConnTblList($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'TYPESPECIAL': {
$fldID = V::get('fldID', 0, $_REQUEST, 'int');
if ($fldID > 0) {
$this->sendTypeSpecial($fldID, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'TYPESPECIALL_CELL': {
$id = V::get('ID', 0, $_REQUEST, 'int');
$col = V::get('col', '', $_REQUEST);
if ($id > 0 && !empty($col)) {
$this->sendTypeSpecialCell($id, $col, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'MORE_FUNCTIONS_CELL': {
$this->sendAjaxResponseJson('ajaxMoreFunctionsCell', $_REQUEST);
break;
}
case 'HIDDEN_COLS_SAVE': {
$this->sendAjaxResponseJson('ajaxHiddenColsSave', $_POST);
break;
}
case 'PAGE_SIZE_SAVE': {
$this->sendAjaxResponseJson('ajaxPageSizeSave', $_POST);
break;
}
case 'THE_GEOM_SAVE': {
$this->sendAjaxResponseJson('ajaxTheGeomSave', $_REQUEST);
break;
}
case 'THE_GEOM_REMOVE': {
$this->sendAjaxResponseJson('ajaxTheGeomRemove', $_REQUEST);
break;
}
case 'PROCES_INIT_FILTR': {
$this->sendAjaxResponseJson('ajaxProcesInitFiltr', $_REQUEST);
break;
}
default:
$this->sendAjaxResponseJson('ajaxData', $_REQUEST);
}
}
/**
* ajax url: &_task=EDIT_INLINE
* @param $rowID - $_GET['ID']
* @param $fieldName - $_GET['col']
*/
private function ajaxInlineEdit() {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
$args = $_REQUEST;
$rowID = V::get('ID', 0, $_REQUEST, 'int');
$fieldName = V::get('col', '', $_REQUEST);
if ($rowID <= 0 || empty($fieldName)) throw new HttpException("404", 404);
$response = array();
ob_start();
$fieldID = $this->_acl->getFieldIdByName($fieldName);
if (!$fieldID) {
echo "404: No field by name ({$fieldName})";
exit;
}
$response['idZasob'] = $fieldID;
$response['htmlFieldName'] = "f{$fieldID}";
if ($DBG) echo "fieldID: {$fieldID}\n";
$row = $this->_acl->getItem($rowID);
if (!$row) {
echo "404: No item ID({$rowID})";
exit;
}
if (!$this->_acl->isAllowed($fieldID, 'R', $row)) {
if ($DBG) echo " R not allowed\n";
} else {
if ($DBG) echo " R allowed\n";
}
if (!$this->_acl->isAllowed($fieldID, 'W', $row)) {
if ($DBG) echo " W not allowed\n";
} else {
if ($DBG) echo " W allowed\n";
}
$fieldVal = '';
if ($this->_acl->isAllowed($fieldID, 'R', $row)) {
$fieldVal = V::get($fieldName, $fieldVal, $row);
} else {
$fieldVal = '*****';
}
$fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
$vCol = $this->_acl->getField($fieldID);
$vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
$response['fieldLabel'] = $vCol['label'];
$tsValues = array();
$typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
if ($typeSpecial) {
if($DBG){echo'Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'';}
$specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
if($DBG){echo'Typespecial('.$fieldID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'';}
if (!empty($specialValues)) {
$tsValues[$row->ID] = implode('
', $specialValues);
}
}
$fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
if (!empty($tsValues[$row->ID])) $fieldParams['typespecialValue'] = $tsValues[$row->ID];
if (!empty($tsValues[$row->ID])) $response['typespecialValue'] = $tsValues[$row->ID];
$vDefault = $this->_acl->getColDefault($fieldName);
if (!empty($vDefault)) $fieldParams['default'] = $vDefault;
if (!empty($vDefault)) $response['defaultValue'] = $vDefault;
{
try {
$item = $this->_acl->getFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
$response['formItem'] = $item;
if (!empty($item['rawColType']['simpleType'])) $response['simpleType'] = $item['rawColType']['simpleType'];
if (!empty($item['rawColType']['restrictions'])) $response['restrictions'] = $item['rawColType']['restrictions'];
echo '';
DBG::_(true, true, "item", $item, __CLASS__, __FUNCTION__, __LINE__);
echo '
';
} catch (Exception $e) {
echo '';
SE_Layout::alert('danger', $e->getMessage());
echo '
';
}
}
?>
_acl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
if ($typeSpecial
|| $this->_acl->isDateField($fieldName)
|| $this->_acl->isDateTimeField($fieldName)
) {
echo '';
}
$response['legacy_html'] = ob_get_clean();
//$response['legacy_html'] = utf8_encode($response['legacy_html']);// pl chars bug
return $response;
}
private function ajaxEditInlineSave($args) {
$primaryKeyField = $this->_acl->getPrimaryKeyField();
$primaryKey = V::get($primaryKeyField, 0, $args, 'int');
$fieldName = V::get('col', '', $_REQUEST);
if (empty($primaryKey) || empty($fieldName)) {
throw new HttpException("Wrong param id or col!", 400);
}
$fieldID = $this->_acl->getFieldIdByName($fieldName);
if (!$fieldID) {
throw new HttpException("Field not exists!", 404);
}
$item = $this->_acl->getItem($primaryKey);
if (!$item) {
throw new HttpException("Item not exists!", 404);
}
$itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
if (!isset($itemFromUser[$fieldName])) {
throw new HttpException("Field not set!", 400);
}
$itemPatch = array();
$itemPatch[$fieldName] = V::get($fieldName, null, $itemFromUser);
$itemPatch[$primaryKeyField] = $primaryKey;
$response = new stdClass();
try {
$affected = $this->_acl->updateItem($itemPatch);
if ($affected > 0) {
$response->type = 'success';
$response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
} else if ($affected == 0) {
$response->type = 'info';
$response->msg = "Nie wprowadzono żadnych zmian";
}
$response->record = $this->_acl->getItem($primaryKey);
}
catch (Exception $e) {
$response->type = 'error';
$response->msg = $e->getMessage();
}
return $response;
}
private function sendAjaxEdit($id, $args) {
header("Content-type: text/plain");
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
$cols = array();
$record = $this->_acl->getItem($id);
if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
echo '';
echo "Brak dostępu do rekordu";// TODO: more info - reason
echo '
';
return;
}
$fieldsList = $this->_acl->getFields();
foreach ($fieldsList as $kID => $vCol) {
if ($vCol['name'] == 'ID') {
unset($fieldsList[$kID]);
continue;
}
$cols[$kID] = '';
if ($this->_acl->isAllowed($kID, 'R', $record)) {
$cols[$kID] = V::get($vCol['name'], '', $record);
} else {
$cols[$kID] = '*****';
}
$cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
$fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : str_replace('_', ' ', $vCol['name']);
}
$tsValues = array();
if($DBG){echo'fieldsList (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fieldsList);echo'
';}
if (!empty($fieldsList)) {
foreach ($fieldsList as $vColID => $vCol) {
$typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
if ($typeSpecial) {
if($DBG){echo'Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'';}
$colValue = V::get($vCol['name'], '', $record);
if($DBG){echo'V::get('.$vCol['name'].', "", $record) (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colValue);echo'';}
$specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $record->ID, $vCol['name'], $colValue);
if($DBG){echo'Typespecial('.$vColID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'';}
if (!empty($specialValues)) {
$tsValues[$vColID] = implode('
', $specialValues);
}
}
}
}
if($DBG){echo'tsValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($tsValues);echo'';}
$rowFunctionsOut = $this->_showRowFunctions($record->ID, array('edit', 'cp'), true);
?>
_acl->getPrimaryKeyField();
$primaryKey = V::get($primaryKeyField, 0, $args, 'int');
if (empty($primaryKey)) {
throw new HttpException("Wrong param id!", 400);
}
$item = $this->_acl->getItem($primaryKey);
if (!$item) {
throw new HttpException("Item not exists!", 404);
}
$itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
$response = new stdClass();
try {
$itemFromUser[$primaryKeyField] = $primaryKey;
$affected = $this->_acl->updateItem($itemFromUser);
if ($affected > 0) {
$response->type = 'success';
$response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
} else if ($affected == 0) {
$response->type = 'info';
$response->msg = "Nie wprowadzono żadnych zmian";
}
$response->record = $this->_acl->getItem($primaryKey);
}
catch (Exception $e) {
$response->type = 'error';
$response->msg = "Wystąpiły błędy!";
$response->msg .= $e->getMessage();
}
return $response;
}
private function sendAjaxCreate($args) {
header("Content-type: text/plain");
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
if (!$this->_acl->hasCreatePerms()) {
?>
Brak uprawnień do utworzenia nowego rekordu.
$v) {
if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
$fldName = substr($k, 3);
$forceFilterInit[$fldName] = $v;
}
}
$fieldsList = $this->_acl->getFields();
foreach ($fieldsList as $kID => $vCol) {
$defaultValue = '';
if ($vCol['name'] == 'ID') {
unset($fieldsList[$kID]);
continue;
}
if (!empty($forceFilterInit[$vCol['name']])) {
$defaultValue = $forceFilterInit[$vCol['name']];
}
// TODO: read from session cache
$cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
$fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
}
?>
_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
$createdId = $this->_acl->addItem($item);
if ($createdId) {
$response->type = 'success';
$response->msg = "Utworzono pomyślnie rekord nr {$createdId}";
$response->id = $createdId;
$response->record = $this->_acl->getItem($createdId);
}
else {
$response->type = 'error';
$response->msg = "Nie udało się utworzyć nowego rekordu!";
}
}
catch (Exception $e) {
$response->type = 'error';
$response->msg = "Wystąpiły błędy!";
$response->msg = $e->getMessage();
}
return $response;
}
private function ajaxCopy($args) {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id <= 0) {
throw new HttpException("Wrong param ID!", 404);
}
$item = $this->_acl->getItem($id);
if (!$item) {
throw new HttpException("Item '{$id}' not exists!", 404);
}
$response = new stdClass();
$itemCopy = $this->_acl->createItemCopy($item);
$createdId = null;
try {
$createdId = $this->_acl->addItem($itemCopy);
if ($createdId) {
$response->type = 'success';
$response->msg = "Rekord skopiowany pomyślnie - utworzono rekord nr {$createdId}";
$response->id = $createdId;
$response->record = $this->_acl->getItem($createdId);
}
else {
$response->type = 'error';
$response->msg = "Nie udało się skopiować rekordu!";
}
}
catch (Exception $e) {
$response->type = 'error';
$response->msg = "Wystąpiły błędy!";
$response->msg = $e->getMessage();
}
return $response;
}
private function sendAjaxHistory($id, $args) {
header("Content-type: text/plain");
$record = $this->_acl->getItem($id);
if (!$record) {
header('HTTP/1.0 404 Not Found');
echo "404: No item ID({$rowID})";
exit;
}
$visibleCols = $this->_acl->getRealFieldList();
$rowsHist = $this->_acl->getHistItems($id);
$rowFunctionsOut = $this->_showRowFunctions($record->ID, array('hist', 'cp'), true);
$visibleColsWithIds = array();
$visibleColsLabels = array();
foreach ($visibleCols as $vColName) {
$fldId = $this->_acl->getFieldIdByName($vColName);
if ($fldId) {
$visibleColsWithIds[$fldId] = $vColName;
$label = $this->_acl->getFieldLabel($fldId);
$label = (!$label)? $vColName : '' . $label . '';
$visibleColsLabels[$fldId] = $label;
}
}
?>
Brak danych
| Data |
User |
Zmiany |
| _created; ?> |
_author; ?> |
$colName) : ?>
$colName == 'N/S;') continue; ?>
:
_acl->isAllowed($fldId, 'R', $record)) : ?>
$colName; ?>
*****
|
$colName) : ?>
|
$colName) : ?>
|
$colName == 'N/S;') : ?>
N/S;
_acl->isAllowed($fldId, 'R', $record)) : ?>
$colName; ?>
*****
|
_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) throw new HttpException("No DB ({$dbID})", 406);
$record = $this->_acl->getItem($id);
if (!$record) throw new HttpException("No item ID({$rowID})", 404);
if (!$this->_acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
if (!$this->_acl->canWriteRecord($record)) throw new Exception("Brak uprawnień do zapisu");
$tblName = $this->_acl->getName();
$confTblName = "{$tblName}_COLUMN";
$folderConfAll = FoldersConfig::getRawData();
if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$tblName})", 404);
$folderConf = FoldersConfig::getAll($confTblName);
$uploader = new FileUploader($confTblName, $record);
if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})", 404);
$uploader->findFolder();
$errorMsg = '';
if (!empty($args['SCANS_COLUMN_ADD'])) {
$uploaded = $uploader->tryMoveFromScanAjax($errorMsg);
}
else {
$uploaded = $uploader->tryUploadAjax($errorMsg);
}
$retJson = new stdClass();
if (!$uploaded) throw new Exception($errorMsg);
$uploadedFileName = '';
$uploadedFile = $uploader->getLastUploadedFile();
if ($uploadedFile) {
$uploadedFileName = explode('/', $uploadedFile);
$uploadedFileName = end($uploadedFileName);
}
//echo '{"type":"SUCCESS", "string": "Plik został poprawnie wgrany do odpowiedniego katalogu '.$uploadedFileName.'"}';
$retJson->type = 'SUCCESS';
$retJson->msg = "Plik został poprawnie wgrany do odpowiedniego katalogu {$uploadedFileName}";
if (!empty($uploadedFileName)) {
$sqlObj = new stdClass();
$sqlObj->ID = $record->ID;
$sqlObj->M_DIST_FILES = "Wgrano plik {$uploadedFileName}";
$db->UPDATE_OBJ($this->_tbl, $sqlObj);
}
return $retJson;
}
public function ajaxFileRemove($args) {
$id = V::get('ID', 0, $args, 'int');
if ($id <= 0) throw new HttpException("404", 404);
$filename = V::get('filename', '', $args);
if (empty($filename)) throw new Exception("Nie wybrano pliku do usunięcia");
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) throw new HttpException("No DB ({$dbID})", 406);
$record = $this->_acl->getItem($id);
if (!$record) throw new HttpException("No item ID({$rowID})", 404);
if (!$this->_acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
if (!$this->_acl->canWriteRecord($record)) throw new Exception("Brak uprawnień do zapisu");
$tblName = $this->_acl->getName();
$confTblName = "{$tblName}_COLUMN";
$folderConfAll = FoldersConfig::getRawData();
if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$tblName})", 404);
$folderConf = FoldersConfig::getAll($confTblName);
$uploader = new FileUploader($confTblName, $record);
if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})", 404);
$uploader->findFolder();
$errorMsg = '';
$removed = $uploader->tryRemoveFromAjax($filename, $errorMsg);
if (!$removed) throw new Exception($errorMsg);
$retJson = new stdClass();
$retJson->type = 'SUCCESS';
$retJson->msg = 'Plik został poprawnie usunięty';
return $retJson;
}
public function ajaxFileList($args) {
$id = V::get('ID', 0, $args, 'int');
if ($id <= 0) throw new HttpException("404", 404);
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) throw new HttpException("No DB ({$dbID})", 406);
$record = $this->_acl->getItem($id);
if (!$record) throw new HttpException("No item ID({$rowID})", 404);
if (!$this->_acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
$tblName = $this->_acl->getName();
$confTblName = "{$tblName}_COLUMN";
$folderConfAll = FoldersConfig::getRawData();
if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$tblName})", 404);
$folderConf = FoldersConfig::getAll($confTblName);
$uploader = new FileUploader($confTblName, $record);
if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})", 404);
$uploader->findFolder();
$mainFolder = $uploader->getDestFolder();
$files = $uploader->getFilesFromFolder($mainFolder, false, true);
$localPath = $uploader->getLocalPath();
$folderWeb = $uploader->getFolderWeb();
$jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
return $jsonFiles;
}
private function ajaxFilePermsRefresh($args) {
$id = V::get('ID', 0, $args, 'int');
if ($id <= 0) throw new HttpException("Wrong param ID", 404);
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) throw new HttpException("No DB", 406);
$record = $this->_acl->getItem($id);
if (!$record) throw new Exception("No item ID({$rowID})", 404);
$tblName = $this->_acl->getName();
// TODO: SyncPermsCustomTables->getRecordTask($tbl, $id);
$sql_L_APPOITMENT_USER = V::get('L_APPOITMENT_USER', '', $record);
$sql_A_ADM_COMPANY = V::get('A_ADM_COMPANY', '', $record);
$sql_A_CLASSIFIED = V::get('A_CLASSIFIED', '', $record);
$mainDB = DB::getDB();
if ('IN7_MK_BAZA_DYSTRYBUCJI' == $tblName) {
$sql = "insert into `_SYNC_FILE_PERMS` (
`ID_PROJECT`,
`A_SYNCHRONIZED`
)
values (
'{$record->ID}'
, 0
)
ON DUPLICATE KEY UPDATE
`A_SYNCHRONIZED`=0
";
}
else if ('IN7_DZIENNIK_KORESP' == $tblName) {
$sql = "insert into `_SYNC_FILE_PERMS` (
`ID_PROJECT`,
`A_SYNCHRONIZED`
)
values (
'{$record->ID_PROJECT}'
, 0
)
ON DUPLICATE KEY UPDATE
`A_SYNCHRONIZED`=0
";
}
else {
$sql = "insert into `_SYNC_TABLE_FILE_PERMS` (
`TBL_NAME`,
`TBL_ID`,
`L_APPOITMENT_USER`,
`A_ADM_COMPANY`,
`A_CLASSIFIED`,
`A_SYNCHRONIZED`
)
values (
'{$tblName}'
, '{$id}'
, '{$sql_L_APPOITMENT_USER}'
, '{$sql_A_ADM_COMPANY}'
, '{$sql_A_CLASSIFIED}'
, 0
)
ON DUPLICATE KEY UPDATE
`A_SYNCHRONIZED`=0
";
}
$res = $mainDB->query($sql);
if ($mainDB->has_errors()) {
//echo' (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'';
//echo' (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mainDB->get_errors());echo'';
throw new Exception("Nie udało się dodać zadania");
}
// TODO: this blocks browser ajax query
//$limit = 3;
//while ($limit--) {
// sleep(10);
// TODO: check if task is done
//}
$confTblName = "{$tblName}_COLUMN";
$folderConfAll = FoldersConfig::getRawData();
if (!FoldersConfig::hasConfig($confTblName)) {
throw new Exception("Brak danych konfiguracyjnych ({$tblName})", 404);
}
$folderConf = FoldersConfig::getAll($confTblName);
$uploader = new FileUploader($confTblName, $record);
if (!$uploader->setConfig($folderConf)) {
throw new Exception("Błąd danych konfiguracyjnych ({$tblName})", 404);
}
$uploader->findFolder();
$mainFolder = $uploader->getDestFolder();
$files = $uploader->getFilesFromFolder($mainFolder, false, true);
$localPath = $uploader->getLocalPath();
$folderWeb = $uploader->getFolderWeb();
$jsonData = new stdClass();
$jsonData->msg = 'Zadanie dodane';
$jsonData->type = 'success';
$jsonData->files = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
return $jsonData;
}
private function sendAjaxFilesConnTblList($id, $args) {
header("Content-type: application/json");
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) {
header('HTTP/1.0 406 Not Acceptable');
echo 'No DB (' . $dbID . ')';
exit;
}
$record = $this->_acl->getItem($id);
if (!$record) {
header('HTTP/1.0 404 Not Found');
echo 'No item ID(' . $rowID . ')';
exit;
}
$connTblName = '';
$connTblID = V::get('connTblID', 0, $_REQUEST, 'int');
if ($connTblID <= 0) {
header('HTTP/1.0 406 Not Acceptable');
echo 'No conn Table ID';
exit;
}
$connTblTypespecials = $this->getConnectedTblTypespecials($connTblID);
if (empty($connTblTypespecials)) {
header('HTTP/1.0 406 Not Acceptable');
echo "No conn Table (ID={$connTblID})";
exit;
}
if($DBG){echo'connTblTypespecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($connTblTypespecials);echo'';}
if(1) {
header('HTTP/1.0 404 Not Found');
echo 'TODO: ...';
exit;
}
$tblName = $this->_acl->getName();
$confTblName = "{$tblName}_COLUMN";
$folderConfAll = FoldersConfig::getRawData();
if (!FoldersConfig::hasConfig($confTblName)) {
header('HTTP/1.0 404 Not Found');
echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
exit;
}
$folderConf = FoldersConfig::getAll($confTblName);
$uploader = new FileUploader($confTblName, $record);
if (!$uploader->setConfig($folderConf)) {
header('HTTP/1.0 404 Not Found');
echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
exit;
}
$uploader->findFolder();
$mainFolder = $uploader->getDestFolder();
$files = $uploader->getFilesFromFolder($mainFolder, false, true);
$localPath = $uploader->getLocalPath();
$folderWeb = $uploader->getFolderWeb();
$jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
echo json_encode($jsonFiles);
exit;
}
public function convertFileListToJson($files, $folderWeb, $localPath, $mainFolder) {
$jsonFiles = array();
if (!is_array($files) || empty($files)) {
return $jsonFiles;
}
sort($files);
foreach ($files as $vFilePath) {
$file = new stdClass();
$file->name = str_replace("{$localPath}/{$mainFolder}/", '', $vFilePath);
//$file->name = explode('/', $vFilePath);
//$file->name = end($file->name);
$file->size = filesize($vFilePath);
$file->sizeStr = round($file->size, 2) . "B";
if ($file->size > 1024 * 1024) {
$file->sizeStr = round(($file->size / (1024 * 1024)), 2) . "M";
} else if ($file->size > 1024) {
$file->sizeStr = round(($file->size / 1024), 2) . "K";
}
$file->type = '';
$file->created = date("Y-m-d H:i:s", filectime($vFilePath));
$file->web = str_replace($localPath, $folderWeb, $vFilePath);
$jsonFiles[] = $file;
}
return $jsonFiles;
}
private function getConnectedTables() {
$connTbls = array();
return $connTbls;// TODO: OFF - hardlinki tworzone w bash_sync_perms.php
$fields = $this->_acl->getVisibleFieldList();
if (!empty($fields)) {
foreach ($fields as $vColID => $vCol) {
$typeSpecial = Typespecial::getInstance($vColID);
if ($typeSpecial) {
$tsConnTbls = $typeSpecial->getTblAliasList();
if (!empty($tsConnTbls)) {
foreach ($tsConnTbls as $kID => $vName) {
$connTbls[$kID] = $vName;
}
}
}
}
}
return $connTbls;
}
private function getConnectedTblTypespecials($connTblID) {
$connTblTypespecials = array();
$fields = $this->_acl->getVisibleFieldList();
if (!empty($fields)) {
foreach ($fields as $vColID => $vCol) {
$typeSpecial = Typespecial::getInstance($vColID);
if ($typeSpecial) {
$tsConnTbls = $typeSpecial->getTblAliasList();
if (array_key_exists($connTblID, $tsConnTbls)) {
$connTblTypespecials[] = $typeSpecial;
}
}
}
}
return $connTblTypespecials;
}
private function sendAjaxFiles($id, $args) {
header("Content-type: text/plain");
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) throw new HttpException("", 406);
$record = $this->_acl->getItem($id);
if (!$record) throw new HttpException("404: No item ID({$rowID})", 404);
if (!$this->_acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
$tblName = $this->_acl->getName();
$confTblName = "{$tblName}_COLUMN";
$folderConfAll = FoldersConfig::getRawData();
if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych", 404);
$folderConf = FoldersConfig::getAll($confTblName);
//echo'$folderConf (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($folderConf);echo'';
$uploader = new FileUploader($confTblName, $record);
$errMsg = '';
if (!$uploader->setConfig($folderConf, $errMsg)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})" . '
' . "\n" . $errMsg, 404);
$uploader->findFolder();
if($DBG){ echo'uploader (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($uploader);echo'
'; }
$mainFolder = $uploader->getDestFolder();
if($DBG){ echo'mainFolder (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mainFolder);echo'
'; }
$files = $uploader->getFilesFromFolder($mainFolder, false, true);
if($DBG){ echo'files (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($files);echo''; }
$sharePoint = V::get('share_point', null, $folderConf);
if ($sharePoint) {
$sharePoint = FoldersConfig::getNfsOsPath() . "{$sharePoint}/{$mainFolder}";
}
$localPath = $uploader->getLocalPath();
$folderWeb = $uploader->getFolderWeb();
$jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
if($DBG){ echo'jsonFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonFiles);echo''; }
$folderSkanyConf = FoldersConfig::getAll('SCANS_COLUMN');
$skanyLocalPath = V::get('mount_point', null, $folderSkanyConf);
$skanySharePoint = V::get('share_point', null, $folderSkanyConf);
$skanyFolderWeb = V::get('www_share_point', null, $folderSkanyConf);
$skanyFiles = $uploader->getFilesFromSkany($folderSkanyConf, false);
sort($skanyFiles);
$fileTypes = FoldersConfig::getAll('m_dist_files_types');
$rowFunctionsOut = $this->_showRowFunctions($record->ID, array('files', 'cp'), true);
$fileIndexField = V::get('DEST_FILE_INDEX_FIELD', 'ID', $folderConf);
$fileIndex = V::get($fileIndexField, $record->ID, $record);
?>
Pliki w katalogu
|
Brak folderu!
Folder dla tego rekordu nie został utworzony.
|
|
Brak plików
|
_acl->canWriteRecord($record)) : ?>
Brak uprawnień do dodawania plików
_acl->getField($fldID);
if($DBG){echo'fld('.$fldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fld);echo'';}
if (!$fld) {
// 404
} else {
$fldName = $fld['name'];
}
$jsonData = array();
$typeSpecial = Typespecial::getInstance($fldID, $fldName);
if ($typeSpecial) {
$query = V::get('q', '', $_REQUEST);
$rawRows = null;
$rows = $typeSpecial->getValuesWithExports($query);
if($DBG){echo'rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'';}
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;
}
}
/*
MENU_INIT:VIEWTABLE_AJAX
ZASOB_ID:1188
_task:TYPESPECIAL
fldID:3866
Form Dataview sourceview URL encoded
q:te
*/
echo json_encode($jsonData);
exit;
}
private function sendTypeSpecialCell($id, $fldName, $args) {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
header("Content-type: application/json");
$jsonData = new stdClass();
$fldID = $this->_acl->getFieldIdByName($fldName);
if($DBG){echo'fld('.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fldID);echo'';}
$item = $this->_acl->getItem($id);
if (!$this->_acl->isAllowed($fldID, 'R', $item)) {
$jsonData->msg = 'Brak dostępu';
echo json_encode($jsonData);
exit;
}
if (!$fldID) {
$jsonData->msg = 'Wrong field';
echo json_encode($jsonData);
exit;
}
$typeSpecial = Typespecial::getInstance($fldID, $fldName);
if ($typeSpecial) {
$jsonData->data = $typeSpecial->getReturnData($this->_zasobID, $id, $fldName, '');
if($DBG){echo'specialValuesByIds('.$id.'/'.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValuesByIds);echo'';}
}
echo json_encode($jsonData);
exit;
}
private function ajaxData($args) {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
$pageSize = V::get('pageSize', $this->_pageSize, $args, 'int');
$page = V::get('page', 0, $args, 'int');
$currSortCol = V::get('currSortCol', '', $args);
$currSortFlip = V::get('currSortFlip', '', $args);
if ($page > 0) {
$page -= 1;
}
else {
}
$params = array();
$params['limit'] = $pageSize;
$params['limitstart'] = $page * $params['limit'];
$params['order_by'] = ($currSortCol)? $currSortCol : '';
$params['order_dir'] = $currSortFlip;
$filters = new stdClass();
$filters->currSortCol = $currSortCol;
$filters->currSortFlip = $currSortFlip;
foreach ($args as $k => $v) {
if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
$params[$k] = $v;
$filters->{$k} = $v;
}
else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
$params[$k] = $v;
$filters->{$k} = $v;
}
}
$this->setFilters($filters);
$vCols = $this->_acl->getVirtualFieldList();
if (!empty($vCols)) {
if($DBG){echo'vCols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCols);echo'';}
}
$visibleCols = $this->_acl->getVisibleFieldList();
if($DBG){echo'visibleCols (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($visibleCols);echo'
';}
$jsonData = new stdClass();
$jsonData->page = $page + 1;
$jsonData->pageSize = $pageSize;
$jsonData->filters = $filters;
$jsonData->cols = new stdClass();
$jsonData->uniqueCol = $this->_acl->getPrimaryKeyField();
$ind = 0;
foreach ($visibleCols as $fieldID => $col) {
$ind++;
$columnConfig = (object)array('index'=>$ind);
if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
$columnConfig->format = '{0}
';
}
else if (in_array($col, array('Status'))) {
// Ahmes problems Status colors
$columnConfig->format = '{0}
';
}
else if ($this->_acl->isGeomField($col)) {
$columnConfig->type = 'geom';
}
if ('' !== ($label = $this->_acl->getFieldLabel($fieldID))) {
$columnConfig->friendly = $label;
}
$colType = $this->_acl->getFieldType($col);
if ($colType) {// @see MarkTableAjaxFilterColType
if ($colType['type'] == 'date') {
//$columnConfig->type = 'date';// TODO: require datetimepicker
}
if (!empty($colType['simpleType'])) $columnConfig->type = $colType['simpleType'];
} else {// typespecial - no type
$columnConfig->type = 'special';
}
$typeSpecial = Typespecial::getInstance($fieldID, $col);
if ($typeSpecial) {
if($DBG){echo'typeSpecial (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'
';}
$columnConfig->_tsRetId = $typeSpecial->getReturnId();
if ($columnConfig->_tsRetId == 0) {
$tsParamOut = V::get('param_out', null, $typeSpecial);
if ($tsParamOut) {
$tsFormat = V::get('format', null, $tsParamOut);
$tsValues = V::get('values', null, $tsParamOut);
$tsAliases = V::get('alias', null, $tsParamOut);
if (false !== strpos($tsFormat, ' Array([ID] => 1467), [alias] => Array([1467] => ID) */
$bugTsColsNotVisible = array();
foreach ($tsValues as $kVarName => $vIdZasob) {
if (array_key_exists($vIdZasob, $tsAliases)) {
$tsAliasMap[$kVarName] = $tsAliases[$vIdZasob];
} else {
$bugTsColsNotVisible[] = "noAliasFor {$vIdZasob}";
}
if (!array_key_exists($vIdZasob, $visibleCols)) {
$bugTsColsNotVisible[] = $vIdZasob;
}
}
if (empty($bugTsColsNotVisible)) {
$tsSimpleLink = new stdClass();
$tsSimpleLink->format = $tsFormat;
$tsSimpleLink->aliasMap = $tsAliasMap;
$columnConfig->_tsSimpleLink = $tsSimpleLink;
$columnConfig->type = 'simpleLink';
} else {
$columnConfig->_tsSimpleLinkBug = $bugTsColsNotVisible;
}
}
}
}
}
// @see ajaxHiddenColsSave
if (UserProfile::isHiddenColumn($this->_zasobID, $fieldID)) {
$columnConfig->hidden = true;
}
$columnConfig->description = $this->_acl->getFieldOpis($fieldID);
$jsonData->cols->{$col} = $columnConfig;
}
$jsonData->rows = array();
$jsonData->total = $this->_acl->getTotal($params);
if($DBG){echo'get_total (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData->total);echo'
';}
$items = $this->_acl->getItems($params);
if($DBG){echo'items (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items);echo'
';}
// TODO: add virtual data by Typespecial
if (!empty($vCols) && !empty($items)) {
foreach ($vCols as $vColID => $vCol) {
$colType = $this->_acl->getFieldTypeById($vColID);
if ($colType) {
continue;// pomin Typespecial dla realnych komorek w bazie danych
}
$typeSpecial = Typespecial::getInstance($vColID, $vCol);
if ($typeSpecial) {
$columnConfig = V::get($vCol, null, $jsonData->cols);
if ($columnConfig && !empty($columnConfig->_tsSimpleLink)) {
// pomin simple link values - mved to js render
} else {
if($DBG){echo'Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'';}
$ids = array_keys($items);
$specialValues = $typeSpecial->getValuesByIds($this->_zasobID, $ids);
if($DBG){echo'Typespecial('.$vCol.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'';}
if (!empty($specialValues)) foreach ($specialValues as $kItemID => $vValues) {
$tsValue = implode('
', $vValues);
if($DBG){echo'Item['.$kItemID.'].'.$vCol.' specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items[$kItemID]);echo'';}
if (!empty($items[$kItemID]->{$vCol}) && !empty($tsValue)) {
$items[$kItemID]->{$vCol} .= ": {$tsValue}";
} else {
$items[$kItemID]->{$vCol} = $tsValue;
}
}
}
}
}
}
foreach ($items as $vItem) {
// TODO: hide items without 'R'
foreach ($visibleCols as $kID => $vCol) {
// TODO: ID default 'R'
if (!$this->_acl->isAllowed($kID, 'R', $vItem)) {
$vItem->{$vCol} = '*****';
}
// null => empty string
if (!isset($vItem->{$vCol}) || (!$vItem->{$vCol} && $vItem->{$vCol} !== '0')) {
if($DBG){echo'isEmptyString['.$vCol.'] (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vItem->{$vCol});echo'';}
$vItem->{$vCol} = '';
}
}
$jsonData->rows[] = $vItem;
}
return $jsonData;
}
private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
$value = '';
$type = $this->_acl->getFieldTypeById($fieldID);
if ($type) {
if ($type['type'] == 'date') {
$value = $type['default'];
}
// fix bug when field is unique and is null allowed: change empty string to null
if ($type['null']) {
$value = 'NULL';
}
// fix bug when field is enum and is set to '0': for php '0' is empty
if (substr($type['type'], 0, 4) == 'enum') {// && $args["f{$fieldID}"] === '0') {
if (false !== strpos($type['type'], "''")) {
// enum('', '1','2')
$value = '';
} else if (false !== strpos($type['type'], "'0'")) {
// enum('0', '1','2')
$value = '0';
} else {
$value = $type['default'];
}
}
}
return $value;
}
/**
* set hidden cols in $_SESSION['USER_PROFILE'][$this->_zasobID];
* $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
*/
private function ajaxHiddenColsSave($args) {
$response = new stdClass();
if (empty($args)) {
$response->type = 'info';
return $response;
}
UserProfile::load();
// clean up old, wrong values
if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
}
$colVis = UserProfile::getHiddenCols($this->_zasobID);
$fields = $this->_acl->getFields();
foreach ($fields as $kFldId => $vFld) {
$vFldName = $vFld['name'];
if (isset($args[$vFldName])) {
if ($args[$vFldName] == 'SHOW') {
$colVis[$kFldId] = 1;
} else if ($args[$vFldName] == 'HIDE') {
$colVis[$kFldId] = 0;
}
}
}
UserProfile::setHiddenCols($this->_zasobID, $colVis);
UserProfile::save();
$response->type = 'success';
return $response;
}
private function ajaxPageSizeSave($args) {
$response = new stdClass();
if (empty($args)) {
$response->type = 'info';
return $response;
}
$pageSize = V::get('pageSize', 0, $args, 'int');
UserProfile::load();
// clean up old, wrong values
if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
}
$tableAjaxSettings = UserProfile::getTableAjaxSettings();
$tableAjaxSettings['pageSize'] = $pageSize;
UserProfile::setTableAjaxSettings($tableAjaxSettings);
UserProfile::save();
$response->type = 'success';
return $response;
}
private function ajaxTheGeomSave($args) {
$primaryKeyField = $this->_acl->getPrimaryKeyField();
$primaryKey = V::get($primaryKeyField, 0, $args, 'int');
$polygon = V::get('polygon', 0, $args);
$geomFieldName = 'the_geom';
if ($primaryKey <= 0) {
throw new HttpException("Wrong param ID", 404);
}
// TODO: validate polygon - ex.: POLYGON((2072030.2315435 7234115.910678,2072029.4815435 7234093.660678,2072115.2315435 7234091.160678,2072115.4815435 7234113.660678,2072115.2315435 7234113.660678,2072094.2315435 7234113.910678,2072030.2315435 7234115.910678)))
$record = $this->_acl->getItem($primaryKey);
if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
throw new HttpException("Brak dostępu do rekordu", 403);
}
$theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
}
$itemPatch = array();
$itemPatch[$geomFieldName] = "GeomFromText('{$polygon}')";
$itemPatch[$primaryKeyField] = $primaryKey;
$response = new stdClass();
try {
$affected = $this->_acl->updateItem($itemPatch);
if ($affected > 0) {
$response->type = 'success';
$response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
} else if ($affected == 0) {
$response->type = 'info';
$response->msg = "Nie wprowadzono żadnych zmian";
}
$response->record = $this->_acl->getItem($primaryKey);
}
catch (Exception $e) {
$response->type = 'error';
$response->msg = $e->getMessage();
}
return $response;
}
private function sendAjaxResponseJson($method, $args) {
try {
$response = $this->{$method}($args);
}
catch (HttpException $e) {
$response = new stdClass();
$response->type = 'error';
$response->msg = $e->getMessage();
$response->errorCode = $e->getCode();
Http::sendHeaderByCode($e->getCode());
}
catch (Exception $e) {
$response = new stdClass();
$response->type = 'error';
$response->msg = $e->getMessage();
$response->errorCode = $e->getCode();
}
header('Content-type: application/json');
if (!$response) $response = new stdClass();
echo json_encode($response);
exit;
}
private function ajaxTheGeomRemove($args) {// ajax task 'THE_GEOM_REMOVE'
$primaryKeyField = $this->_acl->getPrimaryKeyField();
$primaryKey = V::get($primaryKeyField, 0, $args, 'int');
$geomFieldName = 'the_geom';
$response = new stdClass();
if ($primaryKey <= 0) {
throw new HttpException("Wrong param ID", 404);
}
$record = $this->_acl->getItem($primaryKey);
if (!$record) {
throw new HttpException("Nie odnaleziono rekordu nr {$primaryKey}", 404);
}
if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
throw new HttpException("Brak dostępu do rekordu nr {$primaryKey}", 403);
}
$theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
}
if (empty($record->{$geomFieldName})) {
$response->type = 'info';
$response->msg = "Rekord nie jest powiązany z żadnym obiektem na mapie";
$response->record = $record;
return $response;
}
$itemPatch = array();
$itemPatch[$geomFieldName] = "NULL";
$itemPatch[$primaryKeyField] = $primaryKey;
$response = new stdClass();
try {
$affected = $this->_acl->updateItem($itemPatch);
if ($affected > 0) {
$response->type = 'success';
$response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
} else if ($affected == 0) {
$response->type = 'info';
$response->msg = "Nie wprowadzono żadnych zmian";
}
$response->record = $this->_acl->getItem($primaryKey);
}
catch (Exception $e) {
$response->type = 'error';
$response->msg = $e->getMessage();
}
return $response;
}
private function ajaxProcesInitFiltr($args) {// ajax task 'PROCES_INIT_FILTR'
$response = new stdClass();
$pInitList = array();// [proces_init_id] => label (DESC)
if (!$this->_showProcesInit) {
$response->type = 'error';
return $response;
}
$userAcl = User::getAcl();
$pInitList = $userAcl->getTableProcesInitList($this->_zasobID);
if (!empty($pInitList)) {
$procesIds = array_keys($pInitList);
$mapTree = ACL::getProcesInitMapTreeOnlyIds($procesIds);
DBG::_('DBG_MAP', '1', "mapTree", $mapTree, __CLASS__, __FUNCTION__, __LINE__);
DBG::_('DBG_MAP', '1', "pInitList", $pInitList, __CLASS__, __FUNCTION__, __LINE__);
$pInitListSelected = $this->getProcesInitSelected();
$response->pInitData = new stdClass();
$response->pInitData->pInitList = $pInitList;
$response->pInitData->mapTree = $mapTree;
$response->pInitData->pInitListSelected = $pInitListSelected;
}
$response->type = 'success';
return $response;
}
function ajaxMoreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
$id = V::get('ID', 0, $args, 'int');
if ($id <= 0) throw new HttpException("404", 404);
$response = new stdClass();
$response->type = 'success';
$response->msg = 'Funkcje';
$response->rowFunctions = [];
$tableName = $this->_acl->getName();
if(1){// TODO: fetch $totalMsgs from TableMsgs
$msgs = Router::getRoute('Msgs');
$msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
$totalMsgs = count($msgsList);
$rowFunc = new stdClass();
$rowFunc->id = 'msgs';
$rowFunc->ico = 'glyphicon glyphicon-envelope';
$rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $this->_zasobID . '&idRow=' . $id;
$rowFunc->title = "Wiadomości ({$totalMsgs})";
$rowFunc->label = "Wiadomości {$totalMsgs}";
$response->rowFunctions[] = $rowFunc;
}
if ('CRM_PROCES' == $this->_acl->getName()) {// TODO: mv to table gui xml or php class
$record = $this->_acl->getItem($id);
// procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-eye-open';
$rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
$rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
$response->rowFunctions[] = $rowFunc;
$wskazniki = ProcesHelper::get_wskazniki($id);
$connectedZasobyTotal = count($wskazniki);
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-random';
$rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
$rowFunc->title = "Powiązane zasoby {$connectedZasobyTotal}";
$response->rowFunctions[] = $rowFunc;
}
if ('CRM_LISTA_ZASOBOW' == $this->_acl->getName()) {// TODO: mv to table gui xml or php class
$record = $this->_acl->getItem($id);
// procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-eye-open';
$rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
$rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
$response->rowFunctions[] = $rowFunc;
// index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-random';
$rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
$rowFunc->title = "Powiązane procesy (OB)";
$response->rowFunctions[] = $rowFunc;
// index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-random';
$rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
$rowFunc->title = "Powiązane dane (IDS)";
$response->rowFunctions[] = $rowFunc;
$groupTypeList = array();
$groupTypeList[] = 'STANOWISKO';
$groupTypeList[] = 'PODMIOT';
$groupTypeList[] = 'DZIAL';
if (in_array($record->TYPE, $groupTypeList)) {
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-retweet';
$rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
$rowFunc->title = "Synchronizuj do LDAP";
$response->rowFunctions[] = $rowFunc;
}
}
if ('ADMIN_USERS' == $this->_acl->getName()) {// TODO: mv to table gui xml
$record = $this->_acl->getItem($id);
$isAllowedoReadUserLogin = false;
if ($this->_acl->canReadRecord($record)) {
$idFieldUserLogin = $this->_acl->getFieldIdByName('ADM_ACCOUNT');
if ($idFieldUserLogin) {
if ($this->_acl->isAllowed($idFieldUserLogin, 'R', $record)) {
$isAllowedoReadUserLogin = true;
}
}
}
if ($isAllowedoReadUserLogin) {
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-user';
$rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
$rowFunc->title = "Ustal stanowisko";
$response->rowFunctions[] = $rowFunc;
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-retweet';
$rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
$rowFunc->title = "Synchronizuj do LDAP";
$response->rowFunctions[] = $rowFunc;
$rowFunc = new stdClass();
$rowFunc->ico = 'glyphicon glyphicon-minus';
$rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
$rowFunc->title = "Ocena pracownika";
$response->rowFunctions[] = $rowFunc;
}
}
$acl = $this->_acl;
if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) {
foreach ($urlFunctions as $urlFunction) {
$rowFunction = array();
$rowFunction['href'] = $urlFunction['baseLink'];
$rowFunction['ico'] = V::get('ico', 'glyphicon glyphicon-share', $urlFunction);
$rowFunction['label'] = $urlFunction['label'];
$rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction);
if (!empty($urlFunction['cell_id_params'])) {
$record = $acl->getItem($id);
$urlParams = array();// [ "{$urlParamName}={$paramValue}" ]
foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) {
$paramValue = '';
$fld = $acl->getField($idField);
if ($fld) {
$fldName = $fld['name'];
$paramValue = V::get($fldName, '', $record);
$urlParams[] = "{$urlParamName}={$paramValue}";
}
}
if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams);
}
$response->rowFunctions[] = $rowFunction;
}
}
return $response;
}
}