Jelajahi Sumber

Graph View update

Piotr Labudda 11 tahun lalu
induk
melakukan
4d2127d04f

+ 1 - 1
SE/VERSION

@@ -1 +1 @@
-3.9.9-7
+3.9.9-8

+ 0 - 516
SE/superedit-GRAPH_VIEW_PROCES copy.php

@@ -1,516 +0,0 @@
-<?php
-
-
-function GRAPH_VIEW_PROCES() {
-	$id_proces = V::get('id_proces', '', $_REQUEST, 'int');
-	if ($id_proces <= 0) {
-		echo'<p class="err box box-red">'."Wrong ID".'</p>';
-		return;
-	}
-
-	$db = DB::getDB();
-	$proces = $db->get_by_id('CRM_PROCES', $id_proces);
-	if (!$proces) {
-		echo'<p class="err box box-red">'."Process {$id_proces} not exists".'</p>';
-		return;
-	}
-
-	$ajaxTask = V::get('ajaxTask', '', $_REQUEST);
-	if ($ajaxTask == 'getInfo') {
-		$id = V::get('id', 0, $_REQUEST, 'int');
-		if ($id > 0) {
-			$step = $db->get_by_id('CRM_PROCES', $id);
-			//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($step);echo'</pre>';
-			?>
-			<p><code><?php echo $step->ID; ?></code> <?php echo $step->DESC; ?></p>
-			<p><?php echo $step->OPIS; ?></p>
-			<?php
-		}
-		exit;
-	}
-
-	$graph = new stdClass();
-	$graph->htmlID = 'graph_proces_id_' . $id_proces;
-	$graph->procesTreeFlat = array();
-	$graph->procesTreeGoto = array();
-	$graph->treeItems = array();
-
-	$graph->elements = new stdClass();
-	$graph->elements->nodes = array();
-	$graph->elements->edges = array();
-	/*	elements: {
-				nodes: [
-					{ data: { id: 'j', name: 'Jerry' } },
-					{ data: { id: 'e', name: 'Elaine' } },
-					{ data: { id: 'k', name: 'Kramer' } },
-					{ data: { id: 'g', name: 'George' } }
-				],
-				edges: [
-					{ data: { source: 'j', target: 'e' } },
-					{ data: { source: 'j', target: 'k' } },
-					{ data: { source: 'j', target: 'g' } },
-					{ data: { source: 'e', target: 'j' } },
-					{ data: { source: 'e', target: 'k' } },
-					{ data: { source: 'k', target: 'j' } },
-					{ data: { source: 'k', target: 'e' } },
-					{ data: { source: 'k', target: 'g' } },
-					{ data: { source: 'g', target: 'j' } }
-				]
-			},
-	 */
-
-
-	function graph__addNodeID($id, &$graph,$name=null,&$path,$parent=null,$type) {
-		if (!array_key_exists($id, $graph->treeItems)) {
-			$graph->treeItems[$id]= true;
-			if(empty($name)) $name=$id;
-			if(!empty($path))  { $name=$name." ".implode(',', $path);// $path=array(); 
-			}
-			//DEBUG_S(-3,'added id,name,path,parent',array($id,$name,$path,$parent),__FILE__,__FUNCTION__,__LINE__);
-
-			if($type=='PROCES_INIT') $type_init='procesInit'; else $type_init=null;
-			//echo $type_init.$id;
-			$graph->elements->nodes[] = array('data'=>array('id'=>"".$id."", 'name'=>$name , 'type'=>$type_init));
-			
-			if(!empty($parent)) $graph->elements->edges[] = array('data'=>array('source'=>$parent, 'target'=>$id  ));
-			//echo "<br> w AddNode:";
-		}
-	}
-	
-	 
-	 
-class crm_proces_paser {
-
-  // var $this->get_proces_init=array();
-
- // [proces_init]  - A
- //    [step]      - flat 0
- //    [step]      - flat 3 , tree 2 , cut
- //     [step]     - flat 0 , tree 0
- //     [step]     - flat 1 , tree 1
- //       [step]   - flat 1 , tree 1
- //         [step] - flat 0 , tree 0
- //     [step]     - flat 1 , tree 1
- //       [step]   - flat 0 , tree 0
- 
-
-
-   function TestIfHasDeep($id_proces_step) {
-		 $sql="select `ID`,`IF_TRUE_GOTO` from `CRM_PROCES` where `PARENT_ID`=$id_proces_step and  `A_STATUS` in ('WAITING','NORMAL') ";
-		 $res=DB::query($sql);
-		 while($h=DB::fetch($res)) {
-			 $ret[$h->ID]='PARENT_ID';
-		 }
-		 
-		 $sql="select `ID`,`IF_TRUE_GOTO`,`IF_TRUE_GOTO_FLAG` from `CRM_PROCES` where `ID`=$id_proces_step and `IF_TRUE_GOTO`>0 and  `A_STATUS` in ('WAITING','NORMAL') ";
-		  $res=DB::query($sql);
-		  	while($h=DB::fetch($res)) {
-			 $ret[$h->IF_TRUE_GOTO]=$h->IF_TRUE_GOTO_FLAG;
-			 }
-		 return $ret;
-	 }
-   //funckcja do szukania proces_init
-   function get_proces_init() {
-	$sql= "select p.`ID`,`DESC` from `CRM_PROCES` as p where  p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT' and ID=994 limit 1";
-	echo $sql;
-	$res=DB::query($sql);
-		while($h=DB::fetch($res)) {
-			$this->get_proces_init[]=$h->ID;
-		}
-		return $this->get_proces_init;
-	
-   }
-
-   function build_proces_init_tree($id_proces) {
-	  // $tree->Childs[$id_proces]=true;
-	   $tree->Childs[$id_proces]->PARENT=0;
-	   $tree->Parents[0]->CHILD[$id_proces]=$id_proces;
-	   $obj=DB::get_by_id('CRM_PROCES',$id_proces);
-	   $tree->Childs[$id_proces]->TYPE=$obj->TYPE;
-	   self::build_tree_for_proces($tree,$id_proces);
-	   return $tree;
-   }
-   
-      function build_tree_for_proces(&$tree,$cursor) {
-	      	   $sql="select `ID`,`IF_TRUE_GOTO`,`IF_TRUE_GOTO_FLAG` , `TYPE` from `CRM_PROCES` where PARENT_ID={$cursor} and  `A_STATUS` in ('WAITING','NORMAL')";
-		  	  // echo "<br>sql: ".$sql;
-	      	   $res=DB::query($sql);
-	      	   	      	   while ($h=DB::fetch($res)) {
-	      	   	   $tree->Childs[$h->ID]->PARENT=$cursor;
-	      	   	   $tree->Parents[$cursor]->CHILD[$h->ID]=$h->ID;
-		  	   	   $tree->Childs[$h->ID]->TYPE=$h->TYPE;
-	      	   	   if($h->IF_TRUE_GOTO>0) { 
-	      	   	      $tree->Childs[$h->ID]->GOTO_FLAG=$h->IF_TRUE_GOTO_FLAG;
-	      	   	      $tree->Childs[$h->ID]->IF_TRUE_GOTO=$h->IF_TRUE_GOTO;
-	      	   	   }
-		      	   self::build_tree_for_proces($tree,$h->ID);
-	      	   }
-      }
-
-      function build_tree_flat_info(&$tree,$flat) {
-		  /* >> zbudowanie ile ma dzieci <<
-			  $tree->Childs[3208] => stdClass Object
-			  (
-            [PARENT] => 3123
-            [CHILD] => Array
-                (
-             >>       [3219] => 1 <<
-             >>       [3237] => 0 <<
-             >>       [3209] => 0 <<
-                 
-			 */
-	      foreach($tree->Childs as $id=>$obj) {
-			  //sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
-		      foreach($tree->Parents[$id]->CHILD as $child) {
-			      $tree->Childs[$id]->CHILD[$child]=count($tree->Parents[$child]->CHILD);     
-		      }
-	      }    
-      }
-      
-      
-      function detect_tree_where_to_detail_cut(&$tree) {
-	       foreach($tree->Childs as $id=>$obj) {
-			  //sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
-			  $control=0;
-		      foreach($obj->CHILD as $child) {
-			      if($child>0) $control++;   
-		      }
-		      if($control>1) $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true;
-	      }       
-      }
-      function search_parent_ids_till_cut($tree,$init,&$find) {
-	      if(!isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
-	      		  $find[]=$init;
-//		  		  self::zoom_process_links($tree,$init);
-		      foreach($tree->Childs[$init]->CHILD as $id=>$count) {
-			      self::search_parent_ids_till_cut($tree,$id,$find);
-		      }
-	      }
-      }
-      
-      function zoom_process_links($tree,$id,$root_id) {
-	      
-	      if(isset($tree->Childs[$id]->GOTO_FLAG)) {
-					  	if(isset( $tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO])) {
-						  	//adding internal link to the same process
-						  	$tree->Viev_Zpc[$id]->INTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
-
-						  	
-					  	} else { echo "<br>Links zewnetrzny do ".$id." - ".$tree->Childs[$id]->IF_TRUE_GOTO;
-					  		$tree->Viev_Zpc[$id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
-					  	}
-				  	} 
-
-	      
-      }
-      
-      function build_path_zoom_proces_cut(&$tree,$init,$path_zpc=array()) {
-	      //funkcja do pokazania procesow wyplaszczonych, z wypunktowanymi rozgalezieniami - buduje drzewo w sposob inteligentny
-		  //szukam rekordow z gory do pierwszego CUT
-		  foreach($tree->Childs as $id=>$obj) {
-		  		if(!isset($tree->Viev_Zpc_found[$id])) {
-			  		//echo "<br>szukam parentow dla ".$id;
-				  	self::search_parent_ids_till_cut($tree,$id,$find);
-				  	//echo "<br>find:";print_r($find);
-				  	foreach($find as $find_id) {
-				  		$tree->Viev_Zpc_found[$find_id]=$find[0];
-				  	}
-				  	$tree->Viev_Zpc[$id]->PATH=$find;
-				  					  	unset($find);
-			  	}
-		  	
-		  }
-		  
-		  	      
-      }
-      
-      
-}	 
-	 
-	 
-	 
-
-	 
-	 
-	 
-	 
-	 $cp=new crm_proces_paser;
-	$PROC_GET=1349;
-		$PROC_GET=$id_proces;
-	 $init=$cp->get_proces_init();
-	 $tree=$cp->build_proces_init_tree($PROC_GET);
-	 $cp->build_tree_flat_info($tree,null);
-     $cp->detect_tree_where_to_detail_cut($tree);
-	 $cp->build_path_zoom_proces_cut($tree,$PROC_GET);
-	 DEBUG_S(-3,'get_proces_init',$init);
-	 DEBUG_S(-3,'tree->childs',$tree->Childs);
-	 DEBUG_S(-3,'tree->Parents',$tree->Parents);
-	 DEBUG_S(-3,'tree->Viev_Zpc',$tree->Viev_Zpc);
-
-	 	  graph__addNodeID(0, &$graph,$name=null,$path,null);
-	 foreach($tree->Viev_Zpc as $id=>$obj) {
-		  graph__addNodeID($id, &$graph,$name=null,$obj->PATH,$tree->Childs[$id]->PARENT,$tree->Childs[$id]->TYPE);
-		  foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, &$graph,$name=null,$obj->PATH,$link,null);
-	 }
-	 
-	 
-	 
-	 
-/*
-	$db = DB::getDB();
-	
-	$sql= "select p.`ID`,`DESC` from `CRM_PROCES` as p where  p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT' and ID=994 limit 1";
-	$res=DB::query($sql);
-	while($h=DB::fetch($res)) {
-		SearchParentsWithExits($h->ID,$h->ID,$graph,'Proces '.$h->ID,0);
-		//graph__addNodeID($h->ID, $graph);
-		graph__addNodeID('1', $graph,'1');
-
-	//	graph__addNodeID($h->ID, $graph,$h->ID);
-//		graph__addNodeID('100', $graph,'100');
-		//$graph->treeItems[$h->ID] = true;
-		//$graph->treeItems[101] = true;
-
-//		$graph->elements->nodes[] = array('data'=>array('id'=>$h->ID, 'name'=>$h->ID , 'type'=>'procesInit'));
-//		$graph->elements->nodes[] = array('data'=>array('id'=>101, 'name'=>101 , 'type'=>'procesInit'));
-//		$graph->elements->edges[] = array('data'=>array('source'=>994, 'target'=>101));
-
-
-	}
-*/
-	foreach($graph->elements->nodes as $var) {
-	//	echo "<br>\n NODE".$var[data][id];
-		$nodes[$var[data][id]]=$var[data][id];
-	}
-	foreach($graph->elements->edges as $var) {
-		echo "<br>\n".$var[data][source]." ".$var[data][target]." ";
-		if(isset($nodes[$var[data][source]])) echo "OK1"; else echo "FAIL1";
-		if(isset($nodes[$var[data][target]])) echo "OK2"; else echo "FAIL2";
-	}
-
-	DEBUG_S(-3,'nodes',$graph->elements->nodes);
-	DEBUG_S(-3,'edges',$graph->elements->edges);
-/*		
-	$sql = "select p.`ID`, p.`PARENT_ID`
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-	";
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeFlat[$r->PARENT_ID] []= $r->ID;
-	}
-
-	$sql = "select p.`IF_TRUE_GOTO` as ID, p.`ID` as PARENT_ID
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-				and p.IF_TRUE_GOTO>0
-		--		and p.IF_TRUE_GOTO_FLAG='GOTO_AND_RETURN'
-	";
-	
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeGoto[$r->PARENT_ID] []= $r->ID;
-	}
-
-
-	function createGraphRec($id, $tree, &$graph, $lvl = 0) {
-		$graph->treeItems[$id] = true;
-		settype($id, 'string');
-		if ($id == 3122) {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'type'=>'procesInit', 'lvl'=>$lvl));
-		} else {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'lvl'=>$lvl));
-		}
-
-		if ($lvl > 1) {
-		//	return;
-		}
-
-		if (!empty($tree[$id])) {
-			foreach ($tree[$id] as $vChildID) {
-				$graph->elements->edges[] = array('data'=>array('source'=>$id, 'target'=>$vChildID));
-				createGraphRec($vChildID, $tree, $graph, $lvl + 1);
-			}
-		}
-	}
-
-	createGraphRec($id_proces, $graph->procesTreeFlat, $graph);
-
-*/
-/*
-	// addGraphGoto
-	foreach ($graph->procesTreeGoto as $kID => $vGotoIds) {
-		//$graph->treeItems[$id] = true;
-		if (array_key_exists($kID, $graph->treeItems)) {
-			foreach ($vGotoIds as $vGotoID) {
-				graph__addNodeID($vGotoID, $graph);
-				$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-			}
-		} else {
-			foreach ($vGotoIds as $vGotoID) {
-				if (array_key_exists($vGotoID, $graph->treeItems)) {
-//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("TODO: add node ($kID); add edge from $kID to $vGotoID");echo'</pre>';
-					graph__addNodeID($kID, $graph);
-					//$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-				}
-			}
-		}
-	}
-*/
-?>
-<style type="text/css">
-#<?php echo $graph->htmlID; ?>_wrap {
-	position:relative;
-	width:1100px;
-	margin:0 auto;
-	border:1px solid #ccc;
-}
-#<?php echo $graph->htmlID; ?> {
-	height:560px;
-	border-bottom:1px solid #ccc;
-}
-#<?php echo $graph->htmlID; ?>_info {
-	padding:3px;
-}
-#<?php echo $graph->htmlID; ?>_wrap .actions { position:absolute; top:20px; left:-40px; margin:0; padding:0; list-style:none; }
-#<?php echo $graph->htmlID; ?>_wrap .actions button { border-radius:0; background:#fff; border:1px solid #ccc; }
-</style>
-
-<script src="./stuff/cytoscape.js/arbor.js"></script>
-<script src="./stuff/cytoscape.js/cytoscape.js"></script>
-<script>
-jQuery(loadInfo = function(nodeID){
-	$.ajax({
-		url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&HEADER_NOT_INIT=YES',
-		type: 'GET',
-		dataType: 'text',
-		data: '',
-		async: true,
-		success: function (data) {
-			jQuery('#<?php echo $graph->htmlID; ?>_info').html(data);
-		},
-		error: function (err) {
-			console.log('err');
-		}
-	});
-});
-jQuery(loadCy = function(){
-	jQuery('#<?php echo $graph->htmlID; ?>').cytoscape({
-		layout: {
-			name: 'arbor'
-		},
-		style: cytoscape.stylesheet()
-			.selector('node')
-				.css({
-					'shape': 'rectangle',
-					'width': '46px', 'height': '26px',
-					'font-size': '10px',
-					'content': 'data(name)',
-					'text-valign': 'center',
-					'color': 'white',
-					'text-outline-width': 2,
-					'text-outline-color': '#888'
-				})
-			.selector('edge')
-				.css({
-					'target-arrow-shape': 'triangle'
-				})
-			.selector(':selected')
-				.css({
-					'background-color': 'black',
-					'line-color': 'black',
-					'target-arrow-color': 'black',
-					'source-arrow-color': 'black'
-				})
-			.selector('.faded')
-				.css({
-					'opacity': 0.25,
-					'text-opacity': 0
-				})
-			.selector('edge.neighborhood')
-				.css({
-					'background-color': 'blue',
-					'color': 'orange'
-				})
-			.selector('node.procesInit')
-				.css({
-					'background-color': 'red',
-					'text-outline-color': 'red',
-					'font-weight': 'bold'
-				}),
-
-		elements: <?php echo json_encode($graph->elements); ?>,
-
-		ready: function(){
-			var cy = this;
-			window.cy_<?php echo $graph->htmlID; ?> = this;
-
-			cy.elements("node[type = 'procesInit']").addClass('procesInit');
-			cy.elements("node[lvl > 1]").hide();
-
-			cy.elements().unselectify();
-
-			cy.on('tap', 'node', function(e){
-				//console.log('on tap node', e)
-				var node = e.cyTarget;
-				var neighborhood = node.neighborhood().add(node);
-
-				var nodeID = node.id();
-				loadInfo(nodeID);
-
-				cy.elements().addClass('faded').unselect();
-				neighborhood.removeClass('faded');
-				node.select();
-
-				cy.edges().removeClass('neighborhood');
-				node.connectedEdges().addClass('neighborhood');
-
-				neighborhood.show();
-
-				cy.center(neighborhood);
-			});
-
-			cy.on('tap', function(e){
-				if (e.cyTarget === cy){
-					cy.elements().removeClass('faded');
-				}
-			});
-		},
-		showOverlay: false
-	});
-});
-
-jQuery(document).ready(function(){
-	loadCy();
-
-	var parent = $('#<?php echo $graph->htmlID; ?>')
-		.parent()
-	parent.find('.actions .cy-refresh')
-		.on('mousedown touchstart', function(){
-			loadCy();
-
-			cy.attr('style', '');
-		});
-	parent.find('.actions .cy-zoom-plus')
-		.on('mousedown touchstart', function(){
-			window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() + 0.1);
-		});
-  parent.find('.actions .cy-zoom-minus')
-		.on('mousedown touchstart', function(){
-			window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() - 0.1);
-		});
-});
-</script>
-
-<div id="<?php echo $graph->htmlID; ?>_wrap">
-	<div id="<?php echo $graph->htmlID; ?>"></div>
-	<div id="<?php echo $graph->htmlID; ?>_info"></div>
-	<ul class="actions">
-		<li><button class="btn cy-refresh"><i title="Refresh" class="ico-refresh"></i></button></li>
-		<li><button class="btn cy-zoom-plus"><i title="Zoom +" class="ico-plus"></i></button></li>
-		<li><button class="btn cy-zoom-minus"><i title="Zoom -" class="ico-minus"></i></button></li>
-	</ul>
-</div>
-
-<?php
-}

