<?php
defined('PHP168_PATH') or die();
$this_system->check_manager($ACTION) or message('no_privilege');

if(REQUEST_METHOD == 'POST'){
    $id = isset($_POST['id']) ? filter_int($_POST['id']) : array();
	$id or exit('[]');
    $ids = implode(',',$id);
    
    $cid = isset($_POST['cid'])? intval($_POST['cid']):0;
    $cid or exit('[]');
    
    $item = &$this_system->load_module('item');
  
    $query = $core->DB_master->query("SELECT * FROM {$this_module->table} WHERE id IN ($ids)");
    
	$controller = &$core->controller($item);
	
	$ret = array();

   $res=array();
    while($data = $core->DB_master->fetch_array($query)){
        $_REQUEST['model'] = $data['model'];
        $this_system->init_model();
        $item->set_model($_REQUEST['model']);
        $data['data'] = mb_unserialize($data['data']);
        $data['data']['verify'] = 1;
       // $data['data']['timestamp'] = date('Y-m-d H:i:s',$data['data']['timestamp']);
       // $data['data']['list_order'] = date('Y-m-d H:i:s',$data['data']['list_order']);
	   unset($data['data']['timestamp'],$data['data']['list_order']);
        $data['data']['cid'] = $cid;
       if($iid = $controller->add($data['data'])){
           $res[]=$data['id'];
            //追加
            if(!empty($data['data']['addon'])){
                foreach($data['data']['addon'] as $vv){
                    $vv['iid'] = $iid;
                    $controller->addon($vv);
                }
            }
            $this_module->set_receive_status( array( $this_system->SITE ), $data['id']);
        }
    }
    exit(json_encode($res));
    
}    
