View file wapirate/xhtml/beauty_contest.php

File size: 79.41Kb
<?php

// Beauty Contest, created by LORD



// File type version ///////////////

if (isset($_GET['wap']))

	define("VERS", "wap");

else define("VERS", "web");



define("UPERM", "3");

////////////////////////////////////



header("Cache-Control: no-cache, must-revalidate");

header("Pragma: no-cache");

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';

?>



<html xmlns="http://www.w3.org/1999/xhtml" align="center">



<?php // Functions ///////////////////////////////////////////////////////////////////////////////////



function createThumb($image, $target, $width = 200, $height = 200, $quality = 50)

{

	// This sets it to a .jpg, but you can change this to png or gif 

	//header('Content-type: image/jpeg'); 

	

	// Setting the resize parameters

	list($width_orig, $height_orig) = getimagesize($image);

	

	if ($width_orig < $height_orig)

	   $width = ($height / $height_orig) * $width_orig;

	else

	   $height = ($width / $width_orig) * $height_orig;

	

	

	// Creating the Canvas 

	$newImg= imagecreatetruecolor($width, $height); 

	$source = imagecreatefromjpeg($image); 

	

	// Resizing our image to fit the canvas 

	imagecopyresampled($newImg, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); 

	

	// Outputs a jpg image, you could change this to gif or png if needed

	$res = imagejpeg($newImg, $target, $quality);

	imagedestroy($newImg);

	

	return $res;

}



// delete file from host -----------------------

function delfile($itemurl, $site, $location = '../')

{

	if (stristr($itemurl, $site))

	{

		$fname = str_replace($site, $location, $itemurl);

		

		if (file_exists($fname) && is_file($fname))

		{

			unlink($fname);

		}

	}

}

// sort Winners by activity -----------------------

function sortWinners1($a, $b)

{

	global $winners;

	static $keys;

	if (!$keys) $keys = array_keys($winners[1]);

	$x = array_search($a, $keys);

  	$y = array_search($b, $keys);

	

	if ($winners[1][$a] == $winners[1][$b])

	{

		list($uid1) = mysql_fetch_array(mysql_query("SELECT user_id1 FROM beauty_candidates WHERE id=$a"));

		list($uid2) = mysql_fetch_array(mysql_query("SELECT user_id1 FROM beauty_candidates WHERE id=$b"));

		

		list($uactivity1) = mysql_fetch_array(mysql_query("SELECT otime FROM ibwf_users WHERE id=$uid1"));

		list($uactivity2) = mysql_fetch_array(mysql_query("SELECT otime FROM ibwf_users WHERE id=$uid2"));

		

		if ($uactivity1 > $uactivity2) return -1;

		else return 1;

	}

	return ($x < $y ? -1 : 1);

}

//

function sortWinners2($a, $b)

{

	global $winners;

	static $keys;

	if (!$keys) $keys = array_keys($winners[2]);

	$x = array_search($a, $keys);

  	$y = array_search($b, $keys);

	

	if ($winners[2][$a] == $winners[2][$b])

	{

		list($uid1) = mysql_fetch_array(mysql_query("SELECT user_id1 FROM beauty_candidates WHERE id=$a"));

		list($uid2) = mysql_fetch_array(mysql_query("SELECT user_id1 FROM beauty_candidates WHERE id=$b"));

		

		list($uactivity1) = mysql_fetch_array(mysql_query("SELECT otime FROM ibwf_users WHERE id=$uid1"));

		list($uactivity2) = mysql_fetch_array(mysql_query("SELECT otime FROM ibwf_users WHERE id=$uid2"));



		if ($uactivity1 > $uactivity2) return -1;

		else return 1;

	}



	return ($x < $y ? -1 : 1);

}

//

function sortWinners3($a, $b)

{

	global $winners;

	static $keys;

	if (!$keys) $keys = array_keys($winners[3]);

	$x = array_search($a, $keys);

  	$y = array_search($b, $keys);

	

	if ($winners[3][$a] == $winners[3][$b])

	{

		list($uid1_a, $uid1_b) = mysql_fetch_array(mysql_query("SELECT user_id1,user_id2 FROM beauty_candidates WHERE id=$a"));

		list($uid2_a, $uid2_b) = mysql_fetch_array(mysql_query("SELECT user_id1,user_id2 FROM beauty_candidates WHERE id=$b"));

		

		list($uactivity1) = mysql_fetch_array(mysql_query("SELECT sum(otime) FROM ibwf_users WHERE id=$uid1_a OR id=$uid1_b"));

		list($uactivity2) = mysql_fetch_array(mysql_query("SELECT sum(otime) FROM ibwf_users WHERE id=$uid2_a OR id=$uid2_b"));

		

		if ($uactivity1 > $uactivity2) return -1;

		else return 1;

	}



	return ($x < $y ? -1 : 1);

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

?>



<?php



include('captainsafeconfig.php');

include('captainsafecore.php');



connectdb();



////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*

// Test if the user is logged

if(islogged($sid) == false)

{

	echo "<head>";

	echo "<title>$sitte</title>";

	if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

	echo "</head>";

	echo "<body>";

	echo "<p align=\"center\">";

	echo "<small>Nu esti autentificat<br/>";

	echo "sau sesiunea ta a expirat<br/><br/>";

	

	if (VERS == 'web')

		echo "<a href=\"index.php\">Autentificare</a></small>";

	else 

		echo "<a href=\"indexwml.php\">Autentificare</a></small>";



	echo "</p>";

	echo "</body>";

	echo "</html>";

	exit();

}

// Test if the user is banned

if(isbanned($uid))

{

	echo "<head>";

	echo "<title>$sitte</title>";

	if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

	echo "</head>";

	echo "<body>";

	echo "<p align=\"center\">";

	echo "<img src=\"images/notok.gif\" alt=\"x\"/><br/>";

	echo "Esti <b>Banat(a)</b><br/>";

	$banto = mysql_fetch_array(mysql_query("SELECT timeto FROM ibwf_penalties WHERE uid='".$uid."' AND penalty='1'"));

	$banres = mysql_fetch_array(mysql_query("SELECT lastpnreas FROM ibwf_users WHERE id='".$uid."'"));

	

	$remain = $banto[0]- time();

	$rmsg = gettimemsg($remain);

	echo "Timp ramas pana la debanare: $rmsg<br/><br/>";

	echo "Motiv Ban: $banres[0]";

	//echo "<a href=\"indexwml.php\">Login</a>";

	echo "</p>";

	echo "</body>";

	echo "</html>";

	exit();

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

*/



// Variables ////////////////////////////

$site = 'http://wapirate.net/';

$imgFolder = "contest/";



$nrItems = (VERS == 'wap' ? 1 : 12);

$nrCols = 4;

$category = 1;



if (isset($_GET['nritems']) && is_numeric($_GET['nritems']))	$nrItems = $_GET['nritems'];

if (isset($_GET['nrcols']) && is_numeric($_GET['nrcols']))		$nrCols = $_GET['nrcols'];



if (isset($_GET['category']) && $_GET['category'] >= 1 && $_GET['category'] <= 3) $category = $_GET['category'];



list($category_name) = mysql_fetch_array(mysql_query("SELECT name FROM beauty_category WHERE id=$category"));



// get all categories name

$cat = mysql_query("SELECT id, name FROM beauty_category");

while ($row = mysql_fetch_array($cat))

	$categories[ $row['id'] ] = $row['name'];



if ($category == 1)

{	//pink

	$bg1 = '#f7ebf2';

	$bg2 = '#f5dfeb';

}

else if ($category == 2)

{	//blue

	$bg1 = '#e9f0f4';

	$bg2 = '#d7e8f2';

}

else

{	//violet

	$bg1 = '#e7e2ee';

	$bg2 = '#e0d5ed';

}

/////////////////////////////////////////



$sid = $_GET['sid'];

$uid = getuid_sid($sid);

$unick = getnick_uid($uid);

list($usex) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$uid."'"));

//

//list($uperm) = mysql_fetch_array(mysql_query("SELECT perm FROM ibwf_users WHERE id='". $uid ."'"));

list($uperm) = mysql_fetch_array(mysql_query("SELECT perm FROM ibwf_users WHERE id='". $uid ."'"));

//

$uplusses = getplusses($uid);

//

// check if the user has already an entry in the contest

list($uSingleEntry) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_candidates WHERE user_id1='". $uid ."' AND category_id != 3"));

list($uCoupleEntry) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_candidates WHERE (user_id1='". $uid ."' OR user_id2='". $uid ."') AND category_id = 3"));

list($uentry) = mysql_fetch_array(mysql_query("SELECT id FROM beauty_candidates WHERE (user_id1='". $uid ."' OR user_id2='". $uid ."') AND category_id = $category"));

//

// check if current user had voted

list($voted) = @mysql_fetch_array(mysql_query("SELECT candidate_id FROM beauty_votes WHERE voter=$uid AND category_id=$category"));

//

// check if user si married

//$married = @mysql_fetch_array(mysql_query("SELECT who, partner FROM come4me_casatorie WHERE (who=$uid OR partner=$uid) AND accept=1"));

if ($married) $married = ($uid == $married[0] ? $married[1] : $married[0]);



if (isset($_GET["action"]))

	$action = $_GET["action"];

else

	$action = 'main';

	

// get contest settings

$settings = array();

$sett = mysql_query("SELECT name, value FROM beauty_settings");

while ($row = mysql_fetch_array($sett))

{

	$settings[$row['name']] = $row['value'];

}

