Example #1
0
function mp_announcement_create($userid, $handle, $cookieid, $title, $content, $format, $text, $notify, $categoryid)
{
    /* 
     * Proceeds to create an announcement
     *
     */
    require_once QA_INCLUDE_DIR . 'qa-db-post-create.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'mp-app-users.php';
    // persist data to database
    $postid = qa_db_post_create('AN', null, $userid, $cookieid, qa_remote_ip_address(), $title, $content, $format, null, $notify, $categoryid);
    qa_user_report_action(qa_get_logged_in_userid(), null, null, null, null);
    // update new post with category path hierarchy
    qa_db_posts_calc_category_path($postid);
    // send notifications
    if ($notify && isset($postid)) {
        $category = mp_get_categoryinfo($categoryid);
        $recipients = mp_get_category_userids($categoryid);
        foreach ($recipients as $recipient) {
            // retrieve the user flags
            $userflags = mp_get_user_flags($recipient['userid']);
            // check user flags to determine whether user should be notified or not
            // of the new answer post
            if (!($userflags & QA_USER_FLAGS_NOTIFY_ANNOUNCEMENTS)) {
                qa_send_notification($recipient['userid'], null, null, qa_lang('emails/an_posted_subject'), qa_lang('emails/an_posted_body'), array('^an_handle' => $handle, '^category_title' => $category['title'], '^an_title' => $title, '^an_url' => qa_path('mp-announcements-page', null, qa_opt('site_url'), null, null)));
            }
        }
    }
    // report announcement create event
    qa_report_event('an_post', $userid, $handle, $cookieid, array('postid' => $postid, 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $categoryid, 'notify' => $notify));
    return $postid;
}
 function process_request($request)
 {
     $userid = qa_get_logged_in_userid();
     $categoryid = mp_get_categoryid();
     $users = mp_get_category_userids($categoryid);
     $qa_content = qa_content_prepare();
     $qa_content['title'] = 'Classroom';
     $data = "<div class='mp-classroom'>";
     $data .= "<center><div class='mp-classroom-teacher'>&nbsp;</div></center>";
     $data .= "<div class='mp-classroom-users'>";
     foreach ($users as $user) {
         $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($user['userid'], true));
         $data .= "<div class='mp-classroom-user'>";
         $data .= "<div class='mp-classroom-avatar'></div>";
         $data .= "<div class='mp-classroom-useremail'>" . qa_get_one_user_html($userinfo['handle'], false) . "</div>";
         $data .= "</div>";
     }
     $data .= "</div></div>";
     $qa_content['custom'] = $data;
     return $qa_content;
 }
function qa_answer_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question)
{
    $postid = qa_db_post_create('A', $question['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!$question['hidden']) {
        // don't index answer if parent question is hidden
        qa_post_index($postid, 'A', $question['postid'], null, $text, null);
    }
    qa_db_post_acount_update($question['postid']);
    qa_db_hotness_update($question['postid']);
    qa_db_points_update_ifuser($userid, 'aposts');
    qa_db_acount_update();
    qa_db_unaqcount_update();
    if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) {
        require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
        require_once QA_INCLUDE_DIR . 'qa-app-options.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $blockwordspreg = qa_get_block_words_preg();
        $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
        $sendtext = qa_block_words_replace($text, $blockwordspreg);
        qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array('^a_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendtext, '^url' => qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $postid))));
    }
    // notify all members of the category about the new post
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'mp-db-users.php';
    require_once QA_INCLUDE_DIR . 'mp-app-users.php';
    // find list of members of the category
    $recipients = mp_get_category_userids(mp_get_categoryid());
    // remove the current user from the list of recipients
    unset($recipients[$userid]);
    // get details for current category
    $currentcategory = mp_get_categoryinfo(mp_get_categoryid());
    foreach ($recipients as $recipient) {
        // retrieve the user flags
        $userflags = mp_get_user_flags($recipient['userid']);
        // check user flags to determine whether user should be notified or not
        // of the new answer post
        if (!($userflags & QA_USER_FLAGS_NOTIFY_ANSWERS)) {
            // for each member, send notification
            qa_send_notification($recipient['userid'], null, null, qa_lang('emails/q_answered_with_category_subject'), qa_lang('emails/q_answered_with_category_body'), array('^a_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $question['title'], '^a_content' => $text, '^url' => qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $postid)), '^category_title' => $currentcategory['title'] . $userflags));
        }
    }
    qa_report_event('a_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
// build the list of subjects for the emails
$subjects = array('Your Biweekly Microprobe activity for course ', 'Hello, this is your biweekly Microprobe activity for course ', 'A new edition of your biweekly Microprobe activity report for course ');
$subjectindex = rand(0, count($subjects) > 0 ? count($subjects) - 1 : 0);
// set the debug mode.  if debug flag not set, set it to false by default
if ($debug == "true") {
    $debug = TRUE;
} else {
    $debug = FALSE;
}
// check to ensure we provide a category
if (!$category) {
    echo 'ERROR: You must provide a category as a http argment: category=categoryid';
} else {
    $categoryinfo = mp_get_categoryinfo($category);
    // retrieve the list of users
    $users = mp_get_category_userids($category);
    foreach ($users as $user) {
        $u = mp_db_user_find_by_userid($user['userid']);
        $body = sprintf("It has been %s days since your last login to Microprobe %s\n\n", mp_db_user_find_dayssincelastlogin_by_userid($user['userid']), $u[0]['email']);
        $questioncount = mp_get_count_posts_by_userid_category_posttype($user['userid'], $category, 'Q');
        $body .= sprintf("ACTIVITY INFORMATION\n");
        if ($questioncount > 0) {
            $body .= sprintf("You have posted %s questions so far. ", $questioncount);
            $body .= sprintf("It has been %s days since you last posted a question.\n", mp_get_days_since_last_post($user['userid'], $category, 'Q'));
        } else {
            $body .= sprintf("You have not posted a question before.  Posting a question will help increase your activity points while motivating the knowledge sharing process.\n\n");
        }
        $answercount = mp_get_count_posts_by_userid_category_posttype($user['userid'], $category, 'A');
        if ($answercount > 0) {
            $body .= sprintf("You have posted %d answers so far. ", $answercount);
            $body .= sprintf("It has been %d days since you last posted an answer.\n", mp_get_days_since_last_post($user['userid'], $category, 'A'));