ajax.php 18 KB

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