Storage.php 24 KB

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