人人商城

fields.ctrl.php 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $dos = array('display', 'post');
  8. $do = in_array($do, $dos) ? $do : 'display';
  9. if ($do == 'display') {
  10. $_W['page']['title'] = '字段管理 - 用户管理';
  11. $table = table('core_profile_fields');
  12. $keyword = safe_gpc_string($_GPC['keyword']);
  13. if (!empty($keyword)) {
  14. $table->searchKeyword($keyword);
  15. }
  16. if (checksubmit('submit')) {
  17. if (!empty($_GPC['displayorder'])) {
  18. foreach ($_GPC['displayorder'] as $id => $displayorder) {
  19. pdo_update('profile_fields', array(
  20. 'displayorder' => intval($displayorder),
  21. 'available' => intval($_GPC['available'][$id]),
  22. 'showinregister' => intval($_GPC['showinregister'][$id]),
  23. 'required' => intval($_GPC['required'][$id]),
  24. ), array('id' => $id));
  25. }
  26. }
  27. itoast('资料设置更新成功!', referer(), 'success');
  28. }
  29. $fields = $table->getFieldsList();
  30. template('user/fields-display');
  31. }
  32. if ($do == 'post') {
  33. $_W['page']['title'] = '编辑字段 - 用户管理';
  34. $id = intval($_GPC['id']);
  35. if (checksubmit('submit')) {
  36. if (empty($_GPC['title'])) {
  37. itoast('抱歉,请填写资料名称!', '', '');
  38. }
  39. if (empty($_GPC['field'])) {
  40. itoast('请填写字段名!', '', '');
  41. }
  42. if (!preg_match('/^[A-Za-z0-9_]*$/', $_GPC['field'])) {
  43. itoast('请使用字母或数字或下划线组合字段名!', '', '');
  44. }
  45. $data = array(
  46. 'title' => $_GPC['title'],
  47. 'description' => $_GPC['description'],
  48. 'displayorder' => intval($_GPC['displayorder']),
  49. 'available' => intval($_GPC['available']),
  50. 'unchangeable' => intval($_GPC['unchangeable']),
  51. 'showinregister' => intval($_GPC['showinregister']),
  52. 'required' => intval($_GPC['required']),
  53. 'field' => safe_gpc_string($_GPC['field']),
  54. 'field_length' => intval($_GPC['length'])
  55. );
  56. $length = intval($_GPC['length']);
  57. if (empty($id)) {
  58. pdo_insert('profile_fields', $data);
  59. if (!pdo_fieldexists('users_profile', $data['field'])) {
  60. pdo_query("ALTER TABLE ". tablename('users_profile'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  61. }
  62. if (!pdo_fieldexists('mc_members', $data['field'])) {
  63. pdo_query("ALTER TABLE ". tablename('mc_members'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  64. }
  65. } else {
  66. if (!pdo_fieldexists('users_profile', $data['field'])) {
  67. pdo_query("ALTER TABLE ". tablename('users_profile'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  68. } else {
  69. pdo_query("ALTER TABLE ". tablename('users_profile'). " CHANGE `". $data['field']. "` `". $data['field']."` varchar({$length}) NOT NULL default ''");
  70. }
  71. if (!pdo_fieldexists('mc_members', $data['field'])) {
  72. pdo_query("ALTER TABLE ". tablename('mc_members'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  73. } else {
  74. pdo_query("ALTER TABLE ". tablename('mc_members'). " CHANGE `". $data['field']. "` `". $data['field']."` varchar({$length}) NOT NULL default ''");
  75. }
  76. pdo_update('profile_fields', $data, array('id' => $id));
  77. }
  78. itoast('更新字段成功!', url('user/fields'), 'success');
  79. }
  80. if (!empty($id)) {
  81. $item = pdo_get('profile_fields', array('id' => $id));
  82. }
  83. template('user/fields-post');
  84. }