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: plugin_include('workflow', 'classes/class.workflow.php');
17: plugin_include('workflow', 'includes/functions.workflow.php');
18:
19: global $_cecRegistry, $lngAct, $modidartlang;
20:
21: $lngAct['workflow']['workflow_delete'] = i18n('Delete workflow', 'workflow');
22: $lngAct['con_workflow']['workflow_task_user_select'] = i18n('Select workflow task', 'workflow');
23: $lngAct['workflow_common']['workflow_show'] = i18n('Show workflow', 'workflow');
24: $lngAct['workflow_common']['workflow_create'] = i18n('Create workflow', 'workflow');
25: $lngAct['workflow_common']['workflow_save'] = i18n('Edit workflow', 'workflow');
26: $lngAct['con']['workflow_do_action'] = i18n('Process workflow step', 'workflow');
27: $lngAct['con_workflow']['workflow_do_action'] = i18n('Process workflow step', 'workflow');
28: $lngAct['str']['workflow_inherit_down'] = i18n('Inherit workflow down', 'workflow');
29: $lngAct['workflow_steps']['workflow_step_edit'] = i18n('Edit workflow step', 'workflow');
30: $lngAct['workflow_steps']['workflow_step_up'] = i18n('Move workflowstep up', 'workflow');
31: $lngAct['workflow_steps']['workflow_step_down'] = i18n('Move workflowstep down', 'workflow');
32: $lngAct['workflow_steps']['workflow_save_step'] = i18n('Save Workflowstep', 'workflow');
33: $lngAct['workflow_steps']['workflow_create_step'] = i18n('Create workflowstep', 'workflow');
34: $lngAct['workflow_steps']['workflow_step_delete'] = i18n('Delete workflowstep', 'workflow');
35: $lngAct['workflow_steps']['workflow_user_up'] = i18n('Move workflowstepuser up', 'workflow');
36: $lngAct['workflow_steps']['workflow_user_down'] = i18n('Move workflowstepuser down', 'workflow');
37: $lngAct['workflow_steps']['workflow_create_user'] = i18n('Create Workflowstepuser', 'workflow');
38: $lngAct['workflow_steps']['workflow_user_delete'] = i18n('Delete Workflowstepuser', 'workflow');
39: $lngAct['str']['workflow_cat_assign'] = i18n('Associate workflow with category', 'workflow');
40:
41: $_cecRegistry->addChainFunction('Contenido.ArticleCategoryList.ListItems', 'piworkflowCreateTasksFolder');
42: $_cecRegistry->addChainFunction('Contenido.ArticleList.Columns', 'piworkflowProcessArticleColumns');
43: $_cecRegistry->addChainFunction('Contenido.ArticleList.Actions', 'piworkflowProcessActions');
44: $_cecRegistry->addChainFunction('Contenido.ArticleList.RenderColumn', 'piworkflowRenderColumn');
45: $_cecRegistry->addChainFunction('Contenido.ArticleList.RenderAction', 'piworkflowRenderAction');
46: $_cecRegistry->addChainFunction('Contenido.CategoryList.Columns', 'piworkflowCategoryColumns');
47: $_cecRegistry->addChainFunction('Contenido.CategoryList.RenderColumn', 'piworkflowCategoryRenderColumn');
48: $_cecRegistry->addChainFunction('Contenido.Frontend.AllowEdit', 'piworkflowAllowArticleEdit');
49:
50: 51: 52: 53: 54:
55: function prepareWorkflowItems() {
56: global $action, $lang, $modidcat, $workflowSelectBox, $workflowworkflows, $client, $tpl, $cfg;
57:
58: $workflowworkflows = new Workflows();
59:
60: if ($action === 'workflow_inherit_down') {
61: $tmp = strDeeperCategoriesArray($modidcat);
62: $asworkflow = getWorkflowForCat($modidcat);
63:
64: $wfa = new WorkflowAllocations();
65:
66: foreach ($tmp as $tmp_cat) {
67: $idcatlang = getCatLang($tmp_cat, $lang);
68:
69: if ($asworkflow == 0) {
70: $wfa->select("idcatlang = '$idcatlang'");
71:
72: if (($item = $wfa->next()) !== false) {
73: $wfa->delete($item->get("idallocation"));
74:
75:
76: $oArticles = new cArticleCollector(array(
77: 'idcat' => $idcatlang,
78: 'start' => true,
79: 'offline' => true
80: ));
81: while (($oArticle = $oArticles->nextArticle()) !== false) {
82: setUserSequence($oArticle->getField('idartlang'), -1);
83: }
84: }
85: } else {
86: $wfa->select("idcatlang = '$idcatlang'");
87:
88: if (($item = $wfa->next()) !== false) {
89: $item->setWorkflow($asworkflow);
90: $item->store();
91: } else {
92: $wfa->create($asworkflow, $idcatlang);
93:
94:
95: $oArticles = new cArticleCollector(array(
96: 'idcat' => $tmp_cat,
97: 'start' => true,
98: 'offline' => true
99: ));
100: while (($oArticle = $oArticles->nextArticle()) !== false) {
101: setUserSequence($oArticle->getField('idartlang'), $asworkflow);
102: }
103: }
104: }
105: }
106: }
107:
108: if ($action == "workflow_cat_assign") {
109: $seltpl = "wfselect" . $modidcat;
110:
111: $wfa = new WorkflowAllocations();
112: $idcatlang = getCatLang($modidcat, $lang);
113:
114:
115: if ($GLOBALS[$seltpl] != 0) {
116: $wfa->select("idcatlang = '$idcatlang'");
117: if (($item = $wfa->next()) !== false) {
118: $item->setWorkflow($GLOBALS[$seltpl]);
119: $item->store();
120: } else {
121: $wfa->create($GLOBALS[$seltpl], $idcatlang);
122: }
123:
124:
125:
126: $oArticles = new cArticleCollector(array(
127: 'idcat' => $modidcat,
128: 'start' => true,
129: 'offline' => true
130: ));
131: while (($oArticle = $oArticles->nextArticle()) !== false) {
132: setUserSequence($oArticle->getField('idartlang'), $GLOBALS[$seltpl]);
133: }
134: } else {
135:
136: $wfa->select("idcatlang = '$idcatlang'");
137:
138: if (($item = $wfa->next()) !== false) {
139: $alloc = $item->get("idallocation");
140: }
141: $wfa->delete($alloc);
142:
143:
144:
145: $oArticles = new cArticleCollector(array(
146: 'idcat' => $modidcat,
147: 'start' => true,
148: 'offline' => true
149: ));
150: while (($oArticle = $oArticles->nextArticle()) !== false) {
151: setUserSequence($oArticle->getField('idartlang'), -1);
152: }
153: }
154: }
155:
156: $workflowSelectBox = new cHTMLSelectElement("foo");
157: $workflowSelectBox->setClass("text_medium");
158: $workflowworkflows->select("idclient = '$client' AND idlang = " . cSecurity::toInteger($lang));
159:
160: $workflowOption = new cHTMLOptionElement("--- " . i18n("None", "workflow") . " ---", 0);
161: $workflowSelectBox->addOptionElement(0, $workflowOption);
162:
163: while (($workflow = $workflowworkflows->next()) !== false) {
164: $wfa = new WorkflowItems();
165: $wfa->select("idworkflow = '".$workflow->get("idworkflow")."'");
166:
167: if ($wfa->next() !== false) {
168: $workflowOption = new cHTMLOptionElement($workflow->get("name"), $workflow->get("idworkflow"));
169: $workflowSelectBox->addOptionElement($workflow->get("idworkflow"), $workflowOption);
170: }
171: }
172:
173: $workflowSelectBox->updateAttributes(array(
174: "id" => "wfselect{IDCAT}"
175: ));
176: $workflowSelectBox->updateAttributes(array(
177: "name" => "wfselect{IDCAT}"
178: ));
179:
180: $tpl->set('s', 'PLUGIN_WORKFLOW', $workflowSelectBox->render() . '<a href="javascript:setWorkflow({IDCAT}, \\\'wfselect{IDCAT}\\\')"><img src="' . $cfg["path"]["images"] . 'submit.gif" class="spaced"></a>');
181: $tpl->set('s', 'PLUGIN_WORKFLOW_TRANSLATION', i18n("Inherit workflow down", "workflow"));
182: }
183:
184: 185: 186: 187: 188: 189: 190: 191:
192: function piworkflowCategoryRenderColumn($idcat, $type) {
193: switch ($type) {
194: case "workflow":
195: $wfForCat = (int) getWorkflowForCat($idcat);
196: $value = workflowInherit($idcat);
197: $value .= <<<JS
198: <script type="text/javascript" id="wf{$idcat}">
199: (function(Con, $) {
200: $(function() {
201: printWorkflowSelect({$idcat}, {$wfForCat});
202: });
203: })(Con, Con.$);
204: </script>
205: JS;
206: break;
207: }
208:
209: return $value;
210: }
211:
212: 213: 214: 215: 216: 217: 218: 219:
220: function piworkflowCategoryColumns($array) {
221: prepareWorkflowItems();
222: $myarray = array(
223: "workflow" => i18n("Workflow", "workflow")
224: );
225:
226: return ($myarray);
227: }
228:
229: 230: 231: 232: 233: 234: 235:
236: function piworkflowProcessActions($array) {
237: global $idcat;
238:
239: $defaultidworkflow = getWorkflowForCat($idcat);
240: if ($defaultidworkflow != 0) {
241: $narray = array(
242: "todo",
243: "wfartconf",
244: "wftplconf",
245: "wfonline",
246: "wflocked",
247: "duplicate",
248: "delete",
249: "usetime"
250: );
251: } else {
252: $narray = $array;
253: }
254:
255: return $narray;
256: }
257:
258: 259: 260: 261: 262: 263: 264: 265: 266: 267:
268: function piworkflowRenderAction($idcat, $idart, $idartlang, $type) {
269: global $area, $frame, $idtpl, $cfg, $alttitle, $tmp_articletitle;
270: global $tmp_artconf, $onlinelink, $lockedlink, $tplconf_link;
271:
272: $defaultidworkflow = getWorkflowForCat($idcat);
273:
274: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
275: $associatedUserSequence = new WorkflowUserSequence();
276: $associatedUserSequence->loadByPrimaryKey($idusersequence);
277:
278: $currentEditor = $associatedUserSequence->get("iduser");
279: $workflowItem = $associatedUserSequence->getWorkflowItem();
280:
281: if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
282:
283: $wfRights = $workflowItem->getStepRights();
284: $mayEdit = true;
285: } else {
286: $wfRights = "";
287: $mayEdit = false;
288: }
289:
290: switch ($type) {
291: case "wfartconf":
292: if ($wfRights["propertyedit"] == true) {
293: return $tmp_artconf;
294: }
295: break;
296: case "wfonline":
297: if ($wfRights["publish"] == true) {
298: return $onlinelink;
299: }
300: break;
301: case "wflocked":
302: if ($wfRights["lock"] == true) {
303: return $lockedlink;
304: }
305: break;
306: case "wftplconf":
307: if ($wfRights["templateedit"] == true) {
308: return $tplconf_link;
309: }
310: break;
311: default:
312: break;
313: }
314:
315: return "";
316: }
317:
318: 319: 320: 321: 322: 323: 324:
325: function piworkflowProcessArticleColumns($array) {
326: global $idcat, $action, $modidartlang;
327:
328: if ($action == "workflow_do_action") {
329: $selectedAction = "wfselect" . $modidartlang;
330: doWorkflowAction($modidartlang, $GLOBALS[$selectedAction]);
331: }
332:
333: $defaultidworkflow = getWorkflowForCat($idcat);
334:
335: if ($defaultidworkflow != 0) {
336: $narray = array();
337: $bInserted = false;
338: foreach ($array as $sKey => $sValue) {
339: $narray[$sKey] = $sValue;
340: if ($sKey == 'title' && !$bInserted) {
341: $narray["wftitle"] = $array["title"];
342: $narray["wfstep"] = i18n("Workflow Step", "workflow");
343: $narray["wfaction"] = i18n("Workflow Action", "workflow");
344: $narray["wfeditor"] = i18n("Workflow Editor", "workflow");
345: $narray["wflaststatus"] = i18n("Last status", "workflow");
346: $bInserted = true;
347: }
348: }
349: unset($narray['title']);
350: unset($narray['changeddate']);
351: unset($narray['publisheddate']);
352: unset($narray['sortorder']);
353: } else {
354: $narray = $array;
355: }
356:
357: return ($narray);
358: }
359:
360: 361: 362: 363: 364: 365: 366: 367: 368: 369:
370: function piworkflowAllowArticleEdit($idlang, $idcat, $idart, $user) {
371: $defaultidworkflow = getWorkflowForCat($idcat);
372:
373: if ($defaultidworkflow == 0) {
374: return true;
375: }
376:
377: $idartlang = getArtLang($idart, $idlang);
378: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
379: $associatedUserSequence = new WorkflowUserSequence();
380: $associatedUserSequence->loadByPrimaryKey($idusersequence);
381:
382: $currentEditor = $associatedUserSequence->get("iduser");
383:
384: $workflowItem = $associatedUserSequence->getWorkflowItem();
385:
386: if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
387: $wfRights = $workflowItem->getStepRights();
388: $mayEdit = true;
389: } else {
390: $wfRights = "";
391: $mayEdit = false;
392: }
393:
394: if ($wfRights["articleedit"] == true) {
395: return true;
396: } else {
397: return false;
398: }
399: }
400:
401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411:
412: function piworkflowRenderColumn($idcat, $idart, $idartlang, $column) {
413: global $area, $frame, $idtpl, $cfg, $alttitle, $tmp_articletitle;
414: $defaultidworkflow = getWorkflowForCat($idcat);
415:
416: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
417: $associatedUserSequence = new WorkflowUserSequence();
418: $associatedUserSequence->loadByPrimaryKey($idusersequence);
419:
420: $currentEditor = $associatedUserSequence->get("iduser");
421:
422: $workflowItem = $associatedUserSequence->getWorkflowItem();
423:
424: if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
425: $wfRights = $workflowItem->getStepRights();
426: $mayEdit = true;
427: } else {
428: $wfRights = "";
429: $mayEdit = false;
430: }
431:
432: switch ($column) {
433: case "wftitle":
434: if ($wfRights["articleedit"] == true) {
435: $mtitle = $tmp_articletitle;
436: } else {
437: $mtitle = strip_tags($tmp_articletitle);
438: }
439: return ($mtitle);
440: case "wfstep":
441: if ($workflowItem === false) {
442: return "nobody";
443: }
444:
445: return ($workflowItem->get("position") . ".) " . $workflowItem->get("name"));
446: case "wfeditor":
447: $sEditor = getGroupOrUserName($currentEditor);
448: if (!$sEditor) {
449: $sEditor = "nobody";
450: }
451: return $sEditor;
452: case "wfaction":
453: $defaultidworkflow = getWorkflowForCat($idcat);
454: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
455:
456: $sActionSelect = getActionSelect($idartlang, $idusersequence);
457: if (!$sActionSelect) {
458: $mayEdit = false;
459: }
460:
461: $form = new cHTMLForm("wfaction" . $idartlang, "main.php", "get");
462: $form->setVar("area", $area);
463: $form->setVar("action", "workflow_do_action");
464: $form->setVar("frame", $frame);
465: $form->setVar("idcat", $idcat);
466: $form->setVar("modidartlang", $idartlang);
467: $form->setVar("idtpl", $idtpl);
468: $form->appendContent('<table cellspacing="0" border="0"><tr><td>' . $sActionSelect . '</td><td>');
469: $form->appendContent('<input type="image" src="' . $cfg["path"]["htmlpath"] . $cfg["path"]["images"] . "submit.gif" . '"></tr></table>');
470:
471: if ($mayEdit == true) {
472: return ($form->render());
473: } else {
474: return '--- ' . i18n("None") . ' ---';
475: }
476:
477: case "wflaststatus":
478: $sStatus = getLastWorkflowStatus($idartlang);
479: if (!$sStatus) {
480: $sStatus = '--- ' . i18n("None") . ' ---';
481: }
482: return $sStatus;
483: }
484: }
485:
486: 487: 488:
489: function piworkflowCreateTasksFolder() {
490: global $sess, $cfg;
491:
492: $item = array();
493:
494:
495: $tmp_mstr = '<a href="javascript://" onclick="javascript:Con.multiLink(\'%s\', \'%s\', \'%s\', \'%s\')">%s</a>';
496:
497: $mstr = sprintf($tmp_mstr, 'right_bottom', $sess->url("main.php?area=con_workflow&frame=4"), 'right_top', $sess->url("main.php?area=con_workflow&frame=3"), 'Workflow / Todo');
498:
499: $item["image"] = '<img alt="" src="' . cRegistry::getBackendUrl() . $cfg["path"]["plugins"] . 'workflow/images/workflow_erstellen.gif">';
500: $item["title"] = $mstr;
501:
502: return ($item);
503: }
504: