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: }
303:
304: function doWorkflowAction($idartlang, $action) {
305: global $cfg, $idcat;
306:
307: $idartlang = cSecurity::toInteger($idartlang);
308:
309: switch ($action) {
310: case "last":
311: $artAllocations = new WorkflowArtAllocations();
312: $artAllocations->select("idartlang = {$idartlang}");
313:
314: if (($obj = $artAllocations->next()) !== false) {
315: $usersequence = new WorkflowUserSequence();
316: $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
317:
318: $workflowitem = $usersequence->getWorkflowItem();
319:
320: $idworkflow = $workflowitem->get("idworkflow");
321: $newpos = $workflowitem->get("position") - 1;
322:
323: if ($newpos < 1) {
324: $newpos = 1;
325: }
326:
327: $workflowitems = new WorkflowItems();
328: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
329:
330: if (($nextObj = $workflowitems->next()) !== false) {
331: $userSequences = new WorkflowUserSequences();
332: $idworkflowitem = $nextObj->get("idworkflowitem");
333: $userSequences->select("idworkflowitem = '$idworkflowitem'");
334:
335: if (($nextSeqObj = $userSequences->next()) !== false) {
336: $obj->set("lastusersequence", $obj->get("idusersequence"));
337: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
338: $obj->set("laststatus", "last");
339: $obj->store();
340: }
341: }
342: }
343: break;
344: case "next":
345: $artAllocations = new WorkflowArtAllocations();
346: $artAllocations->select("idartlang = {$idartlang}");
347:
348: if (($obj = $artAllocations->next()) !== false) {
349: $usersequence = new WorkflowUserSequence();
350: $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
351:
352: $workflowitem = $usersequence->getWorkflowItem();
353:
354: $idworkflow = $workflowitem->get("idworkflow");
355: $newpos = $workflowitem->get("position") + 1;
356:
357: $workflowitems = new WorkflowItems();
358: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
359:
360: if (($nextObj = $workflowitems->next()) !== false) {
361: $userSequences = new WorkflowUserSequences();
362: $idworkflowitem = $nextObj->get("idworkflowitem");
363: $userSequences->select("idworkflowitem = '$idworkflowitem'");
364:
365: if (($nextSeqObj = $userSequences->next()) !== false) {
366: $obj->set("lastusersequence", '10');
367: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
368: $obj->set("laststatus", "confirm");
369: $obj->store();
370: }
371: } else {
372: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $workflowitem->get("position"));
373: if (($nextObj = $workflowitems->next()) !== false) {
374: $userSequences = new WorkflowUserSequences();
375: $idworkflowitem = $nextObj->get("idworkflowitem");
376: $userSequences->select("idworkflowitem = '$idworkflowitem'");
377:
378: if (($nextSeqObj = $userSequences->next()) !== false) {
379: $obj->set("lastusersequence", $obj->get("idusersequence"));
380: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
381: $obj->set("laststatus", "confirm");
382: $obj->store();
383: }
384: }
385: }
386: }
387: break;
388: case "reject":
389: $artAllocations = new WorkflowArtAllocations();
390: $artAllocations->select("idartlang = {$idartlang}");
391:
392: if (($obj = $artAllocations->next()) !== false) {
393: $usersequence = new WorkflowUserSequence();
394: $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
395:
396: $workflowitem = $usersequence->getWorkflowItem();
397:
398: $idworkflow = $workflowitem->get("idworkflow");
399: $newpos = 1;
400:
401: $workflowitems = new WorkflowItems();
402: $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
403:
404: if (($nextObj = $workflowitems->next()) !== false) {
405: $userSequences = new WorkflowUserSequences();
406: $idworkflowitem = $nextObj->get("idworkflowitem");
407: $userSequences->select("idworkflowitem = '$idworkflowitem'");
408:
409: if (($nextSeqObj = $userSequences->next()) !== false) {
410: $obj->set("lastusersequence", $obj->get("idusersequence"));
411: $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
412: $obj->set("laststatus", "reject");
413: $obj->store();
414: }
415: }
416: }
417: break;
418:
419: case "revise":
420: $db = cRegistry::getDb();
421: $sql = "SELECT idart, idlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = " . $idartlang;
422: $db->query($sql);
423: $db->nextRecord();
424: $idart = $db->f("idart");
425: $idlang = $db->f("idlang");
426:
427: $newidart = conCopyArticle($idart, $idcat, "foo");
428:
429: break;
430: default:
431: }
432: }
433:
434: function getWorkflowForUserSequence($usersequence) {
435: $usersequences = new WorkflowUserSequences();
436: $workflowitems = new WorkflowItems();
437: $usersequences->select("idusersequence = '$usersequence'");
438:
439: if (($obj = $usersequences->next()) !== false) {
440: $idworkflowitem = $obj->get("idworkflowitem");
441: } else {
442: return false;
443: }
444:
445: $workflowitems->select("idworkflowitem = '$idworkflowitem'");
446: if (($obj = $workflowitems->next()) !== false) {
447: return $obj->get("idworkflow");
448: } else {
449: return false;
450: }
451: }
452:
453: function workflowSelect($listid, $default, $idcat) {
454: global $idclient, $cfg, $frame, $area, $workflowworkflows, $client, $lang, $wfcache, $workflowSelectBox;
455:
456: $oSelectBox = new cHTMLSelectElement('workflow');
457: $oSelectBox = $workflowSelectBox;
458:
459: $default = (int) $default;
460: $workflowSelectBox->updateAttributes(array(
461: "id" => "wfselect" . $idcat
462: ));
463: $workflowSelectBox->updateAttributes(array(
464: "name" => "wfselect" . $idcat
465: ));
466: $workflowSelectBox->setDefault($default);
467:
468: $sButton = '<a href="javascript:setWorkflow(' . $idcat . ', \'' . "wfselect" . $idcat . '\')"><img src="' . $cfg["path"]["images"] . 'submit.gif" class="spaced"></a>';
469:
470: return $workflowSelectBox->render() . $sButton;
471: }
472:
473: function workflowInherit($idcat) {
474: global $idclient, $cfg, $frame, $area, $workflowworkflows, $sess;
475: $sUrl = $sess->url("main.php?area=$area&frame=$frame&modidcat=$idcat&action=workflow_inherit_down");
476: $sButton = '<a href="' . $sUrl . '"><img src="' . $cfg["path"]["images"] . 'pfeil_runter.gif" class="spaced" title="' . i18n("Inherit workflow to sub-categories", "workflow") . '"></a>';
477: return $sButton;
478: }
479:
480: ?>