superedit-GIS_OPT_STRUCTURES.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. //
  3. // synchronizacja do serwera postgres GIS
  4. //
  5. include_once('se-lib/DB_Dump.php');
  6. include_once('se-lib/UsersHelper.php');
  7. class GIS_OPT_STRUCTURES {
  8. function init() {
  9. $this->graph = new stdClass();
  10. $this->graph->htmlID = 'graph_proces_id_' . $id_proces;
  11. $this->graph->procesTreeFlat = array();
  12. $this->graph->procesTreeGoto = array();
  13. $this->graph->treeItems = array();
  14. $this->graph->elements = new stdClass();
  15. $this->graph->elements->nodes = array();
  16. $this->graph->elements->edges = array();
  17. }
  18. function set_mysql_zas_id($mysql_zas_id) {
  19. $this->mysql_zas_id=$mysql_zas_id;
  20. }
  21. function set_gis_zas_id($gis_zas_id) {
  22. $this->gis_zas_id=$gis_zas_id;
  23. $this->gdb=DB::getDB($this->gis_zas_id);
  24. }
  25. function get_opt_objects($src_table,$src_index,$src_name,$map_table_id,$map_table_name,$parent_table_id,$parent_table,$limit=null,$ids_ok) {
  26. $sql='select \''.$src_table.'\' as src_table , "'.$src_index.'" as src_index ';
  27. if(!empty($src_name)) $sql.=', "'.$src_name.'" as src_name ';
  28. $sql.=', "'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" '.$limit.' ;';
  29. $res=$this->gdb->query($sql);
  30. while($h=$this->gdb->fetch($res)) {
  31. if(!empty($limit)) {
  32. //bierzemy wszystkie rekordy bo byl limit
  33. $arr[]=$h;
  34. $this->tables->$src_table->src_index[]=$h->src_index;
  35. } else {
  36. //tylko te rekordy dla ktorych byly powiazania
  37. if(in_array($h->parent_table_id, $this->tables->$parent_table->src_index)) {
  38. $this->tables->$src_table->src_index[]=$h->src_index;
  39. // echo "<br> <font color=green>id ".$h->parent_table_id." IS found in ".$parent_table." parent table</font>";
  40. $arr[]=$h;
  41. } //else echo "<br> id ".$h->parent_table_id." not found in ".$parent_table." parent table";
  42. }
  43. }
  44. return $arr;
  45. }
  46. function get_opt_objects_parent($src_table,$src_index,$src_name,$map_table_id,$map_table_name,$parent_table_id,$parent_table,$limit=null,$child_table,$child_joinfield,$child_index){
  47. $i=0;
  48. $where_in=implode(",", $this->tables->$child_table->src_index);
  49. $sql='select \''.$src_table.'\' as src_table , t1."'.$src_index.'" as src_index ';
  50. if(!empty($src_name)) $sql.=', t1."'.$src_name.'" as src_name ';
  51. $sql.=', t1."'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" as t1
  52. inner join "'.$child_table.'" as t2 on t1."'.$src_index.'"=t2."'.$child_joinfield.'"
  53. where t2."'.$child_index.'" in ('.$where_in.') ;';
  54. echo "<br> sql: ".$sql;
  55. $res=$this->gdb->query($sql);
  56. while($h=$this->gdb->fetch($res)) {
  57. $i++;
  58. // if($i>5) continue;
  59. if(!in_array($h->src_index, $this->tables->$src_table->src_index)) {
  60. $this->tables->$src_table->src_index[]=$h->src_index;
  61. $arr[]=$h;
  62. }
  63. }
  64. return $arr;
  65. }
  66. function add_array_to_graph($array,$PROCES_INIT) {
  67. foreach($array as $link) {
  68. if(!empty($link->parent_table_id)) $parent=$link->parent_table.$link->parent_table_id; else $parent=null;
  69. self::graph__addNodeID($link->src_table.$link->src_index, $this->graph,$link->src_name,null,$parent,$PROCES_INIT);
  70. }
  71. }
  72. function graph__addNodeID($id, $graph,$name=null,$path,$parent=null,$type) {
  73. //if (!array_key_exists($id, $this->graph->treeItems)) {
  74. $this->graph->treeItems[$id]= true;
  75. if(empty($name)) $name=$id; //else $name.="".$id;
  76. if(!empty($path)) { $name=$name." ".implode(',', $path);// $path=array();
  77. }
  78. //DEBUG_S(-3,'added id,name,path,parent',array($id,$name,$path,$parent),__FILE__,__FUNCTION__,__LINE__);
  79. if($type=='PROCES_INIT') $type_init='procesInit'; else $type_init=null;
  80. //echo $type_init.$id;
  81. $this->graph->elements->nodes[] = array('data'=>array('id'=>"".$id."", 'name'=>$name , 'type'=>$type_init));
  82. //echo "<br> w AddNode:ID".$id." parent".$parent;
  83. //}
  84. if(!empty($parent)) {
  85. $this->graph->elements->edges[] = array('data'=>array('source'=>$parent, 'target'=>$id ));
  86. }
  87. }
  88. function to_html() {
  89. foreach($this->graph->elements->edges as $data) {
  90. // DEBUG_S(-3,'data',$data,__FILE__,__FUNCTION__,__LINE__);
  91. if(empty($this->graph->treeItems[$data['data']['source']])) {
  92. self::graph__addNodeID($data['data']['source'], $this->graph,$data['data']['source'],null,null,null);
  93. echo "<br> Empty ".$data['data']['source'];
  94. }
  95. }
  96. DEBUG_S(-3,'Graph obj',$this->graph,__FILE__,__FUNCTION__,__LINE__);
  97. DEBUG_S(-3,'tables',$this->tables,__FILE__,__FUNCTION__,__LINE__);
  98. ?>
  99. <style type="text/css">
  100. #<?php echo $this->graph->htmlID; ?>_wrap {
  101. position:relative;
  102. width:1100px;
  103. margin:0 auto;
  104. border:1px solid #ccc;
  105. }
  106. #<?php echo $this->graph->htmlID; ?> {
  107. height:560px;
  108. border-bottom:1px solid #ccc;
  109. }
  110. #<?php echo $this->graph->htmlID; ?>_info {
  111. padding:3px;
  112. }
  113. #<?php echo $this->graph->htmlID; ?>_wrap .actions { position:absolute; top:20px; left:-40px; margin:0; padding:0; list-style:none; }
  114. #<?php echo $this->graph->htmlID; ?>_wrap .actions button { border-radius:0; background:#fff; border:1px solid #ccc; }
  115. </style>
  116. <script src="./stuff/cytoscape.js/arbor.js"></script>
  117. <script src="./stuff/cytoscape.js/cytoscape.js"></script>
  118. <script>
  119. jQuery(loadInfo = function(nodeID){
  120. $.ajax({
  121. url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&HEADER_NOT_INIT=YES',
  122. type: 'GET',
  123. dataType: 'text',
  124. data: '',
  125. async: true,
  126. success: function (data) {
  127. jQuery('#<?php echo $this->graph->htmlID; ?>_info').html(data);
  128. },
  129. error: function (err) {
  130. console.log('err');
  131. }
  132. });
  133. });
  134. jQuery(loadCy = function(){
  135. jQuery('#<?php echo $this->graph->htmlID; ?>').cytoscape({
  136. layout: {
  137. name: 'arbor'
  138. },
  139. style: cytoscape.stylesheet()
  140. .selector('node')
  141. .css({
  142. 'shape': 'rectangle',
  143. 'width': '10px', 'height': '8px',
  144. 'font-size': '10px',
  145. 'content': 'data(name)',
  146. 'text-valign': 'center',
  147. 'color': 'white',
  148. 'text-outline-width': 2,
  149. 'text-outline-color': '#888'
  150. })
  151. .selector('edge')
  152. .css({
  153. 'target-arrow-shape': 'triangle'
  154. })
  155. .selector(':selected')
  156. .css({
  157. 'background-color': 'black',
  158. 'line-color': 'black',
  159. 'target-arrow-color': 'black',
  160. 'source-arrow-color': 'black'
  161. })
  162. .selector('.faded')
  163. .css({
  164. 'opacity': 0.25,
  165. 'text-opacity': 0
  166. })
  167. .selector('edge.neighborhood')
  168. .css({
  169. 'background-color': 'blue',
  170. 'color': 'orange'
  171. })
  172. .selector('node.procesInit')
  173. .css({
  174. 'background-color': 'red',
  175. 'text-outline-color': 'red',
  176. 'font-weight': 'bold'
  177. }),
  178. elements: <?php echo json_encode($this->graph->elements); ?>,
  179. ready: function(){
  180. var cy = this;
  181. window.cy_<?php echo $this->graph->htmlID; ?> = this;
  182. cy.elements("node[type = 'procesInit']").addClass('procesInit');
  183. cy.elements("node[lvl > 1]").hide();
  184. cy.elements().unselectify();
  185. cy.on('tap', 'node', function(e){
  186. //console.log('on tap node', e)
  187. var node = e.cyTarget;
  188. var neighborhood = node.neighborhood().add(node);
  189. var nodeID = node.id();
  190. loadInfo(nodeID);
  191. cy.elements().addClass('faded').unselect();
  192. neighborhood.removeClass('faded');
  193. node.select();
  194. cy.edges().removeClass('neighborhood');
  195. node.connectedEdges().addClass('neighborhood');
  196. neighborhood.show();
  197. cy.center(neighborhood);
  198. });
  199. cy.on('tap', function(e){
  200. if (e.cyTarget === cy){
  201. cy.elements().removeClass('faded');
  202. }
  203. });
  204. },
  205. showOverlay: false
  206. });
  207. });
  208. jQuery(document).ready(function(){
  209. loadCy();
  210. var parent = $('#<?php echo $this->graph->htmlID; ?>')
  211. .parent()
  212. parent.find('.actions .cy-refresh')
  213. .on('mousedown touchstart', function(){
  214. loadCy();
  215. cy.attr('style', '');
  216. });
  217. parent.find('.actions .cy-zoom-plus')
  218. .on('mousedown touchstart', function(){
  219. window.cy_<?php echo $this->graph->htmlID; ?>.zoom(window.cy_<?php echo $this->graph->htmlID; ?>.zoom() + 0.1);
  220. });
  221. parent.find('.actions .cy-zoom-minus')
  222. .on('mousedown touchstart', function(){
  223. window.cy_<?php echo $this->graph->htmlID; ?>.zoom(window.cy_<?php echo $this->graph->htmlID; ?>.zoom() - 0.1);
  224. });
  225. });
  226. </script>
  227. <div id="<?php echo $this->graph->htmlID; ?>_wrap">
  228. <div id="<?php echo $this->graph->htmlID; ?>"></div>
  229. <div id="<?php echo $this->graph->htmlID; ?>_info"></div>
  230. <ul class="actions">
  231. <li><button class="btn cy-refresh"><i title="Refresh" class="glyphicon glyphicon-refresh"></i></button></li>
  232. <li><button class="btn cy-zoom-plus"><i title="Zoom +" class="glyphicon glyphicon-plus"></i></button></li>
  233. <li><button class="btn cy-zoom-minus"><i title="Zoom -" class="glyphicon glyphicon-minus"></i></button></li>
  234. </ul>
  235. </div>
  236. <?
  237. }
  238. }
  239. function GIS_OPT_STRUCTURES() {
  240. global $db,$gdb;
  241. $mysql_zas_id=36;
  242. $gis_zas_id=13102;
  243. $db = DB::getDB();
  244. $gdb= DB::getDB($gis_zas_id);
  245. DEBUG_S(-3,'db',$db);
  246. DEBUG_S(-3,'gis',$gdb);
  247. $cp=new GIS_OPT_STRUCTURES;
  248. $cp->init();
  249. $cp->set_gis_zas_id($gis_zas_id);
  250. $wezly=$cp->get_opt_objects('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje',"where \"Nazwa\" like '%test%'");
  251. $tacki=$cp->get_opt_objects('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy');
  252. $spawy=$cp->get_opt_objects('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki');
  253. $wlokna=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_a','opt_spawy');
  254. $wlokna2=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_b','opt_spawy');
  255. $spawy_b=$cp->get_opt_objects_parent('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki','1=1','opt_wlokna','id_spaw_b','id'); //chce znalezc te sprawy ktore sa w wloknach jako B
  256. $spawy_b2=$cp->get_opt_objects_parent('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki','1=1','opt_wlokna','id_spaw_a','id'); //chce znalezc te sprawy ktore sa w wloknach jako B
  257. $tacki_b=$cp->get_opt_objects_parent('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy','1=1','opt_spawy','id_tacka','id_0'); //chce znalezc te sprawy ktore sa w wloknach jako B
  258. $wezly_b=$cp->get_opt_objects_parent('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje','1=1','opt_tacki','id_przelac','id_0');
  259. $cp->add_array_to_graph($wezly,'PROCES_INIT');
  260. $cp->add_array_to_graph($tacki,null);
  261. $cp->add_array_to_graph($spawy,null);
  262. $cp->add_array_to_graph($wlokna,null);
  263. $cp->add_array_to_graph($wlokna2,null);
  264. $cp->add_array_to_graph($spawy_b,null);
  265. $cp->add_array_to_graph($spawy_b2,null);
  266. $cp->add_array_to_graph($tacki_b,null);
  267. $cp->add_array_to_graph($wezly_b,'PROCES_INIT');
  268. DEBUG_S(-3,'Wezly do dodania',$wezly,__FILE__,__FUNCTION__,__LINE__);
  269. $cp->to_html();
  270. die();
  271. // foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, $graph,$tree->Viev_Zpc[$link]->DESC,null,$link,null);
  272. // foreach($obj->EXTERNAL_LINK as $link) graph__addNodeID($link, $graph,$tree->Viev_Zpc[$link]->DESC,null,$id,'PROCES_INIT');
  273. }
  274. ?>