1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude("includes", "functions.con.php");
19:
20: plugin_include('workflow', 'classes/class.workflowitems.php');
21:
22: function getUsers($listid, $default) {
23: global $idclient, $cfg, $auth;
24:
25: $userColl = new cApiUserCollection();
26: $users = $userColl->getAccessibleUsers(explode(',', $auth->auth['perm']));
27: $groupColl = new cApiGroupCollection();
28: $groups = $groupColl->getAccessibleGroups(explode(',', $auth->auth['perm']));
29:
30: $tpl2 = new cTemplate();
31: $tpl2->set('s', 'NAME', 'user' . $listid);
32: $tpl2->set('s', 'CLASS', 'text_small');
33: $tpl2->set('s', 'OPTIONS', 'size=1');
34:
35: $tpl2->set('d', 'VALUE', 0);
36: $tpl2->set('d', 'CAPTION', '--- ' . i18n("None", "workflow") . ' ---');
37: if ($default == 0) {
38: $tpl2->set('d', 'SELECTED', 'SELECTED');
39: } else {
40: $tpl2->set('d', 'SELECTED', '');
41: }
42: $tpl2->next();
43:
44: if (is_array($users)) {
45: foreach ($users as $key => $value) {
46: $tpl2->set('d', 'VALUE', $key);
47: $tpl2->set('d', 'CAPTION', $value["realname"] . " (" . $value["username"] . ")");
48:
49: if ($default == $key) {
50: $tpl2->set('d', 'SELECTED', 'SELECTED');
51: } else {
52: $tpl2->set('d', 'SELECTED', '');
53: }
54:
55: $tpl2->next();
56: }
57: }
58:
59: $tpl2->set('d', 'VALUE', '0');
60: $tpl2->set('d', 'CAPTION', '------------------------------------');
61: $tpl2->set('d', 'SELECTED', 'disabled');
62: $tpl2->next();
63:
64: if (is_array($groups)) {
65: foreach ($groups as $key => $value) {
66: $tpl2->set('d', 'VALUE', $key);
67: $tpl2->set('d', 'CAPTION', $value["groupname"]);
68:
69: if ($default == $key) {
70: $tpl2->set('d', 'SELECTED', 'SELECTED');
71: } else {
72: $tpl2->set('d', 'SELECTED', '');
73: }
74:
75: $tpl2->next();
76: }
77: }
78:
79: return $tpl2->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
80: }
81:
82: function isCurrentEditor($uid) {
83: global $auth, $cfg;
84:
85:
86: $user = new cApiUser();
87: if ($user->loadByPrimaryKey($uid) == false) {
88: $db2 = cRegistry::getDb();
89:
90:
91: $sql = "SELECT user_id FROM " . $cfg["tab"]["groupmembers"] . "
92: WHERE group_id = '" . $db2->escape($uid) . "'";
93:
94: $db2->query($sql);
95:
96: while ($db2->nextRecord()) {
97: if ($db2->f("user_id") == $auth->auth["uid"]) {
98: return true;
99: }
100: }
101: } else {
102: if ($uid == $auth->auth["uid"]) {
103: return true;
104: }
105: }
106:
107: return false;
108: }
109:
110: function getActionSelect($idartlang, $idusersequence) {
111: global $cfg;
112:
113: $workflowActions = new WorkflowActions();
114:
115: $allActions = $workflowActions->getAvailableWorkflowActions();
116:
117: $wfSelect = new cTemplate();
118: $wfSelect->set('s', 'NAME', 'wfselect' . $idartlang);
119: $wfSelect->set('s', 'CLASS', 'text_medium');
120:
121: $userSequence = new WorkflowUserSequence();
122: $userSequence->loadByPrimaryKey($idusersequence);
123:
124: $workflowItem = $userSequence->getWorkflowItem();
125:
126: if ($workflowItem === false) {
127: return;
128: }
129:
130: $wfRights = $workflowItem->getStepRights();
131:
132: $artAllocation = new WorkflowArtAllocations();
133: $artAllocation->select("idartlang = '$idartlang'");
134:
135: if (($obj = $artAllocation->next()) !== false) {
136: $laststep = $obj->get("lastusersequence");
137: }
138:
139: $bExistOption = false;
140: if ($laststep != $idusersequence) {
141: $wfSelect->set('d', 'VALUE', 'next');
142: $wfSelect->set('d', 'CAPTION', i18n("Confirm", "workflow"));
143: $wfSelect->set('d', 'SELECTED', 'SELECTED');
144: $wfSelect->next();
145: $bExistOption = true;
146: }
147:
148: if ($wfRights["last"] == true) {
149: $wfSelect->set('d', 'VALUE', 'last');
150: $wfSelect->set('d', 'CAPTION', i18n("Back to last editor", "workflow"));
151: $wfSelect->set('d', 'SELECTED', '');
152: $wfSelect->next();
153: $bExistOption = true;
154: }
155:
156: if ($wfRights["reject"] == true) {
157: $wfSelect->set('d', 'VALUE', 'reject');
158: $wfSelect->set('d', 'CAPTION', i18n("Reject article", "workflow"));
159: $wfSelect->set('d', 'SELECTED', '');
160: $wfSelect->next();
161: $bExistOption = true;
162: }
163:
164: if ($wfRights["revise"] == true) {
165: $wfSelect->set('d', 'VALUE', 'revise');
166: $wfSelect->set('d', 'CAPTION', i18n("Revise article", "workflow"));
167: $wfSelect->set('d', 'SELECTED', '');
168: $wfSelect->next();
169: $bExistOption = true;
170: }
171:
172: if ($bExistOption)
173: return ($wfSelect->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true));
174: else {
175: return false;
176: }
177: }
178:
179:
180:
181: function setUserSequence($idartlang, $defaultidworkflow) {
182: $wfaa = new WorkflowArtAllocations();
183: $wfaa->select("idartlang = '$idartlang'");
184: $idusersequence = 0;
185:
186: if (($associatedUserSequence = $wfaa->next()) !== false) {
187: $idartallocation = $associatedUserSequence->get("idartallocation");
188: $wfaa->delete($idartallocation);
189: }
190:
191: if ($defaultidworkflow != -1) {
192: $newObj = $wfaa->create($idartlang);
193:
194: if (!$newObj) {
195: return false;
196: }
197:
198:
199: $workflowItems = new WorkflowItems();
200: $workflowItems->select("idworkflow = '$defaultidworkflow' AND position = '1'");
201:
202: if (($obj = $workflowItems->next()) !== false) {
203: $firstitem = $obj->get("idworkflowitem");
204: }
205:
206: $workflowUserSequences = new WorkflowUserSequences();
207: $workflowUserSequences->select("idworkflowitem = '$firstitem' AND position = '1'");
208:
209: if (($obj = $workflowUserSequences->next()) !== false) {
210: $firstIDUserSequence = $obj->get("idusersequence");
211: }
212:
213: $newObj->set("idusersequence", $firstIDUserSequence);
214: $newObj->store();
215:
216: $idusersequence = $newObj->get("idusersequence");
217: $associatedUserSequence = $newObj;
218: }
219: }
220:
221: 222: 223: 224: 225: 226: 227: 228:
229: function getCurrentUserSequence($idartlang, $defaultidworkflow) {
230: $wfaa = new WorkflowArtAllocations();
231: $wfaa->select("idartlang = '$idartlang'");
232: $idusersequence = 0;
233:
234: if (($associatedUserSequence = $wfaa->next()) !== false) {
235: $idusersequence = $associatedUserSequence->get("idusersequence");
236: }
237:
238: if ($idusersequence == 0) {
239: if ($associatedUserSequence != false) {
240: $newObj = $associatedUserSequence;
241: } else {
242: $newObj = $wfaa->create($idartlang);
243:
244: if (!$newObj) {
245: return false;
246: }
247: }
248:
249:
250: $workflowItems = new WorkflowItems();
251: $workflowItems->select("idworkflow = '$defaultidworkflow' AND position = '1'");
252:
253: if (($obj = $workflowItems->next()) !== false) {
254: $firstitem = $obj->get("idworkflowitem");
255: }
256:
257: $workflowUserSequences = new WorkflowUserSequences();
258: $workflowUserSequences->select("idworkflowitem = '$firstitem' AND position = '1'");
259:
260: if (($obj = $workflowUserSequences->next()) !== false) {
261: $firstIDUserSequence = $obj->get("idusersequence");
262: }
263:
264: $newObj->set("idusersequence", $firstIDUserSequence);
265: $newObj->store();
266:
267: $idusersequence = $newObj->get("idusersequence");
268: $associatedUserSequence = $newObj;
269: }
270:
271: return $idusersequence;
272: }
273:
274: function getLastWorkflowStatus($idartlang) {
275: $wfaa = new WorkflowArtAllocations();
276:
277: $wfaa->select("idartlang = '$idartlang'");
278:
279: if (($associatedUserSequence = $wfaa->next()) !== false) {
280: $laststatus = $associatedUserSequence->get("laststatus");
281: } else {
282: return false;
283: }
284:
285: switch ($laststatus) {
286: case "reject":
287: return (i18n("Rejected", "workflow"));
288: break;
289: case "revise":
290: return (i18n("Revised", "workflow"));
291: break;
292: case "last":
293: return (i18n("Last", "workflow"));
294: break;
295: case "confirm":
296: return (i18n("Confirmed", "workflow"));
297: break;
298: default:
299: return (i18n("None", "workflow"));
300: break;
301: }
302: return "";
303: }
304:
305: function doWorkflowAction($idartlang, $action) {
306: global $cfg, $idcat;
307:
308: $idartlang = cSecurity::toInteger($idartlang);
309:
310: switch ($action) {
311: case "last":
312: $artAllocations = new WorkflowArtAllocations();
313: $artAllocations->select("idartlang = {$idartlang}");
314:
315: if (($obj = $artAllocations->next()) !== false) {
316: $usersequence = new WorkflowUserSequence();
317: $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
318:
319: $workflowitem = $usersequence->getWorkflowItem();
320:
321: $idworkflow = $workflowitem->get("idworkflow");
322: $newpos = $workflowitem->get("position") - 1;
323:
324: if ($newpos < 1) {
325: $newpos = 1;
326: }
327:
328: $workflowitems = new WorkflowItems();
329: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
330:
331: if (($nextObj = $workflowitems->next()) !== false) {
332: $userSequences = new WorkflowUserSequences();
333: $idworkflowitem = $nextObj->get("idworkflowitem");
334: $userSequences->select("idworkflowitem = '$idworkflowitem'");
335:
336: if (($nextSeqObj = $userSequences->next()) !== false) {
337: $obj->set("lastusersequence", $obj->get("idusersequence"));
338: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
339: $obj->set("laststatus", "last");
340: $obj->store();
341: }
342: }
343: }
344: break;
345: case "next":
346: $artAllocations = new WorkflowArtAllocations();
347: $artAllocations->select("idartlang = {$idartlang}");
348:
349: if (($obj = $artAllocations->next()) !== false) {
350: $usersequence = new WorkflowUserSequence();
351: $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
352:
353: $workflowitem = $usersequence->getWorkflowItem();
354:
355: $idworkflow = $workflowitem->get("idworkflow");
356: $newpos = $workflowitem->get("position") + 1;
357:
358: $workflowitems = new WorkflowItems();
359: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
360:
361: if (($nextObj = $workflowitems->next()) !== false) {
362: $userSequences = new WorkflowUserSequences();
363: $idworkflowitem = $nextObj->get("idworkflowitem");
364: $userSequences->select("idworkflowitem = '$idworkflowitem'");
365:
366: if (($nextSeqObj = $userSequences->next()) !== false) {
367: $obj->set("lastusersequence", '10');
368: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
369: $obj->set("laststatus", "confirm");
370: $obj->store();
371: }
372: } else {
373: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $workflowitem->get("position"));
374: if (($nextObj = $workflowitems->next()) !== false) {
375: $userSequences = new WorkflowUserSequences();
376: $idworkflowitem = $nextObj->get("idworkflowitem");
377: $userSequences->select("idworkflowitem = '$idworkflowitem'");
378:
379: if (($nextSeqObj = $userSequences->next()) !== false) {
380: $obj->set("lastusersequence", $obj->get("idusersequence"));
381: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
382: $obj->set("laststatus", "confirm");
383: $obj->store();
384: }
385: }
386: }
387: }
388: break;
389: case "reject":
390: $artAllocations = new WorkflowArtAllocations();
391: $artAllocations->select("idartlang = {$idartlang}");
392:
393: if (($obj = $artAllocations->next()) !== false) {
394: $usersequence = new WorkflowUserSequence();
395: $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
396:
397: $workflowitem = $usersequence->getWorkflowItem();
398:
399: $idworkflow = $workflowitem->get("idworkflow");
400: $newpos = 1;
401:
402: $workflowitems = new WorkflowItems();
403: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
404:
405: if (($nextObj = $workflowitems->next()) !== false) {
406: $userSequences = new WorkflowUserSequences();
407: $idworkflowitem = $nextObj->get("idworkflowitem");
408: $userSequences->select("idworkflowitem = '$idworkflowitem'");
409:
410: if (($nextSeqObj = $userSequences->next()) !== false) {
411: $obj->set("lastusersequence", $obj->get("idusersequence"));
412: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
413: $obj->set("laststatus", "reject");
414: $obj->store();
415: }
416: }
417: }
418: break;
419:
420: case "revise":
421: $db = cRegistry::getDb();
422: $sql = "SELECT idart, idlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = " . $idartlang;
423: $db->query($sql);
424: $db->nextRecord();
425: $idart = $db->f("idart");
426: $idlang = $db->f("idlang");
427:
428: $newidart = conCopyArticle($idart, $idcat, "foo");
429:
430: break;
431: default:
432: }
433: }
434:
435: function getWorkflowForUserSequence($usersequence) {
436: $usersequences = new WorkflowUserSequences();
437: $workflowitems = new WorkflowItems();
438: $usersequences->select("idusersequence = '$usersequence'");
439:
440: if (($obj = $usersequences->next()) !== false) {
441: $idworkflowitem = $obj->get("idworkflowitem");
442: } else {
443: return false;
444: }
445:
446: $workflowitems->select("idworkflowitem = '$idworkflowitem'");
447: if (($obj = $workflowitems->next()) !== false) {
448: return $obj->get("idworkflow");
449: } else {
450: return false;
451: }
452: }
453:
454: function workflowSelect($listid, $default, $idcat) {
455: global $idclient, $cfg, $frame, $area, $workflowworkflows, $client, $lang, $wfcache, $workflowSelectBox;
456:
457: $oSelectBox = new cHTMLSelectElement('workflow');
458: $oSelectBox = $workflowSelectBox;
459:
460: $default = (int) $default;
461: $workflowSelectBox->updateAttributes(array(
462: "id" => "wfselect" . $idcat
463: ));
464: $workflowSelectBox->updateAttributes(array(
465: "name" => "wfselect" . $idcat
466: ));
467: $workflowSelectBox->setDefault($default);
468:
469: $sButton = '<a href="javascript:setWorkflow(' . $idcat . ', \'' . "wfselect" . $idcat . '\')"><img src="' . $cfg["path"]["images"] . 'submit.gif" class="spaced"></a>';
470:
471: return $workflowSelectBox->render() . $sButton;
472: }
473:
474: function workflowInherit($idcat) {
475: global $idclient, $cfg, $frame, $area, $workflowworkflows, $sess;
476: $sUrl = $sess->url("main.php?area=$area&frame=$frame&modidcat=$idcat&action=workflow_inherit_down");
477: $sButton = '<a href="' . $sUrl . '"><img src="' . $cfg["path"]["images"] . 'pfeil_runter.gif" class="spaced" title="' . i18n("Inherit workflow to sub-categories", "workflow") . '"></a>';
478: return $sButton;
479: }
480:
481: ?>