<?php
/**
 * @package iCMS
 * @copyright 2007-2010, iDreamSoft
 * @license http://www.idreamsoft.cn iDreamSoft
 * @author coolmoo <idreamsoft@qq.com>
 */
!defined('iPATH') && exit('What are you doing?'); 
iCMS_admincp_head();
?>
<div id="append_parent"></div>
<div id="default">
  <table class="tb tb2 nobdb" id="tips">
    <tr>
      <th colspan="15" class="partition"><span style="float:right;margin-top:4px;" class="close"><img src="admin/images/close.gif" /></span><span id="dtitle">预设</span></th>
    </tr>
    <tr>
      <td class="tipsblock" style="padding-left:5px;" id="defaultbody">
	 </td>
    </tr>
  </table>
</div>
<script type="text/javascript">admincpnav('首页&nbsp;&raquo;&nbsp;文章管理&nbsp;&raquo;&nbsp;<?=empty($id)?'添加':'编辑'?>文章');</script>
<link rel="stylesheet" href="admin/images/jquery.function.css" type="text/css" media="all" />
<script type="text/javascript" src="admin/js/jquery.function.js"></script>
<script type="text/javascript" src="admin/js/calendar.js"></script>
<script type="text/javascript">
var admincp='<?=__SELF__?>';
$(function(){
	$("#title").focus();
	$("#savearticle").submit(function(){
		if($("#catalog option:selected").attr("value")=="0"){
			$("a[tid=base]").click();
			alert("请选择所属栏目");
			$("#catalog").focus();
			return false;
		}
		if($("#title").val()==''){
			$("a[tid=base]").click();
			alert("标题不能为空!");
			$("#title").focus();
			return false;
		}
		if($("#url").val()==''){
			var oEditor = FCKeditorAPI.GetInstance('content') ;
			if(oEditor.GetXHTML( true )==''){
				$("a[tid=base]").click();
				alert("内容不能为空!");
				oEditor.Focus();
				return false;
			}
		}
		var rel=$("#related option");
		for (var i = 0; i < rel.length; i++) {
			$(rel[i]).attr("selected","selected");
		}
	}); 
	$("#keywordToTag").click( function(){
		$("#tag").toggle();
	}); 
<?php if($iCMS->config['keywordToTag']=="1" && !$id){?>
	$("#keywordToTag").click().attr("checked","checked");
	$("#tag").val("");
<?php }?>
	$("#navlist > li > a").click( function(){
		var that=this;
		$("#navlist > li > a").each(function(){
			this.id="";
			$("#"+$(this).attr("tid")).hide();
		});
		that.id="current";
		$("#"+$(that).attr("tid")).show();
	});
	$(".selectdefault").click(function(){
		var offset 		= $(this).offset();
		var snapTop 	= offset.top+25;
		var snapLeft 	= offset.left;
//		alert(snapTop+"-"+snapLeft);
		var def			= $("#default");
		var inid		=$(this).attr("to");
		if(inid=="pic"){
			$("#dtitle").html("选择");
			$("#defaultbody").empty().html($("#picmenu").html());
		}else{
			$.post("<?=__SELF__?>?do=ajax",{'action':inid},
			  function(data){
				$("#defaultbody").empty().html(data);
			  }
			); 
		}
		def.hide().addClass("selectdefaultdiv")
		.css({"top" : snapTop, "left" : snapLeft,"width":"120"})
		.slideDown("slow");
	});
	$(".close").click(function(){
	    $("#default").slideUp("slow");
	});
//	$("#pic").snap('value');
	$("#pic").dblclick( function () { showPic('pic'); }); 
});
function indefault(v,id){
	var val	=$("#"+id).val();
	if(val==""){
		val=v;
	}else{
		val+=" "+v;
	}
	$("#"+id).val(val);
}
function showPic(id){
	var picurl	=$("#"+id).val();
	if(picurl){
		var img=new Image();
		img.src=picurl;
		var width=img.width||580;
		var height=img.height||580;
		showDialog("<?=__SELF__?>?do=dialog&operation=showpic",picurl,width+20,height+20);
	}else{
		alert("没有图片!");
	}
//	$("#"+id).focus();
}
function cutPic(id){
	var picurl	=$("#"+id).val();
	if(picurl){
		showDialog("<?=__SELF__?>?do=dialog&operation=cutpic&pic="+picurl,id);
	}else{
		alert("没有图片!");
	}
//	$("#"+id).focus();
}
function editContentLink(fieldName){
	showDialog("<?=__SELF__?>?do=dialog&operation=article",fieldName,700,400,"yes");
}
</script>
<div class="container" id="cpcontainer">
  <h3><?=empty($id)?'添加':'编辑'?>文章</h3>
  <table class="tb tb2 nobdb" id="tips">
    <tr>
      <th colspan="15" class="partition">技巧提示</th>
    </tr>
    <tr>
      <td class="tipsblock"><ul id="tipslis">
          <li>点击ID可查看该文章</li>
          <li>清除链接功能会清除所有链接，慎用</li>
        </ul></td>
    </tr>
  </table>
  <form action="<?=__SELF__?>?do=article&operation=post" method="post" enctype="multipart/form-data" name="savearticle" id="savearticle">
    <input type="hidden" name="action" value="save" />
    <table class="tb tb2 ">
    <tr><td colspan="4">
	  <ul id="navlist">
	    <li><a id="current" href="javascript:void(0);" tid="base">基本信息</a></li>
	    <li><a href="javascript:void(0);" tid="publish">发布设置</a></li>
	  </ul>
    </td></tr>
    <tbody id="base">
      <tr>
        <td class="td27" style="width:50px;">栏目：</td>
        <td class="vtop rowform"><?php if($cata_option){?><select name="catalog" id="catalog" style="width:auto;">
          <option value="0"> == 请选择所属栏目 == </option>
          <?php echo $cata_option;}else{?><select name="catalog" id="catalog" onclick="redirect('<?=__SELF__?>?do=catalog&operation=add');">
          <option value="0"> == 暂无栏目请先添加 == </option>
          <?php }?>
        </select></td>
        <td class="td27" style="width:50px;">属性：</td>
        <td class="vtop rowform"><select name="type" id="type">
          <option value="0">普通文章[type='0']</option>
          <?=contentype("article",$rs['type'])?>
        </select>
        </td>
      </tr>
      <tr>
        <td class="td27" style="width:70px;">标题：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input type="text" name="title" class="txt" id="title" value="<?=$rs['title']?>" style="width:520px"/></td>
    </td>
      </tr>
      <tr>
        <td class="td27">短标题：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input name="stitle" class="txt" id="stitle" value="<?=$rs['stitle']?>"  style="width:520px" type="text"/></td>
      </tr>
      <tr>
        <td class="td27">出处：</td>
        <td class="vtop rowform"><input type="text" name="source" class="txt" id="source" value="<?=$rs['source']?>" style="width:200px" /> <button type="button" class="selectdefault" to="source"><span>预 设</span></button></td>
        <td class="td27">作者：</td>
        <td class="vtop rowform"><input type="text" name="author" class="txt" id="author" value="<?=$rs['author']?>" style="width:200px" /> <button type="button" class="selectdefault" to="author"><span>预 设</span></button></td>
      </tr>
      <tr>
        <td class="td27">编辑：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input name="editor" class="txt" type="text" id="editor" value="<?=$rs['editor']?>" /> <button type="button" class="selectdefault" to="editor"><span>预 设</span></button></td>
      </tr>
      <tr>
        <td class="td27">缩略图：</td>
        <td colspan="3" class="vtop rowform" style="width:auto">
          <input id="pic" name="pic" type="text" value="<?=$rs['pic']?>" class="txt" style="width:450px"/> <button type="button" class="selectdefault" to="pic"><span>选 择</span></button><div id="picmenu" style="display:none;">
