<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: install.php 34718 2014-07-14 08:56:39Z nemohou $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

if(!$_G['uid']) {
	showmessage('not_loggedin', NULL, array(), array('login' => 1));
}
$tid = intval($_GET['tid']);


$items = DB::fetch_first("SELECT * FROM ".DB::table('xj_event')." WHERE tid = '$tid'");
$thread =  DB::fetch_first("SELECT subject FROM ".DB::table('forum_thread')." WHERE tid = '$tid'");
$setting = unserialize($items['setting']);
$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) {
					$ufielddata['userfield'][$val] = $memberprofile[$val];
				}
				unset($memberprofile);
			}
			$html = profile_setting($fieldid, $ufielddata['userfield'], false, true);
			if($html) {
				$settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
				$htmls[$fieldid] = $html;
			}
		}
	}
} else {
	$selectuserfield = '';
}
$applynumber = array();
for($i=1;$i<=$items['event_number_max'];$i++){
	$applynumber[] = $i;
}




?>
<script type="text/javascript" src="http://wsq.discuz.qq.com/cdn/discuz/js/openjs.js"></script>
<script>
	var menu = new Array();
	WSQ.initBtmBar(menu);
	WSQ.showBtmBar();
	WSQ.initPlugin({name:'<?php echo $thread['subject'].lang('plugin/xj_event', 'baomin'); ?>'});

	var initWx = {
		'img': '<?php echo $_G['siteurl']; ?>/static/image/common/logo.png',
		'desc': '<?php echo $_G['bbsname'].lang('plugin/xj_event', 'huodzx'); ?>',
		'title': '<?php echo $thread['subject']; ?>',
	'pluginid':'xj_event:wsq_join_test',
		'param': 'a=1&b=2'
	};
	WSQ.initShareWx(initWx);
</script>
    
    
    
<script type="text/javascript" src="source/plugin/xj_event/js/jquery.js"></script>
<script type="text/javascript">
$(function(){ 
     $("#testbtn").click(function(){
		  $.ajax({ 
			  type: 'POST', 
			  url: 'plugin.php?id=xj_event:wsq_join_test', 
			  //data: {level:'fff', roomnumber:'bbb'},
			  data:$('#bmform').serialize(),
			  dataType: 'json', 
			  cache: false, 
			  error: function(){ 
				  alert('出错啦！'); 
				  return false; 
			  }, 
			  success:function(json){ 
				  if(json.full == 2){
					  alert('您已报名过，不可以重复报名！');
					  window.location.href="qiangpiao.php?vid=<?php echo $vid; ?>&oid=<?php echo $openid; ?>";
					  return false;
				  }
				  if(json.full == 1){
					  alert('恭喜您报名成功！');
					  window.location.href="qiangpiao.php?vid=<?php echo $vid; ?>&oid=<?php echo $openid; ?>";
					  return true;
				  }else{
					  alert('出错啦！'); 
					  return false; 
				  }
			  } 
		  });
    }); 
}); 
</script>
  
<style type="text/css">
    #container {margin:5px;}
    body {height:100%;}
	.input1{padding:14px; line-height:14px; width:100%;-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius:4px; border:1px solid #d8d8d8;}
    select{height:42px;-webkit-appearance:none;appearance:none;border:none;font-size:14px;padding:0px 10px;display:block;width:100%;-webkit-box-sizing:border-box;box-sizing:border-box;background-color: #FFFFFF;color:#aaa;border-radius:4px;}
	.selectdiv{margin-top:0px;outline:none;-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius:4px; border:1px solid #d8d8d8;position:relative;}
	.checkbox {
 width: 19px;
 height: 25px;
 padding: 0 5px 0 0;
 background: url(checkbox.png) no-repeat;
 display: block;
 float: left;
}
	label{float:left; font-size:14px; line-height:30px;}
</style>

</head>
<body>
<div>
	<div style="padding:20px; font-size:16px; font-weight:bold; color:#4095ce; text-align:center;">
    	<?php echo $thread['subject']; ?>
    </div>
    <form name="bmform" id="bmform">
    <input type="hidden" name="formhash" value="<?php echo $_G['formhash'];?>" />
    <input type="hidden" name="eid" value="<?php echo $items['eid'];?>" />

    
    <div style="padding:10px 30px;">
        <div class="selectdiv"> 
        <select name="session"> 
        <option>活动场次</option>
        <?php foreach($setting['session'] as $key=>$value){ ?>
        <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
        <?php } ?>
        </select> 
        </div> 
    </div>
    
    
	<?php 
	
	if(!empty($selectuserfield)){
    	foreach($selectuserfield as $fieldid){
			if($settings[$fieldid]['available']){
				if($settings[$fieldid]['formtype'] != 'file'){
					$htmls[$fieldid] = str_replace('class="px"','class="input1" placeholder="'.$settings[$fieldid]['title'].'"',$htmls[$fieldid]);
            		$htmls[$fieldid] = preg_replace("/<div.+<\/div>/is", "", $htmls[$fieldid]);
					if(strpos($htmls[$fieldid],'select')>0){
						$htmls[$fieldid] = str_replace('tabindex="1">','tabindex="1"><option>'.$settings[$fieldid]['title'].'</option>',$htmls[$fieldid]);
						echo '<div style="padding:10px 30px;">'.$htmls[$fieldid].'</div>';
					}elseif(strpos($htmls[$fieldid],'checkbox')>0){
						//$htmls[$fieldid] = str_replace('type="checkbox"','type="checkbox" class="checkbox"',$htmls[$fieldid]);
						echo '<div style="padding:10px 30px;">'.$htmls[$fieldid].'<div style="clear:both;"></div></div>';
					}else{
						echo '<div style="padding:10px 30px;">'.$htmls[$fieldid].'</div>';
					}
				}else{
				}
			}
		}
	}
    ?>
    
    
    
    
    <div style="padding:10px 30px;">
        <div class="selectdiv"> 
        <select name="applynumber"> 
        <option>报名人数</option>
        <?php foreach($applynumber as $key=>$value){ ?>
        <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
        <?php } ?>
        </select> 
        </div> 
    </div>

	<div style="padding:10px 30px;">
    	<input name="message" type="text" placeholder="留言" class="input1">
    </div>
    


	</form>

	<a href="javascript:" id="testbtn">测试</a>
</div>        
</body>
</html>
