<?php
/*
*	Copyright VeryIDE,2007-2009
*	http://www.veryide.com/
*
*	$Id: ,v1 10:39 2010-7-27 19%Girs $
*/

require '../../include/loader.php';
html_start("会员列表 - VeryIDE");
?>

<!--body start-->
	<?php

	//载入通行证函数
	Module :: loader( 'member' );
	Module :: loader( 'passport' );

	$key = getgpc('q');
	$st = getgpc("s");
	$f = getnum("f",-1);
	$fid = getnum('fid',0);
	
	//批处理列表
	$list = getgpc('list');
    $list = is_array($list) ? implode(",", $list) : $list;
	
	$appid = getgpc('appid');
	$action = getgpc('action');
		
	//连接数据库
	System :: connect();
				
	if ($action){
	
		switch($action){
			
			//删除
			case "delete":
			
				//检查权限
				System :: check_func("mod-".$appid."-comment-del", false );	
			
				//删除提交数据
				System :: $db -> execute("DELETE FROM `mod:comment` WHERE appid = '".$appid."' and id in(".$list.")");
				
				$_G['project']['message'] = "成功删除评论！";
				
			break;			
			
			//领取状态
			case "state":
			
				//检查权限
				System :: check_func("mod-".$appid."-comment-mod", false );	
				
				$state = getnum('state',0);
			
				$sql="UPDATE `mod:comment` SET state=".$state." WHERE appid = '".$appid."' and id in(".$list.")";
				System :: $db -> execute($sql);
				
				$_G['project']['message'] = "成功更改评论状态！";

			break;
			
			//回复
			case "reply":			
				
				//检查权限
				System :: check_func("mod-".$appid."-comment-mod", false );		

				$answer = getgpc("answer");
				$id = getnum('id',0);
				$uid = getnum('uid',0);
				
				$sql="UPDATE `mod:comment` SET site_answer='".$answer."',site_dateline='".time()."' WHERE id =".$id;
				System :: $db -> execute($sql);
				
				//发送短消息
				if( $uid ){
					
					$row = System :: $db -> getOne( "SELECT account,tags from `mod:comment` WHERE id=".$id );
					
					$content = str_replace( array('{TIME}','{USER}','{EVENT}','{URL}','{VERYIDE}'),
									array( date('Y-m-d H:i:s') ,$row['account'], $title, $row['tags'], VI_HOST ) ,$_G['setting']['member']['comment_content'] );
					
					Passport :: notice( $uid, $_G['setting']['member']['comment_title'], $content );
				}
				
				$_G['project']['message'] = "成功回复评论！";
				
			break;
			
		}
	}
    ?>
    
    <div id="search">
    <!--用于动作处理_开始-->
    <form name="formReply" id="formReply" method="post" action="?">
        <textarea name="answer" id="reply_answer" cols="50" rows="3" style="display:none;"></textarea>
        <input type="hidden" name="uid" id="reply_uid" value="" />        
        <input type="hidden" name="id" id="reply_id" value="" />
        <input type="hidden" name="action" value="reply" />
        <input type="hidden" name="appid" value="<?php echo $appid;?>" />
        <input type="hidden" name="fid" value="<?php echo $fid;?>" />        
    </form>
     <!--用于动作处理_结束-->		

    <form name="formSearch" id="formSearch" method="get" action="?">
        <select name="s" id="s">
            <option value="uid" checked> U I D</option>
            <option value="account"> 用户名称</option>
            <option value="question"> 评论内容</option>
        </select>
        
        <input name="q" type="text" class="text" id="q" value="<?php echo $key;?>" />
        
        <select name="f" id="f">
            <option value="-1"> 全部评论</option>
            <option value="1"> 有效评论</option>
            <option value="0"> 无效评论</option>
        </select>
        
        <button class="go" type="submit"></button>
        <input name="fid" value="<?php echo $fid;?>" type="hidden" />
        <input name="appid" value="<?php echo $appid;?>" type="hidden" />       
    </form>
    </div>
    
    <script type="text/javascript">
        Mo("select[name=s]").value("<?php echo $st;?>");
        Mo("select[name=f]").value("<?php echo $f;?>");
    </script>

    <?php
	
	//显示有效竞拍（最后一次出价）
    $sql="SELECT * FROM `mod:comment` WHERE appid = '".$appid."' and fid=".$fid;
	
    if ( $f>-1 ){
        $sql.=" and state =".$f;
	}
	
    if ($key){
        $sql.=" and  ".$st." like '%".$key."%'";
    }
    
    //排序
    $sql.=" order BY id desc";
    
    //查询数据库_总记录数
    $row_count = System :: $db -> getCount( $sql );
    //分页参数
    $page=getpage("page");
    $page_start=$_G['setting']['global']['pagesize']*($page-1);
    $sql=$sql." limit $page_start,".$_G['setting']['global']['pagesize'];	
    
    //分页链接
    $url="?q=".$key."&s=".$st."&fid=".$fid."&page=";
    
    $result = System :: $db -> getAll( $sql );
	
    ?>
    
    <!--用于动作处理_开始-->
    <form name="formPost" id="formPost" method="post">
        <input name="action" id="action" type="hidden" value="" />        
        <input name="state" id="state" type="hidden" value="" />
        <input type="hidden" name="appid" value="<?php echo $appid;?>" />
        <input type="hidden" name="fid" value="<?php echo $fid;?>" />
        
        <input name="jump" type="hidden" value="" />
        <script>Mo('#formPost input[name=jump]').value( location.href );</script>
    
    <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table" id="table">
		<?php
		if( count($result)> $_G['setting']['global']['pagesize']/2 ){
		?>
        <tr class="thead">
            <td colspan="11" class="first"><?php echo $_G['module']['member']['comment'];?></td>
        </tr>
      	<?php
		}
		?>
      
        <tr class="title" id="thead">
            <td width="30"></td>
            <td>UID</td>
            <td>用户名</td>
			<td>出价</td>
			<td>姓名</td>
			<td>电话</td>
			<td>QQ号码</td>
            <td width="80">评论状态</td>
            <td>提交时间</td>
            <td>回复时间</td>
            <td width="40">操作</td>
        </tr>
      
    <?php
    foreach( $result as $row ){     
	
		//个人信息
		$member = Passport :: member( $row['uid'] );
	
        ?>
      <tr class="line" pid="<?php echo $row['id'];?>">
        <td title="<?php echo $row['id'];?>">
            <input name="list[]" type="checkbox" class="checkbox" value="<?php echo $row['id'];?>">
        </td>
        <td><?php echo $row['uid'];?></td>
        <td title='<?php echo $row['account'];?>'>
            <a href="<?php echo "../member/member.profile.php?uid=".$row['uid'];?>" target="_blank" onclick="parent.Mo.Window('dialog','用户个人信息' ,this.href ,'850','80%',{}); return false;"><?php echo format_substr($row['account'],30,"...");?></a>
        </td>
        <td><strong class="text-yes"><?php echo $row["price"];?></strong></td>
        <td><?php echo $member['name'];?></td>
        <td><?php echo $member['phone'];?></td>
        <td><?php echo $member['qq'];?></td>
        <td><?php echo $_G['project']['state'][$row['state']];?></td>
        <td><?php echo '<span class="text-yes">'.date("y/m/d G:i:s",$row['dateline']).'</span>';?></td>
        <td><?php echo $row["site_dateline"] ? '<span class="text-key">'.date("y/m/d G:i:s",$row["site_dateline"]).'</span>' : '';?></td>        
        <td>
			<script type='text/javascript'>
                Mo.Tools('RsDelete','?action=delete&appid=<?php echo $row['appid'];?>&fid=<?php echo $row['fid'];?>&list=<?php echo $row['id'];?>','');
            </script>
        </td>
        </tr>
        
        <tr class="line">
              <td colspan="15" class="block">
                <?php echo stripslashes($row["question"]);?>                    
                <hr />                    
                <p>我的回复：<?php if( $row["uid"]){?>（同时站内消息提醒）<?php }?><br />
                <textarea name="answer" id="answer_<?php echo $row["id"];?>" cols="80" rows="3"><?php echo $row["site_answer"];?></textarea>
                <input type="button" class="button" value="保存回复" onclick="Mo('#reply_answer').value( Mo('#answer_<?php echo $row["id"];?>').value() );Mo('#reply_id]').value( <?php echo $row["id"];?> );Mo('#reply_uid]').value( <?php echo $row["uid"];?> );Mo('#formReply').submit();" />
                
                </p>
              </td>
          </tr>
            
        <?php
        }
        ?>    
        <tr class="tfoot">
            <td colspan="11" class="first">
                <?php echo $_G['module']['member']['comment'];?>
            </td>
        </tr>
        </table>
    <?php
  
	//关闭数据库
	System :: connect();
    
    ?>
    </form>
    <!--用于动作处理_结束-->
    
    <div id="saving">
		<?php
            echo multipage($page,$row_count,$_G['setting']['global']['pagesize'],$url,"page");
        ?>
    </div>
    
<!--body end-->

<?php html_close();?>