'."Wrong ID".'

'; return; } $db = DB::getDB(); $proces = $db->get_by_id('CRM_PROCES', $id_proces); if (!$proces) { echo'

'."Process {$id_proces} not exists".'

'; 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'
 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($step);echo'
'; ?>

ID; ?> DESC; ?>

OPIS; ?>

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 "
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 "
{$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 "
{$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 "
".$id_proces_step." count 90 has ".count($next); $wyjsc=array(); foreach($next as $nx=>$nx_type) { echo "
{$id_proces_step} 93 foreach next as nx:".$nx." type ".$nx_type; $next_=TestIfHasDeep($nx); if(count($next_)>0) $wyjsc[]=$nx ; else echo "
{$id_proces_step} ({$nx}) nie posiada wyjscia "; echo "
{$id_proces_step} Wyjsc 96: ".count($wyjsc); } echo "
{$id_proces_step} Wyjsc 98: ".count($wyjsc); if(count($wyjsc)==1) { echo "
".$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 "
{$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 "
{$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 "
\n NODE".$var[data][id]; $nodes[$var[data][id]]=$var[data][id]; } foreach($graph->elements->edges as $var) { echo "
\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'
 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("TODO: add node ($kID); add edge from $kID to $vGotoID");echo'
'; graph__addNodeID($kID, $graph); //$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO')); } } } } */ ?>