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