<?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');

$adtype_arr = array(1=>'超链接',2=>'图片',3=>'Flash',4=>'代码');

if(!$dosubmit) {
    $invalid = $invalid ? 1 : 0;
    $where = array("1=1");
    if(!$invalid) {
        $where[] = "endtime>='$timestamp'";
    } else {
        $where[] = "endtime<'$timestamp'";
    }
    $total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}ads WHERE ".implode(' AND ',$where));
    if($total > 0) {
        $limit = get_limit($page, $offset=10);
        $multipage = multi($total, $offset, $page, 'admincp.php?action='.$action.'&file='.$file.'&vaild='.$valid);
        $query = $db->query("SELECT adid,callid,subject,adtype,begintime,endtime,attr FROM {$dbpre}ads WHERE ".implode(' AND ',$where)." LIMIT $limit");
    }
    include cptpl('list', MOD_ROOT.'./admin/templates/');
} else {
    if(empty($adids)) cpmsg("未选择操作项，请返回选择。");
    $ids = "'".implode("','", $adids)."'";
    if($op=='delete') {
        $callids = array();
        $query = $db->query("SELECT callid FROM {$dbpre}ads WHERE adid IN($ids)");
        while($row=$db->fetch_array($query)) {
            $callids[] = $row['callid'];
        }
        unset($row);
        if(count($callids)>0) {
            $cids = "'".implode("','", $callids)."'";
            $db->query("DELETE FROM {$dbpre}datacall WHERE callid IN ($cids)");
            deleteDatacallCache($callids);  
        }
        $db->query("DELETE FROM {$dbpre}ads WHERE adid IN($ids)");
    } elseif($op=='attr') {
        $query = $db->query("UPDATE {$dbpre}ads SET attr='$attr' WHERE adid IN($ids)");
    } else {
        cpmsg('未选择操作方式，请返回选择。');
    }
    cpmsg('操作完毕!', 'admincp.php?action='.$action.'&file=list');
}
?>