| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- <?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
- }
|