ajax.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <?php
  2. Lib::loadClass('DB_Image');
  3. Lib::loadClass('Http');
  4. if (!class_exists('Lib')) die('404');
  5. function ajax_get_alias_info() {
  6. header('Content-Type: text/html; charset=utf8');//utf8
  7. $idZasob = V::get('idZasob', 0, $_REQUEST, 'int');
  8. if (!$idZasob) die('Wrong param');
  9. $sql = <<<SQL
  10. select z.`ID`
  11. , z.`ALIAS_ID`
  12. , z.`ALIAS_MODE`
  13. , za.`DESC` as `ALIAS_DESC`
  14. , zap.`DESC` as `ALIAS_PARENT_DESC`
  15. , zv.`CHILDS`
  16. , zv.`PATH`
  17. from `CRM_LISTA_ZASOBOW` z
  18. join `CRM_LISTA_ZASOBOW_ALIASY_view` zv on(zv.`ID`=z.`ID`)
  19. left join `CRM_LISTA_ZASOBOW` za on(za.`ID`=z.`ALIAS_ID`)
  20. left join `CRM_LISTA_ZASOBOW` zap on(zap.`ID`=za.`PARENT_ID`)
  21. where z.`ID`='{$idZasob}'
  22. SQL;
  23. $db = DB::getDB();
  24. $res = $db->query($sql);
  25. $info = $db->fetch($res);
  26. if (!$info) {
  27. echo 'Brak danych';
  28. } else {
  29. $outLines = array();
  30. if ($info->ALIAS_ID > 0) {
  31. $js = "return treeAddToFiltr(this, {$info->ALIAS_ID});";
  32. $outAliasedId = '<a href="#" onclick="' . $js . '" title="Dodaj do filtra ' . $info->ALIAS_ID . '">' . $info->ALIAS_ID . '</a>';
  33. $outAliasType = ('VIRTUAL' == $info->ALIAS_MODE)? "ALIAS WIRTUALNY" : "ALIAS";
  34. $outTitle = "{$outAliasType} DO [{$info->ALIAS_ID}] {$info->ALIAS_PARENT_DESC}/{$info->ALIAS_DESC}";
  35. $outLabel = "{$outAliasType} DO [{$outAliasedId}] " . V::strShortUtf8($info->ALIAS_PARENT_DESC, 16, '...') . '/' . V::strShortUtf8($info->ALIAS_DESC, 16, '...');
  36. $outLines[] = '<span title="'.$outTitle.'">'.$outLabel.'</span>';
  37. }
  38. if (!empty($info->PATH)) {
  39. $outLines[] = 'Ścieżka: ' . $info->PATH;
  40. }
  41. if (!empty($info->CHILDS)) {
  42. $outChilds = array();
  43. $childs = explode(',', $info->CHILDS);
  44. foreach($childs as $child) {
  45. $js = "return treeAddToFiltr(this, {$child});";
  46. $outChilds[] = '<a href="#" onclick="' . $js . '">' . $child . '</a>';
  47. }
  48. $outLines[] = 'Aliasy: ' . implode(', ', $outChilds);
  49. }
  50. }
  51. if (empty($outLines)) {
  52. echo 'Brak danych';//Http::sendHeaderByCode(404);
  53. } else {
  54. echo implode('<br>', $outLines) . '<br/>';
  55. }
  56. exit;
  57. }
  58. function ajax_get_subtree() {
  59. header('Content-Type: text/html; charset=utf8');//utf8
  60. $id = V::get('id', '', $_GET);
  61. $tbl = V::get('tbl', '', $_GET);
  62. Lib::loadClass('FilterFactory');
  63. $tree_filter = FilterFactory::build($tbl);
  64. $tree_filter->setArgs($_GET);
  65. $clbk = 'tree_callback__show_item_from_'.$tbl;
  66. if (!function_exists($clbk)) {
  67. $clbk = null;
  68. }
  69. $tree = new Tree($tbl);
  70. if ($clbk) $tree->set_param('show_item_callback', $clbk);
  71. // TODO: get all filters:
  72. $tree->set_param('rozwin', ($tree_filter->get_arg('filtr_drzewo') == 'ROZWIN'));
  73. $tree->set_param('rozwin_proces', ($tree_filter->get_arg('filtr_procesy') == 'ROZWIN'));
  74. $tree->set_param('rozwin_zasoby', ($tree_filter->get_arg('filtr_zasoby') == 'ROZWIN'));
  75. $tree->set_param('rozwin_opis', ($tree_filter->get_arg('filtr_opis') == 'ROZWIN'));
  76. $tree->set_param('filtr_sort_prio', ($tree_filter->get_arg('filtr_sort_prio') == 'SHOW'));
  77. $tree->set_param('filtr_img', ($tree_filter->get_arg('filtr_img') == 'SHOW'));
  78. $tree->set_param('filtr_ob', ($tree_filter->get_arg('filtr_ob') == 'SHOW'));
  79. $tree->set_param('filtr_ids', ($tree_filter->get_arg('filtr_ids') == 'SHOW'));
  80. $tree->set_param('style', $tree_filter->get_arg('filtr_view'));
  81. $tree->set_param('search_id', $tree_filter->get_arg('filtr_search_id'));
  82. //TODO: check perm to edit
  83. $tree->set_param('editable', ($tree_filter->get_arg('filtr_edit') == 'TAK'));
  84. $tree->_limit = 100;
  85. $tree->_deep_limit = 10;
  86. $open_rec = V::get('open_rec', '', $_REQUEST);
  87. if ($open_rec == '1') {
  88. $tree->show_rec_all($id);
  89. } else {
  90. $tree->show_rec($id);
  91. }
  92. exit;
  93. }
  94. function ajax_add_image() {
  95. //sleep(1);// TODO: TEST
  96. $tbl = V::get('tbl', '', $_REQUEST);
  97. $id = V::get('id', '', $_REQUEST);
  98. //echo $tbl;
  99. //fun_IMAGE_ADD();
  100. $remote_table = V::get('tbl', '', $_REQUEST);
  101. $remote_id = V::get('id', '', $_REQUEST, 'int');
  102. $task = V::get('task', '', $_REQUEST);
  103. $thiss = new stdClass();
  104. $thiss->DETECT_TABLE_NAME = $remote_table;
  105. $errors = array();
  106. $msgs = array();
  107. // check remote id
  108. if ($remote_id <= 0) {
  109. echo'<p>';
  110. echo "Error wrong ID";
  111. echo'<br />';
  112. //echo App::link();// TODO: link do ???
  113. echo'</p>';
  114. return;
  115. }
  116. // check remote table
  117. if (!DB_Image::tableIsAllowed($remote_table)) {
  118. $errors[] = "Error table not allowed to add image";
  119. }
  120. // task
  121. $task = V::get('task', '', $_REQUEST);
  122. if ($task == 'REMOVE') {// TODO: przerobic na funkcje, zwrocic msg, pokazac w body
  123. $req = array();
  124. $req['ID'] = V::get('ID', '', $_REQUEST, 'int');
  125. $req['REMOTE_ID'] = V::get('REMOTE_ID', '', $_REQUEST, 'int');
  126. $req['REMOTE_TABLE'] = V::get('REMOTE_TABLE', '', $_REQUEST);
  127. // validate
  128. if ($req['ID'] <= 0) {
  129. $errors[] = 'error ID';
  130. }
  131. if ($req['REMOTE_ID'] <= 0) {
  132. $errors[] = 'error REMOTE_ID';
  133. }
  134. if ($req['REMOTE_TABLE'] != $remote_table) {
  135. $errors[] = 'error REMOTE_TABLE';
  136. }
  137. if (empty($errors)) {
  138. $affected = DB_Image::deleteImage($req['ID'], $req['REMOTE_TABLE'], $req['REMOTE_ID']);
  139. if ($affected == 1) {
  140. $msgs[] = '<p>'."Usunieto zdjecie ID=".$req['ID'].'</p>';
  141. } else {
  142. $erros[] = '<p>'."Wystapil blad podczas usuwania zdjecia ID=".$req['ID'].'</p>';
  143. }
  144. }
  145. }
  146. // check if a file was submitted
  147. if (!isset($_FILES['userfile'])) {
  148. //echo '<p>Please select a file</p>';
  149. }
  150. else {
  151. $errors = DB_Image::uploadImage($remote_table, $remote_id, $_FILES['userfile']);
  152. // give praise and thanks to the php gods
  153. if (empty($errors)) {
  154. $msgs[] = '<p>Thank you for submitting</p>';
  155. } else {
  156. $msgs[] = '<p style="border:1px solid red;">' . "Sorry, could not upload file:" . '<br />' . implode('<br />', $errors) .'</p>';
  157. }
  158. }
  159. $title = 'Dodaj plik do rekordu ID='.$remote_id.' z tabeli '.$remote_table;
  160. echo'<h3>'.$title.'</h3>';
  161. // show masgs
  162. if (!empty($msgs)) {
  163. echo'<div class="box box-green">';
  164. echo implode('<br />', $msgs);
  165. echo'</div>';
  166. }
  167. // show errors
  168. if (!empty($errors)) {
  169. echo'<div class="box box-red">';
  170. echo implode('<br />', $errors);
  171. echo'</div>';
  172. return;
  173. }
  174. echo'<div class="box box-silver">';
  175. $js = "ajax_form(this, 'id', 'tip-popup-box');";
  176. $js = ' onsubmit="'.$js.'"';
  177. echo'<form enctype="multipart/form-data" action="" method="post"'.$js.'>';
  178. echo'<input type="hidden" name="function_init" value="'. __FUNCTION__ .'" />';
  179. echo'<input type="hidden" name="REMOTE_ID" value="'.$remote_id.'" />';
  180. echo'<input type="hidden" name="REMOTE_TABLE" value="'.$remote_table.'" />';
  181. //echo'<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />';
  182. echo"Rodzaj obrazka: ";
  183. echo'<input type="text" name="'."DEST".'" value="'."".'" />';
  184. $select_arr = array();
  185. $select_arr = DB_Image::conf_get_options($thiss->DETECT_TABLE_NAME);
  186. if (!empty($select_arr)) {
  187. echo' ';
  188. $js = "if(this.selectedIndex>0){this.form.DEST.value=this.value}";
  189. echo'<select onchange="'.$js.'">';
  190. echo'<option value="">'."Wybierz".'</option>';
  191. foreach ($select_arr as $key => $val) {
  192. echo'<option value="'.$key.'">'.$val.'</option>';
  193. }
  194. echo'</select>';
  195. }
  196. echo'<br />';
  197. echo'<input name="userfile" type="file" />';
  198. echo'<br />';
  199. echo'<input type="submit" value="'."Dodaj obrazek".'" />';
  200. echo'</form>';
  201. echo'</div>';// .box-silver
  202. // TODO: show images, mv to function {
  203. $images = DB_Image::getImages($thiss->DETECT_TABLE_NAME, $remote_id);
  204. if (empty($images)) {
  205. echo'<p class="err">'."Brak obrazkow".'</p>';
  206. } else {
  207. echo'<h3>'."Wgrane pliki:".'</h3>';
  208. foreach ($images as $r) {
  209. $link_src = '?function_init=fun_SHOW_IMAGE&image_id='.$r->ID.'&HEADER_NOT_INIT=YES';
  210. $st = array();
  211. if ($r->WIDTH > 100 || $r->HEIGHT > 100) {
  212. if ($r->WIDTH > $r->HEIGHT) {
  213. $st[] = 'width:100px';
  214. } else {
  215. $st[] = 'height:100px';
  216. }
  217. }
  218. $st = (empty($st))? '' : ' style="'.implode(';', $st).'"';
  219. echo'<table style="float:left;border:1px solid silver;">';
  220. echo'<tr>';
  221. echo'<td>';
  222. echo''.$r->NAME.'<br />';
  223. echo''.$r->DEST.'<br />';
  224. echo''.$r->A_CREATE_DATE.'<br />';
  225. echo''.DB_Image::show_size($r->SIZE).' '.$r->WIDTH.'x'.$r->HEIGHT.'<br />';
  226. echo'<img src="'.$link_src.'" '.$st.'/>';
  227. echo'</td>';
  228. echo'</tr>';
  229. echo'<tr>';
  230. echo'<td style="text-align:center;">';
  231. echo'<form action="" method="post" style="display:inline">';
  232. echo'<input type="hidden" name="task" value="'."REMOVE".'" />';
  233. echo'<input type="hidden" name="ID" value="'.$r->ID.'" />';
  234. echo'<input type="hidden" name="REMOTE_ID" value="'.$remote_id.'" />';
  235. echo'<input type="hidden" name="REMOTE_TABLE" value="'.$remote_table.'" />';
  236. $js = "if(!confirm('Czy na pewno chcesz usunac obrazek?')) return false;";
  237. echo'<input type="submit" value="Usun" onclick="'.$js.'" />';
  238. echo'</form>';
  239. echo'<form action="" method="post" style="display:inline">';
  240. echo'<input type="hidden" name="task" value="'."EDIT".'" />';
  241. echo'<input type="hidden" name="ID" value="'.$r->ID.'" />';
  242. echo'<input type="hidden" name="REMOTE_ID" value="'.$remote_id.'" />';
  243. echo'<input type="hidden" name="REMOTE_TABLE" value="'.$remote_table.'" />';
  244. echo'<input type="submit" value="Edytuj" />';
  245. echo'</form>';
  246. echo'</td>';
  247. echo'</tr>';
  248. echo'</table>';
  249. }
  250. }
  251. // } function show images
  252. }
  253. function ajax_zasob_search_external_ids() {
  254. header('Content-Type: text/html; charset=utf8');
  255. $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int');
  256. if ($zasob_id <= 0) {
  257. echo'Error: Bad request';// TODO: header
  258. return;
  259. }
  260. $DBG = ('123' == V::get('DBG', '', $_REQUEST));
  261. $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id);
  262. if (!$zasob) {
  263. echo'Error: 404 not found';// TODO: header
  264. return;
  265. }
  266. $cnf = Config::getConfFile('external_ids');
  267. if (!$cnf) {
  268. echo'Config error (external_ids)';
  269. return;
  270. }
  271. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">cnf (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cnf);echo'</pre>'; }
  272. if (!empty($cnf)) {
  273. $external_ids = array();
  274. foreach ($cnf as $k_table_name => $v_cnf) {
  275. $cur_cnf = new stdClass();
  276. $cur_cnf->id_col = V::get('id_col', 'ID', $v_cnf);
  277. $cur_cnf->search_col = V::get('search_col', 'CRM_LISTA_ZASOBOW_ID', $v_cnf);
  278. $cur_cnf->search_col_regex = V::get('search_col_regex', '', $v_cnf);
  279. $sql_id_col = $cur_cnf->id_col;
  280. $sql_where = "";
  281. if ($cur_cnf->search_col_regex) {
  282. $sql_where = "`{$cur_cnf->search_col}` like '".str_replace('$ID', $zasob->ID, $cur_cnf->search_col_regex)."'";
  283. } else {
  284. $sql_where = "`{$cur_cnf->search_col}`='{$zasob->ID}'";
  285. }
  286. $sql = "select t.`ID`, {$sql_id_col} as id_col
  287. from `{$k_table_name}` as t
  288. where {$sql_where}
  289. ";
  290. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>'; }
  291. $db = DB::getDB();
  292. $res = $db->query($sql);
  293. while ($r = $db->fetch($res)) {
  294. if ('ID' != $sql_id_col) {
  295. $external_ids[] = "{$r->ID}({$r->id_col})";
  296. } else {
  297. $external_ids[] = "{$r->id_col}";
  298. }
  299. }
  300. }
  301. }
  302. $out_link = '';
  303. if (empty($external_ids)) {
  304. $out_link = '<span class="not-found">'."Brak danych".'</span>';
  305. } else {
  306. $out_link = implode(', ', $external_ids);
  307. }
  308. echo '<span>';
  309. echo $out_link;
  310. echo " ";
  311. if(strstr("'NARZEDZIE','PLIK','ZASOB_PLIKOW','SOFTWARE','APLIKACJA','SERWER','SERWER_PORT','DOKUMENTY','SEGREGATOR','SKOROSZYT','KUWETA','KUWETA_MAGAZYNOWA','MATERIAL_REKLAMOWY','RESOURCE_CONSUMABLE','MATERIAL_EKSPLOATACYJNY','ALARM-SATEL','ALARM-CZYTNIK-KART','ALARM-KLAWIATURA','DOSTEP-ZAMEK','DOSTEP-KLUCZ','DOSTEP-ZAMEK-ELEKTRONICZNY','DOSTEP-ZAMEK-GRUPA','DOSTEP-ZAMEK-GRUPA-GHZ','DOSTEP-ZAMEK-GRUPA-GS','DOSTEP-ZAMEK-GRUPA-ES','DOSTEP-KARTA','NOTATKA','URZADZENIE','KOMPUTER','WYPOSAZENIE_LOKALU','SZAFA','POLKA','REJESTRATOR','KAMERA','PIECZATKA','PASSWORD','URZADZENIA_I_OZNACZENIA_BHP','OZNACZENIE_LOKALIZACJI','DOSTEP-UPRAWNIENIA'", $zasob->TYPE)
  312. ) {
  313. echo App::link("dodaj", "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=".ProcesHelper::getZasobTableID('DEVICES')."&ff_A_STATUS=WAITING&ff_T_DEVICE_SERIAL=".date('Y-m-d')."-".$zasob->ID."&ff_T_DEVICE_INFO=".urlencode($zasob->OPIS)."&ff_T_DEVICE_TYPE=".urlencode($zasob->DESC)."&ff_CRM_LISTA_ZASOBOW_ID=".$zasob->ID."#CREATE", array('class'=>'btn-p5', 'title'=>'Dodaj zapotrzebowanie', 'onclick'=>null));
  314. echo App::link("szukaj", "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=".ProcesHelper::getZasobTableID('DEVICES')."&ff_CRM_LISTA_ZASOBOW_ID=".$zasob->ID, array('class'=>'btn-p5', 'title'=>'szukaj', 'onclick'=>null));
  315. }
  316. 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"));
  317. echo '</span>';
  318. // TODO: add link to CRM_EXT_IDS - rysuj strukture
  319. }
  320. function ajax_zasob_stanowisko_search_kontakty() {
  321. header('Content-Type: text/html; charset=utf8');
  322. $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int');
  323. if ($zasob_id <= 0) {
  324. echo'Error: Bad request';// TODO: header
  325. return;
  326. }
  327. $DBG = ('123' == V::get('DBG', '', $_REQUEST));
  328. $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id);
  329. if (!$zasob) {
  330. echo'Error: 404 not found';// TODO: header
  331. return;
  332. }
  333. $external_ids = array();
  334. $mailto_links = array();
  335. $db = DB::getDB();
  336. $sql = "select u.`ID`, u.`ADM_ACCOUNT`, u.`ADM_NAME`, u.`EMAIL`
  337. from `CRM_AUTH_PROFILE` as up
  338. left join `ADMIN_USERS` as u on (u.`ID`=up.`REMOTE_ID`)
  339. where
  340. up.`ID_ZASOB`='{$zasob->ID}'
  341. and up.`REMOTE_TABLE`='ADMIN_USERS'
  342. and up.`A_STATUS` in('WAITING', 'NORMAL')
  343. and u.`A_STATUS` in('WAITING', 'NORMAL')
  344. group by u.`ID`
  345. ";
  346. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>'; }
  347. $res = $db->query($sql);
  348. while ($r = $db->fetch($res)) {
  349. $external_ids[] = "{$r->ADM_ACCOUNT}({$r->ADM_NAME})";
  350. if (!empty($r->EMAIL)) {
  351. $mailto_links[$r->EMAIL] = true;
  352. }
  353. }
  354. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">external_ids (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($external_ids);echo'</pre>'; }
  355. $out_link = '';
  356. if (empty($external_ids)) {
  357. $out_link = '<span class="not-found">'."Brak danych".'</span>';
  358. } else {
  359. $out_link = implode(', ', $external_ids);
  360. }
  361. echo '<span>';
  362. echo $out_link;
  363. echo " ";
  364. 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"));
  365. echo " ";
  366. if (!empty($mailto_links)) {
  367. $mailto_links = array_keys($mailto_links);
  368. echo '<a href="' . "mailto:" . implode(', ', $mailto_links) . '"><img src="icon/mail_all.png" height="16" alt=" mail " /></a>';
  369. echo " ";
  370. }
  371. echo App::link(" więcej &raquo; ", array('task'=>"USERS", '_group'=>$zasob_id), array('target'=>"_blank"));
  372. echo '</span>';
  373. // TODO: add link to CRM_EXT_IDS - rysuj strukture
  374. }
  375. function ajax_zasob_get_obowiazki() {
  376. $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int');
  377. if ($zasob_id <= 0) {
  378. echo'Error: Bad request';// TODO: header
  379. return;
  380. }
  381. $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id);
  382. if (!$zasob) {
  383. echo'Error: 404 not found';// TODO: header
  384. return;
  385. }
  386. $external_ids = array();
  387. $db = DB::getDB();
  388. $sql = "select t.`ID_PROCES` as ext_id
  389. from `CRM_WSKAZNIK` as t
  390. join `CRM_PROCES` as p on(p.`ID`=t.`ID_PROCES`)
  391. where
  392. t.`ID_ZASOB`='{$zasob->ID}'
  393. and t.`A_STATUS` in('WAITING','NORMAL')
  394. and p.`A_STATUS` in('WAITING','NORMAL')
  395. ";
  396. $res = $db->query($sql);
  397. while ($r = $db->fetch($res)) {
  398. $external_ids[] = $r->ext_id;
  399. }
  400. $out_link_ids_limit = 5;
  401. $out_link = '';
  402. $out_link_add = '';
  403. if (empty($external_ids)) {
  404. $out_link = '<span class="not-found">'."Brak danych".'</span>';
  405. } else {
  406. $cnt = count($external_ids);
  407. if ($cnt > $out_link_ids_limit) {
  408. $external_ids_tmp = array();
  409. for ($i = 0; $i < $out_link_ids_limit; $i++) {
  410. $external_ids_tmp[] = $external_ids[$i];
  411. }
  412. $out_link_add .= implode(' ', $external_ids_tmp);
  413. $out_link_add .= ' ... ';
  414. $out_link_add .= App::link("({$cnt})", "?task=CRM_WYSWIETL_OBOWIAZKI&CLZ_ID={$zasob->ID}", array('target'=>'_blank', 'title'=>'Procesy powiazane z tym zasobem'));
  415. } else {
  416. $out_link_add .= implode(' ', $external_ids);
  417. $out_link_add .= ' ';
  418. $out_link_add .= App::link("(OB)", "?task=CRM_WYSWIETL_OBOWIAZKI&CLZ_ID={$zasob->ID}", array('target'=>'_blank', 'title'=>'Procesy powiazane z tym zasobem'));
  419. }
  420. }
  421. if ($out_link) {
  422. 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'));
  423. }
  424. if ($out_link_add) {
  425. echo $out_link_add;
  426. }
  427. }
  428. function ajax_show_images() {
  429. $remote_table = V::get('tbl', '', $_REQUEST);
  430. $remote_id = V::get('id', '', $_REQUEST, 'int');
  431. $thiss = new stdClass();
  432. $thiss->DETECT_TABLE_NAME = $remote_table;
  433. // check remote id
  434. if ($remote_id <= 0) {
  435. header('HTTP/1.1 400: Bad Request');
  436. header('Warning: wrong ID L.' . __LINE__);
  437. exit;
  438. }
  439. // check remote table
  440. $remote_tables = DB_Image::conf_get('remote_tables');
  441. if (!in_array($remote_table, $remote_tables)) {
  442. header('HTTP/1.1 400: Bad Request');
  443. header('Warning: table not allowed L.' . __LINE__);
  444. exit;
  445. }
  446. $images = DB_Image::getImages($remote_table, $remote_id);
  447. if (!$images) {
  448. header('HTTP/1.1 400: Bad Request');
  449. header('Warning: images not found in db L.' . __LINE__);
  450. exit;
  451. }
  452. echo'<p>'."Zdjecia dla rekordu <b>{$remote_id}</b> z tabeli {$remote_table}".'</p>';
  453. foreach ($images as $r) {
  454. $src = "?function_init=fun_SHOW_IMAGE&image_id={$r->ID}";
  455. echo'<img src="'.$src.'" alt="'.$r->TYPE.'" />';
  456. }
  457. exit;
  458. }
  459. function ajax_zasob_check_table() {
  460. $zasob_id = V::get('zasob_id', '', $_REQUEST, 'int');
  461. if ($zasob_id <= 0) {
  462. echo'Error: Bad request';// TODO: header
  463. return;
  464. }
  465. $zasob = DB::get_by_id('CRM_LISTA_ZASOBOW', $zasob_id);
  466. if (!$zasob) {
  467. echo'Error: 404 not found';// TODO: header
  468. return;
  469. }
  470. // TODO: get config from parent DATABASE%
  471. $cnf_id = $zasob->PARENT_ID;
  472. //$ext_db = DB::getDB( $r->PARENT_ID );
  473. $cnf = Config::getZasobConf($cnf_id);
  474. if (!$cnf) {
  475. echo'<span class="err">'."Brak konfiguracji dla zasobu <b>{$cnf_id}</b>".'</span>';
  476. return;
  477. } else {
  478. $db = DB::getDB($cnf_id);
  479. if ($db->get_errors()) {
  480. echo'<span class="err">'."Wystapily bledy podczas polaczenia z baza danych (zasob {$cnf_id}):";
  481. echo '<br />'.implode('<br />', $db->get_errors());
  482. echo'</span>';
  483. return;
  484. } else {
  485. //$db;
  486. echo'CONN OK;';// TODO: msg OK
  487. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">';print_r($db);echo'</pre>';
  488. }
  489. }
  490. // conn ok, check if table exists
  491. $sql = "show tables like '{$zasob->DESC}' ; ";
  492. $res = $db->query($sql);
  493. if ($db->num_rows($res) == 1) {
  494. echo'TABLE NAME OK;';// TODO: msg OK
  495. } else {
  496. echo'<span class="err">'."Niepoprawna nazwa tabeli <b>{$zasob->DESC}</b>".'</span>';
  497. return;
  498. }
  499. // conn ok, table exists, check table fields
  500. $fields = array();
  501. $sql = "describe `{$zasob->DESC}` ; ";
  502. $res = $db->query($sql);
  503. // Field, Type, Null, Key, Default, Extra
  504. // ID, int(10), NO, PRI, NULL, auto_increment
  505. // A_RECORD_CREATE_DATE, varchar(30), NO
  506. while ($r = $db->fetch($res)) {
  507. $params = new stdClass();
  508. // TODO: analyze field parameters: Type,Length,Default,Null?
  509. $params->Type = $r->Type;
  510. if (substr($r->Type, 0, 3) == 'int') {
  511. $params->Type = 'int';
  512. $params->Length = substr(substr($r->Type, 3), 1, -1);
  513. } else if (substr($r->Type, 0, 7) == 'varchar') {
  514. $params->Type = 'varchar';
  515. $params->Length = substr(substr($r->Type, 7), 1, -1);
  516. } else if (substr($r->Type, 0, 4) == 'enum') {
  517. $params->Type = 'enum';
  518. $params->Values = substr(substr($r->Type, 4), 1, -1);// TODO: add DANE under KOMORKA
  519. } else if (substr($r->Type, 0, 4) == 'date') {
  520. $params->Type = 'date';
  521. } else if (substr($r->Type, 0, 4) == 'text') {
  522. $params->Type = 'text';
  523. } else {
  524. $params->Type = 'unknown';
  525. }
  526. // TODO: ...
  527. if ($r->Default) $params->Default = $r->Default;
  528. else if ($r->Null == 'YES') $params->Default = 'Null';
  529. $fields[$r->Field] = $params;
  530. }
  531. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">fields=';
  532. foreach ($fields as $f_name => $f_params) {
  533. echo"\n".'['.$f_name.']='.json_encode($f_params);
  534. }
  535. echo'</pre>';
  536. $komorki = array();
  537. $db = DB::getDB();
  538. $sql = "select
  539. `ID`, `TYPE`, `DESC`
  540. -- TODO: , `PARAMS`
  541. from `CRM_LISTA_ZASOBOW`
  542. where `PARENT_ID`='{$zasob->ID}'
  543. ";
  544. $res = $db->query($sql);
  545. // Field, Type, Null, Key, Default, Extra
  546. // ID, int(10), NO, PRI, NULL, auto_increment
  547. // A_RECORD_CREATE_DATE, varchar(30), NO
  548. while ($r = $db->fetch($res)) {
  549. $komorki[$r->DESC] = $r;
  550. }
  551. $errors = array();
  552. foreach ($komorki as $z_name => $z) {
  553. if ($z->TYPE != 'KOMORKA') {
  554. $errors[$z->ID] = "Wrong type ({$z->TYPE},{$z->DESC})";
  555. } else if (!array_key_exists($z->DESC, $fields)) {
  556. $errors[$z->ID] = "Not exists ({$z->DESC})";
  557. } else {
  558. }
  559. }
  560. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">1 ';print_r($errors);echo'</pre>';
  561. $errors = array();
  562. foreach ($fields as $f_name => $f_params) {
  563. if (!array_key_exists($f_name, $komorki)) {
  564. $errors[$f_name] = 'Not exists ('.json_encode($f_params).')';
  565. } else {
  566. }
  567. }
  568. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">2 ';print_r($errors);echo'</pre>';
  569. }
  570. function ajax_get_proces() {
  571. echo'<p>TODO: test ajax function L' . __LINE__ . '</p>';
  572. }