Update database structure part two & like system

This commit is contained in:
Rubenwardy 2013-03-05 18:04:29 +00:00
parent 23a129c84e
commit 18457cb356
8 changed files with 70 additions and 91 deletions

View File

@ -8,8 +8,6 @@ include "scripts/pageheader.php";
echo "<h1>Admin</h1>\n"; echo "<h1>Admin</h1>\n";
progressBar(25,400,"25%");
$id=$_GET['id']; $id=$_GET['id'];
$mode=$_GET['mode']; $mode=$_GET['mode'];
@ -73,6 +71,12 @@ if($mode=="owner"){
echo "<input type=\"text\" name=\"owner\" size=50 value=\"{$qr}\"><br /><br />"; echo "<input type=\"text\" name=\"owner\" size=50 value=\"{$qr}\"><br /><br />";
echo "<input type=\"checkbox\" name=\"override\"> Create account if it does not exist.<br />"; echo "<input type=\"checkbox\" name=\"override\"> Create account if it does not exist.<br />";
echo "<br /><input type=\"submit\" value=\"Change\"></form></center>"; echo "<br /><input type=\"submit\" value=\"Change\"></form></center>";
}else if ($mode=="likes"){
$res = mysql_query("SELECT * FROM mods",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.tags for '$query'");
while ($hash = mysql_fetch_assoc($res)){
updateLikes($hash['mod_id'],$handle);
}
echo "script complete";
}else{ }else{
echo "Welcome to the admin console."; echo "Welcome to the admin console.";
} }

View File

@ -88,6 +88,12 @@ If you have any questions at all, do not hesitate to contact us on <a href="http
<div class="constrain"> <div class="constrain">
<div style="clear: both;"></div> <div style="clear: both;"></div>
<h3><a href="viewmod.php?id=random">Random Extension</a></h3>
<p>
Why dont you try something new? Click the above link to go randomly to one of our extensions.
</p>
<br><br>
<h3>Hottest Extensions</h3> <h3>Hottest Extensions</h3>
<table style="border-spacing: 0; margin: 0; padding: 0; border: 0; width: 100%;"> <table style="border-spacing: 0; margin: 0; padding: 0; border: 0; width: 100%;">
<tr> <tr>

7
scripts/countlikes.php Normal file
View File

@ -0,0 +1,7 @@
<?php
function countLikes(){
}
?>

View File

@ -26,10 +26,7 @@
<div class="constrain"> <div class="constrain">
<span class="inbar_main"> <span class="inbar_main">
<ul> <ul>
<li class="navlink_normal"><a href="http://minetest.net/index.php">Home</a></li> <li class="navlink_normal"><a href="http://minetest.net/index.php">Back to Minetest</a></li>
<li class="navlink_normal"><a href="http://minetest.net/news.php">News</a></li>
<li class="navlink_normal"><a href="http://minetest.net/download.php">Download</a></li>
<li class="navlink_normal"><a href="http://minetest.net/contribute.php">Contribute</a></li>
</ul> </ul>
</span> </span>
<span class="inbar_separator"> <span class="inbar_separator">

View File

@ -31,5 +31,5 @@ $emailver_mod=true; // Require Email Vertification to post
$emailver_login=false; // Require Email Vertification to log in $emailver_login=false; // Require Email Vertification to log in
$mt_lock_down=false; // if true, only admins can access forum $mt_lock_down=false; // if true, only admins can access forum
$mt_lock_msg="Message from Rubenwardy: Updating database"; $mt_lock_msg="Message from Rubenwardy: Updating database and rating systems";
?> ?>

View File

@ -202,10 +202,16 @@ function progressBar($percent,$length,$caption){
echo "<div class=\"progressbar\" style=\"width: ".$length."px;\">"; echo "<div class=\"progressbar\" style=\"width: ".$length."px;\">";
echo "<div class=\"progressbar_inner\" style=\"width: ".(($percent/100)*$length)."px;\"></div>"; echo "<div class=\"progressbar_inner\" style=\"width: ".(($percent/100)*$length)."px;\"></div>";
echo "<div class=\"progress_caption\">$caption</div>"; echo "<div class=\"progress_caption\">$caption</div>";
echo "</div>"; echo "</div>";
} }
function updateLikes($id,$handle){
$res = mysql_query("SELECT * FROM votes WHERE mod_id=$id AND liked=true",$handle);
$result = mysql_num_rows($res);
mysql_query("UPDATE mods SET likes=$result WHERE mod_id=$id",$handle);
}
?> ?>

View File

