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