initial commit

This commit is contained in:
Luke Ogburn
2019-03-30 22:43:34 -04:00
commit c4a666e3b6
78 changed files with 5332 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("owner");
$user = getUserInfo($_GET["user"]);
if($user == false){
msg("That user doesn't exist.");
header("Location: /forum");
}
//Getting the number of posts
$stmt = $conn->prepare("SELECT * FROM forums WHERE poster_id = :usr");
$stmt->bindparam(":usr", $user->id);
$stmt->execute();
$posts = $stmt->rowCount();
//Getting the number of comments
$stmt = $conn->prepare("SELECT * FROM comments WHERE poster_id = :usr");
$stmt->bindparam(":usr", $user->id);
$stmt->execute();
$comments = $stmt->rowCount();
//Getting the number of reported posts made by user
$stmt = $conn->prepare("SELECT * FROM forums WHERE poster_id = :usr AND reports IS NOT NULL");
$stmt->bindparam(":usr", $user->id);
$stmt->execute();
$reportedPosts = $stmt->rowCount();
//Getting the number of reported comments made by user
$stmt = $conn->prepare("SELECT * FROM comments WHERE poster_id = :usr AND reports IS NOT NULL");
$stmt->bindparam(":usr", $user->id);
$stmt->execute();
$reportedComments = $stmt->rowCount();
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2><?=$user->name?></h2>
<?php
$name = $user->name;
$id = $user->id;
$login = makeDate($user->last_login);
if($posts == 0){
$reportedPostsPercent = 0;
}else{
$reportedPostsPercent = round($reportedPosts/$posts);
}
if($comments == 0){
$reportedCommentsPercent = 0;
}else{
$reportedCommentsPercent = round($reportedComments/$comments);
}
echo "
<p>Last login: $login</p>
<p>Posts made: $posts</p>
<p>Reported posts made: $reportedPosts</p>
<p>Percent of posts reported: $reportedPostsPercent%</p>
<p>Comments made: $comments</p>
<p>Reported comments made: $reportedComments</p>
<p>Percent of comments reported: $reportedCommentsPercent%</p>
<p><a class=noStyle href=/user/?user=$id>User's page</a></p>
";
?>
</div>
</body>
</html>

5
admin/portal/admin.css Normal file
View File

@@ -0,0 +1,5 @@
#userBanMsg{
font-style: italic;
width: 70%;
margin: 1.5em auto;
}

