/* Function: Save step */
if ($action == "workflow_save_step" || $action == "workflow_create_user") {
    $workflowactions = new WorkflowActions();
    foreach ($availableWorkflowActions as $key => $value) {
        if ($wfactions[$key] == 1) {
            $workflowactions->set($idworkflowitem, $key);
        } else {
            $workflowactions->remove($idworkflowitem, $key);
        }
    }
    $workflowitem = new WorkflowItem();
    $workflowitem->loadByPrimaryKey($idworkflowitem);
    $workflowitem->setField('idtask', $wftaskselect);
    $workflowitem->setField('name', $wfstepname);
    $workflowitem->setField('description', $wfstepdescription);
    $workflowitem->store();
    $usersequences = new WorkflowUserSequences();
    $usersequences->select("idworkflowitem = '{$idworkflowitem}'");
    while ($usersequence = $usersequences->next()) {
        $wftime = "time" . $usersequence->get("idusersequence");
        $wfuser = "******" . $usersequence->get("idusersequence");
        $wftimelimit = "wftimelimit" . $usersequence->get("idusersequence");
        $usersequence->set("timeunit", ${$wftime});
        $usersequence->set("iduser", ${$wfuser});
        $usersequence->set("timelimit", ${$wftimelimit});
        $usersequence->set("emailnoti", $wfemailnoti[$usersequence->get("idusersequence")]);
        $usersequence->set("escalationnoti", $wfescalnoti[$usersequence->get("idusersequence")]);
        $usersequence->store();
    }
}
function getTimeUnitSelector($listid, $default)
 function swap($idworkflow, $pos1, $pos2)
 {
     $this->select("idworkflow = '{$idworkflow}' AND position = '{$pos1}'");
     if (($item = $this->next()) === false) {
         $this->lasterror = i18n("Swapping items failed: Item doesn't exist", "workflow");
         return false;
     }
     $pos1ID = $item->getField("idworkflowitem");
     $this->select("idworkflow = '{$idworkflow}' AND position = '{$pos2}'");
     if (($item = $this->next()) === false) {
         $this->lasterror = i18n("Swapping items failed: Item doesn't exist", "workflow");
         return false;
     }
     $pos2ID = $item->getField("idworkflowitem");
     $item = new WorkflowItem();
     $item->loadByPrimaryKey($pos1ID);
     $item->setPosition($pos2);
     $item->store();
     $item->loadByPrimaryKey($pos2ID);
     $item->setPosition($pos1);
     $item->store();
     $this->updateArtAllocation($pos1ID);
     $this->updateArtAllocation($pos2ID);
     return true;
 }