<?php
/*
@author waychar
@技术支持 150572314@qq.com
@copyright 2018 waychar.cn 声明：本代码只用于学习交流使用，如果需要商业化，请购买授权，联系电话13435627874
*/
require_once 'model/article.php';

$article = new article();

if ($action == 'admin') {
    admin_check();
    //if had login
    $menu  = get($_GET['menu']);
    if ($menu) 
    {
        $sql_menu="  and menu = $menu ";
    }
    $sql ="select id,title,add_time from article where 1  $sql_menu order by id desc limit 0,100";
    $result = $article->get_data($sql);
    //login
    include 'view/admin_article_list.php';
}
elseif($action == 'add') {
    admin_check();
    //login
    include 'view/article_form.php';
}
elseif($action == 'edit') {
    admin_check();
    //login
    $id = get($_REQUEST['id']);
    $sql = "select * from article where id = ".$id;
    $result = $article->get_data($sql);
    include 'view/article_form.php';
}
elseif($action =='article_add')
{
    $race_id = get($_POST['race_id']);
    if(!$race_id)
    {
        $race_id= 0;
    }
    $sql ="INSERT INTO `article` ( `contant`, `race_id`,`add_time`, `title`, `menu`, `img_url`, `is_index`,`wx_url`) VALUES ('".get($_POST['contant_c'])."', '".$race_id."', '".get_now()."', '".get($_POST['title'])."', '".get($_POST['menu'])."', '".get($_POST['img_url'])."', '1','".get($_POST['wx_url'])."')";
    //die($sql);
    $article->query($sql);
    go("?c=article&action=admin");
}
elseif($action =='article_edit')
{
    $sql =" UPDATE `article` SET `contant` = '".get($_POST['contant_c'])."',`race_id` = '".get($_POST['race_id'])."', `title` = '".get($_POST['title'])."', `menu` = '".get($_POST['menu'])."', `img_url` = '".get($_POST['img_url'])."', `is_index` = '1',`wx_url` = '".get($_POST['wx_url'])."' WHERE `article`.`id` = ".get($_GET['id']);
    //die($sql);
    $article->query($sql);
    go("?c=article&action=admin");
}
elseif($action =="article_msg")
{
    $sql ="select * from article where id = ".$_GET['id'];
    $result= $article->get_data($sql);
    include 'view/top.php';
    include 'view/article_msg.php';
    include 'view/bottom.php';
}
elseif($action=='del')
{
    $sql = "delete from article where id =".$_GET['id'];
    $article->query($sql);
    go("index.php?c=article&action=admin");
}
elseif($action =="list")
{
    $keyword = get($_REQUEST['keyword']);
    if($keyword)
    {
        $sql_keyword = " where  title like '%$keyword%'";
    }
    $sql ="select id,title,add_time,contant,img_url from article $sql_keyword order by id desc limit 0,10";
    $result = $article->get_data($sql);
    //login
    include 'view/top.php';
    include 'view/article_list.php';
    include 'view/bottom.php';
}
elseif ($action == 'our')
{
    include 'view/top.php';
    include 'view/article_our.php';
    include 'view/bottom.php';
}