57
admin/portal/banUser.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("admin");
//Banning user
if(isset($_POST["person"]) && strval(getUserInfo($_POST["person"])->name) != ""){
if(verifyUser("admin", $_POST["person"])){
msg("You cannot ban that user");
unset($_POST);
header("Location: /admin/portal/banUser.php");
exit();//needed for some reason, else the code below runs
}
$person = $_POST["person"];
$reason = $_POST["reason"];
unset($_POST);
conn();
$stmt = $conn->prepare("UPDATE users SET special='banned', ban_reason=:rsn WHERE id=:id");
$stmt->bindParam(":rsn", $reason);
$stmt->bindParam(":id", $person);
$stmt->execute();
if($stmt){
$user = getUserInfo($person)->name;
msg("$user has been banned");
header("Location: /admin/portal/banUser.php");
}
}else if(isset($_POST["person"]) && strval(getUserInfo($_POST["person"])->name) == ""){
unset($_POST);
msg("User doesn't exist");
header("Location: /admin/portal/banUser.php");
}
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>BAN USER</h2>
<p id=userBanMsg>Banning a user will make them unable to access the website. Only do this if there is good reason to do so (e.g. cheating or bullying). This can only be undone by Luke Ogburn.</p>
<form action="" method=POST>
<p>User's ID (NOT their username):</p>
<input type=text name=person placeholder="User's ID" required><br>
<p>Reason for banning user (for them to read):</p>
<input type=text name=reason placeholder="Reason for ban" required>
<button type=submit>Ban User</button>
</form>
<br>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,51 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("owner");
$classes = file_get_contents($_SERVER['DOCUMENT_ROOT']."/res/classes");
$classes = array_filter(explode(",", $classes));
if(isset($_GET["del"]) && in_array($_GET["del"], $classes)){
$classes = array_diff($classes, array($_GET["del"]));
file_put_contents($_SERVER['DOCUMENT_ROOT']."/res/classes", implode(",", $classes));
msg("Class removed.");
header("Location: editClasses.php");
exit();
}
if(isset($_GET["add"]) && !in_array($_GET["add"], $classes)){
$class = str_replace(" ", "_", $_GET["add"]);
$class = strtolower($class);
array_push($classes, $class);
file_put_contents($_SERVER['DOCUMENT_ROOT']."/res/classes", implode(",", $classes));
msg("Class added.");
header("Location: editClasses.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>DELETE A CLASS:</h2>
<?php
foreach($classes as $class){
echo "<p><a class=deletable href=?del=$class>".ucwords(str_replace('_', ' ', $class))."</a></p>";
}
?>
</div>
<div class='card noHover center'>
<h2>ADD A CLASS:</h2>
<form>
<input type=text name=add>
<button type=submit>Add Class</button>
</form>
</div>
</body>
</html>

View File

@@ -0,0 +1,45 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("owner");
conn();
?>
<!DOCTYPE html>
<html>
<?php
include $_SERVER['DOCUMENT_ROOT']."/res/head";
?>
<body>
<?php
if(isset($_GET["del"])){
conn();
$del = $conn->prepare("DELETE FROM issue_tracker WHERE id = :id");
$del->bindParam(":id", $_GET["del"]);
$del->execute();
if($del){
msg("Good job :)");
header("Location: /admin/portal/errorReports.php");
}
}
include $_SERVER['DOCUMENT_ROOT']."/res/top";
$stmt = $conn->prepare("SELECT * FROM issue_tracker ORDER BY date DESC");
$stmt->execute();
$stmt = $stmt->fetchAll();
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>REPORTED ISSUES</h2>
<?php
foreach($stmt as $report){
echo "<a class=deletable href='?del=".$report["id"]."'>".$report['comment']."</a><br>";
echo "<small>Reported by: ".$report["reporter"]." (".getUserInfo($report["reporter"])->name.") ".makeDate($report["date"])."</small><br><br>";
}
if($stmt == NULL){
echo "<i>No issues have been reported :D</i><br>";
}
?>
<br>
</div>
</div>
</body>

48
admin/portal/index.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("admin");
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>NOTIFICATIONS</h2>
<?php
conn();
$stmt = $conn->prepare("SELECT * FROM forums WHERE reports IS NOT NULL");
$stmt->execute();
$res = $stmt->fetchAll();
foreach($res as $post){
$times = substr_count($post["reports"], ",");
$times = $times==1?"1 time":"$times times";
echo "<p><a class=noStyle href=reportedPost.php?post=".$post['post_id'].">Post ".$post["post_id"]." has been reported $times</a></p>";
}
if(count($res)==0){
echo "<p><i>Nothing has been reported.</i></p>";
}
?>
</div>
<div class="card noHover center">
<h2>ADMIN ACTIONS</h2>
<p><a class=noStyle href=banUser.php>Ban a user</a></p>
<p><a class=noStyle href=unbanUser.php>Unban a user</a></p>
<?php
if(verifyUser("owner")){
echo "<p><a class=noStyle href=errorReports.php>Error reports</a></p>";
echo "<p><a class=noStyle href=manage.php>Manage admins</a></p>";
echo "<p><a class=noStyle href=siteVisitors.php>Site visitors</a></p>";
echo "<p><a class=noStyle href=editClasses.php>Edit classes</a></p>";
}
?>
</div>
</div>
</body>
</html>

88
admin/portal/manage.php Normal file
View File

@@ -0,0 +1,88 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("owner");
//Adding admins
if(isset($_POST["person"]) && strval(getUserInfo($_POST["person"])->name) != ""){
$person = $_POST["person"];
unset($_POST);
conn();
$stmt = $conn->prepare("UPDATE users SET special='admin' WHERE id=:id");
$stmt->bindParam(":id", $person);
$stmt->execute();
if($stmt){
$user = getUserInfo($person)->name;
msg("$user added as admin");
header("Location: /admin/portal/manage.php");
}
}else if(isset($_POST["person"]) && strval(getUserInfo($_POST["person"])->name) == ""){
unset($_POST);
msg("User doesn't exist");
header("Location: /admin/portal/manage.php");
}
//Deleting admins
if(isset($_GET["delUser"])){
conn();
$person = $_GET["delUser"];
$stmt = $conn->prepare("SELECT special FROM users WHERE id=:id");
$stmt->bindParam(":id", $person);
$stmt->execute();
$res = $stmt->fetch(PDO::FETCH_ASSOC);
if($res["special"]=="admin"){
$person = $_GET["delUser"];
$stmt = $conn->prepare("UPDATE users SET special=null WHERE id=:id");
$stmt->bindParam(":id", $person);
$stmt->execute();
if($stmt){
$person = getUserInfo($person)->name;
msg("$person's admin rights have been revoked");
header("Location: /admin/portal/manage.php");
}else{
msg("Error revoking $person's admin rights");
reportError("Error revoking admin rights from $person in /admin/portal/manage.php");
header("Location: /admin/portal/manage.php");
}
}else{
msg("That person is not an admin");
header("Location: /admin/portal/manage.php");
}
}
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>ADD ADMIN</h2>
<form action="manage.php" method=POST>
<input type=text name=person placeholder="User's ID">
<button type=submit>Add admin</button>
</form>
<br>
</div>
<div class="card noHover center">
<h2>REMOVE ADMIN</h2>
<p><?php
conn();
$stmt = $conn->prepare("SELECT * FROM users WHERE special='admin'");
$stmt->execute();
$row = $stmt->fetchAll();
if(sizeof($row)==0){
echo "<i>No admins.</i>";
}
foreach($row as $person){
echo "<a class=deletable href=/admin/portal/manage.php?delUser=".$person["id"].">".$person["name"]."</a><br>";
}
?></p>
</div>
</div>
</body>
</html>

126
admin/portal/post.css Normal file
View File

@@ -0,0 +1,126 @@
/* ------------- Global post ------------- */
.container{
width: 60%;
margin: 2% auto 0 auto;
color: #333;
background-color: white;
margin-bottom: 2em;
border-radius: 0.2em;
padding: 1em 2em;
line-height: 1.3em;
}
.container>*{
border-radius: 0.3em;
}
/* General forum stuff */
.forumLink{
text-decoration: none;
}
/* ------------- Post ------------- */
/* Title, username, time posted */
.title>h2{
margin: 0.5em 0;
line-height: 1.2em;
}
.info>*{
font-size: 0.75em;
color: #aaa;
margin: 0;
display: inline-block;
}
.userlink:hover, .postType:hover{
text-decoration: underline;
}
.postType{
color: #888;
font-weight: bold;
margin: 0 0.5em 0 0.2em;
}
/* Text and image */
.content>p{
margin: 0;
}
.forum.card{
margin-bottom: 1em;
}
.postImage{
margin-top: 1em;
width: 100%;
border-radius: 0.3em;
}
.postDocPreview{
margin-top: 1em;
width: 100%;
border-radius: 0.2em;
border: 1px solid #999;
height: 50vh;
}
#show:hover, #hide:hover{
cursor: pointer;
}
#hideImgs{
display: none;
}
#hideImgs ~ #hide{
display: block;
}
#hideImgs ~ #show{
display: none;
}
#hideImgs:checked ~ #hide{
display: none;
}
#hideImgs:checked ~ #show{
display: block;
}
#hideImgs ~ label{
margin-top: 2em;
color: #00d09f;
text-align: center;
font-size: 0.9em;
margin-bottom: 0;
}
#hideImgs:checked ~ .toggleView{
display: none;
}
/* Fixing tag-padding issue
.tags>p{
padding: 0em 0.5em;
}*/
/* Reporting and saving */
.postBottom{
display: block;
height: 1.5em;
font-size: 1em;
padding: 0 1em;
display: grid;
align-content: center;
grid-template-columns: 1fr 1fr;
}
.postReport, .postActions{
margin: 0;
font-size: 0.8em;
color: #999;
}
.postReport{
color: #922;
text-decoration: none;
}
.postActions>a{
color: #888;
text-decoration: none;
}
.postActions>a:hover,.postReport:hover{
text-decoration: underline;
}
.postSave{
color: inherit;
text-decoration: none;
float: right;
}
.postSave>*{
float: right;
}

