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: } }
/** * Duplicates the newsletter specified by $itemID * @param $itemID integer specifies the newsletter id */ public function duplicate($iItemID) { global $client, $lang, $auth; $client = Contenido_Security::toInteger($client); $lang = Contenido_Security::toInteger($lang); cInclude("includes", "functions.con.php"); $oBaseItem = new Newsletter(); $oBaseItem->loadByPrimaryKey($iItemID); $oItem = parent::create(); $oItem->set("name", $oBaseItem->get("name") . "_" . substr(md5(rand()), 0, 10)); $iIDArt = 0; if ($oBaseItem->get("type") == "html" && $oBaseItem->get("idart") > 0 && $oBaseItem->get("template_idart") > 0) { $oClientLang = new cApiClientLanguage(false, $client, $lang); if ($oClientLang->getProperty("newsletter", "html_newsletter") == "true") { $iIDArt = conCopyArticle($oBaseItem->get("idart"), $oClientLang->getProperty("newsletter", "html_newsletter_idcat"), sprintf(i18n("Newsletter: %s", $plugin_name), $oItem->get("name"))); conMakeOnline($iIDArt, $lang); // Article has to be online for sending... } unset($oClientLang); } $oItem->set("idart", $iIDArt); $oItem->set("template_idart", $oBaseItem->get("template_idart")); $oItem->set("idclient", $client); $oItem->set("idlang", $lang); $oItem->set("welcome", 0); $oItem->set("type", $oBaseItem->get("type")); $oItem->set("subject", $oBaseItem->get("subject")); $oItem->set("message", $oBaseItem->get("message")); $oItem->set("newsfrom", $oBaseItem->get("newsfrom")); $oItem->set("newsfromname", $oBaseItem->get("newsfromname")); $oItem->set("newsdate", date("Y-m-d H:i:s"), false); // But more or less deprecated $oItem->set("use_cronjob", $oBaseItem->get("use_cronjob")); $oItem->set("send_to", $oBaseItem->get("send_to")); $oItem->set("send_ids", $oBaseItem->get("send_ids")); $oItem->set("dispatch", $oBaseItem->get("dispatch")); $oItem->set("dispatch_count", $oBaseItem->get("dispatch_count")); $oItem->set("dispatch_delay", $oBaseItem->get("dispatch_delay")); $oItem->set("author", $auth->auth["uid"]); $oItem->set("created", date("Y-m-d H:i:s"), false); // Copy properties, runtime on-demand allocation of the properties object if (!is_object($this->properties)) { $this->properties = new PropertyCollection(); } $this->properties->setWhere("idclient", $client); $this->properties->setWhere("itemtype", $this->primaryKey); $this->properties->setWhere("itemid", $iItemID); $this->properties->query(); while ($oPropertyItem = $this->properties->next()) { $oItem->setProperty($oPropertyItem->get("type"), $oPropertyItem->get("name"), $oPropertyItem->get("value")); } $oItem->store(); return $oItem; }
$oArticles->query(); if ($oArticles->count() == 0) { // Ups, article lost, reset idart and template_idart for newsletter $notis = $notification->returnNotification("error", sprintf(i18n("The html newsletter article has been deleted (idart: %s), the html message is lost", $plugin_name), $oNewsletter->get("idart"))) . "<br>"; $oNewsletter->set("idart", 0); $oNewsletter->set("template_idart", 0); $oNewsletter->store(); } else { $oArticles->resetQuery(); $oArticles->setWhere("idlang", $lang); $oArticles->setWhere("idart", $oNewsletter->get("template_idart")); $oArticles->query(); if ($oArticles->count() == 0) { // Ups, template has been deleted: Restore from current newsletter message article $notis = $notification->returnNotification("warning", i18n("The html newsletter template article has been deleted, it has been restored using the html message article of this newsletter", $plugin_name)) . "<br>"; $iIDArt = conCopyArticle($oNewsletter->get("idart"), $oClientLang->getProperty("newsletter", "html_template_idcat"), sprintf(i18n("%s (Template restored)", $plugin_name), $oNewsletter->get("name"))); $oNewsletter->set("template_idart", $iIDArt); $oNewsletter->store(); } } } } $oForm = new UI_Table_Form("frmNewsletterMsg"); $oForm->setVar("frame", $frame); $oForm->setVar("area", $area); $oForm->setVar("action", "news_save"); $oForm->setVar("idnewsletter", $idnewsletter); $oForm->setWidth("100%"); $oForm->addHeader(sprintf(i18n("Edit newsletter message (%s)", $plugin_name), $oNewsletter->get("name"))); $oForm->add(i18n("Subject", $plugin_name), $oNewsletter->get("subject")); $sTagInfoText = '<a href="javascript:fncShowHide(\'idTagInfoText\');"><strong>' . i18n("Tag information", $plugin_name) . '</strong></a>' . '<div id="idTagInfoText" style="display: none"><br /><b>' . i18n("Special message tags (will be replaced when sending)", $plugin_name) . ':</b><br>' . 'MAIL_NAME: ' . i18n("Name of the recipient", $plugin_name) . '<br />' . 'MAIL_DATE: ' . i18n("Date, when the mail has been sent", $plugin_name) . '<br />' . 'MAIL_TIME: ' . i18n("Time, when the mail has been sent", $plugin_name) . '<br />' . 'MAIL_NUMBER: ' . i18n("Number of recipients", $plugin_name) . '<br />' . 'MAIL_UNSUBSCRIBE: ' . i18n("Link to unsubscribe", $plugin_name) . '<br />' . 'MAIL_STOP: ' . i18n("Link to pause the subscription", $plugin_name) . '<br />' . 'MAIL_GOON: ' . i18n("Link to resume the subscription", $plugin_name);