TypespecialVariable.php 25 KB

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