18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
43 parent::__construct();
63 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
64 echo translate(
'create_new_step_called').
' ';
65 text_box($prefix.
'_new_step',
'', 20);
86 if (isset($_POST[$prefix.
'_new_step']) && trim($_POST[$prefix.
'_new_step'])) {
87 $new_step_name = trim($_POST[$prefix.
'_new_step']);
88 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'workflow_step');
90 $schema_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'sort_order' => -1,
'is_dependant' => 1);
91 $new_step->setAttrValue(
'name', $new_step_name);
92 if (!$new_step->create($schema_link))
return FALSE;
113 $o->
addCssInclude(sq_web_path(
'data').
'/asset_types/'.$asset->
type().
'/css/workflow_stream_edit_fns.css');
114 $o->
addJsInclude(sq_web_path(
'data').
'/asset_types/'.$asset->
type().
'/js/workflow_stream_edit_fns.js');
115 $am = $GLOBALS[
'SQ_SYSTEM']->am;
119 $o->
addOnLoad(
'MatrixWorkflowSchema.onLoad();');
123 $steps_to_process = Array(
125 'assetid' => $asset->id,
130 $step_order = Array();
132 while (count($steps_to_process) > 0) {
133 $current_step = array_shift($steps_to_process);
134 if ($current_step[
'depth'] >= 0) {
135 $step_order[] = $current_step;
137 $current_links = array_reverse($am->getLinks($current_step[
'assetid'], SQ_LINK_TYPE_2,
'workflow_step', TRUE,
'major', NULL, TRUE, FALSE));
138 foreach ($current_links as $current_link) {
140 'assetid' => $current_link[
'minorid'],
141 'depth' => $current_step[
'depth'] + 1,
143 array_unshift($steps_to_process, $new_step);
147 if (count($step_order) > 0) {
148 $step_nums = Array(0);
150 foreach ($step_order as $step) {
151 if ($step[
'depth'] > $current_depth) {
153 array_push($step_nums, 0);
154 echo
'<div class="sq-workflow-step-escalation-indent">';
155 $current_depth = $step[
'depth'];
158 while ($step[
'depth'] < $current_depth) {
160 array_pop($step_nums);
162 echo
'<div class="sq-workflow-step-divider"></div>';
166 echo
'<div class="sq-workflow-step-divider"></div>';
169 $current_step_num = array_pop($step_nums);
171 array_push($step_nums, $current_step_num);
173 $step_assetid = $step[
'assetid'];
174 $step_asset =& $am->getAsset($step_assetid);
176 echo
'<div id="'.$prefix.
'workflow-step-'.$step_assetid.
'" class="sq-workflow-step">';
178 hidden_field($prefix.
'_step_order[]', $step_assetid);
181 echo
'<div class="sq-workflow-step-drag">';
183 sq_print_icon(sq_web_path(
'data').
'/asset_types/'.$asset->
type().
'/files/wf_drag_handle.png', 16, 16,
'Re-Order',
'Re-Order Step',
'align="absmiddle" class="sq-workflow-step-drag-handle"');
185 echo
'Step '.implode(
'.', $step_nums).
'</div>';
186 echo
'<div class="sq-workflow-step-tag-line">'.$step_asset->name.
'</div>';
187 echo
'<div class="sq-workflow-step-condition"><strong>Conditions:</strong> ';
188 $conditions = $am->getLinks($step_assetid, SQ_LINK_TYPE_2,
'workflow_step_condition', TRUE,
'major', NULL, TRUE);
189 if (count($conditions) === 1) {
190 $condition = reset($conditions);
191 $userids = $am->getAttributeValuesByName(
'userid',
'workflow_step_condition', Array($condition[
'minorid']));
192 $userid = $userids[$condition[
'minorid']];
193 echo get_asset_tag_line($userid);
194 }
else if (count($conditions) === 0) {
195 echo
'<span class="sq-backend-warning">None selected</span>';
197 if (($step_asset->attr(
'logic') ===
'all') || ($step_asset->attr(
'logic_num') == count($conditions))) {
198 echo
'All '.count($conditions);
200 echo
'At least '.$step_asset->attr(
'logic_num').
' of '.count($conditions);
205 echo
'<div class="sq-workflow-step-expiry"><strong>Expiry:</strong> ';
206 $expiry = (int)$step_asset->attr(
'expiry_time');
210 if ($step_asset->attr(
'escalate')) {
211 echo
'<span class="sq-backend-warning">Escalates</span>';
217 $hours = ($expiry / 3600);
219 echo easy_time_total($expiry);
224 if ($step[
'depth'] === 0) {
225 $step_url =
'#step-'.$step_assetid;
227 $step_url = $step_asset->getBackendHref(
'details');
229 echo
'<div class="sq-workflow-step-edit-link">[ <a href="'.$step_url.
'">Edit this step</a> ]</div>';
230 echo
'<div style="clear: both"></div>';
235 while ($current_depth > 0) {
236 echo
'<div class="sq-workflow-step-divider"></div>';
242 echo
'<div class="sq-workflow-step-divider"></div>';
246 return $write_access;
266 $new_step_order = array_get_index($_POST, $prefix.
'_step_order', Array());
267 $am = $GLOBALS[
'SQ_SYSTEM']->am;
269 $links_to_build = Array($asset->id);
270 $link_assetids = Array();
272 while (count($links_to_build) > 0) {
273 $assetid = array_shift($links_to_build);
274 $current_links = $am->getLinks($assetid, SQ_LINK_TYPE_2,
'workflow_step', TRUE,
'major', NULL, TRUE, FALSE);
279 foreach ($current_links as $link) {
280 $links_to_build[] = $link[
'minorid'];
281 if (count($current_links) >= 2) {
282 $new_index = array_search($link[
'minorid'], $new_step_order);
283 $link_assetids[$assetid][$new_index] = $link[
'minorid'];
288 foreach (array_keys($link_assetids) as $link_key) {
291 ksort($link_assetids[$link_key]);
292 $link_assetids[$link_key] = array_values($link_assetids[$link_key]);
293 foreach ($link_assetids[$link_key] as $sort_order => $minor_assetid) {
294 $link = $am->getLinkByAsset($link_key, $minor_assetid, SQ_LINK_TYPE_2);
295 if ($sort_order != $link[
'sort_order']) {
297 $am->moveLinkPos($link[
'linkid'], $sort_order);
319 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
323 $current_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'workflow_step', TRUE,
'major', NULL, TRUE, FALSE);
325 foreach ($current_links as $link_data) {
326 $step = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_data[
'minorid']);
327 if (is_null($step))
continue;
332 check_box($prefix.
'_delete_steps['.$link_data[
'linkid'].
']');
333 label(translate(
'delete_step_and_conditions_question'), $prefix.
'_delete_steps['.$link_data[
'linkid'].
']');
336 $edit_fns = $step->getEditFns();
337 if (!$edit_fns->paintStep($step, $o)) $ok = FALSE;
365 $current_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'workflow_step', TRUE,
'major', NULL, TRUE, FALSE);
366 foreach ($current_links as $link_data) {
367 $step = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_data[
'minorid']);
368 if (is_null($step))
continue;
369 $edit_fns = $step->getEditFns();
370 if ($edit_fns->processStep($step, $o)) $updated = TRUE;
374 if (isset($_POST[$prefix.
'_delete_steps'])) {
375 $delete_steps = $_POST[$prefix.
'_delete_steps'];
376 foreach ($delete_steps as $linkid => $on) {
377 if ($asset->
deleteLink($linkid)) $updated = TRUE;
399 $workflow_array[
'steps'] = Array();
400 $workflow_array[
'current_step'] = Array(
'1');
401 $workflow_array[
'complete'] = FALSE;
402 $workflow_array[
'schema_name'] = $asset->name;
403 $workflow_array[
'started'] = time();
404 $workflow_array[
'started_by'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
407 $current_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'workflow_step', TRUE,
'major', NULL, TRUE, FALSE);
408 foreach ($current_links as $link_data) {
409 $step = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_data[
'minorid']);
410 if (is_null($step))
continue;
411 $edit_fns = $step->getEditFns();
412 $workflow_array[
'steps'][$i] = Array();
413 if (!$edit_fns->generateWorkflowArray($step, $workflow_array[
'steps'][$i])) {
417 $workflow_array[
'steps'][$i][
'started'] = time();
421 return $workflow_array;