ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
24  {
25  $this->parent_gui = $parent_gui;
26  }
27 
35  public function handle($command)
36  {
37  switch(strtolower($command))
38  {
39  case 'uploadform':
40  return $this->showUploadForm();
41  break;
42 
43  case 'upload':
44  return $this->handleUploadSubmit();
45  break;
46 
47  case 'applyfilter':
48  return $this->applyFilter();
49  break;
50 
51  case 'resetfilter':
52  return $this->resetFilter();
53  break;
54 
55  case 'start':
56  return $this->startProcess();
57  break;
58 
59  case 'delete':
60  return $this->deleteDefinition();
61  break;
62 
63  case 'startlistening':
64  return $this->startListening();
65  break;
66 
67  case'stoplistening':
68  return $this->stopListening();
69  break;
70 
71  case 'view':
72  default:
73  return $this->showDefinitionsTable();
74  }
75  }
76 
80  public function showDefinitionsTable()
81  {
82  $this->initToolbar();
83  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowEngineDefinitionsTableGUI.php';
84  $table_gui = new ilWorkflowEngineDefinitionsTableGUI($this->parent_gui, 'definitions.view');
85  $table_gui->setFilterCommand("definitions.applyfilter");
86  $table_gui->setResetCommand("definitions.resetFilter");
87  $table_gui->setDisableFilterHiding(false);
88 
89  return $table_gui->getHTML();
90  }
91 
95  public function applyFilter()
96  {
97  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowEngineDefinitionsTableGUI.php';
98  $table_gui = new ilWorkflowEngineDefinitionsTableGUI($this->parent_gui, 'definitions.view');
99  $table_gui->writeFilterToSession();
100  $table_gui->resetOffset();
101 
102  return $this->showDefinitionsTable();
103  }
104 
108  public function resetFilter()
109  {
110  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowEngineDefinitionsTableGUI.php';
111  $table_gui = new ilWorkflowEngineDefinitionsTableGUI($this->parent_gui, 'definitions.view');
112  $table_gui->resetOffset();
113  $table_gui->resetFilter();
114 
115  return $this->showDefinitionsTable();
116  }
117 
121  public function showUploadForm()
122  {
123  require_once './Services/WorkflowEngine/classes/administration/class.ilUploadDefinitionForm.php';
124  $form_definition = new ilUploadDefinitionForm();
125  $form = $form_definition->getForm(
126  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui,'definitions.upload')
127  );
128 
129  return $form->getHTML();
130  }
131 
135  public function handleUploadSubmit()
136  {
137 
139 
140  require_once './Services/WorkflowEngine/classes/administration/class.ilUploadDefinitionForm.php';
141  $form_definition = new ilUploadDefinitionForm();
142  $form = $form_definition->getForm(
143  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui,'definitions.upload')
144  );
145 
146  if(!$form->checkInput())
147  {
148  $form->setValuesByPost();
149  return $form->getHTML();
150  }
151 
152  $repo_dir_name = ilObjWorkflowEngine::getRepositoryDir() . '/';
153  if(!is_dir($repo_dir_name))
154  {
155  \ilUtil::makeDirParents($repo_dir_name);
156  }
157 
158  $temp_dir_name = ilObjWorkflowEngine::getTempDir();
159  if(!is_dir($temp_dir_name))
160  {
161  \ilUtil::makeDirParents($temp_dir_name);
162  }
163 
164  $file_name = $_FILES['process_file']['name'];
165  $temp_name = $_FILES['process_file']['tmp_name'];
167  $temp_name,
168  $file_name,
169  $temp_dir_name . $file_name
170  );
171 
172  $repo_base_name = 'il'.substr($file_name,0,strpos($file_name,'.'));
173  $wf_base_name = 'wfd.'.$repo_base_name.'_v';
174  $version = 0;
175  if ($handle = opendir($repo_dir_name))
176  {
177  while (false !== ($file = readdir($handle)))
178  {
179  if(substr(strtolower($file), 0, strlen($wf_base_name)) == strtolower($wf_base_name)
180  && substr($file, -4) == '.php')
181  {
182  $number = substr($file, strlen($wf_base_name), -4);
183  if($number > $version)
184  {
185  $version = $number;
186  }
187  }
188  }
189  closedir($handle);
190  }
191  $version++;
192 
193  $repo_name = $repo_base_name.'_v'.$version.'.php';
194 
195  // Parse
196  require_once './Services/WorkflowEngine/classes/parser/class.ilBPMN2Parser.php';
197  $parser = new ilBPMN2Parser();
198  $bpmn = file_get_contents($temp_dir_name.$file_name);
199  $code = $parser->parseBPMN2XML($bpmn,$repo_name);
200 
201  file_put_contents($repo_dir_name.'wfd.'.$repo_name,$code);
202  file_put_contents($repo_dir_name.'wfd.'.$repo_base_name.'_v'.$version.'.bpmn2', $bpmn);
203  unlink($temp_dir_name.$file_name);
204 
205  ilUtil::sendSuccess($this->parent_gui->lng->txt('upload_parse_success'), true);
207  html_entity_decode($this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view'))
208  );
209  }
210 
214  public function initToolbar()
215  {
216  require_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
217  $upload_wizard_button = ilLinkButton::getInstance();
218  $upload_wizard_button->setCaption($this->parent_gui->lng->txt('upload_process'), false);
219  $upload_wizard_button->setUrl(
220  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.uploadform')
221  );
222  $this->parent_gui->ilToolbar->addButtonInstance($upload_wizard_button);
223  }
224 
228  protected function processUploadFormCancellation()
229  {
230  if (isset($_POST['cmd']['cancel'])) {
231  ilUtil::sendInfo($this->parent_gui->lng->txt('action_aborted'), true);
233  html_entity_decode(
234  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
235  )
236  );
237  }
238  }
239 
243  public function startListening()
244  {
245  $identifier = basename($_GET['process_id']);
246 
247  require_once ilObjWorkflowEngine::getRepositoryDir() . $identifier . '.php';
248  $class = substr($identifier,4);
250  $workflow_instance = new $class;
251 
252  $workflow_instance->setWorkflowClass('wfd.'.$class.'.php');
253  $workflow_instance->setWorkflowLocation(ilObjWorkflowEngine::getRepositoryDir());
254 
255  $show_armer_form = true;
256  switch(true)
257  {
258  case isset($_POST['process_id']):
259  case isset($_POST['se_type']):
260  case isset($_POST['se_content']):
261  case isset($_POST['se_subject_type']):
262  case isset($_POST['se_context_type']):
263  $show_armer_form = false;
264  break;
265  default:
266  $show_armer_form = true;
267  }
268 
269  // Check for Event definitions
270  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowArmerGUI.php';
271  $this->parent_gui->ilCtrl->saveParameter($this->parent_gui, 'process_id', $identifier);
272  $action = $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.start');
273  $armer = new ilWorkflowArmerGUI($action, $identifier);
274 
275  $form = $armer->getForm($workflow_instance->getInputVars(), $workflow_instance->getStartEventInfo());
276 
277  if($show_armer_form)
278  {
279  return $form->getHTML();
280  }
281 
282  $event_data = array(
283  'type' => stripslashes($_POST['se_type']),
284  'content' => stripslashes($_POST['se_content']),
285  'subject_type' => stripslashes($_POST['se_subject_type']),
286  'subject_id' => (int)$_POST['se_subject_id'],
287  'context_type' => stripslashes($_POST['se_context_type']),
288  'context_id' => (int)$_POST['se_context_id']
289  );
290  $process_id = stripslashes($_POST['process_id']);
291 
292  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
293  $event_id = ilWorkflowDbHelper::writeStartEventData($event_data, $process_id);
294 
295  foreach($workflow_instance->getInputVars() as $input_var)
296  {
297  ilWorkflowDbHelper::writeStaticInput($input_var['name'], stripslashes($_POST[$input_var['name']]), $event_id);
298  }
299 
300  ilUtil::sendSuccess($this->parent_gui->lng->txt('started_listening'), true);
302  html_entity_decode(
303  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
304  )
305  );
306  }
307 
308  public function stopListening()
309  {
310  $process_id = ilUtil::stripSlashes($_GET['process_id']);
311 
312  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
313  ilWorkflowDbHelper::deleteStartEventData($process_id);
314 
315  ilUtil::sendSuccess($this->parent_gui->lng->txt('wfe_stopped_listening'), true);
317  html_entity_decode(
318  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
319  )
320  );
321  }
322 
328  public function startProcess()
329  {
330  if(isset($_POST['cmd']['cancel']))
331  {
332  ilUtil::sendInfo($this->parent_gui->lng->txt('action_aborted'), true);
334  html_entity_decode(
335  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
336  )
337  );
338  }
339 
340  $identifier = basename($_GET['process_id']);
341 
342  require_once ilObjWorkflowEngine::getRepositoryDir() . $identifier . '.php';
343  $class = substr($identifier,4);
345  $workflow_instance = new $class;
346 
347  $workflow_instance->setWorkflowClass('wfd.'.$class.'.php');
348  $workflow_instance->setWorkflowLocation(ilObjWorkflowEngine::getRepositoryDir());
349 
350  if(count($workflow_instance->getInputVars()))
351  {
352  $show_launcher_form = false;
353  foreach($workflow_instance->getInputVars() as $input_var)
354  {
355  if(!isset($_POST[$input_var['name']]))
356  {
357  $show_launcher_form = true;
358  } else {
359  $workflow_instance->setInstanceVarById($input_var['name'], $_POST[$input_var['name']]);
360  }
361  }
362 
363  require_once './Services/WorkflowEngine/classes/administration/class.ilWorkflowLauncherGUI.php';
364  $this->parent_gui->ilCtrl->saveParameter($this->parent_gui, 'process_id', $identifier);
365  $action = $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.start');
366  $launcher = new ilWorkflowLauncherGUI($action, $identifier);
367  $form = $launcher->getForm($workflow_instance->getInputVars());
368 
369  if($show_launcher_form || $form->checkInput() == false)
370  {
371  $form->setValuesByPost();
372  return $form->getHTML();
373  }
374  }
375 
376  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
377  ilWorkflowDbHelper::writeWorkflow( $workflow_instance );
378 
379  $workflow_instance->startWorkflow();
380  $workflow_instance->handleEvent(
381  array(
382  'time_passed',
383  'time_passed',
384  'none',
385  0,
386  'none',
387  0
388  )
389  );
390 
391  ilWorkflowDbHelper::writeWorkflow( $workflow_instance );
392 
393  ilUtil::sendSuccess($this->parent_gui->lng->txt('process_started'), true);
395  html_entity_decode(
396  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
397  )
398  );
399  }
400 
404  public function deleteDefinition()
405  {
406  unlink(ilObjWorkflowEngine::getRepositoryDir() . '/' . stripslashes($_GET['process_id']).'.php');
407  unlink(ilObjWorkflowEngine::getRepositoryDir() . '/' . stripslashes($_GET['process_id']).'.bpmn2');
408 
409  ilUtil::sendSuccess($this->parent_gui->lng->txt('definition_deleted'), true);
411  html_entity_decode(
412  $this->parent_gui->ilCtrl->getLinkTarget($this->parent_gui, 'definitions.view')
413  )
414  );
415  }
416 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
Class ilWorkflowEngineDefinitionsGUI.
$_GET["client_id"]
$code
Definition: example_050.php:99
__construct(ilObjWorkflowEngineGUI $parent_gui)
ilWorkflowEngineDefinitionsGUI constructor.
PhpIncludeInspection
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
$parser
Definition: BPMN2Parser.php:24
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
handle($command)
Handle the command given.
static redirect($a_script)
http redirect to other script
$_POST["username"]
Class ilBPMN2Parser.