<?php	
define('IN_OUN', true);
include_once( "includes/command.php");
include_once(ROOT_PATH . 'class/cls_image.php');
$image = new cls_image();
include_once(ROOT_PATH.'includes/ckeditor/ckeditor.php');  
if(!empty($Aconf['priveMessage']))
{
   echo showMessage($Aconf['priveMessage']);
   exit;
}

if ( $_SESSION[$un_aaction_list] != 'all' and empty($_SESSION[$un_aarticlecat_list]))
{
   echo showMessage("文章分类权限没有指定，不能查阅文章列表，请与管理员联系");
   exit;  
}

$Aarticlecat_list = false;
if(!empty($_SESSION[$un_aarticlecat_list])) {
  //找到所有的文章分类权限,通过提交的分类查找包含的下级分类
	$db_table = $pre."articat";
	$Aarticlecat_list = explode(',',$_SESSION[$un_aarticlecat_list]);
	foreach ($Aarticlecat_list AS  $v)
	{
         $strAcid .= $v.','.next_node_all($v,$db_table,'acid',true).',';
	}
    $Aarticlecat_list = explode(',',$strAcid);
	$Aarticlecat_list = array_unique($Aarticlecat_list);
	$articlecat_list = '';
	foreach ($Aarticlecat_list AS  $v)
	{
         if($v > 0 )
		 {
              $articlecat_list .= $v.',';
		 }
	 } 
	 $articlecat_list = substr($articlecat_list,0,-1);
	 $_SESSION[$un_aarticlecat_list] = $articlecat_list;

	 $Aarticlecat_list = explode(",",$_SESSION[$un_aarticlecat_list]); //得到分类名权限
	 //查找包含的下级分类 end 
}
 
