function process_request($request) { require_once QA_INCLUDE_DIR . 'mp-app-posts.php'; require_once QA_INCLUDE_DIR . 'mp-db-users.php'; $qa_content = qa_content_prepare(); // if the user is not logged in, request user to login if (!qa_get_logged_in_userid()) { $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 first.', $request); return $qa_content; } $qa_content['title'] = 'Course Announcements'; // DISPLAY ANNOUCEMENTS $data = '<div class="qa-q-list">'; // retrieve annoucements $announcements = mp_announcements_get_all(mp_get_categoryid()); if (count($announcements) == 0) { $data .= "No announcements"; } else { foreach ($announcements as $announcement) { $data .= '<div class="qa-q-list-item">'; $data .= '<div class="qa-q-item-title">' . $announcement['title'] . '</div>'; $data .= '<div class="qa-q-view-content">' . $announcement['content'] . '</div>'; $data .= '<div class="qa-q-item-meta">Posted by <A HREF="' . qa_path_html('user/' . $announcement['handle']) . '">' . $announcement['handle'] . '</A> on ' . $announcement['created'] . '</div>'; $data .= '</div>'; $data .= '<div class="qa-q-list-item-clear" ></div>'; } } $data .= '</div>'; $qa_content['custom_2'] = $data; // create the sub menu for navigation $qa_content['navigation']['sub'] = mp_announcements_sub_navigation(); $qa_content['navigation']['sub']['default']['selected'] = true; return $qa_content; }
function process_request($request) { $userid = qa_get_logged_in_userid(); $categoryoptions = array(); $qa_content = qa_content_prepare(); // check if we have done a post of the page if (qa_post_text('okthen')) { // update the current category $newcategory = qa_post_text('category'); if (isset($newcategory)) { mp_set_categoryid($newcategory); // redirect to main page qa_redirect(''); } else { $qa_content['error'] = 'You must select a course to continue.'; } } // retrieve list of categories user is associated with // populate category options $results = mp_get_categories_for_user($userid); foreach ($results as $row) { $categoryoptions[$row['categoryid']] = $row['title']; } $qa_content['title'] = 'Registered courses'; $qa_content['custom'] = 'The following list displays all courses your account is associated with. Select a course from the list below and click <B>Select</B> to change to the new course<br /><br />'; $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('courses' => array('type' => 'select-radio', 'label' => 'Courses', 'tags' => 'NAME="category"', 'options' => $categoryoptions, 'value' => mp_get_categoryid(), 'error' => qa_html(@$errors['course']))), 'buttons' => array('ok' => array('tags' => 'NAME="okthen"', 'label' => 'Select', 'value' => '1'))); return $qa_content; }
function process_event($event, $userid, $handle, $cookieid, $params) { $activityPoints = array("page_enter" => 1, "u_register" => 0, "u_confirmed" => 0, "q_edit" => 50, "a_edit" => 50, "a_vote_up" => 30, "a_vote_down" => 30, "a_vote_nil" => 30, "q_vote_up" => 30, "q_vote_down" => 30, "q_vote_nil" => 30, "q_post" => 200, "a_post" => 300, "u_password" => 5, "u_reset" => 5, "u_edit" => 5, "u_save" => 5, "a_select" => 30, "a_unselect" => 10, "u_login" => 10, "u_logout" => 10); if (array_key_exists($event, $activityPoints)) { qa_db_query_sub('INSERT INTO mp_userpoints (userid, categoryid, eventid, points, award_date) ' . 'VALUES (#, #, $, #, NOW())', is_null($userid) ? '-1' : $userid, is_null(mp_get_categoryid()) ? '-1' : mp_get_categoryid(), $event, $activityPoints[$event]); } //qa_opt('mp_active_category') }
function mp_get_categoryslug() { $i = qa_db_read_all_values(qa_db_query_sub('select backpath from ^categories where categoryid=#', mp_get_categoryid())); if (count($i) > 0) { return array_reverse(explode('/', $i[0])); } else { return ""; } }
function logged_in() { qa_html_theme_base::logged_in(); $qa_login_userid = qa_get_logged_in_userid(); if (isset($qa_login_userid)) { $currentcourse = mp_get_categoryinfo(mp_get_categoryid()); //$this->output('Course: '.$currentcourse['title'] ); //$this->output('<A HREF="'.qa_path_html('mp-change-course-page').'" class="qa-user-link">Change Course</a>'); $this->output('course: <A HREF="' . qa_path_html('mp-change-course-page') . '" class="qa-user-link">' . $currentcourse['title'] . '</a>'); } }
function process_request($request) { require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; require_once QA_INCLUDE_DIR . 'qa-db-post-create.php'; require_once QA_INCLUDE_DIR . 'mp-db-users.php'; // report that we entered this page qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING'])); // create the editor and update its content qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext); $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_qs'); $editor = qa_load_editor(@$incontent, @$informat, $editorname); // retrieve variable data $innotify = qa_post_text('notify') ? true : false; // handle creation of annoucement if (qa_post_text('docreate')) { //retrieve data $title = qa_post_text('title'); $content = $incontent; $format = $informat; // validate data // handle create work // actual create process is in file mp-app-posts.php $postid = qa_post_create('AN', null, $title, $content, $format, mp_get_categoryid(), null, qa_get_logged_in_userid(), $innotify); // redirect page qa_redirect('mp-announcements-page'); // our work is done here } $qa_content = qa_content_prepare(); // if the user is not logged in, request user to login if (!qa_get_logged_in_userid()) { $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 first.', $request); return $qa_content; } $qa_content['title'] = 'Create Announcement'; $qa_content['form_newannouncement'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('title' => array('label' => qa_lang_html('announcements/a_title_label'), 'tags' => 'NAME="title"', 'value' => qa_html(qa_post_text('title')), 'error' => qa_html(@$errors['title'])), 'content' => array_merge($editor->get_field($qa_content, @$incontent, @$informat, 'content', 12, false), array('label' => qa_lang_html('announcements/a_content_label'), 'error' => qa_html(@$errors['content']))), 'notify' => array('label' => 'Send email notification to all registered students', 'tags' => 'NAME="notify"', 'type' => 'checkbox', 'value' => qa_html($innotify))), 'buttons' => array('ok' => array('tags' => 'NAME="docreate"', 'label' => 'Create Announcement', 'value' => '1')), 'hidden' => array('hiddenfield' => '1', 'editor' => qa_html($editorname))); // create the sub menu for navigation $qa_content['navigation']['sub'] = mp_announcements_sub_navigation(); $qa_content['navigation']['sub']['create']['selected'] = true; return $qa_content; }
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'> </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; }
} // create a new cookie if necessary $questionid = qa_question_create($followanswer, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $intitle, $incontent, $informat, $intext, $tagstring, $innotify, $inemail, $incategoryid); qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_post', $questionid, null, null); qa_redirect(qa_q_request($questionid, $intitle)); // our work is done here } } // Prepare content for theme $qa_content = qa_content_prepare(false, array_keys(qa_category_path($categories, @$incategoryid))); $qa_content['title'] = qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title'); $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_qs'); $editor = qa_load_editor(@$incontent, @$informat, $editorname); // MP: find category title $categoryinfo = mp_get_categoryinfo(mp_get_categoryid()); $qa_content['form'] = array('tags' => 'NAME="ask" METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('follows' => array(), 'title' => array('label' => qa_lang_html('question/q_title_label'), 'tags' => 'NAME="title" ID="title" AUTOCOMPLETE="off"', 'value' => qa_html(@$intitle), 'error' => qa_html(@$errors['title'])), 'similar' => array('type' => 'custom', 'html' => '<SPAN ID="similar"></SPAN>'), 'categorylabel' => array('type' => 'static', 'label' => qa_lang_html('question/q_category_label'), 'error' => qa_html(@$errors['category']), 'value' => $categoryinfo['title']), 'content' => array_merge($editor->get_field($qa_content, @$incontent, @$informat, 'content', 12, false), array('label' => qa_lang_html('question/q_content_label'), 'error' => qa_html(@$errors['content']))), 'tags' => array('error' => qa_html(@$errors['tags']))), 'buttons' => array('ask' => array('label' => qa_lang_html('question/ask_button'))), 'hidden' => array('editor' => qa_html($editorname), 'doask' => '1', 'category' => mp_get_categoryid())); if (qa_opt('do_ask_check_qs') || qa_opt('do_example_tags')) { $qa_content['script_rel'][] = 'qa-content/qa-ask.js?' . QA_VERSION; $qa_content['form']['fields']['title']['tags'] .= ' onChange="qa_title_change(this.value);"'; if (strlen(@$intitle)) { $qa_content['script_onloads'][] = 'qa_title_change(' . qa_js($intitle) . ');'; } } //if (qa_using_categories() && count($categories)) { // qa_set_up_category_field($qa_content, $qa_content['form']['fields']['category'], 'category', // $categories, $incategoryid, true, qa_opt('allow_no_sub_category')); // // if (!qa_opt('allow_no_category')) // don't auto-select a category even though one is required // $qa_content['form']['fields']['category']['options']['']=''; // //} else
function process_request($request) { // if the user is not logged in, request user to login if (!qa_get_logged_in_userid()) { $qa_content = qa_content_prepare(); $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 to view leaderboard.', $request); return $qa_content; } $qa_content = qa_content_prepare(); $qa_content['title'] = 'Leaderboards'; // retrieve raw points data $Qpoints = qa_db_read_all_assoc(qa_db_query_sub('SELECT U2.handle, 500 * COUNT(P.postid) points, 100 * SUM(P.upvotes) upvotes, 100 * SUM(P.downvotes) downvotes FROM (SELECT * FROM ^posts WHERE type = "Q" and categoryid = #) P RIGHT JOIN mp_user_category_map U ON P.userid = U.userid, ^users U2 WHERE U.userid = U2.userid AND U.categoryid = # GROUP BY U.userid ORDER BY points DESC', mp_get_categoryid(), mp_get_categoryid()), 'handle'); $Apoints = qa_db_read_all_assoc(qa_db_query_sub('SELECT U2.handle, 500 * COUNT(P.postid) points, 100* SUM(P.upvotes) upvotes, 100 * SUM(P.downvotes) downvotes FROM (SELECT * FROM ^posts WHERE type = "A" AND categoryid = #) P RIGHT JOIN mp_user_category_map U ON P.userid = U.userid, ^users U2 WHERE U.userid = U2.userid AND U.categoryid = # GROUP BY U.userid ORDER BY points DESC', mp_get_categoryid(), mp_get_categoryid()), 'handle'); // Leaderboard by participation $participationData = array(); // combine the Q and A data foreach (array_keys($Qpoints) as $key) { $participationData[$key]['handle'] = $key; $participationData[$key]['points'] = $Qpoints[$key]['points'] + $Apoints[$key]['points'] + $Qpoints[$key]['upvotes'] - $Qpoints[$key]['downvotes'] + $Apoints[$key]['upvotes'] - $Apoints[$key]['downvotes']; } // Obtain a list of columns so it can be sorted using array_multisort $points1 = array(); foreach ($participationData as $key => $row) { $points1[$key] = $row['points']; } array_multisort($points1, SORT_DESC, $participationData); // Leaderboard by contribution $contributionData = array(); // combine the Q and A data foreach (array_keys($Qpoints) as $key) { $contributionData[$key]['handle'] = $key; $contributionData[$key]['points'] = $Apoints[$key]['points'] + $Apoints[$key]['upvotes'] - $Apoints[$key]['downvotes']; } // Obtain a list of columns so it can be sorted using array_multisort $points = array(); foreach ($contributionData as $key => $row) { $points[$key] = $row['points']; } array_multisort($points, SORT_DESC, $contributionData); // calculate activity points $activityPoints = qa_db_read_all_assoc(qa_db_query_sub('SELECT QU.handle, COALESCE(SUM(U.points), 0) points FROM `mp_userpoints` U RIGHT JOIN mp_user_category_map M ON U.userid = M.userid AND U.categoryid = M.categoryid, qa_users QU WHERE M.userid = QU.userid AND M.categoryid = # GROUP BY M.userid ORDER BY points DESC, QU.handle ASC', mp_get_categoryid()), 'handle'); // calculate overall points //$allPoints = qa_db_read_all_assoc( // qa_db_query_sub('SELECT U.handle, P.userid, COALESCE(SUM(POINTS),0) points FROM (SELECT * FROM mp_userpoints WHERE categoryid = # ) P RIGHT JOIN ^users U ON P.userid = U.userid GROUP BY P.userid ORDER BY points DESC', // mp_get_categoryid())); $allPoints = array(); foreach (array_keys($Qpoints) as $key) { $allPoints[$key] = $participationData[$key]['points'] + $contributionData[$key]['points'] + $activityPoints[$key]['points']; } asort($allPoints, SORT_NUMERIC); $allPoints = array_reverse($allPoints, true); ////////////////////////////////////////////////////////////////////////////////////////////////////// // begin data display ////////////////////////////////////////////////////////////////////////////////////////////////////// $data = '<table><tr><td>'; $data .= '<div style="background-color:#EEEEFF;visibility: visible; border:1px solid #4488FF; width:160px; overflow:auto; "> <div style="background-color:#4488FF; font-family:Arial; font-size:14px; text-align:center; color:white; padding:3px;">Total Points</div> <div style="font-family:Arial; font-size:14px; text-align:center; color:black; padding:3px;">'; $data .= '<table width="100%">'; foreach ($allPoints as $handle => $points) { $data .= '<tr><td align="left">' . $handle . '</td><td align="right">' . $points . '</td></tr>'; } $data .= '</table></div></div><br />'; $data .= '</td><td> </td><td>'; $data .= '<div style="background-color:#EEEEFF;visibility: visible; border:1px solid #4488FF; width:160px; overflow:auto; "> <div style="background-color:#4488FF; font-family:Arial; font-size:14px; text-align:center; color:white; padding:3px;">Participation</div> <div style="font-family:Arial; font-size:14px; text-align:center; color:black; padding:3px;">'; $data .= '<table width="100%">'; foreach ($participationData as $row) { $data .= '<tr><td align="left">' . $row['handle'] . '</td><td align="right">' . $row['points'] . '</td></tr>'; } $data .= '</table></div></div><br /> '; $data .= '</td><td> </td><td>'; $data .= '<div style="background-color:#EEEEFF;visibility: visible; border:1px solid #4488FF; width:160px; overflow:auto; "> <div style="background-color:#4488FF; font-family:Arial; font-size:14px; text-align:center; color:white; padding:3px;">Knowledge Contribution</div> <div style="font-family:Arial; font-size:14px; text-align:center; color:black; padding:3px;">'; $data .= '<table width="100%">'; foreach ($contributionData as $row) { $data .= '<tr><td align="left">' . $row['handle'] . '</td><td align="right">' . $row['points'] . '</td></tr>'; } $data .= '</table></div></div><br /> '; $data .= '</td><td> </td><td>'; $data .= '<div style="background-color:#EEEEFF;visibility: visible; border:1px solid #4488FF; width:160px; overflow:auto; "> <div style="background-color:#4488FF; font-family:Arial; font-size:14px; text-align:center; color:white; padding:3px;">Usage Activity</div> <div style="font-family:Arial; font-size:14px; text-align:center; color:black; padding:3px;">'; $data .= '<table width="100%">'; foreach ($activityPoints as $row) { $data .= '<tr><td align="left">' . $row['handle'] . '</td><td align="right">' . $row['points'] . '</td></tr>'; } $data .= '</table></div></div><br /> '; $data .= '</td></tr></table>'; $qa_content['custom_1'] = $data; return $qa_content; }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { // only show for logged in users if (qa_get_logged_in_handle() == null) { return; } require_once QA_INCLUDE_DIR . 'qa-db.php'; require_once QA_INCLUDE_DIR . 'qa-db.php'; require_once QA_INCLUDE_DIR . 'mp-db-users.php'; $userid = qa_get_logged_in_userid(); $categoryid = mp_get_categoryid(); // check each property $nameSQL = qa_db_read_one_value(qa_db_query_sub('select count(content) from ^userprofile p where p.userid =# and content="" and title=#', $userid, 'name')); $aboutSQL = qa_db_read_one_value(qa_db_query_sub('select count(content) from ^userprofile p where p.userid =# and content="" and title=#', $userid, 'about')); $websiteSQL = qa_db_read_one_value(qa_db_query_sub('select count(content) from ^userprofile p where p.userid =# and content="" and title=#', $userid, 'website')); $questionSQL = qa_db_read_one_value(qa_db_query_sub('select count(userid) from ^posts p where p.userid =# and categoryid=# and type=#', $userid, $categoryid, 'Q')); $answerSQL = qa_db_read_one_value(qa_db_query_sub('select count(userid) from ^posts p where p.userid =# and categoryid=# and type=#', $userid, $categoryid, 'A')); $perc = 0; if ($nameSQL == 0) { $perc++; } if ($aboutSQL == 0) { $perc++; } if ($websiteSQL == 0) { $perc++; } if ($questionSQL > 0) { $perc++; } if ($answerSQL > 0) { $perc++; } $themeobject->output('<DIV CLASS="mp-widget-profile-view"><DIV CLASS="mp-widget-profile-title">Profile Progress - ' . $perc * 100 / 5 . '%</DIV>'); $data = '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Name</SPAN>' . ($nameSQL ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>'; // value of 0 is complete $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">About</SPAN>' . ($aboutSQL ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>'; // value of 0 is complete $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Website</SPAN>' . ($websiteSQL ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>'; // value of 0 is complete $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Posted a question</SPAN>' . ($questionSQL <= 0 ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>'; // value > 0 is complete $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Posted an answer</SPAN>' . ($answerSQL <= 0 ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>'; // value > 0 is complete $data .= '<br /><center><a CLASS="qa-page-link" href="' . qa_path_html('account') . '">Edit Profile</a></center><br />'; $themeobject->output($data); $themeobject->output('</DIV>'); }