'game' and name <>'games') and ( (main='0' and matches > 1) OR main='1') order by name asc;";
if ( $phone==1 || $tablet==1 )
{
$query = "select catid, name, mobilematches as matches, main, icon from gamecat where status='0' and ( (mobilemain='0' and mobilematches > 1) OR mobilemain='1') and
(name not like '#%' AND name not like '%,%' AND name not like '%.' AND name <>'game' and name <>'games') order by name asc;";
}
?>
'game' and name <>'games') and ( (main='0' and matches > 1) OR main='1') and name like '".$one."%' order by name asc";
$link = new mysqli('localhost', 'gamez', 'zentech2', 'gamez-db');
mysqli_set_charset($link, "utf8");
$cols = 7; //number of columns, you can set this to any positive integer
$values = array();
$dupcheck= array();
$result = $link->query($query);
$numrows = $result->num_rows;
$rows_per_col = ceil($numrows / $cols);
for ($c=1;$c<=$cols;$c++) { $values['col_'.$c] = array(); }
$c = 1;
$r = 1;
unset($matches);
unset($main);
while ($row = $result->fetch_assoc()) {
$catnv=stripslashes($row['name']);
if( isset($dupcheck[$catnv]) ) continue;
$dupcheck[$catnv]=1;
$matches[$catnv]=$row['matches'];
$main[$catnv]=$row['main'];
$values['col_'.$c][$r] = stripslashes($row['name']);
if ($r == $rows_per_col) { $c++; $r = 1; } else { $r++; }
}
echo '
-1 AND ismobile='1' AND ";
}
// $whereclause="category=";
// $orderby="order by status desc, score desc, plays desc, vendorweight desc ";
// $orderby="order by status desc, vendorweight desc, score desc, plays desc";
// $orderby="order by plays desc, score desc, status desc, vendorweight desc ";
// $orderby="order by plays30 desc, plays desc, kscore desc, score desc, status desc, vendorweight desc ";
$orderby="order by (flashcheckresult > -1 ) DESC, plays30 desc, plays desc, kscore desc, score desc, status desc, vendorweight desc ";
$orderby="order by promoted2 desc, promoted desc, (flashcheckresult > -1 ) DESC, plays desc, kscore desc, score desc, status desc, vendorweight desc ";
$recentadd="";
$plays="";
$learning="";
$starrating="";
$shuffle="";
$nowplaying="";
$nowplayingmg="";
if ( isset($_GET['recentadd']) && $_GET['recentadd']==1 )
{
$plays="";
$starrating="";
$shuffle="";
$nowplaying="";
$nowplayingmg="";
$recentadd=1;
$setcategory="Most Recent";
$orderby=" order by seq desc ";
}
$learnwhereand="";
$learnreq=0;
if(stripos($greq,'learning') !== false) $learnreq=1;
if ( ( isset($_GET['learning']) && $_GET['learning']==1) || $learnreq==1 )
{
$gs="learning";
$learning=1;
$setcategory="Learning";
$learnwhereand=" AND islearning='1' ";
$orderby="order by (flashcheckresult > -1 ) DESC, plays30 desc, plays desc, kscore desc, score desc, vendorweight desc, status desc ";
if ( isset($_GET['recentadd'] ) )
{
$orderby="order by seq desc, plays desc, kscore desc, score desc, vendorweight desc, status desc ";
}
}
if($learnreq==1 && isset($_GET['recentadd']) && $_GET['recentadd']==1 )
{
$setcategory="Most Recent Learning";
}
if ( isset($_GET['starrating']) && $_GET['starrating']==1 )
{
$recentadd="";
$plays="";
$shuffle="";
$nowplaying="";
$nowplayingmg="";
$setcategory="Highest Rated";
if ( isset($_GET['learning']) && $_GET['learning']==1 )
{
$setcategory="Highest Rated Learning";
}
$orderby=" order by score desc, plays desc, status desc, vendorweight desc ";
$starrating=1;
}
if ( isset($_GET['plays']) && $_GET['plays']==1 )
{
$recentadd="";
$starrating="";
$shuffle="";
$nowplaying="";
$nowplayingmg="";
$setcategory="Most Played";
if ( isset($_GET['learning']) && $_GET['learning']==1 )
{
$setcategory="Most Played Learning";
}
$plays=1;
$orderby=" order by plays desc, score desc, status desc, vendorweight desc ";
}
if ( isset($_GET['shuffle']) )
{
$recentadd="";
$plays="";
$starrating="";
$setcategory="Random";
if ( isset($_GET['learning']) && $_GET['learning']==1 )
{
$setcategory="Random Learning";
}
$shuffle=1;
$orderby=" ORDER BY RAND() ";
}
$whereclause=" where $where2 status > $statusmarker $flashandcheck $gamedup ";
$whereclausesearch=" $where2 status > $statusmarker ";
if ( isset($_GET['nowplaying']) && $_GET['nowplaying']=='1' )
{
// error_log(" AAAA ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Now playing request ");
$recentadd="";
$plays="";
$starrating="";
$setcategory="Now Playing";
if ( isset($_GET['learning']) && $_GET['learning']==1 && $_GET['nowplaying']=='1' )
{
$setcategory="Now Playing Education";
}
$shuffle=1;
$orderby=" ORDER BY changedate desc ";
$whereclause=" where $where2 status > $statusmarker AND changedate > (NOW() - INTERVAL 120 MINUTE) and seq <>'192192' ";
$query = "SELECT flashcheckresult, score, seq, source, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions
FROM gamesplayed
$whereclause $ismobileandwhere AND status > -1 $flashandcheck $orderby ";
error_log(" NOW PLAYING QUERY ".$query);
}
else if ( isset($_GET['nowplayingmg']) && $_GET['nowplayingmg']=='1' && strlen($sessionid) > 10 )
{
$recentadd="";
$plays="";
$starrating="";
$nowplaying="";
$setcategory="My Recently Played";
$shuffle=1;
$orderby=" ORDER BY changedate desc ";
// $sessionid = session_id();
$whereclause=" where $where2 status > $statusmarker ";
$query = "SELECT flashcheckresult, score, seq, source, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions
FROM gamesplayed
$whereclause AND status > -1 AND sessionid = '".$sessionid."' $orderby ";
//echo $query;
}
else
{
$query = "SELECT flashcheckresult, promoted, score, seq, source, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
$whereclause $ismobileandwhere AND status > -1 $flashandcheck $gamedup $orderby ";
}
// error_log(" ***************************************** NOW PLAYING *********************************************");
// echo $query;
// $query = "SELECT * FROM games";
if ( isset($_REQUEST['gamesearch']) && strlen($_REQUEST['gamesearch']) > 1 )
{
$gs=trim($_REQUEST['gamesearch']);
$gs=trim($_REQUEST['gamesearch']);
// echo " GS REQ $gs";
if( strlen($gs) > 1 ) {
$gs=cleangs($gs);
//echo " GS2 REQ $gs";
}
$setcategory=$gs;
$gs=$mysqli->real_escape_string($gs);
// echo " GS REQ $category ".$setcategory;
if(isset($gs) && strlen($gs) > 1)
{
// main search
// echo "GS: $gs ";
if ( !isset($catlistset) )
{
$catquery="select name from gamecat where status='0' ";
$catlistset = 1;
$catresult = $mysqli->query($catquery);
while($catrow = $catresult->fetch_assoc())
{
$c=strtolower($catrow['name']);
$thecatlist[$c]=1;
//echo $c.' ';
}
}
$gs =html_entity_decode($_REQUEST['gamesearch'], ENT_QUOTES | ENT_HTML5 | ENT_IGNORE, 'UTF-8');
$gs_stem = removeCommonWordsLarge($gs);
$gs_stem = stemit($gs_stem);
//echo "GS: ".$gs_stem;
$query = "SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
WHERE status > $statusmarker $learnwhereand $ismobileandwhere AND status > -1 $flashandcheck $gamedup AND MATCH(title, tags, description, category, instructions) AGAINST ('\"$gs\"' IN BOOLEAN MODE)
$orderby " ;
$queryb = "SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions, stemed FROM games
WHERE status > $statusmarker $learnwhereand $ismobileandwhere AND status > -1 $flashandcheck $gamedup AND MATCH(title, tags, description, category, instructions,stemed) AGAINST ('\"$gs_stem\"' IN BOOLEAN MODE)
$orderby " ;
$localset = 0;
if ( isset($_REQUEST['localsearch']) && $_REQUEST['localsearch']=="1" || isset($_REQUEST['src']) && $_REQUEST['src']=="kzsearch" )
{
error_log("LOCAL SEARCH SET for ".$gs_stem);
$localset = 1;
}
// related=0&learning=0&recentadd=&starrating=&cat=&gamesearch=Racing&plays=1&catlist
$gs_stem = trim($gs_stem);
$query = "SELECT *,
( (2.3 * (MATCH(title) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.8 * (MATCH(tags) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.4 * (MATCH(description) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.4 * (MATCH(instructions) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.7 * (MATCH(category) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (2.3 * (MATCH(stemed) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
)
AS relevance
FROM games
WHERE (MATCH(title, tags,description, instructions, category, stemed) AGAINST ('$gs_stem' IN BOOLEAN MODE) )
AND STATUS > -1 and dup = '0' $flashandcheck order by (flashcheckresult > -1 ) DESC, relevance DESC, plays DESC ";
if($localset==1)
{
$query = "SELECT *,
( (2.3 * (MATCH(title) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.8 * (MATCH(tags) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.4 * (MATCH(description) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.4 * (MATCH(instructions) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (0.7 * (MATCH(category) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
+ (2.3 * (MATCH(stemed) AGAINST ('$gs_stem' IN BOOLEAN MODE)))
)
AS relevance
FROM games
WHERE (MATCH(title, tags,description, instructions, category, stemed) AGAINST ('$gs_stem' IN BOOLEAN MODE) )
AND STATUS > -1 and dup = '0' order by relevance DESC, plays DESC ";
}
//
// echo "GS: ".$gs.' | '.$thecatlist[ strtolower($gs)];
// print_r($thecatlist);
// use for all cases
if ( isset($_REQUEST['catlist']) || isset($thecatlist[ strtolower($gs)]) )
{
$related=1;
}
//echo $querya;
//echo $query4;
if($related==1)
{
$matchterm=removeCommonWords2z($gs);
$query = "SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
WHERE status > $statusmarker $learnwhereand $ismobileandwhere AND status > -1 $flashandcheck $gamedup AND MATCH(title, tags, description, category, instructions) AGAINST ('$matchterm' IN BOOLEAN MODE)
$orderby " ;
}
}
if($setcategory=="all" || $setcategory=="learning" )
{
$query = "SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
$whereclause $ismobileandwhere AND status > -1 $flashandcheck $gamedup $learnwhereand $orderby " ;
}
// echo $query;
}
// error_log($query);
// error_log("BBBBBBB ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Now playing request ");
$thedevice="computer";
// echo "$setcategory ";
if($tablet==1 || $phone==1) {
$thedevice="mobile";
$query="SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
where status > -1 AND status <> '-4' AND status <> '-3' $flashandcheck $gamedup $ismobileandwhere $learnwhereand $orderby ";
if ( isset($_GET['nowplaying']) && $_GET['nowplaying']=='1' )
{
$orderby=" ORDER BY changedate desc ";
$whereclause=" where $where2 status > $statusmarker AND changedate > (NOW() - INTERVAL 120 MINUTE) ";
$query = "SELECT flashcheckresult, score, seq, source, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM gamesplayed
$whereclause AND status > -1 $flashandcheck $ismobileandwhere $orderby ";
}
if ( isset($_GET['nowplayingmg']) && $_GET['nowplayingmg']=='1' )
{
$orderby=" ORDER BY changedate desc ";
$whereclause=" where $where2 status > $statusmarker ";
$query = "SELECT flashcheckresult, score, seq, source, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM gamesplayed
$whereclause AND status > -1 AND sessionid='".$sessionid."' $orderby ";
}
// error_log("++++++++++++++++++++++++++++++++++ GAME LOG FINAL QUERY ");
// error_log($query);
if( isset($setcategory) && strlen($setcategory) > 2 && !($setcategory=="all"
|| $setcategory=="learning" || $setcategory=="Most Recent" || $setcategory=="Most Played" || $setcategory=="Highest Rated"
|| $setcategory=="Random"
) )
{
if(isset($gs) && strlen($gs) > 1)
{
$query = "SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
WHERE status > $statusmarker $learnwhereand AND status > -1 $flashandcheck $gamedup $ismobileandwhere AND MATCH(title, tags, description, category, instructions) AGAINST ('\"$gs\"' IN BOOLEAN MODE)
$orderby " ;
if($related==1)
{
$matchterm=removeCommonWords2z($gs);
$query = "SELECT flashcheckresult, promoted, score, seq, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
WHERE status > $statusmarker $learnwhereand AND status > -1 $flashandcheck $gamedup $ismobileandwhere AND MATCH(title, tags, description, category, instructions) AGAINST ('$matchterm' IN BOOLEAN MODE)
$orderby " ;
}
}
}
}
//echo "SC: ".$setcategory;
//if($setcategory == "All")$_GET['pop'] = 30;
if ( isset($_GET['pop']) && $_GET['pop']>0 && is_numeric($_GET['pop']) )
{
$popv=$_GET['pop'];
$popv=$mysqli->real_escape_string($popv);
if($popv==1) $setcategory="Today's Hot";
if($popv==7) $setcategory="Weekly Hot";
if($popv==30) $setcategory="Monthly Hot";
if($popv>300) $setcategory="All Time Hot";
$query="SELECT flashcheckresult, games.score, games.seq, games.vendorweight, games.category, games.status, games.counter, games.value,
games.plays, games.cloud, games.seotitle, games.title, games.img1, hotgames.hits as gamehits, games.changedate, games.tags, games.description, games.instructions
FROM games
RIGHT JOIN hotgames
ON games.seq=hotgames.seq WHERE hotgames.device='$thedevice' AND hotgames.cycle='$popv' AND games.status > -1 $flashandcheck $gamedup $ismobileandwhere
ORDER BY hotgames.hits DESC";
}
if( $ip=="104.60.17.86" )
{
// echo "EDIT MODE ";
// $query = "SELECT flashcheckresult, promoted, score, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1 FROM games where status < 0 order by plays desc";
//echo "$query ";
}
//echo $query;
$total_pages=0;
$result = $mysqli->query($query);
if ($result) {
$total_pages = $result->num_rows;
//error_log("FINAL QUERY");
//error_log($query);
}
$tpd=number_format($total_pages);
// echo " RESULTS $tpd ";
if($tpd < 1 )
{
if(isset($gs) && strlen($gs) > 1)
{
$matchterm=removeCommonWords2z($gs);
$query = "SELECT flashcheckresult, promoted, seq, score, vendorweight, category, status, counter, value, plays, cloud, seotitle, flash_file, title, img1, changedate, tags, description, instructions FROM games
WHERE status > -1 $flashandcheck $gamedup $learnwhereand $ismobileandwhere AND MATCH(title, tags, description, category, instructions) AGAINST ('$matchterm' IN BOOLEAN MODE)
$orderby " ;
}
if( $ip=="x104.60.17.86" )
{
// echo "q2 $query ";
}
//echo $query;
//error_log($query);
$result = $mysqli->query($query);
$total_pages = $result->num_rows;
$tpd=number_format($total_pages);
}
// error_log($query);
if( strlen($setcategory)<2 ) $setcategory="";
$setcategoryd=ucwords(displaycat($setcategory));
if ( isset($_GET['plays']) && $_GET['plays']==1 )
{
$setcategoryd="Most Played $setcategoryd";
}
if ( isset($_GET['starrating']) && $_GET['starrating']==1 )
{
$setcategoryd="Highest Rated $setcategoryd";
}
if ( isset($_GET['shuffle']) && $_GET['shuffle']==1 )
{
$setcategoryd="Random $setcategoryd";
}
if (strpos($setcategoryd,'Most Played Most Played') !== false) {
$setcategoryd="Most Played";
}
if (strpos($setcategoryd,'Highest Rated Highest Rated') !== false) {
$setcategoryd="Highest Rated";
}
if (strpos($setcategoryd,'Random Random') !== false) {
$setcategoryd="Random";
}
$mbgame="";
if( $mobile==1 || $tablet==1)
{
$mbgame=" Mobile";
}
echo "
";
?>
1 ) {
$gs=cleangs($gs);
}
// use function!
$gs=$mysqli->real_escape_string($gs);
// echo $query;
$result = $mysqli->query($query);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "
";
//previous button
if ($page > 1)
{
$pagination.= "<<< previous";
$singlepageleft=" < ";
}
else
{
$pagination.= "<<< previous";
$singlepageleft=" < ";
}
//pages
$singlepageleft=" < ";
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "$counter";
else
$pagination.= "$counter";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "$counter";
else
$pagination.= "$counter";
}
$pagination.= "...";
$pagination.= "$lpm1";
$pagination.= "$lastpage";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "1";
$pagination.= "2";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "$counter";
else
$pagination.= "$counter";
}
$pagination.= "...";
$pagination.= "$lpm1";
$pagination.= "$lastpage";
}
//close to end; only hide early pages
else
{
$pagination.= "1";
$pagination.= "2";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "$counter";
else
$pagination.= "$counter";
}
}
}
//next button
if ($page < $counter - 1) {
$pagination.= "next >>>";
$singlepageright=" > ";
}
else {
$pagination.= "next >>>";
$singlepageright = " > ";
}
$pagination.= "