<ul><li onClick="showDialog('<?=__SELF__?>?do=dialog&operation=Aupload','pic',600,140);$('.close').click();">本地上传</li><li onClick="showDialog('<?=__SELF__?>?do=dialog&operation=file&click=file&type=gif,jpg,png,bmp,jpeg','pic');$('.close').click();">从网站选择</li><li onClick="showPic('pic');$('.close').click();">查看缩略图</li><li onClick="cutPic('pic');$('.close').click();">剪裁</li></ul></div>
            </td>
      </tr>
      <tr>
        <td class="td27">副标题：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input name="subtitle" class="txt" id="subtitle" value="<?=$rs['subtitle']?>"  style="width:520px" type="text"/></td>
      </tr>
      <tr>
        <td class="td27">内容：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><span style="float:right;"><img src="<?=$iCMS->dir?>admin/images/add.gif" onclick="setEditorSize('+','content',200)" title="增加编辑器高度"/> <img src="<?=$iCMS->dir?>admin/images/desc.gif" onclick="setEditorSize('-','content',200)" title="减少编辑器高度"/></span><input name="remote" type="checkbox" class="checkbox" id="remote" value="1" <?php if($iCMS->config['remote']=="1")echo 'checked="checked"'?>/>下载远程图片
    	<input name="dellink" type="checkbox" id="dellink" value="1" class="checkbox"/>清除链接
        <input name="autopic" type="checkbox" class="checkbox" id="autopic" value="1" <?php if($iCMS->config['autopic']=="1")echo 'checked="checked"'?>/>提取第一个图片为缩略图 
        <input name="draft" type="checkbox" class="checkbox" id="draft" value="1" <?php if($rs['status']=="0")echo 'checked="checked"'?>/>存为草稿 </td>
      </tr>
      <tr class="nobg" id="editorHtml">
        <td colspan="4"><?=$editor->CreateHtml()?></td>
      </tr>
      <tr>
        <td class="td27">摘要：</td>
        <td colspan="3" class="vtop rowform"><textarea name="description" id="description" onKeyUp="textareasize(this)" class="tarea" style="width:520px"><?=$rs['description']?></textarea></td>
      </tr>
      <tr>
        <td class="td27">关键字：</td>
        <td colspan="3" class="vtop rowform"><input name="keywords" class="txt" type="text" id="keywords" value="<?=$rs['keywords']?>" style="width:520px"/> 多个关键字请用,格开</td>
      </tr>
      <tr>
        <td class="td27">标签：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input name="tag" class="txt" type="text" id="tag" style="width:520px" value="<?=$rs['tags']?>" /><input name="keywordToTag" type="checkbox" class="checkbox" id="keywordToTag" value="1" />
        将关键字转为标签<br />多个标签请用,格开</td>
      </tr>
      <tr>
        <td class="td27">相关文章：</td>
        <td><select id='related' name="related[]" size='10' style="width:100%" multiple="multiple"><?php 
        	if($rs['related']){
	        	$relRs=$iCMS->db->getArray("SELECT `id`, `title` FROM `#iCMS@__article` WHERE `id`IN (".$rs['related'].")");
	        	foreach($relRs AS $rel){
	        		$relatedArray[$rel['id']]=$rel['title'];
	        	}
	        	$relIds=explode(',',$rs['related']);
	        	foreach($relIds AS $relId){
	        		echo '<option value="'.$relId.'">'.$relatedArray[$relId].'</option>';
	        	}
        	}
        	
        	?></select>
