Tree.php 22 KB

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