/** * 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; }
// article category - the article will be shown also, if he doesn't have any rights at all... if ($action == "news_save" && $perm->have_perm_area_action("news", $action)) { // Changing e.g. \' back to ' (magic_quotes) $sMessage = Contenido_Security::unescapeDB($_REQUEST["txtMessage"]); $oNewsletter->set("message", $sMessage); if ($oNewsletter->get("template_idart") != $_REQUEST["selTemplate"]) { if ($oNewsletter->get("idart") > 0) { // Template has been changed: Delete old article // (this discards the current html content as it deletes the existing newsletter article) conDeleteArt($oNewsletter->get("idart")); $iIDArt = 0; } if ($_REQUEST["selTemplate"] > 0) { // Template has been changed, but specified: Store template article as new newsletter article $iIDArt = conCopyArticle($_REQUEST["selTemplate"], $oClientLang->getProperty("newsletter", "html_newsletter_idcat"), sprintf(i18n("Newsletter: %s", $plugin_name), $oNewsletter->get("name"))); conMakeOnline($iIDArt, $lang); // Article has to be online for sending... } $oNewsletter->set("idart", $iIDArt); $oNewsletter->set("template_idart", $_REQUEST["selTemplate"]); } $oNewsletter->store(); } else { if ($oNewsletter->get("idart") > 0) { // Check, if html message article and template article are still available $oArticles = new cApiArticleLanguageCollection(); $oArticles->setWhere("idlang", $lang); $oArticles->setWhere("idart", $oNewsletter->get("idart")); $oArticles->query(); if ($oArticles->count() == 0) { // Ups, article lost, reset idart and template_idart for newsletter