Data_Source.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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. $searchWords = explode(' ', $v);
  527. $sqlWhereWords = array();
  528. if (!empty($searchWords)) {
  529. foreach ($searchWords as $word) {
  530. if (!empty($word)) {
  531. $word = $this->_db->_($word);
  532. $sqlWhereWords[] = "t.`{$fldName}` like '%{$word}%'";
  533. }
  534. }
  535. }
  536. if (!empty($searchWords)) {
  537. $sql_where_and[] = "(" . implode(" and ", $sqlWhereWords) . ")";
  538. }
  539. }
  540. }
  541. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_') {
  542. $sqlFltr = $this->_parseSpecialFilter(substr($k, 3), $v);
  543. if (!empty($sqlFltr)) {
  544. $sql_where_and[] = $sqlFltr;
  545. }
  546. }
  547. else if ('ogc:Filter' == $k) {
  548. $sqlFltr = $this->_parseOgcFilter($v);
  549. if (!empty($sqlFltr)) {
  550. $sql_where_and[] = $sqlFltr;
  551. }
  552. }
  553. }
  554. if (!empty($sql_where_and)) {
  555. $sql_where = implode(" and ", $sql_where_and);
  556. }
  557. if (!$sql_where) $sql_where = "1=1";
  558. 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";}
  559. return $sql_where;
  560. }
  561. private function _sqlValueForGeomField($fldName, $fltrValue, $tblPrefix = 't') {
  562. $sqlFilter = false;
  563. // example: BBOX:54.40993961633866,18.583889010112824,54.337945760687454,18.397121431987586
  564. if ('BBOX:' == substr($fltrValue, 0, 5)) {
  565. $val = substr($fltrValue, 5);
  566. $valParts = explode(',', $val);
  567. if (count($valParts) == 4) {
  568. $isAllNumeric = true;
  569. foreach ($valParts as $v) {
  570. if (!is_numeric($v)) $isAllNumeric = false;
  571. }
  572. if ($isAllNumeric) {
  573. $bounds = "POLYGON((
  574. {$valParts[3]} {$valParts[2]},
  575. {$valParts[3]} {$valParts[0]},
  576. {$valParts[1]} {$valParts[0]},
  577. {$valParts[1]} {$valParts[2]},
  578. {$valParts[3]} {$valParts[2]}
  579. ))";
  580. // for mysql 5.6 use ST_Contains() @see http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions.html
  581. $sqlFilter = "Intersects(GeomFromText('{$bounds}'), GeomFromText(AsWKT({$tblPrefix}.`{$fldName}`)))=1";
  582. }
  583. }
  584. }
  585. else if ('GeometryType=' == substr($fltrValue, 0, 13)) {
  586. $sqlFilter = "GeometryType({$tblPrefix}.`{$fldName}`)='" . substr($fltrValue, 13) . "'";
  587. }
  588. return $sqlFilter;
  589. }
  590. private function _sqlValueForCsvNumericField($fldName, $fltrValue, $tblPrefix = 't') {
  591. $sqlFilter = false;
  592. if (is_numeric($fltrValue)) {
  593. $sqlFilter = "FIND_IN_SET('{$fltrValue}', `{$fldName}`)>0";
  594. } else if (false !== strpos($fltrValue, ' ')) {
  595. $sqlGlue = " or ";
  596. $fltrValues = $fltrValue;
  597. if ('&' == substr($fltrValues, 0, 1)) {
  598. $fltrValues = substr($fltrValues, 1);
  599. $sqlGlue = " and ";
  600. }
  601. $fltrValues = explode(' ', $fltrValues);
  602. $sqlNumericValues = array();
  603. foreach ($fltrValues as $fltrVal) {
  604. if (is_numeric($fltrVal)) {
  605. $sqlNumericValues[] = "FIND_IN_SET('{$fltrVal}', `{$fldName}`)>0";
  606. }
  607. }
  608. if (!empty($sqlNumericValues)) {
  609. $sqlFilter = "(" . implode($sqlGlue, $sqlNumericValues) . ")";
  610. }
  611. }
  612. return $sqlFilter;
  613. }
  614. function get_item($id) {// TODO: RMME
  615. $this->getItem($id);
  616. }
  617. /**
  618. * @returns object
  619. */
  620. public function getItem($primaryKey) {
  621. $primaryKeyField = $this->getPrimaryKeyField();
  622. $ret = null;
  623. $sql_cols = $this->_get_sql_cols();
  624. $primaryKey = intval($primaryKey);// TODO: validate $primaryKey
  625. $sql = "select {$sql_cols}
  626. from `{$this->_tbl}` as t
  627. where t.`{$primaryKeyField}`='{$primaryKey}'
  628. ";
  629. // TODO: use PDO
  630. $res = $this->_db->query($sql);
  631. if ($r = $this->_db->fetch($res)) {
  632. $ret = $r;
  633. }
  634. return $ret;
  635. }
  636. function get_items($params = array()) {// TODO: RMME
  637. $this->getItems($params);
  638. }
  639. public function getItems($params = array()) {
  640. $primaryKeyField = $this->getPrimaryKeyField();
  641. $items = array();
  642. $sql_limit = V::get('limit', $this->_default_sql_limit, $params, 'int');
  643. $sql_offset = V::get('limitstart', 0, $params, 'int');
  644. $sql_order_by = V::get('order_by', '', $params);
  645. if ($sql_order_by) {
  646. $sql_order_dir = V::get('order_dir', '', $params);
  647. // prevent from sorting by special columns
  648. if (!array_key_exists($sql_order_by, $this->_cols)) {
  649. $sql_order_by = null;
  650. $sql_order_dir = null;
  651. }
  652. }
  653. if ($sql_order_by) {
  654. $sql_order_by = "order by t.`{$sql_order_by}`";
  655. if ($sql_order_dir) {
  656. $sql_order_by = "{$sql_order_by} {$sql_order_dir}";
  657. }
  658. }
  659. $sql_cols = $this->_get_sql_cols();
  660. $sql_where = $this->_parseSqlWhere($params);
  661. $sql = "select {$sql_cols}
  662. from {$this->_tbl} as t
  663. where {$sql_where}
  664. {$sql_order_by}
  665. limit {$sql_limit} offset {$sql_offset}
  666. ";
  667. 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";}
  668. $res = $this->_db->query($sql);
  669. while ($r = $this->_db->fetch($res)) {
  670. $items[$r->{$primaryKeyField}] = $r;
  671. }
  672. return $items;
  673. }
  674. function get_hist_items($id) {// TODO: RMME
  675. $this->getHistItems($id);
  676. }
  677. public function getHistItems($id, $params = array()) {
  678. $ret = array();
  679. $sql_tbl = $this->_tbl . "_HIST";
  680. $sql_cols = $this->_get_sql_cols();
  681. $sql_where = "t.`ID_USERS2`='{$id}'";
  682. $paramNotEmptyFlds = V::get('notEmptyFlds', '', $params);
  683. if (!empty($paramNotEmptyFlds) && is_array($paramNotEmptyFlds)) {
  684. $sqlWhereOr = array();
  685. foreach ($paramNotEmptyFlds as $fldName) {
  686. if (array_key_exists($fldName, $this->_cols)) {
  687. $sqlWhereOr[] = "t.`{$fldName}`!='N/S;'";
  688. }
  689. }
  690. if (!empty($sqlWhereOr)) $sql_where .= "\n and (" . implode(" or ", $sqlWhereOr) . ")";
  691. }
  692. $sql = "select {$sql_cols}
  693. from {$sql_tbl} as t
  694. where {$sql_where}
  695. order by ID DESC
  696. ";
  697. 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";}
  698. $res = $this->_db->query($sql);
  699. while ($r = $this->_db->fetch($res)) {
  700. $r->_author = $r->A_RECORD_UPDATE_AUTHOR;
  701. $r->_created = $r->A_RECORD_UPDATE_DATE;
  702. if (!$r->_author || $r->_author == 'N/S;') {
  703. $r->_author = $r->A_RECORD_CREATE_AUTHOR;
  704. }
  705. if (!$r->_created || $r->_created == 'N/S;') {
  706. $r->_created = $r->A_RECORD_CREATE_DATE;
  707. }
  708. $ret[$r->ID] = $r;
  709. }
  710. return $ret;
  711. }
  712. function get_total($params = array()) {// TODO: RMME
  713. $this->getTotal($params);
  714. }
  715. public function getTotal($params = array()) {
  716. $ret = 0;
  717. $sql_where = $this->_parseSqlWhere($params);
  718. $sql = "select count(1) as cnt
  719. from {$this->_tbl} as t
  720. where {$sql_where}
  721. ";
  722. $res = $this->_db->query($sql);
  723. if ($r = $this->_db->fetch($res)) {
  724. $ret = $r->cnt;
  725. }
  726. return $ret;
  727. }
  728. function set_sql_where($sql_where) {
  729. $this->_sql_where = $sql_where;
  730. }
  731. function set_field_sql_type($field, $sql_type) {
  732. $this->_fields_type[$field] = $sql_type;
  733. }
  734. function get_field_sql_type($field) {
  735. if (array_key_exists($field, $this->_fields_type)) {
  736. return $this->_fields_type[$field];
  737. }
  738. return 'varchar(255)';
  739. }
  740. function set_field_perm($field, $perm) {
  741. $this->_fields_perm[$field] = $perm;
  742. }
  743. function get_field_perm($field) {
  744. if (array_key_exists($field, $this->_fields_perm)) {
  745. return $this->_fields_perm[$field];
  746. }
  747. return '';
  748. }
  749. function field_allow_write($field_name) {
  750. return (strpos($this->get_field_perm($field_name), 'W') !== false)? true : false;
  751. }
  752. function field_allow_read($field_name) {
  753. return (strpos($this->get_field_perm($field_name), 'R') !== false)? true : false;
  754. }
  755. function field_allow_create($field_name) {
  756. return (strpos($this->get_field_perm($field_name), 'C') !== false)? true : false;
  757. }
  758. public function add_col($col_name, $label = '', $type = 'string') {
  759. if (!$label) $label = $col_name;
  760. $this->_cols[$col_name] = $label;
  761. $this->_col_types[$col_name] = $type;
  762. }
  763. public function addCol($col_name) {
  764. $this->_cols[$col_name] = $col_name;
  765. }
  766. function count() {
  767. $ret = 0;
  768. $sql_where = ($this->_sql_where)? $this->_sql_where : "1=1";
  769. $sql = "select count(1) as cnt
  770. from `{$this->_tbl}`
  771. where {$sql_where}
  772. ";
  773. $res = $this->_db->query($sql);
  774. if ($r = $this->_db->fetch($res)) {
  775. $ret = $r->cnt;
  776. }
  777. return $ret;
  778. }
  779. function fetch_list($limit = 10, $offset = 0) {
  780. $primaryKeyField = $this->getPrimaryKeyField();
  781. $ret = array();
  782. $this->_sql_limit = $limit;
  783. $this->_sql_offset = $offset;
  784. $sql_cols = (!empty($this->_cols))? implode(',', array_keys($this->_cols)) : "*";
  785. $sql_where = ($this->_sql_where)? $this->_sql_where : "1=1";
  786. $sql = "
  787. select {$sql_cols}
  788. from {$this->_tbl}
  789. where {$sql_where}
  790. limit {$this->_sql_limit} offset {$this->_sql_offset}
  791. ";
  792. $res = $this->_db->query($sql);
  793. while ($r = $this->_db->fetch($res)) {
  794. $ret[$r->{$primaryKeyField}] = $r;
  795. }
  796. return $ret;
  797. }
  798. function field_check_value($field_name, $val) {
  799. if (!$this->field_allow_write($field_name)) {
  800. return false;
  801. }
  802. // post verify
  803. // get type, and check if value is correct
  804. // TODO: if typespecial use it
  805. return true;
  806. }
  807. function save_item(&$item, $values, $prefix) {
  808. if (!$item->ID) {
  809. return null;
  810. }
  811. $sql_obj = new stdClass();
  812. $sql_obj->ID = $item->ID;
  813. foreach ($values as $k_field_with_prefix => $v_field) {
  814. if (substr($k_field_with_prefix, 0, strlen($prefix)) != $prefix) {
  815. continue;
  816. }
  817. $k_field = substr($k_field_with_prefix, strlen($prefix));
  818. if ($this->field_allow_write($k_field)) {
  819. if ($this->field_check_value($k_field, $v_field)) {
  820. $sql_obj->$k_field = $v_field;
  821. }
  822. }
  823. }
  824. $affected = $this->_db->PDATE_OBJ($this->_tbl, $sql_obj);
  825. return $affected;
  826. }
  827. function add_item($values, $prefix) {
  828. $sql_obj = new stdClass();
  829. foreach ($values as $k_field_with_prefix => $v_field) {
  830. if (substr($k_field_with_prefix, 0, strlen($prefix)) != $prefix) {
  831. continue;
  832. }
  833. $k_field = substr($k_field_with_prefix, strlen($prefix));
  834. if ($this->field_allow_create($k_field)) {
  835. if ($this->field_check_value($k_field, $v_field)) {
  836. $sql_obj->$k_field = $v_field;
  837. }
  838. }
  839. }
  840. $insert_id = $this->_db->ADD_NEW_OBJ($this->_tbl, $sql_obj);
  841. return $insert_id;
  842. }
  843. public function getGeomFields() {
  844. return $this->_geomFields;
  845. }
  846. public function isGeomField($fldName) {
  847. return in_array($fldName, $this->_geomFields);
  848. }
  849. public function isCsvNumericField($fldName) {
  850. return ('_CSV_NUM' == substr($fldName, -8));
  851. }
  852. public function updateItem($itemPatch) {
  853. // TODO: $item as array and copy from $db->UPDATE_OBJ using PDO
  854. if (is_object($itemPatch)) {
  855. $itemPatch = (array)$itemPatch;
  856. } else if (!is_array($itemPatch)) {
  857. throw new HttpException('Item patch is not array', 400);
  858. }
  859. if (empty($itemPatch)) {
  860. //throw new Exception('Item patch is empty');
  861. return 0;// nothing to change
  862. }
  863. $primaryKeyField = $this->getPrimaryKeyField();
  864. if (empty($itemPatch[$primaryKeyField])) {
  865. throw new HttpException("Item Primary Key not set!", 400);
  866. }
  867. // the geom fix
  868. foreach ($itemPatch as $fld => $val) {
  869. if ($this->isGeomField($fld)) {
  870. if (!empty($val)
  871. && 'NULL' !== $val
  872. && 'GeomFromText' != substr($val, 0, strlen('GeomFromText'))
  873. ) {
  874. $itemPatch[$fld] = "GeomFromText('{$val}')";
  875. }
  876. }
  877. }
  878. $itemPatch = (object)$itemPatch;
  879. $affected = $this->_db->UPDATE_OBJ($this->_tbl, $itemPatch);
  880. if ($affected < 0) {
  881. $dsErrors = $this->getDbErrors();
  882. //$dsErrors = "Wystąpiły błędy!\n" . implode("\n", $dsErrors);
  883. if (!empty($dsErrors)) {
  884. throw new StorageException($dsErrors);
  885. }
  886. }
  887. return $affected;
  888. }
  889. public function addItem($item) {
  890. // TODO: $item as array and copy from $db->ADD_NEW_OBJ using PDO
  891. if (is_object($item)) {
  892. $item = (array)$item;
  893. } else if (!is_array($item)) {
  894. throw new HttpException('Item is not array', 400);
  895. }
  896. if (empty($item)) {
  897. //throw new Exception('Item patch is empty');
  898. return 0;// nothing to insert
  899. }
  900. // the geom fix
  901. foreach ($item as $fld => $val) {
  902. if ($this->isGeomField($fld)) {
  903. if (!empty($val)
  904. && 'NULL' !== $val
  905. && 'GeomFromText' != substr($val, 0, strlen('GeomFromText'))
  906. ) {
  907. $item[$fld] = "GeomFromText('{$val}')";
  908. }
  909. }
  910. }
  911. $item = (object)$item;
  912. $primaryKey = $this->_db->ADD_NEW_OBJ($this->_tbl, $item);
  913. if ($primaryKey < 0) {
  914. $dsErrors = $this->getDbErrors();
  915. $dsErrors = "Wystąpiły błędy!\n" . implode("\n", $dsErrors);
  916. throw new Exception($dsErrors);
  917. }
  918. return $primaryKey;
  919. }
  920. public function getDbErrors() {
  921. $errors = array();
  922. if ($this->_db->has_errors()) {
  923. $errorsSql = $this->_db->get_errors();
  924. foreach ($errorsSql as $vErr) {
  925. if ('SQL QUERY FAILED: ' == substr($vErr, 0, 18)) {
  926. $vErr = substr($vErr, 18);
  927. }
  928. //$errors[] = StorageException::parseMessage($vErr);
  929. $errors[] = $vErr;
  930. }
  931. }
  932. return $errors;
  933. }
  934. public function getPrimaryKeyField() {
  935. return 'ID';// TODO: read from struct - jest funkcja w Mysql.php my Psql.php
  936. }
  937. }