TypespecialVariable.php 26 KB

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