<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
define('IN_IORANGE', true);
require_once 'include/init.php';

$sort = isset($_GET['sort']) ? S::gp('sort', 'G') : 'favorites';
$sort = 'newbook' == $sort ? 0 : $sort;
$isOriginal = $_GET['s'] == 1 ? true : false;

$cNavArray = array(
    1 => '日点击',
    2 => '周点击',
    3 => '月点击',
    4 => '总点击',
    
    9 => '日红票',
    10 => '周红票',
    11 => '月红票',
    12 => '总红票',
    
    5 => '推荐榜',
	6 => '收藏榜',
    7 => '鲜花榜',
    8 => '挨砖榜',
);

$mapArray = array(
    1 => 'day',
    2 => 'week',
    3 => 'month',
    4 => 'click',
    5 => 'commend',
    6 => 'favorites',
    7 => 'flower',
    8 => 'egg',
    9 => 'd_red',
    10 => 'w_red',
    11 => 'm_red',
    12 => 'red',
);
            
$navArray = array();
$mergeArray = $isOriginal ? array('s'=>1) : array();

foreach ($cNavArray as $key => $value)
{
    if ($sort == $key)
    {
        $navArray[] = $value;
    }
    else
    {
        $navArray[] = ilink($value, url('top', array_merge(array('sort'=>$key), $mergeArray)));
    }
}

$condition = ' view = 1';
$orderBy = ' ORDER BY favorites DESC';
$month = date("Y-m");
if (!$sort)
{
    $condition .= " AND date_format(createdate, '%Y-%m') = '$month'";
}
if ($isOriginal)
{
    $condition .= ' AND type=2';
}

if (array_key_exists($sort, $mapArray))
{
    $orderBy = ' ORDER BY '.$mapArray[$sort] . ' DESC';
}
        
$sql = 'SELECT bookid,bookname,author,bookinfo,status,updatedate,lastchapterid,lastchaptername,typeid,size FROM '.Book::table().' WHERE '.$condition. $orderBy . S::sqlLimit(0, 30);
$books = $db->setQueryString($sql)->find();

include_once tpl('top');