function process_event($event, $userid, $handle, $cookieid, $params)
 {
     // call_this_method();  //here we can call the scheuler
     $loggeduserid = qa_get_logged_in_userid();
     $dolog = true;
     $postid = @$params['postid'];
     // grab all preferences for notifying users
     $all_preferences = qw_get_all_notification_settings();
     switch ($event) {
         case 'a_post':
             // user's question had been answered
             if ($loggeduserid != $params['parent']['userid']) {
                 $effecteduserid = $params['parent']['userid'];
                 $question = $this->GetQuestion($params);
                 $params['qtitle'] = $question['title'];
                 $params['qid'] = $question['postid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'c_post':
             // user's answer had been commented
             $question = $this->GetQuestion($params);
             $params['qtitle'] = $question['title'];
             $params['qid'] = $question['postid'];
             $thread = $params['thread'];
             $already_notified = "";
             unset($params['thread']);
             if ($loggeduserid != $params['parent']['userid']) {
                 $effecteduserid = $params['parent']['userid'];
                 $this->AddEvent($postid, $userid, $params['parent']['userid'], $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
                 $already_notified = $effecteduserid;
             }
             if (count($thread) > 0) {
                 $user_array = array();
                 foreach ($thread as $t) {
                     if ($loggeduserid != $t['userid']) {
                         $user_array[] = $t['userid'];
                     }
                 }
                 $user_array = array_unique($user_array, SORT_REGULAR);
                 foreach ($user_array as $user) {
                     if ($user == $already_notified) {
                         continue;
                     }
                     $this->AddEvent($postid, $userid, $user, $params, $event);
                     $effecteduserid = $user;
                     //for this scenario the $user_array contains all user ids in the current commented thread
                     if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                         qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                     }
                 }
             }
             break;
         case 'q_reshow':
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $post = qa_post_get_full($postid);
             if ($loggeduserid != $post['userid']) {
                 $effecteduserid = $post['userid'];
                 $question = $this->GetQuestion($params);
                 $params['qtitle'] = $question['title'];
                 $params['qid'] = $question['postid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'a_reshow':
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $post = qa_post_get_full($postid);
             if ($loggeduserid != $post['userid']) {
                 $effecteduserid = $post['userid'];
                 $question = $this->GetQuestion($params);
                 $params['qtitle'] = $question['title'];
                 $params['qid'] = $question['postid'];
                 unset($params['oldanswer']);
                 unset($params['content']);
                 unset($params['text']);
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'c_reshow':
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $post = qa_post_get_full($postid);
             if ($loggeduserid != $post['userid']) {
                 unset($params['oldcomment']);
                 $effecteduserid = $post['userid'];
                 $question = $this->GetQuestion($params);
                 $params['qtitle'] = $question['title'];
                 $params['qid'] = $question['postid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
             /* case 'a_unselect':
             			require_once QA_INCLUDE_DIR.'qa-app-posts.php';
             			$post = qa_post_get_full($postid);
             			$effecteduserid = $post['userid'];
             			qa_db_query_sub(
             				"DELETE FROM ^ra_userevent WHERE effecteduserid=$ AND event=$ AND postid=$",
             				$effecteduserid, 'a_select', $postid
             			);
             			if (qw_check_pref_for_event($effecteduserid , $event , $all_preferences )) {
             				qw_do_action('user_event_'.$event, $postid,$userid, $effecteduserid, $params, $event);
             			}
             			
             			break; */
         /* case 'a_unselect':
         			require_once QA_INCLUDE_DIR.'qa-app-posts.php';
         			$post = qa_post_get_full($postid);
         			$effecteduserid = $post['userid'];
         			qa_db_query_sub(
         				"DELETE FROM ^ra_userevent WHERE effecteduserid=$ AND event=$ AND postid=$",
         				$effecteduserid, 'a_select', $postid
         			);
         			if (qw_check_pref_for_event($effecteduserid , $event , $all_preferences )) {
         				qw_do_action('user_event_'.$event, $postid,$userid, $effecteduserid, $params, $event);
         			}
         			
         			break; */
         case 'a_select':
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $post = qa_post_get_full($postid);
             if ($loggeduserid != $post['userid']) {
                 $effecteduserid = $post['userid'];
                 $question = $this->GetQuestion($params);
                 $params['qtitle'] = $question['title'];
                 $params['qid'] = $question['postid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'q_vote_up':
             $this->UpdateVote('q_vote_up', $postid, $userid, $params, 'q_vote_up', 1);
             $dolog = false;
             break;
         case 'a_vote_up':
             $this->UpdateVote('a_vote_up', $postid, $userid, $params, 'a_vote_up', 1);
             $dolog = false;
             break;
         case 'q_vote_down':
             $this->UpdateVote('q_vote_down', $postid, $userid, $params, 'q_vote_down', -1);
             $dolog = false;
             break;
         case 'a_vote_down':
             $this->UpdateVote('a_vote_down', $postid, $userid, $params, 'a_vote_down', -1);
             $dolog = false;
             break;
         case 'q_vote_nil':
             $this->UpdateVote('q_vote_nil', $postid, $userid, $params, 'q_vote_nil', 0);
             $dolog = false;
             break;
         case 'a_vote_nil':
             $this->UpdateVote('a_vote_nil', $postid, $userid, $params, 'a_vote_nil', 0);
             $dolog = false;
             break;
         case 'q_approve':
         case 'a_approve':
         case 'c_approve':
         case 'q_reject':
         case 'a_reject':
         case 'c_reject':
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $post = qa_post_get_full($postid);
             if ($loggeduserid != $post['userid']) {
                 $effecteduserid = $post['userid'];
                 $question = $this->GetQuestion($params);
                 $params['qtitle'] = $question['title'];
                 $params['qid'] = $question['postid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'q_favorite':
             $this->UpdateVote('q_favorite', $postid, $userid, $params, 'favorite', 1);
             if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                 qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
             }
             $dolog = false;
             break;
             /* case 'q_unfavorite':
             			$this->UpdateVote('q_unfavorite', $postid,$userid, $params, 'unfavorite', -1);
             			$dolog=false;					
             			break; */
         /* case 'q_unfavorite':
         			$this->UpdateVote('q_unfavorite', $postid,$userid, $params, 'unfavorite', -1);
         			$dolog=false;					
         			break; */
         case 'q_post':
             $already_notified = "";
             if ($params['parent']['type'] == 'A') {
                 $effecteduserid = $params['parent']['userid'];
                 if ($loggeduserid != $effecteduserid) {
                     $event = 'related';
                     $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                     if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                         qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                     }
                     $already_notified = $effecteduserid;
                 }
             }
             // for social postings
             if (qw_check_pref_for_event(@$effecteduserid, $event, $all_preferences)) {
                 qw_do_action('user_event_q_post_social', $postid, $userid, null, $params, 'q_post');
             }
             $categoryid = isset($params['categoryid']) ? $params['categoryid'] : '';
             $tags = isset($params['tags']) ? $params['tags'] : '';
             $user_datas = $this->qw_get_users_details_notify_email($userid, $tags, $categoryid);
             if (count($user_datas)) {
                 foreach ($user_datas as $user_data) {
                     $effecteduserid = $user_data['userid'];
                     $event = $user_data['event'];
                     if ($effecteduserid != $already_notified) {
                         // $this->AddEvent($postid,$userid, $effecteduserid, $params, $event);
                         if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                             qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                         }
                     }
                 }
             }
             break;
         case 'u_favorite':
             if ($loggeduserid != $params['userid']) {
                 $this->UpdateUserFavorite($postid, $userid, $params, 'u_favorite', 1);
                 $effecteduserid = $params['userid'];
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
                 $dolog = false;
             }
             break;
             /* case 'u_unfavorite':
             			$this->UpdateUserFavorite($postid,$userid, $params, 'u_unfavorite', -1);
             			$dolog=false;
             			break; */
         /* case 'u_unfavorite':
         			$this->UpdateUserFavorite($postid,$userid, $params, 'u_unfavorite', -1);
         			$dolog=false;
         			break; */
         case 'u_message':
             if ($loggeduserid != $params['userid']) {
                 $effecteduserid = $params['userid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'u_wall_post':
             if ($loggeduserid != $params['userid']) {
                 $effecteduserid = $params['userid'];
                 $params['message'] = $params['content'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         case 'u_level':
             $old_level = $params['oldlevel'];
             $new_level = $params['level'];
             if ($new_level > $old_level) {
                 //add the event only if the level increases
                 $effecteduserid = $params['userid'];
                 $this->AddEvent($postid, $userid, $effecteduserid, $params, $event);
                 if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) {
                     qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event);
                 }
             }
             break;
         default:
             $dolog = false;
     }
 }
Beispiel #2
0
function qw_check_pref_for_event($userid, $event, $all_preferences = '')
{
    if (!$all_preferences) {
        $all_preferences = qw_get_all_notification_settings();
    }
    $event = 'qw_mail_when_' . $event;
    foreach ($all_preferences as $preferences) {
        if ($preferences['userid'] == $userid) {
            return @$preferences['settings'][$event];
        }
    }
    return false;
}