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: function getTimeUnitSelector($listid, $default) {
123: global $idclient, $cfg, $auth;
124:
125: $timeunits = array();
126: $timeunits['Seconds'] = i18n("Seconds", "workflow");
127: $timeunits['Minutes'] = i18n("Minutes", "workflow");
128: $timeunits['Hours'] = i18n("Hours", "workflow");
129: $timeunits['Days'] = i18n("Days", "workflow");
130: $timeunits['Weeks'] = i18n("Weeks", "workflow");
131: $timeunits['Months'] = i18n("Months", "workflow");
132: $timeunits['Years'] = i18n("Years", "workflow");
133:
134: $tpl2 = new cTemplate();
135: $tpl2->set('s', 'NAME', 'time' . $listid);
136: $tpl2->set('s', 'CLASS', 'text_small');
137: $tpl2->set('s', 'OPTIONS', 'size=1');
138:
139: foreach ($timeunits as $key => $value) {
140: $tpl2->set('d', 'VALUE', $key);
141: $tpl2->set('d', 'CAPTION', $value);
142:
143: if ($default == $key) {
144: $tpl2->set('d', 'SELECTED', 'SELECTED');
145: } else {
146: $tpl2->set('d', 'SELECTED', '');
147: }
148:
149: $tpl2->next();
150: }
151:
152: return $tpl2->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
153: }
154:
155: function getWorkflowList() {
156: global $idworkflow, $cfg;
157:
158: $backendUrl = cRegistry::getBackendUrl();
159:
160: $ui = new cGuiMenu();
161: $workflowitems = new WorkflowItems();
162:
163: $workflowitems->select("idworkflow = '$idworkflow'", "", "position ASC");
164:
165: while (($workflowitem = $workflowitems->next()) !== false) {
166: $pos = $workflowitem->get("position");
167: $name = preg_replace("/\"/","",($workflowitem->get("name")));
168: $id = $workflowitem->get("idworkflowitem");
169:
170: $edititem = new cHTMLLink();
171: $edititem->setCLink("workflow_steps", 4, "workflow_step_edit");
172: $edititem->setCustom("idworkflowitem", $id);
173: $edititem->setCustom("idworkflow", $idworkflow);
174:
175: $moveup = new cHTMLLink();
176: $moveup->setCLink("workflow_steps", 4, "workflow_step_up");
177: $moveup->setCustom("idworkflowitem", $id);
178: $moveup->setCustom("idworkflow", $idworkflow);
179: $moveup->setCustom("position", $pos);
180: $moveup->setAlt(i18n("Move step up", "workflow"));
181: $moveup->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/no_verschieben.gif" . '">');
182:
183: $movedown = new cHTMLLink();
184: $movedown->setCLink("workflow_steps", 4, "workflow_step_down");
185: $movedown->setCustom("idworkflowitem", $id);
186: $movedown->setCustom("idworkflow", $idworkflow);
187: $movedown->setCustom("position", $pos);
188: $movedown->setAlt(i18n("Move step down", "workflow"));
189: $movedown->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/nu_verschieben.gif" . '">');
190:
191: $deletestep = new cHTMLLink();
192: $deletestep->setCLink("workflow_steps", 4, "workflow_step_delete");
193: $deletestep->setCustom("idworkflowitem", $id);
194: $deletestep->setCustom("idworkflow", $idworkflow);
195: $deletestep->setCustom("position", $pos);
196: $deletestep->setAlt(i18n("Delete step", "workflow"));
197: $deletestep->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_step_delete.gif" . '">');
198:
199: $ui->setTitle($id, "$pos. $name");
200: $ui->setLink($id, $edititem);
201:
202: if ($pos > 1) {
203: $ui->setActions($id, "moveup", $moveup->render());
204: } else {
205: $ui->setActions($id, "moveup", '<img src="images/spacer.gif" width="15" height="1">');
206: }
207:
208: if ($pos < $workflowitems->count()) {
209: $ui->setActions($id, "movedown", $movedown->render());
210: } else {
211: $ui->setActions($id, "movedown", '<img src="images/spacer.gif" width="15" height="1">');
212: }
213:
214: $ui->setActions($id, "delete", $deletestep->render());
215:
216: if ($_GET['idworkflowitem'] == $id) {
217: $ui->setMarked($id);
218: }
219: }
220:
221: $content = $ui->render(false);
222:
223: return ($content);
224: }
225:
226: function createNewWorkflow() {
227: global $idworkflow, $cfg;
228:
229: $backendUrl = cRegistry::getBackendUrl();
230:
231: $content = "";
232: $ui = new cGuiMenu();
233: $rowmark = false;
234:
235: $createstep = new cHTMLLink();
236: $createstep->setCLink("workflow_steps", 4, "workflow_create_step");
237: $createstep->setCustom("idworkflow", $idworkflow);
238:
239:
240: $ui->setTitle("create", i18n("Create new step", "workflow"));
241: $ui->setImage("create", $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_step_new.gif");
242: $ui->setLink("create", $createstep);
243: $ui->setRowmark($rowmark);
244:
245: $content = $ui->render(false);
246: return $content;
247: }
248:
249: function editWorkflowStep($idworkflowitem) {
250: global $area, $idworkflow, $idworkflowitem, $frame, $availableWorkflowActions;
251: global $notification;
252:
253: $workflowitem = new WorkflowItem();
254:
255: if ($workflowitem->loadByPrimaryKey($idworkflowitem) == false) {
256: return " ";
257: }
258:
259: $workflowactions = new WorkflowActions();
260:
261: $stepname = str_replace('\\','',conHtmlSpecialChars($workflowitem->get("name")));
262: $stepdescription = str_replace('\\','',conHtmlSpecialChars($workflowitem->get("description")));
263: $id = $workflowitem->get("idworkflowitem");
264: $task = $workflowitem->get("idtask");
265:
266: $form = new cGuiTableForm("workflow_edit");
267:
268: $form->setVar("area", $area);
269: $form->setVar("action", "workflow_save_step");
270: $form->setVar("idworkflow", $idworkflow);
271: $form->setVar("idworkflowitem", $idworkflowitem);
272: $form->setVar("frame", $frame);
273:
274: $form->addHeader(i18n("Edit workflow step", "workflow"));
275: $oTxtStep = new cHTMLTextbox("wfstepname", $stepname, 40, 255);
276: $form->add(i18n("Step name", "workflow"), $oTxtStep->render());
277: $oTxtStepDesc = new cHTMLTextarea("wfstepdescription", $stepdescription, 60, 10);
278: $form->add(i18n("Step description", "workflow"), $oTxtStepDesc->render());
279:
280: $actions = '';
281:
282: foreach ($availableWorkflowActions as $key => $value) {
283: $oCheckbox = new cHTMLCheckbox("wfactions[" . $key . "]", "1", "wfactions[" . $key . "]1", $workflowactions->get($id, $key));
284: $oCheckbox->setLabelText($value);
285: $actions .= $oCheckbox->toHtml();
286: }
287:
288: $form->add(i18n("Actions", "workflow"), $actions);
289: $form->add(i18n("Assigned users", "workflow"), getWorkflowUsers($idworkflowitem));
290:
291: return $form->render(true);
292: }
293:
294: function getWorkflowUsers($idworkflowitem) {
295: global $idworkflow, $cfg;
296:
297: $backendUrl = cRegistry::getBackendUrl();
298:
299: $ui = new cGuiMenu();
300: $workflowusers = new WorkflowUserSequences();
301:
302: $workflowusers->select("idworkflowitem = '$idworkflowitem'", "", "position ASC");
303:
304: while (($workflowitem = $workflowusers->next()) !== false) {
305: $pos = $workflowitem->get("position");
306: $iduser = $workflowitem->get("iduser");
307: $timelimit = $workflowitem->get("timelimit");
308: $timeunit = $workflowitem->get("timeunit");
309: $email = $workflowitem->get("emailnoti");
310: $escalation = $workflowitem->get("escalationnoti");
311: $timeunit = $workflowitem->get("timeunit");
312: $id = $workflowitem->get("idusersequence");
313:
314: $moveup = new cHTMLLink();
315: $moveup->setCLink("workflow_steps", 4, "workflow_user_up");
316: $moveup->setCustom("idworkflowitem", $idworkflowitem);
317: $moveup->setCustom("idworkflow", $idworkflow);
318: $moveup->setCustom("position", $pos);
319: $moveup->setAlt(i18n("Move user up", "workflow"));
320: $moveup->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/no_verschieben.gif" . '">');
321:
322: $movedown = new cHTMLLink();
323: $movedown->setCLink("workflow_steps", 4, "workflow_user_down");
324: $movedown->setCustom("idworkflowitem", $idworkflowitem);
325: $movedown->setCustom("idworkflow", $idworkflow);
326: $movedown->setCustom("position", $pos);
327: $movedown->setAlt(i18n("Move user down", "workflow"));
328: $movedown->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/nu_verschieben.gif" . '">');
329:
330: $deletestep = new cHTMLLink();
331: $deletestep->setCLink("workflow_steps", 4, "workflow_user_delete");
332: $deletestep->setCustom("idworkflowitem", $idworkflowitem);
333: $deletestep->setCustom("idworkflow", $idworkflow);
334: $deletestep->setCustom("position", $pos);
335: $deletestep->setCustom("idusersequence", $id);
336: $deletestep->setAlt(i18n("Delete user", "workflow"));
337: $deletestep->setContent('<img border="0" src="' . $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_step_delete.gif" . '">');
338:
339: $title = "$pos. " . getUsers($id, $iduser);
340:
341: $oTxtTime = new cHTMLTextbox("wftimelimit" . $id, $timelimit, 3, 6);
342: $title .= $oTxtTime->render();
343: $title .= getTimeUnitSelector($id, $timeunit);
344: $altmail = i18n("Notify this user via E-Mail", "workflow");
345: $altnoti = i18n("Escalate to this user via E-Mail", "workflow");
346:
347: $oCheckbox = new cHTMLCheckbox("wfemailnoti[" . $id . "]", "1", "wfemailnoti[" . $id . "]1", $email);
348: $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>';
349:
350: $oCheckbox = new cHTMLCheckbox("wfescalnoti[" . $id . "]", "1", "wfescalnoti[" . $id . "]1", $escalation);
351: $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>';
352:
353: $ui->setTitle($id, $title);
354: $ui->setLink($id, NULL);
355:
356: if ($pos > 1) {
357: $ui->setActions($id, "moveup", $moveup->render());
358: } else {
359: $ui->setActions($id, "moveup", '<img src="images/spacer.gif" width="15" height="1">');
360: }
361:
362: if ($pos < $workflowusers->count()) {
363: $ui->setActions($id, "movedown", $movedown->render());
364: } else {
365: $ui->setActions($id, "movedown", '<img src="images/spacer.gif" width="15" height="1">');
366: }
367:
368: $ui->setActions($id, "delete", $deletestep->render());
369:
370: $ui->setImage($id, $backendUrl . $cfg["path"]["plugins"] . "workflow/images/workflow_user.gif");
371: }
372:
373: $createstep = new cHTMLLink();
374: $createstep->setCLink("workflow_steps", 4, "workflow_create_user");
375: $createstep->setCustom("idworkflow", $idworkflow);
376: $createstep->setCustom("idworkflowitem", $idworkflowitem);
377:
378: $ui->setLink("spacer", NULL);
379:
380: $ui->setTitle("create", '<input class="text_medium" type="submit" name="adduser" value="' . i18n("Add User", "workflow") . '">');
381: $ui->setLink("create", NULL);
382: $content = $ui->render(false);
383:
384: return $content;
385: }
386:
387: $page->set('s', 'NEW', createNewWorkflow());
388: $page->set('s', 'STEPS', getWorkflowList());
389: $page->set('s', 'EDITSTEP', editWorkflowStep($idworkflowitem));
390: $page->set('s', 'WARNING', i18n('Warning: Changes will reset active Workflows', 'workflow'));
391:
392: $page->render();
393:
394: ?>