<?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");

	$jump = GetQuery("jump");
	$action = GetQuery("action");
	$id = GetNumber("id",0);
	
	if ($action){
		
		//mysql open
		reader_mysql();

		$name = GetQuery("name");
		$link = GetQuery("link");
		$method = GetQuery("method");
		$category = GetQuery("category");
		
		switch($action){
			case "add":
				
				//检查权限
				checker_func("mod-go-add");
				
				//检查数据
				checker_empty($name,$method);
				
				$sql="insert into ".VI_DBMODPRE."go(name,aid,account,category,link,dateline,modify,method) values('".$name."',".$_SESSION["Manager"]["id"].",'".$_SESSION["Manager"]["account"]."','".$category."','".$link."','".time()."',".time().",'".$method."')";
				
				mysql_query($sql,$mysql);
				
				$id = mysql_insert_id($mysql);
				
				//错误处理
				if (!$id) {
					trigger_error($sql, E_USER_ERROR);
					exit();
				}
				
				//缓存广告缓存
				cache_rows($appid,$mysql,VI_DBMODPRE."go","select * from ".VI_DBMODPRE."go where id=".$id);
				
				reader_redirect("go.list.php?mark=".$id,"链接提交成功!");

			break;
				
			case "update":
				
				//检查权限
				checker_func("mod-go-mod");
				
				$sql="update ".VI_DBMODPRE."go set name='".$name."',category='".$category."',link='".$link."',modify=".time().",mender='".$_SESSION["Manager"]["account"]."' where id=".$id;

				mysql_query($sql);
				
				//缓存广告缓存
				cache_rows($appid,$mysql,VI_DBMODPRE."go","select * from ".VI_DBMODPRE."go where id=".$id);		
				
				reader_redirect("go.list.php","链接修改成功!");
			
			break;
			
			case "edit";
				
				//检查权限
				//checker_func("mod-go-mod");		
				
				$sql="select * from ".VI_DBMODPRE."go where id=".$id;
				$result=mysql_query($sql,$mysql);
				
				if(mysql_num_rows($result)==1){
					$row=mysql_fetch_assoc($result);
				}
			
			break;
		}
		  
		//mysql close
		reader_mysql(true);
	  }
	  
	?>
    
    <script type="text/javascript">		
		function doChanged(s){
		
			var b = ['click'];
			if( Mo.Array( b ).indexOf( s ) > -1 ){
				Mo('#addv').show();
			}else{
				Mo('#addv').hide();
			}
		}
    </script>
<!--main-->

	<?php
	
	//显示权限状态
	switch($action){
		case "":
			echo checker_func("mod-go-add",true);
		break;
		
		case "edit":
			echo checker_func("mod-go-mod",true);
		break;
	}
	
	?>

	<div id="box">
	    <form action="" method="post" name="from1" mode="edit" verify="true">        
        	
        <table cellpadding="0" cellspacing="0" class="form">
        
        	<tr text='按内容性质进行分类归档'>
            	<td width="60"><strong>内容分类：</strong></td>
                <td>
                	<select name="category" id="category">
                    	<option value="">请选择...</option>
                    	<?php
						$category = explode(" ",trim($Global["category"]));
						
						foreach($category as $cate){
							echo '<option value="'.$cate.'">'.$cate.'</option>';
						}						
						?>
                    </select>
                    <br />
                    注意：选择分类后此内容将进入关键字系统
                </td>
            </tr>
        
        	<tr>
            	<td width="60"><strong>链接名称：</strong></td>
                <td><input name="name" type="text" class="text" id="name" value="<?php echo $row["name"];?>" size="35" fix_name="链接主题" fix_null="yes" /></td>
            </tr>
        
        	<tr>
            	<td width="60"><strong>数据类型：</strong></td>
                <td>
                <label><input type="radio" class="radio" name="method" value="click" checked="checked" onclick='doChanged(this.value)' <?php echo ($action?' disabled="disabled" ':'');?> /> 点击量 </label>
                <label><input type="radio" class="radio" name="method" value="view" onclick='doChanged(this.value)' <?php echo ($action?' disabled="disabled" ':'');?> /> 浏览量 </label>
                </td>
            </tr>
        
        	<tr id="addv" text='填写此链接引用页地址,将在列表中显示,以后可以更方便的找到引用页'>
            	<td><strong>链接地址：</strong></td>
                <td>
                    <input name="link" type="text" class="text" id="link" value="<?php echo $row["link"];?>" size="70" /> 
                    <?php echo loader_image("icon/globe.png","打开引用地址","","var s=$('quote').value;if(s){window.open(s);}");?>
                
                </td>
            </tr>
        
        	<tr class="nobr">
            	<td><strong></strong></td>
                <td>
					<?php
                        if ($action=="edit"){
                            echo '
                            <input name="action" type="hidden" id="action" value="update" />
                            <input name="id" type="hidden" id="id" value="'.$row["id"].'" />
                            ';
                            echo '<input type="submit" name="Submit" value="修改此统计" class="submit" />';
                        }else{
                            echo '<input name="action" type="hidden" id="action" value="add" />';
                            echo '<input type="submit" name="Submit" value="新增此统计" class="submit" />';
                        }
                    ?>
                </td>
            </tr>
        
        </table>
        
		<script type="text/javascript">
        Mo("input[name=method]").value("<?php echo $row["method"];?>");
        Mo("#category").value( "<?php echo $row["category"];?>" );
		doChanged("<?php echo $row["method"]?$row["method"]:"click";?>");
        </script>
        
    	</form>
        
    </div>
	
<!--body end-->

<?php html_close();?>