+ public function getTitle()
+ {
+ return $this->engine->getTitle();
+ }
+
+ public function getText()
+ {
+ return $this->engine->getText($this->user);
+ }
+
+ public function send($title = null, $text = null)
+ {
+ $this->hash = rand_url_id(12);
+ if (!$title) {
+ $title = $this->engine->getTitle();
+ }
+ if (!$text) {
+ $text = $this->engine->getText($this->user);
+ }
+ $sender = substr($this->sender_mail, 1, strpos($this->sender_mail, '"', 2)-1);
+ $text = str_replace(array("%%hash%%", "%%sender%%"),
+ array($this->hash, $this->sender_mail),
+ $text);
+ $mailer = new PlMailer();
+ $mailer->setFrom($this->sender_mail);
+ $mailer->addTo($this->user['mail']);
+ $mailer->setSubject($title);
+ $mailer->setTxtBody($text);
+ $mailer->send();
+ $this->incr();
+ }
+
+ public function add($valid = true)
+ {
+ XDB::execute('INSERT IGNORE INTO register_marketing
+ (uid, sender, email, date, last, nb, type, hash, message, message_data)
+ VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, {?}, {?}, {?})',
+ $this->user['id'], $this->sender, $this->user['mail'], $this->from, $this->hash,
+ $this->type, $this->data);
+ $this->engine->process($this->user);
+ if ($valid) {
+ require_once 'validations.inc.php';
+ $valid = new MarkReq(User::getSilent($this->sender), $this->user['user'], $this->user['mail'],
+ $this->from == 'user', $this->type, $this->data);
+ $valid->submit();
+ }
+ return true;
+ }
+
+ private function incr()
+ {
+ XDB::execute('UPDATE register_marketing
+ SET nb=nb+1, hash={?}, last=NOW()
+ WHERE uid={?} AND email={?}',
+ $this->hash, $this->user['id'], $this->user['mail']);
+ }
+
+ static public function getEngineList($exclude_data = true)
+ {
+ $array = array();
+ foreach (Marketing::$engines as $e => $d) {
+ if (!$d[1] || !$exclude_data) {
+ $array[] = $e;
+ }
+ }
+ return $array;
+ }
+
+ static public function get($uid, $email, $recentOnly = false)
+ {
+ $res = XDB::query("SELECT uid, email, message, message_data, type, sender
+ FROM register_marketing
+ WHERE uid = {?}
+ AND email = {?}".(
+ $recentOnly ? ' AND DATEDIFF(NOW(), last) < 30' : ''), $uid, $email);
+
+ if ($res->numRows() == 0) {
+ return null;
+ }
+ list ($uid, $email, $type, $data, $from, $sender) = $res->fetchOneRow();
+ return new Marketing($uid, $email, $type, $data, $from, $sender);
+ }
+
+ static public function clear($uid, $email = null)
+ {
+ if (!$email) {
+ XDB::execute("DELETE FROM register_marketing WHERE uid = {?}", $uid);
+ } else {
+ XDB::execute("DELETE FROM register_marketing WHERE uid = {?} AND email = {?}", $uid, $email);
+ }
+ }