View File

@@ -0,0 +1,86 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("admin");
conn();
//Getting and storing the post info to echo later
$post = getPostInfo($_GET["post"]);
$poster_id = $post->poster_id;
$title = $post->title;
$content = decodeUserLink($post->content);
$section = $post->section=="math"?"HL Math":ucwords($post->section);
$section = $post->section=="none"?"":ucwords($post->section);
$type = $post->type=="other"?"":strtolower($post->type);
$type = $section==""?ucwords($type):$type;
$section = $section==$type?"No topic":$section;
$date = $post->date;
$images = $post->image;
$poster = getUserInfo($poster_id)->name;
//Clearing post of reports
if($_GET["clearPost"]){
$stmt = $conn->prepare("UPDATE forums SET reports=null WHERE post_id=:id");
$stmt->bindParam(":id", $_GET["post"]);
$stmt->execute();
if($stmt){
msg("Post cleared of all reports");
header("Location: /forum/post/?post=".$_GET["post"]);
}
}
?>
<!DOCTYPE html>
<html>
<?php
$css2 = 'post';
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div class="container center">
<h2>What should happen to the below post?</h2>
<p>Should this post be <a class=color href=/post/delete.php?post=<?=$_GET["post"]?>>deleted</a> or <a class=color href=?clearPost=1&post=<?=$_GET["post"]?>>cleared of reports</a>?</p>
</div>
<div class="container card noHover">
<div id=post>
<div class="forum card noShadow">
<div class=info>
<p onclick="document.location.href = '/search/?q=<?=$section;?>:+'; return false" class=postType><?=$section." ".$type; ?></p>
<p>Posted <?=makeDate($date);?> by <span onclick="document.location.href = '/user/?user=<?=$poster_id;?>'; return false" class=userlink><?=$poster;?></span></p>
</div>
<div class=title>
<h2><?=$title;?></h2>
</div>
<div class=content>
<p>
<?=$content;?>
<?php
if($images != NULL){
echo "<input type=checkbox id=hideImgs>
<label for=hideImgs id=hide class=noSelect>HIDE ATTACHMENTS</label>
<label for=hideImgs id=show class=noSelect>SHOW ATTACHMENTS</label>";
foreach(explode(",", substr($images, 0, -1)) as $file){
//substr gets rid of the last comma, explode makes the array
$exType = substr($file, strpos($file, '.')+1);
$docFiles = ["doc", "docx", "pdf"];
$imgFiles = ["jpg", "jpeg", "png"];
//image stuff
if(in_array($exType, $docFiles)){
echo "<iframe class='postDocPreview toggleView' src=https://docs.google.com/gview?url=http://ib.lukeogburn.com/forum/images/$file&embedded=true></iframe>";
//<embed src="file_name.pdf" width="800px" height="2100px" />
}else if(in_array($exType, $imgFiles)){
echo "<img class='postImage toggleView' src=/forum/images/$file>";
}
}
}
?>
</p>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,32 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("owner");
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>USERS:</h2>
<?php
conn();
$stmt = $conn->prepare("SELECT name FROM users WHERE id <> '51155'");
$stmt->execute();
$res = $stmt->fetchAll();
foreach($res as $person){
$person = getUserInfoByName($person[0]);
$name = $person->name;
$id = $person->id;
echo "<p><a class=noStyle href=aboutUser.php?user=$id>$name</a></p>";
}
?>
</div>
</body>
</html>

