TypespecialVariable.php 23 KB

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