//=================================================================================================



// start contest ================================================================================================

//

$contest_start = strtotime('+'. $settings['start'] . ' day', (int) $settings['ended']);

$contest_end = strtotime('+'. $settings['end'] . ' day', (int) $settings['started']);

//

if ( (time() > $contest_start && $settings['starton'] == 'y' && !empty($settings['ended']))

	|| isset($_POST['startcontest']))

{

	// delete candidates gallery

	$res = mysql_query("SELECT beauty_gallery.id FROM beauty_gallery, beauty_winners_gallery WHERE beauty_gallery.itemurl = beauty_winners_gallery.itemurl");

	while ($row = mysql_fetch_array($res))

		mysql_query("DELETE FROM beauty_gallery WHERE id=$row[0]");

	//

	$res = mysql_query("SELECT itemurl, thumb FROM beauty_gallery");	

	while ($row = mysql_fetch_array($res))

	{

		delfile($row['itemurl'], $site);

		delfile($row['thumb'], $site);

	}

	

	// delete all data from previous contest

	mysql_query("TRUNCATE TABLE beauty_candidates");

	mysql_query("TRUNCATE TABLE beauty_gallery");

	mysql_query("TRUNCATE TABLE beauty_votes");

	

	// update settings

	mysql_query("UPDATE beauty_settings SET value='". time() ."' WHERE name='started'");

	mysql_query("UPDATE beauty_settings SET value='' WHERE name='ended'");

	mysql_query("UPDATE beauty_settings SET value='y' WHERE name='regon' OR name='voton' OR name='endon'");

	

	// notify all users

	$pmtext = 'Good Friend! The "Beauty Contest" registration had just began! Please remember to vote!';

	pmtoall($pmtext);

}

//

// end contest ================================================================================================

//

else if ( (time() > $contest_end && $settings['endon'] == 'y' && empty($settings['ended']) && !empty($settings['started']))

	|| isset($_POST['endcontest']))

