Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
editchangestate.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Display interface to change state
8  *
9  * @author Anakeen
10  * @version $Id: editchangestate.php,v 1.8 2008/10/02 15:41:45 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Lib.Dir.php");
18 include_once ("FDL/editutil.php");
19 include_once ("FDL/editcard.php");
20 /**
21  * Display editor to fix a document version
22  * @param Action &$action current action
23  * @global string $id Http var : document id
24  * @global string $nstate Http var : next state id
25  */
27 {
28  $docid = GetHttpVars("id");
29  $nextstate = GetHttpVars("nstate");
30  $viewext = GetHttpVars("viewext");
31 
32  $dbaccess = $action->dbaccess;
33 
34  editmode($action);
35  $doc = new_doc($dbaccess, $docid, true);
36  if (!$doc->isAlive()) $action->exitError(sprintf(_("Document %s is not alive") , $docid));
37  if ($doc->wid > 0) {
38  $tneed = array();
39  $err = $doc->lock(true); // autolock
40  if ($err == "") $action->AddActionDone("LOCKDOC", $doc->id);
41  /*
42  * @var WDoc $wdoc
43  */
44  $wdoc = new_Doc($dbaccess, $doc->wid);
45  $wdoc->Set($doc);
46  $action->lay->set("noreason", false);
47  $action->lay->set("realtransition", true);
48  $fstate = $wdoc->GetFollowingStates();
49  $tr = null;
50  foreach ($fstate as $k => $v) {
51  if ($v == $nextstate) {
52  $tr = $wdoc->getTransition($doc->state, $v);
53  $tinputs = array();
54  if (!empty($tr["ask"]) && is_array($tr["ask"])) {
55  foreach ($tr["ask"] as $ka => $va) {
56  /*
57  * @var NormalAttribute $oa
58  */
59  $oa = $wdoc->getAttribute($va);
60  if ($oa) {
61  if ($oa->needed) $tneed[$oa->id] = $oa->getLabel();
62  if ($oa->usefor == 'Q') {
63  $wval = $wdoc->getFamilyParameterValue($oa->id);
64  $wval = $wdoc->getValueMethod($wval);
65  } else {
66  $wval = $wdoc->getRawValue($oa->id);
67  }
68  if ($edittpl = $oa->getOption("edittemplate")) {
69  $input = sprintf("[ZONE FDL:EDITTPL?id=%d&famid=%d&wiid=%d&zone=%s]", $wdoc->id, $wdoc->fromid, $doc->id, $edittpl);
70  } else {
71  $input = getHtmlInput($wdoc, $oa, $wval, "", "", false);
72  }
73  $tinputs[] = array(
74  "alabel" => $oa->getLabel() ,
75  "labelclass" => ($oa->needed) ? "FREEDOMLabelNeeded" : "FREEDOMLabel",
76  "atype" => $oa->type,
77  "avalue" => $input,
78  "aid" => $oa->id,
79  "idisplay" => ($oa->visibility == "H") ? "none" : ""
80  );
81  if ($oa->needed) $tneed[$oa->id] = $oa->getLabel();
82  }
83  }
84  }
85  $action->lay->set("noreason", ((!empty($tr["nr"]) && $tr["nr"] == true)));
86  $action->lay->eSet("viewext", $viewext);
87  $action->lay->setBlockData("FINPUTS", $tinputs);
88  }
89  }
90 
91  setNeededAttributes($action, $wdoc);
92  $activity = $wdoc->getActivity($nextstate);
93  if ($activity) {
94 
95  $action->lay->set("tonewstate", sprintf(_("to the %s activity") , $action->text($activity)));
96  } else {
97  $action->lay->set("tonewstate", sprintf(_("to the %s state") , $action->text($nextstate)));
98  }
99  if ($tr) {
100  if (_($tr["id"]) == $tr["id"]) {
101  if ($activity) {
102  $transitionLabel = sprintf(_("to %s") , $action->text($activity));
103  } else {
104  $transitionLabel = sprintf(_("to %s") , _($nextstate));
105  }
106  } else $transitionLabel = _($tr["id"]);
107  } else {
108  $action->lay->set("realtransition", false);
109  if ($activity) $transitionLabel = sprintf(_("to %s") , $action->text($activity));
110  else $transitionLabel = sprintf(_("to %s") , $action->text($nextstate));
111  }
112 
113  $action->lay->set("tostate", mb_ucfirst($transitionLabel));
114  $action->lay->set("wcolor", $wdoc->getColor($nextstate));
115  $action->lay->Set("Wattrntitle", json_encode(array_values($tneed)));
116  $action->lay->Set("Wattrnid", json_encode(array_keys($tneed)));
117  $action->lay->set("docid", $doc->id);
118  $currentActivity = $wdoc->getActivity($doc->state);
119  if ($currentActivity) {
120  $explanation[] = sprintf(_("The current activity is \"%s\".") , _($currentActivity));
121  } else {
122  $explanation[] = sprintf(_("The current state is \"%s\".") , _($doc->getState()));
123  }
124  $viewState = false;
125  if ($viewState) {
126  $explanation[] = sprintf(_("The document will be stored with \"%s\" state.") , _($nextstate));
127  }
128 
129  if ($activity) {
130  $explanation[] = sprintf(_("The next activity will be \"%s\".") , $action->text($activity));
131  } else {
132  $explanation[] = sprintf(_("The next state will be \"%s\".") , _($nextstate));
133  }
134  $thetitle = mb_ucfirst($transitionLabel);
135  $action->lay->eset("thetitle", $thetitle);
136  $action->lay->set("thetitle_url", urlencode($thetitle));
137  $action->lay->eset("nextstate", $nextstate);
138  $action->lay->set("Explanations", nl2br(implode("\n", $explanation)));
139 
140  $style = $action->parent->getParam("STYLE");
141  if ($viewext) {
142  $action->parent->AddCssRef("STYLE/DEFAULT/Layout/EXT-ADAPTER-SYSTEM.css");
143  if (file_exists(DEFAULT_PUBDIR . "/STYLE/$style/Layout/EXT-ADAPTER-USER.css")) {
144  $action->parent->AddCssRef("STYLE/$style/Layout/EXT-ADAPTER-USER.css");
145  } else {
146  $action->parent->AddCssRef("STYLE/DEFAULT/Layout/EXT-ADAPTER-USER.css");
147  }
148  }
149  }
150 }
static text($code)
global $action
setNeededAttributes(Action &$action, Doc &$doc)
Definition: editcard.php:298
Set($name, &$parent)
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
getHtmlInput(&$doc, &$oattr, $value, $index="", $jsevent="", $notd=false)
Definition: editutil.php:30
editchangestate(Action &$action)
mb_ucfirst($s)
Definition: Lib.Common.php:105
new_Doc($dbaccess, $id= '', $latest=false)
getParam($name, $def="")
editmode(Action &$action)
Definition: editutil.php:41
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen