Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
diffdoc.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  * Difference between 2 documents
9  *
10  * @author Anakeen 2006
11  * @version $Id: diffdoc.php,v 1.5 2008/08/14 09:59:14 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  */
18 
19 include_once ("FDL/Class.Dir.php");
20 /**
21  * Compare 2 documents
22  * @param Action &$action current action
23  * @global id1 Http var : first document identificator to compare
24  * @global id2 Http var : second document identificator to compare
25  */
26 function diffdoc(&$action)
27 {
28  $docid1 = GetHttpVars("id1");
29  $docid2 = GetHttpVars("id2");
30  if ($docid1 > $docid2) {
31  $docid2 = GetHttpVars("id1");
32  $docid1 = GetHttpVars("id2");
33  }
34  $dbaccess = $action->GetParam("FREEDOM_DB");
35  $d1 = new_doc($dbaccess, $docid1);
36  $err = $d1->control("view");
37  if ($err != "") $action->exitError($err);
38  $d2 = new_doc($dbaccess, $docid2);
39  $err = $d2->control("view");
40  if ($err != "") $action->exitError($err);
41 
42  if ($d1->fromid != $d2->fromid) $action->exitError(sprintf(_("cannot compare two document which comes from two different family")));
43 
44  $la = $d1->GetNormalAttributes();
45 
46  foreach ($la as $k => $a) {
47 
48  if ($a->type == "array") {
49  $v1 = $d1->getAValues($a->id);
50  $v2 = $d2->getAValues($a->id);
51  if ($v1 == $v2) $cdiff = "eq";
52  else $cdiff = "ne";
53  } else {
54  $v1 = $d1->getValue($a->id);
55  $v2 = $d2->getValue($a->id);
56  if ($v1 == $v2) $cdiff = "eq";
57  else $cdiff = "ne";
58  }
59 
60  if ($a->visibility == "H") $vdiff = "hi";
61  else $vdiff = $cdiff;
62 
63  if (!$a->inArray()) {
64 
65  switch ($a->type) {
66  case "image":
67  $tattr[$a->id] = array(
68  "attname" => $a->getLabel() ,
69  "v1" => sprintf("<img src=\"%s\">", $d1->getHtmlValue($a, $v1)) ,
70  "v2" => sprintf("<img src=\"%s\">", $d2->getHtmlValue($a, $v2)) ,
71  "cdiff" => $cdiff,
72  "vdiff" => $vdiff,
73  "EQ" => ($cdiff == "eq")
74  );
75  break;
76 
77  default:
78  $tattr[$a->id] = array(
79  "attname" => $a->getLabel() ,
80  "v1" => $d1->getHtmlValue($a, $v1) ,
81  "v2" => $d2->getHtmlValue($a, $v2) ,
82  "cdiff" => $cdiff,
83  "vdiff" => $vdiff,
84  "EQ" => ($cdiff == "eq")
85  );
86  }
87  }
88  }
89 
90  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
91  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDL/Layout/common.js");
92  $action->lay->set("document1", $d1->title);
93  $action->lay->set("id1", $d1->id);
94  $action->lay->set("date1", strftime("%a %d %b %Y %H:%M", $d1->revdate));
95  $action->lay->set("version1", $d1->version);
96  $action->lay->set("revision1", $d1->revision);
97 
98  $action->lay->set("document2", $d2->title);
99  $action->lay->set("id2", $d2->id);
100  $action->lay->set("date2", strftime("%a %d %b %Y %H:%M", $d2->revdate));
101  $action->lay->set("version2", $d2->version);
102  $action->lay->set("revision2", $d2->revision);
103 
104  $action->lay->set("title", sprintf(_("comparison between<br>%s (rev %d) and %s (rev %d)") , $d1->title, $d1->revision, $d2->title, $d2->revision));
105 
106  $action->lay->setBlockData("ATTRS", $tattr);
107 }
108 ?>
← centre documentaire © anakeen - published under CC License - Dynacase