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'

'; return; } // check remote table if (!DB_Image::tableIsAllowed($remote_table)) { $errors[] = "Error table not allowed to add image"; } // task $task = V::get('task', '', $_REQUEST); if ($task == 'REMOVE') {// TODO: przerobic na funkcje, zwrocic msg, pokazac w body $req = array(); $req['ID'] = V::get('ID', '', $_REQUEST, 'int'); $req['REMOTE_ID'] = V::get('REMOTE_ID', '', $_REQUEST, 'int'); $req['REMOTE_TABLE'] = V::get('REMOTE_TABLE', '', $_REQUEST); // validate if ($req['ID'] <= 0) { $errors[] = 'error ID'; } if ($req['REMOTE_ID'] <= 0) { $errors[] = 'error REMOTE_ID'; } if ($req['REMOTE_TABLE'] != $remote_table) { $errors[] = 'error REMOTE_TABLE'; } if (empty($errors)) { $affected = DB_Image::deleteImage($req['ID'], $req['REMOTE_TABLE'], $req['REMOTE_ID']); if ($affected == 1) { $msgs[] = '

'."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) .'

'; } } $title = 'Dodaj plik do rekordu ID='.$remote_id.' z tabeli '.$remote_table; echo'

'.$title.'

'; // show masgs if (!empty($msgs)) { echo'
'; echo implode('
', $msgs); echo'
'; } // show errors if (!empty($errors)) { echo'
'; echo implode('
', $errors); echo'
'; return; } echo'
'; $js = "ajax_form(this, 'id', 'tip-popup-box');"; $js = ' onsubmit="'.$js.'"'; echo'
'; echo''; echo''; echo''; //echo''; echo"Rodzaj obrazka: "; echo''; $select_arr = array(); $select_arr = DB_Image::conf_get_options($thiss->DETECT_TABLE_NAME); if (!empty($select_arr)) { echo' '; $js = "if(this.selectedIndex>0){this.form.DEST.value=this.value}"; echo''; } echo'
'; echo''; echo'
'; echo''; echo'
'; echo'
';// .box-silver // TODO: show images, mv to function { $images = DB_Image::getImages($thiss->DETECT_TABLE_NAME, $remote_id); if (empty($images)) { echo'

'."Brak obrazkow".'

'; } else { echo'

'."Wgrane pliki:".'

'; foreach ($images as $r) { $link_src = '?function_init=fun_SHOW_IMAGE&image_id='.$r->ID.'&HEADER_NOT_INIT=YES'; $st = array(); if ($r->WIDTH > 100 || $r->HEIGHT > 100) { if ($r->WIDTH > $r->HEIGHT) { $st[] = 'width:100px'; } else { $st[] = 'height:100px'; } } $st = (empty($st))? '' : ' style="'.implode(';', $st).'"'; echo''; echo''; echo''; echo''; echo''; echo''; echo''; 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''; echo''; $js = "if(!confirm('Czy na pewno chcesz usunac obrazek?')) return false;"; echo''; echo'
'; echo'
'; echo''; echo''; echo''; echo''; echo''; echo'
'; echo'
'; } } // } function show images } function ajax_zasob_search_external_ids() { 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; } $cnf = Config::getConfFile('external_ids'); if (!$cnf) { echo'Config error (external_ids)'; return; } if($DBG){ 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 ' mail '; echo " "; } echo App::link(" wiÄ™cej » ", array('task'=>"USERS", '_group'=>$zasob_id), array('target'=>"_blank")); echo ''; // TODO: add link to CRM_EXT_IDS - rysuj strukture } function ajax_zasob_get_obowiazki() { $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int'); if ($zasob_id <= 0) { echo'Error: Bad request';// TODO: header return; } $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id); if (!$zasob) { echo'Error: 404 not found';// TODO: header return; } $external_ids = array(); $db = DB::getDB(); $sql = "select t.`ID_PROCES` as ext_id from `CRM_WSKAZNIK` as t join `CRM_PROCES` as p on(p.`ID`=t.`ID_PROCES`) where t.`ID_ZASOB`='{$zasob->ID}' and t.`A_STATUS` in('WAITING','NORMAL') and p.`A_STATUS` in('WAITING','NORMAL') "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $external_ids[] = $r->ext_id; } $out_link_ids_limit = 5; $out_link = ''; $out_link_add = ''; if (empty($external_ids)) { $out_link = ''."Brak danych".''; } else { $cnt = count($external_ids); if ($cnt > $out_link_ids_limit) { $external_ids_tmp = array(); for ($i = 0; $i < $out_link_ids_limit; $i++) { $external_ids_tmp[] = $external_ids[$i]; } $out_link_add .= implode(' ', $external_ids_tmp); $out_link_add .= ' ... '; $out_link_add .= App::link("({$cnt})", "?task=CRM_WYSWIETL_OBOWIAZKI&CLZ_ID={$zasob->ID}", array('target'=>'_blank', 'title'=>'Procesy powiazane z tym zasobem')); } else { $out_link_add .= implode(' ', $external_ids); $out_link_add .= ' '; $out_link_add .= App::link("(OB)", "?task=CRM_WYSWIETL_OBOWIAZKI&CLZ_ID={$zasob->ID}", array('target'=>'_blank', 'title'=>'Procesy powiazane z tym zasobem')); } } if ($out_link) { echo App::link_ajax($out_link, "ajax_zasob_get_obowiazki", array('zasob_id'=>$zasob->ID), array('js_result_type'=>'override', 'js_result'=>'', 'title'=>'refresh OB')); } if ($out_link_add) { echo $out_link_add; } } function ajax_show_images() { $remote_table = V::get('tbl', '', $_REQUEST); $remote_id = V::get('id', '', $_REQUEST, 'int'); $thiss = new stdClass(); $thiss->DETECT_TABLE_NAME = $remote_table; // check remote id if ($remote_id <= 0) { header('HTTP/1.1 400: Bad Request'); header('Warning: wrong ID L.' . __LINE__); exit; } // check remote table $remote_tables = DB_Image::conf_get('remote_tables'); if (!in_array($remote_table, $remote_tables)) { header('HTTP/1.1 400: Bad Request'); header('Warning: table not allowed L.' . __LINE__); exit; } $images = DB_Image::getImages($remote_table, $remote_id); if (!$images) { header('HTTP/1.1 400: Bad Request'); header('Warning: images not found in db L.' . __LINE__); exit; } 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''.$r->TYPE.''; } exit; } function ajax_zasob_check_table() { $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int'); if ($zasob_id <= 0) { echo'Error: Bad request';// TODO: header return; } $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id); if (!$zasob) { echo'Error: 404 not found';// TODO: header return; } // TODO: get config from parent DATABASE% $cnf_id = $zasob->PARENT_ID; //$ext_db = DB::getDB( $r->PARENT_ID ); $cnf = Config::getZasobConf($cnf_id); if (!$cnf) { echo''."Brak konfiguracji dla zasobu {$cnf_id}".''; return; } else { $db = DB::getDB($cnf_id); if ($db->get_errors()) { echo''."Wystapily bledy podczas polaczenia z baza danych (zasob {$cnf_id}):"; echo '
'.implode('
', $db->get_errors()); echo'
'; return; } else { //$db; echo'CONN OK;';// TODO: msg OK //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__ . '

'; }