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