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: function prepareWorkflowItems() {
51: global $action, $lang, $modidcat, $workflowSelectBox, $workflowworkflows, $client, $tpl, $cfg;
52:
53: $workflowworkflows = new Workflows();
54:
55: if ($action === 'workflow_inherit_down') {
56: $tmp = strDeeperCategoriesArray($modidcat);
57: $asworkflow = getWorkflowForCat($modidcat);
58:
59: $wfa = new WorkflowAllocations();
60:
61: foreach ($tmp as $tmp_cat) {
62: $idcatlang = getCatLang($tmp_cat, $lang);
63:
64: if ($asworkflow == 0) {
65: $wfa->select("idcatlang = '$idcatlang'");
66:
67: if (($item = $wfa->next()) !== false) {
68: $wfa->delete($item->get("idallocation"));
69:
70:
71: $oArticles = new cArticleCollector(array(
72: 'idcat' => $idcatlang,
73: 'start' => true,
74: 'offline' => true
75: ));
76: while (($oArticle = $oArticles->nextArticle()) !== false) {
77: setUserSequence($oArticle->getField('idartlang'), -1);
78: }
79: }
80: } else {
81: $wfa->select("idcatlang = '$idcatlang'");
82:
83: if (($item = $wfa->next()) !== false) {
84: $item->setWorkflow($asworkflow);
85: $item->store();
86: } else {
87: $wfa->create($asworkflow, $idcatlang);
88:
89:
90: $oArticles = new cArticleCollector(array(
91: 'idcat' => $tmp_cat,
92: 'start' => true,
93: 'offline' => true
94: ));
95: while (($oArticle = $oArticles->nextArticle()) !== false) {
96: setUserSequence($oArticle->getField('idartlang'), $asworkflow);
97: }
98: }
99: }
100: }
101: }
102:
103: if ($action == "workflow_cat_assign") {
104: $seltpl = "wfselect" . $modidcat;
105:
106: $wfa = new WorkflowAllocations();
107: $idcatlang = getCatLang($modidcat, $lang);
108:
109:
110: if ($GLOBALS[$seltpl] != 0) {
111: $wfa->select("idcatlang = '$idcatlang'");
112: if (($item = $wfa->next()) !== false) {
113: $item->setWorkflow($GLOBALS[$seltpl]);
114: $item->store();
115: } else {
116: $wfa->create($GLOBALS[$seltpl], $idcatlang);
117: }
118:
119:
120:
121: $oArticles = new cArticleCollector(array(
122: 'idcat' => $modidcat,
123: 'start' => true,
124: 'offline' => true
125: ));
126: while (($oArticle = $oArticles->nextArticle()) !== false) {
127: setUserSequence($oArticle->getField('idartlang'), $GLOBALS[$seltpl]);
128: }
129: } else {
130:
131: $wfa->select("idcatlang = '$idcatlang'");
132:
133: if (($item = $wfa->next()) !== false) {
134: $alloc = $item->get("idallocation");
135: }
136: $wfa->delete($alloc);
137:
138:
139:
140: $oArticles = new cArticleCollector(array(
141: 'idcat' => $modidcat,
142: 'start' => true,
143: 'offline' => true
144: ));
145: while (($oArticle = $oArticles->nextArticle()) !== false) {
146: setUserSequence($oArticle->getField('idartlang'), -1);
147: }
148: }
149: }
150:
151: $workflowSelectBox = new cHTMLSelectElement("foo");
152: $workflowSelectBox->setClass("text_medium");
153: $workflowworkflows->select("idclient = '$client' AND idlang = " . cSecurity::toInteger($lang));
154:
155: $workflowOption = new cHTMLOptionElement("--- " . i18n("None", "workflow") . " ---", 0);
156: $workflowSelectBox->addOptionElement(0, $workflowOption);
157:
158: while (($workflow = $workflowworkflows->next()) !== false) {
159: $wfa = new WorkflowItems();
160: $wfa->select("idworkflow = '".$workflow->get("idworkflow")."'");
161:
162: if ($wfa->next() !== false) {
163: $workflowOption = new cHTMLOptionElement($workflow->get("name"), $workflow->get("idworkflow"));
164: $workflowSelectBox->addOptionElement($workflow->get("idworkflow"), $workflowOption);
165: }
166: }
167:
168: $workflowSelectBox->updateAttributes(array(
169: "id" => "wfselect{IDCAT}"
170: ));
171: $workflowSelectBox->updateAttributes(array(
172: "name" => "wfselect{IDCAT}"
173: ));
174:
175: $tpl->set('s', 'PLUGIN_WORKFLOW', $workflowSelectBox->render() . '<a href="javascript:setWorkflow({IDCAT}, \\\'wfselect{IDCAT}\\\')"><img src="' . $cfg["path"]["images"] . 'submit.gif" class="spaced"></a>');
176: $tpl->set('s', 'PLUGIN_WORKFLOW_TRANSLATION', i18n("Inherit workflow down", "workflow"));
177: }
178:
179: function piworkflowCategoryRenderColumn($idcat, $type) {
180: switch ($type) {
181: case "workflow":
182: $wfForCat = (int) getWorkflowForCat($idcat);
183: $value = workflowInherit($idcat);
184: $value .= <<<JS
185: <script type="text/javascript" id="wf{$idcat}">
186: (function(Con, $) {
187: $(function() {
188: printWorkflowSelect({$idcat}, {$wfForCat});
189: });
190: })(Con, Con.$);
191: </script>
192: JS;
193: break;
194: }
195:
196: return $value;
197: }
198:
199: function piworkflowCategoryColumns($array) {
200: prepareWorkflowItems();
201: $myarray = array(
202: "workflow" => i18n("Workflow", "workflow")
203: );
204:
205: return ($myarray);
206: }
207:
208: function piworkflowProcessActions($array) {
209: global $idcat;
210:
211: $defaultidworkflow = getWorkflowForCat($idcat);
212: if ($defaultidworkflow != 0) {
213: $narray = array(
214: "todo",
215: "wfartconf",
216: "wftplconf",
217: "wfonline",
218: "wflocked",
219: "duplicate",
220: "delete",
221: "usetime"
222: );
223: } else {
224: $narray = $array;
225: }
226:
227: return $narray;
228: }
229:
230: function piworkflowRenderAction($idcat, $idart, $idartlang, $type) {
231: global $area, $frame, $idtpl, $cfg, $alttitle, $tmp_articletitle;
232: global $tmp_artconf, $onlinelink, $lockedlink, $tplconf_link;
233:
234: $defaultidworkflow = getWorkflowForCat($idcat);
235:
236: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
237: $associatedUserSequence = new WorkflowUserSequence();
238: $associatedUserSequence->loadByPrimaryKey($idusersequence);
239:
240: $currentEditor = $associatedUserSequence->get("iduser");
241: $workflowItem = $associatedUserSequence->getWorkflowItem();
242:
243: if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
244:
245: $wfRights = $workflowItem->getStepRights();
246: $mayEdit = true;
247: } else {
248: $wfRights = "";
249: $mayEdit = false;
250: }
251:
252: switch ($type) {
253: case "wfartconf":
254: if ($wfRights["propertyedit"] == true) {
255: return $tmp_artconf;
256: }
257: break;
258: case "wfonline":
259: if ($wfRights["publish"] == true) {
260: return $onlinelink;
261: }
262: break;
263: case "wflocked":
264: if ($wfRights["lock"] == true) {
265: return $lockedlink;
266: }
267: break;
268: case "wftplconf":
269: if ($wfRights["templateedit"] == true) {
270: return $tplconf_link;
271: }
272: break;
273: default:
274: break;
275: }
276:
277: return "";
278: }
279:
280: function piworkflowProcessArticleColumns($array) {
281: global $idcat, $action, $modidartlang;
282:
283: if ($action == "workflow_do_action") {
284: $selectedAction = "wfselect" . $modidartlang;
285: doWorkflowAction($modidartlang, $GLOBALS[$selectedAction]);
286: }
287:
288: $defaultidworkflow = getWorkflowForCat($idcat);
289:
290: if ($defaultidworkflow != 0) {
291: $narray = array();
292: $bInserted = false;
293: foreach ($array as $sKey => $sValue) {
294: $narray[$sKey] = $sValue;
295: if ($sKey == 'title' && !$bInserted) {
296: $narray["wftitle"] = $array["title"];
297: $narray["wfstep"] = i18n("Workflow Step", "workflow");
298: $narray["wfaction"] = i18n("Workflow Action", "workflow");
299: $narray["wfeditor"] = i18n("Workflow Editor", "workflow");
300: $narray["wflaststatus"] = i18n("Last status", "workflow");
301: $bInserted = true;
302: }
303: }
304: unset($narray['title']);
305: unset($narray['changeddate']);
306: unset($narray['publisheddate']);
307: unset($narray['sortorder']);
308: } else {
309: $narray = $array;
310: }
311:
312: return ($narray);
313: }
314:
315: function piworkflowAllowArticleEdit($idlang, $idcat, $idart, $user) {
316: $defaultidworkflow = getWorkflowForCat($idcat);
317:
318: if ($defaultidworkflow == 0) {
319: return true;
320: }
321:
322: $idartlang = getArtLang($idart, $idlang);
323: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
324: $associatedUserSequence = new WorkflowUserSequence();
325: $associatedUserSequence->loadByPrimaryKey($idusersequence);
326:
327: $currentEditor = $associatedUserSequence->get("iduser");
328:
329: $workflowItem = $associatedUserSequence->getWorkflowItem();
330:
331: if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
332: $wfRights = $workflowItem->getStepRights();
333: $mayEdit = true;
334: } else {
335: $wfRights = "";
336: $mayEdit = false;
337: }
338:
339: if ($wfRights["articleedit"] == true) {
340: return true;
341: } else {
342: return false;
343: }
344: }
345:
346: function piworkflowRenderColumn($idcat, $idart, $idartlang, $column) {
347: global $area, $frame, $idtpl, $cfg, $alttitle, $tmp_articletitle;
348: $defaultidworkflow = getWorkflowForCat($idcat);
349:
350: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
351: $associatedUserSequence = new WorkflowUserSequence();
352: $associatedUserSequence->loadByPrimaryKey($idusersequence);
353:
354: $currentEditor = $associatedUserSequence->get("iduser");
355:
356: $workflowItem = $associatedUserSequence->getWorkflowItem();
357:
358: if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
359: $wfRights = $workflowItem->getStepRights();
360: $mayEdit = true;
361: } else {
362: $wfRights = "";
363: $mayEdit = false;
364: }
365:
366: switch ($column) {
367: case "wftitle":
368: if ($wfRights["articleedit"] == true) {
369: $mtitle = $tmp_articletitle;
370: } else {
371: $mtitle = strip_tags($tmp_articletitle);
372: }
373: return ($mtitle);
374: case "wfstep":
375: if ($workflowItem === false) {
376: return "nobody";
377: }
378:
379: return ($workflowItem->get("position") . ".) " . $workflowItem->get("name"));
380: case "wfeditor":
381: $sEditor = getGroupOrUserName($currentEditor);
382: if (!$sEditor) {
383: $sEditor = "nobody";
384: }
385: return $sEditor;
386: case "wfaction":
387: $defaultidworkflow = getWorkflowForCat($idcat);
388: $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
389:
390: $sActionSelect = getActionSelect($idartlang, $idusersequence);
391: if (!$sActionSelect) {
392: $mayEdit = false;
393: }
394:
395: $form = new cHTMLForm("wfaction" . $idartlang, "main.php", "get");
396: $form->setVar("area", $area);
397: $form->setVar("action", "workflow_do_action");
398: $form->setVar("frame", $frame);
399: $form->setVar("idcat", $idcat);
400: $form->setVar("modidartlang", $idartlang);
401: $form->setVar("idtpl", $idtpl);
402: $form->appendContent('<table cellspacing="0" border="0"><tr><td>' . $sActionSelect . '</td><td>');
403: $form->appendContent('<input type="image" src="' . $cfg["path"]["htmlpath"] . $cfg["path"]["images"] . "submit.gif" . '"></tr></table>');
404:
405: if ($mayEdit == true) {
406: return ($form->render());
407: } else {
408: return '--- ' . i18n("None") . ' ---';
409: }
410:
411: case "wflaststatus":
412: $sStatus = getLastWorkflowStatus($idartlang);
413: if (!$sStatus) {
414: $sStatus = '--- ' . i18n("None") . ' ---';
415: }
416: return $sStatus;
417: }
418: }
419:
420: function piworkflowCreateTasksFolder() {
421: global $sess, $cfg;
422:
423: $item = array();
424:
425:
426: $tmp_mstr = '<a href="javascript://" onclick="javascript:Con.multiLink(\'%s\', \'%s\', \'%s\', \'%s\')">%s</a>';
427:
428: $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');
429:
430: $item["image"] = '<img alt="" src="' . cRegistry::getBackendUrl() . $cfg["path"]["plugins"] . 'workflow/images/workflow_erstellen.gif">';
431: $item["title"] = $mstr;
432:
433: return ($item);
434: }
435: