<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>信息平台-图片审查模块</title>
    <link href="/bootstrap/img/glyphicons_290_skull.png" rel="shortcut icon"/>
    <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script>
    <style type="text/css">
    .show-grid {padding: 15px; background: #efefef; border-radius: 5px;}
    .mr10 {margin-right: 10px;}
    .nav {margin-bottom: 5px;}
    .pic {display: none;}
    .msg {color: #07c;}
    .mt12 {margin-top: 12px;}
    #search,#insert {margin-top: 2px;float: right;}
    </style>
    <script type="text/javascript">
    $(function() {
        
        $('li[tos]').on('click', function() {
            $('li[site_code]').attr('site_code', $(this).attr('tos'));
            $('li[site_code]>a').html('站点:'+$(this).attr('tos'));
        });
        
        $('li[toa]').on('click', function() {
            $('li[area_type]').attr('area_type', $(this).attr('toa'));
            $('li[area_type]>a').html('分类:'+$(this).attr('toa'));
        });
        
        $('#search').on('click', function() {
            var site_code = $('li[site_code]').attr('site_code');
            var area_type = $('li[area_type]').attr('area_type');
            if (site_code && area_type) {
                location.href = '/info.php/info_image_review/lists/'+site_code+'/'+area_type;
            } else {
                alert('请选择"站点"和"分类"。');
            }
        });
        
        $('#insert').on('click', function() {
            var c = prompt('Password?','');
            if (c=='add') {
                $('.msg').html('');
                ajax_num($('tr.data:eq(0)'));
    			ajax_num($('tr.data:eq(1)'));
            } else {
                alert('error');
            }
        });

        //ajax_num($('tr.data:eq(0)'));
        function ajax_num(n) {
            var _data = {
                'ir_ic_id': n.attr('ir_ic_id'),
                'ir_is_id': n.attr('ir_is_id'),
                'ir_ht_area_type': n.attr('ir_ht_area_type'),
                'ir_ht_area_id': n.attr('ir_ht_area_id'),
                'ir_site_code': n.attr('ir_site_code'),
                'ir_img_replace': null,
                'ir_state': 0
            };

            var img = n.find('.pic').html().split(',');
			var num = img.length;
			var next_tr = n.next().next();
			
            $.each(img, function(index, value) {
                _data.ir_img_src = value;
                $.ajax({
                    url: '/info.php/info_image_review/insert',
                    type: 'post',
                    data: _data,
                    success: function(text) {
                        var s = n.find('.msg');
                        var ss = s.html();
                        n.find('.msg').html(ss+text+'<br/>');
						if (next_tr.length && index+1==num) {
							ajax_num(next_tr);
							//console.log('next--'+next_tr.length+'#'+num+'#'+index);
						} else {
							//console.log('end--'+next_tr.length+'#'+(num+1)+'#'+index);
						}
                    },
                    error: function() {
                        var s = n.find('.msg')
                        var ss = s.html();
                        n.find('.msg').html(ss+'error!<br/>');
                    }
                });
            });
        }
    });
    </script>
</head>
<body>
    <div class="container">
    
        <div class="row show-grid">
            <ul class="nav nav-pills">
                <li class="active dropdown mr10" site_code="<?php echo($site_code);?>">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        站点:<?php echo($site_code);?>
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu">
                        <?php foreach($this->config->item('site') as $it) { ?>
                        <li tos="<?php echo($it['site_code']); ?>">
                            <a><?php echo($it['site_code']); ?></a>
                        </li>
                        <?php } ?>
                    </ul>
                </li>
                <li class="active dropdown mr10" area_type="<?php echo($area_type);?>">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        分类:<?php echo($area_type);?>
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu">
                        <?php foreach($this->config->item('area_type') as $key=>$v) { ?>
                        <li toa="<?php echo($v) ?>"><a><?php echo($key); ?>:<?php echo($v); ?></a></li>
                        <?php } ?>
                    </ul>
                </li>
                <span class="mt12 label label-success">有图片的信息<?php echo($info_num);?>条</span>
                <span class="mt12 label label-info">含图片<?php echo($image_num);?>张</span>
                <a id="insert" class="btn mr10 btn-info">更新</a>
                <a id="search" class="btn mr10 btn-info">查找</a>
            </ul>
        </div>
        
        <div class="row">
            <table class="table table-hover">
                <thead>
                    <tr>
                      <th>#ic_id</th>
                      <th>标题</th>
                      <th>图片</th>
                      <th>State</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($infos as $it) { ?>
                    <tr class="data" ir_ic_id="<?php echo $it->ic_id;?>" ir_is_id="<?php echo $it->is_id;?>" ir_ht_area_type="<?php echo $it->ic_ht_area_type;?>" ir_ht_area_id="<?php echo $it->ic_ht_area_id;?>" ir_site_code="<?php echo $it->ic_sitecode;?>">
                        <td><?php echo($it->ic_id); ?></td>
                        <td><?php echo($it->ic_title); ?></td>
                        <td><?php echo(implode("<br/>",$it->pic_array)); ?></td>
                        <?php if ($it->ir_id) { ?>
                        <td class="msg">存在</td>
                        <?php } else { ?>
                        <td class="msg">???</td>
                        <?php } ?>
                        <td class="pic"><?php echo(implode(",",$it->pic_array)); ?></td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
    
</body>
</html>
