showformheader()创建表单头
showformfooter()创建表单尾
showsubmit()创建表单提交按钮
showsetting()创建表单输入框
showtableheader()创建表格头
showformfooter()创建表格尾
showsubmenu()创建二级导航栏
shownav()创建面包屑导航栏
showtips()创建提示信息
showtablerow()创建列表式页面的行
showformheader()创建表单头
showformheader($action,$extra,$name,$method);
参数:
$action - 表单action的一部分,程序会自动添加 admincp.php?action= 这些内容 $extra - 表单附加属性,可以是样式等 $name - 表单的name和id $method - 表单提交方式 showformfooter()创建表单尾 showformfooter(); showsubmit()创建表单提交按钮 showsubmit($name,$value,$before,$after,$floatright,$entersubmit);
参数:
$name - 定义提交按钮的name值 $value - 定义按钮的文字值 $before - 根据此按钮之前的属性来输出样式 $after - 根据此按钮之后的属性来输出样式 $floatright - 是否有浮动 $entersubmit - 是否使用回车定义按钮提交动作 showsetting()创建表单输入框
定义文件:\source\function\function_admincp.php
function showsetting($setname, $varname, $value, $type = 'radio', $disabled = '', $hidden = 0, $comment = '', $extra = '', $setid = '', $nofaq = false) { global $_G; $s = "\n"; $check = array(); $noborder = false; if(substr($disabled, 0, 8) == 'noborder') { $disabled = trim(substr($disabled, 8)); $noborder = 'class="noborder" '; } $check['disabled'] = $disabled ? ($disabled == 'readonly' ? ' readonly' : ' disabled') : ''; $check['disabledaltstyle'] = $disabled ? ', 1' : ''; $nocomment = false; if(isset($_G['showsetting_multi'])) { $hidden = 0; if(is_array($varname)) { $varnameid = '_'.str_replace(array('[', ']'), '_', $varname[0]).'|'.$_G['showsetting_multi']; $varname[0] = preg_replace('/\w+new/', 'multinew['.$_G['showsetting_multi'].'][\\0]', $varname[0]); } else { $varnameid = '_'.str_replace(array('[', ']'), '_', $varname).'|'.$_G['showsetting_multi']; $varname = preg_replace('/\w+new/', 'multinew['.$_G['showsetting_multi'].'][\\0]', $varname); } } else { $varnameid = ''; } if($type == 'radio') { $value ? $check['true'] = "checked" : $check['false'] = "checked"; $value ? $check['false'] = '' : $check['true'] = ''; $check['hidden1'] = $hidden ? ' οnclick="$(\'hidden_'.$setname.'\').style.display = \'\';"' : ''; $check['hidden0'] = $hidden ? ' οnclick="$(\'hidden_'.$setname.'\').style.display = \'none\';"' : ''; $onclick = $disabled && $disabled == 'readonly' ? ' οnclick="return false"' : ($extra ? $extra : ''); $s .= '<ul οnmοuseοver="altStyle(this'.$check['disabledaltstyle'].');">'. '<li'.($check['true'] ? ' class="checked"' : '').'><input class="radio" type="radio"'.($varnameid ? ' id="_v1_'.$varnameid.'"' : '').' name="'.$varname.'" value="1" '.$check['true'].$check['hidden1'].$check['disabled'].$onclick.'> '.cplang('yes').'</li>'. '<li'.($check['false'] ? ' class="checked"' : '').'><input class="radio" type="radio"'.($varnameid ? ' id="_v0_'.$varnameid.'"' : '').' name="'.$varname.'" value="0" '.$check['false'].$check['hidden0'].$check['disabled'].$onclick.'> '.cplang('no').'</li>'. '</ul>'; } elseif($type == 'text' || $type == 'password' || $type == 'number') { $s .= '<input name="'.$varname.'" value="'.dhtmlspecialchars($value).'" type="'.$type.'" class="txt" '.$check['disabled'].' '.$extra.' />'; } elseif($type == 'htmltext') { $id .= 'html'.random(2); $s .= '<div id="'.$id.'">'.$value.'</div><input id="'.$id.'_v" name="'.$varname.'" value="'.dhtmlspecialchars($value).'" type="hidden" /><script type="text/javascript">sethtml(\''.$id.'\')</script>'; } elseif($type == 'file') { $s .= '<input name="'.$varname.'" value="" type="file" class="txt uploadbtn marginbot" '.$check['disabled'].' '.$extra.' />'; } elseif($type == 'filetext') { $defaulttype = $value ? 1 : 0; $id = 'file'.random(2); $s .= '<input id="'.$id.'_0" style="display:'.($defaulttype ? 'none' : '').'" name="'.($defaulttype ? 'TMP' : '').$varname.'" value="" type="file" class="txt uploadbtn marginbot" '.$check['disabled'].' '.$extra.' />'. '<input id="'.$id.'_1" style="display:'.(!$defaulttype ? 'none' : '').'" name="'.(!$defaulttype ? 'TMP' : '').$varname.'" value="'.dhtmlspecialchars($value).'" type="text" class="txt marginbot" '.$extra.' /><br />'. '<a id="'.$id.'_0a" style="'.(!$defaulttype ? 'font-weight:bold' : '').'" href="javascript:;" οnclick="$(\''.$id.'_1a\').style.fontWeight = \'\';this.style.fontWeight = \'bold\';$(\''.$id.'_1\').name = \'TMP'.$varname.'\';$(\''.$id.'_0\').name = \''.$varname.'\';$(\''.$id.'_0\').style.display = \'\';$(\''.$id.'_1\').style.display = \'none\'">'.cplang('switch_upload').'</a> '. '<a id="'.$id.'_1a" style="'.($defaulttype ? 'font-weight:bold' : '').'" href="javascript:;" οnclick="$(\''.$id.'_0a\').style.fontWeight = \'\';this.style.fontWeight = \'bold\';$(\''.$id.'_0\').name = \'TMP'.$varname.'\';$(\''.$id.'_1\').name = \''.$varname.'\';$(\''.$id.'_1\').style.display = \'\';$(\''.$id.'_0\').style.display = \'none\'">'.cplang('switch_url').'</a>'; } elseif($type == 'textarea') { $readonly = $disabled ? 'readonly' : ''; $s .= "<textarea $readonly rows=\"6\" ".(!isset($_G['showsetting_multi']) ? "οndblclick=\"textareasize(this, 1)\"" : '')." οnkeyup=\"textareasize(this, 0)\" οnkeydοwn=\"textareakey(this, event)\" name=\"$varname\" id=\"$varname\" cols=\"50\" class=\"tarea\" $extra>".dhtmlspecialchars($value)."</textarea>"; } elseif($type == 'select') { $s .= '<select name="'.$varname[0].'" '.$extra.'>'; foreach($varname[1] as $option) { if(!array_key_exists(0, $option)) { $option = array_values($option); } $selected = $option[0] == $value ? 'selected="selected"' : ''; if(empty($option[2])) { $s .= "<option value=\"$option[0]\" $selected>".$option[1]."</option>\n"; } else { $s .= "<optgroup label=\"".$option[1]."\"></optgroup>\n"; } } $s .= '</select>'; } elseif($type == 'mradio' || $type == 'mradio2') { $nocomment = $type == 'mradio2' && !isset($_G['showsetting_multi']) ? true : false; $addstyle = $nocomment ? ' style="float: left; width: 18%"' : ''; $ulstyle = $nocomment ? ' style="width: 790px"' : ''; if(is_array($varname)) { $radiocheck = array($value => ' checked'); $s .= '<ul'.(empty($varname[2]) ? ' class="nofloat"' : '').' οnmοuseοver="altStyle(this'.$check['disabledaltstyle'].');"'.$ulstyle.'>'; foreach($varname[1] as $varary) { if(is_array($varary) && !empty($varary)) { if(!array_key_exists(0, $varary)) { $varary = array_values($varary); } $onclick = ''; if(!isset($_G['showsetting_multi']) && !empty($varary[2])) { foreach($varary[2] as $ctrlid => $display) { $onclick .= '$(\''.$ctrlid.'\').style.display = \''.$display.'\';'; } } $onclick && $onclick = ' οnclick="'.$onclick.'"'; $s .= '<li'.($radiocheck[$varary[0]] ? ' class="checked"' : '').$addstyle.'><input class="radio" type="radio"'.($varnameid ? ' id="_v'.md5($varary[0]).'_'.$varnameid.'"' : '').' name="'.$varname[0].'" value="'.$varary[0].'"'.$radiocheck[$varary[0]].$check['disabled'].$onclick.'> '.$varary[1].'</li>'; } } $s .= '</ul>'; } } elseif($type == 'mcheckbox' || $type == 'mcheckbox2') { $nocomment = $type != 'mcheckbox2' && count($varname[1]) > 3 && !isset($_G['showsetting_multi']) ? true : false; $addstyle = $nocomment ? ' style="float: left;'.(empty($_G['showsetting_multirow']) ? ' width: 18%;overflow: hidden;' : '').'"' : ''; $ulstyle = $nocomment && empty($_G['showsetting_multirow']) ? ' style="width: 790px"' : ''; $s .= '<ul class="nofloat" οnmοuseοver="altStyle(this'.$check['disabledaltstyle'].');"'.$ulstyle.'>'; foreach($varname[1] as $varary) { if(is_array($varary) && !empty($varary)) { if(!array_key_exists(0, $varary)) { $varary = array_values($varary); } $onclick = !isset($_G['showsetting_multi']) && !empty($varary[2]) ? ' οnclick="$(\''.$varary[2].'\').style.display = $(\''.$varary[2].'\').style.display == \'none\' ? \'\' : \'none\';"' : ''; $checked = is_array($value) && in_array($varary[0], $value) ? ' checked' : ''; $s .= '<li'.($checked ? ' class="checked"' : '').$addstyle.' title="'.dhtmlspecialchars($varary[1]).'"><input class="checkbox" type="checkbox"'.($varnameid ? ' id="_v'.md5($varary[0]).'_'.$varnameid.'"' : '').' name="'.$varname[0].'[]" value="'.$varary[0].'"'.$checked.$check['disabled'].$onclick.'> '.$varary[1].'</li>'; } } $s .= '</ul>'; } elseif($type == 'binmcheckbox') { $checkboxs = count($varname[1]); $value = sprintf('%0'.$checkboxs.'b', $value);$i = 1; $s .= '<ul class="nofloat" οnmοuseοver="altStyle(this'.$check['disabledaltstyle'].');">'; foreach($varname[1] as $key => $var) { if($var !== false) { $s .= '<li'.($value{$checkboxs - $i} ? ' class="checked"' : '').'><input class="checkbox" type="checkbox"'.($varnameid ? ' id="_v'.md5($i).'_'.$varnameid.'"' : '').' name="'.$varname[0].'['.$i.']" value="1"'.($value{$checkboxs - $i} ? ' checked' : '').' '.(!empty($varname[2][$key]) ? $varname[2][$key] : '').'> '.$var.'</li>'; } $i++; } $s .= '</ul>'; } elseif($type == 'omcheckbox') { $nocomment = count($varname[1]) > 3 ? true : false; $addstyle = $nocomment ? 'style="float: left; width: 18%"' : ''; $ulstyle = $nocomment ? 'style="width: 790px"' : ''; $s .= '<ul οnmοuseοver="altStyle(this'.$check['disabledaltstyle'].');"'.(empty($varname[2]) ? ' class="nofloat"' : 'class="ckbox"').' '.$ulstyle.'>'; foreach($varname[1] as $varary) { if(is_array($varary) && !empty($varary)) { $checked = is_array($value) && $value[$varary[0]] ? ' checked' : ''; $s .= '<li'.($checked ? ' class="checked"' : '').' '.$addstyle.'><input class="checkbox" type="checkbox" name="'.$varname[0].'['.$varary[0].']" value="'.$varary[2].'"'.$checked.$check['disabled'].'> '.$varary[1].'</li>'; } } $s .= '</ul>'; } elseif($type == 'mselect') { $s .= '<select name="'.$varname[0].'" multiple="multiple" size="10" '.$extra.'>'; foreach($varname[1] as $option) { if(!array_key_exists(0, $option)) { $option = array_values($option); } $selected = is_array($value) && in_array($option[0], $value) ? 'selected="selected"' : ''; if(empty($option[2])) { $s .= "<option value=\"$option[0]\" $selected>".$option[1]."</option>\n"; } else { $s .= "<optgroup label=\"".$option[1]."\"></optgroup>\n"; } } $s .= '</select>'; } elseif($type == 'color') { global $stylestuff; $preview_varname = str_replace('[', '_', str_replace(']', '', $varname)); $code = explode(' ', $value); $css = ''; for($i = 0; $i <= 1; $i++) { if($code[$i] != '') { if($code[$i]{0} == '#') { $css .= strtoupper($code[$i]).' '; } elseif(preg_match('/^http:\/\//i', $code[$i])) { $css .= 'url(\''.$code[$i].'\') '; } else { $css .= 'url(\''.$stylestuff['imgdir']['subst'].'/'.$code[$i].'\') '; } } } $background = trim($css); $colorid = ++$GLOBALS['coloridcount']; $s .= "<input id=\"c{$colorid}_v\" type=\"text\" class=\"txt\" style=\"float:left; width:210px;\" value=\"$value\" name=\"$varname\" οnchange=\"updatecolorpreview('c{$colorid}')\">\n". "<input id=\"c$colorid\" οnclick=\"c{$colorid}_frame.location='static/image/admincp/getcolor.htm?c{$colorid}|c{$colorid}_v';showMenu({'ctrlid':'c$colorid'})\" type=\"button\" class=\"colorwd\" value=\"\" style=\"background: $background\"><span id=\"c{$colorid}_menu\" style=\"display: none\"><iframe name=\"c{$colorid}_frame\" src=\"\" frameborder=\"0\" width=\"210\" height=\"148\" scrolling=\"no\"></iframe></span>\n$extra"; } elseif($type == 'calendar') { $s .= "<input type=\"text\" class=\"txt\" name=\"$varname\" value=\"".dhtmlspecialchars($value)."\" οnclick=\"showcalendar(event, this".($extra ? ', 1' : '').")\">\n"; } elseif(in_array($type, array('multiply', 'range', 'daterange'))) { $onclick = $type == 'daterange' ? ' οnclick="showcalendar(event, this)"' : ''; if(isset($_G['showsetting_multi'])) { $varname[1] = preg_replace('/\w+new/', 'multinew['.$_G['showsetting_multi'].'][\\0]', $varname[1]); } $s .= "<input type=\"text\" class=\"txt\" name=\"$varname[0]\" value=\"".dhtmlspecialchars($value[0])."\" style=\"width: 108px; margin-right: 5px;\"$onclick>".($type == 'multiply' ? ' X ' : ' -- ')."<input type=\"text\" class=\"txt\" name=\"$varname[1]\" value=\"".dhtmlspecialchars($value[1])."\"class=\"txt\" style=\"width: 108px; margin-left: 5px;\"$onclick>"; } else { $s .= $type; } $name = cplang($setname); $name .= $name && substr($name, -1) != ':' ? ':' : ''; $name = $disabled ? '<span class="lightfont">'.$name.'</span>' : $name; $setid = !$setid ? substr(md5($setname), 0, 4) : $setid; $setid = isset($_G['showsetting_multi']) ? 'S'.$setid : $setid; if(!empty($_G['showsetting_multirow'])) { if(empty($_G['showsetting_multirow_n'])) { echo '<tr>'; } echo '<td class="vtop rowform"><p class="td27m">'.$name.'</p>'.$s.'</td>'; $_G['showsetting_multirow_n']++; if($_G['showsetting_multirow_n'] == 2) { if(empty($_G['showsetting_multirow_n'])) { echo '</tr>'; } $_G['showsetting_multirow_n'] = 0; } return; } if(!isset($_G['showsetting_multi'])) { if(!$nofaq) { $faqurl = 'http://faq.comsenz.com?type=admin&ver='.$_G['setting']['version'].'&action='.rawurlencode($_GET['action']).'&operation='.rawurlencode($_GET['operation']).'&key='.rawurlencode($setname); showtablerow($noborder.'οnmοuseοver="setfaq(this, \'faq'.$setid.'\')"', 'colspan="2" class="td27" s="1"', $name.'<a id="faq'.$setid.'" class="faq" title="'.cplang('setting_faq_title').'" href="'.$faqurl.'" target="_blank" style="display:none"> </a>'); } else { showtablerow('', 'colspan="2" class="td27" s="1"', $name); } } else { if(empty($_G['showsetting_multijs'])) { $_G['setting_JS'] .= 'var ss = new Array();'; $_G['showsetting_multijs'] = 1; } if($_G['showsetting_multi'] == 0) { showtablerow('', array('class="td27"'), array('<div id="D'.$setid.'"></div>')); $_G['setting_JS'] .= 'ss[\'D'.$setid.'\'] = new Array();'; } $name = preg_replace("/\r\n|\n|\r/", '\n', addcslashes($name, "'\\")); $_G['setting_JS'] .= 'ss[\'D'.$setid.'\'] += \'<div class="multicol">'.$name.'</div>\';'; } if(!$nocomment && ($type != 'omcheckbox' || $varname[2] != 'isfloat')) { if(!isset($_G['showsetting_multi'])) { showtablerow('class="noborder" οnmοuseοver="setfaq(this, \'faq'.$setid.'\')"', array('class="vtop rowform"', 'class="vtop tips2" s="1"'), array( $s, ($comment ? $comment : cplang($setname.'_comment', false)).($type == 'textarea' ? '<br />'.cplang('tips_textarea') : ''). ($disabled ? '<br /><span class="smalltxt" style="color:#F00">'.cplang($setname.'_disabled', false).'</span>' : NULL) )); } else { if($_G['showsetting_multi'] == 0) { showtablerow('class="noborder"', array('class="vtop rowform" style="width:auto"'), array( '<div id="'.$setid.'"></div>' )); $_G['setting_JS'] .= 'ss[\''.$setid.'\'] = new Array();'; } $s = preg_replace("/\r\n|\n|\r/", '\n', addcslashes($s, "'\\")); $_G['setting_JS'] .= 'ss[\''.$setid.'\'] += \'<div class="multicol">'.$s.'</div>\';'; } } else { showtablerow('class="noborder" οnmοuseοver="setfaq(this, \'faq'.$setid.'\')"', array('colspan="2" class="vtop rowform"'), array($s)); } if($hidden) { showtagheader('tbody', 'hidden_'.$setname, $value, 'sub'); } }
参数:
$setname - 指定输出标题,如:setting_basic_bbname, 自动匹配描述文字为:setting_basic_bbname_comment,comment形式文字可以在./source/language/lang_admincp.php语言包中添加
$varname - 指定表单的name值,如settingnew[bbname]
$value - 指定表单默认值\变量
$type - 表单样式
radio 单选
text 文本、password密码、number数字
file 上传文件
filetext 上传文件或在线文件切换型表单
textarea 多行文本
select 选择框
mradio 高级单选模式
mcheckbox 高级多选模式
binmcheckbox 二进制数值多选模式
mselect 高级选择框模式
color 颜色选择
calendar 日期选择
multiply 多表单型,
daterange时间范围
$disabled - 是否不可修改
$hidden - 是否隐藏
$comment - 强制描述文字
$extra - 表单扩展属性
$setid - 用于拼接表单外层Div的id
示范:
//以文本形式输出表单(站点名称 text):
showsetting('setting_basic_bbname', 'settingnew[bbname]', $setting['bbname'], 'text');
//以单选形式输出表单(显示授权信息链接 radio):
showsetting('setting_basic_boardlicensed', 'settingnew[boardlicensed]', $setting['boardlicensed'], 'radio');
//以多行文本形式输出表单(网站第三方统计代码 textarea):
showsetting('setting_basic_stat', 'settingnew[statcode]', $setting['statcode'], 'textarea');
//以高级单选形式输出表单(新用户注册验证 mradio)
showsetting('setting_access_register_verify', array('settingnew[regverify]', array(
array(0, $lang['none'], array('regverifyext' => 'none')),
array(1, $lang['setting_access_register_verify_email'], array('regverifyext' => '')),
array(2, $lang['setting_access_register_verify_manual'], array('regverifyext' => ''))
)), $setting['regverify'], 'mradio');
//以高级多选形式输出表单('允许新用户注册 mcheckbox)
showsetting('setting_access_register_status', array('settingnew[regstatus]', array(
array('open', $lang['setting_access_register_open']),
array('invite', $lang['setting_access_register_invite'], 'showinvite'),
$_G['setting']['connect']['allow'] ? array('connect', $lang['setting_access_register_connect'], 'showconnect') : array(),
)), $regstatus, 'mcheckbox');
showtableheader()创建表格头
showtableheader($title,$classname,$extra,$titlespan);
参数:
$title - 如果输入title则显示标题,class为header,否则仅显示一个table头
$classname - 定义此输出表格的CSS样式
$extra - 表格扩展属性
$titlespan - 表格列数
showformfooter()创建表格尾
showformfooter();
showsubmenu()创建二级导航栏
showsubmenu($title,$menus);
参数:
$title - 二级导航的当前栏标题
$menus - 多个子导航
示范:
showsubmenu('nav_members', array(
array('search', 'members&operation=search', 1),
array('clean', 'members&operation=clean', 0),
array('nav_repeat', 'members&operation=repeat', 0),
));
shownav()创建面包屑导航栏
shownav($header,$menu,$nav);
参数:
$header - 导航起点
$menu - 子导航标题
$nav - 面包屑导航第三层
showtips()创建提示信息
showtips($tips, $id = 'tips', $display = TRUE, $title = '');
参数:
$tips:具体的提示内容,是以li标签来输出的,所以内容格式是<li>提示信息一<li>提示信息二,列表多了还会自动折叠。
$id:就是生成的提示信息的id嘛,估计一般用不到,默认就行了
$display:默认是否显示,默认为TRUE
$title:提示标题,默认是技巧提示
showtablerow()创建列表式页面的行
返回值:有
参数:
$trstyle - 此行 tr 标签的格式定义,如 class=“partition”
$tdstyle - TD 标签的格式定义,如 class,colspan 等
$tdtext - TD内显示的内容
$return 是否返回值
此函数多用于循环中,用来逐行创建一个有规律的数据列表如:论坛版块列表等
showtablerow('', array('class="td25"', 'class="td28"'), array( '<input type="checkbox" class="checkbox" name="delete[]" value="'.$mod[uid].'"'.($mod['inherited'] ? ' disabled' : '').' />', '<input type="text" class="txt" name="displayordernew['.$mod[uid].']" value="'.$mod[displayorder].'" size="2" />', "<a href=\"".ADMINSCRIPT."?mod=forum&action=members&operation=group&uid=$mod[uid]\" target=\"_blank\">$mod[username]</a>", $modgroups[$mod['groupid']], cplang($mod['inherited'] ? 'yes' : 'no'), ));
关于showsetting()函数创建select或者mselect输入框:
$option = array( array(1,'AAA'), array(2,'BBB'), array(3,'CCC'), );
showsetting("Msg:",array('tarlang',$option),1,'select');
对应的 HTML 代码如下:
<select name="tarlang"> <option value="1" selected="selected">AAA</option> <option value="2">BBB</option> <option value="3">CCC</option> </select>
还没有评论,来说两句吧...