ajax.php 18 KB

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