Tree.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. $sql->select[] = "IF(t.`ALIAS_ID` > 0
  335. , (select concat_ws('.', zap.`DESC`, za.`DESC`)
  336. from `CRM_LISTA_ZASOBOW` as za
  337. left join `CRM_LISTA_ZASOBOW` as zap on(zap.`ID`=za.`PARENT_ID`)
  338. where za.`ID`=t.`ALIAS_ID`
  339. limit 1
  340. )
  341. , ''
  342. ) as ALIAS_NAME
  343. ";
  344. }
  345. $sql->filter = array();
  346. $sql->join_filter = array();
  347. $sql->filter[] = "(t.`{$this->_sql_parent_id_col}`='{$parent_id}')";
  348. $sql->join_filter[] = "(t2.`{$this->_sql_parent_id_col}`=t.`ID`)";
  349. if ($this->_table == 'CRM_LISTA_ZASOBOW') {
  350. // TODO: $this->get_param('TREE_SHOW_P_ID2') $this->get_param('TREE_SHOW_P_ID3')
  351. if ($_SESSION['TREE_SHOW_P_ID2'] || $_SESSION['TREE_SHOW_P_ID3']) {
  352. if ($_SESSION['TREE_SHOW_P_ID2']) {
  353. $sql->filter[] = "(FIND_IN_SET('{$parent_id}', t.`PARENT_ID_ACCESS`) > 0)";
  354. $sql->join_filter[] = "(FIND_IN_SET(t.`ID`, t2.`PARENT_ID_ACCESS`) > 0)";
  355. }
  356. if ($_SESSION['TREE_SHOW_P_ID3']) {
  357. $sql->filter[] = "(FIND_IN_SET('{$parent_id}', t.`PARENT_ID_MAP`) > 0)";
  358. $sql->join_filter[] = "(FIND_IN_SET(t.`ID`, t2.`PARENT_ID_MAP`) > 0)";
  359. }
  360. }
  361. }
  362. $sql->where = implode(" or ", $sql->filter);
  363. $sql->join_filter = implode(" or ", $sql->join_filter);
  364. // filtr_status
  365. if ($this->_table == 'IN7_MK_BAZA_DYSTRYBUCJI') {
  366. $sqlStatus = array();
  367. if ($this->get_param('filtr_status') == 'NORMAL') {
  368. $sqlStatus[] = "'NORMAL'";
  369. } else if ($this->get_param('filtr_status') == 'WAITING') {
  370. $sqlStatus[] = "'NORMAL'";
  371. $sqlStatus[] = "'WAITING'";
  372. }
  373. if (!empty($sqlStatus)) {
  374. $sqlStatus = implode(',', $sqlStatus);
  375. $sql->where = "({$sql->where}) and t.`A_STATUS` in({$sqlStatus}) ";
  376. }
  377. }
  378. if (in_array($this->_table, array('CRM_PROCES','CRM_LISTA_ZASOBOW'))) {
  379. $sql->order_by = "order by t.`SORT_PRIO` asc, t.`ID` asc";
  380. } else {
  381. $sql->order_by = "order by t.`ID` asc";
  382. }
  383. // has_childrens
  384. # IF((select 1 from `CRM_PROCES` as t2 where t2.`PARENT_ID` = t.`ID` limit 1) > 0, 1, 0) AS has_childrens
  385. if ($this->_table == 'CRM_LISTA_ZASOBOW') {
  386. //$sql->select [] = "IF(t.`".$this->_sql_parent_id_col."`='".$parent_id."' and t2.`ID` is not null, 1, 0) as has_childrens";
  387. $sql->select[] = "IF((select 1 from `{$this->_table}` as t2 where {$sql->join_filter} limit 1) is not null, 1, 0) as has_childrens";
  388. } else {
  389. //$sql->select [] = "IF(t2.`ID` is not null, 1, 0) as has_childrens";
  390. $sql->select[] = "IF((select 1 from `{$this->_table}` as t2 where {$sql->join_filter} limit 1) is not null, 1, 0) as has_childrens";
  391. }
  392. $db = DB::getDB();
  393. $sql->select = implode("\n, ", $sql->select);
  394. $sql = "select
  395. {$sql->select}
  396. from `{$this->_table}` as t
  397. where
  398. {$sql->where}
  399. {$sql->order_by}
  400. ";
  401. 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>';}
  402. $res = $db->query($sql);
  403. $rowsCount = 0;
  404. while ($r = $db->fetch($res)) {
  405. $ret[$r->ID] = $r;
  406. $rowsCount++;
  407. }
  408. $this->_nodes_from_db += $rowsCount;
  409. return $ret;
  410. }
  411. public function &get_parents_rec($id, &$arr) {
  412. $db = DB::getDB();
  413. $sql = "select
  414. t.*
  415. , '1' as has_childrens
  416. , 'P_ID' as PARENT_TYPE
  417. from `{$this->_table}` as t
  418. where
  419. t.`ID`='".$id."'
  420. ";
  421. $res = $db->query($sql);
  422. if ($r = $db->fetch($res)) {
  423. array_unshift($arr, $r);
  424. if (null == $this->get_item_p_id($r) || '0' == $this->get_item_p_id($r)) {
  425. return $arr;
  426. } else {
  427. $this->get_parents_rec($this->get_item_p_id($r), $arr);
  428. }
  429. }
  430. return $arr;
  431. }
  432. public function set_param($key, $value) {
  433. $this->_params[$key] = $value;
  434. }
  435. public function get_param($key) {
  436. if (array_key_exists($key, $this->_params)) {
  437. return $this->_params[$key];
  438. }
  439. return null;
  440. }
  441. public function show_css() {
  442. static $_run_only_once;
  443. if ($_run_only_once) {
  444. return;
  445. }
  446. $_run_only_once = true;
  447. ?>
  448. <style type="text/css">
  449. .tree-wrap{border:1px solid #ccc;margin:0;padding:0 5px;list-style:none;font-size:12px;line-height:16px;font-family:monospace;}
  450. .tree-wrap ul{margin:0;padding:0;list-style:none;}
  451. .tree-wrap li{margin:0 0 0 0;padding:0 0 0 10px;line-height:16px;}
  452. .tree-wrap li * {line-height:16px;}
  453. .tree-wrap p,
  454. .tree-wrap .cnt{margin:0 0 0 0;padding:0 0 0 10px;background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  455. .tree-wrap li.tree-leaf .cnt{background:none;}
  456. .tree-wrap p:hover,
  457. .tree-wrap .cnt:hover{background:#FFFFCA url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  458. .tree-wrap li.tree-leaf .cnt:hover{background:none;}
  459. .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;}
  460. .tree-wrap a.item_id:hover {color:#fff; text-decoration:none}
  461. .tree-wrap p .item_id,
  462. .tree-wrap .cnt .item_id{margin:0 0 0 -10px;}
  463. .tree-wrap .cnt .has_wsk .item_id{margin:0 0 0 -20px;}
  464. .tree-wrap ul{background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  465. .tree-wrap li{background:url(stuff/i/t-li.gif) 0 0 no-repeat;}
  466. .tree-wrap li.tree-last{background-color:#fff;}
  467. .tree-wrap .item_type_PROCES_INIT{background:#f00;color:#fff;}
  468. .tree-wrap .btn-p5{margin:0 2px;padding:0 2px;background:#eee;color:#3A3AFF;text-decoration:none;border:0;font-weight:bold;}
  469. .tree-wrap .btn-red{background:#eee;color:#f00;}
  470. .tree-wrap p:hover .btn-box,
  471. .tree-wrap .cnt:hover .btn-box{background:#333;}
  472. .tree-wrap dt:hover .btn-box{background:#333;}
  473. .tree-wrap dt:hover .desc{background-color:#F8F8B4;}
  474. .tree-wrap .active > dl .desc{background-color:#F8F8B4;}
  475. .tree-wrap .active > dl .item_id{background-color:#000;}
  476. .tree-wrap .item-wskazniki{margin:0;padding:0 0 3px 0;}
  477. .tree-wrap .item-has_children{background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  478. .tree-wrap .item-wskazniki ul{margin:0 2px 0 10px;color:#008000;}
  479. .tree-wrap .item-wskazniki ul{background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y;}
  480. .tree-wrap .item-wskazniki li{background:url(stuff/i/t-li-green.gif) 0 0 no-repeat;}
  481. .tree-wrap .item-wskazniki li.tree-last{background-color:#fff;}
  482. .tree-wrap .item-wskazniki p {margin:0;padding:0;background:#fff;}
  483. .tree-wrap .item-wskazniki p:hover{background:#FFFFCA;}
  484. .tree-wrap .item-wskazniki p .wsk_parents{display:none;}
  485. .tree-wrap .item-wskazniki p:hover .wsk_parents{display:inline;color:#555;font-size:11px;}
  486. .tree-wrap .btn-p5:hover{background:#3A3AFF;color:#eee;}
  487. .tree-wrap .btn-open{display:block;width:12px;height:9px;overflow:hidden;}
  488. /*.tree-wrap .btn-open{margin:0;padding:0;position:absolute;top:4px;left:-4px;}*/
  489. /* TODO: IF IE left: -14px */
  490. .tree-wrap .btn-open{border:none;text-decoration:none;background:url(stuff/i/tree-collapse-btn.gif) no-repeat left top;cursor:pointer;}
  491. .tree-wrap li.tree-close .btn-open{background-position:0 -9px;}
  492. .tree-wrap li.tree-close ul{display:none;background:none;}
  493. .tree-wrap li.tree-close .cnt,
  494. .tree-wrap li.tree-close .item-wskazniki,
  495. .tree-wrap li.tree-close dt,
  496. .tree-wrap li.tree-close dd,
  497. .tree-wrap li.tree-close .has_wsk{background:none;}
  498. .tree-wrap li.tree-close dd{padding:0;}
  499. .tree-wrap .desc{margin:0 2px;color:#000;font-weight:normal;}
  500. .tree-wrap .desc-red{color:#f00;}
  501. .tree-wrap .desc-group1{color:navy;}
  502. .tree-wrap .desc-group2{color:olive;}
  503. .tree-wrap .desc .more-desc{color:#333;font-weight:normal;overflow:hidden;}
  504. .tree-wrap .desc .more-desc *{margin:0;}
  505. .tree-wrap .desc .more-desc img{margin:0 2px;}
  506. .tree-wrap .desc .more-desc ul{background:none; list-style:disc; padding:0 0 0 20px;}
  507. .tree-wrap .desc .more-desc ul li {padding:0;}
  508. .tree-wrap .desc .more-desc ul li,
  509. .tree-wrap .desc .more-desc p {background:none;}
  510. .tree-wrap .silver{color:#333;font-weight:normal;}
  511. /* tree-wrap dl-dt-dd: dl{ dt, dd, dl{...} } */
  512. .tree-wrap{border:1px solid #ccc;margin:0;padding:0 5px;list-style:none;font-size:12px;line-height:16px;font-family:monospace;}
  513. .tree-wrap dl{padding:0;margin:0;}
  514. .tree-wrap dt{padding:0 0 0 10px;margin:0;}
  515. .tree-wrap dd{padding:0;margin:0;}
  516. .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;}
  517. .tree-wrap dd{margin:0;padding:0 0 3px 0;}
  518. .tree-wrap dd ul{margin:0 2px 0 10px;color:#008000;}
  519. .tree-wrap dd ul{background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y;}
  520. .tree-wrap dd li{background:url(stuff/i/t-li-green.gif) 0 0 no-repeat;}
  521. .tree-wrap dd li.tree-last{background-color:#fff;}
  522. .tree-wrap dt .item_id{margin:0 0 0 -10px;}
  523. .tree-wrap .has_wsk .item_id{margin:0 0 0 -20px;}
  524. .tree-wrap dd,
  525. .tree-wrap dt{background:url(stuff/i/t-ul.gif) 0 0 repeat-y;}
  526. .tree-wrap dl.has-no-children dd,
  527. .tree-wrap dl.has-no-children dt{background:none;}
  528. .tree-wrap li.tree-leaf dt{background:none;}
  529. .tree-wrap li.tree-leaf dd{background:none;}
  530. .tree-wrap dd p {margin:0;padding:0;background:#fff;}
  531. .tree-wrap dd p:hover{background:#FFFFCA;}
  532. .tree-wrap dd p .wsk_parents{display:none;}
  533. .tree-wrap dd p:hover .wsk_parents{display:inline;color:#555;font-size:11px;}
  534. /* colors by zasob type */
  535. .tree-wrap .type-P_ID .desc {color:#f00;}
  536. .tree-wrap .type-P_ID_ACCESS .desc {color:#0E7E0E;}
  537. .tree-wrap .type-P_ID_MAP .desc {color:#A020F0;}
  538. .tree-wrap .type-ALIAS_ID .desc {color:#FF6900;}
  539. .tree-wrap dt:hover .item_id{background:#000;}
  540. .tree-wrap dl.type-ALIAS_ID dt:hover .item_id{background:#FB9044;}
  541. .tree-wrap dl.type-P_ID_MAP dt:hover .item_id{background:#AB54DF;}
  542. .tree-wrap dl.type-P_ID_ACCESS dt:hover .item_id{background:#0E7E0E;}
  543. /* TODO: IE style
  544. .tree-wrap ul{float:left;overflow:hidden;}
  545. .tree-wrap li{float:left;clear:both}
  546. .tree-wrap dl{float:left;}
  547. .tree-wrap dl{display:inline;}
  548. */
  549. /*
  550. .tree-wrap ul{clear:both;float:left;width:100%;}
  551. .tree-wrap li{float:left;clear:both;width:100%;}
  552. .tree-wrap dl{clear:both;}
  553. .tree-wrap dl dt{float:left}
  554. .tree-wrap dl dd{}
  555. .tree-wrap .btn-open{float:left;margin:4px 0 0 -14px;padding:0;}
  556. .tree-wrap .has_wsk .btn-open{float:left;margin:4px 0 0 -24px;padding:0;}
  557. */
  558. .tree-wrap li{position:relative}
  559. .tree-wrap .btn-open{position:absolute;top:4px;left:-4px;padding:0;}
  560. /*.tree-wrap .has_wsk .btn-open{position:absolute;top:4px;left:-14px;padding:0;}*/
  561. /* zasoby: external ids */
  562. .tree-wrap .external-ids{color:#008A00; font-weight:bold;}
  563. .tree-wrap .external-ids .not-found{color:#666; font-weight:normal;}
  564. .tree-wrap .external-ids a{color:#008A00; font-weight:normal; text-decoration:none;}
  565. .tree-wrap .external-ids a:hover{text-decoration:underline;}
  566. .tree-wrap .external-ids a img{vertical-align:bottom;}
  567. .tree-wrap .search_id .desc{background-color:#C2F9C2;}
  568. .tree-wrap .open-rec{display:none;}
  569. .tree-wrap .tree-close .open-rec{display:inline;}
  570. .tree-wrap li.hide-wskazniki dd{display:none;}
  571. .tree-wrap .wsk-modal,
  572. .tree-wrap .popover,
  573. .tree-wrap .wsk-help {color:#333;}
  574. .tree-wrap .wsk-modal h1,
  575. .tree-wrap .wsk-modal h2,
  576. .tree-wrap .wsk-modal h3,
  577. .tree-wrap .wsk-modal h4,
  578. .tree-wrap .wsk-modal h5,
  579. .tree-wrap .wsk-modal h6 {line-height:1.2em;}
  580. </style>
  581. <?php
  582. }
  583. public function show_js() {
  584. ?>
  585. <script type="text/javascript">
  586. function <?php echo $this->js_tree_hide_fun; ?>(n, id){
  587. var p=jQuery(n).parents('li:first')
  588. <?php echo $this->js_tree_hide_fun; ?>_node(p, id);
  589. }
  590. function <?php echo $this->js_tree_hide_fun; ?>_node(p, id, open_rec) {
  591. p.toggleClass('tree-close');
  592. var c = jQuery.cookie('<?php echo $this->cookie_name; ?>');
  593. if (c === null) c = '';
  594. if (p.hasClass('tree-close')) {// open subtree
  595. // remove id from cookie
  596. //c = (' '+c+' ').replace((new RegExp(' '+id+' ', 'g')), ' ')
  597. var carr = c.split(' ');
  598. jQuery.unique(carr);
  599. c = (' ' + carr.join(' ') + ' ').replace((new RegExp(' ' + id + ' ', 'g')), ' ');
  600. }
  601. else {// close subbtree
  602. // add id to cookie, uniq array
  603. if ((' ' + c + ' ').indexOf(' ' + id + ' ') == -1){
  604. c = (c === '')? '' + id : '' + id + ' ' + c;
  605. }
  606. if (jQuery(p).children('ul').length == 0) {
  607. // create node to verride html from ajax request
  608. var cnt = jQuery('<em>loading...</em>');
  609. jQuery(p).append(cnt);
  610. var cnt = jQuery(p).children('em').get(0);
  611. // run ajax function
  612. var ajax_add_args = '';
  613. if (open_rec) {
  614. ajax_add_args = '&open_rec=1';
  615. }
  616. procesy_ajax_run(cnt, '?function_init=ajax_get_subtree&tbl=<?php echo $this->_table; ?>&id=' + id + ajax_add_args, 'override');
  617. }
  618. }
  619. c = jQuery.trim(c);
  620. //if (console && console.log) console.log(c)
  621. jQuery.cookie('<?php echo $this->cookie_name; ?>', c);
  622. return false;
  623. }
  624. // open recursive
  625. function <?php echo $this->js_tree_open_rec_fun; ?>(n, id) {
  626. // execute ajax function to fetch subtree with Drzewo=ROZWIN
  627. var p = jQuery(n).parents('li:first');
  628. node_id = p.attr('id');
  629. if (node_id.substr(0, 4) == 'TREE') {
  630. node_id = node_id.substr(4);
  631. //console.log('[' + node_id + ']has_class: ' + p.hasClass('tree-close') + ' ...');
  632. var childrens = p.children('ul');
  633. //console.log('[' + node_id + ']childrens: ');
  634. if (childrens) {
  635. childrens.remove();
  636. }
  637. <?php echo $this->js_tree_hide_fun; ?>_node(p, node_id, true);
  638. } else {
  639. //console.log('ERROR: id TREE');
  640. }
  641. return false;
  642. }
  643. // ajax reopen nodes, on document load
  644. jQuery(document).ready(function(){
  645. var nodes = jQuery('.ajax-reopen');
  646. if (nodes.length) nodes.click();
  647. jQuery('.wsk-help').popover({trigger:'hover', html:true, placement:'top'});
  648. //jQuery('.wsk-long-desc').modal();
  649. });
  650. </script>
  651. <?php
  652. }
  653. }