{

	// find the candidates for each category --------------------------------

	$candidates = array( 1=>array(), array(), array() );

	//

	$res = mysql_query("SELECT id FROM beauty_candidates WHERE category_id=1");

	while ($row = mysql_fetch_array($res))

		$candidates[1][] = $row['id'];

	//

	$res = mysql_query("SELECT id FROM beauty_candidates WHERE category_id=2");

	while ($row = mysql_fetch_array($res))

		$candidates[2][] = $row['id'];

	//

	$res = mysql_query("SELECT id FROM beauty_candidates WHERE category_id=3");

	while ($row = mysql_fetch_array($res))

		$candidates[3][] = $row['id'];

	

	// find the nr of votes for each candidate -------------------------------

	//

	$winners = array( array(), array(), array(), array() );

	$prizes = array( 'plusses'=>array(), 'money'=>array() ); 

	//

	// first category - miss

	foreach ($candidates[1] as $candidate)

		list($winners[1][$candidate]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_votes WHERE candidate_id=$candidate"));

	// second category - mister

	foreach ($candidates[2] as $candidate)

		list($winners[2][$candidate]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_votes WHERE candidate_id=$candidate"));

	// third category - married

	foreach ($candidates[3] as $candidate)

		list($winners[3][$candidate]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_votes WHERE candidate_id=$candidate"));



	// sort winners -----------------------------------------------------------

	//

	// first phase - after the nr of votes

	arsort($winners[1], SORT_NUMERIC);

	arsort($winners[2], SORT_NUMERIC);

	arsort($winners[3], SORT_NUMERIC);

	//

	// second phase - after activity

	uksort($winners[1], sortWinners1);

	uksort($winners[2], sortWinners2);

	uksort($winners[3], sortWinners3);



	// find the nr of places

	$nplaces = array();

	list($nplaces[1]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_prizes WHERE category_id=1"));

	list($nplaces[2]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_prizes WHERE category_id=2"));

	list($nplaces[3]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_prizes WHERE category_id=3"));



	// select all winners ---------------------------------

	$i = 0;

	// first category - miss

	foreach ($winners[1] as $candidate => $votes)

	{

		if ($i >= $nplaces[1]) { $i = 0; break;}

		

		$winners[0][$candidate] = $votes;

		

		list( $prizes['plusses'][], $prizes['money'][] ) = mysql_fetch_array(mysql_query("SELECT plusses, money FROM beauty_prizes WHERE category_id=1 ORDER BY id ASC LIMIT $i,1"));

		

		$i++;

	}

	// second category - mister

	$i = 0;

	foreach ($winners[2] as $candidate => $votes)

	{

		if ($i >= $nplaces[2]) { $i = 0; break;}

		

		$winners[0][$candidate] = $votes;

		

		list( $prizes['plusses'][], $prizes['money'][] ) = mysql_fetch_array(mysql_query("SELECT plusses, money FROM beauty_prizes WHERE category_id=2 ORDER BY id ASC LIMIT $i,1"));

		

		$i++;

	}

	// third category - married

	$i = 0;

	foreach ($winners[3] as $candidate => $votes)

	{

		if ($i >= $nplaces[3]) { $i = 0; break;}

		

		$winners[0][$candidate] = $votes;

		

		list( $prizes['plusses'][], $prizes['money'][] ) = mysql_fetch_array(mysql_query("SELECT plusses, money FROM beauty_prizes WHERE category_id=3 ORDER BY id ASC LIMIT $i,1"));

		

		$i++;

	}

	

	// reward winners ---------------------------

	//

	$i = 0;

	$place = 1;

	$categ = 1;

	foreach ($winners[0] as $candidate_id => $votes)

	{

		$candidate = mysql_fetch_array(mysql_query("SELECT * FROM beauty_candidates WHERE id=$candidate_id"));

		$candidate_gallery = array();

		$res = mysql_query("SELECT * FROM beauty_gallery WHERE candidate_id=$candidate_id");

		while ( $row = mysql_fetch_array($res) )

			$candidate_gallery[] = $row;

			

		if ($categ != $candidate['category_id'])

		{

			$categ = $candidate['category_id'];

			$place = 1;

		}

		

		// give reward (plusses)

		mysql_query("UPDATE ibwf_users SET plusses=plusses+{$prizes['plusses'][$i]} WHERE id={$candidate['user_id1']}");

		//

		if ($candidate['category_id'] == 3)

			mysql_query("UPDATE ibwf_users SET plusses=plusses+{$prizes['plusses'][$i]}/2 WHERE id={$candidate['user_id2']}");

		

		// save winners

		$res = mysql_query("INSERT INTO beauty_winners SET

			user_id1={$candidate['user_id1']}, ". ($candidate['user_id2'] ? "user_id2={$candidate['user_id2']}," : '') ."

			category_id={$candidate['category_id']}, description='{$candidate['description']}', votes=$votes, place=$place,

			plusses={$prizes['plusses'][$i]}, money={$prizes['money'][$i]}, start_date='{$settings['started']}', end_date='$contest_end'");

		//

		// save winners gallery

		list($winner_id) = mysql_fetch_array(mysql_query("SELECT id FROM beauty_winners ORDER BY id DESC LIMIT 1"));

		foreach ($candidate_gallery as $wgallery)

		{

			mysql_query("INSERT INTO beauty_winners_gallery SET winner_id=$winner_id, itemurl='{$wgallery['itemurl']}',

				thumb='{$wgallery['thumb']}', comment='{$wgallery['comment']}', priority='{$wgallery['priority']}'");

		}

		

		// notify winners

		$pmtext = "Congratulations! You are the winner in Beauty Contest - ". $categories[ $candidate['category_id'] ] ."Check out what you have won!";

		//

		mysql_query("INSERT INTO ibwf_private SET text='$pmtext', byuid=0, touid={$candidate['user_id1']}, timesent='". time() ."'");

		//

		if ($candidate['category_id'] == 3)

			mysql_query("INSERT INTO ibwf_private SET text='$pmtext', byuid=0, touid={$candidate['user_id2']}, timesent='". time() ."'");

		

		$i++;

		$place++;

	}

	

	// update settings

	mysql_query("UPDATE beauty_settings SET value='$contest_end' WHERE name='ended'");

	

	// notify all users

	$pmtext = "Beauty Contest has ended! Now you can see the winner!";

	pmtoall($pmtext);

}

//=================================================================================================



// get contest settings ================================================

$settings = array();

$sett = mysql_query("SELECT name, value FROM beauty_settings");

while ($row = mysql_fetch_array($sett))

{

	$settings[$row['name']] = $row['value'];

}



//==================================================================================================

// main

if ($action == 'main' && $uid > 0)

{

    echo '<head>';

    echo '<title>"Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center">';

	

    if (isset($_GET['winners']))

    {

		echo "<h2>Beauty Contest - $category_name - Category</h2>";

		addonline(getuid_sid($sid), 'Viewing "Beauty Contest"', "");

    }

    else

    {

    	echo "<h2>Beauty Contest - $category_name</h2>";

		addonline(getuid_sid($sid), 'Viewing "Beauty Contest"', "");

    }

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	// Find the nr of pages required

	//

	if (isset($_GET['p']) && is_numeric($_GET['p']))

	{

		$pages = $_GET['p'];

	}

	else 

	{

		if (isset($_GET['winners']))

		{

			$res = mysql_query("SELECT DISTINCT start_date FROM beauty_winners WHERE category_id=$category ORDER BY start_date DESC");

			$ncontest = mysql_num_rows($res);

			

			if (isset($_GET['contest']) && is_numeric($_GET['contest']) && $_GET['contest'] <= $ncontest && $_GET['contest'] > 0)

				$contest = $_GET['contest'];

			else

				$contest = $ncontest;

			//

			$i = $ncontest;

			$allcontests = array();

			while ($row = mysql_fetch_array($res))

			{

				if ($i == $contest)

					$start_date = $row['start_date'];

					

				$allcontests[$i] = $row['start_date'];

				$i--;

			}

			

			$sql = "SELECT COUNT(id) FROM beauty_winners WHERE category_id=$category AND start_date='$start_date'";

		}

		else

			$sql = "SELECT COUNT(id) FROM beauty_candidates WHERE category_id=$category";

			

		$r = @mysql_query ($sql);

		$row = @mysql_fetch_array ($r, MYSQL_NUM);

		$records = $row[0];



		if ($records > $nrItems)

			$pages = @ceil ($records / $nrItems);

		else 

			$pages = 1;

	}

	

	// Find the starting page

	//

	if (isset($_GET['s']) && is_numeric($_GET['s']) && $_GET['s'] > 0)

		$start = $_GET['s'];

	else

		$start = 0;

	//

	if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0)

	{

		$page = ($_GET['page'] > $pages ? $pages : $_GET['page']);

		$start = $nrItems * ($page - 1);

	}

	

	if (isset($_GET['winners']))

	{

		echo "<a href=\"beauty_contest.php?category=$category&sid=$sid&". VERS ."\">Winners</a>";

	}

	else

	{

		if ($uentry)

		{

			if ($category == 1) $myentry = "Participants";

			else $myentry = "Participants";

			

			echo "<a href=\"beauty_contest.php?action=details&who=$uentry&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">$myentry</a>";

		}

		else

			echo "<a href=\"beauty_contest.php?action=register&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Sign up</a>";

		

		// Prizes panel

		echo " &nbsp;| &nbsp; <a href=\"beauty_contest.php?action=prizes&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Prizes</a>";



		// Winners panel

		echo " &nbsp;| &nbsp; <a href=\"beauty_contest.php?winners&category=$category&sid=$sid&".VERS."\">Winners</a>";

		

		// Top panel

		if ($uperm >= UPERM)

			echo " &nbsp;| &nbsp; <a href=\"beauty_contest.php?action=top&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Top</a>";

		

		// Admin panel

		if ($uperm >= UPERM)

			echo " &nbsp;| &nbsp; <a href=\"beauty_contest.php?action=admin&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Admin</a>";

		

		// Rules

		echo " &nbsp;| &nbsp; <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a>";

	}

	

	echo '<br /><br />';

	

	// display all contests

	if (isset($_GET['winners']))

	{

		if (count($allcontests) > 0)

		{

			echo '<form action="beauty_contest.php" method="get">';

			echo 'Concurs: ';

			echo '<select name="contest">';

			

			foreach ($allcontests as $ncontest => $startdate)

			{

				echo '<option value="'. $ncontest .'" '. ($ncontest == $contest ? 'selected="selected"' : '') .'>'. date('d F, Y', $startdate) .'</option>';

			}

			echo '</select>';

	

			echo ' <input type="submit" value="Go" />

				<input type="hidden" name="winners" />

				<input type="hidden" name="category" value="'.$category.'" />

				<input type="hidden" name="sid" value="'.$sid.'" />

				<input type="hidden" name="'.VERS.'" />';

			echo '</form>';

		}

		echo '<a href="beauty_contest.php?winners&contest='.$contest.'&category=1&sid='.$sid.'&'. VERS .'">'.$categories[1].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?winners&contest='.$contest.'&category=2&sid='.$sid.'&'. VERS .'">'.$categories[2].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?winners&contest='.$contest.'&category=3&sid='.$sid.'&'. VERS .'">'.$categories[3].'</a>';

	}

	else

	{

		echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'. VERS .'">'.$categories[1].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'. VERS .'">'.$categories[2].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'. VERS .'">'.$categories[3].'</a>';

	}



	// Add links for all pages

	if ($pages > 1) 

	{

		echo '<p>';

		$current_page = ($start / $nrItems) + 1;

		

		echo '<form method="GET" action="beauty_contest.php">

			Pagina: <input type="text" name="page" size="4" maxlength="6" />

			<input type="submit" value="Dute" />';

		

		if (isset($_GET['winners']))

		{

			echo '<input type="hidden" name="winners" />

				<input type="hidden" name="contest" value="'. $contest .'" />';

		}

		echo '<input type="hidden" name="nritems" value="'. $nrItems .'" />

			<input type="hidden" name="nrcols" value="'. $nrCols .'" />

			<input type="hidden" name="category" value="'. $category .'" />

			<input type="hidden" name="sid" value="'. $sid .'" />

			<input type="hidden" name="'.VERS.'" />

		</form>';

		

		// previous link

		if ($current_page != 1)

		{

			if (isset($_GET['winners']))

				echo '<a href="beauty_contest.php?winners&contest='.$contest.'&s='. ($start - $nrItems) .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Previous</a>';

			else

				echo '<a href="beauty_contest.php?s='. ($start - $nrItems) .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Previous</a>';

		}

		else

			echo 'Previous';

			

		echo " - <b>$current_page</b> / $pages - ";

			

		// next link

		if ($current_page != $pages)

		{

			if (isset($_GET['winners']))

				echo '<a href="beauty_contest.php?winners&contest='.$contest.'&s='. ($start + $nrItems) .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Next</a>';

			else

				echo '<a href="beauty_contest.php?s='. ($start + $nrItems) .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Next</a>';

		}

		else

			echo 'Next';

			

		echo '<br />';

		echo '</p>';

	}

	else echo '<br /><br />';

	

	// Get all images

	if (isset($_GET['winners']))

		$q = "SELECT * FROM beauty_winners_gallery, beauty_winners

			WHERE beauty_winners_gallery.winner_id = beauty_winners.id AND beauty_winners.category_id = $category AND beauty_winners.start_date='$start_date' AND beauty_winners_gallery.priority = '1'

			ORDER BY beauty_winners.place LIMIT $start, $nrItems";

	else

		$q = "SELECT * FROM beauty_gallery, beauty_candidates

			WHERE beauty_gallery.candidate_id = beauty_candidates.id AND beauty_candidates.category_id = $category AND beauty_gallery.priority = '1'

			ORDER BY beauty_candidates.reg_date DESC LIMIT $start, $nrItems";

	//

	$r = @mysql_query ($q);

	//

	// Start displaying the images

	echo '<table align="center" cellspacing="3" cellpadding="20" width="220">';

	//

	if (mysql_num_rows($r) > 0)

	{

		$i = 0;

		while ($row = @mysql_fetch_array($r, MYSQL_ASSOC))

		{

			if ($i == $nrCols) $i = 0;

			

			// color

			$bg = ($bg==$bg1 ? $bg2 : $bg1);

			

			if ($i == 0)

				echo '<tr>';

				

			list($sex1) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$row['user_id1']."'"));

			list($sex2) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$row['user_id2']."'"));

			$sexname1 = ($sex1 == 'M' ? 'Barbat' : 'Femeie');

			$sexname2 = ($sex2 == 'M' ? 'Barbat' : 'Femeie');

			$nick1 = getnick_uid($row['user_id1']);

			$nick2 = getnick_uid($row['user_id2']);

			

			// check if user is online

			if(isonline($row['user_id1']))

				$ison1 = '<img src="../images/'. ($sex1 == 'M' ? 'onM.gif"' : 'onF.gif"') .'alt="+"/> ';

			else

				$ison1 = '<img src="../images/off.gif" alt="-"/> ';

			//

			if(isonline($row['user_id2']))

				$ison2 = '<img src="../images/'. ($sex2 == 'M' ? 'onM.gif"' : 'onF.gif"') .'alt="+"/> ';

			else

				$ison2 = '<img src="../images/off.gif" alt="-"/> ';

				

			// users profile

			if (VERS == 'web')

			{

				$profile1 = '<a href="index.php?action=viewuser&who='. $row['user_id1'] . '&sid='. $sid .'">'.$nick1.'</a> ';

				$profile2 = '<a href="index.php?action=viewuser&who='. $row['user_id2'] . '&sid='. $sid .'">'.$nick2.'</a> ';

			}

			else

			{

				$profile1 = '<a href="indexwml.php?action=viewuser&who='. $row['user_id1'] . '&sid='. $sid .'">'.$nick1.'</a> ';

				$profile2 = '<a href="indexwml.php?action=viewuser&who='. $row['user_id2'] . '&sid='. $sid .'">'.$nick2.'</a> ';

			}

			

			

			if ($category == 3)

			{

				if ($sex1 == 'M')

					$candidate = $ison1 . $profile1 . '<br />' . $ison2 . $profile2;

				else

					$candidate = $ison2 . $profile2 . '<br />' . $ison1 . $profile1;

			}

			else

				$candidate = $ison1 . $profile1;

					

			echo '<td align="center" bgcolor="' . $bg . '">'.

					$candidate .'

					<br /><br />

					<a href="'. $row['itemurl'] .'"><img src="'. $row['thumb'] .'" /></a>

					<br /><br />';

			//

			if (isset($_GET['winners']))

				echo '<a href="beauty_contest.php?action=details&winners&contest='.$contest.'&who='. $row['winner_id']. '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Details</a>';

			else

			{

				echo '<a href="beauty_contest.php?action=details&who='. $row['candidate_id']. '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Details</a>';

			

				if ($uperm >= UPERM)

				{

					echo '<br /><br />';

					echo '<a href="beauty_contest.php?action=delcandidate&who='. $row['candidate_id']. '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Delete</a>';

				}

			}



			if (isset($_GET['winners']))

			{

				echo '<br />----------------------<br />Loc: <b>'. $row['place'] .'</b>';

				

				echo '<br />----------------------<br />--- <b>Prize</b> ---';

				

				if ($row['money'] > 0)

					echo '<br />Euro: <b>'. $row['money'] .'</b> &euro;';

				if ($row['plusses'] > 0)

					echo '<br />Plusses: <b>'. $row['plusses'] .'</b> +';

					

				echo '<br />----------------------<br />No. of votes: <b>'. $row['votes'] .'</b>';

			}

			else

			{

				// check if can vote ----------------------------------------------------

				if ( (!$voted && $row['user_id1'] != $uid && $row['user_id2'] != $uid)

					&& !($settings['votstart'] > date('j') || $settings['voton'] == 'n')

					&& !((!empty($settings['ended']) || empty($settings['started']))))

				{

					echo '<br />----------------------<br />

						<a href="beauty_contest.php?action=vote&who='. $row['candidate_id']. '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Vote</a>';

				}

				// the user vote goes for...

				else if ($voted == $row['candidate_id'])

					echo '<br /><br /><img src="../images/voted.gif" />';

				// display user votes

				else if ($uid == $row['user_id1'] || $uid == $row['user_id2'])

				{

					list($votes) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_votes WHERE candidate_id=". $row['candidate_id']));

					

					echo '<br />----------------------<br />No. of votes: <b>'. $votes .'</b>';

				}

				//-------------------------------------------------------------------------

			}

			

			echo '</td>';

			

			if ($i == $nrCols-1)

				echo '</tr>';

				

			$i++;

		}

	}

	else

	{

		echo '<tr align="center" bgcolor="' . $bg1 . '"><td>';

		

		if (isset($_GET['winners']))

			echo 'There are no winners for this category!';

		else echo 'There is no participant for this category!';

		

		echo '</tr></td>';

	}

	

	echo '</table>';

	

	echo "<br /><br />";

	

	if (VERS == 'web')

		echo "<img src=\"images/home.gif\" /> <a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";

	else 

		echo "<img src=\"images/home.gif\" /> <a href=\"indexwml.php?action=main&amp;sid=$sid\">Main Menu</a>";

	

	echo '</body>';

}



// register

else if ($action == 'register' && $uid > 0)

{

    echo '<head>';

    echo '<title>Registration "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center" bgcolor="#eeeeee">';

	

	echo '<h2>Beauty Contest - Inscriere</h2>';

	

	addonline(getuid_sid($sid), 'Registration "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'.VERS.'">'.$categories[1].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'.VERS.'">'.$categories[2].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'.VERS.'">'.$categories[3].'</a>';

	echo '<br /><br /><br />';

	

	// register candidate

	if (isset($_POST['submitted']) 

		&& !($settings['regstart'] > date('j') || date('j') > $settings['regend'] || $settings['regon'] == 'n')

		&& ($settings['regplusses'] <= $uplusses))

	{

		// upload

		if (isset($_FILES['image']))

		{

			$ucategory = $_POST['category'];

			$comment = (empty($_POST['comment']) ? '' : $_POST['comment']);

			$description = (empty($_POST['description']) ? '' : $_POST['description']);



			// allowed files

			$allowed = array ('jpeg', 'JPEG', 'jpg', 'JPG', 'GIF', 'gif');

		

			$pathinfo = pathinfo($_FILES['image']['name']);

								

			if (in_array($pathinfo['extension'], $allowed) && $_FILES['image']['size'] > 0)

			{

				// image

				$rand = rand();

				$fname = str_replace(" ", "_", strtolower($_FILES['image']['name']));

				$ipath = $imgFolder . $rand . "_$fname";

				$imglink = $site . $ipath;

				//

				// thumbnail

				//

				$tpath = $imgFolder . $rand . "_thumb_$fname";

				$thumblink = $site . $tpath;

				

				if (move_uploaded_file($_FILES['image']['tmp_name'], "$ipath"))

				{	

					// create thumbnail

					if ( ! createThumb($imglink, "$tpath") ) $thumblink = '';

							

					// add candidate

					if ($ucategory == 3 && !$uCoupleEntry && $married)

					{

						mysql_query("INSERT INTO beauty_candidates (user_id1, user_id2, category_id, description) VALUES ($uid, $married, $ucategory, '$description')");



						// add image

						list($candidate_id) = mysql_fetch_array(mysql_query("SELECT id FROM beauty_candidates WHERE user_id1=$uid AND category_id=$ucategory"));

						mysql_query("INSERT INTO beauty_gallery (candidate_id, itemurl, thumb, comment, priority) VALUES ('". $candidate_id ."', '". $imglink ."', '". $thumblink ."', '". $comment ."', '1')");

					

						// substract plusses

						mysql_query("UPDATE ibwf_users SET plusses=". ($uplusses - $settings['regplusses']) ." WHERE id='".$uid."'");

					}

					else if (!$uSingleEntry)

					{

						$res = mysql_query("INSERT INTO beauty_candidates (user_id1, category_id, description) VALUES ($uid, $ucategory, '$description')");

						

						// add image

						list($candidate_id) = mysql_fetch_array(mysql_query("SELECT id FROM beauty_candidates WHERE user_id1=$uid AND category_id=$ucategory"));

						mysql_query("INSERT INTO beauty_gallery (candidate_id, itemurl, thumb, comment, priority) VALUES ('". $candidate_id ."', '". $imglink ."', '". $thumblink ."', '". $comment ."', '1')");

					

						// substract plusses

						mysql_query("UPDATE ibwf_users SET plusses=". ($uplusses - $settings['regplusses']) ." WHERE id='".$uid."'");

					}

					echo "<img src=\"images/ok.gif\" alt=\"O\"/><b> Photo uploaded successfully!.</b><br/>";

					echo "<br />";

					echo '<a href="beauty_contest.php?action=register&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

				}

				else

				{

					echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> Please try again later</b><br/>";

					echo "<br />";

					echo '<a href="beauty_contest.php?action=register&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

				}

			}

			else

			{

				echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> Selected picture is not valid!</b><br/>";

				echo "<br />";

				echo '<a href="beauty_contest.php?action=register&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</ak>';

			}

		}

	}

	else

	{

		if (!empty($settings['ended']) || empty($settings['started']))

		{

			echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> The contest is closed!</b> <br />

			( To read questions <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )<br/>";

			echo "<br />";

		}

		else if ($settings['regstart'] > date('j') || date('j') > $settings['regend'] || $settings['regon'] == 'n')

		{

			echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> Registrations are now closed!</b> <br />

			( To read questions <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )<br/>";

			echo "<br />";

		}

		else if ($settings['regplusses'] > $uplusses)

		{

			echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> You need {$settings['regplusses']} plusses to participate! You just have $uplusses plussed</b> <br />

			( To read questions <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )<br/>";

			echo "<br />";

		}

		else if ($uSingleEntry && $uCoupleEntry || $uSingleEntry && !$uCoupleEntry && !$married)

		{

			echo "<img src=\"images/ok.gif\" alt=\"O\"/><b> You are already egistered to all possible categories!</b> <br />

			( To read questions <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )<br/>";

			echo "<br />";

		}

		else 

		{

			echo '

			<form enctype="multipart/form-data" action="beauty_contest.php?action=register&s='.$start.'&p='.$pages.'&category='.$category.'&sid='. $sid .'&'.VERS.'" method="post">

				Categorie: <select name="category">';

			

			// check if the user has already an entry in the contest

			if ($usex == 'F' && $uSingleEntry == 0)

				echo '<option value="1">'. $categories[1] .'</option>';

			elseif ($uSingleEntry == 0)

				echo '<option value="2">'. $categories[2] .'</option>';

			//

			if ($uCoupleEntry == 0 && $married)

				echo '<option value="3">'. $categories[3] .'</option>';

			

			echo '</select>

				<br /><br />

				<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

				

				Upload Photo:

				<input type="file" name="image" size="22" /> <br />

				Description: <br />

				<input type="text" name="comment" size="40" maxlength="100" />

				<br /><br />'.

				'About: <br />

				<textarea name="description" rows="5" cols="30"></textarea>

				<br /><br />

				<input type="submit" value="Submit" />

				<input type="hidden" name="submitted" value="1" />

			</form>';

		}

	

		echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	}



	echo '</body>';

}



// details

else if ($action == 'details' && $uid > 0)

{

    echo '<head>';

    echo '<title>Viewing "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center">';

	

    if (isset($_GET['winners']))

    {

		echo "<h2>Beauty Contest - $category_name - category</h2>";

		addonline(getuid_sid($sid), 'Viewing "Beauty Contest"', "");

    }

    else {

		echo "<h2>Beauty Contest - $category_name</h2>";

		addonline(getuid_sid($sid), 'Viewing "Beauty Contest"', "");

    }

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$who = $_GET['who'];

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	if (isset($_GET['winners']))

	{

		$res = mysql_query("SELECT DISTINCT start_date FROM beauty_winners WHERE category_id=$category ORDER BY start_date DESC");

		$ncontest = mysql_num_rows($res);

		

		if (isset($_GET['contest']) && is_numeric($_GET['contest']) && $_GET['contest'] <= $ncontest)

			$contest = $_GET['contest'];

		else

			$contest = $ncontest;

		//

		$i = $ncontest;

		$allcontests = array();

		while ($row = mysql_fetch_array($res))

		{

			if ($i == $contest)

				$start_date = $row['start_date'];

				

			$allcontests[$i] = $row['start_date'];

			$i--;

		}

		

		echo "<a href=\"beauty_contest.php?category=$category&sid=$sid&". VERS ."\">Winners</a><br /><br />";

	

		// display all contests

		echo '<form action="beauty_contest.php" method="get">';

		echo 'Contest: ';

		echo '<select name="contest">';

		

		foreach ($allcontests as $ncontest => $start_date)

		{

			echo '<option value="'. $ncontest .'" '. ($ncontest == $contest ? 'selected="selected"' : '') .'>'. date('d F, Y', $start_date) .'</option>';

		}

		echo '</select>';

		

		echo ' <input type="submit" value="Go" />

			<input type="hidden" name="winners" />

			<input type="hidden" name="category" value="'.$category.'" />

			<input type="hidden" name="sid" value="'.$sid.'" />

			<input type="hidden" name="'.VERS.'" />';

		echo '</form>';

		

		echo '<a href="beauty_contest.php?winners&contest='.$contest.'&category=1&sid='.$sid.'&'. VERS .'">'.$categories[1].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?winners&contest='.$contest.'&category=2&sid='.$sid.'&'. VERS .'">'.$categories[2].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?winners&contest='.$contest.'&category=3&sid='.$sid.'&'. VERS .'">'.$categories[3].'</a>';

	

		echo '<br /><br />';

		echo '<a href="beauty_contest.php?winners&contest='.$contest.'&s='. $start .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	}

	else

	{

		echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'. VERS .'">'.$categories[1].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'. VERS .'">'.$categories[2].'</a>';

		echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'. VERS .'">'.$categories[3].'</a>';

	

		echo '<br /><br />';

		echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	}



	if (isset($_GET['winners']))

		list($user_id1, $user_id2, $description, $votes, $place, $plusses, $money) = mysql_fetch_array(mysql_query("SELECT user_id1, user_id2, description, votes, place, plusses, money FROM beauty_winners WHERE id='".$who."'"));

	else

		list($user_id1, $user_id2, $description) = mysql_fetch_array(mysql_query("SELECT user_id1, user_id2, description FROM beauty_candidates WHERE id='".$who."'"));

	//

	list($sex1) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$user_id1."'"));

	list($sex2) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$user_id2."'"));

	$sexname1 = ($sex1 == 'M' ? 'Barbat' : 'Femeie');

	$sexname2 = ($sex2 == 'M' ? 'Barbat' : 'Femeie');

	$nick1 = getnick_uid($user_id1);

	$nick2 = getnick_uid($user_id2);

	//

	// get description

	if ($description == "")

		$description = '---';

	else

		$description = str_replace( array('[b]', '[/b]'), '', $description );

		

	// check if user is online

	if(isonline($user_id1))

			$ison1 = '<img src="../images/'. ($sex1 == 'M' ? 'onM.gif"' : 'onF.gif"') .'alt="+"/> ';

	else

		$ison1 = '<img src="../images/off.gif" alt="-"/> ';

	//

	if(isonline($user_id2))

		$ison2 = '<img src="../images/'. ($sex2 == 'M' ? 'onM.gif"' : 'onF.gif"') .'alt="+"/> ';

	else

		$ison2 = '<img src="../images/off.gif" alt="-"/> ';

		

	// users profile

	if (VERS == 'web')

	{

		$profile1 = '<a href="index.php?action=viewuser&who='. $user_id1 . '&sid='. $sid .'">'.$nick1.'</a> ';

		$profile2 = '<a href="index.php?action=viewuser&who='. $user_id2 . '&sid='. $sid .'">'.$nick2.'</a> ';

	}

	else 

	{

		$profile1 = '<a href="indexwml.php?action=viewuser&who='. $user_id1 . '&sid='. $sid .'">'.$nick1.'</a> ';

		$profile2 = '<a href="indexwml.php?action=viewuser&who='. $user_id2 . '&sid='. $sid .'">'.$nick2.'</a> ';

	}

	

	if ($category == 3)

	{

		if ($sex1 == 'M')

			$candidate = $ison1 . $profile1 . '<br />' . $ison2 . $profile2;

		else

			$candidate = $ison2 . $profile2 . '<br />' . $ison1 . $profile1;

	}

	else

		$candidate = $ison1 . $profile1;

		

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	//

	if (isset($_GET['winners']))

		list($nimages) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_winners_gallery WHERE winner_id='".$who."' "));

	else

		list($nimages) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_gallery WHERE candidate_id='".$who."' "));

	// upload image

	//

	if (isset($_POST['submitted']) && $nimages < 3)

	{

		// upload

		if (isset($_FILES['image']))

		{

			$comment = (empty($_POST['comment']) ? '' : $_POST['comment']);



			// allowed files

			$allowed = array ('jpeg', 'JPEG', 'jpg', 'JPG', 'GIF', 'gif');

		

			$pathinfo = pathinfo($_FILES['image']['name']);

								

			if (in_array($pathinfo['extension'], $allowed) && $_FILES['image']['size'] > 0)

			{

				// image

				$rand = rand();

				$fname = str_replace(" ", "_", strtolower($_FILES['image']['name']));

				$ipath = $imgFolder . $rand . "_$fname";

				$imglink = $site . $ipath;

				//

				// thumbnail

				//

				$tpath = $imgFolder . $rand . "_thumb_$fname";

				$thumblink = $site . $tpath;

				

				if (move_uploaded_file($_FILES['image']['tmp_name'], "$ipath"))

				{	

					// create thumbnail

					if ( ! createThumb($imglink, "$tpath") ) $thumblink = '';

							

					// add image

					mysql_query("INSERT INTO beauty_gallery (candidate_id, itemurl, thumb, comment) VALUES ('". $who ."', '". $imglink ."', '". $thumblink ."', '". $comment ."')");

				}

			}

		}

	}

	// add image comment

	else if (isset($_POST['addcomment']))

	{

		$imageid = $_POST['image'];

		$comment = (empty($_POST['comment']) ? '' : $_POST['comment']);

		

		mysql_query("UPDATE beauty_gallery SET comment='". $comment ."' WHERE id=$imageid");

	}

	//

	// set image priority

	else if (isset($_POST['setpriority']) && $nimages > 1)

	{

		$imageid = $_POST['image'];

		

		mysql_query("UPDATE beauty_gallery SET priority='1' WHERE id=$imageid");

		mysql_query("UPDATE beauty_gallery SET priority='0' WHERE candidate_id=$who AND id != $imageid");

	}

	//

	// delete image

	else if (isset($_POST['delimage']) && $nimages > 1)

	{

		$imageid = $_POST['image'];

		list($itemurl, $thumb, $priority) = mysql_fetch_array(mysql_query("SELECT itemurl, thumb, priority FROM beauty_gallery WHERE id=$imageid"));

		

		mysql_query("DELETE FROM beauty_gallery WHERE id=$imageid");

		

		if ($priority == '1') mysql_query("UPDATE beauty_gallery SET priority='1' WHERE candidate_id=$who LIMIT 1");

		

		// Delete image from host (if exists) --------------------------------

		delfile($itemurl, $site);

		delfile($thumb, $site);

		//--------------------------------------------------------------------------

	}

	//

	// add candidate description

	else if (isset($_POST['addescription']))

	{

		$description = (empty($_POST['description']) ? '' : $_POST['description']);

		

		mysql_query("UPDATE beauty_candidates SET description='". $description ."', reg_date=reg_date WHERE id=$who");

	}

	//

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	

	// if wap

	if (VERS == 'wap')

	{

		if (isset($_GET['image']) AND is_numeric($_GET['image']))

			$image = $_GET['image'];

		else $image = 0;

		$sql = 'LIMIT '. $image .',1';

	}

	else $sql = '';



	if (isset($_GET['winners']))

	{

		$res = @mysql_query("SELECT * FROM beauty_winners_gallery WHERE winner_id='".$who."' ORDER BY id " . $sql);

		list($nimages) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_winners_gallery WHERE winner_id='".$who."' "));

	}

	else

	{

		$res = @mysql_query("SELECT * FROM beauty_gallery WHERE candidate_id='".$who."' ORDER BY id " . $sql);

		list($nimages) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_gallery WHERE candidate_id='".$who."' "));

	}

	

	echo '<table align="center" cellspacing="3" cellpadding="20" width="220">';

	echo '<tr>';

	while ($row = @mysql_fetch_array($res))

	{	  

		// get image comment

		if ($row['comment'] == "")

			$imgcomment = '---';

		else

			$imgcomment = str_replace( array('[b]', '[/b]'), '', $row['comment'] );

		

		// color

		$bg = ($bg==$bg1 ? $bg2 : $bg1);

		

		echo '<td align="center" bgcolor="' . $bg . '">'.

				$candidate .'

			<br /><br />

			<a href="'. $row['itemurl'] .'"><img src="'. $row['thumb'] .'" /></a>

			<br /><br />	

			<b>Description</b>:<br />'. $imgcomment .'<br />';

		

		if (!isset($_GET['winners']))

		{

			// comment form

			if ($user_id1 == $uid || $user_id2 == $uid)

			{

				echo '<form action="beauty_contest.php?action=details&who='.$who.'&s='.$start.'&p='.$pages.'&category='.$category.'&sid='. $sid .'&'.VERS.'" method="post">

						<input type="text" name="comment" size="30" maxlength="100" />

						<input type="submit" value="Add description" />

						<input type="hidden" name="image" value="'. $row['id'] .'" />

						<input type="hidden" name="addcomment" value="1" />

					</form>';

			}

			

			// set image priority form

			if (($user_id1 == $uid || $user_id2 == $uid) && $nimages > 1 && $row['priority'] == '0')

			{

				echo '<form action="beauty_contest.php?action=details&who='.$who.'&s='.$start.'&p='.$pages.'&category='.$category.'&sid='. $sid .'&'.VERS.'" method="post">

						<input type="submit" value="Main" />

						<input type="hidden" name="image" value="'. $row['id'] .'" />

						<input type="hidden" name="setpriority" value="1" />

					</form>';

			}

			

			// delete image form

			if (($user_id1 == $uid || $user_id2 == $uid) && $nimages > 1)

			{

				echo '<form action="beauty_contest.php?action=details&who='.$who.'&s='.$start.'&p='.$pages.'&category='.$category.'&sid='. $sid .'&'.VERS.'" method="post">

						<input type="submit" value="Delete" />

						<input type="hidden" name="image" value="'. $row['id'] .'" />

						<input type="hidden" name="delimage" value="1" />

					</form>';

			}

		}

		

		if ($nimages > 1 && VERS == 'wap')

		{

			echo '-----<br />';

			echo 'Poze: ';

			

			for ($i = 0; $i < $nimages; $i++)

			{

				if ($image == $i) echo '<b>'. ($i + 1) .'</b>';

				else

				{

					if (isset($_GET['winners']))

						echo '<a href="beauty_contest.php?action=details&winners&contest='.$contest.'&who='. $who . '&s='. $start .'&p='. $pages .'&image='. $i .'&category='. $category .'&sid='. $sid .'&'.VERS.'">'. ($i + 1) .'</a>';

					else

						echo '<a href="beauty_contest.php?action=details&who='. $who . '&s='. $start .'&p='. $pages .'&image='. $i .'&category='. $category .'&sid='. $sid .'&'.VERS.'">'. ($i + 1) .'</a>';

				}

				

				if ($i < $nimages-1) echo ' -';

			}

		}

				

		echo '</td>';

	}

	echo '</tr>';

	

	// description ------------------------------------------------------------

	echo '<tr bgcolor="'. $bg1 .'"><td colspan="3">';

	echo "<b>About " . ($category == 3 ? 'noi:' : 'me:') ."</b><br />";

	if (($user_id1 == $uid || $user_id2 == $uid) && !isset($_GET['winners'])) 

	{

		echo '<form action="beauty_contest.php?action=details&who='.$who.'&s='.$start.'&p='.$pages.'&category='.$category.'&sid='. $sid .'&'.VERS.'" method="post">

				<textarea rows="3" cols="25" name="description">'. $description .'</textarea>

				<input type="submit" value="Edit" />

				<input type="hidden" name="addescription" value="1" />

			</form>';

	}

	else

		echo $description;

	//

	echo '</td></tr>';

	//-------------------------------------------------------------------------

	

	echo '<tr bgcolor="'. $bg1 .'"><td colspan="3">';

	

	if (isset($_GET['winners']))

	{

		echo 'Loc: <b>'. $place .'</b>';

		

		echo '<br />----------------------<br />--- <b>Prize</b> ---';

		

		if ($money > 0)

			echo '<br />Euro: <b>'. $money .'</b> &euro;';

		if ($plusses > 0)

			echo '<br />Plusses: <b>'. $plusses .'</b> +';

			

		echo '<br />----------------------<br />No. of votes: <b>'. $votes .'</b>';

	}

	else

	{

		// check if can vote ----------------------------------------------------

		if ( (!$voted && $user_id1 != $uid && $user_id2 != $uid)

			&& !($settings['votstart'] > date('j') || $settings['voton'] == 'n')

			&& !((!empty($settings['ended']) || empty($settings['started']))) )

			echo ' <a href="beauty_contest.php?action=vote&who='. $who . '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'">Voteaza</a>';

		//

		// the user vote goes for...

		else if ($voted == $who)

			echo '<img src="../images/voted.gif" />';

		//

		// display user votes

		else if ($uid == $user_id1 || $uid == $user_id2)

		{

			list($votes) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_votes WHERE candidate_id=". $who));

			

			echo 'No. of Votes: <b>'. $votes .'</b>';

		}

	}

	

	echo '</td></tr>';

	

	if (($uid == $user_id1 || $uid == $user_id2) && $nimages < 3 && !isset($_GET['winners']))

	{

		echo '<tr bgcolor="'. $bg1 .'"><td colspan="3"><form enctype="multipart/form-data" action="beauty_contest.php?action=details&who='.$who.'&s='.$start.'&p='.$pages.'&category='.$category.'&sid='. $sid .'&'.VERS.'" method="post">

			<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

			Photo: <input type="file" name="image" size="17" /> <br />

			Photo description: <br />

			<input type="text" name="comment" size="35" maxlength="100" />

			<br /><br />

			<input type="submit" value="Add" />

			<input type="hidden" name="submitted" value="1" />

		</form></td></tr>';

	}

	

	echo '</table>';

	

	if (isset($_GET['winners']))

		echo '<a href="beauty_contest.php?winners&contest='.$contest.'&s='. $start .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	else

		echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	

	echo "<br /><br />";

	if (VERS == 'web')

		echo "<img src=\"images/home.gif\" /> <a href=\"index.php?action=main&amp;sid=$sid\"> Previous</a>";

	else

		echo "<img src=\"images/home.gif\" /> <a href=\"indexwml.php?action=main&amp;sid=$sid\"> Previous</a>";

	

	echo '</body>';

}



