人人商城

module.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. class MusicModule extends WeModule {
  8. public $tablename = 'music_reply';
  9. public function fieldsFormDisplay($rid = 0) {
  10. global $_W;
  11. load()->func('tpl');
  12. if (!empty($rid)) {
  13. $replies = pdo_fetchall("SELECT * FROM ".tablename($this->tablename)." WHERE rid = :rid ORDER BY `id` ASC", array(':rid' => $rid));
  14. $replies = istripslashes($replies);
  15. }
  16. include $this->template('form');
  17. }
  18. public function fieldsFormValidate($rid = 0) {
  19. global $_GPC;
  20. if(empty($_GPC['title'])) {
  21. return '必须填写有效的回复内容.';
  22. }
  23. foreach($_GPC['title'] as $k => $v) {
  24. $row = array();
  25. $row['title'] = $v;
  26. $row['url'] = $_GPC['url'][$k];
  27. $row['hqurl'] = $_GPC['hqurl'][$k];
  28. $row['description'] = $_GPC['description'][$k];
  29. $this->replies[] = $row;
  30. }
  31. if(empty($this->replies)) {
  32. return '必须填写有效的回复内容.';
  33. }
  34. foreach($this->replies as &$r) {
  35. if(trim($r['title']) == '' || (trim($r['url']) == '' && trim($r['hqurl']) == '')) {
  36. return '必须填写有效的回复内容.';
  37. }
  38. $r['description'] = htmlspecialchars_decode($r['description']);
  39. }
  40. return '';
  41. }
  42. public function fieldsFormSubmit($rid = 0) {
  43. global $_GPC, $_W;
  44. pdo_delete($this->tablename, array('rid' => $rid));
  45. foreach($this->replies as $reply) {
  46. $reply['rid'] = $rid;
  47. pdo_insert($this->tablename, $reply);
  48. }
  49. return true;
  50. }
  51. public function ruleDeleted($rid = 0) {
  52. global $_W;
  53. $replies = pdo_getall($this->tablename, array('rid' => $rid));
  54. $deleteid = array();
  55. if (!empty($replies)) {
  56. foreach ($replies as $index => $row) {
  57. $deleteid[] = $row['id'];
  58. }
  59. }
  60. pdo_delete($this->tablename, array('id' => $deleteid));
  61. return true;
  62. }
  63. public function doFormDisplay() {
  64. global $_W, $_GPC;
  65. $result = array('error' => 0, 'message' => '', 'content' => '');
  66. $result['content']['id'] = $GLOBALS['id'] = 'add-row-news-'.$_W['timestamp'];
  67. $result['content']['html'] = $this->template('item', TEMPLATE_FETCH);
  68. exit(json_encode($result));
  69. }
  70. public function doUploadMusic() {
  71. global $_W;
  72. checklogin();
  73. if (empty($_FILES['attachFile']['name'])) {
  74. $result['message'] = '请选择要上传的音乐!';
  75. exit(json_encode($result));
  76. }
  77. if ($_FILES['attachFile']['error'] != 0) {
  78. $result['message'] = '上传失败,请重试!';
  79. exit(json_encode($result));
  80. }
  81. if ($file = $this->fileUpload($_FILES['attachFile'], 'music')) {
  82. if (!$file['success']) {
  83. exit(json_encode($file));
  84. }
  85. $result['url'] = $_W['config']['upload']['attachdir'] . $file['path'];
  86. $result['error'] = 0;
  87. $result['filename'] = $file['path'];
  88. exit(json_encode($result));
  89. }
  90. }
  91. public function doDelete() {
  92. global $_W,$_GPC;
  93. $id = intval($_GPC['id']);
  94. $sql = "SELECT id, rid, url, hqurl FROM " . tablename($this->tablename) . " WHERE `id`=:id";
  95. $row = pdo_fetch($sql, array(':id'=>$id));
  96. if (empty($row)) {
  97. itoast('抱歉,回复不存在或是已经被删除!', '', 'error');
  98. }
  99. if (pdo_delete($this->tablename, array('id' => $id))) {
  100. itoast('删除回复成功', '', 'success');
  101. }
  102. }
  103. private function fileUpload($file, $type) {
  104. global $_W;
  105. set_time_limit(0);
  106. $_W['uploadsetting'] = array();
  107. $_W['uploadsetting']['music']['folder'] = 'music';
  108. $_W['uploadsetting']['music']['extentions'] = array('mp3', 'wma', 'wav', 'amr');
  109. $_W['uploadsetting']['music']['limit'] = 50000;
  110. $result = array();
  111. $upload = file_upload($file, 'music');
  112. if (is_error($upload)) {
  113. iajax(1, $upload['message']);
  114. }
  115. $result['url'] = $upload['url'];
  116. $result['error'] = 0;
  117. $result['filename'] = $upload['path'];
  118. return $result;
  119. }
  120. }