View File

@@ -0,0 +1,61 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
restrictAccess("admin");
//Unbanning the user
if(isset($_GET["user"])){
conn();
$person = $_GET["user"];
$stmt = $conn->prepare("SELECT special FROM users WHERE id=:id");
$stmt->bindParam(":id", $person);
$stmt->execute();
$res = $stmt->fetch(PDO::FETCH_ASSOC);
if($res["special"]=="banned"){
$person = $_GET["user"];
$stmt = $conn->prepare("UPDATE users SET special=null, ban_reason=null WHERE id=:id");
$stmt->bindParam(":id", $person);
$stmt->execute();
if($stmt){
$person = getUserInfo($person)->name;
msg("$person has been unbanned");
header("Location: /admin/portal/unbanUser.php");
}else{
msg("Error unbanning $person");
reportError("Error unbanning $person in /admin/portal/manage.php");
header("Location: /admin/portal/unbanUser.php");
}
}else{
msg("$person was never banned");
header("Location: /admin/portal/unbanUser.php");
}
}
?>
<!DOCTYPE html>
<html>
<?php
$css = "/admin/portal/admin";
include "../../res/head";
?>
<body>
<?php
include "../../res/top";
?>
<div id=monoContainer>
<div class="card noHover center">
<h2>UNBAN USER</h2>
<p><?php
conn();
$stmt = $conn->prepare("SELECT * FROM users WHERE special='banned'");
$stmt->execute();
$row = $stmt->fetchAll();
if(sizeof($row)==0){
echo "<i>No banned users :D</i>";
}
foreach($row as $person){
echo "<a class=deletable href=/admin/portal/unbanUser.php?user=".$person["id"].">".$person["name"]."</a><br>";
}
?></p>
</div>
</div>
</body>
</html>