info_type.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. //decode by http://dezend.qiling.org QQ 2859470
  3. function get_type_option($identifier = '')
  4. {
  5. global $var_type;
  6. foreach ($var_type as $k => $value) {
  7. $mymps .= '<option value="' . $k . '"';
  8. $mymps .= $identifier == $k ? ' selected' : '';
  9. $mymps .= '>' . $value . '(' . $k . ')</option>';
  10. }
  11. return $mymps;
  12. }
  13. function get_mymps_admin_info_type($rules = '')
  14. {
  15. global $mymps_admin_info_type;
  16. global $edit;
  17. global $rules;
  18. global $var_type;
  19. foreach ($mymps_admin_info_type as $k => $value) {
  20. $estyle = $edit[type] != $k ? 'style="display:none"' : '';
  21. $str .= '<div id="style_' . $k . '" ' . $estyle . ' class="mytable"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="vbm"><tr class="firstr"><td colspan="2">' . $var_type[$k] . '(' . $k . ')</td></tr>' . $value . '</table></div>';
  22. }
  23. return $str;
  24. }
  25. function get_all_options()
  26. {
  27. global $db;
  28. global $db_mymps;
  29. $sql = 'SELECT optionid,title,type,identifier FROM `' . $db_mymps . 'info_typeoptions`';
  30. $optgroup = $db->getAll($sql . 'WHERE classid = 0 ORDER BY displayorder,optionid DESC');
  31. foreach ($optgroup as $k => $value) {
  32. $opt .= '<optgroup label=' . $value[title] . '>';
  33. $op = $db->getAll($sql . 'WHERE classid != 0 AND classid = \'' . $value['optionid'] . '\' ORDER BY displayorder,optionid DESC');
  34. foreach ($op as $w => $y) {
  35. $opt .= '<option value=' . $y[optionid] . '>' . $y[title] . ' / ' . $y[identifier] . ' / ' . $y[type] . '</option>';
  36. }
  37. $opt .= '</optgroup>';
  38. }
  39. return $opt;
  40. }
  41. define('CURSCRIPT', 'info_type');
  42. require_once dirname(__FILE__) . '/global.php';
  43. require_once MYMPS_INC . '/db.class.php';
  44. $part = $part ? $part : 'option_list';
  45. (!defined('IN_ADMIN') || !defined('IN_MYMPS')) && exit('Access Denied');
  46. if ($admin_cityid) {
  47. write_msg('您没有权限访问该页!');
  48. }
  49. if ($part == 'option_list') {
  50. chk_admin_purview('purview_字段管理');
  51. require_once MYMPS_DATA . '/info.type.inc.php';
  52. $classid = $classid ? $classid : $db->getOne('SELECT MAX(classid) FROM `' . $db_mymps . 'info_typeoptions`');
  53. $here = '信息分类字段';
  54. $options = $db->getAll('SELECT * FROM `' . $db_mymps . 'info_typeoptions` WHERE classid =\'0\' ORDER BY displayorder DESC');
  55. $detail = $db->getRow('SELECT title,optionid FROM `' . $db_mymps . 'info_typeoptions` WHERE optionid =\'' . $classid . '\'');
  56. $option = $db->getAll('SELECT * FROM `' . $db_mymps . 'info_typeoptions` WHERE classid =\'' . $classid . '\' AND classid != \'0\' ORDER BY displayorder DESC');
  57. include mymps_tpl('info_option');
  58. } else {
  59. if ($part == 'option_add') {
  60. (empty($title) || empty($identifier) || empty($type) || empty($classid)) && write_msg('请填写完整相关信息!');
  61. if (0 < mymps_count('info_typeoptions', 'WHERE identifier = \'' . $identifier . '\'')) {
  62. write_msg('变量名' . $identifer . '已存在,请换一个变量名');
  63. exit;
  64. }
  65. $res = $db->query('INSERT INTO `' . $db_mymps . 'info_typeoptions` (title,identifier,type,displayorder,classid,available,required,search)VALUES(\'' . $title . '\',\'' . $identifier . '\',\'' . $type . '\',\'' . $displayorder . '\',\'' . $classid . '\',\'' . $available . '\',\'' . $required . '\',\'' . $search . '\')');
  66. $optionid = $db->insert_id();
  67. clear_cache_files('mod_search_option');
  68. clear_cache_files('mod_search_identifier');
  69. write_msg('信息字段' . $title . '增加成功! 请继续编辑该字段详情以完成该操作!', '?part=option_edit&optionid=' . $optionid, 'mymps.com.cn');
  70. } else {
  71. if ($part == 'option_edit') {
  72. $optionid = intval($_GET['optionid']);
  73. $action = trim($_GET['action']);
  74. switch ($action) {
  75. case 'update':
  76. if ($search == 'on' && empty($rules[number][choices]) && empty($rules[select][choices]) && empty($rules[radio][choices]) && empty($rules[checkbox][choices])) {
  77. write_msg('该字段设计为参与搜索时,检索范围值不能留空!');
  78. exit;
  79. }
  80. $rule = $_POST['rules'];
  81. $rules = serialize(str_replace(' ', '', $rule[$typenew]));
  82. $db->query('UPDATE `' . $db_mymps . 'info_typeoptions` SET title=\'' . $title . '\',identifier=\'' . $identifier . '\',type=\'' . $typenew . '\',classid=\'' . $classid . '\',displayorder=\'' . $displayorder . '\',description=\'' . $description . '\',rules =\'' . $rules . '\',available=\'' . $available . '\',required=\'' . $required . '\',search=\'' . $search . '\' WHERE optionid = \'' . $optionid . '\'');
  83. $rl = str_replace(' ', '', $rule[$typenew]);
  84. $r = $db->getAll('SELECT id,options FROM `' . $db_mymps . 'info_typemodels` WHERE id > 1');
  85. foreach ($r as $k => $v) {
  86. if (in_array($optionid, explode(',', $v['options'])) && $db->num_rows($db->query('SHOW TABLES LIKE \'' . $db_mymps . 'information_' . $v[id] . '\'')) == 1) {
  87. if ($typenew == 'text') {
  88. $option_sql = ' VARCHAR(' . ($rl[maxlength] ? $rl[maxlength] : 250) . ') NOT NULL';
  89. } else {
  90. if ($typenew == 'textarea') {
  91. $option_sql = ' MEDIUMTEXT';
  92. } else {
  93. if ($typenew == 'number') {
  94. $option_sql = ' DECIMAL(10,2) NOT NULL DEFAULT \'0\'';
  95. } else {
  96. if ($typenew == 'radio') {
  97. $option_sql = ' TINYINT(1) NOT NULL DEFAULT \'0\'';
  98. } else {
  99. if ($typenew == 'checkbox') {
  100. $option_sql = ' VARCHAR(100) NOT NULL DEFAULT \'0\'';
  101. } else {
  102. if ($typenew == 'select') {
  103. $option_sql = ' TINYINT(1) NOT NULL DEFAULT \'0\'';
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. if (!in_array($identifier, array('iid', 'id', 'content'))) {
  111. if ($db->num_rows($db->query('SHOW COLUMNS FROM `' . $db_mymps . 'information_' . $v[id] . '` LIKE \'' . $identifier . '\''))) {
  112. $sql = 'ALTER TABLE `' . $db_mymps . 'information_' . $v[id] . '` CHANGE `' . $identifier . '` `' . $identifier . '` ' . $option_sql . ';';
  113. } else {
  114. $sql = 'ALTER TABLE `' . $db_mymps . 'information_' . $v[id] . '` ADD `' . $identifier . '` ' . $option_sql . ';';
  115. }
  116. }
  117. $db->query($sql);
  118. }
  119. }
  120. clear_cache_files('mod_search_option');
  121. clear_cache_files('mod_search_identifier');
  122. clear_cache_files('info_typeoptions');
  123. write_msg('信息字段 <b>' . $title . '</b> 属性修改成功!', '?part=option_edit&optionid=' . $optionid, 'MyMps');
  124. break;
  125. default:
  126. $options = $db->getAll('SELECT * FROM `' . $db_mymps . 'info_typeoptions` WHERE classid =\'0\' ORDER BY optionid DESC');
  127. $edit = $db->getRow('SELECT * FROM `' . $db_mymps . 'info_typeoptions` WHERE optionid =\'' . $optionid . '\'');
  128. $here = '分类字段';
  129. $class_option = $db->getAll('SELECT optionid,title FROM `' . $db_mymps . 'info_typeoptions` WHERE classid = \'0\' ORDER BY displayorder,optionid DESC');
  130. if ($edit[rules]) {
  131. $rule = unserialize($edit[rules]);
  132. if ($edit[type] == 'number') {
  133. $rules[number] = $rule;
  134. } else {
  135. if (is_array($rule)) {
  136. foreach ($rule as $w) {
  137. $rules[$edit[type]] .= $w;
  138. }
  139. }
  140. }
  141. }
  142. require_once MYMPS_DATA . '/info.type.inc.php';
  143. include mymps_tpl('info_option_edit');
  144. break;
  145. }
  146. } else {
  147. if ($part == 'option_delall') {
  148. $a = $db->getAll('SELECT id,options FROM `' . $db_mymps . 'info_typemodels` WHERE id > 1');
  149. foreach ($id as $u => $w) {
  150. if ($identifier = $db->getOne('SELECT identifier FROM `' . $db_mymps . 'info_typeoptions` WHERE optionid = ' . $w)) {
  151. foreach ($a as $k => $v) {
  152. if ($db->num_rows($db->query('SHOW TABLES LIKE \'' . $db_mymps . 'information_' . $v[id] . '\'')) == 1 && $db->num_rows($db->query('SHOW COLUMNS FROM `' . $db_mymps . 'information_' . $v[id] . '` LIKE \'' . $identifier . '\''))) {
  153. $db->query('ALTER TABLE `' . $db_mymps . 'information_' . $v[id] . '` DROP COLUMN `' . $identifier . '`;');
  154. }
  155. }
  156. }
  157. }
  158. foreach ($a as $i => $j) {
  159. if ($j['options']) {
  160. $o = explode(',', $j['options']);
  161. if (is_array($o)) {
  162. $o = array_flip($o);
  163. }
  164. foreach ($id as $t => $b) {
  165. if ($o[$b]) {
  166. unset($o[$b]);
  167. }
  168. }
  169. if (is_array($o)) {
  170. $o = array_flip($o);
  171. }
  172. if (is_array($o)) {
  173. $o = implode(',', $o);
  174. }
  175. $db->query('UPDATE `' . $db_mymps . 'info_typemodels` SET options = \'' . $o . '\' WHERE id = \'' . $j['id'] . '\'');
  176. }
  177. }
  178. clear_cache_files('mod_search_option');
  179. clear_cache_files('mod_search_identifier');
  180. clear_cache_files('info_typeoptions');
  181. write_msg('删除信息字段 ' . mymps_del_all('info_typeoptions', $id, 'optionid') . ' 成功', $url, 'mymps');
  182. } else {
  183. if ($part == 'option_type') {
  184. switch ($action) {
  185. case 'insert':
  186. $title = trim($_POST['title']);
  187. if (empty($title)) {
  188. write_msg('请填写类型名称');
  189. }
  190. $mymps_in = $db->query('INSERT `' . $db_mymps . 'info_typeoptions` (title,classid) VALUES (\'' . $title . '\',\'0\')');
  191. write_msg('字段模型分类' . $title . '添加成功!', '?part=option_type', 'MYMPS.COM.CN');
  192. break;
  193. case 'update':
  194. empty($title) && write_msg('请填写类型名称');
  195. $mymps_rs = $db->query('UPDATE `' . $db_mymps . 'info_typeoptions` SET title = \'' . $title . '\' WHERE optionid = \'' . $id . '\'');
  196. write_msg('字段模型分类' . $title . '修改成功!', '?part=option_type', 'MYMPS.COM.CN');
  197. break;
  198. case 'del':
  199. empty($id) && write_msg('您还没有选定编号');
  200. $mymps_del = mymps_delete('info_typeoptions', 'WHERE optionid = \'' . $id . '\'');
  201. write_msg('字段模型分类' . $id . '删除成功!', '?part=option_type', 'WWW.MYMPS.COM.CN');
  202. break;
  203. default:
  204. $here = '字段类别管理';
  205. $sql = 'SELECT optionid,classid,title FROM `' . $db_mymps . 'info_typeoptions` WHERE classid = 0';
  206. $type = $db->getAll($sql);
  207. include mymps_tpl('info_option_type');
  208. break;
  209. }
  210. } else {
  211. if ($part == 'mod') {
  212. switch ($action) {
  213. case 'insert':
  214. empty($name) && write_msg('请填写字段模型的名称');
  215. $displayorder = trim($_POST['displayorder']) ? trim($_POST['displayorder']) : '0';
  216. $sql = 'INSERT `' . $db_mymps . 'info_typemodels` (id,name,type,displayorder) VALUES (\'\',\'' . $name . '\',\'0\',\'' . $displayorder . '\')';
  217. $db->query($sql);
  218. $mod_id = $db->insert_id();
  219. clear_cache_files('mod_search_option');
  220. clear_cache_files('mod_search_identifier');
  221. write_msg('字段模型 ' . $name . ' 增加成功! 请继续设置添加该模型所要应用的模型字段!', '?part=mod&action=edit&id=' . $mod_id, 'MyMPS.Com.cn');
  222. break;
  223. case 'update':
  224. empty($name) && write_msg('请输入字段模型的名称!');
  225. if (empty($options)) {
  226. write_msg('请至少选择一个字段!');
  227. exit;
  228. }
  229. $post_opt = !empty($options) ? implode(',', $_POST['options']) : '';
  230. $db->query('UPDATE `' . $db_mymps . 'info_typemodels` SET name=\'' . $name . '\',displayorder=\'' . $displayorder . '\',options=\'' . $post_opt . '\' WHERE id = \'' . $id . '\'');
  231. if ($db->num_rows($db->query('SHOW TABLES LIKE \'' . $db_mymps . 'information_' . $id . '\'')) == 1) {
  232. if (1 < $id) {
  233. $options2 = implode(',', $options);
  234. $query = $db->query('SELECT `identifier` FROM `' . $db_mymps . 'info_typeoptions` WHERE optionid IN (' . $options2 . ')');
  235. while ($row = $db->fetchRow($query)) {
  236. $optionsarr[] = $row['identifier'];
  237. }
  238. $columns = $db->getAll('SHOW COLUMNS FROM `' . $db_mymps . 'information_' . $id . '`');
  239. foreach ($columns as $k => $v) {
  240. if (!in_array($v['Field'], array('id', 'iid', 'content')) && !in_array($v['Field'], $optionsarr)) {
  241. $db->query('ALTER TABLE `' . $db_mymps . 'information_' . $id . '` DROP COLUMN `' . $v[Field] . '`');
  242. }
  243. }
  244. }
  245. if (is_array($options)) {
  246. $option_sql = '';
  247. foreach ($options as $k => $v) {
  248. if ($r = $db->getRow('SELECT identifier,type,rules FROM `' . $db_mymps . 'info_typeoptions` WHERE available = \'on\' AND optionid = \'' . $v . '\'')) {
  249. $identifier = $r['identifier'];
  250. $type = $r['type'];
  251. $rule = $charset == 'gbk' ? unserialize($r['rules']) : utf8_unserialize($r['rules']);
  252. if ($type == 'text') {
  253. $option_sql = ' VARCHAR(' . ($rule[maxlength] ? $rule[maxlength] : 250) . ') NOT NULL';
  254. } else {
  255. if ($type == 'textarea') {
  256. $option_sql = ' MEDIUMTEXT';
  257. } else {
  258. if ($type == 'number') {
  259. $option_sql = ' DECIMAL(10,2) NOT NULL DEFAULT \'0\'';
  260. } else {
  261. if ($type == 'radio') {
  262. $option_sql = ' TINYINT(1) NOT NULL DEFAULT \'0\'';
  263. } else {
  264. if ($type == 'checkbox') {
  265. $option_sql = ' VARCHAR(100) NOT NULL DEFAULT \'0\'';
  266. } else {
  267. if ($type == 'select') {
  268. $option_sql = ' TINYINT(1) NOT NULL DEFAULT \'0\'';
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. if (!in_array($identifier, array('iid', 'id', 'content'))) {
  276. if ($db->num_rows($db->query('SHOW COLUMNS FROM `' . $db_mymps . 'information_' . $id . '` LIKE \'' . $identifier . '\''))) {
  277. $sql = 'ALTER TABLE `' . $db_mymps . 'information_' . $id . '` CHANGE `' . $identifier . '` `' . $identifier . '` ' . $option_sql . ';';
  278. } else {
  279. $sql = 'ALTER TABLE `' . $db_mymps . 'information_' . $id . '` ADD `' . $identifier . '` ' . $option_sql . ';';
  280. }
  281. }
  282. }
  283. if (1 < $id) {
  284. $db->query($sql);
  285. }
  286. }
  287. }
  288. } else {
  289. if (is_array($options)) {
  290. $option_sql = '';
  291. foreach ($options as $k => $v) {
  292. if ($r = $db->getRow('SELECT identifier,type,rules FROM `' . $db_mymps . 'info_typeoptions` WHERE available = \'on\' AND optionid = \'' . $v . '\'')) {
  293. $identifier = $r['identifier'];
  294. $type = $r['type'];
  295. $rule = $charset == 'gbk' ? unserialize($r['rules']) : utf8_unserialize($r['rules']);
  296. if ($type == 'text') {
  297. $option_sql .= '`' . $identifier . '` VARCHAR(' . ($rule[maxlength] ? $rule[maxlength] : 250) . ') NOT NULL,';
  298. } else {
  299. if ($type == 'textarea') {
  300. $option_sql .= '`' . $identifier . '` MEDIUMTEXT,';
  301. } else {
  302. if ($type == 'number') {
  303. $option_sql .= '`' . $identifier . '` DECIMAL(10,2) NOT NULL DEFAULT \'0\',';
  304. } else {
  305. if ($type == 'radio') {
  306. $option_sql .= '`' . $identifier . '` TINYINT(1) NOT NULL DEFAULT \'0\',';
  307. } else {
  308. if ($type == 'checkbox') {
  309. $option_sql .= '`' . $identifier . '` VARCHAR(100) NOT NULL DEFAULT \'0\',';
  310. } else {
  311. if ($type == 'select') {
  312. $option_sql .= '`' . $identifier . '` TINYINT(1) NOT NULL DEFAULT \'0\',';
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. if (1 < $id) {
  323. $sqldb = '4.1' < mysql_get_server_info() ? ' DEFAULT CHARSET=' . $dbcharset . ' ' : '';
  324. $sql = 'CREATE TABLE IF NOT EXISTS `' . $db_mymps . 'information_' . $id . '` (' . "\r\n\t\t\t\t\t" . '`iid` MEDIUMINT(7) NOT NULL auto_increment,' . "\r\n\t\t\t\t\t" . '`id` INT(10) NOT NULL DEFAULT \'0\',' . "\r\n\t\t\t\t\t" . $option_sql . "\r\n\t\t\t\t\t" . '`content` MEDIUMTEXT,' . "\r\n\t\t\t\t\t" . 'PRIMARY KEY (`iid`),' . "\r\n\t\t\t\t\t" . 'KEY `id` (`id`)' . "\r\n\t\t\t\t\t" . ') ENGINE=MyISAM ' . $sqldb . ' AUTO_INCREMENT=1 ;';
  325. $db->query($sql);
  326. }
  327. }
  328. clear_cache_files('mod_search_option');
  329. clear_cache_files('mod_search_identifier');
  330. write_msg('字段模型 ' . $name . ' 修改成功', '?part=mod&action=edit&id=' . $id, 'BBS.MYMPS');
  331. break;
  332. case 'edit':
  333. $here = '字段模型设置';
  334. $edit = $db->getRow('SELECT * FROM `' . $db_mymps . 'info_typemodels` WHERE id =\'' . $id . '\'');
  335. if (!empty($edit['options'])) {
  336. $options = explode(',', $edit['options']);
  337. }
  338. $opt = get_all_options();
  339. include mymps_tpl('info_mod_edit');
  340. break;
  341. case 'delall':
  342. if (is_array($id)) {
  343. foreach ($id as $k => $v) {
  344. $db->query('DROP TABLE IF EXISTS `' . $db_mymps . 'information_' . $v . '`;');
  345. }
  346. mymps_del_all('info_typemodels', $id);
  347. clear_cache_files('mod_search_option');
  348. clear_cache_files('mod_search_identifier');
  349. write_msg('成功删除指定字段模型', '?part=mod', 'mymps');
  350. }
  351. break;
  352. default:
  353. chk_admin_purview('purview_模型管理');
  354. $here = '字段模型管理';
  355. $mod = $db->getAll('SELECT * FROM `' . $db_mymps . 'info_typemodels` ORDER BY id ASC');
  356. $rows_num = mymps_count('info_typemodels');
  357. $param = setParam(array('part'));
  358. $mod = page1('SELECT * FROM `' . $db_mymps . 'info_typemodels` ORDER BY id ASC');
  359. include mymps_tpl('info_mod');
  360. break;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. }
  367. }
  368. is_object($db) && $db->Close();
  369. $db = $mymps_global = $part = $action = $here = NULL;