else if ($action == 'vote'&& $uid > 0)

{

    echo '<head>';

    echo '<title>Votare "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center" bgcolor="'. $bg1 .'">';

	

	echo '<h2>Beauty Contest - Votare</h2>';

	

	addonline(getuid_sid($sid), 'Votare "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$who = $_GET['who'];

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	list($user_id1, $user_id2) = mysql_fetch_array(mysql_query("SELECT user_id1, user_id2 FROM beauty_candidates WHERE id='".$who."'"));

	

	list($sex1) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$user_id1."'"));

	list($sex2) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$user_id2."'"));

	$nick1 = getnick_uid($user_id1);

	$nick2 = getnick_uid($user_id2);

	// users profile

	if (VERS == 'web')

	{

		$profile1 = '<a href="index.php?action=viewuser&who='. $user_id1 . '&sid='. $sid .'">'.$nick1.'</a> ';

		$profile2 = '<a href="index.php?action=viewuser&who='. $user_id2 . '&sid='. $sid .'">'.$nick2.'</a> ';

	}

	else

	{

		$profile1 = '<a href="indexwml.php?action=viewuser&who='. $user_id1 . '&sid='. $sid .'">'.$nick1.'</a> ';

		$profile2 = '<a href="indexwml.php?action=viewuser&who='. $user_id2 . '&sid='. $sid .'">'.$nick2.'</a> ';

	}

	

	if ($category == 3)

	{

		if ($sex1 == 'M')

			$candidate = "$profile1 - $profile2";

		else

		  $candidate = "$profile2 - $profile1";

	}

	else $candidate = $profile1;

	

	if (!empty($settings['ended']) || empty($settings['started']))

	{

		echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> Concursul este inchis!</b> <br />

		( Pentru nelamuriri citeste <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )";

	}

	else if ($settings['votstart'] > date('j') || $settings['voton'] == 'n')

	{

		echo "<img src=\"images/notok.gif\" alt=\"X\"/> <b>Votarile sunt inchise momentan!</b> <br />

			( Pentru nelamuriri citeste <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )";

	}

	else if ($settings['votplusses'] > $uplusses)

	{

		echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> You need ($ settings [ 'votplusses']) plusses to vote! You have only $ uplusses plusses</b> <br />

		( Pentru nelamuriri citeste <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )";

	}

	else if (isset($_GET['vote']) && $_GET['vote'] == 'y' && $who > 0)

	{

		if (!$voted && $user_id1 != $uid && $user_id2 != $uid)

			$res = mysql_query("INSERT INTO beauty_votes (category_id, candidate_id, voter) VALUES ($category, $who, $uid)");

		

		if ($res)

		{

			echo "<img src=\"images/ok.gif\" alt=\"O\"/> <b>You voted on $candidate</b>";

			

			// substract plusses

			mysql_query("UPDATE ibwf_users SET plusses=". ($uplusses - $settings['votplusses']) ." WHERE id='".$uid."'");

		}

		else 

			echo "<img src=\"images/notok.gif\" alt=\"X\"/> <b>Invalid vote! Try later!</b>";

	}

	else if ($who > 0)

	{

		echo '<p>You chose to vote on '. $candidate .'. Are you sure?</p>';

			

		echo '<a href="beauty_contest.php?action=vote&vote=y&who='. $who . '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'"><img src="images/ok.gif" /> of</a>';

		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

		echo '<a href="beauty_contest.php?who='. $who . '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'"><img src="images/notok.gif" /> Now</a>';

	}



	echo "<br /><br />";

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	echo '</body>';

}