@ -6,81 +6,34 @@
// //
function likeMod($id,$user,$handle){ function likeMod($id,$user,$handle,$change){
echo "\n\n\n<!-- function likeMod($id,$user,$handle) is executing:\n"; $mod = mysql_query("SELECT * FROM mods WHERE mod_id=$id",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'");
if (is_numeric($id)==false){ $mod = mysql_fetch_array($mod);
echo "[Error]: is not numeric\n";
return 0;
}
$res = mysql_query("SELECT * FROM mods WHERE mod_id=$id",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'"); $user_d = getUser($user,$handle);
$row = mysql_fetch_array($res); $owner_id= $user_d["id"];
$vote = mysql_query("SELECT * FROM votes WHERE owner=$owner_id AND mod_id=$id",$handle) or SQLerror("MySQL Query Error","Error on searching database.votes");
$vote = mysql_fetch_array($vote);
if (!$row) if (!$vote){
return false; if ($change){
mysql_query("INSERT INTO votes (mod_id,owner,liked) VALUES ($id,$owner_id,true)",$handle) or SQLerror("MySQL Query Error","Error on adding like");
header("location: viewmod.php?id=$id");
updateLikes($id,$handle);
}else{
return false;
}
}else{
$liked=$vote['liked']==true;
$nlike = 1-$liked;
$user_d = getUser($user,$handle); if ($change){
mysql_query("UPDATE votes SET liked=$nlike WHERE owner=$owner_id AND mod_id=$id",$handle);
if (!$user_d){ updateLikes($id,$handle);
echo "[Error]: user is null\n"; header("location: viewmod.php?id=$id");
return 0; }else{
} return $liked;
}
echo "[Notice]: calculating\n"; }
if (strstr($user_d['liked'],$row['name;'].",")){
echo "-decreasing likes\n";
changeLikes($id,$user,-1,$handle);
}else{
echo "-increasing likes\n";
changeLikes($id,$user,1,$handle);
}
echo "\n\nend of execution-->\n\n\n";
}
function checkLike($user,$id,$col,$handle){
if (is_numeric($id)==false){
echo "<!--[Error]: is not numeric-->\n";
return 0;
}
$res = mysql_query("SELECT * FROM mods WHERE mod_id=$id",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'");
$row = mysql_fetch_row($res);
$user_d = getUser($user,$handle);
if (!$user_d){
return 0;
}
return strstr($user_d[$col],$row['name'].",");
}
function changeLikes($id,$user,$amount,$handle){
echo "\n\n\n function changeLikes($id,$user,$amount,$handle) is executing\n";
$res = mysql_query("SELECT * FROM mods WHERE mod_id=$id",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'");
$row = mysql_fetch_array($res);
if (!$row)
return false;
$user_d = getUser($user,$handle);
if (!$user_d){
echo "[Error]: user is null\n";
return 0;
}
if ($amount==1){
$tmp=$user_d['liked'].$row['name'].",";
mysql_query("UPDATE users SET liked='$tmp' WHERE name='$user'",$handle) or die("Error on searching database.users.name for '$user'");
$tmp=$row['likes']+1;
mysql_query("UPDATE mods SET likes=$tmp WHERE mod_id=$id",$handle) or die("Error on searching database.mods.mod_id for '$id'");
}else{
$tmp=str_replace($row['name'].",","",$user_d['liked']);
mysql_query("UPDATE users SET liked='$tmp' WHERE name='$user'",$handle) or die("Error on searching database.users.name for '$user'");
$tmp=$row['likes']-1;
mysql_query("UPDATE mods SET likes=$tmp WHERE mod_id=$id",$handle) or die("Error on searching database.mods.mod_id for '$id'");
}
} }
?> ?>

View File

@ -8,7 +8,10 @@ $act=$_GET['action'];
if ($act=="like"){ if ($act=="like"){
echo "Liking"; echo "Liking";
likeMod($id,$_SESSION['user'],$handle); likeMod($id,$_SESSION['user'],$handle,true);
}else if ($act=="update"){
updateLikes($id,$handle);
header("location: viewmod.php?id=$id");
} }
$res=0; $res=0;
@ -45,14 +48,7 @@ $dnw_content=true;
include "scripts/pageheader.php"; include "scripts/pageheader.php";
if (is_member_moderator($_SESSION['user'],$handle)){ if (is_member_moderator($_SESSION['user'],$handle) || getUserId($_SESSION['user'],$handle)==$row['owner']){
$links="<li><a href=\"admin.php?mode=owner&id=$id\">Change Owner</a></li>";
$links.="<li><a href=\"editentry.php?id=$id\">Edit</a></li>";
$links.="<li><a href=\"3mrelinc.php?id=$id\">Increase 3m Release</a></li>";
$links.="<li><a href=\"deleteentry.php?id=$id\">Delete</a></li>";
}elseif (getUserId($_SESSION['user'],$handle)==$row['owner']){
$links="<li><a href=\"editentry.php?id=$id\">Edit</a></li>"; $links="<li><a href=\"editentry.php?id=$id\">Edit</a></li>";
$links.="<li><a href=\"3mrelinc.php?id=$id\">Increase 3m Release</a></li>"; $links.="<li><a href=\"3mrelinc.php?id=$id\">Increase 3m Release</a></li>";
@ -85,7 +81,7 @@ echo "<h1>Similar Code Part of 0.4.4</h1>Only use this for versions before this.
if (is_logged_in()==true){ if (is_logged_in()==true){
$like_ext=""; $like_ext="";
if (checkLike($_SESSION['user'],$id,5,$handle)==true) if (likeMod($id,$_SESSION['user'],$handle,false)==true)
$like_ext="_high"; $like_ext="_high";
echo "<p><a href=\"viewmod.php?id=$id&action=like\"><img src=\"images/like_mod$like_ext.png\" alt=\"like\" /></a></p>"; echo "<p><a href=\"viewmod.php?id=$id&action=like\"><img src=\"images/like_mod$like_ext.png\" alt=\"like\" /></a></p>";
@ -124,6 +120,16 @@ echo "<h1>Similar Code Part of 0.4.4</h1>Only use this for versions before this.
echo "<div class='bar_p'><ul>$links</ul></div>\n"; echo "<div class='bar_p'><ul>$links</ul></div>\n";
} }
if (is_member_moderator($_SESSION['user'],$handle)){
echo "<div class='bar_title'>\n";
echo "Admin Scripts\n";
echo "</div>\n";
echo "<div class='bar_p'><ul>";
echo "<li><a href=\"admin.php?mode=owner&id=$id\">Change Owner</a></li>";
echo "<li><a href=\"viewmod.php?id=$id&action=update\">Update Like</a></li>";
echo "</ul></div>\n";
}
echo "<p>"; echo "<p>";