ApplyAction.class.php 29.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
<?php
class ApplyAction extends CommonAction {
	public $tab='Apply';
	public $tabView='ApplyView';
	public $sumid='';
	public function __construct() {
		parent::__construct();
		$this->sumid=I('sumid');
		$spe_action=array('operate','operate2','operate3','operate4');
		if(!$this->sumid && in_array(ACTION_NAME,$spe_action)){
			$this->sumid=$this->getSumid();
			if(!$this->sumid){
				$this->error(date('Y').'年夏令营信息不存在,请确认!');
				exit;
			}
		}
		if(!$this->sumid){
			$this->error('数据参数有误!');
			exit;
		}
		if(!$this->checkSchool($this->sumid)){
			$this->error('夏令营举办单位与当前账户不相符,请先确认!');
			exit;
		}
		$this->assign('sumid',$this->sumid);
		$this->assign('speSchool',$this->getSpeSchool());	//推免资格学校列表
	}
/**
 * 判断夏令营活动是否属于所登录的账户
 * @param  int $id 夏令营id
 * @return bool 属于返回true,否则返回false
 */
	private function checkSchool($id){
		$m=M('Summer');
		$where['id']=array('eq',$id);
		$data=$m->where($where)->getField('id,sid');
		if($data[$id] == cookie('ADMIN_SCHOOL') || cookie('ADMIN_KEY') == 1)
			return true;
		else
			return false;
	}
/**
 * 返回拟申请项目 一级分类
 * @return array
 */
	private function getAppproject(){
		$where['name']=array('eq','appproject');
		$data=M('Regfields')->where($where)->getfield('d_value');
		$data=explode('#',$data);
		return $data;
	}
/**
 * ajax 返回拟申请项目 二级分类
 * @return json
 */
	public function getAppproject2(){
		$pro=I('appproject');	//一级分类名称
		$pro_list=C('APPPROJECT');	//配置文件中找出对应的二级分类
		$pro2=I('appproject2');	//二级分类默认值
		$list=$pro_list[$pro];
		if($list){
			$data['suc']=true;
			$data['cont']='';
			foreach($list as $v){
				$data['cont'].='<option value="'.$v.'"';
				if($pro2 && $pro2 == $v) $data['cont'].=' selected';
				$data['cont'].='>'.$v.'</option>';
			}
		}else{
			$data['suc']=false;
			$data['cont']='<option value="">请选择</option>';
		}
		echo json_encode($data);
	}
/**
 * 以往夏令营活动学员申请列表
 */
    public function manage(){
		// $Article=D($this->tab);
		$Article=D($this->tabView);
		import('ORG.Util.Pages');
		$where['pid']=array('eq',$this->sumid);
		if($search['entnum']=I('entnum','','trim')) $where['entnum']=array('eq',I('entnum','','trim'));
		if($search['name']=I('name','','trim')) $where['name']=array('like','%'.I('name','','trim').'%');
		if($search['school']=I('school','','trim')) $where['school']=array('eq',I('school','','trim'));
		if($search['appproject']=I('appproject')) $where['appproject']=array('eq',I('appproject'));
		if($search['appproject2']=I('appproject2')) $where['appproject2']=array('eq',I('appproject2'));
		if($search['status']=I('status')){
			switch(I('get.status')){	//1等待审核、2已审核、3已备选、4已录取
				case 1:
					$where['status1&status2&status3']=array('eq',0);
					break;
				case 2:
					$where['status1']=array('eq',1);
					$where['status2&status3']=array('eq',0);
					break;
				case 3:
					$where['status1&status2']=array('eq',1);
					$where['status3']=array('eq',0);
					break;
				case 4:
					$where['status1&status2&status3']=array('eq',1);
					break;
			}
		}
		$this->assign('search',$search);
		$count = $Article->where($where)->count();
		// echo $Article->getLastSql();
		$Page = new Pages($count,20);

		$ord=array();//	985 211 cet6排序
		if(I('orda',0,'intval')) $ord['orda'] = 1;	//985
		if(I('ordb',0,'intval')) $ord['ordb'] = 1;	//211
		if(I('ordc',0,'intval')) $ord['ordc'] = 1;	//cet6
		if($ord){
			if($ord['orda']) $orderby['check985']='desc';
			if($ord['ordb']) $orderby['check211']='desc';
			if($ord['ordc']) $orderby['cet_6']='desc';
		}
		$this->assign('ord',$ord);
		$orderby['Apply.id']='desc';	//注意排序

		$sum=A('Reg');
		$field=$sum->notDel;	//获取报名申请的基本字段
		array_push($field,'addtime','id','status1','status2','status3','entnum','uid');
		$list = $Article->field($field)->order($orderby)->where($where)->page($Page->nowPage.','.$Page->listRows)->select();
		// echo $Article->getLastSql();
		$show = $Page->show();
		$this->assign('page',$show);
		$this->assign('list',$list);
		$sum_info=$this->getSummer(array('id'=>array('eq',$this->sumid)));	//夏令营活动信息
		$this->assign('project',$this->getAppproject());	//拟申请项目 一级分类
		$this->assign('web_title',$sum_info['title'].'—报名信息列表');	//页面列表标题
		$this->display();
	}
/**
 * 根据年份调出sumid
 * @return int
 */
	private function getSumid(){
		$year=date('Y');
		$data=M('Summer')->where(array('year'=>array('eq',$year)))->getfield('id');
		return $data;
	}
/**
 * 当年夏令营 基本操作 获取列表数据
 * @param  array $where 查询where条件
 * @param  string $title  页面title说明
 */
	private function comOperate($where,$title){
		// $Article=D($this->tab);
		$Article=D($this->tabView);
		import('ORG.Util.Pages');
		$where['pid']=$this->sumid;
		$count = $Article->where($where)->count();
		// echo $Article->getLastSql();
		$Page = new Pages($count,20);
		$ord=array();//	985 211 cet6排序
		if(I('orda',0,'intval')) $ord['orda'] = 1;	//985
		if(I('ordb',0,'intval')) $ord['ordb'] = 1;	//211
		if(I('ordc',0,'intval')) $ord['ordc'] = 1;	//cet6
		if($ord){
			if($ord['orda']) $orderby['check985']='desc';
			if($ord['ordb']) $orderby['check211']='desc';
			if($ord['ordc']) $orderby['cet_6']='desc';
		}
		$orderby['Apply.id']='desc';	//注意排序
		$this->assign('ord',$ord);
		
		$sum=A('Reg');
		$field=$sum->notDel;	//获取报名申请的基本字段
		array_push($field,'addtime','id','status1','status2','status2_ac','status3','status3_ac','entnum');
		$list = $Article->field($field)->order($orderby)->where($where)->page($Page->nowPage.','.$Page->listRows)->select();
		// echo $Article->getLastSql();
		$show = $Page->show();
		$this->assign('page',$show);
		$this->assign('list',$list);
		$sum_info=$this->getSummer(array('id'=>array('eq',$this->sumid)));	//夏令营活动信息
		$this->assign('project',$this->getAppproject());	//拟申请项目 一级分类
		$this->assign('web_title',$sum_info['title'].'—'.$title);	//页面列表标题
		$this->assign('nowpage',$Page->nowPage);
	}
/**
 * 当年夏令营活动 报名学生列表
 */
    public function operate(){
		if($search['entnum']=I('entnum','','trim')) $where['entnum']=array('eq',I('entnum','','trim'));
		if($search['name']=I('name','','trim')) $where['name']=array('like','%'.I('name','','trim').'%');
		if($search['school']=I('school','','trim')) $where['school']=array('like','%'.I('school','','trim').'%');
		if($search['appproject']=I('appproject')) $where['appproject']=array('eq',I('appproject'));
		if($search['appproject2']=I('appproject2')) $where['appproject2']=array('eq',I('appproject2'));
		$this->assign('search',$search);
		$this->comOperate($where,'报名学生列表');
		$this->display();
	}
/**
 * 当年夏令营活动 备选库学生列表
 */
    public function operate2(){
    	if($search['entnum']=I('entnum','','trim')) $where['entnum']=array('eq',I('entnum','','trim'));
		if($search['name']=I('name','','trim')) $where['name']=array('like','%'.I('name','','trim').'%');
		if($search['school']=I('school','','trim')) $where['school']=array('eq',I('school','','trim'));
		if($search['appproject']=I('appproject')) $where['appproject']=array('eq',I('appproject'));
		if($search['appproject2']=I('appproject2')) $where['appproject2']=array('eq',I('appproject2'));
		$this->assign('search',$search);
		$where['status1']=array('eq',1);	//备选库学生
		$this->comOperate($where,'备选库学生列表');
		$this->display('Apply:operate');
	}
/**
 * 当年夏令营活动 待录取学生列表
 */
    public function operate3(){
    	if($search['entnum']=I('entnum','','trim')) $where['entnum']=array('eq',I('entnum','','trim'));
		if($search['name']=I('name','','trim')) $where['name']=array('like','%'.I('name','','trim').'%');
		if($search['school']=I('school','','trim')) $where['school']=array('eq',I('school','','trim'));
		if($search['appproject']=I('appproject')) $where['appproject']=array('eq',I('appproject'));
		if($search['appproject2']=I('appproject2')) $where['appproject2']=array('eq',I('appproject2'));
		$this->assign('search',$search);
		$where['status1&status2']=array('eq',1);	//待录取学生
		$where['status2_ac']=array('eq',2);	//学生接受参营邀请
		$this->comOperate($where,'待录取学生列表');
		$this->display('Apply:operate');
	}
/**
 * 当年夏令营活动 录取学生列表
 */
    public function operate4(){
		if($search['name']=I('name','','trim')) $where['name']=array('like','%'.I('name','','trim').'%');
		if($search['school']=I('school','','trim')) $where['school']=array('eq',I('school','','trim'));
		if($search['appproject']=I('appproject')) $where['appproject']=array('eq',I('appproject'));
		if($search['appproject2']=I('appproject2')) $where['appproject2']=array('eq',I('appproject2'));
		$this->assign('search',$search);
		$where['status1&status2&status3']=array('eq',1);	//待录取学生
		$where['status2_ac&status3_ac']=array('eq',2);	//学生接受参营邀请
		$this->comOperate($where,'录取学生列表');
		$this->display('Apply:operate');
	}
/**
 * 获取夏令营数据
 * @param  array $where 筛选条件
 * @param  string $field 字段
 * @return array
 */
	private function getSummer($where,$field='title'){
		$reg=M('Summer');
		$list=$reg->field($field)->where($where)->find();
		return $list;
	}
/**
 * 返回用户所报名夏令营提交的数据(每个人只能申请一次夏令营)
 * @param field 字段
 * @param id apply数据id
 * @return array 用户报名所提交的数据
 */
	private function getAppInfo($where=array(),$field='*'){
		$data=M('Apply')->field($field)->where($where)->find();
		return $data;
	}
/**
 * 查看学生申请的数据
 */
	public function look(){
		$sum_where['id']=array('eq',$this->sumid);
		$summer=$this->getSummer($sum_where,'sid,title,rfields');//获取所申请的夏令营活动相关信息

		$m=M('Regfields');
		$where['isshow']=array('eq',1);
		$where['name']=array('in',$summer['rfields']);	//夏令营活动需要填写的字段
		$order='sort';
		$fields=$this->_getList($m,$where,$order,0,0,'id,name,description,type,rownum,colnum,d_value,ctitle,fline,isdate,upfile');	//获取申请应填写的字段的信息 listdata,result_count

		$this->assign('summer',$summer);	//夏令营信息
		$this->assign('fields',$fields);	//申请应填写的字段信息
		$app_data=$this->getAppInfo(array('id'=>array('eq',I('get.id'))));	//申请夏令营所填写的数据
		$this->assign('app_data',$app_data);	//申请夏令营所填写的数据
		$this->assign('web_title',$app_data['name'].'报名申请信息');
		if(strpos($_SERVER['HTTP_REFERER'],'operate4') !== false)
			$action = 'operate4';
		elseif(strpos($_SERVER['HTTP_REFERER'],'operate3') !== false)
			$action = 'operate3';
		elseif(strpos($_SERVER['HTTP_REFERER'],'operate2') !== false)
			$action = 'operate2';
		elseif(strpos($_SERVER['HTTP_REFERER'],'operate') !== false)
			$action = 'operate';
		$this->assign('action',$action);	//父页面action_name
		$this->assign('nowpage',I('page'));	//父页面分页页数
		$this->display();
	}
/**
 * ajax备选
 */
	public function beixuan(){
		$do='备选';
		$Article=M($this->tab);
		$data['id']=I('get.id');
		if(!$data['id']){
			$data['suc']=false;
			$data['info']='信息参数有误!';
		}else{
			$data['status1']=1;
			$data['time1']=time();
			$is=$Article->save($data);
			if($is){
				$data['suc']=true;
				$data['info']=$do.'操作成功!';
				$data['name']='已入备选库';
			}else{
				$data['suc']=false;
				$data['info']=$do.'操作失败!';
			}
		}
		echo json_encode($data);
	}
/**
 * 确定参营 并发送参营邀请邮件
 */
	public function canying(){
		$do='确定参营';
		$data['id']=I('id');
		if(!$data['id']){
			$this->error("信息参数有误!");
			exit;
		}
		$back_url=U('operate2',array('sumid'=>$this->sumid,'p'=>$this->_param('p')));
		if($this->isPost()){
			$Article=M($this->tab);
			$data['status2']=1;
			$data['time2']=time();
			if(I('doagin','','trim') == 'yes'){
				$data['status2_ac'] = 0;
			}
			$is=$Article->save($data);
			if($is){
				//发送email
				$title=I('title','','trim,htmlspecialchars');
				$content=I('content','','trim');
				$this->sendEmail(array('id'=>array('eq',$data['id'])),1,$title,$content); //发送email并且把email信息入库保存 1确定参营、2待录取
				$this->success($do.'操作成功!',$back_url);
			}else{
				$this->error($do.'操作失败!');
			}
			exit;
		}
		$this->assign('info',$this->getAppInfo(array('id'=>array('eq',$data['id'])),'id,name,email'));	//夏令营报名信息
		$this->assign('webtitle','发送参营邀请');
		$this->assign('back_url',$back_url);
		$this->assign('sumid',$this->sumid);
		$this->assign('p',$this->_param('p'));
		$this->assign('emails',json_decode(R('Email/getTmpEmail'),true));	//获取email模板
		$this->display();
	}
/**
 * 给学生发送邮件,邮件信息并入库
 * @param  array $where 查询夏令营报名条件
 * @param  int $cate  邮件类型:1确定参营,2待录取
 * @param  string $title 邮件标题
 * @param  string $content 邮件内容
 * @return bool 成功ture,失败false
 */
	private function sendEmail($where,$cate,$title,$content){
		$info=$this->getAppInfo($where,'pid,uid,email');
		$data['sumid']=$info['pid'];	//夏令营
		$data['admin']=cookie('ADMIN_KEY'); //后台管理员
		$data['uid']=$info['uid'];	//学生id
		$data['email']=$info['email'];	//学生email
		$data['cate']=$cate;	//邮件各类:1确定参营,2待录取
		$data['title']=$title;	//email 标题
		$data['content']=$content;	//email 内容
		$data['addtime']=time();

		if(sendMail($data['email'], $info['name'], $data['title'], $data['content']) === true){ 	//发送邮件成功
			$lastid=M('Email')->add($data);
			return true;
		}else{	//发送失败
			return false;
		}
	}
/**
 * 待录取 并发送待录取邀请邮件
 */
	public function luqu(){
		$do='待录取';
		$data['id']=I('id');
		if(!$data['id']){
			$this->error("信息参数有误!");
			exit;
		}
		$back_url=U('operate3',array('sumid'=>$this->sumid,'p'=>$this->_param('p')));
		if($this->isPost()){
			$Article=M($this->tab);
			$data['status3']=1;
			$data['time3']=time();
			if(I('doagin','','trim') == 'yes'){
				$data['status3_ac'] = 0;
			}
			$is=$Article->save($data);
			if($is){
				//发送email
				$title=I('title','','trim,htmlspecialchars');
				$content=I('content','','trim');
				$this->sendEmail(array('id'=>array('eq',$data['id'])),2,$title,$content); //发送email并且把email信息入库保存 1确定参营、2待录取
				$this->success($do.'操作成功!',$back_url);
			}else{
				$this->error($do.'操作失败!');
			}
			exit;
		}
		$this->assign('info',$this->getAppInfo(array('id'=>array('eq',$data['id'])),'id,name,email'));	//夏令营报名信息
		$this->assign('webtitle','发送待录取邀请');
		$this->assign('back_url',$back_url);
		$this->assign('sumid',$this->sumid);
		$this->assign('p',$this->_param('p'));
		$this->assign('emails',json_decode(R('Email/getTmpEmail'),true));	//获取email模板
		$this->display('Apply:canying');
	}
/**
 * 返回推免资格学校列表
 * @return array
 */
	private function getSpeSchool(){
		$m=M('School');
		$data=$m->getField('name,check985,graduate,check211');
		return $data;
	}
/**
 * 获取夏令营导出所需的字段信息 选取并提交至下载页
 */
	public function checkField(){
		$sum_info=$this->getSummer(array('id'=>array('eq',$this->sumid)),'title,rfields');	//获取夏令营信息,夏令营名称及夏令营申请应填写信息
		$info=M('Regfields')->field('name,description')->where(array('name'=>array('in',$sum_info['rfields'])))->order('sort asc')->select();	//字段信息 name名称 description注释
		$this->assign('info',$info);
		$action=I('action');
		switch($action){
			case 'operate':
				$webtitle=$sum_info['title'].'——'.'学生信息下载';
				break;
			case 'operate2':	//备选学生
				$webtitle=$sum_info['title'].'——'.'备选学生信息下载';
				break;
			case 'operate3':	//待录取学生
				$webtitle=$sum_info['title'].'——'.'待录取学生信息下载';
				break;
			case 'operate4':	//可录取学生
				$webtitle=$sum_info['title'].'——'.'可录取学生信息下载';
				break;
		}
		$this->assign('web_title',$webtitle);
		$this->assign('action',I('action'));
		$this->assign('sumid',$this->sumid);
		$this->display();
	}
/**
 * 导出学生信息至excel表
 */
	/*public function download2(){
		set_time_limit(0);
		$field=array_filter(I('field'));	//下载所需的字段
		$action=I('action');
		$sum_info=$this->getSummer(array('id'=>array('eq',$this->sumid)),'title');	//获取夏令营信息,夏令营名称及夏令营申请应填写信息
		$info=M('Regfields')->field('name,description,type,')->where(array('name'=>array('in',$field)))->order('sort asc')->select();	//字段信息 name名称 description注释
		if($info){
			foreach($info as $v){
				$new_field[]=$v['name'];
			}
		}
		switch($action){
			case 'operate':
				$filename=$sum_info['title'].'-'.'报名学生列表';
				break;
			case 'operate2':	//备选学生
				$filename=$sum_info['title'].'-'."备选库学生列表";
				$where['status1&status2']=array('eq',1);
				break;
			case 'operate3':	//待录取学生
				$filename=$sum_info['title'].'-'."待录取学生列表";
				$where['status1&status2&status3']=array('eq',1);
				$where['status2_ac']=array('eq',2);
				break;
			case 'operate4':	//录取学生
				$filename=$sum_info['title'].'-'."录取学生列表";
				$where['status1&status2&status3']=array('eq',1);
				$where['status2_ac&status3_ac']=array('eq',2);
				break;
		}
		$where['pid']=array('eq',$this->sumid);	//管理员所选择的字段
		$list=M('Apply')->field($new_field)->where($where)->select();	//符合条件的学生

		$filename.=date('_YmdHis');
		$filename = iconv('utf-8', 'gb2312', $filename);//文件名称
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new PHPExcel();
        $count=count($info);	//导出字段数
		$cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ');
        $obj=$objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	//A1设置居中
        $obj->setCellValue('A1', '序号');	//A1设置标题
        for($i=1,$ii=0;$i <= $count;$i++,$ii++){	//设置标题
        	$objPHPExcel->getActiveSheet()->getStyle($cellName[$i].'1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	//设置居中
        	$obj->setCellValue($cellName[$i].'1', $info[$ii]['description']);
        }
        foreach($list as $k => $v){
        	$obj->setCellValue('A'.($k+2), $k+1);	//A列
        	for($i=1;$i <= $count;$i++){	//设置标题
	        	$objPHPExcel->getActiveSheet()->getStyle($cellName[$i].($k+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	//设置居中
	        	//多行文本、多选框、上传附件
	        	$f_info=$this->getFieldInfo($new_field[$i-1]);//name,type,rownum,colnum,ctitle,upfile
	        	// echo $f_info['name'].'——'.$f_info['type'],'<br/>';
	        	if($f_info['upfile'] == 1){	//图片
	        		$pp_val='';
	        	}elseif($f_info['type'] == 'c_heckbox'){	//多选框
	        		$pp_val=implode(',',$v[$new_field[$i-1]]);
	        	}elseif($f_info['type'] == 'bstring'){	//多文本
	        		$row=$f_info['rownum']?$f_info['rownum']:1;
					$col=$f_info['colnum']?$f_info['colnum']:1;
					$pp_val='';
					if($f_info['ctitle']){	//列标题
						$ctitle=explode('#',$f_info['ctitle']);
						$pp_val.='<tr>';
						foreach($ctitle as $k=>$v){
							$pp_val.='<td>'.$v.'</td>';
						}
						$pp_val.='</tr>';
					}
					if($v[$new_field[$i-1]]) $value=json_decode($v[$new_field[$i-1]],true);	//存在数据
					if($value){	//存在数值
						for($i=1;$i<=$row;$i++){
							for($ii = 1;$ii<=$col;$ii++){
								$pp_val.=$value[$i][$ii].',';
							}
							
						}
					}
	        	}else{
	        		$pp_val=$v[$new_field[$i-1]];
	        	}
	        	$obj->setCellValue($cellName[$i].($k+2), $pp_val);
	        }
        }



		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		// $objPHPExcel->setActiveSheetIndex(0);

		ob_end_clean();//清除缓冲区,避免乱码
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename='.$filename.'.xls');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
	}*/
	public function download(){
		set_time_limit(0);
		$field=array_filter(I('field'));	//下载所需的字段
		$action=I('action');
		$sum_info=$this->getSummer(array('id'=>array('eq',$this->sumid)),'title');	//获取夏令营信息,夏令营名称及夏令营申请应填写信息
		$info=M('Regfields')->field('name,description,rownum,colnum,ctitle,upfile')->where(array('name'=>array('in',$field)))->order('sort asc')->select();	//字段信息 name名称 description注释
		if($info){
			foreach($info as $v){
				$new_field[]=$v['name'];
			}
		}
		$speSchool=$this->getSpeSchool();	//推免资格学校列表
		switch($action){
			case 'operate':
				$filename=$sum_info['title'].'-'.'报名学生列表';
				break;
			case 'operate2':	//备选学生
				$filename=$sum_info['title'].'-'."备选库学生列表";
				$where['status1']=array('eq',1);
				break;
			case 'operate3':	//待录取学生
				$filename=$sum_info['title'].'-'."待录取学生列表";
				$where['status1&status2']=array('eq',1);
				$where['status2_ac']=array('eq',2);
				break;
			case 'operate4':	//录取学生
				$filename=$sum_info['title'].'-'."录取学生列表";
				$where['status1&status2&status3']=array('eq',1);
				$where['status2_ac&status3_ac']=array('eq',2);
				break;
		}
		$where['pid']=array('eq',$this->sumid);	//管理员所选择的字段
		$list=M('Apply')->field($new_field)->where($where)->select();	//符合条件的学生

		$filename.=date('_YmdHis');
		$filename = iconv('utf-8', 'gb2312', $filename);//文件名称
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new PHPExcel();
        $count=count($info);	//导出字段数

		$str='<table width="100%" border="1" cellpadding="0" cellspacing="1">';
		$str.='<tr>';
		$str.='<td align="center">序号</td>';
		for($i=0;$i < $count;$i++){	//设置标题
			$f_info=$this->getFieldInfo($new_field[$i]);//name,type,rownum,colnum,ctitle,upfile
			if($f_info['type'] == 'bstring'){	//多文本
				$str.='<td align="center">';
        		$row=$f_info['rownum']?$f_info['rownum']:1;
				$col=$f_info['colnum']?$f_info['colnum']:1;
				$r_width=100 / $col;
				$str.='<table border="1" cellpadding="0" cellspacing="1">';
				$str.='<tr><td align="center" colspan="'.$col.'">'.$info[$i]['description'].'</td></tr>';
				if($f_info['ctitle']){	//列标题
					$ctitle=explode('#',$f_info['ctitle']);
					$str.='<tr>';
					foreach($ctitle as $val){
						$str.='<td align="center" style="WORD-WRAP: break-word" width="'.$r_width.'%">'.$val.'</td>';
					}
					$str.='</tr>';
				}
				$str.='</table>';
				$str.='</td>';
			}else{
				$str.='<td align="center">'.$info[$i]['description'].'</td>';
			}
			if($f_info['name']=='school'){	//学校 判断是否为985 211
				$str.='<td align="center">985</td><td align="center">211</td>';
			}
        }
		$str.='</tr>';
        foreach($list as $k => $v){
        	$str.='<tr>';
        	$str.='<td align="center">'.($k+1).'</td>';	//A列
        	for($i=0;$i < $count;$i++){	//设置标题
	        	//多行文本、多选框、上传附件
	        	$f_info=$this->getFieldInfo($new_field[$i]);//name,type,rownum,colnum,ctitle,upfile
	        	// echo $f_info['name'].'——'.$f_info['type'],'<br/>';
	        	if($f_info['upfile'] == 1){	//图片
	        		if($v[$new_field[$i]])
	        			// $pp_val='<div><img src="http://'.$_SERVER['SERVER_NAME'].$v[$new_field[$i]].'" width="65" height="65" /></div>';
	        			$pp_val='';
	        		else
	        			$pp_val='';
	        	}elseif($f_info['type'] == 'c_heckbox'){	//多选框
	        		$pp_val=implode(',',$v[$new_field[$i]]);
	        	}elseif($f_info['type'] == 'bool'){	//多选框
	        		$pp_val=$v[$new_field[$i]] == 1?'是':'否';
	        	}elseif($f_info['type'] == 'bstring'){	//多文本
	        		$row=$f_info['rownum']?$f_info['rownum']:1;
					$col=$f_info['colnum']?$f_info['colnum']:1;
					$r_width=100 / $col;
					/*if($f_info['ctitle']){	//列标题
						$ctitle=explode('#',$f_info['ctitle']);
						$pp_val.='<tr>';
						foreach($ctitle as $val){
							$pp_val.='<td align="center" style="WORD-WRAP: break-word" width="'.$r_width.'%">'.$val.'</td>';
						}
						$pp_val.='</tr>';
					}*/
					if($v[$new_field[$i]]) $value=json_decode($v[$new_field[$i]],true);	//存在数据
					if($value){	//存在数值
						$pp_val='<table border="1" cellpadding="0" cellspacing="1">';
						/*for($ii=1;$ii<=$row;$ii++){	//行
							$pp_val.='<tr>';
							for($iii = 1;$iii<=$col;$iii++){	//列
								$pp_val.='<td align="center">'.$value[$ii][$iii].'</td>';
							}
							$pp_val.='</tr>';
						}*/
						foreach($value as $v1){
							$pp_val.='<tr>';
							foreach($v1 as $v2){
								$pp_val.='<td align="center" style="WORD-WRAP: break-word" width="'.$r_width.'%">'.$v2.'</td>';
							}
							$pp_val.='</tr>';
						}
						$pp_val.='</table>';
					}
					unset($row,$col,$r_width,$value);
	        	}elseif(in_array($f_info['name'], array('idnumber','mobile'))){
	        		$pp_val='<div style="vnd.ms-excel.numberformat:@">'.$v[$new_field[$i]].'</div>';
	        	}else{
	        		$pp_val=$v[$new_field[$i]];
	        	}
	        	$str.='<td align="center">'.$pp_val.'</td>';
	        	unset($pp_val);
	        	if($f_info['name']=='school'){	//学校 判断是否为985 211
					$str.='<td align="center" >';
					$str.=($speSchool[$v['school']] && $speSchool[$v['school']]['check985'])?'是':'否';
					$str.='</td><td align="center">';
					$str.=($speSchool[$v['school']] && $speSchool[$v['school']]['check211'])?'是':'否';
					$str.='</td>';
				}
	        }
	        $str.='</tr>';
        }


        $str.='</table>';

        
		// ob_end_clean();//清除缓冲区,避免乱码
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename='.$filename.'.xls');
		$str = iconv('utf-8', 'gb2312', $str);
		echo $str;
	}
/**
 * 获取字段详细信息
 * @param  string $name  字段名
 * @param  string $field 查询field
 * @return array
 */
	private function getFieldInfo($name,$field='name,type,rownum,colnum,ctitle,upfile'){	//type:文本string,多行文本bstring,布尔bool,数字number,文本域t_extarea,下拉列表s_elect,多选框c_heckbox,单选r_adio
		$where['name']=array('eq',$name);
		$data=M('Regfields')->where($where)->field($field)->find();
		return $data;
	}
/**
 * 修改学生信息
 * @return [type] [description]
 */
	public function editUser(){
		$id=(int)I('id','','trim');
		if(!$id){
			exit('<script>alert("信息参数有误!");history.back();</script>');
		}
		if($this->isPost()){
			$user=D('Webuser');
			if(!$user->create()){
				$this->error($user->getError());
			}else{
				if(I('password','','trim') && (I('password','','trim') !== I('repassword','','trim'))){
					$this->error('两次密码不相同,请确认!');
					exit;
				}elseif(I('password','','trim')){
					$user->password=md5(trim($user->password));
				}else{
					unset($user->password);
				}

				if($is=$user->save()){
					$this->success('学生信息修改成功!',U('manage',array('sumid'=>$this->sumid)));
				}else{
					$this->error('学生信息修改失败!');
				}
			}
			exit;
		}
		$this->assign('userinfo',$this->getUserInfo($id));
		$this->display();
	}
/**
 * 获取学生个人信息
 * @param  int $id    wa_webuser表id
 * @param  string $field 字段
 * @return array        
 */
	private function getUserInfo($id,$field){
		$m=M('Webuser');
		$where['id']=array('eq',$id);
		$data=$m->where($where)->field($field)->find();
		return $data;
	}
}