<?php
saxue_includedb();
class saxuearticleexpand extends saxueobjectdata {
		function saxuearticleexpand() {
				$this -> initvar( "eid", SAXUE_TYPE_INT, 0, "序号", false, 11 );
				$this -> initvar( "name", SAXUE_TYPE_TXTBOX, "", "属性名称", false, 30 );
				$this -> initvar( "title", SAXUE_TYPE_TXTBOX, "", "属性标题", false, 30 );
				$this -> initvar( "intro", SAXUE_TYPE_TXTBOX, "", "属性说明", false, 100 );
				$this -> initvar( "type", SAXUE_TYPE_INT, 0, "属性类型", false, 2 );
				$this -> initvar( "adminform", SAXUE_TYPE_TXTAREA, "", "后台表单模版", false, null );
				$this -> initvar( "userform", SAXUE_TYPE_TXTAREA, "", "前台表单模版", false, null );
				$this -> initvar( "options", SAXUE_TYPE_TXTAREA, "", "可用选项值", false, null );
				$this -> initvar( "listorder", SAXUE_TYPE_INT, 0, "排序", false, 10 );
				$this -> initvar( "required", SAXUE_TYPE_INT, 0, "是否必填", false, 1 );
				$this -> initvar( "cids", SAXUE_TYPE_TXTAREA, "", "应用于分类", false, null );
		} 
} 

class saxuearticleexpandhandler extends saxueobjecthandler {
		function saxuearticleexpandhandler( $_db = "" ) {
				$this -> saxueobjecthandler( $_db );
				$this -> basename = "articleexpand";
				$this -> autoid = "eid";
				$this -> dbname = "article_expand";
				$this -> type = array( 1 => 'Input文本框', 2 => 'Textarea多行文本框', 3 => '整数Input框', 4 => '数字Input框', 5 => '密码Input框', 6 => '隐藏Input框', 7 => 'Select选择框', 8 => 'Select多行选择框', 9 => 'Radio单选框', 10 => 'Checkbox多选框' );
		} 

		function type() {
				return $this -> type;
		}

		function adminform( $_row ) {
				if ( !isset( $_row['type'] ) || !isset( $this -> type[$_row['type']] ) ) {
						return '';
				}
				$_row['options'] = explode( ',', $_row['options'] );
				if ( !is_array( $_row['options'] ) ) {
						$_row['options'] = array();
				}
				$_form = '';
				switch ( $_row['type'] ) {
						case 1:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<input type="text" class="text" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" size="25" value="{?$expand.' . $_row['name'] . '?}" />&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 2:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<textarea class="textarea" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" rows="5" cols="60">{?$expand.' . $_row['name'] . '?}</textarea>&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 3:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<input type="text" class="text" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" size="25" value="{?$expand.' . $_row['name'] . '?}" onkeyup="value=value.replace(/[^0-9]/g,\'\');" />&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 4:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<input type="text" class="text" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" size="25" value="{?$expand.' . $_row['name'] . '?}" onkeyup="value=value.replace(/[^0-9\.]/g,\'\');" />&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 5:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<input type="password" class="text" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" size="25" value="{?$expand.' . $_row['name'] . '?}" />&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 6:
								$_form = '<input type="hidden" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" value="{?$expand.' . $_row['name'] . '?}" />';
								break;
						case 7:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<select class="select" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '">';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<option value="' . $v . '"{?if \'' . $v . '\'==$expand.' . $_row['name'] . '?} selected{?/if?}>' . $v . '</option>';
										}
								}
								$_form .= '</select>&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 8:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>
		<select multiple style="height:100px" class="select" name="expand[' . $_row['name'] . '][]" id="expand_' . $_row['name'] . '">';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<option value="' . $v . '" {?$expand[\'' . $_row['name'] . '\'][\'' . $v . '\'].selected?}>' . $v . '</option>';
										}
								}
								$_form .= '</select>&nbsp;
		<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 9:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<label><input class="radio" type="radio" name="expand[' . $_row['name'] . ']" value="' . $v . '"{?if \'' . $v . '\'==$expand.' . $_row['name'] . '?} checked{?/if?}>&nbsp;' . $v . '</label>&nbsp;&nbsp;';
										}
								}
								$_form .= '<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
						case 10:
								$_form = '<tr>
	<td class="tdleft">' . $_row['title'] . '：</td>
	<td>';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<label><input class="checkbox" type="checkbox" name="expand[' . $_row['name'] . '][]" value="' . $v . '" {?$expand[\'' . $_row['name'] . '\'][\'' . $v . '\'].checked?}>&nbsp;' . $v . '</label>&nbsp;&nbsp;';
										}
								}
								$_form .= '<span class="gray">' . $_row['intro'] . '</span>
	</td>
