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