/** * Creates a new recipient * @param string $sEMail Specifies the e-mail adress * @param string $sName Specifies the recipient name (optional) * @param int $iConfirmed Specifies, if the recipient is confirmed (optional) * @param string $sJoinID Specifies additional recipient group ids to join (optional, e.g. 47,12,...) * @param int $iMessageType Specifies the message type for the recipient (0 = text, 1 = html) */ public function create($sEMail, $sName = "", $iConfirmed = 0, $sJoinID = "", $iMessageType = 0, $bAddToDefaultGroup = true) { global $client, $lang, $auth; $iConfirmed = (int) $iConfirmed; $iMessageType = (int) $iMessageType; /* Check if the e-mail adress already exists */ $email = strtolower($email); // e-mail always lower case $this->setWhere("idclient", $client); $this->setWhere("idlang", $lang); $this->setWhere("email", $sEMail); $this->query(); if ($this->next()) { return $this->create($sEMail . "_" . substr(md5(rand()), 0, 10), $sName, 0, $sJoinID, $iMessageType); // 0: Deactivate 'confirmed' } $oItem = parent::create(); $oItem->set("idclient", $client); $oItem->set("idlang", $lang); $oItem->set("name", $sName); $oItem->set("email", $sEMail); $oItem->set("hash", substr(md5(rand()), 0, 17) . uniqid("")); // Generating UID, 30 characters $oItem->set("confirmed", $iConfirmed); $oItem->set("news_type", $iMessageType); if ($iConfirmed) { $oItem->set("confirmeddate", date("Y-m-d H:i:s"), false); } $oItem->set("deactivated", 0); $oItem->set("created", date("Y-m-d H:i:s"), false); $oItem->set("author", $auth->auth["uid"]); $oItem->store(); $iIDRcp = $oItem->get("idnewsrcp"); // Getting internal id of new recipient if ($bAddToDefaultGroup) { // Add this recipient to the default recipient group (if available) $oGroups = new RecipientGroupCollection(); $oGroupMembers = new RecipientGroupMemberCollection(); $oGroups->setWhere("idclient", $client); $oGroups->setWhere("idlang", $lang); $oGroups->setWhere("defaultgroup", 1); $oGroups->query(); while ($oGroup = $oGroups->next()) { $iIDGroup = $oGroup->get("idnewsgroup"); $oGroupMembers->create($iIDGroup, $iIDRcp); } } // Add to other recipient groups as well? Do so! if ($sJoinID != "") { $aJoinID = explode(",", $sJoinID); if (count($aJoinID) > 0) { foreach ($aJoinID as $iIDGroup) { $oGroupMembers->create($iIDGroup, $iIDRcp); } } } return $oItem; }
function set($idworkflowitem, $action) { $this->select("idworkflowitem = '" . Contenido_Security::escapeDB($idworkflowitem, NULL) . "' AND action = '" . Contenido_Security::escapeDB($action, NULL) . "'"); if (!$this->next()) { $newitem = parent::create(); $newitem->setField("idworkflowitem", $idworkflowitem); $newitem->setField("action", $action); $newitem->store(); } }
function create() { global $auth, $client, $lang; $newitem = parent::create(); $newitem->setField("created", date("Y-m-d H-i-s")); $newitem->setField("idauthor", $auth->auth["uid"]); $newitem->setField("idclient", $client); $newitem->setField("idlang", $lang); $newitem->store(); return $newitem; }
function create($idartlang) { global $cfg; $sql = "SELECT idartlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . Contenido_Security::escapeDB($idartlang, $this->db) . "'"; $this->db->query($sql); if (!$this->db->next_record()) { $this->lasterror = i18n("Article doesn't exist", "workflow"); return false; } $this->select("idartlang = '{$idartlang}'"); if ($this->next() !== false) { $this->lasterror = i18n("Article is already assigned to a usersequence step.", "workflow"); return false; } $newitem = parent::create(); $newitem->setField("idartlang", $idartlang); $newitem->store(); return $newitem; }
/** * Creates a single new log item * @param $idnewsjob integer ID of corresponding newsletter send job * @param $idnewsrcp integer ID of recipient * @param $rcp_name string Name of the recipient (-> recipient may be deleted) * @param $rcp_email string E-Mail of the recipient (-> recipient may be deleted) */ public function create($idnewsjob, $idnewsrcp) { global $client, $lang, $auth; $idnewsjob = Contenido_Security::toInteger($idnewsjob); $idnewsrcp = Contenido_Security::toInteger($idnewsrcp); $client = Contenido_Security::toInteger($client); $lang = Contenido_Security::toInteger($lang); $this->resetQuery(); $this->setWhere("idnewsjob", $idnewsjob); $this->setWhere("idnewsrcp", $idnewsrcp); $this->query(); if ($oItem = $this->next()) { return $oItem; } $oRecipient = new Recipient(); if ($oRecipient->loadByPrimaryKey($idnewsrcp)) { $oItem = parent::create(); $oItem->set("idnewsjob", $idnewsjob); $oItem->set("idnewsrcp", $idnewsrcp); $sEMail = $oRecipient->get("email"); $sName = $oRecipient->get("name"); if ($sName == "") { $oItem->set("rcpname", $sEMail); } else { $oItem->set("rcpname", $sName); } $oItem->set("rcpemail", $sEMail); $oItem->set("rcphash", $oRecipient->get("hash")); $oItem->set("rcpnewstype", $oRecipient->get("news_type")); $oItem->set("status", "pending"); $oItem->set("created", date("Y-m-d H:i:s"), false); $oItem->store(); return $oItem; } else { return false; } }
function create() { $newitem = parent::create(); return $newitem; }
/** * Creates a newsletter job * @param $name string Specifies the name of the newsletter, the same name may be used more than once * @param $idnews integer Newsletter id */ public function create($iIDNews, $iIDCatArt, $sName = "") { global $client, $lang, $cfg, $cfgClient, $auth; $oNewsletter = new Newsletter(); if ($oNewsletter->loadByPrimaryKey($iIDNews)) { $iIDNews = Contenido_Security::toInteger($iIDNews); $iIDCatArt = Contenido_Security::toInteger($iIDCatArt); $lang = Contenido_Security::toInteger($lang); $client = Contenido_Security::toInteger($client); $sName = Contenido_Security::escapeDB($sName, null); $oItem = parent::create(); $oItem->set("idnews", $iIDNews); $oItem->set("idclient", $client); $oItem->set("idlang", $lang); if ($sName == "") { $oItem->set("name", $oNewsletter->get("name")); } else { $oItem->set("name", $sName); } $oItem->set("type", $oNewsletter->get("type")); $oItem->set("use_cronjob", $oNewsletter->get("use_cronjob")); $oLang = new cApiLanguage($lang); $oItem->set("encoding", $oLang->get("encoding")); unset($oLang); $oItem->set("idart", $oNewsletter->get("idart")); $oItem->set("subject", $oNewsletter->get("subject")); // Precompile messages #$sPath = $cfgClient[$client]["path"]["htmlpath"]."front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&"; $sPath = Contenido_Url::getInstance()->build(array('idcatart' => $iIDCatArt, 'client' => $client, 'lang' => $lang), true); $sPath .= strpos($sPath, '?') === false ? '?' : '&'; $sMessageText = $oNewsletter->get("message"); // Preventing double lines in mail, you may wish to disable this function on windows servers if (!getSystemProperty("newsletter", "disable-rn-replacement")) { $sMessageText = str_replace("\r\n", "\n", $sMessageText); } $oNewsletter->_replaceTag($sMessageText, false, "unsubscribe", $sPath . "unsubscribe={KEY}"); $oNewsletter->_replaceTag($sMessageText, false, "change", $sPath . "change={KEY}"); $oNewsletter->_replaceTag($sMessageText, false, "stop", $sPath . "stop={KEY}"); $oNewsletter->_replaceTag($sMessageText, false, "goon", $sPath . "goon={KEY}"); $oItem->set("message_text", $sMessageText); if ($oNewsletter->get("type") == "text") { // Text newsletter, no html message $sMessageHTML = ""; } else { // HTML newsletter, get article content $sMessageHTML = $oNewsletter->getHTMLMessage(); if ($sMessageHTML) { $oNewsletter->_replaceTag($sMessageHTML, true, "name", "MAIL_NAME"); $oNewsletter->_replaceTag($sMessageHTML, true, "number", "MAIL_NUMBER"); $oNewsletter->_replaceTag($sMessageHTML, true, "date", "MAIL_DATE"); $oNewsletter->_replaceTag($sMessageHTML, true, "time", "MAIL_TIME"); $oNewsletter->_replaceTag($sMessageHTML, true, "unsubscribe", $sPath . "unsubscribe={KEY}"); $oNewsletter->_replaceTag($sMessageHTML, true, "change", $sPath . "change={KEY}"); $oNewsletter->_replaceTag($sMessageHTML, true, "stop", $sPath . "stop={KEY}"); $oNewsletter->_replaceTag($sMessageHTML, true, "goon", $sPath . "goon={KEY}"); // Replace plugin tags by simple MAIL_ tags if (getSystemProperty("newsletter", "newsletter-recipients-plugin") == "true") { if (is_array($cfg['plugins']['recipients'])) { foreach ($cfg['plugins']['recipients'] as $sPlugin) { plugin_include("recipients", $sPlugin . "/" . $sPlugin . ".php"); if (function_exists("recipients_" . $sPlugin . "_wantedVariables")) { $aPluginVars = array(); $aPluginVars = call_user_func("recipients_" . $sPlugin . "_wantedVariables"); foreach ($aPluginVars as $sPluginVar) { $oNewsletter->_replaceTag($sMessageHTML, true, $sPluginVar, "MAIL_" . strtoupper($sPluginVar)); } } } } } } else { // There was a problem getting html message (maybe article deleted) // Cancel job generation return false; } } $oItem->set("message_html", $sMessageHTML); $oItem->set("newsfrom", $oNewsletter->get("newsfrom")); if ($oNewsletter->get("newsfromname") == "") { $oItem->set("newsfromname", $oNewsletter->get("newsfrom")); } else { $oItem->set("newsfromname", $oNewsletter->get("newsfromname")); } $oItem->set("newsdate", date("Y-m-d H:i:s"), false); //$oNewsletter->get("newsdate")); $oItem->set("dispatch", $oNewsletter->get("dispatch")); $oItem->set("dispatch_count", $oNewsletter->get("dispatch_count")); $oItem->set("dispatch_delay", $oNewsletter->get("dispatch_delay")); // Store "send to" info in serialized array (just info) $aSendInfo = array(); $aSendInfo[] = $oNewsletter->get("send_to"); switch ($oNewsletter->get("send_to")) { case "selection": $oGroups = new RecipientGroupCollection(); $oGroups->setWhere("idnewsgroup", unserialize($oNewsletter->get("send_ids")), "IN"); $oGroups->setOrder("groupname"); $oGroups->query(); #$oGroups->select("idnewsgroup IN ('" . implode("','", unserialize($oNewsletter->get("send_ids"))) . "')", "", "groupname"); while ($oGroup = $oGroups->next()) { $aSendInfo[] = $oGroup->get("groupname"); } unset($oGroup); unset($oGroups); break; case "single": if (is_numeric($oNewsletter->get("send_ids"))) { $oRcp = new Recipient($oNewsletter->get("send_ids")); if ($oRcp->get("name") == "") { $aSendInfo[] = $oRcp->get("email"); } else { $aSendInfo[] = $oRcp->get("name"); } $aSendInfo[] = $oRcp->get("email"); unset($oRcp); } break; default: } $oItem->set("send_to", serialize($aSendInfo), false); $oItem->set("created", date("Y-m-d H:i:s"), false); $oItem->set("author", $auth->auth["uid"]); $oItem->set("authorname", $auth->auth["uname"]); unset($oNewsletter); // Not needed anymore // Adds log items for all recipients and returns recipient count $oLogs = new cNewsletterLogCollection(); $iRecipientCount = $oLogs->initializeJob($oItem->get($oItem->primaryKey), $iIDNews); unset($oLogs); $oItem->set("rcpcount", $iRecipientCount); $oItem->set("sendcount", 0); $oItem->set("status", 1); // Waiting for sending; note, that status will be set to 9, if $iRecipientCount = 0 in store() method $oItem->store(); return $oItem; } else { return false; } }
/** * 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; }
/** * Creates a new association * @param $idrecipientgroup int specifies the newsletter group * @param $idrecipient int specifies the newsletter user */ public function create($idrecipientgroup, $idrecipient) { $idrecipientgroup = Contenido_Security::toInteger($idrecipientgroup); $idrecipient = Contenido_Security::toInteger($idrecipient); $this->setWhere("idnewsgroup", $idrecipientgroup); $this->setWhere("idnewsrcp", $idrecipient); $this->query(); if ($this->next()) { return false; } $oItem = parent::create(); $oItem->set("idnewsrcp", $idrecipient); $oItem->set("idnewsgroup", $idrecipientgroup); $oItem->store(); return $oItem; }
function create($idworkflow, $idcatlang) { $this->select("idcatlang = '{$idcatlang}'"); if ($this->next() !== false) { $this->lasterror = i18n("Category already has a workflow assigned", "workflow"); return false; } $workflows = new Workflows(); $workflows->select("idworkflow = '{$idworkflow}'"); if ($workflows->next() === false) { $this->lasterror = i18n("Workflow doesn't exist", "workflow"); return false; } $newitem = parent::create(); if (!$newitem->setWorkflow($idworkflow)) { $this->lasterror = $newitem->lasterror; $workflows->delete($newitem->getField("idallocation")); return false; } if (!$newitem->setCatLang($idcatlang)) { $this->lasterror = $newitem->lasterror; $workflows->delete($newitem->getField("idallocation")); return false; } $newitem->store(); return $newitem; }
function create($idworkflow) { $workflows = new Workflows(); $workflows->select("idworkflow = '{$idworkflow}'"); if ($workflows->next() === false) { $this->lasterror = i18n("Can't add item to workflow: Workflow doesn't exist", "workflow"); return false; } $this->select("idworkflow = '{$idworkflow}'", "", "position DESC", "1"); $item = $this->next(); if ($item === false) { $lastPos = 1; } else { $lastPos = $item->getField("position") + 1; } $newItem = parent::create(); if ($newItem->init($idworkflow, $lastPos) === false) { $this->delete($newItem->getField("idworkflowitem")); $this->lasterror = $newItem->lasterror; return false; } if ($item === false) { $this->updateArtAllocation(0); } return $newItem; }