找回密码
 立即注册

只需一扫,快速开始

QQ登录

只需一步,快速开始

搜索
查看: 264029|回复: 0

[技术经验] discuz后台函数之showsetting

[复制链接]

8万

主题

431

回帖

9万

积分

管理员

积分
94388
QQ
发表于 2015-11-20 17:07:50 | 显示全部楼层 |阅读模式
  1. 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的时候,由于涉及到比较复杂的数组,所以这个还是比较复杂的。
函数定义,有空可以去看看
  1. function showsetting($setname, $varname, $value, $type = 'radio', $disabled = '', $hidden = 0, $comment = '', $extra = '', $setid = '') {

  2.         global $_G;
  3.         $s = "\n";
  4.         $check = array();
  5.         $check['disabled'] = $disabled ? ($disabled == 'readonly' ? ' readonly' : ' disabled') : '';
  6.         $check['disabledaltstyle'] = $disabled ? ', 1' : '';

  7.         $nocomment = false;

  8.         if(isset($_G['showsetting_multi'])) {
  9.                 $hidden = 0;
  10.                 if(is_array($varname)) {
  11.                         $varnameid = '_'.str_replace(array('[', ']'), '_', $varname[0]).'|'.$_G['showsetting_multi'];
  12.                         $varname[0] = preg_replace('/\w+new/', 'multinew['.$_G['showsetting_multi'].'][\\0]', $varname[0]);
  13.                 } else {
  14.                         $varnameid = '_'.str_replace(array('[', ']'), '_', $varname).'|'.$_G['showsetting_multi'];
  15.                         $varname = preg_replace('/\w+new/', 'multinew['.$_G['showsetting_multi'].'][\\0]', $varname);
  16.                 }
  17.         } else {
  18.                 $varnameid = '';
  19.         }

  20.         if($type == 'radio') {
  21.                 $value ? $check['true'] = "checked" : $check['false'] = "checked";
  22.                 $value ? $check['false'] = '' : $check['true'] = '';
  23.                 $check['hidden1'] = $hidden ? ' onclick="$(\'hidden_'.$setname.'\').style.display = \'\';"' : '';
  24.                 $check['hidden0'] = $hidden ? ' onclick="$(\'hidden_'.$setname.'\').style.display = \'none\';"' : '';
  25.                 $onclick = $disabled && $disabled == 'readonly' ? ' onclick="return false"' : '';
  26.                 $s .= '<ul onmouseover="altStyle(this'.$check['disabledaltstyle'].');">'.
  27.                         '<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>'.
  28.                         '<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>'.
  29.                         '</ul>';
  30.         } elseif($type == 'text' || $type == 'password' || $type == 'number') {
  31.                 $s .= '<input name="'.$varname.'" value="'.dhtmlspecialchars($value).'" type="'.$type.'" class="txt" '.$check['disabled'].' '.$extra.' />';
  32.         } elseif($type == 'file') {
  33.                 $s .= '<input name="'.$varname.'" value="" type="file" class="txt uploadbtn marginbot" '.$check['disabled'].' '.$extra.' />';
  34.         } elseif($type == 'filetext') {
  35.                 $defaulttype = $value ? 1 : 0;
  36.                 $id = 'file'.random(2);
  37.                 $s .= '<input id="'.$id.'_0" style="display:'.($defaulttype ? 'none' : '').'" name="'.($defaulttype ? 'TMP' : '').$varname.'" value="" type="file" class="txt uploadbtn marginbot" '.$check['disabled'].' '.$extra.' />'.
  38.                         '<input id="'.$id.'_1" style="display:'.(!$defaulttype ? 'none' : '').'" name="'.(!$defaulttype ? 'TMP' : '').$varname.'" value="'.dhtmlspecialchars($value).'" type="text" class="txt marginbot" '.$extra.' /><br />'.
  39.                         '<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> '.
  40.                         '<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>';
  41.         } elseif($type == 'textarea') {
  42.                 $readonly = $disabled ? 'readonly' : '';
  43.                 $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>";
  44.         } elseif($type == 'select') {
  45.                 $s .= '<select name="'.$varname[0].'" '.$extra.'>';
  46.                 foreach($varname[1] as $option) {
  47.                         $selected = $option[0] == $value ? 'selected="selected"' : '';
  48.                         if(empty($option[2])) {
  49.                                 $s .= "<option value="$option[0]" $selected>".$option[1]."</option>\n";
  50.                         } else {
  51.                                 $s .= "<optgroup label="".$option[1].""></optgroup>\n";
  52.                         }
  53.                 }
  54.                 $s .= '</select>';
  55.         } elseif($type == 'mradio' || $type == 'mradio2') {
  56.                 $nocomment = $type == 'mradio2' && !isset($_G['showsetting_multi']) ? true : false;
  57.                 $addstyle = $nocomment ? ' style="float: left; width: 18%"' : '';
  58.                 $ulstyle = $nocomment ? ' style="width: 830px"' : '';
  59.                 if(is_array($varname)) {
  60.                         $radiocheck = array($value => ' checked');
  61.                         $s .= '<ul'.(empty($varname[2]) ?  ' class="nofloat"' : '').' onmouseover="altStyle(this'.$check['disabledaltstyle'].');"'.$ulstyle.'>';
  62.                         foreach($varname[1] as $varary) {
  63.                                 if(is_array($varary) && !empty($varary)) {
  64.                                         $onclick = '';
  65.                                         if(!isset($_G['showsetting_multi']) && !empty($varary[2])) {
  66.                                                 foreach($varary[2] as $ctrlid => $display) {
  67.                                                         $onclick .= '$(\''.$ctrlid.'\').style.display = \''.$display.'\';';
  68.                                                 }
  69.                                         }
  70.                                         $onclick && $onclick = ' onclick="'.$onclick.'"';
  71.                                         $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>';
  72.                                 }
  73.                         }
  74.                         $s .= '</ul>';
  75.                 }
  76.         } elseif($type == 'mcheckbox' || $type == 'mcheckbox2') {
  77.                 $nocomment = $type != 'mcheckbox2' && count($varname[1]) > 3 && !isset($_G['showsetting_multi']) ? true : false;
  78.                 $addstyle = $nocomment ? ' style="float: left; width: 18%"' : '';
  79.                 $ulstyle = $nocomment ? ' style="width: 830px"' : '';
  80.                 $s .= '<ul class="nofloat" onmouseover="altStyle(this'.$check['disabledaltstyle'].');"'.$ulstyle.'>';
  81.                 foreach($varname[1] as $varary) {
  82.                         if(is_array($varary) && !empty($varary)) {
  83.                                 $onclick = !isset($_G['showsetting_multi']) && !empty($varary[2]) ? ' onclick="$(\''.$varary[2].'\').style.display = $(\''.$varary[2].'\').style.display == \'none\' ? \'\' : \'none\';"' : '';
  84.                                 $checked = is_array($value) && in_array($varary[0], $value) ? ' checked' : '';
  85.                                 $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>';
  86.                         }
  87.                 }
  88.                 $s .= '</ul>';
  89.         } elseif($type == 'binmcheckbox') {
  90.                 $checkboxs = count($varname[1]);
  91.                 $value = sprintf('%0'.$checkboxs.'b', $value);$i = 1;
  92.                 $s .= '<ul class="nofloat" onmouseover="altStyle(this'.$check['disabledaltstyle'].');">';
  93.                 foreach($varname[1] as $key => $var) {
  94.                         $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>';
  95.                         $i++;
  96.                 }
  97.                 $s .= '</ul>';
  98.         } elseif($type == 'omcheckbox') {
  99.                 $nocomment = count($varname[1]) > 3 ? true : false;
  100.                 $addstyle = $nocomment ? 'style="float: left; width: 18%"' : '';
  101.                 $ulstyle = $nocomment ? 'style="width: 830px"' : '';
  102.                 $s .= '<ul onmouseover="altStyle(this'.$check['disabledaltstyle'].');"'.(empty($varname[2]) ? ' class="nofloat"' : 'class="ckbox"').' '.$ulstyle.'>';
  103.                 foreach($varname[1] as $varary) {
  104.                         if(is_array($varary) && !empty($varary)) {
  105.                                 $checked = is_array($value) && $value[$varary[0]] ? ' checked' : '';
  106.                                 $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>';
  107.                         }
  108.                 }
  109.                 $s .= '</ul>';
  110.         } elseif($type == 'mselect') {
  111.                 $s .= '<select name="'.$varname[0].'" multiple="multiple" size="10" '.$extra.'>';
  112.                 foreach($varname[1] as $option) {
  113.                         $selected = is_array($value) && in_array($option[0], $value) ? 'selected="selected"' : '';
  114.                         if(empty($option[2])) {
  115.                                 $s .= "<option value="$option[0]" $selected>".$option[1]."</option>\n";
  116.                         } else {
  117.                                 $s .= "<optgroup label="".$option[1].""></optgroup>\n";
  118.                         }
  119.                 }
  120.                 $s .= '</select>';
  121.         } elseif($type == 'color') {
  122.                 global $stylestuff;
  123.                 $preview_varname = str_replace('[', '_', str_replace(']', '', $varname));
  124.                 $code = explode(' ', $value);
  125.                 $css = '';
  126.                 for($i = 0; $i <= 1; $i++) {
  127.                         if($code[$i] != '') {
  128.                                 if($code[$i]{0} == '#') {
  129.                                         $css .= strtoupper($code[$i]).' ';
  130.                                 } elseif(preg_match('/^http:\/\//i', $code[$i])) {
  131.                                         $css .= 'url(\''.$code[$i].'\') ';
  132.                                 } else {
  133.                                         $css .= 'url(\''.$stylestuff['imgdir']['subst'].'/'.$code[$i].'\') ';
  134.                                 }
  135.                         }
  136.                 }
  137.                 $background = trim($css);
  138.                 $colorid = ++$GLOBALS['coloridcount'];
  139.                 $s .= "<input id="c{$colorid}_v" type="text" class="txt" style="float:left; width:210px;" value="$value" name="$varname" onchange="updatecolorpreview('c{$colorid}')">\n".
  140.                         "<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";
  141.         } elseif($type == 'calendar') {
  142.                 $s .= "<input type="text" class="txt" name="$varname" value="".dhtmlspecialchars($value)."" onclick="showcalendar(event, this".($extra ? ', 1' : '').")">\n";
  143.         } elseif(in_array($type, array('multiply', 'range', 'daterange'))) {
  144.                 $onclick = $type == 'daterange' ? ' onclick="showcalendar(event, this)"' : '';
  145.                 if(isset($_G['showsetting_multi'])) {
  146.                         $varname[1] = preg_replace('/\w+new/', 'multinew['.$_G['showsetting_multi'].'][\\0]', $varname[1]);
  147.                 }
  148.                 $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>";
  149.         } else {
  150.                 $s .= $type;
  151.         }
  152.         $name = cplang($setname);
  153.         $name .= $name && substr($name, -1) != ':' ? ':' : '';
  154.         $name = $disabled ? '<span class="lightfont">'.$name.'</span>' : $name;
  155.         $setid = !$setid ? substr(md5($setname), 0, 4) : $setid;
  156.         $setid = isset($_G['showsetting_multi']) ? 'S'.$setid : $setid;
  157.         if(!empty($_G['showsetting_multirow'])) {
  158.                 if(empty($_G['showsetting_multirow_n'])) {
  159.                         echo '<tr>';
  160.                 }
  161.                 echo '<td class="vtop rowform"><p class="td27m">'.$name.'</p>'.$s.'</td>';
  162.                 $_G['showsetting_multirow_n']++;
  163.                 if($_G['showsetting_multirow_n'] == 2) {
  164.                         if(empty($_G['showsetting_multirow_n'])) {
  165.                                 echo '</tr>';
  166.                         }
  167.                         $_G['showsetting_multirow_n'] = 0;
  168.                 }
  169.                 return;
  170.         }
  171.         if(!isset($_G['showsetting_multi'])) {
  172.                 $faqurl = 'http://faq.comsenz.com?type=admin&ver='.$_G['setting']['version'].'&action='.rawurlencode($_GET['action']).'&operation='.rawurlencode($_GET['operation']).'&key='.rawurlencode($setname);
  173.                 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>');
  174.         } else {
  175.                 if(empty($_G['showsetting_multijs'])) {
  176.                         $_G['setting_JS'] .= 'var ss = new Array();';
  177.                         $_G['showsetting_multijs'] = 1;
  178.                 }
  179.                 if($_G['showsetting_multi'] == 0) {
  180.                         showtablerow('', array('class="td27"'), array('<div id="D'.$setid.'"></div>'));
  181.                         $_G['setting_JS'] .= 'ss[\'D'.$setid.'\'] = new Array();';
  182.                 }
  183.                 $name = preg_replace("/\r\n|\n|\r/", '\n', addcslashes($name, "'\"));
  184.                 $_G['setting_JS'] .= 'ss[\'D'.$setid.'\'] += \'<div class="multicol">'.$name.'</div>\';';
  185.         }
  186.         if(!$nocomment && ($type != 'omcheckbox' || $varname[2] != 'isfloat')) {
  187.                 if(!isset($_G['showsetting_multi'])) {
  188.                         showtablerow('class="noborder" onmouseover="setfaq(this, \'faq'.$setid.'\')"', array('class="vtop rowform"', 'class="vtop tips2" s="1"'), array(
  189.                                 $s,
  190.                                 ($comment ? $comment : cplang($setname.'_comment', false)).($type == 'textarea' ? '<br />'.cplang('tips_textarea') : '').
  191.                                 ($disabled ? '<br /><span class="smalltxt" style="color:#F00">'.cplang($setname.'_disabled', false).'</span>' : NULL)
  192.                         ));
  193.                 } else {
  194.                         if($_G['showsetting_multi'] == 0) {
  195.                                 showtablerow('class="noborder"', array('class="vtop rowform" style="width:auto"'), array(
  196.                                         '<div id="'.$setid.'"></div>'
  197.                                 ));
  198.                                 $_G['setting_JS'] .= 'ss[\''.$setid.'\'] = new Array();';
  199.                         }
  200.                         $s = preg_replace("/\r\n|\n|\r/", '\n', addcslashes($s, "'\"));
  201.                         $_G['setting_JS'] .= 'ss[\''.$setid.'\'] += \'<div class="multicol">'.$s.'</div>\';';
  202.                 }
  203.         } else {
  204.                 showtablerow('class="noborder" onmouseover="setfaq(this, \'faq'.$setid.'\')"', array('colspan="2" class="vtop rowform"'), array($s));
  205.         }

  206.         if($hidden) {
  207.                 showtagheader('tbody', 'hidden_'.$setname, $value, 'sub');
  208.         }

  209. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册   

本版积分规则

QQ|Archiver|手机版|小黑屋|站秘书 ( 蜀ICP备15034504号-3 )

GMT+8, 2024-5-6 05:19 , Processed in 0.083707 second(s), 40 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表