Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
workflow_step_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/folder/folder_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42  unset($this->static_screens['workflow']);
43  unset($this->static_screens['metadataSchemas']);
44  unset($this->static_screens['metadata']);
45 
46  }//end constructor
47 
48 
59  {
60  $write_access = ($asset->writeAccess('attributes') && $asset->writeAccess('links'));
61  $prefix = $asset->getPrefix();
62  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
63  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
64 
65  $o->openField(translate('step_logic'));
66  $step_logic = $asset->attr('logic');
67  $step_logic_num = $asset->attr('logic_num');
68  if (!$step_logic_num) $step_logic_num = '';
69 
70  if (!$write_access) {
71  echo '<i>'.$wfm->_valid_step_logic[$step_logic];
72  if ($step_logic_num) {
73  echo ' '.$step_logic_num.' condition'.(($step_logic_num > 1) ? 's' : '').' must be met</i>';
74  }
75  } else {
76  combo_box($prefix.'_logic', $wfm->_valid_step_logic, FALSE, $step_logic);
77  echo '&nbsp;';
78  text_box($prefix.'_logic_num', $step_logic_num, 4);
79  echo ' '.translate('conditions_must_be_met_in_this_step');
80  }
81  $o->closeField();
82 
83  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'workflow_step_condition', TRUE, 'major', NULL, TRUE, TRUE);
84  if (!empty($current_links)) {
85  $o->openField('Conditions');
86  ?>
87  <table class="sq-backend-table">
88  <tr>
89  <td class="sq-backend-table-header">&nbsp;</td>
90  <td class="sq-backend-table-header"><?php echo translate('notify_when_live'); ?></td>
91  <td class="sq-backend-table-header"><?php echo translate('require_comment'); ?></td>
92  <td class="sq-backend-table-header" width="270"><?php echo translate('group_logic'); ?></td>
93  <?php
94  if ($write_access) {
95  ?><td align="center" width="70" class="sq-backend-table-header"><b><?php echo translate('delete_question'); ?></b></td><?php
96  }
97  ?>
98  </tr>
99  <?php
100  foreach ($current_links as $link_data) {
101  $condition = $GLOBALS['SQ_SYSTEM']->am->getAsset($link_data['minorid']);
102  if (is_null($condition)) continue;
103  $edit_fns = $condition->getEditFns();
104  echo '<tr>';
105  if (!$edit_fns->paintStepCondition($condition, $o)) {
106  return FALSE;
107  }
108  if ($write_access) {
109  ?><td align="center" class="sq-backend-table-cell"><?php
110  check_box($prefix.'_delete_conditions['.$link_data['linkid'].']')
111  ?></td><?php
112  }
113  echo '</tr>';
114  }
115  ?></table><?php
116  $o->closeField();
117  }//end if
118 
119  $o->openField(translate('require_comment_from_unlisted_users'));
120  $require_comment_attr = $asset->getAttribute('require_comment_from_unlisted_users');
121  $xml = simplexml_load_string('<boolean true_text="yes" false_text="no" />');
122  $require_comment_attr->setEditParams($xml);
123  $require_comment_attr->paint($prefix.'_require_comment_from_unlisted_users', !$write_access);
124  $o->note(translate('require_comment_from_unlisted_users_explanation'));
125  $o->closeField();
126 
127  if ($write_access) {
128  $o->openField(translate('new_condition_question'));
129  asset_finder($prefix.'_new_condition', 0, Array('user' => 'D', 'user_group' => 'D'), 'sq_sidenav', FALSE, 'null', Array('clear'));
130  $o->closeField();
131  }
132  $o->openField(translate('expiry_time'));
133  $comparator_attr = $asset->getAttribute('expiry_time');
134  $comparator_attr->paint($prefix.'_expiry_time', !$write_access);
135  $o->note(translate('step_not_completed_in_time_explanation'));
136  $o->closeField();
137  $o->openField('Escalate?');
138  $comparator_attr = $asset->getAttribute('escalate');
139  $xml = simplexml_load_string('<boolean true_text="yes" false_text="no" />');
140  $comparator_attr->setEditParams($xml);
141  $comparator_attr->paint($prefix.'_escalate', !$write_access);
142  $o->note(translate('escalate_note'));
143  if ($asset->attr('escalate') == TRUE) {
144  $o->openSection('Escalation Steps');
145  // look for all the children of this step and list a bunch of links with delete buttons
146  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'workflow_step', TRUE, 'major', NULL, TRUE, FALSE);
147  if (!empty($current_links)) {
148  $assetids = Array();
149 
150  foreach ($current_links as $link) {
151  $assetids[$link['minorid']] = 'details';
152  }
153  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($assetids));
154  $asset_href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($assetids);
155 
156  $o->openField('Escalation Steps');
157  ?>
158  <table class="sq-backend-table">
159  <tr>
160  <td class="sq-backend-table-header"><b><?php echo translate('step_name'); ?></b></td>
161  <td width="150" class="sq-backend-table-header"><b><?php echo translate('edit_step'); ?></b></td>
162  <?php
163  if ($write_access) {
164  ?><td align="center" width="70" class="sq-backend-table-header"><b><?php echo translate('delete_question'); ?></b></td><?php
165  }
166  ?>
167  </tr>
168  <?php
169  foreach ($current_links as $link_data) {
170  $field = $GLOBALS['SQ_SYSTEM']->am->getAsset($link_data['minorid']);
171  if (is_null($field)) continue;
172  ?>
173  <tr>
174  <td align="left" class="sq-backend-table-cell"><?php echo get_asset_tag_line($field->id);?></td>
175  <td align="left" class="sq-backend-table-cell">[ <a href="<?php echo $asset_href[$field->id];?>"><?php echo translate('edit_step'); ?></a> ]</td>
176  <?php
177  if ($write_access) {
178  ?><td align="center" class="sq-backend-table-cell"><?php
179  check_box($prefix.'_delete_steps['.$link_data['linkid'].']')
180  ?></td><?php
181  }
182  echo '</tr>';
183  }
184  ?></table><?php
185  $o->closeField();
186  }//end if
187 
188  if ($write_access) {
189  $o->openField('Create New Escalation Step');
190  text_box($prefix.'_new_escalation_step', '', 20);
191  $o->closeField();
192  }
193  $o->closeSection();
194  }//end if escalate
195  $o->closeField();
196 
197  return $write_access;
198 
199  }//end paintStep()
200 
201 
212  {
213  // need to have write access to make any changes
214  if (!$asset->writeAccess('attributes') || !$asset->writeAccess('links')) {
215  return FALSE;
216  }
217 
218  $prefix = $asset->getPrefix();
219  $updated = FALSE;
220 
221  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
222  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
223 
224  // set the step logic
225  $step_logic = '';
226  $step_logic_num = 0;
227  if (isset($_POST[$prefix.'_logic'])) {
228  $step_logic = trim($_POST[$prefix.'_logic']);
229  }
230  if (isset($_POST[$prefix.'_logic_num']) && $step_logic != 'all') {
231  // Added condition to ensure a number is entered, and is greater than 0
232  if (is_numeric(trim($_POST[$prefix.'_logic_num']))) {
233  $step_logic_num = (int) trim($_POST[$prefix.'_logic_num']);
234  } else {
235  $step_logic_num = 1;
236  }
237  if ($step_logic_num <= 0) $step_logic_num = 1;
238  }
239  if (!$asset->setAttrValue('logic', $step_logic)) {
240  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
241  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
242  return FALSE;
243  }
244  if (!$asset->setAttrValue('logic_num', $step_logic_num)) {
245  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
246  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
247  return FALSE;
248  }
249 
250  // require comment from unlisted users
251  $require_comment_attr = $asset->getAttribute('require_comment_from_unlisted_users');
252  $require_comment_attr->process($prefix.'_require_comment_from_unlisted_users');
253  if ($require_comment_attr->processed) {
254  $asset->setAttrValue('require_comment_from_unlisted_users', $require_comment_attr->value);
255  $updated = TRUE;
256  }
257 
258  // update expiry date
259  $expiry_time_attr = $asset->getAttribute('expiry_time');
260  $expiry_time_attr->process($prefix.'_expiry_time');
261  if ($expiry_time_attr->processed) {
262  $asset->setAttrValue('expiry_time', $expiry_time_attr->value);
263  $updated = TRUE;
264  }
265 
266  // update escalation
267  $escalate_attr = $asset->getAttribute('escalate');
268  $escalate_attr->process($prefix.'_escalate');
269  if ($escalate_attr->processed) {
270  $asset->setAttrValue('escalate', $escalate_attr->value);
271  $updated = TRUE;
272  }
273 
274  if (!$asset->saveAttributes()) {
275  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
276  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
277  return FALSE;
278  }
279 
280  // delete any steps that need deleting
281  if (isset($_POST[$prefix.'_delete_steps'])) {
282  $delete_steps = $_POST[$prefix.'_delete_steps'];
283  foreach ($delete_steps as $linkid => $on) {
284  if ($asset->deleteLink($linkid)) $updated = TRUE;
285  }
286  }
287 
288  if (isset($_POST[$prefix.'_new_escalation_step']) && trim($_POST[$prefix.'_new_escalation_step'])) {
289  $new_step_name = trim($_POST[$prefix.'_new_escalation_step']);
290  $GLOBALS['SQ_SYSTEM']->am->includeAsset('workflow_step');
291  $new_step = new Workflow_Step();
292  $schema_link = Array('asset' => &$asset, 'link_type' => SQ_LINK_TYPE_2, 'sort_order' => -1, 'is_dependant' => 1);
293  $new_step->setAttrValue('name', $new_step_name);
294 
295  if ($new_step->create($schema_link)) $updated = TRUE;
296  }
297 
298  // process all our current conditions
299  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'workflow_step_condition', TRUE, 'major', NULL, TRUE, TRUE);
300  if (!empty($current_links)) {
301  foreach ($current_links as $link_data) {
302  $condition = $GLOBALS['SQ_SYSTEM']->am->getAsset($link_data['minorid']);
303  if (is_null($condition)) continue;
304  $edit_fns = $condition->getEditFns();
305  if ($edit_fns->processStepCondition($condition, $o)) {
306  $updated = TRUE;
307  }
308  }
309  }
310 
311  // delete any conditions that need deleting
312  if (isset($_POST[$prefix.'_delete_conditions'])) {
313  $delete_conds = $_POST[$prefix.'_delete_conditions'];
314  foreach ($delete_conds as $linkid => $on) {
315  if ($asset->deleteLink($linkid)) $updated = TRUE;
316  }
317  }
318 
319  // create a new condition?
320  if (isset($_POST[$prefix.'_new_condition']['assetid']) && $_POST[$prefix.'_new_condition']['assetid'] > 0) {
321  $GLOBALS['SQ_SYSTEM']->am->includeAsset('workflow_step_condition');
322  $new_cond = new Workflow_Step_Condition();
323  $step_link = Array('asset' => &$asset, 'link_type' => SQ_LINK_TYPE_2, 'sort_order' => -1, 'is_dependant' => 1, 'is_exclusive' => 1);
324  $new_cond->setAttrValue('userid', $_POST[$prefix.'_new_condition']['assetid']);
325  if ($new_cond->create($step_link)) $updated = TRUE;
326  }
327 
328  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
329  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
330 
331  return $updated;
332 
333  }//end processStep()
334 
335 
348  function generateWorkflowArray(Asset $asset, Array &$workflow_array)
349  {
350  $workflow_array = Array();
351  $workflow_array['conditions'] = Array();
352  $workflow_array['escalation_steps'] = Array();
353  $workflow_array['step_name'] = $asset->name;
354  $workflow_array['started'] = 0;
355  $workflow_array['expiry_time'] = $asset->attr('expiry_time');
356  $workflow_array['escalate'] = $asset->attr('escalate');
357  $workflow_array['completed'] = 0;
358  $workflow_array['expired'] = 0;
359  $workflow_array['require_comment_from_unlisted_users'] = $asset->attr('require_comment_from_unlisted_users');
360 
361  $workflow_array['message_invitation'] = $asset->attr('message_invitation');
362  $workflow_array['message_review_invitation'] = $asset->attr('message_review_invitation');
363  $workflow_array['message_approve'] = $asset->attr('message_approve');
364  $workflow_array['message_reject'] = $asset->attr('message_reject');
365  $workflow_array['message_review_cancel'] = $asset->attr('message_review_cancel');
366  $workflow_array['message_stale'] = $asset->attr('message_stale');
367  $workflow_array['message_escalated'] = $asset->attr('message_escalated');
368 
369  $workflow_array['subject_invitation'] = $asset->attr('subject_invitation');
370  $workflow_array['subject_review_invitation'] = $asset->attr('subject_review_invitation');
371  $workflow_array['subject_approve'] = $asset->attr('subject_approve');
372  $workflow_array['subject_reject'] = $asset->attr('subject_reject');
373  $workflow_array['subject_review_cancel'] = $asset->attr('subject_review_cancel');
374  $workflow_array['subject_stale'] = $asset->attr('subject_stale');
375  $workflow_array['subject_escalated'] = $asset->attr('subject_escalated');
376 
377  // work out the logic expression
378  $logic = $asset->attr('logic');
379  $logic_num = $asset->attr('logic_num');
380  $logic = $logic.(($logic_num) ? " $logic_num" : '');
381  $workflow_array['logic'] = $logic;
382 
383  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'workflow_step_condition', TRUE, 'major', NULL, TRUE, TRUE);
384  foreach ($current_links as $link_data) {
385  $condition = $GLOBALS['SQ_SYSTEM']->am->getAsset($link_data['minorid']);
386  if (is_null($condition)) continue;
387  $edit_fns = $condition->getEditFns();
388  if (!$edit_fns->generateWorkflowArray($condition, $workflow_array['conditions'])) {
389  return FALSE;
390  }
391 
392  }
393 
394  // work out the escalation steps
395  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'workflow_step', TRUE, 'major', NULL, TRUE, FALSE);
396  $i = 1;
397  foreach ($current_links as $link_data) {
398  $step = $GLOBALS['SQ_SYSTEM']->am->getAsset($link_data['minorid']);
399  if (is_null($step)) continue;
400  $workflow_array['escalation_steps'][$i] = Array();
401  $edit_fns = $step->getEditFns();
402  if (!$edit_fns->generateWorkflowArray($step, $workflow_array['escalation_steps'][$i])) {
403  return FALSE;
404  }
405  $i++;
406  }
407 
408  return TRUE;
409 
410  }//end generateWorkflowArray()
411 
412 
413 }//end class
414 
415 ?>