<?php
defined('PHP168_PATH') or die();

$mysites = $this_system->get_manage_sites();
$mysites || $this_controller->check_admin_action($ACTION) or message('no_privilege');

if(REQUEST_METHOD == 'GET'){
	$site_create = $this_controller->check_admin_action('site_create');
    $site_delete = $this_controller->check_admin_action('site_delete');
    $site_edit = $this_controller->check_admin_action('site_edit');
    
	load_language($core, 'config');
    
	
	$select = select();
	$select->from($this_module->table, '*');
	$select->in('alias',$mysites);
	$select->order('sort DESC');
	$count = 0;
	$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
	$page = max(1, $page);
	$page_size = 20;
	//echo $select->build_sql();
	$list = $core->list_item(
		$select,
		array(
			'page_size' => 0,
			'ms' => 'master'
		)
	);
	
	$page_url = $this_url .'?page=?page?';
	
	$pages = list_page(array(
		'count' => $count,
		'page' => $page,
		'page_size' => $page_size,
		'url' => $page_url
	));
	include template($this_module, 'list', 'admin');

}else if(REQUEST_METHOD == 'POST'){

		//批量排序
	$display_order = isset($_POST['_sort']) && is_array($_POST['_sort']) ? array_map('intval', $_POST['_sort']) : array();

    if($display_order){
        foreach($display_order as $id => $order){
            $DB_master->update(
                $this_module->table,
                array(
                    'sort' => $order
                ),
                "id = '$id'"
            );
        }
    }else{
        $this_module->cache();
    }
	$this_system->log(array(
		'title' => $P8LANG['_module_cache_admin_log'],
		'request' => $_POST,
	));
	message('done');
	
}
