TypespecialVariable.php 27 KB

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