Sig Of The Week

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
This was a Tutorial written to speed up the process of creating, judging, and managing a SOTW competition (specifically for GFX sites). My friend requested this so, he let me make it public.

Quick Features:
- Easily customized
- Unlimited number of weeks
- One-click judging
- Automatic creation of new weeks

Create a folder called sotw so you can put these files you create, in.

Open up any text editor and place this code in and save it as config.php.

Code:
<?
// This script was made by Josh Rendek @ http://gamersnetwork.us/ Do not remove any of the copyrights please.
$server = 'localhost'; // Usually localhost
$user = ''; // the username to access your database
$pass = ''; // the password to access your database
$db = ''; // the database the files will be stored on
$dbLink = mysql_pconnect($server, $user, $pass) or die("Couldnt select user"); 
$dbC = mysql_select_db($db, $dbLink) or die("Couldnt select database"); 
$adminUser = 'demo';
$adminPass = 'pass';
$sotwPath = '/home/gamnet/www/scripts/gnSOTW/'; // make sure you leave the trailing slash
$copyright = "<center><br><b>Created by:</b> <a href='http://x10hosting.com/'>o0slowpaul0o</a></center>";
?>

Open up your text editor again and save this as installer.php

Code:
<?
include('config.php');
mysql_query("
 CREATE TABLE sotw_submits(
id tinyint( 5 ) NOT NULL AUTO_INCREMENT ,
user varchar( 255 ) NOT NULL default '',
sig varchar( 255 ) NOT NULL default '',
website varchar( 255 ) NOT NULL default '',
wid tinyint( 5 ) NOT NULL default '0',
winner enum( 'Y', 'N' ) NOT NULL default 'N',
UNIQUE KEY id( id )
) TYPE = MYISAM
") or die("Error during install: <b>".mysql_error()."</b>");

mysql_query("
CREATE TABLE sotw_week (
  wid tinyint( 5 ) NOT NULL AUTO_INCREMENT ,
  UNIQUE KEY wid (wid)
) TYPE=MyISAM
        
") or die("Error during install: <b>".mysql_error()."</b>");

echo "Sucesfully installed.";
					echo "Week 1 created automatically.<br>";
					mysql_query("INSERT INTO sotw_week VALUES ('null')") or die(mysql_error());
					echo "New week table created.<br>";
					$wid = 1;
					mkdir($sotwPath.$wid, 0777);
					echo "New week folder created.<br.";
					
?>


Open up your text editor again and save this as sotw_judge.php

Code:
<?
include('config.php');
// Admin check
  if (!isset($_SERVER['PHP_AUTH_USER'])) {
   header('WWW-Authenticate: Basic realm="gnSOTW v1.0"');
   header('HTTP/1.0 401 Unauthorized');
   echo 'You are not authorized to be here.';
   exit;
  } else {
  $check_user = $_SERVER['PHP_AUTH_USER'];
  $check_pass = $_SERVER['PHP_AUTH_PW'];
	if($adminUser == $check_user && $adminPass == $check_pass){
			





					$sql = "SELECT * FROM sotw_week ORDER BY wid DESC LIMIT 1";
					$q = mysql_query($sql);
					while($row = mysql_fetch_array($q)){
					$wid = $row['wid'];
					}
					
					if($admin == 'judge' && $wid && $sig){
					$sql = "UPDATE sotw_submits SET winner='Y' WHERE sig='$sig'";
					mysql_query($sql) or die(mysql_error());
					echo "SOTW Posted, new week created automatically.<br>";
					mysql_query("INSERT INTO sotw_week VALUES ('null')") or die(mysql_error());
					echo "New week table created.<br>";
					$wid = $wid+1;
					mkdir($sotwPath.$wid, 0777);
					echo "New week folder created.<br.";
					}
					?>
					
					<center>Click on the sig to post it as the winner:<br><br>
					<?
					$i = 1;
					if ($handle = opendir($sotwPath.$wid.'')) {
					   while (false !== ($file = readdir($handle))) { 
						   if ($file != "." && $file != "..") { 
							echo "<font color='white'>".$i++.".</font> <a href='?admin=judge&week=".$wid."&sig=".$file."'><img src='".$wid."/".$file."' border=0 /> </a><br>"; 
						   } 
					   }
					   closedir($handle); 
					}
					
					}
					}
					
					
					echo $copyright;
?></center>

Open up your text editor again and save this as sotw_view.php

Code:
<script language="JavaScript" src='pop.js' type="text/javascript"></script><center>
<?
include('config.php');
$sql = "SELECT * FROM sotw_week ORDER BY wid DESC LIMIT 1";
$q = mysql_query($sql);
while($row = mysql_fetch_array($q)){
$wid = $row['wid'];
}
$i = 1;
if ($handle = opendir($wid.'/')) {
   while (false !== ($file = readdir($handle))) { 
       if ($file != "." && $file != "..") { 
		echo "<font color='white'>".$i++.".</font> <a href='".$wid."/$file' target='new'><img src='".$wid."/".$file."' border=0 /> </a><br>"; 
       } 
   }
   closedir($handle); 
}
echo $copyright;
?></center>

Open up your text edit or again and save this as sotw_submit.php

Code:
<center><table width="90%"  border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td class='header2'>Submit Signature</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class='smalltxt'>
	<?
	include('config.php');
	if ("image/pjpeg" == $_FILES['userfile']['type'] || "image/jpeg" == $_FILES['userfile']['type'] || "image/gif" == $_FILES['userfile']['type'])
	{
	$sql = "SELECT * FROM sotw_week ORDER BY wid DESC LIMIT 1";
	$q = mysql_query($sql);
	while($row = mysql_fetch_array($q)){
	$wid = $row['wid'];
	}
	
	$sigs = $sotwPath.$wid."/";
	$uploadfile = $sigs . $_FILES['userfile']['name'];
	if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
	$img = $_FILES['userfile']['name'];
	$name = $_FILES['userfile']['name'];
	$debug = $_FILES;
	
	$sql = "INSERT INTO sotw_submits VALUES ('NULL', '$user', '$name', '$website', '$wid', 'N')";
	mysql_query($sql) or die("Couldnt add sig to DB - ".mysql_error());
	@chmod($sotwPath.$wid."/".$name, 0777);
	
   print "File is valid, and was successfully added to this weeks contest (Week #".$wid.").";
	}else{ echo "File couldnt be uploaded. <b>Debug:</B><br>";
	print_r($_FILES);
	 }
	}
?>
	<form action="" method="post" enctype="multipart/form-data" name="form1">
  <strong>User</strong>: <input type="text" name="user"><br>
  <strong>Sig</strong>:
  <input name="userfile" type="file">
  <br>
  <strong>Website</strong>:
  <input type="text" name="website">
  <br>
  <input type="submit" name="Submit" value="Submit Sig">
    </form></td>
  </tr>
</table>
<? echo $copyright; ?>

Open up your text editor again and save this as sotw_winner.php

Code:
<?
include('config.php');
?>
<script src="pop.js" type="text/javascript"></script>
<?
$sql = "SELECT * FROM sotw_week ORDER BY wid DESC LIMIT 1";
$q = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($q)){
$lastweek = $row['wid'] - 1;
}
$sql = "SELECT * FROM sotw_submits WHERE wid='$lastweek' AND winner='Y'";
$q = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($q)){
echo "<a href='".$lastweek."/".$row['sig']."' target=new><img src='".$lastweek."/".$row['sig']."' width='65%' border=1 target='new' /></a>";
}
echo '
<br>
    <a href="javascript:pop(\'sotw_submit.php\', 400, 100);">Submit Sig</a><br>
	<a href="sotw_view.php?sotw=view">View This Weeks Entries</a>';
	echo $copyright;
?>

Last time now, open up a text editor and save this as pop.js

Code:
function pop(URL, w, h) {
	  window.open(URL,'refrence','width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes'); 
}

Last thing now is to install. Open up config.php and edit your database needs. Upload it to your server and then run www.yourdomain.com/sotw/installer.php. Then your done!

Demo: Would release a demo, but I can't give out my domain till it's finished. The first person to give a demo can get rid of the copyright. :)

Please NOTE: Please do not remove the copyright for x10hosting. I had put it there to gain x10 more users than they usally do. Also, I might not be posting another tutorial for abit. Someone on this site requested a mod for IPB. So i gotta get work and see if I can do it.
 
Last edited:

Akkarin

New Member
Messages
1,654
Reaction score
0
Points
0
Wow, this looks really useful I'll try it out when I can!
 

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
Aha! I knew you would see this quick, I noticed you had a GFX site, so i wanted to help alittle by making a Tut. :D
 

n4tec

Active Member
Messages
3,312
Reaction score
0
Points
36
thanx for the tutorial and thanx for all your tutorials.. when i lauch my other domain which is about graphics i will certainly use you tut...
 
Last edited:
Top