<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view(TPL_FOLDER."header");?>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" >
  <tr>
    <td width="3%" align="left" ><img src="{tpl_path}images/forward.jpg" /></td>
    <td width="97%" align="left" >您现在的位置：<a href="<?php echo site_url(CTL_FOLDER.'industry_catalog');?>">行业类目</a> &gt; 采集行业类目</td>
  </tr>
</table>
<fieldset>
<legend>行业类目采集</legend>
<table width="96%"  border="0" cellpadding="5" cellspacing="0"   style="margin:10px; line-height:30px">
  <tr>
    <td>点击下面的采集按钮开始采集，因为类目比较多，所以耗时比较长，期间请不要刷新页面.</td>
  </tr>
  <tr>
    <td align="center"  style="border-bottom:#CCCCCC 1px solid"><input type="button" value="点击开始采集" id="sbc" onclick="get_data(this)" class="button-style2" style="width:100px" />
    </td>
  </tr>
  <tr>
    <td align="center"><table width="96%"  border="0" cellpadding="5" cellspacing="0" style="margin:10px; line-height:30px" id="process">
      </table></td>
  </tr>
</table>
</fieldset>
<script language="javascript">
function get_data(o)
{
	if(confirm('确定要开始采集吗，期间请不要刷新页面'))
	{
		o.value = '数据采集中..';
		o.disabled = true;
		$.ajax({
			url:js_root_path+"<?php echo CTL_FOLDER;?>get_top_data/get_industry_cats",
			data:"md5key=<?php echo md5($this->config->item('md5_encode_key'));?>&p_id=0",
			type:"POST",
			dataType:'json',
			success:function(msg)
			{
				$('#process').html('');
				$.each(msg,function(k,v){
					$('<tr><td width="20%" align="left">'+v+'</td><td align="center" valign="middle">------------------------------------------------------------------------------</td><td width="15%" align="right" class="cqueue" id="'+k+'"><font color="#FF0000">等待采集</font></td></tr>').appendTo('#process');
				})
				ajax_process();
			}
		});
	}
}

function ajax_process()
{
	if($('.cqueue').length == 0) 
	{
		$('<tr><td align="center" style="font-weight:bold;color:#009900" colspan="3">全部数据采集完毕</td></tr>').insertBefore('#process tr:eq(0)');
		document.getElementById('sbc').value = document.getElementById('sbc').defaultValue;
		document.getElementById('sbc').disabled = false;
		return ;
	}
	var cob = $('.cqueue:eq(0)');
	cob.html('<img src="'+pic_loading_path+'" /> 采集子类目...');
	$.ajax({
		url:js_root_path+"<?php echo CTL_FOLDER;?>get_top_data/get_industry_cats",
		data:"md5key=<?php echo md5($this->config->item('md5_encode_key'));?>&p_id="+cob.attr('id'),
		type:"POST",
		dataType:'json',
		success:function(msg)
		{
			cob.html("<font style=\"color:#009900\">采集完毕</font>");
			cob.removeClass('cqueue');
			ajax_process();
		}
	});
}
</script>
<?php $this->load->view(TPL_FOLDER."footer");?>
