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

/**
 * Show menu list recursively
 * 
 */
function showMIList(&$mi_tree, $level = 0) {
	$row_idx = 0;
	
    foreach ($mi_tree as $mi) {
?>
        <tr class="row_style_<?php echo $row_idx; ?>">
        	<td class="left"><?php echo str_repeat('&nbsp;&nbsp;&nbsp;', $level).$mi->name; ?></td>
        	<td>
        		<a href="#" onclick="move('<?php echo $mi->id; ?>', '<?php echo $mi->siblings['prev']; ?>');return false;" title="<?php _e('Move Up'); ?>"><img src="<?php echo P_TPL_WEB; ?>/images/up.gif" border="0" /></a>
        		<a href="#" onclick="move('<?php echo $mi->id; ?>', '<?php echo $mi->siblings['next']; ?>');return false;" title="<?php _e('Move Down'); ?>"><img src="<?php echo P_TPL_WEB; ?>/images/down.gif" border="0" /></a>
        	</td>
        	<td><?php echo $mi->selected_content; ?></td>
        	<td><?php echo Toolkit::validateYesOrNo($mi->published,$mi->id,Html::uriquery('mod_menu_item', 'admin_pic',array('_id'=>$mi->id)));?></td>
        	<td>
        		<a href="../<?php echo $mi->link?>" title="<?php _e('Preview'); ?>" target="_blank"><img style="border:none;" src="<?php echo P_TPL_WEB; ?>/images/icon3.gif" alt="<?php _e('Preview'); ?>"/></a>
        	</td>
        	<td>
        		<a href="<?php echo Html::uriquery('mod_menu_item', 'admin_addsub', array('mi_id' => $mi->id)); ?>" title="添加子栏目"><img style="border:none;" src="<?php echo P_TPL_WEB; ?>/images/aedit.gif" alt="<?php _e('add submenu'); ?>"/></a>
        	</td>
        	<td>
        		<a href="<?php echo Html::uriquery('mod_menu_item', 'admin_edit', array('mi_id' => $mi->id)); ?>" title="<?php _e('Edit'); ?>"><img style="border:none;" src="<?php echo P_TPL_WEB; ?>/images/edit.gif" alt="<?php _e('Edit'); ?>"/></a>
        	</td>
        	<td>
        		<a href="#" onclick="delete_mi(<?php echo $mi->id; ?>);return false;" title="<?php _e('Delete'); ?>"><img style="border:none;" src="<?php echo P_TPL_WEB; ?>/images/cross.gif" alt="<?php _e('Delete'); ?>"/></a>
        	</td>
        </tr>
<?php
        $row_idx = 1 - $row_idx;
        
        if (sizeof($mi->slaves['MenuItem']) > 0) {
            $level++;
            showMIList($mi->slaves['MenuItem'], $level);
            $level--;
        }
    }
}
?>
<link rel="stylesheet" href="../script/jquery.cluetip.css" type="text/css" />
<script type="text/javascript" src="../script/jquery.cluetip.min.js"></script>
<script type="text/javascript" language="javascript">
<!--
$(document).ready(function(){
	$('#answer').cluetip({splitTitle: '|',width: '300px',height:'68px'});
});
function on_del_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("adminmilst_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("adminmilst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function delete_mi(mi_id) {
	if (confirm("Delete the selected menu item?")) {
	    var stat = document.getElementById("adminmilst_stat");
	    stat.style.display = "block";
	    stat.innerHTML = "<?php _e('Deleting selected menu item...'); ?>";
		_ajax_request("mod_menu_item", 
			"admin_delete", 
	        {
	            mi_id:mi_id
	        }, 
			on_del_success, 
			on_del_failure);
	}
}

function on_mov_success(response) {
    on_del_success(response);
}

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

function move(mi_id, sib_mi_id) {
	if (sib_mi_id == "0") {
	    return false;
	}
	
	var stat = document.getElementById("adminmilst_stat");
	stat.style.display = "block";
	stat.innerHTML = "<?php _e('Moving Menu Item...'); ?>";
	_ajax_request("mod_menu_item", 
		"admin_move", 
	    {
	        mi_id:mi_id,
	        sib_mi_id:sib_mi_id
	    }, 
		on_mov_success, 
		on_mov_failure);
}
//-->
</script>
<ul style="margin-left:1px;">
	<li class="icontj"><a href="<?php echo Html::uriquery('mod_menu_item', 'admin_add', array('menu_id' => ParamHolder::get('menu_id', 0))); ?>" title=""><?php _e('Add Top Column');?></a></li>
	<li style="margin-top:14px;"><?php include_once(P_TPL.'/common/language_switch.php'); if(SessionHolder::get('_LOCALE', DEFAULT_LOCALE) != 'en'){ ?></li><li style="margin-top:0;_margin-top:16px;">
	<img id="answer" class="title" src="<?php echo P_TPL_WEB; ?>/images/answer1.gif" alt="help" title="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;此处语言切换后可以使您在中文后台即时编辑、修改英文版网站内容，而不需切换到英文后台，方便快捷！"/>
	<?php } ?></li>
</ul>
<div class="status_bar">
	<span id="adminmilst_stat" class="status" style="display:none;"></span>
</div>
<table class="list_table" id="admin_menu_item_list" width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
	<thead>
		<tr>
            <td width="19%"><?php _e('Name'); ?></td>
            <td width="8%"><?php _e('Order'); ?></td>
            <td width="28%"><?php _e('Column Property');?></td>
            <td width="8%"><?php _e('Publish'); ?></td>
            <td width="9%"><?php _e('Edit Page'); ?></td>
            <td width="10%"><?php _e('Add sub Column');?></td>
            <td width="12%"><?php _e('Edit Column Property'); ?></td>
            <td width="6%"><?php _e('Delete'); ?></td>
        </tr>
    </thead>
    <tbody>
    <?php
    if (sizeof($menuitems) > 0) {
    	showMIList($menuitems);
    } else {
    ?>
    	<tr class="row_style_0">
    		<td colspan="8"><?php _e('No Records!'); ?></td>
    	</tr>
    <?php
    }
    ?>
    </tbody>
</table>
