public function spamUsers($theme, $tid) { $user = new Model_User(); $helpers = new Helpers_Helpers(); $mailClass = new Model_Mail(); $data1 = array(); $data = array(); $i = 0; $flag = TRUE; $sql = "SELECT tr.uid AS `uid`, users.email, users.notify, tr.gid AS `gid`, tr.all AS `all`\r\n FROM troubles_responsible AS tr\r\n LEFT JOIN users ON (users.id = tr.uid)\r\n WHERE tr.tid = :tid"; $res = $this->registry['db']->prepare($sql); $param = array("tid" => $tid); $res->execute($param); $resp = $res->fetchAll(PDO::FETCH_ASSOC); if (count($resp) > 0) { foreach ($resp as $part) { if ($part["all"]) { $flag = FALSE; $rusers = array(); $allusers = $user->getUsersList(); foreach ($allusers as $uid) { $data1[$i]["uid"] = $uid["id"]; $data1[$i]["email"] = $uid["email"]; $data1[$i]["notify"] = $uid["notify"]; $i++; } } if ($part["gid"] != 0 and $flag) { $gusers = $user->getUserInfoFromGroup($part["gid"]); foreach ($gusers as $uid) { $data1[$i]["uid"] = $uid["uid"]; $data1[$i]["email"] = $uid["email"]; $data1[$i]["notify"] = $uid["notify"]; $i++; } } if ($part["uid"] != 0 and $flag) { $data1[$i]["uid"] = $part["uid"]; $data1[$i]["email"] = $part["email"]; $data1[$i]["notify"] = $part["notify"]; $i++; } } } $sql = "SELECT DISTINCT(ts.uid) AS uid, users.email, ts.id AS `spam`\r\n FROM troubles_spam AS ts\r\n LEFT JOIN users ON (users.id = ts.uid)\r\n WHERE ts.tid = :tid\r\n ORDER BY ts.uid DESC"; $res = $this->registry['db']->prepare($sql); $param = array("tid" => $tid); $res->execute($param); $data2 = $res->fetchAll(PDO::FETCH_ASSOC); $data = array_merge($data1, $data2); $i = 0; $users = array(); foreach ($data as $part) { $flag = true; for ($k = 0; $k < count($users); $k++) { if ($users[$k]["uid"] == $part["uid"]) { $flag = false; } } if ($flag) { if (isset($part["notify"]) and $part["notify"] or isset($part["spam"])) { $users[$i]["uid"] = $part["uid"]; $users[$i]["email"] = $part["email"]; } $i++; } } $task = $this->getTask($tid); if ($task[0]["mail_id"] != 0) { $task[0]["text"] = $mailClass->getMailText($task[0]["mail_id"]); } $comments = $this->getComments($tid); foreach ($users as $part) { $helpers->sendMail($part["email"], $theme, $task, $comments); } }
public function addComment($tid, $text, $status, $attaches = false, $mid = false) { $helpers = new Helpers_Helpers(); if (is_numeric($mid)) { $sql = "INSERT INTO troubles_discussion (tid, uid, mail_id, text, status) VALUES (:tid, :uid, :mail_id, :text, :status)"; $res = $this->registry['db']->prepare($sql); $res->execute(array(":tid" => $tid, ":uid" => $this->uid, ":mail_id" => $mid, ":text" => "", ":status" => $status)); } else { $sql = "INSERT INTO troubles_discussion (tid, uid, text, status) VALUES (:tid, :uid, :text, :status)"; $res = $this->registry['db']->prepare($sql); $res->execute(array(":tid" => $tid, ":uid" => $this->uid, ":text" => $text, ":status" => $status)); } $tdid = $this->registry['db']->lastInsertId(); if (isset($attaches["attaches"])) { foreach ($attaches["attaches"] as $part) { $md5 = $this->getMD5($part); $sql = "INSERT INTO troubles_discussion_attach (`tdid`, `md5`) VALUES (:tdid, :md5)"; $res = $this->registry['db']->prepare($sql); $param = array(":tdid" => $tdid, ":md5" => $md5); $res->execute($param); } } // email move task $post = $this->getTask($tid); if ($post[0]["remote_id"] != 0) { $subject = array(); $body = array(); $user = $this->registry["tt_user"]->getRemoteUserInfo($post[0]["who"]); $subject["method"] = "comment"; $subject["name"] = "OTMS"; $subject["tid"] = $post[0]["remote_id"]; $subject["rc"] = true; $body["uemail"] = $this->registry["ui"]["email"]; $body["uname"] = $this->registry["ui"]["name"]; $body["usoname"] = $this->registry["ui"]["soname"]; $body["ugname"] = $this->registry["ui"]["gname"]; $body["uavatar"] = base64_encode(file_get_contents($this->registry["ui"]["avatarpath"])); $body["attaches"] = $attaches["attaches"]; $body["text"] = $text; $body["status"] = $status; $helpers->sendTask($user["email"], $subject, $body); } else { $data["rall"] = 0; $data["gruser"] = array(); $data["ruser"] = array(); foreach ($post as $part) { if ($part["all"] == 1) { $data["rall"] = 1; } if ($part["rgid"] != 0) { $data["gruser"][] = $part["rgid"]; } if ($part["uid"] != 0) { $data["ruser"][] = $part["uid"]; } } $users = $this->registry["user"]->getUniqUsers($data); foreach ($users as $part) { $subject = array(); $body = array(); $user = $this->registry["user"]->getUserInfo($part); if ($user["email_for_task"]) { if (is_numeric($mid)) { $mailClass = new Model_Mail(); $text = $mailClass->getMailText($mid); $mail = $mailClass->getMailFromId($mid); foreach ($mail[0]["attach"] as $part) { $attaches["attaches"][] = $this->registry["rootPublic"] . "system/settings/../../" . $part["filename"]; } $body["mail"] = true; $body["mail_id"] = $mid; } else { $body["mail"] = false; } $subject["method"] = "comment"; $subject["name"] = "OTMS"; $subject["tid"] = $tid; $subject["rc"] = false; $body["uemail"] = $this->registry["ui"]["email"]; $body["uname"] = $this->registry["ui"]["name"]; $body["usoname"] = $this->registry["ui"]["soname"]; $body["ugname"] = $this->registry["ui"]["gname"]; $body["uavatar"] = base64_encode(file_get_contents($this->registry["ui"]["avatarpath"])); $body["attaches"] = $attaches["attaches"]; $body["text"] = $text; $body["status"] = $status; $helpers->sendTask($user["email"], $subject, $body); } } } // END email move task $string = "Новый комментарий к задаче <a href='" . $this->registry["uri"] . "tt/" . $tid . "/'>" . $tid . "</a>"; if ($status != 0) { $status_text = $this->getCommentStatusText($status); $tinfo["Статус"] = "<span style='padding: 2px 4px' class='info'>" . $status_text . "</span>"; } if ($mid) { $tinfo["Текст"] = '<iframe class="mailtext" src="' . $this->registry["siteName"] . $this->registry["uri"] . 'mail/load/?mid=' . $mid . '&part=1" frameborder="0" width="100%" height="90%"></iframe>'; } else { $tinfo["Текст"] = $text; } $this->registry["logs"]->uid = $this->uid; $this->registry["logs"]->set("com", $string, $tid, $tinfo); }
function getMailText($params) { $mailClass = new Model_Mail(); return $mailClass->getMailText($params[0]); }