ProcesHelper.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <?php
  2. class ProcesHelper {
  3. public static function get_wskazniki($id) {
  4. $ret = array();
  5. $db = DB::getDB();
  6. $sql = "select
  7. clz.*
  8. , w.`ID` as CW_ID, w.`TYP` as CW_TYP, w.`OPIS_ZASOB` as OPIS_ZASOB, w.`SORT_PRIO` as CW_SORT_PRIO, w.`ID_PRZYPADEK` as CW_ID_PRZYPADEK
  9. , w.`A_HAS_IMAGE` as CW_A_HAS_IMAGE
  10. , cp.`PYTANIE` as CP_PYTANIE, cp.`OPIS` as CP_OPIS, cp.`FORM_TREAT` as CP_FORM_TREAT
  11. from `CRM_WSKAZNIK` as w
  12. left join `CRM_LISTA_ZASOBOW` as clz on (clz.`ID`=w.`ID_ZASOB`)
  13. left join `CRM_PRZYPADEK` as cp on (cp.`ID`=w.`ID_PRZYPADEK`)
  14. where
  15. w.`ID_PROCES`='".$id."'
  16. and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  17. order by w.`SORT_PRIO` asc, w.`ID` asc
  18. ";
  19. $res = $db->query($sql);
  20. while ($r = $db->fetch($res)) {
  21. $ret[$r->CW_ID] = $r;
  22. }
  23. return $ret;
  24. }
  25. public static function getWskaznikiByIds($ids, $params = array()) {
  26. $wskazniki = array();
  27. if (empty($ids)) {
  28. return $wskazniki;
  29. }
  30. $db = DB::getDB();
  31. $sql = "select
  32. clz.*
  33. , w.`ID_PROCES`
  34. , w.`ID` as CW_ID, w.`TYP` as CW_TYP, w.`OPIS_ZASOB` as OPIS_ZASOB, w.`SORT_PRIO` as CW_SORT_PRIO, w.`ID_PRZYPADEK` as CW_ID_PRZYPADEK
  35. , w.`A_HAS_IMAGE` as CW_A_HAS_IMAGE
  36. , cp.`PYTANIE` as CP_PYTANIE, cp.`OPIS` as CP_OPIS, cp.`FORM_TREAT` as CP_FORM_TREAT
  37. from `CRM_WSKAZNIK` as w
  38. left join `CRM_LISTA_ZASOBOW` as clz on (clz.`ID`=w.`ID_ZASOB`)
  39. left join `CRM_PRZYPADEK` as cp on (cp.`ID`=w.`ID_PRZYPADEK`)
  40. where
  41. w.`ID_PROCES` in(" . implode(",", $ids) . ")
  42. and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  43. order by w.`SORT_PRIO` asc, w.`ID` asc
  44. ";
  45. $res = $db->query($sql);
  46. while ($r = $db->fetch($res)) {
  47. $wskazniki[$r->ID_PROCES][$r->CW_ID] = $r;
  48. }
  49. if (1 == V::get('group_stanowiska', '', $params)) {
  50. foreach ($wskazniki as $kProcesId => $vWskazniki) {
  51. $stanowiska = array();
  52. foreach ($vWskazniki as $kWskId => $vWsk) {
  53. if ($vWsk->TYPE == 'STANOWISKO') {
  54. $stanowiska[$kWskId] = $vWsk;
  55. }
  56. }
  57. if (!empty($stanowiska)) {
  58. foreach ($stanowiska as $kWskId => $vWsk) {
  59. unset($wskazniki[$kProcesId][$kWskId]);
  60. }
  61. }
  62. $newWsk = array('stanowiska'=>$stanowiska, 'inne'=>$wskazniki[$kProcesId]);
  63. $wskazniki[$kProcesId] = $newWsk;
  64. }
  65. }
  66. return $wskazniki;
  67. }
  68. public static function get_list_for_user_count($user_groups, $params = array()) {
  69. $ret = array();
  70. $db = DB::getDB();
  71. $sql = self::_get_list_for_user_sql($user_groups, $params, true);
  72. $res = $db->query($sql);
  73. if ($r = $db->fetch($res)) {
  74. $ret = $r->cnt;
  75. }
  76. return $ret;
  77. }
  78. public static function get_list_for_user($user_groups, $params = array()) {
  79. $ret = array();
  80. $db = DB::getDB();
  81. $sql = self::_get_list_for_user_sql($user_groups, $params);
  82. $res = $db->query($sql);
  83. while ($r = $db->fetch($res)) {
  84. $ret[] = $r;
  85. }
  86. return $ret;
  87. }
  88. /**
  89. * TODO: find user proces
  90. */
  91. public static function _get_list_for_user_sql($user_groups, $params = array(), $count = false) {
  92. $sql_select = array();
  93. $sql_limit = "";
  94. $sql_where = "";
  95. if ($count) {
  96. $sql_select[] = "count(1) as cnt";
  97. } else {
  98. $sql_select[] = "t.*";
  99. $sql_limit = V::get('limit', '10', $params);
  100. $sql_offset = V::get('offset', '0', $params);
  101. $sql_limit = "limit {$sql_limit} offset {$sql_offset}";
  102. }
  103. $sql_select = implode(", ", $sql_select);
  104. $sql = "select
  105. {$sql_select}
  106. from `CRM_PROCES_LOG` as t
  107. -- left join `` as p on(p.``=t.``)
  108. where
  109. {$sql_where}
  110. {$sql_limit}
  111. ";
  112. return $sql;
  113. }
  114. /**
  115. * Get allowed Stanowiska ID for given proces.
  116. * @param $proces_id - proces ID
  117. * @returns array of Stanowiska ID
  118. * Search recursively up by p.PARENT_ID, stop when find p.PROCES_INIT or find z.STANOWISKO
  119. */
  120. public static function get_allowed_stanowiska_by_proces_id($proces_id) {
  121. $ret = array();
  122. $proces_id = intval($proces_id);
  123. if ($proces_id <= 0) return $ret;
  124. // TODO: DB::get_by_id('CRM_PROCES', $proces_id);
  125. // TODO: check TYPE=PROCES_INIT -> get STANOWISKO and stop
  126. // TODO: find wskazniki STANOWISKO
  127. // TODO: if !empty return else recursive - TODO: add recursive limit!
  128. $db = DB::getDB();
  129. $sql = "select
  130. p.`TYPE` as p__TYPE
  131. , z.`ID` as z__ID
  132. , z.`TYPE` as z__TYPE
  133. from `CRM_PROCES` as p
  134. left join `CRM_WSKAZNIK` as w on(w.`ID_PROCES`=p.`ID`)
  135. left join `CRM_LISTA_ZASOBOW` as z on (z.`ID`=w.`ID_ZASOB`)
  136. where
  137. p.`ID`='{$proces_id}'
  138. and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  139. and z.`TYPE`='STANOWISKO'
  140. ";
  141. $res = $db->query($sql);
  142. while ($r = $db->fetch($res)) {
  143. $ret[] = $r->z__ID;
  144. }
  145. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">ret: ';print_r($ret);echo'</pre>';
  146. return $ret;
  147. }
  148. public static function getProcesByUser($user_name, $groups) {
  149. $ret = array();
  150. $db = DB::getDB();
  151. $sql = "select plog.*
  152. from `CRM_PROCES_LOG` as plog
  153. where
  154. ( plog.`A_RECORD_CREATE_AUTHOR`='{$user_name}'
  155. or plog.`A_RECORD_UPDATE_AUTHOR`='{$user_name}'
  156. )
  157. order by plog.ID DESC
  158. ";
  159. $res = $db->query($sql);
  160. while ($r = $db->fetch($res)) {
  161. $ret[$r->ID] = $r;
  162. }
  163. return $ret;
  164. }
  165. public static function split_wskazniki_by_table(&$wsk) {
  166. $wsk_split = array();
  167. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">wsk: ';print_r($wsk);echo'</pre>';
  168. foreach ($wsk as $k_id => $w) {
  169. $w->_parents = TreeHelper::get_all_parents('CRM_LISTA_ZASOBOW', $w->PARENT_ID);
  170. }
  171. foreach ($wsk as $k_id => $w) {// $w->CW_ID == $k_id
  172. if ($w->TYPE == 'KOMORKA') {
  173. $last_wsk = end($wsk_split);
  174. if (empty($last_wsk)) {
  175. }
  176. } else if ($w->TYPE == 'DOKUMENTY') {
  177. // file
  178. }
  179. }
  180. }
  181. /**
  182. * @param $stanowiska_id - array of integer
  183. */
  184. public static function get_procesy_by_stanowiska($stanowiska_id = array()) {
  185. $db = DB::getDB();
  186. $ret = array();
  187. if (empty($stanowiska_id)) {
  188. return $ret;
  189. }
  190. $sql_stanowiska_id = array();
  191. foreach ($stanowiska_id as $v_id) {
  192. $v_id = intval($v_id);
  193. if ($v_id > 0) {
  194. $sql_stanowiska_id[] = "'{$v_id}'";
  195. }
  196. }
  197. if (empty($sql_stanowiska_id)) {
  198. return $ret;
  199. }
  200. $sql = "select
  201. p.`ID`
  202. , p.`PARENT_ID`
  203. , p.`TYPE`
  204. , p.`DESC`
  205. , w.`ID` as w__ID
  206. , w.`OPIS_ZASOB` as w__OPIS_ZASOB
  207. , z.`ID` as z__ID
  208. from `CRM_PROCES` as p
  209. left join `CRM_WSKAZNIK` as w on(w.`ID_PROCES`=p.`ID`)
  210. left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=w.`ID_ZASOB`)
  211. where
  212. p.`TYPE`='PROCES_INIT'
  213. and p.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  214. and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  215. -- and w.`ID_PRZYPADEK`=1
  216. and z.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  217. and z.`TYPE`='STANOWISKO'
  218. and z.`ID` is not null
  219. and z.`ID` in (" . implode(",", $sql_stanowiska_id) . ")
  220. order by p.`TEST_SORT_PRIO` DESC, p.`ID` ASC
  221. ";
  222. $res = $db->query($sql);
  223. while ($r = $db->fetch($res)) {
  224. $ret[] = $r;
  225. }
  226. return $ret;
  227. }
  228. /**
  229. * List of PROCES_INIT - only order info.
  230. * @return array ID => TEST_SORT_PRIO
  231. */
  232. public static function get_procesy_init_list_order() {
  233. $ret = array();
  234. $db = DB::getDB();
  235. $sql = "select
  236. p.`ID`
  237. , p.`TEST_SORT_PRIO`
  238. from `CRM_PROCES` as p
  239. where
  240. p.`TYPE`='PROCES_INIT'
  241. and p.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  242. order by p.`TEST_SORT_PRIO` DESC, p.`ID` ASC
  243. ";
  244. $res = $db->query($sql);
  245. while ($r = $db->fetch($res)) {
  246. $ret[$r->ID]= $r->TEST_SORT_PRIO;
  247. }
  248. return $ret;
  249. }
  250. /**
  251. * List of PROCES_INIT to sort.
  252. */
  253. public static function get_procesy_init_list() {
  254. $ret = array();
  255. $db = DB::getDB();
  256. $sql = "select
  257. p.`ID`
  258. , p.`PARENT_ID`
  259. , p.`TYPE`
  260. , p.`DESC`
  261. , p.`TEST_SORT_PRIO`
  262. -- , w.`ID` as w__ID
  263. -- , w.`OPIS_ZASOB` as w__OPIS_ZASOB
  264. -- , z.`ID` as z__ID
  265. , cps.`path`
  266. , p.`TEST_SORT_PRIO`
  267. , p.`SORT_PRIO`
  268. from `CRM_PROCES` as p
  269. -- left join `CRM_WSKAZNIK` as w on(w.`ID_PROCES`=p.`ID`)
  270. -- left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=w.`ID_ZASOB`)
  271. left join `_CRM_PROCES_STATS_proc_wiev` as cps on(p.`ID`=cps.`ID`)
  272. where
  273. p.`TYPE`='PROCES_INIT'
  274. and p.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  275. -- and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  276. -- and w.`ID_PRZYPADEK`=1
  277. -- and z.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  278. -- and z.`TYPE`='STANOWISKO'
  279. -- and z.`ID` is not null
  280. order by p.`TEST_SORT_PRIO` DESC, p.`ID` ASC
  281. ";
  282. $res = $db->query($sql);
  283. while ($r = $db->fetch($res)) {
  284. $ret[] = $r;
  285. }
  286. return $ret;
  287. }
  288. /**
  289. * Przeniesienie procesu w kolejności w testach.
  290. */
  291. public static function proces_init_move($proces_id, $sort_prio_dir) {
  292. $db = DB::getDB();
  293. $proces_list = self::get_procesy_init_list();
  294. $proces_list = array_reverse($proces_list);
  295. $wsk = array();
  296. $wsk_order = array();
  297. $sort_prio = 0;
  298. foreach ($proces_list as $r) {
  299. $wsk[$r->ID] = $sort_prio;//$r->SORT_PRIO;
  300. $wsk_order[$sort_prio] = $r->ID;
  301. $sort_prio += 1;
  302. }
  303. if (empty($wsk)) return;
  304. $wsk_new = array();
  305. if ($sort_prio_dir == 'dw') {// wskaznik $wsk_id 'w gore' (zmniejsz sort_prio)
  306. $old_wsk_id = $wsk[$proces_id];
  307. if ($old_wsk_id == 0) return;
  308. //echo'zamien "'.$proces_id.'" na "'.$wsk_order[$wsk[$proces_id] - 1].'"';
  309. $tmp = $wsk_order[$wsk[$proces_id]];
  310. $wsk_order[$wsk[$proces_id]] = $wsk_order[$wsk[$proces_id] - 1];
  311. $wsk_order[$wsk[$proces_id] - 1] = $tmp;
  312. } else {// wskaznik $wsk_id 'w dol' (zwieksz sort_prio)
  313. $old_wsk_id = $wsk[$proces_id];
  314. if ($old_wsk_id + 1 == count($wsk)) return;
  315. //echo'zamien "'.$proces_id.'" na "'.$wsk_order[$wsk[$proces_id] + 1].'"';
  316. $tmp = $wsk_order[$wsk[$proces_id]];
  317. $wsk_order[$wsk[$proces_id]] = $wsk_order[$wsk[$proces_id] + 1];
  318. $wsk_order[$wsk[$proces_id] + 1] = $tmp;
  319. }
  320. if (empty($wsk_order)) return;
  321. foreach ($wsk_order as $k_sort_prio => $v_proces_id) {
  322. $sql = "update `CRM_PROCES` set `TEST_SORT_PRIO`='{$k_sort_prio}' where `ID`='{$v_proces_id}'; ";
  323. $db->query($sql);
  324. }
  325. return true;
  326. }
  327. public static function proces_flag($proces_id, $goto_id, $flag) {
  328. $ret = '';
  329. switch ($flag) {
  330. case 'GOTO':
  331. $ret = '<span style="color:#FF0000">' . "&rarr;" . '</span>' . $goto_id;
  332. break;
  333. case 'GOTO_AND_RETURN':
  334. $ret = '<span style="color:#FF0000">' . "&rarr;" . '</span>' . $goto_id . '<span style="color:#FF0000">' . "&crarr;" . '</span>';
  335. break;
  336. case 'FORK':
  337. $ret = '<span style="color:#FF0000">' . "&oplus;&rarr;" . '</span>' . $goto_id;
  338. break;
  339. }
  340. return $ret;
  341. }
  342. /**
  343. * Get proces GOTO data list.
  344. * @param array $params
  345. * $params['return_by']:
  346. * '' - default retrun array('ID'=>$row)
  347. * 'dest' - return array('IF_TRUE_GOTO'=>array('ID'=>$row))
  348. * @returns array
  349. */
  350. public static function get_goto_list($params = array()) {
  351. $ret = array();
  352. $return_by = V::get('return_by', '', $params);
  353. $db = DB::getDB();
  354. $sql = "select
  355. p.`ID`
  356. , p.`IF_TRUE_GOTO`
  357. , p.`IF_TRUE_GOTO_FLAG`
  358. from `CRM_PROCES` as p
  359. where
  360. p.`IF_TRUE_GOTO`>0
  361. and p.`PARENT_ID`>=0
  362. and p.`A_STATUS` in('WAITING','NORMAL')
  363. ";
  364. $res = $db->query($sql);
  365. while ($r = $db->fetch($res)) {
  366. if ($return_by == 'dest') {
  367. $ret[$r->IF_TRUE_GOTO][] = $r;
  368. } else {
  369. $ret[$r->ID] = $r;
  370. }
  371. }
  372. return $ret;
  373. }
  374. public static function getGoToProces($id) {
  375. static $_cache;
  376. if (!is_array($_cache)) {
  377. $_cache = array();
  378. $db = DB::getDB();
  379. //todo do optymalizacji ze struktur
  380. $sql="select p.`ID`, p.`IF_TRUE_GOTO`, p.`IF_TRUE_GOTO_FLAG`
  381. from `CRM_PROCES` as p
  382. where p.`IF_TRUE_GOTO` > 0
  383. and p.`A_STATUS`!='DELETED'
  384. ";
  385. $res = $db->query($sql);
  386. while ($r = $db->fetch($res)) {
  387. $_cache[$r->IF_TRUE_GOTO][$r->ID] = $r->IF_TRUE_GOTO_FLAG;
  388. }
  389. }
  390. $gotoList = array();
  391. if (array_key_exists($id, $_cache)) {
  392. $gotoList = $_cache[$id];
  393. }
  394. return $gotoList;
  395. }
  396. public static function get_wskaznik($wsk_id) {
  397. $ret = array();
  398. $db = DB::getDB();
  399. $sql = "select
  400. clz.*
  401. , w.`ID` as CW_ID, w.`TYP` as CW_TYP, w.`OPIS_ZASOB` as OPIS_ZASOB, w.`SORT_PRIO` as CW_SORT_PRIO, w.`ID_PRZYPADEK` as CW_ID_PRZYPADEK
  402. , w.`A_HAS_IMAGE` as CW_A_HAS_IMAGE
  403. , cp.`PYTANIE` as CP_PYTANIE, cp.`OPIS` as CP_OPIS, cp.`FORM_TREAT` as CP_FORM_TREAT
  404. from `CRM_WSKAZNIK` as w
  405. left join `CRM_LISTA_ZASOBOW` as clz on (clz.`ID`=w.`ID_ZASOB`)
  406. left join `CRM_PRZYPADEK` as cp on (cp.`ID`=w.`ID_PRZYPADEK`)
  407. where
  408. w.`ID`='{$wsk_id}'
  409. and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
  410. ";
  411. $res = $db->query($sql);
  412. if ($r = $db->fetch($res)) {
  413. $ret[$r->CW_ID] = $r;
  414. }
  415. return $ret;
  416. }
  417. public static function get_proces($next_id) {
  418. return DB::get_by_id('CRM_PROCES', $next_id);
  419. }
  420. public static function get_proces_init_by_zasob_id($id_zasob) {
  421. $db = DB::getDB();
  422. $sqlFilter = " cw.ID_ZASOB={$id_zasob}";
  423. if (is_array($id_zasob)) {
  424. $sqlFilter = " cw.ID_ZASOB in ".implode(',', $id_zasob);
  425. }
  426. $sql = "select
  427. cps.ID_PROCES_INIT
  428. , cw.ID_PROCES
  429. from CRM_WSKAZNIK as cw
  430. left join _CRM_PROCES_STATS_proc_wiev as cps on(cps.ID = cw.ID_PROCES)
  431. where cw.A_STATUS in('NORMAL', 'WAITING')
  432. and cps.ID_PROCES_INIT > 0 and
  433. {$sqlFilter}
  434. ";
  435. $res = $db->query($sql);
  436. while ($h = $db->fetch($res)) {
  437. $ret[] = $h->ID_PROCES_INIT;
  438. }
  439. return $ret;
  440. }
  441. public static function getZasobTableInfo($idTable) {
  442. $tableInfo = null;
  443. $db = DB::getDB();
  444. $sql = <<<SQL
  445. select tv.`ID_TABLE` as `ID`
  446. , tv.`TABLE_NAME` as `DESC`
  447. , tv.`TABLE_LABEL` as `DESC_PL`
  448. , tv.`TABLE_DESCRIPTION` as `OPIS`
  449. , zpp.`ID` as P__ID
  450. , zpp.`DESC` as P__DESC
  451. , zpp.`TYPE` as P__TYPE
  452. from `CRM_PROCES_idx_TABLES_INFO_VIEW` as tv
  453. join `CRM_LISTA_ZASOBOW` as zpp on(zpp.`ID`=tv.`ID_DATABASE`)
  454. where tv.`ID_TABLE`='{$idTable}'
  455. limit 1
  456. SQL;
  457. $res = $db->query($sql);
  458. if ($res) {
  459. $tableInfo = $db->fetch($res);
  460. }
  461. return $tableInfo;
  462. }
  463. public static function getZasobTableInfoByUri($uri) {
  464. $zasobObj = null;
  465. $db = DB::getDB();
  466. $uriParts = explode('/', $uri);
  467. if (count($uriParts) < 2) {
  468. return null;
  469. }
  470. $tblName = array_pop($uriParts);
  471. $dbName = array_pop($uriParts);
  472. if ('default_db' == $dbName) {
  473. $dbName = $db->getDatabaseName();
  474. }
  475. $sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
  476. , zp.`ID` as P__ID, zp.`DESC` as P__DESC, zp.`TYPE` as P__TYPE
  477. from `CRM_LISTA_ZASOBOW` as z
  478. left join `CRM_LISTA_ZASOBOW` as zp on(zp.`ID`=z.`PARENT_ID`)
  479. where z.`DESC`='{$tblName}'
  480. and z.`TYPE`='TABELA'
  481. and zp.`DESC`='{$dbName}'
  482. -- and zp.`TYPE` in('DATABASE_MYSQL','DATABASE','BAZA_DANYCH')
  483. ";
  484. DBG::_('DBG_SQL', '1', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
  485. $res = $db->query($sql);
  486. if ($res) {
  487. $zasobObj = $db->fetch($res);
  488. }
  489. return $zasobObj;
  490. }
  491. public static function getZasobTableFieldsInfo($id) {
  492. $fldsInfo = array();
  493. $db = DB::getDB();
  494. $sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`, z.`SORT_PRIO`
  495. from `CRM_LISTA_ZASOBOW` as z
  496. where z.`TYPE`='KOMORKA'
  497. and z.`PARENT_ID`={$id}
  498. ";
  499. if('1' == V::get('DBG_SQL', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid green;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  500. $res = $db->query($sql);
  501. while ($r = $db->fetch($res)) {
  502. $fldsInfo[$r->DESC] = $r;
  503. }
  504. return $fldsInfo;
  505. }
  506. public static function getZasobInfo($zasobID) {
  507. $zasobObj = null;
  508. $db = DB::getDB();
  509. $sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`, z.`TYPE`
  510. , zp.`ID` as P__ID
  511. , zp.`DESC` as P__DESC
  512. , zp.`TYPE` as P__TYPE
  513. from `CRM_LISTA_ZASOBOW` as z
  514. left join `CRM_LISTA_ZASOBOW` as zp on(zp.`ID`=z.`PARENT_ID`)
  515. where z.`ID`='{$zasobID}'
  516. ";
  517. $res = $db->query($sql);
  518. if ($res) {
  519. $zasobObj = $db->fetch($res);
  520. }
  521. return $zasobObj;
  522. }
  523. public static function getZasobTableID($tblName) {
  524. $zasobID = 0;
  525. $db = DB::getDB();
  526. $sql = "select z.`ID`
  527. from `CRM_LISTA_ZASOBOW` as z
  528. where z.`DESC`='{$tblName}'
  529. and z.`TYPE`='TABELA'
  530. ";
  531. $res = $db->query($sql);
  532. if ($res) {
  533. $r = $db->fetch($res);
  534. $zasobID = $r->ID;
  535. }
  536. return $zasobID;
  537. }
  538. }