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