Tree.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. <?php
  2. class Tree {
  3. var $_table;
  4. var $_params;
  5. var $cookie_name;
  6. var $_limit;// limit nodes from DB
  7. var $_deep_limit;// limit nodes from DB
  8. var $_nodes_from_db;// how much nodes loaded from DB
  9. var $_opened_nodes_to_save;// nodes forced to open, to save in cookie after show tree,subtree
  10. private $_profiler;
  11. public function __construct($table) {
  12. $this->_table = $table;
  13. $this->_sql_parent_id_col = 'PARENT_ID';
  14. $this->_params = array();
  15. $this->cookie_name = 'TREE_' . $table;
  16. // TODO: fun name must be uniq to show couple tree's on one site
  17. $this->js_tree_hide_fun = 'TREE_' . $table . '_hide';
  18. $this->js_tree_open_rec_fun = 'TREE_' . $table . '_open_rec';
  19. $this->_limit = 0;
  20. $this->_deep_limit = 0;
  21. $this->_opened_nodes_to_save = array();
  22. }
  23. public function setProfiler($profiler) {
  24. $this->_profiler = $profiler;
  25. }
  26. public function log($msg, $groups = array()) {
  27. if ($this->_profiler && method_exists($this->_profiler, 'log')) {
  28. $this->_profiler->log($msg, $groups);
  29. }
  30. }
  31. public function set_parent_id_col($p_id_col) {
  32. $this->_sql_parent_id_col = $p_id_col;
  33. }
  34. public function get_item_p_id(&$r) {
  35. if (isset($r->{$this->_sql_parent_id_col})) {
  36. return $r->{$this->_sql_parent_id_col};
  37. }
  38. return null;
  39. }
  40. public function is_closed($id) {
  41. static $c;
  42. if (!$c) {
  43. $c = explode(' ', V::get($this->cookie_name, '', $_COOKIE));
  44. }
  45. if ($this->get_param('lazy_open_rec')) {
  46. if (!in_array($id, $c)) {
  47. $this->lazy_open($id);
  48. }
  49. return false;
  50. }
  51. return !in_array($id, $c);
  52. }
  53. public function show() {
  54. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">';print_r(explode(' ', $_COOKIE[$this->cookie_name]));echo'</pre>';
  55. $this->show_css();
  56. $this->show_js();
  57. echo "\n".'<div class="tree-wrap">'."\n";
  58. $this->show_rec();
  59. echo '</div>'."\n";
  60. $this->_save_lazy_opened_nodes();
  61. echo"\n".'<!-- '."Loaded from DB: ".$this->_nodes_from_db.' -->'."\n";
  62. }
  63. /*
  64. * Save collapsed nodes in cookie
  65. * @see _save_lazy_opened_nodes
  66. */
  67. public function lazy_open($id) {
  68. $this->_opened_nodes_to_save[$id] = true;
  69. }
  70. /*
  71. * Save collapsed nodes in cookie
  72. * @see lazy_open
  73. */
  74. public function _save_lazy_opened_nodes() {
  75. if (!empty($this->_opened_nodes_to_save)) {
  76. $opened = array();
  77. if (!empty($_COOKIE[$this->cookie_name]) && $_COOKIE[$this->cookie_name] != '') {
  78. $opened = explode(' ', $_COOKIE[$this->cookie_name]);
  79. }
  80. foreach ($opened as $id) {
  81. $this->_opened_nodes_to_save [$id] = true;
  82. }
  83. $_COOKIE[$this->cookie_name] = implode(' ', array_keys($this->_opened_nodes_to_save));
  84. echo'<script type="text/javascript">'."
  85. jQuery(document).ready(function(){
  86. jQuery.cookie('".$this->cookie_name."','" . $_COOKIE[$this->cookie_name] . "');
  87. });
  88. ".'</script>';
  89. }
  90. }
  91. public function showSubTree($id = 0) {
  92. $this->show_css();
  93. $this->show_js();
  94. echo "\n".'<div class="tree-wrap">'."\n";
  95. $ids = explode(',', $id);
  96. foreach ($ids as $id) {
  97. $parents = array();
  98. $this->get_parents_rec($id, $parents);
  99. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">';print_r($parents);echo'</pre>';
  100. $this->set_param('show_state', 'parents');
  101. $r = null;
  102. if (($r = reset($parents)) != null && $this->get_item_p_id($r) == -1) {
  103. echo'<b>'."Kosz".'</b>';
  104. }
  105. foreach ($parents as $r) {
  106. $cls = ' class="tree-last"';
  107. echo'<ul>'."\n";
  108. $item_id_html_id = ' id="TREE'.$r->ID.'"';
  109. echo '<li'.$cls.$item_id_html_id.'>';
  110. if ($r->ID == $id) break;
  111. $this->show_item($r);
  112. }
  113. $this->set_param('show_state', 'items');
  114. if ($r) {
  115. $this->show_item($r);
  116. } else {
  117. if ($this->get_param('is_trash')) {// is _trash
  118. echo'<b>'."Kosz".'</b>';
  119. } else {
  120. echo'<b>'."Brak danych".'</b>';
  121. }
  122. }
  123. //TODO: get item and if exists then show parents and childrens
  124. $this->show_rec($id);
  125. foreach ($parents as $r) {
  126. echo '</li>'."\n";
  127. echo'</ul>';
  128. }
  129. echo '<div style="border-bottom:1px solid #ddd"></div>';
  130. }
  131. echo '</div>'."\n";
  132. }
  133. /*
  134. * Wyszukiwanie ID w drzewie.
  135. */
  136. public function showSearchNode($id) {
  137. $parents = array();
  138. $this->get_parents_rec($id, $parents);
  139. if (empty($parents)) {
  140. echo'<p class="box box-red">Rekord id="<b>'.$id.'</b>" nie istnieje.</p>';
  141. } else {
  142. // TODO: drzewo ZWIN, trzeba teraz zmienic zawartosc cookie!
  143. //echo'<p>TODO: wyszukaj "'.$id.'" {'.implode(',', $parent_ids).'}</p>';
  144. echo'<p style="margin:0;padding:1px 10px;background-color:#C2F9C2;border:1px solid #CCC;border-style:solid solid none solid;">';
  145. $js = "return scrollToProces('".$id."');";
  146. echo'<a href="'."#TREE".$id.'" onclick="'.$js.'">'."Przejdz do ID <b>".$id."</b>".'</a>';
  147. echo'</p>';
  148. // TODO: sprawdzi czy aby na pewno dziala poprawnie, test szukaj 901, nie otwiera 892
  149. foreach ($parents as $r) {
  150. $this->lazy_open($r->ID);
  151. }
  152. $this->_save_lazy_opened_nodes();
  153. }
  154. $this->show();
  155. }
  156. /**
  157. * TODO: Np. do menu, czy filtrowania drzewa.
  158. * @see task_CRM_MENU
  159. * @param items - array of items to show, array(ID => $r)
  160. * @param show_item_callback - inna funkcja do wypisywania - TODO: jest $tree->set_param('show_item_callback');
  161. */
  162. public function showItems(&$base_items, $show_item_callback = null) {
  163. $items = array();
  164. // get paretns flat
  165. $items_flat = array();
  166. foreach ($base_items as $p_id => $p) {
  167. $items[$p->ID] = $p;
  168. $items_flat[$p->ID] = $p->PARENT_ID;
  169. $items_flat[$this->get_item_p_id($p)] = null;
  170. }
  171. $user_menu_tree_created = TreeHelper::build_tree_flat($this->_table, $items_flat);
  172. $user_menu_tree = TreeHelper::get_tree_from_flat($items_flat);
  173. $this->fetch_data($items, $items_flat);
  174. if (!empty($user_menu_tree[0])) {
  175. $this->show_css();
  176. echo'<div class="tree-wrap">';
  177. $this->show_rec_by_tree($user_menu_tree[0], $items);
  178. echo'</div>';
  179. } else {
  180. //
  181. }
  182. }
  183. public function show_rec_by_tree(&$tree, &$items) {
  184. if (empty($tree)) {
  185. return;
  186. }
  187. echo'<ul>';
  188. $i = 0; $cnt = count($tree);
  189. foreach ($tree as $k_id => $v_arr) {
  190. $r = (isset($items[$k_id]))? $items[$k_id] : null;
  191. if ($r) {
  192. $cls = array();
  193. if ($this->is_closed($r->ID)) $cls['tree-close'] = true;
  194. if (++$i == $cnt) {
  195. $cls['tree-last'] = true;
  196. }
  197. if (empty($v_arr)) {
  198. $cls['tree-leaf'] = true;
  199. }
  200. $cls = (!empty($cls))? ' class="'.implode(' ', array_keys($cls)).'"' : '';
  201. $item_id_html_id = ' id="TREE'.$r->ID.'"';
  202. echo '<li'.$cls.$item_id_html_id.'>';
  203. if (isset($r->has_childrens) && $r->has_childrens) {
  204. echo'<div class="btn-open'.$btn_open_cls_add.'" onclick="return '.$this->js_tree_hide_fun.'(this,'.$r->ID.');"></div>';
  205. }
  206. $this->show_item($r);
  207. $this->show_rec_by_tree($v_arr, $items);
  208. echo'</li>';
  209. }
  210. }
  211. echo'</ul>';
  212. }
  213. public function fetch_data(&$items, $tree_flat) {
  214. $db = DB::getDB();
  215. $sql_ids = array();
  216. // find only not set
  217. foreach ($tree_flat as $k_id => $v) {
  218. if (empty($items[$k_id])) {
  219. $sql_ids[] = $k_id;
  220. }
  221. }
  222. // add tree parent proces info
  223. if (!empty($sql_ids)) {
  224. $sql_ids = implode(", ", $sql_ids);
  225. $sql = "select p.* from `{$this->_table}` as p where p.`ID` in ({$sql_ids}) ";
  226. $res = $db->query($sql);
  227. while ($r = $db->fetch($res)) {
  228. $items[$r->ID] = $r;
  229. }
  230. }
  231. }
  232. /*
  233. * Open all nodes recursive.
  234. */
  235. public function show_rec_all($parent_id = 0, $deep = 0) {
  236. $this->set_param('lazy_open_rec', true);// @see is_closed
  237. $this->lazy_open($parent_id);
  238. $this->show_rec($parent_id, $deep);
  239. $this->_save_lazy_opened_nodes();
  240. }
  241. public function show_rec($parent_id = 0, $deep = 0) {
  242. //if ($this->_deep_limit > 0 && $deep > $this->_deep_limit) {
  243. // return;
  244. //}
  245. $this->log("show_rec({$parent_id}, {$deep}) start");
  246. $list = $this->get_childrens($parent_id);
  247. if (empty($list)) return;
  248. $this->log("show_rec({$parent_id}, {$deep}) -> get_childrens({$parent_id})", array('get_childrens'));
  249. echo '<ul>'."\n";
  250. $list_total = count($list);
  251. foreach ($list as $r) {
  252. $cls = array();
  253. if (!--$list_total) $cls['tree-last'] = true;
  254. if (!$this->get_param('rozwin')) {
  255. if ($this->is_closed($r->ID)) $cls['tree-close'] = true;
  256. }
  257. if ($this->_deep_limit > 0 && $deep >= $this->_deep_limit) {
  258. $cls['tree-close'] = true;
  259. }
  260. if (!$r->has_childrens) {
  261. $cls['tree-leaf'] = true;
  262. if (isset($cls['tree-close'])) unset($cls['tree-close']);// show wskazniki on leaf
  263. }
  264. $cls = array_keys($cls);// uniq array
  265. // reopen nodes marked as open, but hide by default or deep, etc., @see show_js: tree_..._ajax_reopen
  266. $btn_open_cls_add = '';
  267. if (in_array('tree-close', $cls) && $this->is_closed($r->ID) == false) {
  268. $btn_open_cls_add = ' ajax-reopen';
  269. }
  270. //$cls[] = 'deep-'.$deep;
  271. $cls = (empty($cls))? '' : ' class="'.implode(' ', $cls).'"';
  272. $item_id_html_id = '';
  273. if ($this->get_item_p_id($r) == $parent_id) {// tylko normalny, a nie P_ID2, czy P_ID3, etc
  274. $item_id_html_id = ' id="TREE'.$r->ID.'"';
  275. }
  276. echo '<li'.$cls.$item_id_html_id.'>';
  277. if ($this->get_param('rozwin')) {
  278. if ($r->has_childrens) {
  279. if ($this->_deep_limit > 0 && $deep + 1 > $this->_deep_limit) {
  280. //echo'<a class="btn-open'.$btn_open_cls_add.'" onclick="return '.$this->js_tree_hide_fun.'(this,'.$r->ID.');" href="#">&nbsp;</a>';
  281. echo'<div class="btn-open'.$btn_open_cls_add.'" onclick="return '.$this->js_tree_hide_fun.'(this,'.$r->ID.');"></div>';
  282. }
  283. }
  284. } else {
  285. if ($r->has_childrens) {
  286. //echo'<a class="btn-open'.$btn_open_cls_add.'" onclick="return '.$this->js_tree_hide_fun.'(this,'.$r->ID.');" href="#">&nbsp;</a>';
  287. echo'<div class="btn-open'.$btn_open_cls_add.'" onclick="return '.$this->js_tree_hide_fun.'(this,'.$r->ID.');"></div>';
  288. }
  289. }
  290. $this->log("show_rec({$parent_id}, {$deep}) -> show_item start");
  291. $this->show_item($r);
  292. $this->log("show_rec({$parent_id}, {$deep}) -> show_item end", array('show_item'));
  293. if ($r->has_childrens) {
  294. $this->show_rec($r->ID, $deep + 1);
  295. }
  296. echo '</li>'."\n";
  297. }
  298. echo '</ul>'."\n";
  299. $this->log("show_rec({$parent_id}, {$deep}) end");
  300. }
  301. public function show_item(&$r) {
  302. if ($callback = $this->get_param('show_item_callback')) {
  303. $callback($r, $this);
  304. } else {
  305. echo'<dl><dt>';
  306. echo '<span class="item_id btn-box">'.$r->ID.'</span>';
  307. echo'</dt></dl>';
  308. }
  309. }
  310. public function &get_childrens($parent_id) {
  311. $ret = array();
  312. // check tree limit - load more by ajax
  313. // mved to show_rec
  314. // if ($this->_limit > 0 && $this->_nodes_from_db > $this->_limit) {
  315. // return $ret;
  316. // }
  317. $sql = new stdClass();
  318. $sql->select = array();
  319. $sql->select[] = "t.*";
  320. // PARENT_TYPE dla tabeli CRM_LISTA_ZASOBOW
  321. if ($this->_table == 'CRM_LISTA_ZASOBOW') {
  322. $sql->select[] = "
  323. IF( t.`{$this->_sql_parent_id_col}`='{$parent_id}'
  324. , 'P_ID'
  325. , IF( (FIND_IN_SET('{$parent_id}', t.`PARENT_ID_ACCESS`) > 0)
  326. , 'P_ID_ACCESS'
  327. , IF( (FIND_IN_SET('{$parent_id}', t.`PARENT_ID_MAP`) > 0)
  328. , 'P_ID_MAP'
  329. , 'P_ID_UNKNOWN'
  330. )
  331. )
  332. ) as PARENT_TYPE
  333. ";
  334. }
  335. $sql->filter = array();
  336. $sql->join_filter = array();
  337. $sql->filter[] = "(t.`{$this->_sql_parent_id_col}`='{$parent_id}')";
  338. $sql->join_filter[] = "(t2.`{$this->_sql_parent_id_col}`=t.`ID`)";
  339. if ($this->_table == 'CRM_LISTA_ZASOBOW') {
  340. // TODO: $this->get_param('TREE_SHOW_P_ID2') $this->get_param('TREE_SHOW_P_ID3')
  341. if ($_SESSION['TREE_SHOW_P_ID2'] || $_SESSION['TREE_SHOW_P_ID3']) {
  342. if ($_SESSION['TREE_SHOW_P_ID2']) {
  343. $sql->filter[] = "(FIND_IN_SET('{$parent_id}', t.`PARENT_ID_ACCESS`) > 0)";
  344. $sql->join_filter[] = "(FIND_IN_SET(t.`ID`, t2.`PARENT_ID_ACCESS`) > 0)";
  345. }
  346. if ($_SESSION['TREE_SHOW_P_ID3']) {
  347. $sql->filter[] = "(FIND_IN_SET('{$parent_id}', t.`PARENT_ID_MAP`) > 0)";
  348. $sql->join_filter[] = "(FIND_IN_SET(t.`ID`, t2.`PARENT_ID_MAP`) > 0)";
  349. }
  350. }
  351. }
  352. $sql->where = implode(" or ", $sql->filter);
  353. $sql->join_filter = implode(" or ", $sql->join_filter);
  354. // filtr_status
  355. if ($this->_table == 'IN7_MK_BAZA_DYSTRYBUCJI') {
  356. $sqlStatus = array();
  357. if ($this->get_param('filtr_status') == 'NORMAL') {
  358. $sqlStatus[] = "'NORMAL'";
  359. } else if ($this->get_param('filtr_status') == 'WAITING') {
  360. $sqlStatus[] = "'NORMAL'";
  361. $sqlStatus[] = "'WAITING'";
  362. }
  363. if (!empty($sqlStatus)) {
  364. $sqlStatus = implode(',', $sqlStatus);
  365. $sql->where = "({$sql->where}) and t.`A_STATUS` in({$sqlStatus}) ";
  366. }
  367. }
  368. if (in_array($this->_table, array('CRM_PROCES','CRM_LISTA_ZASOBOW'))) {
  369. $sql->order_by = "order by t.`SORT_PRIO` asc, t.`ID` asc";
  370. } else {
  371. $sql->order_by = "order by t.`ID` asc";
  372. }
  373. // has_childrens
  374. # IF((select 1 from `CRM_PROCES` as t2 where t2.`PARENT_ID` = t.`ID` limit 1) > 0, 1, 0) AS has_childrens
  375. if ($this->_table == 'CRM_LISTA_ZASOBOW') {
  376. //$sql->select [] = "IF(t.`".$this->_sql_parent_id_col."`='".$parent_id."' and t2.`ID` is not null, 1, 0) as has_childrens";
  377. $sql->select[] = "IF((select 1 from `{$this->_table}` as t2 where {$sql->join_filter} limit 1) is not null, 1, 0) as has_childrens";
  378. } else {
  379. //$sql->select [] = "IF(t2.`ID` is not null, 1, 0) as has_childrens";
  380. $sql->select[] = "IF((select 1 from `{$this->_table}` as t2 where {$sql->join_filter} limit 1) is not null, 1, 0) as has_childrens";
  381. }
  382. $db = DB::getDB();
  383. $sql->select = implode("\n, ", $sql->select);
  384. $sql = "select
  385. {$sql->select}
  386. from `{$this->_table}` as t
  387. where
  388. {$sql->where}
  389. {$sql->order_by}
  390. ";
  391. if('123' == V::get('DBG_SQL', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  392. $res = $db->query($sql);
  393. $rowsCount = 0;
  394. while ($r = $db->fetch($res)) {
  395. $ret[$r->ID] = $r;
  396. $rowsCount++;
  397. }
  398. $this->_nodes_from_db += $rowsCount;
  399. return $ret;
  400. }
  401. public function &get_parents_rec($id, &$arr) {
  402. $db = DB::getDB();
  403. $sql = "select
  404. t.*
  405. , '1' as has_childrens
  406. , 'P_ID' as PARENT_TYPE
  407. from `{$this->_table}` as t
  408. where
  409. t.`ID`='".$id."'
  410. ";
  411. $res = $db->query($sql);
  412. if ($r = $db->fetch($res)) {
  413. array_unshift($arr, $r);
  414. if (null == $this->get_item_p_id($r) || '0' == $this->get_item_p_id($r)) {
  415. return $arr;
  416. } else {
  417. $this->get_parents_rec($this->get_item_p_id($r), $arr);
  418. }
  419. }
  420. return $arr;
  421. }
  422. public function set_param($key, $value) {
  423. $this->_params[$key] = $value;
  424. }
  425. public function get_param($key) {
  426. if (array_key_exists($key, $this->_params)) {
  427. return $this->_params[$key];
  428. }
  429. return null;
  430. }
  431. public function show_css() {
  432. static $_run_only_once;
  433. if ($_run_only_once) {
  434. return;
  435. }
  436. $_run_only_once = true;
  437. ?>
  438. <style type="text/css">
  439. .tree-wrap{border:1px solid #ccc;margin:0;padding:0 5px;list-style:none;font-size:12px;line-height:16px;font-family:monospace;}
  440. .tree-wrap ul{margin:0;padding:0;list-style:none;}
  441. .tree-wrap li{margin:0 0 0 0;padding:0 0 0 10px;line-height:16px;}
  442. .tree-wrap li * {line-height:16px;}
  443. .tree-wrap p,
  444. .tree-wrap .cnt{margin:0 0 0 0;padding:0 0 0 10px;background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  445. .tree-wrap li.tree-leaf .cnt{background:none;}
  446. .tree-wrap p:hover,
  447. .tree-wrap .cnt:hover{background:#FFFFCA url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  448. .tree-wrap li.tree-leaf .cnt:hover{background:none;}
  449. .tree-wrap div.has_wsk{margin:0 0 0 0;padding:0 0 0 10px;background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y;}
  450. .tree-wrap a.item_id:hover {color:#fff; text-decoration:none}
  451. .tree-wrap p .item_id,
  452. .tree-wrap .cnt .item_id{margin:0 0 0 -10px;}
  453. .tree-wrap .cnt .has_wsk .item_id{margin:0 0 0 -20px;}
  454. .tree-wrap ul{background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  455. .tree-wrap li{background:url(stuff/i/t-li.gif) 0 0 no-repeat;}
  456. .tree-wrap li.tree-last{background-color:#fff;}
  457. .tree-wrap .item_type_PROCES_INIT{background:#f00;color:#fff;}
  458. .tree-wrap .btn-p5{margin:0 2px;padding:0 2px;background:#eee;color:#3A3AFF;text-decoration:none;border:0;font-weight:bold;}
  459. .tree-wrap .btn-red{background:#eee;color:#f00;}
  460. .tree-wrap p:hover .btn-box,
  461. .tree-wrap .cnt:hover .btn-box{background:#333;}
  462. .tree-wrap dt:hover .btn-box{background:#333;}
  463. .tree-wrap dt:hover .desc{background-color:#F8F8B4;}
  464. .tree-wrap .active > dl .desc{background-color:#F8F8B4;}
  465. .tree-wrap .active > dl .item_id{background-color:#000;}
  466. .tree-wrap .item-wskazniki{margin:0;padding:0 0 3px 0;}
  467. .tree-wrap .item-has_children{background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  468. .tree-wrap .item-wskazniki ul{margin:0 2px 0 10px;color:#008000;}
  469. .tree-wrap .item-wskazniki ul{background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y;}
  470. .tree-wrap .item-wskazniki li{background:url(stuff/i/t-li-green.gif) 0 0 no-repeat;}
  471. .tree-wrap .item-wskazniki li.tree-last{background-color:#fff;}
  472. .tree-wrap .item-wskazniki p {margin:0;padding:0;background:#fff;}
  473. .tree-wrap .item-wskazniki p:hover{background:#FFFFCA;}
  474. .tree-wrap .item-wskazniki p .wsk_parents{display:none;}
  475. .tree-wrap .item-wskazniki p:hover .wsk_parents{display:inline;color:#555;font-size:11px;}
  476. .tree-wrap .btn-p5:hover{background:#3A3AFF;color:#eee;}
  477. .tree-wrap .btn-open{display:block;width:12px;height:9px;overflow:hidden;}
  478. /*.tree-wrap .btn-open{margin:0;padding:0;position:absolute;top:4px;left:-4px;}*/
  479. /* TODO: IF IE left: -14px */
  480. .tree-wrap .btn-open{border:none;text-decoration:none;background:url(stuff/i/tree-collapse-btn.gif) no-repeat left top;cursor:pointer;}
  481. .tree-wrap li.tree-close .btn-open{background-position:0 -9px;}
  482. .tree-wrap li.tree-close ul{display:none;background:none;}
  483. .tree-wrap li.tree-close .cnt,
  484. .tree-wrap li.tree-close .item-wskazniki,
  485. .tree-wrap li.tree-close dt,
  486. .tree-wrap li.tree-close dd,
  487. .tree-wrap li.tree-close .has_wsk{background:none;}
  488. .tree-wrap li.tree-close dd{padding:0;}
  489. .tree-wrap .desc{margin:0 2px;color:#000;font-weight:normal;}
  490. .tree-wrap .desc-red{color:#f00;}
  491. .tree-wrap .desc-group1{color:navy;}
  492. .tree-wrap .desc-group2{color:olive;}
  493. .tree-wrap .desc .more-desc{color:#333;font-weight:normal;overflow:hidden;}
  494. .tree-wrap .desc .more-desc *{margin:0;}
  495. .tree-wrap .desc .more-desc img{margin:0 2px;}
  496. .tree-wrap .desc .more-desc ul{background:none; list-style:disc; padding:0 0 0 20px;}
  497. .tree-wrap .desc .more-desc ul li {padding:0;}
  498. .tree-wrap .desc .more-desc ul li,
  499. .tree-wrap .desc .more-desc p {background:none;}
  500. .tree-wrap .silver{color:#333;font-weight:normal;}
  501. /* tree-wrap dl-dt-dd: dl{ dt, dd, dl{...} } */
  502. .tree-wrap{border:1px solid #ccc;margin:0;padding:0 5px;list-style:none;font-size:12px;line-height:16px;font-family:monospace;}
  503. .tree-wrap dl{padding:0;margin:0;}
  504. .tree-wrap dt{padding:0 0 0 10px;margin:0;}
  505. .tree-wrap dd{padding:0;margin:0;}
  506. .tree-wrap dl.has_wsk dt{margin:0 0 0 0;padding:0 0 0 20px;background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y;}
  507. .tree-wrap dd{margin:0;padding:0 0 3px 0;}
  508. .tree-wrap dd ul{margin:0 2px 0 10px;color:#008000;}
  509. .tree-wrap dd ul{background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y;}
  510. .tree-wrap dd li{background:url(stuff/i/t-li-green.gif) 0 0 no-repeat;}
  511. .tree-wrap dd li.tree-last{background-color:#fff;}
  512. .tree-wrap dt .item_id{margin:0 0 0 -10px;}
  513. .tree-wrap .has_wsk .item_id{margin:0 0 0 -20px;}
  514. .tree-wrap dd,
  515. .tree-wrap dt{background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  516. .tree-wrap dl.has-no-children dd,
  517. .tree-wrap dl.has-no-children dt{background:none;}
  518. .tree-wrap li.tree-leaf dt{background:none;}
  519. .tree-wrap li.tree-leaf dd{background:none;}
  520. .tree-wrap dd p {margin:0;padding:0;background:#fff;}
  521. .tree-wrap dd p:hover{background:#FFFFCA;}
  522. .tree-wrap dd p .wsk_parents{display:none;}
  523. .tree-wrap dd p:hover .wsk_parents{display:inline;color:#555;font-size:11px;}
  524. /* colors by zasob type */
  525. .tree-wrap .type-P_ID .desc {color:#f00;}
  526. .tree-wrap .type-P_ID_ACCESS .desc {color:#0E7E0E;}
  527. .tree-wrap .type-P_ID_MAP .desc {color:#A020F0;}
  528. .tree-wrap .type-ALIAS_ID .desc {color:#FF6900;}
  529. .tree-wrap dt:hover .item_id{background:#000;}
  530. .tree-wrap dl.type-ALIAS_ID dt:hover .item_id{background:#FB9044;}
  531. .tree-wrap dl.type-P_ID_MAP dt:hover .item_id{background:#AB54DF;}
  532. .tree-wrap dl.type-P_ID_ACCESS dt:hover .item_id{background:#0E7E0E;}
  533. /* TODO: IE style
  534. .tree-wrap ul{float:left;overflow:hidden;}
  535. .tree-wrap li{float:left;clear:both}
  536. .tree-wrap dl{float:left;}
  537. .tree-wrap dl{display:inline;}
  538. */
  539. /*
  540. .tree-wrap ul{clear:both;float:left;width:100%;}
  541. .tree-wrap li{float:left;clear:both;width:100%;}
  542. .tree-wrap dl{clear:both;}
  543. .tree-wrap dl dt{float:left}
  544. .tree-wrap dl dd{}
  545. .tree-wrap .btn-open{float:left;margin:4px 0 0 -14px;padding:0;}
  546. .tree-wrap .has_wsk .btn-open{float:left;margin:4px 0 0 -24px;padding:0;}
  547. */
  548. .tree-wrap li{position:relative}
  549. .tree-wrap .btn-open{position:absolute;top:4px;left:-4px;padding:0;}
  550. /*.tree-wrap .has_wsk .btn-open{position:absolute;top:4px;left:-14px;padding:0;}*/
  551. /* zasoby: external ids */
  552. .tree-wrap .external-ids{color:#008A00; font-weight:bold;}
  553. .tree-wrap .external-ids .not-found{color:#666; font-weight:normal;}
  554. .tree-wrap .external-ids a{color:#008A00; font-weight:normal; text-decoration:none;}
  555. .tree-wrap .external-ids a:hover{text-decoration:underline;}
  556. .tree-wrap .external-ids a img{vertical-align:bottom;}
  557. .tree-wrap .search_id .desc{background-color:#C2F9C2;}
  558. .tree-wrap .open-rec{display:none;}
  559. .tree-wrap .tree-close .open-rec{display:inline;}
  560. .tree-wrap li.hide-wskazniki dd{display:none;}
  561. .tree-wrap .wsk-modal,
  562. .tree-wrap .popover,
  563. .tree-wrap .wsk-help {color:#333;}
  564. .tree-wrap .wsk-modal h1,
  565. .tree-wrap .wsk-modal h2,
  566. .tree-wrap .wsk-modal h3,
  567. .tree-wrap .wsk-modal h4,
  568. .tree-wrap .wsk-modal h5,
  569. .tree-wrap .wsk-modal h6 {line-height:1.2em;}
  570. </style>
  571. <?php
  572. }
  573. public function show_js() {
  574. ?>
  575. <script type="text/javascript">
  576. function <?php echo $this->js_tree_hide_fun; ?>(n, id){
  577. var p=jQuery(n).parents('li:first')
  578. <?php echo $this->js_tree_hide_fun; ?>_node(p, id);
  579. }
  580. function <?php echo $this->js_tree_hide_fun; ?>_node(p, id, open_rec) {
  581. p.toggleClass('tree-close');
  582. var c = jQuery.cookie('<?php echo $this->cookie_name; ?>');
  583. if (c === null) c = '';
  584. if (p.hasClass('tree-close')) {// open subtree
  585. // remove id from cookie
  586. //c = (' '+c+' ').replace((new RegExp(' '+id+' ', 'g')), ' ')
  587. var carr = c.split(' ');
  588. jQuery.unique(carr);
  589. c = (' ' + carr.join(' ') + ' ').replace((new RegExp(' ' + id + ' ', 'g')), ' ');
  590. }
  591. else {// close subbtree
  592. // add id to cookie, uniq array
  593. if ((' ' + c + ' ').indexOf(' ' + id + ' ') == -1){
  594. c = (c === '')? '' + id : '' + id + ' ' + c;
  595. }
  596. if (jQuery(p).children('ul').length == 0) {
  597. // create node to verride html from ajax request
  598. var cnt = jQuery('<em>loading...</em>');
  599. jQuery(p).append(cnt);
  600. var cnt = jQuery(p).children('em').get(0);
  601. // run ajax function
  602. var ajax_add_args = '';
  603. if (open_rec) {
  604. ajax_add_args = '&open_rec=1';
  605. }
  606. procesy_ajax_run(cnt, '?function_init=ajax_get_subtree&tbl=<?php echo $this->_table; ?>&id=' + id + ajax_add_args, 'override');
  607. }
  608. }
  609. c = jQuery.trim(c);
  610. //if (console && console.log) console.log(c)
  611. jQuery.cookie('<?php echo $this->cookie_name; ?>', c);
  612. return false;
  613. }
  614. // open recursive
  615. function <?php echo $this->js_tree_open_rec_fun; ?>(n, id) {
  616. // execute ajax function to fetch subtree with Drzewo=ROZWIN
  617. var p = jQuery(n).parents('li:first');
  618. node_id = p.attr('id');
  619. if (node_id.substr(0, 4) == 'TREE') {
  620. node_id = node_id.substr(4);
  621. //console.log('[' + node_id + ']has_class: ' + p.hasClass('tree-close') + ' ...');
  622. var childrens = p.children('ul');
  623. //console.log('[' + node_id + ']childrens: ');
  624. if (childrens) {
  625. childrens.remove();
  626. }
  627. <?php echo $this->js_tree_hide_fun; ?>_node(p, node_id, true);
  628. } else {
  629. //console.log('ERROR: id TREE');
  630. }
  631. return false;
  632. }
  633. // ajax reopen nodes, on document load
  634. jQuery(document).ready(function(){
  635. var nodes = jQuery('.ajax-reopen');
  636. if (nodes.length) nodes.click();
  637. jQuery('.wsk-help').popover({trigger:'hover', html:true, placement:'top'});
  638. //jQuery('.wsk-long-desc').modal();
  639. });
  640. function showZasobAliasTooltip(n) {
  641. var $n = jQuery(n);
  642. if ($n.data('id') <= 0) return false;
  643. var $aliasDescNode = $n.parent().find('.alias-description');
  644. if (!$aliasDescNode.length) return false;
  645. if (!$aliasDescNode.html()) {
  646. $aliasDescNode.html(' loading ...<br/>');
  647. }
  648. console.log('display: ', $aliasDescNode.children().css('display'));
  649. if ('block' == $aliasDescNode.children().css('display')) {
  650. $aliasDescNode.children().css('display', 'none');
  651. return false;
  652. } else if ('none' == $aliasDescNode.children().css('display')) {
  653. $aliasDescNode.children().css('display', 'block');
  654. }
  655. jQuery.ajax({
  656. data: null,
  657. type: "GET",
  658. url: 'procesy5.php?function_init=ajax_get_alias_info&HEADER_NOT_INIT=YES&idZasob=' + $n.data('id'),
  659. })
  660. .done(function(data, textStatus, jqXHR){
  661. if ('Brak danych' == data) {
  662. $n.parent().attr('title', $n.attr('title') + ' - Brak danych');
  663. $n.css({color: '#ddd'});
  664. $n.attr('onclick', 'return false;');
  665. $aliasDescNode.html('');
  666. } else {
  667. $aliasDescNode.html('<div style="padding-left:40px">' + data + '</div>');
  668. }
  669. })
  670. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  671. $aliasDescNode.html("Error");
  672. })
  673. .always(function(data, textStatus, jqXHR) {
  674. });
  675. return false;
  676. }
  677. function treeAddToFiltr(n, idZasob) {
  678. idZasob = parseInt(idZasob);
  679. if (!idZasob) return false;
  680. var $filters = jQuery(n).parents('.tree-wrap:first').prevAll('.filters:first');
  681. if (!$filters.length) return false;
  682. var $filtrIdInput = $filters.find('input[name="filtr_id"]');
  683. if (!$filtrIdInput.length) return false;
  684. var filtrVal = $filtrIdInput.val();
  685. if (!filtrVal.length) {
  686. $filtrIdInput.val(idZasob);
  687. } else {
  688. $filtrIdInput.val(filtrVal + ',' + idZasob);
  689. }
  690. $filtrIdInput.get(0).form.submit();
  691. return false;
  692. }
  693. </script>
  694. <?php
  695. }
  696. }