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;
    }
}
 /**
  * Overriden store function to send mails 
  * @param none
  */
 function store()
 {
     global $cfg, $encoding, $lang;
     $sMailhost = getSystemProperty('system', 'mail_host');
     if ($sMailhost == '') {
         $sMailhost = 'localhost';
     }
     //modified : 2008-06-25 - use php mailer class instead of mail()
     $oMail = new PHPMailer();
     $oMail->CharSet = isset($encoding[$lang]) ? $encoding[$lang] : 'UTF-8';
     $oMail->Host = $sMailhost;
     $oMail->IsHTML(0);
     $oMail->WordWrap = 1000;
     $oMail->IsMail();
     if (array_key_exists("idusersequence", $this->modifiedValues)) {
         $usersequence = new WorkflowUserSequence();
         $usersequence->loadByPrimaryKey($this->values["idusersequence"]);
         $email = $usersequence->get("emailnoti");
         $escal = $usersequence->get("escalationnoti");
         if ($email == 1 || $escal == 1) {
             /* Grab the required informations */
             $curEditor = getGroupOrUserName($usersequence->get("iduser"));
             $idartlang = $this->get("idartlang");
             $timeunit = $usersequence->get("timeunit");
             $timelimit = $usersequence->get("timelimit");
             $db = new DB_Contenido();
             $sql = "SELECT author, title, idart FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . Contenido_Security::escapeDB($idartlang, $db) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $idart = $db->f("idart");
                 $title = $db->f("title");
                 $author = $db->f("author");
             }
             /* Extract category */
             $sql = "SELECT idcat FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = '" . Contenido_Security::escapeDB($idart, $db) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $idcat = $db->f("idcat");
             }
             $sql = "SELECT name FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat = '" . Contenido_Security::escapeDB($idcat, $db) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $catname = $db->f("name");
             }
             $starttime = $this->get("starttime");
             $starttime = strtotime(substr_replace(substr(substr($starttime, 0, 2) . chunk_split(substr($starttime, 2, 6), 2, "-") . chunk_split(substr($starttime, 8), 2, ":"), 0, 19), " ", 10, 1));
             switch ($timeunit) {
                 case "Seconds":
                     $maxtime = $starttime + $timelimit;
                     break;
                 case "Minutes":
                     $maxtime = $starttime + $timelimit * 60;
                     break;
                 case "Hours":
                     $maxtime = $starttime + $timelimit * 3600;
                     break;
                 case "Days":
                     $maxtime = $starttime + $timelimit * 86400;
                     break;
                 case "Weeks":
                     $maxtime = $starttime + $timelimit * 604800;
                     break;
                 case "Months":
                     $maxtime = $starttime + $timelimit * 2678400;
                     break;
                 case "Years":
                     $maxtime = $starttime + $timelimit * 31536000;
                     break;
                 default:
                     $maxtime = $starttime + $timelimit;
             }
             if ($email == 1) {
                 $email = i18n("Hello %s,\n\n" . "you are assigned as the next editor for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n");
                 $filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
                 $user = new User();
                 if (isGroup($usersequence->get("iduser"))) {
                     $sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE\n            \t\t\t\t\t\tgroup_id = '" . Contenido_Security::escapeDB($usersequence->get("iduser"), $db) . "'";
                     $db->query($sql);
                     while ($db->next_record()) {
                         $user->loadUserByUserID($db->f("user_id"));
                         //modified : 2008-06-25 - use php mailer class instead of mail()
                         $oMail->AddAddress($user->getField("email"), "");
                         $oMail->Subject = stripslashes(i18n('Workflow notification', "workflow"));
                         $oMail->Body = $filledMail;
                         $oMail->Send();
                     }
                 } else {
                     $user->loadUserByUserID($usersequence->get("iduser"));
                     //modified : 2008-06-25 - use php mailer class instead of mail()
                     $oMail->AddAddress($user->getField("email"), "");
                     $oMail->Subject = stripslashes(i18n('Workflow notification', "workflow"));
                     $oMail->Body = $filledMail;
                     $oMail->Send();
                 }
             } else {
                 $email = "Hello %s,\n\n" . "you are assigned as the escalator for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n";
                 $filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
                 $user = new User();
                 if (isGroup($usersequence->get("iduser"))) {
                     $sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE\n            \t\t\t\t\t\tgroup_id = '" . Contenido_Security::escapeDB($usersequence->get("iduser"), $db) . "'";
                     $db->query($sql);
                     while ($db->next_record()) {
                         $user->loadUserByUserID($db->f("user_id"));
                         echo "mail to " . $user->getField("email") . "<br>";
                         //modified : 2008-06-25 - use php mailer class instead of mail()
                         $oMail->AddAddress($user->getField("email"), "");
                         $oMail->Subject = stripslashes(i18n('Workflow escalation', "workflow"));
                         $oMail->Body = $filledMail;
                         $oMail->Send();
                     }
                 } else {
                     $user->loadUserByUserID($usersequence->get("iduser"));
                     echo "mail to " . $user->getField("email") . "<br>";
                     //modified : 2008-06-25 - use php mailer class instead of mail()
                     $oMail->AddAddress($user->getField("email"), "");
                     $oMail->Subject = stripslashes(i18n('Workflow escalation', "workflow"));
                     $oMail->Body = $filledMail;
                     $oMail->Send();
                 }
             }
         }
     }
     return parent::store();
 }
} else {
    $tpl->set('s', 'USERSELECT', '');
}
$pageTitle = i18n('Search results') . ' - ' . i18n('Workflow tasks', 'workflow');
$tpl->set('s', 'PAGE_TITLE', $pageTitle);
$tpl->set('s', 'TH_START', i18n("Article"));
$tpl->set('s', 'TH_TEMPLATE', i18n("Template"));
$tpl->set('s', 'TH_ACTIONS', i18n("Actions"));
$tpl->set('s', 'TH_TITLE', i18n("Title"));
$tpl->set('s', 'TH_CHANGED', i18n("Changed"));
$tpl->set('s', 'TH_PUBLISHED', i18n("Published"));
$tpl->set('s', 'TH_WORKFLOW_STEP', i18n("Workflow Step", 'workflow'));
$tpl->set('s', 'TH_WORKFLOW_ACTION', i18n("Workflow Action", 'workflow'));
$tpl->set('s', 'TH_WORKFLOW_EDITOR', i18n("Workflow Editor", 'workflow'));
$tpl->set('s', 'TH_LAST_STATUS', i18n("Last status", 'workflow'));
$currentUserSequence = new WorkflowUserSequence();
if (is_array($isCurrent)) {
    foreach ($isCurrent as $key => $value) {
        if ($value == true) {
            $idartlang = Contenido_Security::toInteger($article[$key]);
            $lang = Contenido_Security::toInteger($lang);
            $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>';