function doWorkflowAction($idartlang, $action)
{
    global $cfg, $idcat;
    switch ($action) {
        case "last":
            $artAllocations = new WorkflowArtAllocations();
            $artAllocations->select("idartlang = '{$idartlang}'");
            if ($obj = $artAllocations->next()) {
                $usersequence = new WorkflowUserSequence();
                $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
                $workflowitem = $usersequence->getWorkflowItem();
                $idworkflow = $workflowitem->get("idworkflow");
                $newpos = $workflowitem->get("position") - 1;
                if ($newpos < 1) {
                    $newpos = 1;
                }
                $workflowitems = new WorkflowItems();
                $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($newpos, NULL) . "'");
                if ($nextObj = $workflowitems->next()) {
                    $userSequences = new WorkflowUserSequences();
                    $idworkflowitem = $nextObj->get("idworkflowitem");
                    $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                    if ($nextSeqObj = $userSequences->next()) {
                        $obj->set("lastusersequence", $obj->get("idusersequence"));
                        $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                        $obj->set("laststatus", "last");
                        $obj->store();
                    }
                }
            }
            break;
        case "next":
            $artAllocations = new WorkflowArtAllocations();
            $artAllocations->select("idartlang = '{$idartlang}'");
            if ($obj = $artAllocations->next()) {
                $usersequence = new WorkflowUserSequence();
                $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
                $workflowitem = $usersequence->getWorkflowItem();
                $idworkflow = $workflowitem->get("idworkflow");
                $newpos = $workflowitem->get("position") + 1;
                $workflowitems = new WorkflowItems();
                $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($newpos, NULL) . "'");
                if ($nextObj = $workflowitems->next()) {
                    $userSequences = new WorkflowUserSequences();
                    $idworkflowitem = $nextObj->get("idworkflowitem");
                    $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                    if ($nextSeqObj = $userSequences->next()) {
                        $obj->set("lastusersequence", '10');
                        $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                        $obj->set("laststatus", "confirm");
                        $obj->store();
                    }
                } else {
                    $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($workflowitem->get("position"), NULL) . "'");
                    if ($nextObj = $workflowitems->next()) {
                        $userSequences = new WorkflowUserSequences();
                        $idworkflowitem = $nextObj->get("idworkflowitem");
                        $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                        if ($nextSeqObj = $userSequences->next()) {
                            $obj->set("lastusersequence", $obj->get("idusersequence"));
                            $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                            $obj->set("laststatus", "confirm");
                            $obj->store();
                        }
                    }
                }
            }
            break;
        case "reject":
            $artAllocations = new WorkflowArtAllocations();
            $artAllocations->select("idartlang = '{$idartlang}'");
            if ($obj = $artAllocations->next()) {
                $usersequence = new WorkflowUserSequence();
                $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
                $workflowitem = $usersequence->getWorkflowItem();
                $idworkflow = $workflowitem->get("idworkflow");
                $newpos = 1;
                $workflowitems = new WorkflowItems();
                $workflowitems->select("idworkflow = '{$idworkflow}' AND position = '" . Contenido_Security::escapeDB($newpos, NULL) . "'");
                if ($nextObj = $workflowitems->next()) {
                    $userSequences = new WorkflowUserSequences();
                    $idworkflowitem = $nextObj->get("idworkflowitem");
                    $userSequences->select("idworkflowitem = '{$idworkflowitem}'");
                    if ($nextSeqObj = $userSequences->next()) {
                        $obj->set("lastusersequence", $obj->get("idusersequence"));
                        $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
                        $obj->set("laststatus", "reject");
                        $obj->store();
                    }
                }
            }
            break;
        case "revise":
            $db = new DB_Contenido();
            $sql = "SELECT idart, idlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . Contenido_Security::escapeDB($idartlang, $db) . "'";
            $db->query($sql);
            $db->next_record();
            $idart = $db->f("idart");
            $idlang = $db->f("idlang");
            $newidart = conCopyArticle($idart, $idcat, "foo");
            break;
        default:
    }
}
function piworkflowRenderColumn($idcat, $idart, $idartlang, $column)
{
    global $area, $frame, $idtpl, $cfg, $alttitle, $tmp_articletitle;
    $defaultidworkflow = getWorkflowForCat($idcat);
    $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
    $associatedUserSequence = new WorkflowUserSequence();
    $associatedUserSequence->loadByPrimaryKey($idusersequence);
    $currentEditor = $associatedUserSequence->get("iduser");
    $workflowItem = $associatedUserSequence->getWorkflowItem();
    if (isCurrentEditor($associatedUserSequence->get("iduser"))) {
        $wfRights = $workflowItem->getStepRights();
        $mayEdit = true;
    } else {
        $wfRights = "";
        $mayEdit = false;
    }
    switch ($column) {
        case "wftitle":
            if ($wfRights["articleedit"] == true) {
                $mtitle = $tmp_articletitle;
            } else {
                $mtitle = strip_tags($tmp_articletitle);
            }
            return $mtitle;
        case "wfstep":
            if ($workflowItem === false) {
                return "nobody";
            }
            return $workflowItem->get("position") . ".) " . $workflowItem->get("name");
        case "wfeditor":
            $sEditor = getGroupOrUserName($currentEditor);
            if (!$sEditor) {
                $sEditor = "nobody";
            }
            return $sEditor;
        case "wfaction":
            $defaultidworkflow = getWorkflowForCat($idcat);
            $idusersequence = getCurrentUserSequence($idartlang, $defaultidworkflow);
            $sActionSelect = getActionSelect($idartlang, $idusersequence);
            if (!$sActionSelect) {
                $mayEdit = false;
            }
            $form = new UI_Form("wfaction" . $idartlang, "main.php", "get");
            $form->setVar("area", $area);
            $form->setVar("action", "workflow_do_action");
            $form->setVar("frame", $frame);
            $form->setVar("idcat", $idcat);
            $form->setVar("modidartlang", $idartlang);
            $form->setVar("idtpl", $idtpl);
            $form->add("select", '<table cellspacing="0" border="0"><tr><td>' . $sActionSelect . '</td><td>');
            $form->add("button", '<input type="image" src="' . $cfg["path"]["htmlpath"] . $cfg["path"]["images"] . "submit.gif" . '"></tr></table>');
            if ($mayEdit == true) {
                return $form->render(true);
            } else {
                return '--- ' . i18n("None") . ' ---';
            }
        case "wflaststatus":
            $sStatus = getLastWorkflowStatus($idartlang);
            if (!$sStatus) {
                $sStatus = '--- ' . i18n("None") . ' ---';
            }
            return $sStatus;
    }
}
 function getWorkflowItem()
 {
     $userSequence = new WorkflowUserSequence();
     $userSequence->loadByPrimaryKey($this->values["idusersequence"]);
     return $userSequence->getWorkflowItem();
 }
 $client = Contenido_Security::toInteger($client);
 $sql = "SELECT B.idcat AS idcat, A.title AS title, A.created AS created, A.lastmodified AS changed, \n                       A.idart as idart, E.name as tpl_name, A.idartlang as idartlang, F.idcatlang as idcatlang,\n                       B.idcatart as idcatart, A.idlang as art_lang, F.startidartlang as startidartlang\n    \t\t\tFROM (" . $cfg["tab"]["art_lang"] . " AS A,\n                     " . $cfg["tab"]["cat_art"] . " AS B,\n \t\t\t\t\t " . $cfg["tab"]["art"] . " AS C)\n                      LEFT JOIN " . $cfg['tab']['tpl_conf'] . " as D ON A.idtplcfg = D.idtplcfg\n                      LEFT JOIN " . $cfg['tab']['tpl'] . " as E ON D.idtpl = E.`idtpl`\n                      LEFT JOIN " . $cfg['tab']['cat_lang'] . " as F ON B.idcat = F.`idcat`\n\t\t\t\t\t WHERE A.idartlang = '{$idartlang}' AND\n\t\t\t\t\t\t   A.idart = B.idart AND\n\t\t\t\t\t\t   A.idart = C.idart AND\n\t\t\t\t\t\t   A.idlang = '{$lang}' AND\n \t\t\t\t\t\t   C.idclient = '{$client}';";
 $db->query($sql);
 if ($db->next_record()) {
     global $area;
     //$area = "con";
     $idcat = $db->f("idcat");
     $idart = $db->f("idart");
     # create javascript multilink
     $tmp_mstr = '<a href="javascript://" onclick="javascript:conMultiLink(\'%s\', \'%s\', \'%s\', \'%s\')"  title="idart: ' . $db->f('idart') . ' idcatart: ' . $db->f('idcatart') . '" alt="idart: ' . $db->f('idart') . ' idcatart: ' . $db->f('idcatart') . '">%s</a>';
     $mstr = sprintf($tmp_mstr, 'right_top', $sess->url("main.php?area=con&frame=3&idcat={$idcat}&idtpl={$idtpl}"), 'right_bottom', $sess->url("main.php?area=con_editart&action=con_edit&frame=4&idcat={$idcat}&idtpl={$idtpl}&idart={$idart}"), $db->f("title"));
     $laststatus = getLastWorkflowStatus($idartlang);
     $username = getGroupOrUserName($userids[$key]);
     $actionSelect = piworkflowRenderColumn($idcat, $idart, $db->f('idartlang'), 'wfaction');
     $currentUserSequence->loadByPrimaryKey($usersequence[$key]);
     $workflowItem = $currentUserSequence->getWorkflowItem();
     $step = $workflowItem->get("name");
     $description = $workflowItem->get("description");
     $sRowId = $db->f('idart') . '-' . $db->f('idartlang') . '-' . $db->f('idcat') . '-' . $db->f('idcatlang') . '-' . $db->f('idcatart') . '-' . $db->f('art_lang');
     if ($db->f('startidartlang') == $db->f('idartlang')) {
         $makeStartarticle = "<img src=\"images/arrow.gif\" alt=\"&gt;\" border=\"0\" style=\"vertical-align: text-top;\"><img src=\"images/isstart0.gif\" border=\"0\" title=\"{$sFlagTitle}\" alt=\"{$sFlagTitle}\" style=\"margin-left: 7px;\">";
     } else {
         $makeStartarticle = "<img src=\"images/isstart0.gif\" border=\"0\" title=\"{$sFlagTitle}\" alt=\"{$sFlagTitle}\" style=\"margin-left: 2px;\">";
     }
     $todoListeSubject = i18n("Reminder");
     $sReminder = i18n("Set reminder / add to todo list");
     $sReminderHtml = "<a id=\"m1\" onclick=\"javascript:window.open('main.php?subject={$todoListeSubject}&amp;area=todo&amp;frame=1&amp;itemtype=idart&amp;itemid={$idart}&amp;contenido={$sSession}', 'todo', 'scrollbars=yes, height=300, width=550');\" alt=\"{$sReminder}\" title=\"{$sReminder}\" href=\"#\"><img id=\"m2\" style=\"padding-left: 2px; padding-right: 2px;\" alt=\"{$sReminder}\" src=\"images/but_setreminder.gif\" border=\"0\"></a>";
     $templatename = $db->f('tpl_name');
     if (!empty($templatename)) {
         $templatename = htmlentities($templatename);
     } else {