+ 0 - 427
SE/superedit-GRAPH_VIEW_PROCES.funkcje-sqix.php

@@ -1,427 +0,0 @@
-<?php
-
-
-function GRAPH_VIEW_PROCES() {
-	$id_proces = V::get('id_proces', '', $_REQUEST, 'int');
-	if ($id_proces <= 0) {
-		echo'<p class="err box box-red">'."Wrong ID".'</p>';
-		return;
-	}
-
-	$db = DB::getDB();
-	$proces = $db->get_by_id('CRM_PROCES', $id_proces);
-	if (!$proces) {
-		echo'<p class="err box box-red">'."Process {$id_proces} not exists".'</p>';
-		return;
-	}
-
-	$ajaxTask = V::get('ajaxTask', '', $_REQUEST);
-	if ($ajaxTask == 'getInfo') {
-		$id = V::get('id', 0, $_REQUEST, 'int');
-		if ($id > 0) {
-			$step = $db->get_by_id('CRM_PROCES', $id);
-			//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($step);echo'</pre>';
-			?>
-			<p><code><?php echo $step->ID; ?></code> <?php echo $step->DESC; ?></p>
-			<p><?php echo $step->OPIS; ?></p>
-			<?php
-		}
-		exit;
-	}
-
-	$graph = new stdClass();
-	$graph->htmlID = 'graph_proces_id_' . $id_proces;
-	$graph->procesTreeFlat = array();
-	$graph->procesTreeGoto = array();
-	$graph->treeItems = array();
-
-	$graph->elements = new stdClass();
-	$graph->elements->nodes = array();
-	$graph->elements->edges = array();
-	/*	elements: {
-				nodes: [
-					{ data: { id: 'j', name: 'Jerry' } },
-					{ data: { id: 'e', name: 'Elaine' } },
-					{ data: { id: 'k', name: 'Kramer' } },
-					{ data: { id: 'g', name: 'George' } }
-				],
-				edges: [
-					{ data: { source: 'j', target: 'e' } },
-					{ data: { source: 'j', target: 'k' } },
-					{ data: { source: 'j', target: 'g' } },
-					{ data: { source: 'e', target: 'j' } },
-					{ data: { source: 'e', target: 'k' } },
-					{ data: { source: 'k', target: 'j' } },
-					{ data: { source: 'k', target: 'e' } },
-					{ data: { source: 'k', target: 'g' } },
-					{ data: { source: 'g', target: 'j' } }
-				]
-			},
-	 */
-
-
-	function graph__addNodeID($id, &$graph,$name=null,&$path,$parent=null) {
-		if (!array_key_exists($id, $graph->treeItems)) {
-			$graph->treeItems[$id]= true;
-			if(empty($name)) $name=$id;
-			if(!empty($path))  { $name=$name." ".implode(',', $path);// $path=array(); 
-			}
-			DEBUG_S(-3,'added id,name,path,parent',array($id,$name,$path,$parent),__FILE__,__FUNCTION__,__LINE__);
-
-
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$name));
-			if(!empty($parent)) $graph->elements->edges[] = array('data'=>array('source'=>$id, 'target'=>$parent ));
-			//echo "<br> w AddNode:";
-		}
-	}
-	
-	 
-	 function TestIfHasDeep($id_proces_step) {
-		 $sql="select `ID`,`IF_TRUE_GOTO` from `CRM_PROCES` where `PARENT_ID`=$id_proces_step and  `A_STATUS` in ('WAITING','NORMAL') ";
-		 $res=DB::query($sql);
-		 while($h=DB::fetch($res)) {
-			 $ret[$h->ID]='PARENT_ID';
-		 }
-		 
-		 $sql="select `ID`,`IF_TRUE_GOTO`,`IF_TRUE_GOTO_FLAG` from `CRM_PROCES` where `ID`=$id_proces_step and `IF_TRUE_GOTO`>0 and  `A_STATUS` in ('WAITING','NORMAL') ";
-		  $res=DB::query($sql);
-		  	while($h=DB::fetch($res)) {
-			 $ret[$h->IF_TRUE_GOTO]=$h->IF_TRUE_GOTO_FLAG;
-			 }
-		 return $ret;
-	 }
-	
-	 function SearchNextIf($id_proces_step,$path,$loop=0,&$graph) { //szukamy pierwszego rozwidlenia w gore
-		 $loop++;
-		 if($loop>1000) die('blad petli');
-		 $path[]=$id_proces_step;
-		 echo "<br> {$id_proces_step} sprawdzam 98";
-		 $next=TestIfHasDeep($id_proces_step);
-		 DEBUG_S(-3,"{$id_proces_step} Next detext",$next,__FILE__,__FUNCTION__,__LINE__);
-		 if(count($next)==1) { //pojedyncze chodzenie - wyplaszczamy
-			 echo "<br>{$id_proces_step} 87  count has ".count($next)."  i jade ".key($next);
-			 SearchNextIf(key($next),$path,$loop,$graph);
-		 } else if(count($next)>1) { //wiecej niz jeden wpis- sprawdzamy, czy nie ma pustych
-			 echo "<br>".$id_proces_step." count 90 has ".count($next);
-			 	$wyjsc=array();
-			 foreach($next as $nx=>$nx_type) {
-				 echo "<br> {$id_proces_step} 93 foreach next as nx:".$nx." type ".$nx_type;
-					 $next_=TestIfHasDeep($nx);
-					 if(count($next_)>0) $wyjsc[]=$nx ; else echo "<br> {$id_proces_step} ({$nx}) nie posiada wyjscia ";
-					 echo "<br>{$id_proces_step} Wyjsc 96: ".count($wyjsc);
-				 }
-			 echo "<br>{$id_proces_step} Wyjsc 98: ".count($wyjsc);
-
-			 if(count($wyjsc)==1) { 
-			     echo "<br> ".$id_proces_step." ma jedno wyjscie ({$wyjsc[0]}), idziemy nim dalej ";
-				 if($next[$wyjsc[0]]=='PARENT_ID') {
-				 SearchNextIf($wyjsc[0],$path,$loop,$graph);
-				 }
-			 } else if(count($wyjsc)==0) {
-				 echo "<br> {$id_proces_step} 118 dupa cnt".count($wyjsc);
-				 //return $path;
-			 } else { 
-			 
-			 	DEBUG_S(-3,"{$id_proces_step} wyjsc - dodaje punkt procesu",$wyjsc,__FILE__,__FUNCTION__,__LINE__);
-			 	foreach($wyjsc as $exit) {
-			 		graph__addNodeID($exit,$graph,$exit,$path,$path[0]);
-			 		if($next[$exit]=='PARENT_ID')
-			 			SearchNextIf($exit,$path,$loop,$graph);
-			 		else if($next[$exit]=='GOTO_AND_RETURN') {
-			 			echo "goto and return";
-			 			graph__addNodeID($exit,$graph,$exit,$path,$path[0]);
-			 			$path=array();
-			 		}
-			 	}
-//			 	die('inny przyp 99');
-			 }
-		 }	 else {
-			 echo "<br> {$id_proces_step} 111 else ";
-
-			DEBUG_S(-3,'path',$path,__FILE__,__FUNCTION__,__LINE__);
-
-
-
-			 graph__addNodeID($path[0],$graph,$path[0],$path,null);
-			// $graph->elements->nodes[] = array('data'=>array('id'=>100, 'name'=>100));
-			 //print_r($graph);	
-			 
-		 
-		 }
-		 
-		 
-	 }
-
-
-	 function SearchParentsWithExits($id_start,$id_proces_step,&$graph,$string,$loop=0,&$path_arr=array()) {
-		 		
-		 	SearchNextIf($id_proces_step,$path,0,$graph);
-
-		//		print_r($graph);	
-				
-
-				//print_r($path);
-//				graph__addNodeID($h->ID, $graph,$h->ID.' '.implode(',',$path));
-//				$graph->elements->edges[] = array('data'=>array('source'=>$id_proces_step, 'target'=>$h->ID, 'type'=>'GOTO'));
-				
-			//	SearchParentsWithExits($h->ID,$h->ID,&$graph,$string,&$loop,$path_arr);
-			
-	 }
-
-
-	$db = DB::getDB();
-	
-	$sql= "select p.`ID`,`DESC` from `CRM_PROCES` as p where  p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT' and ID=994 limit 1";
-	$res=DB::query($sql);
-	while($h=DB::fetch($res)) {
-		SearchParentsWithExits($h->ID,$h->ID,$graph,'Proces '.$h->ID,0);
-		//graph__addNodeID($h->ID, $graph);
-		graph__addNodeID('1', $graph,'1');
-
-	//	graph__addNodeID($h->ID, $graph,$h->ID);
-//		graph__addNodeID('100', $graph,'100');
-		//$graph->treeItems[$h->ID] = true;
-		//$graph->treeItems[101] = true;
-
-//		$graph->elements->nodes[] = array('data'=>array('id'=>$h->ID, 'name'=>$h->ID , 'type'=>'procesInit'));
-//		$graph->elements->nodes[] = array('data'=>array('id'=>101, 'name'=>101 , 'type'=>'procesInit'));
-//		$graph->elements->edges[] = array('data'=>array('source'=>994, 'target'=>101));
-
-
-	}
-	foreach($graph->elements->nodes as $var) {
-	//	echo "<br>\n NODE".$var[data][id];
-		$nodes[$var[data][id]]=$var[data][id];
-	}
-	foreach($graph->elements->edges as $var) {
-		echo "<br>\n".$var[data][source]." ".$var[data][target]." ";
-		if(isset($nodes[$var[data][source]])) echo "OK1"; else echo "FAIL1";
-		if(isset($nodes[$var[data][target]])) echo "OK2"; else echo "FAIL2";
-	}
-
-	DEBUG_S(-3,'nodes',$graph->elements->nodes);
-	DEBUG_S(-3,'edges',$graph->elements->edges);
-/*		
-	$sql = "select p.`ID`, p.`PARENT_ID`
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-	";
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeFlat[$r->PARENT_ID] []= $r->ID;
-	}
-
-	$sql = "select p.`IF_TRUE_GOTO` as ID, p.`ID` as PARENT_ID
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-				and p.IF_TRUE_GOTO>0
-		--		and p.IF_TRUE_GOTO_FLAG='GOTO_AND_RETURN'
-	";
-	
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeGoto[$r->PARENT_ID] []= $r->ID;
-	}
-
-
-	function createGraphRec($id, $tree, &$graph, $lvl = 0) {
-		$graph->treeItems[$id] = true;
-		settype($id, 'string');
-		if ($id == 3122) {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'type'=>'procesInit', 'lvl'=>$lvl));
-		} else {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'lvl'=>$lvl));
-		}
-
-		if ($lvl > 1) {
-		//	return;
-		}
-
-		if (!empty($tree[$id])) {
-			foreach ($tree[$id] as $vChildID) {
-				$graph->elements->edges[] = array('data'=>array('source'=>$id, 'target'=>$vChildID));
-				createGraphRec($vChildID, $tree, $graph, $lvl + 1);
-			}
-		}
-	}
-
-	createGraphRec($id_proces, $graph->procesTreeFlat, $graph);
-
-*/
-/*
-	// addGraphGoto
-	foreach ($graph->procesTreeGoto as $kID => $vGotoIds) {
-		//$graph->treeItems[$id] = true;
-		if (array_key_exists($kID, $graph->treeItems)) {
-			foreach ($vGotoIds as $vGotoID) {
-				graph__addNodeID($vGotoID, $graph);
-				$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-			}
-		} else {
-			foreach ($vGotoIds as $vGotoID) {
-				if (array_key_exists($vGotoID, $graph->treeItems)) {
-//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("TODO: add node ($kID); add edge from $kID to $vGotoID");echo'</pre>';
-					graph__addNodeID($kID, $graph);
-					//$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-				}
-			}
-		}
-	}
-*/
-?>
-<style type="text/css">
-#<?php echo $graph->htmlID; ?>_wrap {
-	position:relative;
-	width:1100px;
-	margin:0 auto;
-	border:1px solid #ccc;
-}
-#<?php echo $graph->htmlID; ?> {
-	height:560px;
-	border-bottom:1px solid #ccc;
-}
-#<?php echo $graph->htmlID; ?>_info {
-	padding:3px;
-}
-#<?php echo $graph->htmlID; ?>_wrap .actions { position:absolute; top:20px; left:-40px; margin:0; padding:0; list-style:none; }
-#<?php echo $graph->htmlID; ?>_wrap .actions button { border-radius:0; background:#fff; border:1px solid #ccc; }
-</style>
-
-<script src="./stuff/cytoscape.js/arbor.js"></script>
-<script src="./stuff/cytoscape.js/cytoscape.js"></script>
-<script>
-jQuery(loadInfo = function(nodeID){
-	$.ajax({
-		url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&HEADER_NOT_INIT=YES',
-		type: 'GET',
-		dataType: 'text',
-		data: '',
-		async: true,
-		success: function (data) {
-			jQuery('#<?php echo $graph->htmlID; ?>_info').html(data);
-		},
-		error: function (err) {
-			console.log('err');
-		}
-	});
-});
-jQuery(loadCy = function(){
-	jQuery('#<?php echo $graph->htmlID; ?>').cytoscape({
-		layout: {
-			name: 'arbor'
-		},
-		style: cytoscape.stylesheet()
-			.selector('node')
-				.css({
-					'shape': 'rectangle',
-					'width': '464px', 'height': '26px',
-					'font-size': '10px',
-					'content': 'data(name)',
-					'text-valign': 'center',
-					'color': 'white',
-					'text-outline-width': 2,
-					'text-outline-color': '#888'
-				})
-			.selector('edge')
-				.css({
-					'target-arrow-shape': 'triangle'
-				})
-			.selector(':selected')
-				.css({
-					'background-color': 'black',
-					'line-color': 'black',
-					'target-arrow-color': 'black',
-					'source-arrow-color': 'black'
-				})
-			.selector('.faded')
-				.css({
-					'opacity': 0.25,
-					'text-opacity': 0
-				})
-			.selector('edge.neighborhood')
-				.css({
-					'background-color': 'blue',
-					'color': 'orange'
-				})
-			.selector('node.procesInit')
-				.css({
-					'background-color': 'red',
-					'text-outline-color': 'red',
-					'font-weight': 'bold'
-				}),
-
-		elements: <?php echo json_encode($graph->elements); ?>,
-
-		ready: function(){
-			var cy = this;
-			window.cy_<?php echo $graph->htmlID; ?> = this;
-
-			cy.elements("node[type = 'procesInit']").addClass('procesInit');
-			cy.elements("node[lvl > 1]").hide();
-
-			cy.elements().unselectify();
-
-			cy.on('tap', 'node', function(e){
-				//console.log('on tap node', e)
-				var node = e.cyTarget;
-				var neighborhood = node.neighborhood().add(node);
-
-				var nodeID = node.id();
-				loadInfo(nodeID);
-
-				cy.elements().addClass('faded').unselect();
-				neighborhood.removeClass('faded');
-				node.select();
-
-				cy.edges().removeClass('neighborhood');
-				node.connectedEdges().addClass('neighborhood');
-
-				neighborhood.show();
-
-				cy.center(neighborhood);
-			});
-
-			cy.on('tap', function(e){
-				if (e.cyTarget === cy){
-					cy.elements().removeClass('faded');
-				}
-			});
-		},
-		showOverlay: false
-	});
-});
-
-jQuery(document).ready(function(){
-	loadCy();
-
-	var parent = $('#<?php echo $graph->htmlID; ?>')
-		.parent()
-	parent.find('.actions .cy-refresh')
-		.on('mousedown touchstart', function(){
-			loadCy();
-
-			cy.attr('style', '');
-		});
-	parent.find('.actions .cy-zoom-plus')
-		.on('mousedown touchstart', function(){
-			window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() + 0.1);
-		});
-  parent.find('.actions .cy-zoom-minus')
-		.on('mousedown touchstart', function(){
-			window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() - 0.1);
-		});
-});
-</script>
-
-<div id="<?php echo $graph->htmlID; ?>_wrap">
-	<div id="<?php echo $graph->htmlID; ?>"></div>
-	<div id="<?php echo $graph->htmlID; ?>_info"></div>
-	<ul class="actions">
-		<li><button class="btn cy-refresh"><i title="Refresh" class="ico-refresh"></i></button></li>
-		<li><button class="btn cy-zoom-plus"><i title="Zoom +" class="ico-plus"></i></button></li>
-		<li><button class="btn cy-zoom-minus"><i title="Zoom -" class="ico-minus"></i></button></li>
-	</ul>
-</div>
-
-<?php
-}

