<?php
/********************************************************************
 *                              DirCMS表单类
 *                            ----------------------
 *   begin                : 2010-4-14
 *   update				  : 2010-11-27   //字段的权限配置
 *   copyright            : (C) 2009 DirCMS
 *   website              : http://www.dircms.net
 *
 *   $Id: form.class.php,v 1.0.0 2010-4-14 M Exp $
 ********************************************************************/

class form
{
	private $modelid;

	function __construct($modelid=0)
	{
		$this->modelid=$modelid;
	}

	function form($modelid) 
	{
		$this->__construct($modelid);
	}

	function get($defaultvalue=array()) // 基本选项
	{
		global $_groupid;
		$r=cache_read('cache_model'.$this->modelid.'.fields.cache.php',DIRCMS_ROOT.'data/cache_model/');
		$i=0;
		if($r)if(is_array($r))foreach($r as $v)
		{
			$priv=is_numeric($this->modelid)?explode(',',$v['privilege']):array(); //2010-11-27 
			if($v['isbase'] && (in_array($_groupid,$priv) ||$_groupid==1||!is_numeric($this->modelid)))
			{
				if($defaultvalue)$_defaultvalue=$defaultvalue[$v['name']];
				else $_defaultvalue=$v['defaultvalue'];

				if($v['createimage'] && $_defaultvalue && strpos($_defaultvalue,'dc_authcode.php?str='))
				{
					preg_match('/<img src=\"dc_authcode\.php\?str=([^\"]+)\"\s+\/>/i',trim($_defaultvalue),$tstr);
					$_defaultvalue=base64_decode(urldecode($tstr[1]));	
				}
				$info[$i]['name']=$v['fieldname'];
				$info[$i]['var']=$v['name'];
				$info[$i]['tips']=$v['tips'];
				$info[$i]['danwei']=$v['danwei'];
				$info[$i]['form']=$this->$v['formtype']($v['name'],htmlspecialchars($_defaultvalue),$v['js'],$v['css'],$v['preg'],$v['minsize'],$v['maxsize'],$v['editorwidth'],$v['editorheight'],$v['optionvalue']);
			}
			$i++;
		}
		return $info;
	}

	function getmore($defaultvalue=array()) // 高级选项
	{
		global $_groupid;
		$r=cache_read('cache_model'.$this->modelid.'.fields.cache.php',DIRCMS_ROOT.'data/cache_model/');
		$i=0;
		if($r)if(is_array($r))foreach($r as $v)
		{
			$priv=is_numeric($this->modelid)?explode(',',$v['privilege']):array(); //2010-11-27 
			if(!$v['isbase'] && (in_array($_groupid,$priv) ||$_groupid==1||!is_numeric($this->modelid)))
			{
				if($defaultvalue)$_defaultvalue=$defaultvalue[$v['name']];
				else $_defaultvalue=$v['defaultvalue'];

				if($v['createimage'] && $_defaultvalue && strpos($_defaultvalue,'dc_authcode.php?str='))
				{
					preg_match('/<img src=\"dc_authcode\.php\?str=([^\"]+)\"\s+\/>/i',trim($_defaultvalue),$tstr);
					
					$_defaultvalue=base64_decode(urldecode($tstr[1]));	
				}
				$info[$i]['name']=$v['fieldname'];
				$info[$i]['var']=$v['name'];
				$info[$i]['tips']=$v['tips'];
				$info[$i]['danwei']=$v['danwei'];
				$info[$i]['form']=$this->$v['formtype']($v['name'],htmlspecialchars($_defaultvalue),$v['js'],$v['css'],$v['preg'],$v['minsize'],$v['maxsize'],$v['editorwidth'],$v['editorheight'],$v['optionvalue']);
			}
			$i++;
		}
		return $info;
	}

	// Defined By System On 2010-5-14 Start!