if(!isset($strMessage)) $strMessage=false;
if(!isset($acid)) $acid=false;
if(!isset($sort_by)) $sort_by=false;
if(!isset($start_time)) $start_time=false;
if(!isset($end_time)) $end_time=false;
if(!isset($dateadd)) $dateadd=false;
if(!isset($sear_name)) $sear_name=false; 
if(!isset($_POST['act'])) $_POST['act']=false; 
if(!isset($acid)) $acid=false; 
if(!isset($filename)) $filename=false;
$http_var = 'acid='.$acid.'&sort_by='.$sort_by.'&start_time='.$start_time.'&end_time='.$end_time.'&dateadd='.$dateadd.'&sear_name='.$sear_name;
if($_POST['act'] == 'insert' || $_POST['act'] == 'update' )
{
	$is_insert   = $_POST['act'] == 'insert';
	$myuser_id   = $_SESSION[$un_auser_id];
    if(trim($_POST['name']) == '' )
	{
		//$strMessage = '标题不能为空';
		$_POST['name'] = sub_str(clean_html($_POST["descs"]),40,false);
	}
	//else
	//{
 	    /* 处理主图 */
		$arti_thumb = $_POST['old_arti_thumb'];
		$min_thumb = $_POST['old_min_thumb'];
	    if($_FILES["arti_thumb"]["size"] > 0 ) {
		    /* 判断图像类型 */
            if (!$image->check_img_type($_FILES['arti_thumb']['type'])) {
                $strMessage =  '图片类型错误,只支持 .jpg,.gif,.png格式.\n';
            }else{
			    if($_FILES["arti_thumb"]["size"] > settype($_POST['MAX_FILE_SIZE'], "integer")){
				    $strMessage =  '文件太大，不能上传：最大为2M.\n';
			    } else{	
   			        $img_width = ($_POST['img_width'] > 0 )?$_POST['img_width']:$Aconf['big_thumb_w'];
					$img_height = ($_POST['img_height'] > 0 )?$_POST['img_height']:$Aconf['big_thumb_h'];

                    if($img_width > $Aconf['min_thumb_w'] ) {
						$img_width_min  = $Aconf['min_thumb_w'];
						$img_height_min = intval($img_width_min * $img_height/$img_width);
					} else {
                        $img_width_min  = $img_width;
						$img_height_min = $img_height;
					}

                    /* 生成缩略图 */
                     $arti_thumb = $image->make_thumb($_FILES["arti_thumb"]['tmp_name'], $img_width, $img_height);
                    /* 像册 */
				     $thumb_url = $image->make_thumb($_FILES["arti_thumb"]['tmp_name'], $img_width_min, $img_height_min);
					 $min_thumb = $thumb_url;
				    /* 原图 */
		             $filename = $image->upload_image($_FILES["arti_thumb"]);
			     }
		     }		  
	     } 

	     /* 像册图片处理 star */
         /* 检查图片：如果有错误，检查尺寸是否超过最大值；否则，检查文件类型 */
         if (isset($_FILES['img_url']['error'][0])) // php 4.2 版本才支持 error
         {
             // 最大上传文件大小
             $php_maxsize = ini_get('upload_max_filesize');
             $htm_maxsize = '2M';
             // 相册图片
             foreach ($_FILES['img_url']['error'] AS $key => $value)
             {				
                 if ($value == 0)
                {		
                    if (!$image->check_img_type($_FILES['img_url']['type'][$key]))
                    {
                       $strMessage = '文件类型错误:'.$key;
					   break;
                    }
                 }
                 elseif ($value == 1)
                {
                    $strMessage = '文件太大:'.$key.' '.$php_maxsize;
				    break;
                }
                elseif ($_FILES['img_url']['error'] == 2)
               {
                   $strMessage = '文件太大:'.$key.' '. $htm_maxsize;
			       break;
               }
             }
	      }
          /* 4。1版本 */
          else
          {
              // 相册图片
		      while( @list( $key, $value ) = @each( $_FILES['img_url']['tmp_name']) )
              {			
                  if ($value != 'none')
                  {				
                      if (!$image->check_img_type($_FILES['img_url']['type'][$key]))
                      {
                          $strMessage = '文件无效:'. $key + 1;
					      break;
                       }
                    }
                }
           }
	      /* 像册图片处理 end */

	  /* 关联文章处理 */
	    $cltion = '';
		while( @list( $k, $v) = @each($_POST['keysname']) ) {
			if($_POST['keyshttp'][$k] != ''){
			   $cltion .=  $v.'[|]'.$_POST['keyshttp'][$k].'{|}';
			}

		}
	    /* 关联产品处理 */
	    $cltion_product = '';
		while( @list( $k, $v) = @each($_POST['keysname_product']) ) {
			if($_POST['keyshttp_product'][$k] != ''){
			   $cltion_product .=  $v.'[|]'.$_POST['keyshttp_product'][$k].'{|}';
			} 
		}
	    /* 关联专题处理 */
	    $cltion_topic = '';
		while( @list( $k, $v) = @each($_POST['keysname_topic']) ){
			if($_POST['keyshttp_topic'][$k] != ''){
			   $cltion_topic .=  $v.'[|]'.$_POST['keyshttp_topic'][$k].'{|}';
			} 
		}

      //数据添加  
	  $otherurl = trim($otherurl);
	  $otherurl = str_replace('http://','', $otherurl);
      if($otherurl)
	  {
		  $otherurl = "http://".$otherurl;
	  }
	  //是否加入图库  
	  $ifpic = $ifpic; 
	  $arti_date = local_strtotime($arti_date);
	  $subname = (trim($_POST["subname"]) == '' )?trim($_POST["name"]):trim($_POST["subname"]);

	  if($is_insert)
	  {
	    /* 入库 */
		$db_table = $pre.'artitxt';
		$sql = "INSERT INTO " . $db_table . " ( `acid` , `aaid` ,`ifpic`,`name` , `subname` , `otherurl` ,`edit_comm`,`top` , `colors` , `arti_date` , `dateadd` ,`user_id` ,`min_thumb`,`arti_thumb`, `states` , `domain_id` )" .
                 "VALUES ('$_POST[acid]','$_POST[aaid]',$ifpic,'$_POST[name]','$subname', '$otherurl','$_POST[edit_comm]','$_POST[top]', '$_POST[colors]','$arti_date',  '".gmtime()."','$myuser_id', '$min_thumb','$arti_thumb','0','$_SESSION[$un_domain_id]')"; 
        $oPub->query($sql);
        /* 编号 */
        $arid = $is_insert ? $oPub->insert_id() : $_POST['arid'];

        $db_table = $pre.'article';
		$sql = "INSERT INTO " . $db_table . " ( `arid` , `user_id` , `sour` , `sourhttp` , `name` ,  `descs` , `cltion` , `cltion_product` ,`cltion_topic` ,`dateadd` , `domain_id`  )" .
                 "VALUES ($arid,'$myuser_id','$_POST[sour]','$_POST[sourhttp]','$_POST[name]','$_POST[descs]', '$cltion','$cltion_product','$cltion_topic', '".gmtime()."', '$_SESSION[$un_domain_id]')"; 
        $oPub->query($sql);

		/* tag */
		$db_table = $pre.'arti_tag';
		foreach ($_POST['keys'] AS $k => $v)
        {
			if($v){
		       $sql = "INSERT INTO " . $db_table . " ( `arid` , `keys` ,`domain_id`)  VALUES ($arid,'$v',$_SESSION[$un_domain_id])"; 
               $oPub->query($sql);
			}
		}
		/* 相册 */
		
		if($filename && $thumb_url)
		{
		     $db_table = $pre.'arti_file';
		     $sql = "INSERT INTO " . $db_table . " ( `arid` ,  `filename` , `thumb_url`,`descs`,`domain_id`  )" .
                    "VALUES ($arid,'$filename', '$thumb_url','$subname',$_SESSION[$un_domain_id])"; 
             $oPub->query($sql);
		 }
		 $strMessage = '添加成功!';
 
         $_REQUEST['action'] = 'edit' ;
		 $_REQUEST['arid']      =  $arid;
	  }
      else if($_POST['act'] == 'update' && $_POST['arid'] > 0 && $_POST['states'] < 1)
	  {
		$db_table = $pre.'artitxt';
		$arid = $_POST['arid']+0;
        $sql = "UPDATE " . $db_table . " SET 
               `acid`='$_POST[acid]' ,
			   `aaid`='$_POST[aaid]' ,
			   `ifpic`='$ifpic',
               `name`='$_POST[name]' ,
			   `subname` ='$subname' ,
			   `otherurl`='$otherurl' ,
			   `edit_comm`='$_POST[edit_comm]',
               `top`='$_POST[top]' , 
               `colors`='$_POST[colors]',
			   `arti_date`='$arti_date',
			   `min_thumb`='$min_thumb',
			   `arti_thumb`='$arti_thumb' 
		        WHERE `arid` =".$arid." 
				and `states` = 0 
				and `domain_id`=".$_SESSION[$un_domain_id];
        $oPub->query($sql);

		$db_table = $pre.'article';
        $sql = "UPDATE " . $db_table . " SET 
               `sour`= '$_POST[sour]', 
               `sourhttp`= '$_POST[sourhttp]', 
               `name` ='$_POST[name]',   
               `descs`= '$_POST[descs]', 
               `cltion`= '$cltion',
			   `cltion_product`= '$cltion_product',
			   `cltion_topic`= '$cltion_topic' 
		        WHERE `arid` =".$arid." and `domain_id`=".$_SESSION[$un_domain_id];
        $oPub->query($sql);

		/* tag */
		$db_table = $pre.'arti_tag';
		$art_pro_type = 0;
		foreach ($_POST['keys'] AS $k => $v)
        {
			if($v){
		       $sql = "SELECT atid FROM ".$db_table." 
                      WHERE `atid` = '$k' 
					  AND art_pro_type = '$art_pro_type'";
               $Anorm = $oPub->selectrow($sql);
		       if( $Anorm[atid] >0){
				    $sql = "UPDATE ".$db_table. " SET `keys`='$v' WHERE atid='$Anorm[atid]'";					
					$oPub->query($sql);
			   }
			   else
			   {
		           $sql = "INSERT INTO " . $db_table . " ( `arid` , `keys`,`domain_id` )  VALUES ($arid,'$v',$_SESSION[$un_domain_id])"; 
                   $oPub->query($sql);
			   }
			}
		}
		/* 相册 */
		if(!isset($filename)) $filename=false;
		if($filename && $thumb_url)
		{
		     $db_table = $pre.'arti_file';
		     $sql = "INSERT INTO " . $db_table . " ( `arid` ,  `filename` , `thumb_url`,`descs`,`domain_id`  )" .
                    "VALUES ($arid,'$filename', '$thumb_url','$subname',$_SESSION[$un_domain_id])"; 
             $oPub->query($sql);
		 }
		/* 编辑图片描述 old_img_desc */
		if (isset($_POST['old_img_desc']))
        {
			foreach ($_POST['old_img_desc'] AS $key => $val)
           {
				$db_table = $pre.'arti_file';
				$sql = "UPDATE " . $db_table . " SET `descs` = '$val' WHERE `fileid` =".$key;
                $oPub->query($sql);              
		   }
		}
 
        $strMessage .= ' 修改成功！';
	  }
	  /* 处理相册图片 */
		handle_gallery_image($arid, $_FILES["img_url"], $_POST['namedesc']); 
		$_REQUEST['action'] = 'edit' ;
		$_REQUEST['arid']      =  $arid;
} 
$strCltion = $strCltion_product  = $strCltion_topic = '';
if($action == 'edit' && $arid) {   
	$sql = "SELECT a.arid,a.acid,a.acid,a.aaid,a.vtid,a.ifpic,a.name,a.subname,a.otherurl,a.top,a.colors,a.arti_date,a.min_thumb,a.arti_thumb,a.states,a.edit_comm,b.sour,b.sourhttp,b.descs,b.cltion,b.cltion_product,b.cltion_topic    
	        FROM ".$pre."artitxt as a,".$pre."article as b 
			where a.arid = b.arid 
			AND a.arid = '$arid'
			AND a.domain_id=$_SESSION[$un_domain_id]";
    $work = $oPub->selectrow($sql);

	$work["arti_date"]  = date("Y-m-d H:i", $work["arti_date"]);
	/* 关联文章格式调整 */ 
	$n = 0;
    if($work["cltion"]) {
		$strCltion = '<b>编辑关联文章：</b><br/>';
		$Acltion = explode("{|}",$work["cltion"]);
        while( @list( $k, $v) = @each($Acltion) ) {
	       $Akeysname = explode("[|]",$v);
		   if(!isset($Akeysname[0])) $Akeysname[0]=false;
		   if(!isset($Akeysname[1])) $Akeysname[1]=false;
           $strCltion .= '标题：<input type="text" name="keysname['.$n.']" value="'.$Akeysname[0].'" size="50"/>';
           $strCltion .= '网址：<input type="text" name="keyshttp['.$n.']" value="'.$Akeysname[1].'" size="50"/>';

           $pos = strpos($Akeysname[1], '://');
           if ($pos === false) {
              $strCltion .= '<A HREF="../'.$Akeysname[1].'" target="_blank"> 详情>> </A><br/>';
		   }else{
			   $strCltion .= '<A HREF="'.$Akeysname[1].'" target="_blank"> 详情>> </A><br/>';
		   }
		   $n ++ ;
        }
	}
	/* 关联产品格式调整 */
    if($work["cltion_product"])
	{
		$strCltion_product = '<b>编辑关联产品：</b><br/>';
		$Acltion = explode("{|}",$work["cltion_product"]);
        while( @list( $k, $v) = @each($Acltion) ) {
	       $Akeysname = explode("[|]",$v);
           $strCltion_product .= '标题：<input type="text" name="keysname_product[]" value="'.$Akeysname[0].'" size="50"/>';
           $strCltion_product .= '网址：<input type="text" name="keyshttp_product[]" value="'.$Akeysname[1].'" size="50"/>';

           $pos = strpos($Akeysname[1], '://');
           if ($pos === false) {
              $strCltion_product .= '<A HREF="../'.$Akeysname[1].'" target="_blank"> 详情>> </A><br/>';
		   }else{
			   $strCltion_product .= '<A HREF="'.$Akeysname[1].'" target="_blank"> 详情>> </A><br/>';
		   }
        }
	}
	/* 关联专题格式调整 */
    if($work["cltion_topic"])
	{
		$strCltion_topic = '<b>编辑关联专题：</b><br/>';
		$Acltion = explode("{|}",$work[cltion_topic]);
        while( @list( $k, $v) = @each($Acltion) ) {
	       $Akeysname = explode("[|]",$v);
           $strCltion_topic .= '标题：<input type="text" name="keysname_topic[]" value="'.$Akeysname[0].'" size="50"/>';
           $strCltion_topic .= '网址：<input type="text" name="keyshttp_topic[]" value="'.$Akeysname[1].'" size="50"/>';

           $pos = strpos($Akeysname[1], '://');
           if ($pos === false) {
              $strCltion_topic .= '<A HREF="../'.$Akeysname[1].'" target="_blank"> 详情>> </A><br/>';
		   }else{
			   $strCltion_topic .= '<A HREF="'.$Akeysname[1].'" target="_blank"> 详情>> </A><br/>';
		   }
        }
	}
    /* 关键词tag */
    $db_table = $pre."arti_tag"; 
	$art_pro_type = 0;
    $sql = "SELECT * FROM ".$db_table." 
	       where arid = $arid 
		   AND art_pro_type = $art_pro_type 
	       ORDER BY atid ASC LIMIT 3";
    $row = $oPub->select($sql);
    while( @list( $k, $v) = @each( $row) ) {
	   $atid = $v[atid];
       $work["keys"][$atid] = $v[keys];
    }
	/* 像册列表 */
	$db_table = $pre.'arti_file';
    $sql = "SELECT * FROM " . $db_table . " WHERE arid = '$arid'";
    $img_list = $oPub->select($sql);
}

