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: cInclude("includes", "functions.encoding.php");
19:
20: $page = new cGuiPage("workflow_steps", "workflow");
21: $page->addStyle('workflow.css');
22:
23: $iIdMarked = (int) $_GET['idworkflowitem'];
24:
25: $workflowActions = new WorkflowActions();
26:
27: $availableWorkflowActions = $workflowActions->getAvailableWorkflowActions();
28:
29: $sCurrentEncoding = cRegistry::getEncoding();
30:
31: if (conHtmlentities($adduser, ENT_COMPAT, $sCurrentEncoding) == i18n("Add User", "workflow")) {
32: $action = "workflow_create_user";
33: }
34:
35:
36: if ($action == "workflow_step_up") {
37: $workflowitems = new WorkflowItems();
38: $workflowitems->swap($idworkflow, $position, $position - 1);
39: }
40:
41:
42: if ($action == "workflow_step_down") {
43: $workflowitems = new WorkflowItems();
44: $workflowitems->swap($idworkflow, $position, $position + 1);
45: }
46:
47:
48: if ($action == "workflow_user_up") {
49: $workflowitems = new WorkflowUserSequences();
50: $workflowitems->swap($idworkflowitem, $position, $position - 1);
51: }
52:
53:
54: if ($action == "workflow_user_down") {
55: $workflowitems = new WorkflowUserSequences();
56: $workflowitems->swap($idworkflowitem, $position, $position + 1);
57: }
58:
59:
60: if ($action == "workflow_create_step") {
61: $workflowitems = new WorkflowItems();
62: $item = $workflowitems->create($idworkflow);
63: $item->set("name", i18n("New Workflow Step", "workflow"));
64: $item->store();
65: $idworkflowitem = $item->get("idworkflowitem");
66: }
67:
68:
69: if ($action == "workflow_step_delete") {
70: $workflowitems = new WorkflowItems();
71: $workflowitems->delete($idworkflowitem);
72: }
73:
74:
75: if ($action == "workflow_create_user") {
76: $workflowusers = new WorkflowUserSequences();
77: $new = $workflowusers->create($idworkflowitem);
78: }
79:
80:
81: if ($action == "workflow_user_delete") {
82: $workflowusers = new WorkflowUserSequences();
83: $workflowusers->delete($idusersequence);
84: }
85:
86:
87: if ($action == "workflow_save_step" || $action == "workflow_create_user") {
88: $workflowactions = new WorkflowActions();
89:
90: foreach ($availableWorkflowActions as $key => $value) {
91: if ($wfactions[$key] == 1) {
92: $workflowactions->set($idworkflowitem, $key);
93: } else {
94: $workflowactions->remove($idworkflowitem, $key);
95: }
96: }
97:
98: $workflowitem = new WorkflowItem();
99: $workflowitem->loadByPrimaryKey($idworkflowitem);
100: $workflowitem->setField('idtask', $wftaskselect);
101: $workflowitem->setField('name', str_replace('\\','',$wfstepname));
102: $workflowitem->setField('description', str_replace('\\','',$wfstepdescription));
103: $workflowitem->store();
104:
105: $usersequences = new WorkflowUserSequences();
106: $usersequences->select("idworkflowitem = '$idworkflowitem'");
107:
108: while (($usersequence = $usersequences->next()) !== false) {
109: $wftime = "time" . $usersequence->get("idusersequence");
110: $wfuser = "user" . $usersequence->get("idusersequence");
111:
112: $wftimelimit = "wftimelimit" . $usersequence->get("idusersequence");
113: $usersequence->set("timeunit", $$wftime);
114: $usersequence->set("iduser", $$wfuser);
115: $usersequence->set("timelimit", $$wftimelimit);
116: $usersequence->set("emailnoti", $wfemailnoti[$usersequence->get("idusersequence")]);
117: $usersequence->set("escalationnoti", $wfescalnoti[$usersequence->get("idusersequence")]);
118: $usersequence->store();
119: }
120: }
121:
122: 123: 124: 125: 126: 127: 128:
129: function getTimeUnitSelector($listid, $default) {
130: global $idclient, $cfg, $auth;
131:
132: $timeunits = array();
133: $timeunits['Seconds'] = i18n("Seconds", "workflow");
134: $timeunits['Minutes'] = i18n("Minutes", "workflow");
135: $timeunits['Hours'] = i18n("Hours", "workflow");
136: $timeunits['Days'] = i18n("Days", "workflow");
137: $timeunits['Weeks'] = i18n("Weeks", "workflow");
138: $timeunits['Months'] = i18n("Months", "workflow");
139: $timeunits['Years'] = i18n("Years", "workflow");
140:
141: $tpl2 = new cTemplate();
142: $tpl2->set('s', 'NAME', 'time' . $listid);
143: $tpl2->set('s', 'CLASS', 'text_small');
144: $tpl2->set('s', 'OPTIONS', 'size=1');
145:
146: foreach ($timeunits as $key => $value) {
147: $tpl2->set('d', 'VALUE', $key);
148: $tpl2->set('d', 'CAPTION', $value);
149:
150: if ($default == $key) {
151: $tpl2->set('d', 'SELECTED', 'SELECTED');
152: } else {
153: $tpl2->set('d', 'SELECTED', '');
154: }
155:
156: $tpl2->next();
157: }
158:
159: return $tpl2->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
160: }
161:
162: 163: 164: 165: 166: 167:
168: function getWorkflowList() {
169: global $idworkflow, $cfg;
170:
171: $backendUrl = cRegistry::getBackendUrl();
172:
173: $ui = new cGuiMenu();
174: $workflowitems = new WorkflowItems();
175:
176: $workflowitems->select("idworkflow = '$idworkflow'", "", "position ASC");
177:
178: while (($workflowitem = $workflowitems->next()) !== false) {
179: $pos = $workflowitem->get("position");
180: $name = preg_replace("/\"/","",($workflowitem->get("name")));
181: $id = $workflowitem->get("idworkflowitem");
182:
183: $edititem = new cHTMLLink();
184: $edititem->setCLink("workflow_steps", 4, "workflow_step_edit");
185: $edititem->setCustom("idworkflowitem", $id);
186: $edititem->setCustom("idworkflow", $idworkflow);
187:
188: $moveup = new cHTMLLink();
189: $moveup->setCLink("workflow_steps", 4, "workflow_step_up");
190: $moveup->setCustom("idworkflowitem", $id);
191: $moveup->setCustom("idworkflow", $idworkflow);
192: $moveup->setCustom("position", $pos);
193: $moveup->setAlt(i18n("Move step up", "workflow"));
194: $moveup->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/no_verschieben.gif" . '">');
195:
196: $movedown = new cHTMLLink();
197: $movedown->setCLink("workflow_steps", 4, "workflow_step_down");
198: $movedown->setCustom("idworkflowitem", $id);
199: $movedown->setCustom("idworkflow", $idworkflow);
200: $movedown->setCustom("position", $pos);
201: $movedown->setAlt(i18n("Move step down", "workflow"));
202: $movedown->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/nu_verschieben.gif" . '">');
203:
204: $deletestep = new cHTMLLink();
205: $deletestep->setCLink("workflow_steps", 4, "workflow_step_delete");
206: $deletestep->setCustom("idworkflowitem", $id);
207: $deletestep->setCustom("idworkflow", $idworkflow);
208: $deletestep->setCustom("position", $pos);
209: $deletestep->setAlt(i18n("Delete step", "workflow"));
210: $deletestep->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_step_delete.gif" . '">');
211:
212: $ui->setTitle($id, "$pos. $name");
213: $ui->setLink($id, $edititem);
214:
215: if ($pos > 1) {
216: $ui->setActions($id, "moveup", $moveup->render());
217: } else {
218: $ui->setActions($id, "moveup", '<img src="images/spacer.gif" width="15" height="1">');
219: }
220:
221: if ($pos < $workflowitems->count()) {
222: $ui->setActions($id, "movedown", $movedown->render());
223: } else {
224: $ui->setActions($id, "movedown", '<img src="images/spacer.gif" width="15" height="1">');
225: }
226:
227: $ui->setActions($id, "delete", $deletestep->render());
228:
229: if ($_GET['idworkflowitem'] == $id) {
230: $ui->setMarked($id);
231: }
232: }
233:
234: $content = $ui->render(false);
235:
236: return ($content);
237: }
238:
239: 240: 241: 242:
243: function createNewWorkflow() {
244: global $idworkflow, $cfg;
245:
246: $backendUrl = cRegistry::getBackendUrl();
247:
248: $content = "";
249: $ui = new cGuiMenu();
250: $rowmark = false;
251:
252: $createstep = new cHTMLLink();
253: $createstep->setCLink("workflow_steps", 4, "workflow_create_step");
254: $createstep->setCustom("idworkflow", $idworkflow);
255:
256:
257: $ui->setTitle("create", i18n("Create new step", "workflow"));
258: $ui->setImage("create", $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_step_new.gif");
259: $ui->setLink("create", $createstep);
260: $ui->setRowmark($rowmark);
261:
262: $content = $ui->render(false);
263: return $content;
264: }
265:
266: 267: 268: 269: 270: 271: 272: 273:
274: function editWorkflowStep($idworkflowitem) {
275: global $area, $idworkflow, $idworkflowitem, $frame, $availableWorkflowActions;
276: global $notification;
277:
278: $workflowitem = new WorkflowItem();
279:
280: if ($workflowitem->loadByPrimaryKey($idworkflowitem) == false) {
281: return " ";
282: }
283:
284: $workflowactions = new WorkflowActions();
285:
286: $stepname = str_replace('\\','',conHtmlSpecialChars($workflowitem->get("name")));
287: $stepdescription = str_replace('\\','',conHtmlSpecialChars($workflowitem->get("description")));
288: $id = $workflowitem->get("idworkflowitem");
289: $task = $workflowitem->get("idtask");
290:
291: $form = new cGuiTableForm("workflow_edit");
292:
293: $form->setVar("area", $area);
294: $form->setVar("action", "workflow_save_step");
295: $form->setVar("idworkflow", $idworkflow);
296: $form->setVar("idworkflowitem", $idworkflowitem);
297: $form->setVar("frame", $frame);
298:
299: $form->addHeader(i18n("Edit workflow step", "workflow"));
300: $oTxtStep = new cHTMLTextbox("wfstepname", $stepname, 40, 255);
301: $form->add(i18n("Step name", "workflow"), $oTxtStep->render());
302: $oTxtStepDesc = new cHTMLTextarea("wfstepdescription", $stepdescription, 60, 10);
303: $form->add(i18n("Step description", "workflow"), $oTxtStepDesc->render());
304:
305: $actions = '';
306:
307: foreach ($availableWorkflowActions as $key => $value) {
308: $oCheckbox = new cHTMLCheckbox("wfactions[" . $key . "]", "1", "wfactions[" . $key . "]1", $workflowactions->get($id, $key));
309: $oCheckbox->setLabelText($value);
310: $actions .= $oCheckbox->toHtml();
311: }
312:
313: $form->add(i18n("Actions", "workflow"), $actions);
314: $form->add(i18n("Assigned users", "workflow"), getWorkflowUsers($idworkflowitem));
315:
316: return $form->render(true);
317: }
318:
319: 320: 321: 322: 323: 324: 325: 326:
327: function getWorkflowUsers($idworkflowitem) {
328: global $idworkflow, $cfg;
329:
330: $backendUrl = cRegistry::getBackendUrl();
331:
332: $ui = new cGuiMenu();
333: $workflowusers = new WorkflowUserSequences();
334:
335: $workflowusers->select("idworkflowitem = '$idworkflowitem'", "", "position ASC");
336:
337: while (($workflowitem = $workflowusers->next()) !== false) {
338: $pos = $workflowitem->get("position");
339: $iduser = $workflowitem->get("iduser");
340: $timelimit = $workflowitem->get("timelimit");
341: $timeunit = $workflowitem->get("timeunit");
342: $email = $workflowitem->get("emailnoti");
343: $escalation = $workflowitem->get("escalationnoti");
344: $timeunit = $workflowitem->get("timeunit");
345: $id = $workflowitem->get("idusersequence");
346:
347: $moveup = new cHTMLLink();
348: $moveup->setCLink("workflow_steps", 4, "workflow_user_up");
349: $moveup->setCustom("idworkflowitem", $idworkflowitem);
350: $moveup->setCustom("idworkflow", $idworkflow);
351: $moveup->setCustom("position", $pos);
352: $moveup->setAlt(i18n("Move user up", "workflow"));
353: $moveup->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/no_verschieben.gif" . '">');
354:
355: $movedown = new cHTMLLink();
356: $movedown->setCLink("workflow_steps", 4, "workflow_user_down");
357: $movedown->setCustom("idworkflowitem", $idworkflowitem);
358: $movedown->setCustom("idworkflow", $idworkflow);
359: $movedown->setCustom("position", $pos);
360: $movedown->setAlt(i18n("Move user down", "workflow"));
361: $movedown->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/nu_verschieben.gif" . '">');
362:
363: $deletestep = new cHTMLLink();
364: $deletestep->setCLink("workflow_steps", 4, "workflow_user_delete");
365: $deletestep->setCustom("idworkflowitem", $idworkflowitem);
366: $deletestep->setCustom("idworkflow", $idworkflow);
367: $deletestep->setCustom("position", $pos);
368: $deletestep->setCustom("idusersequence", $id);
369: $deletestep->setAlt(i18n("Delete user", "workflow"));
370: $deletestep->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_step_delete.gif" . '">');
371:
372: $title = "$pos. " . getUsers($id, $iduser);
373:
374: $oTxtTime = new cHTMLTextbox("wftimelimit" . $id, $timelimit, 3, 6);
375: $title .= $oTxtTime->render();
376: $title .= getTimeUnitSelector($id, $timeunit);
377: $altmail = i18n("Notify this user via E-Mail", "workflow");
378: $altnoti = i18n("Escalate to this user via E-Mail", "workflow");
379:
380: $oCheckbox = new cHTMLCheckbox("wfemailnoti[" . $id . "]", "1", "wfemailnoti[" . $id . "]1", $email);
381: $title .= $oCheckbox->toHtml(false) . '<label for="wfemailnoti[' . $id . ']1"><img alt="' . $altmail . '" title="' . $altmail . '" border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . 'workflow/images/workflow_email_noti.gif"></label>';
382:
383: $oCheckbox = new cHTMLCheckbox("wfescalnoti[" . $id . "]", "1", "wfescalnoti[" . $id . "]1", $escalation);
384: $title .= $oCheckbox->toHtml(false) . '<label for="wfescalnoti[' . $id . ']1"><img alt="' . $altnoti . '" title="' . $altnoti . '" border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . 'workflow/images/workflow_escal_noti.gif"></label>';
385:
386: $ui->setTitle($id, $title);
387: $ui->setLink($id, NULL);
388:
389: if ($pos > 1) {
390: $ui->setActions($id, "moveup", $moveup->render());
391: } else {
392: $ui->setActions($id, "moveup", '<img src="images/spacer.gif" width="15" height="1">');
393: }
394:
395: if ($pos < $workflowusers->count()) {
396: $ui->setActions($id, "movedown", $movedown->render());
397: } else {
398: $ui->setActions($id, "movedown", '<img src="images/spacer.gif" width="15" height="1">');
399: }
400:
401: $ui->setActions($id, "delete", $deletestep->render());
402:
403: $ui->setImage($id, $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_user.gif");
404: }
405:
406: $createstep = new cHTMLLink();
407: $createstep->setCLink("workflow_steps", 4, "workflow_create_user");
408: $createstep->setCustom("idworkflow", $idworkflow);
409: $createstep->setCustom("idworkflowitem", $idworkflowitem);
410:
411: $ui->setLink("spacer", NULL);
412:
413: $ui->setTitle("create", '<input class="text_medium" type="submit" name="adduser" value="' . i18n("Add User", "workflow") . '">');
414: $ui->setLink("create", NULL);
415: $content = $ui->render(false);
416:
417: return $content;
418: }
419:
420: $page->set('s', 'NEW', createNewWorkflow());
421: $page->set('s', 'STEPS', getWorkflowList());
422: $page->set('s', 'EDITSTEP', editWorkflowStep($idworkflowitem));
423: $page->set('s', 'WARNING', i18n('Warning: Changes will reset active Workflows', 'workflow'));
424:
425: $page->render();
426:
427: ?>