Storage.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <?php
  2. // @requires $_SERVER['SERVER_NAME']
  3. Lib::loadClass('RouteBase');
  4. Lib::loadClass('Schema_TableFactory');
  5. /*
  6. # Storage:
  7. - [ ] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
  8. - [ ] check config for connection
  9. - [ ] add cells to Zasoby
  10. - [ ] create cells in Storage
  11. - [x] use PDO
  12. */
  13. class Route_Storage extends RouteBase {
  14. public function handleAuth() {
  15. if (!User::logged()) {
  16. User::authByRequest();
  17. }
  18. }
  19. public function defaultAction() {
  20. SE_Layout::gora();
  21. SE_Layout::menu();
  22. try {
  23. $storageList = $this->getStorageList();
  24. if (empty($storageList)) throw new Exception("No storage defined");
  25. $storageMenu = array();
  26. foreach ($storageList as $storage) {
  27. $menuItem = array();
  28. $menuItem['id'] = $id = $storage['ID'];
  29. $menuItem['nazwa'] = $storage['DESC'];
  30. $menuItem['typ'] = $storage['TYPE'];
  31. $menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=tableList&idStorage=' . $id . '">' . "tabele" . '</a>';
  32. //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
  33. $menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=rawInfo&idStorage=' . $id . '">' . "raw info" . '</a>';
  34. $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
  35. $storageMenu[] = $menuItem;
  36. }
  37. $this->navView();
  38. DBG::table("storageMenu", $storageMenu, __CLASS__, __FUNCTION__, __LINE__);
  39. } catch (Exception $e) {
  40. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  41. }
  42. SE_Layout::dol();
  43. }
  44. public function tableListAction() {
  45. SE_Layout::gora();
  46. SE_Layout::menu();
  47. try {
  48. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  49. if (empty($idStorage)) throw new Exception("No id storage");
  50. $storageList = $this->getStorageList();
  51. if (empty($storageList)) throw new Exception("No storage defined");
  52. if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
  53. $this->navView();
  54. $storagePdo = DB::getStorage($idStorage);
  55. $viewRealList = $storagePdo->getViewList();
  56. $tableRealList = $storagePdo->getTableList();
  57. $tableZasobList = array();
  58. foreach (DB::getPDO()->fetchAllByKey("
  59. select z.ID, z.`DESC`, z.A_STATUS
  60. from CRM_LISTA_ZASOBOW z
  61. where z.PARENT_ID = '{$idStorage}'
  62. ", $key = 'DESC') as $ind => $row) {
  63. $tableZasobList[strtolower($ind)] = $row;
  64. }
  65. $emptyItem = array();
  66. $emptyItem['nazwa'] = '';//->urlTblStruct = $this->buildActionUrl('tableStruct', array('storageId'=>$storageId, 'tblName'=>$tblName));
  67. $emptyItem['type'] = '';
  68. $emptyItem['dodaj zasób'] = '';//->urlTblAddToZasoby = $this->buildAjaxActionUrl('addTableToZasoby', $urlParams);
  69. $emptyItem['struktura'] = '';//->urlTblRawStruct = $this->buildActionUrl('tableStructRaw', array('storageId'=>$storageId, 'tblName'=>$tblName));
  70. $emptyItem['objectTest'] = '';//->urlObjectTest = $this->buildActionUrl('objectTest', array('storageId'=>$storageId, 'tblName'=>$tblName));
  71. $emptyItem['xsd'] = '';//->urlTableXsd = $this->buildActionUrl('tableXsd', array('storageId'=>$storageId, 'tblName'=>$tblName, 'HEADER_NOT_INIT'=>'YES'));
  72. $emptyItem['id_zasob'] = '';//->zasobId = $zasobTableId;
  73. $emptyItem['isHist'] = '';//->isHistTable = ('_HIST' == substr($tblName, -5)) ? true : false;
  74. $emptyItem['uwagi'] = '';
  75. $tableList = array();
  76. foreach ($tableRealList as $row) {
  77. $tblName = $row['table_name'];
  78. $tblItem = V::cloneArray($emptyItem);
  79. $tblItem['nazwa'] = $tblName;
  80. $tblItem['type'] = $row['table_type'];
  81. $tblItem['struktura'] = '<a href="index.php?_route=Storage&_task=tableStruct&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "struct" . '</a>';
  82. $tblItem['xsd'] = '<a href="index.php?_route=Storage&_task=tableXsd&idStorage=' . $idStorage . '&table=' . $tblName . '" target="_blank">' . "xsd" . '</a>';
  83. $tblItem['objectTest'] = '<a href="index.php?_route=Storage&_task=objectTest&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "objectTest" . '</a>';
  84. $tblItem['isHist'] = ('_hist' == substr($tblName, -5));
  85. $tblItem['uwagi'] = '';
  86. $tblZasob = V::get($tblName, '', $tableZasobList);
  87. if ($tblZasob) {
  88. $tableZasobList[$tblName]['_checked'] = true;
  89. $tblItem['id_zasob'] = $tblZasob['ID'];
  90. } else {
  91. $tblItem['uwagi'] .= 'TODO: ADD ZASOB';
  92. $tblItem['dodaj zasób'] = '<a href="#">TODO: ADD ZASOB</a>';
  93. }
  94. $tableList[] = $tblItem;
  95. }
  96. foreach ($viewRealList as $row) {
  97. $tblName = $row['table_name'];
  98. $tblItem = V::cloneArray($emptyItem);
  99. $tblItem['nazwa'] = $tblName;
  100. $tblItem['type'] = $row['table_type'];
  101. $tblItem['struktura'] = '<a href="index.php?_route=Storage&_task=viewStruct&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "struct" . '</a>';
  102. $tblItem['uwagi'] = '';
  103. $tblZasob = V::get($tblName, '', $tableZasobList);
  104. if ($tblZasob) {
  105. $tableZasobList[$tblName]['_checked'] = true;
  106. $tblItem['id_zasob'] = $tblZasob['ID'];
  107. } else {
  108. $tblItem['uwagi'] .= 'TODO: ADD ZASOB';
  109. $tblItem['dodaj zasób'] = '<a href="#">TODO: ADD ZASOB</a>';
  110. }
  111. $tableList[] = $tblItem;
  112. }
  113. foreach ($tableZasobList as $tblName => $row) {
  114. if (!$row['_checked']) {
  115. $tblItem = V::cloneArray($emptyItem);
  116. $tblItem['nazwa'] = $tblName;
  117. $tblItem['id_zasob'] = $row['ID'];
  118. $tblItem['type'] = 'unknown';
  119. $tblItem['uwagi'] = 'TODO: nie istnieje w bazie danych';
  120. $tableList[] = $tblItem;
  121. }
  122. }
  123. DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
  124. } catch (Exception $e) {
  125. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  126. }
  127. SE_Layout::dol();
  128. }
  129. public function rawInfoAction() {
  130. SE_Layout::gora();
  131. SE_Layout::menu();
  132. try {
  133. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  134. if (empty($idStorage)) throw new Exception("No id storage");
  135. $storageList = $this->getStorageList();
  136. if (empty($storageList)) throw new Exception("No storage defined");
  137. if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
  138. $this->navView();
  139. $storagePdo = DB::getStorage($idStorage);
  140. $rawInfo = $storagePdo->getTableListWithInfo();
  141. DBG::table("rawInfo", $rawInfo, __CLASS__, __FUNCTION__, __LINE__);
  142. } catch (Exception $e) {
  143. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  144. }
  145. SE_Layout::dol();
  146. }
  147. public function tableStructAction() {
  148. SE_Layout::gora();
  149. SE_Layout::menu();
  150. try {
  151. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  152. if (empty($idStorage)) throw new Exception("No id storage");
  153. $storageList = $this->getStorageList();
  154. if (empty($storageList)) throw new Exception("No storage defined");
  155. if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
  156. $tblName = V::get('table', '', $_REQUEST, 'word');
  157. if (empty($tblName)) throw new Exception("No table name");
  158. $this->navView();
  159. $storagePdo = DB::getStorage($idStorage);
  160. $tblStruct = $storagePdo->getTableStruct($tblName);
  161. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  162. } catch (Exception $e) {
  163. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  164. }
  165. SE_Layout::dol();
  166. }
  167. public function xsdAction() {
  168. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  169. $storage = DB::getStorage($idStorage);
  170. $tableRealList = $storage->getTableList();
  171. $srvName = $_SERVER['SERVER_NAME'];
  172. $storageZasobId = $storage->getZasobId();
  173. $objNs = "p5_{$storageZasobId}_{$tblName}";
  174. $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}";
  175. $p5TypePrefix = "p5Type";
  176. $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types";
  177. $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd";
  178. header('Content-type: text/plain; charset=utf-8');// TODO: test
  179. //header('Content-type: application/xml; charset=utf-8');
  180. $xmlWriter = new XMLWriter();
  181. $xmlWriter->openUri('php://output');
  182. $xmlWriter->setIndent(true);
  183. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  184. $xmlWriter->startDocument('1.0', 'UTF-8');
  185. $xmlWriter->startElement('xs:schema');
  186. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  187. $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning');
  188. $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri);
  189. $xmlWriter->writeAttribute('elementFormDefault', 'qualified');
  190. $xmlWriter->writeAttribute('targetNamespace', $objNsUri);
  191. $xmlWriter->writeAttribute('vc:minVersion', '1.1');
  192. $xmlWriter->startElement('xs:import');
  193. $xmlWriter->writeAttribute('namespace', $p5TypeNsUri);
  194. $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation);
  195. $xmlWriter->endElement();// xs:import
  196. foreach ($tableRealList as $tbl) {
  197. $tblName = $tbl['table_name'];
  198. $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName);
  199. }
  200. $xmlWriter->endElement();// xs:schema
  201. $xmlWriter->endDocument();
  202. }
  203. public function tableXsdAction() {
  204. $idStorage = V::get('idStorage', '', $_GET);
  205. $tblName = V::get('table', '', $_GET, 'word');
  206. if (empty($tblName)) die("Wrong table name");
  207. header('Content-type: text/plain; charset=utf-8');// TODO: test
  208. $storage = DB::getStorage($idStorage);
  209. $storageZasobId = $storage->getZasobId();
  210. $objNs = "p5_{$storageZasobId}_{$tblName}";
  211. $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}";
  212. $p5TypePrefix = "p5Type";
  213. $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types";
  214. $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd";
  215. //header('Content-type: application/xml; charset=utf-8');
  216. $xmlWriter = new XMLWriter();
  217. $xmlWriter->openUri('php://output');
  218. $xmlWriter->setIndent(true);
  219. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  220. $xmlWriter->startDocument('1.0', 'UTF-8');
  221. $xmlWriter->startElement('xs:schema');
  222. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  223. $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning');
  224. $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri);
  225. $xmlWriter->writeAttribute('elementFormDefault', 'qualified');
  226. $xmlWriter->writeAttribute('targetNamespace', $objNsUri);
  227. $xmlWriter->writeAttribute('vc:minVersion', '1.1');
  228. $xmlWriter->startElement('xs:import');
  229. $xmlWriter->writeAttribute('namespace', $p5TypeNsUri);
  230. $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation);
  231. $xmlWriter->endElement();// xs:import
  232. $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName);
  233. $xmlWriter->endElement();// xs:schema
  234. $xmlWriter->endDocument();
  235. }
  236. public function tableXsdViewXmlWriter(&$xmlWriter, $idStorage, $tblName) {
  237. $storage = DB::getStorage($idStorage);
  238. $schema = Schema_TableFactory::build($tblName, $idStorage, $_SERVER['SERVER_NAME']);
  239. $struct = $schema->getStruct();
  240. DBG::_('DBG', '>1', "struct", $struct, __CLASS__, __FUNCTION__, __LINE__);
  241. $typeName = "{$tblName}Type";
  242. $xmlWriter->startElement('xs:complexType');
  243. $xmlWriter->writeAttribute('name', $typeName);
  244. $xmlWriter->startElement('xs:sequence');
  245. foreach ($struct as $field) {
  246. $xmlWriter->startElement('xs:element');
  247. $xmlWriter->writeAttribute('name', $field['name']);
  248. $xmlWriter->writeAttribute('minOccurs', 0);// TODO: set minOccurs by default, etc.
  249. if ($field['is_nullable']) $xmlWriter->writeAttribute('nillable', 'true');
  250. if (null !== $field['default_value']) {
  251. $xmlWriter->writeAttribute('default', $field['default_value']);
  252. } else if (null === $field['default_value'] && $field['is_nullable']) {
  253. $xmlWriter->writeAttribute('default', $field['default_value']);
  254. } else {
  255. // TODO: Schema BUG?
  256. }
  257. if (empty($field['p5_restrictions'])) {
  258. $xmlWriter->writeAttribute('type', "p5Type:{$field['p5_type']}");
  259. } else {
  260. $xmlWriter->startElement('xs:simpleType');
  261. $xmlWriter->writeAttribute('base', "p5Type:{$field['p5_type']}");
  262. $xmlWriter->startElement('xs:restriction');
  263. if (!empty($field['p5_restrictions']['enumeration'])) {
  264. foreach ($field['p5_restrictions']['enumeration'] as $enumValue) {
  265. $xmlWriter->startElement('xs:enumeration');
  266. $xmlWriter->writeAttribute('value', $enumValue);
  267. $xmlWriter->endElement();// xs:enumeration
  268. }
  269. } else {
  270. // TODO: another restrictions...
  271. }
  272. $xmlWriter->endElement();// xs:restriction
  273. $xmlWriter->endElement();// xs:simpleType
  274. }
  275. $xmlWriter->endElement();// xs:element
  276. }
  277. $xmlWriter->endElement();// xs:sequence
  278. $xmlWriter->endElement();// xs:complexType
  279. return;
  280. // <xs:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xs:integer"/>
  281. $pKeyField = 'ID';//$storageObject->getPrimaryKeyFieldName();
  282. //DBG::_(true, true, "struct", $struct, __CLASS__, __FUNCTION__, __LINE__);
  283. foreach ($struct as $field) {
  284. $fldName = $vField->getName();
  285. $fldType = $vField->getType();
  286. $xsdType = $fldType->getTypeForXsd();
  287. if ($fldType->hasDefault()) {
  288. $fldDefault = $fldType->getDefault();
  289. if (!empty($fldDefault) || '0' === $fldDefault) {
  290. $elNode->setAttribute('default', $fldDefault);
  291. }
  292. }
  293. $fldRestrictions = $fldType->getRestrictions();
  294. if (empty($fldRestrictions)) {
  295. $elNode->setAttribute('type', "{$p5TypePrefix}:{$xsdType}");
  296. } else {
  297. $sType = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:simpleType');
  298. $elNode->appendChild($sType);
  299. $sTypeRes = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:restriction');
  300. $sType->appendChild($sTypeRes);
  301. $sTypeRes->setAttribute('base', "{$p5TypePrefix}:{$xsdType}");
  302. $enumList = $fldType->getEnumeration();
  303. if (empty($enumList)) {
  304. foreach ($fldRestrictions as $restricionName => $restrictionValue) {
  305. if ('maxLength' == $restricionName) {
  306. $sTypeResMaxLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxLength');
  307. $sTypeRes->appendChild($sTypeResMaxLength);
  308. $sTypeResMaxLength->setAttribute('value', $restrictionValue);
  309. } else if ('minLength' == $restricionName) {
  310. $sTypeResMinLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minLength');
  311. $sTypeRes->appendChild($sTypeResMinLength);
  312. $sTypeResMinLength->setAttribute('value', $restrictionValue);
  313. } else if ('pattern' == $restricionName) {
  314. $sTypeResPattern = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:pattern');
  315. $sTypeRes->appendChild($sTypeResPattern);
  316. $sTypeResPattern->setAttribute('value', $restrictionValue);
  317. } else if ('fractionDigits' == $restricionName) {
  318. $sTypeResFractionDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:fractionDigits');
  319. $sTypeRes->appendChild($sTypeResFractionDigits);
  320. $sTypeResFractionDigits->setAttribute('value', $restrictionValue);
  321. } else if ('totalDigits' == $restricionName) {
  322. $sTypeResTotalDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:totalDigits');
  323. $sTypeRes->appendChild($sTypeResTotalDigits);
  324. $sTypeResTotalDigits->setAttribute('value', $restrictionValue);
  325. } else if ('maxExclusive' == $restricionName) {
  326. $sTypeResMaxExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxExclusive');
  327. $sTypeRes->appendChild($sTypeResMaxExclusive);
  328. $sTypeResMaxExclusive->setAttribute('value', $restrictionValue);
  329. } else if ('minExclusive' == $restricionName) {
  330. $sTypeResMinExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minExclusive');
  331. $sTypeRes->appendChild($sTypeResMinExclusive);
  332. $sTypeResMinExclusive->setAttribute('value', $restrictionValue);
  333. } else if ('maxInclusive' == $restricionName) {
  334. $sTypeResMaxInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxInclusive');
  335. $sTypeRes->appendChild($sTypeResMaxInclusive);
  336. $sTypeResMaxInclusive->setAttribute('value', $restrictionValue);
  337. } else if ('minInclusive' == $restricionName) {
  338. $sTypeResMinInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minInclusive');
  339. $sTypeRes->appendChild($sTypeResMinInclusive);
  340. $sTypeResMinInclusive->setAttribute('value', $restrictionValue);
  341. }
  342. /* TODO: xsd restrictions:
  343. enumeration Defines a list of acceptable values
  344. fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
  345. length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
  346. maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
  347. maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
  348. maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero
  349. minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
  350. minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
  351. minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero
  352. pattern Defines the exact sequence of characters that are acceptable
  353. totalDigits Specifies the exact number of digits allowed. Must be greater than zero
  354. whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
  355. */
  356. }
  357. } else {
  358. foreach ($enumList as $enumValue) {
  359. $sTypeResEnum = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:enumeration');
  360. $sTypeRes->appendChild($sTypeResEnum);
  361. $sTypeResEnum->setAttribute('value', $enumValue);
  362. }
  363. }
  364. }
  365. }
  366. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:element');
  367. $rootNode->appendChild($elNode);
  368. $elNode->setAttribute('name', $tblName);
  369. $elNode->setAttribute('type', "{$objNs}:{$typeName}");
  370. header('Content-type: application/xml');
  371. echo $dom->saveXML();
  372. exit;
  373. }
  374. public function navView() {
  375. $backLabel = 'back';
  376. $backLink = 'index.php?_route=Storage';
  377. $backDisabled = true;
  378. $currentLabel = 'Storage';
  379. $currentLink = 'index.php?_route=Storage';
  380. if ($task = V::get('_task', '', $_REQUEST)) {
  381. $currentLink = "index.php?_route=Storage&_task={$task}";
  382. $backDisabled = false;
  383. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  384. $tblName = V::get('table', '', $_REQUEST, 'word');
  385. switch ($task) {
  386. case 'tableList':
  387. case 'viewList':
  388. case 'rawInfo':
  389. $backLabel = 'Storage';
  390. $backLink = 'index.php?_route=Storage';
  391. $currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}";
  392. break;
  393. case 'tableStruct':
  394. $backLabel = "Tabele [{$idStorage}]";
  395. $backLink = "index.php?_route=Storage&_task=tableList&idStorage={$idStorage}";
  396. $currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}&table={$tblName}";
  397. break;
  398. }
  399. switch ($task) {
  400. case 'tableList': $currentLabel = "Tabele [{$idStorage}]"; break;
  401. case 'viewList': $currentLabel = "Widoki [{$idStorage}]"; break;
  402. case 'rawInfo': $currentLabel = "Raw info [{$idStorage}]"; break;
  403. case 'tableStruct': $currentLabel = "Struktura tabeli '{$tblName}'"; break;
  404. }
  405. }
  406. ?>
  407. <nav class="navbar navbar-default navbar-static-top">
  408. <div class="container-fluid">
  409. <div class="navbar-left">
  410. <ul class="nav navbar-nav navbar-center">
  411. <li><a href="<?php echo $backLink; ?>" class="btn <?php echo ($backDisabled)? 'disabled' : ''; ?>"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo $backLabel; ?></a></li>
  412. </ul>
  413. </div>
  414. <div class="navbar-left">
  415. <ul class="nav navbar-nav navbar-center">
  416. <li><a class="btn" href="<?php echo $currentLink; ?>"><?php echo $currentLabel; ?></a></li>
  417. </ul>
  418. </div>
  419. <div class="navbar-right">
  420. <!--
  421. <ul class="nav navbar-nav navbar-right">
  422. <li><a href="#">Link</a></li>
  423. <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>
  424. <ul class="dropdown-menu">
  425. <li><a href="#">Action</a></li>
  426. <li><a href="#">Another action</a></li>
  427. <li><a href="#">Something else here</a></li>
  428. <li role="separator" class="divider"></li>
  429. <li><a href="#">Separated link</a></li>
  430. </ul>
  431. </li>
  432. </ul>
  433. -->
  434. </div>
  435. </div>
  436. </nav>
  437. <?php
  438. }
  439. public function getStorageList() {
  440. $storageList = array();
  441. $sth = DB::getPDO()->prepare("
  442. select z.ID, z.`DESC`, z.`TYPE`
  443. from CRM_LISTA_ZASOBOW z
  444. where z.TYPE in('BAZA_DANYCH','DATABASE_MYSQL','DATABASE_POSTGRESQL')
  445. ");
  446. $sth->execute();
  447. $rows = $sth->fetchAll();
  448. foreach ($rows as $row) {
  449. $storageList[$row['ID']] = $row;
  450. }
  451. return $storageList;
  452. }
  453. }