inc_coupon.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. if (!defined('IN_MYMPS')) {
  3. exit('Forbidden');
  4. }
  5. $ac = in_array($ac, array('list', 'detail')) ? $ac : 'list';
  6. if (submit_check('coupon_submit')) {
  7. if (is_array($selectedids)) {
  8. $create_in = create_in($selectedids);
  9. $query = $db->query('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' AND id ' . $create_in);
  10. while ($row = $db->fetchRow($query)) {
  11. $delete[$row['id']]['picture'] = $row['picture'];
  12. $delete[$row['id']]['pre_picture'] = $row['pre_picture'];
  13. }
  14. foreach ($delete as $k => $v) {
  15. @unlink(MYMPS_ROOT . $v['picture']);
  16. @unlink(MYMPS_ROOT . $v['pre_picture']);
  17. }
  18. $db->query('DELETE FROM `' . $db_mymps . 'coupon` ' . $where . ' AND id ' . $create_in);
  19. unset($delete);
  20. unset($row);
  21. unset($query);
  22. unset($create_in);
  23. write_msg('', '?m=coupon&type=corp&success=3&status=' . $status . '&page=' . $page);
  24. }
  25. include MYMPS_DATA . '/config.inc.php';
  26. $name_file = 'coupon_image';
  27. $title = trim($title);
  28. $content = trim($content);
  29. $des = textarea_post_change($des);
  30. $cate_id = intval($cate_id);
  31. $areaid = intval($areaid);
  32. $begindate = intval(strtotime($begindate));
  33. $enddate = intval(strtotime($enddate));
  34. $status = isset($status) ? intval($status) : '';
  35. if (empty($title)) {
  36. write_msg('', '?m=coupon&type=corp&ac=detail&error=37&id=' . $id);
  37. }
  38. if (empty($content)) {
  39. write_msg('', '?m=coupon&type=corp&ac=detail&error=35&id=' . $id);
  40. }
  41. if (empty($id) && !$_FILES[$name_file]) {
  42. write_msg('', '?m=coupon&type=corp&ac=detail&error=36&id=' . $id);
  43. }
  44. if ($_FILES[$name_file]['name']) {
  45. require_once MYMPS_INC . '/upfile.fun.php';
  46. check_upimage($name_file);
  47. $destination = '/coupon/' . date('Ym') . '/';
  48. $mymps_image = empty($id) ? start_upload($name_file, $destination, 0, $mymps_mymps['cfg_coupon_limit']['width'], $mymps_mymps['cfg_coupon_limit']['height']) : start_upload($name_file, $destination, 0, $mymps_mymps['cfg_coupon_limit']['width'], $mymps_mymps['cfg_coupon_limit']['height'], $picture, $pre_picture);
  49. $picture = $mymps_image[0];
  50. $pre_picture = $mymps_image[1];
  51. unset($mymps_image);
  52. }
  53. if (empty($id)) {
  54. $db->query('INSERT INTO `' . $db_mymps . 'coupon` (title,des,content,pre_picture,picture,cate_id,areaid,begindate,enddate,userid,dateline,ctype,sup,status) VALUES (\'' . $title . '\',\'' . $des . '\',\'' . $content . '\',\'' . $pre_picture . '\',\'' . $picture . '\',\'' . $cate_id . '\',\'' . $areaid . '\',\'' . $begindate . '\',\'' . $enddate . '\',\'' . $s_uid . '\',\'' . $timestamp . '\',\'' . $ctype . '\',\'' . $sup . '\',\'' . $status . '\')');
  55. $score_change = get_credit_score();
  56. $score_changer = $score_change['score']['rank']['coupon'];
  57. $db->query('UPDATE `' . $db_mymps . 'member` SET score = score' . $score_changer . (' WHERE userid = \'' . $s_uid . '\''));
  58. $score_change = $score_changer = NULL;
  59. $url = '?m=coupon&type=corp&success=8&ac=detail&id=' . $id . '&alert=2';
  60. }
  61. else {
  62. $db->query('UPDATE `' . $db_mymps . 'coupon` SET title = \'' . $title . '\',des = \'' . $des . '\',content = \'' . $content . '\',cate_id = \'' . $cate_id . '\',areaid = \'' . $areaid . '\',picture=\'' . $picture . '\',pre_picture=\'' . $pre_picture . '\',begindate = \'' . $begindate . '\',enddate=\'' . $enddate . '\', dateline = \'' . $timestamp . '\' , ctype = \'' . $ctype . '\' , sup = \'' . $sup . '\' , status = \'' . $status . '\' ' . $where . ' AND id = \'' . $id . '\'');
  63. }
  64. write_msg('', $url ? $url : '?m=coupon&type=corp&success=8&ac=detail&id=' . $id);
  65. }
  66. else {
  67. if ($ac == 'list') {
  68. $status = isset($_GET['status']) ? $_GET['status'] : '';
  69. if (!in_array($status, array('yes', 'no')) || empty($status)) {
  70. $status = 'yes';
  71. }
  72. $where .= $status == 'yes' ? ' AND status = \'1\'' : ' AND status = \'0\'';
  73. $rows_num = mymps_count('coupon', $where);
  74. $param = setParam(array('m', 'type', 'ac', 'status'));
  75. $coupon = page1('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY dateline DESC');
  76. }
  77. else if ($ac == 'detail') {
  78. require_once MYMPS_ROOT . '/plugin/coupon/include/functions.php';
  79. require_once MYMPS_INC . '/class.fun.php';
  80. if ($id) {
  81. $edit = $db->getRow('SELECT * FROM `' . $db_mymps . 'coupon` WHERE id = \'' . $id . '\'');
  82. $begindate = date('Y-m-d', $edit['begindate']);
  83. $enddate = date('Y-m-d', $edit['enddate']);
  84. $edit['des'] = de_textarea_post_change($edit['des']);
  85. }
  86. $acontent = get_editor('content', 'Member', $edit['content'], '90%', '250px');
  87. }
  88. $location = location('corp');
  89. include mymps_tpl('coupon_' . $ac);
  90. }
  91. ?>