<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
$toogleactivestr=(ACL::isAdminActionHasPermission('mod_user','admin_toggle_active'))?'true':'false';
$curUserid= SessionHolder::get('user/id', 0);
?>
<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 needtoogle=<?php echo $toogleactivestr; ?>;
     if(!needtoogle) return;
    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,rolename) {
    var active_label_id = "uactive_" + user_id;
    var active_html = "";
    if(rolename!='{admin}'){
			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>";
			}
	}else{
		if (active == "1") {
					active_html = "<a href=\"#\" onclick=\"return false;\" title=\"\">Yes</a>";
			} else {
					active_html = "<a href=\"#\" onclick=\"return false;\" title=\"\">No</a>";
			}
	}
    
    document.getElementById(active_label_id).innerHTML = active_html;
}
//-->
</script>

<ul style="margin-left:1px;min-height: 20px;">
 <?php
    if(ACL::isAdminActionHasPermission('mod_user', 'admin_add')){
?>
	<li><a class="usercont nopngfilter_spec" href="<?php echo Html::uriquery('mod_user', 'admin_add'); ?>" title=""><?php _e('Add User');?></a></li>
<?php
}
?>
 <?php
    if(ACL::isAdminActionHasPermission('mod_roles', 'admin_list')&&Toolkit::issitebaoheAuthorized()){
?>   
    <li><a class="usercont nopngfilter_spec" href="<?php echo Html::uriquery('mod_roles', 'admin_list'); ?>" title=""><?php _e('Role Manage');?></a></li>
<?php
}
?>
</ul>

<div class="status_bar">
	<span id="adminusrlst_stat" class="status" style="display:none;"></span>
</div>
<table width="100%" border="0" cellspacing="1" cellpadding="0" class="form_table_list" style="line-height:24px;margin-top:0;">
  <tr>
    <th width="6%" bgcolor="#f6f6f4">ID</th>
    <th width="11%"><?php _e('Login Name'); ?></th>
    <th width="11%"><?php _e('Role'); ?></th>
    <th width="14%"><?php _e('E-mail'); ?></th>
    <!--td width="14%">电话号码</td-->
    <th width="14%"><?php _e('Last Login Time'); ?></th>
    <th width="14%"><?php _e('Last Login IP'); ?></th>
    <th width="8%"><?php _e('Active'); ?></th>
    <th width="8%"><?php _e('Verify'); ?></th>
    <th width="16%"><?php _e('Operation'); ?></th>
  </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 Role::getRoleDesc($user->s_role); 
					?>
		</td>
        	<td><?php echo $user->email; ?></td>
        	<!--td>021-58356483</td-->
        	<td><?php echo date('Y-m-d H:i:s', $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; ?>","<?php echo $user->s_role; ?>");
        		//-->
        		</script>
        	</td>
			<td>
			<?php 
            $needchange=true;
            if(!ACL::isAdminActionHasPermission('mod_user', 'admin_pic')) $needchange=false;
            echo Toolkit::validateYesOrNo($user->member_verify,$user->id,"index.php?_m=mod_user&_a=admin_pic&_r=ajax&_id=".$user->id,$needchange);
            ?>
        	</td>
        	<td>
        		<span class="small">
                        <?php
					if(ACL::isRoleSuperAdmin()|| !ACL::isRoleSuperAdmin($user->s_role)){
                            if(ACL::isAdminActionHasPermission('mod_user', 'admin_edit')){
                        ?>
					<? //echo Html::uriquery('mod_user', 'admin_edit', array('u_id' => $user->id)); ?>
        			<a href="<?php	//修改后台会员管理跳转链接
					 		 if($_REQUEST["rurl"] == 1){
							 	echo "index.php?_m=mod_user&_a=admin_edit&u_id=$user->id";
							 }else{
					 			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
                            }
                          ?>
					<?php if ($user->s_role != '{admin}') {?>
        		 <?php
                            if(ACL::isAdminActionHasPermission('mod_user', 'admin_delete')&&$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
                            }
                          ?>
					<?php if(EZSITE_LEVEL=='2'&&ACL::isAdminActionHasPermission('mod_user', 'admin_finance')){?>
        			<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');
?>