<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
require_once "includes/tablefunction.inc" ;
function memberList() {
	global $db,$template,$sitepath,$loggedIn ;


		$filter = 'all' ;
		if ($_GET['filter'] != "") {
			$filter = $_GET['filter'] ;
		}
		$search = '' ;
		$nsearchvar = '' ;
		$lsearchvar = '' ;
		$searchurl = '' ;
		$sort = " ORDER BY `created` DESC" ;
		$newsel = " SELECTED" ;
		if ($_GET['lsearch'] != "") {
			$lsearchvar = $_GET['lsearch'] ;
		}
		if ($_GET['nsearch'] != "") {
			$nsearchvar = $_GET['nsearch'] ;
		}
		if ($_POST['namesearch'] != "") {
			$nsearchvar = quote_smart($_POST['namesearch']) ;
		}
		if ($_POST['locationsearch'] != "") {
			$lsearchvar = quote_smart($_POST['locationsearch']) ;
		}
		$newsel = "" ;
		$logsel = "" ;
		if (isset($_POST['namesearch'])) {
			$nsearchvar = quote_smart($_POST['namesearch']) ;
		}
		if (isset($_POST['locationsearch'])) {
			$lsearchvar = quote_smart($_POST['locationsearch']) ;
		}
		if ($_POST['membersort'] == 'newest') {
			$sort = " ORDER BY `created` DESC" ;
			$newsel = " SELECTED" ;
		}
		if ($_POST['membersort'] == 'login') {
			$sort = " ORDER BY `lastlogin` DESC" ;
			$logsel = " SELECTED" ;
		}
		$searchurl = $sitepath."community/_".$filter ;
		if ($nsearchvar != '') {
			$search .= " AND (username LIKE '%".$nsearchvar."%')" ;
			$searchurl .= "/__".urlencode($nsearchvar) ;
		}
		if ($lsearchvar != '') {
			$search .= " AND (location LIKE '%".$lsearchvar."%')" ;
			$searchurl .= "/___".urlencode($lsearchvar) ;
		}
		$query = "SELECT * FROM member WHERE (activationkey=0)" ;
		if ($_POST['agefilter'] == "") {
			$agefilter = "all" ;
			$sellall = " SELECTED" ;
		}
		else {
			$agefilter = quote_smart($_POST['agefilter']) ;
		}
		switch ($agefilter) {
			case "u18":
				$query .= " AND (age<18)" ;
				$sel_u18 = " SELECTED" ;
				break ;
			case "1825":
				$query .= " AND (age>=18 AND age<=25)" ;
				$sel_1825 = " SELECTED" ;
				break ;
			case "2635":
				$query .= " AND (age>=26 AND age<=35)" ;
				$sel_2635 = " SELECTED" ;
				break ;
			case "3650":
				$query .= " AND (age>=36 AND age<=50)" ;
				$sel_3650 = " SELECTED" ;
				break ;
			case "5165":
				$query .= " AND (age>=51 AND age<=65)" ;
				$sel_5165 = " SELECTED" ;
				break ;
			case "o65":
				$query .= " AND (age>65)" ;
				$sel_o65 = " SELECTED" ;
				break ;
		}
		if ($_POST['genderfilter'] == "") {
			$genderfilter = "all" ;
			$sel_either = " SELECTED" ;
		}
		else {
			$genderfilter = quote_smart($_POST['genderfilter']) ;
		}
		switch ($genderfilter) {
			case "male":
				$query .= " AND (gender=0)" ;
				$sel_male = " SELECTED" ;
				break ;
			case "female":
				$query .= " AND (gender=1)" ;
				$sel_female = " SELECTED" ;
				break ;
		}
		$query .= $search.$sort ;
		
		
		$output = '<div id="comsearchtop"><form action="'.$searchurl.'" method="post" name="memberform">
			<table>
			<tbody>
		
				<tr>
					<td>Age Filter</td>
					<td>
						<select name="agefilter" onChange="document.forms["memberform"].submit();">
							<option value="all"'.$sel_all.'>Any Age</option>
							<option value="u18"'.$sel_u18.'>Under 18</option>
							<option value="1825"'.$sel_1825.'>18-25</option>
							<option value="2635"'.$sel_2635.'>26-35</option>
							<option value="3650"'.$sel_3650.'>36-50</option>
							<option value="5165"'.$sel_5165.'>51-65</option>
							<option value="o65"'.$sel_o65.'>Over 65</option>
						</select>
					</td>
					<td>Search Username</td>
					<td><input type="text" size="30" name="namesearch" value="'.$nsearchvar.'" /></td>
				</tr>
				<tr>
					<td>Gender Filter</td>
					<td>
						<select name="genderfilter" onChange="document.forms["memberform"].submit();">
							<option value="either"'.$sel_either.'>Either Gender</option>
							<option value="male"'.$sel_male.'>Male</option>
							<option value="female"'.$sel_female.'>Female</option>
						</select>
					</td>
					<td>Search Location</td>
					<td><input type="text" size="30" name="locationsearch" value="'.$lsearchvar.'" /></td>
				</tr>
				<tr>
					<td>Sort by</td>
					<td>
						<select name="membersort" onChange="document.forms["memberform"].submit();">
							<option value="newest"'.$newsel.'>Newest Members</option>
							<option value="login"'.$logsel.'>last login</option>
						</select>
					</td>
					<td><input type="submit" class="biggerbutton" name="formsubmit" value="Search" /></td>
				</tr>

				</tbody></table></form></div>'.$filterlink ;

		
		$db->query($query) ;
		$resLV = $db->fetchAll() ;
		//Create output for member list results
		if (isset($_GET['page'])) {
			$output .= Tableview(10, $resLV, $_GET['page'], $sitepath."community") ;
		} else {
			$output .= Tableview(10, $resLV, 1, $sitepath."community") ;
		}
		return $output ;

}


?>
