<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<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("adminmenulst_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("adminmenulst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function delete_menu(menu_id) {
    if (confirm("Delete the selected menu?")) {
        var stat = document.getElementById("adminmenulst_stat");
        stat.style.display = "block";
        stat.innerHTML = "<?php _e('Deleting selected menu...'); ?>";
        _ajax_request("mod_menu", 
            "admin_delete", 
            {
                menu_id:menu_id
            }, 
            on_del_success, 
            on_del_failure);
    }
}
//-->
</script>
<div class="content_toolbar">
	<table cellspacing="0" class="wrap_table">
		<tbody>
			<tr>
				<td><div class="title"><?php _e('Menu'); ?></div></td>
				<td><a href="<?php echo Html::uriquery('mod_menu', 'admin_add'); ?>" title=""><?php _e('Add menu'); ?></a></td>
				<td><?php include_once(P_TPL.'/common/language_switch.php'); ?></td>
			</tr>
		</tbody>
	</table>
</div>
<div class="space"></div>
<div class="status_bar">
    <span id="adminmenulst_stat" class="status" style="display:none;"></span>
</div>
<div class="space"></div>
<table cellspacing="0" class="list_table" id="admin_lang_list">
    <thead>
        <tr>
            <th width="20">ID</th>
            <th><?php _e('Name'); ?></th>
            <th><?php _e('Operation'); ?></th>
        </tr>
    </thead>
    <tbody>
    <?php
    if (sizeof($menus) > 0) {
        $row_idx = 0;
        foreach ($menus as $menu) {
    ?>
        <tr class="row_style_<?php echo $row_idx; ?>">
            <td><?php echo $menu->id; ?></td>
            <td><?php echo $menu->name; ?></td>
            <td>
                <span class="small">
                    <a href="<?php echo Html::uriquery('mod_menu', 'admin_edit', array('menu_id' => $menu->id)); ?>" title="<?php _e('Edit'); ?>"><?php _e('Edit'); ?></a>
                    &nbsp;
                    <a href="#" onclick="delete_menu(<?php echo $menu->id; ?>);return false;" title="<?php _e('Delete'); ?>"><?php _e('Delete'); ?></a>
                    &nbsp;
					<a href="<?php echo Html::uriquery('mod_menu_item', 'admin_list', array('menu_id' => $menu->id)); ?>" title="<?php _e('Manage Menu Item'); ?>"><?php _e('Manage Menu Item'); ?></a>
                </span>
            </td>
        </tr>
    <?php
            $row_idx = 1 - $row_idx;
        }
    } else {
    ?>
        <tr class="row_style_0">
            <td colspan="3"><?php _e('No Records!'); ?></td>
        </tr>
    <?php
    }
    ?>
    </tbody>
</table>
<div class="space"></div>
<?php
include_once(P_TPL.'/common/pager.php');
?>
