<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: ,v1 10:39 2008-7-27 Leilei $
*/

require("../../include/header.php");
html_start("擂台列表 - VeryIDE");
?>

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

	//module
	require("naver.php");

	$q = GetQuery("q");
	$s = GetQuery("s");
	
	//批处理列表
    $list = $_POST["list"];
    $list = implode(",", $list);

    //上一页
    $jump = $_POST["jump"];
    
	$status = GetNumber("status",1);
	$order = GetQuery("order");
	$action = GetQuery("action");
	
	//mysql open
	reader_mysql();

	if ($action){
	
		switch($action){
			//删除
			case "delete":
			
				//检查权限
				checker_func("mod-pk-del");		
				
				//直接删除不经过回收站
				if( $Group["sys-system-recycle"]=="Y" ){
					
					mysql_query("delete from ".VI_DBMODPRE."forms where id in(".$list.")");
					mysql_query("delete from ".VI_DBMODPRE."groups where fid in(".$list.")");
					mysql_query("delete from ".VI_DBMODPRE."options where fid in(".$list.")");
					mysql_query("delete from ".VI_DBMODPRE."values  where fid in(".$list.")");				
					
					$Project["queries"]+=4;
					
					//删除缓存
					$array = explode(",",$list);
					foreach( $array as $id ){
						$file = VI_ROOT."/".$Project["cache"]."/".$appid."/forms.".$id.".php";
						unlink($file);
					}
					
					//清空统计
					require("../analytic/function.php");
					clear($appid,$list);
					
					//记录日志										
					event_insert($mysql,"sys-system-recycle",time(),time(),"删除数据：$appid (".$list.")");
					
				}else{
				
					$sql="update ".VI_DBMODPRE."forms set status=-1,modify=".time().",mender='".$_SESSION["Manager"]["account"]."' where appid='".$appid."' and id in(".$list.")";
					mysql_query($sql);				
					
					//生成缓存
					cache_forms($list,$appid,$mysql);
					
				}
				
				reader_redirect($appid.".list.php","表单数据删除成功!");
				
			break;
			
			//状态
			case "create":
				//生成缓存
				cache_forms($list,$appid,$mysql);				
				
				reader_redirect($jump,"表单缓存更新成功!");
				
			break;
			
			case "status":
			
				//检查权限
				checker_func("mod-pk-mod");
				
				$status = GetNumber("status",0);
			
				$sql="update ".VI_DBMODPRE."forms set status=".$status.",modify=".time().",mender='".$_SESSION["Manager"]["account"]."' where appid='".$appid."' and id in(".$list.")";
				mysql_query($sql);
				
				$Project["queries"]++;
				
				//生成缓存
				cache_forms($list,$appid,$mysql);
				
				reader_redirect($jump,"表单状态更改成功!");

			break;
		}
	}
    
    ?>

    <div id="search">
    
    <form name="form1" method="get" action="?">
        <span class="action">
            <input type="button" value="我的擂台" onclick="location.href='?s=account&q=<?php echo urlencode($_SESSION["Manager"]["account"]);?>';" class='cancel'>
            <input type="button" value="新增擂台" onclick="location.href='<?php echo $appid;?>.edit.php';" class='button'>
            <input type="button" value="更新缓存" onclick="if(confirm('确定现在要更新缓存吗？')){location.href='?action=create';}" class='button'>
        </span>
      
        <select name="s" id="s">
            <option value="name" checked> 标题</option>
            <option value="id"> ID</option>
            <option value="account"> 作者</option>
			<option value="mender"> 修改人</option>
            <option value="description"> 内容</option>
            <option value="tags"> 标签</option>
        </select>
        <input name="q" type="text" class="text" id="q" value="<?php echo $q;?>">
        
        <select id="order" name="order">
            <option value="">所有状态</option>
            <option value="normal">正常状态</option>
            <option value="expire">过期表单</option>
        </select>
        
        <button class="go" type="submit"></button>
        
    </form>
    </div>
    
    <script type="text/javascript">
        Mo("#s").value("<?php echo $s;?>");
        Mo("#order").value("<?php echo $order;?>");
        
        Mo.reader(function(){
            
            <?php
            //只针对新增内容
            if($_GET['mark']){
            ?>
            //操作提示
            Mo.Tips(null,$("mark-<?php echo $_GET['mark'];?>"),'info','点这里开始新增表单选项，鼠标指向“小灯泡”将会有小提示。',document,'click',-20,15);
            <?php
            }
            ?>
            
        });
    </script>

    <!--用于动作处理_开始-->
    <form name="formPost" id="formPost" method="post">
        <input name="action" id="action" type="hidden" value="" />        
        <input name="status" id="status" type="hidden" value="" />
        
        <input name="jump" type="hidden" value="" />
        <script>Mo('#formPost input[name=jump]').value( location.href );</script>
    
    <?php		
    $sql="SELECT * FROM ".VI_DBMODPRE."forms where appid='".$appid."' ";

    if ($q && $s){    
        if( strpos($s,"id") !== false ){
            $sql.=" and  ".$s." = ".$q;
        }else{
            $sql.=" and  ".$s." like '%".$q."%'";
        }        
    }
	
	//显示回收站
	if( $Group["sys-system-recycle"]!="Y" ) $sql.=" and status > -1 ";
        
    //排序
    $sql.=" order BY id desc";
    
    //查询数据库_总记录数
    $row_count = $db -> getValue( str_replace("*","count(id)",$sql) );   
    
    $Project["queries"]++;

    //分页参数
    $page=GetPage("page");
    $page_start=$Global["pagesize"]*($page-1);
    $sql=$sql." limit $page_start,".$Global["pagesize"];	
    
    //分页链接
    $url="?q=".$q."&s=".$s."&page=";
    
    $result=mysql_query($sql,$mysql);
	
    $Project["queries"]++;
    ?>
    <table width="100%" border="0" cellpadding="1" cellspacing="1" id="table" class="table">
		<?php
		if( mysql_num_rows($result)> $Global["pagesize"]/2 ){
		?>
        <tr class="thead">
            <td colspan="13" class="first"><?php echo $Modules[$appid]["tool"];?></td>
        </tr>
      	<?php
		}
		?>
      
        <tr class="title" id="thead">
            <td width="30"></td>
            <td>表单名称</td>
            <td align="center">人数 / 上限</td>
            <td>正方</td>
            <td>反方</td>
            <td>所有者</td>
			<td>修改者</td>
            <td>代码 <script>Mo.Tools("Tip","生成的HTML代码，用于嵌入帖子或博客等等");</script></td>
            <td>扩展 <script type="text/javascript">Mo.Tools("Tip","用户 填写提交此表单的用户列表<br />结果 此表单的数据结果<br />引用 此表单引用（调用）页地址，用于管理");</script></td>
            <td>图示</td>
            <td>起止时间</td>
            <td>创建时间</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
      
    <?php
    while($row=mysql_fetch_assoc($result)){
        
        //配置
        $config = fix_json( $row["config"] );
        
        ?>
          <tr class="line" mark="<?php echo $row["id"];?>" edit='<?php echo $appid;?>.edit.php?action=edit&fid=<?php echo $row["id"];?>&jump={jump}'>
            <td title="<?php echo $row["id"];?>">
                <input name="list[]" type="checkbox" class="checkbox" value="<?php echo $row["id"];?>">
            </td>
            <td title='<?php echo $row["name"];?>'>
                <a href="content/?id=<?php echo $row["id"];?>" target="_blank"><?php echo format_substr($row["name"],30,"...");?></a>
                <?php
                if($row["expire"]<time()){
                    echo '<sup class="text-no">[过期]</sup>';
                }
                if($row["status"]==-1){
                    echo '<sup class="text-yes">[回收站]</sup>';
                }
                ?>
            </td>
            <td align="center">
                <a href="../member/member.value.php?appid=<?php echo $appid;?>&fid=<?php echo $row["id"];?>" onclick="parent.Mo.Dialog('dialog','用户列表 - FID <?php echo $row["id"];?>' , '<iframe src='+this.href+' frameborder=0></iframe>','90%','70%',{ 'remove' : true, 'draged' : true, 'create' : true }); return false;"><?php echo $row["stat"];?></a>
                <?php
                if( $config["FORM_MAX"] ){
                    echo "/ ".$config["FORM_MAX"];
                }
                ?>
            </td>
            <td><?php echo $config["POSITIVE"];?></td>
            <td><?php echo $config["NEGATIVE"];?></td>
            <td><a href='?s=account&q=<?php echo urlencode($row["account"]);?>'><?php echo $row["account"];?></a></td>
            <td><a href='?s=mender&q=<?php echo urlencode($row["mender"]);?>'><?php echo $row["mender"];?></a></td>
            <td id="tips-<?php echo $row["id"];?>">
                <a href="<?php echo VI_BASE;?>dialog/iframe.php?<?php echo VI_BASE.$Modules[$appid]["path"]."?id=".$row["id"];?>" target="_blank">完整</a>
                /
                <a href="<?php echo VI_BASE;?>dialog/iframe.php?<?php echo VI_BASE.$Modules[$appid]["path"]."?mode=simple&id=".$row["id"];?>" target="_blank">简洁</a>                
            </td>
            <td>
                <?php
				echo '<a id="mark-'.$row["id"].'" href="content/?mode=layout&id='.$row["id"].'" target="_blank">'.loader_image("icon/color.png","自定义").'</a> ';
				
                echo '<a href="'.VI_BASE.'module/analytic/analytic.show.php?appid='.$appid.'&id='.$row["id"].'&type=views&name='.urlencode($row["name"]).'" onclick="new parent.Mo.Dialog( \'dialog\',\'统计分析\', \'<iframe src=\'+this.href+\' frameborder=0></iframe>\' ,\'90%\',\'70%\',{ \'remove\' : true, \'draged\' : true, \'create\' : true }); return false;">'.loader_image("icon/statistics.png","统计分析").'</a> ';
                
                // echo loader_image("icon/present.png","幸运大抽奖","","window.open('../lucky/?fid=".$row["id"]."&num=50');");
                
                if( $row["quote"] ){
                    echo '<a href="'.$row["quote"].'" target="_blank">'.loader_image("icon/globe.png","打开引用地址").'</a> ';
                }
                ?>
                
            </td>
            <td>
                <?php
                if($config['USER_MODE']=='REG'){
                    echo loader_image("icon/user.png","注册用户");
                }
                
                if($config['VERIFY-MODE']=='IP'){
                    echo loader_image("icon/shield.png","采用 IP 验证");
                }                    
                ?>
            </td>
            <td>
                <?php
                if($row["start"]>time()){
                    echo '<span class="text-no">'.date("y/m/d",$row["start"]).'</span>';
                }else{
                    echo '<span class="text-yes">'.date("y/m/d",$row["start"]).'</span>';
                }
                
                ?>
                -
                <?php
                
                if($row["expire"]<time()){
                    echo '<span class="text-no">'.date("y/m/d",$row["expire"]).'</span>';
                }else{
                    echo '<span class="text-yes">'.date("y/m/d",$row["expire"]).'</span>';
                }
                ?>
            </td>
            <td title="<?php echo date("Y-m-d H:i:s",$row["dateline"]);?>"><?php echo date("y-m-d",$row["dateline"]);?></td>
            <td><?php echo $Project["status"][$row["status"]];?></td>
            <td>
                <script type='text/javascript'>
                    Mo.Tools('RsEdit','<?php echo $appid;?>.edit.php?action=edit&fid=<?php echo $row["id"];?>','');
                    Mo.Tools('RsDelete','<?php echo $appid;?>.list.php?action=delete&list=<?php echo $row["id"];?>','');
                </script>
            </td>
            </tr>
        <?php
        }
        ?>
        
            <tr class="tfoot">
                <td colspan="9" class="first">
                    <?php echo $Modules[$appid]["tool"];?>
                </td>
                <td colspan="5">
                    <?php
                    echo loader_image("icon/color.png");
                    ?>
                    自定义
                    
                    <?php
                    echo loader_image("icon/user.png");
                    ?>
                    注册用户
                    
                    <?php
                    echo loader_image("icon/shield.png");
                    ?>
                    IP 验证
                    
                </td>
            </tr>
        </table>
    <?php
  
    //mysql close
    reader_mysql(true);
    
    ?>
    </form>
    <!--用于动作处理_结束-->
    
    <div id="saving">
		<?php
            echo GetPageLink($page,$row_count,$Global["pagesize"],$url,"page");
        ?>
    </div>
    
<!--body end-->

<?php html_close();?>