';
foreach ($tree as $r) {
echo '
';
echo $r->ID . ' ' . $r->DESC;
echo '
';
}//end foreach
echo '';
echo '';
}
function task_CRM_EXT_IDS() {
echo''."F." . __FUNCTION__ . "..." . '
';
$cnf = Config::getConfFile('external_ids');
if (!$cnf) {
echo'Config error (external_ids)';
return;
}
if (empty($cnf)) {
echo'Config empty (external_ids)';
return;
}
if (($remote_id = V::get('remote_id', '', $_REQUEST, 'int')) > 0 && ($remote_table = V::get('remote_table', '', $_REQUEST)) != '') {
echo'';
echo App::link("CRM_EXT_IDS", "?task=CRM_EXT_IDS");
echo " - Remote {$remote_table}.{$remote_id} ...";
echo'
';
if (!array_key_exists($remote_table, $cnf)) {
echo''."Table not exists in config".'
';
return;
}
$r = DB::get_by_id( $remote_table, $remote_id );
echo'';print_r($r);echo'
';
echo'';
echo'- ';
echo $remote_table.'.';
echo $r->ID;
echo ' '.$r->T_TELBOX_TYPE.'';
echo ' '.$r->T_TELBOX_NAME.'';
echo' ('.$r->S_ADDRESS_STREET.')';
echo'
';
echo'- ';
if ($r->CRM_LISTA_ZASOBOW_ID > 0) {
echo'
'."Przypisany do zasobu ".$r->CRM_LISTA_ZASOBOW_ID.".".'
';
$tree = new Tree( 'CRM_LISTA_ZASOBOW' );
$tree->show_rec( $r->CRM_LISTA_ZASOBOW_ID );
} else {
echo''."Brak przypisanego zasobu.".'
';
}
echo' ';
echo'
';
return;
}
$external_tbls = array();
foreach ($cnf as $k_table_name => $v_cnf) {
$cur_cnf = new stdClass();
$cur_cnf->table_name = $k_table_name;
$cur_cnf->id_col = V::get('id_col', 'ID', $v_cnf);
$cur_cnf->allowed_cols = V::get('allowed_cols', '', $v_cnf);
$cur_cnf->search_col = V::get('search_col', 'CRM_LISTA_ZASOBOW_ID', $v_cnf);
$cur_cnf->search_col_regex = V::get('search_col_regex', '', $v_cnf);
$sql_id_col = $cur_cnf->id_col;
$cur_cnf->cols = array();
$cur_cnf->sql = "";
$cur_cnf->cols ['ID']= 'ID';
$cur_cnf->cols [$cur_cnf->id_col]= $cur_cnf->id_col;
$cur_cnf->cols [$cur_cnf->search_col]= $cur_cnf->search_col;
if (!empty($cur_cnf->allowed_cols)) {
$cols = explode(',', $cur_cnf->allowed_cols);
foreach ($cols as $v_col) {
$v_col = trim($v_col);
$k_col = $v_col;
if (strpos($v_col, ':') !== false) {
list($k_col, $v_col) = explode(':', $v_col, 2);
}
$cur_cnf->cols [$k_col]= $v_col;
}//end foreach
}
$sql_where = "";
if ($cur_cnf->search_col_regex) {
$sql_where = "`".$cur_cnf->search_col."` like '".str_replace('$ID', '%', $cur_cnf->search_col_regex)."'";
} else {
$sql_where = "`".$cur_cnf->search_col."` is not null";
}
$sql_cols = array();
foreach ($cur_cnf->cols as $k_col => $v_col) {
$sql_cols []= "t.`".$k_col."` as ".$v_col."";
}//end foreach
$cur_cnf->sql = "select ".implode(",", $sql_cols)."
from `".$cur_cnf->table_name."` as t
where ".$sql_where."
";
$external_tbls []= $cur_cnf;
}//end foreach
foreach ($external_tbls as $cur_cnf) {
echo''.$cur_cnf->table_name.'
';
$res = DB::query( $cur_cnf->sql );
echo'';
echo'';
echo'';
foreach ($cur_cnf->cols as $k_col => $v_col) {
echo'| '.$v_col.' | ';
}//end foreach
echo'
';
echo'';
echo'';
while ($r = DB::fetch( $res )) {
echo'';
foreach (get_object_vars($r) as $k => $v) {
echo'| ';
if ($k == 'ID') {
echo App::link($v, "?task=CRM_EXT_IDS&remote_table=".$cur_cnf->table_name."&remote_id=".$v);
} else {
echo $v;
}
echo' | ';
}//end foreach
echo'
';
}
echo'';
echo'
';
echo'
';
}//end foreach
echo''."EOF F." . __FUNCTION__ . "..." . '
';
}