else if ($action == 'rules' && $uid > 0)

{

    echo '<head>';

    echo '<title>Rules "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body>';

	

	echo '<h2>Beauty Contest - Rules</h2>';

	

	addonline(getuid_sid($sid), 'Viewing Rules "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'.VERS.'">'.$categories[1].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'.VERS.'">'.$categories[2].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'.VERS.'">'.$categories[3].'</a>';

	echo '<br /><br /><br />';

	

 echo '<div align="left" style="margin-left: 20px">

 <h1> Beauty Contest....</h1>

<p>

  1. To participate in the contest, you must have<strong>MINIMUM</strong> 250 plusses!<br />

  2. Each participant is entitled to upload <strong>MAX.</strong> 3 pictures!<br />

  3. Once you have voted for a person, you will not be able to vote during the current month (and youll see the sign in the right of the person you voted)! <br />

  4. To participate in <strong> Married </ strong> (couple of) you really need to get married first.<br />

  5. To participate in <strong> Married </ strong>, you should have profile pictures, team pictures, photo face, and a collage pictures together! <br />

  6. Winners will be announced after the votes were accumulated during the current month! <br />

  



  7. At the end of each month, in the TOP  winners will be awarded and the top charts will be reset. <br />





</p>

<h3> .....Nice contest</h3></div>';

	

	echo '<br /><br />';

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	

	echo "<br /><br />";

	if (VERS == 'web')

		echo "<img src=\"images/home.gif\" /> <a href=\"index.php?action=main&amp;sid=$sid\"> Previous</a>";

	else

		echo "<img src=\"images/home.gif\" /> <a href=\"indexwml.php?action=main&amp;sid=$sid\"> Previous</a>";

	

	echo '</body>';

}



// admin

else if ($action == 'admin' && $uid > 0)

{

    echo '<head>';

    echo '<title>Manage "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center">';

	

	echo '<h2>Beauty Contest - Settings</h2>';

	

	addonline(getuid_sid($sid), 'Manage "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'.VERS.'">'.$categories[1].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'.VERS.'">'.$categories[2].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'.VERS.'">'.$categories[3].'</a>';

	echo '<br /><br /><br />';

	

	// if form submitted

	if ($_POST['submitted'])

	{

		$regon = ($_POST['regon'] ? 'y' : 'n');

		$voton = ($_POST['voton'] ? 'y' : 'n');

		$endon = ($_POST['endon'] ? 'y' : 'n');

		$starton = ($_POST['starton'] ? 'y' : 'n');

		//

		$regstart = $_POST['regstart'];

		$regend = ($regstart > $_POST['regend'] ? $regstart : $_POST['regend']);

		$votstart = $_POST['votstart'];

		//

		$regplusses = (empty($_POST['regplusses']) || !is_numeric($_POST['regplusses']) ?  0 : $_POST['regplusses']);

		$votplusses = (empty($_POST['votplusses']) || !is_numeric($_POST['votplusses']) ?  0 : $_POST['votplusses']);

		//

		$cstart = $_POST['start'];

		$end = $_POST['end'];



		// update settings

		mysql_query("UPDATE beauty_settings SET value='$regon' WHERE name='regon'");

		mysql_query("UPDATE beauty_settings SET value='$voton' WHERE name='voton'");

		mysql_query("UPDATE beauty_settings SET value='$endon' WHERE name='endon'");

		mysql_query("UPDATE beauty_settings SET value='$starton' WHERE name='starton'");

		//

		mysql_query("UPDATE beauty_settings SET value='$regstart' WHERE name='regstart'");

		mysql_query("UPDATE beauty_settings SET value='$regend' WHERE name='regend'");

		mysql_query("UPDATE beauty_settings SET value='$votstart' WHERE name='votstart'");

		//

		mysql_query("UPDATE beauty_settings SET value='$regplusses' WHERE name='regplusses'");

		mysql_query("UPDATE beauty_settings SET value='$votplusses' WHERE name='votplusses'");

		//

		mysql_query("UPDATE beauty_settings SET value='$cstart' WHERE name='start'");

		mysql_query("UPDATE beauty_settings SET value='$end' WHERE name='end'");

		

		// get contest settings

		$settings = array();

		$sett = mysql_query("SELECT name, value FROM beauty_settings");

		while ($row = mysql_fetch_array($sett))

		{

			$settings[$row['name']] = $row['value'];

		}

	}



	// form ////////////////////////////////////////////

	//

	echo '<form action="beauty_contest.php?action=admin&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'" method="post">';



	// registration data

	echo '<input name="regon" type="checkbox"'. ($settings['regon'] == 'y' ? 'checked="checked"' : '') .'/> <b>Registrations:</b> <br /><br />

	        start <select name="regstart">';

	//

	for ($i = 1; $i <= date('t'); $i++)

		echo "<option value=\"$i\" ". ($settings['regstart'] == $i ? 'selected="selected"' : '') .">$i</option>";

	if ($settings['regstart'] > date('t'))

		echo "<option value=\"{$settings['regstart']}\" selected=\"selected\">{$settings['regstart']}</option>";

	echo '</select>

	        end <select name="regend">';

	//

	for ($i = 1; $i <= date('t'); $i++)

		echo "<option value=\"$i\" ". ($settings['regend'] == $i ? 'selected="selected"' : '') .">$i</option>";

	if ($settings['regend'] > date('t'))

		echo "<option value=\"{$settings['regend']}\" selected=\"selected\">{$settings['regend']}</option>";

	echo '</select>

	        - plusses <input type="text" name="regplusses" size="4" value="'. $settings['regplusses'] .'" maxlength="6" />

	        <br />----------<br /><br />';

	        

	// vote data

	echo '<input name="voton" type="checkbox" '. ($settings['voton'] == 'y' ? 'checked="checked"' : '') .' /> <b>Vote:</b> <br /><br />

	        start <select name="votstart">';

	//

	for ($i = 1; $i <= date('t'); $i++)

		echo "<option value=\"$i\" ". ($settings['votstart'] == $i ? 'selected="selected"' : '') .">$i</option>";

	if ($settings['votstart'] > date('t'))

		echo "<option value=\"{$settings['votstart']}\" selected=\"selected\">{$settings['votstart']}</option>";

	echo '</select>

	        - plusses <input type="text" name="votplusses" size="4" value="'. $settings['votplusses'] .'" maxlength="6" />

	        <br />----------<br /><br />';

	        

	// start - end data

	// end

	echo '<input name="endon" type="checkbox" '. ($settings['endon'] == 'y' ? 'checked="checked"' : '') .' /> <b>Lock after</b>

	    	<select name="end">';

	//

	for ($i = 1; $i <= 30; $i++)

		echo "<option value=\"$i\" ". ($settings['end'] == $i ? 'selected="selected"' : '') .">$i</option>";

	//

	echo '</select> days';

	echo '<br /><br />';

	//

	// start

	echo '<input name="starton" type="checkbox" '. ($settings['starton'] == 'y' ? 'checked="checked"' : '') .' /> <b>Opening after</b>

	    	<select name="start">';

	//

	for ($i = 1; $i <= 10; $i++)

		echo "<option value=\"$i\" ". ($settings['start'] == $i ? 'selected="selected"' : '') .">$i</option>";

	//

	echo '</select> Days

			<br /><br />

			<input type="hidden" name="submitted" value="1" />

			<input type="submit" value="Edit" />

		</form>';

	//================================

	// start contest

	if (empty($settings['started']) || !empty($settings['ended']))

	{

		echo '--------------';

		echo '<form action="beauty_contest.php?action=admin&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'" method="post">

			<input type="submit" value="Open" />

			<input type="hidden" name="startcontest" value="1" />

		</form>';

	}

	// end contest

	else if (empty($settings['ended']))

	{

		echo '--------------';

		echo '<form action="beauty_contest.php?action=admin&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'" method="post">

			<input type="submit" value="Close" />

			<input type="hidden" name="endcontest" value="1" />

		</form>';

	}

	//////////////////////////////////////////////////////////////////////

	

	echo '<br />';

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	

	echo '</body>';

}



// prizes

else if ($action == 'prizes' && $uid > 0)

{

    echo '<head>';

    echo '<title>Prizes "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center">';

	

	echo '<h2>Beauty Contest - Prizes</h2>';

	

	addonline(getuid_sid($sid), 'Viewing Prizes - "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	// update form =========================================

	if (isset($_POST['modify']))

	{

		$plusses = $_POST['plusses'];

		$money = $_POST['money'];

		

		for ($i = 0; $i < count($plusses); $i++)

		{

			list($prizeid) = mysql_fetch_array(mysql_query("SELECT id FROM beauty_prizes WHERE category_id=$category ORDER BY id ASC LIMIT $i, 1"));



			mysql_query("UPDATE beauty_prizes SET plusses=$plusses[$i], money=$money[$i] WHERE id=$prizeid");

		}

	}

	// add prize

	else if (isset($_POST['addprize']))

	{

		$nprizes = $_POST['nprizes'];

		

		for ($i = 0; $i < $nprizes; $i++)

			mysql_query("INSERT INTO beauty_prizes (category_id) VALUES ($category)");

	}

	// delete prize

	else if (isset($_POST['delprize']))

	{

		$nprizes = $_POST['nprizes'];



		mysql_query("DELETE FROM beauty_prizes WHERE category_id=$category ORDER BY id DESC LIMIT $nprizes");

	}

	//=====================================================



	$prizes = mysql_query("SELECT * FROM beauty_prizes WHERE category_id=$category ORDER BY id ASC");

	

	echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'.VERS.'">'.$categories[1].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'.VERS.'">'.$categories[2].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'.VERS.'">'.$categories[3].'</a>';

	echo '<br /><br />';

	

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Inapoi</a>';

	echo '<br /><br />';

	

	echo '<form action="beauty_contest.php?action=prizes&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'" method="post">';

	echo '<table align="center" bgcolor="'. $bg2 .'" cellspacing="5" cellpadding="6">

			<tr bgcolor="'. $bg1  .'"><td colspan="3">Prize - <b>'. $category_name .'</b></td></tr>

	        <tr bgcolor="'. $bg2 .'">

	        	<td>Loc</td>

	            <td>Plusses</td>

	            <td>Euro</td>

	        </tr>';

	

	$i = 1;

	while ($row = mysql_fetch_array($prizes))

	{

		echo '<tr align="center" bgcolor="'. $bg1 .'">

        	<td>'. $i++ .'. </td>';

        

		if ($uperm >= UPERM)

            echo '<td><input type="text" name="plusses[]" size="5" value="'. $row['plusses'] .'" maxlength="6" /> +</td>

            	<td><input type="text" name="money[]" size="2" value="'. $row['money'] .'" maxlength="3" /> &euro;</td>';

        else

        	echo '<td><b>'. $row['plusses'] .'</b> +</td>

        		<td><b>'. $row['money'] .'</b> &euro;</td>';

        

		echo '</tr>';

	}

	echo '</table>';

	echo '<br />';



	if ($uperm >= UPERM)

	{

		echo '<input type="submit" value="Edit" />';

		echo '<input type="hidden" name="modify" value="1" />';

		echo '</form>';

	}

	

	if ($uperm >= UPERM)

	{

		// add prize form -------------------

		echo '<form action="beauty_contest.php?action=prizes&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'" method="post">';

		echo '<select name="nprizes">';

		//

		for ($i = 1; $i <= 5; $i++)

			echo "<option value=\"$i\">$i</option>";

		echo '</select>';

		//

		echo '<input type="submit" value="Add" />

			  <input type="hidden" name="addprize" value="1" />

		</form>';

		//--------------------------------------

		// delete prize form -------------------

		echo '<form action="beauty_contest.php?action=prizes&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'" method="post">';

		echo '<select name="nprizes">';

		//

		for ($i = 1; $i <= mysql_num_rows($prizes); $i++)

			echo "<option value=\"$i\">$i</option>";

		echo '</select>';

		//

		echo '<input type="submit" value="Delete" />

			  <input type="hidden" name="delprize" value="1" />

		</form>';

		//--------------------------------------

	}



	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	

	echo '</body>';

}



// top

else if ($action == 'top' && $uid > 0)

{

    echo '<head>';

    echo '<title> "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center">';

	

	echo '<h2>Beauty Contest - Top</h2>';

	

	addonline(getuid_sid($sid), 'Viewing "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	echo '<a href="beauty_contest.php?category=1&sid='.$sid.'&'.VERS.'">'.$categories[1].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'&'.VERS.'">'.$categories[2].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'&'.VERS.'">'.$categories[3].'</a>';

	echo '<br /><br /><br />';

	

	$candidates = array();

	$res = mysql_query("SELECT id FROM beauty_candidates WHERE category_id=$category");

	while ($row = mysql_fetch_array($res))

		$candidates[] = $row['id'];

		

	// find the nr of votes for each candidate -------------------------------

	//

	$winners = array();

	//

	// first category - miss

	foreach ($candidates as $candidate)

		list($winners[$candidate]) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM beauty_votes WHERE candidate_id=$candidate"));



	// sort winners ---------------

	arsort($winners, SORT_NUMERIC);



	echo '<table align="center" bgcolor="'. $bg2 .'" cellspacing="5" cellpadding="6">';

	echo '<tr><td><b>'. $categories[$category] .'</b></td><td><b>No of Votes:</b></td></tr>';

	foreach ($winners as $candidate_id => $votes)

	{

		$candidate = mysql_fetch_array(mysql_query("SELECT * FROM beauty_candidates WHERE id=$candidate_id"));

		//

		list($sex1) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$candidate['user_id1']."'"));

		list($sex2) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$candidate['user_id2']."'"));

		$nick1 = getnick_uid($candidate['user_id1']);

		$nick2 = getnick_uid($candidate['user_id2']);

		//

		if ($category == 3)

		{

			if ($sex1 == 'M')

				$candidate_name = $nick1 . '<br />' . $nick2;

			else

				$candidate_name = $nick2 . '<br />' . $nick1;

		}

		else $candidate_name = $nick1;

			

		echo '<tr bgcolor="'. $bg1 .'"><td><a href="beauty_contest.php?action=details&who='. $candidate_id .'&category='. $category .'&sid='. $sid .'&'.VERS.'">'. $candidate_name .'</a></td>

				<td>'. $votes .'</td>

			</tr>';

	}

	echo '</table>';

	

			list($sex1) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$row['user_id1']."'"));

			list($sex2) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$row['user_id2']."'"));

			$sexname1 = ($sex1 == 'M' ? 'Barbat' : 'Femeie');

			$sexname2 = ($sex2 == 'M' ? 'Barbat' : 'Femeie');

			$nick1 = getnick_uid($row['user_id1']);

			$nick2 = getnick_uid($row['user_id2']);



			

	

	echo '<br /><br />';

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	

	echo '</body>';

}



