|
- showsetting('选择需要导出的试卷',array('examinationpaper',array(array('bb','aa'),array('dd','ee'))),'dd','select');
复制代码
常用函数大家可以参考官方提供的开发文档:http://faq.comsenz.com/library/p ... ruct_adm.htm#hanshu
可以看出,第二个参数确定了select的name和option,其中第一个参数是name 后面的是一个大的数组,包含了所有option 的key和value,第三个参数为默认值,是key。
但是当时select的时候,由于涉及到比较复杂的数组,所以这个还是比较复杂的。
函数定义,有空可以去看看
- function showsetting($setname, $varname, $value, $type = 'radio', $disabled = '', $hidden = 0, $comment = '', $extra = '', $setid = '') {
-
- global $_G;
- $s = "\n";
- $check = array();
- $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 ? ' onclick="$(\'hidden_'.$setname.'\').style.display = \'\';"' : '';
- $check['hidden0'] = $hidden ? ' onclick="$(\'hidden_'.$setname.'\').style.display = \'none\';"' : '';
- $onclick = $disabled && $disabled == 'readonly' ? ' onclick="return false"' : '';
- $s .= '<ul onmouseover="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 == '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:;" onclick="$(\''.$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:;" onclick="$(\''.$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']) ? "ondblclick="textareasize(this, 1)"" : '')." onkeyup="textareasize(this, 0)" 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) {
- $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: 830px"' : '';
- if(is_array($varname)) {
- $radiocheck = array($value => ' checked');
- $s .= '<ul'.(empty($varname[2]) ? ' class="nofloat"' : '').' onmouseover="altStyle(this'.$check['disabledaltstyle'].');"'.$ulstyle.'>';
- foreach($varname[1] as $varary) {
- if(is_array($varary) && !empty($varary)) {
- $onclick = '';
- if(!isset($_G['showsetting_multi']) && !empty($varary[2])) {
- foreach($varary[2] as $ctrlid => $display) {
- $onclick .= '$(\''.$ctrlid.'\').style.display = \''.$display.'\';';
- }
- }
- $onclick && $onclick = ' onclick="'.$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; width: 18%"' : '';
- $ulstyle = $nocomment ? ' style="width: 830px"' : '';
- $s .= '<ul class="nofloat" onmouseover="altStyle(this'.$check['disabledaltstyle'].');"'.$ulstyle.'>';
- foreach($varname[1] as $varary) {
- if(is_array($varary) && !empty($varary)) {
- $onclick = !isset($_G['showsetting_multi']) && !empty($varary[2]) ? ' onclick="$(\''.$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.'><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" onmouseover="altStyle(this'.$check['disabledaltstyle'].');">';
- foreach($varname[1] as $key => $var) {
- $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: 830px"' : '';
- $s .= '<ul onmouseover="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) {
- $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" onchange="updatecolorpreview('c{$colorid}')">\n".
- "<input id="c$colorid" onclick="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)."" onclick="showcalendar(event, this".($extra ? ', 1' : '').")">\n";
- } elseif(in_array($type, array('multiply', 'range', 'daterange'))) {
- $onclick = $type == 'daterange' ? ' onclick="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'])) {
- $faqurl = 'http://faq.comsenz.com?type=admin&ver='.$_G['setting']['version'].'&action='.rawurlencode($_GET['action']).'&operation='.rawurlencode($_GET['operation']).'&key='.rawurlencode($setname);
- showtablerow('onmouseover="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 {
- 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" onmouseover="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" onmouseover="setfaq(this, \'faq'.$setid.'\')"', array('colspan="2" class="vtop rowform"'), array($s));
- }
-
- if($hidden) {
- showtagheader('tbody', 'hidden_'.$setname, $value, 'sub');
- }
-
- }
复制代码
|
|