function gf_chknotifications($forumid, $topicid, $userid, $type = 'topic', $notifyall = 0) { global $_TABLES, $LANG_GF01, $LANG_GF02, $_CONF, $CONF_FORUM, $_USER; if ($CONF_FORUM['allow_notification'] != '1') { return; } $pid = DB_getItem($_TABLES['gf_topic'], pid, "id='{$topicid}'"); if ($pid == 0) { $pid = $topicid; } if ($notifyall == 1) { // Get the groupid for this forum and retrieve all the users that have view access for notification $grp_id = DB_getItem($_TABLES['gf_forums'], 'grp_id', "forum_id={$forumid}"); require_once $_CONF['path_system'] . 'lib-user.php'; $groups = USER_getChildGroups($grp_id); $groupList = implode(',', $groups); $sql = "SELECT DISTINCT {$_TABLES['users']}.uid " . "FROM {$_TABLES['group_assignments']},{$_TABLES['users']} {$join_userinfo} " . "WHERE {$_TABLES['users']}.uid > 1 " . "AND {$_TABLES['users']}.uid = {$_TABLES['group_assignments']}.ug_uid " . "AND ({$_TABLES['group_assignments']}.ug_main_grp_id IN ({$groupList}))"; $sqlresult = DB_query($sql); } else { $sql = "SELECT * FROM {$_TABLES['gf_watch']} WHERE ((topic_id='{$pid}') OR ((forum_id='{$forumid}') AND (topic_id='0') )) GROUP BY uid"; $sqlresult = DB_query($sql); } $postername = COM_getDisplayName($userid); $nrows = DB_numRows($sqlresult); $topicrecsql = DB_query("SELECT subject,name,forum FROM {$_TABLES['gf_topic']} WHERE id='{$pid}'"); $topicrec = DB_fetchArray($topicrecsql); $from = ''; // Default to being from the site /* Option only used in internal sites where email addresses can be shown * Needs option in the submissionform_main.thtml as well */ $_POST['chk_notifypersonal'] = 0; // BL Set to disable feature - remove if being used if ($_POST['chk_notifypersonal'] == 1) { $query = DB_query("SELECT username,fullname,email FROM {$_TABLES['users']} WHERE uid={$_USER['uid']}"); list($username, $fullname, $email) = DB_fetchArray($query); if ($fullname != '') { $from = "{$fullname} <{$email}>"; } else { $from = "{$usernmae} <{$email}>"; } } $notifyusers = array(); $email_allusers = ''; // Loop through all the user records to notify for ($i = 1; $i <= $nrows; $i++) { $N = DB_fetchArray($sqlresult); // Don't need to send a notification to the user that posted this message and users with NOTIFY disabled if ($N['uid'] > 1 and $N['uid'] != $userid) { // Check and see that user has NOT set their user preference to disable all notifications - regardless of subscription (watch) records. if (DB_count($_TABLES['gf_userprefs'], array('uid', 'enablenotify'), array($N['uid'], 0)) == 0) { // if the topic_id is 0 for this record - user has subscribed to complete forum. Check if they have opted out of this forum topic. if (DB_count($_TABLES['gf_watch'], array('uid', 'forum_id', 'topic_id'), array($N['uid'], $forumid, -$topicid)) == 0) { // Check if user does not want to receive multiple notifications for same topic and already has been notified $userNotifyOnceOption = DB_getItem($_TABLES['gf_userprefs'], 'notify_once', "uid='{$N['uid']}'"); // Retrieve the log record for this user if it exists then check if user has viewed this topic yet // The logtime value may be 0 which indicates the user has not yet viewed the topic $lsql = DB_query("SELECT time FROM {$_TABLES['gf_log']} WHERE uid='{$N['uid']}' AND forum='{$forumid}' AND topic='{$topicid}'"); if (DB_numRows($lsql) == 1) { $nologRecord = false; list($logtime) = DB_fetchArray($lsql); } else { $nologRecord = true; $logtime = 0; } // Add user if notify always OR notify once and has not been notified if ($userNotifyOnceOption == 0 or $userNotifyOnceOption == 1 and ($nologRecord or $logtime != 0)) { $sql = "SELECT email,status FROM {$_TABLES['users']} WHERE uid={$N['uid']}"; $userrec = DB_fetchArray(DB_query($sql), false); if ($userrec['status'] == USER_ACCOUNT_ACTIVE) { $notifyusers[$N['uid']] = $userrec['email']; if ($allusers != '') { $allusers .= ','; } $allusers .= $userrec['email']; } } /* Add log record to indicate user has viewed topic (albeit not true) but the re-using this table for this purpose * to track so that users get notified only once as per request. It's assumed that if they get the basic notification * full post content or the full post content in the email notification they have read it * @TODO: add a new table for tracking this so users with this option can still see un-read posts */ if ($nologRecord and $userNotifyOnceOption == 1) { DB_query("INSERT INTO {$_TABLES['gf_log']} (uid,forum,topic,time) VALUES ({$touid}, '{$forumid}', '{$topicid}','0') "); } } } } } // Manually now add the user who is posting so they are on the email notification if (isset($_USER['uid']) and $_USER['uid'] > 1) { $myemail = DB_getItem($_TABLES['users'], 'email', "uid={$_USER['uid']}"); if ($allusers != '') { $allusers .= ','; } $allusers .= $myemail; } if (count($notifyusers) > 0) { // Plugin API function that can be customized if site requires forumPLG_sendNotification($forumid, $topicid, $userid, $type, $notifyusers, $allusers); } }
/** * This function actually sends the messages to the specified group * * @param array $vars Same as $_POST, holds all the email info * @return string HTML with success or error message * */ function send_messages($vars) { global $_CONF, $_TABLES, $LANG31; require_once $_CONF['path_system'] . 'lib-user.php'; $retval = ''; if (empty($vars['fra']) or empty($vars['fraepost']) or empty($vars['subject']) or empty($vars['message']) or empty($vars['to_group']) or strpos($vars['fra'], '@') !== false) { $retval .= COM_showMessageText($LANG31[26]); return $retval; } $to_group = COM_applyFilter($vars['to_group'], true); if ($to_group > 0) { $group_name = DB_getItem($_TABLES['groups'], 'grp_name', "grp_id = {$to_group}"); if (!SEC_inGroup($group_name)) { return COM_refresh($_CONF['site_admin_url'] . '/mail.php'); } } else { return COM_refresh($_CONF['site_admin_url'] . '/mail.php'); } // Urgent message! if (isset($vars['priority'])) { $priority = 1; } else { $priority = 0; } // If you want to send html mail if (isset($vars['html'])) { $html = true; } else { $html = false; } $groupList = implode(',', USER_getChildGroups($to_group)); // and now mail it if (isset($vars['overstyr'])) { $sql = "SELECT DISTINCT username,fullname,email FROM {$_TABLES['users']},{$_TABLES['group_assignments']} WHERE uid > 1"; $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email IS NOT NULL) and (email != ''))"; $sql .= " AND {$_TABLES['users']}.uid = ug_uid AND ug_main_grp_id IN ({$groupList})"; } else { $sql = "SELECT DISTINCT username,fullname,email,emailfromadmin FROM {$_TABLES['users']},{$_TABLES['userprefs']},{$_TABLES['group_assignments']} WHERE {$_TABLES['users']}.uid > 1"; $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email IS NOT NULL) and (email != ''))"; $sql .= " AND {$_TABLES['users']}.uid = {$_TABLES['userprefs']}.uid AND emailfromadmin = 1"; $sql .= " AND ug_uid = {$_TABLES['users']}.uid AND ug_main_grp_id IN ({$groupList})"; } $result = DB_query($sql); $nrows = DB_numRows($result); $from = COM_formatEmailAddress($vars['fra'], $vars['fraepost']); $subject = COM_stripslashes($vars['subject']); $message = COM_stripslashes($vars['message']); // Loop through and send the messages! $successes = array(); $failures = array(); for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); if (empty($A['fullname'])) { $to = COM_formatEmailAddress($A['username'], $A['email']); } else { $to = COM_formatEmailAddress($A['fullname'], $A['email']); } if (!COM_mail($to, $subject, $message, $from, $html, $priority)) { $failures[] = htmlspecialchars($to); } else { $successes[] = htmlspecialchars($to); } } $retval .= COM_startBlock($LANG31[1]); $failcount = count($failures); $successcount = count($successes); $mailresult = str_replace('<successcount>', $successcount, $LANG31[20]); $retval .= str_replace('<failcount>', $failcount, $mailresult); $retval .= '<h2>' . $LANG31[21] . '</h2>'; for ($i = 0; $i < count($failures); $i++) { $retval .= current($failures) . '<br' . XHTML . '>'; next($failures); } if (count($failures) == 0) { $retval .= $LANG31[23]; } $retval .= '<h2>' . $LANG31[22] . '</h2>'; for ($i = 0; $i < count($successes); $i++) { $retval .= current($successes) . '<br' . XHTML . '>'; next($successes); } if (count($successes) == 0) { $retval .= $LANG31[24]; } $retval .= COM_endBlock(); return $retval; }
function fncsendmail($mode = "", $uidfrom = "", $uidto = "", $wkymlmguserflg = "") { global $_CONF; global $_TABLES; global $LANG_ASSIST_ADMIN; require_once $_CONF['path_system'] . 'lib-user.php'; //$html = true ; // If you want to send html mail $html = false; // If you want to send html mail /// Loop through and send the messages! //log 出力モード設定 0:作成しない,1:ファイルに出力 $logmode = 1; //$logfile = $_CONF['path_log'] . 'wkymlmguser.log'; $logfile = $_CONF['path_log'] . 'assist_newsletter.log'; $retval = ''; $fromname = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_fromname'"); $fromname = COM_stripslashes($fromname); $replyto = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_replyto'"); $replyto = COM_stripslashes($replyto); $sprefix = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_sprefix'"); $sprefix = COM_stripslashes($sprefix); $sid = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_sid'"); $sid = COM_stripslashes($sid); $testto = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_testto'"); $testto = COM_stripslashes($testto); $uidfrom = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_uidfrom'"); $uidfrom = COM_stripslashes($uidfrom); $uidto = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_uidto'"); $uidto = COM_stripslashes($uidto); //送信先環境 $toenv = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_toenv'"); $toenv = COM_stripslashes($toenv); //送信先グループ $selectgroup = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_selectgroup'"); $selectgroup = COM_stripslashes($selectgroup); // 冒頭文 本文 introbody $introbody = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_introbody'"); $introbody = COM_stripslashes($introbody); // ユーザの受信許可設定を無視して送る $overstyr = DB_getItem($_TABLES['vars'], 'value', "name = 'assist_overstyr'"); $overstyr = COM_stripslashes($overstyr); $from = COM_formatEmailAddress($fromname, $replyto); $subject = DB_getItem($_TABLES['stories'], "title", "sid='{$sid}'"); $subject = $sprefix . $subject; if ($introbody == "1") { $message = DB_getItem($_TABLES['stories'], "bodytext", "sid='{$sid}'"); } else { $message = DB_getItem($_TABLES['stories'], "introtext", "sid='{$sid}'"); } $message = str_replace('<br' . XHTML . '>', LB, $message); $message = strip_tags($message); $failures = array(); $successes = array(); if ($mode == "test") { $message = $LANG_ASSIST_ADMIN['mail_test_message'] . LB . $message; $to = $testto; if (!COM_mail($to, $subject, $message, $from, $html, $priority)) { $failures[] = htmlspecialchars($to); $logentry = $LANG_ASSIST_ADMIN['mail_test_ng'] . $to; $dummy = LIB_OutLog($logentry, $logfile, $logmode); } else { $successes[] = htmlspecialchars($to); $logentry = $LANG_ASSIST_ADMIN['mail_test_ok'] . $to; $dummy = LIB_OutLog($logentry, $logfile, $logmode); } $retval = $logentry; } else { $sql = "SELECT DISTINCT t1.uid ,t1.email FROM "; //メルマガユーザか選択されたグループの登録ユーザか if ($selectgroup === "99999") { if ($wkymlmguserflg) { $sql .= $_TABLES['wkymlmguser'] . " AS t1 " . LB; $sql .= " where " . LB; if ($uidfrom != "0") { $sql .= " (t1.uid between " . $uidfrom . " and " . $uidto . ")" . LB; } } else { $err = "メルマガプラグインが有効ではありません"; return $err; } } else { $groupList = implode(',', USER_getChildGroups($selectgroup)); $sql .= "{$_TABLES['users']} AS t1 " . LB; $sql .= ",{$_TABLES['userprefs']} AS t2 " . LB; $sql .= ",{$_TABLES['group_assignments']} AS t3 " . LB; $sql .= " where " . LB; $sql .= " (t1.uid = t2.uid ) " . LB; $sql .= " AND (t1.uid >1) " . LB; $sql .= " AND (t1.status =3) " . LB; // ユーザの受信許可設定を無視して送る でなければ if ($overstyr != "1") { $sql .= " AND (t2.emailfromadmin =1) " . LB; } //指定グループ $sql .= " AND (t1.uid = t3.ug_uid) AND t3.ug_main_grp_id IN ({$groupList})" . LB; if ($uidfrom != "0") { $sql .= " AND (t1.uid between " . $uidfrom . " and " . $uidto . ")" . LB; } } //--- $sql .= " order by uid " . LB; $result = DB_query($sql); if ($result !== false) { $result = DB_query($sql); $nrows = DB_numRows($result); for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); //送付先環境のチェック if ($toenv == '1') { // PCのみ if (LIB_mail_is_mobile($A['email'])) { continue; } } elseif ($toenv == '2') { // 携帯のみ if (!LIB_mail_is_mobile($A['email'])) { continue; } } // $to = $A['email']; if (!COM_mail($to, $subject, $message, $from, $html, $priority)) { $failures[] = htmlspecialchars($to); $logentry = "NG uid:{$A['uid']} mail:{$A['email']}"; $dummy = LIB_OutLog($logentry, $logfile, $logmode); } else { $successes[] = htmlspecialchars($to); $logentry = "OK uid:{$A['uid']} mail:{$A['email']}"; $dummy = LIB_OutLog($logentry, $logfile, $logmode); } } } $failcount = count($failures); $successcount = count($successes); $retval .= $LANG_ASSIST_ADMIN['mail_send_success'] . "=" . $successcount . $LANG_ASSIST_ADMIN['mail_send_failure'] . "=" . $failcount . "<br>"; } return $retval; }
/** * This function actually sends the messages to the specified group * * @param array $vars Same as $_POST, holds all the email info * @return string HTML with success or error message * */ function MAIL_sendMessages($vars) { global $_CONF, $_TABLES, $LANG31; USES_lib_user(); $retval = ''; $html = 0; $message = $vars['message']; if ($vars['postmode'] == 'html') { $html = true; } $usermode = (int) $vars['to_uid'] > 0 && (int) $vars['to_group'] == 0 ? true : false; if (empty($vars['fra']) or empty($vars['fraepost']) or empty($vars['subject']) or empty($message) or empty($vars['to_group']) && empty($vars['to_uid'])) { $retval .= COM_showMessageText($LANG31[26], $LANG31[1], true); $msg = htmlspecialchars($vars['message'], ENT_COMPAT, COM_getEncodingt()); $subject = htmlspecialchars($vars['subject'], ENT_COMPAT, COM_getEncodingt()); $fra = htmlspecialchars($vars['fra'], ENT_COMPAT, COM_getEncodingt()); $fraepost = htmlspecialchars($vars['fraepost'], ENT_COMPAT, COM_getEncodingt()); $retval .= MAIL_displayForm($vars['to_uid'], $vars['to_group'], $fra, $fraepost, $subject, $msg); return $retval; } // Urgent message! if (isset($vars['priority'])) { $priority = 1; } else { $priority = 0; } $toUsers = array(); if ($usermode) { $result = DB_query("SELECT email,username FROM {$_TABLES['users']} WHERE uid=" . (int) COM_applyFilter($vars['to_uid'], true)); if (DB_numRows($result) > 0) { list($email, $username) = DB_fetchArray($result); $toUsers[] = COM_formatEmailAddress($username, $email); } } else { $groupList = implode(',', USER_getChildGroups((int) COM_applyFilter($vars['to_group'], true))); // and now mail it if (isset($vars['overstyr'])) { $sql = "SELECT DISTINCT username,fullname,email FROM {$_TABLES['users']},{$_TABLES['group_assignments']} WHERE uid > 1"; $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))"; $sql .= " AND {$_TABLES['users']}.uid = ug_uid AND ug_main_grp_id IN ({$groupList})"; } else { $sql = "SELECT DISTINCT username,fullname,email,emailfromadmin FROM {$_TABLES['users']},{$_TABLES['userprefs']},{$_TABLES['group_assignments']} WHERE {$_TABLES['users']}.uid > 1"; $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))"; $sql .= " AND {$_TABLES['users']}.uid = {$_TABLES['userprefs']}.uid AND emailfromadmin = 1"; $sql .= " AND ug_uid = {$_TABLES['users']}.uid AND ug_main_grp_id IN ({$groupList})"; } $result = DB_query($sql); $nrows = DB_numRows($result); for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); if (empty($A['fullname'])) { $toUsers[] = COM_formatEmailAddress($A['username'], $A['email']); } else { $toUsers[] = COM_formatEmailAddress($A['fullname'], $A['email']); } } } $from = array(); $from = COM_formatEmailAddress($vars['fra'], $vars['fraepost']); $subject = $vars['subject']; // Loop through and send the messages! $successes = array(); $failures = array(); foreach ($toUsers as $to) { if (defined('DEMO_MODE')) { $successes[] = htmlspecialchars($to[0]); } else { if (!COM_mail($to, $subject, $message, $from, $html, $priority)) { $failures[] = htmlspecialchars($to[0]); } else { $successes[] = htmlspecialchars($to[0]); } } } $retval .= COM_startBlock($LANG31[1]); $failcount = count($failures); $successcount = count($successes); $mailresult = str_replace('<successcount>', $successcount, $LANG31[20]); $retval .= str_replace('<failcount>', $failcount, $mailresult); $retval .= '<h2>' . $LANG31[21] . '</h2>'; for ($i = 0; $i < count($failures); $i++) { $retval .= current($failures) . '<br/>'; next($failures); } if (count($failures) == 0) { $retval .= $LANG31[23]; } $retval .= '<h2>' . $LANG31[22] . '</h2>'; for ($i = 0; $i < count($successes); $i++) { $retval .= current($successes) . '<br/>'; next($successes); } if (count($successes) == 0) { $retval .= $LANG31[24]; } $retval .= COM_endBlock(); return $retval; }
function gf_chknotifications($forumid, $topicid, $userid, $type = 'topic', $notifyall = 0) { global $_TABLES, $LANG_GF01, $LANG_GF02, $_CONF, $CONF_FORUM, $_USER; if ($CONF_FORUM['allow_notification'] != '1') { return; } $pid = DB_getItem($_TABLES['gf_topic'], pid, "id='{$topicid}'"); if ($pid == 0) { $pid = $topicid; } if ($notifyall == 1) { // Get the groupid for this forum and retrieve all the users that have view access for notification $grp_id = DB_getItem($_TABLES['gf_forums'], 'grp_id', "forum_id={$forumid}"); require_once $_CONF['path_system'] . 'lib-user.php'; $groups = USER_getChildGroups($grp_id); $groupList = implode(',', $groups); $sql = "SELECT DISTINCT {$_TABLES['users']}.uid " . "FROM {$_TABLES['group_assignments']},{$_TABLES['users']} {$join_userinfo} " . "WHERE {$_TABLES['users']}.uid > 1 " . "AND {$_TABLES['users']}.uid = {$_TABLES['group_assignments']}.ug_uid " . "AND ({$_TABLES['group_assignments']}.ug_main_grp_id IN ({$groupList}))"; $sqlresult = DB_query($sql); } else { $sql = "SELECT * FROM {$_TABLES['gf_watch']} WHERE ((topic_id='{$pid}') OR ((forum_id='{$forumid}') AND (topic_id='0') )) GROUP BY uid"; $sqlresult = DB_query($sql); } $postername = COM_getDisplayName($userid); $nrows = DB_numRows($sqlresult); $topicrecsql = DB_query("SELECT subject,name,forum FROM {$_TABLES['gf_topic']} WHERE id='{$pid}'"); $topicrec = DB_fetchArray($topicrecsql); $from = ''; // Default to being from the site /* Option only used in internal sites where email addresses can be shown * Needs option in the submissionform_main.thtml as well */ $_POST['chk_notifypersonal'] = 0; // BL Set to disable feature - remove if being used if ($_POST['chk_notifypersonal'] == 1) { $query = DB_query("SELECT username,fullname,email FROM {$_TABLES['users']} WHERE uid={$_USER['uid']}"); list($username, $fullname, $email) = DB_fetchArray($query); if ($fullname != '') { $from = "{$fullname} <{$email}>"; } else { $from = "{$usernmae} <{$email}>"; } } $notifyusers = array(); $email_allusers = ''; // Loop through all the user records to notify for ($i = 1; $i <= $nrows; $i++) { $N = DB_fetchArray($sqlresult); // Don't need to send a notification to the user that posted this message and users with NOTIFY disabled if ($N['uid'] > 1 and $N['uid'] != $userid) { // if the topic_id is 0 for this record - user has subscribed to complete forum. Check if they have opted out of this forum topic. if (DB_count($_TABLES['gf_watch'], array('uid', 'forum_id', 'topic_id'), array($N['uid'], $forumid, -$topicid)) == 0) { // Check if user does not want to receive multiple notifications for same topic and already has been notified $userNotifyOnceOption = DB_getItem($_TABLES['gf_userprefs'], 'notify_once', "uid='{$N['uid']}'"); // Retrieve the log record for this user if it exists then check if user has viewed this topic yet // The logtime value may be 0 which indicates the user has not yet viewed the topic $lsql = DB_query("SELECT time FROM {$_TABLES['gf_log']} WHERE uid='{$N['uid']}' AND forum='{$forumid}' AND topic='{$topicid}'"); if (DB_numRows($lsql) == 1) { $nologRecord = false; list($logtime) = DB_fetchArray($lsql); } else { $nologRecord = true; $logtime = 0; } if ($userNotifyOnceOption == 0 or $userNotifyOnceOption == 1 and ($nologRecord or $logtime != 0)) { $sql = "SELECT username,fullname,email,status FROM {$_TABLES['users']} WHERE uid={$N['uid']}"; $userrec = DB_fetchArray(DB_query($sql), false); $notifyusers[$N['uid']] = $userrec; if ($email_allusers != '') { $email_allusers .= ','; } $email_allusers .= $userrec['email']; } } } } // Manually now add the user who is posting so they are on the email notification $myemail = DB_getItem($_TABLES['users'], 'email', "uid={$_USER['uid']}"); if ($email_allusers != '') { $email_allusers .= ','; } $email_allusers .= $myemail; $notifyextracontent = ''; if ($_POST['notificationtype'] == 'full') { $notifyextracontent = $LANG_GF02['notify_premsg']; $notifyextracontent .= $_POST['comment']; $notifyextracontent .= $LANG_GF02['notify_postmsg']; } elseif ($_POST['notificationtype'] == 'summary') { $notifyextracontent = $LANG_GF02['notify_premsg']; $notifyextracontent .= substr($_POST['comment'], 0, 200); $notifyextracontent .= $LANG_GF02['notify_postmsg']; } elseif ($_POST['notificationtype'] == 'custom') { $notifyextracontent = $LANG_GF02['notify_premsg']; $notifyextracontent .= $_POST['customnotification']; $notifyextracontent .= $LANG_GF02['notify_postmsg']; } if (count($notifyusers) > 0) { $subjectline = "{$_CONF['site_name']} {$LANG_GF02['msg22']}"; if ($_POST['chk_notifypersonal'] == 1) { $toemail = $email_allusers; $message = "{$LANG_GF01['HELLOMEMBER']},\n\n"; if ($type == 'forum') { $forum_name = DB_getItem($_TABLES['gf_forums'], forum_name, "forum_id='{$forumid}'"); $message .= sprintf($LANG_GF02['notify_newtopic'], $topicrec['subject'], $topicrec['name'], $forum_name, $_CONF['site_name'], $_CONF['site_url'], $pid); } else { $message .= sprintf($LANG_GF02['notify_newreply'], $topicrec['subject'], $postername, $topicrec['name'], $_CONF['site_name'], $_CONF['site_url'], $pid); } $message .= $LANG_GF02['replynote']; $message .= $notifyextracontent; $message .= sprintf($LANG_GF02['notify_reason'], "{$_CONF['site_url']}/forum/notify.php", $_CONF['site_name'], $LANG_GF01['ADMIN']); if ($nologRecord and $userNotifyOnceOption == 1) { DB_query("INSERT INTO {$_TABLES['gf_log']} (uid,forum,topic,time) VALUES ({$touid}, '{$forumid}', '{$topicid}','0') "); } COM_errorLog("COM_mail({$toemail},{$subjectline},{$message}"); COM_mail($toemail, $subjectline, $message, $from); } else { reset($notifyusers); foreach ($notifyusers as $touid => $B) { if ($B['status'] == USER_ACCOUNT_ACTIVE) { if ($fullname != '') { $nameparts = explode(' ', $B['fullname']); $toname = ucfirst($nameparts[0]); } else { $toname = $B['username']; } $message = "{$LANG_GF01['HELLO']} {$toname},\n\n"; if ($type == 'forum') { $forum_name = DB_getItem($_TABLES['gf_forums'], forum_name, "forum_id='{$forumid}'"); $message .= sprintf($LANG_GF02['notify_newtopic'], $topicrec['subject'], $topicrec['name'], $forum_name, $_CONF['site_name'], $_CONF['site_url'], $pid); } else { $message .= sprintf($LANG_GF02['notify_newreply'], $topicrec['subject'], $postername, $topicrec['name'], $_CONF['site_name'], $_CONF['site_url'], $pid); } $message .= $notifyextracontent; $message .= sprintf($LANG_GF02['notify_reason'], "{$_CONF['site_url']}/forum/notify.php", $_CONF['site_name'], $LANG_GF01['ADMIN']); if ($nologRecord and $userNotifyOnceOption == 1) { DB_query("INSERT INTO {$_TABLES['gf_log']} (uid,forum,topic,time) VALUES ({$touid}, '{$forumid}', '{$topicid}','0') "); } COM_errorLog("COM_mail({$B['email']},{$subjectline},{$message}"); COM_mail($B['email'], $subjectline, $message); } } } } }
/** * This function record in the hello queue the message to send to the specified group or to csv list * * @param array $vars Same as $_POST, holds all the email info * @return string HTML with success or error message * */ function send_messages($vars) { global $_CONF, $_TABLES, $LANG31, $LANG_HELLO01; require_once $_CONF['path_system'] . 'lib-user.php'; $retval = ''; if (empty($vars['fra']) or empty($vars['fraepost']) or empty($vars['subject']) or empty($vars['content'])) { $retval .= COM_startBlock($LANG31[1], '', COM_getBlockTemplate('_msg_block', 'header')); $retval .= $LANG31[26]; $retval .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer')); $retval .= $display .= display_mailform($vars); return $retval; } // Urgent message! if (isset($vars['priority'])) { $priority = 1; } else { $priority = 0; } if (!empty($vars['to_group'])) { $groupList = implode(',', USER_getChildGroups($vars['to_group'])); //Group name $group_name = DB_query("SELECT grp_name FROM {$_TABLES['groups']} WHERE grp_id =" . $vars['to_group'] . " "); $group_name = DB_fetchArray($group_name); $email_group = $group_name[0]; if (isset($vars['overstyr'])) { $sql = "SELECT DISTINCT username,fullname,email FROM {$_TABLES['users']},{$_TABLES['group_assignments']} WHERE uid > 1"; $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))"; $sql .= " AND {$_TABLES['users']}.uid = ug_uid AND ug_main_grp_id IN ({$groupList})"; } else { $sql = "SELECT DISTINCT username,fullname,email,emailfromadmin FROM {$_TABLES['users']},{$_TABLES['userprefs']},{$_TABLES['group_assignments']} WHERE {$_TABLES['users']}.uid > 1"; $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))"; $sql .= " AND {$_TABLES['users']}.uid = {$_TABLES['userprefs']}.uid AND emailfromadmin = 1"; $sql .= " AND ug_uid = {$_TABLES['users']}.uid AND ug_main_grp_id IN ({$groupList})"; } $result = DB_query($sql); $nrows = DB_numRows($result); $quantity = $nrows; } else { // OK, let's upload csv file require_once $_CONF['path_system'] . 'classes/upload.class.php'; $upload = new upload(); //Debug with story debug function if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) { $upload->setLogFile($_CONF['path'] . 'logs/error.log'); $upload->setDebug(true); } $upload->setMaxFileUploads(1); $upload->setAllowedMimeTypes(array('text/csv' => '.csv', 'text/comma-separated-values' => '.csv', 'application/vnd.ms-excel' => '.csv', 'application/x-csv' => '.csv')); if (!$upload->setPath($_CONF['path_data'])) { $output = COM_siteHeader('menu', $LANG24[30]); $output .= COM_startBlock($LANG24[30], '', COM_getBlockTemplate('_msg_block', 'header')); $output .= $upload->printErrors(false); $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer')); $output .= COM_siteFooter(); echo $output; exit; } // Set file permissions on file after it gets uploaded (number is in octal) $upload->setPerms('0644'); $curfile = current($_FILES); if (!empty($curfile['name'])) { $pos = strrpos($curfile['name'], '.') + 1; $fextension = substr($curfile['name'], $pos); $filename = 'import_hello_' . COM_makesid() . '.' . $fextension; } if ($filename == '') { $output = COM_siteHeader('menu', $LANG24[30]); $output .= COM_startBlock($LANG24[30], '', COM_getBlockTemplate('_msg_block', 'header')); $output .= 'Upload error: csv file name is empty. Please try again...'; $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer')); $output .= COM_siteFooter(); echo $output; exit; } $upload->setFileNames($filename); reset($_FILES); $upload->uploadFiles(); if ($upload->areErrors()) { $msg = $upload->printErrors(false); return $LANG24[30]; } //email group $email_group = $LANG_HELLO01['csv_file']; $destinataires = array(); $separator = $vars['separator']; if (!in_array($separator, array(',', 'tab', ';'))) { $separator = ','; } if ($separator == 'tab') { $separator = "\t"; } if (($handle = fopen($_CONF['path_data'] . $filename, "r")) !== FALSE) { $quantity = 0; while (($data = fgetcsv($handle, 0, $separator)) !== FALSE) { //todo check if email is valid if ($data[0] != '' and COM_isEmail($data[0])) { $quantity++; $destinataires[] = $data[0]; } } fclose($handle); } } $retval .= COM_startBlock($LANG31[1]); // register hello $creation = date('YmdHi', time()); $subject = addslashes($vars['subject']); $content = addslashes($vars['content']); $from = COM_formatEmailAddress($vars['fra'], $vars['fraepost']); $sql_ajout_hello = "INSERT INTO {$_TABLES['hello']} (subject, creation, email_group, quantity, content) VALUES ('{$subject}', '{$creation}', '{$email_group}', '{$quantity}','{$content}')"; DB_query($sql_ajout_hello); $new_hello_id = DB_insertId(); // Loop through and send the messages in the DB! $successes = 0; $failures = 0; if (!empty($vars['to_group'])) { for ($i = 0; $i < $quantity; $i++) { $A = DB_fetchArray($result); $destinataire = $A['email']; $expediteur = $from; $date = date('YmdHi', time()); $sql_ajout_hello = "INSERT INTO {$_TABLES['hello_queue']} (expediteur, destinataire, date, hello_id, subject, content, priority) VALUES ('{$expediteur}', '{$destinataire}', '{$date}', '{$new_hello_id}', '{$subject}', '{$content}', '{$priority}')"; if ($destinataire != '') { if (DB_query($sql_ajout_hello)) { $successes = $successes + 1; } else { $failures = $failures + 1; } } else { $failures = $failures + 1; } } } else { //csv file for ($i = 0; $i < $quantity; $i++) { $destinataire = $destinataires[$i]; $expediteur = $from; $date = date('YmdHi', time()); $sql_ajout_hello = "INSERT INTO {$_TABLES['hello_queue']} (expediteur, destinataire, date, hello_id, subject, content, priority) VALUES ('{$expediteur}', '{$destinataire}', '{$date}', '{$new_hello_id}', '{$subject}', '{$content}', '{$priority}')"; if (DB_query($sql_ajout_hello)) { $successes = $successes + 1; } else { $failures = $failures + 1; } } } if ($successes >= 0) { $retval .= $i . ' ' . $LANG_HELLO01['email_schedule'] . '<br />' . $vars['priority']; } if ($failures > 0) { $retval .= 'Oups... There was ' . $failures . ' failure(s)'; } if (empty($vars['to_group'])) { //list emails from csv reset($destinataires); $retval .= COM_makeList($destinataires); } $retval .= COM_endBlock(); return $retval; }