ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWorkflowEngineDefinitionsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
16  protected $parent_gui;
17 
21  protected $dic;
22 
29  public function __construct(ilObjWorkflowEngineGUI $parent_gui, \ILIAS\DI\Container $dic = null)
30  {
31  $this->parent_gui = $parent_gui;
32 
33  if ($dic === null) {
34  $dic = $GLOBALS['DIC'];
35  }
36  $this->dic = $dic;
37  }
38 
46  public function handle($command)
47  {
48  switch (strtolower($command)) {
49  case 'uploadform':
50  return $this->showUploadForm();
51  break;
52 
53  case 'upload':
54  return $this->handleUploadSubmit();
55  break;
56 
57  case 'applyfilter':
58  return $this->applyFilter();
59  break;
60 
61  case 'resetfilter':
62  return $this->resetFilter();
63  break;
64 
65  case 'start':
66  return $this->startProcess();
67  break;
68 
69  case 'delete':
70  return $this->deleteDefinition();
71  break;
72 
73  case 'confirmdelete':
74  return $this->confirmDeleteDefinition();
75  break;
76 
77  case 'startlistening':
78  return $this->startListening();
79  break;
80 
81  case'stoplistening':
82  return $this->stopListening();
83  break;
84 
85  case 'view':
86  default:
87  return $this->showDefinitionsTable();
88  }
89  }
90 
94  public function showDefinitionsTable()
95  {
96  if ($this->dic->rbac()->system()->checkAccess('write', $_GET['ref_id'])) {
97  $this->initToolbar();
98  }
99  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowEngineDefinitionsTableGUI.php';
100  $table_gui = new ilWorkflowEngineDefinitionsTableGUI($this->parent_gui, 'definitions.view');
101  $table_gui->setFilterCommand("definitions.applyfilter");
102  $table_gui->setResetCommand("definitions.resetFilter");
103  $table_gui->setDisableFilterHiding(false);
104 
105  return $table_gui->getHTML();
106  }
107 
111  public function applyFilter()
112  {
113  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowEngineDefinitionsTableGUI.php';
114  $table_gui = new ilWorkflowEngineDefinitionsTableGUI($this->parent_gui, 'definitions.view');
115  $table_gui->writeFilterToSession();
116  $table_gui->resetOffset();
117 
118  return $this->showDefinitionsTable();
119  }
120 
124  public function resetFilter()
125  {
126  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowEngineDefinitionsTableGUI.php';
127  $table_gui = new ilWorkflowEngineDefinitionsTableGUI($this->parent_gui, 'definitions.view');
128  $table_gui->resetOffset();
129  $table_gui->resetFilter();
130 
131  return $this->showDefinitionsTable();
132  }
133 
137  public function showUploadForm()
138  {
139  require_once './Services/WorkflowEngine/classes/administration/class.ilUploadDefinitionForm.php';
140  $form_definition = new ilUploadDefinitionForm();
141  $form = $form_definition->getForm(
142  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.upload')
143  );
144 
145  return $form->getHTML();
146  }
147 
154  public function handleUploadSubmit()
155  {
157 
158  require_once './Services/WorkflowEngine/classes/administration/class.ilUploadDefinitionForm.php';
159  $form_definition = new ilUploadDefinitionForm();
160  $form = $form_definition->getForm(
161  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.upload')
162  );
163 
164  if (!$form->checkInput()) {
165  $form->setValuesByPost();
166  return $form->getHTML();
167  }
168 
169  $fs = $this->dic->filesystem()->storage();
170  $upload = $this->dic->upload();
171 
172  $repositoryDirectory = ilObjWorkflowEngine::getRepositoryDir(true);
173  if (!$fs->hasDir($repositoryDirectory)) {
174  $fs->createDir($repositoryDirectory);
175  }
176 
177  $tmpDirectory = ilObjWorkflowEngine::getTempDir(true);
178  if (!$fs->hasDir($tmpDirectory)) {
179  $fs->createDir($tmpDirectory);
180  }
181 
182  if (!$upload->hasUploads() || $upload->hasBeenProcessed()) {
183  $form->setValuesByPost();
184  return $form->getHTML();
185  }
186 
187  $upload->process();
188 
190  $uploadResult = array_values($upload->getResults())[0];
191  if (!$uploadResult || $uploadResult->getStatus() != \ILIAS\FileUpload\DTO\ProcessingStatus::OK) {
192  $form->setValuesByPost();
193  return $form->getHTML();
194  }
195 
196  $upload->moveOneFileTo(
197  $uploadResult,
198  $tmpDirectory,
199  \ILIAS\FileUpload\Location::STORAGE,
200  $uploadResult->getName(),
201  true
202  );
203 
204  $repo_base_name = 'il' . substr($uploadResult->getName(), 0, strpos($uploadResult->getName(), '.'));
205  $wf_base_name = 'wfd.' . $repo_base_name . '_v';
206  $version = 0;
207 
208  $fileList = $fs->listContents($repositoryDirectory, true);
209 
210  foreach ($fileList as $file) {
211  if ($file->isDir()) {
212  continue;
213  }
214 
215  $fileBaseName = basename($file->getPath());
216 
217  if (
218  substr(strtolower($fileBaseName), 0, strlen($wf_base_name)) == strtolower($wf_base_name) &&
219  substr($fileBaseName, -4) == '.php'
220  ) {
221  $number = substr($fileBaseName, strlen($wf_base_name), -4);
222  if ($number > $version) {
223  $version = $number;
224  }
225  }
226  }
227  $version++;
228 
229  $repo_name = $repo_base_name . '_v' . $version . '.php';
230 
231  require_once './Services/WorkflowEngine/classes/parser/class.ilBPMN2Parser.php';
232  $parser = new ilBPMN2Parser();
233  $bpmn = $fs->read($tmpDirectory . $uploadResult->getName());
234  $code = $parser->parseBPMN2XML($bpmn, $repo_name);
235 
236  $fs->put($repositoryDirectory . 'wfd.' . $repo_name, $code);
237  $fs->put($repositoryDirectory . 'wfd.' . $repo_base_name . '_v' . $version . '.bpmn2', $bpmn);
238  $fs->delete($tmpDirectory . $uploadResult->getName());
239 
240  // TODO: Workaround because of file extension whitelist. You currently cannot create/put '.php' files
241  $absRepositoryDirectory = ilObjWorkflowEngine::getRepositoryDir();
242  $sourceFile = $absRepositoryDirectory . str_replace('.', '', 'wfd.' . $repo_name) . '.sec';
243  $targetFile = $absRepositoryDirectory . 'wfd.' . $repo_name;
244  if (file_exists($sourceFile)) {
245  rename($sourceFile, $targetFile);
246  }
247 
248  ilUtil::sendSuccess($this->parent_gui->lng->txt('upload_parse_success'), true);
250  html_entity_decode($this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view'))
251  );
252  }
253 
257  public function initToolbar()
258  {
259  require_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
260  $upload_wizard_button = ilLinkButton::getInstance();
261  $upload_wizard_button->setCaption($this->parent_gui->lng->txt('upload_process'), false);
262  $upload_wizard_button->setUrl(
263  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.uploadform')
264  );
265  $this->parent_gui->ilToolbar->addButtonInstance($upload_wizard_button);
266  }
267 
271  protected function processUploadFormCancellation()
272  {
273  if (isset($_POST['cmd']['cancel'])) {
274  ilUtil::sendInfo($this->parent_gui->lng->txt('action_aborted'), true);
276  html_entity_decode(
277  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
278  )
279  );
280  }
281  }
282 
286  public function startListening()
287  {
288  $identifier = basename($_GET['process_id']);
289 
290  require_once ilObjWorkflowEngine::getRepositoryDir() . $identifier . '.php';
291  $class = substr($identifier, 4);
293  $workflow_instance = new $class;
294 
295  $workflow_instance->setWorkflowClass('wfd.' . $class . '.php');
296  $workflow_instance->setWorkflowLocation(ilObjWorkflowEngine::getRepositoryDir());
297 
298  $show_armer_form = true;
299  switch (true) {
300  case isset($_POST['process_id']):
301  case isset($_POST['se_type']):
302  case isset($_POST['se_content']):
303  case isset($_POST['se_subject_type']):
304  case isset($_POST['se_context_type']):
305  $show_armer_form = false;
306  break;
307  default:
308  $show_armer_form = true;
309  }
310 
311  // Check for Event definitions
312  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowArmerGUI.php';
313  $this->parent_gui->ilCtrl->saveParameter($this->parent_gui, 'process_id', $identifier);
314  $action = $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.start');
315  $armer = new ilWorkflowArmerGUI($action, $identifier);
316 
317  $form = $armer->getForm($workflow_instance->getInputVars(), $workflow_instance->getStartEventInfo());
318 
319  if ($show_armer_form) {
320  return $form->getHTML();
321  }
322 
323  $event_data = array(
324  'type' => stripslashes($_POST['se_type']),
325  'content' => stripslashes($_POST['se_content']),
326  'subject_type' => stripslashes($_POST['se_subject_type']),
327  'subject_id' => (int) $_POST['se_subject_id'],
328  'context_type' => stripslashes($_POST['se_context_type']),
329  'context_id' => (int) $_POST['se_context_id']
330  );
331  $process_id = stripslashes($_POST['process_id']);
332 
333  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
334  $event_id = ilWorkflowDbHelper::writeStartEventData($event_data, $process_id);
335 
336  foreach ($workflow_instance->getInputVars() as $input_var) {
337  ilWorkflowDbHelper::writeStaticInput($input_var['name'], stripslashes($_POST[$input_var['name']]), $event_id);
338  }
339 
340  ilUtil::sendSuccess($this->parent_gui->lng->txt('wfe_started_listening'), true);
342  html_entity_decode(
343  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
344  )
345  );
346  }
347 
348  public function stopListening()
349  {
350  $process_id = ilUtil::stripSlashes($_GET['process_id']);
351 
352  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
353  ilWorkflowDbHelper::deleteStartEventData($process_id);
354 
355  ilUtil::sendSuccess($this->parent_gui->lng->txt('wfe_stopped_listening'), true);
357  html_entity_decode(
358  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
359  )
360  );
361  }
362 
368  public function startProcess()
369  {
370  if (isset($_POST['cmd']['cancel'])) {
371  ilUtil::sendInfo($this->parent_gui->lng->txt('action_aborted'), true);
373  html_entity_decode(
374  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
375  )
376  );
377  }
378 
379  $identifier = basename($_GET['process_id']);
380 
381  require_once ilObjWorkflowEngine::getRepositoryDir() . $identifier . '.php';
382  $class = substr($identifier, 4);
384  $workflow_instance = new $class;
385 
386  $workflow_instance->setWorkflowClass('wfd.' . $class . '.php');
387  $workflow_instance->setWorkflowLocation(ilObjWorkflowEngine::getRepositoryDir());
388 
389  if (count($workflow_instance->getInputVars())) {
390  $show_launcher_form = false;
391  foreach ($workflow_instance->getInputVars() as $input_var) {
392  if (!isset($_POST[$input_var['name']])) {
393  $show_launcher_form = true;
394  } else {
395  $workflow_instance->setInstanceVarById($input_var['name'], $_POST[$input_var['name']]);
396  }
397  }
398 
399  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowLauncherGUI.php';
400  $this->parent_gui->ilCtrl->saveParameter($this->parent_gui, 'process_id', $identifier);
401  $action = $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.start');
402  $launcher = new ilWorkflowLauncherGUI($action, $identifier);
403  $form = $launcher->getForm($workflow_instance->getInputVars());
404 
405  if ($show_launcher_form || $form->checkInput() == false) {
406  $form->setValuesByPost();
407  return $form->getHTML();
408  }
409  }
410 
411  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
412  ilWorkflowDbHelper::writeWorkflow($workflow_instance);
413 
414  $workflow_instance->startWorkflow();
415  $workflow_instance->handleEvent(
416  array(
417  'time_passed',
418  'time_passed',
419  'none',
420  0,
421  'none',
422  0
423  )
424  );
425 
426  ilWorkflowDbHelper::writeWorkflow($workflow_instance);
427 
428  ilUtil::sendSuccess($this->parent_gui->lng->txt('process_started'), true);
430  html_entity_decode(
431  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
432  )
433  );
434  }
435 
439  private function ensureProcessIdInRequest()
440  {
441  if (!isset($this->dic->http()->request()->getQueryParams()['process_id'])) {
442  ilUtil::sendInfo($this->parent_gui->lng->txt('wfe_request_missing_process_id'));
443  $this->parent_gui->ilCtrl->redirect($this->parent_gui, 'definitions.view');
444  }
445  }
446 
450  private function getProcessIdFromRequest()
451  {
452  $processId = str_replace(['\\', '/'], '', stripslashes($this->dic->http()->request()->getQueryParams()['process_id']));
453 
454  return basename($processId);
455  }
456 
460  public function deleteDefinition()
461  {
462  $this->ensureProcessIdInRequest();
463 
464  $processId = $this->getProcessIdFromRequest();
465 
466  $pathToProcessPhpFile = ilObjWorkflowEngine::getRepositoryDir() . '/' . $processId . '.php';
467  $pathToProcessBpmn2File = ilObjWorkflowEngine::getRepositoryDir() . '/' . $processId . '.bpmn2';
468 
469  if (file_exists($pathToProcessPhpFile)) {
470  unlink($pathToProcessPhpFile);
471  }
472  if (file_exists($pathToProcessBpmn2File)) {
473  unlink($pathToProcessBpmn2File);
474  }
475 
476  ilUtil::sendSuccess($this->parent_gui->lng->txt('definition_deleted'), true);
478  html_entity_decode(
479  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
480  )
481  );
482  }
483 
487  public function confirmDeleteDefinition()
488  {
489  $this->ensureProcessIdInRequest();
490 
491  $processId = $this->getProcessIdFromRequest();
492 
493  require_once 'Services/WorkflowEngine/classes/administration/class.ilWorkflowDefinitionRepository.php';
494  $repository = new ilWorkflowDefinitionRepository(
495  $this->dic->database(),
496  $this->dic->filesystem(),
498  );
499  $processDefinition = $repository->getById($processId);
500 
501  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
502  $confirmation = new ilConfirmationGUI();
503  $confirmation->addItem('process_id[]', $processDefinition['id'], $processDefinition['title']);
504  $this->parent_gui->ilCtrl->setParameter($this->parent_gui, 'process_id', $processDefinition['id']);
505  $confirmation->setFormAction($this->parent_gui->ilCtrl->getFormAction($this->parent_gui, 'definitions.view'));
506  $confirmation->setHeaderText($this->parent_gui->lng->txt('wfe_sure_to_delete_process_def'));
507  $confirmation->setConfirm($this->parent_gui->lng->txt('confirm'), 'definitions.delete');
508  $confirmation->setCancel($this->parent_gui->lng->txt('cancel'), 'definitions.view');
509 
510  return $confirmation->getHTML();
511  }
512 }
Class ilWorkflowEngineDefinitionsGUI.
$_GET["client_id"]
Class ChatMainBarProvider .
static getRepositoryDir($relative=false)
PhpIncludeInspection
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class HTTPServicesTest.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Class ilWorkflowDefinitionRepository.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct(ilObjWorkflowEngineGUI $parent_gui, \ILIAS\DI\Container $dic=null)
ilWorkflowEngineDefinitionsGUI constructor.
$parser
Definition: BPMN2Parser.php:23
static getTempDir($relative=false)
handle($command)
Handle the command given.
static redirect($a_script)
$_POST["username"]
Class ilBPMN2Parser.
Confirmation screen class.