TypespecialVariable.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. if (search && search == item.id) {
  175. return 1;
  176. } else {
  177. return score(item);// score(item) * (1 + Math.min(item.watchers / 100, 1));
  178. }
  179. };
  180. },
  181. load: function(query, callback) {
  182. if (!query.length) return callback();
  183. $.ajax({
  184. url: '{$ajaxDataUrlBase}',
  185. data: 'q=' + encodeURIComponent(query),
  186. type: 'POST',
  187. error: function() {
  188. callback();
  189. },
  190. success: function(res) {
  191. for (var i in res) {
  192. if (!res[i].name || res[i].id != res[i].name) {
  193. res[i].name = res[i].id + ': ' + res[i].name;
  194. }
  195. }
  196. callback(res);
  197. }
  198. });
  199. }
  200. });
  201. });
  202. " . '</script>';
  203. return $out;
  204. }
  205. /**
  206. * @params $query - query string
  207. * @params $strict - search only euqal value
  208. * @returns [{id:int, param_out:str, exports:[]}]
  209. */
  210. private function _getValues($query, $strict = false, $params = array()) {
  211. $values = array();
  212. switch ($this->fldName) {
  213. case 'A_ADM_COMPANY':
  214. case 'A_CLASSIFIED':
  215. Lib::loadClass('UsersHelper');
  216. $userName = User::getLogin();
  217. $userLdapGroups = UsersHelper::getLDAPGroupByUserName($userName);
  218. 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>';}
  219. if (!empty($userLdapGroups)) {
  220. foreach ($userLdapGroups as $kID => $vLdapGroup) {
  221. $allowGroup = false;
  222. //$allowGroup = $vLdapGroup->gidNumber > 1000;
  223. if ('workgroup' == $vLdapGroup->cn) {
  224. $allowGroup = true;
  225. } else {
  226. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  227. $cnTest = explode('_', $cnTest);
  228. $cnTest = $cnTest[0];
  229. if (is_numeric($cnTest)) {
  230. $allowGroup = true;
  231. }
  232. }
  233. if ($allowGroup) {
  234. if ($strict) {
  235. if (!empty($query) && $query == $vLdapGroup->cn) {
  236. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  237. }
  238. } else {
  239. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  240. //$values[$vLdapGroup->cn] = $vLdapGroup->cn;
  241. }
  242. }
  243. }
  244. }
  245. break;
  246. case 'DEFAULT_ACL_GROUP':
  247. Lib::loadClass('UsersHelper');
  248. $userLdapGroups = UsersHelper::getLDAPGroupsAll();
  249. 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>';}
  250. if (!empty($userLdapGroups)) {
  251. foreach ($userLdapGroups as $kID => $vLdapGroup) {
  252. $allowGroup = false;
  253. //$allowGroup = $vLdapGroup->gidNumber > 1000;
  254. if ('workgroup' == $vLdapGroup->cn) {
  255. $allowGroup = true;
  256. } else {
  257. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  258. $cnTest = explode('_', $cnTest);
  259. $cnTest = $cnTest[0];
  260. if (is_numeric($cnTest)) {
  261. $allowGroup = true;
  262. }
  263. }
  264. if ($allowGroup) {
  265. if ($strict) {
  266. if (!empty($query) && $query == $vLdapGroup->cn) {
  267. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  268. }
  269. } else {
  270. $values[$vLdapGroup->cn] = (object)array('id'=>$vLdapGroup->cn, 'param_out'=>$vLdapGroup->cn);
  271. //$values[$vLdapGroup->cn] = $vLdapGroup->cn;
  272. }
  273. }
  274. }
  275. }
  276. break;
  277. case 'K_OD_KOGO':
  278. $db = DB::getDB();
  279. $OD_KOGO_ADRES_ID = 0;
  280. $sql = "select z2.`ID`
  281. from `CRM_LISTA_ZASOBOW` as z
  282. join `CRM_LISTA_ZASOBOW` as z2 on (z2.`PARENT_ID`=z.`PARENT_ID`)
  283. where
  284. z.`ID`='{$this->fldID}'
  285. and z2.`DESC`='OD_KOGO_ADRES'
  286. ";
  287. 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>';}
  288. $res = $db->query($sql);
  289. while ($r = $db->fetch($res)) {
  290. $OD_KOGO_ADRES_ID = $r->ID;
  291. }
  292. $sqlLimit = 20;
  293. $query = trim($query, ' %');
  294. $query = $db->_($query);
  295. $sqlSearch = "k.`K_OD_KOGO` like '%{$query}%'";
  296. if ($strict) {
  297. if (!empty($query)) {
  298. $sqlLimit = 1;
  299. $sqlSearch = "k.`K_OD_KOGO`='{$query}'";
  300. } else {
  301. return $values;
  302. }
  303. }
  304. $sql = "select k.`K_OD_KOGO`, k.`OD_KOGO_ADRES`
  305. from `IN7_DZIENNIK_KORESP` as k
  306. where {$sqlSearch}
  307. group by k.`K_OD_KOGO`
  308. limit {$sqlLimit}
  309. ";
  310. 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>';}
  311. $res = $db->query($sql);
  312. while ($r = $db->fetch($res)) {
  313. $values[] = (object)array('id'=>$r->K_OD_KOGO, 'param_out'=>$r->K_OD_KOGO, 'exports'=>array($OD_KOGO_ADRES_ID => $r->OD_KOGO_ADRES));
  314. }
  315. 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>';}
  316. break;
  317. case 'OD_KOGO_ADRES':
  318. $db = DB::getDB();
  319. $query = trim($query, ' %');
  320. $query = $db->_($query);
  321. $sqlLimit = 20;
  322. $sqlSearch = "k.`OD_KOGO_ADRES` like '%{$query}%'";
  323. if ($strict) {
  324. if (!empty($query)) {
  325. $sqlLimit = 1;
  326. $sqlSearch = "k.`OD_KOGO_ADRES`='{$query}'";
  327. } else {
  328. return $values;
  329. }
  330. }
  331. $sql = "select k.`OD_KOGO_ADRES`
  332. from `IN7_DZIENNIK_KORESP` as k
  333. where {$sqlSearch}
  334. group by k.`OD_KOGO_ADRES`
  335. limit {$sqlLimit}
  336. ";
  337. 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>';}
  338. $res = $db->query($sql);
  339. while ($r = $db->fetch($res)) {
  340. $values[] = (object)array('id'=>$r->OD_KOGO_ADRES, 'param_out'=>$r->OD_KOGO_ADRES);
  341. }
  342. 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>';}
  343. break;
  344. case 'M_DISTRIBUTOR':
  345. $db = DB::getDB();
  346. $query = trim($query, ' %');
  347. $query = $db->_($query);
  348. $sqlLimit = 20;
  349. $sqlSearch = "p.`M_DISTRIBUTOR` like '%{$query}%'";
  350. if ($strict) {
  351. if (!empty($query)) {
  352. $sqlLimit = 1;
  353. $sqlSearch = "p.`M_DISTRIBUTOR`='{$query}'";
  354. } else {
  355. return $values;
  356. }
  357. }
  358. $sql = "select p.`M_DISTRIBUTOR`
  359. from `IN7_MK_BAZA_DYSTRYBUCJI` as p
  360. where p.`M_DISTRIBUTOR` like '%{$query}%'
  361. group by p.`M_DISTRIBUTOR`
  362. limit {$sqlLimit}
  363. ";
  364. 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>';}
  365. $res = $db->query($sql);
  366. while ($r = $db->fetch($res)) {
  367. $values[] = (object)array('id'=>$r->M_DISTRIBUTOR, 'param_out'=>$r->M_DISTRIBUTOR);
  368. }
  369. 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>';}
  370. break;
  371. case '__NESTED_GROUPS': {
  372. $db = DB::getDB();
  373. $query = trim($query, ' %');
  374. $query = $db->_($query);
  375. $sqlLimit = 20;
  376. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  377. from `CRM_LISTA_ZASOBOW` as z
  378. where z.`A_STATUS` in('NORMAL', 'WAITING')
  379. and z.`TYPE` in('STANOWISKO', 'PODMIOT', 'DZIAL')
  380. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  381. group by z.`DESC`
  382. limit {$sqlLimit}
  383. ";
  384. 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>';}
  385. $res = $db->query($sql);
  386. while ($r = $db->fetch($res)) {
  387. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  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;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
  390. break;
  391. }
  392. case '__USER_GROUPS': {
  393. $db = DB::getDB();
  394. $query = trim($query, ' %');
  395. $query = $db->_($query);
  396. $sqlLimit = 20;
  397. $sql = "select z.`ID`, z.`DESC`, z.`TYPE`
  398. from `CRM_LISTA_ZASOBOW` as z
  399. where z.`A_STATUS` in('NORMAL', 'WAITING')
  400. and z.`TYPE` in('STANOWISKO', 'PODMIOT', 'DZIAL')
  401. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  402. group by z.`DESC`
  403. limit {$sqlLimit}
  404. ";
  405. 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>';}
  406. $res = $db->query($sql);
  407. while ($r = $db->fetch($res)) {
  408. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->TYPE . ' ' . $r->DESC);
  409. }
  410. 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>';}
  411. break;
  412. }
  413. case '__TELBOXES': {
  414. $db = DB::getDB();
  415. $query = trim($query, ' %');
  416. $query = $db->_($query);
  417. $sqlLimit = 20;
  418. $sql = "select tx.`ID`, tx.`T_TELBOX_NAME`, tx.`T_TELBOX_TYPE`
  419. from `TELBOXES` as tx
  420. where
  421. tx.`A_STATUS`!='DELETED'
  422. and (tx.`ID` like '%{$query}%' or tx.`T_TELBOX_NAME` like '%{$query}%')
  423. order by tx.`T_TELBOX_NAME`
  424. limit {$sqlLimit}
  425. ";
  426. 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>';}
  427. $res = $db->query($sql);
  428. while ($r = $db->fetch($res)) {
  429. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->T_TELBOX_NAME . ' ' . $r->T_TELBOX_TYPE);
  430. }
  431. 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>';}
  432. break;
  433. }
  434. case '__TELBOXES_NAME': {
  435. $db = DB::getDB();
  436. $query = trim($query, ' %');
  437. $query = $db->_($query);
  438. $sqlLimit = 20;
  439. $sql = "select tx.`ID`, tx.`T_TELBOX_NAME`, tx.`T_TELBOX_TYPE`
  440. from `TELBOXES` as tx
  441. where
  442. tx.`A_STATUS`!='DELETED'
  443. and (tx.`ID` like '%{$query}%' or tx.`T_TELBOX_NAME` like '%{$query}%')
  444. order by tx.`T_TELBOX_NAME`
  445. limit {$sqlLimit}
  446. ";
  447. 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>';}
  448. $res = $db->query($sql);
  449. while ($r = $db->fetch($res)) {
  450. $values[] = (object)array('id'=>$r->T_TELBOX_NAME, 'param_out'=>$r->T_TELBOX_NAME . ' ' . $r->T_TELBOX_TYPE);
  451. }
  452. 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>';}
  453. break;
  454. }
  455. case '__ZASOB': {
  456. $db = DB::getDB();
  457. $query = trim($query, ' %');
  458. $query = $db->_($query);
  459. $sqlLimit = 20;
  460. $sqlSelectLabel = "concat(z.`TYPE`, ' ', z.`DESC`)";
  461. $sqlWhere = "";
  462. if (!empty($params['zasob_type_in'])) {
  463. if (is_scalar($params['zasob_type_in'])) $params['zasob_type_in'] = array($params['zasob_type_in']);
  464. $sqlWhere = " and z.`TYPE` IN('" . implode("','", $params['zasob_type_in']) . "') ";
  465. if (in_array('KOMORKA', $params['zasob_type_in'])) {
  466. $sqlSelectLabel = "concat(z.`TYPE`, ' ', z.`DESC` , ' (', (select zp.`DESC` from `CRM_LISTA_ZASOBOW` as zp where zp.`ID`=z.`PARENT_ID` limit 1), ')')";
  467. }
  468. }
  469. if (is_numeric($query)) {
  470. $sql = "select z.`ID`
  471. , {$sqlSelectLabel} as `LABEL`
  472. , IF (z.`ID`='{$query}', 1000,
  473. IF (z.`ID` like '{$query}%', 900, 100)
  474. ) as _bestFit
  475. from `CRM_LISTA_ZASOBOW` as z
  476. where z.`A_STATUS` in('NORMAL', 'WAITING')
  477. and (z.`ID` like '%{$query}%' or z.`DESC` like '%{$query}%')
  478. {$sqlWhere}
  479. order by _bestFit DESC
  480. limit {$sqlLimit}
  481. ";
  482. } else {
  483. $sql = "select z.`ID`
  484. , {$sqlSelectLabel} as `LABEL`
  485. from `CRM_LISTA_ZASOBOW` as z
  486. where z.`A_STATUS` in('NORMAL', 'WAITING')
  487. and (z.`ID` like '%{$query}%' or z.`DESC` like '%{$query}%')
  488. {$sqlWhere}
  489. limit {$sqlLimit}
  490. ";
  491. }
  492. 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>';}
  493. $res = $db->query($sql);
  494. while ($r = $db->fetch($res)) {
  495. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  496. }
  497. 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>';}
  498. break;
  499. }
  500. case '__PROCES': {
  501. $db = DB::getDB();
  502. $query = trim($query, ' %');
  503. $query = $db->_($query);
  504. $sqlLimit = 20;
  505. $sqlSelectLabel = "concat(z.`TYPE`, ' ', z.`DESC`)";
  506. $sqlWhereAdd = "";
  507. if (is_numeric($query)) {
  508. $sql = "select z.`ID`
  509. , {$sqlSelectLabel} as `LABEL`
  510. , IF (z.`ID`='{$query}', 1000,
  511. IF (z.`ID` like '{$query}%', 900, 100)
  512. ) as _bestFit
  513. from `CRM_PROCES` as z
  514. where z.`A_STATUS` in('NORMAL', 'WAITING')
  515. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  516. {$sqlWhereAdd}
  517. order by _bestFit DESC
  518. limit {$sqlLimit}
  519. ";
  520. } else {
  521. $sql = "select z.`ID`
  522. , {$sqlSelectLabel} as `LABEL`
  523. from `CRM_PROCES` as z
  524. where z.`A_STATUS` in('NORMAL', 'WAITING')
  525. and (z.`DESC` like '%{$query}%' or z.`ID` like '%{$query}%')
  526. {$sqlWhereAdd}
  527. limit {$sqlLimit}
  528. ";
  529. }
  530. 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>';}
  531. $res = $db->query($sql);
  532. while ($r = $db->fetch($res)) {
  533. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  534. }
  535. 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>';}
  536. break;
  537. }
  538. case '__COMPANIES': {
  539. $db = DB::getDB();
  540. $query = trim($query, ' %');
  541. $query = $db->_($query);
  542. $sqlLimit = 20;
  543. $sql = "select c.`ID`, c.`P_NAME`, c.`P_NIP`
  544. from `COMPANIES` as c
  545. where c.`A_STATUS` in('NORMAL', 'WAITING')
  546. and (c.`P_NAME` like '%{$query}%' or c.`P_NIP` like '%{$query}%' or c.`ID` like '%{$query}%')
  547. limit {$sqlLimit}
  548. ";
  549. 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>';}
  550. $res = $db->query($sql);
  551. while ($r = $db->fetch($res)) {
  552. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->P_NAME . ' ' . $r->P_NIP);
  553. }
  554. 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>';}
  555. break;
  556. }
  557. case 'VERSION_GIT': {
  558. $gitPath = '/Library/Server/Web/Data/Sites/SE-production-git/';
  559. $versions = array();
  560. if (file_exists($gitPath)) {
  561. $cmd = "cd {$gitPath} && git tag -l| sort -r -n -t. -k1,1 -k2,2 -k3,3 -k4,4|head -10";
  562. $cmdOut = null; $cmdRet = null;
  563. exec($cmd, $cmdOut, $cmdRet);
  564. if ($cmdRet == 0) {
  565. if (!empty($cmdOut)) {
  566. foreach ($cmdOut as $tag) {
  567. array_unshift($versions, $tag);
  568. }
  569. }
  570. }
  571. }
  572. foreach ($versions as $version) {
  573. if (!empty($query)) {
  574. if ($strict) {
  575. if ($version != $query) {
  576. continue;
  577. }
  578. }
  579. else {
  580. if (false === strpos($version, $query)) {
  581. continue;
  582. }
  583. }
  584. }
  585. $values[] = (object)array('id'=>$version, 'param_out'=>$version);
  586. }
  587. }
  588. case '__USER_ID': {
  589. $db = DB::getDB();
  590. $query = trim($query, ' %');
  591. $query = $db->_($query);
  592. $sqlLimit = 20;
  593. $sqlSelectLabel = array();
  594. $sqlSelectLabel[] = 'u.`ADM_NAME`';
  595. $sqlSelectLabel[] = "' ('";
  596. $sqlSelectLabel[] = 'u.`ADM_ACCOUNT`';
  597. $sqlSelectLabel[] = "', '";
  598. $sqlSelectLabel[] = 'u.`EMAIL`';
  599. $sqlSelectLabel[] = "', '";
  600. $sqlSelectLabel[] = 'u.`ADM_PHONE`';
  601. $sqlSelectLabel[] = "')'";
  602. $sqlSelectLabel = "concat(" . implode(", ", $sqlSelectLabel) . ")";
  603. $sql = "select u.`ID`
  604. , {$sqlSelectLabel} as `LABEL`
  605. from `ADMIN_USERS` as u
  606. where u.`A_STATUS` in('NORMAL', 'WAITING','MONITOR','WARNING')
  607. and u.`EMPLOYEE_TYPE` in('Pracownik','Partner')
  608. and (u.`ID` like '%{$query}%'
  609. or u.`ADM_ACCOUNT` like '%{$query}%'
  610. or u.`ADM_NAME` like '%{$query}%'
  611. or u.`ADM_PHONE` like '%{$query}%'
  612. or u.`EMAIL` like '%{$query}%'
  613. )
  614. limit {$sqlLimit}
  615. ";
  616. 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>';}
  617. $res = $db->query($sql);
  618. while ($r = $db->fetch($res)) {
  619. $values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
  620. }
  621. 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>';}
  622. break;
  623. }
  624. default:
  625. }
  626. return $values;
  627. }
  628. /**
  629. * @returns object
  630. * {
  631. * ext_tbl_id: "1466",
  632. * ext_row_id: "2975",
  633. * id: "2975",
  634. * tbl_label: "Zasoby",
  635. * link_type_id: "5",
  636. * link_type: "NestedGroups",
  637. * },
  638. */
  639. public function getReturnData($tblId, $rowId, $fieldName) {
  640. $retData = new stdClass();
  641. $retData->items = array();
  642. $values = array();
  643. switch ($this->fldName) {
  644. case '__CONNECTIONS': {
  645. $linkTypes = array();
  646. $tblLabels = array();
  647. $db = DB::getDB();
  648. $sqlLimit = 21;
  649. $sql = "select l.*
  650. from `ITEM_LINKS` as l
  651. where l.`A_STATUS` in('NORMAL', 'WAITING')
  652. and (
  653. (l.`TABLE_1_ZASOB_ID`={$tblId} and l.`TABLE_1_ID`={$rowId})
  654. or
  655. (l.`TABLE_2_ZASOB_ID`={$tblId} and l.`TABLE_2_ID`={$rowId})
  656. )
  657. and l.`LINKS_TYPE_ID`>1
  658. limit {$sqlLimit}
  659. ";
  660. 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>';}
  661. $res = $db->query($sql);
  662. while ($r = $db->fetch($res)) {
  663. $connObj = new stdClass();
  664. if ($r->TABLE_1_ZASOB_ID == $tblId && $r->TABLE_1_ID == $rowId) {
  665. $connObj->ext_tbl_id = $r->TABLE_2_ZASOB_ID;
  666. $connObj->ext_row_id = $r->TABLE_2_ID;
  667. $connObj->id = $r->TABLE_2_ID;
  668. $connObj->label = "{$r->TABLE_2_ZASOB_ID}({$r->TABLE_2_ID})";
  669. }
  670. else if ($r->TABLE_2_ZASOB_ID == $tblId && $r->TABLE_2_ID == $rowId) {
  671. $connObj->ext_tbl_id = $r->TABLE_1_ZASOB_ID;
  672. $connObj->ext_row_id = $r->TABLE_1_ID;
  673. $connObj->id = $r->TABLE_1_ID;
  674. $connObj->label = "{$r->TABLE_1_ZASOB_ID}({$r->TABLE_1_ID})";
  675. }
  676. if ($connObj) {
  677. $connObj->link_type_id = $r->LINKS_TYPE_ID;
  678. $linkTypes[$connObj->link_type_id] = '';
  679. $tblLabels[$connObj->ext_tbl_id] = '';
  680. $retData->items[] = $connObj;
  681. }
  682. }
  683. if (!empty($linkTypes)) {
  684. $sql = "select lt.`ID`, lt.`NAME`
  685. from `ITEM_LINK_TYPES` as lt
  686. where lt.`ID` in (" . implode(", ", array_keys($linkTypes)) . ")
  687. ";
  688. $res = $db->query($sql);
  689. while ($r = $db->fetch($res)) {
  690. $linkTypes[$r->ID] = $r->NAME;
  691. }
  692. }
  693. if (!empty($tblLabels)) {
  694. $sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
  695. from `CRM_LISTA_ZASOBOW` as z
  696. where z.`ID` in (" . implode(", ", array_keys($tblLabels)) . ")
  697. ";
  698. $res = $db->query($sql);
  699. while ($r = $db->fetch($res)) {
  700. if (!empty($r->DESC_PL)) {
  701. $tblLabels[$r->ID] = $r->DESC_PL;
  702. } else if (!empty($r->OPIS)) {
  703. $tblLabels[$r->ID] = V::strShortUtf8($r->OPIS, 20);
  704. } else {
  705. $tblLabels[$r->ID] = $r->DESC;
  706. }
  707. }
  708. }
  709. foreach ($retData->items as $k => $connObj) {
  710. $connObj->link_type = V::get($connObj->link_type_id, $connObj->link_type_id, $linkTypes);
  711. $connObj->tbl_label = V::get($connObj->ext_tbl_id, $connObj->ext_tbl_id, $tblLabels);
  712. }
  713. 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>';}
  714. return $retData;
  715. break;
  716. }
  717. default:
  718. }
  719. return null;
  720. }
  721. }