TypespecialVariable.php 26 KB

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