navView(); try { $storageList = $this->getStorageList(); if (empty($storageList)) throw new Exception("No storage defined"); $storageMenu = array(); foreach ($storageList as $storage) { $menuItem = array(); $menuItem['id'] = $id = $storage['ID']; $menuItem['nazwa'] = $storage['DESC']; $menuItem['typ'] = $storage['TYPE']; $menuItem['tabele i widoki'] = '' . "tabele" . ''; //$menuItem['views'] = '' . "views" . ''; $menuItem['raw info'] = '' . "raw info" . ''; $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } {// core object list $menuItem = array(); //$menuItem['id'] = 'Obiekty'; $menuItem['nazwa'] = 'Obiekty podstawowe'; $menuItem['typ'] = 'OBJECTS'; $menuItem['tabele i widoki'] = '' . "obiekty" . ''; //$menuItem['views'] = '' . "views" . ''; $menuItem['raw info'] = '' . "parse All" . ''; // TODO: $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } {// object list - for current company $hostName = $_SERVER['SERVER_NAME']; $cleanHostName = str_replace(array(".", "-"), '_', $hostName); $menuItem = array(); //$menuItem['id'] = 'Obiekty'; $menuItem['nazwa'] = "Obiekty dla domeny '{$cleanHostName}'"; $menuItem['typ'] = 'OBJECTS'; $menuItem['tabele i widoki'] = '' . "obiekty" . ''; //$menuItem['views'] = '' . "views" . ''; //$menuItem['raw info'] = '' . "raw info" . ''; // TODO: $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } {// core object list $menuItem = array(); //$menuItem['id'] = 'Obiekty'; $menuItem['nazwa'] = 'SystemObjects'; $menuItem['typ'] = 'OBJECTS'; $menuItem['tabele i widoki'] = '' . "SystemObjects" . ''; //$menuItem['views'] = '' . "views" . ''; // $menuItem['raw info'] = '' . "parse All" . ''; // TODO: $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } DBG::table("storageMenu", $storageMenu, __CLASS__, __FUNCTION__, __LINE__); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function checkObjectInstallAjaxAction() { $response = array(); try { $objectName = V::get('object', '', $_REQUEST, 'word'); if (empty($objectName)) throw new Exception("Missing Object name"); $response['object'] = $objectName; $json = OBJ::getCoreObjectFromFile($objectName); OBJ::checkInstall($json); $response['type'] = 'success'; $response['msg'] = "OK - object installed"; } catch (Exception $e) { $response['type'] = 'error'; $response['msg'] = $e->getMessage(); $response['code'] = $e->getCode(); $response['line'] = $e->getLine(); } Response::sendJsonExit($response); } public function coreObjectStructAction() { UI::gora(); UI::menu(); $this->navView(); try { $objectName = V::get('object', '', $_REQUEST, 'word'); if (empty($objectName)) throw new Exception("Missing Object name"); $json = OBJ::getCoreObjectFromFile($objectName); $label = OBJ::getLabel($json); $parentList = OBJ::getParentList($json); $linksParentList = array(); foreach ($parentList as $parentName) { $parentLink = '' . $parentName . ''; array_unshift($linksParentList, $parentLink); } $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })"; $btnCheckInstall = ''; UI::startContainer(); UI::tag('h1', [], "Obiekt {$label} {$btnCheckInstall}"); if (!empty($parentList)) { UI::startTag('ol', ['class'=>"breadcrumb"]); UI::tag('li', [], "Dziedziczy z:"); foreach ($linksParentList as $parentLink) { UI::tag('li', [], $parentLink); } // UI::endTag('ol'); // } // TODO: UI::table(['rows'=>array_map()]); ?> $field) : ?>
Struktura:
nazwa typ label json
Przypisz rekordy do klasy showTableWidget($mainTable, $sqlFields); ?> getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function coreObjectConnectAction() { UI::gora(); UI::menu(); $this->navView(); try { $objectName = V::get('object', '', $_REQUEST, 'word'); if (empty($objectName)) throw new Exception("Missing Object name"); $json = OBJ::getCoreObjectFromFile($objectName); $label = OBJ::getLabel($json); $parentList = OBJ::getParentList($json); $linksParentList = array(); foreach ($parentList as $parentName) { $parentLink = '' . $parentName . ''; array_unshift($linksParentList, $parentLink); } $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })"; $btnCheckInstall = ''; ?>

Obiekt

$objectName, 'name' => $objectName); $linksParentList = array(); foreach ($parentList as $parentName) { // $parentLink = '' . $parentName . ''; // array_unshift($linksParentList, $parentLink); $tableOne['rows'][] = array('__primary_key' => $parentName, 'name' => $parentName); } $tableTwo = array(); $tableTwo['caption'] = 'Rekordy w tabeli głównej'; $mainTable = OBJ::getMainTableName($json); $sqlFields = OBJ::getTableFields($json); $tableTwo['rows'] = $this->getTableRows($mainTable, $sqlFields); foreach ($tableTwo['rows'] as $idx => $row) { // $tableTwo['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName); $tableTwo['rows'][$idx]['__primary_key'] = $row['ID']; } echo '
'; // TODO: filter connected rows // TODO: filter not connected rows // TODO: action connect rows - args(schema, rows_primary_key_list) // TODO: action un connect rows - args(schema, rows_primary_key_list) $this->showConnectSchemaToTableWidget(compact('tableOne', 'tableTwo')); ?>
getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function showConnectSchemaToTableWidget($params) { if (empty($params['tableOne'])) throw new Exception("Missing tableOne in Connect widget"); if (empty($params['tableTwo'])) throw new Exception("Missing tableTwo in Connect widget"); $tableOne = $params['tableOne']; $tableTwo = $params['tableTwo']; // TODO: add p5BtnAjax to table filters button // TODO: add p5BtnAjax to conn button $jsEventNamespace = 'ConnectTableWidget' . time(); $htmlIdWrap = "{$jsEventNamespace}-wrap"; $stateLogId = "{$jsEventNamespace}-state-log"; $stateSelectedTotalId = "{$jsEventNamespace}-state-selected"; $stateClearSelectedBtnId = "{$jsEventNamespace}-state-clear-selected-btn"; foreach ($tableOne['rows'] as $idx => $r) { $tableOne['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableOne', { primary_key: '{$r['__primary_key']}' });"; } foreach ($tableTwo['rows'] as $idx => $r) { $tableTwo['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableTwo', { primary_key: '{$r['__primary_key']}' });"; } $tableOne['hidden_cols'] = $tableTwo['hidden_cols'] = array('__primary_key', '@onClick', '__html_id'); $tableTwo['__html_id'] = "{$jsEventNamespace}-table-two"; ?>
Zaznaczono 0

fetchAll(" select {$sqlFields} from `{$tblName}` t where 1=1 limit 10 "); return $rows; } public function showTableWidget($tblName, $fields) { $rows = $this->getTableRows($tblName, $fields); UI::table(array('caption' => "table({$tblName})", 'rows' => $rows)); } public function coreObjectParseAllAction() { UI::gora(); UI::menu(); $this->navView(); try { OBJ::parseAll(); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function coreObjectListAction() { UI::gora(); UI::menu(); $this->navView(); try { $coreObjlist = OBJ::getCoreObjectList(); $objectList = array(); foreach ($coreObjlist as $objName) { $objItem = array(); $objItem['name'] = $objName; $objItem['struktura'] = '' . "struct" . ''; // $objItem['label'] = "";// TODO: read from json $objectList[] = $objItem; } usort($objectList, function($rowA, $rowB) { $a = $rowA['nazwa']; $b = $rowB['nazwa']; if ($a == $b) return 0; return ($a < $b) ? -1 : 1; }); DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function objectListAction() { UI::gora(); UI::menu(); try { } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function tableListAction() { UI::gora(); UI::menu(); $this->navView(); try { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); if (empty($idStorage)) throw new Exception("Missing id storage"); $storageList = $this->getStorageList(); if (empty($storageList)) throw new Exception("No storage defined"); if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage id='{$idStorage}' not exists"); $storagePdo = DB::getStorage($idStorage); $viewRealList = $storagePdo->getViewList(); $tableRealList = $storagePdo->getTableList(); $tableZasobList = array(); foreach (DB::getPDO()->fetchAllByKey(" select z.ID, z.`DESC`, z.A_STATUS from CRM_LISTA_ZASOBOW z where z.PARENT_ID = '{$idStorage}' ", $key = 'DESC') as $ind => $row) { $tableZasobList[strtolower($ind)] = $row; } $emptyItem = array(); $emptyItem['nazwa'] = ''; $emptyItem['type'] = ''; $emptyItem['id_zasob'] = ''; $emptyItem['struktura'] = ''; $emptyItem['objectTest'] = ''; $emptyItem['xsd'] = ''; $emptyItem['isHist'] = ''; $emptyItem['uwagi'] = ''; $tableList = array(); foreach ($tableRealList as $row) { $tblName = $row['table_name']; $tblItem = V::cloneArray($emptyItem); $tblItem['nazwa'] = $tblName; $tblItem['type'] = $row['table_type']; $tblItem['struktura'] = '' . "struct" . ''; $tblItem['xsd'] = '' . "xsd" . ''; $tblItem['objectTest'] = '' . "objectTest" . ''; $tblItem['isHist'] = ('_hist' == substr($tblName, -5)); $tblItem['uwagi'] = ''; $tblZasob = V::get($tblName, '', $tableZasobList); if ($tblZasob) { $tableZasobList[$tblName]['_checked'] = true; $tblItem['id_zasob'] = $tblZasob['ID']; } else { $tblItem['uwagi'] .= 'TODO: ADD ZASOB'; $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addTableToZasoby&idStorage={$idStorage}&tblName={$tblName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addTableToZasoby', { href: '{$ajaxAddZasobLink}' })"; $tblItem['id_zasob'] = 'TODO: ADD ZASOB'; } $tableList[] = $tblItem; } foreach ($viewRealList as $row) { $tblName = $row['table_name']; $tblItem = V::cloneArray($emptyItem); $tblItem['nazwa'] = $tblName; $tblItem['type'] = $row['table_type']; $tblItem['struktura'] = '' . "struct" . ''; $tblItem['uwagi'] = ''; $tblZasob = V::get($tblName, '', $tableZasobList); if ($tblZasob) { $tableZasobList[$tblName]['_checked'] = true; $tblItem['id_zasob'] = $tblZasob['ID']; } else { $tblItem['uwagi'] .= 'TODO: ADD ZASOB'; $tblItem['id_zasob'] = 'TODO: ADD ZASOB'; } $tableList[] = $tblItem; } foreach ($tableZasobList as $tblName => $row) { if (!$row['_checked']) { $tblItem = V::cloneArray($emptyItem); $tblItem['nazwa'] = $tblName; $tblItem['id_zasob'] = $row['ID']; $tblItem['type'] = 'unknown'; $tblItem['uwagi'] = 'TODO: nie istnieje w bazie danych'; $tableList[] = $tblItem; } } usort($tableList, function($rowA, $rowB) { $a = $rowA['nazwa']; $b = $rowB['nazwa']; if ($a == $b) return 0; $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1); if (('_' == $a1 || '_' == $b1) && $a1 != $b1) { return ($a1 < $b1) ? 1 : -1; } return ($a < $b) ? -1 : 1; }); DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__); ?> getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function rawInfoAction() { UI::gora(); UI::menu(); $this->navView(); try { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); if (empty($idStorage)) throw new Exception("Missing id storage"); $storageList = $this->getStorageList(); if (empty($storageList)) throw new Exception("No storage defined"); if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists"); $storagePdo = DB::getStorage($idStorage); $rawInfo = $storagePdo->getTableListWithInfo(); DBG::table("rawInfo", $rawInfo, __CLASS__, __FUNCTION__, __LINE__); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function tableStructAction() { UI::gora(); UI::menu(); $this->navView(); try { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); if (empty($idStorage)) throw new Exception("Missing id storage"); $storageList = $this->getStorageList(); if (empty($storageList)) throw new Exception("No storage defined"); if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists"); $tblName = V::get('table', '', $_REQUEST, 'word'); if (empty($tblName)) throw new Exception("No table name"); $storagePdo = DB::getStorage($idStorage); $tblStruct = $storagePdo->getTableStruct($tblName); $idTable = $this->fetchTableId($idStorage, $tblName); if ($idTable <= 0) { UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__); throw new Exception("Zasob tabela '{$tblName}' nie istnieje"); } $cellZasobList = array(); foreach (DB::getPDO()->fetchAllByKey(" select z.ID, z.`DESC`, z.`TYPE` as ZASOB_TYPE, z.A_STATUS from CRM_LISTA_ZASOBOW z where z.PARENT_ID = '{$idTable}' ", $key = 'DESC') as $ind => $row) { $cellZasobList[strtolower($ind)] = $row; } $emptyItem = array(); $emptyItem['name'] = ''; $emptyItem['id_zasob'] = ''; $emptyItem['zasob_type'] = ''; $emptyItem['uwagi'] = ''; $emptyItem['type'] = ''; $emptyItem['is_nullable'] = ''; $emptyItem['default_value'] = ''; $emptyItem['default_is_null'] = ''; $emptyItem['max_length'] = ''; $emptyItem['num_precision'] = ''; $emptyItem['num_scale'] = ''; $emptyItem['char_encoding'] = ''; $emptyItem['char_collation'] = ''; $emptyItem['extra'] = ''; $emptyItem['raw_storage_type'] = ''; $tableList = array(); foreach ($tblStruct as $row) { $cellName = $row['name']; $tblItem = V::cloneArray($emptyItem); $tblItem['name'] = $cellName; foreach ($row as $fldName => $fldVal) { if (array_key_exists($fldName, $tblItem)) $tblItem[$fldName] = $fldVal; } $tblItem['uwagi'] = ''; $lowerCellName = strtolower($cellName); $tblZasob = V::get($lowerCellName, '', $cellZasobList); if ($tblZasob) { $cellZasobList[$lowerCellName]['_checked'] = true; $tblItem['id_zasob'] = $tblZasob['ID']; $tblItem['zasob_type'] = $tblZasob['ZASOB_TYPE']; } else { $tblItem['uwagi'] .= '!Zasob';//'TODO: ADD ZASOB'; $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addCellToZasoby&idStorage={$idStorage}&tblName={$tblName}&cellName={$cellName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addCellToZasoby', { href: '{$ajaxAddZasobLink}' })"; $tblItem['id_zasob'] = 'TODO: ADD ZASOB'; } $tableList[] = $tblItem; } foreach ($cellZasobList as $cellName => $row) { if ('URL_ACTION' == $row['ZASOB_TYPE']) continue; if (!$row['_checked']) { $tblItem = V::cloneArray($emptyItem); $tblItem['name'] = $cellName; $tblItem['id_zasob'] = $row['ID']; $tblItem['zasob_type'] = $row['ZASOB_TYPE']; $tblItem['uwagi'] = '!DB';//'TODO: nie istnieje w bazie danych'; $tableList[] = $tblItem; } } usort($tableList, function($rowA, $rowB) { $a = $rowA['name']; $b = $rowB['name']; if ('ID' == $a) return -1; if ('ID' == $b) return 1; if ($a == $b) return 0; $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1); if (('_' == $a1 || '_' == $b1) && $a1 != $b1) { return ($a1 < $b1) ? 1 : -1; } return ($a < $b) ? -1 : 1; }); UI::table([ 'caption' => "tableList", 'cols' => array_keys($emptyItem), 'rows' => $tableList ]); echo UI::h('script', [], " jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:click', function(e, n, payload) { console.log('event p5UIBtnAjax:Storage:addCellToZasoby:click', n, payload); }); jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', function(e, n, payload) { console.log('event p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', n, payload); if ('success' == payload.type && payload.body && payload.body.id > 0) { var cellUwagiJQNode = jQuery(n).parents('td').next('td'); cellUwagiJQNode.text(cellUwagiJQNode.text().replace('!Zasob', '')) jQuery(n).parents('td').text(payload.body.id); jQuery(n).remove(); } jQuery.notify(payload.msg, payload.type); }); "); $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addGeomEtykietaCells&idStorage={$idStorage}&tblName={$tblName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addGeomEtykietaCells', { href: '{$ajaxAddZasobLink}' })"; UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj komórki etykiet", true); echo "(`etykieta_x`, `etykieta_y`, `etykieta_obrot`)"; echo UI::h('script', [], " jQuery(document).on('p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', function(e, n, payload) { console.log('event p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', n, payload); if ('success' == payload.type && payload.body && payload.body.id > 0) { var cellUwagiJQNode = jQuery(n).parents('td').next('td'); cellUwagiJQNode.text(cellUwagiJQNode.text().replace('!Zasob', '')) jQuery(n).parents('td').text(payload.body.id); jQuery(n).remove(); } jQuery.notify(payload.msg, payload.type); }); "); $tableActions = array_filter($cellZasobList, function ($row) { return ('URL_ACTION' == $row['ZASOB_TYPE']); }); UI::table([ 'caption' => "tableActions", // 'cols' => array_keys($emptyItem), 'rows' => array_map(function ($item) { $sqlIdAction = DB::getPDO()->quote($item['ID'], PDO::PARAM_INT); $args = DB::getPDO()->fetchAll(" select z.`DESC` , a.ID as ALIAS_ID, a.`DESC` as ALIAS_DESC, a.OPIS as ALIAS_OPIS from CRM_LISTA_ZASOBOW z left join CRM_LISTA_ZASOBOW a on(a.ID = z.ALIAS_ID) where z.PARENT_ID = {$sqlIdAction} and z.`TYPE` = 'PARAM_IN' "); $definitionArgs = DB::getPDO()->fetchAll(" select p.ID, p.`DESC` from CRM_LISTA_ZASOBOW z join CRM_LISTA_ZASOBOW d on(d.ID = z.ALIAS_ID) left join CRM_LISTA_ZASOBOW p on(p.PARENT_ID = d.ID) where z.ID = {$sqlIdAction} and p.`TYPE` = 'PARAM_IN' "); $flatDefinitionArgs = implode(";", array_map(function ($arg) { return "{$arg['ID']}={$arg['DESC']}"; }, $definitionArgs)); return [ 'label' => DB::getPDO()->fetchValue(" select z.OPIS from CRM_LISTA_ZASOBOW z where z.ID = {$sqlIdAction} ") . " " . UI::h('i', [ 'class' => "glyphicon glyphicon-pencil", 'style' => "cursor:pointer", 'onClick' => "return Storage__tableStruct__editActionLabel(this, {$sqlIdAction})"], ''), 'args' => implode("
&", array_map(function ($item) { return (NULL === $item['ALIAS_ID']) ? $item['DESC'] : "{$item['DESC']}=" . '{$row["' . $item['ALIAS_DESC'] . '"]}';// TODO: add rmParam btn }, $args)) . " " . UI::h('i', [ 'class' => "glyphicon glyphicon-plus-sign", 'style' => "cursor:pointer", 'title' => "Dodaj PARAM_IN", 'onClick' => "return Storage__tableStruct__addParamAction(this, {$sqlIdAction}, '{$flatDefinitionArgs}')"], ''), // 'args_info' => '
' . var_export($args, true) . '
', 'ID' => $item['ID'], 'DESC' => $item['DESC'], 'A_STATUS' => $item['A_STATUS'], 'definition args' => implode("", array_map(function ($item) { return '
' . "[{$item['ID']}] {$item['DESC']}" . '
'; }, $definitionArgs)), ]; }, $tableActions) ]); echo UI::h('button', [ 'onClick'=>"Storage__tableStruct__addAction()", 'class'=>"btn btn-xs btn-default" ], "Dodaj Akcję"); echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]); echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]); echo UI::h('style', [], " .swal2-radio.p5-swal-radio-as-list { text-align:left } .swal2-radio.p5-swal-radio-as-list > label { display:block; margin-left:20px } "); UI::inlineJS(__FILE__ . '.tableActions.js', [ 'ID_STORAGE' => $idStorage, 'TABLE_NAME' => $tblName, 'FETCH_URL' => Request::getPathUri() . 'index.php?_route=Storage&_task=fetchActionListAjax', 'ADD_ACTION_URL' => Request::getPathUri() . 'index.php?_route=Storage&_task=addActionAjax' ]); echo '
'; $ajaxAddBaseProcesLink = Request::getPathUri() . "index.php?_route=Storage&_task=addBaseProces&idStorage={$idStorage}&tblName={$tblName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addBaseProces', { href: '{$ajaxAddBaseProcesLink}' })"; UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj podstawowy proces dla tabeli '{$tblName}' - read only", true); echo UI::h('script', [], " jQuery(document).on('p5UIBtnAjax:Storage:addBaseProces:ajaxLoaded', function(e, n, payload) { jQuery.notify(payload.msg, payload.type); }); "); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function fetchActionListAjaxAction() { Response::sendTryCatchJson(array($this, 'fetchActionListAjax'), $args = 'JSON_FROM_REQUEST_BODY'); } public function fetchActionListAjax($args) { return [ 'type' => 'success', '__args' => $args, 'options' => DB::getPDO()->fetchAll(" select z.ID, z.`DESC`, z.OPIS from CRM_LISTA_ZASOBOW z where z.`TYPE` = 'URL_ACTION' and z.A_STATUS != 'DELETED' and z.ALIAS_ID = 0 ") ]; } public function addActionAjaxAction() { Response::sendTryCatchJson(array($this, 'addActionAjax'), $args = 'JSON_FROM_REQUEST_BODY'); } public function addActionAjax($args) { $idStorage = V::get('idStorage', 0, $args, 'int'); if ($idStorage <= 0) throw new Exception("Missing id storage"); $idAction = V::get('idAction', 0, $args, 'int'); if ($idAction <= 0) throw new Exception("Missing id action"); $storageList = $this->getStorageList(); if (empty($storageList)) throw new Exception("No storage defined"); if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists"); $tblName = V::get('table', '', $args, 'word'); if (empty($tblName)) throw new Exception("No table name"); $storagePdo = DB::getStorage($idStorage); // $tblStruct = $storagePdo->getTableStruct($tblName); $idTable = $this->fetchTableId($idStorage, $tblName); if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje"); $action = DB::getPDO()->fetchFirst(" select z.ID, z.`DESC`, z.OPIS from CRM_LISTA_ZASOBOW z where z.ID = {$idAction} "); if (empty($action)) throw new Exception("Action '{$idAction}' not exists"); $idInsertedAction = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [ 'PARENT_ID' => $idTable, 'ALIAS_ID' => $idAction, 'TYPE' => 'URL_ACTION', 'DESC' => $action['DESC'], 'OPIS' => V::get('OPIS', $action['DESC'], $action), ]); if (!$idInsertedAction) throw new Exception("Nie udało się dodać akcji"); try { DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', [ 'ID_USERS2' => $idInsertedAction, 'PARENT_ID' => $idTable, 'ALIAS_ID' => $idAction, 'TYPE' => 'URL_ACTION', 'DESC' => $action['DESC'], 'OPIS' => V::get('OPIS', $action['DESC'], $action), ]); } catch (Exception $e) { DBG::log($e); } return [ 'type' => 'success', 'msg' => "Dodano akcję - rekord nr {$idInsertedAction}", '__DBG__' => [ '$args' => $args, '$idStorage' => $idStorage, '$tblName' => $tblName, // '$tblStruct' => $tblStruct, '$idTable' => $idTable, '$action' => $action, ] ]; } public function addBaseProcesAction() { Response::sendTryCatchJson(array($this, 'addBaseProces'), $_REQUEST); } public function addBaseProces($args) { $return = [ 'type' => 'error', 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__, ]; $idStorage = V::get('idStorage', 0, $args, 'int'); if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400); $storage = DB::getStorage($idStorage); $tblName = V::get('tblName', 0, $args, 'word'); if (empty($tblName)) throw new HttpException("Missing tblName", 400); $tableStruct = $storage->getTableStruct($tblName); $return['$tableStruct'] = $tableStruct; $idTable = $this->fetchTableId($idStorage, $tblName); if ($idTable <= 0) { UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__); throw new Exception("Zasob tabela '{$tblName}' nie istnieje"); } $cellZasobList = array(); foreach (DB::getPDO()->fetchAllByKey(" select z.ID, z.`DESC`, z.A_STATUS from CRM_LISTA_ZASOBOW z where z.PARENT_ID = '{$idTable}' ", $key = 'DESC') as $ind => $row) { $cellZasobList[strtolower($ind)] = $row; } $return['$cellZasobList'] = $cellZasobList; $idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[ 'TYPE' => 'PROCES_INIT', 'DESC' => "Proces dla tabeli '{$tblName}'", ]); if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu"); foreach ($cellZasobList as $loverName => $row) { DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[ 'ID_PROCES' => $idProces, 'ID_ZASOB' => $row['ID'], 'TYP' => 'P', 'ID_PRZYPADEK' => 2 ]); } $return['type'] = 'success'; $return['msg'] = "Utworzono proces {{$idProces}}"; return $return; } public function addGeomEtykietaCellsAction() { Response::sendTryCatchJson(array($this, 'addGeomEtykietaCells'), $_REQUEST); } public function addGeomEtykietaCells($args) { $return = [ 'type' => 'error', 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__, ]; $return['_DBG_request'] = $args; // idStorage: "36" // tblName: "test_geom_linestring" $idStorage = V::get('idStorage', 0, $args, 'int'); if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400); $storage = DB::getStorage($idStorage); $tblName = V::get('tblName', 0, $args, 'word'); if (empty($tblName)) throw new HttpException("Missing tblName", 400); $tableStruct = $storage->getTableStruct($tblName); $return['_DBG_$tableStruct'] = $tableStruct; if ('mysql' == DB::getPDO($idStorage)->getType()) { $dbName = DB::getPDO($idStorage)->getDatabaseName(); $fixedTableName = DB::getPDO($idStorage)->fetchValue(" select t.TABLE_NAME from `information_schema`.`TABLES` t where t.TABLE_SCHEMA = '{$dbName}' and t.TABLE_NAME LIKE '{$tblName}' "); $return['_DBG_sql_fix__$tblName'] = " select t.TABLE_NAME from `information_schema`.`TABLES` t where t.TABLE_SCHEMA = '{$dbName}' and t.TABLE_NAME LIKE '{$tblName}' "; if (empty($fixedTableName)) return $return; if (empty($fixedTableName)) throw new HttpException("Database Error", 500); $return['_DBG_$fixedTableName'] = $fixedTableName; $tblName = $fixedTableName; } $return['_DBG_$tableStruct'] = $tableStruct; $return['_DBG_has_field__etykieta_x'] = (null != V::geti('etykieta_x', null, $tableStruct)); $return['_DBG_has_field__etykieta_y'] = (null != V::geti('etykieta_y', null, $tableStruct)); $return['_DBG_has_field__etykieta_obrot'] = (null != V::geti('etykieta_obrot', null, $tableStruct)); if (!V::geti('etykieta_x', null, $tableStruct)) { try { DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_x` varchar(16) DEFAULT 'N/S;'"); } catch (Exception $e) { $return['__DBG_hist_errors__etykieta_x'] = $e->getMessage(); } DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_x` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'"); } if (!V::geti('etykieta_y', null, $tableStruct)) { try { DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_y` varchar(16) DEFAULT 'N/S;'"); } catch (Exception $e) { $return['__DBG_hist_errors__etykieta_y'] = $e->getMessage(); } DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_y` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'"); } if (!V::geti('etykieta_obrot', null, $tableStruct)) { try { DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_obrot` varchar(16) DEFAULT 'N/S;'"); } catch (Exception $e) { $return['__DBG_hist_errors__etykieta_obrot'] = $e->getMessage(); } DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_obrot` decimal(16,10) DEFAULT NULL"); } return $return; } public function xsdAction() { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); $storage = DB::getStorage($idStorage); $tableRealList = $storage->getTableList(); $srvName = $_SERVER['SERVER_NAME']; $storageZasobId = $storage->getZasobId(); $objNs = "p5_{$storageZasobId}_{$tblName}"; $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}"; $p5TypePrefix = "p5Type"; $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types"; $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd"; header('Content-type: text/plain; charset=utf-8');// TODO: test //header('Content-type: application/xml; charset=utf-8'); $xmlWriter = new XMLWriter(); $xmlWriter->openUri('php://output'); $xmlWriter->setIndent(true); if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('xs:schema'); $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema'); $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning'); $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri); $xmlWriter->writeAttribute('elementFormDefault', 'qualified'); $xmlWriter->writeAttribute('targetNamespace', $objNsUri); $xmlWriter->writeAttribute('vc:minVersion', '1.1'); $xmlWriter->startElement('xs:import'); $xmlWriter->writeAttribute('namespace', $p5TypeNsUri); $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation); $xmlWriter->endElement();// xs:import foreach ($tableRealList as $tbl) { $tblName = $tbl['table_name']; $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName); } $xmlWriter->endElement();// xs:schema $xmlWriter->endDocument(); } public function tableXsdAction() { $idStorage = V::get('idStorage', '', $_GET); $tblName = V::get('table', '', $_GET, 'word'); if (empty($tblName)) die("Wrong table name"); header('Content-type: text/plain; charset=utf-8');// TODO: test $storage = DB::getStorage($idStorage); $storageZasobId = $storage->getZasobId(); $objNs = "p5_{$storageZasobId}_{$tblName}"; $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}"; $p5TypePrefix = "p5Type"; $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types"; $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd"; //header('Content-type: application/xml; charset=utf-8'); $xmlWriter = new XMLWriter(); $xmlWriter->openUri('php://output'); $xmlWriter->setIndent(true); if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('xs:schema'); $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema'); $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning'); $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri); $xmlWriter->writeAttribute('elementFormDefault', 'qualified'); $xmlWriter->writeAttribute('targetNamespace', $objNsUri); $xmlWriter->writeAttribute('vc:minVersion', '1.1'); $xmlWriter->startElement('xs:import'); $xmlWriter->writeAttribute('namespace', $p5TypeNsUri); $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation); $xmlWriter->endElement();// xs:import $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName); $xmlWriter->endElement();// xs:schema $xmlWriter->endDocument(); } public function tableXsdViewXmlWriter(&$xmlWriter, $idStorage, $tblName) { $storage = DB::getStorage($idStorage); $schema = Schema_TableFactory::build($tblName, $idStorage, $_SERVER['SERVER_NAME']); $struct = $schema->getStruct(); DBG::_('DBG', '>1', "struct", $struct, __CLASS__, __FUNCTION__, __LINE__); $typeName = "{$tblName}Type"; $xmlWriter->startElement('xs:complexType'); $xmlWriter->writeAttribute('name', $typeName); $xmlWriter->startElement('xs:sequence'); foreach ($struct as $field) { $xmlWriter->startElement('xs:element'); $xmlWriter->writeAttribute('name', $field['name']); $xmlWriter->writeAttribute('minOccurs', 0);// TODO: set minOccurs by default, etc. if ($field['is_nullable']) $xmlWriter->writeAttribute('nillable', 'true'); if (null !== $field['default_value']) { $xmlWriter->writeAttribute('default', $field['default_value']); } else if (null === $field['default_value'] && $field['is_nullable']) { $xmlWriter->writeAttribute('default', $field['default_value']); } else { // TODO: Schema BUG? } if (empty($field['p5_restrictions'])) { $xmlWriter->writeAttribute('type', "p5Type:{$field['p5_type']}"); } else { $xmlWriter->startElement('xs:simpleType'); $xmlWriter->writeAttribute('base', "p5Type:{$field['p5_type']}"); $xmlWriter->startElement('xs:restriction'); if (!empty($field['p5_restrictions']['enumeration'])) { foreach ($field['p5_restrictions']['enumeration'] as $enumValue) { $xmlWriter->startElement('xs:enumeration'); $xmlWriter->writeAttribute('value', $enumValue); $xmlWriter->endElement();// xs:enumeration } } else { // TODO: another restrictions... } $xmlWriter->endElement();// xs:restriction $xmlWriter->endElement();// xs:simpleType } $xmlWriter->endElement();// xs:element } $xmlWriter->endElement();// xs:sequence $xmlWriter->endElement();// xs:complexType return; // $pKeyField = 'ID';//$storageObject->getPrimaryKeyFieldName(); //DBG::_(true, true, "struct", $struct, __CLASS__, __FUNCTION__, __LINE__); foreach ($struct as $field) { $fldName = $vField->getName(); $fldType = $vField->getType(); $xsdType = $fldType->getTypeForXsd(); if ($fldType->hasDefault()) { $fldDefault = $fldType->getDefault(); if (!empty($fldDefault) || '0' === $fldDefault) { $elNode->setAttribute('default', $fldDefault); } } $fldRestrictions = $fldType->getRestrictions(); if (empty($fldRestrictions)) { $elNode->setAttribute('type', "{$p5TypePrefix}:{$xsdType}"); } else { $sType = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:simpleType'); $elNode->appendChild($sType); $sTypeRes = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:restriction'); $sType->appendChild($sTypeRes); $sTypeRes->setAttribute('base', "{$p5TypePrefix}:{$xsdType}"); $enumList = $fldType->getEnumeration(); if (empty($enumList)) { foreach ($fldRestrictions as $restricionName => $restrictionValue) { if ('maxLength' == $restricionName) { $sTypeResMaxLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxLength'); $sTypeRes->appendChild($sTypeResMaxLength); $sTypeResMaxLength->setAttribute('value', $restrictionValue); } else if ('minLength' == $restricionName) { $sTypeResMinLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minLength'); $sTypeRes->appendChild($sTypeResMinLength); $sTypeResMinLength->setAttribute('value', $restrictionValue); } else if ('pattern' == $restricionName) { $sTypeResPattern = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:pattern'); $sTypeRes->appendChild($sTypeResPattern); $sTypeResPattern->setAttribute('value', $restrictionValue); } else if ('fractionDigits' == $restricionName) { $sTypeResFractionDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:fractionDigits'); $sTypeRes->appendChild($sTypeResFractionDigits); $sTypeResFractionDigits->setAttribute('value', $restrictionValue); } else if ('totalDigits' == $restricionName) { $sTypeResTotalDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:totalDigits'); $sTypeRes->appendChild($sTypeResTotalDigits); $sTypeResTotalDigits->setAttribute('value', $restrictionValue); } else if ('maxExclusive' == $restricionName) { $sTypeResMaxExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxExclusive'); $sTypeRes->appendChild($sTypeResMaxExclusive); $sTypeResMaxExclusive->setAttribute('value', $restrictionValue); } else if ('minExclusive' == $restricionName) { $sTypeResMinExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minExclusive'); $sTypeRes->appendChild($sTypeResMinExclusive); $sTypeResMinExclusive->setAttribute('value', $restrictionValue); } else if ('maxInclusive' == $restricionName) { $sTypeResMaxInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxInclusive'); $sTypeRes->appendChild($sTypeResMaxInclusive); $sTypeResMaxInclusive->setAttribute('value', $restrictionValue); } else if ('minInclusive' == $restricionName) { $sTypeResMinInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minInclusive'); $sTypeRes->appendChild($sTypeResMinInclusive); $sTypeResMinInclusive->setAttribute('value', $restrictionValue); } /* TODO: xsd restrictions: enumeration Defines a list of acceptable values fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value) maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value) maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value) minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero pattern Defines the exact sequence of characters that are acceptable totalDigits Specifies the exact number of digits allowed. Must be greater than zero whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled */ } } else { foreach ($enumList as $enumValue) { $sTypeResEnum = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:enumeration'); $sTypeRes->appendChild($sTypeResEnum); $sTypeResEnum->setAttribute('value', $enumValue); } } } } $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:element'); $rootNode->appendChild($elNode); $elNode->setAttribute('name', $tblName); $elNode->setAttribute('type', "{$objNs}:{$typeName}"); header('Content-type: application/xml'); echo $dom->saveXML(); exit; } public function navView() { $backLabel = 'back'; $backLink = 'index.php?_route=Storage'; $backDisabled = true; $currentLabel = 'Storage'; $currentLink = 'index.php?_route=Storage'; if ($task = V::get('_task', '', $_REQUEST)) { $currentLink = "index.php?_route=Storage&_task={$task}"; $backDisabled = false; $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); $tblName = V::get('table', '', $_REQUEST, 'word'); $objName = V::get('object', '', $_REQUEST, 'word'); switch ($task) { case 'tableList': case 'viewList': case 'rawInfo': $backLabel = 'Storage'; $backLink = 'index.php?_route=Storage'; $currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}"; break; case 'tableStruct': $backLabel = "Tabele [{$idStorage}]"; $backLink = "index.php?_route=Storage&_task=tableList&idStorage={$idStorage}"; $currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}&table={$tblName}"; break; case 'objectStruct': break; case 'coreObjectStruct': $backLabel = "Obiekty podstawowe"; $backLink = "index.php?_route=Storage&_task=coreObjectList"; $currentLink = "index.php?_route=Storage&_task={$task}&object={$objName}"; break; } switch ($task) { case 'tableList': $currentLabel = "Tabele [{$idStorage}]"; break; case 'viewList': $currentLabel = "Widoki [{$idStorage}]"; break; case 'rawInfo': $currentLabel = "Raw info [{$idStorage}]"; break; case 'tableStruct': $currentLabel = "Struktura tabeli '{$tblName}'"; break; case 'coreObjectList': $currentLabel = "Obiekty podstawowe"; break; case 'coreObjectStruct': $currentLabel = "Obiekt '{$objName}'"; break; case 'objectList': $currentLabel = "Obiekty z aktualnej domeny"; break;// TODO: domain from $_GET } } UI::startTag('nav', ['class'=>"navbar navbar-default navbar-static-top", 'style'=>"z-index:999"]); UI::startTag('div', ['class'=>"container-fluid"]); UI::startTag('div', ['class'=>"navbar-left"]); UI::startTag('ul', ['class'=>"nav navbar-nav navbar-center"]); UI::startTag('li'); UI::tag('a', ['href'=>$backLink, 'class'=>"btn" . ($backDisabled ? ' disabled' : '')], ' ' . $backLabel); UI::endTag('li'); UI::endTag('ul'); UI::endTag('div'); UI::startTag('div', ['class'=>"navbar-left"]); UI::startTag('ul', ['class'=>"nav navbar-nav navbar-center"]); UI::startTag('li'); UI::tag('a', ['href'=>$currentLink, 'class'=>"btn"], $currentLabel); UI::endTag('li'); UI::endTag('ul'); UI::endTag('div'); UI::startTag('div', ['class'=>"navbar-right"]); // UI::endTag('div'); UI::endTag('div');// .container-fluid UI::endTag('nav'); } public function getStorageList() { $storageList = array(); $sth = DB::getPDO()->prepare(" select z.ID, z.`DESC`, z.`TYPE` from CRM_LISTA_ZASOBOW z where z.TYPE in('BAZA_DANYCH','DATABASE_MYSQL','DATABASE_POSTGRESQL') "); $sth->execute(); $rows = $sth->fetchAll(); foreach ($rows as $row) { $storageList[$row['ID']] = $row; } return $storageList; } public function addTableToZasobyAction() {// sends JSON $response = new stdClass(); try { $idStorage = V::get('storageId', '', $_GET); $tblName = V::get('tblName', '', $_GET, 'word'); if (empty($tblName)) throw new HttpException("Wrong table name"); // $response->zasobTblId = $zasobItemFound->TABLE_ID; // $response->zasobId = $zasobItemFound->ID; $storage = DB::getStorage($idStorage); $tableStruct = $storage->getTableStruct($tblName); $zasobStorageId = $storage->getZasobId(); if (!is_numeric($zasobStorageId)) throw new HttpException("Storage id is not set in config file"); $zasobItem = array(); $zasobItem['PARENT_ID'] = $zasobStorageId; $zasobItem['TYPE'] = 'TABELA'; $zasobItem['DESC'] = $tblName; $zasobItem['DESC_PL'] = $tblName; $zasobItemFound = null; { $rows = DB::getPDO()->fetchAll(" select z.`ID`, z.`DESC` from `CRM_LISTA_ZASOBOW` z where z.`PARENT_ID`='{$zasobStorageId}' and z.`DESC`='{$tblName}' and z.`A_STATUS` in('NORMAL','WAITING') "); if (!empty($rows)) { $zasobItemFound = $rows[0]['ID']; } } if ($zasobItemFound > 0) { $response->_replaceButtonNode = "[{$zasobItemFound}]"; throw new AlertInfoException("Zasob tabela '{$tblName}' już istnieje - nr '{$zasobItemFound}'"); } try { $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow'); } catch (Exception $e) { throw new Exception("Brak dostępu do tabeli Zasoby"); } $item = array(); $item['PARENT_ID'] = $zasobStorageId; $item['TYPE'] = 'TABELA'; $item['DESC'] = $tblName; $item['DESC_PL'] = $tblName; if (DBG::isActive()) $response->_itemToCreate = $item; $createdId = $acl->addItem($item); if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!"); $response->id = $createdId; $response->record = $acl->getItem($createdId); $response->_replaceButtonNode = "[{$createdId}]"; throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}"); } catch (AlertSuccessException $e) { $response->type = 'success'; $response->msg = $e->getMessage(); } catch (AlertInfoException $e) { $response->type = 'info'; $response->msg = $e->getMessage(); } catch (Exception $e) { $response->type = 'error'; $response->msg = $e->getMessage(); } Response::sendJsonExit($response); } public function addCellToZasobyAction() {// sends JSON $response = new stdClass(); try { $idStorage = V::get('storageId', '', $_GET); $tblName = V::get('tblName', '', $_GET, 'word'); $cellName = V::get('cellName', '', $_GET, 'word'); if (empty($tblName)) throw new HttpException("Wrong table name"); if (empty($tblName)) throw new HttpException("Wrong cell name"); $storage = DB::getStorage($idStorage); $tableStruct = $storage->getTableStruct($tblName); $zasobStorageId = $storage->getZasobId(); if (!is_numeric($zasobStorageId)) throw new HttpException("Storage id is not set in config file"); $idTable = $this->fetchTableId($zasobStorageId, $tblName); if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje"); try { $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow'); } catch (Exception $e) { throw new Exception("Brak dostępu do tabeli Zasoby"); } $item = array(); $item['PARENT_ID'] = $idTable; $item['TYPE'] = 'KOMORKA'; $item['DESC'] = $cellName; $item['DESC_PL'] = $cellName; if (DBG::isActive()) $response->_itemToCreate = $item; $createdId = $acl->addItem($item); if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!"); $response->id = $createdId; $response->record = $acl->getItem($createdId); $response->_replaceButtonNode = "[{$createdId}]"; throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}"); } catch (AlertSuccessException $e) { $response->type = 'success'; $response->msg = $e->getMessage(); } catch (AlertInfoException $e) { $response->type = 'info'; $response->msg = $e->getMessage(); } catch (Exception $e) { $response->type = 'error'; $response->msg = $e->getMessage(); } Response::sendJsonExit($response); } public function fetchTableId($idZasobStorage, $tblName) { $rows = DB::getPDO()->fetchAll(" select z.`ID`, z.`DESC` from `CRM_LISTA_ZASOBOW` z where z.`PARENT_ID`='{$idZasobStorage}' and z.`DESC`='{$tblName}' and z.`A_STATUS` in('NORMAL','WAITING') "); if (!empty($rows)) return (int)$rows[0]['ID']; return null; } public function systemObjectsStructAction() { UI::gora(); UI::menu(); $this->navView(); try { throw new Exception("TODO: F." . __FUNCTION__ . ' L.' . __LINE__); // $coreObjlist = OBJXSD::getSystemObjectsStruct(); // $objectList = array(); // foreach ($coreObjlist as $objName) { // $objItem = array(); // $objItem['name'] = $objName; // $objItem['struktura'] = '' . "struct" . ''; // // $objItem['label'] = "";// TODO: read from json // $objectList[] = $objItem; // } // usort($objectList, function($rowA, $rowB) { // $a = $rowA['nazwa']; $b = $rowB['nazwa']; // if ($a == $b) return 0; // return ($a < $b) ? -1 : 1; // }); // // DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function systemObjectsAction() { UI::gora(); UI::menu(); $this->navView(); try { Lib::loadClass('Schema_SystemObjectStorageAcl'); $acl = new Schema_SystemObjectStorageAcl(); UI::table([ 'rows' => array_map( function ($item) { return [ 'ns' => $item['namespace'], 'nazwa' => $item['nazwa'], 'edit' => 'edit', 'wfs Describe' => 'DescribeFeatureType', 'wfs getFeature' => 'GetFeature (max:10)' ]; } , $acl->getItems([ 'order_by' => 'ID', 'order_dir' => 'asc' ]) ) ]); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } }