TypespecialVariable.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. Lib::loadClass('TypespecialBase');
  3. class TypespecialVariable extends TypespecialBase {
  4. private $fldID;
  5. private $fldName;
  6. public function __construct($fldID, $fldName) {
  7. $this->fldID = $fldID;
  8. $this->fldName = $fldName;
  9. }
  10. public static function getInstance($fldID, $fldName) {
  11. switch ($fldName) {
  12. case 'A_ADM_COMPANY':
  13. case 'A_CLASSIFIED':
  14. case 'K_OD_KOGO':
  15. case 'OD_KOGO_ADRES':
  16. case 'M_DISTRIBUTOR':
  17. case '__CONNECTIONS':
  18. case '__NESTED_GROUPS':
  19. case '__USER_GROUPS':
  20. case '__TELBOXES':
  21. case '__TELBOXES_NAME':
  22. case '__ZASOB':
  23. case '__COMPANIES':
  24. return new TypespecialVariable($fldID, $fldName);
  25. break;
  26. }
  27. return null;
  28. }
  29. /**
  30. * @returns [{id:int, param_out:str, exports:[]}]
  31. */
  32. public function getValuesWithExports($query) {
  33. $items = $this->_getValues($query);
  34. return $items;
  35. }
  36. public function getValuesByIds($tblId, $ids) {
  37. return null;
  38. }
  39. public function getEditSelectedValuesByIds($tblId, $id, $fieldName, $fieldValue) {
  40. $items = $this->_getValues($fieldValue, true);
  41. $values = array();
  42. foreach ($items as $vItem) {
  43. $values[$vItem->param_out] = $vItem->param_out;
  44. }
  45. return $values;
  46. }
  47. public function showFormItem($tblID, $fName, $selValue = '', $params = array(), $record = null) {
  48. $out = '';
  49. $jsonAllowCreate = 'true';
  50. switch ($this->fldName) {
  51. case 'A_ADM_COMPANY':
  52. case 'A_CLASSIFIED':
  53. $jsonAllowCreate = 'false';
  54. break;
  55. default:
  56. $jsonAllowCreate = 'true';
  57. }
  58. if (isset($params['allowCreate'])) {
  59. $jsonAllowCreate = ($params['allowCreate'])? 'true' : 'false';
  60. }
  61. $tsValue = V::get('typespecialValue', '', $params);
  62. if (!empty($selValue) && !empty($tsValue)) {
  63. $tsValue = "{$selValue}: {$tsValue}";
  64. }
  65. $optionsJson = 'null';
  66. $out .= '<div class="typepsecial">';
  67. $out .= '<select id="ts-' . $fName . '">';
  68. if (!empty($selValue)) {
  69. $tsVal = (!empty($tsValue))? $tsValue : $selValue;
  70. //$out .= '<option value="' . $selValue . '" selected="selected" typespecial="'.$tsVal.'">' . $tsVal . '</option>';
  71. $out .= '<option value="' . $selValue . '" selected="selected">' . $tsVal . '</option>';
  72. $optionsJson = new stdClass();
  73. $optionsJson->id = $selValue;
  74. $optionsJson->name = ($tsValue)? $tsValue : $selValue;
  75. $optionsJson = array($optionsJson);
  76. $optionsJson = json_encode($optionsJson);
  77. }
  78. $out .= '</select>';
  79. $out .= '</div>';
  80. $ajaxDataUrlBase = "index-ajax.php?_cls=TableAjax&_zasobID={$tblID}&_task=TYPESPECIAL&fldID={$this->fldID}";
  81. $ajaxDataUrlBase = V::get('ajaxDataUrlBase', $ajaxDataUrlBase, $params);
  82. $out .= '<script>' . "
  83. (function(){
  84. var fldNode=jQuery('#{$fName}'), tsNode=jQuery('#ts-{$fName}');
  85. if (!fldNode && !tsNode) {
  86. return;
  87. }
  88. fldNode.attr('name', '');
  89. fldNode.hide();
  90. if (fldNode.parent().hasClass('show-last-value')) {
  91. fldNode.parent().hide();
  92. }
  93. tsNode.attr('name', '{$fName}');
  94. tsNode.attr('tabindex', fldNode.attr('tabindex'));
  95. tsNode.selectize({
  96. theme: 'typespecial',
  97. valueField: 'id',
  98. labelField: 'id',
  99. searchField: 'name',
  100. sortField: 'name',
  101. create: {$jsonAllowCreate},
  102. delimiter: ';',
  103. dataAttr: 'typespecial',
  104. // preload: true,
  105. options: {$optionsJson},
  106. render: {
  107. item: function(item, escape) {
  108. //console.log('item', item);
  109. //var name = formatName(item);
  110. return '<div>' +
  111. '<span class=\"name\">' + escape(item.name || item.id) + '</span>' +
  112. '</div>';
  113. },
  114. option: function(item, escape) {
  115. //console.log('--- render.option item(',item,') this:',this);
  116. return '<div>' +
  117. '<span class=\"title\">' +
  118. escape(item.name || item.id) +
  119. '</span>' +
  120. '</div>';
  121. }
  122. },
  123. onItemAdd: function(value, item) {// Invoked when an item is selected.
  124. var curSel = this.options[value] || null, fieldExport;
  125. //console.log('--- onItemAdd val(',value,'/',item.data('name'),'/',item,') this:curSel:',curSel);
  126. if (curSel && curSel.exports) {
  127. for (var i in curSel.exports) {
  128. fieldExport = jQuery('#ts-f' + i);
  129. if (fieldExport.length) {
  130. //console.log('--- onItemAdd fieldExport.selectize(',fieldExport.selectize,')', fieldExport);
  131. if (fieldExport.get(0).selectize) {
  132. fieldExport.get(0).selectize.addOption({id:curSel.exports[i], name:curSel.exports[i]});
  133. fieldExport.get(0).selectize.setValue(curSel.exports[i]);
  134. } else {
  135. //jQuery('#f' + i).val(curSel.exports[i]);
  136. }
  137. } else {
  138. //console.log('--- onItemAdd jQuery(#f' + i + ').val(', curSel.exports[i], '): fieldExport.is(input:',fieldExport.is('input'),'/select:',fieldExport.is('select'),')', fieldExport);
  139. fieldExport = jQuery('#f' + i);
  140. if (fieldExport.is('input')) {
  141. jQuery('#f' + i).val(curSel.exports[i]);
  142. } else if (fieldExport.is('select')) {
  143. //TODO: add option and select //jQuery('#f' + i).val(curSel.exports[i]);
  144. }
  145. }
  146. }
  147. }
  148. },
  149. score: function(search) {
  150. var score = this.getScoreFunction(search);
  151. return function(item) {
  152. //console.log('score:item:', item, ', score:', score(item));
  153. return score(item);// score(item) * (1 + Math.min(item.watchers / 100, 1));
  154. };
  155. },
  156. load: function(query, callback) {
  157. if (!query.length) return callback();
  158. $.ajax({
  159. url: '{$ajaxDataUrlBase}',
  160. data: 'q=' + encodeURIComponent(query),
  161. type: 'POST',
  162. error: function() {
  163. callback();
  164. },
  165. success: function(res) {
  166. for (var i in res) {
  167. if (!res[i].name || res[i].id != res[i].name) {
  168. res[i].name = res[i].id + ': ' + res[i].name;
  169. }
  170. }
  171. callback(res);
  172. }
  173. });
  174. }
  175. });
  176. })()
  177. " . '</script>';
  178. return $out;
  179. }
  180. /**
  181. * @params $query - query string
  182. * @params $strict - search only euqal value
  183. * @returns [{id:int, param_out:str, exports:[]}]
  184. */
  185. private function _getValues($query, $strict = false) {
  186. $values = array();
  187. switch ($this->fldName) {
  188. case 'A_ADM_COMPANY':
  189. case 'A_CLASSIFIED':
  190. Lib::loadClass('UsersHelper');
  191. $userName = User::getLogin();
  192. $userLdapGroups = UsersHelper::getLDAPGroupByUserName($userName);
  193. 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>';}
  194. if (!empty($userLdapGroups)) {
  195. foreach ($userLdapGroups as $kID => $vLdapGroup) {
  196. $allowGroup = false;
  197. //$allowGroup = $vLdapGroup->gidNumber > 1000;
  198. if ('workgroup' == $vLdapGroup->cn) {
  199. $allowGroup = true;
  200. } else {
  201. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  202. $cnTest = explode('_', $cnTest);
  203. $cnTest = $cnTest[0];
  204. if (is_numeric($cnTest)) {
  205. $allowGroup = true;
  206. }
  207. }
  208. if ($allowGroup) {
  209. if ($strict) {
  210. if (!empty($query) && $query == $vLdapGroup->cn) {
  211. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  212. }
  213. } else {
  214. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  215. //$values[$vLdapGroup->cn] = $vLdapGroup->cn;
  216. }
  217. }
  218. }
  219. }
  220. break;
  221. case 'K_OD_KOGO':
  222. $db = DB::getDB();
  223. $OD_KOGO_ADRES_ID = 0;
  224. $sql = "select z2.`ID`
  225. from `CRM_LISTA_ZASOBOW` as z
  226. join `CRM_LISTA_ZASOBOW` as z2 on (z2.`PARENT_ID`=z.`PARENT_ID`)
  227. where
  228. z.`ID`='{$this->fldID}'
  229. and z2.`DESC`='OD_KOGO_ADRES'
  230. ";
  231. 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>';}
  232. $res = $db->query($sql);
  233. while ($r = $db->fetch($res)) {
  234. $OD_KOGO_ADRES_ID = $r->ID;
  235. }
  236. $sqlLimit = 20;
  237. $query = trim($query, ' %');
  238. $query = $db->_($query);
  239. $sqlSearch = "k.`K_OD_KOGO` like '%{$query}%'";
  240. if ($strict) {
  241. if (!empty($query)) {
  242. $sqlLimit = 1;
  243. $sqlSearch = "k.`K_OD_KOGO`='{$query}'";
  244. } else {
  245. return $values;
  246. }
  247. }
  248. $sql = "select k.`K_OD_KOGO`, k.`OD_KOGO_ADRES`
  249. from `IN7_DZIENNIK_KORESP` as k
  250. where {$sqlSearch}
  251. group by k.`K_OD_KOGO`
  252. limit {$sqlLimit}
  253. ";
  254. 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>';}
  255. $res = $db->query($sql);
  256. while ($r = $db->fetch($res)) {
  257. $values[] = (object)array('id'=>$r->K_OD_KOGO, 'param_out'=>$r->K_OD_KOGO, 'exports'=>array($OD_KOGO_ADRES_ID => $r->OD_KOGO_ADRES));
  258. }
  259. 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>';}
  260. break;
  261. case 'OD_KOGO_ADRES':
  262. $db = DB::getDB();
  263. $query = trim($query, ' %');
  264. $query = $db->_($query);
  265. $sqlLimit = 20;
  266. $sqlSearch = "k.`OD_KOGO_ADRES` like '%{$query}%'";
  267. if ($strict) {
  268. if (!empty($query)) {
  269. $sqlLimit = 1;
  270. $sqlSearch = "k.`OD_KOGO_ADRES`='{$query}'";
  271. } else {
  272. return $values;
  273. }
  274. }
  275. $sql = "select k.`OD_KOGO_ADRES`
  276. from `IN7_DZIENNIK_KORESP` as k
  277. where {$sqlSearch}
  278. group by k.`OD_KOGO_ADRES`
  279. limit {$sqlLimit}
  280. ";
  281. 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>';}
  282. $res = $db->query($sql);
  283. while ($r = $db->fetch($res)) {
  284. $values[] = (object)array('id'=>$r->OD_KOGO_ADRES, 'param_out'=>$r->OD_KOGO_ADRES);
  285. }
  286. 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>';}
  287. break;
  288. case 'M_DISTRIBUTOR':
  289. $db = DB::getDB();
  290. $query = trim($query, ' %');
  291. $query = $db->_($query);
  292. $sqlLimit = 20;
  293. $sqlSearch = "p.`M_DISTRIBUTOR` like '%{$query}%'";
  294. if ($strict) {
  295. if (!empty($query)) {
  296. $sqlLimit = 1;
  297. $sqlSearch = "p.`M_DISTRIBUTOR`='{$query}'";
  298. } else {
  299. return $values;
  300. }
  301. }
  302. $sql = "select p.`M_DISTRIBUTOR`
  303. from `IN7_MK_BAZA_DYSTRYBUCJI` as p
  304. where p.`M_DISTRIBUTOR` like '%{$query}%'
  305. group by p.`M_DISTRIBUTOR`
  306. limit {$sqlLimit}
  307. ";
  308. 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>';}
  309. $res = $db->query($sql);
  310. while ($r = $db->fetch($res)) {
  311. $values[] = (object)array('id'=>$r->M_DISTRIBUTOR, 'param_out'=>$r->M_DISTRIBUTOR);
  312. }
  313. 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>';}
  314. break;
  315. case '__NESTED_GROUPS': {
  316. $db = DB::getDB();
  317. $query = trim($query, ' %');
  318. $query = $db->_($query);
  319. $sqlLimit = 20;
  320. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  321. from `CRM_LISTA_ZASOBOW` as z
  322. where z.`A_STATUS` in('NORMAL', 'WAITING')
  323. and z.`TYPE` in('STANOWISKO', 'PODMIOT', 'DZIAL')
  324. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  325. group by z.`DESC`
  326. limit {$sqlLimit}
  327. ";
  328. 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>';}
  329. $res = $db->query($sql);
  330. while ($r = $db->fetch($res)) {
  331. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  332. }
  333. 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>';}
  334. break;
  335. }
  336. case '__USER_GROUPS': {
  337. $db = DB::getDB();
  338. $query = trim($query, ' %');
  339. $query = $db->_($query);
  340. $sqlLimit = 20;
  341. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  342. from `CRM_LISTA_ZASOBOW` as z
  343. where z.`A_STATUS` in('NORMAL', 'WAITING')
  344. and z.`TYPE` in('STANOWISKO', 'PODMIOT', 'DZIAL')
  345. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  346. group by z.`DESC`
  347. limit {$sqlLimit}
  348. ";
  349. 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>';}
  350. $res = $db->query($sql);
  351. while ($r = $db->fetch($res)) {
  352. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  353. }
  354. 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>';}
  355. break;
  356. }
  357. case '__TELBOXES': {
  358. $db = DB::getDB();
  359. $query = trim($query, ' %');
  360. $query = $db->_($query);
  361. $sqlLimit = 20;
  362. $sql = "select tx.`ID`, tx.`T_TELBOX_NAME`, tx.`T_TELBOX_TYPE`
  363. from `TELBOXES` as tx
  364. where
  365. tx.`A_STATUS`!='DELETED'
  366. and (tx.`ID` like '%{$query}%' or tx.`T_TELBOX_NAME` like '%{$query}%')
  367. order by tx.`T_TELBOX_NAME`
  368. limit {$sqlLimit}
  369. ";
  370. 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>';}
  371. $res = $db->query($sql);
  372. while ($r = $db->fetch($res)) {
  373. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->T_TELBOX_NAME . ' ' . $r->T_TELBOX_TYPE);
  374. }
  375. 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>';}
  376. break;
  377. }
  378. case '__TELBOXES_NAME': {
  379. $db = DB::getDB();
  380. $query = trim($query, ' %');
  381. $query = $db->_($query);
  382. $sqlLimit = 20;
  383. $sql = "select tx.`ID`, tx.`T_TELBOX_NAME`, tx.`T_TELBOX_TYPE`
  384. from `TELBOXES` as tx
  385. where
  386. tx.`A_STATUS`!='DELETED'
  387. and (tx.`ID` like '%{$query}%' or tx.`T_TELBOX_NAME` like '%{$query}%')
  388. order by tx.`T_TELBOX_NAME`
  389. limit {$sqlLimit}
  390. ";
  391. 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>';}
  392. $res = $db->query($sql);
  393. while ($r = $db->fetch($res)) {
  394. $values[] = (object)array('id'=>$r->T_TELBOX_NAME, 'param_out'=>$r->T_TELBOX_NAME . ' ' . $r->T_TELBOX_TYPE);
  395. }
  396. 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>';}
  397. break;
  398. }
  399. case '__ZASOB': {
  400. $db = DB::getDB();
  401. $query = trim($query, ' %');
  402. $query = $db->_($query);
  403. $sqlLimit = 20;
  404. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  405. from `CRM_LISTA_ZASOBOW` as z
  406. where z.`A_STATUS` in('NORMAL', 'WAITING')
  407. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  408. -- group by z.`DESC`
  409. limit {$sqlLimit}
  410. ";
  411. 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>';}
  412. $res = $db->query($sql);
  413. while ($r = $db->fetch($res)) {
  414. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  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;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  417. break;
  418. }
  419. case '__COMPANIES': {
  420. $db = DB::getDB();
  421. $query = trim($query, ' %');
  422. $query = $db->_($query);
  423. $sqlLimit = 20;
  424. $sql = "select c.`ID`, c.`P_NAME`, c.`P_NIP`
  425. from `COMPANIES` as c
  426. where c.`A_STATUS` in('NORMAL', 'WAITING')
  427. and (c.`P_NAME` like '%{$query}%' or c.`P_NIP` like '%{$query}%' or c.`ID` like '%{$query}%')
  428. limit {$sqlLimit}
  429. ";
  430. 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>';}
  431. $res = $db->query($sql);
  432. while ($r = $db->fetch($res)) {
  433. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->P_NAME . ' ' . $r->P_NIP);
  434. }
  435. 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>';}
  436. break;
  437. }
  438. default:
  439. }
  440. return $values;
  441. }
  442. /**
  443. * @returns object
  444. * {
  445. * ext_tbl_id: "1466",
  446. * ext_row_id: "2975",
  447. * id: "2975",
  448. * tbl_label: "Zasoby",
  449. * link_type_id: "5",
  450. * link_type: "NestedGroups",
  451. * },
  452. */
  453. public function getReturnData($tblId, $rowId, $fieldName) {
  454. $retData = new stdClass();
  455. $retData->items = array();
  456. $values = array();
  457. switch ($this->fldName) {
  458. case '__CONNECTIONS': {
  459. $linkTypes = array();
  460. $tblLabels = array();
  461. $db = DB::getDB();
  462. $sqlLimit = 21;
  463. $sql = "select l.*
  464. from `ITEM_LINKS` as l
  465. where l.`A_STATUS` in('NORMAL', 'WAITING')
  466. and (
  467. (l.`TABLE_1_ZASOB_ID`={$tblId} and l.`TABLE_1_ID`={$rowId})
  468. or
  469. (l.`TABLE_2_ZASOB_ID`={$tblId} and l.`TABLE_2_ID`={$rowId})
  470. )
  471. and l.`LINKS_TYPE_ID`>1
  472. limit {$sqlLimit}
  473. ";
  474. 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>';}
  475. $res = $db->query($sql);
  476. while ($r = $db->fetch($res)) {
  477. $connObj = new stdClass();
  478. if ($r->TABLE_1_ZASOB_ID == $tblId && $r->TABLE_1_ID == $rowId) {
  479. $connObj->ext_tbl_id = $r->TABLE_2_ZASOB_ID;
  480. $connObj->ext_row_id = $r->TABLE_2_ID;
  481. $connObj->id = $r->TABLE_2_ID;
  482. $connObj->label = "{$r->TABLE_2_ZASOB_ID}({$r->TABLE_2_ID})";
  483. }
  484. else if ($r->TABLE_2_ZASOB_ID == $tblId && $r->TABLE_2_ID == $rowId) {
  485. $connObj->ext_tbl_id = $r->TABLE_1_ZASOB_ID;
  486. $connObj->ext_row_id = $r->TABLE_1_ID;
  487. $connObj->id = $r->TABLE_1_ID;
  488. $connObj->label = "{$r->TABLE_1_ZASOB_ID}({$r->TABLE_1_ID})";
  489. }
  490. if ($connObj) {
  491. $connObj->link_type_id = $r->LINKS_TYPE_ID;
  492. $linkTypes[$connObj->link_type_id] = '';
  493. $tblLabels[$connObj->ext_tbl_id] = '';
  494. $retData->items[] = $connObj;
  495. }
  496. }
  497. if (!empty($linkTypes)) {
  498. $sql = "select lt.`ID`, lt.`NAME`
  499. from `ITEM_LINK_TYPES` as lt
  500. where lt.`ID` in (" . implode(", ", array_keys($linkTypes)) . ")
  501. ";
  502. $res = $db->query($sql);
  503. while ($r = $db->fetch($res)) {
  504. $linkTypes[$r->ID] = $r->NAME;
  505. }
  506. }
  507. if (!empty($tblLabels)) {
  508. $sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
  509. from `CRM_LISTA_ZASOBOW` as z
  510. where z.`ID` in (" . implode(", ", array_keys($tblLabels)) . ")
  511. ";
  512. $res = $db->query($sql);
  513. while ($r = $db->fetch($res)) {
  514. if (!empty($r->DESC_PL)) {
  515. $tblLabels[$r->ID] = $r->DESC_PL;
  516. } else if (!empty($r->OPIS)) {
  517. $tblLabels[$r->ID] = V::strShortUtf8($r->OPIS, 20);
  518. } else {
  519. $tblLabels[$r->ID] = $r->DESC;
  520. }
  521. }
  522. }
  523. foreach ($retData->items as $k => $connObj) {
  524. $connObj->link_type = V::get($connObj->link_type_id, $connObj->link_type_id, $linkTypes);
  525. $connObj->tbl_label = V::get($connObj->ext_tbl_id, $connObj->ext_tbl_id, $tblLabels);
  526. }
  527. 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>';}
  528. return $retData;
  529. break;
  530. }
  531. default:
  532. }
  533. return null;
  534. }
  535. }