<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id lis.inc.php 2 2008-08-24 11:39 $
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');

if(!$dosubmit) {

    if($adid > 0) {
        $ad = $db->get_one("SELECT * FROM {$dbpre}ads WHERE adid='$adid'");
        empty($ad) and cpmsg('不存在这个广告，请返回。');
        $ad['content'] = unserialize($ad['content']);
        $isedit = 1;
    } else {
        $ad['adtype'] = 1;
        $ad['begintime'] = $timestamp;
    }
    $ad['begintime'] = date('Y-m-d', $ad['begintime']);
    $ad['endtime'] = empty($ad['endtime'])||$ad['endtime']=='2000000000'?'':date('Y-m-d', $ad['endtime']);

    include cptpl('detail', MOD_ROOT.'./admin/templates/');

} else {

    (!$ad['subject'] || count($ad['content'])==0 || !$ad['adtype']) and cpmsg('未将广告各项填写完整，请返回填写。');
    //1577808000
    $ad['begintime'] = empty($ad['begintime']) ? $timestamp : strtotime($ad['begintime'].' 00:00:00');
    $ad['endtime'] = empty($ad['endtime']) ? '2000000000' : strtotime($ad['endtime'].' 23:59:59');
    $ad['code'] = convertToCode($ad['adtype'], $ad['content']);
    $ad['content'] = addslashes(serialize($ad['content']));
    if($isedit) {
        $db->update_new($dbpre.'ads', "adid='$adid'",$ad);
    } else {
        $db->insert_new($dbpre.'ads', $ad);
        $adid=$db->insert_id();
    }
    insertDataCall($adid);
    cpmsg("操作完毕！", "admincp.php?action=$action&file=list");
    
}
?>