<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	2011/6/5 Lay
*/

require '../../include/loader.php';
html_start("分类编辑 - VeryIDE");
?>

<!--body start-->
	<?php
	
	//form
	require 'naver.php';
	
	$fid = getnum('fid',0);
	$appid = getgpc('appid');
	
	//日期筛选
	$start = getgpc('start');
	$end = getgpc('end');
	
	$data = getgpc('data');
	$size = getnum("size",0);
	$max = getnum('max',0);
	$state = getnum('state',-1);
	
	$site = getgpc("site");
	$charset = getgpc('charset');
	?>
<!--main-->

	<?php    
	echo loader_script(array(VI_BASE."js/mo.calendar.js"),"utf-8",$_G['product']['version']);    
	?>
    
	<?php
	
	//加载缓存
	if ( $appid && $fid ) Cached :: loader( $appid, 'form.'.$fid );
	
	if( function_exists("mcrypt_module_open") ){
		
		//生成密钥
		if ( $appid && $fid ){
			$hash = array("appid"=>$appid,"fid"=>$fid,"name"=>$_CACHE[$appid]['form']["name"],"site"=>$site);
		}else{
			$hash = array("site"=>$site);
		}
		
		$keys = authcrypt( serialize($hash), VI_START );
		
	}else{
		
		echo "<div id='state' class='failure'>服务器不支持 <strong>mcrypt</strong> 模块！您可能无法继续本页某些操作，请联系系统管理员。</div>";
	}
	?>

    <script type="text/javascript">	
	
	function getCode(){
		/*数据类型*/
		var url = "<?php echo VI_HOST;?>module/member/content/api.php?keys=<?php echo rawurlencode($keys);?>&data="+Mo("input[name=data]").value();
	
		/*数据源*/
		url += "&source=<?php echo $appid && $fid? "value" : "member";?>";
	
		/*开始时间*/
		url += "&start=" + Mo("#start").value();
	
		/*结束时间*/
		url += "&end=" + Mo("#end").value();
	
		/*用户状态*/
		url += "&state=" + Mo("select[name=state]").value();
	
		/*每页大小*/
		url += "&size=" + Mo("#size").value();
	
		/*数量总量*/
		url += "&max=" + Mo("#max").value();

		/*编码*/
		url += "&charset=" + Mo("#charset").value();
	
		/*关键字*/
		url += "&key=" + encodeURIComponent(Mo("#key").value());
		
		Mo("#preview").html('');
		
		if( Mo("input[name=data]").value() == "xml" ){
			var code = url;
		}else{
			var code = '<sc'+'ript type="text/javascript" src="'+url+'" charset="'+Mo("#charset").value()+'"></sc'+'ript>';
		}
			
		/*取得要运行的代码*/
		var temp=document.createElement("IFRAME");
			  temp.id="add-iframe";
			  temp.style.width="100%";
			  temp.style.height="150px";
			  temp.src = url + '&preview=true';
		
		/*创建一个隐藏的IFRAME*/
		
		Mo("#give").append(temp);
		
		Mo("#code").value(code);
	}
	
	</script>
    
	<div id="box">
	    <form action="" method="post" name="from1" verify="true">
                
        <table cellpadding="0" cellspacing="0" class="form">
        
        <tr>
        	<td colspan="2" class="section"><strong>引用设置</strong></td>                
        </tr>

		<tbody>
          
          	<?php
			if( $appid && $fid ){
			?>
        	<tr>
            	<td><strong>数据名称：</strong></td>
                <td style="word-break:break-all;">
                	<span class="text-yes"><?php echo $_CACHE[$appid]['form']["name"];?></span>
                </td>
            </tr>
       		<?php
			}
			?>
       
            <tr>
                <td width="60"><strong>数据类型：</strong></td>
                <td>
                    <label>
                    	<input type="radio" class="radio" name="data" value="json" checked>
                    	JSON
                    </label>
                
                    <label>
                        <input type="radio" class="radio" name="data" value="xml">
                        XML
                    </label>
                </td>
            </tr>
         
        	<tr>
            	<td><strong>数据数量：</strong></td>
                <td>
                	<input name="size" type="text" class="text" id="size" value="10" size="13" fix_name="分类排序" fix_number="no" />
                    每页
                	<input name="max" type="text" class="text" id="max" value="100" size="13" fix_name="分类排序" fix_number="no" />
                    总数
                    <script type="text/javascript">Mo.Tools("Tip","当 [每页] 和 [总数] 都不为空时表示为分页显示");</script>
                </td>
            </tr>
        
            <tr>
                <td width="60"><strong>时间范围：</strong></td>
                <td>
                    <!--时间节点-->
                    <input name="start" type="text" class="date" id="start" value="<?php echo $start;?>" size="10" readonly="true" onclick="return showCalendar(this.id,'y-mm-dd');" title="年月日" onchange="Mo('#formSeacrh').submit();">
                    &nbsp;&nbsp;—&nbsp;&nbsp;
                    <input name="end" type="text" class="date" id="end" value="<?php echo $end;?>" size="10" readonly="true" onclick="return showCalendar(this.id,'y-mm-dd');" title="年月日" onchange="Mo('#formSeacrh').submit();">
                    <!--时间节点-->
                </td>
            </tr>
        
            <tr>
                <td width="60"><strong>用户状态：</strong></td>
                <td>
                    <select name="state">
                        <option value="-1">所有状态</option>
                        <option value="0">未确认</option>
                        <option value="1">已确认</option>
                    </select>                    
                </td>
            </tr>
         
        	<tr>
            	<td><strong>关键字：</strong></td>
                <td>
                	<input name="key" type="text" class="text" id="key" value="" size="37" fix_name="分类排序" fix_null="no" />
                     <script type="text/javascript">Mo.Tools("Tip","针对商家进行标题和简介搜索");</script>
                </td>
            </tr>
         
        	<tr>
            	<td><strong>你的网址：</strong></td>
                <td>
                	<input name="site" type="text" class="text" id="site" value="<?php echo $site?$site:"http://";?>" size="37" fix_name="你的网址" fix_null="yes" />
                     <script type="text/javascript">Mo.Tools("Tip","此API只能在此网址范围内使用");</script>
                </td>
            </tr>
         
        	<tr>
            	<td><strong>输出编码：</strong></td>
                <td>
                	<select name="charset" id="charset">
                    	<option value="">自动</option>
                    	<option value="gbk">GBK</option>
                    	<option value="utf-8">UTF-8</option>
                    </select>
                </td>
            </tr>
                        
            <tr class="nobr">
                <td><strong></strong></td>
                <td>
                    <input type="submit" name="Submit" value="生成代码" class="submit" />
                </td>
                
            </tr>
        </tbody>
        
        <tr>
        	<td colspan="2" class="section"><strong>引用代码</strong></td>                
        </tr>
    
        <tr>
            <td>
            </td>
            <td>
                <textarea name="code" id="code" rows="5" cols="100"></textarea>
            </td>
        </tr>
        
        <tr>
        	<td colspan="2" class="section"><strong>数据预览</strong></td>                
        </tr>
     
        <tr>
            <td>
            </td>
            <td id="give">
				<script type="text/javascript">
				Mo("input[name=data]").value("<?php echo $data ? $data : "json";?>");
				Mo("select[name=state]").value("<?php echo $state;?>");				
				Mo("#charset").value("<?php echo $charset;?>");				
				
				getCode();
				</script>
            </td>
        </tr>
       
        
        </table>
            
	 </form>
	</div>
	
<!--body end-->

<?php html_close();?>