event_join_modify.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /**
  3. * [超级活动(xj_event.{modulename})] (C)2012-2099 Powered by 逍遥工作室.
  4. * Version: 1.0
  5. * Date: 2012-9-15 10:27
  6. */
  7. if (!defined('IN_DISCUZ')) {
  8. exit('Access Denied');
  9. }
  10. //判断是否是安米浏览器
  11. if (strpos($_SERVER["HTTP_USER_AGENT"], 'Appbyme') > 0) {
  12. $Appbyme = true;
  13. }
  14. if (strpos($_SERVER["HTTP_USER_AGENT"], 'MAGAPP') > 0) {
  15. $magapp = true;
  16. }
  17. if (strpos($_SERVER['HTTP_USER_AGENT'], 'QianFan') > 0) {
  18. $QianFan = true;
  19. }
  20. if (!$_G['uid']) {
  21. showmessage('not_loggedin', null, array(), array('login' => 1));
  22. }
  23. //调用核心类
  24. include 'source/plugin/xj_event/include/core.class.php';
  25. $eventcore = new xj_eventcore();
  26. include 'include/sms_func.php';
  27. $tid = intval($_GET['tid']);
  28. $uid = intval($_G['uid']);
  29. $items = DB::fetch(DB::query("SELECT A.*,B.authorid,B.subject FROM " . DB::table('xj_event') . " A LEFT JOIN " . DB::table('forum_thread') . " B ON A.tid = B.tid WHERE A.tid = '$tid'"));
  30. $eid = $items['eid'];
  31. $setting = unserialize($items['setting']);
  32. //报名方式判断
  33. if ($setting['nodaibaoming']) {
  34. dheader('location: plugin.php?id=xj_event:event_join_modify_single&tid=' . $tid);
  35. }
  36. if ($_GET['action'] == 'modifyfull') {
  37. if ($_GET['formhash'] != $_G['formhash']) {
  38. showmessage('submit_invalid');
  39. }
  40. $post = file_get_contents("php://input");
  41. $post = json_decode($post, true);
  42. if ($_G['charset'] == 'gbk') {
  43. foreach ($post as $key => $value) {
  44. foreach ($value as $key2 => $value2) {
  45. $post[$key][$key2] = iconv('utf-8', 'gbk', $value2);
  46. }
  47. }
  48. }
  49. //验证手机号和身份证
  50. if (file_exists(DISCUZ_ROOT . './source/plugin/xj_event/module/checkapply/checkapply.php')) {
  51. @include 'module/checkapply/checkapply.php';
  52. }
  53. $applynumber = count($post); //本次修改后报名人数
  54. //获取已报名的人数
  55. $count = DB::result_first("SELECT count(*) FROM " . DB::table('xj_eventapply') . " WHERE tid='$tid' and uid=$uid");
  56. if ($count != $applynumber) {
  57. //如果修改的报名数比以前多
  58. if ($applynumber > $count) {
  59. //判断积分够不够
  60. $member = DB::fetch_first("SELECT extcredits1,extcredits2,extcredits3,extcredits4,extcredits5,extcredits6,extcredits7,extcredits8 FROM " . DB::table('common_member_count') . " WHERE uid = " . $_G['uid']);
  61. /*
  62. if($member['extcredits'.$items['use_extcredits']]<($items['use_extcredits_num']*($applynumber-$count))){
  63. $result['full'] = 2;
  64. $result['message'] = $_G['setting']['extcredits'][$items['use_extcredits']]['title'].lang('plugin/xj_event', 'bgwfcj');
  65. $result['message'] = $_G['charset'] == 'gbk'?iconv('gbk','utf-8',$result['message']):$result['message'];
  66. echo json_encode($result);
  67. exit;
  68. }
  69. */
  70. //验证报名名额是否够
  71. $applynum = DB::result_first("SELECT SUM(applynumber) FROM " . DB::table('xj_eventapply') . " WHERE tid='$tid' and verify=1"); //已报名人数
  72. $applycountnum = DB::result_first("SELECT event_number FROM " . DB::table('xj_event') . " WHERE tid='$tid'"); //活动总人数
  73. if ($applycountnum > 0) {
  74. if (($applynumber - $count) > ($applycountnum - $applynum)) {
  75. $result['full'] = 2;
  76. $result['message'] = $_G['charset'] == 'gbk' ? iconv('gbk', 'utf-8', lang('plugin/xj_event', 'baomrsym')) : lang('plugin/xj_event', 'baomrsym');
  77. echo json_encode($result);
  78. exit;
  79. }
  80. }
  81. }
  82. }
  83. //删除以前的报名
  84. DB::query("DELETE FROM " . DB::table('xj_eventapply') . " WHERE tid = $tid and uid = $uid");
  85. //还原积分操作
  86. /*
  87. if($items['use_extcredits_num']>0){
  88. $extnum = $items['use_extcredits_num']*$count;
  89. updatemembercount($_G['uid'],array($items['use_extcredits']=>$extnum));
  90. }
  91. */
  92. //获取活动组织人的ID
  93. $event_uid = $items['authorid'];
  94. //活动标题
  95. $event_title = $items['subject'];
  96. //活动开始时间
  97. $event_starttime = dgmdate($items['starttime'], 'dt');
  98. //报名资料入数据库
  99. $first = 1;
  100. if ($setting['myuserfield']) {
  101. $myuserfield = $eventcore->GetUserField($setting['myuserfield']); //新报名字段
  102. }
  103. foreach ($post as $key => $value) {
  104. $ufielddata = array();
  105. foreach ($value as $key2 => $value2) {
  106. if ($key2 != 'message' && $key2 != 'session') {
  107. $ufielddata[$key2] = $value2;
  108. }
  109. }
  110. //新的报名字段的报名资料入数据库
  111. foreach ($myuserfield as $val) {
  112. $ufielddata['myfield' . $val['id']] = $value['myfield' . $val['id']];
  113. }
  114. $ufielddata = serialize($ufielddata);
  115. $eventapply = array();
  116. $eventapply['tid'] = $tid;
  117. $eventapply['eid'] = $items['eid'];
  118. $eventapply['uid'] = $uid;
  119. $eventapply['realname'] = addslashes($value['realname']);
  120. $eventapply['qq'] = addslashes($value['qq']);
  121. $eventapply['mobile'] = addslashes($value['mobile']);
  122. $eventapply['bmmessage'] = addslashes($value['message']);
  123. $eventapply['dateline'] = $_G['timestamp'];
  124. $eventapply['applynumber'] = 1;
  125. $eventapply['ufielddata'] = $ufielddata;
  126. $eventapply['seccode'] = random(8, 1);
  127. $eventapply['session'] = intval($value['session']);
  128. $eventapply['first'] = $first;
  129. DB::insert('xj_eventapply', $eventapply);
  130. $first = 0; //代报名的是0
  131. }
  132. //用户活动相关的信息数据表是否存在,不存在就新建
  133. $num = DB::result_first("SELECT count(*) FROM " . DB::table('xj_event_member_info') . " WHERE uid = '$uid'");
  134. if ($num == 0) {
  135. DB::query("INSERT INTO " . DB::table('xj_event_member_info') . " (uid) VALUES ('$uid')");
  136. }
  137. //积分操作
  138. /*
  139. if($items['use_extcredits_num']>0){
  140. $extnum = $items['use_extcredits_num'] * $applynumber;
  141. updatemembercount($_G['uid'],array($items['use_extcredits']=>-$extnum));
  142. }
  143. */
  144. //发通知
  145. notification_add($event_uid, 'system', 'activity_notice', array('tid' => $tid, 'subject' => $event_title));
  146. $result['full'] = 1;
  147. $result['message'] = lang('plugin/xj_event', 'bmzlxgcg');
  148. $result['message'] = $_G['charset'] == 'gbk' ? iconv('gbk', 'utf-8', $result['message']) : $result['message'];
  149. $result['url'] = "forum.php?mod=viewthread&tid=$tid";
  150. echo json_encode($result);
  151. exit;
  152. }
  153. //用户报名资料
  154. $apply = DB::fetch_all("SELECT * FROM " . DB::table('xj_eventapply') . " WHERE tid=$tid AND uid=$uid ORDER BY first DESC");
  155. foreach ($apply as $key => $value) {
  156. $apply[$key]['ufielddata'] = unserialize($value['ufielddata']);
  157. }
  158. //报名数
  159. $applynumber = count($apply);
  160. //下一个TAB序号
  161. $tabCounter = $applynumber + 1;
  162. //获取用户报名字段
  163. if ($_G['mobile']) {
  164. $userfield = unserialize($items['userfield']);
  165. $selectuserfield = unserialize($items['userfield']);
  166. if ($selectuserfield) {
  167. if ($selectuserfield) {
  168. $htmls = $settings = array();
  169. require_once libfile('function/profile');
  170. foreach ($selectuserfield as $fieldid) {
  171. /*
  172. if(empty($ufielddata['userfield'])) {
  173. $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
  174. foreach($selectuserfield as $val) {
  175. if($val == 'birthday'){
  176. $ufielddata['userfield']['birthyear'] = $memberprofile['birthyear'];
  177. $ufielddata['userfield']['birthmonth'] = $memberprofile['birthmonth'];
  178. }
  179. $ufielddata['userfield'][$val] = $memberprofile[$val];
  180. }
  181. unset($memberprofile);
  182. }
  183. */
  184. $html = profile_setting($fieldid, $ufielddata['userfield'], false, true);
  185. if ($fieldid == 'birthday') {
  186. $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
  187. $mybirthday = $memberprofile['birthyear'] . '-' . $memberprofile['birthmonth'] . '-' . $memberprofile['birthday'];
  188. $mybirthday = strtotime($mybirthday);
  189. $mybirthday = date("Y-m-d", $mybirthday);
  190. $html = '<input name="birthday" type="date" id="birthday" value="' . $mybirthday . '" class="join_text" />';
  191. }
  192. if ($fieldid == 'residecity') {
  193. $html = '<div><input type="hidden" name="residecity" value=""><span></span> <button class="residecity ui-btn">' . lang('plugin/xj_event', 'select') . '</button><span></span></div>';
  194. }
  195. if ($html) {
  196. if (strpos($html, 'checkbox') > 0) {
  197. $html = '<fieldset data-role="controlgroup">' . $html . '</fieldset>';
  198. $html = str_replace(' class="lb"', '', $html);
  199. //echo $html;
  200. //exit();
  201. }
  202. //下拉列表
  203. if (strpos($html, 'select name=') > 0 && strpos($html, 'name="birthprovince"') < 1) {
  204. if (strpos($html, 'name="gender"') > 0) {
  205. preg_match('/name\=\"(.+?)\"/i', $html, $selectname);
  206. preg_match_all('/value\=\"(.+?)\"/i', $html, $optionvalue);
  207. preg_match_all('/\"\>(.+?)\<\/op/i', $html, $optiontext);
  208. $html = '<div class="xjselect"><input type="hidden" name="' . $selectname[1] . '" id="' . $selectname[1] . '" value="">';
  209. foreach ($optionvalue[1] as $opkey => $opvalue) {
  210. $html .= '<span data-value="' . $opvalue . '" style="background-color:#ccc; font-size:14px; padding:3px 12px; color:#FFF; border-radius:4px; margin-bottom:5px; margin-right:5px; float:left;font-weight:normal; text-shadow:none;">' . $optiontext[1][$opkey] . '</span>';
  211. }
  212. $html .= '</div><div style="clear:both;"></div>';
  213. } else {
  214. preg_match('/name\=\"(.+?)\"/i', $html, $selectname);
  215. preg_match_all('/value\=\"(.+?)\"/i', $html, $optionvalue);
  216. $html = '<div class="xjselect"><input type="hidden" name="' . $selectname[1] . '" id="' . $selectname[1] . '" value="">';
  217. foreach ($optionvalue[1] as $opvalue) {
  218. $html .= '<span data-value="' . $opvalue . '" style="background-color:#ccc; font-size:14px; padding:3px 12px; color:#FFF; border-radius:4px; margin-bottom:5px; margin-right:5px; float:left;font-weight:normal; text-shadow:none;">' . $opvalue . '</span>';
  219. }
  220. $html .= '</div><div style="clear:both;"></div>';
  221. }
  222. }
  223. $html = preg_replace("/<div class=\"rq mtn\" id=\"showerror.+<\/div>/is", "", $html);
  224. if (strpos($html, 'type="text"') > 0) {
  225. $html = str_replace('class="px"', 'class="join_text"', $html);
  226. }
  227. $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
  228. $htmls[$fieldid] = $html;
  229. }
  230. }
  231. }
  232. } else {
  233. $selectuserfield = '';
  234. }
  235. } else {
  236. $userfield = unserialize($items['userfield']);
  237. $selectuserfield = unserialize($items['userfield']);
  238. if ($selectuserfield) {
  239. if ($selectuserfield) {
  240. $htmls = $settings = array();
  241. require_once libfile('function/profile');
  242. foreach ($selectuserfield as $fieldid) {
  243. /*
  244. if(empty($ufielddata['userfield'])) {
  245. $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
  246. foreach($selectuserfield as $val) {
  247. if($val == 'birthday'){
  248. $ufielddata['userfield']['birthyear'] = $memberprofile['birthyear'];
  249. $ufielddata['userfield']['birthmonth'] = $memberprofile['birthmonth'];
  250. }
  251. $ufielddata['userfield'][$val] = $memberprofile[$val];
  252. }
  253. unset($memberprofile);
  254. }
  255. */
  256. $html = profile_setting($fieldid, $ufielddata['userfield'], false, true);
  257. //$html = preg_replace('/value\=\"(.+?)\"/i','value=""',$html);
  258. if ($fieldid == 'birthday') {
  259. $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
  260. $mybirthday = $memberprofile['birthyear'] . '-' . $memberprofile['birthmonth'] . '-' . $memberprofile['birthday'];
  261. $html = '<div style="height:36px;"><input name="birthday" type="text" value="' . $mybirthday . '" class="dateselect" /><div></div></div>';
  262. }
  263. if ($fieldid == 'residecity') {
  264. $html = '<div style="height:36px;"><input type="hidden" name="residecity" value=""><span></span> <button class="residecity">' . lang('plugin/xj_event', 'select') . '</button><span></span></div>';
  265. }
  266. if ($html) {
  267. $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
  268. $htmls[$fieldid] = $html;
  269. }
  270. }
  271. }
  272. } else {
  273. $selectuserfield = '';
  274. }
  275. }
  276. //checkbox处理
  277. foreach ($apply as $key => $value) {
  278. if (!empty($selectuserfield)) {
  279. foreach ($selectuserfield as $fieldid) {
  280. if ($settings[$fieldid]['available']) {
  281. if ($settings[$fieldid]['formtype'] == 'checkbox') {
  282. $apply[$key]['ufielddata'][$fieldid] = $htmls[$fieldid];
  283. $tmp = explode(',', $value['ufielddata'][$fieldid]);
  284. foreach ($tmp as $cbvalue) {
  285. $apply[$key]['ufielddata'][$fieldid] = str_replace($cbvalue . '"', $cbvalue . '" checked', $apply[$key]['ufielddata'][$fieldid]);
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. //过滤掉自动填入的数据
  293. /*
  294. foreach($htmls as $key=>$value){
  295. $htmls[$key] = preg_replace("/value=\"[^\"]+\"/", "value=\"\"", $value);
  296. }
  297. */
  298. //新的报名字段
  299. if ($setting['myuserfield']) {
  300. $myuserfield = $eventcore->GetUserField($setting['myuserfield']);
  301. foreach ($apply as $key => $value) {
  302. $apply[$key]['myuserfield'] = $eventcore->GetUserField($setting['myuserfield'], $value['ufielddata']);
  303. }
  304. }
  305. include template('xj_event:event_join_modify');