navView(); UI::startContainer(); try { $sourceStorage = SchemaFactory::loadDefaultObject('SystemSource'); try { $sourceStorage->getTotal(); } catch (Exception $e) { UI::alert('warning', $e->getMessage()); $sourceStorage->updateCache(); UI::alert('info', "Lista dostępnych baz danych zaktualizowana"); } if ('1' == V::get('refreshSourceList', '', $_POST)) { $sourceStorage->updateCache(); UI::alert('info', "Lista dostępnych baz danych zaktualizowana"); } UI::table([ 'caption' => "Bazy danych " . UI::hButtonPost('' . " odśwież", [ 'class' => "btn btn-xs btn-link", 'data' => [ 'refreshSourceList' => '1' ] ]), 'rows' => array_merge( array_map(function ($item) { return [ 'Nr zasobu' => $item['idZasob'], 'nazwa' => $item['name'], 'opis' => $item['description'], 'config?' => ($item['hasConfig']) ? 'TAK' : 'brak', 'obiekty' => UI::h('a', [ 'href' => $this->getLink('tableList', [ 'idStorage' => $item['idZasob'] ]) ], "obiekty"), 'raw info' => UI::h('a', [ 'href' => $this->getLink('rawInfo', [ 'idStorage' => $item['idZasob'] ]) ], "raw info"), 'xsd' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestXsd')->getLink('', [ 'idStorage' => $item['idZasob'] ]) ], "xsd"), ]; }, $sourceStorage->getItems()) , [ [ 'Nr zasobu' => '', 'nazwa' => "Narzędzia systemowe", 'opis' => "SystemObjects", 'config?' => 'n/d', 'obiekty' => UI::h('a', [ 'href' => Router::getRoute('Storage_Tools')->getLink() ], "narzędzia"), ], [ 'Nr zasobu' => '', 'nazwa' => '' . "Obiekty" . '', 'opis' => '' . "SystemObjects" . '', 'config?' => 'brak', 'obiekty' => UI::h('a', [ 'href' => $this->getLink('systemObjects') ], "obiekty"), ], [ 'Nr zasobu' => '', 'nazwa' => '' . "Obiekty Test" . '', 'opis' => '' . "Obiekty podstawowe (test json)" . '', 'config?' => 'brak', 'obiekty' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestObj')->getLink('coreObjectList') ], "obiekty"), 'raw info' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestObj')->getLink('coreObjectParseAll') ], "raw info"), ], [ 'Nr zasobu' => '', 'nazwa' => '' . "Obiekty Test" . '', 'opis' => '' . "Obiekty dla domeny '" . str_replace(array(".", "-"), '_', $_SERVER['SERVER_NAME']) . "' (test json)" . '', 'config?' => 'brak', 'obiekty' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestObj')->getLink('objectList') ], "obiekty"), // 'raw info' => UI::h('a', [ 'href' => $this->getLink('objectRawInfo') ], "raw info"), ], ] ) ]); // $sourceStorage = SchemaFactory::loadDefaultObject('SystemObject'); // $sourceStorage->updateCache(); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::endContainer(); UI::dol(); } public function getTableRows($tblName, $fields) { $sqlFields = array(); foreach ($fields as $fldName) { $sqlFields[] = "t.`{$fldName}`"; } $sqlFields = (!empty($sqlFields))? implode(", ", $sqlFields) : "t.*"; $rows = DB::getPDO()->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 tableListAction() { UI::gora(); UI::menu(); $this->navView(); UI::startContainer(); try { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); if (empty($idStorage)) throw new Exception("Missing id storage"); $sourceStorage = SchemaFactory::loadDefaultObject('SystemSource'); $sourceItem = $sourceStorage->getItem($idStorage); if (!$sourceItem) throw new Exception("Storage id='{$idStorage}' not exists"); DBG::log($sourceItem, 'array', '$sourceItem'); // TODO: fetch SystemObject childrens from $sourceItem: // 1. 'SystemSource' -> getItems([ 'cols' => 'SystemObject/*', 'featureId' => $sourceItem['idZasob'] ]) // 2. 'SystemObject' -> getItems([ 'refFrom' => $sourceItem['idZasob'] ]) // 'default_objects' => _task=systemObjects $objectStorage = SchemaFactory::loadDefaultObject('SystemObject'); try { $objectStorage->getTotal(); } catch (Exception $e) { UI::alert('warning', $e->getMessage()); DBG::log($e); $objectStorage->updateCache(); UI::alert('info', "Lista obiektów zaktualizowana"); } if ('1' == V::get('refreshObjectList', '', $_POST)) { $objectStorage->updateCache(); // TODO: execute Storage_AclReinstall::reinstallAcl($namespace) for all objects UI::alert('info', "Lista obiektów zaktualizowana"); } { echo UI::h('style', ['type' => "text/css"], " .p5UI__dropdown-content { min-width:300px; padding:8px; background-color: #f6f6f6; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) } .p5UI__dropdown-content a { display:block; color:#000; padding:8px; text-decoration:none } .p5UI__dropdown-content a:hover { background-color:#ebebeb } "); echo UI::h('script', [], " function p5_Storage_actions_filterInput(n) { var input, filter, ul, li, a, i, div; input = n // .id-myInput filter = input.value.toUpperCase() div = n.parentNode // .id-myDropdown a = div.getElementsByTagName('a') for (i = 0; i < a.length; i++) { if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) { a[i].style.display = '' } else { a[i].style.display = 'none' } } } "); } $thisGetLink = array($this, 'getLink'); UI::table([ 'caption' => "Obiekty w bazie '{$sourceItem['name']}' " . UI::hButtonPost('' . " odśwież listę", [ 'class' => "btn btn-link", 'data' => [ 'refreshObjectList' => '1' ] ]) . ( ($projectName = Config::getProjectName()) ? " project({$projectName})" : '' ), 'rows' => array_map(function ($item) use ($idStorage, $thisGetLink) { $typeName = $item['typeName']; // $typeName = Api_WfsNs::typeName($item['namespace']); return [ 'namespace' => '' . substr($item['namespace'], 0, strlen($item['namespace']) - strlen($item['name'])) . '' . '' . $item['name'] . '', '_type' => $item['_type'], // TODO: editable? 'Nr zasobu' => ($item['idZasob'] > 0) ? $item['idZasob'] : UI::hButtonAjax("Dodaj do zasobów", 'addAclObjectToZasobyAjax', [ 'class' => "btn btn-xs btn-primary", 'href' => $this->getLink('addAclObjectToZasobyAjax'), 'data' => [ 'idStorage' => $idStorage, 'namespace' => $item['namespace'], ] ]), // 'opis' => $item['description'], 'hasStruct' => ($item['hasStruct']) ? 'TAK' : 'nie', 'installed' => $item['isStructInstalled'] ? 'TAK' : 'nie', 'active?' => $item['isObjectActive'] ? 'TAK' : 'nie', 'menu' => UI::h('div', ['class'=>"p5UI__dropdown-wrap"], [ UI::h('button', ['onClick' => "p5UI__dropdown(event, this, 'left bottom')", 'class' => "btn btn-xs btn-default p5UI__dropdown-btn"], [ '', " menu" ]), UI::h('div', ['class' => "p5UI__dropdown-content"], [ UI::h('input', ['type' => "text", 'placeholder' => "Search..", 'class' => "p5UI__dropdown-input", 'onkeyup' => "p5_Storage_actions_filterInput(this)"], null), UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'namespace' => $item['namespace'] ]) ], "struktura"), UI::h('a', [ 'href' => $item['reinstallLink'] ], "reinstall"), UI::h('a', [ 'href' => $this->getLink('rawInfo', [ 'idStorage' => $idStorage, 'table' => $item['name'] ]) ], "raw info"), UI::h('a', [ 'href' => Router::getRoute('ViewTableAjax')->getLink('', ['namespace' => $item['namespace']]) ], "view table"), // 'xsd' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestXsd')->getLink('', [ 'idStorage' => $idStorage ]) ], "xsd"), UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME={$typeName}" ], "wfs DescribeFeatureType"), UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureTypeAdvanced&TYPENAME={$typeName}" ], "wfs DescribeFeatureTypeAdvanced"), UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=10" ], "wfs GetFeature (max: 10)"), UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeatureAdvanced&TYPENAME={$typeName}&MAXFEATURES=10" ], "wfs GetFeatureAdvanced (max: 10)"), UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=3&resolve=all&resolveDepth=3" ], "wfs GetFeature (max: 3, resolveDepth: 3)"), UI::h('a', [ 'href' => "index.php?_route=WfsJsRequestPanel&namespace={$item['namespace']}" ], "JavaScript WFS Panel"), ]) ]), ]; }, $objectStorage->getItems([ '#refFrom' => [ 'namespace' => 'default_objects/SystemSource', 'primaryKey' => $sourceItem['idZasob'] ], 'order_by' => 'namespace', 'order_dir' => 'asc' ])) ]); UI::hButtonAjaxOnResponse('addAclObjectToZasobyAjax', /* payload, n */ " if (!payload.type) return false if ('success' === payload.type || 'info' === payload.type) { if (payload.body && payload.body.id && payload.body.id > 0) { n.parentNode.replaceChild(document.createTextNode(payload.body.id), n) } else { console.log('TODO: addAclObjectToZasobyAjax unknown response', payload); } jQuery.notify(payload.msg, payload.type); } "); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); DBG::log($e); } UI::endContainer(); 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 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 addTableBaseProcesAction() { Response::sendTryCatchJson(array($this, 'addTableBaseProces'), $_REQUEST); } public function addTableBaseProces($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 addObjectBaseProcesAjaxAction() { Response::sendTryCatchJson(array($this, 'addObjectBaseProcesAjax'), $_REQUEST); } public function addObjectBaseProcesAjax($args) { $return = [ 'type' => 'error', 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__, ]; $namespace = V::get('namespace', 0, $args); if (empty($namespace)) throw new HttpException("Missing namespace", 400); $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]); DBG::log($item, 'array', "TODO: addObjectBaseProcesAjax for \$item"); if (!$item['idZasob']) throw new Exception("Missing id zasob for object '{$namespace}'"); if (!$item['idDatabase']) throw new Exception("Missing id database for object '{$namespace}'"); if (!$item['_rootTableName']) throw new Exception("Missing root table name for object '{$namespace}'"); switch ($item['_type']) { case 'AntAcl': break; // OK case 'StorageAcl': break; // OK default: throw new Exception("Not implemented type '{$item['_type']}' for namespace '{$namespace}' - only AntAcl supported"); } if (!$item['hasStruct']) throw new Exception("Missing structure for object '{$namespace}'"); if (!$item['isStructInstalled']) throw new Exception("Structure not installed for object '{$namespace}'"); if (!$item['isObjectActive']) throw new Exception("Object is not active '{$namespace}'"); $fieldsWithIdZasob = array_filter($item['field'], function ($field) { if (!$field['idZasob']) return false; return true; }); if (empty($fieldsWithIdZasob)) throw new Exception("Missing fields with id zasob in object '{$namespace}'"); $idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[ 'TYPE' => 'PROCES_INIT', 'DESC' => "TODO: Proces dla obiektu '{$namespace}'", ]); if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu"); array_map(function ($field) use ($idProces) { DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[ 'ID_PROCES' => $idProces, 'ID_ZASOB' => $field['idZasob'], 'TYP' => 'P', 'ID_PRZYPADEK' => 2 ]); }, $fieldsWithIdZasob); $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 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'); $namespace = V::get('namespace', '', $_REQUEST, 'word'); switch ($task) { case 'obejctList': $backLabel = 'Storage'; $backLink = $this->getLink(); $currentLink = $this->getLink('obejctList', ['idStorage' => $idStorage]); break; case 'tableList': $backLabel = 'Storage'; $backLink = $this->getLink(); $currentLink = $this->getLink('tableList', ['idStorage' => $idStorage]); break; case 'viewList': $backLabel = 'Storage'; $backLink = $this->getLink(); $currentLink = $this->getLink('viewList', ['idStorage' => $idStorage]); break; case 'rawInfo': $backLabel = 'Storage'; $backLink = $this->getLink(); $currentLink = $this->getLink('rawInfo', ['idStorage' => $idStorage]); break; case 'tableStruct': $backLabel = "Tabele [{$idStorage}]"; $backLink = $this->getLink('tableList', ['idStorage' => $idStorage]); $currentLink = $this->getLink('tableStruct', ['idStorage' => $idStorage, 'table' => $tblName]); break; case 'objectStruct': $backLabel = "Obiekty [{$idStorage}]"; $backLink = $this->getLink('tableList', ['idStorage' => $idStorage]);// TODO: mv tableList to objectList $currentLink = $this->getLink('objectStruct', ['idStorage' => $idStorage, 'namespace' => $namespace]); break; case 'coreObjectStruct': $backLabel = "Obiekty podstawowe"; $backLink = Router::getRoute('Storage_TestObj')->getLink('coreObjectList', ['idStorage' => $idStorage]); $currentLink = $this->getLink('coreObjectStruct', ['idStorage' => $idStorage, '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 'objectStruct': $currentLabel = "Obiekt '{$namespace}'"; 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 } } echo UI::h('nav', ['class'=>"navbar navbar-default navbar-static-top", 'style'=>"z-index:999"], [ UI::h('div', ['class'=>"container-fluid"], [ UI::h('div', ['class'=>"navbar-left"], [ UI::h('ul', ['class'=>"nav navbar-nav navbar-center"], [ UI::h('li', [], [ UI::h('a', ['href'=>$backLink, 'class'=>"btn" . ($backDisabled ? ' disabled' : '')], ' ' . $backLabel) ]) ]) ]), UI::h('div', ['class'=>"navbar-left"], [ UI::h('ul', ['class'=>"nav navbar-nav navbar-center"], [ UI::h('li', [], [ UI::h('a', ['href'=>$currentLink, 'class'=>"btn"], $currentLabel) ]) ]) ]), UI::h('div', ['class'=>"navbar-right"], [ //
]) ]) ]); } 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 addAclObjectToZasobyAction() {// sends JSON $response = new stdClass(); try { $idStorage = V::get('idStorage', '', $_GET); $namespace = V::get('namespace', '', $_GET); if (empty($idStorage)) throw new HttpException("Missing idStorage param"); if (empty($namespace)) throw new HttpException("Missing namespace param"); $objectStorage = SchemaFactory::loadDefaultObject('SystemObject'); $items = $objectStorage->getItems([ 'f_namespace' => "={$namespace}", ]); if (empty($items)) throw new Exception("SystemObject '{$namespace}' not found"); $objectItem = reset($items); if (empty($objectItem)) throw new Exception("SystemObject '{$namespace}' not found"); DBG::log($objectItem, 'array', 'object acl $objectItem'); if ($objectItem['idZasob'] > 0) { // TODO: check if realy exists? @see SchemaFactory::loadDefaultObject('SystemObject')::updateCache() $response->_replaceButtonNode = "[{$objectItem['idZasob']}]"; throw new AlertInfoException("Zasob '{$objectItem['namespace']}' już istnieje - nr '{$objectItem['idZasob']}'"); } $idZasobFound = 0; switch ($objectItem['_type']) { case 'TableAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['name']}' "); break; case 'AntAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break; default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'"); } if ($idZasobFound > 0) { DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [ 'idZasob' => $idZasobFound ]); $response->id = $idZasobFound; throw new AlertSuccessException("Zasob '{$objectItem['namespace']}' już istnieje - nr '{$idZasobFound}' - cache zaktualizowany"); } try { $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow'); } catch (Exception $e) { DBG::log($e); throw new Exception("Brak dostępu do tabeli Zasoby"); } if (empty($objectItem['idDatabase'])) throw new Exception("Missing database id"); if ($idStorage != $objectItem['idDatabase']) throw new Exception("Database id must be the same"); if (empty($objectItem['_rootTableName'])) throw new Exception("Missing root table name"); switch ($objectItem['_type']) { case 'TableAcl': $newZasobItem = [ 'PARENT_ID' => $objectItem['idDatabase'], 'TYPE' => 'TABELA', 'DESC' => $objectItem['_rootTableName'], 'DESC_PL' => $objectItem['name'], ]; break; case 'AntAcl': $newZasobItem = [ 'PARENT_ID' => $objectItem['idDatabase'], 'TYPE' => 'TABELA', 'DESC' => $objectItem['namespace'], 'DESC_PL' => $objectItem['name'], ]; break; default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'"); } $idCreated = $acl->addItem($newZasobItem); if (!$idCreated) throw new Exception("Nie udało się utworzyć nowego rekordu!"); try { DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [ 'idZasob' => $idCreated ]); } catch (Exception $e) { DBG::log($e); } $response->id = $idCreated; $response->record = $acl->getItem($idCreated); $response->_replaceButtonNode = "[{$idCreated}]"; throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$idCreated}"); } 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(); DBG::log($e); } Response::sendJsonExit($response); } public function addAclObjectToZasobyAjaxAction() { DBG::log($_REQUEST, 'array', '$_REQUEST'); Response::sendTryCatchJson(array($this, 'addAclObjectToZasobyAjax'), $_REQUEST); } public function addAclObjectToZasobyAjax($args) { $namespace = V::get('namespace', '', $args); if (empty($namespace)) throw new HttpException("Missing namespace"); $idStorage = V::get('idStorage', '', $args); if (empty($idStorage)) throw new HttpException("Missing idStorage"); $objectStorage = SchemaFactory::loadDefaultObject('SystemObject'); $items = $objectStorage->getItems([ 'f_namespace' => "={$namespace}", ]); if (empty($items)) throw new Exception("SystemObject '{$namespace}' not found"); $objectItem = reset($items); if (empty($objectItem)) throw new Exception("SystemObject '{$namespace}' not found"); DBG::log($objectItem, 'array', 'object acl $objectItem'); try { $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow'); } catch (Exception $e) { DBG::log($e); throw new Exception("Brak dostępu do tabeli Zasoby"); } if ($objectItem['idZasob'] > 0) { // TODO: check if realy exists? @see SchemaFactory::loadDefaultObject('SystemObject')::updateCache() return [ 'type' => 'info', 'msg' => "Zasob '{$objectItem['namespace']}' już istnieje - nr '{$objectItem['idZasob']}'", 'body' => [ 'id' => $objectItem['idZasob'], 'record' => $acl->getItem($objectItem['idZasob']), '_replaceButtonNode' => "[{$objectItem['idZasob']}]", ] ]; } $idZasobFound = 0; if ('StorageAcl' === $objectItem['_type']) { if (!$objectItem['idDatabase']) throw new Exception("Brak idDatabase dla '{$objectItem['namespace']}'"); } switch ($objectItem['_type']) { case 'TableAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['name']}' "); break; case 'AntAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break; case 'StorageAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break; default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'"); } if ($idZasobFound > 0) { DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [ 'idZasob' => $idZasobFound ]); return [ 'type' => 'info', 'msg' => "Zasob '{$objectItem['namespace']}' już istnieje - nr '{$idZasobFound}' - cache zaktualizowany", 'body' => [ 'id' => $idZasobFound, 'record' => $acl->getItem($idZasobFound), '_replaceButtonNode' => "[{$idZasobFound}]", ] ]; } if (empty($objectItem['idDatabase'])) throw new Exception("Missing database id"); if ($idStorage != $objectItem['idDatabase']) throw new Exception("Database id must be the same"); if (empty($objectItem['_rootTableName'])) throw new Exception("Missing root table name"); switch ($objectItem['_type']) { case 'TableAcl': $newZasobItem = [ 'PARENT_ID' => $objectItem['idDatabase'], 'TYPE' => 'TABELA', 'DESC' => $objectItem['_rootTableName'], 'DESC_PL' => $objectItem['name'], ]; break; case 'AntAcl': $newZasobItem = [ 'PARENT_ID' => $objectItem['idDatabase'], 'TYPE' => 'TABELA', 'DESC' => $objectItem['namespace'], 'DESC_PL' => $objectItem['name'], ]; break; case 'StorageAcl': $newZasobItem = [ 'PARENT_ID' => $objectItem['idDatabase'], 'TYPE' => 'TABELA', 'DESC' => $objectItem['namespace'], 'DESC_PL' => $objectItem['name'], ]; break; default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'"); } $idCreated = $acl->addItem($newZasobItem); if (!$idCreated) throw new Exception("Nie udało się utworzyć nowego rekordu!"); try { DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [ 'idZasob' => $idCreated ]); } catch (Exception $e) { DBG::log($e); } return [ 'type' => 'success', 'msg' => "Utworzono pomyślnie rekord nr {$idCreated}", 'body' => [ 'id' => $idCreated, 'record' => $acl->getItem($idCreated), '_replaceButtonNode' => "[{$idCreated}]", ] ]; } public function addCellToZasobyAction() {// sends JSON $response = new stdClass(); try { $idStorage = V::get('idStorage', '', $_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) { DBG::log($e); $response->type = 'success'; $response->msg = $e->getMessage(); } catch (AlertInfoException $e) { DBG::log($e); $response->type = 'info'; $response->msg = $e->getMessage(); } catch (Exception $e) { DBG::log($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() {// TableAjax view: index.php?_route=ViewTableAjax&namespace=default_objects/SystemObject 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['name'], 'type' => $item['_type'], 'edit' => 'edit', 'wfs Describe' => 'DescribeFeatureType', 'wfs getFeature' => 'GetFeature (max:10)' ]; } , $acl->getItems([ 'order_by' => 'namespace', 'order_dir' => 'asc' ]) ) ]); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); DBG::log($e); } UI::dol(); } function activateObjectAjaxAction() { Response::sendTryCatchJson(array($this, 'activateObjectAjax'), $_REQUEST); } function activateObjectAjax($args) { $namespace = V::get('namespace', '', $args); if (empty($namespace)) throw new Exception("Missing param namespace"); $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]); if (empty($item)) throw new HttpException("Namespace not found", 404); DBG::log($item, 'array', "activateObjectAjax \$item"); if ($item['isObjectActive']) throw new AlertSuccessException("Namespace '{$namespace}' already active"); if (!$item['hasStruct']) throw new Exception("Missing struct for namespace '{$namespace}'"); if (!$item['isStructInstalled']) throw new Exception("Namespace struct not installed '{$namespace}'"); $activeFields = array_filter($item['field'], function ($field) { if (!$field['isActive']) return false; if (!$field['idZasob']) return false; return true; }); if (empty($activeFields)) throw new Exception("Missing active fields for namespace '{$namespace}'"); $affected = SchemaFactory::loadDefaultObject('SystemObject')->updateItem([ 'namespace' => $item['namespace'], 'isObjectActive' => 1, ]); if ($affected < 0) throw new Exception("Nie udało się aktywować obiektu '{$namespace}'"); return [ 'type' => "success", 'msg' => "Aktywowano obiekt '{$namespace}'", 'body' => [ 'isObjectActive' => 1 ] ]; } function activateTableAclAjaxAction() { Response::sendTryCatchJson(array($this, 'activateTableAclAjax'), $_REQUEST); } function activateTableAclAjax($args) { $namespace = V::get('namespace', '', $args); if (empty($namespace)) throw new Exception("Missing param namespace"); $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]); if (empty($item)) throw new HttpException("Namespace not found", 404); DBG::log($item, 'array', "activateTableAclAjax \$item"); if ($item['isObjectActive']) throw new AlertSuccessException("Namespace '{$namespace}' already active"); // if (!$item['hasStruct']) throw new Exception("Missing struct for namespace '{$namespace}'"); // if (!$item['isStructInstalled']) throw new Exception("Namespace struct not installed '{$namespace}'"); // $activeFields = array_filter($item['field'], function ($field) { // if (!$field['isActive']) return false; // if (!$field['idZasob']) return false; // return true; // }); // if (empty($activeFields)) throw new Exception("Missing active fields for namespace '{$namespace}'"); $affected = SchemaFactory::loadDefaultObject('SystemObject')->updateItem([ 'namespace' => $item['namespace'], 'isObjectActive' => 1, ]); if ($affected < 0) throw new Exception("Nie udało się aktywować obiektu '{$namespace}'"); return [ 'type' => "success", 'msg' => "Aktywowano obiekt '{$namespace}'", 'body' => [ 'isObjectActive' => 1 ] ]; } function deactivateObjectAjaxAction() { Response::sendTryCatchJson(array($this, 'deactivateObjectAjax'), $_REQUEST); } function deactivateObjectAjax($args) { $namespace = V::get('namespace', '', $args); if (empty($namespace)) throw new Exception("Missing param namespace"); $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]); if (empty($item)) throw new HttpException("Namespace not found", 404); DBG::log($item, 'array', "activateObjectAjax \$item"); if (!$item['isObjectActive']) throw new AlertSuccessException("Namespace '{$namespace}' already not active"); $affected = SchemaFactory::loadDefaultObject('SystemObject')->updateItem([ 'namespace' => $item['namespace'], 'isObjectActive' => 0, ]); if ($affected < 0) throw new Exception("Nie udało się wyłączyć obiektu '{$namespace}'"); return [ 'type' => "success", 'msg' => "Wyłączono obiekt '{$namespace}'", 'body' => [ 'isObjectActive' => 0 ] ]; } }