<?php
if (!defined('IN_CONTEXT')) die('access violation error!');

$cols = 4;//每个页面，每行4列展示
$category_manimun = 4;//模板类别展示最小值
$category_cols = 4;//模板分类列表4列排列
$sceenpic = substr($_SERVER['HTTP_REFERER'],0,strpos($_SERVER['HTTP_REFERER'],"admin/index.php"));
$tmp_arr = array();
$tmp_arr1 = array();
?>
<style type="text/css">
.d_c_list{ width:759px; background:#f2f2f2;border:1px solid #e2e2e2;position:relative;bottom:12px;right:35px;padding:0 10px; overflow: hidden;}
.d_c_list ul{background:none; height:auto; border:none;}
.d_c_list ul li{ width: 150px; float:left; _display:inline; white-space: nowrap; height:22px; line-height:22px; overflow:hidden; margin-bottom:5px;}
.template_grid {
	width: 100%;
}
.template_grid td {
	text-align: center;
	background: #f8f8f8;
	border:0px;
	padding-top:20px;
}
.template_grid td img.tpl_thumb {
	border-top: 2px solid #dedede;
	border-left: 2px solid #dedede;
	border-right: 2px solid #999;
	border-bottom: 2px solid #999;
	width: 160px;
	height: 120px;
	margin-top: 4px;
	padding:5px;
}

.template_grid td img.tpl_thumb1 {
	border-top: 2px solid #dedede;
	border-left: 2px solid #dedede;
	border-right: 2px solid #999;
	border-bottom: 2px solid #999;
	border-color:#f68b17;
	width: 160px;
	height: 120px;
	margin-top: 4px;
	padding:5px;
}

.template_grid .small {
    display: block;
    padding: 3px 0px;
}
</style>
<style>
#init{background:url(images/Init_bg.jpg) repeat-x; height:34px; font-size:12px; line-height:34px;}
#init_sub{float:left;background:url(images/Init_left.jpg) no-repeat;height:34px;}
#init_sub a{text-align:center; color:#fff; width:150px; display:block; background:url(images/Init_a.jpg) no-repeat; line-height:26px; margin:4px 4px 0px 4px;text-decoration:underline;}
#init_sub a:hover{background:url(images/Init_hover.jpg);}
#init_sub p{float:left; }
#init_right { background:url(images/Init_right.jpg) no-repeat top right;}
</style>
<script type="text/javascript" language="javascript">
<!--

function on_del_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("admintpllst_stat");
    if (o_result.result == "ERROR") {
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
        stat.innerHTML = "<?php _e('OK, refreshing...'); ?>";
        reloadPage();
    } else {
        return on_failure(response);
    }
}

function on_del_failure(response) {
	//错误消息最好改成“已超时”
	document.getElementById("admintpllst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    reloadPage();
    return false;
}

function delete_tpl(tpl_id) {
    if (confirm("Delete the selected template?")) {
        var stat = document.getElementById("admintpllst_stat");
        stat.style.display = "block";
        stat.innerHTML = "<?php _e('Deleting selected template...'); ?>";
        _ajax_request("mod_template", 
            "admin_delete", 
            {
                tpl_id:tpl_id
            }, 
            on_del_success, 
            on_del_failure);
    }
}

function on_tog_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("admintpllst_stat");
    if (o_result.result == "ERROR") {
        stat.innerHTML = o_result.errmsg;
        alert(o_result.errmsg);
        reloadPage();
        return false;
    } else if (o_result.result == "OK") {
        stat.innerHTML = "<?php _e('OK, refreshing...'); ?>";
        reloadPage();
    } else {
        return on_failure(response);
    }
}

function on_tog_failure(response) {
    on_del_failure(response);
}

function reset_tpl_data() {
	if (!confirm("<?php _e('This action will take some time to download the reset-data from the server,please be patient.'); ?>")) return;
    show_iframe_win("index.php?_m=mod_template&_a=show_reset_data","",'483','210');
//    _ajax_request("mod_template",
//        "reset_tpl_data", false, 
//        on_reset_success, 
//        on_reset_failure);
}