/* 找到所有的分类到select start*/
$db_table = $pre."articat"; 
$sql = "SELECT * FROM ".$db_table." where fid = 0 AND domain_id=".$_SESSION[$un_domain_id]." ORDER BY acid ASC";
$AnormAll = $oPub->select($sql);
$Stropt = '<SELECT NAME="acid">';
$n = 0;
if(!isset($work['acid'])) $work['acid']=false;
while( @list( $key, $value ) = @each( $AnormAll) ) {
	   $acid = !empty($work['acid']) ? $work['acid']:$acid;
       $selected = ($acid == $value["acid"])? 'SELECTED':'';
	   if(is_array($Aarticlecat_list) && $_SESSION[$un_aaction_list] != 'all') {
	      if(in_array($value["acid"],$Aarticlecat_list)) {
		    $n ++;
            
            $Stropt .= '<OPTION VALUE="'.$value["acid"].'" '.$selected.' >'.$n.'、'.$value["name"].'</OPTION>';
		  }
	   }  else {
	     $n ++;
         $Stropt .= '<OPTION VALUE="'.$value["acid"].'" '.$selected.' >'.$n.'、'.$value["name"].'</OPTION>';
	   }
	   /* 查找儿子 */
       if($value["next_node"] != '') {          
             $Stropt .= get_next_node($value["next_node"],$work['acid'],$str = '　',$Aarticlecat_list);
	   } 
}
$Stropt .= '</SELECT>';
/* 找到所有的分类到select end*/