else if ($action == 'delcandidate'&& $uid > 0)

{

    echo '<head>';

    echo '<title>Vote "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center" bgcolor="'. $bg1 .'">';

	

	echo '<h2>Beauty Contest - Delete Participant</h2>';

	

	addonline(getuid_sid($sid), '"Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$who = $_GET['who'];

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	list($user_id1, $user_id2) = mysql_fetch_array(mysql_query("SELECT user_id1, user_id2 FROM beauty_candidates WHERE id='".$who."'"));

	

	list($sex1) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$user_id1."'"));

	list($sex2) = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$user_id2."'"));

	$nick1 = getnick_uid($user_id1);

	$nick2 = getnick_uid($user_id2);

	// users profile

	if (VERS == 'web')

	{

		$profile1 = '<a href="index.php?action=viewuser&who='. $user_id1 . '&sid='. $sid .'">'.$nick1.'</a> ';

		$profile2 = '<a href="index.php?action=viewuser&who='. $user_id2 . '&sid='. $sid .'">'.$nick2.'</a> ';

	}

	else

	{

		$profile1 = '<a href="indexwml.php?action=viewuser&who='. $user_id1 . '&sid='. $sid .'">'.$nick1.'</a> ';

		$profile2 = '<a href="indexwml.php?action=viewuser&who='. $user_id2 . '&sid='. $sid .'">'.$nick2.'</a> ';

	}

	

	if ($category == 3)

	{

		if ($sex1 == 'M')

			$candidate = "$profile1 - $profile2";

		else

		  $candidate = "$profile2 - $profile1";

	}

	else $candidate = $profile1;

	

	if (!empty($settings['ended']) || empty($settings['started']))

	{

		echo "<img src=\"images/notok.gif\" alt=\"X\"/><b> The contest is closed</b> <br />

		( Pentru nelamuriri citeste <a href=\"beauty_contest.php?action=rules&s=$start&p=$pages&category=$category&sid=$sid&".VERS."\">Rules</a> )";

	}

	else if (isset($_GET['del']) && $_GET['del'] == 'y' && $uperm >= UPERM)

	{



		mysql_query("DELETE FROM beauty_candidates WHERE id='".$who."'");

		mysql_query("DELETE FROM beauty_gallery WHERE candidate_id='".$who."'");

		mysql_query("DELETE FROM beauty_votes WHERE candidate_id='".$who."'");

		

		echo "<img src=\"images/ok.gif\" alt=\"OK\" />";

	}

	else if ($uperm >= UPERM)

	{

		echo '<p>You have chosen to delete the '. $candidate .'. Are you sure?</p>';

			

		echo '<a href="beauty_contest.php?action=delcandidate&del=y&who='. $who . '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'"><img src="images/ok.gif" /> of</a>';

		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

		echo '<a href="beauty_contest.php?who='. $who . '&s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'"><img src="images/notok.gif" /> Now</a>';

	}



	echo "<br /><br />";

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'&'.VERS.'">Back</a>';

	echo '</body>';

}



