国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

enums.func.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php if(!defined('DEDEINC')) exit("Request Error!");
  2. /**
  3. * 联动菜单类
  4. *
  5. * @version $Id: enums.func.php 2 13:19 2011-3-24 tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. // 弱不存在缓存文件则写入缓存
  12. if(!file_exists(DEDEDATA.'/enums/system.php')) WriteEnumsCache();
  13. /**
  14. * 更新枚举缓存
  15. *
  16. * @access public
  17. * @param string $egroup 联动组
  18. * @return string
  19. */
  20. function WriteEnumsCache($egroup='')
  21. {
  22. global $dsql;
  23. $egroups = array();
  24. if($egroup=='') {
  25. $dsql->SetQuery("SELECT egroup FROM `#@__sys_enum` GROUP BY egroup ");
  26. }
  27. else {
  28. $dsql->SetQuery("SELECT egroup FROM `#@__sys_enum` WHERE egroup='$egroup' GROUP BY egroup ");
  29. }
  30. $dsql->Execute('enum');
  31. while($nrow = $dsql->GetArray('enum')) {
  32. $egroups[] = $nrow['egroup'];
  33. }
  34. foreach($egroups as $egroup)
  35. {
  36. $cachefile = DEDEDATA.'/enums/'.$egroup.'.php';
  37. $fp = fopen($cachefile,'w');
  38. fwrite($fp,'<'."?php\r\nglobal \$em_{$egroup}s;\r\n\$em_{$egroup}s = array();\r\n");
  39. $dsql->SetQuery("SELECT ename,evalue,issign FROM `#@__sys_enum` WHERE egroup='$egroup' ORDER BY disorder ASC, evalue ASC ");
  40. $dsql->Execute('enum');
  41. $issign = -1;
  42. $tenum = false; //三级联动标识
  43. while($nrow = $dsql->GetArray('enum'))
  44. {
  45. fwrite($fp,"\$em_{$egroup}s['{$nrow['evalue']}'] = '{$nrow['ename']}';\r\n");
  46. if($issign==-1) $issign = $nrow['issign'];
  47. if($nrow['issign']==2) $tenum = true;
  48. }
  49. if ($tenum) $dsql->ExecuteNoneQuery("UPDATE `#@__stepselect` SET `issign`=2 WHERE egroup='$egroup'; ");
  50. fwrite($fp,'?'.'>');
  51. fclose($fp);
  52. if(empty($issign)) WriteEnumsJs($egroup);
  53. }
  54. return '成功更新所有枚举缓存!';
  55. }
  56. /**
  57. * 获取联动表单两级数据的父类与子类
  58. *
  59. * @access public
  60. * @param string $v
  61. * @return array
  62. */
  63. function GetEnumsTypes($v)
  64. {
  65. $rearr['top'] = $rearr['son'] = 0;
  66. if($v==0) return $rearr;
  67. if($v%500==0) {
  68. $rearr['top'] = $v;
  69. }
  70. else {
  71. $rearr['son'] = $v;
  72. $rearr['top'] = $v - ($v%500);
  73. }
  74. return $rearr;
  75. }
  76. /**
  77. * 获取枚举的select表单
  78. *
  79. * @access public
  80. * @param string $egroup 联动组
  81. * @param string $evalue 联动值
  82. * @param string $formid 表单ID
  83. * @param string $seltitle 选择标题
  84. * @return string 成功后返回一个枚举表单
  85. */
  86. function GetEnumsForm($egroup, $evalue=0, $formid='', $seltitle='')
  87. {
  88. $cachefile = DEDEDATA.'/enums/'.$egroup.'.php';
  89. include($cachefile);
  90. if($formid=='')
  91. {
  92. $formid = $egroup;
  93. }
  94. $forms = "<select name='$formid' id='$formid' class='enumselect form-control'>\r\n";
  95. $forms .= "\t<option value='0' selected='selected'>--请选择--{$seltitle}</option>\r\n";
  96. foreach(${'em_'.$egroup.'s'} as $v=>$n)
  97. {
  98. $prefix = ($v > 500 && $v%500 != 0) ? '└─ ' : '';
  99. if (preg_match("#\.#", $v)) $prefix = ' &nbsp;&nbsp;└── ';
  100. if($v==$evalue)
  101. {
  102. $forms .= "\t<option value='$v' selected='selected'>$prefix$n</option>\r\n";
  103. }
  104. else
  105. {
  106. $forms .= "\t<option value='$v'>$prefix$n</option>\r\n";
  107. }
  108. }
  109. $forms .= "</select>";
  110. return $forms;
  111. }
  112. /**
  113. * 获取一级数据
  114. *
  115. * @access public
  116. * @param string $egroup 联动组
  117. * @return array
  118. */
  119. function getTopData($egroup)
  120. {
  121. $data = array();
  122. $cachefile = DEDEDATA.'/enums/'.$egroup.'.php';
  123. include($cachefile);
  124. foreach(${'em_'.$egroup.'s'} as $k=>$v)
  125. {
  126. if($k >= 500 && $k%500 == 0) {
  127. $data[$k] = $v;
  128. }
  129. }
  130. return $data;
  131. }
  132. /**
  133. * 获取数据的JS代码(二级联动)
  134. *
  135. * @access public
  136. * @param string $egroup 联动组
  137. * @return string
  138. */
  139. function GetEnumsJs($egroup)
  140. {
  141. global ${'em_'.$egroup.'s'};
  142. include_once(DEDEDATA.'/enums/'.$egroup.'.php');
  143. $jsCode = "<!--\r\n";
  144. $jsCode .= "em_{$egroup}s=new Array();\r\n";
  145. foreach(${'em_'.$egroup.'s'} as $k => $v)
  146. {
  147. // JS中将3级类目存放到第二个key中去
  148. if (preg_match("#([0-9]{1,})\.([0-9]{1,})#", $k, $matchs))
  149. {
  150. $valKey = $matchs[1] + $matchs[2] / 1000;
  151. $jsCode .= "em_{$egroup}s[{$valKey}]='$v';\r\n";
  152. } else {
  153. $jsCode .= "em_{$egroup}s[$k]='$v';\r\n";
  154. }
  155. }
  156. $jsCode .= "-->";
  157. return $jsCode;
  158. }
  159. /**
  160. * 写入联动JS代码
  161. *
  162. * @access public
  163. * @param string $egroup 联动组
  164. * @return string
  165. */
  166. function WriteEnumsJs($egroup)
  167. {
  168. $jsfile = DEDEDATA.'/enums/'.$egroup.'.js';
  169. $fp = fopen($jsfile, 'w');
  170. fwrite($fp, GetEnumsJs($egroup));
  171. fclose($fp);
  172. }
  173. /**
  174. * 获取枚举的值
  175. *
  176. * @access public
  177. * @param string $egroup 联动组
  178. * @param string $evalue 联动值
  179. * @return string
  180. */
  181. function GetEnumsValue($egroup, $evalue=0)
  182. {
  183. include_once(DEDEDATA.'/enums/'.$egroup.'.php');
  184. if(isset(${'em_'.$egroup.'s'}[$evalue])) {
  185. return ${'em_'.$egroup.'s'}[$evalue];
  186. }
  187. else {
  188. return "保密";
  189. }
  190. }