fields.ctrl.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $condition = '' ;
  12. $params = array();
  13. if (!empty($_GPC['keyword'])) {
  14. $condition .= " WHERE title LIKE :title";
  15. $params[':title'] = "%{$_GPC['keyword']}%";
  16. }
  17. if (checksubmit('submit')) {
  18. if (!empty($_GPC['displayorder'])) {
  19. foreach ($_GPC['displayorder'] as $id => $displayorder) {
  20. pdo_update('profile_fields', array(
  21. 'displayorder' => intval($displayorder),
  22. 'available' => intval($_GPC['available'][$id]),
  23. 'showinregister' => intval($_GPC['showinregister'][$id]),
  24. 'required' => intval($_GPC['required'][$id]),
  25. ), array('id' => $id));
  26. }
  27. }
  28. itoast('资料设置更新成功!', referer(), 'success');
  29. }
  30. $sql = "SELECT * FROM " . tablename('profile_fields'). $condition ." ORDER BY displayorder DESC";
  31. $fields = pdo_fetchall($sql, $params);
  32. template('user/fields-display');
  33. }
  34. if ($do == 'post') {
  35. $_W['page']['title'] = '编辑字段 - 用户管理';
  36. $id = intval($_GPC['id']);
  37. if (checksubmit('submit')) {
  38. if (empty($_GPC['title'])) {
  39. itoast('抱歉,请填写资料名称!', '', '');
  40. }
  41. if (empty($_GPC['field'])) {
  42. itoast('请填写字段名!', '', '');
  43. }
  44. if (!preg_match('/^[A-Za-z0-9_]*$/', $_GPC['field'])) {
  45. itoast('请使用字母或数字或下划线组合字段名!', '', '');
  46. }
  47. $data = array(
  48. 'title' => $_GPC['title'],
  49. 'description' => $_GPC['description'],
  50. 'displayorder' => intval($_GPC['displayorder']),
  51. 'available' => intval($_GPC['available']),
  52. 'unchangeable' => intval($_GPC['unchangeable']),
  53. 'showinregister' => intval($_GPC['showinregister']),
  54. 'required' => intval($_GPC['required']),
  55. 'field' => trim($_GPC['field']),
  56. 'field_length' => intval($_GPC['length'])
  57. );
  58. $length = intval($_GPC['length']);
  59. if (empty($id)) {
  60. pdo_insert('profile_fields', $data);
  61. if (!pdo_fieldexists('users_profile', $data['field'])) {
  62. pdo_query("ALTER TABLE ". tablename('users_profile'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  63. }
  64. if (!pdo_fieldexists('mc_members', $data['field'])) {
  65. pdo_query("ALTER TABLE ". tablename('mc_members'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  66. }
  67. } else {
  68. if (!pdo_fieldexists('users_profile', $data['field'])) {
  69. pdo_query("ALTER TABLE ". tablename('users_profile'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  70. } else {
  71. pdo_query("ALTER TABLE ". tablename('users_profile'). " CHANGE `". $data['field']. "` `". $data['field']."` varchar({$length}) NOT NULL default ''");
  72. }
  73. if (!pdo_fieldexists('mc_members', $data['field'])) {
  74. pdo_query("ALTER TABLE ". tablename('mc_members'). " ADD `". $data['field']."` varchar({$length}) NOT NULL default '';");
  75. } else {
  76. pdo_query("ALTER TABLE ". tablename('mc_members'). " CHANGE `". $data['field']. "` `". $data['field']."` varchar({$length}) NOT NULL default ''");
  77. }
  78. pdo_update('profile_fields', $data, array('id' => $id));
  79. }
  80. itoast('更新字段成功!', url('user/fields'), 'success');
  81. }
  82. if (!empty($id)) {
  83. $item = pdo_fetch("SELECT * FROM ".tablename('profile_fields')." WHERE id = :id", array(':id' => $id));
  84. }
  85. template('user/fields-post');
  86. }