function report_most_popular($count, $cid = 0) { global $db; $output = ''; $course = course_load($cid); $output .= '<div id="report_most_popular">'; $output .= select_course('cid', $cid); $output .= '<h2>Most popular questions of ' . ($cid == 0 ? 'all courses' : '"' . $course['Course_Name'] . '"') . '</h2>'; $posts = $db->array_load_all('POST'); $posts = array_filter($posts, array(new Filter(1), 'filter_current')); if ($cid != 0) { $posts = array_filter($posts, array(new Filter($cid), 'filter_cid')); } sort($posts); for ($p = 0; $p < count($posts); $p++) { $posts[$p]['comments_count'] = count_comments($posts[$p]['Post_ID']); } for ($p = 0; $p < count($posts); $p++) { $posts[$p]['likes_count'] = count_post_likes($posts[$p]['Post_ID']); } for ($p = 0; $p < count($posts); $p++) { $posts[$p]['follows_count'] = count_post_follows($posts[$p]['Post_ID']); } usort($posts, 'sort_likes_count_descend'); $output .= '<table width="50%">'; $output .= '<tr><th>Most liked questions</th><th>Number of likes</th></tr>'; for ($i = 0; $i < $count; $i++) { if (isset($posts[$i])) { $class = 'class="' . table_row_class($i) . '"'; $output .= '<tr ' . $class . '><td width="30%"><a href="?p=question/' . $posts[$i]['Post_URL'] . '">' . $posts[$i]['Post_Title'] . '</td><td width="20%">' . $posts[$i]['likes_count'] . ($posts[$i]['likes_count'] != 0 && $posts[$i]['likes_count'] != 1 ? ' likes' : ' like') . '</td></tr>'; } } $output .= '</table><br/>'; usort($posts, 'sort_comments_count_descend'); $output .= '<table width="50%">'; $output .= '<tr><th>Most commented questions</th><th>Number of comments</th></tr>'; for ($i = 0; $i < $count; $i++) { if (isset($posts[$i])) { $class = 'class="' . table_row_class($i) . '"'; $output .= '<tr ' . $class . '><td width="30%"><a href="?p=question/' . $posts[$i]['Post_URL'] . '">' . $posts[$i]['Post_Title'] . '</td><td width="20%">' . $posts[$i]['comments_count'] . ($posts[$i]['comments_count'] != 0 && $posts[$i]['comments_count'] != 1 ? ' comments' : ' comment') . '</td></tr>'; } } $output .= '</table><br/>'; usort($posts, 'sort_follows_count_descend'); $output .= '<table width="50%">'; $output .= '<tr><th>Most followed questions</th><th>Number of follows</th></tr>'; for ($i = 0; $i < $count; $i++) { if (isset($posts[$i])) { $class = 'class="' . table_row_class($i) . '"'; $output .= '<tr ' . $class . '><td width="30%"><a href="?p=question/' . $posts[$i]['Post_URL'] . '">' . $posts[$i]['Post_Title'] . '</td><td width="20%">' . $posts[$i]['follows_count'] . ($posts[$i]['follows_count'] != 0 && $posts[$i]['follows_count'] != 1 ? ' follows' : ' follow') . '</tr></td>'; } } $output .= '</table><br/>'; $output .= '</div>'; $output .= '<script> $("select#cid").change(function(){ $("#report_most_popular").load("triggers/report_most_popular.php",{cid:$(this).val(),report_type:"Most popular questions",count:' . $count . '}); }); </script>'; return $output; }
function list_members($page = 1, $keyword = '') { //Return members list, for admin use $output = ''; $emails = array(); $members = array(); $path = realpath($_SERVER['DOCUMENT_ROOT']) . '/member/'; $directories = array_filter(glob($path . '*'), 'is_dir'); foreach ($directories as $directory) { if (str_replace($path, '', $directory) != 'login' && str_replace($path, '', $directory) != 'register') { $emails[] = str_replace($path, '', $directory); } } $count = count($emails); sort($emails); for ($m = 0; $m < $count; ++$m) { $members[$m] = load_member_from_email($emails[$m]); } usort($members, 'sort_date_member_ascend'); $output .= '<a class="button" href="/member/register/">Register new member</a>'; $output .= '<table class="admin">'; $output .= '<tr><th>Email</th><th>Fullname</th><th>DOB</th><th>Language</th><th>Created at</th><th>Edited at</th><th colspan="2">Operations</th></tr>'; $output .= '<tr><td class="count" colspan="8">' . $count . ' item' . ($count > 1 ? 's' : '') . ' to display.</td></tr>'; for ($i = 0; $i < $count; ++$i) { $class = 'class="' . table_row_class($i) . '"'; $output .= '<tr ' . $class . '>'; $output .= '<td>' . $members[$i]['email'] . '</td>'; $output .= '<td>' . $members[$i]['fullname'] . '</td>'; $output .= '<td>' . $members[$i]['dob'] . '</td>'; $output .= '<td>' . $members[$i]['lang'] . '</td>'; $output .= '<td>' . $members[$i]['created_at'] . '</td>'; $output .= '<td>' . $members[$i]['edited_at'] . '</td>'; $output .= '<td><a class="button" href="/member/' . $members[$i]['email'] . '/">Edit</a></td>'; $output .= '<td><a class="button" onclick="return confirm(\'Are you sure?\')" href="/triggers/member_delete.php?email=' . $members[$i]['email'] . '">Delete</a></td>'; $output .= '</tr>'; } $output .= '</table>'; return $output; }