//安装模板时触发
function toggle_default(tpl_id, is_remote, tpl_name) {
    var remote_tpl = "0";
    if (is_remote) {
        remote_tpl = "1";
    }
	show_iframe_win("index.php?_m=mod_template&_a=template_remote&tpl_id="+tpl_id+"&is_remote="+remote_tpl+"&tpl_name="+tpl_name, '', 483, 210);
}

//设为默认模板时触发
function make_default(tpl_name) {
		show_iframe_win('index.php?_m=mod_template&_a=template_local&tpl_name='+tpl_name, '', 483, 210);
}

//-->
</script>

<?php 
$bool1 = extension_loaded('zip');
$bool2 = extension_loaded('soap');
$bool1 = true;//现在不用soap
$bool2 = true;//现在不用zip
if(($bool1 && $bool2)){
?>


<div id="init">
        <div id="init_sub"><a href="#">客户请注意</a></div>
        <div id="init_right"><marquee scrollAmount=2 width="80%"> 从现在开始每套模板只要200元，请与我们客服取的联系，QQ：122812289  550288171</marquee></div>
</div>
<div class="status_bar">
    <span id="admintpllst_stat" class="status" style="display:none;"></span>
</div>
<?php }?>
<table class="list_table" id="admin_tpl_list" width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
	<thead>
	</thead>
    <tbody>
	    <tr>
		    <td>
			    <table class="template_grid" cellspacing="0">
			    	<?php
			    	$html_script = "<div class='d_c_list'><ul style='background:none;border:none;'><li><a href='index.php?_m=mod_template&_a=admin_list&_cates=_all&_p=1'>所有模板</a><span style='color:#c7c7c7'></span></li>";
			    	if(empty($tmplate_category)) $tmplate_category = array();
			    	foreach($tmplate_category as $k => $v)
			    	{
			    		if($v['amount'] >= $category_manimun)
			    		{
			    			$html_script .= "<li><a href='index.php?_m=mod_template&_a=admin_list&_cates={$v['id']}&_p=1'>{$v['name']}</a><span style='color:#c7c7c7'></span></li>";
			    		}
			    	}
			    	$html_script .= '</ul></div>';
			    	//获取默认模板文件夹名称
			    	$n_tpls = sizeof($output_array);
			    	$count_number = count($template_owns);
			    	if($category_number == '_all'){
			    	for($i = 0; $i < $count_number; $i++)
			    	{
			    		if(is_array($template_owns[$i])) 
			    		{
			    			continue;
			    		}
			    		$tmp_arr1 = explode('#$',$template_owns[$i]);
			    		if(DEFAULT_TPL == $tmp_arr1[0])	//show choosed template
			    		{
			    			echo "<tr>";
			    			echo '<td width="'.intval(100 / $cols).'%">';
			    			echo '<a href="'.Html::uriquery('mod_modules', 'index').'" target="_blank" title="'.__('Manage Layout').'"><div><img style="position:relative;left:2px;" class="tpl_thumb" src="../template/'.$tmp_arr1[0].'/screenshot.jpg" onmouseover="this.className=\''.'tpl_thumb1'.'\'" onmouseout="this.className=\''.'tpl_thumb'.'\'"/></div></a><span class="small">';
							echo $template_owns_name[$i].'&nbsp;&nbsp;&nbsp;'.__('default template');
				            echo '&nbsp;';
			            	echo '</span></td><td style="text-align:left;">'.$html_script.'</td></tr>';
			            	break;
			    		}
			    	}
					
			    echo '</table>';
			    } else {
			    	echo "<tr>";
			    	echo '<td width="'.intval(100 / $cols).'%">';
			    	echo '<a href="'.Html::uriquery('mod_modules', 'index').'" target="_blank" title="'.__('Manage Layout').'"><div><img style="position:relative;left:2px;" class="tpl_thumb" src="../template/'.DEFAULT_TPL.'/screenshot.jpg" onmouseover="this.className=\''.'tpl_thumb1'.'\'" onmouseout="this.className=\''.'tpl_thumb'.'\'"/></div></a><span class="small">';
			    	include_once(ROOT.DS.'template'.DS.DEFAULT_TPL.DS.'conf.php');
			    	echo $template_name.'&nbsp;&nbsp;&nbsp;'.__('default template');
			    	echo '&nbsp;';
			    	echo '</span></td><td style="text-align:left;">'.$html_script.'</td></tr>';
			    	echo '</table>';
			    }
			    if(!($bool1 && $bool2))
			    {
			    	echo '</td></tr></tbody></table>';
			    	if(!$bool1 && $bool2)
			    		echo '<div style="font-size:24px;font-weight:24px;">'._e('Please install zip extension!').'</div>';
			    	elseif($bool1 && !$bool2)
			    		echo '<div style="font-size:24px;font-weight:24px;">'._e('Please install soap extension!').'</div>';
			    	else
			    		echo '<div style="font-size:24px;font-weight:24px;">'._e('Please install soap extension!').'</div>';
			    	die;
			    }
				 
			    echo '<table class="template_grid" cellspacing="0">';
			    	$i = 0;
			        while($i < $n_tpls)
			        {
			        	echo "<tr>";
			        	for($j = 0; $j < $cols; $j++)
			        	{
			        		if($i >= count($output_array))
			        		{
			        			break;	
			        		}
			        		
			        		if(is_array($output_array[$i]))//When getting remote templates happend..
			        		{
				        		if(DEFAULT_TPL_ID == $output_array[$i]['id'])
				        		{
				        			$i++;
				        			$j--;
				        			continue;	
				        		}	
			        		}
			    	?>
			            <td width="<?php echo intval(100 / $cols); ?>%">
			            	<?php if(!is_array($output_array[$i])){//Get local templates
			            			$tmp_arr = explode('#$',$output_array[$i]);
			            			if($tmp_arr[0] != DEFAULT_TPL)
			            			{//echo $output_array[$i];
			            	?>
			            	<a href="<?php echo $tmp_arr[1];?>" target="_blank"><div id=<?php echo '"'.$templates[$i]['id'].'"';?>><img class="tpl_thumb" src="<?php echo '../template/'.$tmp_arr[0].'/screenshot.jpg'; ?>" onmouseover="this.className='tpl_thumb1';" onmouseout="this.className='tpl_thumb';" /></div></a>
			            	<span class="small">
				            <?php
								echo '企业网站-'.$output_array_name[$i].'&nbsp;&nbsp;&nbsp;'."<a href='#' onclick=\"make_default('$tmp_arr[0]')\">".__('Install the choosed template')."</a>";
				            ?>
				            &nbsp;
			            	</span>
			            	<?php }else {?>
	            		  <div id=<?php echo '"'.$templates[$i]['id'].'"';?>><img class="tpl_thumb" src="<?php echo '../template/'.$tmp_arr[0].'/screenshot.jpg'; ?>" onmouseover="this.className='tpl_thumb1';" onmouseout="this.className='tpl_thumb';" /></div>
				            	<span class="small">
					            <?php
									echo '企业网站-'.$output_array_name[$i].'&nbsp;&nbsp;&nbsp;';_e('Installed');
					            ?>
					            &nbsp;
				            	</span>
			            	<?php }}else {?><!-- Get remote templates -->
			            	<?php 
			            	$arr = explode('/',$output_array[$i]['screenshot_url']);
			            	$image_key = count($arr)-1;
			            	$image_name = $arr[$image_key];
			            	?>
		            	  <div id=<?php echo '"'.$output_array[$i]['id'].'"';?>><img class="tpl_thumb" src="<?php echo SCREENSHOT_URL.'screenshots/'.$image_name; ?>" onmouseover="this.className='tpl_thumb1';" onmouseout="this.className='tpl_thumb';"/></div>
					        <span class="small">
					        <?php
						        $remote_flag = isset($output_array[$i]['package_url'])?'true':'false';
						        $tpl_name = substr($output_array[$i]['archive'],0,-4);
						        echo $output_array[$i]['name'].'&nbsp;&nbsp;'.'';
						    ?>
					        &nbsp;
					        </span>
			            	<?php }?>
			            </td>
			        <?php
				        	$i++;
			        	}
			        	for($a = 0; $a < $cols-$j; $a++)
			        	{
			        		 echo '<td width="'.intval(100 / $cols).'%"></td>';
			        	}
			        	echo "</tr>";
			        }
			        ?>
			    </table>
		    </td>
	    </tr>
    </tbody>