+ 0 - 350
SE/superedit-GRAPH_VIEW_PROCES.old.php

@@ -1,350 +0,0 @@
-<?php
-
-
-function GRAPH_VIEW_PROCES() {
-	$id_proces = V::get('id_proces', '', $_REQUEST, 'int');
-	if ($id_proces <= 0) {
-		echo'<p class="err box box-red">'."Wrong ID".'</p>';
-		return;
-	}
-
-	$db = DB::getDB();
-	$proces = $db->get_by_id('CRM_PROCES', $id_proces);
-	if (!$proces) {
-		echo'<p class="err box box-red">'."Process {$id_proces} not exists".'</p>';
-		return;
-	}
-
-	$ajaxTask = V::get('ajaxTask', '', $_REQUEST);
-	if ($ajaxTask == 'getInfo') {
-		$id = V::get('id', 0, $_REQUEST, 'int');
-		if ($id > 0) {
-			$step = $db->get_by_id('CRM_PROCES', $id);
-			//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($step);echo'</pre>';
-			?>
-			<p><code><?php echo $step->ID; ?></code> <?php echo $step->DESC; ?></p>
-			<p><?php echo $step->OPIS; ?></p>
-			<?php
-		}
-		exit;
-	}
-
-	$graph = new stdClass();
-	$graph->htmlID = 'graph_proces_id_' . $id_proces;
-	$graph->procesTreeFlat = array();
-	$graph->procesTreeGoto = array();
-	$graph->treeItems = array();
-
-	$graph->elements = new stdClass();
-	$graph->elements->nodes = array();
-	$graph->elements->edges = array();
-	/*	elements: {
-				nodes: [
-					{ data: { id: 'j', name: 'Jerry' } },
-					{ data: { id: 'e', name: 'Elaine' } },
-					{ data: { id: 'k', name: 'Kramer' } },
-					{ data: { id: 'g', name: 'George' } }
-				],
-				edges: [
-					{ data: { source: 'j', target: 'e' } },
-					{ data: { source: 'j', target: 'k' } },
-					{ data: { source: 'j', target: 'g' } },
-					{ data: { source: 'e', target: 'j' } },
-					{ data: { source: 'e', target: 'k' } },
-					{ data: { source: 'k', target: 'j' } },
-					{ data: { source: 'k', target: 'e' } },
-					{ data: { source: 'k', target: 'g' } },
-					{ data: { source: 'g', target: 'j' } }
-				]
-			},
-	 */
-
-
-	function graph__addNodeID($id, $graph,$name=null) {
-		if (!array_key_exists($id, $graph->treeItems)) {
-			if(empty($name)) $name=$id;
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id));
-		}
-	}
-
-
-	 function SearchParentsWithExits($id_start,$id_proces_step,&$graph,$string,$loop=0,&$path_arr=array()) {
-
-	graph__addNodeID('994', $graph,'994');
-	graph__addNodeID('3468', $graph,'3468');
-
-		 return ;
-
-		 		$loop++;
-		 if($loop>100) { return false;
-		 				  die('error loop');
-		 }
-		$sql="select `ID`,`IF_TRUE_GOTO`,`TYPE`,`PARENT_ID` from `CRM_PROCES` where PARENT_ID=994 and `A_STATUS` in ('WAITING','NORMAL') "	;
-		$res=DB::query($sql);
-		if(DB::num_rows($res) >0) {
-			while($h=DB::fetch($res)) {	
-				$path_arr[$h->ID]=true;
-				$string.=" \n".$h->ID;
-				
-			//
-			//	$graph->elements->edges[] = array('data'=>array('source'=>$id_proces_step, 'target'=>$h->ID, 'type'=>'GOTO'));
-				
-			//	SearchParentsWithExits($h->ID,$h->ID,&$graph,$string,&$loop,$path_arr);
-				
-			}	
-		}
-	 }
-
-
-	$db = DB::getDB();
-	
-	$sql= "select p.`ID`,`DESC` from `CRM_PROCES` as p where  p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT' and ID=994 limit 1";
-	$res=DB::query($sql);
-	while($h=DB::fetch($res)) {
-		SearchParentsWithExits($h->ID,$h->ID,$graph,'Proces '.$h->ID,0);
-	
-	 //   graph__addNodeID(995,$graph,995);	
-	   // graph__addNodeID(3468, $graph,3468);
-		//$graph->treeItems[$h->ID] = true;
-		//$graph->elements->nodes[] = array('data'=>array('id'=>$h->ID, 'name'=>$h->ID.substr($h->DESC,0,50) , 'type'=>'procesInit'));
-	}
-		echo 'dupaxxx';
-
-	foreach($graph->elements->nodes as $var) {
-		//echo "<br>\n".$var[data][id];
-		$nodes[$var[data][id]]=$var[data][id];
-	}
-	foreach($graph->elements->edges as $var) {
-		echo "<br>\n".$var[data][source]." ".$var[data][target]." ";
-		if(isset($nodes[$var[data][source]])) echo "OK1"; else echo "FAIL1";
-		if(isset($nodes[$var[data][target]])) echo "OK2"; else echo "FAIL2";
-	}
-
-	DEBUG_S(-3,'nodes',$graph->elements->nodes);
-	DEBUG_S(-3,'edges',$graph->elements->edges);
-	DEBUG_S(-3,'edges',$graph);
-
-/*		
-	$sql = "select p.`ID`, p.`PARENT_ID`
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-	";
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeFlat[$r->PARENT_ID] []= $r->ID;
-	}
-
-	$sql = "select p.`IF_TRUE_GOTO` as ID, p.`ID` as PARENT_ID
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-				and p.IF_TRUE_GOTO>0
-		--		and p.IF_TRUE_GOTO_FLAG='GOTO_AND_RETURN'
-	";
-	
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeGoto[$r->PARENT_ID] []= $r->ID;
-	}
-
-
-	function createGraphRec($id, $tree, &$graph, $lvl = 0) {
-		$graph->treeItems[$id] = true;
-		settype($id, 'string');
-		if ($id == 3122) {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'type'=>'procesInit', 'lvl'=>$lvl));
-		} else {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'lvl'=>$lvl));
-		}
-
-		if ($lvl > 1) {
-		//	return;
-		}
-
-		if (!empty($tree[$id])) {
-			foreach ($tree[$id] as $vChildID) {
-				$graph->elements->edges[] = array('data'=>array('source'=>$id, 'target'=>$vChildID));
-				createGraphRec($vChildID, $tree, $graph, $lvl + 1);
-			}
-		}
-	}
-
-	createGraphRec($id_proces, $graph->procesTreeFlat, $graph);
-
-*/
-/*
-	// addGraphGoto
-	foreach ($graph->procesTreeGoto as $kID => $vGotoIds) {
-		//$graph->treeItems[$id] = true;
-		if (array_key_exists($kID, $graph->treeItems)) {
-			foreach ($vGotoIds as $vGotoID) {
-				graph__addNodeID($vGotoID, $graph);
-				$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-			}
-		} else {
-			foreach ($vGotoIds as $vGotoID) {
-				if (array_key_exists($vGotoID, $graph->treeItems)) {
-//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("TODO: add node ($kID); add edge from $kID to $vGotoID");echo'</pre>';
-					graph__addNodeID($kID, $graph);
-					//$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-				}
-			}
-		}
-	}
-*/
-?>
-<style type="text/css">
-#<?php echo $graph->htmlID; ?>_wrap {
-	position:relative;
-	width:1100px;
-	margin:0 auto;
-	border:1px solid #ccc;
-}
-#<?php echo $graph->htmlID; ?> {
-	height:560px;
-	border-bottom:1px solid #ccc;
-}
-#<?php echo $graph->htmlID; ?>_info {
-	padding:3px;
-}
-#<?php echo $graph->htmlID; ?>_wrap .actions { position:absolute; top:20px; left:-40px; margin:0; padding:0; list-style:none; }
-#<?php echo $graph->htmlID; ?>_wrap .actions button { border-radius:0; background:#fff; border:1px solid #ccc; }
-</style>
-
-<script src="./stuff/cytoscape.js/arbor.js"></script>
-<script src="./stuff/cytoscape.js/cytoscape.js"></script>
-<script>
-jQuery(loadInfo = function(nodeID){
-	$.ajax({
-		url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&HEADER_NOT_INIT=YES',
-		type: 'GET',
-		dataType: 'text',
-		data: '',
-		async: true,
-		success: function (data) {
-			jQuery('#<?php echo $graph->htmlID; ?>_info').html(data);
-		},
-		error: function (err) {
-			console.log('err');
-		}
-	});
-});
-jQuery(loadCy = function(){
-	jQuery('#<?php echo $graph->htmlID; ?>').cytoscape({
-		layout: {
-			name: 'arbor'
-		},
-		style: cytoscape.stylesheet()
-			.selector('node')
-				.css({
-					'shape': 'rectangle',
-					'width': '464px', 'height': '26px',
-					'font-size': '10px',
-					'content': 'data(name)',
-					'text-valign': 'center',
-					'color': 'white',
-					'text-outline-width': 2,
-					'text-outline-color': '#888'
-				})
-			.selector('edge')
-				.css({
-					'target-arrow-shape': 'triangle'
-				})
-			.selector(':selected')
-				.css({
-					'background-color': 'black',
-					'line-color': 'black',
-					'target-arrow-color': 'black',
-					'source-arrow-color': 'black'
-				})
-			.selector('.faded')
-				.css({
-					'opacity': 0.25,
-					'text-opacity': 0
-				})
-			.selector('edge.neighborhood')
-				.css({
-					'background-color': 'blue',
-					'color': 'orange'
-				})
-			.selector('node.procesInit')
-				.css({
-					'background-color': 'red',
-					'text-outline-color': 'red',
-					'font-weight': 'bold'
-				}),
-
-		elements: <?php echo json_encode($graph->elements); ?>,
-
-		ready: function(){
-			var cy = this;
-			window.cy_<?php echo $graph->htmlID; ?> = this;
-
-			cy.elements("node[type = 'procesInit']").addClass('procesInit');
-			cy.elements("node[lvl > 1]").hide();
-
-			cy.elements().unselectify();
-
-			cy.on('tap', 'node', function(e){
-				//console.log('on tap node', e)
-				var node = e.cyTarget;
-				var neighborhood = node.neighborhood().add(node);
-
-				var nodeID = node.id();
-				loadInfo(nodeID);
-
-				cy.elements().addClass('faded').unselect();
-				neighborhood.removeClass('faded');
-				node.select();
-
-				cy.edges().removeClass('neighborhood');
-				node.connectedEdges().addClass('neighborhood');
-
-				neighborhood.show();
-
-				cy.center(neighborhood);
-			});
-
-			cy.on('tap', function(e){
-				if (e.cyTarget === cy){
-					cy.elements().removeClass('faded');
-				}
-			});
-		},
-		showOverlay: false
-	});
-});
-
-jQuery(document).ready(function(){
-	loadCy();
-
-	var parent = $('#<?php echo $graph->htmlID; ?>')
-		.parent()
-	parent.find('.actions .cy-refresh')
-		.on('mousedown touchstart', function(){
-			loadCy();
-
-			cy.attr('style', '');
-		});
-	parent.find('.actions .cy-zoom-plus')
-		.on('mousedown touchstart', function(){
-			window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() + 0.1);
-		});
-  parent.find('.actions .cy-zoom-minus')
-		.on('mousedown touchstart', function(){
-			window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() - 0.1);
-		});
-});
-</script>
-
-<div id="<?php echo $graph->htmlID; ?>_wrap">
-	<div id="<?php echo $graph->htmlID; ?>"></div>
-	<div id="<?php echo $graph->htmlID; ?>_info"></div>
-	<ul class="actions">
-		<li><button class="btn cy-refresh"><i title="Refresh" class="ico-refresh"></i></button></li>
-		<li><button class="btn cy-zoom-plus"><i title="Zoom +" class="ico-plus"></i></button></li>
-		<li><button class="btn cy-zoom-minus"><i title="Zoom -" class="ico-minus"></i></button></li>
-	</ul>
-</div>
-
-<?php
-}