	function sign($name='sign')
	{
		global $id,$db;
		$id=intval($id);
		$sql="SELECT COUNT(id) as num FROM `".DB_PRE."sign` WHERE `".DB_PRE."sign`.`contentid`=$id";
		$r=$db->fetch_one($sql);
		$num=$r?$r['num']:0;
		return '已报名人数'.$num.'人';
	}

	function catid($catid=0,$defaultvalue=0) //2010-11-28 
	{	
		$r=cache_read('finalcatid.cache.php',DIRCMS_ROOT.'data/cache_category/');
		$cateidselect='<select name="info[catid]" id="catid" onchange="loadcatid(this.value);">';
		if($defaultvalue && in_array($defaultvalue,$r))
		{
			$r=cache_read('category'.$defaultvalue.'.cache.php',DIRCMS_ROOT.'data/cache_category/');
			$cateidselect.='<option value='.$defaultvalue.' selected="selected">'.$r['categoryname'].'</option>';
		}
		else
		{
			$cateidselect.='<option value=0>选择栏目</option>';
		}
		$r=cache_read('parent'.$catid.'.cache.php',DIRCMS_ROOT.'data/cache_category/');
		if($r)foreach($r as $_r)
		{
			if($_r['isshow'] && !$_r['ispage'])
			{
				$isselect=$defaultvalue==$_r['id'] && !$defaultvalue?' selected="selected"':'';
				$cateidselect.='<option value='.$_r['id'].$isselect.'>'.$_r['categoryname'].'</option>';
			}
		}
		$cateidselect.='</select> <span id="catid_span"></span>';
		return $cateidselect;
	}

	function areaid($name='areaid',$defaultvalue=0)
	{		
		$areaid='<select name="info[areaid]" id="areaid" style="width:85px"><option value=0>请选择</option>';
		$r=cache_read('area.cache.php',DIRCMS_ROOT.'data/cache/');
		if($r)foreach($r as $_r)
		{
			$isselect=$defaultvalue==$_r['id']?' selected="selected"':'';
			$areaid.='<option value='.$_r['id'].$isselect.'>'.$_r['area'].'</option>';
		}
		$areaid.='</select>';
		return $areaid;
	}

	function title($name='title',$defaultvalue='')
	{	
		$defaultvalue=empty($defaultvalue)?'':'value="'.$defaultvalue.'"';
		return '<input type="text" name="info[title]" id="title" datatype="limit" min="1" max="160" size="50" '.$defaultvalue.' onblur="$.post(\''.SITE_URL.'keywords.inc.php\',{data:$(\'#title\').val()}, function(data){if(data)$(\'#keywords\').val(data);});" />';
	}

	function description($name='description',$defaultvalue='')
	{
		$len=$defaultvalue?(255-strlen($defaultvalue)):255;
		return '还可以输入 <font id="ls_description" color="#ff0000;">'.$len.'</font> 个字符！<br /><textarea class="input_textarea" name="info[description]" rows="4" cols="50"  datatype="limit" min="0" max="255" style="width:500px" onkeyup="javascript:var l=255-this.value.length*3;document.getElementById(\'ls_description\').innerHTML=l;if(l<1)this.value=this.value.substr(0,255);">'.$defaultvalue.'</textarea>';
	}

	function status($name='status',$defaultvalue=1)
	{
		$passchecked=$defaultvalue?' checked="checked"':'';
		$nopasschecked=!$defaultvalue?' checked="checked"':'';
		return '<label><input type="radio" name="info[status]" style="border:0px" value=1'.$passchecked.' />发布</label> <label><input type="radio" name="info[status]" style="border:0px" value=0 '.$nopasschecked.'>审核</label>';
	}

	function keyword($name='keywords',$defaultvalue='')
	{	
		$defaultvalue=empty($defaultvalue)?'':'value="'.$defaultvalue.'"';
		return '<input type="text" name="info[keywords]" id="keywords" datatype="limit" min="0" max="100" size="50" '.$defaultvalue.' />';
	}

