예제 #1
0
function NotifyDiscussion($DiscussionForm)
{
    $DiscussionID = @$DiscussionForm->DelegateParameters['ResultDiscussion']->DiscussionID;
    if ($DiscussionID > 0) {
        #Detect if Whispered
        $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'");
        $row = mysql_fetch_row($result);
        if ($row[0] > 0) {
            $Whispered = 1;
        } else {
            $Whispered = 0;
        }
        $WhisperUserID = $row[0];
        if (CheckSubscribeOwn($DiscussionForm->Context)) {
            ChangeNotify($DiscussionForm->Context, 'DISCUSSION', $DiscussionID, 1);
        }
    } else {
        $DiscussionID = @$DiscussionForm->DelegateParameters['ResultComment']->DiscussionID;
        #Detect if Whispered
        $mTitle = @$DiscussionForm->DelegateParameters['ResultComment']->Title;
        $CommentID = @$DiscussionForm->DelegateParameters['ResultComment']->CommentID;
        $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'");
        $row = mysql_fetch_row($result);
        if ($row[0] > 0) {
            $Whispered = 1;
        } else {
            $Whispered = 0;
        }
        $WhisperUserID = $row[0];
        if ($Whispered == 0) {
            $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Comment WHERE CommentID = '{$CommentID}'");
            $row = mysql_fetch_row($result);
            if ($row[0] > 0) {
                $Whispered = 1;
            } else {
                $Whispered = 0;
            }
            $WhisperUserID = $row[0];
        }
    }
    if ($DiscussionID > 0) {
        $Notifieusers = array();
        $SelfUser = $DiscussionForm->Context->Session->UserID;
        if ($DiscussionForm->Context->Configuration['NOTIFY_AUTO_ALL'] == 0) {
            #Add all users who have subscribed to all, aren't already notified except the posting user
            if ($DiscussionForm->Context->Configuration['NOTIFY_ALLOW_ALL'] == 1) {
                $result = mysql_query("SELECT A.UserID,Email,FirstName, LastName FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notify AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'ALL' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND B.Notified = 0", $DiscussionForm->Context->Database->Connection);
                while ($row = mysql_fetch_row($result)) {
                    if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) {
                        array_push($Notifieusers, array($row[0], $row[1], $row[2], $row[3]));
                    }
                }
            }
            #Add all users who have subscribed to this category , aren't already notified except the posting user
            if ($DiscussionForm->Context->Configuration['NOTIFY_ALLOW_CATEGORY'] == 1) {
                $result = mysql_query("SELECT CategoryID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'", $DiscussionForm->Context->Database->Connection);
                $row = mysql_fetch_row($result);
                $result2 = mysql_query("SELECT A.UserID,Email,FirstName, LastName FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notify AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'CATEGORY' AND A.SelectID = '{$row['0']}' AND A.UserID <> '{$SelfUser}'  AND A.UserID = B.UserID AND B.Notified = 0", $DiscussionForm->Context->Database->Connection);
                while ($row2 = mysql_fetch_row($result2)) {
                    if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) {
                        array_push($Notifieusers, array($row2[0], $row2[1], $row2[2], $row2[3]));
                    }
                }
            }
            #Add all users who have subscribed to this discussion , aren't already notified except the posting user
            if ($DiscussionForm->Context->Configuration['NOTIFY_ALLOW_DISCUSSION'] == 1) {
                $result2 = mysql_query("SELECT A.UserID,Email,FirstName, LastName FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notify AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'DISCUSSION' AND A.SelectID = '{$DiscussionID}' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND B.Notified = 0", $DiscussionForm->Context->Database->Connection);
                while ($row2 = mysql_fetch_row($result2)) {
                    if ($Whispered == 1 and $WhisperUserID = $row[0] or $Whispered == 0) {
                        array_push($Notifieusers, array($row2[0], $row2[1], $row2[2], $row2[3]));
                    }
                }
            }
        } else {
            #Add all users
            $result = mysql_query("SELECT UserID,Email,FirstName, LastName FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User WHERE UserID <> '{$SelfUser}' AND Notified = 0", $DiscussionForm->Context->Database->Connection);
            while ($row = mysql_fetch_row($result)) {
                if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) {
                    array_push($Notifieusers, array($row[0], $row[1], $row[2], $row[3]));
                }
            }
        }
        #Remove double inserted users
        array_unique($Notifieusers);
        #Send an email for each user:
        $mailsent = array();
        $e = $DiscussionForm->Context->ObjectFactory->NewContextObject($DiscussionForm->Context, 'Email');
        $e->HtmlOn = 0;
        foreach ($Notifieusers as $val) {
            $mName = '';
            if ($val[2] != '') {
                $mName = ' ' . $val[2];
            }
            if ($val[1] != "" and !in_array($val[1], $mailsent)) {
                if ($val[2] != "" and $val[3] != "") {
                    $NotifyName = '';
                } else {
                    $NotifyName = $val[2] . ' ' . $val[3];
                }
                $e->Clear();
                $e->AddFrom($DiscussionForm->Context->Configuration['SUPPORT_EMAIL'], $DiscussionForm->Context->Configuration['SUPPORT_NAME']);
                $e->AddRecipient($val[1], $NotifyName);
                $e->Subject = $DiscussionForm->Context->Configuration['APPLICATION_TITLE'] . ' ' . $DiscussionForm->Context->GetDefinition('Notification');
                $EmailBody = @file_get_contents($DiscussionForm->Context->Configuration['EXTENSIONS_PATH'] . 'Notify/email_notify.txt');
                $e->Body = str_replace(array("{name}", "{forum_name}", "{title}", "{comment}", "{user}", "{topic_url}", "{support_name}"), array($mName, $DiscussionForm->Context->Configuration['APPLICATION_TITLE'], $mTitle, $mComment, $mUser, ConcatenatePath($DiscussionForm->Context->Configuration['BASE_URL'] . 'comments.php?DiscussionID=' . $DiscussionID, ''), $DiscussionForm->Context->Configuration['SUPPORT_NAME']), $EmailBody);
                $e->Send();
                array_push($mailsent, $val[1]);
                mysql_query("UPDATE " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User SET Notified = 1 WHERE UserID = '{$val['0']}'");
            }
        }
    }
}
예제 #2
0
파일: ajax.php 프로젝트: jaran/opencongress
<?php

include '../../appg/settings.php';
include '../../conf/settings.php';
include '../../appg/init_vanilla.php';
$PostBackAction = ForceIncomingString('PostBackAction', '');
$Type = ForceIncomingString('Type', '');
$ElementID = ForceIncomingInt('ElementID', 0);
$Value = ForceIncomingInt('Value', 0);
if ($PostBackAction == 'ChangeNotify') {
    if ($Type != 'OWN') {
        ChangeNotify(&$Context, $Type, $ElementID, $Value);
    } else {
        SwitchOwnNotify(&$Context, $Value, $Context->Session->UserID);
    }
    echo 'Complete';
}
$Context->Unload();