</table>
<div style="text-align:center;margin-top:2px;">
  <?php 
$str11 = '';
$per_page = 5;
if($last_page <= $per_page)
{
	for($ii = 1;$ii <= $last_page;$ii++)
	{
		if($page_number == $ii)
		{
			$str11 .= $ii."&nbsp;|&nbsp;";
		}
		else
		{
			$str11 .= "<a href='index.php?_m=mod_template&_a=admin_list&_p=$ii&_cates=$category_number'>$ii</a>&nbsp;|&nbsp;";
		}
	}
}
else
{
	for($ii = 1;$ii <= $per_page;$ii++)
	{
		if($page_number == $ii)
		{
			$str11 .= $ii."&nbsp;|&nbsp;";
		}
		else
		{
			$str11 .= "<a href='index.php?_m=mod_template&_a=admin_list&_p=$ii&_cates=$category_number'>$ii</a>&nbsp;|&nbsp;";
		}
	}
	
	$str11 .= "<a href='index.php?_m=mod_template&_a=admin_list&_p=$last_page&_cates=$category_number'>..$last_page</a>&nbsp;|&nbsp;";
	$str22 .= "<form style='display:inline;margin:0px;' method='post' action='index.php?_m=mod_template&_a=admin_list' id='langswform' name='langswform'>";
	$str22 .= "<input name='_cates' type='hidden' value='$category_number'>转跳至:<input style='width:25px;' type='text' name='_p' value='$page_number'><input type='submit' value='确定'></form>";
}
if($page_number == $last_page)
{
	if($page_number > 1){
?>
  <a href='index.php?_m=mod_template&amp;_a=admin_list&amp;_p=1&amp;_cates=<?php echo $category_number;?>'>
  <?php _e('First');?>
  </a>&nbsp;|&nbsp;<a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $page_number-1;?>">
  <?php _e('Previous');?>
  </a>&nbsp;|&nbsp;<?php echo $str11;?><a href="#">
  <?php _e('Next');?>
  </a>&nbsp;|&nbsp;<a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $last_page;?>">
  <?php _e('Last');?>
  </a><?php echo '&nbsp|&nbsp;'.$str22;?>
  <?php } elseif($page_number == 1) {?>
  <a href='index.php?_m=mod_template&amp;_a=admin_list&amp;_p=1&amp;_cates=<?php echo $category_number;?>'>
  <?php _e('First');?>
  </a>&nbsp;|&nbsp;<a href="#">
  <?php _e('Previous');?>
  </a>&nbsp;|&nbsp;<?php echo $str11;?><a href="#">
  <?php _e('Next');?>
  </a>&nbsp;|&nbsp;<a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $last_page;?>">
  <?php _e('Last');?>
  </a><?php echo '&nbsp|&nbsp;'.$str22;?>
  <?php	}?>
  <?php
}
elseif($page_number == 1)
{
?>
  <a href='index.php?_m=mod_template&amp;_a=admin_list&amp;_p=1&amp;_cates=<?php echo $category_number;?>'>
  <?php _e('First');?>
  </a>&nbsp;|&nbsp;<a href="#">
  <?php _e('Previous');?>
  </a>&nbsp;|&nbsp;<?php echo $str11;?><a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $page_number+1;?>">
  <?php _e('Next');?>
  </a>&nbsp;|&nbsp;<a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $last_page;?>">
  <?php _e('Last');?>
  </a><?php echo '&nbsp|&nbsp;'.$str22;?>
  <?php
}
else
{
?>
  <a href='index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=1'>
  <?php _e('First');?>
  </a>&nbsp;|&nbsp;<a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $page_number-1;?>">
  <?php _e('Previous');?>
  </a>&nbsp;|&nbsp;<?php echo $str11;?><a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $page_number+1;?>">
  <?php _e('Next');?>
  </a>&nbsp;|&nbsp;<a href="index.php?_m=mod_template&amp;_a=admin_list&amp;_cates=<?php echo $category_number;?>&amp;_p=<?php echo $last_page;?>">
  <?php _e('Last');?>
  </a><?php echo '&nbsp|&nbsp;'.$str22;?>
  <?php 
}

//if($last_page > $per_page)
//{
//	echo $str22;
//}
?>
</div>
