Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
wdoc_graphviz.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generate worflow graph
9  *
10  * @author Anakeen 2007
11  * @version $Id: wdoc_graphviz.php,v 1.17 2009/01/07 18:04:19 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  * @global id Http var : document id to affect
18  * @global type Http var : type of graph
19  * @global format Http var : file format pnh or svg
20  * @global orient Http var :orientation TB (TopBottom) or LR (LeftRight)
21  * @global size Http var : global size of graph
22  */
23 // refreah for a classname
24 // use this only if you have changed title attributes
25 include_once ("FDL/Lib.Attr.php");
26 include_once ("FDL/Class.DocFam.php");
27 
28 $style = array(
29  'autonext-color' => '#006400', // darkgreen
30  'arrow-label-font-color' => '#555555', // dark grey
31  'arrow-color' => '#00008b', // darkblue
32  'condition-color' => '#ffff00', // yellow
33  'action-color' => '#ffa500', // orange
34  'mail-color' => '#a264d2', // light violet
35  'timer-color' => '#64a2d2', // light blue
36  'start-color' => '#0000ff', // blue
37 
38 );
39 
40 $dbaccess = $appl->GetParam("FREEDOM_DB");
41 if ($dbaccess == "") {
42  print "Database not found : param FREEDOM_DB";
43  exit;
44 }
45 
46 $docid = GetHttpVars("docid", 0); // special docid
47 $type = GetHttpVars("type"); // type of graph
48 $orient = GetHttpVars("orient", "LR"); // type of graph
49 $isize = GetHttpVars("size", "10"); // size of graph
50 $ratio = GetHttpVars("ratio", "auto"); // ratio of graph
51 $label = ($type == "complet");
52 $doc = new_doc($dbaccess, $docid);
53 
55 
56 $fontsize = 13;
57 if ($isize == "auto") $size = "";
58 else {
59  if ($isize == "A4") {
60  $size = "size=\"7.6,11!\";"; // A4 whith 1.5cm margin
61 
62  } else {
63  if (preg_match("/([0-9\.]+),([0-9\.]+)/", $isize, $reg)) {
64 
65  $fontsize = intval(min($reg[1], $reg[2]) / 2);
66  $size = sprintf("size=\"%.2f,%.2f!\";", floatval($reg[1]) / 2.55, floatval($reg[2]) / 2.55);
67  } else {
68  $isize = sprintf("%.2f", floatval($isize) / 2.55);
69  $size = "size=\"$isize,$isize!\";";
70  }
71  }
72 }
73 
74 $statefontsize = $fontsize;
75 $conditionfontsize = intval($fontsize * 10 / 13);
76 $labelfontsize = intval($fontsize * 11 / 13);
77 /*$statefontsize="";
78 $conditionfontsize="";
79 $labelfontsize="";*/
80 
81 $tact = array();
82 foreach ($doc->cycle as $k => $v) {
83  $tmain = '';
84  if (isset($doc->autonext[$v["e1"]]) && ($doc->autonext[$v["e1"]] == $v["e2"])) {
85  $tmain = sprintf('color="%s",style="setlinewidth(3)",arrowsize=1.0', $style['autonext-color']);
86  }
87 
88  if ($label) {
89  $e1 = _($v["e1"]);
90  $e2 = _($v["e2"]);
91  $act = $doc->getActivity($v["e1"]);
92  if ($act && ($tact[$v["e1"]] == "")) {
93  $tact[$v["e1"]] = 'act' . $k;
94  $line[] = '"' . str_replace(" ", "\\n", 'act' . $k) . '" [ label="' . $act . '", fixedsize=false,shape=box,color="' . $doc->getColor($v["e1"]) . '" ];';
95 
96  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans, label="%s"];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", 'act' . $k) , $style['arrow-label-font-color'], $style['arrow-color'], "");
97  $e1 = 'act' . $k;
98  } elseif ($tact[$v["e1"]] != "") {
99  $e1 = $tact[$v["e1"]];
100  }
101 
102  $m1 = $doc->transitions[$v["t"]]["m1"];
103  $m2 = $doc->transitions[$v["t"]]["m2"];
104 
105  $ttrans = array();
106  $tm = $doc->getValue($doc->attrPrefix . "_TRANS_TMID" . $v["t"]);
107  if ($tm) $ttrans[] = $tm;
108  $ttrans = array_merge($ttrans, $doc->getTValue($doc->attrPrefix . "_TRANS_PA_TMID" . $v["t"]));
109  $mtrans = $doc->getTValue($doc->attrPrefix . "_TRANS_MTID" . $v["t"]);
110 
111  if ($m1) {
112  // if ($tmain) $tmain.=",";
113  // $tmain.="taillabel=$m1";
114  $line[] = '"' . str_replace(" ", "\\n", $m1 . $k) . '" [ label="' . $m1 . '", fixedsize=false,shape=diamond,color="' . $style['condition-color'] . '" ];';
115 
116  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans, label="%s"];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $m1 . $k) , $style['arrow-label-font-color'], $style['arrow-color'], _($v["t"]));
117  $e1 = $m1 . $k;
118  }
119  if ($m2) {
120  $line[] = '"' . str_replace(" ", "\\n", $m2 . $k) . '" [ label="' . $m2 . '",fixedsize=false,shape=box,color="' . $style['action-color'] . '"];';
121  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $m2 . $k) , $style['arrow-label-font-color'], $style['arrow-color']);
122  $e1 = $m2 . $k;
123  }
124 
125  if (count($mtrans) > 0) {
126  $ex = 'mt' . $k;
127  $tmlabel = "mail";
128 
129  $tmlabel = str_replace(array(
130  "\n",
131  '<BR>'
132  ) , "\\n", $doc->getHtmlValue($doc->getAttribute($doc->attrPrefix . "_TRANS_MTID" . $v["t"]) , $doc->_array2val($mtrans) , '_self', false));
133  $timgt = ' image="' . DEFAULT_PUBDIR . '/Images/tmail.png"';
134  $line[] = '"' . str_replace(" ", "\\n", $ex) . '" [ label="' . $tmlabel . '",fixedsize=false,style=bold,shape=house,color="' . $style['mail-color'] . '"' . $timgt . ' ];';
135  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s",labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $ex) , $style['arrow-label-font-color'], $style['arrow-color']);
136  $e1 = $ex;
137  }
138 
139  $aid = strtolower($doc->attrPrefix . "_MTID" . $v["e2"]);
140  $mt = $doc->getTValue($aid);
141  if (count($mt) > 0) {
142  $ex = 'mtf' . $k;
143 
144  $tmlabel = str_replace(array(
145  "\n",
146  '<BR>'
147  ) , "\\n", $doc->getHtmlValue($doc->getAttribute($doc->attrPrefix . "_MTID" . $v["e2"]) , $doc->_array2val($mt) , '_self', false));
148  $timgt = ' image="' . DEFAULT_PUBDIR . '/Images/tmail.png"';
149  $line[] = '"' . str_replace(" ", "\\n", $ex) . '" [ label="' . $tmlabel . '",fixedsize=false,style=bold,shape=house,color="' . $style['mail-color'] . '"' . $timgt . ' ];';
150  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $ex) , $style['arrow-label-font-color'], $style['arrow-color']);
151  $e1 = $ex;
152  }
153 
154  $aid = strtolower($doc->attrPrefix . "_TMID" . $v["e2"]);
155  $mt = $doc->getTValue($aid);
156  if (count($mt) > 0) {
157  $ex = 'tmf' . $k;
158  $tmlabel = str_replace(array(
159  "\n",
160  '<BR>'
161  ) , "\\n", $doc->getHtmlValue($doc->getAttribute($doc->attrPrefix . "_TMID" . $v["e2"]) , $doc->_array2val($mt) , '_self', false));
162  $timgt = ' image="' . DEFAULT_PUBDIR . '/Images/timer.png"';
163  $line[] = '"' . str_replace(" ", "\\n", $ex) . '" [ label="' . $tmlabel . '",fixedsize=false,style=bold,shape=octagon,color="' . $style['timer-color'] . '"' . $timgt . ' ];';
164  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s",labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $ex) , $style['arrow-label-font-color'], $style['arrow-color']);
165  $e1 = $ex;
166  }
167  if (count($ttrans) > 0) {
168  $ex = 'tm' . $k;
169  $tmlabel = "tumer";
170  $tmlabel = str_replace(array(
171  "\n",
172  '<BR>'
173  ) , "\\n", $doc->getHtmlValue($doc->getAttribute($doc->attrPrefix . "_TRANS_MTID" . $v["t"]) , $doc->_array2val($ttrans) , '_self', false));
174  $timgt = ' image="' . DEFAULT_PUBDIR . '/Images/timer.png"';
175  $line[] = '"' . str_replace(" ", "\\n", $ex) . '" [ label="' . $tmlabel . '",fixedsize=false,style=bold,shape=octagon,color="' . $style['timer-color'] . '"' . $timgt . ' ];';
176  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s",labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $ex) , $style['arrow-label-font-color'], $style['arrow-color']);
177  $e1 = $ex;
178  }
179 
180  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans,label="%s" %s];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $e2) , $style['arrow-label-font-color'], $style['arrow-color'], _($v["t"]) , $tmain);
181  } else {
182  $e1 = _($v["e1"]);
183  $e2 = _($v["e2"]);
184  $act = $doc->getActivity($v["e1"]);
185  if ($type == "activity") {
186  if ($act && ($tact[$v["e1"]] == "")) {
187  $tact[$v["e1"]] = 'act' . $k;
188  $line[] = '"' . str_replace(" ", "\\n", 'act' . $k) . '" [ label="' . $act . '", fixedsize=false,shape=box,color="' . $doc->getColor($v["e1"]) . '" ];';
189 
190  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans, label="%s"];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", 'act' . $k) , $style['arrow-label-font-color'], $style['arrow-color'], "");
191  $e1 = 'act' . $k;
192  } elseif ($tact[$v["e1"]] != "") {
193  $e1 = $tact[$v["e1"]];
194  }
195  }
196  $line[] = sprintf('"%s" -> "%s" [labelfontsize=6,color="%s" %s,labelfontname=sans, label="%s"];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $e2) , $style['arrow-color'], $tmain, ($type == "activity") ? _($v["t"]) : "");
197  }
198 }
199 $line[] = '"' . str_replace(" ", "\\n", _($doc->firstState)) . '" [shape = doublecircle,style=filled, width=1.5, fixedsize=true,fontname=sans];';
200 
201 if ($label) {
202  $aid = strtolower($doc->attrPrefix . "_TMID" . $doc->firstState);
203  $tm = $doc->getTValue($aid);
204  $aid = strtolower($doc->attrPrefix . "_MTID" . $doc->firstState);
205  $mt = $doc->getTValue($aid);
206  $e1 = "D";
207  if ((count($tm) > 0) || (count($mt) > 0)) {
208  $line[] = '"' . str_replace(" ", "\\n", $e1) . '" [shape = point,style=filled, width=0.3, fixedsize=true,fontname=sans,color="' . $style['start-color'] . '"];';;
209  }
210 
211  if (count($tm) > 0) {
212  $e2 = 'tmfirst';
213 
214  $tmlabel = str_replace(array(
215  "\n",
216  '<BR>'
217  ) , "\\n", $doc->getHtmlValue($doc->getAttribute($doc->attrPrefix . "_TMID" . $doc->firstState) , $doc->_array2val($tm) , '_self', false));
218  $timgt = ' image="' . DEFAULT_PUBDIR . '/Images/timer.png"';
219  $line[] = '"' . str_replace(" ", "\\n", $e2) . '" [ label="' . $tmlabel . '",fixedsize=false,style=bold,shape=octagon,color="' . $style['timer-color'] . '", fontsize=' . $conditionfontsize . $timgt . ' ];';
220  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $e2) , $style['arrow-label-font-color'], $style['arrow-color']);
221  $e1 = $e2;
222  }
223  if (count($mt) > 0) {
224  $e2 = 'mtfirst';
225  $tmlabel = str_replace(array(
226  "\n",
227  '<BR>'
228  ) , "\\n", $doc->getHtmlValue($doc->getAttribute($doc->attrPrefix . "_MTID" . $doc->firstState) , $doc->_array2val($mt) , '_self', false));
229  $timgt = ' image="' . DEFAULT_PUBDIR . '/Images/tmail.png"';
230  $line[] = '"' . str_replace(" ", "\\n", $e2) . '" [ label="' . $tmlabel . '",fixedsize=false,style=bold,shape=house,color="' . $style['mail-color'] . '", fontsize=' . $conditionfontsize . $timgt . ' ];';
231  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $e2) , $style['arrow-label-font-color'], $style['arrow-color']);
232  $e1 = $e2;
233  }
234 
235  if ($e1 != 'D') {
236  //attach to first state
237  $e2 = _($doc->firstState);
238  $line[] = sprintf('"%s" -> "%s" [labelfontcolor="%s",decorate=false, color="%s", labelfontname=sans];', str_replace(" ", "\\n", $e1) , str_replace(" ", "\\n", $e2) , $style['arrow-label-font-color'], $style['arrow-color']);
239  }
240 }
241 $states = $doc->getStates();
242 foreach ($states as $k => $v) {
243  $color = $doc->getColor($v);
244  $saction = $doc->getActivity($v);
245  if ($saction) $tt = ', tooltip="' . $saction . '"';
246  else $tt = "";
247 
248  if ($color) $line[] = '"' . str_replace(" ", "\\n", _($v)) . '" [fillcolor="' . $color . '"' . $tt . ' ];';
249  else {
250  if ($tt) $tt = substr($tt, 2);
251  $line[] = '"' . str_replace(" ", "\\n", _($v)) . '" [' . $tt . '];';
252  }
253 }
254 # page=\"11.6,8.2\";
255 $ft = str_replace(" ", '\n', _($doc->firstState));
256 
257 $dot = "digraph \"" . $doc->title . "\" {
258  ratio=\"$ratio\";
259  rankdir=$rankdir;
260  $size
261  bgcolor=\"transparent\";
262  {rank=1; \"$ft\";}
263  splines=true;
264  node [shape = circle, style=filled, fixedsize=true,width=1.5, fontname=sans];\n";
265 
266 $dot.= implode($line, "\n");
267 $dot.= "\n}";
268 
269 print $dot;
270 ?>
← centre documentaire © anakeen - published under CC License - Dynacase