| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- <?php
- // @requires $_SERVER['SERVER_NAME']
- Lib::loadClass('RouteBase');
- Lib::loadClass('Schema_TableFactory');
- Lib::loadClass('Response');
- /*
- # Storage:
- - [ ] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
- - [ ] check config for connection
- - [ ] 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() {
- SE_Layout::gora();
- SE_Layout::menu();
- 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;
- }
- $this->navView();
- DBG::table("storageMenu", $storageMenu, __CLASS__, __FUNCTION__, __LINE__);
- } catch (Exception $e) {
- SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- SE_Layout::dol();
- }
- public function tableListAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- 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");
- $this->navView();
- $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'] = '';//->urlTblStruct = $this->buildActionUrl('tableStruct', array('storageId'=>$storageId, 'tblName'=>$tblName));
- $emptyItem['type'] = '';
- $emptyItem['dodaj zasób'] = '';//->urlTblAddToZasoby = $this->buildAjaxActionUrl('addTableToZasoby', $urlParams);
- $emptyItem['struktura'] = '';//->urlTblRawStruct = $this->buildActionUrl('tableStructRaw', array('storageId'=>$storageId, 'tblName'=>$tblName));
- $emptyItem['objectTest'] = '';//->urlObjectTest = $this->buildActionUrl('objectTest', array('storageId'=>$storageId, 'tblName'=>$tblName));
- $emptyItem['xsd'] = '';//->urlTableXsd = $this->buildActionUrl('tableXsd', array('storageId'=>$storageId, 'tblName'=>$tblName, 'HEADER_NOT_INIT'=>'YES'));
- $emptyItem['id_zasob'] = '';//->zasobId = $zasobTableId;
- $emptyItem['isHist'] = '';//->isHistTable = ('_HIST' == substr($tblName, -5)) ? true : false;
- $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::getUriDirName() . "/index.php?_route=Storage&_task=addTableToZasoby&idStorage={$idStorage}&tblName={$tblName}";
- $onClick = "return p5UI__ButtonAjax(this, { href: '{$ajaxAddZasobLink}' })";
- $tblItem['dodaj zasób'] = '<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['dodaj zasób'] = '<a href="#">TODO: ADD ZASOB</a>';
- }
- $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;
- }
- }
- DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
- ?>
- <script>
- jQuery(document).on('p5UI__ButtonAjax:click', function(e, n, payload) {
- console.log('event p5UI__ButtonAjax:click', n, payload);
- });
- jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
- console.log('event p5UI__ButtonAjax:ajaxLoaded', n, payload);
- if ('success' == payload.type && payload.body && payload.body.id > 0) {
- jQuery(n).parents('td').next('td').next('td').next('td').next('td').text(payload.body.id);
- jQuery(n).remove();
- }
- jQuery.notify(payload.msg, payload.type);
- });
- </script>
- <?php
- } catch (Exception $e) {
- SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- SE_Layout::dol();
- }
- public function rawInfoAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- 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");
- $this->navView();
- $storagePdo = DB::getStorage($idStorage);
- $rawInfo = $storagePdo->getTableListWithInfo();
- DBG::table("rawInfo", $rawInfo, __CLASS__, __FUNCTION__, __LINE__);
- } catch (Exception $e) {
- SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- SE_Layout::dol();
- }
- public function tableStructAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- 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");
- $this->navView();
- $storagePdo = DB::getStorage($idStorage);
- $tblStruct = $storagePdo->getTableStruct($tblName);
- $idTable = $this->fetchTableId($idStorage, $tblName);
- if ($idTable <= 0) {
- SE_Layout::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['dodaj zasób'] = '';
- $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::getUriDirName() . "/index.php?_route=Storage&_task=addCellToZasoby&idStorage={$idStorage}&tblName={$tblName}&cellName={$cellName}";
- $onClick = "return p5UI__ButtonAjax(this, { href: '{$ajaxAddZasobLink}' })";
- $tblItem['dodaj zasób'] = '<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;
- }
- }
- DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
- ?>
- <script>
- jQuery(document).on('p5UI__ButtonAjax:click', function(e, n, payload) {
- console.log('event p5UI__ButtonAjax:click', n, payload);
- });
- jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
- console.log('event p5UI__ButtonAjax:ajaxLoaded', n, payload);
- if ('success' == payload.type && payload.body && payload.body.id > 0) {
- jQuery(n).parents('td').next('td').text(payload.body.id);
- jQuery(n).remove();
- }
- jQuery.notify(payload.msg, payload.type);
- });
- </script>
- <?php
- } catch (Exception $e) {
- SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- SE_Layout::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');
- 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;
- }
- 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;
- }
- }
- ?>
- <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;
- }
- }
|