ajax.php 18 KB

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