DESC; $db = DB::getDB(); $r = $db->get_by_id($tblName, $id); if (!$r) { throw new HttpException("Rekord ID={$id} nie istnieje", 404); } $wsk = array(); $ids_conf_arr = array(); $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"); $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"); if (!empty($ids_conf_arr)) { $external_ids = array(); foreach ($ids_conf_arr as $k_table_name => $v_cnf) { $cur_cnf = new stdClass(); $cur_cnf->id_col = V::get('id_col', 'ID', $v_cnf); $cur_cnf->search_col = V::get('search_col', 'ID_PROJECT', $v_cnf); $cur_cnf->search_col_regex = V::get('search_col_regex', '', $v_cnf); $sql_id_col = $cur_cnf->id_col; $sql_where = ""; if ($cur_cnf->search_col_regex) { $sql_where = "`{$cur_cnf->search_col}` like '".str_replace('$ID', $r->ID, $cur_cnf->search_col_regex)."'"; } else { $sql_where = "`{$cur_cnf->search_col}`='{$r->ID}'"; } $db = DB::getDB(); $sql = "select t.`{$sql_id_col}` from `{$k_table_name}` as t where {$sql_where} "; $res = $db->query($sql); while ($r_wsk = $db->fetch($res)) { $wsk[] = (object)array('name'=>$r_wsk->$sql_id_col, 'table'=>$k_table_name); } } } $response = new stdClass(); $response->ids = $wsk; return $response; } function TREEJS() { global $result,$thiss; $ajaxTask = V::get('_ajaxTask', '', $_GET); $funName = "TREEJS__ajaxTask__{$ajaxTask}"; if (function_exists($funName)) { try { $response = $funName($_GET); } catch (HttpException $e) { $response = new stdClass(); $response->type = 'error'; $response->msg = $e->getMessage(); $response->errorCode = $e->getCode(); Http::sendHeaderByCode($e->getCode()); } catch (Exception $e) { $response = new stdClass(); $response->type = 'error'; $response->msg = $e->getMessage(); $response->errorCode = $e->getCode(); } header('Content-type: application/json'); if (!$response) $response = new stdClass(); echo json_encode($response); exit; } $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int'); if ($zasobID <= 0) { echo 'Wrong param ZASOB_ID'; return; } $TEST_TREE_LAZY_LOAD = 1; $DBG_TIME = ('1' == V::get('DBG_TIME', '', $_GET)); $dbgExecTime = new DebugExecutionTime(); if ($DBG_TIME) $dbgExecTime->activate(); $dbgExecTime->log('start'); echo "<<".'Powrot do tabeli'; $conf = null; $tblName = ''; $zasobObj = ProcesHelper::getZasobTableInfo($zasobID); if (!$zasobObj) { echo "Zasob TABELA ID={$zasobID} nie istnieje"; return; } $tblName = $zasobObj->DESC; $allowed_tables_conf = array(); $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI'] = array('set_parent_id_col'=>'P_ID'); $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params'] = array(); $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params']['show_item_callback'] = 'tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI'; $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params']['ajax'] ='NIE'; if (!array_key_exists($tblName, $allowed_tables_conf)) { echo'

'."Brak dostepu".'

