| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202 |
- <?php
- // @requires $_SERVER['SERVER_NAME']
- Lib::loadClass('RouteBase');
- Lib::loadClass('Schema_TableFactory');
- Lib::loadClass('Response');
- Lib::loadClass('UI');
- Lib::loadClass('OBJ');
- /*
- # Storage:
- - [x] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
- - [x] check config for connection
- - [x] add cells to Zasoby
- - [ ] create cells in Storage
- - [x] use PDO
- */
- class Route_Storage extends RouteBase {
- public function handleAuth() {
- if (!User::logged()) {
- User::authByRequest();
- }
- }
- public function defaultAction() {
- UI::gora();
- UI::menu();
- $this->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'] = '<a href="index.php?_route=Storage&_task=tableList&idStorage=' . $id . '">' . "tabele" . '</a>';
- //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
- $menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=rawInfo&idStorage=' . $id . '">' . "raw info" . '</a>';
- $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
- $storageMenu[] = $menuItem;
- }
- {// core object list
- $menuItem = array();
- //$menuItem['id'] = 'Obiekty';
- $menuItem['nazwa'] = 'Obiekty podstawowe';
- $menuItem['typ'] = 'OBJECTS';
- $menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=coreObjectList">' . "obiekty" . '</a>';
- //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
- $menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=coreObjectParseAll">' . "parse All" . '</a>';
- // TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
- $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'] = '<a href="index.php?_route=Storage&_task=objectList">' . "obiekty" . '</a>';
- //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
- //$menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=objectRawInfo">' . "raw info" . '</a>';
- // TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
- $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 = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
- 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 = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
- ?>
- <div class="container">
- <h1>Obiekt <code><?php echo $label; ?></code> <small><?php echo $btnCheckInstall; ?></small></h1>
- <?php if (!empty($parentList)) : ?>
- <ol class="breadcrumb">
- <li>Dziedziczy z:</li>
- <?php foreach ($linksParentList as $parentLink) : ?>
- <li><?php echo $parentLink; ?></li>
- <?php endforeach; ?>
- <!-- <li class="active">Data</li> -->
- </ol>
- <!-- <p> <?php echo implode(", ", $parentList); ?></p> -->
- <?php endif; ?>
- <table class="table table-bordered table-hovered">
- <caption>Struktura:</caption>
- <thead>
- <tr>
- <th>nazwa</th>
- <th>typ</th>
- <th>label</th>
- <th>json</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach (OBJ::getFields($json) as $fieldName => $field) : ?>
- <tr>
- <td><?php echo $fieldName; ?></td>
- <td><?php echo $field['type']; ?></td>
- <td><?php echo $field['label']; ?></td>
- <td><?php echo json_encode($field); ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <a href="index.php?_route=Storage&_task=coreObjectConnect&object=<?php echo $objectName; ?>" class="btn btn-primary">Przypisz rekordy do klasy</a>
- <?php
- $mainTable = OBJ::getMainTableName($json);
- $sqlFields = OBJ::getTableFields($json);
- $this->showTableWidget($mainTable, $sqlFields);
- ?>
- </div>
- <script>
- jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
- console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
- });
- jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
- console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
- if ('success' == payload.type) {
- // jQuery(n).parents('td').text(payload.body.id);
- }
- jQuery.notify(payload.msg, payload.type);
- });
- </script>
- <?php
- DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->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 = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
- 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 = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
- ?>
- <div class="container">
- <h1>Obiekt <code><?php echo $label; ?></code> <small><?php echo $btnCheckInstall; ?></small></h1>
- <?php if (!empty($parentList)) : ?>
- <ol class="breadcrumb">
- <li>Dziedziczy z:</li>
- <?php foreach ($linksParentList as $parentLink) : ?>
- <li><?php echo $parentLink; ?></li>
- <?php endforeach; ?>
- <!-- <li class="active">Data</li> -->
- </ol>
- <!-- <p> <?php echo implode(", ", $parentList); ?></p> -->
- <?php endif; ?>
- <?php
- $tableOne = array();
- $tableOne['caption'] = 'Klasy';
- $tableOne['rows'] = array();
- $parentList = OBJ::getParentList($json);
- $tableOne['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
- $linksParentList = array(); foreach ($parentList as $parentName) {
- // $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
- // 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 '<hr>';
- // 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'));
- ?>
- </div>
- <script>
- jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
- console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
- });
- jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
- console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
- if ('success' == payload.type) {
- // jQuery(n).parents('td').text(payload.body.id);
- }
- jQuery.notify(payload.msg, payload.type);
- });
- </script>
- <?php
- DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->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 __js_on_click to $tableOne and $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]['__js_on_click'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableOne', { primary_key: '{$r['__primary_key']}' });";
- }
- foreach ($tableTwo['rows'] as $idx => $r) {
- $tableTwo['rows'][$idx]['__js_on_click'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableTwo', { primary_key: '{$r['__primary_key']}' });";
- }
- $tableOne['hidden_cols'] = $tableTwo['hidden_cols'] = array('__primary_key', '__js_on_click', '__html_id');
- $tableTwo['__html_id'] = "{$jsEventNamespace}-table-two";
- ?>
- <div id="<?php echo $htmlIdWrap; ?>">
- <?php UI::table($tableOne); ?>
- <div class="btn-group">
- <button class="btn btn-default" title="Wybierz rekordy wg instancji"><i class="glyphicon glyphicon-question-sign"></i></button>
- <button class="btn btn-default conn-btn-filter-yes">Przypisani</button>
- <button class="btn btn-default conn-btn-filter-no active">Nieprzypisani</button>
- <button class="btn btn-default conn-btn-filter-clear" title="Wszystkie"><i class="glyphicon glyphicon-remove"></i></button>
- </div>
- <div class="btn-group">
- <span style="padding-left:30px;">Zaznaczono
- <span class="conn-selected-total">0</span>
- <button class="conn-btn-clear-selected btn btn-link"
- onClick="return p5UI__Clickable(this, '<?php echo $jsEventNamespace; ?>:clearSelection', {});"
- style="display:none"><i class="glyphicon glyphicon-remove" style="color:red"></i></button>
- </span>
- </div>
- <?php UI::jsAjaxTable($tableTwo); ?>
- <pre class="conn-log"></pre>
- </div>
- <script>
- (function(){
- var state = {
- selectedTableOne: null,
- selectedTableTwo: [],
- filterSelected: 'no'
- }
- var props = {
- jsEventNamespace: '<?php echo $jsEventNamespace; ?>',
- htmlIdWrap: '<?php echo $htmlIdWrap; ?>',
- tableTwoId: '#<?php echo $tableTwo['__html_id']; ?>',
- stateSelectedTotalId: '#<?php echo $stateSelectedTotalId; ?>',
- stateClearSelectedBtnId: '#<?php echo $stateClearSelectedBtnId; ?>',
- stateLogId: '#<?php echo $stateLogId; ?>'
- }
- var wrap = jQuery('#' + props.htmlIdWrap);
- var jqNodes = {
- wrap: wrap,
- filter_yes: wrap.find('.conn-btn-filter-yes'),
- filter_no: wrap.find('.conn-btn-filter-no'),
- filter_clear: wrap.find('.conn-btn-filter-clear'),
- total_selected: wrap.find('.conn-selected-total'),
- btn_clear_selected: wrap.find('.conn-btn-clear-selected'),
- state_log: wrap.find('.conn-log')
- }
- function render() {
- jqNodes['total_selected'].text(state.selectedTableTwo.length);
- if (state.selectedTableTwo.length > 0) {
- jQuery(props.stateClearSelectedBtnId).show();
- } else {
- jQuery(props.stateClearSelectedBtnId).hide();
- }
- jqNodes['state_log'].text(JSON.stringify(state));
- switch (state.filterSelected) {
- case 'yes':
- jqNodes['filter_yes'].addClass('active');
- jqNodes['filter_no'].removeClass('active');
- jqNodes['filter_clear'].removeClass('active');
- break;
- case 'no':
- jqNodes['filter_yes'].removeClass('active');
- jqNodes['filter_no'].addClass('active');
- jqNodes['filter_clear'].removeClass('active');
- break;
- case 'clear':
- jqNodes['filter_yes'].removeClass('active');
- jqNodes['filter_no'].removeClass('active');
- jqNodes['filter_clear'].addClass('active');
- break;
- }
- }
- function action__selectTableOneRow(pk) {
- state.selectedTableOne = pk;
- render();
- }
- function action__unselectTableOneRow() {
- state.selectedTableOne = null;
- render();
- }
- function action__selectTableTwoRow(pk) {
- var idx = state.selectedTableTwo.indexOf(pk);
- if (-1 === idx) state.selectedTableTwo.push(pk);
- else console.log("Error selectedTableTwo - should be not set");
- render();
- }
- function action__unselectTableTwoRow(pk) {
- var idx = state.selectedTableTwo.indexOf(pk);
- if (-1 === idx) state.selectedTableTwo.push(pk);
- else state.selectedTableTwo.splice(idx, 1);
- render();
- }
- function action__clearSelection() {
- state.selectedTableTwo = [];
- jQuery(props.tableTwoId).find('tbody').children('.info').removeClass('info');
- render();
- }
- function action__filterSet(fltr) {
- state.filterSelected = fltr;
- render();
- // TODO: ajax load tableTwo based on filter
- }
- jQuery(document).on(props.jsEventNamespace + ':tableOne:click', function(e, n, payload) {
- var n$ = jQuery(n);
- console.log('event '+props.jsEventNamespace+':tableOne:click', n, payload);
- jQuery.notify('tableOne row clicked [' + payload.props.primary_key + ']', 'info');
- if (n$.hasClass('info')) {
- n$.removeClass('info');
- action__unselectTableOneRow();
- } else {
- n$.parent().children('.info').removeClass('info');
- n$.addClass('info');
- action__selectTableOneRow(payload.props.primary_key);
- }
- });
- jQuery(document).on(props.jsEventNamespace + ':tableTwo:click', function(e, n, payload) {
- var n$ = jQuery(n);
- console.log('event '+props.jsEventNamespace+':tableTwo:click', n, payload);
- jQuery.notify('tableTwo row clicked [' + payload.props.primary_key + ']', 'info');
- if (n$.hasClass('info')) {
- n$.removeClass('info');
- action__unselectTableTwoRow(payload.props.primary_key);
- } else {
- n$.addClass('info');
- action__selectTableTwoRow(payload.props.primary_key);
- }
- });
- jQuery(document).on(props.jsEventNamespace + ':clearSelection:click', function(e, n, payload) {
- action__clearSelection();
- });
- jqNodes['filter_yes'].on('click', function(e) {
- action__filterSet('yes');
- });
- jqNodes['filter_no'].on('click', function(e) {
- action__filterSet('no');
- });
- jqNodes['filter_clear'].on('click', function(e) {
- action__filterSet('clear');
- });
- })();
- </script>
- <?php
- }
- 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 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'] = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . $objName . '">' . "struct" . '</a>';
- // $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("No 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'] = '<a href="index.php?_route=Storage&_task=tableStruct&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "struct" . '</a>';
- $tblItem['xsd'] = '<a href="index.php?_route=Storage&_task=tableXsd&idStorage=' . $idStorage . '&table=' . $tblName . '" target="_blank">' . "xsd" . '</a>';
- $tblItem['objectTest'] = '<a href="index.php?_route=Storage&_task=objectTest&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "objectTest" . '</a>';
- $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'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
- }
- $tableList[] = $tblItem;
- }
- foreach ($viewRealList as $row) {
- $tblName = $row['table_name'];
- $tblItem = V::cloneArray($emptyItem);
- $tblItem['nazwa'] = $tblName;
- $tblItem['type'] = $row['table_type'];
- $tblItem['struktura'] = '<a href="index.php?_route=Storage&_task=viewStruct&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "struct" . '</a>';
- $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__);
- ?>
- <script>
- jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:click', function(e, n, payload) {
- console.log('event p5UIBtnAjax:Storage:addTableToZasoby:click', n, payload);
- });
- jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(e, n, payload) {
- console.log('event p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', n, payload);
- if ('success' == payload.type && payload.body && payload.body.id > 0) {
- jQuery(n).parents('td').text(payload.body.id);
- }
- jQuery.notify(payload.msg, payload.type);
- });
- </script>
- <?php
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->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("No id storage");
- $storageList = $this->getStorageList();
- if (empty($storageList)) throw new Exception("No storage defined");
- if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id 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("No id storage");
- $storageList = $this->getStorageList();
- if (empty($storageList)) throw new Exception("No storage defined");
- if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id 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.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['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'];
- } 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'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
- }
- $tableList[] = $tblItem;
- }
- foreach ($cellZasobList as $cellName => $row) {
- if (!$row['_checked']) {
- $tblItem = V::cloneArray($emptyItem);
- $tblItem['name'] = $cellName;
- $tblItem['id_zasob'] = $row['ID'];
- $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;
- });
- DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
- ?>
- <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 cellUwagi$Node = jQuery(n).parents('td').next('td');
- cellUwagi$Node.text(cellUwagi$Node.text().replace('!Zasob', ''))
- jQuery(n).parents('td').text(payload.body.id);
- jQuery(n).remove();
- }
- jQuery.notify(payload.msg, payload.type);
- });
- </script>
- <?php
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- UI::dol();
- }
- 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;
- // <xs:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xs:integer"/>
- $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
- }
- }
- ?>
- <nav class="navbar navbar-default navbar-static-top">
- <div class="container-fluid">
- <div class="navbar-left">
- <ul class="nav navbar-nav navbar-center">
- <li><a href="<?php echo $backLink; ?>" class="btn <?php echo ($backDisabled)? 'disabled' : ''; ?>"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo $backLabel; ?></a></li>
- </ul>
- </div>
- <div class="navbar-left">
- <ul class="nav navbar-nav navbar-center">
- <li><a class="btn" href="<?php echo $currentLink; ?>"><?php echo $currentLabel; ?></a></li>
- </ul>
- </div>
- <div class="navbar-right">
- <!--
- <ul class="nav navbar-nav navbar-right">
- <li><a href="#">Link</a></li>
- <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
- <ul class="dropdown-menu">
- <li><a href="#">Action</a></li>
- <li><a href="#">Another action</a></li>
- <li><a href="#">Something else here</a></li>
- <li role="separator" class="divider"></li>
- <li><a href="#">Separated link</a></li>
- </ul>
- </li>
- </ul>
- -->
- </div>
- </div>
- </nav>
- <?php
- }
- 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}'");
- }
- $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
- if (!$acl) 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");
- $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
- if (!$acl) 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 $rows[0]['ID'];
- return null;
- }
- }
|