jhuesser/bzu-jodel-clone

View on GitHub
user.php

Summary

Maintainability
A
1 hr
Test Coverage
<?php
session_start();
//include required functions & config, set meta data (title, stylesheet)
require 'functions/apicalls.php';
$config = require('config.php');
$title = "My profile | SocialDomayn";
$stylesheet = "jodel.css";
include 'functions/header.php';
 
//checks if user wants to logout
if(isset($_GET['logout'])) {
session_destroy();
//log out the user ^ and redirect to login \/
header('Location: ' . $config->baseUrl . 'login.php');
}
$userid = $_SESSION['userid'];
?>
 
<!-- main menu-->
<a class="forker" target="_blank" href="https://github.com/jhuesser/bzu-jodel-clone"><img class="forker" style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
<div id="top"></div>
 
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link" href="jodels.php"><i class="fa fa-chevron-left" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:window.location.reload();"><i class="fa fa-refresh" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="user.php"><i class="fa fa-user" aria-hidden="true"></i><?php echo $_SESSION['karma'];?></a>
</li>
<li class="nav-item">
<a class="nav-link" href="?logout=1"><i class="fa fa-sign-out" aria-hidden="true"></i></a>
</li>
</ul>
 
<div class="test"></div>
<!-- end main menu -->
<?php
if(isset($_SESSION['errorMsg'])) {
?>
<!-- error messages -->
<div class="alert alert-danger" role="alert">
<strong>Holy guacamole!</strong> <?php echo $_SESSION['errorMsg'];?>
</div>
<!-- end error messages -->
<?php
 
}
?>
<!-- user functions -->
<div class="container">
<h1>
<?php echo "Hello " . $_SESSION['username'];?>
</h1>
<div class="list-group">
<a href="<?php echo $config->baseUrl;?>jodels.php?sort=my" class="list-group-item list-group-item-action">My <?php echo $config->app_vocabulary['posts'];?></a>
<a href="<?php echo $config->baseUrl;?>jodels.php?sort=mycomms" class="list-group-item list-group-item-action">My <?php echo $config->app_vocabulary['comments'];?></a>
<a href="<?php echo $config->baseUrl;?>jodels.php?sort=myvotes" class="list-group-item list-group-item-action">My votes</a>
</div>
<!-- end user functions -->
 
<?php
//get the account type of the user and set the name of the user role. also get user caps.
switch($_SESSION['acctype']){
case 0:
$accdesc = $config->app_vocabulary['baned'];
break;
case 1:
$accdesc = $config->app_vocabulary['jodler'];
$caps = $config->user_caps->user;
break;
case 2:
$accdesc = $config->app_vocabulary['mod'];
$caps = $config->user_caps->mod;
break;
case 3:
$accdesc = $config->app_vocabulary['admin'];
$caps = $config->user_caps->admin;
break;
case 4:
$accdesc = $config->app_vocabulary['superadmin'];
$caps = $config->user_caps->superadmin;
break;
default:
$accdesc = "Well you are a funny type of user.";
}
$_SESSION['my_caps'] = $caps;
 
//show user tools
echo "<h2>You are " . $accdesc . ". Here are your tools:</h2>";
?>
 
 
<div class="list-group">
<?php
if($caps['mod_posts'] == true){
//is mod
echo '<a href="user/mod.php" class="list-group-item list-group-item-action">Moderation</a>';
$hascaps = true;
}
if($caps['reset_paswd'] == true){
//can change passwords
echo '<a href="user/resetpasswd.php" class="list-group-item list-group-item-action">Reset user password</a>';
$_SESSION['caps_reset_paswd'] = true;
$hascaps = true;
}
Consider simplifying this complex logical expression.
if($caps['promote_to_mod'] == true || $caps['promote_to_admin'] == true || $caps['promote_to_superadmin'] == true || $caps['promote_to_user'] == true || $caps['ban'] == true || $caps['delete_users'] == true || $caps['change_karma'] == true ) {
//can manage users
echo '<a href="user/usermgmt.php" class="list-group-item list-group-item-action">Usermanagement</a>';
$hascaps = true;
}
if($caps['delete_posts'] == true || $caps['change_post_score'] == true || $caps['change_votes'] == true || $caps['edit_posts'] == true){
//can manage posts
echo '<a href="user/postmgmt.php" class="list-group-item list-group-item-action">Postmanagement</a>';
$hascaps = true;
}
if($caps['add_color'] == true){
//can manage colors
echo '<a href="user/colormgmt.php" class="list-group-item list-group-item-action">Add a color</a>';
$hascaps = true;
}
if($caps['create_admin_notice'] == true){
//can manage admin notices
echo '<a href="user/adminote.php" class="list-group-item list-group-item-action">Create admin notice</a>';
$hascaps = true;
}
if(!isset($hascaps)){
//user has no caps
echo '<div class="alert alert-warning" role="alert"><strong>Oh snap!</strong> You don\'t have any tools, go create good vibes and incerase your ' . $config->app_vocabulary['karma'] . ' to recive some.</div>';
}
?>
</div>