您的位置:首页 > 数据库

动态生成页面,页面所有属性均来自数据库

2011-03-12 19:20 295 查看
function _getInputType( &$row,$val) {

$type = $row['input_type'];
$html = '';
switch ($type) {
case 'Input':
// $html.='
$html .= '<span><input type="text" name="'. $row['name'].'" id="'. $row['name'].'" value="'
.($val==''?$row['default_value']:$val).'" class="textinput" size="30" ></span>';
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
break;
case 'Select':
$opts = explode(';', $row['enum_values']);
$html .= '<select name="'. $row['name'].'" id="'. $row['name'].'">';
foreach($opts as $v) {
$tmp=explode(':',$v);
$html .='<option value="'.$tmp[0].'"'.(($val==''?$row['default_value']:$val)==$tmp[0]?'selected':'').
'>'.$tmp[1].'</option>';
}
$html .= '</select>';
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
break;
case 'CheckBox':
$opts = explode(';', $row['enum_values']);
foreach($opts as $v) {
$tmp=explode(':',$v);
$html .= '<span><input type="checkbox" name="'. $row['name'].'[]"'.
'" value="'. $tmp[0].'"'.(($val==''?$row['default_value']:$val)==$tmp[0]?'checked':'').
'>'.$tmp[1].'</span>';
}
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
break;
case 'Radio':
$opts = explode(';', $row['enum_values']);
foreach($opts as $v) {
$tmp=explode(':',$v);
$html .= '<span><input type="radio" name="'. $row['name'].'[]"'.
'" value="'. $tmp[0].'"'.(($val==''?$row['default_value']:$val)==$tmp[0]?'checked':'').'>'
.$tmp[1].'</span>';
}
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
break;
case 'File':
$html = '<span><input type="file" name="'. $row['name'].'" id="'. $row['name'].'" value="'
.($val==''?$row['default_value']:$val).'"   ></span>';
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
break;
case 'Textarea':
$html .= '<textarea type="text" name="'. $row['name'].'" id="'. $row['name'].'" value="'
.($val==''?$row['default_value']:$val).'" class="textareabox" cols="60" rows="10" >';
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
break;
case 'Hidden':
$html .= '<input type="hidden" name="'. $row['name'].'" value="'.($val==''?$row['default_value']:$val).'">';
break;
DEFAULT :
$html .= '<span><input type="text" name="'. $row['name'].'" id="'. $row['name'].'" value="'
.($val==''?$row['default_value']:$val).'" class="textinput" size="30" ></span>';
if(!empty($row['comments'])) {
$html .=  '<div class="listrows tips"><label> </label><span>'.
$row['comments'].'</span></div>';
}
}
return $html;
}


动态生成输入页面。支持多种输入框

<?   function _checkFile(&$file) {
$allowable = array ( 'bmp', 'csv','doc','jepg','gif','ico','jpg',
'pdf', 'png', 'ppt', 'txt','xcf','xls' );

if (!isset($file) ||! is_array($file)) {
return '参数错误';
}

$format = $this->_getExt($file['name']);
if(! in_array($format, $allowable) ) {
return '不允许上传此文件类型!';
}
}
function _getExt($file,$sp='.') {
$chunks = explode($sp, $file);
$chunksCount = count($chunks) - 1;

if($chunksCount > 0) {
return $chunks[$chunksCount];
}
return false;
}

function _upload($upFile,$path,$filename) {
$file    = $_FILES[$upFile];
$msg='';
$msg=$this->_checkFile($file);
if(!empty($msg)) {
return $msg;
}
if (!move_uploaded_file($file['tmp_name'], $path.DS.$filename)) {
return '文件上传失败!';
} else {
return '';
}
}
?>


上传文件的时候,文件类型检查
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