Data_Source.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. <?php
  2. Lib::loadClass('SqlQueryWhereBuilder');
  3. /**
  4. * API:
  5. * get($field_name) - source field value
  6. * get_item($id) - get item by ID
  7. */
  8. class Data_Source {
  9. var $_db;
  10. var $_tbl;// sql table name, TODO: or zasob ID
  11. var $_default_sql_limit;
  12. var $_fields_type;// array of fields ( name => type )
  13. var $_fields_perm;// array of field perm ( name => perm )
  14. var $_cols = array();
  15. var $_vCols = array();// setVirtualCols - TODO: use Typespecial
  16. var $_col_types = array();// TODO: array( col_name => TYPE )
  17. var $_sql_where;// sql where
  18. var $_sql_limit;
  19. var $_sql_offset;
  20. var $_sql_left_join;// TODO: left join in table
  21. var $_isAccessFltrAllowed = null;
  22. private $_geomFields = array();
  23. private $_fieldOwner = null;
  24. private $_fieldGroupWrite = null;
  25. private $_fieldGroupRead = null;
  26. function __construct($db = null) {
  27. if ($db) {
  28. $this->_db = DB::getDB($db);
  29. } else {
  30. $this->_db = DB::getDB();
  31. }
  32. $this->_default_sql_limit = 10;
  33. $this->_geomFields = array('the_geom');
  34. }
  35. function set_table($tbl) {// TODO: RMME
  36. $this->setTable($tbl);
  37. }
  38. public function setTable($tbl) {
  39. $this->_tbl = $tbl;
  40. $this->_fields_type = array();
  41. $this->_fields_perm = array();
  42. }
  43. function get_cols() {
  44. // TODO: cache in session
  45. if (empty($this->_cols)) {
  46. if (!$this->_tbl) {
  47. return $this->_tbl;
  48. }
  49. $sql = "show fields from `{$this->_tbl}` ; ";
  50. $res = $this->_db->query($sql);
  51. while ($r = $this->_db->fetch($res)) {
  52. $this->_cols[$r->Field] = $r->Field;
  53. $this->_col_types[$r->Field] = $r->Type . ';' . $r->Default;
  54. }
  55. }
  56. return $this->_cols;
  57. }
  58. public function getFieldTypes() {
  59. $fieldTypes = array();
  60. //$dbID = $this->getDB();
  61. $db = $this->_db;//(TableAcl) DB::getDB($dbID);
  62. $tblName = $this->_tbl;//(TableAcl) $this->getName();
  63. if (!$db) {
  64. throw new Exception('DataSource is not defined');
  65. }
  66. $res = $db->query("show fields from `{$tblName}` ");
  67. while ($h = $db->fetch_row($res)) {
  68. $fieldName = $h[0];
  69. $fieldType = $h[1];
  70. $fieldTypes[$fieldName] = array('type'=>$h[1], 'null'=>('YES' == $h[2]), 'default'=>$h[4]);
  71. }
  72. return $fieldTypes;
  73. }
  74. public function getUniqueKeys() {
  75. $sqlKeys = array();
  76. //$dbID = $this->getDB();
  77. $db = $this->_db;//(TableAcl) DB::getDB($dbID);
  78. $tblName = $this->_tbl;//(TableAcl) $this->getName();
  79. if (!$db) {
  80. throw new Exception('DataSource is not defined');
  81. }
  82. $sql = "SHOW KEYS FROM `{$tblName}`";
  83. $res = $db->query($sql);
  84. while ($r = $db->fetch($res)) {
  85. if ($r->Non_unique == '0') {
  86. $sqlKeys[$r->Column_name] = true;
  87. }
  88. }
  89. $sqlKeys = array_keys($sqlKeys);
  90. return $sqlKeys;
  91. }
  92. function set_cols($cols) {// TODO: RMME
  93. $this->setCols($cols);
  94. }
  95. function setCols($cols) {
  96. foreach ($cols as $v_field_name) {
  97. $this->_cols[$v_field_name] = $v_field_name;
  98. }
  99. }
  100. public function setColTypes($types) {
  101. $this->_col_types = $types;
  102. // TableAcl->getTypes(): $this->_types[$fieldName] = array('type'=>$h[1], 'null'=>('YES' == $h[2]), 'default'=>$h[4]);
  103. }
  104. public function getColDefault($fieldName) {
  105. $fldType = V::get($fieldName, '', $this->_col_types);
  106. if (!$fldType) return '';
  107. return V::get('default', '', $fldType);
  108. }
  109. function setVirtualCols($cols) {
  110. foreach ($cols as $v_field_name) {
  111. $this->_vCols[$v_field_name] = $v_field_name;
  112. }
  113. }
  114. public function setFieldGroupWrite($fieldName, $fieldExists = false) {
  115. if ($fieldExists) {
  116. $this->_fieldGroupWrite = $fieldName;
  117. $this->_cols[$fieldName] = $fieldName;
  118. }
  119. }
  120. public function setFieldGroupRead($fieldName, $fieldExists = false) {
  121. if ($fieldExists) {
  122. $this->_fieldGroupRead = $fieldName;
  123. $this->_cols[$fieldName] = $fieldName;
  124. }
  125. }
  126. public function setFieldOwner($fieldName, $fieldExists = false) {
  127. if ($fieldExists) {
  128. $this->_fieldOwner = $fieldName;
  129. $this->_cols[$fieldName] = $fieldName;
  130. }
  131. }
  132. public function getFieldGroupWrite() {
  133. return $this->_fieldGroupWrite;
  134. }
  135. public function getFieldGroupRead() {
  136. return $this->_fieldGroupRead;
  137. }
  138. public function getFieldOwner() {
  139. return $this->_fieldOwner;
  140. }
  141. function _get_sql_cols() {
  142. $sql_cols = "t.*";
  143. if (!empty($this->_cols)) {
  144. $sql_cols_arr = array();
  145. foreach ($this->_cols as $k_field => $v_field_label) {
  146. if ($this->isGeomField($k_field)) {
  147. $sqlFld = "AsWKT(t.`{$k_field}`) as {$k_field}";
  148. } else {
  149. $sqlFld = "t.`{$k_field}`";
  150. }
  151. $sql_cols_arr[] = $sqlFld;
  152. }
  153. $sql_cols = implode(", ", $sql_cols_arr);
  154. }
  155. if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql_cols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql_cols);echo'</pre>'."\n\n";}
  156. return $sql_cols;
  157. }
  158. public function setAccessFltrAllowed($isAccessFltrAllowed) {
  159. $this->_isAccessFltrAllowed = $isAccessFltrAllowed;
  160. }
  161. public function isAccessFltrAllowed() {
  162. if (false === $this->_isAccessFltrAllowed) {
  163. return false;
  164. }
  165. else if ($this->hasAclGroupFields()) {
  166. return true;
  167. }
  168. return false;
  169. }
  170. public function hasAclGroupFields() {
  171. if ( !empty($this->_fieldGroupWrite)
  172. && !empty($this->_fieldGroupRead)
  173. && array_key_exists('A_ADM_COMPANY', $this->_cols)
  174. && array_key_exists('A_CLASSIFIED', $this->_cols)
  175. ) {
  176. return true;
  177. }
  178. return false;
  179. }
  180. function getSpecialFilters() {
  181. $fltrs = array();
  182. if (array_key_exists('A_PROBLEM', $this->_cols)) {
  183. $fltrs['Problemy'] = new stdClass();
  184. $fltrs['Problemy']->icon = 'glyphicon glyphicon-warning-sign';
  185. $fltrs['Problemy']->btns = array();
  186. $fltrs['Problemy']->btns['PROBLEMY'] = (object)array('value'=>'PROBLEM');
  187. $fltrs['Problemy']->btns['OSTRZEZENIA'] = (object)array('value'=>'WARNING');
  188. $fltrs['Problemy']->btns['BEZ_PROBLEM.'] = (object)array('value'=>'NORMAL');
  189. }
  190. if (array_key_exists('A_STATUS', $this->_cols)) {
  191. $fltrs['Status'] = new stdClass();
  192. $fltrs['Status']->icon = 'glyphicon glyphicon-question-sign';
  193. $fltrs['Status']->btns = array();
  194. $fltrs['Status']->btns['OCZEKUJACY'] = (object)array('value'=>'WAITING');
  195. $fltrs['Status']->btns['AKTYWNI'] = (object)array('value'=>'AKTYWNI');
  196. }
  197. if (array_key_exists('L_APPOITMENT_DATE', $this->_cols)) {
  198. $fltrs['Spotkania'] = new stdClass();
  199. $fltrs['Spotkania']->icon = 'glyphicon glyphicon-calendar';
  200. $fltrs['Spotkania']->btns = array();
  201. $fltrs['Spotkania']->btns['STARE'] = (object)array('value'=>'OLD');
  202. $fltrs['Spotkania']->btns['ZARAZ'] = (object)array('value'=>'NOW');
  203. $fltrs['Spotkania']->btns['DZISIAJ'] = (object)array('value'=>'TODAY');
  204. $fltrs['Spotkania']->btns['BRAK'] = (object)array('value'=>'BRAK');
  205. }
  206. if ($this->isAccessFltrAllowed()) {
  207. $fltrs['Access'] = new stdClass();
  208. $fltrs['Access']->icon = 'glyphicon glyphicon-lock';
  209. $fltrs['Access']->btns = array();
  210. $fltrs['Access']->btns['Pokaż'] = (object)array('value'=>'SHOW');
  211. }
  212. return $fltrs;
  213. }
  214. public function _parseOgcFilter($ogcFilter) {
  215. $ogcFilterXmlString = <<<OGC_FILTER_XML_FILE
  216. <?xml version="1.0" encoding="UTF-8"?>
  217. <filter xmlns="https://biuro.biall-net.pl/SE/version-git/schema/filter.xsd"
  218. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  219. xmlns:ogc="http://www.opengis.net/ogc">
  220. {$ogcFilter}
  221. </filter>
  222. OGC_FILTER_XML_FILE;
  223. $convertedGuiXml = $this->_convertGuiXmlToCmdList($ogcFilterXmlString);
  224. DBG::_('DBG_DS_OGC', '>1', "convertedGuiXml(".strlen($convertedGuiXml).")", $convertedGuiXml, __CLASS__, __FUNCTION__, __LINE__);
  225. $tags = array();
  226. $parserXml = xml_parser_create();
  227. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  228. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  229. if (0 == xml_parse_into_struct($parserXml, $convertedGuiXml, $tags)) {
  230. throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction failed");
  231. }
  232. xml_parser_free($parserXml);
  233. if (empty($tags)) {
  234. throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction returns empty structure");
  235. }
  236. $queryWhereBuilder = new SqlQueryWhereBuilder();
  237. foreach ($tags as $tag) {
  238. switch ($tag['tag']) {
  239. case 'filter': {// root tag
  240. }
  241. break;
  242. case 'sql_filter_comparisonFieldToValue': {
  243. $fieldName = V::get('fieldName', '', $tag['attributes']);
  244. $comparisonSign = V::get('comparisonSign', '', $tag['attributes']);
  245. $value = V::get('value', '', $tag['attributes']);
  246. $queryWhereBuilder->addComparisonFieldToValue($fieldName, $comparisonSign, $value);
  247. }
  248. break;
  249. case 'sql_filter_openBlock': {
  250. $blockType = V::get('type', '', $tag['attributes']);
  251. DBG::_('DBG_DS_OGC', '>2', "sql_filter_openBlock block Type {$blockType} attrs", json_encode($tag), __CLASS__, __FUNCTION__, __LINE__);
  252. $queryWhereBuilder->openBlock($blockType);
  253. }
  254. break;
  255. case 'sql_filter_closeBlock': {
  256. $blockType = V::get('type', '', $tag['attributes']);
  257. $queryWhereBuilder->closeBlock($blockType);
  258. }
  259. break;
  260. default: {
  261. DBG::_('DBG_DS_OGC', '>1', "TODO: tag {$tag['tag']}", $queryWhereBuilder, __CLASS__, __FUNCTION__, __LINE__);
  262. throw new Exception("TODO: tag {$tag['tag']}");
  263. }
  264. }
  265. }
  266. $queryWhereBuilder->parseQueryWhere();
  267. DBG::_('DBG_DS_OGC', '>1', "queryWhereBuilder", $queryWhereBuilder, __CLASS__, __FUNCTION__, __LINE__);
  268. return $queryWhereBuilder->getQueryWhere('t');
  269. }
  270. public function _convertGuiXmlToCmdList($ogcFilterXmlString) {
  271. $convertOgcFilterXslString = <<<XSL_CONVERT_OGC_FILTER_TO_XML_TASK_LIST
  272. <?xml version="1.0" encoding="UTF-8"?>
  273. <xsl:stylesheet version="1.0"
  274. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  275. xmlns:filter="https://biuro.biall-net.pl/SE/version-git/schema/filter.xsd"
  276. xmlns:ogc="http://www.opengis.net/ogc"
  277. >
  278. <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
  279. <xsl:template match="/">
  280. <xsl:element name="filter">
  281. <xsl:apply-templates select="filter:filter/ogc:Filter"/>
  282. </xsl:element>
  283. </xsl:template>
  284. <xsl:template match="ogc:Filter">
  285. <xsl:apply-templates/>
  286. </xsl:template>
  287. <xsl:template match="ogc:Or">
  288. <xsl:element name="sql_filter_openBlock">
  289. <xsl:attribute name="type"><xsl:value-of select="'or'" /></xsl:attribute>
  290. </xsl:element>
  291. <xsl:apply-templates/>
  292. <xsl:element name="sql_filter_closeBlock">
  293. <xsl:attribute name="type"><xsl:value-of select="'or'" /></xsl:attribute>
  294. </xsl:element>
  295. </xsl:template>
  296. <xsl:template match="ogc:And">
  297. <xsl:element name="sql_filter_openBlock">
  298. <xsl:attribute name="type"><xsl:value-of select="'and'" /></xsl:attribute>
  299. </xsl:element>
  300. <xsl:apply-templates/>
  301. <xsl:element name="sql_filter_closeBlock">
  302. <xsl:attribute name="type"><xsl:value-of select="'and'" /></xsl:attribute>
  303. </xsl:element>
  304. </xsl:template>
  305. <xsl:template match="ogc:PropertyIsEqualTo">
  306. <xsl:element name="sql_filter_comparisonFieldToValue">
  307. <xsl:attribute name="fieldName"><xsl:value-of select="ogc:PropertyName" /></xsl:attribute>
  308. <xsl:attribute name="comparisonSign"><xsl:value-of select="'='" /></xsl:attribute>
  309. <xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
  310. </xsl:element>
  311. </xsl:template>
  312. </xsl:stylesheet>
  313. XSL_CONVERT_OGC_FILTER_TO_XML_TASK_LIST;
  314. $requestXml = new DOMDocument();
  315. $requestXml->loadXml($ogcFilterXmlString);
  316. $convertOgcFilterXsl = new DOMDocument();
  317. $convertOgcFilterXsl->loadXml($convertOgcFilterXslString);
  318. $proc = new XSLTProcessor();
  319. $proc->importStylesheet($convertOgcFilterXsl);
  320. return $proc->transformToXML($requestXml);
  321. }
  322. function _parseSpecialFilter($fltr, $value) {
  323. $sqlFltr = "";
  324. switch ($fltr) {
  325. case 'Problemy':
  326. if (array_key_exists('A_PROBLEM', $this->_cols)) {
  327. switch ($value) {
  328. case 'PROBLEM':
  329. $sqlFltr = " t.`A_PROBLEM`!='' ";
  330. break;
  331. case 'WARNING':
  332. $sqlFltr = " t.`A_PROBLEM`='WARNING' ";
  333. break;
  334. case 'NORMAL':
  335. $sqlFltr = " t.`A_PROBLEM`='' ";
  336. break;
  337. }
  338. }
  339. break;
  340. case 'Status':
  341. if (array_key_exists('A_STATUS', $this->_cols)) {
  342. switch ($value) {
  343. case 'WAITING':
  344. $sqlFltr = " t.`A_STATUS`='WAITING' ";
  345. break;
  346. case 'AKTYWNI':
  347. $sqlFltr = " t.`A_STATUS` in('NORMAL', 'WARNING') ";
  348. // TODO: $_SESSION['USERS_FILTER_STATUS_SQL']="and (( $thiss->DETECT_TABLE_NAME.A_STATUS='NORMAL' or $thiss->DETECT_TABLE_NAME.A_STATUS='WARNING' ) or ( $thiss->DETECT_TABLE_NAME.A_STATUS='OFF_SOFT' and $thiss->DETECT_TABLE_NAME.A_PROBLEM_DESC not like '%odla%fizy%' and $thiss->DETECT_TABLE_NAME.A_PROBLEM!='' ) or ( $thiss->DETECT_TABLE_NAME.A_STATUS='OFF_SOFT' and $thiss->DETECT_TABLE_NAME.A_PROBLEM='' )) ";
  349. // if ($thiss->DETECT_TABLE_NAME == 'KSIEG_DOKUMENTY') $_SESSION['USERS_FILTER_STATUS_SQL']="and ( $thiss->DETECT_TABLE_NAME.A_STATUS='NORMAL' or $thiss->DETECT_TABLE_NAME.A_STATUS='WARNING' ) ";
  350. break;
  351. }
  352. }
  353. break;
  354. case 'Spotkania':
  355. if (array_key_exists('L_APPOITMENT_DATE', $this->_cols)) {
  356. switch ($value) {
  357. case 'OLD':
  358. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<UNIX_TIMESTAMP(now()) and t.`L_APPOITMENT_DATE`!='' ";
  359. break;
  360. case 'NOW':
  361. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<UNIX_TIMESTAMP(now())+3600 and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>UNIX_TIMESTAMP(now())-3600 ";
  362. break;
  363. case 'TODAY':
  364. $start = mktime(0,0,0, date("m"), date("d"), date("Y"));
  365. $end = mktime(0,0,0, date("m"), date("d") + 1, date("Y"));
  366. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
  367. break;
  368. case 'TOMORROW':
  369. $start = mktime(0,0,0, date("m"), date("d") + 1, date("Y"));
  370. $end = mktime(0,0,0, date("m"), date("d") + 2, date("Y"));
  371. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
  372. break;
  373. case 'YESTERDAY':
  374. $start = mktime(0,0,0, date("m"), date("d") - 1, date("Y"));
  375. $end = mktime(0,0,0, date("m"), date("d") - 2, date("Y"));
  376. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
  377. break;
  378. case 'BRAK':
  379. $start = mktime(0,0,0, date("m"), date("d") - 1, date("Y"));
  380. $end = mktime(0,0,0, date("m"), date("d") - 2, date("Y"));
  381. $sqlFltr = " t.`L_APPOITMENT_DATE`='' ";
  382. break;
  383. }
  384. }
  385. break;
  386. case 'Access':
  387. if ('SHOW' != $value && $this->isAccessFltrAllowed()) {
  388. $userLogin = User::getLogin();
  389. $usrAclGroups = User::getLdapGroupsNames();
  390. $usrAclGroups[] = '';// TODO: allow empty for everyone?
  391. $sqlUsrAclGroups = "'" . implode("','", $usrAclGroups) . "'";
  392. $sqlFltr = "
  393. t.`{$this->_fieldGroupWrite}` in({$sqlUsrAclGroups})
  394. and t.`{$this->_fieldGroupRead}` in({$sqlUsrAclGroups})
  395. ";
  396. if (array_key_exists('L_APPOITMENT_USER', $this->_cols)) {
  397. $sqlFltr = "
  398. (
  399. ({$sqlFltr})
  400. or t.`L_APPOITMENT_USER`='{$userLogin}'
  401. )
  402. ";
  403. }
  404. }
  405. break;
  406. default:
  407. }
  408. /*
  409. //USERS_FILTER_PROBLEM
  410. // PROBLEMY https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_PROBLEM&USERS_FILTER_PROBLEM=PROBLEM
  411. // OSTRZEZENIA https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_PROBLEM&USERS_FILTER_PROBLEM=WARNING
  412. // BEZ_PROBLEM. https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_PROBLEM&USERS_FILTER_PROBLEM=NORMAL
  413. // KASUJ-FILTR https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_PROBLEM&USERS_FILTER_PROBLEM=
  414. //USERS_FILTER_STATUS
  415. // OCZEKUJACY https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_STATUS&USERS_FILTER_STATUS=WAITING
  416. // AKTYWNI https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_STATUS&USERS_FILTER_STATUS=AKTYWNI
  417. // KASUJ-FILTR https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_STATUS&USERS_FILTER_STATUS=
  418. //USERS_FILTER_APPOINTMENT
  419. // A_STARE https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_APPOINTMENT&USERS_FILTER_APPOINTMENT=OLD
  420. // A_ZARAZ https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_APPOINTMENT&USERS_FILTER_APPOINTMENT=NOW
  421. // A_DZISIAJ https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_APPOINTMENT&USERS_FILTER_APPOINTMENT=TODAY
  422. // APP_ALL https://biuro.biall-net.pl/SE/se-dev/index.php?FUNCTION_INIT=USERS_FILTER_APPOINTMENT&USERS_FILTER_APPOINTMENT=
  423. // btn class: active, disabled
  424. {// USERS_FILTER_PROBLEM
  425. var groupHtml = $('<div class="btn-group"></div>');
  426. $('<button class="btn btn-xs" title="Problemy"><i class="glyphicon glyphicon-warning-sign"></i></button>').appendTo(groupHtml);
  427. $('<button class="btn btn-xs">PROBLEMY</button>').appendTo(groupHtml);
  428. $('<button class="btn btn-xs">OSTRZEZENIA</button>').appendTo(groupHtml);
  429. $('<button class="btn btn-xs active">BEZ_PROBLEM.</button>').appendTo(groupHtml);
  430. $('<button class="btn btn-xs disabled" title="Kasuj filtr"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupHtml);
  431. groupHtml.appendTo(_headSpecialFilter);
  432. }
  433. {// USERS_FILTER_STATUS
  434. var groupHtml = $('<div class="btn-group"></div>');
  435. $('<button class="btn btn-xs" title="Status"><i class="glyphicon glyphicon-question-sign"></i></button>').appendTo(groupHtml);
  436. $('<button class="btn btn-xs">OCZEKUJACY</button>').appendTo(groupHtml);
  437. $('<button class="btn btn-xs">AKTYWNI</button>').appendTo(groupHtml);
  438. $('<button class="btn btn-xs disabled" title="Kasuj filtr"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupHtml);
  439. groupHtml.appendTo(_headSpecialFilter);
  440. }
  441. {// USERS_FILTER_APPOINTMENT
  442. var groupHtml = $('<div class="btn-group"></div>');
  443. $('<button class="btn btn-xs" title="Spotkania"><i class="glyphicon glyphicon-calendar"></i></button>').appendTo(groupHtml);
  444. $('<button class="btn btn-xs">A_STARE</button>').appendTo(groupHtml);
  445. $('<button class="btn btn-xs">A_ZARAZ</button>').appendTo(groupHtml);
  446. $('<button class="btn btn-xs active">A_DZISIAJ</button>').appendTo(groupHtml);
  447. $('<button class="btn btn-xs disabled" title="Kasuj filtr"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupHtml);// To samo co KASUJ-FILTR
  448. groupHtml.appendTo(_headSpecialFilter);
  449. }
  450. */
  451. return $sqlFltr;
  452. }
  453. private function isColTypeNumber($colName) {
  454. if ($colName == 'ID') {
  455. return true;
  456. }
  457. $type = V::get($colName, null, $this->_col_types);
  458. if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">type['.$colName.'] (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('type'=>$type, '!empty'=>(!empty($type['type']['type']))));echo'</pre>'."\n\n";}
  459. if (!empty($type['type'])) {
  460. $sqlType = $type['type'];
  461. if (substr($sqlType, 0, 3) == 'int'
  462. || substr($sqlType, 0, 7) == 'tinyint'
  463. || substr($sqlType, 0, 8) == 'smallint'
  464. ) {
  465. return true;
  466. }
  467. }
  468. return false;
  469. }
  470. public function _parseSqlWhere($params = array()) {
  471. // default filter value
  472. if (empty($params['sf_Access'])) $params['sf_Access'] = 'HIDE';
  473. $sql_where = '';
  474. // ... parse filters
  475. $sql_where_and = array();
  476. foreach ($params as $k => $v) {
  477. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_') {
  478. //$v = trim($v, '% ');
  479. //$sql_where_and[] = "t.`" . substr($k, 2) . "` like '%" . DB::_($v) . "%'";
  480. $fldName = substr($k, 2);
  481. if ($this->isGeomField($fldName)) {
  482. $sqlFilter = $this->_sqlValueForGeomField($fldName, $v, 't');
  483. if ($sqlFilter) $sql_where_and[] = $sqlFilter;
  484. continue;
  485. }
  486. if ($this->isCsvNumericField($fldName)) {
  487. $sqlFilter = $this->_sqlValueForCsvNumericField($fldName, $v, 't');
  488. if ($sqlFilter) $sql_where_and[] = $sqlFilter;
  489. continue;
  490. }
  491. if (substr($v, 0, 1) == '=') {
  492. $v = $this->_db->_(substr($v, 1));
  493. if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`='{$v}'";
  494. }
  495. else if ($v == '!NULL' || $v == 'IS NOT NULL') {
  496. $sql_where_and[] = "t.`{$fldName}` is not null";
  497. }
  498. else if (substr($v, 0, 1) == '!') {
  499. $v = $this->_db->_(substr($v, 1));
  500. if (strlen($v)) $sql_where_and[] = "t.`{$fldName}` not like '{$v}'";
  501. }
  502. else if (substr($v, 0, 2) == '<=') {
  503. $v = $this->_db->_(substr($v, 2));
  504. if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`<='{$v}'";
  505. }
  506. else if (substr($v, 0, 2) == '>=') {
  507. $v = $this->_db->_(substr($v, 2));
  508. if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`>='{$v}'";
  509. }
  510. else if (substr($v, 0, 1) == '<') {
  511. $v = $this->_db->_(substr($v, 1));
  512. if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`<'{$v}'";
  513. }
  514. else if (substr($v, 0, 1) == '>') {
  515. $v = $this->_db->_(substr($v, 1));
  516. if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`>'{$v}'";
  517. }
  518. else if (false !== strpos($v, '%')) {
  519. $sql_where_and[] = "t.`{$fldName}` like '{$v}'";
  520. }
  521. else if ($this->isColTypeNumber($fldName)) {
  522. $v = $this->_db->_($v);
  523. $sql_where_and[] = "t.`{$fldName}`='{$v}'";
  524. }
  525. else {
  526. $queryWhereBuilder = new SqlQueryWhereBuilder();
  527. $searchWords = $queryWhereBuilder->splitQueryToWords($v);
  528. $sqlWhereWords = array();
  529. if (!empty($searchWords)) {
  530. foreach ($searchWords as $word) {
  531. $sqlWord = $this->_db->_($word);
  532. $sqlWhereWords[] = "t.`{$fldName}` like '%{$sqlWord}%'";
  533. }
  534. }
  535. if (!empty($searchWords)) {
  536. $sql_where_and[] = "(" . implode(" and ", $sqlWhereWords) . ")";
  537. }
  538. }
  539. }
  540. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_') {
  541. $sqlFltr = $this->_parseSpecialFilter(substr($k, 3), $v);
  542. if (!empty($sqlFltr)) {
  543. $sql_where_and[] = $sqlFltr;
  544. }
  545. }
  546. else if ('ogc:Filter' == $k) {
  547. $sqlFltr = $this->_parseOgcFilter($v);
  548. if (!empty($sqlFltr)) {
  549. $sql_where_and[] = $sqlFltr;
  550. }
  551. }
  552. }
  553. if (!empty($sql_where_and)) {
  554. $sql_where = implode(" and ", $sql_where_and);
  555. }
  556. if (!$sql_where) $sql_where = "1=1";
  557. if(V::get('DBG_DS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql_where (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql_where);echo'</pre>'."\n\n";}
  558. return $sql_where;
  559. }
  560. private function _sqlValueForGeomField($fldName, $fltrValue, $tblPrefix = 't') {
  561. $sqlFilter = false;
  562. // example: BBOX:54.40993961633866,18.583889010112824,54.337945760687454,18.397121431987586
  563. if ('BBOX:' == substr($fltrValue, 0, 5)) {
  564. $val = substr($fltrValue, 5);
  565. $valParts = explode(',', $val);
  566. if (count($valParts) == 4) {
  567. $isAllNumeric = true;
  568. foreach ($valParts as $v) {
  569. if (!is_numeric($v)) $isAllNumeric = false;
  570. }
  571. if ($isAllNumeric) {
  572. $bounds = "POLYGON((
  573. {$valParts[3]} {$valParts[2]},
  574. {$valParts[3]} {$valParts[0]},
  575. {$valParts[1]} {$valParts[0]},
  576. {$valParts[1]} {$valParts[2]},
  577. {$valParts[3]} {$valParts[2]}
  578. ))";
  579. // for mysql 5.6 use ST_Contains() @see http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions.html
  580. $sqlFilter = "Intersects(GeomFromText('{$bounds}'), GeomFromText(AsWKT({$tblPrefix}.`{$fldName}`)))=1";
  581. }
  582. }
  583. }
  584. else if ('GeometryType=' == substr($fltrValue, 0, 13)) {
  585. $sqlFilter = "GeometryType({$tblPrefix}.`{$fldName}`)='" . substr($fltrValue, 13) . "'";
  586. }
  587. return $sqlFilter;
  588. }
  589. private function _sqlValueForCsvNumericField($fldName, $fltrValue, $tblPrefix = 't') {
  590. $sqlFilter = false;
  591. if (is_numeric($fltrValue)) {
  592. $sqlFilter = "FIND_IN_SET('{$fltrValue}', `{$fldName}`)>0";
  593. } else if (false !== strpos($fltrValue, ' ')) {
  594. $sqlGlue = " or ";
  595. $fltrValues = $fltrValue;
  596. if ('&' == substr($fltrValues, 0, 1)) {
  597. $fltrValues = substr($fltrValues, 1);
  598. $sqlGlue = " and ";
  599. }
  600. $fltrValues = explode(' ', $fltrValues);
  601. $sqlNumericValues = array();
  602. foreach ($fltrValues as $fltrVal) {
  603. if (is_numeric($fltrVal)) {
  604. $sqlNumericValues[] = "FIND_IN_SET('{$fltrVal}', `{$fldName}`)>0";
  605. }
  606. }
  607. if (!empty($sqlNumericValues)) {
  608. $sqlFilter = "(" . implode($sqlGlue, $sqlNumericValues) . ")";
  609. }
  610. }
  611. return $sqlFilter;
  612. }
  613. function get_item($id) {// TODO: RMME
  614. $this->getItem($id);
  615. }
  616. /**
  617. * @returns object
  618. */
  619. public function getItem($primaryKey) {
  620. $primaryKeyField = $this->getPrimaryKeyField();
  621. $ret = null;
  622. $sql_cols = $this->_get_sql_cols();
  623. $primaryKey = intval($primaryKey);// TODO: validate $primaryKey
  624. $sql = "select {$sql_cols}
  625. from `{$this->_tbl}` as t
  626. where t.`{$primaryKeyField}`='{$primaryKey}'
  627. ";
  628. // TODO: use PDO
  629. $res = $this->_db->query($sql);
  630. if ($r = $this->_db->fetch($res)) {
  631. $ret = $r;
  632. }
  633. return $ret;
  634. }
  635. function get_items($params = array()) {// TODO: RMME
  636. $this->getItems($params);
  637. }
  638. public function getItems($params = array()) {
  639. $primaryKeyField = $this->getPrimaryKeyField();
  640. $items = array();
  641. $sql_limit = V::get('limit', $this->_default_sql_limit, $params, 'int');
  642. $sql_offset = V::get('limitstart', 0, $params, 'int');
  643. $sql_order_by = V::get('order_by', '', $params);
  644. if ($sql_order_by) {
  645. $sql_order_dir = V::get('order_dir', '', $params);
  646. // prevent from sorting by special columns
  647. if (!array_key_exists($sql_order_by, $this->_cols)) {
  648. $sql_order_by = null;
  649. $sql_order_dir = null;
  650. }
  651. }
  652. if ($sql_order_by) {
  653. $sql_order_by = "order by t.`{$sql_order_by}`";
  654. if ($sql_order_dir) {
  655. $sql_order_by = "{$sql_order_by} {$sql_order_dir}";
  656. }
  657. }
  658. $sql_cols = $this->_get_sql_cols();
  659. $sql_where = $this->_parseSqlWhere($params);
  660. $sql = "select {$sql_cols}
  661. from {$this->_tbl} as t
  662. where {$sql_where}
  663. {$sql_order_by}
  664. limit {$sql_limit} offset {$sql_offset}
  665. ";
  666. if(V::get('DBG_DS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>'."\n\n";}
  667. $res = $this->_db->query($sql);
  668. while ($r = $this->_db->fetch($res)) {
  669. $items[$r->{$primaryKeyField}] = $r;
  670. }
  671. return $items;
  672. }
  673. function get_hist_items($id) {// TODO: RMME
  674. $this->getHistItems($id);
  675. }
  676. public function getHistItems($id, $params = array()) {
  677. $ret = array();
  678. $sql_tbl = $this->_tbl . "_HIST";
  679. $sql_cols = $this->_get_sql_cols();
  680. $sql_where = "t.`ID_USERS2`='{$id}'";
  681. $paramNotEmptyFlds = V::get('notEmptyFlds', '', $params);
  682. if (!empty($paramNotEmptyFlds) && is_array($paramNotEmptyFlds)) {
  683. $sqlWhereOr = array();
  684. foreach ($paramNotEmptyFlds as $fldName) {
  685. if (array_key_exists($fldName, $this->_cols)) {
  686. $sqlWhereOr[] = "t.`{$fldName}`!='N/S;'";
  687. }
  688. }
  689. if (!empty($sqlWhereOr)) $sql_where .= "\n and (" . implode(" or ", $sqlWhereOr) . ")";
  690. }
  691. $sql = "select {$sql_cols}
  692. from {$sql_tbl} as t
  693. where {$sql_where}
  694. order by ID DESC
  695. ";
  696. if(V::get('DBG_DS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>'."\n\n";}
  697. $res = $this->_db->query($sql);
  698. while ($r = $this->_db->fetch($res)) {
  699. $r->_author = $r->A_RECORD_UPDATE_AUTHOR;
  700. $r->_created = $r->A_RECORD_UPDATE_DATE;
  701. if (!$r->_author || $r->_author == 'N/S;') {
  702. $r->_author = $r->A_RECORD_CREATE_AUTHOR;
  703. }
  704. if (!$r->_created || $r->_created == 'N/S;') {
  705. $r->_created = $r->A_RECORD_CREATE_DATE;
  706. }
  707. $ret[$r->ID] = $r;
  708. }
  709. return $ret;
  710. }
  711. function get_total($params = array()) {// TODO: RMME
  712. $this->getTotal($params);
  713. }
  714. public function getTotal($params = array()) {
  715. $ret = 0;
  716. $sql_where = $this->_parseSqlWhere($params);
  717. $sql = "select count(1) as cnt
  718. from {$this->_tbl} as t
  719. where {$sql_where}
  720. ";
  721. $res = $this->_db->query($sql);
  722. if ($r = $this->_db->fetch($res)) {
  723. $ret = $r->cnt;
  724. }
  725. return $ret;
  726. }
  727. function set_sql_where($sql_where) {
  728. $this->_sql_where = $sql_where;
  729. }
  730. function set_field_sql_type($field, $sql_type) {
  731. $this->_fields_type[$field] = $sql_type;
  732. }
  733. function get_field_sql_type($field) {
  734. if (array_key_exists($field, $this->_fields_type)) {
  735. return $this->_fields_type[$field];
  736. }
  737. return 'varchar(255)';
  738. }
  739. function set_field_perm($field, $perm) {
  740. $this->_fields_perm[$field] = $perm;
  741. }
  742. function get_field_perm($field) {
  743. if (array_key_exists($field, $this->_fields_perm)) {
  744. return $this->_fields_perm[$field];
  745. }
  746. return '';
  747. }
  748. function field_allow_write($field_name) {
  749. return (strpos($this->get_field_perm($field_name), 'W') !== false)? true : false;
  750. }
  751. function field_allow_read($field_name) {
  752. return (strpos($this->get_field_perm($field_name), 'R') !== false)? true : false;
  753. }
  754. function field_allow_create($field_name) {
  755. return (strpos($this->get_field_perm($field_name), 'C') !== false)? true : false;
  756. }
  757. public function add_col($col_name, $label = '', $type = 'string') {
  758. if (!$label) $label = $col_name;
  759. $this->_cols[$col_name] = $label;
  760. $this->_col_types[$col_name] = $type;
  761. }
  762. public function addCol($col_name) {
  763. $this->_cols[$col_name] = $col_name;
  764. }
  765. function count() {
  766. $ret = 0;
  767. $sql_where = ($this->_sql_where)? $this->_sql_where : "1=1";
  768. $sql = "select count(1) as cnt
  769. from `{$this->_tbl}`
  770. where {$sql_where}
  771. ";
  772. $res = $this->_db->query($sql);
  773. if ($r = $this->_db->fetch($res)) {
  774. $ret = $r->cnt;
  775. }
  776. return $ret;
  777. }
  778. function fetch_list($limit = 10, $offset = 0) {
  779. $primaryKeyField = $this->getPrimaryKeyField();
  780. $ret = array();
  781. $this->_sql_limit = $limit;
  782. $this->_sql_offset = $offset;
  783. $sql_cols = (!empty($this->_cols))? implode(',', array_keys($this->_cols)) : "*";
  784. $sql_where = ($this->_sql_where)? $this->_sql_where : "1=1";
  785. $sql = "
  786. select {$sql_cols}
  787. from {$this->_tbl}
  788. where {$sql_where}
  789. limit {$this->_sql_limit} offset {$this->_sql_offset}
  790. ";
  791. $res = $this->_db->query($sql);
  792. while ($r = $this->_db->fetch($res)) {
  793. $ret[$r->{$primaryKeyField}] = $r;
  794. }
  795. return $ret;
  796. }
  797. function field_check_value($field_name, $val) {
  798. if (!$this->field_allow_write($field_name)) {
  799. return false;
  800. }
  801. // post verify
  802. // get type, and check if value is correct
  803. // TODO: if typespecial use it
  804. return true;
  805. }
  806. function save_item(&$item, $values, $prefix) {
  807. if (!$item->ID) {
  808. return null;
  809. }
  810. $sql_obj = new stdClass();
  811. $sql_obj->ID = $item->ID;
  812. foreach ($values as $k_field_with_prefix => $v_field) {
  813. if (substr($k_field_with_prefix, 0, strlen($prefix)) != $prefix) {
  814. continue;
  815. }
  816. $k_field = substr($k_field_with_prefix, strlen($prefix));
  817. if ($this->field_allow_write($k_field)) {
  818. if ($this->field_check_value($k_field, $v_field)) {
  819. $sql_obj->$k_field = $v_field;
  820. }
  821. }
  822. }
  823. $affected = $this->_db->PDATE_OBJ($this->_tbl, $sql_obj);
  824. return $affected;
  825. }
  826. function add_item($values, $prefix) {
  827. $sql_obj = new stdClass();
  828. foreach ($values as $k_field_with_prefix => $v_field) {
  829. if (substr($k_field_with_prefix, 0, strlen($prefix)) != $prefix) {
  830. continue;
  831. }
  832. $k_field = substr($k_field_with_prefix, strlen($prefix));
  833. if ($this->field_allow_create($k_field)) {
  834. if ($this->field_check_value($k_field, $v_field)) {
  835. $sql_obj->$k_field = $v_field;
  836. }
  837. }
  838. }
  839. $insert_id = $this->_db->ADD_NEW_OBJ($this->_tbl, $sql_obj);
  840. return $insert_id;
  841. }
  842. public function getGeomFields() {
  843. return $this->_geomFields;
  844. }
  845. public function isGeomField($fldName) {
  846. return in_array($fldName, $this->_geomFields);
  847. }
  848. public function isCsvNumericField($fldName) {
  849. return ('_CSV_NUM' == substr($fldName, -8));
  850. }
  851. public function updateItem($itemPatch) {
  852. // TODO: $item as array and copy from $db->UPDATE_OBJ using PDO
  853. if (is_object($itemPatch)) {
  854. $itemPatch = (array)$itemPatch;
  855. } else if (!is_array($itemPatch)) {
  856. throw new HttpException('Item patch is not array', 400);
  857. }
  858. if (empty($itemPatch)) {
  859. //throw new Exception('Item patch is empty');
  860. return 0;// nothing to change
  861. }
  862. $primaryKeyField = $this->getPrimaryKeyField();
  863. if (empty($itemPatch[$primaryKeyField])) {
  864. throw new HttpException("Item Primary Key not set!", 400);
  865. }
  866. // the geom fix
  867. foreach ($itemPatch as $fld => $val) {
  868. if ($this->isGeomField($fld)) {
  869. if (!empty($val)
  870. && 'NULL' !== $val
  871. && 'GeomFromText' != substr($val, 0, strlen('GeomFromText'))
  872. ) {
  873. $itemPatch[$fld] = "GeomFromText('{$val}')";
  874. }
  875. }
  876. }
  877. $itemPatch = (object)$itemPatch;
  878. $affected = $this->_db->UPDATE_OBJ($this->_tbl, $itemPatch);
  879. if ($affected < 0) {
  880. $dsErrors = $this->getDbErrors();
  881. //$dsErrors = "Wystąpiły błędy!\n" . implode("\n", $dsErrors);
  882. if (!empty($dsErrors)) {
  883. throw new StorageException($dsErrors);
  884. }
  885. }
  886. return $affected;
  887. }
  888. public function addItem($item) {
  889. // TODO: $item as array and copy from $db->ADD_NEW_OBJ using PDO
  890. if (is_object($item)) {
  891. $item = (array)$item;
  892. } else if (!is_array($item)) {
  893. throw new HttpException('Item is not array', 400);
  894. }
  895. if (empty($item)) {
  896. //throw new Exception('Item patch is empty');
  897. return 0;// nothing to insert
  898. }
  899. // the geom fix
  900. foreach ($item as $fld => $val) {
  901. if ($this->isGeomField($fld)) {
  902. if (!empty($val)
  903. && 'NULL' !== $val
  904. && 'GeomFromText' != substr($val, 0, strlen('GeomFromText'))
  905. ) {
  906. $item[$fld] = "GeomFromText('{$val}')";
  907. }
  908. }
  909. }
  910. $item = (object)$item;
  911. $primaryKey = $this->_db->ADD_NEW_OBJ($this->_tbl, $item);
  912. if ($primaryKey < 0) {
  913. $dsErrors = $this->getDbErrors();
  914. $dsErrors = "Wystąpiły błędy!\n" . implode("\n", $dsErrors);
  915. throw new Exception($dsErrors);
  916. }
  917. return $primaryKey;
  918. }
  919. public function getDbErrors() {
  920. $errors = array();
  921. if ($this->_db->has_errors()) {
  922. $errorsSql = $this->_db->get_errors();
  923. foreach ($errorsSql as $vErr) {
  924. if ('SQL QUERY FAILED: ' == substr($vErr, 0, 18)) {
  925. $vErr = substr($vErr, 18);
  926. }
  927. //$errors[] = StorageException::parseMessage($vErr);
  928. $errors[] = $vErr;
  929. }
  930. }
  931. return $errors;
  932. }
  933. public function getPrimaryKeyField() {
  934. return 'ID';// TODO: read from struct - jest funkcja w Mysql.php my Psql.php
  935. }
  936. }