<?php
define('IN_OUN', true);
include_once( "includes/command.php");
include_once(ROOT_PATH . 'class/cls_image.php');
$image = new cls_image($_CFG['bgcolor']);
include_once(ROOT_PATH.'includes/ckeditor/ckeditor.php');

if($Aconf['priveMessage'] != '')
{
   echo showMessage($Aconf['priveMessage']);
   exit;
}

$db_table = $pre."sysconfig";
if( $_POST['action'] == 'edit' && $_POST['scid'] > 0){ 
		$sql = "UPDATE " . $db_table . " SET  notices='$_POST[notices]' WHERE  scid=".$_SESSION[$un_domain_id];
		$oPub->query($sql); 
		/* 处理相册图片 */
		/* 编辑图片描述 old_img_desc */
		if (isset($_POST['old_img_desc']))
		{
			foreach ($_POST['old_img_desc'] AS $key => $val)
		   {
				$sql = "UPDATE " . $pre."arti_file SET `descs` = '$val' WHERE `fileid` =".$key;
				$oPub->query($sql);              
		   }
		}
		$type='notices';$arid =$_SESSION[$un_domain_id];
		handle_gallery_image($arid, $_FILES[img_url], $_POST['namedesc'],$type); 
		$strMessage = '公告编辑成功'; 
}
/* 网站配置信息 */
 
$sql = "SELECT scid,notices FROM ".$pre."sysconfig WHERE scid = ".$_SESSION[$un_domain_id]." ORDER BY scid ASC LIMIT 1";
$Anorm = $oPub->selectrow($sql);  
$sql = "SELECT * FROM " . $pre."arti_file WHERE type = 'notices' and arid=".$_SESSION[$un_domain_id];
$img_list = $oPub->select($sql);
?>
<?php
	include_once( "header.php");
	if ($strMessage != '') {
		 echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>';
	}
?>
<DIV class=content>
  <form name="form1" method="post" action="" enctype="multipart/form-data" style="margin: 0px">
<TABLE width="800" border=0>
  <TR > 
    <TD width="800" align="left" >
		 <?php echo create_html_ck('notices',$Anorm['notices']); ?>  
    </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>
  <tr>
  <td>
 		<input type="hidden" name="action" value="<?php echo ($Anorm['scid'])?'edit':'add';?>" />
        <input type="submit" name="Submit" value="<?php echo ($Anorm['scid'])?'公告编辑提交':'增加';?>" style="background-color: #FFCC66"/>
		<input type="hidden" name="scid" value="<?php echo ($Anorm['scid'])?$Anorm['scid']:'0';?>" />  
  </td>
  </tr>
</TABLE> 
</form>
  <!-- 附件 end --> 
</DIV>
<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>
//<![CDATA[ 
  function addImg(obj)
  {
	  id="fileid"+document.getElementsByTagName('input').length;
	  iid=document.getElementsByTagName('input').length+1;
	  kid="imgid"+iid;
      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 +  "&op=delimg&action=notices";  
	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.notices; 
	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!' );
}  
//]]> 
</SCRIPT>
<?php 
include_once( "footer.php");
?>