/* 找到所有的属性到select start*/
$db_table = $pre."arti_attr"; 
$sql = "SELECT * FROM ".$db_table." where  domain_id=".$_SESSION[$un_domain_id]." ORDER BY aaid ASC";
$AnormAll = $oPub->select($sql);

$Stroptaaid = '<SELECT NAME="aaid">';
$n = 0;
if(!isset($work['aaid'])) $work['aaid']=false;
while( @list( $key, $value ) = @each( $AnormAll) )
{
    $n ++;
    $selected = ($work['aaid'] == $value["aaid"])? 'SELECTED':'';
    $Stroptaaid .= '<OPTION VALUE="'.$value["aaid"].'" '.$selected.' >'.$value["attr_name"].'</OPTION>';
}
$Stroptaaid .= '</SELECT>';
/* 找到所有的属性到select end*/
//调查项显示
$vt_name = '';
if(!isset($work["arid"])) $work["arid"]=false;
if($work["arid"] > 0){
	if($work["vtid"] > 0){
		$sql = "SELECT vt_name FROM ".$pre."vote_title where vtid=".$work["vtid"];  
		$vt_name = $oPub->getOne($sql);
		$vt_name = '<span style="color:#f00;font-size:20px">[<a href="vote_title.php?vtid='.$work["vtid"].'&action=edit&arid='.$work["arid"].'" >网上关联调查：'.$vt_name.'</a>]</span>';
	}else{
		$vt_name = '<span style="color:#0c0;font-size:20px">[<a href="vote_title.php?arid='.$work["arid"].'">网上关联调查申请</a>]</span>';
	}
} 
?>
<?php
include_once( "header.php");
if (!empty($strMessage) ) echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>';
?> 
<table width="900" border="0" cellspacing="1" cellpadding="1" class="button">
  <TR class=bg1>
    <TD align=right >
	   <span style="float: right"> <a href="articlelist.php?<?PHP ECHO $http_var;?>"> [返回文章列表]</a></span>
	</TD> 
  </TR>