'; } $conf = $allowed_tables_conf[$tblName]; echo''."\n"; App::show_head_css(); App::show_head_js(); function tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI(&$r, &$tree) { $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int'); // TODO: btn-box zasob type from PARENT_ID $cls = array(); if (($search_id = $tree->get_param('search_id')) > 0 && $search_id == $r->ID) { $cls[] = 'search_id'; } $cls = (!empty($cls))? ' class="'.implode(' ', $cls).'"' : ''; echo''; echo'
'; $out_id = ($r->ID < 10)? ' '.$r->ID.'' : $r->ID; echo'ID}#TREE{$r->ID}" . '" class="item_id btn-box">'.$out_id.''; echo'ID}".'" class="btn btn-xs btn-link" title="'."Edit".'">'."E".''; //if ($r->has_childrens) { // if (!$tree->get_param('rozwin')) { // $js = "return " . $tree->js_tree_open_rec_fun . "(this," . $r->ID . ");"; // echo''."L".''; // } //} // TODO: edycja nie działa - bierze ostatni edytowany rekord //echo' ID}".'" class="btn-box">'."E".''; $st_status_bg = ''; if ($r->A_STATUS == 'NORMAL') { $st_status_bg = '#8F8;'; } else if ($r->A_STATUS == 'WAITING') { $st_status_bg = '#F8F;'; } else if ($r->A_STATUS == 'DELETED') { $st_status_bg = '#ccc;'; } else if ($r->A_STATUS == 'OFF_SOFT') { $st_status_bg = '#F99;'; } else if ($r->A_STATUS == 'OFF_HARD') { $st_status_bg = '#eee;'; } $st_status_bg = ($st_status_bg)? 'background-color:'.$st_status_bg : ''; echo''; echo''.$r->A_STATUS.''; echo' '.((strlen($r->M_DIST_TYPE) > 5)? substr($r->M_DIST_TYPE, 0, 5).'...' : $r->M_DIST_TYPE).''; echo' '.$r->M_DIST_DESC.''; echo' '.$r->M_DISTRIBUTOR.''; echo' '.$r->M_DIST_INVENTOR.''; echo''; $htmlTreeId = $tree->get_param('htmlTreeId'); echo ' '; echo'
'; echo''."\n"; } {// tree filter $tbl = $tblName; $tree_filter = new Filter($_GET, $tbl, 'session'); if ($tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') { { // filtr_status $filtr = array(); $filtr['WSZYSTKIE'] = 'WSZYSTKIE'; $filtr['WAITING'] = 'WAITING'; $filtr['NORMAL'] = 'NORMAL'; // TODO: add js search without page reload, add #TREE{ID} $tree_filter->add_filter('filtr_status', $filtr, 'WSZYSTKIE', 'Status'); } {// filtr_id $filtr = array('search'); $tree_filter->add_filter('filtr_id', $filtr, '', 'Filtruj ID'); } { // filtr_search_id $filtr = array('search'); // TODO: add js search without page reload, add #TREE{ID} $tree_filter->add_filter('filtr_search_id', $filtr, '', 'Wyszukaj ID'); } { // filtr_ids $filtr = array(); $filtr['SHOW'] = '0'; $filtr['HIDE'] = '1'; $tree_filter->add_filter('filtr_ids', $filtr, 'HIDE', 'IDS'); } } }// tree filter $tree_filter->_save_args(); session_write_close();// End the current session and store session data. Below $_SESSION is read-only. $htmlTreeId = "tree" . md5(time()); echo '
'; if(0){// RMME echo'
'; echo'
'; //echo''; echo''; echo''; //$tree_filter->show_filters(array('submit_function'=>$htmlTreeId . '_filters(this)')); echo'
'; echo'
'; } ?>
" style="margin:0;padding:0;"> Status
Filtruj ID "> ">
">
log('start-lazy-load'); $items = array(); $db = DB::getDB(); $sql = "select p.ID, p.P_ID , p.`A_STATUS` , p.`M_DIST_TYPE` , p.`M_DIST_DESC` , p.`M_DISTRIBUTOR` , p.`M_DIST_INVENTOR` from `{$tblName}` as p where p.P_ID!='-1' -- and p.P_ID!='' and p.P_ID>=0 "; $res = $db->query($sql); $dbgExecTime->log('lazy-execute-sql', array('lazy-load')); while ($r = $db->fetch($res)) { $r->sub = array(); $r->P_ID = trim($r->P_ID); $r->P_ID = str_replace(' ', ',', $r->P_ID); $v_parents = array(); $v_parents_test = explode(',', $r->P_ID); foreach ($v_parents_test as $v_id) { $v_id = intval(trim($v_id)); if ($v_id > 0) { $v_parents[] = $v_id; } } if (empty($v_parents)) { $r->P_ID = 0; } else { $r->P_ID = $v_parents; } $items[$r->ID] = $r; } $dbgExecTime->log('lazy-load-sql', array('lazy-load')); // set root for tree $pro_tree $pro_tree = array(); foreach ($items as $k_id => $r) { if ($r->P_ID == 0) { $pro_tree[$r->ID] = array(); $v_id = $r->P_ID; if (array_key_exists($v_id, $items)) { $items[$v_id]->sub[$r->ID] = true; } } else {// array foreach ($r->P_ID as $v_id) { if (array_key_exists($v_id, $items)) { $items[$v_id]->sub[$r->ID] = true; } } } } ksort($pro_tree); // set up has_childrens foreach ($items as $k_id => $r) { $items[$k_id]->has_childrens = !empty($r->sub); } // build tree by P_ID - array or 0 function TREEJS_create_project_tree_rec($p_id, &$items) { static $rec_ind; $rec_ind++; $ret = array(); if (!array_key_exists($p_id, $items)) { return false; } else { $r = $items[$p_id]; if (empty($r->sub)) { return false; } foreach ($r->sub as $k_id => $v) { $ret[$k_id] = TREEJS_create_project_tree_rec($k_id, $items); } return $ret; } } //$pro_tree = TREEJS_create_project_tree_rec($pro_tree, $items); foreach ($pro_tree as $k_id => $v_childrens) { if (array_key_exists($k_id, $items)) { $pro_tree[$k_id] = TREEJS_create_project_tree_rec($k_id, $items); } } $dbgExecTime->log('end-lazy-load', array('lazy-load')); } $tree = new Tree($tblName); $tree->set_param('htmlTreeId', $htmlTreeId); $tree->setProfiler($dbgExecTime); if (($p_id_col = V::get('set_parent_id_col', '', $conf)) != '') { $tree->set_parent_id_col($p_id_col); } if (!empty($conf['params'])) { foreach ($conf['params'] as $k_param => $v_param) { $tree->set_param($k_param, $v_param); } } $tree->set_param('filtr_status', $tree_filter->get_arg('filtr_status')); $dbgExecTime->log('start-show-tree'); if ($TEST_TREE_LAZY_LOAD) { $tree->show_css(); $tree->show_js(); echo "\n".'
'."\n"; $tree->show_rec_by_tree($pro_tree, $items); echo '
'."\n"; } else { if ($tree_filter->get_arg('filtr_id') != 0) { $tree->showSubTree($tree_filter->get_arg('filtr_id')); } else if ($tree_filter->get_arg('filtr_search_id') > 0) { $tree->showSearchNode($tree_filter->get_arg('filtr_search_id')); } else { $tree->show(); } } $dbgExecTime->log('end-show-tree', array('show-tree')); echo '
'; ?> log('end'); $dbgExecTime->printDebug(); } }