superedit-TREEJS.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <?php
  2. function TREEJS() {
  3. global $result,$thiss;
  4. $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
  5. if ($zasobID <= 0) {
  6. echo 'Wrong param ZASOB_ID';
  7. return;
  8. }
  9. echo "&lt;&lt;".'<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobID}" . '" title="Powrot">Powrot do tabeli</a>';
  10. $conf = null;
  11. $tblName = '';
  12. Lib::loadClass('ProcesHelper');
  13. $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
  14. if (!$zasobObj) {
  15. echo "Zasob TABELA ID={$zasobID} nie istnieje";
  16. return;
  17. }
  18. $tblName = $zasobObj->DESC;
  19. $allowed_tables_conf = array();
  20. $allowed_tables_conf ['IN7_MK_BAZA_DYSTRYBUCJI'] = array('set_parent_id_col'=>'P_ID');
  21. $allowed_tables_conf ['IN7_MK_BAZA_DYSTRYBUCJI']['params'] = array();
  22. $allowed_tables_conf ['IN7_MK_BAZA_DYSTRYBUCJI']['params']['show_item_callback']='tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI';
  23. $allowed_tables_conf ['IN7_MK_BAZA_DYSTRYBUCJI']['params']['ajax']='NIE';
  24. if (!array_key_exists($tblName, $allowed_tables_conf)) {
  25. echo'<p>'."Brak dostepu".'</p>';
  26. }
  27. $conf = $allowed_tables_conf[$tblName];
  28. require_once dirname(__FILE__) . '/' . 'se-lib' . '/' . 'Lib.php';
  29. Lib::loadClass('V');
  30. Lib::loadClass('DB');
  31. Lib::loadClass('Tree');
  32. Lib::loadClass('TreeHelper');
  33. Lib::loadClass('App');
  34. echo'<style type="text/css">'."
  35. .btn-box{margin:0 2px 0 0;padding:0 3px;background:#bbb;color:#fff;text-decoration:none;border:0;font-weight:bold;}
  36. .btn-box-blue{background:#3A3AFF;color:#fff;}
  37. .btn-box-green{background:#008A00;color:#fff;}
  38. .btn-box-lgreen{background:#97CF97;color:#fff;}
  39. .btn-box-red{background:#FF4646;color:#fff;}
  40. .btn-box-group1{background-color:#9F9FCB;color:#fff;}
  41. .btn-box-group2{background-color:#B8B879;color:#fff;}
  42. /*.tree-wrap .btn{border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;}*/
  43. /*.btn-box{border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;}*/
  44. .filters{margin:0;padding:2px;background:#F0F0F0 url(./stuff/flexigrid/css/images/bg.gif) repeat-x top;border:1px solid #ccc;border-style:solid solid none solid;clear:both;overflow:hidden;}
  45. .filters .btnseparator{float:left;height:22px;border-left:1px solid #CCC;border-right:1px solid #fff;margin:1px;}
  46. .filters form{margin:0;padding:0;}
  47. .filters nobr{display:block;float:left;margin:0;padding:2px;font-weight:normal;font-size:13px;}
  48. .filters nobr:hover{text-decoration:underline;}
  49. .filters nobr.active{color:#f00;font-weight:normal;}
  50. .filters nobr input,
  51. .filters nobr select,
  52. .filters nobr button{margin:0 1px;padding:0 2px;font-size:13px;}
  53. ".'</style>'."\n";
  54. App::show_head_css();
  55. App::show_head_js();
  56. function tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI( &$r, &$tree ) {
  57. $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
  58. // TODO: btn-box zasob type from PARENT_ID
  59. $cls = array();
  60. if (($search_id = $tree->get_param('search_id')) > 0 && $search_id == $r->ID) {
  61. $cls []= 'search_id';
  62. }
  63. $cls = (!empty($cls))? ' class="'.implode(' ', $cls).'"' : '';
  64. {// $wsk == ids
  65. $wsk = array();
  66. if ($tree->get_param('filtr_ids')) {
  67. /*
  68. [DEVICES]
  69. id_col="T_DEVICE_SERIAL"
  70. allowed_cols="ID,CRM_LISTA_ZASOBOW_ID:CLZ_ID,T_TELBOX_NEIGHBOUR_IN,T_DEVICE_SERIAL,T_DEVICE_INFO,A_STATUS_EV,S_OTHER_INFO"
  71. [TELBOXES]
  72. id_col="T_TELBOX_NAME"
  73. allowed_cols="ID,CRM_LISTA_ZASOBOW_ID:CLZ_ID,T_TELBOX_NEIGHBOUR_IN,T_TELBOX_NEIGHBOUR_OUT,T_TELBOX_NAME,A_STATUS,S_OTHER_INFO"
  74. */
  75. $ids_conf_arr = array();
  76. $ids_conf_arr ['DEVICES']= array('id_col'=>"T_DEVICE_SERIAL",'allowed_cols'=>"ID,CRM_LISTA_ZASOBOW_ID:CLZ_ID,T_TELBOX_NEIGHBOUR_IN,T_DEVICE_SERIAL,T_DEVICE_INFO,A_STATUS,S_OTHER_INFO");
  77. $ids_conf_arr ['TELBOXES']= array('id_col'=>"T_TELBOX_NAME",'allowed_cols'=>"ID,CRM_LISTA_ZASOBOW_ID:CLZ_ID,T_TELBOX_NEIGHBOUR_IN,T_TELBOX_NEIGHBOUR_OUT,T_TELBOX_NAME,A_STATUS,S_OTHER_INFO");
  78. if (!empty($ids_conf_arr)) {
  79. $external_ids = array();
  80. foreach ($ids_conf_arr as $k_table_name => $v_cnf) {
  81. $cur_cnf = new stdClass();
  82. $cur_cnf->id_col = V::get('id_col', 'ID', $v_cnf);
  83. $cur_cnf->search_col = V::get('search_col', 'ID_PROJECT', $v_cnf);
  84. $cur_cnf->search_col_regex = V::get('search_col_regex', '', $v_cnf);
  85. $sql_id_col = $cur_cnf->id_col;
  86. $sql_where = "";
  87. if ($cur_cnf->search_col_regex) {
  88. $sql_where = "`".$cur_cnf->search_col."` like '".str_replace('$ID', $zasob->ID, $cur_cnf->search_col_regex)."'";
  89. } else {
  90. $sql_where = "`".$cur_cnf->search_col."`='".$r->ID."'";
  91. }
  92. $sql = "select t.`".$sql_id_col."`
  93. from `".$k_table_name."` as t
  94. where ".$sql_where."
  95. ";
  96. $res = DB::query( $sql );
  97. while ($r_wsk = DB::fetch( $res )) {
  98. $wsk []= (object)array('name'=>$r_wsk->$sql_id_col, 'table'=>$k_table_name);
  99. }
  100. }//end foreach
  101. }
  102. }
  103. }
  104. echo'<dl'.$cls.'>';
  105. echo'<dt>';
  106. $out_id = ($r->ID < 10)? '&nbsp;'.$r->ID.'' : $r->ID;
  107. echo'<a href="'."index.php?MENU_INIT=TREEJS&ZASOB_ID={$zasobID}&filtr_id=".$r->ID."#TREE".$r->ID.'" class="item_id btn-box">'.$out_id.'</a>';
  108. echo'<a href="'."index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobID}#EDIT/{$r->ID}".'" class="btn" title="'."Edit".'">'."E".'</a>';
  109. //if ($r->has_childrens) {
  110. // if (!$tree->get_param('rozwin')) {
  111. // $js = "return " . $tree->js_tree_open_rec_fun . "(this," . $r->ID . ");";
  112. // echo'<a href="'."#".'" title="'."Rozwin wszystko".'" onclick="'.$js.'" class="btn open-rec">'."L".'</a>';
  113. // }
  114. //}
  115. // TODO: edycja nie działa - bierze ostatni edytowany rekord
  116. //echo' <a href="'."?FUNCTION_INIT=IN7_MK_BAZA_DYSTRYBUCJI_EDIT&ARG1=EDIT&ARG1_VAL=".$r->ID.'" class="btn-box">'."E".'</a>';
  117. $st_status_bg = '';
  118. if ($r->A_STATUS == 'NORMAL') {
  119. $st_status_bg = '#8F8;';
  120. } else if ($r->A_STATUS == 'WAITING') {
  121. $st_status_bg = '#F8F;';
  122. } else if ($r->A_STATUS == 'DELETED') {
  123. $st_status_bg = '#ccc;';
  124. } else if ($r->A_STATUS == 'OFF_SOFT') {
  125. $st_status_bg = '#F99;';
  126. } else if ($r->A_STATUS == 'OFF_HARD') {
  127. $st_status_bg = '#eee;';
  128. }
  129. $st_status_bg = ($st_status_bg)? 'background-color:'.$st_status_bg : '';
  130. echo'<span class="desc">';
  131. echo'<span class="btn-box" style="'.$st_status_bg.'">'.$r->A_STATUS.'</span>';
  132. echo' <em style="color:#666;" title="'.$r->M_DIST_TYPE.'">'.((strlen($r->M_DIST_TYPE) > 5)? substr($r->M_DIST_TYPE, 0, 5).'...' : $r->M_DIST_TYPE).'</em>';
  133. echo' <i style="color:red">'.$r->M_DIST_DESC.'</i>';
  134. echo' <span>'.$r->M_DISTRIBUTOR.'</span>';
  135. echo' <font size="-1">'.$r->M_DIST_INVENTOR.'</font>';
  136. echo'</span>';
  137. echo'</dt>';
  138. if (!empty($wsk)) {
  139. echo'<dd>';
  140. echo'<ul>';
  141. $wsk_cnt = count( $wsk );
  142. foreach ($wsk as $w) {
  143. echo'<li'.((--$wsk_cnt)? '' : ' class="last"').'>';
  144. echo'<p>';
  145. //TODO: test: echo ' <span class="btn-box btn-box-silver">'.".".$w->CW_ID.".".'</span>';
  146. echo ' <span class="silver">'.$w->table.'</span>';
  147. echo' <b>'.$w->name.'</b>';
  148. echo'</p>';
  149. echo'</li>';
  150. }
  151. echo'</dd>';
  152. }
  153. echo'</dl>'."\n";
  154. }
  155. {// tree filter
  156. $tbl = $tblName;
  157. Lib::loadClass('Filter');
  158. $tree_filter = new Filter( $_GET, $tbl, 'session' );
  159. if ($tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') {
  160. { // filtr_status
  161. $filtr = array();
  162. $filtr['WSZYSTKIE'] = 'WSZYSTKIE';
  163. $filtr['WAITING'] = 'WAITING';
  164. $filtr['NORMAL'] = 'NORMAL';
  165. // TODO: add js search without page reload, add #TREE{ID}
  166. $tree_filter->add_filter( 'filtr_status', $filtr, 'WSZYSTKIE', 'Status' );
  167. }
  168. {// filtr_id
  169. $filtr = array('search');
  170. $tree_filter->add_filter( 'filtr_id', $filtr, '', 'Filtruj ID' );
  171. }
  172. { // filtr_search_id
  173. $filtr = array('search');
  174. // TODO: add js search without page reload, add #TREE{ID}
  175. $tree_filter->add_filter( 'filtr_search_id', $filtr, '', 'Wyszukaj ID' );
  176. }
  177. { // filtr_ids
  178. $filtr = array();
  179. $filtr['SHOW'] = '0';
  180. $filtr['HIDE'] = '1';
  181. $tree_filter->add_filter( 'filtr_ids', $filtr, 'HIDE', 'IDS' );
  182. }
  183. }
  184. }// tree filter
  185. $tree_filter->_save_args();
  186. echo'<div class="filters">';
  187. echo'<form action="'."".'" method="get" style="margin:0;padding:0;">';
  188. //echo'<input type="hidden" name="'."FUNCTION_INIT".'" value="'."TREEJS".'" />';
  189. echo'<input type="hidden" name="'."MENU_INIT".'" value="'."TREEJS".'" />';
  190. echo'<input type="hidden" name="'."ZASOB_ID".'" value="'."{$zasobID}".'" />';
  191. $tree_filter->show_filters();
  192. if(0){
  193. {// save profile - btn
  194. echo'<nobr>';
  195. echo'<input type="submit" name="save_profile" value="'."Save".'" title="'."Save profile".'" />';
  196. echo'</nobr>';
  197. }
  198. {// load profile - btn
  199. echo'<nobr>';
  200. echo'<input type="submit" name="load_profile" value="'."Load".'" title="'."Load profile".'" />';
  201. echo'</nobr>';
  202. }
  203. }
  204. echo'</form>';
  205. echo'</div>';
  206. if(0){// test-tree-js
  207. $items = array();
  208. $sql = "select p.ID, p.P_ID
  209. , p.`A_STATUS`
  210. , p.`M_DIST_TYPE`
  211. , p.`M_DIST_DESC`
  212. , p.`M_DISTRIBUTOR`
  213. , p.`M_DIST_INVENTOR`
  214. from `".$tblName."` as p
  215. where
  216. p.P_ID!='-1' and p.P_ID!=''
  217. ";
  218. $res = DB::query( $sql );
  219. while ($r = DB::fetch( $res )) {
  220. $r->sub = array();
  221. $r->P_ID = trim($r->P_ID);
  222. $r->P_ID = str_replace(' ', ',', $r->P_ID);
  223. $v_parents = array();
  224. $v_parents_test = explode(',', $r->P_ID);
  225. foreach ($v_parents_test as $v_id) {
  226. $v_id = intval(trim($v_id));
  227. if ($v_id > 0) {
  228. $v_parents []= $v_id;
  229. }
  230. }//end foreach
  231. if (empty($v_parents)) {
  232. $r->P_ID = 0;
  233. } else {
  234. $r->P_ID = $v_parents;
  235. }
  236. $items[$r->ID] = $r;
  237. }
  238. // set root for tree $pro_tree
  239. $pro_tree = array();
  240. foreach ($items as $k_id => $r) {
  241. if ($r->P_ID == 0) {
  242. $pro_tree [ $r->ID ] = array();
  243. $v_id = $r->P_ID;
  244. if (array_key_exists($v_id, $items)) {
  245. $items[$v_id]->sub [$r->ID] = true;
  246. }
  247. } else {// array
  248. foreach ($r->P_ID as $v_id) {
  249. if (array_key_exists($v_id, $items)) {
  250. $items[$v_id]->sub [$r->ID] = true;
  251. }
  252. }//end foreach
  253. }
  254. }//end foreach
  255. ksort($pro_tree);
  256. // set up has_childrens
  257. foreach ($items as $k_id => $r) {
  258. $items[$k_id]->has_childrens = !empty($r->sub);
  259. }//end foreach
  260. // build tree by P_ID - array or 0
  261. function TREEJS_create_project_tree_rec( $p_id, &$items ) {
  262. static $rec_ind;
  263. $rec_ind++;
  264. $ret = array();
  265. if (!array_key_exists($p_id, $items)) {
  266. return false;
  267. } else {
  268. $r = $items[$p_id];
  269. if (empty($r->sub)) {
  270. return false;
  271. }
  272. foreach ($r->sub as $k_id => $v) {
  273. $ret [$k_id] = TREEJS_create_project_tree_rec( $k_id, $items );
  274. }//end foreach
  275. return $ret;
  276. }
  277. }
  278. //$pro_tree = TREEJS_create_project_tree_rec( $pro_tree, $items );
  279. foreach ($pro_tree as $k_id => $v_childrens) {
  280. if (array_key_exists($k_id, $items)) {
  281. $pro_tree[$k_id] = TREEJS_create_project_tree_rec( $k_id, $items );
  282. }
  283. }
  284. }// test-tree-js
  285. $tree = new Tree( $tblName );
  286. if (($p_id_col = V::get('set_parent_id_col', '', $conf)) != '') {
  287. $tree->set_parent_id_col( $p_id_col );
  288. }
  289. if (!empty($conf['params'])) {
  290. foreach ($conf['params'] as $k_param => $v_param) {
  291. $tree->set_param($k_param, $v_param);
  292. }//end foreach
  293. }
  294. $tree->set_param('filtr_status', $tree_filter->get_arg('filtr_status'));
  295. $tree->set_param('filtr_ids', ($tree_filter->get_arg('filtr_ids') == 'SHOW'));
  296. if(0){// test-tree-js
  297. $tree->show_css();
  298. $tree->show_js();
  299. echo "\n".'<div class="tree-wrap">'."\n";
  300. $tree->show_rec_by_tree($pro_tree, $items);
  301. echo '</div>'."\n";
  302. return;
  303. echo'<br /><hr /><br />';
  304. // TODO: rm
  305. }// test-tree-js
  306. if ($tree_filter->get_arg('filtr_id') != 0) {
  307. $tree->showSubTree( $tree_filter->get_arg('filtr_id') );
  308. } else if ($tree_filter->get_arg('filtr_search_id') > 0) {
  309. $tree->showSearchNode( $tree_filter->get_arg('filtr_search_id') );
  310. } else {
  311. $tree->show();
  312. }
  313. }