else if ($action == 'dummy' && $uid > 0)

{

    echo '<head>';

    echo '<title> "Beauty Contest"</title>';

    if (VERS == 'web') echo '<link rel="stylesheet" type="text/css" href="../themes/tema.css">';

    echo '</head>';

    echo '<body align="center">';

	

	echo '<h2>Beauty Contest</h2>';

	

	addonline(getuid_sid($sid), 'Viewing "Beauty Contest"', "");

	

	// check PM

	$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE unread='1' AND touid='".$uid."'"));

	$unrd="[".$unreadinbox[0]."]";

	if ($unreadinbox[0]>0)

	{	

		echo '-----<br/>';

		echo "<b>Ai: <a href=\"postawml.php?action=main&amp;sid=$sid\">$unrd</a> PMs</b><br/>-----<br/>";

	}

	

	$start = $_GET["s"];

	$pages = $_GET["p"];

	

	echo '<a href="beauty_contest.php?category=1&sid='.$sid.'">'.$categories[1].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=2&sid='.$sid.'">'.$categories[2].'</a>';

	echo ' &nbsp;|&nbsp; <a href="beauty_contest.php?category=3&sid='.$sid.'">'.$categories[3].'</a>';

	echo '<br /><br /><br />';

	

	// TODO

	

	echo '<br /><br />';

	echo '<a href="beauty_contest.php?s='. $start .'&p='. $pages .'&category='. $category .'&sid='. $sid .'">Back</a>';

	

	echo '</body>';

}



?>

</html>