TypespecialVariable.php 25 KB

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