123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- /**
- * [超级活动(xj_event.{modulename})] (C)2012-2099 Powered by 逍遥工作室.
- * Version: 1.0
- * Date: 2012-9-15 10:27
- */
- if (!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- //判断是否是安米浏览器
- if (strpos($_SERVER["HTTP_USER_AGENT"], 'Appbyme') > 0) {
- $Appbyme = true;
- }
- if (strpos($_SERVER["HTTP_USER_AGENT"], 'MAGAPP') > 0) {
- $magapp = true;
- }
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'QianFan') > 0) {
- $QianFan = true;
- }
- if (!$_G['uid']) {
- showmessage('not_loggedin', null, array(), array('login' => 1));
- }
- //调用核心类
- include 'source/plugin/xj_event/include/core.class.php';
- $eventcore = new xj_eventcore();
- include 'include/sms_func.php';
- $tid = intval($_GET['tid']);
- $uid = intval($_G['uid']);
- $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'"));
- $eid = $items['eid'];
- $setting = unserialize($items['setting']);
- //报名方式判断
- if ($setting['nodaibaoming']) {
- dheader('location: plugin.php?id=xj_event:event_join_modify_single&tid=' . $tid);
- }
- if ($_GET['action'] == 'modifyfull') {
- if ($_GET['formhash'] != $_G['formhash']) {
- showmessage('submit_invalid');
- }
- $post = file_get_contents("php://input");
- $post = json_decode($post, true);
- if ($_G['charset'] == 'gbk') {
- foreach ($post as $key => $value) {
- foreach ($value as $key2 => $value2) {
- $post[$key][$key2] = iconv('utf-8', 'gbk', $value2);
- }
- }
- }
- //验证手机号和身份证
- if (file_exists(DISCUZ_ROOT . './source/plugin/xj_event/module/checkapply/checkapply.php')) {
- @include 'module/checkapply/checkapply.php';
- }
- $applynumber = count($post); //本次修改后报名人数
- //获取已报名的人数
- $count = DB::result_first("SELECT count(*) FROM " . DB::table('xj_eventapply') . " WHERE tid='$tid' and uid=$uid");
- if ($count != $applynumber) {
- //如果修改的报名数比以前多
- if ($applynumber > $count) {
- //判断积分够不够
- $member = DB::fetch_first("SELECT extcredits1,extcredits2,extcredits3,extcredits4,extcredits5,extcredits6,extcredits7,extcredits8 FROM " . DB::table('common_member_count') . " WHERE uid = " . $_G['uid']);
- /*
- if($member['extcredits'.$items['use_extcredits']]<($items['use_extcredits_num']*($applynumber-$count))){
- $result['full'] = 2;
- $result['message'] = $_G['setting']['extcredits'][$items['use_extcredits']]['title'].lang('plugin/xj_event', 'bgwfcj');
- $result['message'] = $_G['charset'] == 'gbk'?iconv('gbk','utf-8',$result['message']):$result['message'];
- echo json_encode($result);
- exit;
- }
- */
- //验证报名名额是否够
- $applynum = DB::result_first("SELECT SUM(applynumber) FROM " . DB::table('xj_eventapply') . " WHERE tid='$tid' and verify=1"); //已报名人数
- $applycountnum = DB::result_first("SELECT event_number FROM " . DB::table('xj_event') . " WHERE tid='$tid'"); //活动总人数
- if ($applycountnum > 0) {
- if (($applynumber - $count) > ($applycountnum - $applynum)) {
- $result['full'] = 2;
- $result['message'] = $_G['charset'] == 'gbk' ? iconv('gbk', 'utf-8', lang('plugin/xj_event', 'baomrsym')) : lang('plugin/xj_event', 'baomrsym');
- echo json_encode($result);
- exit;
- }
- }
- }
- }
- //删除以前的报名
- DB::query("DELETE FROM " . DB::table('xj_eventapply') . " WHERE tid = $tid and uid = $uid");
- //还原积分操作
- /*
- if($items['use_extcredits_num']>0){
- $extnum = $items['use_extcredits_num']*$count;
- updatemembercount($_G['uid'],array($items['use_extcredits']=>$extnum));
- }
- */
- //获取活动组织人的ID
- $event_uid = $items['authorid'];
- //活动标题
- $event_title = $items['subject'];
- //活动开始时间
- $event_starttime = dgmdate($items['starttime'], 'dt');
- //报名资料入数据库
- $first = 1;
- if ($setting['myuserfield']) {
- $myuserfield = $eventcore->GetUserField($setting['myuserfield']); //新报名字段
- }
- foreach ($post as $key => $value) {
- $ufielddata = array();
- foreach ($value as $key2 => $value2) {
- if ($key2 != 'message' && $key2 != 'session') {
- $ufielddata[$key2] = $value2;
- }
- }
- //新的报名字段的报名资料入数据库
- foreach ($myuserfield as $val) {
- $ufielddata['myfield' . $val['id']] = $value['myfield' . $val['id']];
- }
- $ufielddata = serialize($ufielddata);
- $eventapply = array();
- $eventapply['tid'] = $tid;
- $eventapply['eid'] = $items['eid'];
- $eventapply['uid'] = $uid;
- $eventapply['realname'] = addslashes($value['realname']);
- $eventapply['qq'] = addslashes($value['qq']);
- $eventapply['mobile'] = addslashes($value['mobile']);
- $eventapply['bmmessage'] = addslashes($value['message']);
- $eventapply['dateline'] = $_G['timestamp'];
- $eventapply['applynumber'] = 1;
- $eventapply['ufielddata'] = $ufielddata;
- $eventapply['seccode'] = random(8, 1);
- $eventapply['session'] = intval($value['session']);
- $eventapply['first'] = $first;
- DB::insert('xj_eventapply', $eventapply);
- $first = 0; //代报名的是0
- }
- //用户活动相关的信息数据表是否存在,不存在就新建
- $num = DB::result_first("SELECT count(*) FROM " . DB::table('xj_event_member_info') . " WHERE uid = '$uid'");
- if ($num == 0) {
- DB::query("INSERT INTO " . DB::table('xj_event_member_info') . " (uid) VALUES ('$uid')");
- }
- //积分操作
- /*
- if($items['use_extcredits_num']>0){
- $extnum = $items['use_extcredits_num'] * $applynumber;
- updatemembercount($_G['uid'],array($items['use_extcredits']=>-$extnum));
- }
- */
- //发通知
- notification_add($event_uid, 'system', 'activity_notice', array('tid' => $tid, 'subject' => $event_title));
- $result['full'] = 1;
- $result['message'] = lang('plugin/xj_event', 'bmzlxgcg');
- $result['message'] = $_G['charset'] == 'gbk' ? iconv('gbk', 'utf-8', $result['message']) : $result['message'];
- $result['url'] = "forum.php?mod=viewthread&tid=$tid";
- echo json_encode($result);
- exit;
- }
- //用户报名资料
- $apply = DB::fetch_all("SELECT * FROM " . DB::table('xj_eventapply') . " WHERE tid=$tid AND uid=$uid ORDER BY first DESC");
- foreach ($apply as $key => $value) {
- $apply[$key]['ufielddata'] = unserialize($value['ufielddata']);
- }
- //报名数
- $applynumber = count($apply);
- //下一个TAB序号
- $tabCounter = $applynumber + 1;
- //获取用户报名字段
- if ($_G['mobile']) {
- $userfield = unserialize($items['userfield']);
- $selectuserfield = unserialize($items['userfield']);
- if ($selectuserfield) {
- if ($selectuserfield) {
- $htmls = $settings = array();
- require_once libfile('function/profile');
- foreach ($selectuserfield as $fieldid) {
- /*
- if(empty($ufielddata['userfield'])) {
- $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
- foreach($selectuserfield as $val) {
- if($val == 'birthday'){
- $ufielddata['userfield']['birthyear'] = $memberprofile['birthyear'];
- $ufielddata['userfield']['birthmonth'] = $memberprofile['birthmonth'];
- }
- $ufielddata['userfield'][$val] = $memberprofile[$val];
- }
- unset($memberprofile);
- }
- */
- $html = profile_setting($fieldid, $ufielddata['userfield'], false, true);
- if ($fieldid == 'birthday') {
- $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
- $mybirthday = $memberprofile['birthyear'] . '-' . $memberprofile['birthmonth'] . '-' . $memberprofile['birthday'];
- $mybirthday = strtotime($mybirthday);
- $mybirthday = date("Y-m-d", $mybirthday);
- $html = '<input name="birthday" type="date" id="birthday" value="' . $mybirthday . '" class="join_text" />';
- }
- if ($fieldid == 'residecity') {
- $html = '<div><input type="hidden" name="residecity" value=""><span></span> <button class="residecity ui-btn">' . lang('plugin/xj_event', 'select') . '</button><span></span></div>';
- }
- if ($html) {
- if (strpos($html, 'checkbox') > 0) {
- $html = '<fieldset data-role="controlgroup">' . $html . '</fieldset>';
- $html = str_replace(' class="lb"', '', $html);
- //echo $html;
- //exit();
- }
- //下拉列表
- if (strpos($html, 'select name=') > 0 && strpos($html, 'name="birthprovince"') < 1) {
- if (strpos($html, 'name="gender"') > 0) {
- preg_match('/name\=\"(.+?)\"/i', $html, $selectname);
- preg_match_all('/value\=\"(.+?)\"/i', $html, $optionvalue);
- preg_match_all('/\"\>(.+?)\<\/op/i', $html, $optiontext);
- $html = '<div class="xjselect"><input type="hidden" name="' . $selectname[1] . '" id="' . $selectname[1] . '" value="">';
- foreach ($optionvalue[1] as $opkey => $opvalue) {
- $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>';
- }
- $html .= '</div><div style="clear:both;"></div>';
- } else {
- preg_match('/name\=\"(.+?)\"/i', $html, $selectname);
- preg_match_all('/value\=\"(.+?)\"/i', $html, $optionvalue);
- $html = '<div class="xjselect"><input type="hidden" name="' . $selectname[1] . '" id="' . $selectname[1] . '" value="">';
- foreach ($optionvalue[1] as $opvalue) {
- $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>';
- }
- $html .= '</div><div style="clear:both;"></div>';
- }
- }
- $html = preg_replace("/<div class=\"rq mtn\" id=\"showerror.+<\/div>/is", "", $html);
- if (strpos($html, 'type="text"') > 0) {
- $html = str_replace('class="px"', 'class="join_text"', $html);
- }
- $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
- $htmls[$fieldid] = $html;
- }
- }
- }
- } else {
- $selectuserfield = '';
- }
- } else {
- $userfield = unserialize($items['userfield']);
- $selectuserfield = unserialize($items['userfield']);
- if ($selectuserfield) {
- if ($selectuserfield) {
- $htmls = $settings = array();
- require_once libfile('function/profile');
- foreach ($selectuserfield as $fieldid) {
- /*
- if(empty($ufielddata['userfield'])) {
- $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
- foreach($selectuserfield as $val) {
- if($val == 'birthday'){
- $ufielddata['userfield']['birthyear'] = $memberprofile['birthyear'];
- $ufielddata['userfield']['birthmonth'] = $memberprofile['birthmonth'];
- }
- $ufielddata['userfield'][$val] = $memberprofile[$val];
- }
- unset($memberprofile);
- }
- */
- $html = profile_setting($fieldid, $ufielddata['userfield'], false, true);
- //$html = preg_replace('/value\=\"(.+?)\"/i','value=""',$html);
- if ($fieldid == 'birthday') {
- $memberprofile = C::t('common_member_profile')->fetch($_G['uid']);
- $mybirthday = $memberprofile['birthyear'] . '-' . $memberprofile['birthmonth'] . '-' . $memberprofile['birthday'];
- $html = '<div style="height:36px;"><input name="birthday" type="text" value="' . $mybirthday . '" class="dateselect" /><div></div></div>';
- }
- if ($fieldid == 'residecity') {
- $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>';
- }
- if ($html) {
- $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
- $htmls[$fieldid] = $html;
- }
- }
- }
- } else {
- $selectuserfield = '';
- }
- }
- //checkbox处理
- foreach ($apply as $key => $value) {
- if (!empty($selectuserfield)) {
- foreach ($selectuserfield as $fieldid) {
- if ($settings[$fieldid]['available']) {
- if ($settings[$fieldid]['formtype'] == 'checkbox') {
- $apply[$key]['ufielddata'][$fieldid] = $htmls[$fieldid];
- $tmp = explode(',', $value['ufielddata'][$fieldid]);
- foreach ($tmp as $cbvalue) {
- $apply[$key]['ufielddata'][$fieldid] = str_replace($cbvalue . '"', $cbvalue . '" checked', $apply[$key]['ufielddata'][$fieldid]);
- }
- }
- }
- }
- }
- }
- //过滤掉自动填入的数据
- /*
- foreach($htmls as $key=>$value){
- $htmls[$key] = preg_replace("/value=\"[^\"]+\"/", "value=\"\"", $value);
- }
- */
- //新的报名字段
- if ($setting['myuserfield']) {
- $myuserfield = $eventcore->GetUserField($setting['myuserfield']);
- foreach ($apply as $key => $value) {
- $apply[$key]['myuserfield'] = $eventcore->GetUserField($setting['myuserfield'], $value['ufielddata']);
- }
- }
- include template('xj_event:event_join_modify');
|