setArgs($_GET); $clbk = 'tree_callback__show_item_from_'.$tbl; if (!function_exists($clbk)) { $clbk = null; } $tree = new Tree($tbl); if ($clbk) $tree->set_param('show_item_callback', $clbk); // TODO: get all filters: $tree->set_param('rozwin', ($tree_filter->get_arg('filtr_drzewo') == 'ROZWIN')); $tree->set_param('rozwin_proces', ($tree_filter->get_arg('filtr_procesy') == 'ROZWIN')); $tree->set_param('rozwin_zasoby', ($tree_filter->get_arg('filtr_zasoby') == 'ROZWIN')); $tree->set_param('rozwin_opis', ($tree_filter->get_arg('filtr_opis') == 'ROZWIN')); $tree->set_param('filtr_sort_prio', ($tree_filter->get_arg('filtr_sort_prio') == 'SHOW')); $tree->set_param('filtr_img', ($tree_filter->get_arg('filtr_img') == 'SHOW')); $tree->set_param('filtr_ob', ($tree_filter->get_arg('filtr_ob') == 'SHOW')); $tree->set_param('filtr_ids', ($tree_filter->get_arg('filtr_ids') == 'SHOW')); $tree->set_param('style', $tree_filter->get_arg('filtr_view')); $tree->set_param('search_id', $tree_filter->get_arg('filtr_search_id')); //TODO: check perm to edit $tree->set_param('editable', ($tree_filter->get_arg('filtr_edit') == 'TAK')); $tree->_limit = 100; $tree->_deep_limit = 10; $open_rec = V::get('open_rec', '', $_REQUEST); if ($open_rec == '1') { $tree->show_rec_all($id); } else { $tree->show_rec($id); } exit; } function ajax_add_image() { //sleep(1);// TODO: TEST $tbl = V::get('tbl', '', $_REQUEST); $id = V::get('id', '', $_REQUEST); //echo $tbl; //fun_IMAGE_ADD(); $remote_table = V::get('tbl', '', $_REQUEST); $remote_id = V::get('id', '', $_REQUEST, 'int'); $task = V::get('task', '', $_REQUEST); $thiss = new stdClass(); $thiss->DETECT_TABLE_NAME = $remote_table; $errors = array(); $msgs = array(); // check remote id if ($remote_id <= 0) { echo'
';
echo "Error wrong ID";
echo'
';
//echo App::link();// TODO: link do ???
echo'
'."Usunieto zdjecie ID=".$req['ID'].'
'; } else { $erros[] = ''."Wystapil blad podczas usuwania zdjecia ID=".$req['ID'].'
'; } } } // check if a file was submitted if (!isset($_FILES['userfile'])) { //echo 'Please select a file
'; } else { $errors = DB_Image::uploadImage($remote_table, $remote_id, $_FILES['userfile']); // give praise and thanks to the php gods if (empty($errors)) { $msgs[] = 'Thank you for submitting
'; } else { $msgs[] = '' . "Sorry, could not upload file:" . '
' . implode('
', $errors) .'
'."Brak obrazkow".'
'; } else { echo'| ';
echo''.$r->NAME.' '; echo''.$r->DEST.' '; echo''.$r->A_CREATE_DATE.' '; echo''.DB_Image::show_size($r->SIZE).' '.$r->WIDTH.'x'.$r->HEIGHT.' '; echo' | ';
echo'
| '; echo''; echo''; echo' | '; echo'
cnf (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cnf);echo''; } if (!empty($cnf)) { $external_ids = array(); foreach ($cnf 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', '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; $sql_where = ""; if ($cur_cnf->search_col_regex) { $sql_where = "`{$cur_cnf->search_col}` like '".str_replace('$ID', $zasob->ID, $cur_cnf->search_col_regex)."'"; } else { $sql_where = "`{$cur_cnf->search_col}`='{$zasob->ID}'"; } $sql = "select t.`ID`, {$sql_id_col} as id_col from `{$k_table_name}` as t where {$sql_where} "; if($DBG){ echo'
sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo''; } $db = DB::getDB(); $res = $db->query($sql); while ($r = $db->fetch($res)) { if ('ID' != $sql_id_col) { $external_ids[] = "{$r->ID}({$r->id_col})"; } else { $external_ids[] = "{$r->id_col}"; } } } } $out_link = ''; if (empty($external_ids)) { $out_link = ''."Brak danych".''; } else { $out_link = implode(', ', $external_ids); } echo ''; echo $out_link; echo " "; echo App::link_ajax("refresh", "ajax_zasob_search_external_ids", array('zasob_id'=>$zasob->ID), array('js_result_type'=>'override_parent', 'js_result'=>'', 'title'=>'refresh IDS', 'ico'=>"refresh.png")); echo ''; // TODO: add link to CRM_EXT_IDS - rysuj strukture } function ajax_zasob_stanowisko_search_kontakty() { header('Content-Type: text/html; charset=utf8'); $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int'); if ($zasob_id <= 0) { echo'Error: Bad request';// TODO: header return; } $DBG = ('123' == V::get('DBG', '', $_REQUEST)); $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id); if (!$zasob) { echo'Error: 404 not found';// TODO: header return; } $external_ids = array(); $mailto_links = array(); $db = DB::getDB(); $sql = "select u.`ID`, u.`ADM_ACCOUNT`, u.`ADM_NAME`, u.`EMAIL` from `CRM_AUTH_PROFILE` as up left join `ADMIN_USERS` as u on (u.`ID`=up.`REMOTE_ID`) where up.`ID_ZASOB`='{$zasob->ID}' and up.`REMOTE_TABLE`='ADMIN_USERS' and up.`A_STATUS` in('WAITING', 'NORMAL') and u.`A_STATUS` in('WAITING', 'NORMAL') group by u.`ID` "; if($DBG){ echo'
sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo''; } $res = $db->query($sql); while ($r = $db->fetch($res)) { $external_ids[] = "{$r->ADM_ACCOUNT}({$r->ADM_NAME})"; if (!empty($r->EMAIL)) { $mailto_links[$r->EMAIL] = true; } } if($DBG){ echo'
external_ids (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($external_ids);echo''; } $out_link = ''; if (empty($external_ids)) { $out_link = ''."Brak danych".''; } else { $out_link = implode(', ', $external_ids); } echo ''; echo $out_link; echo " "; echo App::link_ajax("refresh", "ajax_zasob_stanowisko_search_kontakty", array('zasob_id'=>$zasob->ID), array('js_result_type'=>'override_parent', 'js_result'=>'', 'title'=>'refresh IDS', 'ico'=>"refresh.png")); echo " "; if (!empty($mailto_links)) { $mailto_links = array_keys($mailto_links); echo '
'."Zdjecia dla rekordu {$remote_id} z tabeli {$remote_table}".'
'; foreach ($images as $r) { $src = "?function_init=fun_SHOW_IMAGE&image_id={$r->ID}"; echo'';print_r($db);echo''; } } // conn ok, check if table exists $sql = "show tables like '{$zasob->DESC}' ; "; $res = $db->query($sql); if ($db->num_rows($res) == 1) { echo'TABLE NAME OK;';// TODO: msg OK } else { echo''."Niepoprawna nazwa tabeli {$zasob->DESC}".''; return; } // conn ok, table exists, check table fields $fields = array(); $sql = "describe `{$zasob->DESC}` ; "; $res = $db->query($sql); // Field, Type, Null, Key, Default, Extra // ID, int(10), NO, PRI, NULL, auto_increment // A_RECORD_CREATE_DATE, varchar(30), NO while ($r = $db->fetch($res)) { $params = new stdClass(); // TODO: analyze field parameters: Type,Length,Default,Null? $params->Type = $r->Type; if (substr($r->Type, 0, 3) == 'int') { $params->Type = 'int'; $params->Length = substr(substr($r->Type, 3), 1, -1); } else if (substr($r->Type, 0, 7) == 'varchar') { $params->Type = 'varchar'; $params->Length = substr(substr($r->Type, 7), 1, -1); } else if (substr($r->Type, 0, 4) == 'enum') { $params->Type = 'enum'; $params->Values = substr(substr($r->Type, 4), 1, -1);// TODO: add DANE under KOMORKA } else if (substr($r->Type, 0, 4) == 'date') { $params->Type = 'date'; } else if (substr($r->Type, 0, 4) == 'text') { $params->Type = 'text'; } else { $params->Type = 'unknown'; } // TODO: ... if ($r->Default) $params->Default = $r->Default; else if ($r->Null == 'YES') $params->Default = 'Null'; $fields[$r->Field] = $params; } echo'
fields=';
foreach ($fields as $f_name => $f_params) {
echo"\n".'['.$f_name.']='.json_encode($f_params);
}
echo'';
$komorki = array();
$db = DB::getDB();
$sql = "select
`ID`, `TYPE`, `DESC`
-- TODO: , `PARAMS`
from `CRM_LISTA_ZASOBOW`
where `PARENT_ID`='{$zasob->ID}'
";
$res = $db->query($sql);
// Field, Type, Null, Key, Default, Extra
// ID, int(10), NO, PRI, NULL, auto_increment
// A_RECORD_CREATE_DATE, varchar(30), NO
while ($r = $db->fetch($res)) {
$komorki[$r->DESC] = $r;
}
$errors = array();
foreach ($komorki as $z_name => $z) {
if ($z->TYPE != 'KOMORKA') {
$errors[$z->ID] = "Wrong type ({$z->TYPE},{$z->DESC})";
} else if (!array_key_exists($z->DESC, $fields)) {
$errors[$z->ID] = "Not exists ({$z->DESC})";
} else {
}
}
echo'1 ';print_r($errors);echo''; $errors = array(); foreach ($fields as $f_name => $f_params) { if (!array_key_exists($f_name, $komorki)) { $errors[$f_name] = 'Not exists ('.json_encode($f_params).')'; } else { } } echo'
2 ';print_r($errors);echo''; } function ajax_get_proces() { echo'
TODO: test ajax function L' . __LINE__ . '
'; }