superedit-SYNC_GIS_TABLES.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. <?php
  2. //
  3. // synchronizacja do serwera postgres GIS
  4. //
  5. die('@2016-08-08 bindera: wylaczam mozliwosc synchronizacji - tabele do przepisania, przyda sie historycznie ten kod aby spojrzec na relacje przestrzenne w praktyce');
  6. include_once('se-lib/DB_Dump.php');
  7. include_once('se-lib/UsersHelper.php');
  8. function SYNC_GIS_TABLES() {
  9. global $db,$gdb;
  10. $mysql_zas_id=36;
  11. $gis_zas_id=13102;
  12. $loc_sync_table="_sync_to_gis_36_to_13102";
  13. $sql_cr="";
  14. $db = DB::getDB();
  15. $gdb= DB::getDB($gis_zas_id);
  16. DEBUG_S(-3,'db',$db);
  17. DEBUG_S(-3,'gis',$gdb);
  18. $tbls_to_sync[]='BUILDINGS';
  19. //$tbls_to_sync[]='MK_Budynki';
  20. $rem_field_timestamp='TIMESTAMP';
  21. //nadanie uprawnien do tabeli GIS
  22. //="dodanie wszystkich mozliwych zasobow jako role-stanowiska";
  23. function add_pg_roles() {
  24. global $db,$gdb;
  25. $groups=UsersHelper::get_group_list();
  26. DEBUG_S(-3,'Lista group ',$groups,__FILE__,__FUNCTION__,__LINE__);
  27. foreach($groups as $idg=>$val) {
  28. $sql="drop role if exists \"".$idg."\"";
  29. echo "<br> dodaje role: ".$sql;
  30. $gdb->query($sql);
  31. $sql="create role \"".$idg."\"";
  32. echo "<br> dodaje role: ".$sql;
  33. $gdb->query($sql);
  34. }
  35. }
  36. echo "<br> aktualziacja relacji obiektow do paszportyzacji optycznej";
  37. function gis_opto_intersect($table_to_set,$field_index,$field_to_set,$table_from,$field_from,$filter_table_from='') {
  38. global $gdb;
  39. $sql='drop table if exists gis_opto_relations;
  40. -- gis_opto_intersect
  41. select t1."'.$field_index.'" as "field_index", t2."'.$field_from.'" as "field_from"
  42. , 1
  43. as if_true , t2.*
  44. into temporary table gis_opto_relations
  45. FROM "'.$table_to_set.'" as t1
  46. INNER JOIN "'.$table_from.'" as t2 ON ST_Intersects(t1.the_geom, t2.the_geom) '.$filter_table_from.' ;
  47. CREATE INDEX myfield ON gis_opto_relations ("field_from");
  48. update "'.$table_to_set.'" t1
  49. set "'.$field_to_set.'"=t2.field_from
  50. from gis_opto_relations t2
  51. where t1."'.$field_index.'"=t2.field_index and t2.if_true=1
  52. '.$filter_sql.'
  53. ;
  54. drop table gis_opto_relations;';
  55. DEBUG_S(-3,"Zapytanie sql aktualizujace ".$table_to_set,$sql,__FILE__,__FUNCTION__,__LINE__);
  56. $gdb->query($sql);
  57. }
  58. function gis_opto_relations($table_to_set,$field_index,$field_to_set,$table_from,$field_from,$ST_Relate='******F**',$filter_sql='',$filter_table_from=' on 1=1 ') {
  59. global $gdb;
  60. $sql='
  61. -- gis_opto_relations
  62. drop table if exists gis_opto_relations;
  63. select t1."'.$field_index.'" as "field_index", t2."'.$field_from.'" as "field_from"
  64. , case ST_Relate(t1."the_geom",t2."the_geom",\''.$ST_Relate.'\') when true then
  65. 1
  66. else 0 end
  67. as if_true , t2.*
  68. into temporary table gis_opto_relations
  69. FROM "'.$table_to_set.'" as t1
  70. LEFT JOIN "'.$table_from.'" as t2 '.$filter_table_from.' ;
  71. CREATE INDEX myfield ON gis_opto_relations (field_from);
  72. update "'.$table_to_set.'" t1
  73. set "'.$field_to_set.'"=t2.field_from
  74. from gis_opto_relations t2
  75. where t1."'.$field_index.'"=t2.field_index and t2.if_true=1
  76. '.$filter_sql.'
  77. ;
  78. drop table gis_opto_relations;
  79. -- select t1.'.$field_index.' as "field_index", t2."'.$field_from.'" as "field_from" ,ST_Relate(t1."the_geom",t2."the_geom",\''.$ST_Relate.'\') as if_true into table gis_opto_relations_ FROM "'.$table_to_set.'" as t1 CROSS JOIN "'.$table_from.'" as t2;
  80. ';
  81. DEBUG_S(-3,"Zapytanie sql aktualizujace",$sql,__FILE__,__FUNCTION__,__LINE__);
  82. $gdb->query($sql);
  83. }
  84. function gis_opto_calculations($table_to_set,$field_index,$field_to_set,$table_from,$field_from_geom,$ST_Relate='******F**',$filter_sql='',$price_column='',$lenght_column='') {
  85. global $gdb;
  86. $sql_select='';$sql_price='';
  87. if(is_array($field_index)) {
  88. $field_index_t1=$field_index[0];
  89. $field_index_t2=$field_index[1];
  90. } else {
  91. $field_index_t1=$field_index;
  92. $field_index_t2=$field_index;
  93. }
  94. if(strlen($price_column)>0) { $sql_select=', t2."'.$price_column.'"';
  95. $sql_price='*t2."'.$price_column.'"';
  96. }
  97. // if(!empty($filter_sql)) {
  98. // $ST_Relate=" 1=1 ";
  99. // $ST_Intersects=" 1=1 ";
  100. // } else {
  101. $ST_Relate='ST_Relate(t1."'.$field_from_geom.'",t2."'.$field_from_geom.'",\''.$ST_Relate.'\')';
  102. $ST_Intersects='ST_Intersects(t1."'.$field_from_geom.'",t2."'.$field_from_geom.'")';
  103. // }
  104. $sql='
  105. -- gis_opto_calculations
  106. drop table if exists "'.$table_from.'_AGR" ;
  107. select t1."'.$field_index_t1.'" as field_index '.$sql_select.'
  108. , '.$ST_Intersects.'
  109. , case '.$ST_Relate.' '.$filter_sql.' when true then
  110. ST_Length_Spheroid(t2."'.$field_from_geom.'",\'SPHEROID["WGS 84",6378137,298.257223563]\')
  111. else \'0\' end
  112. as length
  113. into temporary table "'.$table_from.'_AGR"
  114. FROM "'.$table_to_set.'" as t1
  115. CROSS JOIN "'.$table_from.'" as t2
  116. ;
  117. CREATE INDEX ON "'.$table_from.'_AGR" ("field_index");
  118. update "'.$table_to_set.'" t1
  119. set "'.$field_to_set.'"=(
  120. select case when round(sum(t2.length'.$sql_price.')) is null then
  121. 0 else
  122. round(sum(t2.length'.$sql_price.'))
  123. end
  124. from "'.$table_from.'_AGR" as t2 where t2."field_index"=t1."'.$field_index_t1.'"
  125. )
  126. ;';
  127. if(!empty($lenght_column)) { //wylicamy dlugosc
  128. }
  129. DEBUG_S(-3,'Zapyt gis_opt '.$table_to_set,$sql,__FILE__,__FUNCTION__,__LINE__);
  130. flush();
  131. $gdb->query($sql);
  132. }
  133. function gis_opto_calculations_count($table_to_set,$field_index,$field_to_set,$table_from,$field_from_geom,$ST_Relate='******F**',$filter_sql='',$price_column='') {
  134. global $gdb;
  135. $sql_select='';$sql_price='';
  136. if(strlen($price_column)>0) { $sql_select=', t2."'.$price_column.'"';
  137. $sql_price='*t2."'.$price_column.'"';
  138. }
  139. if(is_array($field_index)) {
  140. $field_index_t1=$field_index[0];
  141. $field_index_t2=$field_index[1];
  142. } else {
  143. $field_index_t1=$field_index;
  144. $field_index_t2=$field_index;
  145. }
  146. $sql='
  147. -- gis_opto_calculations_count
  148. drop table if exists "'.$table_from.'_AGR" ;
  149. select t1."'.$field_index_t1.'" as field_index '.$sql_select.'
  150. , ST_Intersects(t1."'.$field_from_geom.'",t2."'.$field_from_geom.'")
  151. , case ST_Relate(t1."'.$field_from_geom.'",t2."'.$field_from_geom.'",\''.$ST_Relate.'\') '.$filter_sql.' when true then
  152. 1
  153. else 0 end
  154. as length
  155. into temporary table "'.$table_from.'_AGR"
  156. FROM "'.$table_to_set.'" as t1
  157. CROSS JOIN "'.$table_from.'" as t2
  158. ;
  159. CREATE INDEX ON "'.$table_from.'_AGR" ("field_index");
  160. update "'.$table_to_set.'" t1
  161. set "'.$field_to_set.'"=(
  162. select
  163. sum(t2.length'.$sql_price.')
  164. from "'.$table_from.'_AGR" as t2 where t2."field_index"=t1."'.$field_index_t1.'"
  165. )
  166. ;';
  167. DEBUG_S(-3,'sql',array($sql,debug_backtrace()),__FILE__,__FUNCTION__,__LINE__);
  168. $gdb->query($sql);
  169. }
  170. function gis_opto_calculations_sum($table_to_set,$field_index,$field_to_set,$table_from,$field_from_geom,$ST_Relate='******F**',$filter_sql='',$field_to_sum) {
  171. global $gdb;
  172. if(is_array($field_index)) {
  173. $field_index_t1=$field_index[0];
  174. $field_index_t2=$field_index[1];
  175. } else {
  176. $field_index_t1=$field_index;
  177. $field_index_t2=$field_index;
  178. }
  179. $sql='
  180. -- gis_opto_calculations_sum
  181. drop table if exists "'.$table_from.'_AGR" ;
  182. select t1."'.$field_index_t1.'" as field_index
  183. , ST_Intersects(t1."'.$field_from_geom.'",t2."'.$field_from_geom.'")
  184. , case ST_Relate(t1."'.$field_from_geom.'",t2."'.$field_from_geom.'",\''.$ST_Relate.'\') '.$filter_sql.' when true then
  185. t2."'.$field_to_sum.'"
  186. else 0 end
  187. as length
  188. into temporary table "'.$table_from.'_AGR"
  189. FROM "'.$table_to_set.'" as t1
  190. CROSS JOIN "'.$table_from.'" as t2
  191. ;
  192. CREATE INDEX ON "'.$table_from.'_AGR" ("field_index");
  193. update "'.$table_to_set.'" t1
  194. set "'.$field_to_set.'"=(
  195. select
  196. sum(t2.length)
  197. from "'.$table_from.'_AGR" as t2 where t2."field_index"=t1."'.$field_index_t1.'"
  198. )
  199. ;';
  200. DEBUG_S(-3,'sql calc_sum '.$table_to_set,$sql,__FILE__,__FUNCTION__,__LINE__);
  201. $gdb->query($sql);
  202. }
  203. function gis_opto_calculations_set_lenght($table_to_set,$field_to_set) {
  204. global $gdb;
  205. $sql='
  206. -- gis_opto_calculations_set_lenght
  207. update "'.$table_to_set.'" set "'.$field_to_set.'"=round(ST_Length_Spheroid("the_geom",\'SPHEROID["WGS 84",6378137,298.257223563]\')) ';
  208. DEBUG_S(-3,'sql set_lenght '.$table_to_set,$sql,__FILE__,__FUNCTION__,__LINE__);
  209. $gdb->query($sql);
  210. }
  211. function USERS2_MARKETING_OVERWIEV_to_MK_Budynki(){
  212. global $db,$gdb;
  213. $sql='select t1.* , t2.A_STATUS as BUILDING_STATUS , t2.geoportal_gml_punkty_adr_gml_id from USERS2_MARKETING_OVERWIEV t1 inner join
  214. BUILDINGS as t2 on t2.S_ADDRESS_STREET=t1.T_TELBOX_BUILDING_IN where t2.geoportal_gml_punkty_adr_gml_id!=\'\' or S_ADDRESS_STREET!=\'\'';
  215. $res=$db->query($sql);
  216. echo "<br> To update USERS2_MARKETING_OVERWIEV use ?FUNCTION_INIT=STATYSTYKA_TABELE ".$sql;
  217. $row=0;
  218. while($h=$db->fetch($res)) {
  219. if($row==0) { //add columns
  220. foreach($h as $col=>$val) {
  221. $sql="SELECT column_name FROM information_schema.columns WHERE table_name='MK_Budynki' and column_name='".$col."'";
  222. $res2=$gdb->query($sql);
  223. if($gdb->count($res2)==0) {
  224. $sql='alter table "MK_Budynki" add "'.$col.'" char(255) not null default \'\' '; echo "<br> ".$sql; flush();
  225. $gdb->query($sql);
  226. } else echo " Field ".$col." exists. ";
  227. }
  228. }
  229. $set=array();
  230. foreach($h as $col=>$val) {
  231. $set[]="\"".$col."\"='".$val."'";
  232. }
  233. $sql='update "MK_Budynki" set '.implode(',', $set).' where ( geoportal_gml_punkty_adr_gml_id=\''.$h->geoportal_gml_punkty_adr_gml_id.'\' and geoportal_gml_punkty_adr_gml_id!=\'\' ) or ( "T_TELBOX_BUILDING_IN"=\''.$h->T_TELBOX_BUILDING_IN.'\' and ( geoportal_gml_punkty_adr_gml_id=\'\' or geoportal_gml_punkty_adr_gml_id is null ) )';
  234. echo "<br> ".$sql;
  235. $gdb->query($sql);
  236. $row++;
  237. }
  238. }
  239. function PROCESY5_to_GIS($p5_table,$p5_key,$gis_table,$gis_key,$p5_what_extra='',$p5_join='',$p5_limit=''){
  240. global $db,$gdb;
  241. //! pierw trigger
  242. $trigger_psql_do_timestamp="CREATE OR REPLACE FUNCTION update_A_RECORD_UPDATE_DATE_column()
  243. RETURNS TRIGGER AS $$
  244. BEGIN
  245. NEW.\"A_RECORD_UPDATE_DATE\" = now();
  246. RETURN NEW;
  247. END;
  248. $$ language 'plpgsql';";
  249. $gdb->query($sql);
  250. $sql='select t1.* '.$p5_what.' from '.$p5_table.' as t1
  251. where t1.'.$p5_key.'!=\'\' or t1.'.$p5_key.' is not null ';
  252. $res=$db->query($sql);
  253. echo "<br> f.PROCESY5_to_GIS use ".$sql;
  254. $row=0;
  255. while($h=$db->fetch($res)) {
  256. if($row==0) { //add columns
  257. foreach($h as $col=>$val) {
  258. $sql="SELECT column_name FROM information_schema.columns WHERE table_name='".$gis_table."' and column_name='".$col."'";
  259. $res2=$gdb->query($sql);
  260. if($gdb->count($res2)==0) {
  261. $sql='alter table "'.$gis_table.'" add "'.$col.'" char(255) not null default \'\' '; echo "<br> ".$sql; flush();
  262. $gdb->query($sql);
  263. if($col=='A_RECORD_UPDATE_DATE') {
  264. $gdb->query("CREATE DEFINER=`root`@`localhost` TRIGGER update_A_RECORD_UPDATE_DATE BEFORE UPDATE
  265. ON \"".$gis_table."\" FOR EACH ROW EXECUTE PROCEDURE
  266. update_A_RECORD_UPDATE_DATE_column();");
  267. }
  268. } else echo " Field ".$col." exists. ";
  269. }
  270. }
  271. $set=array();
  272. $insert=array();
  273. foreach($h as $col=>$val) {
  274. if($col=='the_geom') continue; //todo GEOM tez kopiowac trzeba ale inaczej
  275. if($col==$gis_key) continue;
  276. $set[]="\"".$col."\"='".$gdb->_($val)."'";
  277. $insert['row'][]='"'.$col.'"';
  278. $insert['vals'][]="'".$gdb->_($val)."'";
  279. }
  280. $sql='update "'.$gis_table.'" set '.implode(',', $set).' where ( "'.$gis_key.'"=\''.$h->$p5_key.'\' and "'.$gis_key.'"!=\'\' )
  281. ';
  282. // -- and "A_RECORD_UPDATE_DATE"<\''.$h->A_RECORD_UPDATE_DATE.'\''; //Jak poprawi Piotr aktualizacje GIS to bedzie OK.
  283. // echo "<br> ".$sql;
  284. $gdb->query($sql);
  285. if(!empty($h->the_geom)) { //new record dodajemy jak jest oznaczona geometria
  286. $sql='insert into "'.$his_table.'" ( '.implode(',', $insert['row']).' values ( '.implode(',',$insert['vals']).' )';
  287. // echo "<br> ".$sql;
  288. }
  289. $row++;
  290. }
  291. { //! teraz aktualizujemy po timestampie w prawo
  292. }
  293. }
  294. function POSTGIS_to_MYSQL_Tables($local_table_mysql,$local_key,$remote_table_postgis,$remote_key){
  295. global $db,$gdb;
  296. $sql='select "'.$remote_key.'", ST_AsText(the_geom) as the_geom from "'.$remote_table_postgis.'" where "'.$remote_key.'"!=\'\' and "'.$remote_key.'" is not null and the_geom!=\'\' and the_geom is not null ';
  297. $res=$gdb->query($sql);
  298. while($h=$gdb->fetch($res)) {
  299. $sql2="update `".$local_table_mysql."` set `the_geom`=GeomFromText('".$h->the_geom."') where `".$local_key."`='".trim($h->$remote_key)."' and `".$local_key."`!='' and `".$local_key."` is not null
  300. and ( the_geom='' or the_geom is null )";
  301. echo "<br> ".$sql2;
  302. $db->query($sql2) or die('Problem with sql 228: '.$sql);
  303. }
  304. }
  305. gis_opto_calculations_set_lenght('Rozdzielcza_rurociag_wsg84','dlugosc');
  306. gis_opto_calculations_set_lenght('Rozdzielcza_Kabel_Swiatlowodowy_wsg84','Dlugosc');
  307. gis_opto_intersect('geoportal_gml_punkty_adr','id_0','Mk_Rewir_set','MK_Rewiry','gid');
  308. gis_opto_intersect('Rozdzielcza_rurociag_wsg84','gid','Mk_Rewir_set','MK_Rewiry','gid');
  309. gis_opto_intersect('MK_Budynki','gid','geoportal_gml_punkty_adr_gml_id','geoportal_gml_punkty_adr','gml_id',' and t2."Mk_Rewir_set">0 ');
  310. // gis_opto_intersect('Rozdzielcza_Wykop_przedmiar_na_mikrorurki','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  311. gis_opto_intersect('Rozdzielcza_Wykop_przedmiar_na_mikrorurki','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  312. // gis_opto_intersect('Rozdzielcza_Mikrokanalizacja_do_klienta','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  313. gis_opto_intersect('Rozdzielcza_Mikrokanalizacja_do_klienta','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  314. // gis_opto_intersect('Rozdzielcza_Pakiet5MikrorurekMagistrala_WSG84','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  315. gis_opto_intersect('Rozdzielcza_Pakiet5MikrorurekMagistrala_WSG84','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  316. // gis_opto_intersect('Rozdzielcza_Przeciski_110mm','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  317. gis_opto_intersect('Rozdzielcza_Przeciski_110mm','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  318. // gis_opto_intersect('Rozdzielcza_Zabruki','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  319. gis_opto_intersect('Rozdzielcza_Zabruki','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  320. // gis_opto_intersect('Rozdzielcza_koszty_dodatkowe_wsg84','id_0','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  321. gis_opto_intersect('Rozdzielcza_koszty_dodatkowe_wsg84','id_0','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  322. // gis_opto_intersect('Rozdzielcza_rurociag_wsg84','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  323. gis_opto_intersect('Rozdzielcza_rurociag_wsg84','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  324. // gis_opto_intersect('Rozdzielcza_wezly','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  325. gis_opto_intersect('TELBOXES','ID','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  326. // gis_opto_intersect('Rozdzielcza_Kabel_Swiatlowodowy_wsg84','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  327. gis_opto_intersect('Rozdzielcza_Kabel_Swiatlowodowy_wsg84','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  328. // gis_opto_intersect('MK_Budynki','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  329. gis_opto_intersect('MK_Budynki','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  330. // gis_opto_intersect('MK_Mieszkania','gid','ID_PROJECT','Inwestycje_Planowane','ID_PROJECT',' and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  331. gis_opto_intersect('MK_Mieszkania','gid','ID_PROJECT','IN7_MK_BAZA_DYSTRYBUCJI','ID',' and t2."ID"!=0 and ( t1."ID_PROJECT"=\'0\' or t1."ID_PROJECT"=\'\' or t1."ID_PROJECT" is null ) ');
  332. // gis_opto_intersect('MK_Budynki','gid','geoportal_gml_punkty_adr_gml_id','geoportal_gml_punkty_adr','gml_id','');
  333. //gis_opto_relations('MK_Budynki','gid','geoportal_gml_punkty_adr_gml_id','geoportal_gml_punkty_adr','gml_id','T********',''," on t2.\"Mk_Rewir_set\" > 0 ");
  334. // die('celowe 228');
  335. DEBUG_S(-3,'Agr rurociag',null,__FILE__,__FUNCTION__,__LINE__);
  336. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_Rozdzielcza_rurociag_wsg84','Rozdzielcza_rurociag_wsg84','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  337. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI','ID','Agr_Rozdzielcza_rurociag_wsg84_ilosc','Rozdzielcza_rurociag_wsg84','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0 ');
  338. // die('431');
  339. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_Rozdzielcza_rurociag_wsg84_koszt','Rozdzielcza_rurociag_wsg84','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ','cena_jedn');
  340. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI','ID','Agr_Rozdzielcza_rurociag_wsg84_koszt','Rozdzielcza_rurociag_wsg84','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0 ','cena_jedn');
  341. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_Rozdzielcza_Kabel_Swiatlowodowy_wsg84','Rozdzielcza_Kabel_Swiatlowodowy_wsg84','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  342. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_Kabel_Swiatlowodowy_wsg84_ilosc','Rozdzielcza_Kabel_Swiatlowodowy_wsg84','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  343. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_Rozdzielcza_Kabel_Swiatlowodowy_wsg84_koszt','Rozdzielcza_Kabel_Swiatlowodowy_wsg84','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ','cena_jedn');
  344. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_Kabel_Swiatlowodowy_wsg84_koszt','Rozdzielcza_Kabel_Swiatlowodowy_wsg84','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0','cena_jedn');
  345. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_metrow_mikrorurek_5szt','Rozdzielcza_Pakiet5MikrorurekMagistrala_WSG84','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  346. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_metrow_mikrorurek_5szt','Rozdzielcza_Pakiet5MikrorurekMagistrala_WSG84','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  347. DEBUG_S(-3,'CheckPoint',null,__FILE__,__FUNCTION__,__LINE__);
  348. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_metrow_mikrorurek','Rozdzielcza_Mikrokanalizacja_do_klienta','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  349. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_Mikrokanalizacja_do_klienta_ilosc','Rozdzielcza_Mikrokanalizacja_do_klienta','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  350. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_ilosc_wykopu','Rozdzielcza_Wykop_przedmiar_na_mikrorurki','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  351. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_Wykop_przedmiar_na_mikrorurki_ilosc','Rozdzielcza_Wykop_przedmiar_na_mikrorurki','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  352. DEBUG_S(-3,'CheckPoint Wykop prev',null,__FILE__,__FUNCTION__,__LINE__);
  353. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_ilosc_przeciskow','Rozdzielcza_Przeciski_110mm','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  354. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_Przeciski_110mm_ilosc','Rozdzielcza_Przeciski_110mm','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  355. // gis_opto_calculations('Inwestycje_Planowane','gid','Agr_ilosc_zabrukow','Rozdzielcza_Zabruki','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  356. gis_opto_calculations('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_Zabruki_ilosc','Rozdzielcza_Zabruki','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  357. DEBUG_S(-3,'CheckPoint',null,__FILE__,__FUNCTION__,__LINE__);
  358. // gis_opto_calculations_count('Inwestycje_Planowane','gid','Agr_ilosc_domow','MK_Mieszkania','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  359. gis_opto_calculations_count('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_USERS2_MARKETING_ilosc','MK_Mieszkania','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  360. // gis_opto_calculations_count('Inwestycje_Planowane','gid','Agr_ilosc_wezlow','Rozdzielcza_wezly','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ');
  361. gis_opto_calculations_count('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_wezly_ilosc','TELBOXES','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0');
  362. // gis_opto_calculations_count('Inwestycje_Planowane','gid','Agr_ilosc_wezlow_koszt','Rozdzielcza_wezly','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT" ','cena_jedn');
  363. gis_opto_calculations_count('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_wezly_koszt','TELBOXES','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0','cena_jedn');
  364. // gis_opto_calculations_sum('Inwestycje_Planowane','gid','Agr_Rozdzielcza_koszty_dodatkowe_wsg84','Rozdzielcza_koszty_dodatkowe_wsg84','the_geom','******F**','and t1."ID_PROJECT"=t2."ID_PROJECT"','Wartosc_kosztu');
  365. gis_opto_calculations_sum('IN7_MK_BAZA_DYSTRYBUCJI',array('ID','gid'),'Agr_Rozdzielcza_koszty_dodatkowe_wsg84','Rozdzielcza_koszty_dodatkowe_wsg84','the_geom','******F**','and t1."ID"::int=t2."ID_PROJECT"::int and t1."ID"!=0','Wartosc_kosztu');
  366. // PROCESY5_to_GIS('TELBOXES','ID','Rozdzielcza_lokalizacje','ID_TELBOXES');
  367. // PROCESY5_to_GIS('IN7_MK_BAZA_DYSTRYBUCJI','ID','Inwestycje_Planowane','ID_PROJECT');
  368. // POSTGIS_to_MYSQL_Tables('BUILDINGS','geoportal_gml_punkty_adr_gml_id','MK_Budynki','geoportal_gml_punkty_adr_gml_id');
  369. // POSTGIS_to_MYSQL_Tables('IN7_MK_BAZA_DYSTRYBUCJI','ID','Inwestycje_Planowane','ID_PROJECT');
  370. // USERS2_MARKETING_OVERWIEV_to_MK_Budynki();
  371. // $sql_cena='update "Inwestycje_Planowane" set "Agr_metrow_mikrorurek_5szt"=0 where "Agr_metrow_mikrorurek_5szt" is null;';
  372. // $gdb->query($sql_cena);
  373. $sql_cena='update "IN7_MK_BAZA_DYSTRYBUCJI" set "Agr_metrow_mikrorurek_5szt"=0 where "Agr_metrow_mikrorurek_5szt" is null;';
  374. $gdb->query($sql_cena);
  375. // $sql_cena='update "Inwestycje_Planowane" set "Agr_ilosc_zabrukow"=0 where "Agr_ilosc_zabrukow" is null;';
  376. // $gdb->query($sql_cena);
  377. $sql_cena='update "IN7_MK_BAZA_DYSTRYBUCJI" set "Agr_Rozdzielcza_Zabruki_ilosc"=0 where "Agr_Rozdzielcza_Zabruki_ilosc" is null;';
  378. $gdb->query($sql_cena);
  379. /* $sql_cena='update "Inwestycje_Planowane" set
  380. koszt_wspolny="Agr_ilosc_wykopu"*"Agr_ilosc_wykopu_cena"
  381. +"Agr_metrow_mikrorurek"*"Agr_metrow_mikrorurek_cena"
  382. +"Agr_metrow_mikrorurek_5szt"*"Agr_metrow_mikrorurek_5szt_cena"
  383. +"Agr_ilosc_przeciskow"*"Agr_ilosc_przeciskow_cena"
  384. +"Agr_ilosc_zabrukow"*"Agr_ilosc_zabrukow_cena"
  385. +"Agr_ilosc_wezlow_koszt"
  386. +"Agr_Rozdzielcza_koszty_dodatkowe_wsg84"
  387. +"Agr_Rozdzielcza_rurociag_wsg84_koszt"
  388. +"Agr_Rozdzielcza_Kabel_Swiatlowodowy_wsg84_koszt"
  389. +"Agr_ilosc_domow"*"Agr_MK_Mieszkania_cena_jedn"
  390. ;'; //"Agr_metrow_w_tpsa*3 +Agr_metrow_kabel*
  391. ////+ studnia1300 z pioh+ mufa 300 + spliter 200 = 1800 PLN za wezel
  392. $gdb->query($sql_cena);
  393. */
  394. $sql_cena='update "IN7_MK_BAZA_DYSTRYBUCJI" set
  395. koszt_wspolny="Agr_Rozdzielcza_Wykop_przedmiar_na_mikrorurki_ilosc"*"Agr_Rozdzielcza_Wykop_przedmiar_na_mikrorurki_cena"
  396. +"Agr_Rozdzielcza_Mikrokanalizacja_do_klienta_ilosc"*"Agr_Rozdzielcza_Mikrokanalizacja_do_klienta_cena"
  397. +"Agr_metrow_mikrorurek_5szt"*"Agr_metrow_mikrorurek_5szt_cena"
  398. +"Agr_Rozdzielcza_Przeciski_110mm_ilosc"*"Agr_Rozdzielcza_Przeciski_110mm_cena"
  399. +"Agr_Rozdzielcza_Zabruki_ilosc"*"Agr_Rozdzielcza_Zabruki_cena"
  400. +"Agr_Rozdzielcza_wezly_koszt"
  401. +"Agr_Rozdzielcza_koszty_dodatkowe_wsg84"
  402. +"Agr_Rozdzielcza_rurociag_wsg84_koszt"
  403. +"Agr_Rozdzielcza_Kabel_Swiatlowodowy_wsg84_koszt"
  404. +"Agr_USERS2_MARKETING_ilosc"*"Agr_USERS2_MARKETING_cena"
  405. ;'; //"Agr_metrow_w_tpsa*3 +Agr_metrow_kabel*
  406. ////+ studnia1300 z pioh+ mufa 300 + spliter 200 = 1800 PLN za wezel
  407. $gdb->query($sql_cena);
  408. // $sql_cena='update "Inwestycje_Planowane" set "Agr_MK_Mieszkania_koszt"=round("Agr_MK_Mieszkania_cena_jedn"*"Agr_ilosc_domow") where "Agr_ilosc_domow">0 ' ;
  409. // $gdb->query($sql_cena);
  410. // $sql_cena='update "Inwestycje_Planowane" set "koszt_na_dom"=round("koszt_wspolny"/"Agr_ilosc_domow") where "Agr_ilosc_domow">0 ' ;
  411. // $gdb->query($sql_cena);
  412. $sql_cena='update "IN7_MK_BAZA_DYSTRYBUCJI" set "Agr_USERS2_MARKETING_koszt"=round("Agr_USERS2_MARKETING_cena"*"Agr_USERS2_MARKETING_ilosc") where "Agr_USERS2_MARKETING_ilosc">0 ' ;
  413. $gdb->query($sql_cena);
  414. $sql_cena='update "IN7_MK_BAZA_DYSTRYBUCJI" set "koszt_na_mieszkanie"=round("koszt_wspolny"/"Agr_USERS2_MARKETING_ilosc") where "Agr_USERS2_MARKETING_ilosc">0 ' ;
  415. $gdb->query($sql_cena);
  416. ///
  417. die("celowe zabicie zapytanie: ");
  418. gis_opto_relations('opt_tacki','id_0','id_przelac','opt_przelacznice_mufy','id_0','T********');
  419. gis_opto_relations('opt_spawy','id_0','id_tacka','opt_tacki','id_0','T********');
  420. $gdb->query('update opt_wlokna set id_tuba=null ');
  421. gis_opto_relations('opt_wlokna','id','id_tuba','opt_tuby','id_0','T********');
  422. gis_opto_relations('opt_tuby','id_0','id_kabel','opt_kable','id_0','T********');
  423. $gdb->query('update opt_wlokna set id_tacka_a=null, id_tacka_b=null; ');
  424. gis_opto_relations('opt_wlokna','id','id_tacka_a','opt_tacki','id_0','T********','and t1.id_tacka_a is null ');
  425. gis_opto_relations('opt_wlokna','id','id_tacka_b','opt_tacki','id_0','T********','and t1.id_tacka_a!=t2.field_from and t1.id_tacka_b is null');
  426. $gdb->query('update opt_przelacznice_mufy set id_opt_lokalizacja=null; ');
  427. gis_opto_relations('opt_przelacznice_mufy','id_0','id_opt_lokalizacja','opt_lokalizacje','id_0','T********');
  428. $gdb->query('update opt_wlokna set id_spaw_a=null, id_spaw_b=null; ');
  429. gis_opto_relations('opt_wlokna','id','id_spaw_a','opt_spawy','id_0','FF10F0FF2','and t1.id_spaw_a is null');
  430. gis_opto_relations('opt_wlokna','id','id_spaw_b','opt_spawy','id_0','FF10F0FF2','and t1.id_spaw_a!=t2.field_from and t1.id_spaw_b is null');
  431. // add_pg_roles();
  432. //dodanie wszystkich uzytkownikow z haslem
  433. // public static function &get_users_list( $params = array(), $limit = 10, $limit_start = 0, $order_by = '', $order_dir = '' ) {
  434. //$tbl_perms=UserAcl::getTableAcl();
  435. include_once('se-lib/UserAcl.php');
  436. $Users=UsersHelper::get_users_list();
  437. DEBUG_S(-3,'UsersHelper::get_users_list()',$Users,__FILE__,__FUNCTION__,__LINE__);
  438. $userAcl = UsersHelper::getUserAcl($Users[9]->ID);
  439. // $userAcl->fetchGroups();
  440. $userAcl->fetchAllPerms();
  441. //$getTablesAcl=$userAcl->getTablesAcl();
  442. getAcl();
  443. DEBUG_S(-3,'UserAcl::getTablesAcl',$getTablesAcl,__FILE__,__FUNCTION__,__LINE__);
  444. if ($userAcl->hasTableAcl($zasobObj->ID)) {
  445. $tblAcl = $usrAcl->getTableAcl($tableZasobID);
  446. $tblAcl->init();
  447. }
  448. DEBUG_S(-3,'UsersHelper::getUserAcl',$userAcl,__FILE__,__FUNCTION__,__LINE__);
  449. //odlaczenie wszystkich rol od uzytkownikow
  450. die('zabilem skrypt');
  451. //$sql="select ID from CRM_LISTA_ZASOBOW where `TYPE`='STANOWISKO' and "
  452. foreach($tbls_to_sync as $tbl) {
  453. $res=$gdb->describe_table($tbl);
  454. $ile=$gdb->count($res);
  455. $struct=$db->STRUCTURE_GENERATE(array($tbl),null,null);
  456. DEBUG_S(-3,'Structure local',$struct,__FILE__,__FUNCTION__,__LINE__);
  457. if(!$ile) {
  458. $gdb->STRUCTURE_GENERATE_PARSE($struct);
  459. $gdb->query('alter table "'.$tbl.'" add "gid" serial primary key ;'); //todo before "ID"
  460. $gdb->query("CREATE OR REPLACE FUNCTION update_A_RECORD_UPDATE_DATE_column()
  461. RETURNS TRIGGER AS $$
  462. BEGIN
  463. NEW.\"A_RECORD_UPDATE_DATE\" = now();
  464. RETURN NEW;
  465. END;
  466. $$ language 'plpgsql';");
  467. $gdb->query("CREATE DEFINER=`root`@`localhost` TRIGGER update_A_RECORD_UPDATE_DATE BEFORE UPDATE
  468. ON \"".$tbl."\" FOR EACH ROW EXECUTE PROCEDURE
  469. update_A_RECORD_UPDATE_DATE_column();");
  470. //$gdb->query('alter table "'.$tbl.'" add "the_geom" serial primary key ;'); //todo before "ID"
  471. } else {
  472. $gdb->STRUCTURE_GENERATE_PARSE($struct);
  473. echo "<br> Znalazlem cos, wiec !ile nie zadzialalo!(".$ile.")";
  474. }
  475. //1) try to put newer data
  476. $sql="select t1.* from ".$tbl." as t1 left join _SYNC_to_gis_36_to_13102 as t2 on t1.ID=t2.LID and t2.LTABLE='".$tbl."'
  477. where t2.LID is NULL; "; //unix_timestamp(t1.A_RECORD_UPDATE_DATE)>unix_timestamp(t2.LTS) or
  478. echo "<br>".$sql;
  479. $lres=$db->query($sql);
  480. while($h=$db->fetch($lres)) {
  481. $data=array();
  482. foreach($h as $ind=>$val) {
  483. //if($ind=='the_geom')
  484. //$data[$ind]="'01030000000100000005000000A681BD96FAAB32402B9771AC13334B40A430199F0DAC3240E91B087D12334B4092AA81BA0DAC3240A8DFAECE15334B40004534E3FAAB32401568C3D418334B40A681BD96FAAB32402B9771AC13334B40'";
  485. //else
  486. if(empty($val))
  487. $data[$ind]="null";
  488. else
  489. $data[$ind]="'".$gdb->_($val)."'";
  490. //
  491. }
  492. DEBUG_S(-3,'zminne H to ',$data);
  493. //$array=array('lastname', 'email', 'phone');
  494. //$comma_separated = implode(",", $array);
  495. //uczylem dzieciaki
  496. $keys=array_keys($data);
  497. $comma_separated = '"'.implode('","', $keys).'"';
  498. DEBUG_S(-3,'comma_separated',$comma_separated);
  499. $values_comma_separated=implode(",",$data);
  500. $sql="insert into \"".$tbl."\" ( ".$comma_separated." ) values ( ".$values_comma_separated." ) ";
  501. DEBUG_S(-3,'nasze zapytanie SQL',$sql);
  502. $gdb->query($sql) or die('blad 104');
  503. $sql="insert into _SYNC_to_gis_36_to_13102 ( LTABLE, LID, RID, RIDCOLUMN , RTS, LTS )
  504. values ( '".$tbl."',".$data['ID'].",'".$gdb->insert_id()."','gid',now(),now()) ";
  505. DEBUG_S(-3,'sql to synctable',array($sql,$gdb->insert_id()),__FILE__,__FUNCTION__,__LINE__);
  506. $db->query($sql) or die('blad 107');
  507. //die('123');
  508. //
  509. // DEBUG_S(-3,'rec data',$data);
  510. // $sql="insert into \"".$tbl."\" ( \"".implode('","', array_keys($data))."\") values (".implode(',', $data).") ";
  511. //
  512. // die($sql);
  513. }
  514. /* $sql_rem="create table if not exists ".$tbl." (GIS_TIMESTAMP timestamp) ;";
  515. $gdb->query($sql_rem);
  516. $sql_rem="select max(GIS_TIMESTAMP) as max from ".$tbl."";
  517. $res=$gdb->query($sql_rem);
  518. $last_rem=$gdb->fetch_assoc($res);
  519. if(empty($last_rem['max'])) $last_rem['max']=0;
  520. DEBUG_S(-3,'Last ts z rem',$last_rem['max']);
  521. $sql_loc="select * from ".$tbl." where unix_timestamp(A_RECORD_UPDATE_DATE)>".$last_rem['max']." ";
  522. echo $sql_loc;
  523. $res=$db->query($sql_loc);
  524. $i=0;
  525. while($h=$db->fetch($res)) {
  526. print_r($h);
  527. }
  528. */
  529. // $structure_local=DB_Dump::get_db_structure_by_table_prefix($db,$tbl);
  530. // $structure_remote=DB_Dump::get_db_structure_by_table_prefix($gdb,$tbl);
  531. // DEBUG_S(-3,'structure_local',$structure_local,__FILE__,__FUNCTION__,__LINE__);
  532. // DEBUG_S(-3,'structure_remote',$structure_remote,__FILE__,__FUNCTION__,__LINE__);
  533. }
  534. }