ajax.php 22 KB

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