</tr>';
								break;
				}
				return $_form;
		}

		function userform( $_row ) {
				if ( !isset( $_row['type'] ) || !isset( $this -> type[$_row['type']] ) ) {
						return '';
				}
				$_row['options'] = explode( ',', $_row['options'] );
				if ( !is_array( $_row['options'] ) ) {
						$_row['options'] = array();
				}
				$_form = '';
				switch ( $_row['type'] ) {
						case 1:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<input name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" type="text" value="{?$expand.' . $_row['name'] . '?}" size="80" class="inptxt" />&nbsp;
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 2:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<textarea name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" style="width:600px;height:60px;" class="inptxt txt">{?$expand.' . $_row['name'] . '?}</textarea><br>
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 3:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<input name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" type="text" value="{?$expand.' . $_row['name'] . '?}" size="80" class="inptxt" onkeyup="value=value.replace(/[^0-9]/g,\'\');" />&nbsp;
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 4:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<input name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" type="text" value="{?$expand.' . $_row['name'] . '?}" size="80" class="inptxt" onkeyup="value=value.replace(/[^0-9\.]/g,\'\');" />&nbsp;
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 5:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<input name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" type="password" value="{?$expand.' . $_row['name'] . '?}" size="80" class="inptxt" />&nbsp;
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 6:
								$_form = '<input type="hidden" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" value="{?$expand.' . $_row['name'] . '?}" /';
								break;
						case 7:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<select name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" class="select">';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<option value="' . $v . '"{?if \'' . $v . '\'==$expand.' . $_row['name'] . '?} selected{?/if?}>' . $v . '</option>';
										}
								}
								$_form .= '</select>&nbsp;
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 8:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">
			<select multiple style="height:100px" name="expand[' . $_row['name'] . ']" id="expand_' . $_row['name'] . '" class="select">';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<option value="' . $v . '" {?$expand[\'' . $_row['name'] . '\'][\'' . $v . '\'].selected?}>' . $v . '</option>';
										}
								}
								$_form .= '</select>&nbsp;
			<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 9:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<label><input type="radio" name="expand[' . $_row['name'] . ']" value="' . $v . '"{?if \'' . $v . '\'==$expand.' . $_row['name'] . '?} checked{?/if?}>&nbsp;' . $v . '</label>&nbsp;&nbsp;';
										}
								}
								$_form .= '<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
						case 10:
								$_form = '<div class="m-sec">
	<div class="sub">' . $_row['title'] . ':</div>
	<div class="main main-2">
		<div class="inner">';
								if ( !empty( $_row['options'] ) ) {
										foreach ( $_row['options'] as $v ) {
												$_form .= '<label><input type="checkbox" name="expand[' . $_row['name'] . '][]" value="' . $v . '" {?$expand[\'' . $_row['name'] . '\'][\'' . $v . '\'].checked?}>&nbsp;' . $v . '</label>&nbsp;&nbsp;';
										}
								}
								$_form .= '<span class="gray">' . $_row['intro'] . '</span>
		</div>
	</div>
</div>';
								break;
				}
				return $_form;
		}
}