</td>
<td colspan="2">
<input type="button" onclick="del(this.form.related)" value="×" tabindex="13" class="btn"/>
<br/>
<br/>
<input type="button" onclick="moveUp(this.form.related)" value="∧" tabindex="13" class="btn"/>
<br/>
<input type="button" onclick="moveDown(this.form.related)" value="∨" tabindex="13" class="btn"/>
<br/>
<br/>
<input type="button" onclick="editContentLink('related')" value="..." tabindex="13" class="btn"/>
</td>
      </tr>
      </tbody>
      <tbody id="publish" style="display:none;">
      <tr>
        <td style="width:70px;"></td>
        <td class="vtop rowform"></td>
        <td class="td27"></td>
        <td class="vtop rowform"></td>
    </td>
      <tr>
        <td class="td27">虚链接：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><select name="vlink[]" size="10" multiple="multiple" id="vlink">
          <?=$catalog->select(0,0,1,'channel=1&list&page','all')?>
        </select><script language="javascript" type="text/javascript"><?php if(strpos($rs['vlink'], ",")){?>var type='<?=$rs['vlink']?>';$('#vlink').val(type.split(','));<?php }else{?>$('#vlink').val(<?=(int)$rs['vlink']?>);<?php }?></script><br />按住Ctrl可多选    </td>
    </tr>
      <tr>
        <td class="td27">置顶权重：</td>
        <td colspan="3" class="vtop rowform"><input id="top" class="txt" value="<?=_int($rs['top'])?>" name="top" type="text"/></td>
      </tr>
      <tr>
        <td class="td27">发布时间：</td>
        <td colspan="3" class="vtop rowform"><input id="pubdate" class="txt" value="<?=$rs['pubdate']?>" name="pubdate" type="text" onclick="showcalendar(event, this)" style="width:208px"/></td>
      </tr>
      <tr>
        <td class="td27">模板：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input id="template" class="txt" value="<?=$rs['tpl']?>" name="template" type="text"/> <img src="admin/images/selecttpl.gif" width="67" height="19" align="absmiddle" onclick="showDialog('<?=__SELF__?>?do=dialog&operation=template&click=file&type=htm','template');"/></td>
      </tr>
      <tr>
        <td class="td27">自定链接：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input name="customlink" class="txt" type="text" id="customlink" value="<?=$rs['customlink']?>" />
        <br />
        只能由英文字母、数字或_-组成(不支持中文),留空则自动以标题拼音填充</td>
      </tr>
      <tr>
        <td class="td27">外部链接：</td>
        <td colspan="3" class="vtop rowform" style="width:auto"><input name="url" class="txt" type="text" id="url" size="50" value="<?=$rs['url']?>" /> 
        不填写请留空.</td>
      </tr>
       </tbody>
      <!--tr class="nobg"><td colspan="4">
		<table width="100%" cellspacing="0" cellpadding="0">
			<tr><th width="50%"><b>上传附件</b></th><th><b>描述</b></th></tr>
			<tbody id="attachbodyhidden" style="display:none"><tr><th><input type="file" name="attach[]" class="uploadbtn"/><span id="localfile[]"></span><input type="hidden" name="localid[]" /></th><th class="vtop rowform"><input type="text" name="attachdesc[]" class="txt" /></th></tr></tbody>
			<tbody id="attachbody"></tbody>
		</table>
		<div id="img_hidden" alt="1" style="position:absolute;top:-100000px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image');width:400px;height:300px"></div>
			</td></tr-->
      <tr class="nobg">
        <td colspan="4" align="center"><input name="aid" type="hidden" id="aid" value="<?=$id?>" />
         <input name="userid" type="hidden" id="userid" value="<?=$rs['userid']?>" />
         <input name="postype" type="hidden" id="postype" value="1" />
        <input name="action" type="hidden" id="action" value="save" />
        <input type="submit" value="提交" class="btn" />
        &nbsp;&nbsp;<input type="reset" value="重置" class="btn" /></td>
      </tr>
    </table>
  </form>
</div>
<!--
<script language="javascript" type="text/javascript">
var thumbwidth = parseInt(400);
var thumbheight = parseInt(300);
var extensions = '<?=$iCMS->config['fileext']?>';
lang['post_attachment_ext_notallowed']	= '对不起，不支持上传此类扩展名的附件。';
lang['post_attachment_img_invalid']	= '无效的图片文件。';
lang['post_attachment_deletelink']	= '删除';
lang['post_attachment_insert']		= '点击这里将本附件插入帖子内容中当前光标的位置';
lang['post_attachment_insertlink']	= '插入';
</script>
<script src="javascript/post_attach.js" type="text/javascript"></script>
-->
</body></html>