	function downurl($name='downurl',$defaultvalue='')
	{
		$str='';
		if($defaultvalue)
		{
			$defaultvalue=explode("\n",$defaultvalue);
			foreach($defaultvalue as $_r)
			{
				if($_r)
				{
					$_v=explode('|',$_r);
					$str.='<input type="hidden" name="info['.$name.']"><input type="text" name="download_from_'.$name.'[]" value="'.$_v[0].'"> <input size="50" type="text" name="download_url_'.$name.'[]" value="'.$_v[1].'"> <input type="button" value="增加"  class="button" onclick="add_downurl_text'.$name.'()" /><br />';
				}
			}
			return '<script language="javascript">
		var downurli='.(sizeof($defaultvalue)+1).';
function add_downurl_text'.$name.'()
{
	if(downurli>20)
	{
		alert("不要超过20个链接!");
		return false;
	}
	$(\'#downurl_span_add'.$name.'\').append(\'<input type="text"  name="download_from_'.$name.'[]" value="下载地址\'+downurli+\'"> <input size="50" type="text" name="download_url_'.$name.'[]" value="http://"><br>\');
	downurli++;
}
</script>'.$str.'<span id="downurl_span_add'.$name.'"></span>';
		}
		else
		{
			return '<script language="javascript">
		var downurli=2;
function add_downurl_text'.$name.'()
{
	if(downurli>20)
	{
		alert("不要超过20个链接!");
		return false;
	}
	$(\'#downurl_span_add'.$name.'\').append(\'<input type="text"  name="download_from_'.$name.'[]" value="下载地址\'+downurli+\'"> <input size="50" type="text" name="download_url_'.$name.'[]" value="http://"><br>\');
	downurli++;
}
</script><input type="hidden" name="info['.$name.']"><input type="text" name="download_from_'.$name.'[]" value="下载地址1"> <input size="50" type="text" name="download_url_'.$name.'[]" value="http://"> <input type="button" value="增加" class="button" onclick="add_downurl_text'.$name.'()" /><br /><span id="downurl_span_add'.$name.'"></span>';
		}
	}

	function videourl($name='videourl',$defaultvalue='')
	{
		$str='';
		if($defaultvalue)
		{
			$defaultvalue=explode("\n",$defaultvalue);
			foreach($defaultvalue as $_r)
			{
				if($_r)
				{
					$_v=explode('|',$_r);
					$str.='<input type="hidden" name="info['.$name.']"><input type="text" name="video_from_'.$name.'[]" value="'.$_v[0].'"> <input size="50" type="text" name="video_url_'.$name.'[]" value="'.$_v[1].'"> <input type="button" value="增加" class="button" onclick="add_videourl_text'.$name.'()" /><br />';
				}
			}
			return '<script language="javascript">
		var videourli='.(sizeof($defaultvalue)+1).';
function add_videourl_text'.$name.'()
{
	if(videourli>20)
	{
		alert("不要超过20个地址!");
		return false;
	}
	$(\'#videourl_span_add'.$name.'\').append(\'<input type="text"  name="video_from_'.$name.'[]" value="观看地址\'+videourli+\'"> <input size="50" type="text" name="video_url_'.$name.'[]" value="http://"><br>\');
	videourli++;
}
</script>'.$str.'<span id="videourl_span_add'.$name.'"></span>';
		}
		else
		{
			return '<script language="javascript">
		var videourli=2;
function add_videourl_text'.$name.'()
{
	if(videourli>20)
	{
		alert("不要超过20个地址!");
		return false;
	}
	$(\'#videourl_span_add'.$name.'\').append(\'<input type="text"  name="video_from_'.$name.'[]" value="观看地址\'+videourli+\'"> <input size="50" style="height:20px" type="text" name="video_url_'.$name.'[]" value="http://"><br>\');
	videourli++;
}
</script><input type="hidden" name="info['.$name.']"><input type="text" name="video_from_'.$name.'[]" value="观看地址"> <input size="50" type="text" name="video_url_'.$name.'[]" value="http://"> <input type="button" value="增加" class="button" onclick="add_videourl_text'.$name.'()"/><br /><span id="videourl_span_add'.$name.'"></span>';
		}
	}

	function images($name='images',$defaultvalue='')
	{
		$str='';
		if($defaultvalue)
		{
			$defaultvalue=explode("\n",$defaultvalue);
			foreach($defaultvalue as $_r)
			{
				if($_r)
				{
					$_v=explode('|',$_r);
					$str.='<input type="hidden" name="info['.$name.']"><input type="hidden" value="'.$_v[1].'" name="old_images_file'.$name.'[]"><input type="text" name="old_images_name'.$name.'[]"  value="'.$_v[0].'"> <a href="'.$_v[1].'" target="_blank">'.basename($_v[1]).'</a> <input type="button" value="增加" onclick="add_imagesurl_text'.$name.'()"  class="button" /><br /><font color="#ff0000"> * 如需删除清空注释即可!</font><br />';
				}
			}
			return '<script language="javascript">
		var imagesli='.(sizeof($defaultvalue)+1).';
function add_imagesurl_text'.$name.'()
{
	if(imagesli>25)
	{
		alert("同时上传不要超过25张图片!");
		return false;
	}
	$(\'#imagesurl_span_add'.$name.'\').append(\'<input type="text"  name="images_name'.$name.'[]" value="图片\'+imagesli+\'注释"> <input size="20" type="file"  name="images_file'.$name.'[]"><br>\');
	imagesli++;
}
</script>'.$str.'<span id="imagesurl_span_add'.$name.'"></span>';
		}
		else
		{
			return '<script language="javascript">
		var imagesli=2;
function add_imagesurl_text'.$name.'()
{
	if(imagesli>25)
	{
		alert("同时上传不要超过25张图片!");
		return false;
	}
	$(\'#imagesurl_span_add'.$name.'\').append(\'<input type="text"  name="images_name'.$name.'[]"  value="图片\'+imagesli+\'注释"> <input size="20" type="file" accept= "image/*"  name="images_file'.$name.'[]"><br>\');
	imagesli++;
}
</script><input type="hidden" name="info['.$name.']"><input type="text" name="images_name'.$name.'[]" value="图片注释"> <input size="20" type="file" name="images_file'.$name.'[]" value="http://"> <input type="button" value="增加" class="button" onclick="add_imagesurl_text'.$name.'()" /><br /><span id="imagesurl_span_add'.$name.'"></span>';
		}
	}

	function typeid($defaultvalue='',$modelid=0) // 双参，根据模型的不同类型不同
	{
		$typeid='<select name="info[typeid]" id="typeid" style="width:85px"><option value=0>请选择</option>';
		$r=cache_read('type'.$modelid.'.cache.php',DIRCMS_ROOT.'data/cache/');
		if($r)foreach($r as $_r)
		{
			$isselect=$defaultvalue==$_r['id']?' selected="selected"':'';
			$typeid.='<option value='.$_r['id'].$isselect.'>'.$_r['name'].'</option>';
		}
		$typeid.='</select>';
		return $typeid;
	}

	function groupid($name='groupid',$defaultvalue='')
	{
		if($defaultvalue)
		{
			$defaultvalue=explode(',',$defaultvalue);
		}else
		{
			$defaultvalue=array();
		}
		$groupid='';
		$r=cache_read('membergrade.cache.php',DIRCMS_ROOT.'data/cache/');
		if($r)foreach($r as $_r)
		{
			$ischeck=in_array($_r['id'],$defaultvalue)?' checked ':'';
			$groupid.='<label><input type="checkbox" name="info[groupid][]"'.$ischeck.' style="border:0px" value='.$_r['id'].' />'.$_r['gradename'].'</label> ';
		}
		return $groupid;
	}

	function islink($defaultvalue='',$islink=0)
	{
		$defaultvalue=$islink?$defaultvalue:'';
		$islink=$islink?' checked ':'';
		$disabled=$islink?'':' disabled="disabled"';
		return '<label style="color:#ff0000"><input type="text" name="info[url]" value="'.$defaultvalue.'" id="url_2010rand" '.$disabled.' size="35" />&nbsp;&nbsp;<input type="checkbox" style="border:0px" name="info[islink]" '.$islink.' value=1 onclick="javascript:if(this.checked)document.getElementById(\'url_2010rand\').disabled=\'\';else document.getElementById(\'url_2010rand\').disabled=\'disabled\';" /> 转向链接<br />如果使用转向链接则点击标题就直接跳转而内容设置无效</label>';
	}
	
	function inputtime($name='inputtime',$defaultvalue='')
	{
		$defaultvalue=$defaultvalue?$defaultvalue:time();
		$defaultvalue=date('Y-m-d',$defaultvalue);
		return $this->_date('inputtime',$defaultvalue);
	}
	
	function style($name='style',$defaultvalue='')
	{
		if($defaultvalue)
		{
			$r=explode(';',$defaultvalue);
			$color=substr(strrchr($r[0],':'),1)?substr(strrchr($r[0],':'),1):'';
			$bold=substr(strrchr($r[1],':'),1)?substr(strrchr($r[1],':'),1):'';
			$isbold=$bold=='bold'?' checked ':'';
		}
		return '<select name="style_color1_id1"  id="style_color_id1" onchange="document.all.style_id1.value=\'color:\'+document.all.style_color1_id1.value;if(document.all.style_strong1_id1.checked)document.all.style_id1.value += \';font-weight:\'+document.all.style_strong1_id1.value;">
	<option value="">字体颜色</option>
	<option style="background-color:#000000;" value="#000000"></option>
	<option style="background-color:#333333;" value="#333333"></option>
	<option style="background-color:#660033;" value="#660033"></option>
	<option style="background-color:#0000FF;" value="#0000FF"></option>
	<option style="background-color:#FFCC00;" value="#FFCC00"></option>
	<option style="background-color:#0066cc;" value="#0066cc"></option>
	<option style="background-color:#cc0000;" value="#cc0000"></option>
	<option style="background-color:#FFFFFF;" value="#FFFFFF"></option>
	<option style="background-color:#FF0000;" value="#FF0000"></option>
	<option style="background-color:#00FF00;" value="#00FF00"></option>
</select>
<input type="checkbox" value="bold" '.$isbold.' style="border:0px" id="style_strong1_id1" name="style_strong1_id1"  onclick="document.all.style_id1.value=\'color:\'+document.all.style_color1_id1.value;if(document.all.style_strong1_id1.checked)document.all.style_id1.value += \';font-weight:\'+document.all.style_strong1_id1.value;"/>加粗显示 
<input type="hidden" name="info[style]" id="style_id1" value="'.$defaultvalue.'"><script>document.all.style_color1_id1.value="'.$color.'";</script>';
	}

	function thumb($name='thumb',$defaultvalue='')
	{
		global $catid;
		return '<input type="text" name=info[thumb] id="thumb" value="'.$defaultvalue.'" size="45" /> <input type="button" value="上 传" class="button" onclick="javascript:window.open(\''.DIRCMS_PATH.'upload.php?action=thumb&catid='.$catid.'\',\'upload\',\'width=600,height=300\');" />';

	}

	function point($name='point',$defaultvalue=0)
	{
		return '<input type="text" name="info[point]" size="4" id="info_content_point" datatype="number" value="'.$defaultvalue.'" />点';
	}

	function content_tlp($cateid=0,$defaultvalue='',$template='show')
	{
		$r=cache_read('category'.$cateid.'.cache.php',DIRCMS_ROOT.'data/cache_category/'); // 读取默认模板
		$defaultvalue=$defaultvalue?$defaultvalue:$r['contenttlp'];

		$r=cache_read('template.cache.php',TPL_ROOT.TPL_NAME.'/');
		$t='<select name="info[template]" style="z-index:0">';
		if($r)foreach($r as $tmp)
		{
			
			if(substr($tmp['template'],0,strlen($template))==$template)
			{
				$isselect=$defaultvalue==$tmp['template']?' selected="selected"':'';
				$t.='<option value="'.$tmp['template'].'"'.$isselect.'>'.$tmp['name'].'('.$tmp['template'].'.html)</option>';
			}
		}
		$t.='</select>';
		return $t;
	}

	function posid($name='posid',$defaultvalue=array())
	{
		global $db,$id,$_groupid;
		if($id)
		{
			$defaultvalue=array();
			$r=$db->fetch_all("SELECT posid FROM ".DB_PRE."content_posid WHERE contentid=".intval($id));
			if($r)foreach($r as $_r)
			{
				$defaultvalue[]=$_r['posid'];
			}
		}
		else
		{
			$defaultvalue=$defaultvalue?explode('/',$defaultvalue):array();
		}
		$posid='';
		$r=cache_read('posid.cache.php',DIRCMS_ROOT.'data/cache/');
		if($r)foreach($r as $_r)
		{
			$isselect=in_array($_r['id'],$defaultvalue)?' checked="checked"':'';
			$t.='<input type="checkbox" style="border:0px" name="info[posid][]" value="'.$_r['id'].'"'.$isselect.'>'.$_r['posname'].'&nbsp;';
		}
		if($_groupid==1)$t.=' <a href="'.ADMIN_FILE.'?file=posid&action=manage" target="_blank"><u>管理推荐位</u></a>';
		return $t;
	}

	// Defined By System On 2010-5-14 Over!

	function text($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50)
	{
		$defaultvalue=empty($defaultvalue)?'':'value="'.$defaultvalue.'"';
		$css=empty($css)?'':'class="'.$css.'"';
		$minsize=max(0,intval($minsize));
		$maxsize=min(255,intval($maxsize));
		return '<input type="text" name="info['.$name.']" datatype="'.$preg.'" min="'.$minsize.'" max="'.$maxsize.'" '.$css.' '.$js.' '.$defaultvalue.' />';
	}

	function password($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50)
	{
		$defaultvalue=empty($defaultvalue)?'':'value="'.$defaultvalue.'"';
		$css=empty($css)?'':'class="'.$css.'"';
		$minsize=max(0,intval($minsize));
		$maxsize=min(255,intval($maxsize));
		return '<input type="password" name="info['.$name.']" datatype="'.$preg.'" min="'.$minsize.'" max="'.$maxsize.'" '.$css.' '.$js.' '.$defaultvalue.' />';
	}

	function textarea($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50)
	{
		$css=empty($css)?'':' class="'.$css.'" ';
		return '<textarea name="info['.$name.']" '.$css.$js.'>'.$defaultvalue.'</textarea>';
	}

	function radio($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50,$width=500,$heigh=300,$optionvalue='')
	{
		$str='';
		$css=empty($css)?'':'class="'.$css.'"';
		$r=explode("\r\n",$optionvalue);
		foreach($r as $v)
		{
			$varray=explode("|",$v);
			$ischecked=$defaultvalue==$varray[0]?' checked="checked" ':'';
			$str.='<input type="radio" style="border:0px" value="'.$varray[0].'" name="info['.$name.']" '.$css.$ischecked.'>'.$varray[1].' &nbsp;';
		}
		return $str;
	}
	
	function checkbox($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50,$width=500,$heigh=300,$optionvalue='')
	{
		$str='';
		$css=empty($css)?'':' class="'.$css.'" ';
		$r=explode("\r\n",$optionvalue);
		$defaultvalue=explode('/',$defaultvalue);
		if($r)foreach($r as $v)
		{
			$varray=explode("|",$v);
			$ischecked=in_array($varray[0],$defaultvalue)?' checked="checked" ':'';
			$str.='<input type="checkbox" style="border:0px" value="'.$varray[0].'" style="border:0px" name="info['.$name.'][]" '.$css.$ischecked.'>'.$varray[1].' &nbsp;';
		}
		return $str;
	}

	function select($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50,$width=500,$heigh=300,$optionvalue='')
	{
		$css=empty($css)?'':' class="'.$css.'" ';
		$str='<select name="info['.$name.']" '.$css.$js.'>';	
		$r=explode("\r\n",$optionvalue);
		if($r)foreach($r as $v)
		{
			$varray=explode("|",$v);
			$ischecked=$defaultvalue==$varray[0]?' selected="selected"':'';
			$str.='<option value="'.$varray[0].'"'.$ischecked.'>'.$varray[1].'</option>';
		}
		$str.='</select>';
		return $str;
	}

	function _date($name='inputtime',$defaultvalue='')
	{
		$defaultvalue=$defaultvalue?$defaultvalue:date('Y-m-d');
		$date='<script language="javascript" src="'.DIRCMS_PATH.'images/js/calendar.js"></script><script>var c = new Calendar("c");document.write(c);</script>';
		$date.='<input name="info['.$name.']" value="'.$defaultvalue.'" style="height:20px; line-height:20px;padding-left:2px; width:95px;border:1px solid #D1D1D1;cursor:default" type="text" onfocus="c.showMoreDay = false;c.show(this);"/>';
		return $date;
	}

	function file($name,$defaultvalue='')
	{
		return '<input type="text" name=info['.$name.'] id="file_'.$name.'" value="'.$defaultvalue.'" size="45" /> <input type="button" class="button" value="上 传" onclick="javascript:window.open(\''.DIRCMS_PATH.'upload.php?objid=file_'.$name.'&action=files\',\'upload\',\'width=600,height=300\');" />';
	}

	function image($name,$defaultvalue='')
	{
		return '<input type="text" name=info['.$name.'] id="image_'.$name.'" value="'.$defaultvalue.'" size="45"/> <input type="button"  class="button" value="上 传" onclick="javascript:window.open(\''.DIRCMS_PATH.'upload.php?objid=image_'.$name.'&action=images\',\'upload\',\'width=600,height=300\');" />';
	}

	function editor($name,$defaultvalue='',$js='',$css='',$preg='limit',$minsize=0,$maxsize=50,$width=700,$heigh=300,$optionvalue='Standard')
	{
		if(!in_array($optionvalue,array('Standard','Basic')))$optionvalue='Basic';
		return '<script language="javascript" src="'.DIRCMS_PATH.'fckeditor/fckeditor.js"></script><textarea name="info['.$name.']" id="editor_'.$name.'" style="display:none">'.$defaultvalue.'</textarea>
			<script type="text/javascript" language="javascript">
				<!--
				var SiteUrl = "'.SITE_URL.'";
				var sBasePath = "'.SITE_URL.'"+"fckeditor/" ;			
				var oFCKeditor = new FCKeditor( "editor_'.$name.'" ) ;
				oFCKeditor.BasePath	= sBasePath ;
				oFCKeditor.ToolbarSet	="'.$optionvalue.'";
				oFCKeditor.Width	= '.$width.';
				oFCKeditor.Height	= '.$heigh.' ;
				oFCKeditor.ReplaceTextarea();
				//-->
			</script>';
	}


	function author($name='author',$defaultvalue='')
	{
		global $_groupid;
		$defaultvalue=empty($defaultvalue)?'':'value="'.$defaultvalue.'"';
		$author='<input type="text"  name="info['.$name.']" id="form_'.$name.'" size="20" '.$defaultvalue.' />&nbsp;&nbsp;<select onchange="document.getElementById(\'form_'.$name.'\').value=this.value"><option value="'.SITE_NAME.'">选择作者</option>';
		$r=cache_read('author.cache.php',DIRCMS_ROOT.'data/cache/');
		if($r)foreach($r as $_r)
		{
			$isselect=$defaultvalue==$_r['username']?' selected="selected"':'';
			$author.='<option value='.$_r['username'].' '.$isselect.'>'.$_r['username'].'</option>';
		}
		if($_groupid==1)
		{
			$author.='</select>&nbsp; <a href="'.ADMIN_FILE.'?file=author&action=manage" target="_blank"><u>管理作者</u></a>';
		}
		else
		{
			$author.='</select>';
		}
		return $author;
	}

	function map($name='map',$defaultvalue='')
	{
		$pos=$defaultvalue;
		$defaultvalue=empty($defaultvalue)?'':'value="'.$defaultvalue.'"';
		if($defaultvalue)
		{
			$xy=explode(',',$pos);
		}
		$map=MAPAPI.'地图经纬度：<input type="text" id="map_'.$name.'" name="info['.$name.']" size="20" '.$defaultvalue.' /> <input type="button" value="标注到'.MAPAPI.'地图" onclick="javascript:window.open(\''.DIRCMS_PATH.'api/map_api_'.MAPAPI.'.php?action=distancepole&x='.$xy[0].'&y='.$xy[1].'&id=map_'.$name.'\',\'upload\',\'width=600,height=500\');"  class="button"/>';
		return $map;
	}

	function vote($name='vote',$defaultvalue='')
	{
		global $db,$_groupid;
		$r=$db->fetch_all("SELECT * FROM `".DB_PRE."vote`");
		$vote='<select name="info['.$name.']"><option value="0">不加入投票</option>';

		if($r)foreach($r as $_r)
		{
			$isselect=$defaultvalue==$_r['id']?' selected="selected"':'';
			$vote.='<option value="'.$_r['id'].'" '.$isselect.'>'.$_r['votename'].'</option>';
		}
		if($_groupid==1)
		{
			$vote.='</select>&nbsp; <a href="'.ADMIN_FILE.'?file=other&action=vote" target="_blank"><u>投票管理</u></a>';
		}
		else
		{
			$vote.='</select>';
		}
		return $vote;
	}

	function copyfrom($name='copyfrom',$defaultvalue='')
	{
		global $_groupid;
		$defaultvalue=empty($defaultvalue)?'value="'.SITE_NAME.'"':'value="'.$defaultvalue.'"';
		$copyfrom='<input type="text"  name="info['.$name.']" id="'.$name.'" size="20" '.$defaultvalue.' />&nbsp;&nbsp;<select onchange="document.getElementById(\''.$name.'\').value=this.value"><option value="'.SITE_NAME.'">'.SITE_NAME.'</option>';
		$r=cache_read('copyfrom.cache.php',DIRCMS_ROOT.'data/cache/');
		if($r)foreach($r as $_r)
		{
			$isselect=$defaultvalue==$_r['copyfrom']?' selected="selected"':'';
			if(!$_r['url'])
			{
				$copyfrom.='<option value="'.$_r['copyfrom'].'" '.$isselect.'>'.$_r['copyfrom'].'</option>';
			}
			else
			{
				$copyfrom.='<option value="<a href='.$_r['url'].' target=_blank>'.$_r['copyfrom'].'</a>" '.$isselect.'>'.$_r['copyfrom'].'</option>';
			}
		}
		if($_groupid==1)
		{
			$copyfrom.='</select>&nbsp; <a href="'.ADMIN_FILE.'?file=copyfrom&action=manage" target="_blank"><u>管理稿件来源</u></a>';
		}
		else
		{
			$copyfrom.='</select>';
		}
		return $copyfrom;
	}
}
?>