navView(); try { $storageList = $this->getStorageList(); if (empty($storageList)) throw new Exception("No storage defined"); $storageMenu = array(); foreach ($storageList as $storage) { $menuItem = array(); $menuItem['id'] = $id = $storage['ID']; $menuItem['nazwa'] = $storage['DESC']; $menuItem['typ'] = $storage['TYPE']; $menuItem['tabele i widoki'] = '' . "tabele" . ''; //$menuItem['views'] = '' . "views" . ''; $menuItem['raw info'] = '' . "raw info" . ''; $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } {// core object list $menuItem = array(); //$menuItem['id'] = 'Obiekty'; $menuItem['nazwa'] = 'Obiekty podstawowe'; $menuItem['typ'] = 'OBJECTS'; $menuItem['tabele i widoki'] = '' . "obiekty" . ''; //$menuItem['views'] = '' . "views" . ''; $menuItem['raw info'] = '' . "parse All" . ''; // TODO: $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } {// object list - for current company $hostName = $_SERVER['SERVER_NAME']; $cleanHostName = str_replace(array(".", "-"), '_', $hostName); $menuItem = array(); //$menuItem['id'] = 'Obiekty'; $menuItem['nazwa'] = "Obiekty dla domeny '{$cleanHostName}'"; $menuItem['typ'] = 'OBJECTS'; $menuItem['tabele i widoki'] = '' . "obiekty" . ''; //$menuItem['views'] = '' . "views" . ''; //$menuItem['raw info'] = '' . "raw info" . ''; // TODO: $menuItem['xsd'] = '' . "xsd" . ''; $storageMenu[] = $menuItem; } DBG::table("storageMenu", $storageMenu, __CLASS__, __FUNCTION__, __LINE__); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function checkObjectInstallAjaxAction() { $response = array(); try { $objectName = V::get('object', '', $_REQUEST, 'word'); if (empty($objectName)) throw new Exception("Missing Object name"); $response['object'] = $objectName; $json = OBJ::getCoreObjectFromFile($objectName); OBJ::checkInstall($json); $response['type'] = 'success'; $response['msg'] = "OK - object installed"; } catch (Exception $e) { $response['type'] = 'error'; $response['msg'] = $e->getMessage(); $response['code'] = $e->getCode(); $response['line'] = $e->getLine(); } Response::sendJsonExit($response); } public function coreObjectStructAction() { UI::gora(); UI::menu(); $this->navView(); try { $objectName = V::get('object', '', $_REQUEST, 'word'); if (empty($objectName)) throw new Exception("Missing Object name"); $json = OBJ::getCoreObjectFromFile($objectName); $label = OBJ::getLabel($json); $parentList = OBJ::getParentList($json); $linksParentList = array(); foreach ($parentList as $parentName) { $parentLink = '' . $parentName . ''; array_unshift($linksParentList, $parentLink); } $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })"; $btnCheckInstall = ''; ?>
| nazwa | typ | label | json |
|---|---|---|---|
">fetchAll(" select {$sqlFields} from `{$tblName}` t where 1=1 limit 10 "); return $rows; } public function showTableWidget($tblName, $fields) { $rows = $this->getTableRows($tblName, $fields); UI::table(array('caption' => "table({$tblName})", 'rows' => $rows)); } public function coreObjectParseAllAction() { UI::gora(); UI::menu(); $this->navView(); try { OBJ::parseAll(); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function coreObjectListAction() { UI::gora(); UI::menu(); $this->navView(); try { $coreObjlist = OBJ::getCoreObjectList(); $objectList = array(); foreach ($coreObjlist as $objName) { $objItem = array(); $objItem['name'] = $objName; $objItem['struktura'] = '' . "struct" . ''; // $objItem['label'] = "";// TODO: read from json $objectList[] = $objItem; } usort($objectList, function($rowA, $rowB) { $a = $rowA['nazwa']; $b = $rowB['nazwa']; if ($a == $b) return 0; return ($a < $b) ? -1 : 1; }); DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function objectListAction() { UI::gora(); UI::menu(); try { } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function tableListAction() { UI::gora(); UI::menu(); $this->navView(); try { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); if (empty($idStorage)) throw new Exception("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'] = '' . "struct" . ''; $tblItem['xsd'] = '' . "xsd" . ''; $tblItem['objectTest'] = '' . "objectTest" . ''; $tblItem['isHist'] = ('_hist' == substr($tblName, -5)); $tblItem['uwagi'] = ''; $tblZasob = V::get($tblName, '', $tableZasobList); if ($tblZasob) { $tableZasobList[$tblName]['_checked'] = true; $tblItem['id_zasob'] = $tblZasob['ID']; } else { $tblItem['uwagi'] .= 'TODO: ADD ZASOB'; $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addTableToZasoby&idStorage={$idStorage}&tblName={$tblName}"; $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addToZasoby', { href: '{$ajaxAddZasobLink}' })"; $tblItem['id_zasob'] = 'TODO: ADD ZASOB'; } $tableList[] = $tblItem; } foreach ($viewRealList as $row) { $tblName = $row['table_name']; $tblItem = V::cloneArray($emptyItem); $tblItem['nazwa'] = $tblName; $tblItem['type'] = $row['table_type']; $tblItem['struktura'] = '' . "struct" . ''; $tblItem['uwagi'] = ''; $tblZasob = V::get($tblName, '', $tableZasobList); if ($tblZasob) { $tableZasobList[$tblName]['_checked'] = true; $tblItem['id_zasob'] = $tblZasob['ID']; } else { $tblItem['uwagi'] .= 'TODO: ADD ZASOB'; $tblItem['id_zasob'] = 'TODO: ADD ZASOB'; } $tableList[] = $tblItem; } foreach ($tableZasobList as $tblName => $row) { if (!$row['_checked']) { $tblItem = V::cloneArray($emptyItem); $tblItem['nazwa'] = $tblName; $tblItem['id_zasob'] = $row['ID']; $tblItem['type'] = 'unknown'; $tblItem['uwagi'] = 'TODO: nie istnieje w bazie danych'; $tableList[] = $tblItem; } } usort($tableList, function($rowA, $rowB) { $a = $rowA['nazwa']; $b = $rowB['nazwa']; if ($a == $b) return 0; $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1); if (('_' == $a1 || '_' == $b1) && $a1 != $b1) { return ($a1 < $b1) ? 1 : -1; } return ($a < $b) ? -1 : 1; }); DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__); ?> getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function rawInfoAction() { UI::gora(); UI::menu(); $this->navView(); try { $idStorage = V::get('idStorage', 0, $_REQUEST, 'int'); if (empty($idStorage)) throw new Exception("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:addToZasoby', { href: '{$ajaxAddZasobLink}' })"; $tblItem['id_zasob'] = 'TODO: ADD ZASOB'; } $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__); ?> 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; //