<?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("adminusrlst_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("adminusrlst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function delete_user(user_id) {
	if (confirm("<?php _e('Delete the selected user?'); ?>")) {
	    var stat = document.getElementById("adminusrlst_stat");
	    stat.style.display = "block";
	    stat.innerHTML = "<?php _e('Deleting selected user...'); ?>";
		_ajax_request("mod_user", 
			"admin_delete", 
	        {
	            u_id:user_id
	        }, 
			on_del_success, 
			on_del_failure);
	}
}

function on_tog_success(response) {
	// 10:47 2010-3-11 Jane Edit >>>
    //var o_result = _eval_json(response.responseText);
    var o_result = _eval_json(response);
    // <<< 10:47 2010-3-11 Jane Edit
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("adminusrlst_stat");
    if (o_result.result == "ERROR") {
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
    	show_active(o_result.u_id, o_result.u_acti);
	    stat.style.display = "none";
    } else {
        return on_failure(response);
    }
}

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

function toggle_active(user_id, active) {
    var stat = document.getElementById("adminusrlst_stat");
    stat.style.display = "block";
    stat.innerHTML = "<?php _e('Changing user status...'); ?>";
    _ajax_request("mod_user", 
    	"admin_toggle_active", 
    	{
    	    u_id:user_id,
    	    u_acti:active
    	}, 
    	on_tog_success, 
    	on_tog_failure);
}

function show_active(user_id, active) {
    var active_label_id = "uactive_" + user_id;
    var active_html = "";
    if (active == "1") {
        active_html = "<a href=\"#\" onclick=\"toggle_active('" + user_id + "', '0');return false;\" title=\"\">Yes</a>";
    } else {
        active_html = "<a href=\"#\" onclick=\"toggle_active('" + user_id + "', '1');return false;\" title=\"\">No</a>";
    }
    
    document.getElementById(active_label_id).innerHTML = active_html;
}
//-->
</script>
<ul style="margin-left:1px;">
	<li><a class="usercont" href="<?php echo Html::uriquery('mod_user', 'admin_add'); ?>" title=""><?php _e('Add User');?></a></li>
</ul>
<div class="status_bar">
	<span id="adminusrlst_stat" class="status" style="display:none;"></span>
</div>
<table width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
  <tr>
    <td width="6%" bgcolor="#f6f6f4">ID</td>
    <td width="11%"><?php _e('Login'); ?></td>
    <td width="11%"><?php _e('Name'); ?></td>
    <td width="14%"><?php _e('E-mail'); ?></td>
    <!--td width="14%">电话号码</td-->
    <td width="14%"><?php _e('Last Login Time'); ?></td>
    <td width="14%"><?php _e('Last Login IP'); ?></td>
    <td width="16%"><?php _e('Active'); ?></td>
    <td width="16%"><?php _e('Operation'); ?></td>
  </tr>
  <?php
    if (sizeof($users) > 0) {
        $row_idx = 0;
        foreach ($users as $user) {
            //if (intval($user->id) == 1) {
                //continue;
            //}
    ?>
        <tr class="row_style_<?php echo $row_idx; ?>">
        	<td><?php echo $user->id; ?></td>
        	<td><?php echo $user->login; ?></td>
        	<td><?php echo $user->full_name; ?></td>
        	<td><?php echo $user->email; ?></td>
        	<!--td>021-58356483</td-->
        	<td><?php echo date('y-n-j g:i', $user->lastlog_time); ?></td>
        	<td><?php echo $user->lastlog_ip; ?></td>
        	<td><span id="uactive_<?php echo $user->id; ?>"></span>
        		<script type="text/javascript" language="javascript">
        		<!--
        			show_active("<?php echo $user->id; ?>", "<?php echo $user->active; ?>")
        		//-->
        		</script>
        	</td>
        	<td>
        		<span class="small">
        			<a href="<?php echo Html::uriquery('mod_user', 'admin_edit', array('u_id' => $user->id)); ?>" title="<?php _e('Edit'); ?>"><img style="border:none;position:relative;top:3px;" alt="<?php _e('Edit');?>" src="<?php echo P_TPL_WEB; ?>/images/edit.gif"/></a>
        			&nbsp;
					<!--?php if ($user->s_role != '{admin}') {?-->
        			<a href="#" onclick="delete_user(<?php echo $user->id; ?>);return false;" title="<?php _e('Delete'); ?>"><img style="border:none;position:relative;top:3px;" alt="<?php _e('Delete');?>" src="<?php echo P_TPL_WEB; ?>/images/cross.gif"/></a>
        			&nbsp;
					<?php if(EZSITE_LEVEL=='2'){?>
        			<a href="<?php echo Html::uriquery('mod_user', 'admin_finance', array('u_id' => $user->id)); ?>" title="<?php _e('Finance'); ?>"><img style="border:none;position:relative;top:3px;" alt="<?php _e('Finance');?>" src="<?php echo P_TPL_WEB; ?>/images/money.png"/></a>
					<?php }?>
					<!--?php }?-->
        		</span>
        	</td>
        </tr>
    <?php
            $row_idx = 1 - $row_idx;
        }
    } else {
    ?>
    	<tr class="row_style_0">
    		<td colspan="8"><?php _e('No Records!'); ?></td>
    	</tr>
    <?php
    }
    ?>
</table>
<?php
include_once(P_TPL.'/common/pager.php');
?>