17 include_once (
"DATA/Class.Document.php");
27 function getDocument($onlyvalues =
false, $completeprop =
true)
29 $out = parent::getDocument($onlyvalues, $completeprop);
37 if ($this->doc->doctype !=
'W')
return null;
38 $states = $this->doc->getStates();
40 $out[
"states"][$v] = array(
42 "activity" => $this->doc->getActivity($v) ,
47 foreach ($this->doc->cycle as $v) {
48 $out[
"transitions"][] = array(
51 "transitionType" => $v[
"t"]
54 foreach ($this->doc->transitions as $k => $v) {
55 $out[
"transitionTypes"][$k] = array(
59 "preMethod" => $v[
"m1"],
60 "postMethod" => $v[
"m2"],
61 "noComment" => $v[
"nr"] ?
true :
false
70 return $this->modifyTransition(
"add",
$start, $finish, $transitionType);
75 return $this->modifyTransition(
"remove",
$start, $finish);
78 private function modifyTransition($addorrem,
$start, $finish, $transitionType =
'')
81 if (
$start && $finish && ($addorrem ==
"remove" || $transitionType)) {
82 if ($this->doc->doctype !=
'W')
return null;
83 $err = $this->doc->lock(
true);
89 $cycles = $this->doc->cycle;
90 foreach ($cycles as $k => $v) {
91 if ($v[
"e1"] ==
$start && $v[
"e2"] == $finish) unset($cycles[$k]);
93 if ($addorrem ==
"add") {
97 "t" => $transitionType
100 $fam = $this->doc->getFamDoc();
101 $classname = $fam->classname;
103 if (file_exists(
$file)) {
104 if (!is_writable(
$file)) {
105 $this->doc->unlock(
true);
106 $this->
setError(sprintf(_(
"workflow file %s is not writable") ,
$file));
110 foreach ($cycles as $k => $v) {
111 $na.= sprintf(
'array("e1"=>"%s", "e2"=>"%s", "t"=>"%s"),' .
"\n", $v[
"e1"], $v[
"e2"], $v[
"t"]);
113 $na = substr($na, 0, -2) .
")";
115 $nc = preg_replace(
'/\$cycle\s*=([^;]*);/i',
"\$cycle=$na;",
$content);
117 file_put_contents(
$file, $nc);
118 $this->doc->cycle = $cycles;
123 $err = $this->doc->unlock(
true);
125 $this->
setError(_(
"modifyTransition: missing parameter"));
133 if ($key && $text &&
$lang) {
134 $mo = sprintf(
'msgid ""
136 "Content-Type: text/plain; charset=UTF-8\n"
137 "Content-Transfer-Encoding: 8bit\n"
140 msgstr "%s"', $key, str_replace(
'"',
'\"', $text));
142 $mofile = sprintf(
"%s/locale/%s/LC_MESSAGES/w%s.po",
DEFAULT_PUBDIR,
$lang, $this->doc->fromid);
143 file_put_contents($mofile, $mo);
147 $cmd = sprintf(
'cd %s/locale/%s/LC_MESSAGES;msgunfmt 0w.mo > _w.po && msgcat --use-first %s _w.po > __w.po && msgfmt __w.po -o 0w.mo && %s/whattext',
DEFAULT_PUBDIR,
$lang, $mofile,
DEFAULT_PUBDIR);
161 $this->alterState(
"add", $key,
$label, $activity);
167 $this->alterState(
"modify", $key,
$label, $activity);
172 $this->alterState(
"remove", $key);
175 private function alterState($fn, $key,
$label =
'', $activity =
'')
179 if ($this->doc->doctype !=
'W')
return null;
180 $err = $this->doc->lock(
true);
186 $states = $this->doc->getStates();
187 if ($fn ==
"remove") {
189 $cycles = $this->doc->cycle;
190 foreach ($cycles as $k => $v) {
191 if (($v[
"e1"] == $key) || ($v[
"e2"] == $key)) unset($cycles[$k]);
194 foreach ($cycles as $k => $v) {
195 $ncy.= sprintf(
'array("e1"=>"%s", "e2"=>"%s", "t"=>"%s"),' .
"\n", $v[
"e1"], $v[
"e2"], $v[
"t"]);
197 $ncy = substr($ncy, 0, -2) .
")";
198 $this->doc->cycle = $cycles;
202 $fam = $this->doc->getFamDoc();
203 $classname = $fam->classname;
205 if (file_exists(
$file)) {
206 if (!is_writable(
$file)) {
207 $this->doc->unlock(
true);
208 $this->
setError(sprintf(_(
"workflow file %s is not writable") ,
$file));
212 foreach (
$states as $k => $v) {
213 $na.= sprintf(
'"%s"=>"%s",' .
"\n", $k, $v);
215 $na = substr($na, 0, -2) .
")";
217 $nc = preg_replace(
'/public \$states\s*=([^;]*);/i',
"public \$states=$na;",
$content, 1, $count);
219 $nc = preg_replace(
"/(extends WDoc {\s*)/i",
"extends WDoc {\n\tpublic \$states=$na;\n",
$content, 1, $count);
222 if ($ncy) $nc = preg_replace(
'/\$cycle\s*=([^;]*);/i',
"\$cycle=$ncy;", $nc);
229 $na.= sprintf(
'"%s"=>"%s",' .
"\n", $key, $activity);
230 foreach (
$states as $k => $v) {
231 $actid = $this->doc->attrPrefix .
"_ACTIVITYLABEL" . $k;
235 $na.= sprintf(
'"%s"=>"%s",' .
"\n", $k, $actv);
239 $na = substr($na, 0, -2) .
")";
240 $nc = preg_replace(
'/public \$stateactivity\s*=([^;]*);/i',
"public \$stateactivity=$na;", $nc, 1, $count);
242 $nc = preg_replace(
"/(extends WDoc {\s*)/i",
"extends WDoc {\n\tpublic \$stateactivity=$na;\n", $nc, 1, $count);
244 $this->doc->stateactivity[$key] = $activity;
245 $this->doc->postModify();
248 file_put_contents(
$file, $nc);
251 $cmd = $wsh .
" --api=fdl_adoc --docid=" . intval($this->doc->fromid);
258 $err = $this->doc->unlock(
true);
260 $this->
setError(_(
"addState: missing parameter"));
266 function addTransitiontype($key,
$label =
'', $ask = null, $preMethod = null, $postmethod = null, $noComment =
false, $autoNext = null)
268 return $this->alterTransitiontype(
"add", $key,
$label, $ask, $preMethod, $postmethod, $noComment, $autoNext);
273 return $this->alterTransitiontype(
"modify", $key,
$label, $ask, $preMethod, $postmethod, $noComment, $autoNext);
277 return $this->alterTransitiontype(
"remove", $key);
280 private function alterTransitiontype($addorrem, $key,
$label =
'', $ask = null, $preMethod = null, $postmethod = null, $noComment = null, $autoNext = null)
284 if ($this->doc->doctype !=
'W')
return null;
285 $err = $this->doc->lock(
true);
291 $transitions = $this->doc->transitions;
292 if ($addorrem ==
"remove") {
293 unset($transitions[$key]);
294 $cycles = $this->doc->cycle;
295 foreach ($cycles as $k => $v) {
296 if ($v[
"t"] == $key) unset($cycles[$k]);
299 foreach ($cycles as $k => $v) {
300 $ncy.= sprintf(
'array("e1"=>"%s", "e2"=>"%s", "t"=>"%s"),' .
"\n", $v[
"e1"], $v[
"e2"], $v[
"t"]);
302 $ncy = substr($ncy, 0, -2) .
")";
303 $this->doc->cycle = $cycles;
305 if ($addorrem ==
"modify") {
306 $tkey = $transitions[$key];
307 if ($ask === null) $ask = $tkey[
"ask"];
308 if ($preMethod === null) $preMethod = $tkey[
"m1"];
309 if ($postMethod === null) $postMethod = $tkey[
"m2"];
310 if ($noComment === null) $noComment = $tkey[
"nr"];
312 $transitions[$key] = array(
322 $fam = $this->doc->getFamDoc();
323 $classname = $fam->classname;
325 if (file_exists(
$file)) {
326 if (!is_writable(
$file)) {
327 $this->doc->unlock(
true);
328 $this->
setError(sprintf(_(
"workflow file %s is not writable") ,
$file));
332 foreach ($transitions as $k => $v) {
333 if (is_array($v[
"ask"])) {
335 $v[
"ask"] =
'array(';
336 foreach ($sax as $ax) {
337 $v[
"ask"].=
"'" . $ax .
"',";
339 $v[
"ask"] = substr($v[
"ask"], 0, -1) .
")";
341 }
else $v[
"ask"] =
"null";
342 $na.= sprintf(
'"%s"=>array("m1"=>"%s", "m2"=>"%s", "ask"=>%s, "nr"=>%s),' .
"\n", $k, $v[
"m1"], $v[
"m2"], $v[
"ask"], $v[
"nr"] ?
"true" :
"false");
344 $na = substr($na, 0, -2) .
")";
346 $nc = preg_replace(
'/\$transitions\s*=([^;]*);/i',
"\$transitions=$na;",
$content);
347 if ($ncy) $nc = preg_replace(
'/\$cycle\s*=([^;]*);/i',
"\$cycle=$ncy;", $nc);
349 file_put_contents(
$file, $nc);
350 $this->doc->transitions = $transitions;
352 $cmd = $wsh .
" --api=fdl_adoc --docid=" . intval($this->doc->fromid);
359 $err = $this->doc->unlock(
true);
361 $this->
setError(_(
"alterTransitiontype: missing parameter"));