</table>
<form action="" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate();">
<TABLE width="900" border=0 cellspacing="0" cellpadding="0">
  <TR class=bg1>
    <TD align=left>
	     <b>分类选择:</b>
		 <?php echo $Stropt;?>
		 <b>属性:</b><?php echo $Stroptaaid;?>
		 <?php
		 
		 if(!isset($work["colors"])) $work["colors"]=false;
		 $Strcolorsopt = '<b>标题颜色:</b>';
         $Strcolorsopt .= '<SELECT NAME="colors">'; 
		 $Strcolorsopt .= '<OPTION VALUE=""  '.( (!empty($work["colors"]))?"SELECTED":"").'>默认</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#FF0000" style="color:#FF0000"'. ( ($work["colors"]=="#FF0000")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#00FF00" style="color:#00FF00"'. ( ($work["colors"]=="#00FF00")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#0000FF" style="color:#0000FF"'. ( ($work["colors"]=="#0000FF")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#000000" style="color:#000000"'. ( ($work["colors"]=="#000000")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#FF6600" style="color:#FF6600"'. ( ($work["colors"]=="#FF6600")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#33CC00" style="color:#33CC00"'. ( ($work["colors"]=="#33CC00")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#0066FF" style="color:#0066FF"'. ( ($work["colors"]=="#0066FF")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#CC3333" style="color:#CC3333"'. ( ($work["colors"]=="#CC3333")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#3399FF" style="color:#3399FF"'. ( ($work["colors"]=="#3399FF")?"SELECTED":"").'>■■■</OPTION>';
		 $Strcolorsopt .= '<OPTION VALUE="#CC6666" style="color:#CC6666"'. ( ($work["colors"]=="#CC6666")?"SELECTED":"").'>■■■</OPTION>';
         $Strcolorsopt  .= '</SELECT>';

		 $Strtopopt = '<b>置顶:</b>';
         $Strtopopt .= '<SELECT NAME="top">';
		 if(!isset($work["top"])) $work["top"]=false;
         $selected0 = ($work["top"]==0)?'selected':'';
		 $selected1 = ($work["top"]==1)?'selected':'';
         $Strtopopt .= '<OPTION VALUE="0" '.$selected0.' >否</OPTION>';
		 $Strtopopt .= '<OPTION VALUE="1" '.$selected1.' >是</OPTION>';
         $Strtopopt .= '</SELECT>';
		 echo $Strcolorsopt.$Strtopopt; 
 
		 ?>	
		 <b>文章时间:</b>

		 <input type="text" name="arti_date" value="<?php echo !empty($work["arid"])?$work["arti_date"]:date("Y-m-d H:i");?>" size="19"/>
         <br/><b style="color:#F00">文章标题:</b><input type="text" id="name" name="name" value="<?php echo (!empty($work["arid"]))?$work["name"]:'';?>" size="50"/>
		 <b>短标题:</b><input type="text" name="subname" value="<?php echo !empty($work["arid"])?$work["subname"]:'';?>" id="status" onkeydown='countChar("status","counter");' onkeyup='countChar("status","counter");'  size="30"/>输入<span id="counter">30</span>字
 
		 <br/><b>文章来源:</b><input type="text" name="sour" value="<?php echo !empty($work["arid"])?$work["sour"]:'';?>" />
		 <b>来源网址:</b><input type="text" name="sourhttp" value="<?php echo !empty($work["arid"])?$work["sourhttp"]:'';?>" size="46"/>

         <br/>
		 <b>文章缩图:</b>
		 <input type="file" name="arti_thumb"  style="width:150px"/>
		 缩图尺寸:宽<input type="text" name="img_width"  size="2" value="<?php echo $Aconf["big_thumb_w"];?>" />
		 高<input type="text" name="img_height"  size="2" value="<?php echo $Aconf["big_thumb_h"];?>"/>
		 <b>同时显示在图库</b>
		 <?php
		 if(!isset($work["ifpic"])) $work["ifpic"]=false;
		 ?>
		 <SELECT NAME="ifpic">
			<OPTION VALUE="0" <?php echo $work["ifpic"] < 1?'selected':'';?>>否</option>
			<OPTION VALUE="1" <?php echo $work["ifpic"] ==1?'selected':'';?>>是</option>
		 </SELECT>

		 <span id="arti_thumb_show">
         <?php 

		 if(!empty($work["arti_thumb"])) {
			 $tmp = '<A HREF="../'.$work["arti_thumb"].'" target="_blank">';
			 $tmp .= '<IMG SRC="images/icon_view.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="显示缩图"></A> ';
			 $tmp .= '<a href="javascript:;" onclick="if (confirm(\'删除\')) drop_artitxtImg(\''.$work["arid"].'\',\''.$work["arti_thumb"].'\')">';
			 $tmp .= '<IMG SRC="images/b_drop.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="删除缩图"></A> ';
		     $tmp .= '<input type="hidden" name="old_arti_thumb" value="'.$work["arti_thumb"].'" />';
			 $tmp .= '<input type="hidden" name="old_min_thumb" value="'.$work["min_thumb"].'" />';
		 } else {
             $tmp = '<input type="hidden" name="old_arti_thumb" value="" />';
			 $tmp .= '<input type="hidden" name="old_min_thumb" value="" />';
		 }
		 echo $tmp;
		 ?>
		 </span>
 
	</TD> 
  </TR>
 <tr class=bg1>
   <td>
	<b><span style="color:#7C7C7C">外部网址:</span></b><input type="text" name="otherurl" value="<?php echo ($work["arid"] > 0)?$work["otherurl"]:'';?>" size="50"/> 
   <br/><b>编辑点评:</b><TEXTAREA NAME="edit_comm" ROWS="2" COLS="16"><?php echo ($work["arid"] > 0)?$work["edit_comm"]:'';?></TEXTAREA>
   </td>
 </tr>
  <TR class=bg1>
    <TD align=left>
	 <b>正文:</b>  
	 <?php  
	if(!isset($work["descs"])) $work["descs"]='';
	 echo create_html_ck('descs',$work["descs"]); 
	 ?>  
    </TD> 
  </TR>
</TABLE>
<!-- 附件 start --> 
<DIV id=tabbar-div></DIV><!-- tab body -->
<TABLE id=gallery-table width="100%" align=center cellspacing="0" cellpadding="0">
 <tr>
   <td>
    文章相册：(<U>1.点“加号”可以批量上传多张图片；2.点提交按钮提交图片；3.单击相册列表中的缩图，可把原图添加到编辑器中</U>) 
     <div id="delimg_show" style="margin: 0">
    <?php
       while( @list( $k, $v ) = @each( $img_list) )
		{
    ?>
			<div id="gallery_<?php echo $v['fileid'];?>" style="float:left; text-align:center; border: 1px solid #DADADA; margin: 4px; padding:2px;">
			<a href="javascript:;" onclick="if(confirm('删除')) dropImg('<?php echo $v['fileid'];?>','<?php echo $v['arid'];?>')" title="删除">[-]</a>
			<a href="../<?php echo $v['filename'];?>" target="_blank" title="查看原信息:<?php echo $v['descs'];?>">[>]</a>  
			<br />                
			<?php if($v['thumb_url'] != '') { ?>
				 <img src="../<?php  echo $v['filename'];?>" width="120" height="90"  border="0" title="插入编辑器" onclick="InsertHTML('insert<?php echo  $v['fileid'];?>');" id="insert<?php echo $v['fileid'];?>" />
			<?php } else {?>
				 <div style="width:120;height:90"><br/><br/><a href="../<?php  echo $v['filename'];?>" target="_blank">查阅>></a></div>
			<?php }?>
				<br />
			<input type="text" value="<?php echo $v['descs'];?>" size="15" name="old_img_desc[<?php echo $v['fileid'];?>]" />
			</div>
   <?php
		}
	?>
	 </div>
    </TD> 
  </TR> 
  <TR>
	<TD>
	<A onclick=addImg(this) href="javascript:;">[+]</A> 
	图片描述:<INPUT TYPE="text" NAME=namedesc[] value="" size="60"/>
	地址:<INPUT type=file name=img_url[] id="fileToUpload" >
	</TD>
  </TR>
</TABLE>

  <!-- 附件 end -->
<TABLE width="100%" border=0 cellspacing="0" cellpadding="0">
  <TR>
    <TD align=left>
     <b>本文关键词(TAG)：</b>
	 <?php
	   $n = 0;
	   $strKeys = '';
       while( @list( $k, $v ) = @each($work["keys"]) ) {
         $strKeys .= '<input type="text" id="keys'.$n.'" name="keys['.$k.']" value="'.$v.'" size="8"> ';
		 $n ++;
      }
	  for($n;$n < 3;$n++ )
	  {
		  $x = 88888888 + $n;
		  $strKeys .= '<input type="text" id="keys'.$n.'" name="keys['.$x.']" value="" size="8"> ';
	  }
	  echo $strKeys;
     ?>
	 <span style="cursor:pointer;color: #CC0000" onmousedown="return check_cltion()">
			  (搜索关联文章)
	 </span>
 
	 <div id="cltion">
	 <?php echo $strCltion;?>
	 </div>
	 <div id="cltion_product">
	 <?php echo $strCltion_product;?>
	 </div>	
	 <div id="cltion_topic">
	 <?php echo $strCltion_topic;?>
	 </div>
    </TD> 
  </TR>

</table> 
<table width="100%" align=center cellspacing="0" cellpadding="0">
  <TR>
    <TD align=left>
	 <?php 
	if(!isset($work["states"])) $work["states"]=false;
	if(!isset($_REQUEST["sear_name"])) $_REQUEST["sear_name"]=false;
	if(!isset($_REQUEST["dateadd"])) $_REQUEST["dateadd"]=false;
	if(!isset($_REQUEST["end_time"])) $_REQUEST["end_time"]=false;
	if(!isset($_REQUEST["start_time"])) $_REQUEST["start_time"]=false;
	if(!isset($_REQUEST["sort_by"])) $_REQUEST["sort_by"]=false; 
	 if($work["states"] < 1) { ?>
       <input type="submit" value="<?php echo ($work["arid"] > 0)?'修改提交':'确认提交';?>" style="background-color: #FFCC66;margin-left: 50px;margin-top:10px;font-size: 14px" onclick="javascript:document.cookie='submit2=yes'"/>
	   <input type="hidden" name="arid" value="<?php echo ($work["arid"] > 0)?$work["arid"]:0;?>" id="arid" /> 
       <input type="hidden" name="act" value="<?php echo ($work["arid"] > 0)?'update':'insert';?>" />  
       <input type="hidden" name="states" value="<?php echo ($work["arid"] > 0)?$work["states"]:0;?>" />
	   <input type="hidden" name="sort_by" value="<?php echo $_REQUEST["sort_by"];?>" />
	   <input type="hidden" name="start_time" value="<?php echo $_REQUEST["start_time"];?>" />
	   <input type="hidden" name="end_time" value="<?php echo $_REQUEST["end_time"];?>" />
	   <input type="hidden" name="dateadd" value="<?php echo $_REQUEST["dateadd"];?>" />
	   <input type="hidden" name="sear_name" value="<?php echo $_REQUEST["sear_name"];?>" />
	<?php } ?>
    </TD> 
  </TR> 
  <TR>
	  <TD> <?php echo $vt_name;?> </TD>
  </TR>
 </table>
</form>
<SCRIPT src="js/tab.js" type="text/javascript"></SCRIPT>
<SCRIPT src="js/utils.js" type="text/javascript"></SCRIPT>	
<SCRIPT src="../js/ajax.js" type="text/javascript"></SCRIPT>
<!--以下的两个script为添加的ajax上传-->
<SCRIPT language=JavaScript> 
  function addImg(obj)
  {
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
  } 
  /**
   * ~{I>3}M<F,IO4+~}
   */
  function removeImg(obj)
  {
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');

      tbl.deleteRow(row);
  } 
  /**
   * ~{I>3}M<F,~}
   */
  function dropImg(fileid,arid)
  {
    obj = "delimg_show";
	var strTemp = "ajax_arti_delimg.php?fileid=" + fileid + "&arid=" + arid + "&op=delimg&action=edit"; 
	send_request(strTemp);	
  }
  function drop_artitxtImg(arid,arti_thumb_file)
  {
    obj = "arti_thumb_show";
	var strTemp = "ajax_arti_delimg.php?arid=" + arid + "&arti_thumb_file=" + arti_thumb_file;
	send_request(strTemp);	
  }

  function check_cltion()
  {
     obj = "cltion";
     var keys0 = document.getElementById("keys0").value;  
	 var keys1 = document.getElementById("keys1").value;
	 var keys2 = document.getElementById("keys2").value;
	 var arid = document.getElementById("arid").value;
	 
	 var strTemp = "ajax_check_cltion.php?keys0=" + escape(keys0) + "&keys1=" + escape(keys1) + "&keys2=" + escape(keys2) + "&arid=" + arid;
	 //alert(strTemp);
	 send_request(strTemp);
  }
  function check_cltion_product()
  {
     obj = "cltion_product";
     var keys0 = document.getElementById("keys0").value;  
	 var keys1 = document.getElementById("keys1").value;
	 var keys2 = document.getElementById("keys2").value;
	 
	 var strTemp = "ajax_check_cltion_product.php?keys0=" + escape(keys0) + "&keys1=" + escape(keys1) + "&keys2=" + escape(keys2);
	 //alert(strTemp);
	 send_request(strTemp);
  }
  function check_cltion_topic()
  {
     obj = "cltion_topic";
     var keys0 = document.getElementById("keys0").value;  
	 var keys1 = document.getElemen4tById("keys1").value;
	 var keys2 = document.getElementById("keys2").value;
	 
	 var strTemp = "ajax_check_cltion_topic.php?keys0=" + escape(keys0) + "&keys1=" + escape(keys1) + "&keys2=" + escape(keys2);
	 send_request(strTemp);
  }

   function list_help(a,b)
  {
	   obj = b; 
	   var strTemp = "help.php?value=" + a ;

	   send_request(strTemp);
  }

  function style_display(a)
  {   obj = a; 
       document.getElementById(obj).innerHTML="";
  }
   
	function countChar(textareaName,spanName) 
	{   
		document.getElementById(spanName).innerHTML =  document.getElementById(textareaName).value.length; 
	}   
	 
	 
	function InsertHTML(a)
	{
		var oEditor = CKEDITOR.instances.descs;
		//var value = document.getElementById( 'plainArea' ).value;
		//var value = document.getElementById( a ).innerHTML  
		var value = '<img src="' + document.images(a).src + '"/>';  
		if ( oEditor.mode == 'wysiwyg' )
		{
			// Insert the desired HTML.
			oEditor.insertHtml( value );
		}
		else
			alert( 'You must be on WYSIWYG mode!' );
	} 

	function validate()
	{
	  var frm          = document.forms['theForm'];
	  var name = document.getElementById("name").value;  

	  var msg = '';
	  var reg = null;

	  if( name.length < 4) {
		msg += '请输入文章标题' + '\n';
	  } 
	  if (msg.length > 0) {
		alert(msg);
		return false;
	  }  else
	  {
		return true;
	  }
	} 
</SCRIPT>
<?php

/* OPTION 递归 */
/* OPTION 递归 */
function get_next_node($next_node,$fid,$str = '　',$Aarticat = false)
{
   global $oPub,$pre,$_SESSION,$un_aaction_list;
   $db_table = $pre.'articat';
   $Agrad = explode(',',$next_node);
   $Stropt = '';
   if(count($Agrad) > 0 )
	{
	   $tn = 0;
	   $str .= '　';
	   while( @list( $k, $v ) = @each( $Agrad ) ) {
           if ($v == 0 && $v =='')
		   {
              break;
		   }		   
		   $sql = "SELECT * FROM ".$db_table." where acid = $v";
           $Anorm = $oPub->selectrow($sql);
		   if( $Anorm["name"] != ''){
			   $tn ++;
			   $selected = ($fid == $v)? 'SELECTED':'';
			   if(is_array($Aarticat)  && $_SESSION[$un_aaction_list] != 'all')
			   {
                  if(in_array($v,$Aarticat))
				   {
					  $tn ++;
                      $Stropt .=  '<OPTION VALUE="'.$v.'" '.$selected.'>'.$str.$tn.'）'.$Anorm["name"].'</OPTION>';
				   }
			   }
			   else
			   {
				   $tn ++;
		          $Stropt .=  '<OPTION VALUE="'.$v.'" '.$selected.'>'.$str.$tn.'）'.$Anorm["name"].'</OPTION>';
			   }

              $Stropt .= get_next_node($Anorm["next_node"],$fid,$str,$Aarticat);
		   }
		   
	   }
	}
	return $Stropt;
}
/* tbale 递归 */
function tab_next_node($next_node,$fid,$str = '　')
{
   global $oPub,$pre;
   $db_table = $pre.'articat';
   $Agrad = explode(',',$next_node);
   $Strtab = '';
   if(count($Agrad) > 0 )
	{
	   $tn = 0;
	   while( @list( $k, $v ) = @each( $Agrad ) ) {
           if ($v == 0 && $v =='')
		   {
              break;
		   }		   
		    $sql = "SELECT * FROM ".$db_table." where acid = $v";
            $Anorm = $oPub->selectrow($sql);
			if( $Anorm["name"] != ''){
			  $tn ++ ;
	          $tmpstr = ($n % 2 == 0)?"even":"odd";
              $Strtab  .= '<TR class='.$tmpstr.'>';

              $Strtab  .= '<TD align=left>'.$str.$tn.'）'.$Anorm["name"].'</TD>';
			  $Strtab  .= '<TD align=left>'.$Anorm["descs"].'</TD>';
			  $tmp = ($Anorm["ifshow"])?'是':'否';
			  $Strtab  .= '<TD align=left>'.$tmp.'</TD>';
	          $tmp = ($Anorm["ifnav"])?'是':'否';
	          $Strtab .= '<TD align=left>'.$tmp.'</TD>';
              $Strtab  .= '<TD align=left><a href="'.$_SERVER["PHP_SELF"].'?acid='.$v.'&fid='.$fid.'&action=edit"><IMG SRC="images/b_edit.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="[编辑]"></a> ';
	          $Strtab  .= '<a href="'.$_SERVER["PHP_SELF"].'?acid='.$v.'&fid='.$fid.'&action=del"><IMG SRC="images/b_drop.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="[删除]"></a></TD>';
              $Strtab  .= '</TR>';  
	          $n ++;
              $Strtab .= tab_next_node($Anorm["next_node"],$v,$str .= '　');
		      $str = '　';
			}
	   }
	}
	return $Strtab;
}
 ?>
<?php
include_once( "footer.php");
?>

