Update database structure part two & like system

master
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";
progressBar(25,400,"25%");
$id=$_GET['id'];
$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=\"checkbox\" name=\"override\"> Create account if it does not exist.<br />";
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{
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 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>
<table style="border-spacing: 0; margin: 0; padding: 0; border: 0; width: 100%;">
<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">
<span class="inbar_main">
<ul>
<li class="navlink_normal"><a href="http://minetest.net/index.php">Home</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>
<li class="navlink_normal"><a href="http://minetest.net/index.php">Back to Minetest</a></li>
</ul>
</span>
<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
$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_inner\" style=\"width: ".(($percent/100)*$length)."px;\"></div>";
echo "<div class=\"progress_caption\">$caption</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){
echo "\n\n\n<!-- function likeMod($id,$user,$handle) is executing:\n";
if (is_numeric($id)==false){
echo "[Error]: is not numeric\n";
return 0;
}
function likeMod($id,$user,$handle,$change){
$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'");
$mod = mysql_fetch_array($mod);
$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);
$user_d = getUser($user,$handle);
$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)
return false;
if (!$vote){
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 (!$user_d){
echo "[Error]: user is null\n";
return 0;
}
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'");
}
if ($change){
mysql_query("UPDATE votes SET liked=$nlike WHERE owner=$owner_id AND mod_id=$id",$handle);
updateLikes($id,$handle);
header("location: viewmod.php?id=$id");
}else{
return $liked;
}
}
}
?>

View File

@ -8,7 +8,10 @@ $act=$_GET['action'];
if ($act=="like"){
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;
@ -45,14 +48,7 @@ $dnw_content=true;
include "scripts/pageheader.php";
if (is_member_moderator($_SESSION['user'],$handle)){
$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']){
if (is_member_moderator($_SESSION['user'],$handle) || getUserId($_SESSION['user'],$handle)==$row['owner']){
$links="<li><a href=\"editentry.php?id=$id\">Edit</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){
$like_ext="";
if (checkLike($_SESSION['user'],$id,5,$handle)==true)
if (likeMod($id,$_SESSION['user'],$handle,false)==true)
$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>";
@ -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";
}
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>";