TypespecialVariable.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. <?php
  2. Lib::loadClass('TypespecialBase');
  3. Lib::loadClass('SqlQueryWhereBuilder');
  4. class TypespecialVariable extends TypespecialBase {
  5. private $fldID;
  6. private $fldName;
  7. public function __construct($fldID, $fldName) {
  8. $this->fldID = $fldID;
  9. $this->fldName = $fldName;
  10. }
  11. public static function getInstance($fldID, $fldName) {
  12. switch ($fldName) {
  13. case 'A_ADM_COMPANY':
  14. case 'A_CLASSIFIED':
  15. case 'K_OD_KOGO':
  16. case 'OD_KOGO_ADRES':
  17. case 'M_DISTRIBUTOR':
  18. case '__CONNECTIONS':
  19. case '__NESTED_GROUPS':
  20. case '__USER_GROUPS':
  21. case '__TELBOXES':
  22. case '__TELBOXES_NAME':
  23. case '__DEALS_SALES_TELBOXES_NAME':
  24. case '__ZALICZKI_NAJEMCOW__NAJEMCA':
  25. case '__ZASOB':
  26. case '__PROCES':
  27. case '__COMPANIES':
  28. case 'DEFAULT_ACL_GROUP':
  29. case 'VERSION_GIT':
  30. case '__USER_ID':
  31. case '__USER_LOGIN':
  32. case 'A_EXEC_GROUP':
  33. // case 'L_APPOITMENT_USER':
  34. return new TypespecialVariable($fldID, $fldName);
  35. break;
  36. }
  37. return null;
  38. }
  39. /**
  40. * @returns [{id:int, param_out:str, exports:[]}]
  41. */
  42. public function getValuesWithExports($query, $params = array()) {
  43. $items = $this->_getValues($query, false, $params);
  44. return $items;
  45. }
  46. public function getValuesByIds($tblId, $ids) {
  47. return null;
  48. }
  49. public function getEditSelectedValuesByIds($tblId, $id, $fieldName, $fieldValue) {
  50. $items = $this->_getValues($fieldValue, true);
  51. $values = array();
  52. foreach ($items as $vItem) {
  53. $values[$vItem->param_out] = $vItem->param_out;
  54. }
  55. return $values;
  56. }
  57. public function hGetFormItem($acl, $fieldNamespace, $tblID, $fName, $selValue = '', $params = array(), $record = null) {
  58. $jsonAllowCreate = 'true';
  59. switch ($this->fldName) {
  60. case 'L_APPOITMENT_USER':
  61. case 'A_ADM_COMPANY':
  62. case 'A_CLASSIFIED':
  63. case 'DEFAULT_ACL_GROUP':
  64. case 'VERSION_GIT':
  65. case '__USER_ID':
  66. case '__USER_LOGIN':
  67. $jsonAllowCreate = 'false';
  68. break;
  69. }
  70. if (array_key_exists('allowCreate', $params)) $jsonAllowCreate = ($params['allowCreate'])? 'true' : 'false';
  71. $tsValue = V::get('typespecialValue', '', $params);
  72. if (!empty($selValue) && !empty($tsValue)) {
  73. $tsValue = "{$selValue}: {$tsValue}"; // TODO: only in TypespecialVariable - skip in Typespecial
  74. }
  75. $options = [];
  76. if (!empty($selValue)) {
  77. $tsVal = (!empty($tsValue))? $tsValue : $selValue;
  78. //$out .= '<option value="' . $selValue . '" selected="selected" typespecial="'.$tsVal.'">' . $tsVal . '</option>';
  79. $out .= '<option value="' . $selValue . '" selected="selected">' . $tsVal . '</option>';
  80. $options[] = [
  81. 'id' => $selValue,
  82. 'name' => ($tsValue)? $tsValue : $selValue
  83. ];
  84. }
  85. return [ 'P5UI__Typespecial', array_filter([
  86. 'idField' => $this->fldID,
  87. 'fieldNamespace' => $fieldNamespace,
  88. 'fieldName' => $fName,
  89. 'frmFldName' => V::get('formFieldName', $fName, $params),
  90. 'create' => $jsonAllowCreate,
  91. 'ajaxDataUrlBase' => V::get('ajaxDataUrlBase', "index-ajax.php?_cls=TableAjax&_zasobID={$tblID}&_task=TYPESPECIAL&fldID={$this->fldID}", $params),
  92. 'options' => $options,
  93. 'type' => "TypespecialVariable",
  94. 'preload' => false,
  95. ], function ($value) { return null !== $value; }),
  96. (!empty($options))
  97. ? [ [ 'option', [ 'value' => $options[0]['id'] ], $options[0]['name'] ] ]
  98. : []
  99. ];
  100. }
  101. public function showFormItem($tblID, $fName, $selValue = '', $params = array(), $record = null) {
  102. $out = '';
  103. $jsonAllowCreate = 'true';
  104. switch ($this->fldName) {
  105. case 'L_APPOITMENT_USER':
  106. case 'A_ADM_COMPANY':
  107. case 'A_CLASSIFIED':
  108. case 'DEFAULT_ACL_GROUP':
  109. case 'VERSION_GIT':
  110. case '__USER_ID':
  111. case '__USER_LOGIN':
  112. $jsonAllowCreate = 'false';
  113. break;
  114. default:
  115. $jsonAllowCreate = 'true';
  116. }
  117. if (isset($params['allowCreate'])) {
  118. $jsonAllowCreate = ($params['allowCreate'])? 'true' : 'false';
  119. }
  120. $jsonPreload = 'false';
  121. switch ($this->fldName) {
  122. case 'VERSION_GIT':
  123. //$jsonPreload = 'true';
  124. break;
  125. default:
  126. $jsonPreload = 'false';
  127. }
  128. $tsValue = V::get('typespecialValue', '', $params);
  129. if (!empty($selValue) && !empty($tsValue)) {
  130. $tsValue = "{$selValue}: {$tsValue}";
  131. }
  132. $optionsJson = 'null';
  133. $out .= '<div class="typepsecial">';
  134. $outPlaceholder = '';
  135. if ('' != ($paramPlaceholder = V::get('placeholder', '', $params))) {
  136. $outPlaceholder = ' placeholder="' . $paramPlaceholder . '"';
  137. }
  138. $out .= '<select id="ts-' . $fName . '"' . $outPlaceholder . '>';
  139. if (!empty($selValue)) {
  140. $tsVal = (!empty($tsValue))? $tsValue : $selValue;
  141. //$out .= '<option value="' . $selValue . '" selected="selected" typespecial="'.$tsVal.'">' . $tsVal . '</option>';
  142. $out .= '<option value="' . $selValue . '" selected="selected">' . $tsVal . '</option>';
  143. $optionsJson = new stdClass();
  144. $optionsJson->id = $selValue;
  145. $optionsJson->name = ($tsValue)? $tsValue : $selValue;
  146. $optionsJson = array($optionsJson);
  147. $optionsJson = json_encode($optionsJson);
  148. }
  149. $out .= '</select>';
  150. $out .= '</div>';
  151. $ajaxDataUrlBase = "index-ajax.php?_cls=TableAjax&_zasobID={$tblID}&_task=TYPESPECIAL&fldID={$this->fldID}";
  152. $ajaxDataUrlBase = V::get('ajaxDataUrlBase', $ajaxDataUrlBase, $params);
  153. $frmFldName = V::get('formFieldName', $fName, $params);
  154. $out .= '<script>' . "
  155. jQuery(document).ready(function(){
  156. var fldNode=jQuery('#{$fName}'), tsNode=jQuery('#ts-{$fName}');
  157. if (!fldNode && !tsNode) {
  158. return;
  159. }
  160. fldNode.attr('name', '');
  161. fldNode.hide();
  162. if (fldNode.parent().hasClass('show-last-value')) {
  163. fldNode.parent().hide();
  164. }
  165. tsNode.attr('name', '{$frmFldName}');
  166. tsNode.attr('tabindex', fldNode.attr('tabindex'));
  167. tsNode.selectize({
  168. theme: 'typespecial',
  169. valueField: 'id',
  170. labelField: 'id',
  171. searchField: 'name',
  172. sortField: 'name',
  173. create: {$jsonAllowCreate},
  174. delimiter: ';',
  175. dataAttr: 'typespecial',
  176. preload: {$jsonPreload},
  177. options: {$optionsJson},
  178. render: {
  179. item: function(item, escape) {
  180. //console.log('item', item);
  181. //var name = formatName(item);
  182. return '<div>' +
  183. '<span class=\"name\">' + escape(item.name || item.id) + '</span>' +
  184. '</div>';
  185. },
  186. option: function(item, escape) {
  187. //console.log('--- render.option item(',item,') this:',this);
  188. return '<div>' +
  189. '<span class=\"title\">' +
  190. escape(item.name || item.id) +
  191. '</span>' +
  192. '</div>';
  193. }
  194. },
  195. onItemAdd: function(value, item) {// Invoked when an item is selected.
  196. var curSel = this.options[value] || null, fieldExport;
  197. //console.log('--- onItemAdd val(',value,'/',item.data('name'),'/',item,') this:curSel:',curSel);
  198. if (curSel && curSel.exports) {
  199. for (var i in curSel.exports) {
  200. fieldExport = jQuery('#ts-f' + i);
  201. if (fieldExport.length) {
  202. //console.log('--- onItemAdd fieldExport.selectize(',fieldExport.selectize,')', fieldExport);
  203. if (fieldExport.get(0).selectize) {
  204. fieldExport.get(0).selectize.addOption({id:curSel.exports[i], name:curSel.exports[i]});
  205. fieldExport.get(0).selectize.setValue(curSel.exports[i]);
  206. } else {
  207. //jQuery('#f' + i).val(curSel.exports[i]);
  208. }
  209. } else {
  210. //console.log('--- onItemAdd jQuery(#f' + i + ').val(', curSel.exports[i], '): fieldExport.is(input:',fieldExport.is('input'),'/select:',fieldExport.is('select'),')', fieldExport);
  211. fieldExport = jQuery('#f' + i);
  212. if (fieldExport.is('input')) {
  213. jQuery('#f' + i).val(curSel.exports[i]);
  214. } else if (fieldExport.is('select')) {
  215. //TODO: add option and select //jQuery('#f' + i).val(curSel.exports[i]);
  216. }
  217. }
  218. }
  219. }
  220. },
  221. score: function(search) {
  222. var score = this.getScoreFunction(search);
  223. return function(item) {
  224. //console.log('score:item:', item, ', score:', score(item));
  225. if (search && search == item.id) {
  226. return 1;
  227. } else {
  228. return score(item);// score(item) * (1 + Math.min(item.watchers / 100, 1));
  229. }
  230. };
  231. },
  232. load: function(query, callback) {
  233. if (!query.length) return callback();
  234. $.ajax({
  235. url: '{$ajaxDataUrlBase}',
  236. data: 'q=' + encodeURIComponent(query),
  237. type: 'POST',
  238. error: function() {
  239. callback();
  240. },
  241. success: function(res) {
  242. for (var i in res) {
  243. if (!res[i].name || res[i].id != res[i].name) {
  244. res[i].name = res[i].id + ': ' + res[i].name;
  245. }
  246. }
  247. callback(res);
  248. }
  249. });
  250. }
  251. });
  252. });
  253. " . '</script>';
  254. return $out;
  255. }
  256. /**
  257. * @params $query - query string
  258. * @params $strict - search only equal value
  259. * @returns [{id:int, param_out:str, exports:[]}]
  260. */
  261. private function _getValues($query, $strict = false, $params = array()) {
  262. $values = array();
  263. switch ($this->fldName) {
  264. case 'A_ADM_COMPANY':
  265. case 'A_CLASSIFIED':
  266. case 'A_EXEC_GROUP':
  267. Lib::loadClass('UsersHelper');
  268. $userName = User::getLogin();
  269. $userLdapGroups = UsersHelper::getLDAPGroupByUserName($userName);
  270. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">userLdapGroups (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($userLdapGroups);echo'</pre>';}
  271. if (!empty($userLdapGroups)) {
  272. foreach ($userLdapGroups as $kID => $vLdapGroup) {
  273. $allowGroup = false;
  274. //$allowGroup = $vLdapGroup->gidNumber > 1000;
  275. if ('workgroup' == $vLdapGroup->cn) {
  276. $allowGroup = true;
  277. } else {
  278. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  279. $cnTest = explode('_', $cnTest);
  280. $cnTest = $cnTest[0];
  281. if (is_numeric($cnTest)) {
  282. $allowGroup = true;
  283. }
  284. }
  285. if ($allowGroup) {
  286. if ($strict) {
  287. if (!empty($query) && $query == $vLdapGroup->cn) {
  288. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  289. }
  290. } else {
  291. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  292. //$values[$vLdapGroup->cn] = $vLdapGroup->cn;
  293. }
  294. }
  295. }
  296. }
  297. break;
  298. case 'DEFAULT_ACL_GROUP':
  299. Lib::loadClass('UsersHelper');
  300. $userLdapGroups = UsersHelper::getLDAPGroupsAll();
  301. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">userLdapGroups (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($userLdapGroups);echo'</pre>';}
  302. if (!empty($userLdapGroups)) {
  303. foreach ($userLdapGroups as $kID => $vLdapGroup) {
  304. $allowGroup = false;
  305. //$allowGroup = $vLdapGroup->gidNumber > 1000;
  306. if ('workgroup' == $vLdapGroup->cn) {
  307. $allowGroup = true;
  308. } else {
  309. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  310. $cnTest = explode('_', $cnTest);
  311. $cnTest = $cnTest[0];
  312. if (is_numeric($cnTest)) {
  313. $allowGroup = true;
  314. }
  315. }
  316. if ($allowGroup) {
  317. if ($strict) {
  318. if (!empty($query) && $query == $vLdapGroup->cn) {
  319. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  320. }
  321. } else {
  322. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  323. //$values[$vLdapGroup->cn] = $vLdapGroup->cn;
  324. }
  325. }
  326. }
  327. }
  328. break;
  329. case 'K_OD_KOGO':
  330. $db = DB::getDB();
  331. $OD_KOGO_ADRES_ID = 0;
  332. $sql = "select z2.`ID`
  333. from `CRM_LISTA_ZASOBOW` as z
  334. join `CRM_LISTA_ZASOBOW` as z2 on (z2.`PARENT_ID`=z.`PARENT_ID`)
  335. where
  336. z.`ID`='{$this->fldID}'
  337. and z2.`DESC`='OD_KOGO_ADRES'
  338. ";
  339. if(V::get('DBG_TS', 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>';}
  340. $res = $db->query($sql);
  341. while ($r = $db->fetch($res)) {
  342. $OD_KOGO_ADRES_ID = $r->ID;
  343. }
  344. $sqlLimit = 20;
  345. $query = trim($query, ' %');
  346. $query = $db->_($query);
  347. $sqlSearch = "k.`K_OD_KOGO` like '%{$query}%'";
  348. if ($strict) {
  349. if (!empty($query)) {
  350. $sqlLimit = 1;
  351. $sqlSearch = "k.`K_OD_KOGO`='{$query}'";
  352. } else {
  353. return $values;
  354. }
  355. }
  356. $sql = "select k.`K_OD_KOGO`, k.`OD_KOGO_ADRES`
  357. from `IN7_DZIENNIK_KORESP` as k
  358. where {$sqlSearch}
  359. group by k.`K_OD_KOGO`
  360. limit {$sqlLimit}
  361. ";
  362. if(V::get('DBG_TS', 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>';}
  363. $res = $db->query($sql);
  364. while ($r = $db->fetch($res)) {
  365. $values[] = (object)array('id'=>$r->K_OD_KOGO, 'param_out'=>$r->K_OD_KOGO, 'exports'=>array($OD_KOGO_ADRES_ID => $r->OD_KOGO_ADRES));
  366. }
  367. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  368. break;
  369. case 'OD_KOGO_ADRES':
  370. $db = DB::getDB();
  371. $query = trim($query, ' %');
  372. $query = $db->_($query);
  373. $sqlLimit = 20;
  374. $sqlSearch = "k.`OD_KOGO_ADRES` like '%{$query}%'";
  375. if ($strict) {
  376. if (!empty($query)) {
  377. $sqlLimit = 1;
  378. $sqlSearch = "k.`OD_KOGO_ADRES`='{$query}'";
  379. } else {
  380. return $values;
  381. }
  382. }
  383. $sql = "select k.`OD_KOGO_ADRES`
  384. from `IN7_DZIENNIK_KORESP` as k
  385. where {$sqlSearch}
  386. group by k.`OD_KOGO_ADRES`
  387. limit {$sqlLimit}
  388. ";
  389. if(V::get('DBG_TS', 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>';}
  390. $res = $db->query($sql);
  391. while ($r = $db->fetch($res)) {
  392. $values[] = (object)array('id'=>$r->OD_KOGO_ADRES, 'param_out'=>$r->OD_KOGO_ADRES);
  393. }
  394. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  395. break;
  396. case 'M_DISTRIBUTOR':
  397. $db = DB::getDB();
  398. $query = trim($query, ' %');
  399. $query = $db->_($query);
  400. $sqlLimit = 20;
  401. $sqlSearch = "p.`M_DISTRIBUTOR` like '%{$query}%'";
  402. if ($strict) {
  403. if (!empty($query)) {
  404. $sqlLimit = 1;
  405. $sqlSearch = "p.`M_DISTRIBUTOR`='{$query}'";
  406. } else {
  407. return $values;
  408. }
  409. }
  410. $sql = "select p.`M_DISTRIBUTOR`
  411. from `IN7_MK_BAZA_DYSTRYBUCJI` as p
  412. where p.`M_DISTRIBUTOR` like '%{$query}%'
  413. group by p.`M_DISTRIBUTOR`
  414. limit {$sqlLimit}
  415. ";
  416. if(V::get('DBG_TS', 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>';}
  417. $res = $db->query($sql);
  418. while ($r = $db->fetch($res)) {
  419. $values[] = (object)array('id'=>$r->M_DISTRIBUTOR, 'param_out'=>$r->M_DISTRIBUTOR);
  420. }
  421. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  422. break;
  423. case '__NESTED_GROUPS': {
  424. $db = DB::getDB();
  425. $query = trim($query, ' %');
  426. $query = $db->_($query);
  427. $sqlLimit = 20;
  428. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  429. from `CRM_LISTA_ZASOBOW` as z
  430. where z.`A_STATUS` in('NORMAL', 'WAITING')
  431. and z.`TYPE` in('STANOWISKO', 'PODMIOT', 'DZIAL')
  432. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  433. group by z.`DESC`
  434. limit {$sqlLimit}
  435. ";
  436. if(V::get('DBG_TS', 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>';}
  437. $res = $db->query($sql);
  438. while ($r = $db->fetch($res)) {
  439. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  440. }
  441. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  442. break;
  443. }
  444. case '__USER_GROUPS': {
  445. $db = DB::getDB();
  446. $query = trim($query, ' %');
  447. $query = $db->_($query);
  448. $sqlLimit = 20;
  449. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  450. from `CRM_LISTA_ZASOBOW` as z
  451. where z.`A_STATUS` in('NORMAL', 'WAITING')
  452. and z.`TYPE` in('STANOWISKO', 'PODMIOT', 'DZIAL')
  453. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  454. group by z.`DESC`
  455. limit {$sqlLimit}
  456. ";
  457. if(V::get('DBG_TS', 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>';}
  458. $res = $db->query($sql);
  459. while ($r = $db->fetch($res)) {
  460. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  461. }
  462. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  463. break;
  464. }
  465. case '__TELBOXES': {
  466. $db = DB::getDB();
  467. $query = trim($query, ' %');
  468. $query = $db->_($query);
  469. $sqlLimit = 20;
  470. $sql = "select tx.`ID`, tx.`T_TELBOX_NAME`, tx.`T_TELBOX_TYPE`
  471. from `TELBOXES` as tx
  472. where
  473. tx.`A_STATUS`!='DELETED'
  474. and (tx.`ID` like '%{$query}%' or tx.`T_TELBOX_NAME` like '%{$query}%')
  475. order by tx.`T_TELBOX_NAME`
  476. limit {$sqlLimit}
  477. ";
  478. if(V::get('DBG_TS', 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>';}
  479. $res = $db->query($sql);
  480. while ($r = $db->fetch($res)) {
  481. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->T_TELBOX_NAME . ' ' . $r->T_TELBOX_TYPE);
  482. }
  483. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  484. break;
  485. }
  486. case '__TELBOXES_NAME': {
  487. $db = DB::getDB();
  488. $query = trim($query, ' %');
  489. $query = $db->_($query);
  490. $sqlLimit = 20;
  491. $sql = "select tx.`ID`, tx.`T_TELBOX_NAME`, tx.`T_TELBOX_TYPE`
  492. from `TELBOXES` as tx
  493. where
  494. tx.`A_STATUS`!='DELETED'
  495. and (tx.`ID` like '%{$query}%' or tx.`T_TELBOX_NAME` like '%{$query}%')
  496. order by tx.`T_TELBOX_NAME`
  497. limit {$sqlLimit}
  498. ";
  499. if(V::get('DBG_TS', 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>';}
  500. $res = $db->query($sql);
  501. while ($r = $db->fetch($res)) {
  502. $values[] = (object)array('id'=>$r->T_TELBOX_NAME, 'param_out'=>$r->T_TELBOX_NAME . ' ' . $r->T_TELBOX_TYPE);
  503. }
  504. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  505. break;
  506. }
  507. case '__DEALS_SALES_TELBOXES_NAME': {
  508. $db = DB::getDB();
  509. $query = trim($query, ' %');
  510. $query = $db->_($query);
  511. $sqlLimit = 20;
  512. $sql = "select x.`id`, x.`label`
  513. from (
  514. select d.`T_TELBOX_NEIGHBOUR_IN` as `id`
  515. , d.`marka` as `label`
  516. from `DEALS_SALES` d
  517. where d.`A_STATUS`!='DELETED'
  518. group by d.`T_TELBOX_NEIGHBOUR_IN`, d.`marka`
  519. ) as x
  520. where x.`id` like '%{$query}%' or x.`label` like '%{$query}%'
  521. order by x.`label`
  522. limit {$sqlLimit}
  523. ";
  524. if(V::get('DBG_TS', 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>';}
  525. $res = $db->query($sql);
  526. while ($r = $db->fetch($res)) {
  527. $values[] = (object)array('id'=>$r->id . ': '. $r->label, 'param_out'=>'');
  528. }
  529. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  530. break;
  531. }
  532. case '__ZALICZKI_NAJEMCOW__NAJEMCA': {
  533. $pdo = DB::getPDO();
  534. $query = trim($query, ' %');
  535. $sqlLimit = 20;
  536. $sql = "select x.`id`, x.`label`
  537. from (
  538. select d.`NAJEMCA` as `id`
  539. , d.`NAJEMCA` as `label`
  540. from `ZALICZKI_NAJEMCOW` d
  541. where d.`A_STATUS`!='DELETED'
  542. and d.`NAJEMCA` like :query_like
  543. group by d.`NAJEMCA`
  544. ) as x
  545. order by x.`label`
  546. limit {$sqlLimit}
  547. ";
  548. DBG::_('DBG_TS', '>2', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
  549. $sth = $pdo->prepare($sql);
  550. $sth->bindValue(':query_like', "%{$query}%", PDO::PARAM_STR);
  551. $sth->execute();
  552. $list = $sth->fetchAll();
  553. foreach ($list as $item) {
  554. $values[] = (object)array('id'=>$item['id'], 'param_out'=>'');
  555. }
  556. DBG::_('DBG_TS', '>2', "values", $values, __CLASS__, __FUNCTION__, __LINE__);
  557. break;
  558. }
  559. case '__ZASOB': {
  560. $db = DB::getDB();
  561. $sqlQuery = new stdClass();
  562. $sqlQuery->limit = 20;
  563. $sqlQuery->orderBy = "";
  564. $sqlQuery->selectLabel = "concat(z.`TYPE`, ' ', z.`DESC`)";
  565. $sqlQuery->selectAddBestFit = "";
  566. $sqlQuery->whereAddQueryByWords = "";
  567. $sqlWhereAddType = "";
  568. if (!empty($params['zasob_type_in'])) {
  569. if (is_scalar($params['zasob_type_in'])) $params['zasob_type_in'] = array($params['zasob_type_in']);
  570. $sqlWhereAddType = " and z.`TYPE` IN('" . implode("','", $params['zasob_type_in']) . "') ";
  571. if (in_array('KOMORKA', $params['zasob_type_in'])) {
  572. $sqlQuery->selectLabel = "concat(z.`TYPE`, ' ', z.`DESC` , ' (', (select zp.`DESC` from `CRM_LISTA_ZASOBOW` as zp where zp.`ID`=z.`PARENT_ID` limit 1), ')')";
  573. }
  574. }
  575. $query = trim($query, ' %');
  576. $sqlQuery->_queryByWords = array();
  577. if (is_numeric($query)) {
  578. $sqlQueryNum = intval($query);
  579. $sqlQuery->_queryByWords[] = "z.`ID` like '%{$sqlQueryNum}%'";
  580. $sqlQuery->selectAddBestFit = "
  581. , IF (z.`ID`='{$sqlQueryNum}', 1000,
  582. IF (z.`ID` like '{$sqlQueryNum}%', 900, 100)
  583. ) as _bestFit
  584. ";
  585. $sqlQuery->orderBy = "order by _bestFit DESC";
  586. } else {
  587. $queryWhereBuilder = new SqlQueryWhereBuilder();
  588. $searchWords = $queryWhereBuilder->splitQueryToWords($query);
  589. DBG::_('DBG_TS', '>2', "SqlQueryWhereBuilder->splitQueryToWords({$query})", $searchWords, __CLASS__, __FUNCTION__, __LINE__);
  590. $sqlWords = array();
  591. if (!empty($searchWords)) {
  592. foreach ($searchWords as $word) {
  593. if (is_numeric($word)) {
  594. $sqlWord = intval($word);
  595. $sqlQuery->_queryByWords[] = " ( z.`ID` like '%{$sqlWord}%' or z.`DESC` like '%{$sqlWord}%' ) ";
  596. } else {
  597. $sqlWord = $db->_($word);
  598. $sqlQuery->_queryByWords[] = "z.`DESC` like '%{$sqlWord}%'";
  599. }
  600. }
  601. }
  602. }
  603. if (!empty($sqlQuery->_queryByWords)) {
  604. $sqlQuery->whereAddQueryByWords = " and (" . implode(" and ", $sqlQuery->_queryByWords) . ")";
  605. }
  606. $sql = "select z.`ID`
  607. , {$sqlQuery->selectLabel} as `LABEL`
  608. {$sqlQuery->selectAddBestFit}
  609. from `CRM_LISTA_ZASOBOW` as z
  610. where z.`A_STATUS` in('NORMAL', 'WAITING')
  611. {$sqlQuery->whereAddQueryByWords}
  612. {$sqlWhereAddType}
  613. {$sqlQuery->orderBy}
  614. limit {$sqlQuery->limit}
  615. ";
  616. DBG::_('DBG_TS', '>2', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
  617. $res = $db->query($sql);
  618. while ($r = $db->fetch($res)) {
  619. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  620. }
  621. DBG::_('DBG_TS', '>2', "values", $values, __CLASS__, __FUNCTION__, __LINE__);
  622. break;
  623. }
  624. case '__PROCES': {
  625. $db = DB::getDB();
  626. $query = trim($query, ' %');
  627. $query = $db->_($query);
  628. $sqlLimit = 20;
  629. $sqlSelectLabel = "concat(z.`TYPE`, ' ', z.`DESC`)";
  630. $sqlWhereAdd = "";
  631. if (is_numeric($query)) {
  632. $sql = "select z.`ID`
  633. , {$sqlSelectLabel} as `LABEL`
  634. , IF (z.`ID`='{$query}', 1000,
  635. IF (z.`ID` like '{$query}%', 900, 100)
  636. ) as _bestFit
  637. from `CRM_PROCES` as z
  638. where z.`A_STATUS` in('NORMAL', 'WAITING')
  639. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  640. {$sqlWhereAdd}
  641. order by _bestFit DESC
  642. limit {$sqlLimit}
  643. ";
  644. } else {
  645. $sql = "select z.`ID`
  646. , {$sqlSelectLabel} as `LABEL`
  647. from `CRM_PROCES` as z
  648. where z.`A_STATUS` in('NORMAL', 'WAITING')
  649. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  650. {$sqlWhereAdd}
  651. limit {$sqlLimit}
  652. ";
  653. }
  654. if(V::get('DBG_TS', 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>';}
  655. $res = $db->query($sql);
  656. while ($r = $db->fetch($res)) {
  657. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  658. }
  659. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  660. break;
  661. }
  662. case '__COMPANIES': {
  663. $db = DB::getDB();
  664. $query = trim($query, ' %');
  665. $query = $db->_($query);
  666. $sqlLimit = 20;
  667. $sql = "select c.`ID`, c.`P_NAME`, c.`P_NIP`
  668. from `COMPANIES` as c
  669. where c.`A_STATUS` in('NORMAL', 'WAITING')
  670. and (c.`P_NAME` like '%{$query}%' or c.`P_NIP` like '%{$query}%' or c.`ID` like '%{$query}%')
  671. limit {$sqlLimit}
  672. ";
  673. if(V::get('DBG_TS', 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>';}
  674. $res = $db->query($sql);
  675. while ($r = $db->fetch($res)) {
  676. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->P_NAME . ' ' . $r->P_NIP);
  677. }
  678. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  679. break;
  680. }
  681. case 'VERSION_GIT': {
  682. $gitPath = '/Library/Server/Web/Data/Sites/SE-production-git/';
  683. $versions = array();
  684. if (file_exists($gitPath)) {
  685. $cmd = "cd {$gitPath} && git tag -l| sort -r -n -t. -k1,1 -k2,2 -k3,3 -k4,4|head -10";
  686. $cmdOut = null; $cmdRet = null;
  687. exec($cmd, $cmdOut, $cmdRet);
  688. if ($cmdRet == 0) {
  689. if (!empty($cmdOut)) {
  690. foreach ($cmdOut as $tag) {
  691. array_unshift($versions, $tag);
  692. }
  693. }
  694. }
  695. }
  696. foreach ($versions as $version) {
  697. if (!empty($query)) {
  698. if ($strict) {
  699. if ($version != $query) {
  700. continue;
  701. }
  702. }
  703. else {
  704. if (false === strpos($version, $query)) {
  705. continue;
  706. }
  707. }
  708. }
  709. $values[] = (object)array('id'=>$version, 'param_out'=>$version);
  710. }
  711. }
  712. case '__USER_ID': {
  713. $db = DB::getDB();
  714. $query = trim($query, ' %');
  715. $query = $db->_($query);
  716. $sqlLimit = 20;
  717. $sqlSelectLabel = array();
  718. $sqlSelectLabel[] = 'u.`ADM_NAME`';
  719. $sqlSelectLabel[] = "' ('";
  720. $sqlSelectLabel[] = 'u.`ADM_ACCOUNT`';
  721. $sqlSelectLabel[] = "', '";
  722. $sqlSelectLabel[] = 'u.`EMAIL`';
  723. $sqlSelectLabel[] = "', '";
  724. $sqlSelectLabel[] = 'u.`ADM_PHONE`';
  725. $sqlSelectLabel[] = "')'";
  726. $sqlSelectLabel = "concat(" . implode(", ", $sqlSelectLabel) . ")";
  727. $sql = "select u.`ID`
  728. , {$sqlSelectLabel} as `LABEL`
  729. from `ADMIN_USERS` as u
  730. where u.`A_STATUS` in('NORMAL', 'WAITING','MONITOR','WARNING')
  731. and u.`EMPLOYEE_TYPE` in('Pracownik','Partner')
  732. and (u.`ID` like '%{$query}%'
  733. or u.`ADM_ACCOUNT` like '%{$query}%'
  734. or u.`ADM_NAME` like '%{$query}%'
  735. or u.`ADM_PHONE` like '%{$query}%'
  736. or u.`EMAIL` like '%{$query}%'
  737. )
  738. limit {$sqlLimit}
  739. ";
  740. if(V::get('DBG_TS', 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>';}
  741. $res = $db->query($sql);
  742. while ($r = $db->fetch($res)) {
  743. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  744. }
  745. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  746. break;
  747. }
  748. case '__USER_LOGIN': {
  749. $db = DB::getDB();
  750. $query = trim($query, ' %');
  751. $query = $db->_($query);
  752. $sqlLimit = 20;
  753. $sqlSelectLabel = array();
  754. $sqlSelectLabel[] = 'u.`ADM_NAME`';
  755. $sqlSelectLabel[] = "' ('";
  756. $sqlSelectLabel[] = 'u.`ADM_ACCOUNT`';
  757. $sqlSelectLabel[] = "', '";
  758. $sqlSelectLabel[] = 'u.`EMAIL`';
  759. $sqlSelectLabel[] = "', '";
  760. $sqlSelectLabel[] = 'u.`ADM_PHONE`';
  761. $sqlSelectLabel[] = "')'";
  762. $sqlSelectLabel = "concat(" . implode(", ", $sqlSelectLabel) . ")";
  763. $sql = "select u.`ADM_ACCOUNT` as ID
  764. , {$sqlSelectLabel} as `LABEL`
  765. from `ADMIN_USERS` as u
  766. where u.`A_STATUS` in('NORMAL', 'WAITING','MONITOR','WARNING')
  767. and u.`EMPLOYEE_TYPE` in('Pracownik','Partner')
  768. and (u.`ID` like '%{$query}%'
  769. or u.`ADM_ACCOUNT` like '%{$query}%'
  770. or u.`ADM_NAME` like '%{$query}%'
  771. or u.`ADM_PHONE` like '%{$query}%'
  772. or u.`EMAIL` like '%{$query}%'
  773. )
  774. limit {$sqlLimit}
  775. ";
  776. if(V::get('DBG_TS', 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>';}
  777. $res = $db->query($sql);
  778. while ($r = $db->fetch($res)) {
  779. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  780. }
  781. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  782. return $values;
  783. }
  784. case 'L_APPOITMENT_USER': {
  785. $query = trim($query, ' %');
  786. $acl = User::getAcl()->getObjectAcl('default_db', 'ADMIN_USERS');
  787. $queryFeatures = $acl->buildQuery([
  788. (!empty($query))
  789. ? [null, 'or', [
  790. (is_numeric($query)) ? ['ID', 'like', "{$query}%"] : null,
  791. ['ADM_ACCOUNT', 'like', "%{$query}%"],
  792. ['ADM_NAME', 'like', "%{$query}%"],
  793. ['ADM_PHONE', 'like', "%{$query}%"],
  794. ['EMAIL', 'like', "%{$query}%"],
  795. ] ]
  796. : null,
  797. 'f_A_STATUS' => '=NORMAL',
  798. 'f_ADM_TECH_WORKER' => '!NO',
  799. 'limit' => 20
  800. ]);
  801. return array_map(function ($item) {
  802. return (object)[
  803. 'id' => $item['ID'],
  804. 'param_out' => "{$item['ADM_NAME']} ({$item['ADM_ACCOUNT']})"
  805. ];
  806. }, $queryFeatures->getItems());
  807. } break;
  808. default:
  809. }
  810. return $values;
  811. }
  812. /**
  813. * @returns object
  814. * {
  815. * ext_tbl_id: "1466",
  816. * ext_row_id: "2975",
  817. * id: "2975",
  818. * tbl_label: "Zasoby",
  819. * link_type_id: "5",
  820. * link_type: "NestedGroups",
  821. * },
  822. */
  823. public function getReturnData($tblId, $rowId, $fieldName) {
  824. $retData = new stdClass();
  825. $retData->items = array();
  826. $values = array();
  827. switch ($this->fldName) {
  828. case '__CONNECTIONS': {
  829. $linkTypes = array();
  830. $tblLabels = array();
  831. $db = DB::getDB();
  832. $sqlLimit = 21;
  833. $sql = "select l.*
  834. from `ITEM_LINKS` as l
  835. where l.`A_STATUS` in('NORMAL', 'WAITING')
  836. and (
  837. (l.`TABLE_1_ZASOB_ID`={$tblId} and l.`TABLE_1_ID`={$rowId})
  838. or
  839. (l.`TABLE_2_ZASOB_ID`={$tblId} and l.`TABLE_2_ID`={$rowId})
  840. )
  841. and l.`LINKS_TYPE_ID`>1
  842. limit {$sqlLimit}
  843. ";
  844. if(V::get('DBG_TS', 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>';}
  845. $res = $db->query($sql);
  846. while ($r = $db->fetch($res)) {
  847. $connObj = new stdClass();
  848. if ($r->TABLE_1_ZASOB_ID == $tblId && $r->TABLE_1_ID == $rowId) {
  849. $connObj->ext_tbl_id = $r->TABLE_2_ZASOB_ID;
  850. $connObj->ext_row_id = $r->TABLE_2_ID;
  851. $connObj->id = $r->TABLE_2_ID;
  852. $connObj->label = "{$r->TABLE_2_ZASOB_ID}({$r->TABLE_2_ID})";
  853. }
  854. else if ($r->TABLE_2_ZASOB_ID == $tblId && $r->TABLE_2_ID == $rowId) {
  855. $connObj->ext_tbl_id = $r->TABLE_1_ZASOB_ID;
  856. $connObj->ext_row_id = $r->TABLE_1_ID;
  857. $connObj->id = $r->TABLE_1_ID;
  858. $connObj->label = "{$r->TABLE_1_ZASOB_ID}({$r->TABLE_1_ID})";
  859. }
  860. if ($connObj) {
  861. $connObj->link_type_id = $r->LINKS_TYPE_ID;
  862. $linkTypes[$connObj->link_type_id] = '';
  863. $tblLabels[$connObj->ext_tbl_id] = '';
  864. $retData->items[] = $connObj;
  865. }
  866. }
  867. if (!empty($linkTypes)) {
  868. $sql = "select lt.`ID`, lt.`NAME`
  869. from `ITEM_LINK_TYPES` as lt
  870. where lt.`ID` in (" . implode(", ", array_keys($linkTypes)) . ")
  871. ";
  872. $res = $db->query($sql);
  873. while ($r = $db->fetch($res)) {
  874. $linkTypes[$r->ID] = $r->NAME;
  875. }
  876. }
  877. if (!empty($tblLabels)) {
  878. $sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
  879. from `CRM_LISTA_ZASOBOW` as z
  880. where z.`ID` in (" . implode(", ", array_keys($tblLabels)) . ")
  881. ";
  882. $res = $db->query($sql);
  883. while ($r = $db->fetch($res)) {
  884. if (!empty($r->DESC_PL)) {
  885. $tblLabels[$r->ID] = $r->DESC_PL;
  886. } else if (!empty($r->OPIS)) {
  887. $tblLabels[$r->ID] = V::strShortUtf8($r->OPIS, 20);
  888. } else {
  889. $tblLabels[$r->ID] = $r->DESC;
  890. }
  891. }
  892. }
  893. foreach ($retData->items as $k => $connObj) {
  894. $connObj->link_type = V::get($connObj->link_type_id, $connObj->link_type_id, $linkTypes);
  895. $connObj->tbl_label = V::get($connObj->ext_tbl_id, $connObj->ext_tbl_id, $tblLabels);
  896. }
  897. if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">retData->items('.count($retData->items).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($retData->items);echo'</pre>';}
  898. return $retData;
  899. break;
  900. }
  901. default:
  902. }
  903. return null;
  904. }
  905. }