+ 373 - 468
SE/superedit-GRAPH_VIEW_PROCES.php

@@ -1,271 +1,60 @@
 <?php
 
-class crm_proces_paser {
-
-  // var $this->get_proces_init=array();
-
- // [proces_init]  - A
- //    [step]      - flat 0
- //    [step]      - flat 3 , tree 2 , cut
- //     [step]     - flat 0 , tree 0
- //     [step]     - flat 1 , tree 1
- //       [step]   - flat 1 , tree 1
- //         [step] - flat 0 , tree 0
- //     [step]     - flat 1 , tree 1
- //       [step]   - flat 0 , tree 0
- 
-
-
-   
-   //funckcja do szukania proces_init
-   function get_proces_init($id_proces) {
-	$sql= "select p.`ID`,p.`DESC` from `CRM_PROCES` as p 
-	   LEFT JOIN _CRM_PROCES_INIT_STATS AS cs ON cs.ID = p.ID
-	where  p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT' 
-	and (cs.`path` like '%/".$id_proces."/%' or cs.`path` like '%/".$id_proces."'  or cs.`path` like '".$id_proces."/%' ) 
-	";
-//	echo $sql;
-	$res=DB::query($sql);
-		while($h=DB::fetch($res)) {
-			$this->get_proces_init[]=$h->ID;
-		}
-		return $this->get_proces_init;
-	
-   }
-
-   function build_proces_init_tree($id_proces) {
-	  // $tree->Childs[$id_proces]=true;
-	   $tree->Childs[$id_proces]->PARENT=0;
-	   $tree->Childs[$id_proces]->SOURCE='build_tree_for_proces';
-
-	   $tree->Parents[0]->CHILD[$id_proces]=$id_proces;
-	   $obj=DB::get_by_id('CRM_PROCES',$id_proces);
-	   $tree->Childs[$id_proces]->TYPE=$obj->TYPE;
-	 //  echo "here".$id_proces;
-	   self::build_tree_for_proces($tree,$id_proces,$id_proces);
-	   return $tree;
-   }
-   
-      function build_tree_for_proces(&$tree,$cursor,$init_once=null) {
-		  	   if(!empty($init_once)) $sql_or=" or ID={$init_once} "; else $sql_or="";
-	      	   $sql="select `ID`,`IF_TRUE_GOTO`,`IF_TRUE_GOTO_FLAG` , `TYPE` from `CRM_PROCES` where ( PARENT_ID={$cursor} {$sql_or} ) and  `A_STATUS` in ('WAITING','NORMAL')";
-		  	 //  echo "<br>sql: ".$sql;
-	      	   $res=DB::query($sql);
-	      	   	      	   while ($h=DB::fetch($res)) {
-	      	   	 if(empty($init_once))  $tree->Childs[$h->ID]->PARENT=$cursor; //wyzwolenie tylko pozniejsze
-	      	   	  if(empty($init_once))  $tree->Parents[$cursor]->CHILD[$h->ID]=$h->ID;
-		  	   	   $tree->Childs[$h->ID]->TYPE=$h->TYPE;
-		  	   	   $tree->Childs[$h->ID]->SOURCE='build_tree_for_proces';
-
-
-	      	   	   if($h->IF_TRUE_GOTO>0) { 
-	      	   	      $tree->Childs[$h->ID]->GOTO_FLAG=$h->IF_TRUE_GOTO_FLAG;
-	      	   	      $tree->Childs[$h->ID]->IF_TRUE_GOTO=$h->IF_TRUE_GOTO;
-	      	   	      $tree->Childs[$h->IF_TRUE_GOTO]->IS_EXECUTED_BY[$h->ID]=$h->ID;
-	      	   	   }
-		      	   self::build_tree_for_proces($tree,$h->ID,null);
-	      	   }
-      }
-
-      function build_tree_flat_info(&$tree,$flat) {
-		  /* >> zbudowanie ile ma dzieci <<
-			  $tree->Childs[3208] => stdClass Object
-			  (
-            [PARENT] => 3123
-            [CHILD] => Array
-                (
-             >>       [3219] => 1 <<
-             >>       [3237] => 0 <<
-             >>       [3209] => 0 <<
-                 
-			 */
-	      foreach($tree->Childs as $id=>$obj) {
-			  //sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
-		      foreach($tree->Parents[$id]->CHILD as $child) {
-			      $tree->Childs[$id]->CHILD[$child]=count($tree->Parents[$child]->CHILD);     
-		      }
-	      }    
-      }
-      
-      
-      function detect_tree_where_to_detail_cut(&$tree,$flag_not_to_cut=null) {
-	       foreach($tree->Childs as $id=>$obj) {
-			  //sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
-			  $control=0;
-		      foreach($obj->CHILD as $child) {
-			      if($child>0) $control++;   
-		      }
-		      if(empty($flag_not_to_cut)) {
-		       
-		       if($control>1) $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true;  //przeciecie jezeli jest wiecej wyjsc niz jedno z zaglebieniami
-		        //przeciecie, jezeli jest wyjscie z kroku procesu do innego 
-		        if(isset($tree->Childs[$id]->GOTO_FLAG)) $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true;
-		        //trzeba zbadac tez czy nie jest do niego dowiazywany w jakims miejscu proces
-		         if(isset($tree->Childs[$id]->IS_EXECUTED_BY)) { $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true;
-		         //echo "<br> Is executed by CUT!";
-		         }
-
-		       } else $tree->Childs[$id]->NO_CUT_FLAG=true;
-	      }       
-      }
-      function search_parent_ids_till_cut(&$tree,$init,&$find) {
-      //szukam lancuchow do optymalizacji do miejsca flagi CUT, kojarzac od razu linki
-	     	if(isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
-		    	//if(!empty($find))
-		    	//if($init==2444)
-		    	  self::zoom_process_links($tree,$init,$init); 
-			}
-//			$tree->Viev_Zpc_Parent_cut[$init]=$find[0];
-	        if(!isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
-				  
-	      		  $find[]=$init;
-		  		  self::zoom_process_links($tree,$init,$find[0]);
-		      foreach($tree->Childs[$init]->CHILD as $id=>$count) {
-			      self::search_parent_ids_till_cut($tree,$id,$find);
-		      }
-	      } //else
-	     // return $find;
-      }
-      
-      function zoom_process_links($tree,$id,$root_id) {
-      	//dobudowuje znaczniki dotyczace LINKOW oraz brakujace ID z tym zwiazane
-	      //echo "<br>testuje zoom dla ".$id." root:".$root_id;
-
-	      if(isset($tree->Childs[$id]->GOTO_FLAG)) {
-					  	if(isset( $tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO])) {
-						  	//adding internal link to the same process
-						  	//TODO trzeba przemyslec, czy dowiazywac linki do zagregowanych krokow, czy trzeba robic cut w tych miejscach - na ten moment domyslnie CUT
-//						  	if(empty($tree->Childs[$id]->NO_CUT_FLAG)) //tylko linki zewnetrzne jak flaga NOCUT!
-						  	//echo "... dodaje 218:  ".$tree->Childs[$id]->IF_TRUE_GOTO;
-						  	if(isset($tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO]->SOURCE)) {
-						  		$tree->Viev_Zpc[$root_id]->INTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
-						  		//echo "dodalem Linka dla ".$root_id;
-						  	} else { //echo "To jest link external - bo referencyjny ID{$tree->Childs[$id]->IF_TRUE_GOTO}nie byl w procesie";
-
-						  		$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
-						  	}
-						  	
-					  	} else { //echo "<br>Links zewnetrzny do ".$id." - ".$tree->Childs[$id]->IF_TRUE_GOTO;
-					  		$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
-					  		//$tree->Viev_Zpc_found[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO; //zeby tego rekordu nie przetwarzal ? TODO ?
-					  		$obj=DB::get_by_id('CRM_PROCES',$tree->Childs[$id]->IF_TRUE_GOTO);
-					  		$tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->DESC="{".$obj->ID."}".substr($obj->DESC,0,50);
-					  		if($tree->Childs[$id]->GOTO_FLAG=='GOTO_AND_RETURN') {	 //dodanie zwrotnej strzalki TODO dac inny typ strzalki!!
-					  		 $tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->EXTERNAL_LINK[$root_id]=$root_id;
-					  		 //echo "<br> GOTO_AND_RETURN!!!".$tree->Childs[$id]->IF_TRUE_GOTO." -- ".$root_id;
-					  		}
-					  		
-					  	}
-				  	} 
-
-	      
-      }
-      
-      function build_path_zoom_proces_cut(&$tree,$init,$path_zpc=array()) {
-	      //funkcja do pokazania procesow wyplaszczonych, z wypunktowanymi rozgalezieniami - buduje drzewo w sposob inteligentny
-		  //szukam rekordow z gory do pierwszego CUT
-		  foreach($tree->Childs as $id=>$obj) {
-		  		if(!isset($tree->Viev_Zpc_found[$id])) {
-			  		//echo "<br>szukam parentow dla ".$id;
-				  	self::search_parent_ids_till_cut($tree,$id,$find);
-			//	  	echo "<br>find:238 for id {$id} ".implode(',', $find)." EOL. ";
-				  	if(empty($find))  { //echo " - Find empty for ".$id."  adding ".$tree->Childs[$id]->PARENT;
-					  	//trzeba przeskanowac w find jest dany parent -> Viev_Zpc_found
-					  	//	if(isset($tree->Childs[$id]->PARENT))
-					  	//		$tree->Viev_Zpc_Parent[$id]=$tree->Childs[$id]->PARENT;
-				  	}
-				  	foreach($find as $find_id) {
-				  		$tree->Viev_Zpc_found[$find_id]=$find[0];
-				  		if($find_id<>$find[0]) $tree->Viev_Zpc_Parent[$find_id]=$find[0]; //todo moze byc to z bledem jak nadrzedny bedzie zbitym ciagiem
-				  		else $tree->Viev_Zpc_Parent[$find_id]=$tree->Childs[$find_id]->PARENT;
-				  	}
-				  	$tree->Viev_Zpc[$id]->PATH=$find;
-				  	//wykrycie parenta polega na znalezieniu jego naturalnego parenta i poszukaniu w ktorej jest grupie
-				  	//$tree->Viev_Zpc[$id]->PARENT=$tree->Viev_Zpc_Parent[$tree->Childs[$id]->PARENT]  ;
-				  	$obj=DB::get_by_id('CRM_PROCES',$id);
-				  	$tree->Viev_Zpc[$id]->DESC="{".$id."}".substr($obj->DESC,0,50)."...";
-				  					  	unset($find);
-			  	}
-			  	
-		  	
-		  }
-		  		//parenty trzeba zrobic za drugim rzutem
-			  	foreach($tree->Viev_Zpc as $id=>$obj) {
-			 // 		echo "<br>256 wykrywam parenta dla {$id}";
-				  				    {
-					  	//skanujemy wszystkie rekordy w Viev_Zpc w celu znalezienia czy danego ID parent nie jest w ktoryms z ID - tego szukamy
-					  if(!isset($obj->PARENT)) //tylko dla tych ktore nie maja parentow
-					  	foreach($tree->Viev_Zpc as $id_=>$obj_) {
-						  	if(isset($tree->Childs[$id_]->SOURCE))
-						  	if(in_array($tree->Childs[$id]->PARENT, $obj_->PATH)) {
-						  	//	echo "<br>206 Skanuje dla brakujacego parenta dla ".$id." i znalazlem".$id_;
-						  		$tree->Viev_Zpc[$id]->PARENT=$id_;
-						  	} //else  echo "<br>&nbsp;&nbsp;   199: nie znalazlem w ".$id_." path:".implode(',', $obj_->PATH);
-					  	}
-					  	
-					  if(!isset($tree->Viev_Zpc[$id]->PARENT)) { //jezeli nie znaleziono ta metoda to znaczy ze parent jest naturalny
-						  $tree->Viev_Zpc[$id]->PARENT=$tree->Childs[$id]->PARENT;
-						//  echo " - 204 ustawilem ostatecznie ".$tree->Childs[$id]->PARENT;
-					  }
-					  	
-				  	}
-				  	
-			  	}
-		  
-		  	      
-      }
-      
-      
-}	 
-
-
 function GRAPH_VIEW_PROCES() {
 	$id_proces = V::get('id_proces', '', $_REQUEST, 'int');
-//	$id_proces = $_REQUEST['id_proces'];
-	//TOOD bug funkcji V nie mozna dac INT=0!!!
-//	if (empty($id_proces)) {
-//		echo'<p class="err box box-red">'."Wrong ID".'</p>';
-//		return;
-//	}
+	$id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
 
 	$db = DB::getDB();
-	//$proces = $db->get_by_id('CRM_PROCES', $id_proces);
-	//if (empty($proces)) {
-	//	echo'<p class="err box box-red">'."Process {$id_proces} not exists".'</p>';
-	//	return;
-	//}
 
 	$ajaxTask = V::get('ajaxTask', '', $_REQUEST);
 	if ($ajaxTask == 'getInfo') {
 		$id = V::get('id', 0, $_REQUEST, 'int');
+		$id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
+
 		if ($id > 0) {
-			//TODO najlepiej wyslac to od razu w jsonie i przekazac jakos do uzycia do wykresu!
 			$step = $db->get_by_id('CRM_PROCES', $id);
-						 $cp=new crm_proces_paser;
-						 $tree=$cp->build_proces_init_tree($id);
-						 $cp->build_tree_flat_info($tree,null);
-						 $cp->detect_tree_where_to_detail_cut($tree);
-						 $cp->build_path_zoom_proces_cut($tree,$id);
-
-
+			$cp = new GraphViewProcessParser();
+			$tree = $cp->build_proces_init_tree($id);
+			$cp->build_tree_flat_info($tree, null);
+			$cp->detect_tree_where_to_detail_cut($tree);
+			$cp->build_path_zoom_proces_cut($tree, $id);
 
-			//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($step);echo'</pre>';
 			?>
-			<?php if($step->TYPE=='PROCES_INIT') echo "<a href=?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces={$step->PARENT_ID}&PROCES_INIT_SCAN=1>Widok mapy {$step->PARENT_ID}</a>"; ?>
-			<p><code><?php echo "<a href=?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces={$id}>".$step->ID."</a> - ".$step->DESC; ?></code> <?php echo $step->DESC; ?></p>
+			<?php if ($step->TYPE == 'PROCES_INIT') : ?>
+				<a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $step->PARENT_ID; ?>&PROCES_INIT_SCAN=1">Widok mapy <?php echo $step->PARENT_ID; ?></a>
+			<?php endif; ?>
+			<?php if (empty($_REQUEST['RESOURCES'])) : ?>
+				<a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $step->PARENT_ID; ?>&PROCES_INIT_SCAN=1&RESOURCES=1&id_zasob=<?php echo $id_zasob; ?>"> | mapa z zasobami</a>
+			<?php endif; ?>
+			<p>
+				<span style="color:red">
+					<a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id; ?>"><?php echo $step->ID; ?></a>
+					- <?php echo $step->DESC; ?> <?php echo $step->DESC; ?>
+				</span>
+				| <a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id; ?>&RESOURCES=1&id_zasob=<?php echo $id_zasob; ?>"> widok procesu z zasobami </a>
+			</p>
 			<p><?php echo $step->OPIS; ?></p>
-			 	<?php foreach ($tree->Viev_Zpc[$id]->PATH as $ind=>$id_include) {
-			 					if($ind==0) continue; //pierwszy wiersz wyswietlony wyzej
-				 				$step = $db->get_by_id('CRM_PROCES', $id_include);
-				 			    echo "<p><b>".$step->ID."</a> - ".$step->DESC."</b> <font size=-3>".$step->OPIS."</font></p>";
-				 			 } ?>
+				<?php foreach ($tree->Viev_Zpc[$id]->PATH as $ind=>$id_include) : ?>
+					<?php if ($ind == 0) continue; //pierwszy wiersz wyswietlony wyzej ?>
+					<?php $step = $db->get_by_id('CRM_PROCES', $id_include); ?>
+					<p><b><?php echo $step->ID; ?></a> - <?php echo $step->DESC; ?></b> <font size="-3"><?php echo $step->OPIS; ?></font></p>
+				<?php endforeach; ?>
 			<?php
 		}
+		else {//zasob
+			$id = V::get('id', 0, $_REQUEST);
+			if ($id[0] == 'Z') {
+				Lib::loadClass('ProcesHelper');
+				$zasob = ProcesHelper::getZasobInfo(4975);
+				echo "Zasob: [".$zasob->ID."], Typ: ".$zasob->TYPE.", Nazwa: ".$zasob->DESC." (".$zasob->DESC_PL.")<br>".$zasob->OPIS;
+				echo "<hr> Nadrzędny: Zasob: [".$zasob->P__ID."] , Typ: ".$zasob->P__TYPE.", Nazwa: ".$zasob->P__DESC." (".$zasob->P__DESC_PL.")<br>".$zasob->P__OPIS;
+			}
+		}
 		exit;
 	}
 
 	$graph = new stdClass();
-	$graph->htmlID = 'graph_proces_id_' . $id_proces;
+	$graph->htmlID = "graph_proces_id_{$id_proces}";
 	$graph->procesTreeFlat = array();
 	$graph->procesTreeGoto = array();
 	$graph->treeItems = array();
@@ -273,241 +62,137 @@ function GRAPH_VIEW_PROCES() {
 	$graph->elements = new stdClass();
 	$graph->elements->nodes = array();
 	$graph->elements->edges = array();
-	/*	elements: {
-				nodes: [
-					{ data: { id: 'j', name: 'Jerry' } },
-					{ data: { id: 'e', name: 'Elaine' } },
-					{ data: { id: 'k', name: 'Kramer' } },
-					{ data: { id: 'g', name: 'George' } }
-				],
-				edges: [
-					{ data: { source: 'j', target: 'e' } },
-					{ data: { source: 'j', target: 'k' } },
-					{ data: { source: 'j', target: 'g' } },
-					{ data: { source: 'e', target: 'j' } },
-					{ data: { source: 'e', target: 'k' } },
-					{ data: { source: 'k', target: 'j' } },
-					{ data: { source: 'k', target: 'e' } },
-					{ data: { source: 'k', target: 'g' } },
-					{ data: { source: 'g', target: 'j' } }
-				]
-			},
-	 */
-
-
-	function graph__addNodeID($id, &$graph,$name=null,$path,$parent=null,$type) {
+
+	function graph__addNodeID($id, &$graph, $name = null, $path, $parent = null, $type, $once = null) {
 		if (!array_key_exists($id, $graph->treeItems)) {
-			$graph->treeItems[$id]= true;
-			if(empty($name)) $name=$id;
-			if(!empty($path))  { $name=$name." ".implode(',', $path);// $path=array(); 
+			$graph->treeItems[$id] = true;
+			if (empty($name)) $name = $id;
+			if (!empty($path)) {
+				$name = $name . " " . implode(',', $path);
 			}
-			//DEBUG_S(-3,'added id,name,path,parent',array($id,$name,$path,$parent),__FILE__,__FUNCTION__,__LINE__);
-
-			if($type=='PROCES_INIT') $type_init='procesInit'; else $type_init=null;
-			//echo $type_init.$id;
-			$graph->elements->nodes[] = array('data'=>array('id'=>"".$id."", 'name'=>$name , 'type'=>$type_init));
-			
+			$type_init = null;
+			if ($type == 'PROCES_INIT') $type_init = 'procesInit';
+			else if($type == 'RESOURCE') $type_init = 'RESOURCE';
 
-			//echo "<br> w AddNode:ID".$id." parent".$parent;
-		}
-		   if(!empty($parent)) $graph->elements->edges[] = array('data'=>array('source'=>$parent, 'target'=>$id  ));
-
-	}
-	
-	 
-	 
-	 
-	 
-	 
-
-	 $PROCES_INIT_SCAN = V::get('PROCES_INIT_SCAN', '', $_REQUEST, 'int');
-	if(!empty($PROCES_INIT_SCAN))	 {
-	     //mapa procesow
-
-		
-		$cp=new crm_proces_paser;
-
-	$PROCES_INIT_SCAN_STANOWISKO = V::get('PROCES_INIT_SCAN_STANOWISKO', '', $_REQUEST, 'int');		
-	$PROCES_INIT_SCAN_USER = V::get('PROCES_INIT_SCAN_USER', '', $_REQUEST, 'int');		
-
-	
-	
-	if(!empty($PROCES_INIT_SCAN_STANOWISKO))  {
-		Lib::loadClass('ProcesHelper');
-		$proces_list_obj = ProcesHelper::get_procesy_by_stanowiska( array($PROCES_INIT_SCAN_STANOWISKO) );
-		foreach($proces_list_obj as $obj) {
-			$init[$obj->ID]=$obj->ID;
+			$graph->elements->nodes[] = array('data' => array('id' => "{$id}", 'name' => $name, 'type' => $type_init));
 		}
-    } else if(!empty($PROCES_INIT_SCAN_USER))  {
-		Lib::loadClass('UsersHelper');
-		$proces_list_obj = UsersHelper::get_group_by_user($PROCES_INIT_SCAN_USER,array('SHOW_IN_PERIOD_MARK'=>'YES'));
-		//echo "here";
-
-		foreach($proces_list_obj as $obj) {
-			$init[$obj->ID]=$obj->ID;
+		if (!empty($parent)) {
+			if (isset($once)) {
+				if (!isset($graph->used_elements[$parent][$id]) && !isset($graph->used_elements[$id][$parent])) {
+					$graph->elements->edges[] = array('data' => array('source' => $parent, 'target' => $id));
+				}
+			} else {
+				$graph->elements->edges[] = array('data' => array('source' => $parent, 'target' => $id));
+			}
+			$graph->used_elements[$parent][$id] = 1;
+			$graph->used_elements[$id][$parent] = 1;
 		}
-    } else  {
-
-	    $init=$cp->get_proces_init($id_proces);
 	}
-	
-	DEBUG_S(3,'lista procesow init',$init);
-		foreach($init as $id_proces) {
-
-			 $tree=$cp->build_proces_init_tree($id_proces);
-			 $cp->build_tree_flat_info($tree,null);
-		     $cp->detect_tree_where_to_detail_cut($tree,'nocut');
-			 $cp->build_path_zoom_proces_cut($tree,$id_proces);
-			 DEBUG_S(3,'get_proces_init',$init);
-			 DEBUG_S(3,'tree->childs',$tree->Childs);
-			 DEBUG_S(3,'tree->Parents',$tree->Parents);
-			 DEBUG_S(3,'tree->Viev_Zpc',$tree->Viev_Zpc);
-			 DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
-
-		
-			 	  graph__addNodeID(0, $graph,$name=null,$path,null);
-			 foreach($tree->Viev_Zpc as $id=>$obj) {
-
-				  graph__addNodeID($id, $graph,$obj->DESC,null,((isset($obj->PARENT)) ? $obj->PARENT : null),$tree->Childs[$id]->TYPE);
-				//  foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, &$graph,$tree->Viev_Zpc[$link]->DESC,null,$link,null);
-				  foreach($obj->EXTERNAL_LINK as $link) graph__addNodeID($link, $graph,$tree->Viev_Zpc[$link]->DESC,null,$id,'PROCES_INIT');
-	
-			 }
-			 unset($tree);
-		}
-		
-		
-	}else {
-		 //dokladnie 1 proces
-		 $cp=new crm_proces_paser;
-
-		 $tree=$cp->build_proces_init_tree($id_proces);
-		 $cp->build_tree_flat_info($tree,null);
-	     $cp->detect_tree_where_to_detail_cut($tree);
-		 $cp->build_path_zoom_proces_cut($tree,$id_proces);
-		 DEBUG_S(3,'get_proces_init',$init);
-		 DEBUG_S(3,'tree->childs',$tree->Childs);
-		 DEBUG_S(3,'tree->Parents',$tree->Parents);
-		 DEBUG_S(3,'tree->Viev_Zpc',$tree->Viev_Zpc);
-		 DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
-		 DEBUG_S(3,'tree->Viev_Zpc_Parent_cut',$tree->Viev_Zpc_Parent_cut);
-		 DEBUG_S(3,'tree->Viev_Zpc_found',$tree->Viev_Zpc_found);	
-		 	  graph__addNodeID(0, $graph,$name=null,$path,null);
-		 foreach($tree->Viev_Zpc as $id=>$obj) {
-		 			    //echo "<br> tst edg:".$id." / ".$tree->Childs[$id]->PARENT;
-		 			   // : $tree->Viev_Zpc[$tree->Childs[$id]->PARENT])
-			  graph__addNodeID($id, $graph,$obj->DESC,null,((isset($obj->PARENT)) ? $obj->PARENT : null),$tree->Childs[$id]->TYPE);
-			  foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, $graph,$tree->Viev_Zpc[$link]->DESC,null,$link,null);
-			  foreach($obj->EXTERNAL_LINK as $link) graph__addNodeID($link, $graph,$tree->Viev_Zpc[$link]->DESC,null,$id,'PROCES_INIT');
-	
-		 }
-		 
-	 }
-	 
-	 
-	 
-	 
-/*
-	$db = DB::getDB();
-	
-	$sql= "select p.`ID`,`DESC` from `CRM_PROCES` as p where  p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT' and ID=994 limit 1";
-	$res=DB::query($sql);
-	while($h=DB::fetch($res)) {
-		SearchParentsWithExits($h->ID,$h->ID,$graph,'Proces '.$h->ID,0);
-		//graph__addNodeID($h->ID, $graph);
-		graph__addNodeID('1', $graph,'1');
 
-	//	graph__addNodeID($h->ID, $graph,$h->ID);
-//		graph__addNodeID('100', $graph,'100');
-		//$graph->treeItems[$h->ID] = true;
-		//$graph->treeItems[101] = true;
+	$id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
 
-//		$graph->elements->nodes[] = array('data'=>array('id'=>$h->ID, 'name'=>$h->ID , 'type'=>'procesInit'));
-//		$graph->elements->nodes[] = array('data'=>array('id'=>101, 'name'=>101 , 'type'=>'procesInit'));
-//		$graph->elements->edges[] = array('data'=>array('source'=>994, 'target'=>101));
+	$PROCES_INIT_SCAN = V::get('PROCES_INIT_SCAN', '', $_REQUEST, 'int');
+	if (!empty($PROCES_INIT_SCAN)) {
+		$cp = new GraphViewProcessParser();
 
+		$PROCES_INIT_SCAN_STANOWISKO = V::get('PROCES_INIT_SCAN_STANOWISKO', '', $_REQUEST, 'int');
+		$PROCES_INIT_SCAN_USER = V::get('PROCES_INIT_SCAN_USER', '', $_REQUEST, 'int');
 
-	}
-*/
-	foreach($graph->elements->nodes as $var) {
-	//	echo "<br>\n NODE".$var[data][id];
-		$nodes[$var[data][id]]=$var[data][id];
-	}
-	foreach($graph->elements->edges as $var) {
-		//echo "<br>\n".$var[data][source]." ".$var[data][target]." ";
-		if(!isset($nodes[$var[data][source]]))  echo "<br>FAIL1 ".$var[data][source];
-		if(!isset($nodes[$var[data][target]]))  echo "<br>FAIL2 ".$var[data][target];
-	}
-
-	DEBUG_S(3,'nodes',$graph->elements->nodes);
-	DEBUG_S(3,'edges',$graph->elements->edges);
-/*		
-	$sql = "select p.`ID`, p.`PARENT_ID`
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-	";
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeFlat[$r->PARENT_ID] []= $r->ID;
-	}
-
-	$sql = "select p.`IF_TRUE_GOTO` as ID, p.`ID` as PARENT_ID
-			from `CRM_PROCES` as p
-			where p.`A_STATUS` in('WAITING','NORMAL')
-				and p.IF_TRUE_GOTO>0
-		--		and p.IF_TRUE_GOTO_FLAG='GOTO_AND_RETURN'
-	";
-	
-	$res = $db->query($sql);
-	while ($r = $db->fetch($res)) {
-		$graph->procesTreeGoto[$r->PARENT_ID] []= $r->ID;
-	}
-
-
-	function createGraphRec($id, $tree, &$graph, $lvl = 0) {
-		$graph->treeItems[$id] = true;
-		settype($id, 'string');
-		if ($id == 3122) {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'type'=>'procesInit', 'lvl'=>$lvl));
+		if (!empty($PROCES_INIT_SCAN_STANOWISKO)) {
+			Lib::loadClass('ProcesHelper');
+			$PROCES_INIT_SCAN_STANOWISKA = array($PROCES_INIT_SCAN_STANOWISKO);
+			$proces_list_obj = ProcesHelper::get_procesy_by_stanowiska($PROCES_INIT_SCAN_STANOWISKA);
+			foreach ($proces_list_obj as $obj) {
+				$init[$obj->ID] = $obj->ID;
+			}
+		} else if(!empty($PROCES_INIT_SCAN_USER))  {
+			Lib::loadClass('UsersHelper');
+			$proces_list_obj = UsersHelper::get_group_by_user($PROCES_INIT_SCAN_USER, array('SHOW_IN_PERIOD_MARK' => 'YES'));
+			foreach ($proces_list_obj as $obj) {
+				$init[$obj->ID] = $obj->ID;
+			}
+		} else if(!empty($id_zasob)) {
+			Lib::LoadClass('ProcesHelper');
+			$init = ProcesHelper::get_proces_init_by_zasob_id($id_zasob);
 		} else {
-			$graph->elements->nodes[] = array('data'=>array('id'=>$id, 'name'=>$id, 'lvl'=>$lvl));
+			$init = $cp->get_proces_init($id_proces);
 		}
-
-		if ($lvl > 1) {
-		//	return;
-		}
-
-		if (!empty($tree[$id])) {
-			foreach ($tree[$id] as $vChildID) {
-				$graph->elements->edges[] = array('data'=>array('source'=>$id, 'target'=>$vChildID));
-				createGraphRec($vChildID, $tree, $graph, $lvl + 1);
+		DEBUG_S(3,'lista procesow init',$init,__FILE__,__FUNCTION__,__LINE__);
+		foreach ($init as $id_proces) {
+			$tree = $cp->build_proces_init_tree($id_proces);
+			$cp->build_tree_flat_info($tree, null);
+			$cp->detect_tree_where_to_detail_cut($tree, 'nocut');
+			$cp->build_path_zoom_proces_cut($tree, $id_proces);
+			DEBUG_S(3,'get_proces_init',$init);
+			DEBUG_S(3,'tree->childs',$tree->Childs);
+			DEBUG_S(3,'tree->Parents',$tree->Parents);
+			DEBUG_S(3,'tree->Viev_Zpc',$tree->Viev_Zpc);
+			DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
+			DEBUG_S(3,'tree->get_resources_by_proceses_id',$tree->get_resources_by_proceses_id);
+			graph__addNodeID(0, $graph, $name = null, $path, null);
+			foreach ($tree->Viev_Zpc as $id => $obj) {
+				graph__addNodeID($id, $graph, $obj->DESC, null, ((isset($obj->PARENT))? $obj->PARENT : null), $tree->Childs[$id]->TYPE);
+				foreach ($obj->EXTERNAL_LINK as $link) {
+					graph__addNodeID($link, $graph, $tree->Viev_Zpc[$link]->DESC, null, $id, 'PROCES_INIT');
+				}
+			}
+			if (!empty($_REQUEST['RESOURCES'])) {
+				$resources = $cp->get_resources_by_proceses_id($tree->Childs, $id_proces, $id_zasob);
+				foreach ($resources['PARENT_ID'] as $ID => $DESC) {
+					graph__addNodeID("Z_{$ID}", $graph, $DESC, null, null, 'RESOURCE');
+				}
+				foreach ($resources['ID'] as $ID => $DESC) {
+					graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, $id_proces, 'RESOURCE');
+					graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, "Z_{$DESC['PARENT_ID']}", 'RESOURCE', 'once');
+				}
 			}
+			unset($tree);
 		}
 	}
-
-	createGraphRec($id_proces, $graph->procesTreeFlat, $graph);
-
-*/
-/*
-	// addGraphGoto
-	foreach ($graph->procesTreeGoto as $kID => $vGotoIds) {
-		//$graph->treeItems[$id] = true;
-		if (array_key_exists($kID, $graph->treeItems)) {
-			foreach ($vGotoIds as $vGotoID) {
-				graph__addNodeID($vGotoID, $graph);
-				$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
+	else {
+		$cp = new GraphViewProcessParser();
+		$tree = $cp->build_proces_init_tree($id_proces);
+		$cp->build_tree_flat_info($tree, null);
+		$cp->detect_tree_where_to_detail_cut($tree);
+		$cp->build_path_zoom_proces_cut($tree, $id_proces);
+		DEBUG_S(3,'get_proces_init',$init);
+		DEBUG_S(3,'tree->childs',$tree->Childs);
+		DEBUG_S(3,'tree->Parents',$tree->Parents);
+		DEBUG_S(-3,'tree->Viev_Zpc',$tree->Viev_Zpc);
+		DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
+		DEBUG_S(3,'tree->Viev_Zpc_Parent_cut',$tree->Viev_Zpc_Parent_cut);
+		DEBUG_S(3,'tree->Viev_Zpc_found',$tree->Viev_Zpc_found);
+		graph__addNodeID(0, $graph, $name = null, $path, null);
+		foreach ($tree->Viev_Zpc as $id => $obj) {
+			graph__addNodeID($id, $graph, $obj->DESC, null, ((isset($obj->PARENT))? $obj->PARENT : null), $tree->Childs[$id]->TYPE);
+			foreach ($obj->INTERNAL_LINK as $link) {
+				graph__addNodeID($id, $graph, $tree->Viev_Zpc[$link]->DESC, null, $link, null);
 			}
-		} else {
-			foreach ($vGotoIds as $vGotoID) {
-				if (array_key_exists($vGotoID, $graph->treeItems)) {
-//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("TODO: add node ($kID); add edge from $kID to $vGotoID");echo'</pre>';
-					graph__addNodeID($kID, $graph);
-					//$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
-				}
+			foreach ($obj->EXTERNAL_LINK as $link) {
+				graph__addNodeID($link, $graph, $tree->Viev_Zpc[$link]->DESC, null, $id, 'PROCES_INIT');
 			}
 		}
+		if (!empty($_REQUEST['RESOURCES'])) {
+			$resources = $cp->get_resources_by_proceses_id($tree->Childs, $id_proces, $id_zasob);
+			foreach ($resources['PARENT_ID'] as $ID => $DESC) {
+				graph__addNodeID("Z_{$ID}", $graph, $DESC, null, null, 'RESOURCE');
+			}
+			foreach ($resources['ID'] as $ID => $DESC) {
+				graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, $id_proces, 'RESOURCE');
+				graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, "Z_{$DESC['PARENT_ID']}", 'RESOURCE');
+			}
+		}
+	}
+
+	foreach($graph->elements->nodes as $var) {
+		$nodes[$var['data']['id']] = $var['data']['id'];
+	}
+	foreach($graph->elements->edges as $var) {
+		if (!isset($nodes[$var['data']['source']])) echo "<br>FAIL1 ".$var['data']['source'];
+		if (!isset($nodes[$var['data']['target']])) echo "<br>FAIL2 ".$var['data']['target'];
 	}
-*/
+	DEBUG_S(3,'nodes',$graph->elements->nodes);
+	DEBUG_S(3,'edges',$graph->elements->edges);
 ?>
 <style type="text/css">
 #<?php echo $graph->htmlID; ?>_wrap {
@@ -517,7 +202,7 @@ function GRAPH_VIEW_PROCES() {
 	border:1px solid #ccc;
 }
 #<?php echo $graph->htmlID; ?> {
-	height:560px;
+	height:860px;
 	border-bottom:1px solid #ccc;
 }
 #<?php echo $graph->htmlID; ?>_info {
@@ -526,13 +211,12 @@ function GRAPH_VIEW_PROCES() {
 #<?php echo $graph->htmlID; ?>_wrap .actions { position:absolute; top:20px; left:-40px; margin:0; padding:0; list-style:none; }
 #<?php echo $graph->htmlID; ?>_wrap .actions button { border-radius:0; background:#fff; border:1px solid #ccc; }
 </style>
-
 <script src="./stuff/cytoscape.js/arbor.js"></script>
 <script src="./stuff/cytoscape.js/cytoscape.js"></script>
 <script>
 jQuery(loadInfo = function(nodeID){
 	$.ajax({
-		url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&HEADER_NOT_INIT=YES',
+		url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&id_zasob=<?php echo $id_zasob; ?>&HEADER_NOT_INIT=YES',
 		type: 'GET',
 		dataType: 'text',
 		data: '',
@@ -588,7 +272,15 @@ jQuery(loadCy = function(){
 					'background-color': 'red',
 					'text-outline-color': 'red',
 					'font-weight': 'bold'
-				}),
+				})
+			.selector('node.RESOURCE')
+				.css({
+					'background-color': 'black',
+					'text-outline-color': 'black',
+					'font-weight': 'normal','font-size': '8'
+
+				})
+				,
 
 		elements: <?php echo json_encode($graph->elements); ?>,
 
@@ -597,6 +289,7 @@ jQuery(loadCy = function(){
 			window.cy_<?php echo $graph->htmlID; ?> = this;
 
 			cy.elements("node[type = 'procesInit']").addClass('procesInit');
+			cy.elements("node[type = 'RESOURCE']").addClass('RESOURCE');
 			cy.elements("node[lvl > 1]").hide();
 
 			cy.elements().unselectify();
@@ -652,7 +345,6 @@ jQuery(document).ready(function(){
 		});
 });
 </script>
-
 <div id="<?php echo $graph->htmlID; ?>_wrap">
 	<div id="<?php echo $graph->htmlID; ?>"></div>
 	<div id="<?php echo $graph->htmlID; ?>_info"></div>
@@ -665,3 +357,216 @@ jQuery(document).ready(function(){
 
 <?php
 }
+
+class GraphViewProcessParser {
+
+// var $this->get_proces_init=array();
+// [proces_init]  - A
+//    [step]      - flat 0
+//    [step]      - flat 3 , tree 2 , cut
+//     [step]     - flat 0 , tree 0
+//     [step]     - flat 1 , tree 1
+//       [step]   - flat 1 , tree 1
+//         [step] - flat 0 , tree 0
+//     [step]     - flat 1 , tree 1
+//       [step]   - flat 0 , tree 0
+
+	public function get_proces_init($id_proces) {
+		$db = DB::getDB();
+		$sql = "select
+				p.`ID`
+				, p.`DESC`
+			from `CRM_PROCES` as p
+				left join `_CRM_PROCES_INIT_STATS` as cs on(cs.`ID` = p.`ID`)
+			where
+				p.`A_STATUS` in('WAITING','NORMAL')
+				and p.`TYPE`='PROCES_INIT'
+				and (cs.`path` like '%/{$id_proces}/%' or cs.`path` like '%/{$id_proces}'  or cs.`path` like '{$id_proces}/%')
+		";
+		$res = $db->query($sql);
+		while ($h = $db->fetch($res)) {
+			$this->get_proces_init[] = $h->ID;
+		}
+		return $this->get_proces_init;
+	}
+
+	public function build_proces_init_tree($id_proces) {
+		$db = DB::getDB();
+		$tree->Childs[$id_proces]->PARENT = 0;
+		$tree->Childs[$id_proces]->SOURCE = 'build_tree_for_proces';
+		$tree->Parents[0]->CHILD[$id_proces] = $id_proces;
+		$obj = $db->get_by_id('CRM_PROCES', $id_proces);
+		$tree->Childs[$id_proces]->TYPE = $obj->TYPE;
+		$this->build_tree_for_proces($tree, $id_proces, $id_proces);
+		return $tree;
+	}
+
+	public function build_tree_for_proces(&$tree, $cursor, $init_once = null) {
+		$db = DB::getDB();
+		$sqlOr = (!empty($init_once))? " or cp.ID={$init_once} " : "";
+		$sql = "select
+			cp.`ID`
+			, cp.`IF_TRUE_GOTO`
+			, cp.`IF_TRUE_GOTO_FLAG`
+			, cp.`TYPE`
+		from `CRM_PROCES` as cp
+		where
+			(cp.PARENT_ID={$cursor} {$sqlOr})
+			and  cp.`A_STATUS` in('WAITING','NORMAL')
+		";
+		$res = $db->query($sql);
+		while ($h = $db->fetch($res)) {
+			if (empty($init_once)) $tree->Childs[$h->ID]->PARENT = $cursor;
+			if (empty($init_once)) $tree->Parents[$cursor]->CHILD[$h->ID] = $h->ID;
+			$tree->Childs[$h->ID]->TYPE = $h->TYPE;
+			$tree->Childs[$h->ID]->SOURCE = 'build_tree_for_proces';
+			if ($h->IF_TRUE_GOTO > 0) {
+				$tree->Childs[$h->ID]->GOTO_FLAG = $h->IF_TRUE_GOTO_FLAG;
+				$tree->Childs[$h->ID]->IF_TRUE_GOTO = $h->IF_TRUE_GOTO;
+				$tree->Childs[$h->IF_TRUE_GOTO]->IS_EXECUTED_BY[$h->ID] = $h->ID;
+			}
+			$this->build_tree_for_proces($tree, $h->ID, null);
+		}
+	}
+
+	public function get_resources_by_proceses_id($id_proces_obj, $id_proces, $filter_zasob) {
+		$db = DB::getDB();
+		$filter = "";
+		if (is_array($filter_zasob)) {
+			$filter = " and cz.ID in (".implode(',', $filter_zasob).") ";
+		}
+		else if (!empty($filter_zasob)) {
+			$filter = " and cz.ID={$filter_zasob}";
+		}
+		$sql = "select
+				cz.ID
+				, cz.PARENT_ID
+				, cz.`DESC`
+				, cz.`TYPE`
+				, czp.`DESC` as DESC_czp
+				, czp.`TYPE` as TYPE_czp
+			from CRM_WSKAZNIK as cw
+				left join CRM_LISTA_ZASOBOW as cz on(cz.ID=cw.ID_ZASOB)
+				left join CRM_LISTA_ZASOBOW as czp on(czp.ID=cz.PARENT_ID)
+			where cw.ID_PROCES in(".implode(',', array_keys($id_proces_obj)).")
+				and cw.A_STATUS in ('NORMAL','WAITING')
+				and czp.`TYPE` in ('TABELA')
+				{$filter}
+		";
+		$res = $db->query($sql);
+		while ($h = $db->fetch($res)) {
+			$found['ID'][$h->ID]['PARENT_ID'] = $h->PARENT_ID;
+			$found['ID'][$h->ID]['DESC'] = $h->DESC;
+			$found['PARENT_ID'][$h->PARENT_ID] = $h->DESC_czp;
+		}
+		return $found;
+	}
+
+	public function build_tree_flat_info(&$tree, $flat) {
+		foreach ($tree->Childs as $id => $obj) {
+			//sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
+			foreach ($tree->Parents[$id]->CHILD as $child) {
+				$tree->Childs[$id]->CHILD[$child] = count($tree->Parents[$child]->CHILD);
+			}
+		}
+	}
+
+	public function detect_tree_where_to_detail_cut(&$tree, $flag_not_to_cut = null) {
+		foreach ($tree->Childs as $id => $obj) {
+			//sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
+			$control = 0;
+			foreach ($obj->CHILD as $child) {
+				if ($child > 0) $control++;
+			}
+			if (empty($flag_not_to_cut)) {
+				if ($control > 1) {
+					//przeciecie jezeli jest wiecej wyjsc niz jedno z zaglebieniami
+					$tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
+				}
+				if (isset($tree->Childs[$id]->GOTO_FLAG)) {
+					//przeciecie, jezeli jest wyjscie z kroku procesu do innego 
+					$tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
+				}
+				if (isset($tree->Childs[$id]->IS_EXECUTED_BY)) {
+					//trzeba zbadac tez czy nie jest do niego dowiazywany w jakims miejscu proces
+					$tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
+				}
+			} else {
+				$tree->Childs[$id]->NO_CUT_FLAG = true;
+			}
+		}
+	}
+
+	public function search_parent_ids_till_cut(&$tree, $init, &$find) {
+		//szukam lancuchow do optymalizacji do miejsca flagi CUT, kojarzac od razu linki
+		if (isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
+			$this->zoom_process_links($tree, $init, $init);
+		}
+		if (!isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
+			$find[] = $init;
+			$this->zoom_process_links($tree, $init, $find[0]);
+			foreach($tree->Childs[$init]->CHILD as $id => $count) {
+				$this->search_parent_ids_till_cut($tree, $id, $find);
+			}
+		}
+	}
+
+	public function zoom_process_links($tree, $id, $root_id) {
+		$db = DB::getDB();
+		if (isset($tree->Childs[$id]->GOTO_FLAG)) {
+			if (isset($tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO])) {
+				if (isset($tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO]->SOURCE)) {
+					$tree->Viev_Zpc[$root_id]->INTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
+				} else {
+					$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
+				}
+			} else {
+				$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
+				$obj = $db->get_by_id('CRM_PROCES',$tree->Childs[$id]->IF_TRUE_GOTO);
+				$tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->DESC = "{" . $obj->ID . "}" . substr($obj->DESC, 0, 50);
+				if ($tree->Childs[$id]->GOTO_FLAG == 'GOTO_AND_RETURN') {
+					$tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->EXTERNAL_LINK[$root_id] = $root_id;
+				}
+			}
+		}
+	}
+
+	public function build_path_zoom_proces_cut(&$tree, $init, $path_zpc = array()) {
+		$db = DB::getDB();
+		foreach ($tree->Childs as $id => $obj) {
+			if (!isset($tree->Viev_Zpc_found[$id])) {
+				$find = array();
+				$this->search_parent_ids_till_cut($tree, $id, $find);
+				foreach ($find as $find_id) {
+					$tree->Viev_Zpc_found[$find_id] = $find[0];
+					if ($find_id != $find[0]) {
+						$tree->Viev_Zpc_Parent[$find_id] = $find[0];// TODO: moze byc to z bledem jak nadrzedny bedzie zbitym ciagiem
+					}
+					else {
+						$tree->Viev_Zpc_Parent[$find_id] = $tree->Childs[$find_id]->PARENT;
+					}
+				}
+				$tree->Viev_Zpc[$id]->PATH = $find;
+				$obj = $db->get_by_id('CRM_PROCES', $id);
+				$tree->Viev_Zpc[$id]->DESC = "{" . $id . "}" . substr($obj->DESC, 0, 50) . "...";
+			}
+		}
+
+		foreach($tree->Viev_Zpc as $id => $obj) {
+			if (!isset($obj->PARENT)) {
+				foreach($tree->Viev_Zpc as $id_=>$obj_) {
+					if (isset($tree->Childs[$id_]->SOURCE)) {
+						if (in_array($tree->Childs[$id]->PARENT, $obj_->PATH)) {
+							$tree->Viev_Zpc[$id]->PARENT = $id_;
+						}
+					}
+				}
+			}
+
+			if (!isset($tree->Viev_Zpc[$id]->PARENT)) {
+				$tree->Viev_Zpc[$id]->PARENT = $tree->Childs[$id]->PARENT;
+			}
+		}
+	}
+
+}